diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d7eb524f..5e23469f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,9 +2,9 @@ name: CI on: push: - branches: [main, release_workflow, 'release_**'] + branches: [main, develop, release_workflow, 'release_**'] pull_request: - branches: [main, release_workflow] + branches: [main, develop, release_workflow] concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/.gitignore b/.gitignore index 82e4dc5e..c5987319 100644 --- a/.gitignore +++ b/.gitignore @@ -55,3 +55,7 @@ nodeId.properties # vm_trace /vm_trace/ + +#test dependence +solcDIR +gRPCurl \ No newline at end of file diff --git a/testcase/build.gradle b/testcase/build.gradle index 7f35924a..bc55d92c 100644 --- a/testcase/build.gradle +++ b/testcase/build.gradle @@ -225,7 +225,6 @@ task lint(type: Checkstyle) { source 'src' include '**/*.java' exclude 'main/gen/**' - exclude 'test/**' // empty classpath classpath = files() //Failing the build diff --git a/testcase/src/test/java/org/tron/common/zksnark/IncrementalMerkleTreeContainer.java b/testcase/src/test/java/org/tron/common/zksnark/IncrementalMerkleTreeContainer.java index 54b46162..1ed5a6ce 100644 --- a/testcase/src/test/java/org/tron/common/zksnark/IncrementalMerkleTreeContainer.java +++ b/testcase/src/test/java/org/tron/common/zksnark/IncrementalMerkleTreeContainer.java @@ -17,9 +17,7 @@ @Slf4j public class IncrementalMerkleTreeContainer { - @Getter - @Setter - private static Integer DEPTH = 32; + @Getter @Setter private static Integer DEPTH = 32; private IncrementalMerkleTreeCapsule treeCapsule; @@ -53,8 +51,7 @@ public void wfcheck() throws ZksnarkException { } if ((!leftIsPresent()) && treeCapsule.getParents().size() > 0) { - throw new ZksnarkException( - "tree has non-canonical representation; parents should be empty"); + throw new ZksnarkException("tree has non-canonical representation; parents should be empty"); } } @@ -86,9 +83,7 @@ public int size() { return ret; } - /** - * append PedersenHash to the merkletree. - */ + /** append PedersenHash to the merkletree. */ public void append(PedersenHash obj) throws ZksnarkException { if (isComplete(DEPTH)) { throw new ZksnarkException("tree is full"); @@ -143,9 +138,7 @@ public boolean isComplete(long depth) { return true; } - /** - * get the depth of the skip exist element. - */ + /** get the depth of the skip exist element. */ public int nextDepth(int skip) { if (!leftIsPresent()) { if (skip != 0) { @@ -314,9 +307,9 @@ public PedersenHash next(int depth) { public static class EmptyMerkleRoots { - @Setter - @Getter + @Setter @Getter private static EmptyMerkleRoots emptyMerkleRootsInstance = new EmptyMerkleRoots(); + private List emptyRoots = new ArrayList<>(); public EmptyMerkleRoots() { diff --git a/testcase/src/test/java/org/tron/common/zksnark/IncrementalMerkleVoucherContainer.java b/testcase/src/test/java/org/tron/common/zksnark/IncrementalMerkleVoucherContainer.java index deafcbe2..0dbffd84 100644 --- a/testcase/src/test/java/org/tron/common/zksnark/IncrementalMerkleVoucherContainer.java +++ b/testcase/src/test/java/org/tron/common/zksnark/IncrementalMerkleVoucherContainer.java @@ -11,9 +11,7 @@ public class IncrementalMerkleVoucherContainer { - @Getter - @Setter - private static Integer DEPTH = IncrementalMerkleTreeContainer.getDEPTH(); + @Getter @Setter private static Integer DEPTH = IncrementalMerkleTreeContainer.getDEPTH(); private IncrementalMerkleVoucherCapsule voucherCapsule; @@ -96,7 +94,7 @@ public int size() { + voucherCapsule.getCursor().toMerkleTreeContainer().size(); } - //for test only + // for test only public void printSize() { System.out.println( "TreeSize:" diff --git a/testcase/src/test/java/org/tron/common/zksnark/JLibrustzcash.java b/testcase/src/test/java/org/tron/common/zksnark/JLibrustzcash.java index eba08a28..8fe1c474 100644 --- a/testcase/src/test/java/org/tron/common/zksnark/JLibrustzcash.java +++ b/testcase/src/test/java/org/tron/common/zksnark/JLibrustzcash.java @@ -1,10 +1,30 @@ package org.tron.common.zksnark; import lombok.extern.slf4j.Slf4j; +import org.tron.common.zksnark.LibrustzcashParam.BindingSigParams; +import org.tron.common.zksnark.LibrustzcashParam.CheckOutputNewParams; +import org.tron.common.zksnark.LibrustzcashParam.CheckOutputParams; +import org.tron.common.zksnark.LibrustzcashParam.CheckSpendNewParams; +import org.tron.common.zksnark.LibrustzcashParam.CheckSpendParams; +import org.tron.common.zksnark.LibrustzcashParam.ComputeCmParams; +import org.tron.common.zksnark.LibrustzcashParam.ComputeNfParams; +import org.tron.common.zksnark.LibrustzcashParam.CrhIvkParams; +import org.tron.common.zksnark.LibrustzcashParam.FinalCheckNewParams; +import org.tron.common.zksnark.LibrustzcashParam.FinalCheckParams; +import org.tron.common.zksnark.LibrustzcashParam.InitZksnarkParams; +import org.tron.common.zksnark.LibrustzcashParam.IvkToPkdParams; +import org.tron.common.zksnark.LibrustzcashParam.KaAgreeParams; +import org.tron.common.zksnark.LibrustzcashParam.KaDerivepublicParams; +import org.tron.common.zksnark.LibrustzcashParam.MerkleHashParams; +import org.tron.common.zksnark.LibrustzcashParam.OutputProofParams; +import org.tron.common.zksnark.LibrustzcashParam.SpendProofParams; +import org.tron.common.zksnark.LibrustzcashParam.SpendSigParams; +import org.tron.common.zksnark.LibrustzcashParam.Zip32XfvkAddressParams; +import org.tron.common.zksnark.LibrustzcashParam.Zip32XskDeriveParams; +import org.tron.common.zksnark.LibrustzcashParam.Zip32XskMasterParams; import stest.tron.wallet.common.client.utils.ByteUtil; import stest.tron.wallet.common.client.utils.CommonParameter; import stest.tron.wallet.common.client.utils.exception.ZksnarkException; -import org.tron.common.zksnark.LibrustzcashParam.*; @Slf4j public class JLibrustzcash { @@ -22,8 +42,11 @@ public static void librustzcashInitZksnarkParams(InitZksnarkParams params) { if (!isOpenZen()) { return; } - INSTANCE.librustzcashInitZksnarkParams(params.getSpend_path(), - params.getSpend_hash(), params.getOutput_path(), params.getOutput_hash()); + INSTANCE.librustzcashInitZksnarkParams( + params.getSpend_path(), + params.getSpend_hash(), + params.getOutput_path(), + params.getOutput_hash()); } public static void librustzcashZip32XskDerive(Zip32XskDeriveParams params) { @@ -37,8 +60,8 @@ public static boolean librustzcashZip32XfvkAddress(Zip32XfvkAddressParams params if (!isOpenZen()) { return true; } - return INSTANCE.librustzcashZip32XfvkAddress(params.getXfvk(), params.getJ(), - params.getJ_ret(), params.getAddr_ret()); + return INSTANCE.librustzcashZip32XfvkAddress( + params.getXfvk(), params.getJ(), params.getJ_ret(), params.getAddr_ret()); } public static void librustzcashCrhIvk(CrhIvkParams params) { @@ -59,14 +82,21 @@ public static boolean librustzcashComputeCm(ComputeCmParams params) { if (!isOpenZen()) { return true; } - return INSTANCE.librustzcashSaplingComputeCm(params.getD(), params.getPkD(), - params.getValue(), params.getR(), params.getCm()); + return INSTANCE.librustzcashSaplingComputeCm( + params.getD(), params.getPkD(), params.getValue(), params.getR(), params.getCm()); } public static boolean librustzcashComputeNf(ComputeNfParams params) { if (isOpenZen()) { - INSTANCE.librustzcashSaplingComputeNf(params.getD(), params.getPkD(), params.getValue(), - params.getR(), params.getAk(), params.getNk(), params.getPosition(), params.getResult()); + INSTANCE.librustzcashSaplingComputeNf( + params.getD(), + params.getPkD(), + params.getValue(), + params.getR(), + params.getAk(), + params.getNk(), + params.getPosition(), + params.getResult()); } return true; } @@ -101,9 +131,7 @@ public static byte[] librustzcashNskToNk(byte[] nsk) throws ZksnarkException { // void librustzcash_nsk_to_nk(const unsigned char *nsk, unsigned char *result); - /** - * @return r: random number, less than r_J, 32 bytes - */ + /** @return r: random number, less than r_J, 32 bytes */ public static byte[] librustzcashSaplingGenerateR(byte[] r) throws ZksnarkException { if (!isOpenZen()) { return ByteUtil.EMPTY_BYTE_ARRAY; @@ -117,8 +145,8 @@ public static boolean librustzcashSaplingKaDerivepublic(KaDerivepublicParams par if (!isOpenZen()) { return true; } - return INSTANCE.librustzcashSaplingKaDerivepublic(params.getDiversifier(), params.getEsk(), - params.getResult()); + return INSTANCE.librustzcashSaplingKaDerivepublic( + params.getDiversifier(), params.getEsk(), params.getResult()); } public static long librustzcashSaplingProvingCtxInit() { @@ -145,9 +173,18 @@ public static boolean librustzcashSaplingSpendProof(SpendProofParams params) { if (!isOpenZen()) { return true; } - return INSTANCE.librustzcashSaplingSpendProof(params.getCtx(), params.getAk(), - params.getNsk(), params.getD(), params.getR(), params.getAlpha(), params.getValue(), - params.getAnchor(), params.getVoucherPath(), params.getCv(), params.getRk(), + return INSTANCE.librustzcashSaplingSpendProof( + params.getCtx(), + params.getAk(), + params.getNsk(), + params.getD(), + params.getR(), + params.getAlpha(), + params.getValue(), + params.getAnchor(), + params.getVoucherPath(), + params.getCv(), + params.getRk(), params.getZkproof()); } @@ -155,8 +192,14 @@ public static boolean librustzcashSaplingOutputProof(OutputProofParams params) { if (!isOpenZen()) { return true; } - return INSTANCE.librustzcashSaplingOutputProof(params.getCtx(), params.getEsk(), - params.getD(), params.getPkD(), params.getR(), params.getValue(), params.getCv(), + return INSTANCE.librustzcashSaplingOutputProof( + params.getCtx(), + params.getEsk(), + params.getD(), + params.getPkD(), + params.getR(), + params.getValue(), + params.getCv(), params.getZkproof()); } @@ -164,16 +207,16 @@ public static boolean librustzcashSaplingSpendSig(SpendSigParams params) { if (!isOpenZen()) { return true; } - return INSTANCE.librustzcashSaplingSpendSig(params.getAsk(), params.getAlpha(), - params.getSigHash(), params.getResult()); + return INSTANCE.librustzcashSaplingSpendSig( + params.getAsk(), params.getAlpha(), params.getSigHash(), params.getResult()); } public static boolean librustzcashSaplingBindingSig(BindingSigParams params) { if (!isOpenZen()) { return true; } - return INSTANCE.librustzcashSaplingBindingSig(params.getCtx(), - params.getValueBalance(), params.getSighash(), params.getResult()); + return INSTANCE.librustzcashSaplingBindingSig( + params.getCtx(), params.getValueBalance(), params.getSighash(), params.getResult()); } /** @@ -209,52 +252,74 @@ public static boolean librustzcashSaplingCheckSpend(CheckSpendParams params) { if (!isOpenZen()) { return true; } - return INSTANCE.librustzcashSaplingCheckSpend(params.getCtx(), params.getCv(), - params.getAnchor(), params.getNullifier(), params.getRk(), params.getZkproof(), - params.getSpendAuthSig(), params.getSighashValue()); + return INSTANCE.librustzcashSaplingCheckSpend( + params.getCtx(), + params.getCv(), + params.getAnchor(), + params.getNullifier(), + params.getRk(), + params.getZkproof(), + params.getSpendAuthSig(), + params.getSighashValue()); } public static boolean librustzcashSaplingCheckOutput(CheckOutputParams params) { if (!isOpenZen()) { return true; } - return INSTANCE.librustzcashSaplingCheckOutput(params.getCtx(), params.getCv(), - params.getCm(), params.getEphemeralKey(), params.getZkproof()); + return INSTANCE.librustzcashSaplingCheckOutput( + params.getCtx(), + params.getCv(), + params.getCm(), + params.getEphemeralKey(), + params.getZkproof()); } public static boolean librustzcashSaplingFinalCheck(FinalCheckParams params) { if (!isOpenZen()) { return true; } - return INSTANCE.librustzcashSaplingFinalCheck(params.getCtx(), - params.getValueBalance(), params.getBindingSig(), params.getSighashValue()); + return INSTANCE.librustzcashSaplingFinalCheck( + params.getCtx(), + params.getValueBalance(), + params.getBindingSig(), + params.getSighashValue()); } public static boolean librustzcashSaplingCheckSpendNew(CheckSpendNewParams params) { if (!isOpenZen()) { return true; } - return INSTANCE.librustzcashSaplingCheckSpendNew(params.getCv(), - params.getAnchor(), params.getNullifier(), params.getRk(), params.getZkproof(), - params.getSpendAuthSig(), params.getSighashValue()); + return INSTANCE.librustzcashSaplingCheckSpendNew( + params.getCv(), + params.getAnchor(), + params.getNullifier(), + params.getRk(), + params.getZkproof(), + params.getSpendAuthSig(), + params.getSighashValue()); } public static boolean librustzcashSaplingCheckOutputNew(CheckOutputNewParams params) { if (!isOpenZen()) { return true; } - return INSTANCE.librustzcashSaplingCheckOutputNew(params.getCv(), params.getCm(), - params.getEphemeralKey(), params.getZkproof()); + return INSTANCE.librustzcashSaplingCheckOutputNew( + params.getCv(), params.getCm(), params.getEphemeralKey(), params.getZkproof()); } public static boolean librustzcashSaplingFinalCheckNew(FinalCheckNewParams params) { if (!isOpenZen()) { return true; } - return INSTANCE - .librustzcashSaplingFinalCheckNew(params.getValueBalance(), params.getBindingSig(), - params.getSighashValue(), params.getSpendCv(), params.getSpendCvLen(), - params.getOutputCv(), params.getOutputCvLen()); + return INSTANCE.librustzcashSaplingFinalCheckNew( + params.getValueBalance(), + params.getBindingSig(), + params.getSighashValue(), + params.getSpendCv(), + params.getSpendCvLen(), + params.getOutputCv(), + params.getOutputCvLen()); } public static void librustzcashSaplingVerificationCtxFree(long ctx) { @@ -275,13 +340,11 @@ public static void librustzcashMerkleHash(MerkleHashParams params) { if (!isOpenZen()) { return; } - INSTANCE.librustzcashMerkleHash(params.getDepth(), params.getA(), params.getB(), - params.getResult()); + INSTANCE.librustzcashMerkleHash( + params.getDepth(), params.getA(), params.getB(), params.getResult()); } - /** - * @param result uncommitted value, 32 bytes - */ + /** @param result uncommitted value, 32 bytes */ public static void librustzcashTreeUncommitted(byte[] result) throws ZksnarkException { if (!isOpenZen()) { return; @@ -297,5 +360,4 @@ public static boolean isOpenZen() { } return res; } - } diff --git a/testcase/src/test/java/org/tron/common/zksnark/JLibsodium.java b/testcase/src/test/java/org/tron/common/zksnark/JLibsodium.java index c6726efc..edf9e256 100644 --- a/testcase/src/test/java/org/tron/common/zksnark/JLibsodium.java +++ b/testcase/src/test/java/org/tron/common/zksnark/JLibsodium.java @@ -1,6 +1,5 @@ package org.tron.common.zksnark; - import org.tron.common.zksnark.JLibsodiumParam.Black2bSaltPersonalParams; import org.tron.common.zksnark.JLibsodiumParam.Blake2bFinalParams; import org.tron.common.zksnark.JLibsodiumParam.Blake2bInitSaltPersonalParams; @@ -19,33 +18,42 @@ public static int cryptoGenerichashBlake2bInitSaltPersonal(Blake2bInitSaltPerson if (!isOpenZen()) { return 0; } - return INSTANCE - .cryptoGenerichashBlake2BInitSaltPersonal(params.getState(), params.getKey(), - params.getKeyLen(), params.getOutLen(), params.getSalt(), params.getPersonal()); + return INSTANCE.cryptoGenerichashBlake2BInitSaltPersonal( + params.getState(), + params.getKey(), + params.getKeyLen(), + params.getOutLen(), + params.getSalt(), + params.getPersonal()); } public static int cryptoGenerichashBlake2bUpdate(Blake2bUpdateParams params) { if (!isOpenZen()) { return 0; } - return INSTANCE - .cryptoGenerichashBlake2BUpdate(params.getState(), params.getIn(), params.getInLen()); + return INSTANCE.cryptoGenerichashBlake2BUpdate( + params.getState(), params.getIn(), params.getInLen()); } public static int cryptoGenerichashBlake2bFinal(Blake2bFinalParams params) { if (!isOpenZen()) { return 0; } - return INSTANCE.cryptoGenerichashBlake2BFinal(params.getState(), - params.getOut(), params.getOutLen()); + return INSTANCE.cryptoGenerichashBlake2BFinal( + params.getState(), params.getOut(), params.getOutLen()); } public static int cryptoGenerichashBlack2bSaltPersonal(Black2bSaltPersonalParams params) { if (!isOpenZen()) { return 0; } - return INSTANCE.cryptoGenerichashBlake2BSaltPersonal(params.getOut(), params.getOutLen(), - params.getIn(), params.getInLen(), params.getKey(), params.getKeyLen(), + return INSTANCE.cryptoGenerichashBlake2BSaltPersonal( + params.getOut(), + params.getOutLen(), + params.getIn(), + params.getInLen(), + params.getKey(), + params.getKeyLen(), params.getSalt(), params.getPersonal()); } @@ -55,11 +63,16 @@ public static int cryptoAeadChacha20poly1305IetfDecrypt( if (!isOpenZen()) { return 0; } - return INSTANCE - .cryptoAeadChacha20Poly1305IetfDecrypt(params.getM(), params.getMLenP(), - params.getNSec(), - params.getC(), params.getCLen(), params.getAd(), - params.getAdLen(), params.getNPub(), params.getK()); + return INSTANCE.cryptoAeadChacha20Poly1305IetfDecrypt( + params.getM(), + params.getMLenP(), + params.getNSec(), + params.getC(), + params.getCLen(), + params.getAd(), + params.getAdLen(), + params.getNPub(), + params.getK()); } public static int cryptoAeadChacha20Poly1305IetfEncrypt( @@ -67,10 +80,16 @@ public static int cryptoAeadChacha20Poly1305IetfEncrypt( if (!isOpenZen()) { return 0; } - return INSTANCE - .cryptoAeadChacha20Poly1305IetfEncrypt(params.getC(), params.getCLenP(), params.getM(), - params.getMLen(), params.getAd(), params.getAdLen(), - params.getNSec(), params.getNPub(), params.getK()); + return INSTANCE.cryptoAeadChacha20Poly1305IetfEncrypt( + params.getC(), + params.getCLenP(), + params.getM(), + params.getMLen(), + params.getAd(), + params.getAdLen(), + params.getNSec(), + params.getNPub(), + params.getK()); } public static long initState() { @@ -88,8 +107,7 @@ public static void freeState(long state) { } private static boolean isOpenZen() { - boolean res = CommonParameter.getInstance() - .isFullNodeAllowShieldedTransactionArgs(); + boolean res = CommonParameter.getInstance().isFullNodeAllowShieldedTransactionArgs(); if (res) { INSTANCE = LibsodiumWrapper.getInstance(); } diff --git a/testcase/src/test/java/org/tron/common/zksnark/JLibsodiumParam.java b/testcase/src/test/java/org/tron/common/zksnark/JLibsodiumParam.java index 6a5211f7..bffc365e 100644 --- a/testcase/src/test/java/org/tron/common/zksnark/JLibsodiumParam.java +++ b/testcase/src/test/java/org/tron/common/zksnark/JLibsodiumParam.java @@ -34,27 +34,16 @@ public static void validParamLength(byte[] value, int length) throws ZksnarkExce public static class Blake2bInitSaltPersonalParams implements ValidParam { - @Setter - @Getter - private long state; - @Setter - @Getter - private byte[] key; - @Setter - @Getter - private int keyLen; - @Setter - @Getter - private int outLen; - @Setter - @Getter - private byte[] salt; - @Setter - @Getter - private byte[] personal; - - public Blake2bInitSaltPersonalParams(long state, byte[] key, int keyLen, int outLen, - byte[] salt, byte[] personal) throws ZksnarkException { + @Setter @Getter private long state; + @Setter @Getter private byte[] key; + @Setter @Getter private int keyLen; + @Setter @Getter private int outLen; + @Setter @Getter private byte[] salt; + @Setter @Getter private byte[] personal; + + public Blake2bInitSaltPersonalParams( + long state, byte[] key, int keyLen, int outLen, byte[] salt, byte[] personal) + throws ZksnarkException { this.state = state; this.key = key; this.keyLen = keyLen; @@ -74,15 +63,9 @@ public void valid() throws ZksnarkException { public static class Blake2bUpdateParams implements ValidParam { - @Setter - @Getter - private long state; - @Setter - @Getter - private byte[] in; - @Setter - @Getter - private long inLen; + @Setter @Getter private long state; + @Setter @Getter private byte[] in; + @Setter @Getter private long inLen; public Blake2bUpdateParams(long state, byte[] in, long inLen) throws ZksnarkException { this.state = state; @@ -103,15 +86,9 @@ public void valid() throws ZksnarkException { public static class Blake2bFinalParams implements ValidParam { - @Setter - @Getter - private long state; - @Setter - @Getter - private byte[] out; - @Setter - @Getter - private int outLen; + @Setter @Getter private long state; + @Setter @Getter private byte[] out; + @Setter @Getter private int outLen; public Blake2bFinalParams(long state, byte[] out, int outLen) throws ZksnarkException { this.state = state; @@ -132,34 +109,25 @@ public void valid() throws ZksnarkException { public static class Black2bSaltPersonalParams implements ValidParam { - @Setter - @Getter - private byte[] out; - @Setter - @Getter - private int outLen; - @Setter - @Getter - private byte[] in; - @Setter - @Getter - private long inLen; - @Setter - @Getter - private byte[] key; - @Setter - @Getter - private int keyLen; - @Setter - @Getter - private byte[] salt; - @Setter - @Getter - private byte[] personal; - - - public Black2bSaltPersonalParams(byte[] out, int outLen, byte[] in, long inLen, byte[] key, - int keyLen, byte[] salt, byte[] personal) throws ZksnarkException { + @Setter @Getter private byte[] out; + @Setter @Getter private int outLen; + @Setter @Getter private byte[] in; + @Setter @Getter private long inLen; + @Setter @Getter private byte[] key; + @Setter @Getter private int keyLen; + @Setter @Getter private byte[] salt; + @Setter @Getter private byte[] personal; + + public Black2bSaltPersonalParams( + byte[] out, + int outLen, + byte[] in, + long inLen, + byte[] key, + int keyLen, + byte[] salt, + byte[] personal) + throws ZksnarkException { this.out = out; this.outLen = outLen; this.in = in; @@ -175,8 +143,8 @@ public Black2bSaltPersonalParams(byte[] out, int outLen, byte[] in, long inLen, @Override public void valid() throws ZksnarkException { if (out.length != outLen || in.length != inLen) { - throw new ZksnarkException("out.length is not equal to outlen " - + "or in.length is not equal to inlen"); + throw new ZksnarkException( + "out.length is not equal to outlen " + "or in.length is not equal to inlen"); } validParamLength(out, 32); validParamLength(personal, 16); @@ -185,36 +153,27 @@ public void valid() throws ZksnarkException { public static class Chacha20poly1305IetfDecryptParams implements ValidParam { - @Setter - @Getter - private byte[] m; - @Setter - @Getter - private long[] mLenP; - @Setter - @Getter - private byte[] nSec; - @Setter - @Getter - private byte[] c; - @Setter - @Getter - private long cLen; - @Setter - @Getter - private byte[] ad; - @Setter - @Getter - private long adLen; - @Setter - @Getter - private byte[] nPub; - @Setter - @Getter - private byte[] k; - - public Chacha20poly1305IetfDecryptParams(byte[] m, long[] mLenP, byte[] nSec, byte[] c, - long cLen, byte[] ad, long adLen, byte[] nPub, byte[] k) throws ZksnarkException { + @Setter @Getter private byte[] m; + @Setter @Getter private long[] mLenP; + @Setter @Getter private byte[] nSec; + @Setter @Getter private byte[] c; + @Setter @Getter private long cLen; + @Setter @Getter private byte[] ad; + @Setter @Getter private long adLen; + @Setter @Getter private byte[] nPub; + @Setter @Getter private byte[] k; + + public Chacha20poly1305IetfDecryptParams( + byte[] m, + long[] mLenP, + byte[] nSec, + byte[] c, + long cLen, + byte[] ad, + long adLen, + byte[] nPub, + byte[] k) + throws ZksnarkException { this.m = m; this.mLenP = mLenP; this.nSec = nSec; @@ -237,36 +196,27 @@ public void valid() throws ZksnarkException { public static class Chacha20Poly1305IetfEncryptParams implements ValidParam { - @Setter - @Getter - private byte[] c; - @Setter - @Getter - private long[] cLenP; - @Setter - @Getter - private byte[] m; - @Setter - @Getter - private long mLen; - @Setter - @Getter - private byte[] ad; - @Setter - @Getter - private long adLen; - @Setter - @Getter - private byte[] nSec; - @Setter - @Getter - private byte[] nPub; - @Setter - @Getter - private byte[] k; - - public Chacha20Poly1305IetfEncryptParams(byte[] c, long[] cLenP, byte[] m, long mLen, - byte[] ad, long adLen, byte[] nSec, byte[] nPub, byte[] k) throws ZksnarkException { + @Setter @Getter private byte[] c; + @Setter @Getter private long[] cLenP; + @Setter @Getter private byte[] m; + @Setter @Getter private long mLen; + @Setter @Getter private byte[] ad; + @Setter @Getter private long adLen; + @Setter @Getter private byte[] nSec; + @Setter @Getter private byte[] nPub; + @Setter @Getter private byte[] k; + + public Chacha20Poly1305IetfEncryptParams( + byte[] c, + long[] cLenP, + byte[] m, + long mLen, + byte[] ad, + long adLen, + byte[] nSec, + byte[] nPub, + byte[] k) + throws ZksnarkException { this.c = c; this.cLenP = cLenP; this.m = m; diff --git a/testcase/src/test/java/org/tron/common/zksnark/LibrustzcashParam.java b/testcase/src/test/java/org/tron/common/zksnark/LibrustzcashParam.java index d6209ca0..b11bb357 100644 --- a/testcase/src/test/java/org/tron/common/zksnark/LibrustzcashParam.java +++ b/testcase/src/test/java/org/tron/common/zksnark/LibrustzcashParam.java @@ -2,7 +2,7 @@ import lombok.Getter; import lombok.Setter; -import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ByteUtil; import stest.tron.wallet.common.client.utils.exception.ZksnarkException; @@ -68,21 +68,14 @@ interface ValidParam { public static class InitZksnarkParams implements ValidParam { - @Setter - @Getter - private String spend_path; - @Setter - @Getter - private String spend_hash; - @Setter - @Getter - private String output_path; - @Setter - @Getter - private String output_hash; - - public InitZksnarkParams(String spend_path, String spend_hash, String output_path, - String output_hash) throws ZksnarkException { + @Setter @Getter private String spend_path; + @Setter @Getter private String spend_hash; + @Setter @Getter private String output_path; + @Setter @Getter private String output_hash; + + public InitZksnarkParams( + String spend_path, String spend_hash, String output_path, String output_hash) + throws ZksnarkException { this.spend_path = spend_path; this.spend_hash = spend_hash; this.output_path = output_path; @@ -91,22 +84,14 @@ public InitZksnarkParams(String spend_path, String spend_hash, String output_pat } @Override - public void valid() throws ZksnarkException { - - } + public void valid() throws ZksnarkException {} } public static class Zip32XskMasterParams implements ValidParam { - @Setter - @Getter - private byte[] data; - @Setter - @Getter - private int size; - @Setter - @Getter - private byte[] m_bytes; + @Setter @Getter private byte[] data; + @Setter @Getter private int size; + @Setter @Getter private byte[] m_bytes; public Zip32XskMasterParams(byte[] data, int size, byte[] m_bytes) throws ZksnarkException { this.data = data; @@ -128,25 +113,15 @@ public Zip32XskDeriveParams(byte[] data, int size, byte[] m_bytes) throws Zksnar } @Override - public void valid() throws ZksnarkException { - - } + public void valid() throws ZksnarkException {} } public static class Zip32XfvkAddressParams implements ValidParam { - @Setter - @Getter - private byte[] xfvk; - @Setter - @Getter - private byte[] j; - @Setter - @Getter - private byte[] j_ret; - @Setter - @Getter - private byte[] addr_ret; + @Setter @Getter private byte[] xfvk; + @Setter @Getter private byte[] j; + @Setter @Getter private byte[] j_ret; + @Setter @Getter private byte[] addr_ret; public Zip32XfvkAddressParams(byte[] xfvk, byte[] j, byte[] j_ret, byte[] addr_ret) throws ZksnarkException { @@ -158,9 +133,7 @@ public Zip32XfvkAddressParams(byte[] xfvk, byte[] j, byte[] j_ret, byte[] addr_r } @Override - public void valid() throws ZksnarkException { - - } + public void valid() throws ZksnarkException {} } /** @@ -169,15 +142,9 @@ public void valid() throws ZksnarkException { */ public static class CrhIvkParams implements ValidParam { - @Setter - @Getter - private byte[] ak; - @Setter - @Getter - private byte[] nk; - @Setter - @Getter - private byte[] ivk; + @Setter @Getter private byte[] ak; + @Setter @Getter private byte[] nk; + @Setter @Getter private byte[] ivk; public CrhIvkParams(byte[] ak, byte[] nk, byte[] ivk) throws ZksnarkException { this.ak = ak; @@ -194,20 +161,12 @@ public void valid() throws ZksnarkException { } } - /** - * KaAgree(sk,p)=[h_J*sk]p p: point, 32 bytes sk: 32 bytes result: 32 bytes - */ + /** KaAgree(sk,p)=[h_J*sk]p p: point, 32 bytes sk: 32 bytes result: 32 bytes */ public static class KaAgreeParams implements ValidParam { - @Setter - @Getter - private byte[] p; - @Setter - @Getter - private byte[] sk; - @Setter - @Getter - private byte[] result; + @Setter @Getter private byte[] p; + @Setter @Getter private byte[] sk; + @Setter @Getter private byte[] result; public KaAgreeParams(byte[] p, byte[] sk, byte[] result) throws ZksnarkException { this.p = p; @@ -225,26 +184,16 @@ public void valid() throws ZksnarkException { } /** - * Compute note commitment d: diversifier, 11 bytes pkD: 32 bytes r: rcm, 32 bytes cm: note + * Compute note commitment d: diversifier, 11 bytes pkD: 32 bytes r: rcm, 32 bytes cm: note * commitment, 32 bytes, value >= 0 */ public static class ComputeCmParams implements ValidParam { - @Setter - @Getter - private byte[] d; - @Setter - @Getter - private byte[] pkD; - @Setter - @Getter - private long value; - @Setter - @Getter - private byte[] r; - @Setter - @Getter - private byte[] cm; + @Setter @Getter private byte[] d; + @Setter @Getter private byte[] pkD; + @Setter @Getter private long value; + @Setter @Getter private byte[] r; + @Setter @Getter private byte[] cm; public ComputeCmParams(byte[] d, byte[] pkD, long value, byte[] r, byte[] cm) throws ZksnarkException { @@ -267,39 +216,31 @@ public void valid() throws ZksnarkException { } /** - * compute nullifier d: diversifier, 11 bytes pkD, 32 bytes r: rcm, 32 bytes ak: + * compute nullifier d: diversifier, 11 bytes pkD, 32 bytes r: rcm, 32 bytes ak: * spendAuthSig.PulicKey, 32 bytes nk: to genarate nullifier, 32 bytes result: nullifier, 32 * bytes, value >= 0, position >= 0 */ public static class ComputeNfParams implements ValidParam { - @Setter - @Getter - private byte[] d; - @Setter - @Getter - private byte[] pkD; - @Setter - @Getter - private long value; - @Setter - @Getter - private byte[] r; - @Setter - @Getter - private byte[] ak; - @Setter - @Getter - private byte[] nk; - @Setter - @Getter - private long position; - @Setter - @Getter - private byte[] result; - - public ComputeNfParams(byte[] d, byte[] pkD, long value, byte[] r, byte[] ak, byte[] nk, - long position, byte[] result) throws ZksnarkException { + @Setter @Getter private byte[] d; + @Setter @Getter private byte[] pkD; + @Setter @Getter private long value; + @Setter @Getter private byte[] r; + @Setter @Getter private byte[] ak; + @Setter @Getter private byte[] nk; + @Setter @Getter private long position; + @Setter @Getter private byte[] result; + + public ComputeNfParams( + byte[] d, + byte[] pkD, + long value, + byte[] r, + byte[] ak, + byte[] nk, + long position, + byte[] result) + throws ZksnarkException { this.d = d; this.pkD = pkD; this.value = value; @@ -324,20 +265,12 @@ public void valid() throws ZksnarkException { } } - /** - * diversifier: d, 11 bytes esk: 32 bytes result: return 32 bytes - */ + /** diversifier: d, 11 bytes esk: 32 bytes result: return 32 bytes */ public static class KaDerivepublicParams implements ValidParam { - @Setter - @Getter - private byte[] diversifier; - @Setter - @Getter - private byte[] esk; - @Setter - @Getter - private byte[] result; + @Setter @Getter private byte[] diversifier; + @Setter @Getter private byte[] esk; + @Setter @Getter private byte[] result; public KaDerivepublicParams(byte[] diversifier, byte[] esk, byte[] result) throws ZksnarkException { @@ -363,46 +296,33 @@ public void valid() throws ZksnarkException { */ public static class SpendProofParams implements ValidParam { - @Setter - @Getter - private long ctx; - @Setter - @Getter - private byte[] ak; - @Setter - @Getter - private byte[] nsk; - @Setter - @Getter - private byte[] d; - @Setter - @Getter - private byte[] r; - @Setter - @Getter - private byte[] alpha; - @Setter - @Getter - private long value; - @Setter - @Getter - private byte[] anchor; - @Setter - @Getter - private byte[] voucherPath; - @Setter - @Getter - private byte[] cv; - @Setter - @Getter - private byte[] rk; - @Setter - @Getter - private byte[] zkproof; - - public SpendProofParams(long ctx, byte[] ak, byte[] nsk, byte[] d, byte[] r, - byte[] alpha, long value, byte[] anchor, byte[] voucherPath, byte[] cv, byte[] rk, - byte[] zkproof) throws ZksnarkException { + @Setter @Getter private long ctx; + @Setter @Getter private byte[] ak; + @Setter @Getter private byte[] nsk; + @Setter @Getter private byte[] d; + @Setter @Getter private byte[] r; + @Setter @Getter private byte[] alpha; + @Setter @Getter private long value; + @Setter @Getter private byte[] anchor; + @Setter @Getter private byte[] voucherPath; + @Setter @Getter private byte[] cv; + @Setter @Getter private byte[] rk; + @Setter @Getter private byte[] zkproof; + + public SpendProofParams( + long ctx, + byte[] ak, + byte[] nsk, + byte[] d, + byte[] r, + byte[] alpha, + long value, + byte[] anchor, + byte[] voucherPath, + byte[] cv, + byte[] rk, + byte[] zkproof) + throws ZksnarkException { this.ctx = ctx; this.ak = ak; this.nsk = nsk; @@ -418,8 +338,7 @@ public SpendProofParams(long ctx, byte[] ak, byte[] nsk, byte[] d, byte[] r, valid(); } - public static SpendProofParams decode(long ctx, byte[] data) - throws ZksnarkException { + public static SpendProofParams decode(long ctx, byte[] data) throws ZksnarkException { byte[] ak = new byte[32]; byte[] nsk = new byte[32]; byte[] d = new byte[11]; @@ -444,8 +363,19 @@ public static SpendProofParams decode(long ctx, byte[] data) System.arraycopy(data, 211 + 1065, rk, 0, 192); System.arraycopy(data, 243 + 1065, zkproof, 0, 64); - return new SpendProofParams(ctx, ak, nsk, d, r, alpha, ByteArray.toLong(valueByte), - anchor, voucherPath, cv, rk, zkproof); + return new SpendProofParams( + ctx, + ak, + nsk, + d, + r, + alpha, + ByteArray.toLong(valueByte), + anchor, + voucherPath, + cv, + rk, + zkproof); } @Override @@ -488,33 +418,18 @@ public byte[] encode() { */ public static class OutputProofParams implements ValidParam { - @Setter - @Getter - private long ctx; - @Setter - @Getter - private byte[] esk; - @Setter - @Getter - private byte[] d; - @Setter - @Getter - private byte[] pkD; - @Setter - @Getter - private byte[] r; - @Setter - @Getter - private long value; - @Setter - @Getter - private byte[] cv; - @Setter - @Getter - private byte[] zkproof; - - public OutputProofParams(long ctx, byte[] esk, byte[] d, byte[] pkD, byte[] r, - long value, byte[] cv, byte[] zkproof) throws ZksnarkException { + @Setter @Getter private long ctx; + @Setter @Getter private byte[] esk; + @Setter @Getter private byte[] d; + @Setter @Getter private byte[] pkD; + @Setter @Getter private byte[] r; + @Setter @Getter private long value; + @Setter @Getter private byte[] cv; + @Setter @Getter private byte[] zkproof; + + public OutputProofParams( + long ctx, byte[] esk, byte[] d, byte[] pkD, byte[] r, long value, byte[] cv, byte[] zkproof) + throws ZksnarkException { this.ctx = ctx; this.esk = esk; this.d = d; @@ -544,18 +459,10 @@ public void valid() throws ZksnarkException { */ public static class SpendSigParams implements ValidParam { - @Setter - @Getter - private byte[] ask; - @Setter - @Getter - private byte[] alpha; - @Setter - @Getter - private byte[] sigHash; - @Setter - @Getter - private byte[] result; + @Setter @Getter private byte[] ask; + @Setter @Getter private byte[] alpha; + @Setter @Getter private byte[] sigHash; + @Setter @Getter private byte[] result; public SpendSigParams(byte[] ask, byte[] alpha, byte[] sigHash, byte[] result) throws ZksnarkException { @@ -581,18 +488,10 @@ public void valid() throws ZksnarkException { */ public static class BindingSigParams implements ValidParam { - @Setter - @Getter - private long ctx; - @Setter - @Getter - private long valueBalance; - @Setter - @Getter - private byte[] sighash; - @Setter - @Getter - private byte[] result; + @Setter @Getter private long ctx; + @Setter @Getter private long valueBalance; + @Setter @Getter private byte[] sighash; + @Setter @Getter private byte[] result; public BindingSigParams(long ctx, long valueBalance, byte[] sighash, byte[] result) throws ZksnarkException { @@ -617,33 +516,24 @@ public void valid() throws ZksnarkException { */ public static class CheckSpendParams implements ValidParam { - @Setter - @Getter - private long ctx; - @Setter - @Getter - private byte[] cv; - @Setter - @Getter - private byte[] anchor; - @Setter - @Getter - private byte[] nullifier; - @Setter - @Getter - private byte[] rk; - @Setter - @Getter - private byte[] zkproof; - @Setter - @Getter - private byte[] spendAuthSig; - @Setter - @Getter - private byte[] sighashValue; - - public CheckSpendParams(long ctx, byte[] cv, byte[] anchor, byte[] nullifier, - byte[] rk, byte[] zkproof, byte[] spendAuthSig, byte[] sighashValue) + @Setter @Getter private long ctx; + @Setter @Getter private byte[] cv; + @Setter @Getter private byte[] anchor; + @Setter @Getter private byte[] nullifier; + @Setter @Getter private byte[] rk; + @Setter @Getter private byte[] zkproof; + @Setter @Getter private byte[] spendAuthSig; + @Setter @Getter private byte[] sighashValue; + + public CheckSpendParams( + long ctx, + byte[] cv, + byte[] anchor, + byte[] nullifier, + byte[] rk, + byte[] zkproof, + byte[] spendAuthSig, + byte[] sighashValue) throws ZksnarkException { this.ctx = ctx; this.cv = cv; @@ -672,8 +562,8 @@ public static CheckSpendParams decode(long ctx, byte[] data, byte[] sigHashValue System.arraycopy(data, 128, zkproof, 0, 192); System.arraycopy(data, 320, spendAuthSig, 0, 64); - return new CheckSpendParams(ctx, cv, anchor, nullifier, rk, zkproof, spendAuthSig, - sigHashValue); + return new CheckSpendParams( + ctx, cv, anchor, nullifier, rk, zkproof, spendAuthSig, sigHashValue); } @Override @@ -694,24 +584,14 @@ public void valid() throws ZksnarkException { */ public static class CheckOutputParams implements ValidParam { - @Setter - @Getter - private long ctx; - @Setter - @Getter - private byte[] cv; - @Setter - @Getter - private byte[] cm; - @Setter - @Getter - private byte[] ephemeralKey; - @Setter - @Getter - private byte[] zkproof; - - public CheckOutputParams(long ctx, byte[] cv, byte[] cm, byte[] ephemeralKey, - byte[] zkproof) throws ZksnarkException { + @Setter @Getter private long ctx; + @Setter @Getter private byte[] cv; + @Setter @Getter private byte[] cm; + @Setter @Getter private byte[] ephemeralKey; + @Setter @Getter private byte[] zkproof; + + public CheckOutputParams(long ctx, byte[] cv, byte[] cm, byte[] ephemeralKey, byte[] zkproof) + throws ZksnarkException { this.ctx = ctx; this.cv = cv; this.cm = cm; @@ -720,8 +600,7 @@ public CheckOutputParams(long ctx, byte[] cv, byte[] cm, byte[] ephemeralKey, valid(); } - public static CheckOutputParams decode(long ctx, byte[] data) - throws ZksnarkException { + public static CheckOutputParams decode(long ctx, byte[] data) throws ZksnarkException { byte[] cv = new byte[32]; byte[] cm = new byte[32]; byte[] ephemeralKey = new byte[32]; @@ -735,8 +614,7 @@ public static CheckOutputParams decode(long ctx, byte[] data) return new CheckOutputParams(ctx, cv, cm, ephemeralKey, zkproof); } - public static CheckOutputParams decodeZ(long ctx, byte[] data) - throws ZksnarkException { + public static CheckOutputParams decodeZ(long ctx, byte[] data) throws ZksnarkException { byte[] cv = new byte[32]; byte[] cm = new byte[32]; byte[] ephemeralKey = new byte[32]; @@ -768,26 +646,16 @@ public void valid() throws ZksnarkException { } } - /** - * bindingSig: 64 bytes sighashValue: sha256 of transaction,32 bytes - */ + /** bindingSig: 64 bytes sighashValue: sha256 of transaction,32 bytes */ public static class FinalCheckParams implements ValidParam { - @Setter - @Getter - private long ctx; - @Setter - @Getter - private long valueBalance; - @Setter - @Getter - private byte[] bindingSig; - @Setter - @Getter - private byte[] sighashValue; - - public FinalCheckParams(long ctx, long valueBalance, byte[] bindingSig, - byte[] sighashValue) throws ZksnarkException { + @Setter @Getter private long ctx; + @Setter @Getter private long valueBalance; + @Setter @Getter private byte[] bindingSig; + @Setter @Getter private byte[] sighashValue; + + public FinalCheckParams(long ctx, long valueBalance, byte[] bindingSig, byte[] sighashValue) + throws ZksnarkException { this.ctx = ctx; this.valueBalance = valueBalance; this.bindingSig = bindingSig; @@ -809,30 +677,22 @@ public void valid() throws ZksnarkException { */ public static class CheckSpendNewParams implements ValidParam { - @Setter - @Getter - private byte[] cv; - @Setter - @Getter - private byte[] anchor; - @Setter - @Getter - private byte[] nullifier; - @Setter - @Getter - private byte[] rk; - @Setter - @Getter - private byte[] zkproof; - @Setter - @Getter - private byte[] spendAuthSig; - @Setter - @Getter - private byte[] sighashValue; - - public CheckSpendNewParams(byte[] cv, byte[] anchor, byte[] nullifier, - byte[] rk, byte[] zkproof, byte[] spendAuthSig, byte[] sighashValue) + @Setter @Getter private byte[] cv; + @Setter @Getter private byte[] anchor; + @Setter @Getter private byte[] nullifier; + @Setter @Getter private byte[] rk; + @Setter @Getter private byte[] zkproof; + @Setter @Getter private byte[] spendAuthSig; + @Setter @Getter private byte[] sighashValue; + + public CheckSpendNewParams( + byte[] cv, + byte[] anchor, + byte[] nullifier, + byte[] rk, + byte[] zkproof, + byte[] spendAuthSig, + byte[] sighashValue) throws ZksnarkException { this.cv = cv; this.anchor = anchor; @@ -862,18 +722,10 @@ public void valid() throws ZksnarkException { */ public static class CheckOutputNewParams implements ValidParam { - @Setter - @Getter - private byte[] cv; - @Setter - @Getter - private byte[] cm; - @Setter - @Getter - private byte[] ephemeralKey; - @Setter - @Getter - private byte[] zkproof; + @Setter @Getter private byte[] cv; + @Setter @Getter private byte[] cm; + @Setter @Getter private byte[] ephemeralKey; + @Setter @Getter private byte[] zkproof; public CheckOutputNewParams(byte[] cv, byte[] cm, byte[] ephemeralKey, byte[] zkproof) throws ZksnarkException { @@ -893,35 +745,26 @@ public void valid() throws ZksnarkException { } } - /** - * bindingSig: 64 bytes sighashValue: sha256 of transaction,32 bytes, - */ + /** bindingSig: 64 bytes sighashValue: sha256 of transaction,32 bytes, */ public static class FinalCheckNewParams implements ValidParam { - @Setter - @Getter - private long valueBalance; - @Setter - @Getter - private byte[] bindingSig; - @Setter - @Getter - private byte[] sighashValue; - @Setter - @Getter - private byte[] spendCv; - @Setter - @Getter - private int spendCvLen; - @Setter - @Getter - private byte[] outputCv; - @Setter - @Getter - private int outputCvLen; - - public FinalCheckNewParams(long valueBalance, byte[] bindingSig, byte[] sighashValue, - byte[] spendCv, int spendCvLen, byte[] outputCv, int outputCvLen) throws ZksnarkException { + @Setter @Getter private long valueBalance; + @Setter @Getter private byte[] bindingSig; + @Setter @Getter private byte[] sighashValue; + @Setter @Getter private byte[] spendCv; + @Setter @Getter private int spendCvLen; + @Setter @Getter private byte[] outputCv; + @Setter @Getter private int outputCvLen; + + public FinalCheckNewParams( + long valueBalance, + byte[] bindingSig, + byte[] sighashValue, + byte[] spendCv, + int spendCvLen, + byte[] outputCv, + int outputCvLen) + throws ZksnarkException { this.valueBalance = valueBalance; this.bindingSig = bindingSig; this.sighashValue = sighashValue; @@ -949,20 +792,13 @@ public void valid() throws ZksnarkException { } /** - * ivk: incoming viewing key, 32 bytes, should be 251bits , not checked; d: 11 bytes pkD: 32 - * bytes + * ivk: incoming viewing key, 32 bytes, should be 251bits , not checked; d: 11 bytes pkD: 32 bytes */ public static class IvkToPkdParams implements ValidParam { - @Setter - @Getter - private byte[] ivk; - @Setter - @Getter - private byte[] d; - @Setter - @Getter - private byte[] pkD; + @Setter @Getter private byte[] ivk; + @Setter @Getter private byte[] d; + @Setter @Getter private byte[] pkD; public IvkToPkdParams(byte[] ivk, byte[] d, byte[] pkD) throws ZksnarkException { this.ivk = ivk; @@ -982,23 +818,13 @@ public void valid() throws ZksnarkException { } } - /** - * 0 <= depth < 63 a: 32 bytes b: 32 bytes result: 32 bytes - */ + /** 0 <= depth < 63 a: 32 bytes b: 32 bytes result: 32 bytes */ public static class MerkleHashParams implements ValidParam { - @Setter - @Getter - private int depth; - @Setter - @Getter - private byte[] a; - @Setter - @Getter - private byte[] b; - @Setter - @Getter - private byte[] result; + @Setter @Getter private int depth; + @Setter @Getter private byte[] a; + @Setter @Getter private byte[] b; + @Setter @Getter private byte[] result; public MerkleHashParams(int depth, byte[] a, byte[] b, byte[] result) throws ZksnarkException { this.depth = depth; diff --git a/testcase/src/test/java/org/tron/common/zksnark/MerklePath.java b/testcase/src/test/java/org/tron/common/zksnark/MerklePath.java index 2462d3ba..06ec0574 100644 --- a/testcase/src/test/java/org/tron/common/zksnark/MerklePath.java +++ b/testcase/src/test/java/org/tron/common/zksnark/MerklePath.java @@ -9,11 +9,9 @@ public class MerklePath { - @Getter - private List> authenticationPath; + @Getter private List> authenticationPath; - @Getter - private List index; + @Getter private List index; public MerklePath(List> authenticationPath, List index) { this.authenticationPath = authenticationPath; @@ -81,8 +79,7 @@ public byte[] encode() throws ZksnarkException { for (int i = 0; i < authenticationPath.size(); i++) { pathByteList.add(Lists.newArrayList()); for (int p = 0; p < authenticationPath.get(i).size(); p++) { - byte bByte = (byte) (authenticationPath.get(i).get(p) ? 1 - : 0); + byte bByte = (byte) (authenticationPath.get(i).get(p) ? 1 : 0); int i1; if (pathByteList.get(i).size() > (p / 8)) { i1 = pathByteList.get(i).get(p / 8) | bByte << (7 - (p % 8)); @@ -91,7 +88,6 @@ public byte[] encode() throws ZksnarkException { i1 = bByte << (7 - (p % 8)); pathByteList.get(i).add((byte) i1); } - } } indexLong = convertVectorToLong(index); @@ -100,8 +96,7 @@ public byte[] encode() throws ZksnarkException { byte[] pathByteArray = listList2Bytes(pathByteList); byte[] result = new byte[pathByteArray.length + 8]; System.arraycopy(pathByteArray, 0, result, 0, pathByteArray.length); - System.arraycopy(indexBytes, 0, result, - pathByteArray.length, 8); + System.arraycopy(indexBytes, 0, result, pathByteArray.length, 8); return result; } } diff --git a/testcase/src/test/java/org/tron/common/zksnark/ZksnarkUtils.java b/testcase/src/test/java/org/tron/common/zksnark/ZksnarkUtils.java index 8d82dee3..15fe143f 100644 --- a/testcase/src/test/java/org/tron/common/zksnark/ZksnarkUtils.java +++ b/testcase/src/test/java/org/tron/common/zksnark/ZksnarkUtils.java @@ -10,5 +10,4 @@ public static void sort(byte[] bytes) { bytes[bytes.length - i - 1] = b; } } - } diff --git a/testcase/src/test/java/stest/tron/wallet/account/BrokerageTest001.java b/testcase/src/test/java/stest/tron/wallet/account/BrokerageTest001.java index cb4333c5..fc50b340 100644 --- a/testcase/src/test/java/stest/tron/wallet/account/BrokerageTest001.java +++ b/testcase/src/test/java/stest/tron/wallet/account/BrokerageTest001.java @@ -5,7 +5,6 @@ import io.grpc.ManagedChannelBuilder; import lombok.extern.slf4j.Slf4j; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.BytesMessage; @@ -16,7 +15,6 @@ import org.tron.protos.contract.StorageContract.UpdateBrokerageContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.PublicMethod; - import stest.tron.wallet.common.client.utils.TronBaseTest; @Slf4j @@ -24,23 +22,19 @@ public class BrokerageTest001 extends TronBaseTest { private ManagedChannel channelSoliInFull = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSoliInFull = null; - private String soliInFullnode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1); + private String soliInFullnode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); private String dev001Key = foundationKey; private byte[] dev001Address = foundationAddress; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); initPbftChannel(); - channelSoliInFull = ManagedChannelBuilder.forTarget(soliInFullnode) - .usePlaintext() - .build(); + channelSoliInFull = ManagedChannelBuilder.forTarget(soliInFullnode).usePlaintext().build(); blockingStubSoliInFull = WalletSolidityGrpc.newBlockingStub(channelSoliInFull); PublicMethod.printAddress(dev001Key); @@ -63,9 +57,8 @@ public void updateBrokerageTest001() { @Test public void getBrokerageTest001() { - BytesMessage bytesMessage = BytesMessage.newBuilder().setValue(ByteString - .copyFrom(witnessAddress)) - .build(); + BytesMessage bytesMessage = + BytesMessage.newBuilder().setValue(ByteString.copyFrom(witnessAddress)).build(); Assert.assertEquals(20, blockingStubFull.getBrokerageInfo(bytesMessage).getNum()); @@ -77,9 +70,8 @@ public void getBrokerageTest001() { @Test public void getRewardTest002() { - BytesMessage bytesMessage = BytesMessage.newBuilder().setValue(ByteString - .copyFrom(witnessAddress)) - .build(); + BytesMessage bytesMessage = + BytesMessage.newBuilder().setValue(ByteString.copyFrom(witnessAddress)).build(); Assert.assertTrue(blockingStubFull.getRewardInfo(bytesMessage) != null); // getRewardInfo from solidity node @@ -87,19 +79,20 @@ public void getRewardTest002() { Assert.assertTrue(blockingStubPbft.getRewardInfo(bytesMessage) != null); Assert.assertTrue(blockingStubSoliInFull.getRewardInfo(bytesMessage) != null); } - boolean updateBrokerage(byte[] owner, int brokerage, - WalletGrpc.WalletBlockingStub blockingStubFull) { + + boolean updateBrokerage( + byte[] owner, int brokerage, WalletGrpc.WalletBlockingStub blockingStubFull) { UpdateBrokerageContract.Builder updateBrokerageContract = UpdateBrokerageContract.newBuilder(); updateBrokerageContract.setOwnerAddress(ByteString.copyFrom(owner)).setBrokerage(brokerage); - TransactionExtention transactionExtention = blockingStubFull - .updateBrokerage(updateBrokerageContract.build()); + TransactionExtention transactionExtention = + blockingStubFull.updateBrokerage(updateBrokerageContract.build()); Protocol.Transaction transaction = transactionExtention.getTransaction(); if (transactionExtention == null || !transactionExtention.getResult().getResult()) { if (transactionExtention != null) { System.out.println("Code = " + transactionExtention.getResult().getCode()); - System.out - .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + System.out.println( + "Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); } return false; } @@ -110,7 +103,5 @@ boolean updateBrokerage(byte[] owner, int brokerage, return true; } - public void getBrokerage() { - - } -} \ No newline at end of file + public void getBrokerage() {} +} diff --git a/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount001.java b/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount001.java index 9066a114..139a3577 100644 --- a/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount001.java +++ b/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount001.java @@ -7,7 +7,6 @@ import org.apache.commons.lang3.StringUtils; import org.bouncycastle.util.encoders.Hex; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.NumberMessage; @@ -17,40 +16,40 @@ import org.tron.protos.Protocol.Block; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.PublicMethod; - import stest.tron.wallet.common.client.utils.TronBaseTest; + @Slf4j public class WalletTestAccount001 extends TronBaseTest { - private static final long now = System.currentTimeMillis(); //just test key + private static final long now = System.currentTimeMillis(); // just test key private final String invalidTestKey = - "592BB6C9BB255409A6A45EFD18E9A74FECDDCCE93A40D96B70FBE334E6361E36"; private ManagedChannel channelSolidity = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; /** - * constructor. - */ + "592BB6C9BB255409A6A45EFD18E9A74FECDDCCE93A40D96B70FBE334E6361E36"; + + /** constructor. */ + @BeforeClass - public void beforeClass() { } + public void beforeClass() {} @Test public void testqueryaccountfromfullnode() { initSolidityChannel(); - //Query success, get the right balance,bandwidth and the account name. + // Query success, get the right balance,bandwidth and the account name. Account queryResult = queryAccount(foundationKey2, blockingStubFull); /* Account queryResult = PublicMethod.queryAccountByAddress(fromAddress,blockingStubFull); logger.info(ByteArray.toStr(queryResult.getAccountName().toByteArray())); logger.info(Long.toString(queryResult.getBalance())); logger.info(ByteArray.toStr(queryResult.getAddress().toByteArray()));*/ Assert.assertTrue(queryResult.getBalance() > 0); - //Assert.assertTrue(queryResult.getBandwidth() >= 0); + // Assert.assertTrue(queryResult.getBandwidth() >= 0); Assert.assertTrue(queryResult.getAccountName().toByteArray().length > 0); Assert.assertFalse(queryResult.getAddress().isEmpty()); - //Query failed + // Query failed Account invalidQueryResult = queryAccount(invalidTestKey, blockingStubFull); Assert.assertTrue(invalidQueryResult.getAccountName().isEmpty()); Assert.assertTrue(invalidQueryResult.getAddress().isEmpty()); - //Improve coverage. + // Improve coverage. queryResult.hashCode(); queryResult.getSerializedSize(); queryResult.equals(queryResult); @@ -59,25 +58,21 @@ public void testqueryaccountfromfullnode() { @Test public void testqueryaccountfromsoliditynode() { - //Query success, get the right balance,bandwidth and the account name. + // Query success, get the right balance,bandwidth and the account name. Account queryResult = solidityqueryAccount(foundationKey2, blockingStubSolidity); Assert.assertTrue(queryResult.getBalance() > 0); - //Assert.assertTrue(queryResult.getBandwidth() >= 0); + // Assert.assertTrue(queryResult.getBandwidth() >= 0); Assert.assertTrue(queryResult.getAccountName().toByteArray().length > 0); Assert.assertFalse(queryResult.getAddress().isEmpty()); - //Query failed + // Query failed Account invalidQueryResult = solidityqueryAccount(invalidTestKey, blockingStubSolidity); Assert.assertTrue(invalidQueryResult.getAccountName().isEmpty()); Assert.assertTrue(invalidQueryResult.getAddress().isEmpty()); - } - /** - * constructor. - */ + /** constructor. */ - public Account queryAccount(String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull) { + public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -87,7 +82,7 @@ public Account queryAccount(String priKey, } ECKey ecKey = temKey; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; @@ -98,19 +93,16 @@ public Account queryAccount(String priKey, } logger.info(Integer.toString(ecKey.getAddress().length)); - //PublicMethod.AddPreFix(); + // PublicMethod.AddPreFix(); logger.info(Integer.toString(ecKey.getAddress().length)); System.out.println("address ====== " + ByteArray.toHexString(ecKey.getAddress())); return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); - //return grpcQueryAccount(address,blockingStubFull); + // return grpcQueryAccount(address,blockingStubFull); } - /** - * constructor. - */ - - public Account solidityqueryAccount(String priKey, - WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity) { + /** constructor. */ + public Account solidityqueryAccount( + String priKey, WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity) { ECKey temKey = null; try { @@ -121,7 +113,7 @@ public Account solidityqueryAccount(String priKey, } ECKey ecKey = temKey; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; @@ -130,15 +122,12 @@ public Account solidityqueryAccount(String priKey, byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } - //byte[] address = PublicMethod.AddPreFix(ecKey.getAddress()); + // byte[] address = PublicMethod.AddPreFix(ecKey.getAddress()); return grpcQueryAccountSolidity(ecKey.getAddress(), blockingStubSolidity); - //return grpcQueryAccountSolidity(address,blockingStubSolidity); + // return grpcQueryAccountSolidity(address,blockingStubSolidity); } - /** - * constructor. - */ - + /** constructor. */ public String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); @@ -148,39 +137,27 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ - - public Account grpcQueryAccount(byte[] address, - WalletGrpc.WalletBlockingStub blockingStubFull) { - //address = PublicMethod.AddPreFix(address); + /** constructor. */ + public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { + // address = PublicMethod.AddPreFix(address); ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ - - public Account grpcQueryAccountSolidity(byte[] address, - WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity) { - //address = PublicMethod.AddPreFix(address); + /** constructor. */ + public Account grpcQueryAccountSolidity( + byte[] address, WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity) { + // address = PublicMethod.AddPreFix(address); ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubSolidity.getAccount(request); } - /** - * constructor. - */ - + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } } - diff --git a/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount003.java b/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount003.java index e4da4fc0..dc1192e5 100644 --- a/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount003.java +++ b/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount003.java @@ -25,9 +25,10 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - //import stest.tron.wallet.common.client.AccountComparator; +import stest.tron.wallet.common.client.utils.Utils; + +// import stest.tron.wallet.common.client.AccountComparator; @Slf4j public class WalletTestAccount003 extends TronBaseTest { @@ -35,35 +36,34 @@ public class WalletTestAccount003 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final String name = "testAssetIssue_" + Long.toString(now); private static final long TotalSupply = now; - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); - String mostLongNamePlusOneChar = "1abcdeabcdefabcdefg1abcdefg10o0og1abcdefg10o0oabcd" - + "efabcdefg1abcdefg10o0og1abcdefg10o0oabcdefabcdefg1abcdefg10o0og1abcdefg10o0oab" - + "cdefabcdefg1abcdefg10o0og1abcdefg10o0ofabcdefg1abcdefg10o0og1abcdefg10o0o"; - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - //get account + String mostLongNamePlusOneChar = + "1abcdeabcdefabcdefg1abcdefg10o0og1abcdefg10o0oabcd" + + "efabcdefg1abcdefg10o0og1abcdefg10o0oabcdefabcdefg1abcdefg10o0og1abcdefg10o0oab" + + "cdefabcdefg1abcdefg10o0og1abcdefg10o0ofabcdefg1abcdefg10o0og1abcdefg10o0o"; + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + // get account ECKey ecKey = new ECKey(Utils.getRandom()); byte[] lowBalAddress = ecKey.getAddress(); String lowBalTest = ByteArray.toHexString(ecKey.getPrivKeyBytes()); - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] noBandwitchAddress = ecKey1.getAddress(); String noBandwitch = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - /** - * constructor. - */ + /** constructor. */ public static String getRandomStr(int length) { String base = "abcdefghijklmnopqrstuvwxyz0123456789"; - int randomNum; + int randomNum; char randomChar; Random random = new Random(); StringBuffer str = new StringBuffer(); @@ -76,14 +76,11 @@ public static String getRandomStr(int length) { return str.toString(); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass public void beforeClass() { - PublicMethod.printAddress(lowBalTest); } + PublicMethod.printAddress(lowBalTest); + } @Test(groups = {"smoke"}) public void test1CreateAccount() { @@ -100,52 +97,80 @@ public void test1CreateAccount() { Assert.assertTrue(noCreateAccount.getBalance() == 1); } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void test2UpdateAccount() { - Assert.assertFalse(PublicMethod.updateAccount(lowBalAddress, - mostLongNamePlusOneChar.getBytes(), lowBalTest, blockingStubFull)); - Assert.assertFalse(PublicMethod.updateAccount(lowBalAddress, "".getBytes(), lowBalTest, - blockingStubFull)); - String mostLongName = getRandomStr(33); - Assert.assertTrue(PublicMethod.updateAccount(lowBalAddress, mostLongName.getBytes(), lowBalTest, - blockingStubFull)); - String firstUpdateName = getRandomStr(32); - Assert.assertFalse(PublicMethod.updateAccount(lowBalAddress, firstUpdateName.getBytes(), - lowBalTest, blockingStubFull)); - String secondUpdateName = getRandomStr(15); - Assert.assertFalse(PublicMethod.updateAccount(lowBalAddress, secondUpdateName.getBytes(), - lowBalTest, blockingStubFull)); + Assert.assertFalse( + PublicMethod.updateAccount( + lowBalAddress, mostLongNamePlusOneChar.getBytes(), lowBalTest, blockingStubFull)); + Assert.assertFalse( + PublicMethod.updateAccount(lowBalAddress, "".getBytes(), lowBalTest, blockingStubFull)); + String mostLongName = getRandomStr(33); + Assert.assertTrue( + PublicMethod.updateAccount( + lowBalAddress, mostLongName.getBytes(), lowBalTest, blockingStubFull)); + String firstUpdateName = getRandomStr(32); + Assert.assertFalse( + PublicMethod.updateAccount( + lowBalAddress, firstUpdateName.getBytes(), lowBalTest, blockingStubFull)); + String secondUpdateName = getRandomStr(15); + Assert.assertFalse( + PublicMethod.updateAccount( + lowBalAddress, secondUpdateName.getBytes(), lowBalTest, blockingStubFull)); } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void test3NoBalanceCreateAssetIssue() { Account lowaccount = PublicMethod.queryAccount(lowBalTest, blockingStubFull); if (lowaccount.getBalance() > 0) { Assert.assertTrue(sendCoin(toAddress, lowaccount.getBalance(), lowBalAddress, lowBalTest)); } - //Create AssetIssue failed when there is no enough balance. - Assert.assertFalse(PublicMethod.createAssetIssue(lowBalAddress, name, TotalSupply, 1, - 1, now + 100000000L, now + 10000000000L, 2, - description, url, 10000L, 10000L, 1L, - 1L, lowBalTest, blockingStubFull)); + // Create AssetIssue failed when there is no enough balance. + Assert.assertFalse( + PublicMethod.createAssetIssue( + lowBalAddress, + name, + TotalSupply, + 1, + 1, + now + 100000000L, + now + 10000000000L, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + lowBalTest, + blockingStubFull)); logger.info("nobalancecreateassetissue"); } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void test4NoBalanceTransferTrx() { - //Send Coin failed when there is no enough balance. + // Send Coin failed when there is no enough balance. Assert.assertFalse(sendCoin(toAddress, 100000000000000000L, lowBalAddress, lowBalTest)); } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void test5NoBalanceCreateWitness() { - //Apply to be super witness failed when no enough balance. + // Apply to be super witness failed when no enough balance. Assert.assertFalse(createWitness(lowBalAddress, foundationAddress, lowBalTest)); } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void test6NoFreezeBalanceToUnfreezeBalance() { - //Unfreeze account failed when no freeze balance + // Unfreeze account failed when no freeze balance Account noFreezeAccount = PublicMethod.queryAccount(lowBalTest, blockingStubFull); if (noFreezeAccount.getFrozenCount() == 0) { Assert.assertFalse(unFreezeBalance(lowBalAddress, lowBalTest)); @@ -154,16 +179,11 @@ public void test6NoFreezeBalanceToUnfreezeBalance() { } } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ + /** constructor. */ public Boolean createWitness(byte[] owner, byte[] url, String priKey) { ECKey temKey = null; try { @@ -174,8 +194,8 @@ public Boolean createWitness(byte[] owner, byte[] url, String priKey) { } final ECKey ecKey = temKey; - WitnessContract.WitnessCreateContract.Builder builder = WitnessContract.WitnessCreateContract - .newBuilder(); + WitnessContract.WitnessCreateContract.Builder builder = + WitnessContract.WitnessCreateContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(owner)); builder.setUrl(ByteString.copyFrom(url)); WitnessContract.WitnessCreateContract contract = builder.build(); @@ -188,12 +208,10 @@ public Boolean createWitness(byte[] owner, byte[] url, String priKey) { return response.getResult(); } - /** - * constructor. - */ + /** constructor. */ public Boolean sendCoin(byte[] to, long amount, byte[] owner, String priKey) { - //String priKey = foundationKey; - ECKey temKey = null; + // String priKey = foundationKey; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -202,8 +220,8 @@ public Boolean sendCoin(byte[] to, long amount, byte[] owner, String priKey) { } final ECKey ecKey = temKey; - BalanceContract.TransferContract.Builder builder = BalanceContract.TransferContract - .newBuilder(); + BalanceContract.TransferContract.Builder builder = + BalanceContract.TransferContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); ByteString bsOwner = ByteString.copyFrom(owner); builder.setToAddress(bsTo); @@ -226,12 +244,19 @@ public Boolean sendCoin(byte[] to, long amount, byte[] owner, String priKey) { } } - /** - * constructor. - */ - public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, Integer trxNum, - Integer icoNum, Long startTime, Long endTime, - Integer voteScore, String description, String url, String priKey) { + /** constructor. */ + public Boolean createAssetIssue( + byte[] address, + String name, + Long totalSupply, + Integer trxNum, + Integer icoNum, + Long startTime, + Long endTime, + Integer voteScore, + String description, + String url, + String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -242,8 +267,8 @@ public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, I ECKey ecKey = temKey; try { - AssetIssueContractOuterClass.AssetIssueContract.Builder builder - = AssetIssueContractOuterClass.AssetIssueContract.newBuilder(); + AssetIssueContractOuterClass.AssetIssueContract.Builder builder = + AssetIssueContractOuterClass.AssetIssueContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(address)); builder.setName(ByteString.copyFrom(name.getBytes())); builder.setTotalSupply(TotalSupply); @@ -279,23 +304,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Protocol.Transaction signTransaction(ECKey ecKey, Protocol.Transaction transaction) { @@ -307,12 +327,10 @@ private Protocol.Transaction signTransaction(ECKey ecKey, Protocol.Transaction t return TransactionUtils.sign(transaction, ecKey); } - /** - * constructor. - */ + /** constructor. */ public boolean unFreezeBalance(byte[] address, String priKey) { - //byte[] address = address; - ECKey temKey = null; + // byte[] address = address; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -320,8 +338,8 @@ public boolean unFreezeBalance(byte[] address, String priKey) { ex.printStackTrace(); } final ECKey ecKey = temKey; - BalanceContract.UnfreezeBalanceContract.Builder builder - = BalanceContract.UnfreezeBalanceContract.newBuilder(); + BalanceContract.UnfreezeBalanceContract.Builder builder = + BalanceContract.UnfreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddreess); @@ -343,9 +361,7 @@ public boolean unFreezeBalance(byte[] address, String priKey) { } } - /** - * constructor. - */ + /** constructor. */ public Boolean voteWitness(HashMap witness, byte[] address, String priKey) { ECKey temKey = null; @@ -356,15 +372,15 @@ public Boolean voteWitness(HashMap witness, byte[] address, Stri ex.printStackTrace(); } final ECKey ecKey = temKey; - WitnessContract.VoteWitnessContract.Builder builder = WitnessContract.VoteWitnessContract - .newBuilder(); + WitnessContract.VoteWitnessContract.Builder builder = + WitnessContract.VoteWitnessContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(address)); for (String addressBase58 : witness.keySet()) { String value = witness.get(addressBase58); long count = Long.parseLong(value); - WitnessContract.VoteWitnessContract.Vote.Builder voteBuilder - = WitnessContract.VoteWitnessContract.Vote.newBuilder(); - byte[] addRess = WalletClient.decodeFromBase58Check(addressBase58); + WitnessContract.VoteWitnessContract.Vote.Builder voteBuilder = + WitnessContract.VoteWitnessContract.Vote.newBuilder(); + byte[] addRess = WalletClient.decodeFromBase58Check(addressBase58); if (addRess == null) { return false; } @@ -389,16 +405,14 @@ public Boolean voteWitness(HashMap witness, byte[] address, Stri return true; } - /** - * constructor. - */ - public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDuration, - String priKey) { + /** constructor. */ + public Boolean freezeBalance( + byte[] addRess, long freezeBalance, long freezeDuration, String priKey) { byte[] address = addRess; long frozenBalance = freezeBalance; long frozenDuration = freezeDuration; - //String priKey = foundationKey; - ECKey temKey = null; + // String priKey = foundationKey; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -407,11 +421,13 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura } final ECKey ecKey = temKey; - BalanceContract.FreezeBalanceContract.Builder builder = BalanceContract.FreezeBalanceContract - .newBuilder(); + BalanceContract.FreezeBalanceContract.Builder builder = + BalanceContract.FreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess).setFrozenBalance(frozenBalance) + builder + .setOwnerAddress(byteAddreess) + .setFrozenBalance(frozenBalance) .setFrozenDuration(frozenDuration); BalanceContract.FreezeBalanceContract contract = builder.build(); @@ -429,8 +445,6 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura return false; } return true; - - } class AccountComparator implements Comparator { @@ -439,7 +453,4 @@ public int compare(Object o1, Object o2) { return Long.compare(((Account) o2).getBalance(), ((Account) o1).getBalance()); } } - } - - diff --git a/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount004.java b/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount004.java index ccb90f25..d49cfabb 100644 --- a/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount004.java +++ b/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount004.java @@ -11,60 +11,57 @@ import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.EmptyMessage; import org.tron.api.GrpcAPI.NumberMessage; import org.tron.api.GrpcAPI.Return; import org.tron.api.WalletGrpc; - import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.Block; import org.tron.protos.Protocol.Transaction; import org.tron.protos.contract.BalanceContract.FreezeBalanceContract; import org.tron.protos.contract.BalanceContract.UnfreezeBalanceContract; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.Parameter.CommonConstant; -import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; +import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; -import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; @Slf4j @MultiNode public class WalletTestAccount004 extends TronBaseTest { { fullnode = config.getStringList("fullnode.ip.list").get(1); - } private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + } + + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); - //just test key + // just test key private final String noFrozenBalanceTestKey = "8CB4480194192F30907E14B52498F594BD046E21D7C4D8FE866563A6760AC891"; private final byte[] noFrozenAddress = PublicMethod.getFinalAddress(noFrozenBalanceTestKey); - Long freezeAmount = 2000000L; private ManagedChannel searchChannelFull = null; private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; private String searchFullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + Long freezeAmount = 2000000L; + private ManagedChannel searchChannelFull = null; + private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; + private String searchFullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - /** - * constructor. - */ - + /** constructor. */ @BeforeClass - public void beforeClass() { searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode) - .usePlaintext() - .build(); + public void beforeClass() { + searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode).usePlaintext().build(); searchBlockingStubFull = WalletGrpc.newBlockingStub(searchChannelFull); - } @Test(enabled = true) @@ -74,75 +71,76 @@ public void testFreezeBalance() { byte[] account004AddressForFreeze = ecKey2.getAddress(); String account004KeyForFreeze = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(account004AddressForFreeze, 10000000, - fromAddress, foundationKey2, blockingStubFull)); - //Freeze failed when freeze amount is large than currently balance. - Assert.assertFalse(freezeBalance(account004AddressForFreeze, 9000000000000000000L, - 3L, account004KeyForFreeze)); - //Freeze failed when freeze amount less than 1Trx - Assert.assertFalse(freezeBalance(account004AddressForFreeze, 999999L, 3L, - account004KeyForFreeze)); - //Freeze failed when freeze duration isn't 3 days. - //Assert.assertFalse(freezeBalance(fromAddress, 1000000L, 2L, foundationKey2)); - //Unfreeze balance failed when 3 days hasn't come. - Assert.assertFalse(PublicMethod.unFreezeBalance(account004AddressForFreeze, - account004KeyForFreeze, 0, null, blockingStubFull)); - //Freeze failed when freeze amount is 0. - Assert.assertFalse(freezeBalance(account004AddressForFreeze, 0L, 3L, - account004KeyForFreeze)); - //Freeze failed when freeze amount is -1. - Assert.assertFalse(freezeBalance(account004AddressForFreeze, -1L, 3L, - account004KeyForFreeze)); - //Freeze failed when freeze duration is -1. - //Assert.assertFalse(freezeBalance(fromAddress, 1000000L, -1L, foundationKey2)); - //Freeze failed when freeze duration is 0. - //Assert.assertFalse(freezeBalance(fromAddress, 1000000L, 0L, foundationKey2)); + Assert.assertTrue( + PublicMethod.sendcoin( + account004AddressForFreeze, 10000000, foundationAddress2, + foundationKey2, blockingStubFull)); + // Freeze failed when freeze amount is large than currently balance. + Assert.assertFalse( + freezeBalance( + account004AddressForFreeze, 9000000000000000000L, 3L, account004KeyForFreeze)); + // Freeze failed when freeze amount less than 1Trx + Assert.assertFalse( + freezeBalance(account004AddressForFreeze, 999999L, 3L, account004KeyForFreeze)); + // Freeze failed when freeze duration isn't 3 days. + // Assert.assertFalse(freezeBalance(fromAddress, 1000000L, 2L, foundationKey2)); + // Unfreeze balance failed when 3 days hasn't come. + Assert.assertFalse( + PublicMethod.unFreezeBalance( + account004AddressForFreeze, account004KeyForFreeze, 0, null, blockingStubFull)); + // Freeze failed when freeze amount is 0. + Assert.assertFalse(freezeBalance(account004AddressForFreeze, 0L, 3L, account004KeyForFreeze)); + // Freeze failed when freeze amount is -1. + Assert.assertFalse(freezeBalance(account004AddressForFreeze, -1L, 3L, account004KeyForFreeze)); + // Freeze failed when freeze duration is -1. + // Assert.assertFalse(freezeBalance(fromAddress, 1000000L, -1L, foundationKey2)); + // Freeze failed when freeze duration is 0. + // Assert.assertFalse(freezeBalance(fromAddress, 1000000L, 0L, foundationKey2)); } @Test(enabled = true) public void testUnFreezeBalance() { - //Unfreeze failed when there is no freeze balance. - //Wait to be create account + // Unfreeze failed when there is no freeze balance. + // Wait to be create account - Assert.assertFalse(PublicMethod.unFreezeBalance(noFrozenAddress, noFrozenBalanceTestKey, 1, - null, blockingStubFull)); + Assert.assertFalse( + PublicMethod.unFreezeBalance( + noFrozenAddress, noFrozenBalanceTestKey, 1, null, blockingStubFull)); logger.info("Test unfreezebalance"); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] account004Address = ecKey1.getAddress(); String account004Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert - .assertTrue(PublicMethod.sendcoin(account004Address, freezeAmount, fromAddress, foundationKey2, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + account004Address, freezeAmount, foundationAddress2, foundationKey2, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalance(account004Address, freezeAmount, 0, - account004Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance( + account004Address, freezeAmount, 0, account004Key, blockingStubFull)); Account account004; account004 = PublicMethod.queryAccount(account004Address, blockingStubFull); Assert.assertTrue(account004.getBalance() == 0); - Assert.assertTrue(PublicMethod.unFreezeBalance(account004Address, account004Key, 0, - null, blockingStubFull)); + Assert.assertTrue( + PublicMethod.unFreezeBalance(account004Address, account004Key, 0, null, blockingStubFull)); account004 = PublicMethod.queryAccount(account004Address, blockingStubFull); Assert.assertTrue(account004.getBalance() == freezeAmount); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(account004Address, freezeAmount, 0, - 1, account004Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + account004Address, freezeAmount, 0, 1, account004Key, blockingStubFull)); account004 = PublicMethod.queryAccount(account004Address, blockingStubFull); Assert.assertTrue(account004.getBalance() == 0); - Assert.assertFalse(PublicMethod.unFreezeBalance(account004Address, account004Key, 0, - null, blockingStubFull)); - Assert.assertTrue(PublicMethod.unFreezeBalance(account004Address, account004Key, 1, - null, blockingStubFull)); + Assert.assertFalse( + PublicMethod.unFreezeBalance(account004Address, account004Key, 0, null, blockingStubFull)); + Assert.assertTrue( + PublicMethod.unFreezeBalance(account004Address, account004Key, 1, null, blockingStubFull)); account004 = PublicMethod.queryAccount(account004Address, blockingStubFull); Assert.assertTrue(account004.getBalance() == freezeAmount); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { if (channelFull != null) { @@ -153,17 +151,14 @@ public void shutdown() throws InterruptedException { } } - /** - * constructor. - */ - - public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDuration, - String priKey) { + /** constructor. */ + public Boolean freezeBalance( + byte[] addRess, long freezeBalance, long freezeDuration, String priKey) { byte[] address = addRess; long frozenBalance = freezeBalance; long frozenDuration = freezeDuration; - //String priKey = foundationKey2; + // String priKey = foundationKey2; ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -176,18 +171,20 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura final Long beforeBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Account beforeFronzen = queryAccount(ecKey, blockingStubFull); Long beforeFrozenBalance = 0L; - //Long beforeBandwidth = beforeFronzen.getBandwidth(); + // Long beforeBandwidth = beforeFronzen.getBandwidth(); if (beforeFronzen.getFrozenCount() != 0) { beforeFrozenBalance = beforeFronzen.getFrozen(0).getFrozenBalance(); - //beforeBandwidth = beforeFronzen.getBandwidth(); - //logger.info(Long.toString(beforeFronzen.getBandwidth())); + // beforeBandwidth = beforeFronzen.getBandwidth(); + // logger.info(Long.toString(beforeFronzen.getBandwidth())); logger.info(Long.toString(beforeFronzen.getFrozen(0).getFrozenBalance())); } FreezeBalanceContract.Builder builder = FreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess).setFrozenBalance(frozenBalance) + builder + .setOwnerAddress(byteAddreess) + .setFrozenBalance(frozenBalance) .setFrozenDuration(frozenDuration); FreezeBalanceContract contract = builder.build(); @@ -222,23 +219,21 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura Account afterFronzen = queryAccount(ecKey, searchBlockingStubFull); Long afterFrozenBalance = afterFronzen.getFrozen(0).getFrozenBalance(); - //Long afterBandwidth = afterFronzen.getBandwidth(); - //logger.info(Long.toString(afterFronzen.getBandwidth())); + // Long afterBandwidth = afterFronzen.getBandwidth(); + // logger.info(Long.toString(afterFronzen.getBandwidth())); logger.info(Long.toString(afterFronzen.getFrozen(0).getFrozenBalance())); - //logger.info(Integer.toString(search.getFrozenCount())); + // logger.info(Integer.toString(search.getFrozenCount())); logger.info( - "beforefronen" + beforeFrozenBalance.toString() + " afterfronzen" + afterFrozenBalance - .toString()); + "beforefronen" + + beforeFrozenBalance.toString() + + " afterfronzen" + + afterFrozenBalance.toString()); Assert.assertTrue(afterFrozenBalance - beforeFrozenBalance == freezeBalance); - //Assert.assertTrue(afterBandwidth - beforeBandwidth == freezeBalance * frozen_duration); + // Assert.assertTrue(afterBandwidth - beforeBandwidth == freezeBalance * frozen_duration); return true; - } - /** - * constructor. - */ - + /** constructor. */ public boolean unFreezeBalance(byte[] addRess, String priKey) { byte[] address = addRess; @@ -252,8 +247,7 @@ public boolean unFreezeBalance(byte[] addRess, String priKey) { ECKey ecKey = temKey; Account search = queryAccount(ecKey, blockingStubFull); - UnfreezeBalanceContract.Builder builder = UnfreezeBalanceContract - .newBuilder(); + UnfreezeBalanceContract.Builder builder = UnfreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddreess); @@ -276,14 +270,11 @@ public boolean unFreezeBalance(byte[] addRess, String priKey) { } } - /** - * constructor. - */ - + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; @@ -299,25 +290,17 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ - + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ - + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } } - diff --git a/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount005.java b/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount005.java index d5c0a378..aebc2230 100644 --- a/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount005.java +++ b/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount005.java @@ -12,76 +12,68 @@ import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.NumberMessage; import org.tron.api.GrpcAPI.Return; import org.tron.api.WalletGrpc; - import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.Block; import org.tron.protos.Protocol.Transaction; import org.tron.protos.contract.BalanceContract; import org.tron.protos.contract.WitnessContract; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.Parameter.CommonConstant; import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; - import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; + @Slf4j @MultiNode -public class WalletTestAccount005 extends TronBaseTest { private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); +public class WalletTestAccount005 extends TronBaseTest { + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); - //just test key + // just test key private final String notWitnessTestKey = "8CB4480194192F30907E14B52498F594BD046E21D7C4D8FE866563A6760AC891"; - private final byte[] notWitness = PublicMethod.getFinalAddress(notWitnessTestKey); private ManagedChannel searchChannelFull = null; private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; private String searchFullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private final byte[] notWitness = PublicMethod.getFinalAddress(notWitnessTestKey); + private ManagedChannel searchChannelFull = null; + private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; + private String searchFullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - /** - * constructor. - */ - + /** constructor. */ @BeforeClass - public void beforeClass() { searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode) - .usePlaintext() - .build(); + public void beforeClass() { + searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode).usePlaintext().build(); searchBlockingStubFull = WalletGrpc.newBlockingStub(searchChannelFull); - } @Test public void testWithdrawBalance() { - //Withdraw failed when you are not witness + // Withdraw failed when you are not witness Assert.assertFalse(withdrawBalance(notWitness, notWitnessTestKey)); - //Due to it's hard to automation, withdraw balance success case is not automation, + // Due to it's hard to automation, withdraw balance success case is not automation, // please test by manual - //Assert.assertTrue(WithdrawBalance(fromAddress,foundationKey2)); - //Withdraw failed when the latest time to withdraw within 1 day. + // Assert.assertTrue(WithdrawBalance(fromAddress,foundationKey2)); + // Withdraw failed when the latest time to withdraw within 1 day. if (withdrawBalance(fromAddress, foundationKey2)) { Assert.assertFalse(withdrawBalance(fromAddress, foundationKey2)); } else { logger.info("This account has withdraw within 1 day, please confirm"); } - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { if (channelFull != null) { @@ -92,10 +84,7 @@ public void shutdown() throws InterruptedException { } } - /** - * constructor. - */ - + /** constructor. */ public boolean withdrawBalance(byte[] address, String priKey) { ECKey temKey = null; try { @@ -124,13 +113,9 @@ public boolean withdrawBalance(byte[] address, String priKey) { } logger.info("test withdraw" + priKey); return true; - } - /** - * constructor. - */ - + /** constructor. */ public Boolean voteWitness(HashMap witness, byte[] address, String priKey) { ECKey temKey = null; @@ -147,8 +132,8 @@ public Boolean voteWitness(HashMap witness, byte[] address, Stri beforeVoteNum = beforeVote.getVotes(0).getVoteCount(); } - WitnessContract.VoteWitnessContract.Builder builder = WitnessContract.VoteWitnessContract - .newBuilder(); + WitnessContract.VoteWitnessContract.Builder builder = + WitnessContract.VoteWitnessContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(address)); for (String addressBase58 : witness.keySet()) { String value = witness.get(addressBase58); @@ -177,7 +162,7 @@ public Boolean voteWitness(HashMap witness, byte[] address, Stri return false; } Account afterVote = queryAccount(ecKey, searchBlockingStubFull); - //Long afterVoteNum = afterVote.getVotes(0).getVoteCount(); + // Long afterVoteNum = afterVote.getVotes(0).getVoteCount(); for (String key : witness.keySet()) { for (int j = 0; j < afterVote.getVotesCount(); j++) { if (key.equals(afterVote.getVotes(j).getVoteAddress())) { @@ -190,14 +175,11 @@ public Boolean voteWitness(HashMap witness, byte[] address, Stri return true; } - /** - * constructor. - */ - + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; @@ -213,25 +195,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ - + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ - + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -243,4 +218,3 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } } - diff --git a/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount006.java b/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount006.java index 55ba1b76..93025744 100644 --- a/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount006.java +++ b/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount006.java @@ -6,20 +6,16 @@ import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; import org.tron.api.GrpcAPI; import org.tron.api.GrpcAPI.AccountNetMessage; - - import org.tron.protos.Protocol.Account; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.Parameter.CommonConstant; -import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestAccount006 extends TronBaseTest { @@ -30,38 +26,39 @@ public class WalletTestAccount006 extends TronBaseTest { private static final long FREENETLIMIT = 5000L; private static final long BASELINE = 4800L; private static String name = "AssetIssue012_" + Long.toString(now); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); - //get account + // get account ECKey ecKey = new ECKey(Utils.getRandom()); byte[] account006Address = ecKey.getAddress(); String account006Key = ByteArray.toHexString(ecKey.getPrivKeyBytes()); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(account006Key); } + PublicMethod.printAddress(account006Key); + } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void test1GetAccountNet() { ecKey = new ECKey(Utils.getRandom()); account006Address = ecKey.getAddress(); account006Key = ByteArray.toHexString(ecKey.getPrivKeyBytes()); - //Sendcoin to this account + // Sendcoin to this account ByteString addressBS1 = ByteString.copyFrom(account006Address); Account request1 = Account.newBuilder().setAddress(addressBS1).build(); - GrpcAPI.AssetIssueList assetIssueList1 = blockingStubFull - .getAssetIssueByAccount(request1); + GrpcAPI.AssetIssueList assetIssueList1 = blockingStubFull.getAssetIssueByAccount(request1); Optional queryAssetByAccount = Optional.ofNullable(assetIssueList1); - Assert.assertTrue(PublicMethod.freezeBalance(foundationAddress, 100000000, 3, foundationKey, - blockingStubFull)); - Assert.assertTrue(PublicMethod - .sendcoin(account006Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); - //Get new account net information. + Assert.assertTrue( + PublicMethod.freezeBalance( + foundationAddress, 100000000, 3, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + account006Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + // Get new account net information. ByteString addressBs = ByteString.copyFrom(account006Address); Account request = Account.newBuilder().setAddress(addressBs).build(); AccountNetMessage accountNetMessage = blockingStubFull.getAccountNet(request); @@ -78,57 +75,66 @@ public void test1GetAccountNet() { Assert.assertTrue(accountNetMessage.getTotalNetLimit() > 0); Assert.assertTrue(accountNetMessage.getTotalNetWeight() > 0); logger.info("testGetAccountNet"); - } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void test2UseFreeNet() { - //Transfer some TRX to other to test free net cost. - Assert.assertTrue(PublicMethod.sendcoin(foundationAddress, 1L, account006Address, - account006Key, blockingStubFull)); + // Transfer some TRX to other to test free net cost. + Assert.assertTrue( + PublicMethod.sendcoin( + foundationAddress, 1L, account006Address, account006Key, blockingStubFull)); ByteString addressBs = ByteString.copyFrom(account006Address); Account request = Account.newBuilder().setAddress(addressBs).build(); AccountNetMessage accountNetMessage = blockingStubFull.getAccountNet(request); - //Every transaction may cost 200 net. - Assert.assertTrue(accountNetMessage.getFreeNetUsed() > 0 && accountNetMessage - .getFreeNetUsed() < 300); + // Every transaction may cost 200 net. + Assert.assertTrue( + accountNetMessage.getFreeNetUsed() > 0 && accountNetMessage.getFreeNetUsed() < 300); logger.info("testUseFreeNet"); } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void test3UseMoneyToDoTransaction() { - Assert.assertTrue(PublicMethod.sendcoin(account006Address, 1000000L, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + account006Address, 1000000L, foundationAddress, foundationKey, blockingStubFull)); ByteString addressBs = ByteString.copyFrom(account006Address); Account request = Account.newBuilder().setAddress(addressBs).build(); AccountNetMessage accountNetMessage = blockingStubFull.getAccountNet(request); - //Use out the free net + // Use out the free net Integer times = 0; while (accountNetMessage.getFreeNetUsed() < BASELINE && times++ < 30) { - PublicMethod.sendcoin(foundationAddress, 1L, account006Address, account006Key, - blockingStubFull); + PublicMethod.sendcoin( + foundationAddress, 1L, account006Address, account006Key, blockingStubFull); accountNetMessage = blockingStubFull.getAccountNet(request); } Account queryAccount = PublicMethod.queryAccount(account006Key, blockingStubFull); - Long beforeSendBalance = queryAccount.getBalance(); - Assert.assertTrue(PublicMethod.sendcoin(foundationAddress, 1L, account006Address, account006Key, - blockingStubFull)); + Long beforeSendBalance = queryAccount.getBalance(); + Assert.assertTrue( + PublicMethod.sendcoin( + foundationAddress, 1L, account006Address, account006Key, blockingStubFull)); queryAccount = PublicMethod.queryAccount(account006Key, blockingStubFull); - Long afterSendBalance = queryAccount.getBalance(); - //when the free net is not enough and no balance freeze, use money to do the transaction. + Long afterSendBalance = queryAccount.getBalance(); + // when the free net is not enough and no balance freeze, use money to do the transaction. Assert.assertTrue(beforeSendBalance - afterSendBalance > 1); logger.info("testUseMoneyToDoTransaction"); } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void test4UseNet() { - //Freeze balance to own net. - Assert.assertTrue(PublicMethod.freezeBalance(account006Address, 10000000L, - 3, account006Key, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(toAddress, 1L, account006Address, - account006Key, blockingStubFull)); + // Freeze balance to own net. + Assert.assertTrue( + PublicMethod.freezeBalance( + account006Address, 10000000L, 3, account006Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin(toAddress, 1L, account006Address, account006Key, blockingStubFull)); ByteString addressBs = ByteString.copyFrom(account006Address); Account request = Account.newBuilder().setAddress(addressBs).build(); AccountNetMessage accountNetMessage = blockingStubFull.getAccountNet(request); @@ -136,29 +142,28 @@ public void test4UseNet() { Assert.assertTrue(accountNetMessage.getNetUsed() > 150); Account queryAccount = PublicMethod.queryAccount(account006Key, blockingStubFull); - Long beforeSendBalance = queryAccount.getBalance(); - Assert.assertTrue(PublicMethod.sendcoin(foundationAddress, 1L, account006Address, - account006Key, blockingStubFull)); + Long beforeSendBalance = queryAccount.getBalance(); + Assert.assertTrue( + PublicMethod.sendcoin( + foundationAddress, 1L, account006Address, account006Key, blockingStubFull)); queryAccount = PublicMethod.queryAccount(account006Key, blockingStubFull); - Long afterSendBalance = queryAccount.getBalance(); - //when you freeze balance and has net,you didn't cost money. - logger.info("before is " + Long.toString(beforeSendBalance) + " and after is " - + Long.toString(afterSendBalance)); + Long afterSendBalance = queryAccount.getBalance(); + // when you freeze balance and has net,you didn't cost money. + logger.info( + "before is " + + Long.toString(beforeSendBalance) + + " and after is " + + Long.toString(afterSendBalance)); Assert.assertTrue(beforeSendBalance - afterSendBalance == 1); addressBs = ByteString.copyFrom(account006Address); request = Account.newBuilder().setAddress(addressBs).build(); accountNetMessage = blockingStubFull.getAccountNet(request); - //when you freeze balance and has net,you cost net. + // when you freeze balance and has net,you cost net. logger.info(Long.toString(accountNetMessage.getNetUsed())); Assert.assertTrue(accountNetMessage.getNetUsed() > 350); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount007.java b/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount007.java index 6952a402..8fc33a33 100644 --- a/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount007.java +++ b/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount007.java @@ -4,19 +4,15 @@ import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.AccountNetMessage; - - import org.tron.protos.Protocol.Account; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.Parameter.CommonConstant; -import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestAccount007 extends TronBaseTest { @@ -27,75 +23,72 @@ public class WalletTestAccount007 extends TronBaseTest { private static final long FREENETLIMIT = 5000L; private static final long BASELINE = 4800L; private static String name = "AssetIssue012_" + Long.toString(now); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); - //owner account + // owner account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] account007Address = ecKey1.getAddress(); String account007Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - //Wait to be create account + // Wait to be create account ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] newAccountAddress = ecKey2.getAddress(); String newAccountKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - logger.info(account007Key); } + logger.info(account007Key); + } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void testCreateAccount() { - Assert.assertTrue(PublicMethod.sendcoin(account007Address, 10000000, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + account007Address, 10000000, foundationAddress, foundationKey, blockingStubFull)); Account accountInfo = PublicMethod.queryAccount(account007Key, blockingStubFull); - final Long beforeBalance = accountInfo.getBalance(); + final Long beforeBalance = accountInfo.getBalance(); - AccountNetMessage accountNetInfo = PublicMethod.getAccountNet(account007Address, - blockingStubFull); - final Long beforeFreeNet = accountNetInfo.getFreeNetUsed(); + AccountNetMessage accountNetInfo = + PublicMethod.getAccountNet(account007Address, blockingStubFull); + final Long beforeFreeNet = accountNetInfo.getFreeNetUsed(); - Assert.assertTrue(PublicMethod.createAccount(account007Address, newAccountAddress, - account007Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createAccount( + account007Address, newAccountAddress, account007Key, blockingStubFull)); accountInfo = PublicMethod.queryAccount(account007Key, blockingStubFull); - Long afterBalance = accountInfo.getBalance(); + Long afterBalance = accountInfo.getBalance(); - accountNetInfo = PublicMethod.getAccountNet(account007Address, - blockingStubFull); - Long afterFreeNet = accountNetInfo.getFreeNetUsed(); + accountNetInfo = PublicMethod.getAccountNet(account007Address, blockingStubFull); + Long afterFreeNet = accountNetInfo.getFreeNetUsed(); logger.info(Long.toString(beforeBalance)); logger.info(Long.toString(afterBalance)); - //When creator has no bandwidth, he can't use the free net. + // When creator has no bandwidth, he can't use the free net. Assert.assertTrue(afterFreeNet == beforeFreeNet); - //When the creator has no bandwidth, create a new account should spend 0.1TRX. + // When the creator has no bandwidth, create a new account should spend 0.1TRX. Assert.assertTrue(beforeBalance - afterBalance == 100000); } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void testExceptionCreateAccount() { - //Try to create an exist account - Assert - .assertFalse(PublicMethod.createAccount(account007Address, account007Address, account007Key, - blockingStubFull)); - //Try to create an invalid account + // Try to create an exist account + Assert.assertFalse( + PublicMethod.createAccount( + account007Address, account007Address, account007Key, blockingStubFull)); + // Try to create an invalid account byte[] wrongAddress = "wrongAddress".getBytes(); - Assert.assertFalse(PublicMethod.createAccount(account007Address, wrongAddress, account007Key, - blockingStubFull)); + Assert.assertFalse( + PublicMethod.createAccount( + account007Address, wrongAddress, account007Key, blockingStubFull)); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } - - + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount009.java b/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount009.java index 35665838..59ff9728 100644 --- a/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount009.java +++ b/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount009.java @@ -8,11 +8,11 @@ import org.tron.api.GrpcAPI.AccountResourceMessage; import org.tron.protos.Protocol.Account; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestAccount009 extends TronBaseTest { @@ -23,8 +23,8 @@ public class WalletTestAccount009 extends TronBaseTest { private static final long FREENETLIMIT = 5000L; private static final long BASELINE = 4800L; private static String name = "AssetIssue012_" + Long.toString(now); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] account009Address = ecKey1.getAddress(); @@ -36,63 +36,72 @@ public class WalletTestAccount009 extends TronBaseTest { byte[] account009InvalidAddress = ecKey3.getAddress(); String account009InvalidKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(account009Key); - PublicMethod.printAddress(account009SecondKey); } + PublicMethod.printAddress(account009SecondKey); + } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void testGetEnergy() { - Assert.assertTrue(PublicMethod.sendcoin(account009Address, 10000000, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(account009SecondAddress, 10000000, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(account009InvalidAddress, 10000000, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + account009Address, 10000000, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + account009SecondAddress, 10000000, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + account009InvalidAddress, + 10000000, + foundationAddress, + foundationKey, + blockingStubFull)); Account account009Info = PublicMethod.queryAccount(account009Key, blockingStubFull); - logger.info(Long.toString( - account009Info.getAccountResource().getFrozenBalanceForEnergy().getExpireTime())); + logger.info( + Long.toString( + account009Info.getAccountResource().getFrozenBalanceForEnergy().getExpireTime())); Assert.assertTrue(account009Info.getAccountResource().getEnergyUsage() == 0); - Assert.assertTrue(account009Info.getAccountResource().getFrozenBalanceForEnergy() - .getExpireTime() == 0); + Assert.assertTrue( + account009Info.getAccountResource().getFrozenBalanceForEnergy().getExpireTime() == 0); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(account009Address, 1000000L, - 3, 1, account009Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + account009Address, 1000000L, 3, 1, account009Key, blockingStubFull)); account009Info = PublicMethod.queryAccount(account009Key, blockingStubFull); Assert.assertTrue(account009Info.getAccountResource().getEnergyUsage() == 0); - Assert.assertTrue(account009Info.getAccountResource().getFrozenBalanceForEnergy() - .getFrozenBalance() == 1000000L); + Assert.assertTrue( + account009Info.getAccountResource().getFrozenBalanceForEnergy().getFrozenBalance() + == 1000000L); - AccountResourceMessage account009Resource = PublicMethod.getAccountResource(account009Address, - blockingStubFull); + AccountResourceMessage account009Resource = + PublicMethod.getAccountResource(account009Address, blockingStubFull); Assert.assertTrue(account009Resource.getTotalEnergyLimit() >= 50000000000L); Assert.assertTrue(account009Resource.getEnergyLimit() > 0); Assert.assertTrue(account009Resource.getTotalEnergyWeight() >= 1); } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void testGetEnergyInvalid() { - //The resourceCode can only be 0 or 1 - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(account009InvalidAddress, - 1000000L, 3, 0, account009InvalidKey, blockingStubFull)); - Assert.assertFalse(PublicMethod.freezeBalanceGetEnergy(account009InvalidAddress, 1000000L, - 3, -1, account009InvalidKey, blockingStubFull)); - Assert.assertFalse(PublicMethod.freezeBalanceGetEnergy(account009InvalidAddress, 1000000L, - 3, 3, account009InvalidKey, blockingStubFull)); - + // The resourceCode can only be 0 or 1 + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + account009InvalidAddress, 1000000L, 3, 0, account009InvalidKey, blockingStubFull)); + Assert.assertFalse( + PublicMethod.freezeBalanceGetEnergy( + account009InvalidAddress, 1000000L, 3, -1, account009InvalidKey, blockingStubFull)); + Assert.assertFalse( + PublicMethod.freezeBalanceGetEnergy( + account009InvalidAddress, 1000000L, 3, 3, account009InvalidKey, blockingStubFull)); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount011.java b/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount011.java index 6344a243..3d6e7b98 100644 --- a/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount011.java +++ b/testcase/src/test/java/stest/tron/wallet/account/WalletTestAccount011.java @@ -1,6 +1,5 @@ package stest.tron.wallet.account; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import lombok.extern.slf4j.Slf4j; import org.testng.annotations.AfterClass; @@ -8,42 +7,38 @@ import org.testng.annotations.Test; import org.tron.api.GrpcAPI.EmptyMessage; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class WalletTestAccount011 extends TronBaseTest { ECKey ecKey1 = new ECKey(Utils.getRandom()); +public class WalletTestAccount011 extends TronBaseTest { + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] account011Address = ecKey1.getAddress(); String account011Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(account011Key); channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + PublicMethod.printAddress(account011Key); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, groups = {"smoke"}) + @Test( + enabled = false, + groups = {"smoke"}) public void testgenerateAddress() { EmptyMessage.Builder builder = EmptyMessage.newBuilder(); blockingStubFull.generateAddress(builder.build()); blockingStubSolidity.generateAddress(builder.build()); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/block/WalletTestBlock003.java b/testcase/src/test/java/stest/tron/wallet/block/WalletTestBlock003.java index 1fce6f5c..e0f83e7c 100644 --- a/testcase/src/test/java/stest/tron/wallet/block/WalletTestBlock003.java +++ b/testcase/src/test/java/stest/tron/wallet/block/WalletTestBlock003.java @@ -1,7 +1,6 @@ package stest.tron.wallet.block; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -23,56 +22,49 @@ import stest.tron.wallet.common.client.utils.TronBaseTest; @Slf4j -public class WalletTestBlock003 extends TronBaseTest { private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); +public class WalletTestBlock003 extends TronBaseTest { + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void testGetNextMaintenanceTime() { long now = System.currentTimeMillis(); - NumberMessage getNextMaintenanceTime = blockingStubFull - .getNextMaintenanceTime(GrpcAPI.EmptyMessage.newBuilder().build()); + NumberMessage getNextMaintenanceTime = + blockingStubFull.getNextMaintenanceTime(GrpcAPI.EmptyMessage.newBuilder().build()); logger.info(Long.toString(getNextMaintenanceTime.getNum())); logger.info(Long.toString(now)); Assert.assertTrue(getNextMaintenanceTime.getNum() > now); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -82,23 +74,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -110,5 +97,3 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/block/WalletTestBlock004.java b/testcase/src/test/java/stest/tron/wallet/block/WalletTestBlock004.java index 7ebddc58..21de7e7c 100644 --- a/testcase/src/test/java/stest/tron/wallet/block/WalletTestBlock004.java +++ b/testcase/src/test/java/stest/tron/wallet/block/WalletTestBlock004.java @@ -17,28 +17,28 @@ import org.tron.protos.Protocol.Block; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.TronBaseTest; - //import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIConversion; - //import stest.tron.wallet.common.client.AccountComparator; + +// import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIConversion; +// import stest.tron.wallet.common.client.AccountComparator; @Slf4j -public class WalletTestBlock004 extends TronBaseTest { public static String loadPubKey() { +public class WalletTestBlock004 extends TronBaseTest { + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void testGetBlockByLimitNext() { // Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); + Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Assert.assertFalse(currentBlockNum < 0); while (currentBlockNum <= 5) { logger.info("Now has very little block, Please wait"); @@ -53,10 +53,12 @@ public void testGetBlockByLimitNext() { Optional getBlockByLimitNext = Optional.ofNullable(blockList); Assert.assertTrue(getBlockByLimitNext.isPresent()); Assert.assertTrue(getBlockByLimitNext.get().getBlockCount() == 2); - logger.info(Long.toString( - getBlockByLimitNext.get().getBlock(0).getBlockHeader().getRawData().getNumber())); - logger.info(Long.toString( - getBlockByLimitNext.get().getBlock(1).getBlockHeader().getRawData().getNumber())); + logger.info( + Long.toString( + getBlockByLimitNext.get().getBlock(0).getBlockHeader().getRawData().getNumber())); + logger.info( + Long.toString( + getBlockByLimitNext.get().getBlock(1).getBlockHeader().getRawData().getNumber())); Assert.assertTrue( getBlockByLimitNext.get().getBlock(0).getBlockHeader().getRawData().getNumber() < 4); Assert.assertTrue( @@ -64,17 +66,29 @@ public void testGetBlockByLimitNext() { Assert.assertTrue(getBlockByLimitNext.get().getBlock(0).hasBlockHeader()); Assert.assertTrue(getBlockByLimitNext.get().getBlock(1).hasBlockHeader()); Assert.assertFalse( - getBlockByLimitNext.get().getBlock(0).getBlockHeader().getRawData().getParentHash() + getBlockByLimitNext + .get() + .getBlock(0) + .getBlockHeader() + .getRawData() + .getParentHash() .isEmpty()); Assert.assertFalse( - getBlockByLimitNext.get().getBlock(1).getBlockHeader().getRawData().getParentHash() + getBlockByLimitNext + .get() + .getBlock(1) + .getBlockHeader() + .getRawData() + .getParentHash() .isEmpty()); } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void testGetBlockByExceptionLimitNext() { Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); + Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Assert.assertFalse(currentBlockNum < 0); while (currentBlockNum <= 5) { logger.info("Now has very little block, Please wait"); @@ -82,28 +96,28 @@ public void testGetBlockByExceptionLimitNext() { currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); } - //From -1 to 1 + // From -1 to 1 GrpcAPI.BlockLimit.Builder builder = GrpcAPI.BlockLimit.newBuilder(); builder.setStartNum(-1); builder.setEndNum(1); GrpcAPI.BlockList blockList = blockingStubFull.getBlockByLimitNext(builder.build()); Optional getBlockByLimitNext = Optional.ofNullable(blockList); Assert.assertTrue(getBlockByLimitNext.get().getBlockCount() == 0); - //From 3 to 3 + // From 3 to 3 builder = GrpcAPI.BlockLimit.newBuilder(); builder.setStartNum(3); builder.setEndNum(3); blockList = blockingStubFull.getBlockByLimitNext(builder.build()); getBlockByLimitNext = Optional.ofNullable(blockList); Assert.assertTrue(getBlockByLimitNext.get().getBlockCount() == 0); - //From 4 to 2 + // From 4 to 2 builder = GrpcAPI.BlockLimit.newBuilder(); builder.setStartNum(4); builder.setEndNum(2); blockList = blockingStubFull.getBlockByLimitNext(builder.build()); getBlockByLimitNext = Optional.ofNullable(blockList); Assert.assertTrue(getBlockByLimitNext.get().getBlockCount() == 0); - //From 999999990 to 999999999 + // From 999999990 to 999999999 builder = GrpcAPI.BlockLimit.newBuilder(); builder.setStartNum(999999990); builder.setEndNum(999999999); @@ -112,19 +126,14 @@ public void testGetBlockByExceptionLimitNext() { Assert.assertTrue(getBlockByLimitNext.get().getBlockCount() == 0); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -133,13 +142,13 @@ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockin } ECKey ecKey = temKey; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -149,24 +158,17 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/block/WalletTestBlock005.java b/testcase/src/test/java/stest/tron/wallet/block/WalletTestBlock005.java index 12e4b613..62ce2d92 100644 --- a/testcase/src/test/java/stest/tron/wallet/block/WalletTestBlock005.java +++ b/testcase/src/test/java/stest/tron/wallet/block/WalletTestBlock005.java @@ -17,29 +17,28 @@ import org.tron.protos.Protocol.Block; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.TronBaseTest; - //import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIConversion; - //import stest.tron.wallet.common.client.AccountComparator; + +// import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIConversion; +// import stest.tron.wallet.common.client.AccountComparator; @Slf4j -public class WalletTestBlock005 extends TronBaseTest { public static String loadPubKey() { +public class WalletTestBlock005 extends TronBaseTest { + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void testGetBlockByLatestNum() { // Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); + Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Assert.assertFalse(currentBlockNum < 0); while (currentBlockNum <= 5) { logger.info("Now the block num is " + Long.toString(currentBlockNum) + " Please wait"); @@ -56,16 +55,22 @@ public void testGetBlockByLatestNum() { Assert.assertTrue( getBlockByLatestNum.get().getBlock(1).getBlockHeader().getRawData().getNumber() > 0); Assert.assertFalse( - getBlockByLatestNum.get().getBlock(2).getBlockHeader().getRawData().getParentHash() + getBlockByLatestNum + .get() + .getBlock(2) + .getBlockHeader() + .getRawData() + .getParentHash() .isEmpty()); logger.info("TestGetBlockByLatestNum ok!!!"); - } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void testGetBlockByExceptionNum() { Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); + Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Assert.assertFalse(currentBlockNum < 0); while (currentBlockNum <= 5) { logger.info("Now the block num is " + Long.toString(currentBlockNum) + " Please wait"); @@ -86,23 +91,16 @@ public void testGetBlockByExceptionNum() { blockList = blockingStubFull.getBlockByLatestNum(numberMessage); getBlockByLatestNum = Optional.ofNullable(blockList); Assert.assertTrue(getBlockByLatestNum.get().getBlockCount() == 0); - - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -111,13 +109,13 @@ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockin } ECKey ecKey = temKey; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -127,24 +125,17 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/block/WalletTestBlock006.java b/testcase/src/test/java/stest/tron/wallet/block/WalletTestBlock006.java index 552c55f6..4a4bde02 100644 --- a/testcase/src/test/java/stest/tron/wallet/block/WalletTestBlock006.java +++ b/testcase/src/test/java/stest/tron/wallet/block/WalletTestBlock006.java @@ -3,7 +3,6 @@ import io.grpc.ManagedChannel; import lombok.extern.slf4j.Slf4j; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI; @@ -11,13 +10,13 @@ import org.tron.api.WalletSolidityGrpc; import org.tron.protos.Protocol.Block; import stest.tron.wallet.common.client.utils.TronBaseTest; + @Slf4j -public class WalletTestBlock006 extends TronBaseTest { private ManagedChannel channelSolidity = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; /** - * constructor. - */ +public class WalletTestBlock006 extends TronBaseTest { + /** constructor. */ @BeforeClass - public void beforeClass() { } + public void beforeClass() {} @Test(enabled = true) public void testGetTransactionCountByBlockNumFromFullnode() { @@ -25,20 +24,20 @@ public void testGetTransactionCountByBlockNumFromFullnode() { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(0); Long transactionNumInBlock = 0L; - transactionNumInBlock = blockingStubFull.getTransactionCountByBlockNum(builder - .build()).getNum(); + transactionNumInBlock = + blockingStubFull.getTransactionCountByBlockNum(builder.build()).getNum(); Assert.assertTrue(transactionNumInBlock >= 1); builder.setNum(-10); - transactionNumInBlock = blockingStubFull.getTransactionCountByBlockNum(builder - .build()).getNum(); + transactionNumInBlock = + blockingStubFull.getTransactionCountByBlockNum(builder.build()).getNum(); Assert.assertTrue(transactionNumInBlock == -1); Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); builder.setNum(currentBlockNum + 10000L); - transactionNumInBlock = blockingStubFull.getTransactionCountByBlockNum(builder - .build()).getNum(); + transactionNumInBlock = + blockingStubFull.getTransactionCountByBlockNum(builder.build()).getNum(); Assert.assertTrue(transactionNumInBlock == -1); } @@ -47,21 +46,20 @@ public void testGetTransactionCountByBlockNumFromSolidity() { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(0); Long transactionNumInBlock = 0L; - transactionNumInBlock = blockingStubSolidity.getTransactionCountByBlockNum(builder - .build()).getNum(); + transactionNumInBlock = + blockingStubSolidity.getTransactionCountByBlockNum(builder.build()).getNum(); Assert.assertTrue(transactionNumInBlock >= 1); builder.setNum(-10); - transactionNumInBlock = blockingStubSolidity.getTransactionCountByBlockNum(builder - .build()).getNum(); + transactionNumInBlock = + blockingStubSolidity.getTransactionCountByBlockNum(builder.build()).getNum(); Assert.assertTrue(transactionNumInBlock == -1); Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); builder.setNum(currentBlockNum + 10000L); - transactionNumInBlock = blockingStubSolidity.getTransactionCountByBlockNum(builder - .build()).getNum(); + transactionNumInBlock = + blockingStubSolidity.getTransactionCountByBlockNum(builder.build()).getNum(); Assert.assertTrue(transactionNumInBlock == -1); } } - diff --git a/testcase/src/test/java/stest/tron/wallet/committee/WalletTestCommittee001.java b/testcase/src/test/java/stest/tron/wallet/committee/WalletTestCommittee001.java index f9628fb1..4b40076f 100644 --- a/testcase/src/test/java/stest/tron/wallet/committee/WalletTestCommittee001.java +++ b/testcase/src/test/java/stest/tron/wallet/committee/WalletTestCommittee001.java @@ -1,6 +1,5 @@ package stest.tron.wallet.committee; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.HashMap; import java.util.Optional; @@ -21,66 +20,58 @@ public class WalletTestCommittee001 extends TronBaseTest { private static final long now = System.currentTimeMillis(); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); - //Witness 47.93.9.236 //Witness 47.93.33.201 - //Witness 123.56.10.6 - //Wtiness 39.107.80.135 - //Witness 47.93.184.2 + // Witness 47.93.9.236 //Witness 47.93.33.201 + // Witness 123.56.10.6 + // Wtiness 39.107.80.135 + // Witness 47.93.184.2 private final byte[] witness001Address = PublicMethod.getFinalAddress(witnessKey); private final byte[] witness002Address = PublicMethod.getFinalAddress(witnessKey2); private final byte[] witness003Address = PublicMethod.getFinalAddress(witnessKey3); private final byte[] witness004Address = PublicMethod.getFinalAddress(witnessKey4); private final byte[] witness005Address = PublicMethod.getFinalAddress(witnessKey5); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } @Test(groups = {"smoke"}) public void testListProposals() { - //List proposals + // List proposals ProposalList proposalList = blockingStubFull.listProposals(EmptyMessage.newBuilder().build()); Optional listProposals = Optional.ofNullable(proposalList); - final Integer beforeProposalCount = listProposals.get().getProposalsCount(); - //CreateProposal + final Integer beforeProposalCount = listProposals.get().getProposalsCount(); + // CreateProposal final long now = System.currentTimeMillis(); HashMap proposalMap = new HashMap(); proposalMap.put(0L, 1000000L); PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull); - //List proposals + // List proposals proposalList = blockingStubFull.listProposals(EmptyMessage.newBuilder().build()); listProposals = Optional.ofNullable(proposalList); Integer afterProposalCount = listProposals.get().getProposalsCount(); Assert.assertTrue(beforeProposalCount + 1 == afterProposalCount); logger.info(Long.toString(listProposals.get().getProposals(0).getCreateTime())); logger.info(Long.toString(now)); - //Assert.assertTrue(listProposals.get().getProposals(0).getCreateTime() >= now); + // Assert.assertTrue(listProposals.get().getProposals(0).getCreateTime() >= now); Assert.assertTrue(listProposals.get().getProposals(0).getParametersMap().equals(proposalMap)); - //getProposalListPaginated + // getProposalListPaginated PaginatedMessage.Builder pageMessageBuilder = PaginatedMessage.newBuilder(); pageMessageBuilder.setOffset(0); pageMessageBuilder.setLimit(1); - ProposalList paginatedProposalList = blockingStubFull - .getPaginatedProposalList(pageMessageBuilder.build()); + ProposalList paginatedProposalList = + blockingStubFull.getPaginatedProposalList(pageMessageBuilder.build()); Assert.assertTrue(paginatedProposalList.getProposalsCount() >= 1); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - diff --git a/testcase/src/test/java/stest/tron/wallet/committee/WalletTestCommittee002.java b/testcase/src/test/java/stest/tron/wallet/committee/WalletTestCommittee002.java index 87d9a3dc..32008134 100644 --- a/testcase/src/test/java/stest/tron/wallet/committee/WalletTestCommittee002.java +++ b/testcase/src/test/java/stest/tron/wallet/committee/WalletTestCommittee002.java @@ -4,287 +4,284 @@ import java.util.HashMap; import lombok.extern.slf4j.Slf4j; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.WalletSolidityGrpc; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.PublicMethod; - import stest.tron.wallet.common.client.utils.TronBaseTest; + @Slf4j public class WalletTestCommittee002 extends TronBaseTest { - private static final long now = System.currentTimeMillis(); private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); - //Witness 47.93.9.236 - //Witness 47.93.33.201 - //Witness 123.56.10.6 - //Wtiness 39.107.80.135 - //Witness 47.93.184.2 + private static final long now = System.currentTimeMillis(); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); + // Witness 47.93.9.236 + // Witness 47.93.33.201 + // Witness 123.56.10.6 + // Wtiness 39.107.80.135 + // Witness 47.93.184.2 private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); private final byte[] witness001Address = PublicMethod.getFinalAddress(witnessKey); private final byte[] witness002Address = PublicMethod.getFinalAddress(witnessKey2); private final byte[] witness003Address = PublicMethod.getFinalAddress(witnessKey3); private final byte[] witness004Address = PublicMethod.getFinalAddress(witnessKey4); - private final byte[] witness005Address = PublicMethod.getFinalAddress(witnessKey5); private ManagedChannel channelSolidity = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; /** - * constructor. - */ + private final byte[] witness005Address = PublicMethod.getFinalAddress(witnessKey5); + private ManagedChannel channelSolidity = null; + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + /** constructor. */ @BeforeClass - public void beforeClass() { } + public void beforeClass() {} @Test(enabled = true) - public void testCreateProposalMaintenanceTimeInterval() { Assert.assertTrue(PublicMethod.sendcoin(witness001Address, 10000000L, - toAddress, testKey003, blockingStubFull)); + public void testCreateProposalMaintenanceTimeInterval() { + Assert.assertTrue( + PublicMethod.sendcoin( + witness001Address, 10000000L, toAddress, testKey003, blockingStubFull)); - //0:MAINTENANCE_TIME_INTERVAL,[3*27s,24h] - //Minimum interval + // 0:MAINTENANCE_TIME_INTERVAL,[3*27s,24h] + // Minimum interval HashMap proposalMap = new HashMap(); proposalMap.put(0L, 81000L); - Assert.assertTrue(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Maximum interval + // Maximum interval proposalMap.put(0L, 86400000L); - Assert.assertTrue(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Minimum -1 interval, create failed. + // Minimum -1 interval, create failed. proposalMap.put(0L, 80000L); - Assert.assertFalse(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertFalse( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Maximum + 1 interval + // Maximum + 1 interval proposalMap.put(0L, 86401000L); - Assert.assertFalse(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertFalse( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Non witness account + // Non witness account proposalMap.put(0L, 86400000L); - Assert.assertFalse(PublicMethod.createProposal(toAddress, testKey003, proposalMap, - blockingStubFull)); + Assert.assertFalse( + PublicMethod.createProposal(toAddress, testKey003, proposalMap, blockingStubFull)); } @Test(enabled = true) public void testCreateProposalAccountUpgradeCost() { initSolidityChannel(); - //1:ACCOUNT_UPGRADE_COST,[0,100 000 000 000 000 000]//drop - //Minimum AccountUpgradeCost + // 1:ACCOUNT_UPGRADE_COST,[0,100 000 000 000 000 000]//drop + // Minimum AccountUpgradeCost HashMap proposalMap = new HashMap(); proposalMap.put(1L, 0L); - Assert.assertTrue(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Maximum AccountUpgradeCost + // Maximum AccountUpgradeCost proposalMap.put(1L, 100000000000000000L); - Assert.assertTrue(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Minimum - 1 AccountUpgradeCost + // Minimum - 1 AccountUpgradeCost proposalMap.put(1L, -1L); - Assert.assertFalse(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertFalse( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Maximum + 1 AccountUpgradeCost + // Maximum + 1 AccountUpgradeCost proposalMap.put(1L, 100000000000000001L); - Assert.assertFalse(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertFalse( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Non witness account + // Non witness account proposalMap.put(1L, 86400000L); - Assert.assertFalse(PublicMethod.createProposal(toAddress, testKey003, - proposalMap, blockingStubFull)); + Assert.assertFalse( + PublicMethod.createProposal(toAddress, testKey003, proposalMap, blockingStubFull)); } @Test(enabled = true) public void testCreateProposalCreateAccountFee() { - //2:CREATE_ACCOUNT_FEE,[0,100 000 000 000 000 000]//drop - //Minimum CreateAccountFee + // 2:CREATE_ACCOUNT_FEE,[0,100 000 000 000 000 000]//drop + // Minimum CreateAccountFee HashMap proposalMap = new HashMap(); proposalMap.put(2L, 0L); - Assert.assertTrue(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Maximum CreateAccountFee + // Maximum CreateAccountFee proposalMap.put(2L, 100000000000000000L); - Assert.assertTrue(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Minimum - 1 CreateAccountFee + // Minimum - 1 CreateAccountFee proposalMap.put(2L, -1L); - Assert.assertFalse(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertFalse( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Maximum + 1 CreateAccountFee + // Maximum + 1 CreateAccountFee proposalMap.put(2L, 100000000000000001L); - Assert.assertFalse(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertFalse( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Non witness account + // Non witness account proposalMap.put(2L, 86400000L); - Assert.assertFalse(PublicMethod.createProposal(toAddress, testKey003, - proposalMap, blockingStubFull)); - + Assert.assertFalse( + PublicMethod.createProposal(toAddress, testKey003, proposalMap, blockingStubFull)); } @Test(enabled = true) public void testTransactionFee() { - //3:TRANSACTION_FEE,[0,100 000 000 000 000 000]//drop - //Minimum TransactionFee + // 3:TRANSACTION_FEE,[0,100 000 000 000 000 000]//drop + // Minimum TransactionFee HashMap proposalMap = new HashMap(); proposalMap.put(3L, 0L); - Assert.assertTrue(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Maximum TransactionFee + // Maximum TransactionFee proposalMap.put(3L, 100000000000000000L); - Assert.assertTrue(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Minimum - 1 TransactionFee + // Minimum - 1 TransactionFee proposalMap.put(3L, -1L); - Assert.assertFalse(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertFalse( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Maximum + 1 TransactionFee + // Maximum + 1 TransactionFee proposalMap.put(3L, 100000000000000001L); - Assert.assertFalse(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertFalse( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Non witness account + // Non witness account proposalMap.put(3L, 86400000L); - Assert.assertFalse(PublicMethod.createProposal(toAddress, testKey003, - proposalMap, blockingStubFull)); - + Assert.assertFalse( + PublicMethod.createProposal(toAddress, testKey003, proposalMap, blockingStubFull)); } @Test(enabled = true) public void testAssetIssueFee() { - //4:ASSET_ISSUE_FEE,[0,100 000 000 000 000 000]//drop - //Minimum AssetIssueFee + // 4:ASSET_ISSUE_FEE,[0,100 000 000 000 000 000]//drop + // Minimum AssetIssueFee HashMap proposalMap = new HashMap(); proposalMap.put(4L, 0L); - Assert.assertTrue(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Duplicat proposals + // Duplicat proposals proposalMap.put(4L, 0L); - Assert.assertTrue(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Maximum AssetIssueFee + // Maximum AssetIssueFee proposalMap.put(4L, 100000000000000000L); - Assert.assertTrue(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Minimum - 1 AssetIssueFee + // Minimum - 1 AssetIssueFee proposalMap.put(4L, -1L); - Assert.assertFalse(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertFalse( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Maximum + 1 AssetIssueFee + // Maximum + 1 AssetIssueFee proposalMap.put(4L, 100000000000000001L); - Assert.assertFalse(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertFalse( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Non witness account + // Non witness account proposalMap.put(4L, 86400000L); - Assert.assertFalse(PublicMethod.createProposal(toAddress, testKey003, - proposalMap, blockingStubFull)); - + Assert.assertFalse( + PublicMethod.createProposal(toAddress, testKey003, proposalMap, blockingStubFull)); } @Test(enabled = true) public void testWitnessPayPerBlock() { - //5:WITNESS_PAY_PER_BLOCK,[0,100 000 000 000 000 000]//drop - //Minimum WitnessPayPerBlock + // 5:WITNESS_PAY_PER_BLOCK,[0,100 000 000 000 000 000]//drop + // Minimum WitnessPayPerBlock HashMap proposalMap = new HashMap(); proposalMap.put(5L, 0L); - Assert.assertTrue(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Maximum WitnessPayPerBlock + // Maximum WitnessPayPerBlock proposalMap.put(5L, 100000000000000000L); - Assert.assertTrue(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Minimum - 1 WitnessPayPerBlock + // Minimum - 1 WitnessPayPerBlock proposalMap.put(5L, -1L); - Assert.assertFalse(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertFalse( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Maximum + 1 WitnessPayPerBlock + // Maximum + 1 WitnessPayPerBlock proposalMap.put(5L, 100000000000000001L); - Assert.assertFalse(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertFalse( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Non witness account + // Non witness account proposalMap.put(5L, 86400000L); - Assert.assertFalse(PublicMethod.createProposal(toAddress, testKey003, - proposalMap, blockingStubFull)); - + Assert.assertFalse( + PublicMethod.createProposal(toAddress, testKey003, proposalMap, blockingStubFull)); } @Test(enabled = true) public void testWitnessStandbyAllowance() { - //6:WITNESS_STANDBY_ALLOWANCE,[0,100 000 000 000 000 000]//drop - //Minimum WitnessStandbyAllowance + // 6:WITNESS_STANDBY_ALLOWANCE,[0,100 000 000 000 000 000]//drop + // Minimum WitnessStandbyAllowance HashMap proposalMap = new HashMap(); proposalMap.put(6L, 0L); - Assert.assertTrue(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Maximum WitnessStandbyAllowance + // Maximum WitnessStandbyAllowance proposalMap.put(6L, 100000000000000000L); - Assert.assertTrue(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Minimum - 1 WitnessStandbyAllowance + // Minimum - 1 WitnessStandbyAllowance proposalMap.put(6L, -1L); - Assert.assertFalse(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertFalse( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Maximum + 1 WitnessStandbyAllowance + // Maximum + 1 WitnessStandbyAllowance proposalMap.put(6L, 100000000000000001L); - Assert.assertFalse(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertFalse( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Non witness account + // Non witness account proposalMap.put(6L, 86400000L); - Assert.assertFalse(PublicMethod.createProposal(toAddress, testKey003, - proposalMap, blockingStubFull)); - + Assert.assertFalse( + PublicMethod.createProposal(toAddress, testKey003, proposalMap, blockingStubFull)); } @Test(enabled = true) public void testCreateNewAccountFeeInSystemControl() { - //7:CREATE_NEW_ACCOUNT_FEE_IN_SYSTEM_CONTRACT,0 or 1 + // 7:CREATE_NEW_ACCOUNT_FEE_IN_SYSTEM_CONTRACT,0 or 1 HashMap proposalMap = new HashMap(); proposalMap.put(7L, 1L); - Assert.assertTrue(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Maximum WitnessStandbyAllowance + // Maximum WitnessStandbyAllowance proposalMap.put(7L, 100000000000000000L); - Assert.assertTrue(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Minimum - 1 WitnessStandbyAllowance + // Minimum - 1 WitnessStandbyAllowance proposalMap.put(6L, -1L); - Assert.assertFalse(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertFalse( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Maximum + 1 WitnessStandbyAllowance + // Maximum + 1 WitnessStandbyAllowance proposalMap.put(6L, 100000000000000001L); - Assert.assertFalse(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertFalse( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //Non witness account + // Non witness account proposalMap.put(6L, 86400000L); - Assert.assertFalse(PublicMethod.createProposal(toAddress, testKey003, - proposalMap, blockingStubFull)); - + Assert.assertFalse( + PublicMethod.createProposal(toAddress, testKey003, proposalMap, blockingStubFull)); } @Test(enabled = true) @@ -292,14 +289,12 @@ public void testInvalidProposals() { // The index isn't from 0-9 HashMap proposalMap = new HashMap(); proposalMap.put(10L, 60L); - Assert.assertFalse(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertFalse( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); - //The index is -1 + // The index is -1 proposalMap.put(-1L, 6L); - Assert.assertFalse(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); - + Assert.assertFalse( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); } } - diff --git a/testcase/src/test/java/stest/tron/wallet/committee/WalletTestCommittee003.java b/testcase/src/test/java/stest/tron/wallet/committee/WalletTestCommittee003.java index 399d2c5c..062f1abd 100644 --- a/testcase/src/test/java/stest/tron/wallet/committee/WalletTestCommittee003.java +++ b/testcase/src/test/java/stest/tron/wallet/committee/WalletTestCommittee003.java @@ -1,6 +1,5 @@ package stest.tron.wallet.committee; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.HashMap; import java.util.Optional; @@ -21,100 +20,100 @@ public class WalletTestCommittee003 extends TronBaseTest { private static final long now = System.currentTimeMillis(); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); - //Witness 47.93.33.201 - //Witness 123.56.10.6 - //Wtiness 39.107.80.135 - //Witness 47.93.184.2 + // Witness 47.93.33.201 + // Witness 123.56.10.6 + // Wtiness 39.107.80.135 + // Witness 47.93.184.2 private final byte[] witness001Address = PublicMethod.getFinalAddress(witnessKey); - //private final byte[] witness003Address = PublicMethod.getFinalAddress(witnessKey3); - //private final byte[] witness004Address = PublicMethod.getFinalAddress(witnessKey4); - //private final byte[] witness005Address = PublicMethod.getFinalAddress(witnessKey5); + // private final byte[] witness003Address = PublicMethod.getFinalAddress(witnessKey3); + // private final byte[] witness004Address = PublicMethod.getFinalAddress(witnessKey4); + // private final byte[] witness005Address = PublicMethod.getFinalAddress(witnessKey5); private final byte[] witness002Address = PublicMethod.getFinalAddress(witnessKey2); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void testApproveProposal() { - PublicMethod.sendcoin(witness001Address, 1000000L, - toAddress, testKey003, blockingStubFull); - PublicMethod.sendcoin(witness002Address, 1000000L, - toAddress, testKey003, blockingStubFull); + PublicMethod.sendcoin(witness001Address, 1000000L, toAddress, testKey003, blockingStubFull); + PublicMethod.sendcoin(witness002Address, 1000000L, toAddress, testKey003, blockingStubFull); HashMap proposalMap = new HashMap(); proposalMap.put(0L, 81000L); - Assert.assertTrue(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Get proposal list + // Get proposal list ProposalList proposalList = blockingStubFull.listProposals(EmptyMessage.newBuilder().build()); Optional listProposals = Optional.ofNullable(proposalList); - final Integer proposalId = listProposals.get().getProposalsCount(); + final Integer proposalId = listProposals.get().getProposalsCount(); logger.info(Integer.toString(proposalId)); - Assert.assertTrue(PublicMethod.approveProposal(witness002Address, witnessKey2, proposalId, - true, blockingStubFull)); + Assert.assertTrue( + PublicMethod.approveProposal( + witness002Address, witnessKey2, proposalId, true, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Get proposal list after approve + // Get proposal list after approve proposalList = blockingStubFull.listProposals(EmptyMessage.newBuilder().build()); listProposals = Optional.ofNullable(proposalList); logger.info(Integer.toString(listProposals.get().getProposals(0).getApprovalsCount())); Assert.assertTrue(listProposals.get().getProposals(0).getApprovalsCount() == 1); - //logger.info(Base58.encode58Check(witness002Address)); - //logger.info(Base58.encode58Check(listProposals.get().getProposals(0). + // logger.info(Base58.encode58Check(witness002Address)); + // logger.info(Base58.encode58Check(listProposals.get().getProposals(0). // getApprovalsList().get(0).toByteArray())); - Assert.assertTrue(Base58.encode58Check(witness002Address).equals(Base58.encode58Check( - listProposals.get().getProposals(0).getApprovalsList().get(0).toByteArray()))); - //Failed to approve proposal when you already approval this proposal - Assert.assertFalse(PublicMethod.approveProposal(witness002Address, witnessKey2, proposalId, - true, blockingStubFull)); - //Success to change the option from true to false. - Assert.assertTrue(PublicMethod.approveProposal(witness002Address, witnessKey2, proposalId, - false, blockingStubFull)); + Assert.assertTrue( + Base58.encode58Check(witness002Address) + .equals( + Base58.encode58Check( + listProposals.get().getProposals(0).getApprovalsList().get(0).toByteArray()))); + // Failed to approve proposal when you already approval this proposal + Assert.assertFalse( + PublicMethod.approveProposal( + witness002Address, witnessKey2, proposalId, true, blockingStubFull)); + // Success to change the option from true to false. + Assert.assertTrue( + PublicMethod.approveProposal( + witness002Address, witnessKey2, proposalId, false, blockingStubFull)); proposalList = blockingStubFull.listProposals(EmptyMessage.newBuilder().build()); listProposals = Optional.ofNullable(proposalList); Assert.assertTrue(listProposals.get().getProposals(0).getApprovalsCount() == 0); - //Failed to approvel proposal when you already approval this proposal - Assert.assertFalse(PublicMethod.approveProposal(witness002Address, witnessKey2, proposalId, - false, blockingStubFull)); - //Non witness can't approval proposal - Assert.assertFalse(PublicMethod.approveProposal(toAddress, testKey003, proposalId, - true, blockingStubFull)); - //Muti approval - Assert.assertTrue(PublicMethod.approveProposal(witness001Address, witnessKey, proposalId, - true, blockingStubFull)); - Assert.assertTrue(PublicMethod.approveProposal(witness002Address, witnessKey2, proposalId, - true, blockingStubFull)); - //Assert.assertTrue(PublicMethod.approveProposal(witness003Address,witnessKey3,proposalId, + // Failed to approvel proposal when you already approval this proposal + Assert.assertFalse( + PublicMethod.approveProposal( + witness002Address, witnessKey2, proposalId, false, blockingStubFull)); + // Non witness can't approval proposal + Assert.assertFalse( + PublicMethod.approveProposal(toAddress, testKey003, proposalId, true, blockingStubFull)); + // Muti approval + Assert.assertTrue( + PublicMethod.approveProposal( + witness001Address, witnessKey, proposalId, true, blockingStubFull)); + Assert.assertTrue( + PublicMethod.approveProposal( + witness002Address, witnessKey2, proposalId, true, blockingStubFull)); + // Assert.assertTrue(PublicMethod.approveProposal(witness003Address,witnessKey3,proposalId, // true,blockingStubFull)); - //Assert.assertTrue(PublicMethod.approveProposal(witness004Address,witnessKey4,proposalId, + // Assert.assertTrue(PublicMethod.approveProposal(witness004Address,witnessKey4,proposalId, // true,blockingStubFull)); - //Assert.assertTrue(PublicMethod.approveProposal(witness005Address,witnessKey5,proposalId, + // Assert.assertTrue(PublicMethod.approveProposal(witness005Address,witnessKey5,proposalId, // true,blockingStubFull)); proposalList = blockingStubFull.listProposals(EmptyMessage.newBuilder().build()); listProposals = Optional.ofNullable(proposalList); Assert.assertTrue(listProposals.get().getProposals(0).getApprovalsCount() == 2); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - diff --git a/testcase/src/test/java/stest/tron/wallet/committee/WalletTestCommittee004.java b/testcase/src/test/java/stest/tron/wallet/committee/WalletTestCommittee004.java index 8a17e521..89a5afd4 100644 --- a/testcase/src/test/java/stest/tron/wallet/committee/WalletTestCommittee004.java +++ b/testcase/src/test/java/stest/tron/wallet/committee/WalletTestCommittee004.java @@ -1,7 +1,6 @@ package stest.tron.wallet.committee; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.HashMap; import java.util.Optional; @@ -17,7 +16,7 @@ import org.tron.protos.Protocol.ChainParameters; import org.tron.protos.Protocol.Proposal; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; @@ -25,118 +24,126 @@ public class WalletTestCommittee004 extends TronBaseTest { private static final long now = System.currentTimeMillis(); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); - //Witness 47.93.33.201 - //Witness 123.56.10.6 - //Wtiness 39.107.80.135 - //Witness 47.93.184.2 + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); + // Witness 47.93.33.201 + // Witness 123.56.10.6 + // Wtiness 39.107.80.135 + // Witness 47.93.184.2 private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); private final byte[] witness001Address = PublicMethod.getFinalAddress(witnessKey); - //private final byte[] witness003Address = PublicMethod.getFinalAddress(witnessKey3); - //private final byte[] witness004Address = PublicMethod.getFinalAddress(witnessKey4); - //private final byte[] witness005Address = PublicMethod.getFinalAddress(witnessKey5); + // private final byte[] witness003Address = PublicMethod.getFinalAddress(witnessKey3); + // private final byte[] witness004Address = PublicMethod.getFinalAddress(witnessKey4); + // private final byte[] witness005Address = PublicMethod.getFinalAddress(witnessKey5); private final byte[] witness002Address = PublicMethod.getFinalAddress(witnessKey2); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void test1DeleteProposal() { - PublicMethod.sendcoin(witness001Address, 1000000L, - toAddress, testKey003, blockingStubFull); - PublicMethod.sendcoin(witness002Address, 1000000L, - toAddress, testKey003, blockingStubFull); + PublicMethod.sendcoin(witness001Address, 1000000L, toAddress, testKey003, blockingStubFull); + PublicMethod.sendcoin(witness002Address, 1000000L, toAddress, testKey003, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Create a proposal and approval it + // Create a proposal and approval it HashMap proposalMap = new HashMap(); proposalMap.put(1L, 99999L); - Assert.assertTrue(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } - //Get proposal list + // Get proposal list ProposalList proposalList = blockingStubFull.listProposals(EmptyMessage.newBuilder().build()); Optional listProposals = Optional.ofNullable(proposalList); - final Integer proposalId = listProposals.get().getProposalsCount(); - Assert.assertTrue(PublicMethod.approveProposal(witness001Address, witnessKey, - proposalId, true, blockingStubFull)); + final Integer proposalId = listProposals.get().getProposalsCount(); + Assert.assertTrue( + PublicMethod.approveProposal( + witness001Address, witnessKey, proposalId, true, blockingStubFull)); logger.info(Integer.toString(listProposals.get().getProposals(0).getStateValue())); - //The state is "pending", state value == 0 + // The state is "pending", state value == 0 Assert.assertTrue(listProposals.get().getProposals(0).getStateValue() == 0); - //When the proposal isn't created by you, you can't delete it. - Assert.assertFalse(PublicMethod.deleteProposal(witness002Address, witnessKey2, - proposalId, blockingStubFull)); - //Cancel the proposal - Assert.assertTrue(PublicMethod.deleteProposal(witness001Address, witnessKey, - proposalId, blockingStubFull)); - //When the state is cancel, you can't delete it again. - Assert.assertFalse(PublicMethod.deleteProposal(witness001Address, witnessKey, - proposalId, blockingStubFull)); - //You can't delete an invalid proposal - Assert.assertFalse(PublicMethod.deleteProposal(witness001Address, witnessKey, - proposalId + 100, blockingStubFull)); + // When the proposal isn't created by you, you can't delete it. + Assert.assertFalse( + PublicMethod.deleteProposal(witness002Address, witnessKey2, proposalId, blockingStubFull)); + // Cancel the proposal + Assert.assertTrue( + PublicMethod.deleteProposal(witness001Address, witnessKey, proposalId, blockingStubFull)); + // When the state is cancel, you can't delete it again. + Assert.assertFalse( + PublicMethod.deleteProposal(witness001Address, witnessKey, proposalId, blockingStubFull)); + // You can't delete an invalid proposal + Assert.assertFalse( + PublicMethod.deleteProposal( + witness001Address, witnessKey, proposalId + 100, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); proposalList = blockingStubFull.listProposals(EmptyMessage.newBuilder().build()); listProposals = Optional.ofNullable(proposalList); logger.info(Integer.toString(listProposals.get().getProposals(0).getStateValue())); - //The state is "cancel", state value == 3 + // The state is "cancel", state value == 3 Assert.assertTrue(listProposals.get().getProposals(0).getStateValue() == 3); - //When the state is cancel, you can't approval proposal - Assert.assertFalse(PublicMethod.approveProposal(witness001Address, witnessKey, - proposalId, true, blockingStubFull)); - Assert.assertFalse(PublicMethod.approveProposal(witness001Address, witnessKey, - proposalId, false, blockingStubFull)); + // When the state is cancel, you can't approval proposal + Assert.assertFalse( + PublicMethod.approveProposal( + witness001Address, witnessKey, proposalId, true, blockingStubFull)); + Assert.assertFalse( + PublicMethod.approveProposal( + witness001Address, witnessKey, proposalId, false, blockingStubFull)); } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void test2GetProposal() { - //Create a proposal and approval it + // Create a proposal and approval it HashMap proposalMap = new HashMap(); proposalMap.put(1L, 999999999L); - Assert.assertTrue(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); - //Get proposal list + Assert.assertTrue( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); + // Get proposal list ProposalList proposalList = blockingStubFull.listProposals(EmptyMessage.newBuilder().build()); Optional listProposals = Optional.ofNullable(proposalList); - final Integer proposalId = listProposals.get().getProposalsCount(); + final Integer proposalId = listProposals.get().getProposalsCount(); - BytesMessage request = BytesMessage.newBuilder().setValue(ByteString.copyFrom( - ByteArray.fromLong(Long.parseLong(proposalId.toString())))) - .build(); + BytesMessage request = + BytesMessage.newBuilder() + .setValue( + ByteString.copyFrom(ByteArray.fromLong(Long.parseLong(proposalId.toString())))) + .build(); Proposal proposal = blockingStubFull.getProposalById(request); Optional getProposal = Optional.ofNullable(proposal); Assert.assertTrue(getProposal.isPresent()); Assert.assertTrue(getProposal.get().getStateValue() == 0); - //Invalid get proposal + // Invalid get proposal final Integer wrongProposalId = proposalId + 99; - request = BytesMessage.newBuilder().setValue(ByteString.copyFrom( - ByteArray.fromLong(Long.parseLong(wrongProposalId.toString())))) - .build(); + request = + BytesMessage.newBuilder() + .setValue( + ByteString.copyFrom(ByteArray.fromLong(Long.parseLong(wrongProposalId.toString())))) + .build(); proposal = blockingStubFull.getProposalById(request); getProposal = Optional.ofNullable(proposal); logger.info(Long.toString(getProposal.get().getCreateTime())); Assert.assertTrue(getProposal.get().getCreateTime() == 0); } - @Test(enabled = false, groups = {"smoke"}) + @Test( + enabled = false, + groups = {"smoke"}) public void testGetChainParameters() { - //Set the default map + // Set the default map HashMap defaultCommitteeMap = new HashMap(); defaultCommitteeMap.put("MAINTENANCE_TIME_INTERVAL", 300000L); defaultCommitteeMap.put("ACCOUNT_UPGRADE_COST", 9999000000L); @@ -148,8 +155,8 @@ public void testGetChainParameters() { defaultCommitteeMap.put("CREATE_NEW_ACCOUNT_FEE_IN_SYSTEM_CONTRACT", 0L); defaultCommitteeMap.put("CREATE_NEW_ACCOUNT_BANDWIDTH_RATE", 1L); - ChainParameters chainParameters = blockingStubFull - .getChainParameters(EmptyMessage.newBuilder().build()); + ChainParameters chainParameters = + blockingStubFull.getChainParameters(EmptyMessage.newBuilder().build()); Optional getChainParameters = Optional.ofNullable(chainParameters); logger.info(Long.toString(getChainParameters.get().getChainParameterCount())); for (Integer i = 0; i < getChainParameters.get().getChainParameterCount(); i++) { @@ -157,20 +164,13 @@ public void testGetChainParameters() { logger.info(Long.toString(getChainParameters.get().getChainParameter(i).getValue())); } Assert.assertTrue(getChainParameters.get().getChainParameterCount() >= 10); - Assert.assertTrue(getChainParameters.get() - .getChainParameter(1).getValue() == 9999000000L); - Assert.assertTrue(getChainParameters.get().getChainParameter(4) - .getValue() == 1024000000L); + Assert.assertTrue(getChainParameters.get().getChainParameter(1).getValue() == 9999000000L); + Assert.assertTrue(getChainParameters.get().getChainParameter(4).getValue() == 1024000000L); Assert.assertTrue(getChainParameters.get().getChainParameter(7).getValue() == 0); Assert.assertTrue(getChainParameters.get().getChainParameter(8).getValue() == 1); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/Configuration.java b/testcase/src/test/java/stest/tron/wallet/common/client/Configuration.java index 9d0cdd05..959f062d 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/Configuration.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/Configuration.java @@ -11,16 +11,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; - public class Configuration { private static final Logger logger = LoggerFactory.getLogger("Configuration"); private static Config config; - /** - * constructor. - */ - + /** constructor. */ public static Config getByPath(final String configurationPath) { if (isBlank(configurationPath)) { throw new IllegalArgumentException("Configuration path is required!"); @@ -30,8 +26,9 @@ public static Config getByPath(final String configurationPath) { File configFile = new File(System.getProperty("user.dir") + '/' + configurationPath); if (configFile.exists()) { try { - config = ConfigFactory - .parseReader(new InputStreamReader(new FileInputStream(configurationPath))); + config = + ConfigFactory.parseReader( + new InputStreamReader(new FileInputStream(configurationPath))); logger.info("use user defined config file in current dir"); } catch (FileNotFoundException e) { logger.error("load user defined config file exception: " + e.getMessage()); diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/GrpcClient.java b/testcase/src/test/java/stest/tron/wallet/common/client/GrpcClient.java index 862add72..05dd121e 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/GrpcClient.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/GrpcClient.java @@ -35,7 +35,6 @@ import org.tron.protos.contract.WitnessContract; import stest.tron.wallet.common.client.utils.ByteArray; - public class GrpcClient { private ManagedChannel channelFull = null; @@ -51,30 +50,20 @@ public class GrpcClient { // blockingStub = WalletGrpc.newBlockingStub(channel); // } - /** - * constructor. - */ - + /** constructor. */ public GrpcClient(String fullnode, String soliditynode) { if (!(fullnode.isEmpty())) { - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext() - .build(); + channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); blockingStubFull = WalletGrpc.newBlockingStub(channelFull); } if (!(soliditynode.isEmpty())) { - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); blockingStubExtension = WalletExtensionGrpc.newBlockingStub(channelSolidity); } } - /** - * constructor. - */ - + /** constructor. */ public void shutdown() throws InterruptedException { if (channelFull != null) { channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); @@ -84,10 +73,7 @@ public void shutdown() throws InterruptedException { } } - /** - * constructor. - */ - + /** constructor. */ public Account queryAccount(byte[] address) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); @@ -149,20 +135,14 @@ public boolean broadcastTransaction(Transaction signaturedTransaction) { return response.getResult(); } - /** - * constructor. - */ - + /** constructor. */ public AccountNetMessage getAccountNet(byte[] address) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccountNet(request); } - /** - * constructor. - */ - + /** constructor. */ public Block getBlock(long blockNum) { if (blockNum < 0) { if (blockingStubSolidity != null) { @@ -181,75 +161,61 @@ public Block getBlock(long blockNum) { } /* public Optional listAccounts() { - if(blockingStubSolidity != null) { - AccountList accountList = blockingStubSolidity.listAccounts( - EmptyMessage.newBuilder().build()); - return Optional.ofNullable(accountList); - }else{ - AccountList accountList = blockingStubFull.listAccounts( - EmptyMessage.newBuilder().build()); - return Optional.ofNullable(accountList); - } - }*/ - - /** - * constructor. - */ + if(blockingStubSolidity != null) { + AccountList accountList = blockingStubSolidity.listAccounts( + EmptyMessage.newBuilder().build()); + return Optional.ofNullable(accountList); + }else{ + AccountList accountList = blockingStubFull.listAccounts( + EmptyMessage.newBuilder().build()); + return Optional.ofNullable(accountList); + } + }*/ + + /** constructor. */ public Optional listWitnesses() { if (blockingStubSolidity != null) { - WitnessList witnessList = blockingStubSolidity.listWitnesses( - EmptyMessage.newBuilder().build()); + WitnessList witnessList = + blockingStubSolidity.listWitnesses(EmptyMessage.newBuilder().build()); return Optional.ofNullable(witnessList); } else { - WitnessList witnessList = blockingStubFull.listWitnesses( - EmptyMessage.newBuilder().build()); + WitnessList witnessList = blockingStubFull.listWitnesses(EmptyMessage.newBuilder().build()); return Optional.ofNullable(witnessList); } } - /** - * constructor. - */ - + /** constructor. */ public Optional getAssetIssueList(long offset, long limit) { PaginatedMessage.Builder pageMessageBuilder = PaginatedMessage.newBuilder(); pageMessageBuilder.setOffset(offset); pageMessageBuilder.setLimit(limit); if (blockingStubSolidity != null) { - AssetIssueList assetIssueList = blockingStubSolidity - .getPaginatedAssetIssueList(pageMessageBuilder.build()); + AssetIssueList assetIssueList = + blockingStubSolidity.getPaginatedAssetIssueList(pageMessageBuilder.build()); return Optional.ofNullable(assetIssueList); } else { - AssetIssueList assetIssueList = blockingStubFull - .getPaginatedAssetIssueList(pageMessageBuilder.build()); + AssetIssueList assetIssueList = + blockingStubFull.getPaginatedAssetIssueList(pageMessageBuilder.build()); return Optional.ofNullable(assetIssueList); } } - - /** - * constructor. - */ - + /** constructor. */ public Optional getAssetIssueList() { if (blockingStubSolidity != null) { - AssetIssueList assetIssueList = blockingStubSolidity - .getAssetIssueList(EmptyMessage.newBuilder().build()); + AssetIssueList assetIssueList = + blockingStubSolidity.getAssetIssueList(EmptyMessage.newBuilder().build()); return Optional.ofNullable(assetIssueList); } else { - AssetIssueList assetIssueList = blockingStubFull - .getAssetIssueList(EmptyMessage.newBuilder().build()); + AssetIssueList assetIssueList = + blockingStubFull.getAssetIssueList(EmptyMessage.newBuilder().build()); return Optional.ofNullable(assetIssueList); } } - /** - * constructor. - */ - + /** constructor. */ public Optional listNodes() { - NodeList nodeList = blockingStubFull - .listNodes(EmptyMessage.newBuilder().build()); + NodeList nodeList = blockingStubFull.listNodes(EmptyMessage.newBuilder().build()); return Optional.ofNullable(nodeList); } @@ -267,63 +233,57 @@ public Optional listNodes() { } }*/ /* public AssetIssueContract getAssetIssueByName(String assetName) { - ByteString assetNameBs = ByteString.copyFrom(assetName.getBytes()); - BytesMessage request = BytesMessage.newBuilder().setValue(assetNameBs).build(); - if(blockingStubSolidity != null) { - return blockingStubSolidity.getAssetIssueByName(request); - } else { - return blockingStubFull.getAssetIssueByName(request); - } - }*/ + ByteString assetNameBs = ByteString.copyFrom(assetName.getBytes()); + BytesMessage request = BytesMessage.newBuilder().setValue(assetNameBs).build(); + if(blockingStubSolidity != null) { + return blockingStubSolidity.getAssetIssueByName(request); + } else { + return blockingStubFull.getAssetIssueByName(request); + } + }*/ /* public NumberMessage getTotalTransaction() { - if(blockingStubSolidity != null) { - return blockingStubSolidity.totalTransaction(EmptyMessage.newBuilder().build()); - } else { - return blockingStubFull.totalTransaction(EmptyMessage.newBuilder().build()); - } - }*/ + if(blockingStubSolidity != null) { + return blockingStubSolidity.totalTransaction(EmptyMessage.newBuilder().build()); + } else { + return blockingStubFull.totalTransaction(EmptyMessage.newBuilder().build()); + } + }*/ /* public Optional getAssetIssueListByTimestamp(long time) { - NumberMessage.Builder timeStamp = NumberMessage.newBuilder(); - timeStamp.setNum(time); - AssetIssueList assetIssueList = blockingStubSolidity - .getAssetIssueListByTimestamp(timeStamp.build()); - return Optional.ofNullable(assetIssueList); - }*/ + NumberMessage.Builder timeStamp = NumberMessage.newBuilder(); + timeStamp.setNum(time); + AssetIssueList assetIssueList = blockingStubSolidity + .getAssetIssueListByTimestamp(timeStamp.build()); + return Optional.ofNullable(assetIssueList); + }*/ /* public Optional getTransactionsByTimestamp( - long start, long end, int offset , int limit) { - TimeMessage.Builder timeMessage = TimeMessage.newBuilder(); - timeMessage.setBeginInMilliseconds(start); - timeMessage.setEndInMilliseconds(end); - TimePaginatedMessage.Builder timePageMessage = TimePaginatedMessage.newBuilder(); - timePageMessage.setTimeMessage(timeMessage); - timePageMessage.setOffset(offset); - timePageMessage.setLimit(limit); - TransactionList transactionList = blockingStubExtension - .getTransactionsByTimestamp(timePageMessage.build()); - return Optional.ofNullable(transactionList); - }*/ - - /** - * constructor. - */ + long start, long end, int offset , int limit) { + TimeMessage.Builder timeMessage = TimeMessage.newBuilder(); + timeMessage.setBeginInMilliseconds(start); + timeMessage.setEndInMilliseconds(end); + TimePaginatedMessage.Builder timePageMessage = TimePaginatedMessage.newBuilder(); + timePageMessage.setTimeMessage(timeMessage); + timePageMessage.setOffset(offset); + timePageMessage.setLimit(limit); + TransactionList transactionList = blockingStubExtension + .getTransactionsByTimestamp(timePageMessage.build()); + return Optional.ofNullable(transactionList); + }*/ + /** constructor. */ public Optional getTransactionsFromThis(byte[] address) { ByteString addressBs = ByteString.copyFrom(address); Account account = Account.newBuilder().setAddress(addressBs).build(); AccountPaginated.Builder builder = AccountPaginated.newBuilder().setAccount(account); builder.setLimit(1000); builder.setOffset(0); - TransactionList transactionList = blockingStubExtension - .getTransactionsFromThis(builder.build()); + TransactionList transactionList = + blockingStubExtension.getTransactionsFromThis(builder.build()); return Optional.ofNullable(transactionList); } - /** - * constructor. - */ - + /** constructor. */ public Optional getTransactionsToThis(byte[] address) { ByteString addressBs = ByteString.copyFrom(address); Account account = Account.newBuilder().setAddress(addressBs).build(); @@ -335,22 +295,18 @@ public Optional getTransactionsToThis(byte[] address) { } /* public Optional getTransactionById(String txID){ - ByteString bsTxid = ByteString.copyFrom(ByteArray.fromHexString(txID)); - BytesMessage request = BytesMessage.newBuilder().setValue(bsTxid).build(); - if(blockingStubSolidity != null) { - Transaction transaction = blockingStubSolidity.getTransactionById(request); - return Optional.ofNullable(transaction); - } else { - Transaction transaction = blockingStubFull.getTransactionById(request); - return Optional.ofNullable(transaction); - } - }*/ - - - /** - * constructor. - */ + ByteString bsTxid = ByteString.copyFrom(ByteArray.fromHexString(txID)); + BytesMessage request = BytesMessage.newBuilder().setValue(bsTxid).build(); + if(blockingStubSolidity != null) { + Transaction transaction = blockingStubSolidity.getTransactionById(request); + return Optional.ofNullable(transaction); + } else { + Transaction transaction = blockingStubFull.getTransactionById(request); + return Optional.ofNullable(transaction); + } + }*/ + /** constructor. */ public Optional getBlockById(String blockId) { ByteString bsTxid = ByteString.copyFrom(ByteArray.fromHexString(blockId)); BytesMessage request = BytesMessage.newBuilder().setValue(bsTxid).build(); @@ -358,10 +314,7 @@ public Optional getBlockById(String blockId) { return Optional.ofNullable(block); } - /** - * constructor. - */ - + /** constructor. */ public Optional getBlockByLimitNext(long start, long end) { BlockLimit.Builder builder = BlockLimit.newBuilder(); builder.setStartNum(start); @@ -370,10 +323,7 @@ public Optional getBlockByLimitNext(long start, long end) { return Optional.ofNullable(blockList); } - /** - * constructor. - */ - + /** constructor. */ public Optional getBlockByLatestNum(long num) { NumberMessage numberMessage = NumberMessage.newBuilder().setNum(num).build(); BlockList blockList = blockingStubFull.getBlockByLatestNum(numberMessage); diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/Parameter.java b/testcase/src/test/java/stest/tron/wallet/common/client/Parameter.java index 8fead433..df645d0f 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/Parameter.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/Parameter.java @@ -4,11 +4,11 @@ public interface Parameter { interface CommonConstant { - byte ADD_PRE_FIX_BYTE = (byte) 0xa0; //a0 + address ,a0 is version + byte ADD_PRE_FIX_BYTE = (byte) 0xa0; // a0 + address ,a0 is version String ADD_PRE_FIX_STRING = "a0"; int ADDRESS_SIZE = 21; int BASE58CHECK_ADDRESS_SIZE = 35; - byte ADD_PRE_FIX_BYTE_MAINNET = (byte) 0x41; //41 + address - byte ADD_PRE_FIX_BYTE_TESTNET = (byte) 0xa0; //a0 + address + byte ADD_PRE_FIX_BYTE_MAINNET = (byte) 0x41; // 41 + address + byte ADD_PRE_FIX_BYTE_TESTNET = (byte) 0xa0; // a0 + address } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/WalletClient.java b/testcase/src/test/java/stest/tron/wallet/common/client/WalletClient.java index 934a2e3e..0cf6b5af 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/WalletClient.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/WalletClient.java @@ -45,9 +45,9 @@ import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.exception.CancelException; -//import org.tron.core.exception.CipherException; +// import org.tron.core.exception.CipherException; -//import org.tron.common.utils.Sha256Hash; +// import org.tron.common.utils.Sha256Hash; public class WalletClient { @@ -60,19 +60,14 @@ public class WalletClient { private ECKey ecKey = null; private boolean loginState = false; - /** - * Creates a new WalletClient with a random ECKey or no ECKey. - */ - + /** Creates a new WalletClient with a random ECKey or no ECKey. */ public WalletClient(boolean genEcKey) { if (genEcKey) { this.ecKey = new ECKey(Utils.getRandom()); } } - /** - * constructor. - */ + /** constructor. */ // Create Wallet with a pritKey public WalletClient(String priKey) { @@ -86,18 +81,12 @@ public WalletClient(String priKey) { this.ecKey = temKey; } - /** - * Creates a Wallet with an existing ECKey. - */ - + /** Creates a Wallet with an existing ECKey. */ public WalletClient(final ECKey ecKey) { this.ecKey = ecKey; } - /** - * constructor. - */ - + /** constructor. */ public static boolean init(int itype) { Config config = Configuration.getByPath("testng.conf"); dbPath = config.getString("CityDb.DbPath"); @@ -127,12 +116,9 @@ public static boolean init(int itype) { return true; } - /** - * constructor. - */ - + /** constructor. */ public static GrpcClient init() { - //Config config = org.tron.core.config.Configuration.getByPath("config.conf"); + // Config config = org.tron.core.config.Configuration.getByPath("config.conf"); Config config = Configuration.getByPath("testng.conf"); dbPath = config.getString("CityDb.DbPath"); txtPath = System.getProperty("user.dir") + "/" + config.getString("CityDb.TxtPath"); @@ -161,10 +147,7 @@ public static void setAddressPreFixByte(byte addressPreFixByte) { WalletClient.addressPreFixByte = addressPreFixByte; } - /** - * constructor. - */ - + /** constructor. */ public static String selectFullNode() { Map witnessMap = new HashMap<>(); Config config = Configuration.getByPath("config.conf"); @@ -206,48 +189,32 @@ public static String getTxtPath() { } public static Account queryAccount(byte[] address) { - return rpcCli.queryAccount(address);//call rpc + return rpcCli.queryAccount(address); // call rpc } - - - /** - * constructor. - */ - - public static Transaction createTransferAssetTransaction(byte[] to, byte[] assertName, - byte[] owner, long amount) { - AssetIssueContractOuterClass.TransferAssetContract contract = createTransferAssetContract(to, - assertName, owner, - amount); + /** constructor. */ + public static Transaction createTransferAssetTransaction( + byte[] to, byte[] assertName, byte[] owner, long amount) { + AssetIssueContractOuterClass.TransferAssetContract contract = + createTransferAssetContract(to, assertName, owner, amount); return rpcCli.createTransferAssetTransaction(contract); } - /** - * constructor. - */ - - public static Transaction participateAssetIssueTransaction(byte[] to, byte[] assertName, - byte[] owner, long amount) { + /** constructor. */ + public static Transaction participateAssetIssueTransaction( + byte[] to, byte[] assertName, byte[] owner, long amount) { AssetIssueContractOuterClass.ParticipateAssetIssueContract contract = participateAssetIssueContract(to, assertName, owner, amount); return rpcCli.createParticipateAssetIssueTransaction(contract); } - /** - * constructor. - */ - + /** constructor. */ public static Transaction updateAccountTransaction(byte[] addressBytes, byte[] accountNameBytes) { - AccountUpdateContract contract = createAccountUpdateContract(accountNameBytes, - addressBytes); + AccountUpdateContract contract = createAccountUpdateContract(accountNameBytes, addressBytes); return rpcCli.createTransaction(contract); } - /** - * constructor. - */ - + /** constructor. */ public static boolean broadcastTransaction(byte[] transactionBytes) throws InvalidProtocolBufferException { Transaction transaction = Transaction.parseFrom(transactionBytes); @@ -257,17 +224,14 @@ public static boolean broadcastTransaction(byte[] transactionBytes) return rpcCli.broadcastTransaction(transaction); } - /** - * constructor. - */ - + /** constructor. */ public static Transaction createWitnessTransaction(byte[] owner, byte[] url) { WitnessContract.WitnessCreateContract contract = createWitnessCreateContract(owner, url); return rpcCli.createWitness(contract); } - public static Transaction createVoteWitnessTransaction(byte[] owner, - HashMap witness) { + public static Transaction createVoteWitnessTransaction( + byte[] owner, HashMap witness) { WitnessContract.VoteWitnessContract contract = createVoteWitnessContract(owner, witness); return rpcCli.voteWitnessAccount(contract); } @@ -280,12 +244,8 @@ public static Block getGetBlock(long blockNum) { return rpcCli.getBlock(blockNum); } - /** - * constructor. - */ - - public static TransferContract createTransferContract(byte[] to, byte[] owner, - long amount) { + /** constructor. */ + public static TransferContract createTransferContract(byte[] to, byte[] owner, long amount) { TransferContract.Builder builder = TransferContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); ByteString bsOwner = ByteString.copyFrom(owner); @@ -295,10 +255,7 @@ public static TransferContract createTransferContract(byte[] to, byte[] owner, return builder.build(); } - /** - * constructor. - */ - + /** constructor. */ public static AssetIssueContractOuterClass.TransferAssetContract createTransferAssetContract( byte[] to, byte[] assertName, byte[] owner, long amount) { AssetIssueContractOuterClass.TransferAssetContract.Builder builder = @@ -314,14 +271,10 @@ public static AssetIssueContractOuterClass.TransferAssetContract createTransferA return builder.build(); } - /** - * constructor. - */ - + /** constructor. */ public static ParticipateAssetIssueContract participateAssetIssueContract( byte[] to, byte[] assertName, byte[] owner, long amount) { - ParticipateAssetIssueContract.Builder builder = - ParticipateAssetIssueContract.newBuilder(); + ParticipateAssetIssueContract.Builder builder = ParticipateAssetIssueContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); ByteString bsName = ByteString.copyFrom(assertName); ByteString bsOwner = ByteString.copyFrom(owner); @@ -338,22 +291,15 @@ public static Transaction createTransaction4Transfer(TransferContract contract) return transaction; } - /** - * constructor. - */ - - public static AccountCreateContract createAccountCreateContract(byte[] owner, - byte[] address) { + /** constructor. */ + public static AccountCreateContract createAccountCreateContract(byte[] owner, byte[] address) { AccountCreateContract.Builder builder = AccountCreateContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(owner)); builder.setAccountAddress(ByteString.copyFrom(address)); return builder.build(); } - /** - * constructor. - */ - + /** constructor. */ public static AccountCreateContract createAccountCreateContract( AccountType accountType, byte[] accountName, byte[] address) { AccountCreateContract.Builder builder = AccountCreateContract.newBuilder(); @@ -365,21 +311,15 @@ public static AccountCreateContract createAccountCreateContract( return builder.build(); } - /** - * constructor. - */ - + /** constructor. */ public static Transaction createAccountTransaction(byte[] owner, byte[] address) { AccountCreateContract contract = createAccountCreateContract(owner, address); return rpcCli.createAccount(contract); } - /** - * constructor. - */ - - public static AccountUpdateContract createAccountUpdateContract(byte[] accountName, - byte[] address) { + /** constructor. */ + public static AccountUpdateContract createAccountUpdateContract( + byte[] accountName, byte[] address) { AccountUpdateContract.Builder builder = AccountUpdateContract.newBuilder(); ByteString bsAddress = ByteString.copyFrom(address); ByteString bsAccountName = ByteString.copyFrom(accountName); @@ -390,34 +330,28 @@ public static AccountUpdateContract createAccountUpdateContract(byte[] accountNa return builder.build(); } - /** - * constructor. - */ - - public static WitnessContract.WitnessCreateContract createWitnessCreateContract(byte[] owner, - byte[] url) { - WitnessContract.WitnessCreateContract.Builder builder = WitnessContract.WitnessCreateContract - .newBuilder(); + /** constructor. */ + public static WitnessContract.WitnessCreateContract createWitnessCreateContract( + byte[] owner, byte[] url) { + WitnessContract.WitnessCreateContract.Builder builder = + WitnessContract.WitnessCreateContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(owner)); builder.setUrl(ByteString.copyFrom(url)); return builder.build(); } - /** - * constructor. - */ - + /** constructor. */ public static WitnessContract.VoteWitnessContract createVoteWitnessContract( byte[] owner, HashMap witness) { - WitnessContract.VoteWitnessContract.Builder builder = WitnessContract.VoteWitnessContract - .newBuilder(); + WitnessContract.VoteWitnessContract.Builder builder = + WitnessContract.VoteWitnessContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(owner)); for (String addressBase58 : witness.keySet()) { String value = witness.get(addressBase58); long count = Long.parseLong(value); - WitnessContract.VoteWitnessContract.Vote.Builder voteBuilder - = WitnessContract.VoteWitnessContract.Vote.newBuilder(); + WitnessContract.VoteWitnessContract.Vote.Builder voteBuilder = + WitnessContract.VoteWitnessContract.Vote.newBuilder(); byte[] address = WalletClient.decodeFromBase58Check(addressBase58); if (address == null) { continue; @@ -434,15 +368,7 @@ public static AccountNetMessage getAccountNet(byte[] address) { return rpcCli.getAccountNet(address); } - - - - - - /** - * constructor. - */ - + /** constructor. */ public static byte[] getEncKey(String password) { if (!passwordValid(password)) { return null; @@ -453,12 +379,7 @@ public static byte[] getEncKey(String password) { return encKey; } - - - /** - * constructor. - */ - + /** constructor. */ public static boolean passwordValid(String password) { if (StringUtils.isEmpty(password)) { logger.warn("Warning: Password is empty !!"); @@ -468,14 +389,11 @@ public static boolean passwordValid(String password) { logger.warn("Warning: Password is too short !!"); return false; } - //Other rule; + // Other rule; return true; } - /** - * constructor. - */ - + /** constructor. */ public static boolean addressValid(byte[] address) { if (address == null || address.length == 0) { logger.warn("Warning: Address is empty !!"); @@ -483,24 +401,28 @@ public static boolean addressValid(byte[] address) { } if (address.length != CommonConstant.ADDRESS_SIZE) { logger.warn( - "Warning: Address length need " + CommonConstant.ADDRESS_SIZE + " but " + address.length + "Warning: Address length need " + + CommonConstant.ADDRESS_SIZE + + " but " + + address.length + " !!"); return false; } byte preFixbyte = address[0]; if (preFixbyte != getAddressPreFixByte()) { - logger.warn("Warning: Address need prefix with " + getAddressPreFixByte() + " but " - + preFixbyte + " !!"); + logger.warn( + "Warning: Address need prefix with " + + getAddressPreFixByte() + + " but " + + preFixbyte + + " !!"); return false; } - //Other rule; + // Other rule; return true; } - /** - * constructor. - */ - + /** constructor. */ public static String encode58Check(byte[] input) { byte[] hash0 = Sha256Hash.hash(true, input); byte[] hash1 = Sha256Hash.hash(true, hash0); @@ -528,10 +450,7 @@ public static byte[] decode58Check(String input) { return null; } - /** - * constructor. - */ - + /** constructor. */ public static byte[] decodeFromBase58Check(String addressBase58) { if (StringUtils.isEmpty(addressBase58)) { logger.warn("Warning: Address is empty !!"); @@ -544,10 +463,7 @@ public static byte[] decodeFromBase58Check(String addressBase58) { return address; } - /** - * constructor. - */ - + /** constructor. */ public static boolean priKeyValid(String priKey) { if (StringUtils.isEmpty(priKey)) { logger.warn("Warning: PrivateKey is empty !!"); @@ -557,13 +473,11 @@ public static boolean priKeyValid(String priKey) { logger.warn("Warning: PrivateKey length need 64 but " + priKey.length() + " !!"); return false; } - //Other rule; + // Other rule; return true; } - /** - * constructor. - */ + /** constructor. */ public static Optional listWitnesses() { Optional result = rpcCli.listWitnesses(); if (result.isPresent()) { @@ -611,7 +525,6 @@ public static Optional getBlockByLatestNum(long num) { return rpcCli.getBlockByLatestNum(num); } - public boolean isLoginState() { return loginState; } @@ -646,10 +559,7 @@ private Transaction signTransaction(Transaction transaction) { return rpcCli.getTransactionsByTimestamp(start, end, offset, limit); }*/ - /** - * constructor. - */ - + /** constructor. */ public boolean sendCoin(byte[] to, long amount) { byte[] owner = getAddress(); TransferContract contract = createTransferContract(to, owner, amount); @@ -661,13 +571,9 @@ public boolean sendCoin(byte[] to, long amount) { return rpcCli.broadcastTransaction(transaction); } - /** - * constructor. - */ - + /** constructor. */ public boolean updateAccount(byte[] addressBytes, byte[] accountNameBytes) { - AccountUpdateContract contract = createAccountUpdateContract(accountNameBytes, - addressBytes); + AccountUpdateContract contract = createAccountUpdateContract(accountNameBytes, addressBytes); Transaction transaction = rpcCli.createTransaction(contract); if (transaction == null || transaction.getRawData().getContractCount() == 0) { @@ -690,10 +596,7 @@ public static GrpcAPI.NumberMessage getTotalTransaction() { return rpcCli.getTotalTransaction(); }*/ - /** - * constructor. - */ - + /** constructor. */ public boolean transferAsset(byte[] to, byte[] assertName, long amount) { byte[] owner = getAddress(); Transaction transaction = createTransferAssetTransaction(to, assertName, owner, amount); @@ -704,10 +607,7 @@ public boolean transferAsset(byte[] to, byte[] assertName, long amount) { return rpcCli.broadcastTransaction(transaction); } - /** - * constructor. - */ - + /** constructor. */ public boolean participateAssetIssue(byte[] to, byte[] assertName, long amount) { byte[] owner = getAddress(); Transaction transaction = participateAssetIssueTransaction(to, assertName, owner, amount); @@ -722,10 +622,7 @@ public boolean participateAssetIssue(byte[] to, byte[] assertName, long amount) return rpcCli.getTransactionById(txID); }*/ - /** - * constructor. - */ - + /** constructor. */ public boolean createAssetIssue(AssetIssueContract contract) { Transaction transaction = rpcCli.createAssetIssue(contract); if (transaction == null || transaction.getRawData().getContractCount() == 0) { @@ -735,10 +632,7 @@ public boolean createAssetIssue(AssetIssueContract contract) { return rpcCli.broadcastTransaction(transaction); } - /** - * constructor. - */ - + /** constructor. */ public boolean createWitness(byte[] url) { byte[] owner = getAddress(); Transaction transaction = createWitnessTransaction(owner, url); @@ -749,10 +643,7 @@ public boolean createWitness(byte[] url) { return rpcCli.broadcastTransaction(transaction); } - /** - * constructor. - */ - + /** constructor. */ public boolean voteWitness(HashMap witness) { byte[] owner = getAddress(); WitnessContract.VoteWitnessContract contract = createVoteWitnessContract(owner, witness); @@ -764,10 +655,7 @@ public boolean voteWitness(HashMap witness) { return rpcCli.broadcastTransaction(transaction); } - /** - * constructor. - */ - + /** constructor. */ public boolean createAccount(byte[] address) throws CipherException, IOException, CancelException { byte[] owner = getAddress(); @@ -780,14 +668,10 @@ public boolean createAccount(byte[] address) return rpcCli.broadcastTransaction(transaction); } - /** - * constructor. - */ - + /** constructor. */ public boolean freezeBalance(long frozenBalance, long frozenDuration) { - FreezeBalanceContract contract = createFreezeBalanceContract(frozenBalance, - frozenDuration); + FreezeBalanceContract contract = createFreezeBalanceContract(frozenBalance, frozenDuration); Transaction transaction = rpcCli.createTransaction(contract); @@ -799,22 +683,21 @@ public boolean freezeBalance(long frozenBalance, long frozenDuration) { return rpcCli.broadcastTransaction(transaction); } - private FreezeBalanceContract createFreezeBalanceContract(long frozenBalance, - long frozenDuration) { + private FreezeBalanceContract createFreezeBalanceContract( + long frozenBalance, long frozenDuration) { byte[] address = getAddress(); FreezeBalanceContract.Builder builder = FreezeBalanceContract.newBuilder(); ByteString byteAddress = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddress).setFrozenBalance(frozenBalance) + builder + .setOwnerAddress(byteAddress) + .setFrozenBalance(frozenBalance) .setFrozenDuration(frozenDuration); return builder.build(); } - /** - * constructor. - */ - + /** constructor. */ public boolean unfreezeBalance() { UnfreezeBalanceContract contract = createUnfreezeBalanceContract(); @@ -831,18 +714,14 @@ public boolean unfreezeBalance() { private UnfreezeBalanceContract createUnfreezeBalanceContract() { byte[] address = getAddress(); - UnfreezeBalanceContract.Builder builder = UnfreezeBalanceContract - .newBuilder(); + UnfreezeBalanceContract.Builder builder = UnfreezeBalanceContract.newBuilder(); ByteString byteAddress = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddress); return builder.build(); } - /** - * constructor. - */ - + /** constructor. */ public boolean withdrawBalance() { WithdrawBalanceContract contract = createWithdrawBalanceContract(); @@ -858,8 +737,7 @@ public boolean withdrawBalance() { private WithdrawBalanceContract createWithdrawBalanceContract() { byte[] address = getAddress(); - WithdrawBalanceContract.Builder builder = WithdrawBalanceContract - .newBuilder(); + WithdrawBalanceContract.Builder builder = WithdrawBalanceContract.newBuilder(); ByteString byteAddress = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddress); diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/WitnessComparator.java b/testcase/src/test/java/stest/tron/wallet/common/client/WitnessComparator.java index c032fce9..a905249c 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/WitnessComparator.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/WitnessComparator.java @@ -8,4 +8,4 @@ class WitnessComparator implements Comparator { public int compare(Object o1, Object o2) { return Long.compare(((Witness) o2).getVoteCount(), ((Witness) o1).getVoteCount()); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/AbiUtil.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/AbiUtil.java index ba7d99e5..299af7e6 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/AbiUtil.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/AbiUtil.java @@ -155,8 +155,7 @@ public static byte[] pack(List codes, List values) { System.arraycopy(new DataWord(dynamicOffset).getData(), 0, data, offset, 32); offset += 32; - System.arraycopy(encodedList.get(idx), 0, data, dynamicOffset, - encodedList.get(idx).length); + System.arraycopy(encodedList.get(idx), 0, data, dynamicOffset, encodedList.get(idx).length); dynamicOffset += encodedList.get(idx).length; } else { System.arraycopy(encodedList.get(idx), 0, data, offset, encodedList.get(idx).length); @@ -250,15 +249,24 @@ public static void main(String[] args) { System.out.println("token:" + parseMethod(tokenMethod, tokenParams)); String method1 = "test(uint256,string,string,uint256[])"; - String expected1 = "db103cf30000000000000000000000000000000000000000000000000000000000000005000" - + "0000000000000000000000000000000000000000000000000000000000080000000000000000000000000000" - + "00000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000" - + "0000000000100000000000000000000000000000000000000000000000000000000000000000142000000000" - + "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000143000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000000030000000000000000000" - + "0000000000000000000000000000000000000000000010000000000000000000000000000000000000000000" - + "0000000000000000000020000000000000000000000000000000000000000000000000000000000000003"; + String expected1 = + "db103cf30000000000000000000000000000000000000000000000000000000000000005000" + + "000000000000000000000000000000000000000000000000000000000008000000000000000000000000" + + "0000" + + "00000000000000000000000000000000000c000000000000000000000000000000000000000000000000" + + "0000" + + "000000000010000000000000000000000000000000000000000000000000000000000000000014200000" + + "0000" + + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + + "0000" + + "000000000000000000000000000014300000000000000000000000000000000000000000000000000000" + + "0000" + + "000000000000000000000000000000000000000000000000000000000000000000003000000000000000" + + "0000" + + "000000000000000000000000000000000000000000001000000000000000000000000000000000000000" + + "0000" + + "000000000000000000002000000000000000000000000000000000000000000000000000000000000000" + + "3"; String method2 = "test(uint256,string,string,uint256[3])"; String listString = "1 ,\"B\",\"C\", [1, 2, 3]"; System.out.println(parseMethod(method1, listString)); @@ -277,7 +285,6 @@ abstract static class Coder { abstract byte[] encode(String value); abstract byte[] decode(); - } static class CoderArray extends Coder { @@ -402,7 +409,6 @@ byte[] encode(String value) { } else { return new DataWord(0).getData(); } - } @Override diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/AccountHelper.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/AccountHelper.java index 6e9f6ff3..c0832113 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/AccountHelper.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/AccountHelper.java @@ -384,7 +384,10 @@ private static Permission json2Permission(JSONObject json) { return permissionBuilder.build(); } - /** Update account permissions (owner, witness, actives) using a JSON descriptor and multi-sig keys. */ + /** + * Update account permissions (owner, witness, actives) using a JSON descriptor and multi-sig + * keys. + */ public static boolean accountPermissionUpdate( String permissionJson, byte[] owner, @@ -793,17 +796,18 @@ public static Return sendcoin2( return ret; } - /** Transfer TRX and return the transaction ID string, delegating to sendcoinWithMemoGetTransactionId. */ + /** + * Transfer TRX and return the transaction ID string, delegating to + * sendcoinWithMemoGetTransactionId. + */ public static String sendcoinGetTransactionId( byte[] to, long amount, byte[] owner, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull - ) { - return sendcoinWithMemoGetTransactionId(to,amount,null,owner, - priKey,blockingStubFull); -} + WalletGrpc.WalletBlockingStub blockingStubFull) { + return sendcoinWithMemoGetTransactionId(to, amount, null, owner, priKey, blockingStubFull); + } /** Transfer TRX with an optional memo and return the transaction ID string. */ public static String sendcoinWithMemoGetTransactionId( @@ -838,7 +842,7 @@ public static String sendcoinWithMemoGetTransactionId( return null; } // Test raw data - if(null != memo) { + if (null != memo) { Protocol.Transaction.raw.Builder builder1 = transaction.getRawData().toBuilder(); builder1.setData(ByteString.copyFromUtf8(memo)); Transaction.Builder builder2 = transaction.toBuilder(); @@ -846,7 +850,6 @@ public static String sendcoinWithMemoGetTransactionId( transaction = builder2.build(); } - transaction = PublicMethod.signTransaction(ecKey, transaction); GrpcAPI.Return response = PublicMethod.broadcastTransaction(transaction, blockingStubFull); if (response.getResult() == false) { diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/AssetHelper.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/AssetHelper.java index 2e6c4673..0e1d4402 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/AssetHelper.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/AssetHelper.java @@ -1051,9 +1051,11 @@ public static Optional getExchange( } /** Get the exchange ID for exchanges created by a specific address. */ - public static Long getExchangeIdByCreatorAddress(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { - List exchangeList = PublicMethod.getExchangeList(blockingStubFull).get().getExchangesList(); - for (int i = 0; i < exchangeList.size(); i++){ + public static Long getExchangeIdByCreatorAddress( + byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { + List exchangeList = + PublicMethod.getExchangeList(blockingStubFull).get().getExchangesList(); + for (int i = 0; i < exchangeList.size(); i++) { Exchange exchange = exchangeList.get(i); if (exchange.getCreatorAddress().equals(ByteString.copyFrom(address))) { return exchange.getExchangeId(); diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/BIUtil.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/BIUtil.java index 6cb1c98a..00f4ab69 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/BIUtil.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/BIUtil.java @@ -66,7 +66,6 @@ public static boolean isMoreThan(BigInteger valueA, BigInteger valueB) { return valueA.compareTo(valueB) > 0; } - /** * @param valueA - not null * @param valueB - not null @@ -76,7 +75,6 @@ public static BigInteger sum(BigInteger valueA, BigInteger valueB) { return valueA.add(valueB); } - /** * @param data = not null * @return new positive BigInteger @@ -93,7 +91,6 @@ public static BigInteger toBI(long data) { return BigInteger.valueOf(data); } - public static boolean isPositive(BigInteger value) { return value.signum() > 0; } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/Base58.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/Base58.java index 9955e6b0..f6bf0b55 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/Base58.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/Base58.java @@ -4,15 +4,12 @@ import java.math.BigInteger; import stest.tron.wallet.common.client.WalletClient; - public class Base58 { - /** - * constructor. - */ + /** constructor. */ + public static final char[] ALPHABET = + "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".toCharArray(); - public static final char[] ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" - .toCharArray(); private static final int BASE58CHECK_ADDRESS_SIZE = 35; private static final int ADDRESS_SIZE = 21; private static final byte ADD_PRE_FIX_BYTE = (byte) 0xa0; @@ -27,10 +24,7 @@ public class Base58 { } } - /** - * constructor. - */ - + /** constructor. */ public static String encode(byte[] input) { if (input.length == 0) { return ""; @@ -65,14 +59,11 @@ public static String encode(byte[] input) { try { return new String(output, "US-ASCII"); } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); // Cannot happen. + throw new RuntimeException(e); // Cannot happen. } } - /** - * constructor. - */ - + /** constructor. */ public static byte[] decode(String input) throws IllegalArgumentException { if (input.length() == 0) { return new byte[0]; @@ -135,7 +126,6 @@ private static byte divmod58(byte[] number, int startAt) { return (byte) remainder; } - private static byte divmod256(byte[] number58, int startAt) { int remainder = 0; for (int i = startAt; i < number58.length; i++) { @@ -157,10 +147,7 @@ private static byte[] copyOfRange(byte[] source, int from, int to) { return range; } - /** - * constructor. - */ - + /** constructor. */ public static byte[] decodeFromBase58Check(String addressBase58) { if (addressBase58 == null || addressBase58.length() == 0) { System.out.println("Warning: Address is empty !!"); @@ -168,7 +155,9 @@ public static byte[] decodeFromBase58Check(String addressBase58) { } if (addressBase58.length() != BASE58CHECK_ADDRESS_SIZE) { System.out.println( - "Warning: Base58 address length need " + BASE58CHECK_ADDRESS_SIZE + " but " + "Warning: Base58 address length need " + + BASE58CHECK_ADDRESS_SIZE + + " but " + addressBase58.length() + " !!"); return null; @@ -180,10 +169,7 @@ public static byte[] decodeFromBase58Check(String addressBase58) { return address; } - /** - * constructor. - */ - + /** constructor. */ public static boolean addressValid(byte[] address) { if (address == null || address.length == 0) { System.out.println("Warning: Address is empty !!"); @@ -191,29 +177,23 @@ public static boolean addressValid(byte[] address) { } if (address.length != ADDRESS_SIZE) { System.out.println( - "Warning: Address length need " + ADDRESS_SIZE + " but " + address.length - + " !!"); + "Warning: Address length need " + ADDRESS_SIZE + " but " + address.length + " !!"); return false; } byte preFixbyte = address[0]; if (preFixbyte != ADD_PRE_FIX_BYTE) { - System.out.println("Warning: Address need prefix with " + ADD_PRE_FIX_BYTE + " but " - + preFixbyte + " !!"); + System.out.println( + "Warning: Address need prefix with " + ADD_PRE_FIX_BYTE + " but " + preFixbyte + " !!"); return false; } - //Other rule; + // Other rule; return true; } - /** - * constructor. - */ - + /** constructor. */ public static String encode58Check(byte[] input) { - byte[] hash0 = Sha256Hash.hash(CommonParameter - .getInstance().isECKeyCryptoEngine(), input); - byte[] hash1 = Sha256Hash.hash(CommonParameter - .getInstance().isECKeyCryptoEngine(), hash0); + byte[] hash0 = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), input); + byte[] hash1 = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), hash0); byte[] inputCheck = new byte[input.length + 4]; System.arraycopy(input, 0, inputCheck, 0, input.length); System.arraycopy(hash1, 0, inputCheck, input.length, 4); @@ -237,6 +217,4 @@ public static byte[] decode58CheckForShield(String input) { } return null; } - - -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/Bech32.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/Bech32.java index 1e33a393..ae606541 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/Bech32.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/Bech32.java @@ -1,6 +1,5 @@ package stest.tron.wallet.common.client.utils; - /* * Copyright 2018 Coinomi Ltd * @@ -17,7 +16,6 @@ * limitations under the License. */ - import static com.google.common.base.Preconditions.checkArgument; import java.util.Arrays; @@ -25,28 +23,22 @@ public class Bech32 { - /** - * The Bech32 character set for encoding. - */ + /** The Bech32 character set for encoding. */ private static final String CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"; - /** - * The Bech32 character set for decoding. - */ + /** The Bech32 character set for decoding. */ private static final byte[] CHARSET_REV = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 15, -1, 10, 17, 21, 20, 26, 30, 7, 5, -1, -1, -1, -1, -1, -1, - -1, 29, -1, 24, 13, 25, 9, 8, 23, -1, 18, 22, 31, 27, 19, -1, - 1, 0, 3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, -1, - -1, 29, -1, 24, 13, 25, 9, 8, 23, -1, 18, 22, 31, 27, 19, -1, - 1, 0, 3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, -1 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 15, -1, 10, 17, 21, 20, 26, 30, 7, 5, -1, -1, -1, -1, -1, -1, + -1, 29, -1, 24, 13, 25, 9, 8, 23, -1, 18, 22, 31, 27, 19, -1, + 1, 0, 3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, -1, + -1, 29, -1, 24, 13, 25, 9, 8, 23, -1, 18, 22, 31, 27, 19, -1, + 1, 0, 3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, -1 }; - /** - * Find the polynomial with value coefficients mod the generator as 30-bit. - */ + /** Find the polynomial with value coefficients mod the generator as 30-bit. */ private static int polymod(final byte[] values) { int c = 1; for (byte v_i : values) { @@ -71,12 +63,10 @@ private static int polymod(final byte[] values) { return c; } - /** - * Expand a HRP for use in checksum computation. - */ + /** Expand a HRP for use in checksum computation. */ private static byte[] expandHrp(final String hrp) { int hrpLength = hrp.length(); - byte ret[] = new byte[hrpLength * 2 + 1]; + byte[] ret = new byte[hrpLength * 2 + 1]; for (int i = 0; i < hrpLength; ++i) { int c = hrp.charAt(i) & 0x7f; // Limit to standard 7-bit ASCII ret[i] = (byte) ((c >>> 5) & 0x07); @@ -86,9 +76,7 @@ private static byte[] expandHrp(final String hrp) { return ret; } - /** - * Verify a checksum. - */ + /** Verify a checksum. */ private static boolean verifyChecksum(final String hrp, final byte[] values) { byte[] hrpExpanded = expandHrp(hrp); byte[] combined = new byte[hrpExpanded.length + values.length]; @@ -97,9 +85,7 @@ private static boolean verifyChecksum(final String hrp, final byte[] values) { return polymod(combined) == 1; } - /** - * Create a checksum. - */ + /** Create a checksum. */ private static byte[] createChecksum(final String hrp, final byte[] values) { byte[] hrpExpanded = expandHrp(hrp); byte[] enc = new byte[hrpExpanded.length + values.length + 6]; @@ -113,16 +99,12 @@ private static byte[] createChecksum(final String hrp, final byte[] values) { return ret; } - /** - * Encode a Bech32 string. - */ + /** Encode a Bech32 string. */ public static String encode(final Bech32Data bech32) { return encode(bech32.hrp, bech32.data); } - /** - * Encode a Bech32 string. - */ + /** Encode a Bech32 string. */ public static String encode(String hrp, final byte[] values) { checkArgument(hrp.length() >= 1, "Human-readable part is too short"); checkArgument(hrp.length() <= 83, "Human-readable part is too long"); @@ -140,11 +122,10 @@ public static String encode(String hrp, final byte[] values) { return sb.toString(); } - /** - * Decode a Bech32 string. - */ + /** Decode a Bech32 string. */ public static Bech32Data decode(final String str) throws IllegalArgumentException { - boolean lower = false, upper = false; + boolean lower = false; + boolean upper = false; if (str.length() < 8) { throw new IllegalArgumentException("Input too short: " + str.length()); } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/BlockCapsule.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/BlockCapsule.java index c748a901..e4bb971c 100755 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/BlockCapsule.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/BlockCapsule.java @@ -27,7 +27,6 @@ public class BlockCapsule implements ProtoCapsule { public boolean generatedByMyself = false; - private BlockId blockId = new BlockId(Sha256Hash.ZERO_HASH, 0); private Block block; @@ -35,7 +34,6 @@ public class BlockCapsule implements ProtoCapsule { private StringBuilder toStringBuff = new StringBuilder(); private boolean isSwitch; - public boolean isSwitch() { return isSwitch; } @@ -45,40 +43,49 @@ public BlockCapsule setSwitch(boolean aSwitch) { return this; } - - - - - - public BlockId getBlockId() { if (blockId.equals(Sha256Hash.ZERO_HASH)) { blockId = - new BlockId(Sha256Hash.of(CommonParameter.getInstance().isECKeyCryptoEngine(), - this.block.getBlockHeader().getRawData().toByteArray()), getNum()); + new BlockId( + Sha256Hash.of( + CommonParameter.getInstance().isECKeyCryptoEngine(), + this.block.getBlockHeader().getRawData().toByteArray()), + getNum()); } return blockId; } - - public void setAccountStateRoot(byte[] root) { BlockHeader.raw blockHeaderRaw = - this.block.getBlockHeader().getRawData().toBuilder() - .setAccountStateRoot(ByteString.copyFrom(root)).build(); + this.block + .getBlockHeader() + .getRawData() + .toBuilder() + .setAccountStateRoot(ByteString.copyFrom(root)) + .build(); - this.block = this.block.toBuilder().setBlockHeader( - this.block.getBlockHeader().toBuilder().setRawData(blockHeaderRaw)).build(); + this.block = + this.block + .toBuilder() + .setBlockHeader(this.block.getBlockHeader().toBuilder().setRawData(blockHeaderRaw)) + .build(); } /* only for genesis */ public void setWitness(String witness) { BlockHeader.raw blockHeaderRaw = - this.block.getBlockHeader().getRawData().toBuilder().setWitnessAddress( - ByteString.copyFrom(witness.getBytes())).build(); + this.block + .getBlockHeader() + .getRawData() + .toBuilder() + .setWitnessAddress(ByteString.copyFrom(witness.getBytes())) + .build(); - this.block = this.block.toBuilder().setBlockHeader( - this.block.getBlockHeader().toBuilder().setRawData(blockHeaderRaw)).build(); + this.block = + this.block + .toBuilder() + .setBlockHeader(this.block.getBlockHeader().toBuilder().setRawData(blockHeaderRaw)) + .build(); } public Sha256Hash getMerkleRoot() { @@ -135,8 +142,6 @@ public boolean hasWitnessSignature() { return !getInstance().getBlockHeader().getWitnessSignature().isEmpty(); } - - public static class BlockId extends Sha256Hash { private long num; @@ -153,9 +158,7 @@ public BlockId(Sha256Hash blockId) { num = Longs.fromByteArray(blockNum); } - /** - * Use {@link #wrap(byte[])} instead. - */ + /** Use {@link #wrap(byte[])} instead. */ public BlockId(Sha256Hash hash, long num) { super(num, hash); this.num = num; diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/BlockHelper.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/BlockHelper.java index 917ecc1a..fcf0ccf9 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/BlockHelper.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/BlockHelper.java @@ -43,9 +43,9 @@ public static boolean waitSolidityNodeSynFullNodeData( blockingStubSolidity.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); Integer wait = 0; long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); - logger.info("start sync soliditynode, SR number: " + PublicMethod.getWitnessNum(blockingStubFull)); - while (solidityCurrentBlock.getBlockHeader().getRawData().getNumber() - <= currentBlockNum + 1 + logger.info( + "start sync soliditynode, SR number: " + PublicMethod.getWitnessNum(blockingStubFull)); + while (solidityCurrentBlock.getBlockHeader().getRawData().getNumber() <= currentBlockNum + 1 && wait < ((PublicMethod.getWitnessNum(blockingStubFull) >= 27) ? 27 @@ -63,8 +63,11 @@ public static boolean waitSolidityNodeSynFullNodeData( } wait++; } - logger.info("Fullnode number: " + currentBlockNum - + ", solidity node number: " + solidityCurrentBlock.getBlockHeader().getRawData().getNumber()); + logger.info( + "Fullnode number: " + + currentBlockNum + + ", solidity node number: " + + solidityCurrentBlock.getBlockHeader().getRawData().getNumber()); return true; } @@ -82,7 +85,9 @@ public static boolean waitProduceNextBlock(WalletGrpc.WalletBlockingStub blockin Long nextNum = nextBlock.getBlockHeader().getRawData().getNumber(); Integer wait = 0; - logger.info("start wait produce block, current num: " + currentBlock.getBlockHeader().getRawData().getNumber()); + logger.info( + "start wait produce block, current num: " + + currentBlock.getBlockHeader().getRawData().getNumber()); while (nextNum <= currentNum + 1 && wait <= 45) { try { Thread.sleep(1000); @@ -102,7 +107,8 @@ public static boolean waitProduceNextBlock(WalletGrpc.WalletBlockingStub blockin } /** Wait until transaction info is found by txId, or timeout. */ - public static void waitUntilTransactionInfoFound(WalletGrpc.WalletBlockingStub blockingStubFull, String txId, int timeout) { + public static void waitUntilTransactionInfoFound( + WalletGrpc.WalletBlockingStub blockingStubFull, String txId, int timeout) { Integer wait = 0; while (wait++ <= timeout) { try { @@ -111,14 +117,14 @@ public static void waitUntilTransactionInfoFound(WalletGrpc.WalletBlockingStub b } catch (InterruptedException e) { e.printStackTrace(); } - Optional infoById = PublicMethod.getTransactionInfoById(txId, blockingStubFull); - if(infoById.get().getBlockTimeStamp() > 0){ + Optional infoById = + PublicMethod.getTransactionInfoById(txId, blockingStubFull); + if (infoById.get().getBlockTimeStamp() > 0) { logger.info("quit normally, wait tx by id: " + txId + " times: " + wait); return; } } logger.info("quit timeout, wait tx by id: " + txId + " times: " + wait); - } /** Get transaction info list by block number from the full node. */ diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ByteArray.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ByteArray.java index 912ef13f..15c8e79f 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ByteArray.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ByteArray.java @@ -1,6 +1,6 @@ package stest.tron.wallet.common.client.utils; -//import static org.tron.common.utils.ByteUtil.EMPTY_BYTE_ARRAY; +// import static org.tron.common.utils.ByteUtil.EMPTY_BYTE_ARRAY; import com.google.common.primitives.Ints; import com.google.common.primitives.Longs; @@ -40,9 +40,7 @@ public static String toHexString(byte[] data) { return data == null ? "" : Hex.toHexString(data); } - /** - * get bytes data from hex string data. - */ + /** get bytes data from hex string data. */ public static byte[] fromHexString(String data) { if (data == null) { return ByteUtil.EMPTY_BYTE_ARRAY; @@ -56,30 +54,22 @@ public static byte[] fromHexString(String data) { return Hex.decode(data); } - /** - * get long data from bytes data. - */ + /** get long data from bytes data. */ public static long toLong(byte[] b) { return ArrayUtils.isEmpty(b) ? 0 : new BigInteger(1, b).longValue(); } - /** - * get int data from bytes data. - */ + /** get int data from bytes data. */ public static int toInt(byte[] b) { return ArrayUtils.isEmpty(b) ? 0 : new BigInteger(1, b).intValue(); } - /** - * get bytes data from string data. - */ + /** get bytes data from string data. */ public static byte[] fromString(String s) { return StringUtils.isBlank(s) ? null : s.getBytes(); } - /** - * get string data from bytes data. - */ + /** get string data from bytes data. */ public static String toStr(byte[] b) { return ArrayUtils.isEmpty(b) ? null : new String(b); } @@ -92,9 +82,7 @@ public static byte[] fromInt(int val) { return Ints.toByteArray(val); } - /** - * get bytes data from object data. - */ + /** get bytes data from object data. */ public static byte[] fromObject(Object obj) { byte[] bytes = null; try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); @@ -108,15 +96,23 @@ public static byte[] fromObject(Object obj) { return bytes; } - /** - * Stringify byte[] x - * null for null - * null for empty [] - */ + /** Stringify byte[] x null for null null for empty [] */ public static String toJsonHex(byte[] x) { return x == null || x.length == 0 ? "0x" : "0x" + Hex.toHexString(x); } + public static String toJsonHex(Long x) { + return x == null ? null : "0x" + Long.toHexString(x); + } + + public static String toJsonHex(int x) { + return toJsonHex((long) x); + } + + public static String toJsonHex(String x) { + return "0x" + x; + } + // ignore the 41 public static String toJsonHexAddress(byte[] x) { if (x == null || x.length == 0) { @@ -131,18 +127,6 @@ public static String toJsonHexAddress(byte[] x) { } } - public static String toJsonHex(Long x) { - return x == null ? null : "0x" + Long.toHexString(x); - } - - public static String toJsonHex(int x) { - return toJsonHex((long) x); - } - - public static String toJsonHex(String x) { - return "0x" + x; - } - public static BigInteger hexToBigInteger(String input) { if (input.startsWith("0x")) { return new BigInteger(input.substring(2), 16); @@ -174,7 +158,7 @@ public static int jsonHexToInt(String x) throws Exception { * @param start the start index * @param end the end index * @return a subarray of input, ranging from start (inclusively) to end - * (exclusively) + * (exclusively) */ public static byte[] subArray(byte[] input, int start, int end) { byte[] result = new byte[end - start]; diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ByteArrayWrapper.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ByteArrayWrapper.java index 67e49ea6..2a9980ae 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ByteArrayWrapper.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ByteArrayWrapper.java @@ -21,15 +21,12 @@ import java.util.Arrays; import org.bouncycastle.util.encoders.Hex; - public class ByteArrayWrapper implements Comparable, Serializable { private final byte[] data; private int hashCode = 0; - /** - * constructor. - */ + /** constructor. */ public ByteArrayWrapper(byte[] data) { if (data == null) { throw new NullPointerException("Data must not be null"); @@ -38,18 +35,13 @@ public ByteArrayWrapper(byte[] data) { this.hashCode = Arrays.hashCode(data); } - - /** - * equals Objects. - */ + /** equals Objects. */ public boolean equals(Object other) { if (other == null || this.getClass() != other.getClass()) { return false; } byte[] otherData = ((ByteArrayWrapper) other).getData(); - return FastByteComparisons.compareTo( - data, 0, data.length, - otherData, 0, otherData.length) == 0; + return FastByteComparisons.compareTo(data, 0, data.length, otherData, 0, otherData.length) == 0; } @Override @@ -59,9 +51,7 @@ public int hashCode() { @Override public int compareTo(ByteArrayWrapper o) { - return FastByteComparisons.compareTo( - data, 0, data.length, - o.getData(), 0, o.getData().length); + return FastByteComparisons.compareTo(data, 0, data.length, o.getData(), 0, o.getData().length); } public byte[] getData() { diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ByteUtil.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ByteUtil.java index 47b48915..4dd502fb 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ByteUtil.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ByteUtil.java @@ -30,20 +30,15 @@ import java.util.zip.DataFormatException; import java.util.zip.Deflater; import java.util.zip.Inflater; -//import javassist.bytecode.ByteArray; import stest.tron.wallet.common.client.utils.exception.EventBloomException; - public class ByteUtil { public static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; - public static final byte[] ZERO_BYTE_ARRAY = new byte[]{0}; + public static final byte[] ZERO_BYTE_ARRAY = new byte[] {0}; public static final int WORD_SIZE = 32; - - /** - * return a cloned byte array. return null if parameter data is null - */ + /** return a cloned byte array. return null if parameter data is null */ public static byte[] cloneBytes(byte[] data) { if (data == null) { return null; @@ -58,8 +53,8 @@ public static byte[] cloneBytes(byte[] data) { } /** - * The regular {@link BigInteger#toByteArray()} method isn't quite what we often need: - * it appends a leading zero to indicate that the number is positive and may need padding. + * The regular {@link BigInteger#toByteArray()} method isn't quite what we often need: it appends + * a leading zero to indicate that the number is positive and may need padding. * * @param b the integer to format into a byte array * @param numBytes the desired size of the resulting byte array @@ -78,12 +73,14 @@ public static byte[] bigIntegerToBytes(BigInteger b, int numBytes) { } /** - * Omitting sign indication byte.

Instead of {@link org.spongycastle.util.BigIntegers#asUnsignedByteArray(BigInteger)} - *
we use this custom method to avoid an empty array in case of BigInteger.ZERO + * Omitting sign indication byte.
+ *
+ * Instead of {@link org.spongycastle.util.BigIntegers#asUnsignedByteArray(BigInteger)}
+ * we use this custom method to avoid an empty array in case of BigInteger.ZERO * * @param value - any big integer number. A null-value will return null * @return A byte array without a leading zero byte if present in the signed encoding. - * BigInteger.ZERO will return an array with length 1 and byte-value 0. + * BigInteger.ZERO will return an array with length 1 and byte-value 0. */ public static byte[] bigIntegerToBytes(BigInteger value) { if (value == null) { @@ -122,9 +119,7 @@ public static byte[] merge(byte[]... arrays) { return mergedArray; } - /** - * Creates a copy of bytes and appends b to the end of it. - */ + /** Creates a copy of bytes and appends b to the end of it. */ public static byte[] appendByte(byte[] bytes, byte b) { byte[] result = Arrays.copyOf(bytes, bytes.length + 1); result[result.length - 1] = b; @@ -147,9 +142,7 @@ public static String nibblesToPrettyString(byte[] nibbles) { return builder.toString(); } - /** - * get hex string data from byte data. - */ + /** get hex string data from byte data. */ public static String oneByteToHexString(byte value) { String retVal = Integer.toString(value & 0xFF, 16); if (retVal.length() == 1) { @@ -231,7 +224,7 @@ public static BigInteger bytesToBigInteger(byte[] bb) { /** * Cast hex encoded value from byte[] to long null is parsed like byte[0] * - * Limited to Long.MAX_VALUE: 263-1 (8 bytes) + *

Limited to Long.MAX_VALUE: 263-1 (8 bytes) * * @param b array contains the values * @return unsigned positive long value. @@ -417,13 +410,12 @@ public static byte[] hexToBytes(String s) { int len = s.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { - data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) - + Character.digit(s.charAt(i + 1), 16)); + data[i / 2] = + (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16)); } return data; } - public static List convertBytesVectorToVector(final byte[] bytes) { List ret = new ArrayList<>(); @@ -514,5 +506,4 @@ public static byte[] decompress(byte[] data) throws IOException, DataFormatExcep return output; } - } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/CipherException.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/CipherException.java index a0164c6b..6ee6ed30 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/CipherException.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/CipherException.java @@ -1,8 +1,6 @@ package stest.tron.wallet.common.client.utils; -/** - * Cipher exception wrapper. - */ +/** Cipher exception wrapper. */ public class CipherException extends Exception { public CipherException(String message) { diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/CommonHelper.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/CommonHelper.java index 502b1a4b..7ee386f0 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/CommonHelper.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/CommonHelper.java @@ -4,7 +4,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonParser; - import java.io.BufferedReader; import java.io.File; import java.io.FileReader; @@ -17,7 +16,6 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; - import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.bouncycastle.util.encoders.Hex; @@ -27,7 +25,9 @@ import stest.tron.wallet.common.client.WalletClient; @Slf4j -/** Helper for common utilities: address/key conversion, encoding, and general-purpose operations. */ +/** + * Helper for common utilities: address/key conversion, encoding, and general-purpose operations. + */ public class CommonHelper { // --------------------------------------------------------------------------- @@ -83,7 +83,9 @@ public static String loadPubKey() { // Encoding / Decoding // --------------------------------------------------------------------------- - /** Decodes a Base58Check-encoded string and verifies its checksum, returning the payload bytes. */ + /** + * Decodes a Base58Check-encoded string and verifies its checksum, returning the payload bytes. + */ public static byte[] decode58Check(String input) { byte[] decodeCheck = Base58.decode(input); if (decodeCheck.length <= 4) { @@ -500,7 +502,10 @@ public static SmartContract.ABI.Entry.StateMutabilityType getStateMutability( // Contract address helpers // --------------------------------------------------------------------------- - /** Generates a contract address by hashing the transaction raw data combined with the owner address. */ + /** + * Generates a contract address by hashing the transaction raw data combined with the owner + * address. + */ public static byte[] generateContractAddress(Transaction trx, byte[] owneraddress) { // get owner address @@ -640,7 +645,7 @@ public static String fileRead(String filePath, boolean isLibrary) throws Excepti } /** Executes a shell command and returns stdout or stderr, whichever is longer. */ - public synchronized static String exec(String command) throws InterruptedException { + public static synchronized String exec(String command) throws InterruptedException { String returnString = ""; String errReturnString = ""; Process pro = null; diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/CommonParameter.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/CommonParameter.java index d4ed956c..d008a465 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/CommonParameter.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/CommonParameter.java @@ -12,472 +12,328 @@ public class CommonParameter { public static final String IGNORE_WRONG_WITNESS_ADDRESS_FORMAT = "The localWitnessAccountAddress format is incorrect, ignored"; public static CommonParameter PARAMETER = new CommonParameter(); - @Setter - public static boolean ENERGY_LIMIT_HARD_FORK = false; - @Parameter(names = {"-c", "--config"}, description = "Config File") + @Setter public static boolean ENERGY_LIMIT_HARD_FORK = false; + + @Parameter( + names = {"-c", "--config"}, + description = "Config File") public String shellConfFileName = ""; + @Getter - @Parameter(names = {"-d", "--output-directory"}, description = "Directory") + @Parameter( + names = {"-d", "--output-directory"}, + description = "Directory") public String outputDirectory = "output-directory"; + @Getter @Parameter(names = {"--log-config"}) public String logbackPath = ""; + @Getter - @Parameter(names = {"-h", "--help"}, help = true, description = "HELP message") + @Parameter( + names = {"-h", "--help"}, + help = true, + description = "HELP message") public boolean help = false; + @Getter @Setter @Parameter(names = {"-w", "--witness"}) public boolean witness = false; + @Getter @Setter @Parameter(names = {"--support-constant"}) public boolean supportConstant = false; + @Getter @Setter @Parameter(names = {"--max-energy-limit-for-constant"}) public long maxEnergyLimitForConstant = 100_000_000L; + @Getter @Setter @Parameter(names = {"--debug"}) public boolean debug = false; + @Getter @Setter @Parameter(names = {"--min-time-ratio"}) public double minTimeRatio = 0.0; + @Getter @Setter @Parameter(names = {"--max-time-ratio"}) public double maxTimeRatio = calcMaxTimeRatio(); + @Getter @Setter @Parameter(names = {"--long-running-time"}) public int longRunningTime = 10; + @Getter @Setter @Parameter(names = {"--max-connect-number"}) public int maxHttpConnectNumber = 50; + @Getter @Parameter(description = "--seed-nodes") public List seedNodes = new ArrayList<>(); - @Parameter(names = {"-p", "--private-key"}, description = "private-key") + + @Parameter( + names = {"-p", "--private-key"}, + description = "private-key") public String privateKey = ""; - @Parameter(names = {"--witness-address"}, description = "witness-address") + + @Parameter( + names = {"--witness-address"}, + description = "witness-address") public String witnessAddress = ""; - @Parameter(names = {"--password"}, description = "password") + + @Parameter( + names = {"--password"}, + description = "password") public String password; - @Parameter(names = {"--storage-db-directory"}, description = "Storage db directory") + + @Parameter( + names = {"--storage-db-directory"}, + description = "Storage db directory") public String storageDbDirectory = ""; - @Parameter(names = {"--storage-db-version"}, description = "Storage db version.(1 or 2)") + + @Parameter( + names = {"--storage-db-version"}, + description = "Storage db version.(1 or 2)") public String storageDbVersion = ""; - @Parameter(names = { - "--storage-db-engine"}, description = "Storage db engine.(leveldb or rocksdb)") + + @Parameter( + names = {"--storage-db-engine"}, + description = "Storage db engine.(leveldb or rocksdb)") public String storageDbEngine = ""; - @Parameter(names = { - "--storage-db-synchronous"}, + + @Parameter( + names = {"--storage-db-synchronous"}, description = "Storage db is synchronous or not.(true or false)") public String storageDbSynchronous = ""; - @Parameter(names = {"--contract-parse-enable"}, + + @Parameter( + names = {"--contract-parse-enable"}, description = "enable contract parses in java-tron or not.(true or false)") public String contractParseEnable = ""; - @Parameter(names = {"--storage-index-directory"}, + + @Parameter( + names = {"--storage-index-directory"}, description = "Storage index directory") public String storageIndexDirectory = ""; - @Parameter(names = {"--storage-index-switch"}, description = "Storage index switch.(on or off)") + + @Parameter( + names = {"--storage-index-switch"}, + description = "Storage index switch.(on or off)") public String storageIndexSwitch = ""; - @Parameter(names = {"--storage-transactionHistory-switch"}, + + @Parameter( + names = {"--storage-transactionHistory-switch"}, description = "Storage transaction history switch.(on or off)") public String storageTransactionHistorySwitch = ""; + @Getter @Parameter(names = {"--fast-forward"}) public boolean fastForward = false; - @Getter - @Setter - public String chainId; - @Getter - @Setter - public boolean needSyncCheck; - @Getter - @Setter - public boolean nodeDiscoveryEnable; - @Getter - @Setter - public boolean nodeDiscoveryPersist; - @Getter - @Setter - public int nodeConnectionTimeout; - @Getter - @Setter - public int nodeChannelReadTimeout; - @Getter - @Setter - public int nodeMaxActiveNodes; - @Getter - @Setter - public int nodeMaxActiveNodesWithSameIp; - @Getter - @Setter - public int minParticipationRate; - @Getter - @Setter - public int nodeListenPort; - @Getter - @Setter - public String nodeDiscoveryBindIp; - @Getter - @Setter - public String nodeExternalIp; - @Getter - @Setter - public boolean nodeDiscoveryPublicHomeNode; - @Getter - @Setter - public long nodeDiscoveryPingTimeout; - @Getter - @Setter - public long nodeP2pPingInterval; + + @Getter @Setter public String chainId; + @Getter @Setter public boolean needSyncCheck; + @Getter @Setter public boolean nodeDiscoveryEnable; + @Getter @Setter public boolean nodeDiscoveryPersist; + @Getter @Setter public int nodeConnectionTimeout; + @Getter @Setter public int nodeChannelReadTimeout; + @Getter @Setter public int nodeMaxActiveNodes; + @Getter @Setter public int nodeMaxActiveNodesWithSameIp; + @Getter @Setter public int minParticipationRate; + @Getter @Setter public int nodeListenPort; + @Getter @Setter public String nodeDiscoveryBindIp; + @Getter @Setter public String nodeExternalIp; + @Getter @Setter public boolean nodeDiscoveryPublicHomeNode; + @Getter @Setter public long nodeDiscoveryPingTimeout; + @Getter @Setter public long nodeP2pPingInterval; + @Getter @Setter @Parameter(names = {"--save-internaltx"}) public boolean saveInternalTx; + + @Getter @Setter public int nodeP2pVersion; + @Getter @Setter public String p2pNodeId; + // If you are running a solidity node for java tron, this flag is set to true + @Getter @Setter public boolean solidityNode = false; + @Getter @Setter public int rpcPort; + @Getter @Setter public int rpcOnSolidityPort; + @Getter @Setter public int fullNodeHttpPort; + @Getter @Setter public int solidityHttpPort; + @Getter @Setter public int jsonRpcHttpFullNodePort; + @Getter @Setter public int jsonRpcHttpSolidityPort; + @Getter @Setter public int jsonRpcHttpPBFTPort; + @Getter @Setter - public int nodeP2pVersion; - @Getter - @Setter - public String p2pNodeId; - //If you are running a solidity node for java tron, this flag is set to true - @Getter - @Setter - public boolean solidityNode = false; - @Getter - @Setter - public int rpcPort; - @Getter - @Setter - public int rpcOnSolidityPort; - @Getter - @Setter - public int fullNodeHttpPort; - @Getter - @Setter - public int solidityHttpPort; - @Getter - @Setter - public int jsonRpcHttpFullNodePort; - @Getter - @Setter - public int jsonRpcHttpSolidityPort; - @Getter - @Setter - public int jsonRpcHttpPBFTPort; - @Getter - @Setter - @Parameter(names = {"--rpc-thread"}, description = "Num of gRPC thread") + @Parameter( + names = {"--rpc-thread"}, + description = "Num of gRPC thread") public int rpcThreadNum; + @Getter @Setter - @Parameter(names = {"--solidity-thread"}, description = "Num of solidity thread") + @Parameter( + names = {"--solidity-thread"}, + description = "Num of solidity thread") public int solidityThreads; + + @Getter @Setter public int maxConcurrentCallsPerConnection; + @Getter @Setter public int flowControlWindow; + @Getter @Setter public long maxConnectionIdleInMillis; + @Getter @Setter public int blockProducedTimeOut; + @Getter @Setter public long netMaxTrxPerSecond; + @Getter @Setter public long maxConnectionAgeInMillis; + @Getter @Setter public int maxMessageSize; + @Getter @Setter public int maxHeaderListSize; + @Getter @Setter - public int maxConcurrentCallsPerConnection; - @Getter - @Setter - public int flowControlWindow; - @Getter - @Setter - public long maxConnectionIdleInMillis; - @Getter - @Setter - public int blockProducedTimeOut; - @Getter - @Setter - public long netMaxTrxPerSecond; - @Getter - @Setter - public long maxConnectionAgeInMillis; - @Getter - @Setter - public int maxMessageSize; - @Getter - @Setter - public int maxHeaderListSize; - @Getter - @Setter - @Parameter(names = {"--validate-sign-thread"}, description = "Num of validate thread") + @Parameter( + names = {"--validate-sign-thread"}, + description = "Num of validate thread") public int validateSignThreadNum; - @Getter - @Setter - public long maintenanceTimeInterval; // (ms) - @Getter - @Setter - public long proposalExpireTime; // (ms) - @Getter - @Setter - public int checkFrozenTime; // for test only - @Getter - @Setter - public long allowCreationOfContracts; //committee parameter - @Getter - @Setter - public long allowAdaptiveEnergy; //committee parameter - @Getter - @Setter - public long allowDelegateResource; //committee parameter - @Getter - @Setter - public long allowSameTokenName; //committee parameter - @Getter - @Setter - public long allowTvmTransferTrc10; //committee parameter - @Getter - @Setter - public long allowTvmConstantinople; //committee parameter - @Getter - @Setter - public long allowTvmSolidity059; //committee parameter - @Getter - @Setter - public long forbidTransferToContract; //committee parameter - @Getter - @Setter - public int tcpNettyWorkThreadNum; - @Getter - @Setter - public int udpNettyWorkThreadNum; - @Getter - @Setter - @Parameter(names = {"--trust-node"}, description = "Trust node addr") - public String trustNodeAddr; - @Getter - @Setter - public boolean walletExtensionApi; - @Getter - @Setter - public int backupPriority; - @Getter - @Setter - public int backupPort; - @Getter - @Setter - public int keepAliveInterval; - @Getter - @Setter - public List backupMembers; - @Getter - @Setter - public double connectFactor; - @Getter - @Setter - public double activeConnectFactor; - @Getter - @Setter - public double disconnectNumberFactor; - @Getter - @Setter - public double maxConnectNumberFactor; - @Getter - @Setter - public long receiveTcpMinDataLength; - @Getter - @Setter - public boolean isOpenFullTcpDisconnect; - @Getter - @Setter - public int allowMultiSign; - @Getter - @Setter - public boolean vmTrace; - @Getter - @Setter - public boolean needToUpdateAsset; - @Getter - @Setter - public String trxReferenceBlock; - @Getter - @Setter - public int minEffectiveConnection; - @Getter - @Setter - public boolean trxCacheEnable; - @Getter - @Setter - public long allowMarketTransaction; //committee parameter + @Getter @Setter public long maintenanceTimeInterval; // (ms) + @Getter @Setter public long proposalExpireTime; // (ms) + @Getter @Setter public int checkFrozenTime; // for test only + @Getter @Setter public long allowCreationOfContracts; // committee parameter + @Getter @Setter public long allowAdaptiveEnergy; // committee parameter + @Getter @Setter public long allowDelegateResource; // committee parameter + @Getter @Setter public long allowSameTokenName; // committee parameter + @Getter @Setter public long allowTvmTransferTrc10; // committee parameter + @Getter @Setter public long allowTvmConstantinople; // committee parameter + @Getter @Setter public long allowTvmSolidity059; // committee parameter + @Getter @Setter public long forbidTransferToContract; // committee parameter - @Getter - @Setter - public long allowTransactionFeePool; + @Getter @Setter public int tcpNettyWorkThreadNum; + @Getter @Setter public int udpNettyWorkThreadNum; @Getter @Setter - public long allowBlackHoleOptimization; + @Parameter( + names = {"--trust-node"}, + description = "Trust node addr") + public String trustNodeAddr; - @Getter - @Setter - public long allowNewResourceModel; + @Getter @Setter public boolean walletExtensionApi; + @Getter @Setter public int backupPriority; + @Getter @Setter public int backupPort; + @Getter @Setter public int keepAliveInterval; + @Getter @Setter public List backupMembers; + @Getter @Setter public double connectFactor; + @Getter @Setter public double activeConnectFactor; + @Getter @Setter public double disconnectNumberFactor; + @Getter @Setter public double maxConnectNumberFactor; + @Getter @Setter public long receiveTcpMinDataLength; + @Getter @Setter public boolean isOpenFullTcpDisconnect; + @Getter @Setter public int allowMultiSign; + @Getter @Setter public boolean vmTrace; + @Getter @Setter public boolean needToUpdateAsset; + @Getter @Setter public String trxReferenceBlock; + @Getter @Setter public int minEffectiveConnection; + @Getter @Setter public boolean trxCacheEnable; + @Getter @Setter public long allowMarketTransaction; // committee parameter + + @Getter @Setter public long allowTransactionFeePool; + + @Getter @Setter public long allowBlackHoleOptimization; + + @Getter @Setter public long allowNewResourceModel; // @Getter // @Setter // public long allowShieldedTransaction; //committee parameter // full node used this parameter to close shielded transaction - @Getter - @Setter - public boolean fullNodeAllowShieldedTransactionArgs; - @Getter - @Setter - public long blockNumForEnergyLimit; + @Getter @Setter public boolean fullNodeAllowShieldedTransactionArgs; + @Getter @Setter public long blockNumForEnergyLimit; + @Getter @Setter @Parameter(names = {"--es"}) public boolean eventSubscribe = false; - @Getter - @Setter - public long trxExpirationTimeInMilliseconds; // (ms) - @Parameter(names = {"-v", "--version"}, description = "output code version", help = true) + + @Getter @Setter public long trxExpirationTimeInMilliseconds; // (ms) + + @Parameter( + names = {"-v", "--version"}, + description = "output code version", + help = true) public boolean version; - @Getter - @Setter - public String zenTokenId; - @Getter - @Setter - public long allowProtoFilterNum; - @Getter - @Setter - public long allowAccountStateRoot; - @Getter - @Setter - public int validContractProtoThreadNum = 1; - @Getter - @Setter - public int shieldedTransInPendingMaxCounts; - @Getter - @Setter - public long changedDelegation; - @Getter - @Setter - public Set actuatorSet; - @Getter - @Setter - public String cryptoEngine = Constant.ECKey_ENGINE; - @Getter - @Setter - public boolean fullNodeHttpEnable = true; - @Getter - @Setter - public boolean solidityNodeHttpEnable = true; - @Getter - @Setter - public boolean jsonRpcHttpFullNodeEnable = false; - @Getter - @Setter - public boolean jsonRpcHttpSolidityNodeEnable = false; - @Getter - @Setter - public boolean jsonRpcHttpPBFTNodeEnable = false; - @Getter - @Setter - public int maxTransactionPendingSize; - @Getter - @Setter - public long pendingTransactionTimeout; - @Getter - @Setter - public boolean nodeMetricsEnable = false; + @Getter @Setter public String zenTokenId; + @Getter @Setter public long allowProtoFilterNum; + @Getter @Setter public long allowAccountStateRoot; + @Getter @Setter public int validContractProtoThreadNum = 1; + @Getter @Setter public int shieldedTransInPendingMaxCounts; + @Getter @Setter public long changedDelegation; + @Getter @Setter public Set actuatorSet; - @Getter - @Setter - public boolean metricsStorageEnable = false; + @Getter @Setter public String cryptoEngine = Constant.ECKey_ENGINE; + @Getter @Setter public boolean fullNodeHttpEnable = true; + @Getter @Setter public boolean solidityNodeHttpEnable = true; + @Getter @Setter public boolean jsonRpcHttpFullNodeEnable = false; + @Getter @Setter public boolean jsonRpcHttpSolidityNodeEnable = false; + @Getter @Setter public boolean jsonRpcHttpPBFTNodeEnable = false; + @Getter @Setter public int maxTransactionPendingSize; + @Getter @Setter public long pendingTransactionTimeout; + @Getter @Setter public boolean nodeMetricsEnable = false; - @Getter - @Setter - public String influxDbIp; + @Getter @Setter public boolean metricsStorageEnable = false; - @Getter - @Setter - public int influxDbPort; + @Getter @Setter public String influxDbIp; - @Getter - @Setter - public String influxDbDatabase; + @Getter @Setter public int influxDbPort; - @Getter - @Setter - public int metricsReportInterval = 10; + @Getter @Setter public String influxDbDatabase; - @Getter - @Setter - public int agreeNodeCount; + @Getter @Setter public int metricsReportInterval = 10; - @Getter - @Setter - public long allowPBFT; - @Getter - @Setter - public int rpcOnPBFTPort; - @Getter - @Setter - public int pBFTHttpPort; - @Getter - @Setter - public long oldSolidityBlockNum = -1; + @Getter @Setter public int agreeNodeCount; - @Getter/**/ - @Setter - public long allowShieldedTRC20Transaction; + @Getter @Setter public long allowPBFT; + @Getter @Setter public int rpcOnPBFTPort; + @Getter @Setter public int pBFTHttpPort; + @Getter @Setter public long oldSolidityBlockNum = -1; - @Getter/**/ - @Setter - public long allowTvmIstanbul; + @Getter /**/ @Setter public long allowShieldedTRC20Transaction; - @Getter - @Setter - public long allowTvmFreeze; + @Getter /**/ @Setter public long allowTvmIstanbul; - @Getter - @Setter - public long allowTvmVote; + @Getter @Setter public long allowTvmFreeze; - @Getter - @Setter - public long allowTvmLondon; + @Getter @Setter public long allowTvmVote; - @Getter - @Setter - public long allowTvmCompatibleEvm; + @Getter @Setter public long allowTvmLondon; - @Getter - @Setter - public boolean openHistoryQueryWhenLiteFN = false; + @Getter @Setter public long allowTvmCompatibleEvm; - @Getter - @Setter - public boolean isLiteFullNode = false; + @Getter @Setter public boolean openHistoryQueryWhenLiteFN = false; + + @Getter @Setter public boolean isLiteFullNode = false; @Getter @Setter @Parameter(names = {"--history-balance-lookup"}) public boolean historyBalanceLookup = false; - @Getter - @Setter - public boolean openPrintLog = true; - @Getter - @Setter - public boolean openTransactionSort = false; + @Getter @Setter public boolean openPrintLog = true; + @Getter @Setter public boolean openTransactionSort = false; - @Getter - @Setter - public long allowAccountAssetOptimization; + @Getter @Setter public long allowAccountAssetOptimization; - @Getter - @Setter - public List disabledApiList; + @Getter @Setter public List disabledApiList; private static double calcMaxTimeRatio() { - //return max(2.0, min(5.0, 5 * 4.0 / max(Runtime.getRuntime().availableProcessors(), 1))); + // return max(2.0, min(5.0, 5 * 4.0 / max(Runtime.getRuntime().availableProcessors(), 1))); return 5.0; } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/Constant.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/Constant.java index 0802b502..30cefb2a 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/Constant.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/Constant.java @@ -2,10 +2,10 @@ public class Constant { - //config for testnet, mainnet, beta + // config for testnet, mainnet, beta public static final String TESTNET_CONF = "config.conf"; - //config for junit test + // config for junit test public static final String TEST_CONF = "config-test.conf"; // locate in storageDbDirectory, store the db infos, @@ -14,16 +14,16 @@ public class Constant { // the block number that split between the snapshot and history public static final String SPLIT_BLOCK_NUM = "split_block_num"; - public static final byte ADD_PRE_FIX_BYTE_MAINNET = (byte) 0x41; //41 + address + public static final byte ADD_PRE_FIX_BYTE_MAINNET = (byte) 0x41; // 41 + address public static final String ADD_PRE_FIX_STRING_MAINNET = "41"; - public static final byte ADD_PRE_FIX_BYTE_TESTNET = (byte) 0xa0; //a0 + address + public static final byte ADD_PRE_FIX_BYTE_TESTNET = (byte) 0xa0; // a0 + address public static final String ADD_PRE_FIX_STRING_TESTNET = "a0"; // config for transaction public static final long TRANSACTION_MAX_BYTE_SIZE = 500 * 1_024L; - public static final long MAXIMUM_TIME_UNTIL_EXPIRATION = 24 * 60 * 60 * 1_000L; //one day - public static final long TRANSACTION_DEFAULT_EXPIRATION_TIME = 60 * 1_000L; //60 seconds - public static final long TRANSACTION_FEE_POOL_PERIOD = 1; //1 blocks + public static final long MAXIMUM_TIME_UNTIL_EXPIRATION = 24 * 60 * 60 * 1_000L; // one day + public static final long TRANSACTION_DEFAULT_EXPIRATION_TIME = 60 * 1_000L; // 60 seconds + public static final long TRANSACTION_FEE_POOL_PERIOD = 1; // 1 blocks // config for smart contract public static final long SUN_PER_ENERGY = 100; // 1 us = 100 SUN = 100 * 10^-6 TRX public static final long ENERGY_LIMIT_IN_CONSTANT_TX = 3_000_000L; // ref: 1 us = 1 energy @@ -31,28 +31,26 @@ public class Constant { public static final long PB_DEFAULT_ENERGY_LIMIT = 0L; public static final long CREATOR_DEFAULT_ENERGY_LIMIT = 1000 * 10_000L; - // Numbers public static final int ONE_HUNDRED = 100; public static final int ONE_THOUSAND = 1000; - public static final byte[] ZTRON_EXPANDSEED_PERSONALIZATION = {'Z', 't', 'r', 'o', 'n', '_', 'E', - 'x', - 'p', 'a', 'n', 'd', 'S', 'e', 'e', 'd'}; + public static final byte[] ZTRON_EXPANDSEED_PERSONALIZATION = { + 'Z', 't', 'r', 'o', 'n', '_', 'E', 'x', 'p', 'a', 'n', 'd', 'S', 'e', 'e', 'd' + }; public static final int ZC_DIVERSIFIER_SIZE = 11; public static final int ZC_OUTPUT_DESC_MAX_SIZE = 10; - /** * normal transaction is 0 representing normal transaction unexecuted deferred transaction is 1 * representing unexecuted deferred transaction executing deferred transaction is 2 representing * executing deferred transaction */ public static final int NORMALTRANSACTION = 0; + public static final int UNEXECUTEDDEFERREDTRANSACTION = 1; public static final int EXECUTINGDEFERREDTRANSACTION = 2; - // Configuration items public static final String NET_TYPE = "net.type"; public static final String TESTNET = "testnet"; @@ -108,26 +106,31 @@ public class Constant { public static final String NODE_RPC_THREAD = "node.rpc.thread"; public static final String NODE_SOLIDITY_THREADS = "node.solidity.threads"; - public static final String NODE_RPC_MAX_CONCURRENT_CALLS_PER_CONNECTION = "node.rpc.maxConcurrentCallsPerConnection"; + public static final String NODE_RPC_MAX_CONCURRENT_CALLS_PER_CONNECTION = + "node.rpc.maxConcurrentCallsPerConnection"; public static final String NODE_RPC_FLOW_CONTROL_WINDOW = "node.rpc.flowControlWindow"; - public static final String NODE_RPC_MAX_CONNECTION_IDLE_IN_MILLIS = "node.rpc.maxConnectionIdleInMillis"; + public static final String NODE_RPC_MAX_CONNECTION_IDLE_IN_MILLIS = + "node.rpc.maxConnectionIdleInMillis"; public static final String NODE_PRODUCED_TIMEOUT = "node.blockProducedTimeOut"; public static final String NODE_MAX_HTTP_CONNECT_NUMBER = "node.maxHttpConnectNumber"; public static final String NODE_NET_MAX_TRX_PER_SECOND = "node.netMaxTrxPerSecond"; - public static final String NODE_RPC_MAX_CONNECTION_AGE_IN_MILLIS = "node.rpc.maxConnectionAgeInMillis"; + public static final String NODE_RPC_MAX_CONNECTION_AGE_IN_MILLIS = + "node.rpc.maxConnectionAgeInMillis"; public static final String NODE_RPC_MAX_MESSAGE_SIZE = "node.rpc.maxMessageSize"; public static final String NODE_RPC_MAX_HEADER_LIST_SIZE = "node.rpc.maxHeaderListSize"; - public static final String NODE_OPEN_HISTORY_QUERY_WHEN_LITEFN = "node.openHistoryQueryWhenLiteFN"; + public static final String NODE_OPEN_HISTORY_QUERY_WHEN_LITEFN = + "node.openHistoryQueryWhenLiteFN"; public static final String BLOCK_MAINTENANCE_TIME_INTERVAL = "block.maintenanceTimeInterval"; public static final String BLOCK_PROPOSAL_EXPIRE_TIME = "block.proposalExpireTime"; public static final String BLOCK_CHECK_FROZEN_TIME = "block.checkFrozenTime"; - public static final String COMMITTEE_ALLOW_CREATION_OF_CONTRACTS = "committee.allowCreationOfContracts"; + public static final String COMMITTEE_ALLOW_CREATION_OF_CONTRACTS = + "committee.allowCreationOfContracts"; public static final String COMMITTEE_ALLOW_MULTI_SIGN = "committee.allowMultiSign"; @@ -139,11 +142,13 @@ public class Constant { public static final String COMMITTEE_ALLOW_TVM_TRANSFER_TRC10 = "committee.allowTvmTransferTrc10"; - public static final String COMMITTEE_ALLOW_TVM_CONSTANTINOPLE = "committee.allowTvmConstantinople"; + public static final String COMMITTEE_ALLOW_TVM_CONSTANTINOPLE = + "committee.allowTvmConstantinople"; public static final String COMMITTEE_ALLOW_TVM_SOLIDITY059 = "committee.allowTvmSolidity059"; - public static final String COMMITTEE_FORBID_TRANSFER_TO_CONTRACT = "committee.forbidTransferToContract"; + public static final String COMMITTEE_FORBID_TRANSFER_TO_CONTRACT = + "committee.forbidTransferToContract"; public static final String NODE_TCP_NETTY_WORK_THREAD_NUM = "node.tcpNettyWorkThreadNum"; @@ -175,7 +180,8 @@ public class Constant { public static final String TRX_REFERENCE_BLOCK = "trx.reference.block"; - public static final String TRX_EXPIRATION_TIME_IN_MILLIS_SECONDS = "trx.expiration.timeInMilliseconds"; + public static final String TRX_EXPIRATION_TIME_IN_MILLIS_SECONDS = + "trx.expiration.timeInMilliseconds"; public static final String NODE_RPC_MIN_EFFECTIVE_CONNECTION = "node.rpc.minEffectiveConnection"; @@ -187,13 +193,13 @@ public class Constant { public static final String VM_SAVE_INTERNAL_TX = "vm.saveInternalTx"; - // public static final String COMMITTEE_ALLOW_SHIELDED_TRANSACTION = "committee.allowShieldedTransaction"; + // public static final String COMMITTEE_ALLOW_SHIELDED_TRANSACTION = + // "committee.allowShieldedTransaction"; - public static final String COMMITTEE_ALLOW_SHIELDED_TRC20_TRANSACTION = "committee" - + ".allowShieldedTRC20Transaction"; + public static final String COMMITTEE_ALLOW_SHIELDED_TRC20_TRANSACTION = + "committee" + ".allowShieldedTRC20Transaction"; - public static final String COMMITTEE_ALLOW_TVM_ISTANBUL = "committee" - + ".allowTvmIstanbul"; + public static final String COMMITTEE_ALLOW_TVM_ISTANBUL = "committee" + ".allowTvmIstanbul"; public static final String COMMITTEE_ALLOW_MARKET_TRANSACTION = "committee.allowMarketTransaction"; @@ -202,8 +208,8 @@ public class Constant { public static final String EVENT_SUBSCRIBE_FILTER = "event.subscribe.filter"; - public static final String NODE_FULLNODE_ALLOW_SHIELDED_TRANSACTION = "node" - + ".fullNodeAllowShieldedTransaction"; + public static final String NODE_FULLNODE_ALLOW_SHIELDED_TRANSACTION = + "node" + ".fullNodeAllowShieldedTransaction"; public static final String NODE_ZEN_TOKENID = "node.zenTokenId"; @@ -219,7 +225,8 @@ public class Constant { public static final String NODE_FAST_FORWARD = "node.fastForward"; - public static final String NODE_SHIELDED_TRANS_IN_PENDING_MAX_COUNTS = "node.shieldedTransInPendingMaxCounts"; + public static final String NODE_SHIELDED_TRANS_IN_PENDING_MAX_COUNTS = + "node.shieldedTransInPendingMaxCounts"; public static final String RATE_LIMITER = "rate.limiter"; @@ -241,8 +248,10 @@ public class Constant { public static final String EVENT_SUBSCRIBE_TOPICS = "event.subscribe.topics"; public static final String EVENT_SUBSCRIBE_FROM_BLOCK = "event.subscribe.filter.fromblock"; public static final String EVENT_SUBSCRIBE_TO_BLOCK = "event.subscribe.filter.toblock"; - public static final String EVENT_SUBSCRIBE_CONTRACT_ADDRESS = "event.subscribe.filter.contractAddress"; - public static final String EVENT_SUBSCRIBE_CONTRACT_TOPIC = "event.subscribe.filter.contractTopic"; + public static final String EVENT_SUBSCRIBE_CONTRACT_ADDRESS = + "event.subscribe.filter.contractAddress"; + public static final String EVENT_SUBSCRIBE_CONTRACT_TOPIC = + "event.subscribe.filter.contractTopic"; public static final String NODE_DISCOVERY_BIND_IP = "node.discovery.bind.ip"; @@ -271,10 +280,13 @@ public class Constant { public static final String COMMITTEE_ALLOW_PBFT = "committee.allowPBFT"; public static final String NODE_AGREE_NODE_COUNT = "node.agreeNodeCount"; - public static final String COMMITTEE_ALLOW_TRANSACTION_FEE_POOL = "committee.allowTransactionFeePool"; - public static final String COMMITTEE_ALLOW_BLACK_HOLE_OPTIMIZATION = "committee.allowBlackHoleOptimization"; + public static final String COMMITTEE_ALLOW_TRANSACTION_FEE_POOL = + "committee.allowTransactionFeePool"; + public static final String COMMITTEE_ALLOW_BLACK_HOLE_OPTIMIZATION = + "committee.allowBlackHoleOptimization"; public static final String COMMITTEE_ALLOW_NEW_RESOURCE_MODEL = "committee.allowNewResourceModel"; - public static final String COMMITTEE_ALLOW_RECEIPTS_MERKLE_ROOT = "committee.allowReceiptsMerkleRoot"; + public static final String COMMITTEE_ALLOW_RECEIPTS_MERKLE_ROOT = + "committee.allowReceiptsMerkleRoot"; public static final String COMMITTEE_ALLOW_TVM_FREEZE = "committee.allowTvmFreeze"; public static final String COMMITTEE_ALLOW_TVM_VOTE = "committee.allowTvmVote"; @@ -286,13 +298,15 @@ public class Constant { public static final String METRICS_INFLUXDB_IP = "node.metrics.influxdb.ip"; public static final String METRICS_INFLUXDB_PORT = "node.metrics.influxdb.port"; public static final String METRICS_INFLUXDB_DATABASE = "node.metrics.influxdb.database"; - public static final String METRICS_REPORT_INTERVAL = "node.metrics.influxdb.metricsReportInterval"; + public static final String METRICS_REPORT_INTERVAL = + "node.metrics.influxdb.metricsReportInterval"; public static final String HISTORY_BALANCE_LOOKUP = "storage.balance.history.lookup"; public static final String OPEN_PRINT_LOG = "node.openPrintLog"; public static final String OPEN_TRANSACTION_SORT = "node.openTransactionSort"; - public static final String ALLOW_ACCOUNT_ASSET_OPTIMIZATION = "committee.allowAccountAssetOptimization"; + public static final String ALLOW_ACCOUNT_ASSET_OPTIMIZATION = + "committee.allowAccountAssetOptimization"; public static final String LOCAL_HOST = "127.0.0.1"; } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ContractHelper.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ContractHelper.java index 7de7f27f..de4f9110 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ContractHelper.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ContractHelper.java @@ -33,7 +33,9 @@ import stest.tron.wallet.common.client.WalletClient; @Slf4j -/** Helper for smart contract operations: deployment, triggering, ABI management, and constant calls. */ +/** + * Helper for smart contract operations: deployment, triggering, ABI management, and constant calls. + */ public class ContractHelper { // --------------------------------------------------------------------------- @@ -100,15 +102,15 @@ public static byte[] deployContractFallbackReceive( CreateSmartContract contractDeployContract = contractBuilder.setNewContract(builder.build()).build(); - - //estimateEnergyDeployContract + // estimateEnergyDeployContract if (null != libraryAddress) { - estimateDeployContractEnergy(PublicMethod.code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); + estimateDeployContractEnergy( + PublicMethod.code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); } else { - estimateDeployContractEnergy(code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); + estimateDeployContractEnergy( + code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); } - TransactionExtention transactionExtention = blockingStubFull.deployContract(contractDeployContract); if (transactionExtention == null || !transactionExtention.getResult().getResult()) { @@ -237,11 +239,13 @@ public static byte[] deployContract( CreateSmartContract contractDeployContract = contractBuilder.setNewContract(builder.build()).build(); - //estimateEnergyDeployContract + // estimateEnergyDeployContract if (null != libraryAddress) { - estimateDeployContractEnergy(PublicMethod.code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); + estimateDeployContractEnergy( + PublicMethod.code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); } else { - estimateDeployContractEnergy(code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); + estimateDeployContractEnergy( + code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); } TransactionExtention transactionExtention = @@ -402,11 +406,13 @@ public static Transaction deployContractWithoutBroadcast( CreateSmartContract contractDeployContract = contractBuilder.setNewContract(builder.build()).build(); - //estimateEnergyDeployContract + // estimateEnergyDeployContract if (null != libraryAddress) { - estimateDeployContractEnergy(PublicMethod.code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); + estimateDeployContractEnergy( + PublicMethod.code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); } else { - estimateDeployContractEnergy(code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); + estimateDeployContractEnergy( + code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); } TransactionExtention transactionExtention = @@ -461,9 +467,9 @@ public static Transaction deployContractWithoutBroadcast( System.out.println( "txid = " + ByteArray.toHexString( - Sha256Hash.hash( - CommonParameter.getInstance().isECKeyCryptoEngine(), - transaction.getRawData().toByteArray()))); + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()))); return transaction; } @@ -561,9 +567,10 @@ public static byte[] deployContractForLibrary( CreateSmartContract contractDeployContract = contractBuilder.setNewContract(builder.build()).build(); - //estimateEnergyDeployContract + // estimateEnergyDeployContract if (null != libraryAddress) { - estimateDeployContractEnergy(PublicMethod.code, value, "0", 0L, ownerAddress, blockingStubFull); + estimateDeployContractEnergy( + PublicMethod.code, value, "0", 0L, ownerAddress, blockingStubFull); } else { estimateDeployContractEnergy(code, value, "0", 0L, ownerAddress, blockingStubFull); } @@ -730,14 +737,15 @@ public static String deployContractAndGetTransactionInfoById( CreateSmartContract contractDeployContract = contractBuilder.setNewContract(builder.build()).build(); - //estimateEnergyDeployContract + // estimateEnergyDeployContract if (null != libraryAddress) { - estimateDeployContractEnergy(PublicMethod.code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); + estimateDeployContractEnergy( + PublicMethod.code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); } else { - estimateDeployContractEnergy(code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); + estimateDeployContractEnergy( + code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); } - TransactionExtention transactionExtention = blockingStubFull.deployContract(contractDeployContract); if (transactionExtention == null || !transactionExtention.getResult().getResult()) { @@ -865,15 +873,15 @@ public static GrpcAPI.Return deployContractAndGetResponse( CreateSmartContract contractDeployContract = contractBuilder.setNewContract(builder.build()).build(); - - //estimateEnergyDeployContract + // estimateEnergyDeployContract if (null != libraryAddress) { - estimateDeployContractEnergy(PublicMethod.code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); + estimateDeployContractEnergy( + PublicMethod.code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); } else { - estimateDeployContractEnergy(code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); + estimateDeployContractEnergy( + code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); } - TransactionExtention transactionExtention = blockingStubFull.deployContract(contractDeployContract); if (transactionExtention == null || !transactionExtention.getResult().getResult()) { @@ -1035,11 +1043,13 @@ public static String deployContractWithConstantParame( CreateSmartContract contractDeployContract = contractBuilder.setNewContract(builder.build()).build(); - //estimateEnergyDeployContract + // estimateEnergyDeployContract if (null != libraryAddress) { - estimateDeployContractEnergy(PublicMethod.code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); + estimateDeployContractEnergy( + PublicMethod.code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); } else { - estimateDeployContractEnergy(code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); + estimateDeployContractEnergy( + code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); } TransactionExtention transactionExtention = @@ -2491,8 +2501,7 @@ public static Optional estimateEnergy( String argsStr, Boolean isHex, long tokenValue, - String tokenId - ) { + String tokenId) { TriggerSmartContract.Builder builder = TriggerSmartContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(owner)); if (contractAddress != null) { @@ -2508,7 +2517,8 @@ public static Optional estimateEnergy( builder.setCallTokenValue(tokenValue); builder.setTokenId(Long.parseLong(tokenId)); } - GrpcAPI.EstimateEnergyMessage estimateEnergyMessage = blockingStubFull.estimateEnergy(builder.build()); + GrpcAPI.EstimateEnergyMessage estimateEnergyMessage = + blockingStubFull.estimateEnergy(builder.build()); return Optional.ofNullable(estimateEnergyMessage); } @@ -2522,8 +2532,7 @@ public static Optional estimateEnergySolidity( String argsStr, Boolean isHex, long tokenValue, - String tokenId - ) { + String tokenId) { TriggerSmartContract.Builder builder = TriggerSmartContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(owner)); if (contractAddress != null) { @@ -2539,19 +2548,19 @@ public static Optional estimateEnergySolidity( builder.setCallTokenValue(tokenValue); builder.setTokenId(Long.parseLong(tokenId)); } - GrpcAPI.EstimateEnergyMessage estimateEnergyMessage = blockingStubFull.estimateEnergy(builder.build()); + GrpcAPI.EstimateEnergyMessage estimateEnergyMessage = + blockingStubFull.estimateEnergy(builder.build()); return Optional.ofNullable(estimateEnergyMessage); } /** Estimate energy required to deploy a smart contract. */ public static Optional estimateEnergyDeployContract( - WalletGrpc.WalletBlockingStub blockingStubFull, - byte[] owner, - long callValue, - long tokenValue, - String tokenId, - String code - ) { + WalletGrpc.WalletBlockingStub blockingStubFull, + byte[] owner, + long callValue, + long tokenValue, + String tokenId, + String code) { TriggerSmartContract.Builder builder = TriggerSmartContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(owner)); builder.setData(ByteString.copyFrom(Hex.decode(code))); @@ -2560,88 +2569,87 @@ public static Optional estimateEnergyDeployContra builder.setCallTokenValue(tokenValue); builder.setTokenId(Long.parseLong(tokenId)); } - GrpcAPI.EstimateEnergyMessage estimateEnergyMessage = blockingStubFull.estimateEnergy(builder.build()); + GrpcAPI.EstimateEnergyMessage estimateEnergyMessage = + blockingStubFull.estimateEnergy(builder.build()); return Optional.ofNullable(estimateEnergyMessage); } /** Estimate and log energy for a contract deployment (currently a no-op placeholder). */ public static void estimateDeployContractEnergy( - String code, - long value, - String tokenId, - long tokenValue, - byte[] ownerAddress, - WalletGrpc.WalletBlockingStub blockingStubFull - ) { -// String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") -// .get(1); + String code, + long value, + String tokenId, + long tokenValue, + byte[] ownerAddress, + WalletGrpc.WalletBlockingStub blockingStubFull) { + // String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") + // .get(1); try { logger.info("temp skip estimateDeployContractEnergy"); -// logger.info("triggerConstantContract ------------ start -----------"); -// HttpResponse response = HttpMethod -// .triggerConstantContractWithData( -// httpnode, -// ownerAddress, null, null, null, code, value, tokenValue, Long.parseLong(tokenId)); -// JSONObject jsonObject = HttpMethod.parseResponseContent(response); -// HttpMethod.printJsonContent(jsonObject); -// Long constantEnergy = jsonObject.getLong("energy_used"); -// logger.info("constantEnergy:" + constantEnergy); -// -// TransactionExtention trx = PublicMethod -// .triggerConstantContractDeployContract( -// code, ownerAddress, value, tokenId, tokenValue, blockingStubFull); -// Long grpcConstantEnergy = trx.getEnergyUsed(); -// logger.info("grpcConstantEnergy:" + grpcConstantEnergy); -// Assert.assertEquals(grpcConstantEnergy.longValue(), constantEnergy.longValue()); -// logger.info("triggerConstantContract ------------ end -----------"); -// -// Long energyFee = PublicMethod.getChainParametersValue( -// ProposalEnum.GetEnergyFee.getProposalName(), blockingStubFull); -// logger.info("energyFee:" + energyFee); - - -// logger.info("EstimateEnergy -------- start ------"); -// response = HttpMethod.getEstimateEnergyDeployContract(httpnode, -// ownerAddress, null, null, null, code, value, tokenValue, Long.parseLong(tokenId), true); -// jsonObject = HttpMethod.parseResponseContent(response); -// HttpMethod.printJsonContent(jsonObject); -// Long estimateEnergy = jsonObject.getLong("energy_required"); -// logger.info("estimateEnergy:" + estimateEnergy); - - -// Optional estimateEnergyMessage = -// PublicMethod.estimateEnergyDeployContract(blockingStubFull2, -// ownerAddress, -// value, -// tokenValue, -// tokenId, -// code); -// logger.info(estimateEnergyMessage.get().toString()); -// Long grpcEstimateEnergy = estimateEnergyMessage.get().getEnergyRequired(); -// logger.info("grpcEstimateEnergy: " + grpcEstimateEnergy); -// logger.info("EstimateEnergy ------------ end -----------"); - -// logger.info("(estimateEnergy - constantEnergy) * energyFee: " -// + (estimateEnergy - constantEnergy) * energyFee); -// Assert.assertEquals(grpcEstimateEnergy.longValue(), estimateEnergy.longValue()); -// Assert.assertTrue((estimateEnergy - constantEnergy) * energyFee < 1000000L); + // logger.info("triggerConstantContract ------------ start -----------"); + // HttpResponse response = HttpMethod + // .triggerConstantContractWithData( + // httpnode, + // ownerAddress, null, null, null, code, value, tokenValue, + // Long.parseLong(tokenId)); + // JSONObject jsonObject = HttpMethod.parseResponseContent(response); + // HttpMethod.printJsonContent(jsonObject); + // Long constantEnergy = jsonObject.getLong("energy_used"); + // logger.info("constantEnergy:" + constantEnergy); + // + // TransactionExtention trx = PublicMethod + // .triggerConstantContractDeployContract( + // code, ownerAddress, value, tokenId, tokenValue, blockingStubFull); + // Long grpcConstantEnergy = trx.getEnergyUsed(); + // logger.info("grpcConstantEnergy:" + grpcConstantEnergy); + // Assert.assertEquals(grpcConstantEnergy.longValue(), constantEnergy.longValue()); + // logger.info("triggerConstantContract ------------ end -----------"); + // + // Long energyFee = PublicMethod.getChainParametersValue( + // ProposalEnum.GetEnergyFee.getProposalName(), blockingStubFull); + // logger.info("energyFee:" + energyFee); + + // logger.info("EstimateEnergy -------- start ------"); + // response = HttpMethod.getEstimateEnergyDeployContract(httpnode, + // ownerAddress, null, null, null, code, value, tokenValue, + // Long.parseLong(tokenId), true); + // jsonObject = HttpMethod.parseResponseContent(response); + // HttpMethod.printJsonContent(jsonObject); + // Long estimateEnergy = jsonObject.getLong("energy_required"); + // logger.info("estimateEnergy:" + estimateEnergy); + + // Optional estimateEnergyMessage = + // PublicMethod.estimateEnergyDeployContract(blockingStubFull2, + // ownerAddress, + // value, + // tokenValue, + // tokenId, + // code); + // logger.info(estimateEnergyMessage.get().toString()); + // Long grpcEstimateEnergy = estimateEnergyMessage.get().getEnergyRequired(); + // logger.info("grpcEstimateEnergy: " + grpcEstimateEnergy); + // logger.info("EstimateEnergy ------------ end -----------"); + + // logger.info("(estimateEnergy - constantEnergy) * energyFee: " + // + (estimateEnergy - constantEnergy) * energyFee); + // Assert.assertEquals(grpcEstimateEnergy.longValue(), estimateEnergy.longValue()); + // Assert.assertTrue((estimateEnergy - constantEnergy) * energyFee < 1000000L); } catch (Exception e) { logger.error("EnergyEstimateDeploy: catch Exception!!"); e.printStackTrace(); } - } /** Trigger a constant contract call for deploying a contract (used for energy estimation). */ public static TransactionExtention triggerConstantContractDeployContract( - String code, - byte[] ownerAddress, - long callValue, - String tokenId, - long tokenValue, - WalletGrpc.WalletBlockingStub blockingStubFull) { + String code, + byte[] ownerAddress, + long callValue, + String tokenId, + long tokenValue, + WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] owner = ownerAddress; TriggerSmartContract.Builder builder = TriggerSmartContract.newBuilder(); @@ -2654,7 +2662,7 @@ public static TransactionExtention triggerConstantContractDeployContract( } TriggerSmartContract triggerContract = builder.build(); TransactionExtention transactionExtention = - blockingStubFull.triggerConstantContract(triggerContract); + blockingStubFull.triggerConstantContract(triggerContract); return transactionExtention; } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/DailyBuildReport.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/DailyBuildReport.java index 49159d56..71c4b802 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/DailyBuildReport.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/DailyBuildReport.java @@ -15,9 +15,10 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; - import lombok.extern.slf4j.Slf4j; import org.testng.Assert; +import org.testng.ISuite; +import org.testng.ISuiteListener; import org.testng.ITestContext; import org.testng.ITestResult; import org.testng.TestListenerAdapter; @@ -25,8 +26,9 @@ import org.tron.api.WalletGrpc; import org.tron.protos.Protocol; import stest.tron.wallet.common.client.Configuration; + @Slf4j -public class DailyBuildReport extends TestListenerAdapter { +public class DailyBuildReport extends TestListenerAdapter implements ISuiteListener { StringBuffer passedDescriptionList = new StringBuffer(""); StringBuffer failedDescriptionList = new StringBuffer(""); @@ -36,16 +38,13 @@ public class DailyBuildReport extends TestListenerAdapter { private AtomicInteger skippedNum = new AtomicInteger(0); private String reportPath; public Map transactionType = new HashMap<>(); - public Long endBlockNum = 0L; + public Long endBlockNum = 0L; public static Long startBlockNum = 0L; public AtomicLong totalTransactionNum = new AtomicLong(0L); public ManagedChannel channelFull = null; public WalletGrpc.WalletBlockingStub blockingStubFull = null; - private String fullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(0); - - private String reportFlag = Configuration.getByPath("testng.conf") - .getString("defaultParameter.ReportFlag"); + private String fullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0); private String slack = "slack"; @@ -56,8 +55,7 @@ public class DailyBuildReport extends TestListenerAdapter { @Override public void onConfigurationFailure(ITestResult itr) { super.onConfigurationFailure(itr); - failedDescriptionList.append(itr.getTestClass().getName() + ": " - + "beforeClass" + "\n"); + failedDescriptionList.append(itr.getTestClass().getName() + ": " + "beforeClass" + "\n"); failedNum.getAndAdd(1); String caseFailedNotification = itr.getTestClass().getName() + " beforeClass Failed"; logger.info(caseFailedNotification); @@ -67,12 +65,13 @@ public void onConfigurationFailure(ITestResult itr) { PublicMethod.exec(cmd); logger.info("Send slack end className: " + itr.getTestClass().getName()); } catch (InterruptedException e) { - logger.info("Slack notification delivery failed. Please verify Slack integration " - + "configuration. If slack notifications are not needed, this can be safely ignored."); + logger.info( + "Slack notification delivery failed. Please verify Slack integration " + + "configuration. If slack notifications are not needed," + + " this can be safely ignored."); } } - @Override public void onStart(ITestContext context) { reportPath = "Daily_Build_Report"; @@ -85,111 +84,146 @@ public void onStart(ITestContext context) { } } + public void onStart(ISuite suite) { + // no-op + } + @Override public void onTestStart(ITestResult result) { - logger.info(result.getMethod().getRealClass().getName() + "." + result.getMethod().getMethodName() + " Start"); + logger.info( + result.getMethod().getRealClass().getName() + + "." + + result.getMethod().getMethodName() + + " Start"); } - @Override public void onTestSuccess(ITestResult result) { - passedDescriptionList.append(result.getMethod().getRealClass() + ": " - + result.getMethod().getDescription() + "\n"); + passedDescriptionList.append( + result.getMethod().getRealClass() + ": " + result.getMethod().getDescription() + "\n"); passedNum.getAndAdd(1); - logger.info(result.getMethod().getRealClass().getName() + "." + result.getMethod().getMethodName() + " Success"); + logger.info( + result.getMethod().getRealClass().getName() + + "." + + result.getMethod().getMethodName() + + " Success"); } @Override public void onTestFailure(ITestResult result) { - failedDescriptionList.append(result.getMethod().getRealClass() + ": " - + result.getMethod().getDescription() + "\n"); + failedDescriptionList.append( + result.getMethod().getRealClass() + ": " + result.getMethod().getDescription() + "\n"); failedNum.getAndAdd(1); - String caseFailedNotification = result.getMethod().getRealClass().getName() + "." + result.getMethod().getMethodName() + " Failed"; + String caseFailedNotification = + result.getMethod().getRealClass().getName() + + "." + + result.getMethod().getMethodName() + + " Failed"; logger.info(caseFailedNotification); String cmd = slack + " " + caseFailedNotification; try { - logger.info("Send slack begin caseName: "+ result.getMethod().getMethodName()); + logger.info("Send slack begin caseName: " + result.getMethod().getMethodName()); PublicMethod.exec(cmd); - logger.info("Send slack end caseName: "+ result.getMethod().getMethodName()); + logger.info("Send slack end caseName: " + result.getMethod().getMethodName()); } catch (InterruptedException e) { - logger.info("Slack notification delivery failed. Please verify slack integration " - + "configuration. If slack notifications are not needed, this can be safely ignored."); + logger.info( + "Slack notification delivery failed. Please verify slack integration " + + "configuration. If slack notifications are not needed," + + " this can be safely ignored."); } - } @Override public void onTestSkipped(ITestResult result) { - skippedDescriptionList.append(result.getMethod().getRealClass() + ": " - + result.getMethod().getDescription() + "\n"); + skippedDescriptionList.append( + result.getMethod().getRealClass() + ": " + result.getMethod().getDescription() + "\n"); skippedNum.getAndAdd(1); - logger.info(result.getMethod().getRealClass().getName() + "." + result.getMethod().getMethodName() + " Skip"); - + logger.info( + result.getMethod().getRealClass().getName() + + "." + + result.getMethod().getMethodName() + + " Skip"); } - @Override public void onFinish(ITestContext testContext) { - if(testContext.getName().equals(reportFlag)) { - logger.info(testContext.getName() + "test finished, start to generate report..."); - StringBuilder sb = new StringBuilder(); - // on beforeClass Failed occur, Total num will be bigger than ALL-pass case. - sb.append("Total: " + (passedNum.get() + failedNum.get() + skippedNum.get()) + ", " + "Passed: " + passedNum - + ", " + "Failed: " + failedNum + ", " + "Skipped: " + skippedNum + "\n"); - sb.append("------------------------------------------------------------------------------\n"); - List> list = null; - try { - list = calculateAfterDailyBuild(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - sb.append("Total transaction number:" + totalTransactionNum.get() + "\n"); - sb.append("Transaction type list:" + "\n"); - for (Map.Entry entry : list) { - sb.append(entry.getKey()); - for (int i = entry.getKey().length(); i < 40; i++) { - sb.append(" "); - } - sb.append(" : " + entry.getValue() + "\n"); + // report generation moved to ISuiteListener.onFinish to run after all tests complete + } + @Override + public void onFinish(ISuite suite) { + logger.info("Suite [" + suite.getName() + "] finished, start to generate report..."); + StringBuilder sb = new StringBuilder(); + // on beforeClass Failed occur, Total num will be bigger than ALL-pass case. + sb.append("Total: " + (passedNum.get() + failedNum.get() + skippedNum.get()) + + ", " + "Passed: " + passedNum + + ", " + "Failed: " + failedNum + ", " + "Skipped: " + skippedNum + "\n"); + sb.append("------------------------------------------------------------------------------\n"); + List> list = null; + try { + list = calculateAfterDailyBuild(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + sb.append("Total transaction number:" + totalTransactionNum.get() + "\n"); + sb.append("Transaction type list:" + "\n"); + for (Map.Entry entry : list) { + sb.append(entry.getKey()); + for (int i = entry.getKey().length(); i < 40; i++) { + sb.append(" "); } - sb.append("------------------------------------------------------------------------------\n"); - sb.append("Passed list " + "\n"); - //sb.append("Passed case List: " + "\n"); - sb.append(passedDescriptionList.toString()); - sb.append("------------------------------------------------------------------------------\n"); - sb.append("Failed list: " + "\n"); - //sb.append("Failed case List: " + "\n"); - sb.append(failedDescriptionList.toString()); - sb.append("------------------------------------------------------------------------------\n"); - sb.append("Skipped list: " + "\n"); - //sb.append("Skipped case List: " + "\n"); - sb.append(skippedDescriptionList.toString()); - sb.append("----------------------------------------------------------------\n"); + sb.append(" : " + entry.getValue() + "\n"); + } + sb.append("------------------------------------------------------------------------------\n"); + sb.append("Passed list " + "\n"); + sb.append(passedDescriptionList.toString()); + sb.append("------------------------------------------------------------------------------\n"); + sb.append("Failed list: " + "\n"); + sb.append(failedDescriptionList.toString()); + sb.append("------------------------------------------------------------------------------\n"); + sb.append("Skipped list: " + "\n"); + sb.append(skippedDescriptionList.toString()); + sb.append("----------------------------------------------------------------\n"); + + String res = sb.toString(); + try { + Files.write((Paths.get(reportPath)), res.getBytes("utf-8"), StandardOpenOption.APPEND); + } catch (IOException e) { + e.printStackTrace(); + } - String res = sb.toString(); + boolean sr3Status = checkSRStatus(); + if (!sr3Status) { + logger.info("3rd witness not produce block"); + String cmd = slack + " " + "3rd witness not produce block"; try { - Files.write((Paths.get(reportPath)), res.getBytes("utf-8"), StandardOpenOption.APPEND); - } catch (IOException e) { - e.printStackTrace(); + PublicMethod.exec(cmd); + } catch (InterruptedException e) { + logger.info("Slack notification delivery failed for SR3 status."); } - } + try { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } } - /** - * calculate transaction num and transaction type After DailyBuild. - */ + /** calculate transaction num and transaction type After DailyBuild. */ public List> calculateAfterDailyBuild() throws InterruptedException { - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext() - .build(); + channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); blockingStubFull = WalletGrpc.newBlockingStub(channelFull); - endBlockNum = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + endBlockNum = + blockingStubFull + .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); System.out.println("-----startnum :" + startBlockNum + "-----endnum:" + endBlockNum); - if(endBlockNum >= 8000) { + if (endBlockNum >= 8000) { System.out.println("Not daily build env, skip this step"); return new ArrayList<>(); } @@ -214,51 +248,44 @@ public List> calculateAfterDailyBuild() throws Interr } } - boolean sr3Status = checkSRStatus(); - //if(!sr3Status){ - // String cmd = slack + " " + "3rd witness not produce block"; - // PublicMethod.exec(cmd); - //} - Assert.assertTrue(sr3Status,"3rd witness not produce block"); - - try { - if (channelFull != null) { - channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } - } catch (InterruptedException e) { - e.printStackTrace(); - } - List> list = new ArrayList<>(transactionType.entrySet()); - Collections.sort(list, new Comparator>() { - @Override - public int compare(Map.Entry o1, Map.Entry o2) { - return (o2.getValue()).compareTo(o1.getValue()); - } - }); + Collections.sort( + list, + new Comparator>() { + @Override + public int compare(Map.Entry o1, Map.Entry o2) { + return (o2.getValue()).compareTo(o1.getValue()); + } + }); return list; } - public boolean checkSRStatus(){ + public boolean checkSRStatus() { String add41 = ByteArray.toHexString(witnessAddress03); - Long beginNum = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + Long beginNum = + blockingStubFull + .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); Long nowNum = beginNum; while (nowNum - beginNum < 210) { List list = PublicMethod.listWitnesses(blockingStubFull).get().getWitnessesList(); - for (Protocol.Witness tem: list) { + for (Protocol.Witness tem : list) { if ((add41.equalsIgnoreCase(ByteArray.toHexString(tem.getAddress().toByteArray()))) && (tem.getTotalProduced() > 3)) { return true; } } PublicMethod.waitProduceNextBlock(blockingStubFull); - nowNum = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + nowNum = + blockingStubFull + .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); } return false; } - } - diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/DataWord.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/DataWord.java index 69443a51..90b13d16 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/DataWord.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/DataWord.java @@ -15,6 +15,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with the ethereumJ library. If not, see . */ + package stest.tron.wallet.common.client.utils; import com.fasterxml.jackson.annotation.JsonCreator; @@ -39,12 +40,11 @@ public class DataWord implements Comparable { public static final BigInteger _2_256 = BigInteger.valueOf(2).pow(256); public static final BigInteger MAX_VALUE = _2_256.subtract(BigInteger.ONE); // TODO not safe - public static final DataWord ZERO = new DataWord( - new byte[WORD_SIZE]); // don't push it in to the stack + public static final DataWord ZERO = + new DataWord(new byte[WORD_SIZE]); // don't push it in to the stack private byte[] data = new byte[WORD_SIZE]; - public DataWord() { - } + public DataWord() {} public DataWord(int num) { this(ByteBuffer.allocate(4).putInt(num)); @@ -94,13 +94,16 @@ public static DataWord of(byte num) { byte[] bb = new byte[WORD_SIZE]; bb[31] = num; return new DataWord(bb); - } public static String bigIntValue(byte[] data) { return new BigInteger(data).toString(); } + public String bigIntValue() { + return new BigInteger(data).toString(); + } + public static boolean isZero(byte[] data) { for (byte tmp : data) { if (tmp != 0) { @@ -110,12 +113,26 @@ public static boolean isZero(byte[] data) { return true; } + public boolean isZero() { + for (byte tmp : data) { + if (tmp != 0) { + return false; + } + } + return true; + } + public static String shortHex(byte[] data) { byte[] bytes = ByteUtil.stripLeadingZeroes(data); String hexValue = Hex.toHexString(bytes).toUpperCase(); return "0x" + hexValue.replaceFirst("^0+(?!$)", ""); } + public String shortHex() { + String hexValue = Hex.toHexString(getNoLeadZeroesData()).toUpperCase(); + return "0x" + hexValue.replaceFirst("^0+(?!$)", ""); + } + public static long sizeInWords(long bytesSize) { return bytesSize == 0 ? 0 : (bytesSize - 1) / WORD_SIZE + 1; } @@ -153,9 +170,7 @@ public byte[] getData() { return data; } - /** - * be careful, this one will not throw Exception when data.length > WORD_SIZE - */ + /** be careful, this one will not throw Exception when data.length > WORD_SIZE */ public byte[] getClonedData() { byte[] ret = ByteUtil.EMPTY_BYTE_ARRAY; if (data != null) { @@ -206,9 +221,7 @@ public int intValue() { return intVal; } - /** - * In case of int overflow returns Integer.MAX_VALUE otherwise works as #intValue() - */ + /** In case of int overflow returns Integer.MAX_VALUE otherwise works as #intValue() */ public int intValueSafe() { int bytesOccupied = bytesOccupied(); int intValue = intValue(); @@ -235,9 +248,7 @@ public long longValue() { return longVal; } - /** - * In case of long overflow returns Long.MAX_VALUE otherwise works as #longValue() - */ + /** In case of long overflow returns Long.MAX_VALUE otherwise works as #longValue() */ public long longValueSafe() { int bytesOccupied = bytesOccupied(); long longValue = longValue(); @@ -251,19 +262,6 @@ public BigInteger sValue() { return new BigInteger(data); } - public String bigIntValue() { - return new BigInteger(data).toString(); - } - - public boolean isZero() { - for (byte tmp : data) { - if (tmp != 0) { - return false; - } - } - return true; - } - // only in case of signed operation // when the number is explicit defined // as negative @@ -441,11 +439,6 @@ public String toPrefixString() { return Hex.toHexString(pref).substring(0, 6); } - public String shortHex() { - String hexValue = Hex.toHexString(getNoLeadZeroesData()).toUpperCase(); - return "0x" + hexValue.replaceFirst("^0+(?!$)", ""); - } - public DataWord clone() { return new DataWord(Arrays.clone(data)); } @@ -462,7 +455,6 @@ public boolean equals(Object o) { DataWord dataWord = (DataWord) o; return java.util.Arrays.equals(data, dataWord.data); - } @Override @@ -475,9 +467,8 @@ public int compareTo(DataWord o) { if (o == null || o.getData() == null) { return -1; } - int result = FastByteComparisons.compareTo( - data, 0, data.length, - o.getData(), 0, o.getData().length); + int result = + FastByteComparisons.compareTo(data, 0, data.length, o.getData(), 0, o.getData().length); // Convert result into -1, 0 or 1 as is the convention return (int) Math.signum(result); } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/DecodeUtil.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/DecodeUtil.java index 546d2faf..0a7e016f 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/DecodeUtil.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/DecodeUtil.java @@ -18,17 +18,15 @@ public static boolean addressValid(byte[] address) { } if (address.length != ADDRESS_SIZE / 2) { logger.warn( - "Warning: Address length need " + ADDRESS_SIZE + " but " + address.length - + " !!"); + "Warning: Address length need " + ADDRESS_SIZE + " but " + address.length + " !!"); return false; } if (address[0] != addressPreFixByte) { - logger.warn("Warning: Address need prefix with " + addressPreFixByte + " but " - + address[0] + " !!"); + logger.warn( + "Warning: Address need prefix with " + addressPreFixByte + " but " + address[0] + " !!"); return false; } return true; } - } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ECKey.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ECKey.java index b255181b..c1a42ea7 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ECKey.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ECKey.java @@ -51,10 +51,6 @@ import org.bouncycastle.math.ec.ECPoint; import org.bouncycastle.util.encoders.Base64; import org.bouncycastle.util.encoders.Hex; -//import org.tron.common.crypto.jce.ECKeyFactory; -//import org.tron.common.crypto.jce.ECKeyPairGenerator; -//import org.tron.common.crypto.jce.TronCastleProvider; -//import org.tron.common.utils.BIUtil; import stest.tron.wallet.common.client.utils.jce.ECKeyFactory; import stest.tron.wallet.common.client.utils.jce.ECKeyPairGenerator; import stest.tron.wallet.common.client.utils.jce.TronCastleProvider; @@ -62,10 +58,9 @@ @Slf4j(topic = "crypto") public class ECKey implements Serializable, SignInterface { - /** - * The parameters of the secp256k1 curve. - */ + /** The parameters of the secp256k1 curve. */ public static final ECDomainParameters CURVE; + public static final ECParameterSpec CURVE_SPEC; /** @@ -76,8 +71,8 @@ public class ECKey implements Serializable, SignInterface { *

See https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki * #Low_S_values_in_signatures */ - public static final BigInteger HALF_CURVE_ORDER; + private static final BigInteger SECP256K1N = new BigInteger("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", 16); private static final SecureRandom secureRandom; @@ -86,10 +81,9 @@ public class ECKey implements Serializable, SignInterface { static { // All clients must agree on the curve to use by agreement. X9ECParameters params = SECNamedCurves.getByName("secp256k1"); - CURVE = new ECDomainParameters(params.getCurve(), params.getG(), - params.getN(), params.getH()); - CURVE_SPEC = new ECParameterSpec(params.getCurve(), params.getG(), - params.getN(), params.getH()); + CURVE = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH()); + CURVE_SPEC = + new ECParameterSpec(params.getCurve(), params.getG(), params.getN(), params.getH()); HALF_CURVE_ORDER = params.getN().shiftRight(1); secureRandom = new SecureRandom(); } @@ -141,15 +135,17 @@ public ECKey(Provider provider, SecureRandom secureRandom) { pub = extractPublicKey((ECPublicKey) pubKey); } else { throw new AssertionError( - "Expected Provider " + provider.getName() + "Expected Provider " + + provider.getName() + " to produce a subtype of ECPublicKey, found " + pubKey.getClass()); } } /** - * Generates an entirely new keypair with the given {@link SecureRandom} object.

BouncyCastle - * will be used as the Java Security Provider + * Generates an entirely new keypair with the given {@link SecureRandom} object. + * + *

BouncyCastle will be used as the Java Security Provider * * @param secureRandom - */ @@ -162,7 +158,6 @@ public ECKey(SecureRandom secureRandom) { * *

All private key operations will use the provider. */ - public ECKey(byte[] key, boolean isPrivateKey) { if (isPrivateKey) { BigInteger pk = new BigInteger(1, key); @@ -182,10 +177,10 @@ public ECKey(Provider provider, @Nullable PrivateKey privKey, ECPoint pub) { this.privKey = privKey; } else { throw new IllegalArgumentException( - "Expected EC private key, given a private key object with" + - " class " - + privKey.getClass().toString() + - " and algorithm " + "Expected EC private key, given a private key object with" + + " class " + + privKey.getClass().toString() + + " and algorithm " + privKey.getAlgorithm()); } @@ -197,15 +192,12 @@ public ECKey(Provider provider, @Nullable PrivateKey privKey, ECPoint pub) { } /** - * Pair a private key integer with a public EC point

BouncyCastle will be used as the Java - * Security Provider + * Pair a private key integer with a public EC point + * + *

BouncyCastle will be used as the Java Security Provider */ public ECKey(@Nullable BigInteger priv, ECPoint pub) { - this( - TronCastleProvider.getInstance(), - privateKeyFromBigInteger(priv), - pub - ); + this(TronCastleProvider.getInstance(), privateKeyFromBigInteger(priv), pub); } /* Convert a Java JCE ECPublicKey into a BouncyCastle ECPoint @@ -225,8 +217,7 @@ private static ECPoint extractPublicKey(final ECPublicKey ecPublicKey) { * a fallback that covers this case is to check the key algorithm */ private static boolean isECPrivateKey(PrivateKey privKey) { - return privKey instanceof ECPrivateKey || privKey.getAlgorithm() - .equals("EC"); + return privKey instanceof ECPrivateKey || privKey.getAlgorithm().equals("EC"); } /* Convert a BigInteger into a PrivateKey object @@ -236,10 +227,8 @@ private static PrivateKey privateKeyFromBigInteger(BigInteger priv) { return null; } else { try { - return ECKeyFactory - .getInstance(TronCastleProvider.getInstance()) - .generatePrivate(new ECPrivateKeySpec(priv, - CURVE_SPEC)); + return ECKeyFactory.getInstance(TronCastleProvider.getInstance()) + .generatePrivate(new ECPrivateKeySpec(priv, CURVE_SPEC)); } catch (InvalidKeySpecException ex) { throw new AssertionError("Assumed correct key spec statically"); } @@ -302,8 +291,7 @@ public static ECKey fromPrivate(byte[] privKeyBytes) { * @param pub - * @return - */ - public static ECKey fromPrivateAndPrecalculatedPublic(BigInteger priv, - ECPoint pub) { + public static ECKey fromPrivateAndPrecalculatedPublic(BigInteger priv, ECPoint pub) { return new ECKey(priv, pub); } @@ -316,12 +304,10 @@ public static ECKey fromPrivateAndPrecalculatedPublic(BigInteger priv, * @param pub - * @return - */ - public static ECKey fromPrivateAndPrecalculatedPublic(byte[] priv, byte[] - pub) { + public static ECKey fromPrivateAndPrecalculatedPublic(byte[] priv, byte[] pub) { check(priv != null, "Private key must not be null"); check(pub != null, "Public key must not be null"); - return new ECKey(new BigInteger(1, priv), CURVE.getCurve() - .decodePoint(pub)); + return new ECKey(new BigInteger(1, priv), CURVE.getCurve().decodePoint(pub)); } /** @@ -354,15 +340,15 @@ public static ECKey fromPublicOnly(byte[] pub) { * @param compressed - * @return - */ - public static byte[] publicKeyFromPrivate(BigInteger privKey, boolean - compressed) { + public static byte[] publicKeyFromPrivate(BigInteger privKey, boolean compressed) { ECPoint point = CURVE.getG().multiply(privKey); return point.getEncoded(compressed); } /** - * Compute the encoded X, Y coordinates of a public point.

This is the encoded public key - * without the leading byte. + * Compute the encoded X, Y coordinates of a public point. + * + *

This is the encoded public key without the leading byte. * * @param pubPoint a public point * @return 64-byte X,Y point pair @@ -385,8 +371,8 @@ public static ECKey fromNodeId(byte[] nodeId) { return ECKey.fromPublicOnly(pubBytes); } - public static byte[] signatureToKeyBytes(byte[] messageHash, String - signatureBase64) throws SignatureException { + public static byte[] signatureToKeyBytes(byte[] messageHash, String signatureBase64) + throws SignatureException { byte[] signatureEncoded; try { signatureEncoded = Base64.decode(signatureBase64); @@ -397,8 +383,8 @@ public static byte[] signatureToKeyBytes(byte[] messageHash, String } // Parse the signature bytes into r/s and the selector value. if (signatureEncoded.length < 65) { - throw new SignatureException("Signature truncated, expected 65 " + - "bytes and got " + signatureEncoded.length); + throw new SignatureException( + "Signature truncated, expected 65 " + "bytes and got " + signatureEncoded.length); } return signatureToKeyBytes( @@ -409,10 +395,9 @@ public static byte[] signatureToKeyBytes(byte[] messageHash, String (byte) (signatureEncoded[0] & 0xFF))); } - public static byte[] signatureToKeyBytes(byte[] messageHash, - ECDSASignature sig) throws SignatureException { - check(messageHash.length == 32, "messageHash argument has length " + - messageHash.length); + public static byte[] signatureToKeyBytes(byte[] messageHash, ECDSASignature sig) + throws SignatureException { + check(messageHash.length == 32, "messageHash argument has length " + messageHash.length); int header = sig.v; // The header byte: 0x1B = first key with even y, 0x1C = first key // with odd y, @@ -425,11 +410,9 @@ public static byte[] signatureToKeyBytes(byte[] messageHash, header -= 4; } int recId = header - 27; - byte[] key = ECKey.recoverPubBytesFromSignature(recId, sig, - messageHash); + byte[] key = ECKey.recoverPubBytesFromSignature(recId, sig, messageHash); if (key == null) { - throw new SignatureException("Could not recover public key from " + - "signature"); + throw new SignatureException("Could not recover public key from " + "signature"); } return key; } @@ -441,10 +424,9 @@ public static byte[] signatureToKeyBytes(byte[] messageHash, * @param signatureBase64 Base-64 encoded signature * @return 20-byte address */ - public static byte[] signatureToAddress(byte[] messageHash, String - signatureBase64) throws SignatureException { - return Hash.computeAddress(signatureToKeyBytes(messageHash, - signatureBase64)); + public static byte[] signatureToAddress(byte[] messageHash, String signatureBase64) + throws SignatureException { + return Hash.computeAddress(signatureToKeyBytes(messageHash, signatureBase64)); } /** @@ -454,9 +436,8 @@ public static byte[] signatureToAddress(byte[] messageHash, String * @param sig - * @return 20-byte address */ - public static byte[] signatureToAddress(byte[] messageHash, - ECDSASignature sig) throws - SignatureException { + public static byte[] signatureToAddress(byte[] messageHash, ECDSASignature sig) + throws SignatureException { return Hash.computeAddress(signatureToKeyBytes(messageHash, sig)); } @@ -467,10 +448,9 @@ public static byte[] signatureToAddress(byte[] messageHash, * @param signatureBase64 Base-64 encoded signature * @return ECKey */ - public static ECKey signatureToKey(byte[] messageHash, String - signatureBase64) throws SignatureException { - final byte[] keyBytes = signatureToKeyBytes(messageHash, - signatureBase64); + public static ECKey signatureToKey(byte[] messageHash, String signatureBase64) + throws SignatureException { + final byte[] keyBytes = signatureToKeyBytes(messageHash, signatureBase64); return ECKey.fromPublicOnly(keyBytes); } @@ -494,21 +474,35 @@ public static boolean isPubKeyCanonical(byte[] pubkey) { } /** - *

Given the components of a signature and a selector value, recover and return the public key - * that generated the signature according to the algorithm in SEC1v2 section 4.1.6.

+ * Returns true if this pubkey is canonical, i.e. the correct length taking into account + * compression. + * + * @return - + */ + public boolean isPubKeyCanonical() { + return isPubKeyCanonical(pub.getEncoded(/* uncompressed */ false)); + } + + /** + * Given the components of a signature and a selector value, recover and return the public key + * that generated the signature according to the algorithm in SEC1v2 section 4.1.6. + * + *

* - *

The recId is an index from 0 to 3 which indicates which of the 4 possible allKeys is - * the + *

The recId is an index from 0 to 3 which indicates which of the 4 possible allKeys is the * correct one. Because the key recovery operation yields multiple potential allKeys, the correct * key must either be stored alongside the signature, or you must be willing to try each recId in - * turn until you find one that outputs the key you are expecting.

+ * turn until you find one that outputs the key you are expecting. + * + *

* - *

If this method returns null it means recovery was not possible and recId should be - * iterated.

+ *

If this method returns null it means recovery was not possible and recId should be iterated. * - *

Given the above two points, a correct usage of this method is inside a for loop from 0 - * to 3, and if the output is null OR a key that is not the one you expect, you try again with the - * next recId.

+ *

+ * + *

Given the above two points, a correct usage of this method is inside a for loop from 0 to 3, + * and if the output is null OR a key that is not the one you expect, you try again with the next + * recId. * * @param recId Which possible key to recover. * @param sig the R and S components of the signature, wrapped. @@ -516,8 +510,8 @@ public static boolean isPubKeyCanonical(byte[] pubkey) { * @return 65-byte encoded public key */ @Nullable - public static byte[] recoverPubBytesFromSignature(int recId, - ECDSASignature sig, byte[] messageHash) { + public static byte[] recoverPubBytesFromSignature( + int recId, ECDSASignature sig, byte[] messageHash) { check(recId >= 0, "recId must be positive"); check(sig.r.signum() >= 0, "r must be positive"); check(sig.s.signum() >= 0, "s must be positive"); @@ -525,7 +519,7 @@ public static byte[] recoverPubBytesFromSignature(int recId, // 1.0 For j from 0 to h (h == recId here and the loop is outside // this function) // 1.1 Let x = r + jn - BigInteger n = CURVE.getN(); // Curve order. + BigInteger n = CURVE.getN(); // Curve order. BigInteger i = BigInteger.valueOf((long) recId / 2); BigInteger x = sig.r.add(i.multiply(n)); // 1.2. Convert the integer x to an octet string X of length mlen @@ -541,7 +535,7 @@ public static byte[] recoverPubBytesFromSignature(int recId, // More concisely, what these points mean is to use X as a compressed // public key. ECCurve.Fp curve = (ECCurve.Fp) CURVE.getCurve(); - BigInteger prime = curve.getQ(); // Bouncy Castle is not consistent + BigInteger prime = curve.getQ(); // Bouncy Castle is not consistent // about the letter it uses for the prime. if (x.compareTo(prime) >= 0) { // Cannot have point co-ordinates larger than this as everything @@ -581,8 +575,7 @@ public static byte[] recoverPubBytesFromSignature(int recId, BigInteger rInv = sig.r.modInverse(n); BigInteger srInv = rInv.multiply(sig.s).mod(n); BigInteger eInvrInv = rInv.multiply(eInv).mod(n); - ECPoint.Fp q = (ECPoint.Fp) ECAlgorithms.sumOfTwoMultiplies(CURVE - .getG(), eInvrInv, R, srInv); + ECPoint.Fp q = (ECPoint.Fp) ECAlgorithms.sumOfTwoMultiplies(CURVE.getG(), eInvrInv, R, srInv); return q.getEncoded(/* compressed */ false); } @@ -593,10 +586,9 @@ public static byte[] recoverPubBytesFromSignature(int recId, * @return 20-byte address */ @Nullable - public static byte[] recoverAddressFromSignature(int recId, - ECDSASignature sig, byte[] messageHash) { - final byte[] pubBytes = recoverPubBytesFromSignature(recId, sig, - messageHash); + public static byte[] recoverAddressFromSignature( + int recId, ECDSASignature sig, byte[] messageHash) { + final byte[] pubBytes = recoverPubBytesFromSignature(recId, sig, messageHash); if (pubBytes == null) { return null; } else { @@ -611,10 +603,8 @@ public static byte[] recoverAddressFromSignature(int recId, * @return ECKey */ @Nullable - public static ECKey recoverFromSignature(int recId, ECDSASignature sig, - byte[] messageHash) { - final byte[] pubBytes = recoverPubBytesFromSignature(recId, sig, - messageHash); + public static ECKey recoverFromSignature(int recId, ECDSASignature sig, byte[] messageHash) { + final byte[] pubBytes = recoverPubBytesFromSignature(recId, sig, messageHash); if (pubBytes == null) { return null; } else { @@ -629,11 +619,9 @@ public static ECKey recoverFromSignature(int recId, ECDSASignature sig, * @param yBit - * @return - */ - private static ECPoint decompressKey(BigInteger xBN, boolean yBit) { X9IntegerConverter x9 = new X9IntegerConverter(); - byte[] compEnc = x9.integerToBytes(xBN, 1 + x9.getByteLength(CURVE - .getCurve())); + byte[] compEnc = x9.integerToBytes(xBN, 1 + x9.getByteLength(CURVE.getCurve())); compEnc[0] = (byte) (yBit ? 0x03 : 0x02); return CURVE.getCurve().decodePoint(compEnc); } @@ -688,9 +676,7 @@ public byte[] Base64toBytes(String signature) { return ByteUtil.appendByte(temp, first); } - /** - * Generates the NodeID based on this key, that is the public key without first format byte - */ + /** Generates the NodeID based on this key, that is the public key without first format byte */ public byte[] getNodeId() { if (nodeId == null) { nodeId = pubBytesWithoutFormat(this.pub); @@ -698,7 +684,6 @@ public byte[] getNodeId() { return nodeId; } - @Override public byte[] getPrivateKey() { return getPrivKeyBytes(); @@ -755,8 +740,7 @@ public String toStringWithPrivate() { StringBuilder b = new StringBuilder(); b.append(toString()); if (privKey != null && privKey instanceof BCECPrivateKey) { - b.append(" priv:").append(Hex.toHexString(((BCECPrivateKey) - privKey).getD().toByteArray())); + b.append(" priv:").append(Hex.toHexString(((BCECPrivateKey) privKey).getD().toByteArray())); } return b.toString(); } @@ -770,22 +754,20 @@ public String toStringWithPrivate() { */ public ECDSASignature doSign(byte[] input) { if (input.length != 32) { - throw new IllegalArgumentException("Expected 32 byte input to " + - "ECDSA signature, not " + input.length); + throw new IllegalArgumentException( + "Expected 32 byte input to " + "ECDSA signature, not " + input.length); } // No decryption of private key required. if (privKey == null) { throw new MissingPrivateKeyException(); } if (privKey instanceof BCECPrivateKey) { - ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new - SHA256Digest())); - ECPrivateKeyParameters privKeyParams = new ECPrivateKeyParameters - (((BCECPrivateKey) privKey).getD(), CURVE); + ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest())); + ECPrivateKeyParameters privKeyParams = + new ECPrivateKeyParameters(((BCECPrivateKey) privKey).getD(), CURVE); signer.init(true, privKeyParams); BigInteger[] components = signer.generateSignature(input); - return new ECDSASignature(components[0], components[1]) - .toCanonicalised(); + return new ECDSASignature(components[0], components[1]).toCanonicalised(); } else { throw new RuntimeException("ECKey signing error"); } @@ -812,24 +794,13 @@ public ECDSASignature sign(byte[] messageHash) { } } if (recId == -1) { - throw new RuntimeException("Could not construct a recoverable key" + - ". This should never happen."); + throw new RuntimeException( + "Could not construct a recoverable key" + ". This should never happen."); } sig.v = (byte) (recId + 27); return sig; } - - /** - * Returns true if this pubkey is canonical, i.e. the correct length taking into account - * compression. - * - * @return - - */ - public boolean isPubKeyCanonical() { - return isPubKeyCanonical(pub.getEncoded(/* uncompressed */ false)); - } - /** * Returns a 32 byte array containing the private key, or null if the key is encrypted or public * only @@ -874,10 +845,10 @@ public int hashCode() { public static class ECDSASignature implements SignatureInterface { - /** - * The two components of the signature. - */ - public final BigInteger r, s; + /** The two components of the signature. */ + public final BigInteger r; + public final BigInteger s; + public byte v; /** @@ -904,8 +875,7 @@ public ECDSASignature(byte[] r, byte[] s, byte v) { * @return - */ private static ECDSASignature fromComponents(byte[] r, byte[] s) { - return new ECDSASignature(new BigInteger(1, r), new BigInteger(1, - s)); + return new ECDSASignature(new BigInteger(1, r), new BigInteger(1, s)); } /** @@ -914,15 +884,13 @@ private static ECDSASignature fromComponents(byte[] r, byte[] s) { * @param v - * @return - */ - public static ECDSASignature fromComponents(byte[] r, byte[] s, byte - v) { + public static ECDSASignature fromComponents(byte[] r, byte[] s, byte v) { ECDSASignature signature = fromComponents(r, s); signature.v = v; return signature; } - public static boolean validateComponents(BigInteger r, BigInteger s, - byte v) { + public static boolean validateComponents(BigInteger r, BigInteger s, byte v) { if (v != 27 && v != 28) { return false; @@ -941,7 +909,6 @@ public static boolean validateComponents(BigInteger r, BigInteger s, return BIUtil.isLessThan(s, SECP256K1N); } - public boolean validateComponents() { return validateComponents(r, s, v); } @@ -963,11 +930,9 @@ public ECDSASignature toCanonicalised() { } } - /** - * @return - - */ + /** @return - */ public String toBase64() { - byte[] sigData = new byte[65]; // 1 header + 32 bytes for R + 32 + byte[] sigData = new byte[65]; // 1 header + 32 bytes for R + 32 // bytes for S sigData[0] = v; System.arraycopy(ByteUtil.bigIntegerToBytes(this.r, 32), 0, sigData, 1, 32); @@ -975,16 +940,13 @@ public String toBase64() { return new String(Base64.encode(sigData), Charset.forName("UTF-8")); } - public byte[] toByteArray() { - final byte fixedV = this.v >= 27 - ? (byte) (this.v - 27) - : this.v; + final byte fixedV = this.v >= 27 ? (byte) (this.v - 27) : this.v; return ByteUtil.merge( ByteUtil.bigIntegerToBytes(this.r, 32), ByteUtil.bigIntegerToBytes(this.s, 32), - new byte[]{fixedV}); + new byte[] {fixedV}); } public String toHex() { @@ -1017,8 +979,5 @@ public int hashCode() { } @SuppressWarnings("serial") - public static class MissingPrivateKeyException extends RuntimeException { - - } - + public static class MissingPrivateKeyException extends RuntimeException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/EnergyCost.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/EnergyCost.java index 1bca8816..aa2f7e9c 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/EnergyCost.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/EnergyCost.java @@ -46,7 +46,6 @@ public class EnergyCost { private static final long STOP = 0; private static final long CREATE_DATA = 200; - public static long getNewAcctCall() { return NEW_ACCT_CALL; } @@ -54,8 +53,4 @@ public static long getNewAcctCall() { public static long getCreateData() { return CREATE_DATA; } - - - - } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/FailureClassifier.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/FailureClassifier.java index edef9ab9..c94c174e 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/FailureClassifier.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/FailureClassifier.java @@ -12,20 +12,22 @@ /** * TestNG listener that classifies test failures by root cause. * - *

At the end of each suite, prints a summary that separates environment - * issues from real bugs, so developers can focus on actionable failures. + *

At the end of each suite, prints a summary that separates environment issues from real bugs, + * so developers can focus on actionable failures. * *

Classification categories: + * *

    - *
  • {@code ENV_NODE_DOWN} — gRPC connection refused or UNAVAILABLE
  • - *
  • {@code ENV_SINGLE_NODE} — @MultiNode test skipped on single-node
  • - *
  • {@code ENV_NO_MONGO} — MongoDB-related failure
  • - *
  • {@code FLAKY} — Test marked with @Flaky annotation
  • - *
  • {@code TIMEOUT} — Execution timeout
  • - *
  • {@code BUG} — Likely a real code bug (assertion failure, NPE, etc.)
  • + *
  • {@code ENV_NODE_DOWN} — gRPC connection refused or UNAVAILABLE + *
  • {@code ENV_SINGLE_NODE} — @MultiNode test skipped on single-node + *
  • {@code ENV_NO_MONGO} — MongoDB-related failure + *
  • {@code FLAKY} — Test marked with @Flaky annotation + *
  • {@code TIMEOUT} — Execution timeout + *
  • {@code BUG} — Likely a real code bug (assertion failure, NPE, etc.) *
* *

Register in testng XML: + * *

  * <listeners>
  *   <listener class-name="stest.tron.wallet.common.client.utils.FailureClassifier"/>
@@ -50,8 +52,7 @@ public FailureClassifier() {
   @Override
   public void onTestFailure(ITestResult result) {
     totalFailures++;
-    String testName = result.getTestClass().getRealClass().getSimpleName()
-        + "." + result.getName();
+    String testName = result.getTestClass().getRealClass().getSimpleName() + "." + result.getName();
     Throwable cause = result.getThrowable();
     String category = classify(result, cause);
     classified.get(category).add(testName);
@@ -63,10 +64,12 @@ public void onTestSkipped(ITestResult result) {
     Throwable cause = result.getThrowable();
     if (cause instanceof SkipException) {
       String msg = cause.getMessage();
-      if (msg != null && (msg.contains("Multi-node") || msg.contains("single-node")
-          || msg.contains("fullnode"))) {
-        String testName = result.getTestClass().getRealClass().getSimpleName()
-            + "." + result.getName();
+      if (msg != null
+          && (msg.contains("Multi-node")
+              || msg.contains("single-node")
+              || msg.contains("fullnode"))) {
+        String testName =
+            result.getTestClass().getRealClass().getSimpleName() + "." + result.getName();
         classified.get("ENV_SINGLE_NODE").add(testName);
       }
     }
@@ -159,8 +162,7 @@ private boolean isFlaky(ITestResult result) {
     if (testClass.getAnnotation(Flaky.class) != null) {
       return true;
     }
-    java.lang.reflect.Method method =
-        result.getMethod().getConstructorOrMethod().getMethod();
+    java.lang.reflect.Method method = result.getMethod().getConstructorOrMethod().getMethod();
     return method != null && method.getAnnotation(Flaky.class) != null;
   }
 
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/FastByteComparisons.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/FastByteComparisons.java
index 658e0bd6..825c2698 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/FastByteComparisons.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/FastByteComparisons.java
@@ -2,7 +2,6 @@
 
 import com.google.common.primitives.UnsignedBytes;
 
-
 /**
  * Utility code to do optimized byte-array comparison. This is borrowed and slightly modified from
  * Guava's {@link UnsignedBytes} class to be able to compare arrays that start at non-zero offsets.
@@ -26,8 +25,7 @@ public static boolean equalByte(byte[] b1, byte[] b2) {
    * @return int
    */
   public static int compareTo(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
-    return LexicographicalComparerHolder.BEST_COMPARER.compareTo(
-        b1, s1, l1, b2, s2, l2);
+    return LexicographicalComparerHolder.BEST_COMPARER.compareTo(b1, s1, l1, b2, s2, l2);
   }
 
   private static Comparer lexicographicalComparerJavaImpl() {
@@ -36,8 +34,7 @@ private static Comparer lexicographicalComparerJavaImpl() {
 
   private interface Comparer {
 
-    int compareTo(T buffer1, int offset1, int length1,
-        T buffer2, int offset2, int length2);
+    int compareTo(T buffer1, int offset1, int length1, T buffer2, int offset2, int length2);
   }
 
   /**
@@ -61,8 +58,7 @@ static Comparer getBestComparer() {
 
         // yes, UnsafeComparer does implement Comparer
         @SuppressWarnings("unchecked")
-        Comparer comparer =
-            (Comparer) theClass.getEnumConstants()[0];
+        Comparer comparer = (Comparer) theClass.getEnumConstants()[0];
         return comparer;
       } catch (Throwable t) { // ensure we really catch *everything*
         return lexicographicalComparerJavaImpl();
@@ -73,12 +69,10 @@ private enum PureJavaComparer implements Comparer {
       INSTANCE;
 
       @Override
-      public int compareTo(byte[] buffer1, int offset1, int length1,
-          byte[] buffer2, int offset2, int length2) {
+      public int compareTo(
+          byte[] buffer1, int offset1, int length1, byte[] buffer2, int offset2, int length2) {
         // Short circuit equal case
-        if (buffer1 == buffer2
-            && offset1 == offset2
-            && length1 == length2) {
+        if (buffer1 == buffer2 && offset1 == offset2 && length1 == length2) {
           return 0;
         }
         int end1 = offset1 + length1;
@@ -93,7 +87,5 @@ public int compareTo(byte[] buffer1, int offset1, int length1,
         return length1 - length2;
       }
     }
-
-
   }
 }
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/FileUtil.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/FileUtil.java
index 03268fa8..ef94e1a4 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/FileUtil.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/FileUtil.java
@@ -16,52 +16,48 @@
 
 public class FileUtil {
 
-  /**
-   * constructor.
-   */
-
+  /** constructor. */
   public static List recursiveList(String path) throws IOException {
 
     final List files = new ArrayList<>();
 
-    Files.walkFileTree(Paths.get(path), new FileVisitor() {
-      @Override
-      public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
-        return FileVisitResult.CONTINUE;
-      }
+    Files.walkFileTree(
+        Paths.get(path),
+        new FileVisitor() {
+          @Override
+          public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
+            return FileVisitResult.CONTINUE;
+          }
 
-      @Override
-      public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
-        files.add(file.toString());
-        return FileVisitResult.CONTINUE;
-      }
+          @Override
+          public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
+            files.add(file.toString());
+            return FileVisitResult.CONTINUE;
+          }
 
-      @Override
-      public FileVisitResult visitFileFailed(Path file, IOException exc) {
-        return FileVisitResult.CONTINUE;
-      }
+          @Override
+          public FileVisitResult visitFileFailed(Path file, IOException exc) {
+            return FileVisitResult.CONTINUE;
+          }
 
-      @Override
-      public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
-        return FileVisitResult.CONTINUE;
-      }
-    });
+          @Override
+          public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
+            return FileVisitResult.CONTINUE;
+          }
+        });
 
     return files;
   }
 
-  /**
-   * constructor.
-   */
-
+  /** constructor. */
   public static boolean recursiveDelete(String fileName) {
     File file = new File(fileName);
     if (file.exists()) {
-      //check if the file is a directory
+      // check if the file is a directory
       if (file.isDirectory()) {
         if ((file.list()).length > 0) {
           for (String s : file.list()) {
-            //call deletion of file individually
+            // call deletion of file individually
             recursiveDelete(fileName + System.getProperty("file.separator") + s);
           }
         }
@@ -75,10 +71,7 @@ public static boolean recursiveDelete(String fileName) {
     }
   }
 
-  /**
-   * constructor.
-   */
-
+  /** constructor. */
   public static void saveData(String filePath, byte[] data) {
     FileOutputStream fos = null;
     try {
@@ -99,10 +92,7 @@ public static void saveData(String filePath, byte[] data) {
     }
   }
 
-  /**
-   * constructor.
-   */
-
+  /** constructor. */
   public static byte[] readData(String filePath) {
     FileInputStream fi = null;
     try {
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/Flaky.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/Flaky.java
index afa4a83f..2b788502 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/Flaky.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/Flaky.java
@@ -9,10 +9,11 @@
 /**
  * Marks a test method or class as flaky.
  *
- * 

Flaky tests are those that fail intermittently due to timing, environment, - * or external service dependencies rather than actual code bugs. + *

Flaky tests are those that fail intermittently due to timing, environment, or external service + * dependencies rather than actual code bugs. * *

Usage: + * *

  * {@literal @}Flaky(reason = "Depends on MongoDB availability",
  *        since = "2026-04-03",
@@ -22,10 +23,11 @@
  * 
* *

Governance rules: + * *

    - *
  • Every {@code @Flaky} annotation must include a {@code reason}
  • - *
  • Tests marked flaky for more than 30 days without a fix should be reviewed for removal
  • - *
  • Flaky tests still run in CI but failures are tracked separately
  • + *
  • Every {@code @Flaky} annotation must include a {@code reason} + *
  • Tests marked flaky for more than 30 days without a fix should be reviewed for removal + *
  • Flaky tests still run in CI but failures are tracked separately *
*/ @Documented diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/FlakyTestListener.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/FlakyTestListener.java index e63eace1..8cfe3fb1 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/FlakyTestListener.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/FlakyTestListener.java @@ -10,11 +10,11 @@ /** * TestNG listener that tracks flaky test results separately. * - *

When a test annotated with {@link Flaky} fails, it is logged but does not - * count as an unexpected failure. At the end of the suite, a summary of all - * flaky failures is printed. + *

When a test annotated with {@link Flaky} fails, it is logged but does not count as an + * unexpected failure. At the end of the suite, a summary of all flaky failures is printed. * *

Register in testng XML: + * *

  * <listeners>
  *   <listener class-name="stest.tron.wallet.common.client.utils.FlakyTestListener"/>
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/GovernanceHelper.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/GovernanceHelper.java
index 1877a822..a3ccfc52 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/GovernanceHelper.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/GovernanceHelper.java
@@ -13,10 +13,6 @@
 import org.tron.api.GrpcAPI.TransactionExtention;
 import org.tron.api.WalletGrpc;
 import org.tron.api.WalletSolidityGrpc;
-import stest.tron.wallet.common.client.utils.ECKey;
-import stest.tron.wallet.common.client.utils.CommonParameter;
-import stest.tron.wallet.common.client.utils.ByteArray;
-import stest.tron.wallet.common.client.utils.Sha256Hash;
 import org.tron.protos.Protocol;
 import org.tron.protos.Protocol.ChainParameters;
 import org.tron.protos.Protocol.Transaction;
@@ -33,28 +29,30 @@ public class GovernanceHelper {
 
   /** Check whether the FreezeV2 proposal (UnfreezeDelayDays) is enabled on-chain. */
   public static Boolean freezeV2ProposalIsOpen(WalletGrpc.WalletBlockingStub blockingStubFull) {
-    return GovernanceHelper.getChainParametersValue(ProposalEnum.GetUnfreezeDelayDays
-        .getProposalName(), blockingStubFull) > 0;
+    return GovernanceHelper.getChainParametersValue(
+            ProposalEnum.GetUnfreezeDelayDays.getProposalName(), blockingStubFull)
+        > 0;
   }
 
-
   /** Check whether the TronPower (AllowNewResourceModel) proposal is enabled on-chain. */
   public static Boolean tronPowerProposalIsOpen(WalletGrpc.WalletBlockingStub blockingStubFull) {
-    return GovernanceHelper.getChainParametersValue(ProposalEnum.GetAllowNewResourceModel
-        .getProposalName(), blockingStubFull) == 1;
+    return GovernanceHelper.getChainParametersValue(
+            ProposalEnum.GetAllowNewResourceModel.getProposalName(), blockingStubFull)
+        == 1;
   }
 
   /** Check whether the AllowDynamicEnergy proposal is enabled on-chain. */
-  public static Boolean getAllowDynamicEnergyProposalIsOpen(WalletGrpc.WalletBlockingStub blockingStubFull) {
-    return GovernanceHelper.getChainParametersValue(ProposalEnum.GetAllowDynamicEnergy
-        .getProposalName(), blockingStubFull) == 1;
+  public static Boolean getAllowDynamicEnergyProposalIsOpen(
+      WalletGrpc.WalletBlockingStub blockingStubFull) {
+    return GovernanceHelper.getChainParametersValue(
+            ProposalEnum.GetAllowDynamicEnergy.getProposalName(), blockingStubFull)
+        == 1;
   }
 
-
-
   /** Get the current memo fee from the proposal parameters. */
   public static Long getProposalMemoFee(WalletGrpc.WalletBlockingStub blockingStubFull) {
-    return GovernanceHelper.getChainParametersValue(ProposalEnum.GetMemoFee.getProposalName(),blockingStubFull);
+    return GovernanceHelper.getChainParametersValue(
+        ProposalEnum.GetMemoFee.getProposalName(), blockingStubFull);
   }
 
   /** Query the memo fee price history string from the full node. */
@@ -68,7 +66,8 @@ public static String getEnergyPrice(WalletGrpc.WalletBlockingStub blockingStubFu
   }
 
   /** Query the energy price history string from the solidity node. */
-  public static String getEnergyPriceSolidity(WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) {
+  public static String getEnergyPriceSolidity(
+      WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) {
     return blockingStubFull.getEnergyPrices(EmptyMessage.newBuilder().build()).getPrices();
   }
 
@@ -78,7 +77,8 @@ public static String getBandwidthPrices(WalletGrpc.WalletBlockingStub blockingSt
   }
 
   /** Query the bandwidth price history string from the solidity node. */
-  public static String getBandwidthPricesSolidity(WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) {
+  public static String getBandwidthPricesSolidity(
+      WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) {
     return blockingStubFull.getBandwidthPrices(EmptyMessage.newBuilder().build()).getPrices();
   }
 
@@ -264,20 +264,19 @@ public static boolean deleteProposal(
   }
 
   /** Look up a chain parameter value by its proposal name string. */
-  public static Long getChainParametersValue(String proposalName,WalletGrpc.WalletBlockingStub blockingStubFull) {
-    ChainParameters chainParameters = blockingStubFull
-        .getChainParameters(EmptyMessage.newBuilder().build());
+  public static Long getChainParametersValue(
+      String proposalName, WalletGrpc.WalletBlockingStub blockingStubFull) {
+    ChainParameters chainParameters =
+        blockingStubFull.getChainParameters(EmptyMessage.newBuilder().build());
     Optional getChainParameters = Optional.ofNullable(chainParameters);
     logger.info(Long.toString(getChainParameters.get().getChainParameterCount()));
     for (Integer i = 0; i < getChainParameters.get().getChainParameterCount(); i++) {
-      if(getChainParameters.get().getChainParameter(i).getKey().equals(proposalName)) {
+      if (getChainParameters.get().getChainParameter(i).getKey().equals(proposalName)) {
         return getChainParameters.get().getChainParameter(i).getValue();
       }
     }
 
     return 0L;
-
-
   }
 
   /** List all active witnesses from the full node. */
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/Hash.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/Hash.java
index 5b203f63..466913a3 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/Hash.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/Hash.java
@@ -19,9 +19,6 @@
 package stest.tron.wallet.common.client.utils;
 
 import static java.util.Arrays.copyOfRange;
-//import static org.tron.common.utils.ByteUtil.EMPTY_BYTE_ARRAY;
-//import static org.tron.common.utils.ByteUtil.isNullOrZeroArray;
-//import static org.tron.common.utils.ByteUtil.isSingleZero;
 
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
@@ -33,7 +30,6 @@
 import org.bouncycastle.crypto.digests.RIPEMD160Digest;
 import org.bouncycastle.math.ec.ECPoint;
 import stest.tron.wallet.common.client.utils.jce.TronCastleProvider;
-//import org.tron.common.crypto.jce.TronCastleProvider;
 
 @Slf4j(topic = "crypto")
 public class Hash {
@@ -78,22 +74,19 @@ public class Hash {
   public static byte[] sha3(byte[] input) {
     MessageDigest digest;
     try {
-      digest = MessageDigest.getInstance(HASH_256_ALGORITHM_NAME,
-          CRYPTO_PROVIDER);
+      digest = MessageDigest.getInstance(HASH_256_ALGORITHM_NAME, CRYPTO_PROVIDER);
       digest.update(input);
       return digest.digest();
     } catch (NoSuchAlgorithmException e) {
       logger.error(ALGORITHM_NOT_FOUND, e);
       throw new RuntimeException(e);
     }
-
   }
 
   public static byte[] sha3(byte[] input1, byte[] input2) {
     MessageDigest digest;
     try {
-      digest = MessageDigest.getInstance(HASH_256_ALGORITHM_NAME,
-          CRYPTO_PROVIDER);
+      digest = MessageDigest.getInstance(HASH_256_ALGORITHM_NAME, CRYPTO_PROVIDER);
       digest.update(input1, 0, input1.length);
       digest.update(input2, 0, input2.length);
       return digest.digest();
@@ -114,8 +107,7 @@ public static byte[] sha3(byte[] input1, byte[] input2) {
   public static byte[] sha3(byte[] input, int start, int length) {
     MessageDigest digest;
     try {
-      digest = MessageDigest.getInstance(HASH_256_ALGORITHM_NAME,
-          CRYPTO_PROVIDER);
+      digest = MessageDigest.getInstance(HASH_256_ALGORITHM_NAME, CRYPTO_PROVIDER);
       digest.update(input, start, length);
       return digest.digest();
     } catch (NoSuchAlgorithmException e) {
@@ -128,7 +120,7 @@ public static byte[] encodeElement(byte[] srcData) {
 
     // [0x80]
     if (ByteUtil.isNullOrZeroArray(srcData)) {
-      return new byte[]{(byte) OFFSET_SHORT_ITEM};
+      return new byte[] {(byte) OFFSET_SHORT_ITEM};
 
       // [0x00]
     } else if (ByteUtil.isSingleZero(srcData)) {
@@ -181,8 +173,7 @@ public static byte[] computeAddress(ECPoint pubPoint) {
   }
 
   public static byte[] computeAddress(byte[] pubBytes) {
-    return sha3omit12(
-        Arrays.copyOfRange(pubBytes, 1, pubBytes.length));
+    return sha3omit12(Arrays.copyOfRange(pubBytes, 1, pubBytes.length));
   }
 
   /**
@@ -198,10 +189,10 @@ public static byte[] sha3omit12(byte[] input) {
     return address;
   }
 
-   /** @param data - message to hash
-    *
-    * @return - ripemd160 hash of the message
-    */
+  /**
+   * @param data - message to hash
+   * @return - ripemd160 hash of the message
+   */
   public static byte[] ripemd160(byte[] data) {
     Digest digest = new RIPEMD160Digest();
 
@@ -210,5 +201,4 @@ public static byte[] ripemd160(byte[] data) {
     digest.doFinal(resBuf, 0);
     return resBuf;
   }
-
 }
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/HttpMethod.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/HttpMethod.java
index 4387a81f..7e782bf2 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/HttpMethod.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/HttpMethod.java
@@ -7,7 +7,6 @@
 import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
 import com.google.protobuf.ByteString;
-import io.grpc.ManagedChannel;
 import io.netty.util.internal.StringUtil;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
@@ -30,7 +29,6 @@
 import org.junit.Assert;
 import org.testng.collections.Lists;
 import org.tron.api.GrpcAPI;
-import org.tron.api.WalletGrpc;
 import org.tron.protos.Protocol;
 import stest.tron.wallet.common.client.Configuration;
 import stest.tron.wallet.common.client.utils.zen.address.DiversifierT;
@@ -69,7 +67,7 @@ public static Integer getWitnessNum() {
   /** constructor. */
   public static HttpResponse updateAccount(
       String httpNode, byte[] updateAccountAddress, String accountName, String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/updateaccount";
       JsonObject userBaseObj2 = new JsonObject();
@@ -95,7 +93,7 @@ public static HttpResponse setAccountId(
       String accountId,
       Boolean visable,
       String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/setaccountid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -119,7 +117,7 @@ public static HttpResponse setAccountId(
   /** constructor. */
   public static HttpResponse updateWitness(
       String httpNode, byte[] witnessAddress, String updateUrl, String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/updatewitness";
       JsonObject userBaseObj2 = new JsonObject();
@@ -141,7 +139,7 @@ public static HttpResponse updateWitness(
   /** constructor. */
   public static HttpResponse voteWitnessAccount(
       String httpNode, byte[] ownerAddress, JsonArray voteArray, String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/votewitnessaccount";
       JsonObject userBaseObj2 = new JsonObject();
@@ -164,7 +162,7 @@ public static HttpResponse voteWitnessAccount(
   /** constructor. */
   public static HttpResponse createAccount(
       String httpNode, byte[] ownerAddress, byte[] accountAddress, String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/createaccount";
       JsonObject userBaseObj2 = new JsonObject();
@@ -183,7 +181,7 @@ public static HttpResponse createAccount(
 
   /** constructor. */
   public static HttpResponse createWitness(String httpNode, byte[] ownerAddress, String url) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/createwitness";
       JsonObject userBaseObj2 = new JsonObject();
@@ -203,7 +201,7 @@ public static HttpResponse createWitness(String httpNode, byte[] ownerAddress, S
 
   /** constructor. */
   public static HttpResponse withdrawBalance(String httpNode, byte[] witnessAddress) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/withdrawbalance";
       JsonObject userBaseObj2 = new JsonObject();
@@ -220,19 +218,19 @@ public static HttpResponse withdrawBalance(String httpNode, byte[] witnessAddres
     return response;
   }
 
-
   /** constructor. */
-  public static HttpResponse withdrawExpireUnfreeze(String httpNode, byte[] ownerAddress,String ownerKey) {
-      HttpResponse response = null;
+  public static HttpResponse withdrawExpireUnfreeze(
+      String httpNode, byte[] ownerAddress, String ownerKey) {
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/withdrawexpireunfreeze";
       JsonObject userBaseObj2 = new JsonObject();
       userBaseObj2.addProperty("owner_address", ByteArray.toHexString(ownerAddress));
       response = createConnect(requestUrl, userBaseObj2);
       logger.info(userBaseObj2.toString());
-       String transactionString = EntityUtils.toString(response.getEntity());
-       String transactionSignString = gettransactionsign(httpNode,transactionString,ownerKey);
-        response = broadcastTransaction(httpNode,transactionSignString);
+      String transactionString = EntityUtils.toString(response.getEntity());
+      String transactionSignString = gettransactionsign(httpNode, transactionString, ownerKey);
+      response = broadcastTransaction(httpNode, transactionSignString);
     } catch (Exception e) {
       e.printStackTrace();
       return null;
@@ -243,7 +241,7 @@ public static HttpResponse withdrawExpireUnfreeze(String httpNode, byte[] ownerA
   /** constructor. */
   public static HttpResponse sendCoin(
       String httpNode, byte[] fromAddress, byte[] toAddress, Long amount, String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/createtransaction";
       JsonObject userBaseObj2 = new JsonObject();
@@ -269,7 +267,7 @@ public static String sendCoin(
       Long amount,
       String notes,
       String fromKey) {
-      String transactionString = null;
+    String transactionString = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/createtransaction";
       JsonObject userBaseObj2 = new JsonObject();
@@ -297,7 +295,7 @@ public static HttpResponse sendCoin(
       Long amount,
       Integer permissionId,
       String[] managerKeys) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/createtransaction";
       JsonObject userBaseObj2 = new JsonObject();
@@ -373,7 +371,7 @@ public static HttpResponse sendCoinReplaceTransactionType(
   /** constructor. */
   public static String sendCoinGetTxid(
       String httpNode, byte[] fromAddress, byte[] toAddress, Long amount, String fromKey) {
-      String transactionString = null;
+    String transactionString = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/createtransaction";
       JsonObject userBaseObj2 = new JsonObject();
@@ -398,7 +396,7 @@ public static String sendCoinGetTxid(
   /** constructor. */
   public static HttpResponse createProposal(
       String httpNode, byte[] ownerAddress, Long proposalKey, Long proposalValue, String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/proposalcreate";
       JsonObject userBaseObj2 = new JsonObject();
@@ -428,7 +426,7 @@ public static HttpResponse approvalProposal(
       Integer proposalId,
       Boolean isAddApproval,
       String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/proposalapprove";
       JsonObject userBaseObj2 = new JsonObject();
@@ -451,7 +449,7 @@ public static HttpResponse approvalProposal(
   /** constructor. */
   public static HttpResponse deleteProposal(
       String httpNode, byte[] ownerAddress, Integer proposalId, String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/proposaldelete";
       JsonObject userBaseObj2 = new JsonObject();
@@ -472,7 +470,7 @@ public static HttpResponse deleteProposal(
 
   /** constructor. */
   public static HttpResponse getEnergyPric(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/getenergyprices";
       response = createConnect(requestUrl);
@@ -482,8 +480,9 @@ public static HttpResponse getEnergyPric(String httpNode) {
     }
     return response;
   }
+
   public static HttpResponse getEnergyPricSolidity(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/walletsolidity/getenergyprices";
       response = createConnect(requestUrl);
@@ -495,7 +494,7 @@ public static HttpResponse getEnergyPricSolidity(String httpNode) {
   }
 
   public static HttpResponse getEnergyPricPbft(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/walletpbft/getenergyprices";
       response = createConnect(requestUrl);
@@ -508,7 +507,7 @@ public static HttpResponse getEnergyPricPbft(String httpNode) {
 
   /** constructor. */
   public static HttpResponse getBandPric(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/getbandwidthprices";
       response = createConnect(requestUrl);
@@ -518,8 +517,9 @@ public static HttpResponse getBandPric(String httpNode) {
     }
     return response;
   }
+
   public static HttpResponse getBandPricSolidity(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/walletsolidity/getbandwidthprices";
       response = createConnect(requestUrl);
@@ -529,8 +529,9 @@ public static HttpResponse getBandPricSolidity(String httpNode) {
     }
     return response;
   }
+
   public static HttpResponse getBandPricPbft(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/walletpbft/getbandwidthprices";
       response = createConnect(requestUrl);
@@ -540,8 +541,9 @@ public static HttpResponse getBandPricPbft(String httpNode) {
     }
     return response;
   }
+
   public static HttpResponse getMemoFee(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/getmemofee";
       response = createConnect(requestUrl);
@@ -554,7 +556,7 @@ public static HttpResponse getMemoFee(String httpNode) {
 
   /** constructor. */
   public static HttpResponse getChainParameters(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/getchainparameters";
       response = createConnect(requestUrl);
@@ -566,32 +568,29 @@ public static HttpResponse getChainParameters(String httpNode) {
   }
 
   public static Boolean proposalFreezeV2IsOpen(String http) {
-    return getProposalValue(http,ProposalEnum.GetUnfreezeDelayDays.getProposalName()) > 0;
+    return getProposalValue(http, ProposalEnum.GetUnfreezeDelayDays.getProposalName()) > 0;
   }
 
   public static Boolean proposalTronPowerIsOpen(String http) {
-    return getProposalValue(http,ProposalEnum.GetAllowNewResourceModel.getProposalName()) > 0;
+    return getProposalValue(http, ProposalEnum.GetAllowNewResourceModel.getProposalName()) > 0;
   }
 
   /** constructor. */
-  public static Long getProposalValue(String httpNode,String proposalName) {
+  public static Long getProposalValue(String httpNode, String proposalName) {
     HttpResponse response = HttpMethod.getChainParameters(httpNode);
     JSONObject responseContent = HttpMethod.parseResponseContent(response);
     JSONArray temp;
     temp = responseContent.getJSONArray("chainParameter");
     for (int i = 0; i < temp.size(); i++) {
       if (temp.getJSONObject(i).get("key").equals(proposalName)) {
-        if(temp.getJSONObject(i).containsKey("value")) {
+        if (temp.getJSONObject(i).containsKey("value")) {
           return temp.getJSONObject(i).getLong("value");
         } else {
           return 0L;
         }
-
-
       }
     }
     return 0L;
-
   }
 
   /** constructor. */
@@ -602,7 +601,7 @@ public static HttpResponse accountPermissionUpdate(
       JsonObject witnessObject,
       JsonObject activesObject,
       String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/accountpermissionupdate";
       JsonObject userBaseObj2 = new JsonObject();
@@ -634,7 +633,7 @@ public static HttpResponse exchangeCreate(
       String secondTokenId,
       Long secondTokenBalance,
       String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/exchangecreate";
       JsonObject userBaseObj2 = new JsonObject();
@@ -662,7 +661,7 @@ public static HttpResponse exchangeInject(
       String tokenId,
       Long quant,
       String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/exchangeinject";
       JsonObject userBaseObj2 = new JsonObject();
@@ -689,7 +688,7 @@ public static HttpResponse exchangeWithdraw(
       String tokenId,
       Long quant,
       String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/exchangewithdraw";
       JsonObject userBaseObj2 = new JsonObject();
@@ -717,7 +716,7 @@ public static HttpResponse exchangeTransaction(
       Long quant,
       Long expected,
       String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/exchangetransaction";
       JsonObject userBaseObj2 = new JsonObject();
@@ -755,7 +754,7 @@ public static HttpResponse assetIssue(
       Long freeAssetNetLimit,
       Long publicFreeAssetNetLimit,
       String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/createassetissue";
       JsonObject userBaseObj2 = new JsonObject();
@@ -792,7 +791,7 @@ public static HttpResponse transferAsset(
       String assetIssueById,
       Long amount,
       String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/transferasset";
       JsonObject userBaseObj2 = new JsonObject();
@@ -811,8 +810,7 @@ public static HttpResponse transferAsset(
     return response;
   }
 
-  /** constructor.
-   * visible: true and broadcast hex */
+  /** constructor. visible: true and broadcast hex */
   public static HttpResponse transferAsset(
       String httpNode,
       String ownerAddress,
@@ -820,7 +818,7 @@ public static HttpResponse transferAsset(
       String assetIssueById,
       Long amount,
       String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/transferasset";
       JsonObject userBaseObj2 = new JsonObject();
@@ -836,9 +834,11 @@ public static HttpResponse transferAsset(
       System.out.println(transactionSignString);
       JSONObject ob = JSONObject.parseObject(transactionSignString);
       Protocol.Transaction.Builder transaction = Protocol.Transaction.newBuilder();
-      Protocol.Transaction.raw raw = Protocol.Transaction.raw.parseFrom(Hex.decode(ob.getString("raw_data_hex")));
+      Protocol.Transaction.raw raw =
+          Protocol.Transaction.raw.parseFrom(Hex.decode(ob.getString("raw_data_hex")));
       transaction.setRawData(raw);
-      transaction.addSignature(ByteString.copyFrom(Hex.decode(ob.getJSONArray("signature").get(0).toString())));
+      transaction.addSignature(
+          ByteString.copyFrom(Hex.decode(ob.getJSONArray("signature").get(0).toString())));
       response = broadcasthex(httpNode, Hex.toHexString(transaction.build().toByteArray()));
     } catch (Exception e) {
       e.printStackTrace();
@@ -862,7 +862,7 @@ public static HttpResponse deployContract(
       Long tokenValue,
       byte[] ownerAddress,
       String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/deploycontract";
       JsonObject userBaseObj2 = new JsonObject();
@@ -906,7 +906,7 @@ public static String deployContractGetTxid(
       Long tokenValue,
       byte[] ownerAddress,
       String fromKey) {
-      String transactionString = null;
+    String transactionString = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/deploycontract";
       JsonObject userBaseObj2 = new JsonObject();
@@ -953,7 +953,7 @@ public static HttpResponse deployContractGetTxidWithTooBigLong(
       Long tokenValue,
       byte[] ownerAddress,
       String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/deploycontract";
 
@@ -998,7 +998,7 @@ public static String triggerContractGetTxid(
       Long tokenValue,
       String data,
       String fromKey) {
-      String transactionSignString = null;
+    String transactionSignString = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/triggersmartcontract";
       JsonObject userBaseObj2 = new JsonObject();
@@ -1067,7 +1067,7 @@ public static String triggerContractGetTxidWithVisibleTrue(
       Integer tokenId,
       Long tokenValue,
       String fromKey) {
-      String transactionSignString = null;
+    String transactionSignString = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/triggersmartcontract";
       JsonObject userBaseObj2 = new JsonObject();
@@ -1109,7 +1109,7 @@ public static HttpResponse triggerConstantContract(
       String parameter,
       Long feeLimit,
       String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/triggerconstantcontract";
       JsonObject userBaseObj2 = new JsonObject();
@@ -1165,10 +1165,10 @@ public static HttpResponse triggerConstantContractWithData(
       final String requestUrl = "http://" + httpNode + "/wallet/triggerconstantcontract";
       JsonObject userBaseObj2 = new JsonObject();
       userBaseObj2.addProperty("owner_address", ByteArray.toHexString(ownerAddress));
-      if(contractAddress == null) {
+      if (contractAddress == null) {
         String tem = null;
         userBaseObj2.addProperty("contract_address", tem);
-      }else {
+      } else {
         userBaseObj2.addProperty("contract_address", contractAddress);
       }
       userBaseObj2.addProperty("function_selector", functionSelector);
@@ -1240,7 +1240,7 @@ public static HttpResponse participateAssetIssue(
       String assetIssueById,
       Long amount,
       String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/participateassetissue";
       JsonObject userBaseObj2 = new JsonObject();
@@ -1270,7 +1270,7 @@ public static HttpResponse updateAssetIssue(
       Long newLimit,
       Long newPublicLimit,
       String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/updateasset";
       JsonObject userBaseObj2 = new JsonObject();
@@ -1311,28 +1311,23 @@ public static HttpResponse freezeBalance(
       Integer frozenDuration,
       Integer resourceCode,
       String fromKey) {
-    if(getProposalValue(httpNode,ProposalEnum.GetAllowNewResourceModel.getProposalName()) != 0
-    && getProposalValue(httpNode,ProposalEnum.GetUnfreezeDelayDays.getProposalName()) == 0) {
+    if (getProposalValue(httpNode, ProposalEnum.GetAllowNewResourceModel.getProposalName()) != 0
+        && getProposalValue(httpNode, ProposalEnum.GetUnfreezeDelayDays.getProposalName()) == 0) {
       return freezeBalance(
           httpNode, ownerAddress, frozenBalance, frozenDuration, resourceCode, null, fromKey);
     }
 
-    if(getProposalValue(httpNode,ProposalEnum.GetAllowNewResourceModel.getProposalName()) == 0
-        && getProposalValue(httpNode,ProposalEnum.GetUnfreezeDelayDays.getProposalName()) == 0) {
+    if (getProposalValue(httpNode, ProposalEnum.GetAllowNewResourceModel.getProposalName()) == 0
+        && getProposalValue(httpNode, ProposalEnum.GetUnfreezeDelayDays.getProposalName()) == 0) {
       return freezeBalance(
           httpNode, ownerAddress, frozenBalance, frozenDuration, resourceCode, null, fromKey);
     }
 
-    if(getProposalValue(httpNode,ProposalEnum.GetUnfreezeDelayDays.getProposalName()) > 0) {
-      return freezeBalanceV2(
-          httpNode, ownerAddress, frozenBalance, resourceCode, null,fromKey);
+    if (getProposalValue(httpNode, ProposalEnum.GetUnfreezeDelayDays.getProposalName()) > 0) {
+      return freezeBalanceV2(httpNode, ownerAddress, frozenBalance, resourceCode, null, fromKey);
     }
 
-
     return null;
-
-
-
   }
 
   /** constructor. */
@@ -1344,14 +1339,21 @@ public static HttpResponse freezeBalance(
       Integer resourceCode,
       byte[] receiverAddress,
       String fromKey) {
-    if(getProposalValue(httpNode,ProposalEnum.GetUnfreezeDelayDays.getProposalName()) != 0) {
-      return freezeBalanceV2(httpNode,ownerAddress,frozenBalance,resourceCode,receiverAddress,fromKey);
+    if (getProposalValue(httpNode, ProposalEnum.GetUnfreezeDelayDays.getProposalName()) != 0) {
+      return freezeBalanceV2(
+          httpNode, ownerAddress, frozenBalance, resourceCode, receiverAddress, fromKey);
     } else {
-      return freezeBalanceV1(httpNode,ownerAddress,frozenBalance,frozenDuration,resourceCode,receiverAddress,fromKey);
+      return freezeBalanceV1(
+          httpNode,
+          ownerAddress,
+          frozenBalance,
+          frozenDuration,
+          resourceCode,
+          receiverAddress,
+          fromKey);
     }
   }
 
-
   /** constructor. */
   public static HttpResponse freezeBalanceV1(
       String httpNode,
@@ -1361,7 +1363,7 @@ public static HttpResponse freezeBalanceV1(
       Integer resourceCode,
       byte[] receiverAddress,
       String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/freezebalance";
       JsonObject userBaseObj2 = new JsonObject();
@@ -1399,7 +1401,7 @@ public static HttpResponse freezeBalanceV2(
       Integer resourceCode,
       byte[] receiverAddress,
       String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/freezebalancev2";
       JsonObject userBaseObj2 = new JsonObject();
@@ -1412,12 +1414,12 @@ public static HttpResponse freezeBalanceV2(
         userBaseObj2.addProperty("resource", "ENERGY");
       }
       if (resourceCode == 2) {
-        if(getProposalValue(httpNode,ProposalEnum.GetAllowNewResourceModel.getProposalName()) == 1) {
+        if (getProposalValue(httpNode, ProposalEnum.GetAllowNewResourceModel.getProposalName())
+            == 1) {
           userBaseObj2.addProperty("resource", "TRON_POWER");
         } else {
           userBaseObj2.addProperty("resource", "ENERGY");
         }
-
       }
 
       response = createConnect(requestUrl, userBaseObj2);
@@ -1425,10 +1427,17 @@ public static HttpResponse freezeBalanceV2(
       String transactionSignString = gettransactionsign(httpNode, transactionString, fromKey);
       response = broadcastTransaction(httpNode, transactionSignString);
 
-      if(receiverAddress != null) {
+      if (receiverAddress != null) {
         waitToProduceOneBlock(httpNode);
-        delegateresource(httpNode,ownerAddress,frozenBalance / 2,resourceCode,null,null,receiverAddress,fromKey);
-
+        delegateresource(
+            httpNode,
+            ownerAddress,
+            frozenBalance / 2,
+            resourceCode,
+            null,
+            null,
+            receiverAddress,
+            fromKey);
       }
     } catch (Exception e) {
       e.printStackTrace();
@@ -1447,7 +1456,7 @@ public static HttpResponse delegateresource(
       Long lockPeriod,
       byte[] receiverAddress,
       String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/delegateresource";
       JsonObject userBaseObj2 = new JsonObject();
@@ -1461,7 +1470,8 @@ public static HttpResponse delegateresource(
         userBaseObj2.addProperty("resource", "ENERGY");
       }
       if (resourceCode == 2) {
-        if(getProposalValue(httpNode,ProposalEnum.GetAllowNewResourceModel.getProposalName()) == 1) {
+        if (getProposalValue(httpNode, ProposalEnum.GetAllowNewResourceModel.getProposalName())
+            == 1) {
           userBaseObj2.addProperty("resource", "TRON_POWER");
         } else {
           userBaseObj2.addProperty("resource", "ENERGY");
@@ -1481,22 +1491,23 @@ public static HttpResponse delegateresource(
       String transactionSignString = gettransactionsign(httpNode, transactionString, fromKey);
       response = broadcastTransaction(httpNode, transactionSignString);
 
-
     } catch (Exception e) {
       e.printStackTrace();
       return null;
     }
 
     return response;
-
-
   }
 
-
   /** constructor. */
   public static HttpResponse unDelegateresource(
-      String httpNode, byte[] ownerAddress, Long delegteAmount, Integer resourceCode,byte[] receiverAddress,String fromKey) {
-      HttpResponse response = null;
+      String httpNode,
+      byte[] ownerAddress,
+      Long delegteAmount,
+      Integer resourceCode,
+      byte[] receiverAddress,
+      String fromKey) {
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/undelegateresource";
       JsonObject userBaseObj2 = new JsonObject();
@@ -1510,7 +1521,8 @@ public static HttpResponse unDelegateresource(
         userBaseObj2.addProperty("resource", "ENERGY");
       }
       if (resourceCode == 2) {
-        if(getProposalValue(httpNode,ProposalEnum.GetAllowNewResourceModel.getProposalName()) == 1) {
+        if (getProposalValue(httpNode, ProposalEnum.GetAllowNewResourceModel.getProposalName())
+            == 1) {
           userBaseObj2.addProperty("resource", "TRON_POWER");
         } else {
           userBaseObj2.addProperty("resource", "ENERGY");
@@ -1531,25 +1543,24 @@ public static HttpResponse unDelegateresource(
     }
 
     return response;
-
-
   }
 
   /** constructor. */
   public static HttpResponse unFreezeBalance(
-      String httpNode, byte[] ownerAddress, Long unfreezeBalance,Integer resourceCode, String fromKey) {
-    if(getProposalValue(httpNode,ProposalEnum.GetUnfreezeDelayDays.getProposalName()) == 0) {
-      return unFreezeBalance(httpNode, ownerAddress, unfreezeBalance,resourceCode, null, fromKey);
+      String httpNode,
+      byte[] ownerAddress,
+      Long unfreezeBalance,
+      Integer resourceCode,
+      String fromKey) {
+    if (getProposalValue(httpNode, ProposalEnum.GetUnfreezeDelayDays.getProposalName()) == 0) {
+      return unFreezeBalance(httpNode, ownerAddress, unfreezeBalance, resourceCode, null, fromKey);
     }
 
-    if(getProposalValue(httpNode,ProposalEnum.GetUnfreezeDelayDays.getProposalName()) != 0) {
-      return unFreezeBalanceV2(
-          httpNode, ownerAddress,unfreezeBalance, resourceCode, fromKey);
+    if (getProposalValue(httpNode, ProposalEnum.GetUnfreezeDelayDays.getProposalName()) != 0) {
+      return unFreezeBalanceV2(httpNode, ownerAddress, unfreezeBalance, resourceCode, fromKey);
     }
 
     return null;
-
-
   }
 
   /** constructor. */
@@ -1560,15 +1571,17 @@ public static HttpResponse unFreezeBalance(
       Integer resourceCode,
       byte[] receiverAddress,
       String fromKey) {
-    if(getProposalValue(httpNode,ProposalEnum.GetAllowNewResourceModel.getProposalName()) == 0 && resourceCode == 2) {
+    if (getProposalValue(httpNode, ProposalEnum.GetAllowNewResourceModel.getProposalName()) == 0
+        && resourceCode == 2) {
       resourceCode = 1;
     }
-    if(getProposalValue(httpnode,ProposalEnum.GetUnfreezeDelayDays.getProposalName()) > 0) {
-      unDelegateresource(httpNode,ownerAddress,unfreezeBalance / 2,resourceCode,receiverAddress,fromKey);
+    if (getProposalValue(httpnode, ProposalEnum.GetUnfreezeDelayDays.getProposalName()) > 0) {
+      unDelegateresource(
+          httpNode, ownerAddress, unfreezeBalance / 2, resourceCode, receiverAddress, fromKey);
       waitToProduceOneBlock(httpNode);
-      return unFreezeBalanceV2(httpnode,ownerAddress,unfreezeBalance,resourceCode,fromKey);
+      return unFreezeBalanceV2(httpnode, ownerAddress, unfreezeBalance, resourceCode, fromKey);
     } else {
-      return unFreezeBalanceV1(httpNode,ownerAddress,resourceCode,receiverAddress,fromKey);
+      return unFreezeBalanceV1(httpNode, ownerAddress, resourceCode, receiverAddress, fromKey);
     }
   }
 
@@ -1579,7 +1592,7 @@ public static HttpResponse unFreezeBalanceV1(
       Integer resourceCode,
       byte[] receiverAddress,
       String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/unfreezebalance";
       JsonObject userBaseObj2 = new JsonObject();
@@ -1614,7 +1627,7 @@ public static HttpResponse unFreezeBalanceV2(
       Long unfreezeBalance,
       Integer resourceCode,
       String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/unfreezebalancev2";
       JsonObject userBaseObj2 = new JsonObject();
@@ -1645,10 +1658,8 @@ public static HttpResponse unFreezeBalanceV2(
 
   /** constructor. */
   public static HttpResponse cancelAllUnfreezeBalanceV2(
-      String httpNode,
-      byte[] ownerAddress,
-      String fromKey) {
-      HttpResponse response = null;
+      String httpNode, byte[] ownerAddress, String fromKey) {
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/cancelallunfreezev2";
       JsonObject userBaseObj2 = new JsonObject();
@@ -1670,15 +1681,15 @@ public static HttpResponse cancelAllUnfreezeBalanceV2(
   public static String gettransactionsign(
       String httpNode, String transactionString, String privateKey) {
     boolean visible = transactionString.contains("visible\":true");
-    String transactionSignString = TransactionUtils.getTransactionSign(transactionString, privateKey,
-        visible);
+    String transactionSignString =
+        TransactionUtils.getTransactionSign(transactionString, privateKey, visible);
     return transactionSignString;
   }
 
   /** constructor. */
   public static HttpResponse broadcastTransaction(String httpNode, String transactionSignString) {
-      HttpPost httppost = null;
-      HttpResponse response = null;
+    HttpPost httppost = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/broadcasttransaction";
       httpClient
@@ -1728,7 +1739,7 @@ public static HttpResponse broadcastTransaction(String httpNode, String transact
 
   /** constructor. */
   public static HttpResponse broadcasthex(String httpNode, String transactionHex) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/broadcasthex";
       JsonObject userBaseObj2 = new JsonObject();
@@ -1743,7 +1754,7 @@ public static HttpResponse broadcasthex(String httpNode, String transactionHex)
 
   /** constructor. */
   public static HttpResponse getAccountById(String httpNode, String accountId, Boolean visable) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getaccountbyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -1760,7 +1771,7 @@ public static HttpResponse getAccountById(String httpNode, String accountId, Boo
   /** constructor. */
   public static HttpResponse getAccountByIdFromSolidity(
       String httpSolidityNode, String accountId, Boolean visable) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/getaccountbyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -1777,7 +1788,7 @@ public static HttpResponse getAccountByIdFromSolidity(
   /** constructor. */
   public static HttpResponse getAccountByIdFromPbft(
       String httpSolidityNode, String accountId, Boolean visable) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletpbft/getaccountbyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -1793,7 +1804,7 @@ public static HttpResponse getAccountByIdFromPbft(
 
   /** constructor. */
   public static HttpResponse getAccount(String httpNode, byte[] queryAddress) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getaccount";
       JsonObject userBaseObj2 = new JsonObject();
@@ -1806,8 +1817,6 @@ public static HttpResponse getAccount(String httpNode, byte[] queryAddress) {
     return response;
   }
 
-
-
   /** constructor. */
   public static Long getAccountForResponse(String httpNode, byte[] queryAddress, Integer times) {
     try {
@@ -1824,7 +1833,7 @@ public static Long getAccountForResponse(String httpNode, byte[] queryAddress, I
 
   /** constructor. */
   public static HttpResponse getAccountFromSolidity(String httpSolidityNode, byte[] queryAddress) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/getaccount";
       JsonObject userBaseObj2 = new JsonObject();
@@ -1855,7 +1864,7 @@ public static HttpResponse getAccountFromPbft(String httpSolidityNode, byte[] qu
 
   /** constructor. */
   public static HttpResponse getContract(String httpNode, String contractAddress) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getcontract";
       JsonObject userBaseObj2 = new JsonObject();
@@ -1870,7 +1879,7 @@ public static HttpResponse getContract(String httpNode, String contractAddress)
 
   /** constructor. */
   public static HttpResponse getSignWeight(String httpNode, String transactionSignString) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getsignweight";
       httpClient
@@ -1898,7 +1907,7 @@ public static HttpResponse getSignWeight(String httpNode, String transactionSign
   /** constructor. */
   public static HttpResponse getTransactionApprovedList(
       String httpNode, String transactionSignString) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getapprovedlist";
       httpClient
@@ -1925,7 +1934,7 @@ public static HttpResponse getTransactionApprovedList(
 
   /** constructor. */
   public static HttpResponse listExchanges(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/listexchanges";
       response = createConnect(requestUrl);
@@ -1938,7 +1947,7 @@ public static HttpResponse listExchanges(String httpNode) {
 
   /** constructor. */
   public static HttpResponse listExchangesFromSolidity(String httpSolidityNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/listexchanges";
       response = createConnect(requestUrl);
@@ -1951,7 +1960,7 @@ public static HttpResponse listExchangesFromSolidity(String httpSolidityNode) {
 
   /** constructor. */
   public static HttpResponse listExchangesFromPbft(String httpSolidityNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletpbft/listexchanges";
       response = createConnect(requestUrl);
@@ -1964,7 +1973,7 @@ public static HttpResponse listExchangesFromPbft(String httpSolidityNode) {
 
   /** constructor. */
   public static HttpResponse listNodes(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/listnodes";
       response = createConnect(requestUrl);
@@ -1977,7 +1986,7 @@ public static HttpResponse listNodes(String httpNode) {
 
   /** constructor. */
   public static HttpResponse getStatsInfo(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/monitor/getstatsinfo";
       response = createConnectForGet(requestUrl);
@@ -1990,7 +1999,7 @@ public static HttpResponse getStatsInfo(String httpNode) {
 
   /** constructor. */
   public static HttpResponse getNextmaintenanceTime(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getnextmaintenancetime";
       response = createConnect(requestUrl);
@@ -2003,7 +2012,7 @@ public static HttpResponse getNextmaintenanceTime(String httpNode) {
 
   /** constructor. */
   public static HttpResponse getChainParameter(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getchainparameters";
       response = createConnect(requestUrl);
@@ -2016,7 +2025,7 @@ public static HttpResponse getChainParameter(String httpNode) {
 
   /** constructor. */
   public static HttpResponse getNodeInfo(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getnodeinfo";
       response = createConnect(requestUrl);
@@ -2029,7 +2038,7 @@ public static HttpResponse getNodeInfo(String httpNode) {
 
   /** constructor. */
   public static HttpResponse listwitnesses(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/listwitnesses";
       response = createConnect(requestUrl);
@@ -2042,7 +2051,7 @@ public static HttpResponse listwitnesses(String httpNode) {
 
   /** constructor. */
   public static HttpResponse listwitnesses(String httpNode, Boolean visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/listwitnesses";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2057,7 +2066,7 @@ public static HttpResponse listwitnesses(String httpNode, Boolean visible) {
 
   /** constructor. */
   public static HttpResponse listwitnessesFromSolidity(String httpSolidityNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/listwitnesses";
       response = createConnect(requestUrl);
@@ -2070,7 +2079,7 @@ public static HttpResponse listwitnessesFromSolidity(String httpSolidityNode) {
 
   /** constructor. */
   public static HttpResponse listwitnessesFromPbft(String httpSolidityNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletpbft/listwitnesses";
       response = createConnect(requestUrl);
@@ -2083,7 +2092,7 @@ public static HttpResponse listwitnessesFromPbft(String httpSolidityNode) {
 
   /** constructor. */
   public static HttpResponse listProposals(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/listproposals";
       response = createConnect(requestUrl);
@@ -2096,7 +2105,7 @@ public static HttpResponse listProposals(String httpNode) {
 
   /** constructor. */
   public static HttpResponse getExchangeById(String httpNode, Integer exchangeId) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getexchangebyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2112,7 +2121,7 @@ public static HttpResponse getExchangeById(String httpNode, Integer exchangeId)
   /** constructor. */
   public static HttpResponse getExchangeByIdFromSolidity(
       String httpSolidityNode, Integer exchangeId) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/getexchangebyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2127,7 +2136,7 @@ public static HttpResponse getExchangeByIdFromSolidity(
 
   /** constructor. */
   public static HttpResponse getExchangeByIdFromPbft(String httpSolidityNode, Integer exchangeId) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletpbft/getexchangebyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2142,7 +2151,7 @@ public static HttpResponse getExchangeByIdFromPbft(String httpSolidityNode, Inte
 
   /** constructor. */
   public static HttpResponse getProposalById(String httpNode, Integer proposalId) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getproposalbyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2157,7 +2166,7 @@ public static HttpResponse getProposalById(String httpNode, Integer proposalId)
 
   /** constructor. */
   public static HttpResponse getAssetIssueListByName(String httpNode, String name) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getassetissuelistbyname";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2173,7 +2182,7 @@ public static HttpResponse getAssetIssueListByName(String httpNode, String name)
   /** constructor. */
   public static HttpResponse getAssetIssueListByNameFromSolidity(
       String httpSolidityNode, String name) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/getassetissuelistbyname";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2188,7 +2197,7 @@ public static HttpResponse getAssetIssueListByNameFromSolidity(
 
   /** constructor. */
   public static HttpResponse getAssetIssueListByNameFromPbft(String httpPbftNode, String name) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpPbftNode + "/walletpbft/getassetissuelistbyname";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2203,7 +2212,7 @@ public static HttpResponse getAssetIssueListByNameFromPbft(String httpPbftNode,
 
   /** constructor. */
   public static HttpResponse getAssetIssueById(String httpNode, String assetIssueId) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getassetissuebyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2219,7 +2228,7 @@ public static HttpResponse getAssetIssueById(String httpNode, String assetIssueI
   /** constructor. */
   public static HttpResponse getAssetIssueByIdFromSolidity(
       String httpSolidityNode, String assetIssueId) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/getassetissuebyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2235,7 +2244,7 @@ public static HttpResponse getAssetIssueByIdFromSolidity(
   /** constructor. */
   public static HttpResponse getAssetIssueByIdFromPbft(
       String httpSolidityNode, String assetIssueId) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletpbft/getassetissuebyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2250,7 +2259,7 @@ public static HttpResponse getAssetIssueByIdFromPbft(
 
   /** constructor. */
   public static HttpResponse getTransactionById(String httpNode, String txid) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/gettransactionbyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2279,7 +2288,7 @@ public static Long getTransactionByIdForResponse(String httpNode, String txid, I
 
   /** constructor. */
   public static HttpResponse getTransactionByIdFromSolidity(String httpSolidityNode, String txid) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/gettransactionbyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2294,7 +2303,7 @@ public static HttpResponse getTransactionByIdFromSolidity(String httpSolidityNod
 
   /** constructor. */
   public static HttpResponse getTransactionByIdFromPbft(String httpSolidityNode, String txid) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletpbft/gettransactionbyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2314,7 +2323,7 @@ public static HttpResponse getTransactionInfoById(String httpNode, String txid)
 
   /** constructor. */
   public static HttpResponse getTransactionInfoById(String httpNode, String txid, Boolean visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/gettransactioninfobyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2331,7 +2340,7 @@ public static HttpResponse getTransactionInfoById(String httpNode, String txid,
   /** constructor. */
   public static HttpResponse getTransactionInfoByIdFromSolidity(
       String httpSolidityNode, String txid) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/gettransactioninfobyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2346,7 +2355,7 @@ public static HttpResponse getTransactionInfoByIdFromSolidity(
 
   /** constructor. */
   public static HttpResponse getTransactionInfoByIdFromPbft(String httpSolidityNode, String txid) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletpbft/gettransactioninfobyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2361,7 +2370,7 @@ public static HttpResponse getTransactionInfoByIdFromPbft(String httpSolidityNod
 
   /** constructor. */
   public static HttpResponse getTransactionInfoByBlocknum(String httpNode, long blocknum) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/gettransactioninfobyblocknum";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2377,7 +2386,7 @@ public static HttpResponse getTransactionInfoByBlocknum(String httpNode, long bl
   /** constructor. */
   public static HttpResponse getTransactionInfoByBlocknumFromSolidity(
       String httpSolidityNode, long blocknum) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl =
           "http://" + httpSolidityNode + "/walletsolidity/gettransactioninfobyblocknum";
@@ -2394,7 +2403,7 @@ public static HttpResponse getTransactionInfoByBlocknumFromSolidity(
   /** constructor. */
   public static HttpResponse getTransactionCountByBlocknumFromSolidity(
       String httpSolidityNode, long blocknum) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl =
           "http://" + httpSolidityNode + "/walletsolidity/gettransactioncountbyblocknum";
@@ -2411,7 +2420,7 @@ public static HttpResponse getTransactionCountByBlocknumFromSolidity(
   /** constructor. */
   public static HttpResponse getTransactionCountByBlocknumFromPbft(
       String httpSolidityNode, long blocknum) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl =
           "http://" + httpSolidityNode + "/walletpbft/gettransactioncountbyblocknum";
@@ -2428,7 +2437,7 @@ public static HttpResponse getTransactionCountByBlocknumFromPbft(
   /** constructor. */
   public static HttpResponse getTransactionsFromThisFromSolidity(
       String httpSolidityNode, byte[] fromAddress, long offset, long limit) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       Map map1 = new HashMap();
       Map map = new HashMap();
@@ -2450,7 +2459,7 @@ public static HttpResponse getTransactionsFromThisFromSolidity(
   /** constructor. */
   public static HttpResponse getTransactionsToThisFromSolidity(
       String httpSolidityNode, byte[] toAddress, long offset, long limit) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       Map map1 = new HashMap();
       Map map = new HashMap();
@@ -2471,7 +2480,7 @@ public static HttpResponse getTransactionsToThisFromSolidity(
 
   /** constructor. */
   public static HttpResponse getAssetIssueByName(String httpNode, String name) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getassetissuebyname";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2486,7 +2495,7 @@ public static HttpResponse getAssetIssueByName(String httpNode, String name) {
 
   /** constructor. */
   public static HttpResponse getAssetIssueByNameFromSolidity(String httpSolidityNode, String name) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/getassetissuebyname";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2501,7 +2510,7 @@ public static HttpResponse getAssetIssueByNameFromSolidity(String httpSolidityNo
 
   /** constructor. */
   public static HttpResponse getAssetIssueByNameFromPbft(String httpSolidityNode, String name) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletpbft/getassetissuebyname";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2516,7 +2525,7 @@ public static HttpResponse getAssetIssueByNameFromPbft(String httpSolidityNode,
 
   /** constructor. */
   public static Long getBalance(String httpNode, byte[] queryAddress) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getaccount";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2536,7 +2545,7 @@ public static Long getBalance(String httpNode, byte[] queryAddress) {
 
   /** constructor. */
   public static HttpResponse getAccountNet(String httpNode, byte[] queryAddress) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getaccountnet";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2551,7 +2560,7 @@ public static HttpResponse getAccountNet(String httpNode, byte[] queryAddress) {
 
   /** constructor. */
   public static HttpResponse getAccountReource(String httpNode, byte[] queryAddress) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getaccountresource";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2567,7 +2576,7 @@ public static HttpResponse getAccountReource(String httpNode, byte[] queryAddres
   /** constructor. */
   public static HttpResponse getAccountBalance(
       String httpNode, byte[] queryAddress, Long blockNum, String blockHash) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/getaccountbalance";
       JsonObject addressObj = new JsonObject();
@@ -2590,7 +2599,7 @@ public static HttpResponse getAccountBalance(
 
   /** constructor. */
   public static HttpResponse getBlockBalance(String httpNode, Long blockNum, String blockHash) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/getblockbalance";
       JsonObject blockObj = new JsonObject();
@@ -2607,7 +2616,7 @@ public static HttpResponse getBlockBalance(String httpNode, Long blockNum, Strin
 
   /** constructor. */
   public static Long getBurnTrx(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/getburntrx";
       JsonObject blockObj = new JsonObject();
@@ -2622,7 +2631,7 @@ public static Long getBurnTrx(String httpNode) {
 
   /** constructor. */
   public static Long getBurnTrxFromSolidity(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/walletsolidity/getburntrx";
       JsonObject blockObj = new JsonObject();
@@ -2637,7 +2646,7 @@ public static Long getBurnTrxFromSolidity(String httpNode) {
 
   /** constructor. */
   public static Long getBurnTrxFromPbft(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/walletpbft/getburntrx";
       JsonObject blockObj = new JsonObject();
@@ -2657,7 +2666,7 @@ public static HttpResponse getNowBlock(String httpNode) {
 
   /** constructor. */
   public static HttpResponse getNowBlock(String httpNode, Boolean visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getnowblock";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2672,7 +2681,7 @@ public static HttpResponse getNowBlock(String httpNode, Boolean visible) {
 
   /** constructor. */
   public static Long getNowBlockNum(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getnowblock";
       response = createConnect(requestUrl);
@@ -2688,7 +2697,7 @@ public static Long getNowBlockNum(String httpNode) {
 
   /** constructor. */
   public static Long getNowBlockNumOnSolidity(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/walletsolidity/getnowblock";
       response = createConnect(requestUrl);
@@ -2704,7 +2713,7 @@ public static Long getNowBlockNumOnSolidity(String httpNode) {
 
   /** constructor. */
   public static HttpResponse getNowBlockFromSolidity(String httpSolidityNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/getnowblock";
       response = createConnect(requestUrl);
@@ -2717,7 +2726,7 @@ public static HttpResponse getNowBlockFromSolidity(String httpSolidityNode) {
 
   /** constructor. */
   public static HttpResponse getNowBlockFromPbft(String httpSolidityNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletpbft/getnowblock";
       response = createConnect(requestUrl);
@@ -2783,7 +2792,11 @@ public static void waitToProduceOneBlockFromSolidity(String httpNode, String htt
   public static void waitUntilFixedBlockFromSolidity(int blockNum, String httpSolidityNode) {
     HttpResponse response = HttpMethod.getNowBlockFromSolidity(httpSolidityNode);
     JSONObject responseContent = HttpMethod.parseResponseContent(response);
-    Integer currentBlockNum = responseContent.getJSONObject("block_header").getJSONObject("raw_data").getIntValue("number");
+    Integer currentBlockNum =
+        responseContent
+            .getJSONObject("block_header")
+            .getJSONObject("raw_data")
+            .getIntValue("number");
     Integer times = 0;
     while (currentBlockNum < blockNum
         && times++ <= ((getWitnessNum() >= 27) ? 27 : getWitnessNum() + 4)) {
@@ -2794,7 +2807,11 @@ public static void waitUntilFixedBlockFromSolidity(int blockNum, String httpSoli
       }
       response = HttpMethod.getNowBlockFromSolidity(httpSolidityNode);
       responseContent = HttpMethod.parseResponseContent(response);
-      currentBlockNum = responseContent.getJSONObject("block_header").getJSONObject("raw_data").getIntValue("number");
+      currentBlockNum =
+          responseContent
+              .getJSONObject("block_header")
+              .getJSONObject("raw_data")
+              .getIntValue("number");
     }
     logger.info("currentBlockNum2:" + currentBlockNum);
   }
@@ -2825,22 +2842,21 @@ public static void waitToProduceOneBlockFromPbft(String httpNode, String httpSol
 
   /** constructor. */
   public static HttpResponse getBlock(String httpNode, String idOrNum, Boolean detail) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getblock";
       JsonObject userBaseObj2 = new JsonObject();
-      if(null != idOrNum) {
+      if (null != idOrNum) {
         userBaseObj2.addProperty("id_or_num", idOrNum);
       }
-      if(null != detail) {
+      if (null != detail) {
         userBaseObj2.addProperty("detail", detail);
       }
 
-      if(userBaseObj2.size() == 0) {
+      if (userBaseObj2.size() == 0) {
         userBaseObj2 = null;
       }
 
-
       response = createConnect(requestUrl, userBaseObj2);
     } catch (Exception e) {
       e.printStackTrace();
@@ -2849,9 +2865,6 @@ public static HttpResponse getBlock(String httpNode, String idOrNum, Boolean det
     return response;
   }
 
-
-
-
   /** constructor. */
   public static HttpResponse getBlockByNum(String httpNode, Long blockNUm) {
     return getBlockByNum(httpNode, blockNUm, false);
@@ -2859,7 +2872,7 @@ public static HttpResponse getBlockByNum(String httpNode, Long blockNUm) {
 
   /** constructor. */
   public static HttpResponse getBlockByNum(String httpNode, Long blockNUm, Boolean visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getblockbynum";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2893,7 +2906,7 @@ public static String convertJsonObjectToGetParam(HashMap hashMap
   /** constructor. */
   public static HttpResponse getBlockByNumWithType(
       String httpNode, HashMap hashMap) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getblockbynum";
       requestUrl = requestUrl + convertJsonObjectToGetParam(hashMap);
@@ -2922,7 +2935,7 @@ public static Long getBlockByNumForResponse(String httpNode, Integer blockNUm, I
 
   /** constructor. */
   public static HttpResponse getBlockByNumFromSolidity(String httpSolidityNode, Long blockNum) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/getblockbynum";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2937,7 +2950,7 @@ public static HttpResponse getBlockByNumFromSolidity(String httpSolidityNode, Lo
 
   /** constructor. */
   public static HttpResponse getBlockByNumFromPbft(String httpSolidityNode, Long blockNum) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletpbft/getblockbynum";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2951,9 +2964,8 @@ public static HttpResponse getBlockByNumFromPbft(String httpSolidityNode, Long b
   }
 
   /** constructor. */
-  public static HttpResponse getBlockByLimitNext(
-      String httpNode, Long startNum, Long endNum) {
-      HttpResponse response = null;
+  public static HttpResponse getBlockByLimitNext(String httpNode, Long startNum, Long endNum) {
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getblockbylimitnext";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2970,7 +2982,7 @@ public static HttpResponse getBlockByLimitNext(
   /** constructor. */
   public static HttpResponse getBlockByLimitNextFromSolidity(
       String httpNode, Long startNum, Long endNum) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/walletsolidity/getblockbylimitnext";
       JsonObject userBaseObj2 = new JsonObject();
@@ -2987,7 +2999,7 @@ public static HttpResponse getBlockByLimitNextFromSolidity(
   /** constructor. */
   public static HttpResponse getBlockByLimitNextFromPbft(
       String httpNode, Long startNum, Long endNum) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/walletpbft/getblockbylimitnext";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3003,7 +3015,7 @@ public static HttpResponse getBlockByLimitNextFromPbft(
 
   /** constructor. */
   public static HttpResponse getBlockByLastNum(String httpNode, Integer num) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getblockbylatestnum";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3018,7 +3030,7 @@ public static HttpResponse getBlockByLastNum(String httpNode, Integer num) {
 
   /** constructor. */
   public static HttpResponse getBlockByLastNum2(String httpNode, Integer num) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/walletsolidity/getblockbylatestnum2";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3033,7 +3045,7 @@ public static HttpResponse getBlockByLastNum2(String httpNode, Integer num) {
 
   /** constructor. */
   public static HttpResponse getBlockByLastNumFromSolidity(String httpNode, Integer num) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/walletsolidity/getblockbylatestnum";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3048,7 +3060,7 @@ public static HttpResponse getBlockByLastNumFromSolidity(String httpNode, Intege
 
   /** constructor. */
   public static HttpResponse getBlockByLastNumFromPbft(String httpNode, Integer num) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/walletpbft/getblockbylatestnum";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3062,7 +3074,7 @@ public static HttpResponse getBlockByLastNumFromPbft(String httpNode, Integer nu
 
   /** constructor. */
   public static HttpResponse getBlockById(String httpNode, String blockId) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getblockbyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3077,7 +3089,7 @@ public static HttpResponse getBlockById(String httpNode, String blockId) {
 
   /** constructor. */
   public static HttpResponse getBlockByIdFromSolidity(String httpNode, String blockId) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/walletsolidity/getblockbyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3093,7 +3105,7 @@ public static HttpResponse getBlockByIdFromSolidity(String httpNode, String bloc
   /** constructor. */
   public static HttpResponse getBlockByIdFromSolidity(
       String httpNode, String blockId, Integer type) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/walletsolidity/getblockbyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3109,7 +3121,7 @@ public static HttpResponse getBlockByIdFromSolidity(
 
   /** constructor. */
   public static HttpResponse getBlockByIdFromPbft(String httpNode, String blockId) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/walletpbft/getblockbyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3125,7 +3137,7 @@ public static HttpResponse getBlockByIdFromPbft(String httpNode, String blockId)
   /** constructor. */
   public static HttpResponse getDelegatedResource(
       String httpNode, byte[] fromAddress, byte[] toAddress) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getdelegatedresource";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3142,7 +3154,7 @@ public static HttpResponse getDelegatedResource(
   /** constructor. */
   public static HttpResponse getDelegatedResourceFromSolidity(
       String httpSolidityNode, byte[] fromAddress, byte[] toAddress) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/getdelegatedresource";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3159,7 +3171,7 @@ public static HttpResponse getDelegatedResourceFromSolidity(
   /** constructor. */
   public static HttpResponse getDelegatedResourceFromPbft(
       String httpSolidityNode, byte[] fromAddress, byte[] toAddress) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletpbft/getdelegatedresource";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3176,7 +3188,7 @@ public static HttpResponse getDelegatedResourceFromPbft(
   /** constructor. */
   public static HttpResponse getDelegatedResourceAccountIndex(
       String httpNode, byte[] queryAddress) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getdelegatedresourceaccountindex";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3192,7 +3204,7 @@ public static HttpResponse getDelegatedResourceAccountIndex(
   /** constructor. */
   public static HttpResponse getDelegatedResourceAccountIndexFromSolidity(
       String httpSolidityNode, byte[] queryAddress) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl =
           "http://" + httpSolidityNode + "/walletsolidity/getdelegatedresourceaccountindex";
@@ -3209,7 +3221,7 @@ public static HttpResponse getDelegatedResourceAccountIndexFromSolidity(
   /** constructor. */
   public static HttpResponse getDelegatedResourceAccountIndexFromPbft(
       String httpSolidityNode, byte[] queryAddress) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl =
           "http://" + httpSolidityNode + "/walletpbft/getdelegatedresourceaccountindex";
@@ -3225,7 +3237,7 @@ public static HttpResponse getDelegatedResourceAccountIndexFromPbft(
 
   /** constructor. */
   public static HttpResponse createConnect(String url) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       httpClient
           .getParams()
@@ -3246,7 +3258,7 @@ public static HttpResponse createConnect(String url) {
   /** constructor. */
   public static HttpResponse createConnect(String url, JsonObject requestBody) {
     logger.info("Thread count :" + Thread.activeCount());
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       httpClient
           .getParams()
@@ -3273,7 +3285,7 @@ public static HttpResponse createConnect(String url, JsonObject requestBody) {
 
   /** constructor. */
   public static HttpResponse createConnect(String url, JsonArray requestBody) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       httpClient
           .getParams()
@@ -3300,7 +3312,7 @@ public static HttpResponse createConnect(String url, JsonArray requestBody) {
 
   /** constructor. */
   public static HttpResponse createConnectForGet(String url) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       httpClient
           .getParams()
@@ -3322,7 +3334,7 @@ public static HttpResponse createConnectForGet(String url) {
 
   /** constructor. */
   public static HttpResponse createConnectForShieldTrc20(String url, JSONObject requestBody) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       httpClient
           .getParams()
@@ -3383,7 +3395,7 @@ public static Long createConnectForResponse(String url, JsonObject requestBody,
 
   /** constructor. */
   public static HttpResponse createConnect1(String url, JSONObject requestBody) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       httpClient
           .getParams()
@@ -3412,7 +3424,7 @@ public static HttpResponse createConnect1(String url, JSONObject requestBody) {
 
   /** constructor. */
   public static HttpResponse getAssetissueList(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getassetissuelist";
       response = createConnect(requestUrl);
@@ -3444,7 +3456,7 @@ public static Long getAssetIssueValue(
 
   /** constructor. */
   public static HttpResponse getAssetIssueListFromSolidity(String httpSolidityNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/getassetissuelist";
       response = createConnect(requestUrl);
@@ -3457,7 +3469,7 @@ public static HttpResponse getAssetIssueListFromSolidity(String httpSolidityNode
 
   /** constructor. */
   public static HttpResponse getAssetIssueListFromPbft(String httpSolidityNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletpbft/getassetissuelist";
       response = createConnect(requestUrl);
@@ -3471,7 +3483,7 @@ public static HttpResponse getAssetIssueListFromPbft(String httpSolidityNode) {
   /** constructor. */
   public static HttpResponse getPaginatedAssetissueList(
       String httpNode, Integer offset, Integer limit) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/getpaginatedassetissuelist";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3489,7 +3501,7 @@ public static HttpResponse getPaginatedAssetissueList(
   /** constructor. */
   public static HttpResponse getPaginatedAssetissueListFromSolidity(
       String httpSolidityNode, Integer offset, Integer limit) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl =
           "http://" + httpSolidityNode + "/walletsolidity/getpaginatedassetissuelist";
@@ -3507,7 +3519,7 @@ public static HttpResponse getPaginatedAssetissueListFromSolidity(
   /** constructor. */
   public static HttpResponse getPaginatedAssetissueListFromPbft(
       String httpSolidityNode, Integer offset, Integer limit) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletpbft/getpaginatedassetissuelist";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3524,7 +3536,7 @@ public static HttpResponse getPaginatedAssetissueListFromPbft(
   /** constructor. */
   public static HttpResponse getPaginatedProposalList(
       String httpNode, Integer offset, Integer limit) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getpaginatedproposallist";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3541,7 +3553,7 @@ public static HttpResponse getPaginatedProposalList(
   /** constructor. */
   public static HttpResponse getPaginatedExchangeList(
       String httpNode, Integer offset, Integer limit) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getpaginatedexchangelist";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3562,7 +3574,7 @@ public static HttpResponse updateSetting(
       String contractAddress,
       Integer consumeUserResourcePercent,
       String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/updatesetting";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3590,7 +3602,7 @@ public static HttpResponse updateEnergyLimit(
       String contractAddress,
       Integer originEnergyLimit,
       String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/updateenergylimit";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3613,7 +3625,7 @@ public static HttpResponse updateEnergyLimit(
 
   /** constructor. */
   public static HttpResponse createAddress(String httpNode, String value) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/createaddress";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3629,7 +3641,7 @@ public static HttpResponse createAddress(String httpNode, String value) {
 
   /** constructor. */
   public static HttpResponse generateAddress(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/generateaddress";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3643,7 +3655,7 @@ public static HttpResponse generateAddress(String httpNode) {
 
   /** constructor. */
   public static HttpResponse getTransactionCountByBlocknum(String httpNode, long blocknum) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/gettransactioncountbyblocknum";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3658,7 +3670,7 @@ public static HttpResponse getTransactionCountByBlocknum(String httpNode, long b
 
   /** constructor. */
   public static HttpResponse validateAddress(String httpNode, String address) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/validateaddress";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3675,7 +3687,7 @@ public static HttpResponse validateAddress(String httpNode, String address) {
   /** constructor. */
   public static HttpResponse easyTransfer(
       String httpNode, String value, byte[] toAddress, Long amount) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/easytransfer";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3696,7 +3708,7 @@ public static HttpResponse easyTransfer(
   /** constructor. */
   public static HttpResponse easyTransferByPrivate(
       String httpNode, String privateKey, byte[] toAddress, Long amount) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/easytransferbyprivate";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3717,7 +3729,7 @@ public static HttpResponse easyTransferByPrivate(
   /** constructor. */
   public static HttpResponse easyTransferAsset(
       String httpNode, String value, byte[] toAddress, Long amount, String assetId) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/easytransferasset";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3739,7 +3751,7 @@ public static HttpResponse easyTransferAsset(
   /** constructor. */
   public static HttpResponse easyTransferAssetByPrivate(
       String httpNode, String privateKey, byte[] toAddress, Long amount, String assetId) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/easytransferassetbyprivate";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3760,7 +3772,7 @@ public static HttpResponse easyTransferAssetByPrivate(
 
   /** constructor. */
   public static HttpResponse getContractInfo(String httpNode, String contractAddress) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getcontractinfo";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3851,7 +3863,7 @@ public static String str2hex(String str) {
   /** constructor. */
   public static HttpResponse clearABiGetTxid(
       String httpNode, byte[] ownerAddress, String contractAddress, String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/clearabi";
       JsonObject userBaseObj2 = new JsonObject();
@@ -3967,7 +3979,7 @@ public static List addShieldOutputList(
 
   /** constructor. */
   public static HttpResponse getSpendingKey(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getspendingkey";
       response = createConnect(requestUrl);
@@ -3980,7 +3992,7 @@ public static HttpResponse getSpendingKey(String httpNode) {
 
   /** constructor. */
   public static HttpResponse getDiversifier(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getdiversifier";
       response = createConnect(requestUrl);
@@ -3993,7 +4005,7 @@ public static HttpResponse getDiversifier(String httpNode) {
 
   /** constructor. */
   public static HttpResponse getRcm(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getrcm";
       response = createConnect(requestUrl);
@@ -4006,7 +4018,7 @@ public static HttpResponse getRcm(String httpNode) {
 
   /** constructor. */
   public static HttpResponse getExpandedSpendingKey(String httpNode, String spendingKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getexpandedspendingkey";
       JsonObject userBaseObj2 = new JsonObject();
@@ -4021,7 +4033,7 @@ public static HttpResponse getExpandedSpendingKey(String httpNode, String spendi
 
   /** constructor. */
   public static HttpResponse getAkFromAsk(String httpNode, String ask) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getakfromask";
       JsonObject userBaseObj2 = new JsonObject();
@@ -4036,7 +4048,7 @@ public static HttpResponse getAkFromAsk(String httpNode, String ask) {
 
   /** constructor. */
   public static HttpResponse getNkFromNsk(String httpNode, String nsk) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getnkfromnsk";
       JsonObject userBaseObj2 = new JsonObject();
@@ -4051,7 +4063,7 @@ public static HttpResponse getNkFromNsk(String httpNode, String nsk) {
 
   /** constructor. */
   public static HttpResponse getIncomingViewingKey(String httpNode, String ak, String nk) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getincomingviewingkey";
       JsonObject userBaseObj2 = new JsonObject();
@@ -4067,7 +4079,7 @@ public static HttpResponse getIncomingViewingKey(String httpNode, String ak, Str
 
   /** constructor. */
   public static HttpResponse getNewShieldedAddress(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getnewshieldedaddress";
       response = createConnect(requestUrl);
@@ -4080,7 +4092,7 @@ public static HttpResponse getNewShieldedAddress(String httpNode) {
 
   /** constructor. */
   public static HttpResponse getZenPaymentAddress(String httpNode, String ivk, String d) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getzenpaymentaddress";
       JsonObject userBaseObj2 = new JsonObject();
@@ -4097,7 +4109,7 @@ public static HttpResponse getZenPaymentAddress(String httpNode, String ivk, Str
   /** constructor. */
   public static HttpResponse getMerkleTreeVoucherInfo(
       String httpNode, String hash, Integer index, int blockNum) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getmerkletreevoucherinfo";
       JSONObjectWarp jsonObjectWarp = new JSONObjectWarp();
@@ -4120,7 +4132,7 @@ public static HttpResponse getMerkleTreeVoucherInfo(
   /** constructor. */
   public static HttpResponse getMerkleTreeVoucherInfoFromSolidity(
       String httpSolidityNode, String hash, Integer index, int blockNum) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/getmerkletreevoucherinfo";
       JSONObjectWarp jsonObjectWarp = new JSONObjectWarp();
@@ -4143,7 +4155,7 @@ public static HttpResponse getMerkleTreeVoucherInfoFromSolidity(
   /** constructor. */
   public static HttpResponse getMerkleTreeVoucherInfoFromPbft(
       String httpSolidityNode, String hash, Integer index, int blockNum) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletpbft/getmerkletreevoucherinfo";
       JSONObjectWarp jsonObjectWarp = new JSONObjectWarp();
@@ -4174,7 +4186,7 @@ public static HttpResponse sendShieldCoin(
       byte[] publicZenTokenToAddress,
       long toAmount,
       String zenTokenOwnerKey) {
-        HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/createshieldedtransaction";
 
@@ -4252,7 +4264,8 @@ public static HttpResponse sendShieldCoin(
       String transactionString = EntityUtils.toString(response.getEntity());
       logger.info(transactionString);
       if (!ByteUtil.isNullOrZeroArray(publicZenTokenOwnerAddress)) {
-        String transactionSignString = gettransactionsign(httpNode, transactionString, zenTokenOwnerKey);
+        String transactionSignString =
+            gettransactionsign(httpNode, transactionString, zenTokenOwnerKey);
         logger.info(transactionSignString);
         response = broadcastTransaction(httpNode, transactionSignString);
       } else {
@@ -4271,7 +4284,7 @@ public static Boolean getSpendResult(
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/isspend";
 
-      HttpResponse response = 
+      HttpResponse response =
           HttpMethod.getExpandedSpendingKey(httpNode, ByteArray.toHexString(shieldAddressInfo.sk));
       JSONObject responseContent = HttpMethod.parseResponseContent(response);
       String ask = responseContent.getString("ask");
@@ -4325,7 +4338,7 @@ public static Boolean getSpendResultFromSolidity(
     try {
       final String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/isspend";
 
-      HttpResponse response = 
+      HttpResponse response =
           HttpMethod.getExpandedSpendingKey(httpNode, ByteArray.toHexString(shieldAddressInfo.sk));
       JSONObject responseContent = HttpMethod.parseResponseContent(response);
       String ask = responseContent.getString("ask");
@@ -4380,7 +4393,7 @@ public static Boolean getSpendResultFromPbft(
       final String requestUrl = "http://" + httpSolidityNode + "/walletpbft/isspend";
       final JSONObjectWarp jsonObjectWarp = new JSONObjectWarp();
 
-      HttpResponse response = 
+      HttpResponse response =
           HttpMethod.getExpandedSpendingKey(httpNode, ByteArray.toHexString(shieldAddressInfo.sk));
       JSONObject responseContent = HttpMethod.parseResponseContent(response);
       String ask = responseContent.getString("ask");
@@ -4624,7 +4637,7 @@ public static List scanNoteByIvkFromPbft(
   public static List scanAndMarkNoteByIvk(
       String httpNode, ShieldAddressInfo shieldAddressInfo) {
     try {
-      HttpResponse response = 
+      HttpResponse response =
           HttpMethod.getExpandedSpendingKey(httpNode, ByteArray.toHexString(shieldAddressInfo.sk));
       JSONObject responseContent = HttpMethod.parseResponseContent(response);
       String ask = responseContent.getString("ask");
@@ -4691,7 +4704,7 @@ public static List scanAndMarkNoteByIvk(
   public static List scanAndMarkNoteByIvkFromSolidity(
       String httpNode, String httpSolidityNode, ShieldAddressInfo shieldAddressInfo) {
     try {
-      HttpResponse response = 
+      HttpResponse response =
           HttpMethod.getExpandedSpendingKey(httpNode, ByteArray.toHexString(shieldAddressInfo.sk));
       JSONObject responseContent = HttpMethod.parseResponseContent(response);
       String ask = responseContent.getString("ask");
@@ -4759,7 +4772,7 @@ public static List scanAndMarkNoteByIvkFromSolidity(
   public static List scanAndMarkNoteByIvkFromPbft(
       String httpNode, String httpSolidityNode, ShieldAddressInfo shieldAddressInfo) {
     try {
-      HttpResponse response = 
+      HttpResponse response =
           HttpMethod.getExpandedSpendingKey(httpNode, ByteArray.toHexString(shieldAddressInfo.sk));
       JSONObject responseContent = HttpMethod.parseResponseContent(response);
       String ask = responseContent.getString("ask");
@@ -4933,7 +4946,7 @@ public static HttpResponse sendShieldCoinWithoutAsk(
       byte[] publicZenTokenToAddress,
       long toAmount,
       String zenTokenOwnerKey) {
-        HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl =
           "http://" + httpNode + "/wallet/createshieldedtransactionwithoutspendauthsig";
@@ -5065,7 +5078,8 @@ public static HttpResponse sendShieldCoinWithoutAsk(
       }
 
       if (!ByteUtil.isNullOrZeroArray(publicZenTokenOwnerAddress)) {
-        String transactionSignString = gettransactionsign(httpNode, transactionString, zenTokenOwnerKey);
+        String transactionSignString =
+            gettransactionsign(httpNode, transactionString, zenTokenOwnerKey);
         logger.info(transactionSignString);
         response = broadcastTransaction(httpNode, transactionSignString);
       } else {
@@ -5091,7 +5105,7 @@ public static void freeResource(
   /** constructor. */
   public static HttpResponse updateBrokerage(
       String httpNode, byte[] ownerAddress, Long brokerage, String fromKey) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/updateBrokerage";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5112,7 +5126,7 @@ public static HttpResponse updateBrokerage(
   /** constructor. */
   public static HttpResponse updateBrokerageOnVisible(
       String httpNode, byte[] ownerAddress, Long brokerage, String fromKey, String visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/updateBrokerage";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5137,7 +5151,7 @@ public static HttpResponse updateBrokerageOnVisible(
 
   /** constructor. */
   public static HttpResponse getReward(String httpNode, byte[] address) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getReward";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5153,7 +5167,7 @@ public static HttpResponse getReward(String httpNode, byte[] address) {
 
   /** constructor. */
   public static HttpResponse getRewardFromSolidity(String httpSolidityNode, byte[] address) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/getReward";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5169,7 +5183,7 @@ public static HttpResponse getRewardFromSolidity(String httpSolidityNode, byte[]
 
   /** constructor. */
   public static HttpResponse getRewardFromPbft(String httpSolidityNode, byte[] address) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletpbft/getReward";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5185,7 +5199,7 @@ public static HttpResponse getRewardFromPbft(String httpSolidityNode, byte[] add
 
   /** constructor. */
   public static HttpResponse getBrokerage(String httpNode, byte[] address) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getBrokerage";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5201,7 +5215,7 @@ public static HttpResponse getBrokerage(String httpNode, byte[] address) {
 
   /** constructor. */
   public static HttpResponse getBrokerageFromSolidity(String httpSolidityNode, byte[] address) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/getBrokerage";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5217,7 +5231,7 @@ public static HttpResponse getBrokerageFromSolidity(String httpSolidityNode, byt
 
   /** constructor. */
   public static HttpResponse getRewardOnVisible(String httpNode, byte[] address, String visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/getReward";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5239,7 +5253,7 @@ public static HttpResponse getRewardOnVisible(String httpNode, byte[] address, S
   /** constructor. */
   public static HttpResponse getRewardFromSolidityOnVisible(
       String httpSolidityNode, byte[] address, String visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/getReward";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5261,7 +5275,7 @@ public static HttpResponse getRewardFromSolidityOnVisible(
   /** constructor. */
   public static HttpResponse getBrokerageOnVisible(
       String httpNode, byte[] address, String visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/getBrokerage";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5283,7 +5297,7 @@ public static HttpResponse getBrokerageOnVisible(
   /** constructor. */
   public static HttpResponse getBrokerageFromSolidityOnVisible(
       String httpSolidityNode, byte[] address, String visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/getBrokerage";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5304,7 +5318,7 @@ public static HttpResponse getBrokerageFromSolidityOnVisible(
 
   /** constructor. */
   public static HttpResponse getBrokerageFromPbft(String httpSolidityNode, byte[] address) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpSolidityNode + "/walletpbft/getBrokerage";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5327,7 +5341,7 @@ public static String marketSellAssetGetTxId(
       Long buyTokenQuantity,
       String fromKey,
       String visible) {
-      String transactionSignString = null;
+    String transactionSignString = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/marketsellasset";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5359,7 +5373,7 @@ public static String marketSellAssetGetTxId(
 
   /** constructor. */
   public static HttpResponse getMarketOrderById(String httpNode, String orderId, String visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getmarketorderbyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5376,7 +5390,7 @@ public static HttpResponse getMarketOrderById(String httpNode, String orderId, S
   /** constructor. */
   public static HttpResponse getMarketOrderByIdFromSolidity(
       String httpSolidityNode, String orderId, String visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/getmarketorderbyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5393,7 +5407,7 @@ public static HttpResponse getMarketOrderByIdFromSolidity(
   /** constructor. */
   public static HttpResponse getMarketOrderByIdFromPbft(
       String httpPbftNode, String orderId, String visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpPbftNode + "/walletpbft/getmarketorderbyid";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5410,7 +5424,7 @@ public static HttpResponse getMarketOrderByIdFromPbft(
   /** constructor. */
   public static String marketCancelOrder(
       String httpNode, byte[] ownerAddress, String orderId, String fromKey, String visible) {
-      String transactionSignString = null;
+    String transactionSignString = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/marketcancelorder";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5438,7 +5452,7 @@ public static String marketCancelOrder(
   /** constructor. */
   public static HttpResponse getMarketOrderByAccount(
       String httpNode, byte[] ownerAddress, String visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getmarketorderbyaccount";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5459,7 +5473,7 @@ public static HttpResponse getMarketOrderByAccount(
   /** constructor. */
   public static HttpResponse getMarketOrderByAccountFromSolidity(
       String httpSolidityNode, byte[] ownerAddress, String visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/getmarketorderbyaccount";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5480,7 +5494,7 @@ public static HttpResponse getMarketOrderByAccountFromSolidity(
   /** constructor. */
   public static HttpResponse getMarketOrderByAccountFromPbft(
       String httpPbftNode, byte[] ownerAddress, String visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpPbftNode + "/walletpbft/getmarketorderbyaccount";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5500,7 +5514,7 @@ public static HttpResponse getMarketOrderByAccountFromPbft(
 
   /** constructor. */
   public static HttpResponse getMarketPairList(String httpNode, String visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getmarketpairlist";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5516,7 +5530,7 @@ public static HttpResponse getMarketPairList(String httpNode, String visible) {
   /** constructor. */
   public static HttpResponse getMarketPairListFromSolidity(
       String httpSolidityNode, String visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/getmarketpairlist";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5531,7 +5545,7 @@ public static HttpResponse getMarketPairListFromSolidity(
 
   /** constructor. */
   public static HttpResponse getMarketPairListFromPbft(String httpPbftNode, String visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpPbftNode + "/walletpbft/getmarketpairlist";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5547,7 +5561,7 @@ public static HttpResponse getMarketPairListFromPbft(String httpPbftNode, String
   /** constructor. */
   public static HttpResponse getMarketOrderListByPair(
       String httpNode, String sellTokenId, String buyTokenId, String visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getmarketorderlistbypair";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5570,7 +5584,7 @@ public static HttpResponse getMarketOrderListByPair(
   /** constructor. */
   public static HttpResponse getMarketOrderListByPairFromSolidity(
       String httpSolidityNode, String sellTokenId, String buyTokenId, String visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/getmarketorderlistbypair";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5593,7 +5607,7 @@ public static HttpResponse getMarketOrderListByPairFromSolidity(
   /** constructor. */
   public static HttpResponse getMarketOrderListByPairFromPbft(
       String httpPbftNode, String sellTokenId, String buyTokenId, String visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpPbftNode + "/walletpbft/getmarketorderlistbypair";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5616,7 +5630,7 @@ public static HttpResponse getMarketOrderListByPairFromPbft(
   /** constructor. */
   public static HttpResponse getMarketPriceByPair(
       String httpNode, String sellTokenId, String buyTokenId, String visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getmarketpricebypair";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5639,7 +5653,7 @@ public static HttpResponse getMarketPriceByPair(
   /** constructor. */
   public static HttpResponse getMarketPriceByPairFromSolidity(
       String httpSolidityNode, String sellTokenId, String buyTokenId, String visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpSolidityNode + "/walletsolidity/getmarketpricebypair";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5662,7 +5676,7 @@ public static HttpResponse getMarketPriceByPairFromSolidity(
   /** constructor. */
   public static HttpResponse getMarketPriceByPairFromPbft(
       String httpPbftNode, String sellTokenId, String buyTokenId, String visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpPbftNode + "/walletpbft/getmarketpricebypair";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5684,7 +5698,7 @@ public static HttpResponse getMarketPriceByPairFromPbft(
 
   /** constructor. */
   public static int getTransactionPendingSize(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getpendingsize";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5699,7 +5713,7 @@ public static int getTransactionPendingSize(String httpNode) {
 
   /** constructor. */
   public static HttpResponse getTransactionListFromPending(String httpNode) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/gettransactionlistfrompending";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5713,7 +5727,7 @@ public static HttpResponse getTransactionListFromPending(String httpNode) {
 
   /** constructor. */
   public static HttpResponse getTransactionFromPending(String httpNode, String txid) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/gettransactionfrompending";
       JsonObject userBaseObj2 = new JsonObject();
@@ -5726,12 +5740,15 @@ public static HttpResponse getTransactionFromPending(String httpNode, String txi
     return response;
   }
   /** constructor. */
-  public static HttpResponse getCanDelegatedMaxSize(String httpNode,  byte[] ownerAddress, Long type, boolean visible) {
-      HttpResponse response = null;
+
+  public static HttpResponse getCanDelegatedMaxSize(
+      String httpNode, byte[] ownerAddress, Long type, boolean visible) {
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getcandelegatedmaxsize";
       JsonObject requestParam = new JsonObject();
-      requestParam.addProperty("owner_address",
+      requestParam.addProperty(
+          "owner_address",
           visible ? Base58.encode58Check(ownerAddress) : ByteArray.toHexString(ownerAddress));
       requestParam.addProperty("type", type);
       requestParam.addProperty("visible", visible);
@@ -5742,12 +5759,15 @@ public static HttpResponse getCanDelegatedMaxSize(String httpNode,  byte[] owner
     return response;
   }
   /** constructor. */
-  public static HttpResponse getAvailableUnfreezeCount(String httpNode, byte[] ownerAddress, boolean visible) {
-      HttpResponse response = null;
+
+  public static HttpResponse getAvailableUnfreezeCount(
+      String httpNode, byte[] ownerAddress, boolean visible) {
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getavailableunfreezecount";
       JsonObject requestParam = new JsonObject();
-      requestParam.addProperty("owner_address",
+      requestParam.addProperty(
+          "owner_address",
           visible ? Base58.encode58Check(ownerAddress) : ByteArray.toHexString(ownerAddress));
       requestParam.addProperty("visible", visible);
       response = createConnect(requestUrl, requestParam);
@@ -5757,13 +5777,15 @@ public static HttpResponse getAvailableUnfreezeCount(String httpNode, byte[] own
     return response;
   }
   /** constructor. */
+
   public static HttpResponse getCanWithdrawUnfreezeAmount(
       String httpNode, byte[] ownerAddress, Long timestamp, boolean visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getcanwithdrawunfreezeamount";
       JsonObject requestParam = new JsonObject();
-      requestParam.addProperty("owner_address",
+      requestParam.addProperty(
+          "owner_address",
           visible ? Base58.encode58Check(ownerAddress) : ByteArray.toHexString(ownerAddress));
       requestParam.addProperty("timestamp", timestamp);
       requestParam.addProperty("visible", visible);
@@ -5774,15 +5796,18 @@ public static HttpResponse getCanWithdrawUnfreezeAmount(
     return response;
   }
   /** constructor. */
+
   public static HttpResponse getDelegatedResourceV2(
       String httpNode, byte[] fromAddress, byte[] toAddress, boolean visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getdelegatedresourcev2";
       JsonObject requestParam = new JsonObject();
-      requestParam.addProperty("fromAddress",
+      requestParam.addProperty(
+          "fromAddress",
           visible ? Base58.encode58Check(fromAddress) : ByteArray.toHexString(fromAddress));
-      requestParam.addProperty("toAddress",
+      requestParam.addProperty(
+          "toAddress",
           visible ? Base58.encode58Check(toAddress) : ByteArray.toHexString(toAddress));
       requestParam.addProperty("visible", visible);
       response = createConnect(requestUrl, requestParam);
@@ -5792,46 +5817,52 @@ public static HttpResponse getDelegatedResourceV2(
     return response;
   }
   /** constructor. */
-  public static HttpResponse getDelegatedResourceAccountIndexV2(String httpNode, byte[] address, boolean visible) {
-      HttpResponse response = null;
+
+  public static HttpResponse getDelegatedResourceAccountIndexV2(
+      String httpNode, byte[] address, boolean visible) {
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/getdelegatedresourceaccountindexv2";
       JsonObject requestParam = new JsonObject();
-      requestParam.addProperty("value",
-          visible ? Base58.encode58Check(address) : ByteArray.toHexString(address));
+      requestParam.addProperty(
+          "value", visible ? Base58.encode58Check(address) : ByteArray.toHexString(address));
       requestParam.addProperty("visible", visible);
       response = createConnect(requestUrl, requestParam);
     } catch (Exception e) {
       e.printStackTrace();
     }
-    return  response;
+    return response;
   }
 
   /** constructor. */
   public static HttpResponse getCanDelegatedMaxSizeSolidity(
-      String httpNodeSolidity,  byte[] ownerAddress, Long type, boolean visible) {
-      HttpResponse response = null;
+      String httpNodeSolidity, byte[] ownerAddress, Long type, boolean visible) {
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNodeSolidity + "/walletsolidity/getcandelegatedmaxsize";
       JsonObject requestParam = new JsonObject();
-      requestParam.addProperty("owner_address",
+      requestParam.addProperty(
+          "owner_address",
           visible ? Base58.encode58Check(ownerAddress) : ByteArray.toHexString(ownerAddress));
       requestParam.addProperty("type", type);
       requestParam.addProperty("visible", visible);
       response = createConnect(requestUrl, requestParam);
-    }catch(Exception e) {
+    } catch (Exception e) {
       e.printStackTrace();
     }
     return response;
   }
   /** constructor. */
+
   public static HttpResponse getAvailableUnfreezeCountSolidity(
-      String httpNodeSolidity, byte[] ownerAddress, boolean visible){
-      HttpResponse response = null;
+      String httpNodeSolidity, byte[] ownerAddress, boolean visible) {
+    HttpResponse response = null;
     try {
-      String requestUrl = "http://" + httpNodeSolidity + "/walletsolidity/getavailableunfreezecount";
+      String requestUrl =
+          "http://" + httpNodeSolidity + "/walletsolidity/getavailableunfreezecount";
       JsonObject requestParam = new JsonObject();
-      requestParam.addProperty("owner_address",
+      requestParam.addProperty(
+          "owner_address",
           visible ? Base58.encode58Check(ownerAddress) : ByteArray.toHexString(ownerAddress));
       requestParam.addProperty("visible", visible);
       response = createConnect(requestUrl, requestParam);
@@ -5841,13 +5872,16 @@ public static HttpResponse getAvailableUnfreezeCountSolidity(
     return response;
   }
   /** constructor. */
+
   public static HttpResponse getCanWithdrawUnfreezeAmountSolidity(
-      String httpNodeSolidity, byte[] ownerAddress, Long timestamp, boolean visible){
-      HttpResponse response = null;
+      String httpNodeSolidity, byte[] ownerAddress, Long timestamp, boolean visible) {
+    HttpResponse response = null;
     try {
-      String requestUrl = "http://" + httpNodeSolidity + "/walletsolidity/getcanwithdrawunfreezeamount";
+      String requestUrl =
+          "http://" + httpNodeSolidity + "/walletsolidity/getcanwithdrawunfreezeamount";
       JsonObject requestParam = new JsonObject();
-      requestParam.addProperty("owner_address",
+      requestParam.addProperty(
+          "owner_address",
           visible ? Base58.encode58Check(ownerAddress) : ByteArray.toHexString(ownerAddress));
       requestParam.addProperty("timestamp", timestamp);
       requestParam.addProperty("visible", visible);
@@ -5858,15 +5892,18 @@ public static HttpResponse getCanWithdrawUnfreezeAmountSolidity(
     return response;
   }
   /** constructor. */
+
   public static HttpResponse getDelegatedResourceV2Solidity(
-      String httpNodeSolidity, byte[] fromAddress, byte[] toAddress,boolean visible) {
-      HttpResponse response = null;
+      String httpNodeSolidity, byte[] fromAddress, byte[] toAddress, boolean visible) {
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNodeSolidity + "/walletsolidity/getdelegatedresourcev2";
       JsonObject requestParam = new JsonObject();
-      requestParam.addProperty("fromAddress",
+      requestParam.addProperty(
+          "fromAddress",
           visible ? Base58.encode58Check(fromAddress) : ByteArray.toHexString(fromAddress));
-      requestParam.addProperty("toAddress",
+      requestParam.addProperty(
+          "toAddress",
           visible ? Base58.encode58Check(toAddress) : ByteArray.toHexString(toAddress));
       requestParam.addProperty("visible", visible);
       response = createConnect(requestUrl, requestParam);
@@ -5879,26 +5916,30 @@ public static HttpResponse getDelegatedResourceV2Solidity(
   /** constructor. */
   public static HttpResponse getDelegatedResourceAccountIndexV2Solidity(
       String httpNodeSolidity, byte[] address, boolean visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
-      String requestUrl = "http://" + httpNodeSolidity + "/walletsolidity/getdelegatedresourceaccountindexv2";
+      String requestUrl =
+          "http://" + httpNodeSolidity + "/walletsolidity/getdelegatedresourceaccountindexv2";
       JsonObject requestParam = new JsonObject();
-      requestParam.addProperty("value",
-          visible ? Base58.encode58Check(address) : ByteArray.toHexString(address));
+      requestParam.addProperty(
+          "value", visible ? Base58.encode58Check(address) : ByteArray.toHexString(address));
       requestParam.addProperty("visible", visible);
       response = createConnect(requestUrl, requestParam);
     } catch (Exception e) {
       e.printStackTrace();
     }
-    return  response;
+    return response;
   }
   /** constructor. */
-  public static HttpResponse getCanDelegatedMaxSizePbft(String httpNode,  byte[] ownerAddress, Long type, boolean visible) {
-      HttpResponse response = null;
+
+  public static HttpResponse getCanDelegatedMaxSizePbft(
+      String httpNode, byte[] ownerAddress, Long type, boolean visible) {
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/walletpbft/getcandelegatedmaxsize";
       JsonObject requestParam = new JsonObject();
-      requestParam.addProperty("owner_address",
+      requestParam.addProperty(
+          "owner_address",
           visible ? Base58.encode58Check(ownerAddress) : ByteArray.toHexString(ownerAddress));
       requestParam.addProperty("type", type);
       requestParam.addProperty("visible", visible);
@@ -5909,12 +5950,15 @@ public static HttpResponse getCanDelegatedMaxSizePbft(String httpNode,  byte[] o
     return response;
   }
   /** constructor. */
-  public static HttpResponse getAvailableUnfreezeCountPbft(String httpNode, byte[] ownerAddress, boolean visible) {
-      HttpResponse response = null;
+
+  public static HttpResponse getAvailableUnfreezeCountPbft(
+      String httpNode, byte[] ownerAddress, boolean visible) {
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/walletpbft/getavailableunfreezecount";
       JsonObject requestParam = new JsonObject();
-      requestParam.addProperty("owner_address",
+      requestParam.addProperty(
+          "owner_address",
           visible ? Base58.encode58Check(ownerAddress) : ByteArray.toHexString(ownerAddress));
       requestParam.addProperty("visible", visible);
       response = createConnect(requestUrl, requestParam);
@@ -5924,13 +5968,15 @@ public static HttpResponse getAvailableUnfreezeCountPbft(String httpNode, byte[]
     return response;
   }
   /** constructor. */
+
   public static HttpResponse getCanWithdrawUnfreezeAmountPbft(
       String httpNode, byte[] ownerAddress, Long timestamp, boolean visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/walletpbft/getcanwithdrawunfreezeamount";
       JsonObject requestParam = new JsonObject();
-      requestParam.addProperty("owner_address",
+      requestParam.addProperty(
+          "owner_address",
           visible ? Base58.encode58Check(ownerAddress) : ByteArray.toHexString(ownerAddress));
       requestParam.addProperty("timestamp", timestamp);
       requestParam.addProperty("visible", visible);
@@ -5941,15 +5987,18 @@ public static HttpResponse getCanWithdrawUnfreezeAmountPbft(
     return response;
   }
   /** constructor. */
+
   public static HttpResponse getDelegatedResourceV2Pbft(
       String httpNode, byte[] fromAddress, byte[] toAddress, boolean visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/walletpbft/getdelegatedresourcev2";
       JsonObject requestParam = new JsonObject();
-      requestParam.addProperty("fromAddress",
+      requestParam.addProperty(
+          "fromAddress",
           visible ? Base58.encode58Check(fromAddress) : ByteArray.toHexString(fromAddress));
-      requestParam.addProperty("toAddress",
+      requestParam.addProperty(
+          "toAddress",
           visible ? Base58.encode58Check(toAddress) : ByteArray.toHexString(toAddress));
       requestParam.addProperty("visible", visible);
       response = createConnect(requestUrl, requestParam);
@@ -5959,19 +6008,21 @@ public static HttpResponse getDelegatedResourceV2Pbft(
     return response;
   }
   /** constructor. */
-  public static HttpResponse getDelegatedResourceAccountIndexV2Pbft(String httpNode, byte[] address, boolean visible) {
-      HttpResponse response = null;
+
+  public static HttpResponse getDelegatedResourceAccountIndexV2Pbft(
+      String httpNode, byte[] address, boolean visible) {
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/walletpbft/getdelegatedresourceaccountindexv2";
       JsonObject requestParam = new JsonObject();
-      requestParam.addProperty("value",
-          visible ? Base58.encode58Check(address) : ByteArray.toHexString(address));
+      requestParam.addProperty(
+          "value", visible ? Base58.encode58Check(address) : ByteArray.toHexString(address));
       requestParam.addProperty("visible", visible);
       response = createConnect(requestUrl, requestParam);
     } catch (Exception e) {
       e.printStackTrace();
     }
-    return  response;
+    return response;
   }
 
   /** constructor. */
@@ -5986,18 +6037,22 @@ public static HttpResponse getEstimateEnergy(
       long call_value,
       long call_token_value,
       long token_id) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/wallet/estimateenergy";
       JsonObject requestParam = new JsonObject();
-      requestParam.addProperty("owner_address",
+      requestParam.addProperty(
+          "owner_address",
           visible ? Base58.encode58Check(ownerAddress) : ByteArray.toHexString(ownerAddress));
-      if(contractAddress == null){
+      if (contractAddress == null) {
         String tem = null;
         requestParam.addProperty("contract_address", tem);
-      }else {
-        requestParam.addProperty("contract_address",
-            visible ? Base58.encode58Check(contractAddress) : ByteArray.toHexString(contractAddress));
+      } else {
+        requestParam.addProperty(
+            "contract_address",
+            visible
+                ? Base58.encode58Check(contractAddress)
+                : ByteArray.toHexString(contractAddress));
       }
       requestParam.addProperty("function_selector", functionSelector);
       requestParam.addProperty("parameter", parameter);
@@ -6007,7 +6062,7 @@ public static HttpResponse getEstimateEnergy(
     } catch (Exception e) {
       e.printStackTrace();
     }
-    return  response;
+    return response;
   }
 
   /** constructor. */
@@ -6018,13 +6073,15 @@ public static HttpResponse getEstimateEnergySolidity(
       String functionSelector,
       String parameter,
       boolean visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/walletsolidity/estimateenergy";
       JsonObject requestParam = new JsonObject();
-      requestParam.addProperty("owner_address",
+      requestParam.addProperty(
+          "owner_address",
           visible ? Base58.encode58Check(ownerAddress) : ByteArray.toHexString(ownerAddress));
-      requestParam.addProperty("contract_address",
+      requestParam.addProperty(
+          "contract_address",
           visible ? Base58.encode58Check(contractAddress) : ByteArray.toHexString(contractAddress));
       requestParam.addProperty("function_selector", functionSelector);
       requestParam.addProperty("parameter", parameter);
@@ -6033,7 +6090,7 @@ public static HttpResponse getEstimateEnergySolidity(
     } catch (Exception e) {
       e.printStackTrace();
     }
-    return  response;
+    return response;
   }
 
   /** constructor. */
@@ -6044,13 +6101,15 @@ public static HttpResponse getEstimateEnergyPBFT(
       String functionSelector,
       String parameter,
       boolean visible) {
-      HttpResponse response = null;
+    HttpResponse response = null;
     try {
       String requestUrl = "http://" + httpNode + "/walletpbft/estimateenergy";
       JsonObject requestParam = new JsonObject();
-      requestParam.addProperty("owner_address",
+      requestParam.addProperty(
+          "owner_address",
           visible ? Base58.encode58Check(ownerAddress) : ByteArray.toHexString(ownerAddress));
-      requestParam.addProperty("contract_address",
+      requestParam.addProperty(
+          "contract_address",
           visible ? Base58.encode58Check(contractAddress) : ByteArray.toHexString(contractAddress));
       requestParam.addProperty("function_selector", functionSelector);
       requestParam.addProperty("parameter", parameter);
@@ -6059,32 +6118,37 @@ public static HttpResponse getEstimateEnergyPBFT(
     } catch (Exception e) {
       e.printStackTrace();
     }
-    return  response;
+    return response;
   }
   /** constructor. */
+
   public static HttpResponse getEstimateEnergyDeployContract(
-          String httpNode,
-          byte[] ownerAddress,
-          byte[] contractAddress,
-          String functionSelector,
-          String parameter,
-          String data,
-          long call_value,
-          long call_token_value,
-          long token_id,
-          boolean visible) {
-      HttpResponse response = null;
+      String httpNode,
+      byte[] ownerAddress,
+      byte[] contractAddress,
+      String functionSelector,
+      String parameter,
+      String data,
+      long call_value,
+      long call_token_value,
+      long token_id,
+      boolean visible) {
+    HttpResponse response = null;
     try {
       final String requestUrl = "http://" + httpNode + "/wallet/estimateenergy";
       JsonObject requestParam = new JsonObject();
-      requestParam.addProperty("owner_address",
-              visible ? Base58.encode58Check(ownerAddress) : ByteArray.toHexString(ownerAddress));
+      requestParam.addProperty(
+          "owner_address",
+          visible ? Base58.encode58Check(ownerAddress) : ByteArray.toHexString(ownerAddress));
       if (contractAddress == null) {
         String tem = null;
         requestParam.addProperty("contract_address", tem);
       } else {
-        requestParam.addProperty("contract_address",
-                visible ? Base58.encode58Check(contractAddress) : ByteArray.toHexString(contractAddress));
+        requestParam.addProperty(
+            "contract_address",
+            visible
+                ? Base58.encode58Check(contractAddress)
+                : ByteArray.toHexString(contractAddress));
       }
       requestParam.addProperty("function_selector", functionSelector);
       requestParam.addProperty("parameter", parameter);
@@ -6099,9 +6163,6 @@ public static HttpResponse getEstimateEnergyDeployContract(
     } catch (Exception e) {
       e.printStackTrace();
     }
-    return  response;
+    return response;
   }
-
-
-
 }
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/HttpSelfFormatFieldName.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/HttpSelfFormatFieldName.java
index 9227121d..a10994c6 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/HttpSelfFormatFieldName.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/HttpSelfFormatFieldName.java
@@ -9,183 +9,180 @@ public class HttpSelfFormatFieldName {
   private static Map NameFieldNameMap = new HashMap<>();
 
   static {
-    //***** api.proto *****
-    //DelegatedResourceMessage
+    // ***** api.proto *****
+    // DelegatedResourceMessage
     AddressFieldNameMap.put("protocol.DelegatedResourceMessage.fromAddress", 1);
     AddressFieldNameMap.put("protocol.DelegatedResourceMessage.toAddress", 1);
-    //TransactionSignWeight
+    // TransactionSignWeight
     AddressFieldNameMap.put("protocol.TransactionSignWeight.approved_list", 1);
-    //TransactionApprovedList
+    // TransactionApprovedList
     AddressFieldNameMap.put("protocol.TransactionApprovedList.approved_list", 1);
-    //PrivateParameters
+    // PrivateParameters
     AddressFieldNameMap.put("protocol.PrivateParameters.transparent_from_address", 1);
     AddressFieldNameMap.put("protocol.PrivateParameters.transparent_to_address", 1);
-    //PrivateParametersWithoutAsk
+    // PrivateParametersWithoutAsk
     AddressFieldNameMap.put("protocol.PrivateParametersWithoutAsk.transparent_from_address", 1);
     AddressFieldNameMap.put("protocol.PrivateParametersWithoutAsk.transparent_to_address", 1);
-    //PrivateShieldedTRC20Parameters
-    AddressFieldNameMap.put(
-        "protocol.PrivateShieldedTRC20Parameters.transparent_to_address", 1);
+    // PrivateShieldedTRC20Parameters
+    AddressFieldNameMap.put("protocol.PrivateShieldedTRC20Parameters.transparent_to_address", 1);
     AddressFieldNameMap.put(
         "protocol.PrivateShieldedTRC20Parameters.shielded_TRC20_contract_address", 1);
-    //PrivateShieldedTRC20ParametersWithoutAsk
+    // PrivateShieldedTRC20ParametersWithoutAsk
     AddressFieldNameMap.put(
         "protocol.PrivateShieldedTRC20ParametersWithoutAsk.transparent_to_address", 1);
     AddressFieldNameMap.put(
         "protocol.PrivateShieldedTRC20ParametersWithoutAsk.shielded_TRC20_contract_address", 1);
-    //IvkDecryptTRC20Parameters
+    // IvkDecryptTRC20Parameters
     AddressFieldNameMap.put(
         "protocol.IvkDecryptTRC20Parameters.shielded_TRC20_contract_address", 1);
-    //OvkDecryptTRC20Parameters
+    // OvkDecryptTRC20Parameters
     AddressFieldNameMap.put(
         "protocol.OvkDecryptTRC20Parameters.shielded_TRC20_contract_address", 1);
-    //NfTRC20Parameters
-    AddressFieldNameMap.put(
-        "protocol.NfTRC20Parameters.shielded_TRC20_contract_address", 1);
-    //ShieldedTRC20TriggerContractParameters
+    // NfTRC20Parameters
+    AddressFieldNameMap.put("protocol.NfTRC20Parameters.shielded_TRC20_contract_address", 1);
+    // ShieldedTRC20TriggerContractParameters
     AddressFieldNameMap.put(
         "protocol.ShieldedTRC20TriggerContractParameters.transparent_to_address", 1);
-    AddressFieldNameMap.put(
-        "protocol.DecryptNotesTRC20.NoteTx.transparent_to_address", 1);
+    AddressFieldNameMap.put("protocol.DecryptNotesTRC20.NoteTx.transparent_to_address", 1);
 
-    //***** Contract.proto *****
-    //AccountCreateContract
+    // ***** Contract.proto *****
+    // AccountCreateContract
     AddressFieldNameMap.put("protocol.AccountCreateContract.owner_address", 1);
     AddressFieldNameMap.put("protocol.AccountCreateContract.account_address", 1);
-    //AccountUpdateContract
+    // AccountUpdateContract
     AddressFieldNameMap.put("protocol.AccountUpdateContract.owner_address", 1);
-    //SetAccountIdContract
+    // SetAccountIdContract
     AddressFieldNameMap.put("protocol.SetAccountIdContract.owner_address", 1);
-    //TransferContract
+    // TransferContract
     AddressFieldNameMap.put("protocol.TransferContract.owner_address", 1);
     AddressFieldNameMap.put("protocol.TransferContract.to_address", 1);
-    //CancelDeferredTransactionContract
+    // CancelDeferredTransactionContract
     AddressFieldNameMap.put("protocol.CancelDeferredTransactionContract.ownerAddress", 1);
-    //TransferAssetContract
+    // TransferAssetContract
     AddressFieldNameMap.put("protocol.TransferAssetContract.owner_address", 1);
     AddressFieldNameMap.put("protocol.TransferAssetContract.to_address", 1);
-    //VoteAssetContract
+    // VoteAssetContract
     AddressFieldNameMap.put("protocol.VoteAssetContract.owner_address", 1);
     AddressFieldNameMap.put("protocol.VoteAssetContract.vote_address", 1);
-    //VoteWitnessContract
+    // VoteWitnessContract
     AddressFieldNameMap.put("protocol.VoteWitnessContract.Vote.vote_address", 1);
     AddressFieldNameMap.put("protocol.VoteWitnessContract.owner_address", 1);
-    //UpdateSettingContract
+    // UpdateSettingContract
     AddressFieldNameMap.put("protocol.UpdateSettingContract.owner_address", 1);
     AddressFieldNameMap.put("protocol.UpdateSettingContract.contract_address", 1);
-    //UpdateEnergyLimitContract
+    // UpdateEnergyLimitContract
     AddressFieldNameMap.put("protocol.UpdateEnergyLimitContract.owner_address", 1);
     AddressFieldNameMap.put("protocol.UpdateEnergyLimitContract.contract_address", 1);
-    //ClearABIContract
+    // ClearABIContract
     AddressFieldNameMap.put("protocol.ClearABIContract.owner_address", 1);
     AddressFieldNameMap.put("protocol.ClearABIContract.contract_address", 1);
-    //WitnessCreateContract
+    // WitnessCreateContract
     AddressFieldNameMap.put("protocol.WitnessCreateContract.owner_address", 1);
-    //WitnessUpdateContract
+    // WitnessUpdateContract
     AddressFieldNameMap.put("protocol.WitnessUpdateContract.owner_address", 1);
-    //AssetIssueContract
+    // AssetIssueContract
     AddressFieldNameMap.put("protocol.AssetIssueContract.owner_address", 1);
-    //ParticipateAssetIssueContract
+    // ParticipateAssetIssueContract
     AddressFieldNameMap.put("protocol.ParticipateAssetIssueContract.owner_address", 1);
     AddressFieldNameMap.put("protocol.ParticipateAssetIssueContract.to_address", 1);
-    //FreezeBalanceContract
+    // FreezeBalanceContract
     AddressFieldNameMap.put("protocol.FreezeBalanceContract.owner_address", 1);
     AddressFieldNameMap.put("protocol.FreezeBalanceContract.receiver_address", 1);
-    //UnfreezeBalanceContract
+    // UnfreezeBalanceContract
     AddressFieldNameMap.put("protocol.UnfreezeBalanceContract.owner_address", 1);
     AddressFieldNameMap.put("protocol.UnfreezeBalanceContract.receiver_address", 1);
-    //UnfreezeAssetContract
+    // UnfreezeAssetContract
     AddressFieldNameMap.put("protocol.UnfreezeAssetContract.owner_address", 1);
-    //WithdrawBalanceContract
+    // WithdrawBalanceContract
     AddressFieldNameMap.put("protocol.WithdrawBalanceContract.owner_address", 1);
-    //UpdateAssetContract
+    // UpdateAssetContract
     AddressFieldNameMap.put("protocol.UpdateAssetContract.owner_address", 1);
-    //ProposalCreateContract
+    // ProposalCreateContract
     AddressFieldNameMap.put("protocol.ProposalCreateContract.owner_address", 1);
-    //ProposalApproveContract
+    // ProposalApproveContract
     AddressFieldNameMap.put("protocol.ProposalApproveContract.owner_address", 1);
-    //ProposalDeleteContract
+    // ProposalDeleteContract
     AddressFieldNameMap.put("protocol.ProposalDeleteContract.owner_address", 1);
-    //CreateSmartContract
+    // CreateSmartContract
     AddressFieldNameMap.put("protocol.CreateSmartContract.owner_address", 1);
-    //TriggerSmartContract
+    // TriggerSmartContract
     AddressFieldNameMap.put("protocol.TriggerSmartContract.owner_address", 1);
     AddressFieldNameMap.put("protocol.TriggerSmartContract.contract_address", 1);
-    //BuyStorageContract
+    // BuyStorageContract
     AddressFieldNameMap.put("protocol.BuyStorageContract.owner_address", 1);
-    //BuyStorageBytesContract
+    // BuyStorageBytesContract
     AddressFieldNameMap.put("protocol.BuyStorageBytesContract.owner_address", 1);
-    //SellStorageContract
+    // SellStorageContract
     AddressFieldNameMap.put("protocol.SellStorageContract.owner_address", 1);
-    //ExchangeCreateContract
+    // ExchangeCreateContract
     AddressFieldNameMap.put("protocol.ExchangeCreateContract.owner_address", 1);
-    //ExchangeInjectContract
+    // ExchangeInjectContract
     AddressFieldNameMap.put("protocol.ExchangeInjectContract.owner_address", 1);
-    //ExchangeWithdrawContract
+    // ExchangeWithdrawContract
     AddressFieldNameMap.put("protocol.ExchangeWithdrawContract.owner_address", 1);
-    //ExchangeTransactionContract
+    // ExchangeTransactionContract
     AddressFieldNameMap.put("protocol.ExchangeTransactionContract.owner_address", 1);
-    //AccountPermissionUpdateContract
+    // AccountPermissionUpdateContract
     AddressFieldNameMap.put("protocol.AccountPermissionUpdateContract.owner_address", 1);
-    //UpdateBrokerageContract
+    // UpdateBrokerageContract
     AddressFieldNameMap.put("protocol.UpdateBrokerageContract.owner_address", 1);
-    //ShieldedTransferContract
+    // ShieldedTransferContract
     AddressFieldNameMap.put("protocol.ShieldedTransferContract.transparent_from_address", 1);
     AddressFieldNameMap.put("protocol.ShieldedTransferContract.transparent_to_address", 1);
-    //FreezeBalanceV2Contract
+    // FreezeBalanceV2Contract
     AddressFieldNameMap.put("protocol.FreezeBalanceV2Contract.owner_address", 1);
-    //UnfreezeBalanceV2Contract
+    // UnfreezeBalanceV2Contract
     AddressFieldNameMap.put("protocol.UnfreezeBalanceV2Contract.owner_address", 1);
-    //WithdrawExpireUnfreezeContract
+    // WithdrawExpireUnfreezeContract
     AddressFieldNameMap.put("protocol.WithdrawExpireUnfreezeContract.owner_address", 1);
-    //DelegateResourceContract
+    // DelegateResourceContract
     AddressFieldNameMap.put("protocol.DelegateResourceContract.owner_address", 1);
     AddressFieldNameMap.put("protocol.DelegateResourceContract.receiver_address", 1);
-    //UnDelegateResourceContract
+    // UnDelegateResourceContract
     AddressFieldNameMap.put("protocol.UnDelegateResourceContract.owner_address", 1);
     AddressFieldNameMap.put("protocol.UnDelegateResourceContract.receiver_address", 1);
-    //CancelAllUnfreezeV2Contract
+    // CancelAllUnfreezeV2Contract
     AddressFieldNameMap.put("protocol.CancelAllUnfreezeV2Contract.owner_address", 1);
     AddressFieldNameMap.put("protocol.CanDelegatedMaxSizeRequestMessage.owner_address", 1);
     AddressFieldNameMap.put("protocol.GetAvailableUnfreezeCountRequestMessage.owner_address", 1);
     AddressFieldNameMap.put("protocol.CanWithdrawUnfreezeAmountRequestMessage.owner_address", 1);
 
-    //***** Tron.proto *****
-    //AccountId
+    // ***** Tron.proto *****
+    // AccountId
     AddressFieldNameMap.put("protocol.AccountId.address", 1);
-    //Vote
+    // Vote
     AddressFieldNameMap.put("protocol.Vote.vote_address", 1);
-    //Proposal
+    // Proposal
     AddressFieldNameMap.put("protocol.Proposal.proposer_address", 1);
     AddressFieldNameMap.put("protocol.Proposal.approvals", 1);
-    //Exchange
+    // Exchange
     AddressFieldNameMap.put("protocol.Exchange.creator_address", 1);
-    //Account
+    // Account
     AddressFieldNameMap.put("protocol.Account.address", 1);
-    //Key
+    // Key
     AddressFieldNameMap.put("protocol.Key.address", 1);
-    //DelegatedResource
+    // DelegatedResource
     AddressFieldNameMap.put("protocol.DelegatedResource.from", 1);
     AddressFieldNameMap.put("protocol.DelegatedResource.to", 1);
-    //Witness
+    // Witness
     AddressFieldNameMap.put("protocol.Witness.address", 1);
-    //Votes
+    // Votes
     AddressFieldNameMap.put("protocol.Votes.address", 1);
-    //TransactionInfo
+    // TransactionInfo
     AddressFieldNameMap.put("protocol.TransactionInfo.Log.address", 1);
     AddressFieldNameMap.put("protocol.TransactionInfo.contract_address", 1);
-    //DeferredTransaction
+    // DeferredTransaction
     AddressFieldNameMap.put("protocol.DeferredTransaction.senderAddress", 1);
     AddressFieldNameMap.put("protocol.DeferredTransaction.receiverAddress", 1);
-    //BlockHeader
+    // BlockHeader
     AddressFieldNameMap.put("protocol.BlockHeader.raw.witness_address", 1);
-    //SmartContract
+    // SmartContract
     AddressFieldNameMap.put("protocol.SmartContract.origin_address", 1);
     AddressFieldNameMap.put("protocol.SmartContract.contract_address", 1);
-    //InternalTransaction
+    // InternalTransaction
     AddressFieldNameMap.put("protocol.InternalTransaction.caller_address", 1);
     AddressFieldNameMap.put("protocol.InternalTransaction.transferTo_address", 1);
-    //DelegatedResourceAccountIndex
+    // DelegatedResourceAccountIndex
     AddressFieldNameMap.put("protocol.DelegatedResourceAccountIndex.account", 1);
     AddressFieldNameMap.put("protocol.DelegatedResourceAccountIndex.fromAccounts", 1);
     AddressFieldNameMap.put("protocol.DelegatedResourceAccountIndex.toAccounts", 1);
@@ -193,64 +190,64 @@ public class HttpSelfFormatFieldName {
     AddressFieldNameMap.put("protocol.AccountIdentifier.address", 1);
     AddressFieldNameMap.put("protocol.TransactionBalanceTrace.Operation.address", 1);
 
-    //***** api.proto *****
-    //Return
+    // ***** api.proto *****
+    // Return
     NameFieldNameMap.put("protocol.Return.message", 1);
-    //Address
+    // Address
     NameFieldNameMap.put("protocol.Address.host", 1);
-    //Note
+    // Note
     NameFieldNameMap.put("protocol.Note.memo", 1);
 
-    //***** Contract.proto *****
-    //AccountUpdateContract
+    // ***** Contract.proto *****
+    // AccountUpdateContract
     NameFieldNameMap.put("protocol.AccountUpdateContract.account_name", 1);
-    //SetAccountIdContract
+    // SetAccountIdContract
     NameFieldNameMap.put("protocol.SetAccountIdContract.account_id", 1);
-    //TransferAssetContract
+    // TransferAssetContract
     NameFieldNameMap.put("protocol.TransferAssetContract.asset_name", 1);
-    //WitnessCreateContract
+    // WitnessCreateContract
     NameFieldNameMap.put("protocol.WitnessCreateContract.url", 1);
-    //WitnessUpdateContract
+    // WitnessUpdateContract
     NameFieldNameMap.put("protocol.WitnessUpdateContract.update_url", 1);
-    //AssetIssueContract
+    // AssetIssueContract
     NameFieldNameMap.put("protocol.AssetIssueContract.name", 1);
     NameFieldNameMap.put("protocol.AssetIssueContract.abbr", 1);
     NameFieldNameMap.put("protocol.AssetIssueContract.description", 1);
     NameFieldNameMap.put("protocol.AssetIssueContract.url", 1);
-    //ParticipateAssetIssueContract
+    // ParticipateAssetIssueContract
     NameFieldNameMap.put("protocol.ParticipateAssetIssueContract.asset_name", 1);
-    //UpdateAssetContract
+    // UpdateAssetContract
     NameFieldNameMap.put("protocol.UpdateAssetContract.description", 1);
     NameFieldNameMap.put("protocol.UpdateAssetContract.url", 1);
-    //ExchangeCreateContract
+    // ExchangeCreateContract
     NameFieldNameMap.put("protocol.ExchangeCreateContract.first_token_id", 1);
     NameFieldNameMap.put("protocol.ExchangeCreateContract.second_token_id", 1);
-    //ExchangeInjectContract
+    // ExchangeInjectContract
     NameFieldNameMap.put("protocol.ExchangeInjectContract.token_id", 1);
-    //ExchangeWithdrawContract
+    // ExchangeWithdrawContract
     NameFieldNameMap.put("protocol.ExchangeWithdrawContract.token_id", 1);
-    //ExchangeTransactionContract
+    // ExchangeTransactionContract
     NameFieldNameMap.put("protocol.ExchangeTransactionContract.token_id", 1);
 
-    //***** Tron.proto *****
-    //AccountId
+    // ***** Tron.proto *****
+    // AccountId
     NameFieldNameMap.put("protocol.AccountId.name", 1);
-    //Exchange
+    // Exchange
     NameFieldNameMap.put("protocol.Exchange.first_token_id", 1);
     NameFieldNameMap.put("protocol.Exchange.second_token_id", 1);
-    //Account
+    // Account
     NameFieldNameMap.put("protocol.Account.account_name", 1);
     NameFieldNameMap.put("protocol.Account.asset_issued_name", 1);
     NameFieldNameMap.put("protocol.Account.asset_issued_ID", 1);
     NameFieldNameMap.put("protocol.Account.account_id", 1);
-    //authority
+    // authority
     NameFieldNameMap.put("protocol.authority.permission_name", 1);
-    //Transaction
+    // Transaction
     NameFieldNameMap.put("protocol.Transaction.Contract.ContractName", 1);
-    //TransactionInfo
+    // TransactionInfo
     NameFieldNameMap.put("protocol.TransactionInfo.resMessage", 1);
 
-    //***** market.proto *****
+    // ***** market.proto *****
     // MarketSellAssetContract
     AddressFieldNameMap.put("protocol.MarketSellAssetContract.owner_address", 1);
     NameFieldNameMap.put("protocol.MarketSellAssetContract.sell_token_id", 1);
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/IncrementalMerkleTreeCapsule.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/IncrementalMerkleTreeCapsule.java
index 2897d400..4e697c08 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/IncrementalMerkleTreeCapsule.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/IncrementalMerkleTreeCapsule.java
@@ -8,7 +8,6 @@
 import org.tron.protos.contract.ShieldContract.IncrementalMerkleTree;
 import org.tron.protos.contract.ShieldContract.PedersenHash;
 
-
 @Slf4j
 public class IncrementalMerkleTreeCapsule implements ProtoCapsule {
 
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/JsonFormat.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/JsonFormat.java
index ac805410..6aac07a9 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/JsonFormat.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/JsonFormat.java
@@ -3,7 +3,7 @@
 /*
   Copyright (c) 2009, Orbitz World Wide
   All rights reserved.
-  
+
   Redistribution and use in source and binary forms, with or without modification,
   are permitted provided that the following conditions are met:
 
@@ -54,7 +54,6 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 import java.util.TreeMap;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.tron.protos.contract.BalanceContract;
@@ -67,7 +66,8 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * 

(c) 2009-10 Orbitz World Wide. All Rights Reserved. * * @author eliran.bivas@gmail.com Eliran Bivas - * @author aantonov@orbitz.com Alex Antonov

* Based on the original code by: + * @author aantonov@orbitz.com Alex Antonov + *

* Based on the original code by: * @author wenboz@google.com Wenbo Zhu * @author kenton@google.com Kenton Varda */ @@ -75,21 +75,19 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT public class JsonFormat { private static final int BUFFER_SIZE = 4096; - private static final Pattern DIGITS = Pattern.compile( - "[0-9]", - Pattern.CASE_INSENSITIVE); - private static final String WRITING_STRING_BUILDER_EXCEPTION - = "Writing to a StringBuilder threw an IOException (should never happen)."; + private static final Pattern DIGITS = Pattern.compile("[0-9]", Pattern.CASE_INSENSITIVE); + private static final String WRITING_STRING_BUILDER_EXCEPTION = + "Writing to a StringBuilder threw an IOException (should never happen)."; private static final String EXPECTED_STRING = "Expected string."; private static final String MISSING_END_QUOTE = "String missing ending quote."; public static final boolean ALWAYS_OUTPUT_DEFAULT_VALUE_FIELDS = true; - public static final Set> MESSAGES = ImmutableSet.of( - BalanceContract.AccountBalanceResponse.class, - BalanceContract.BlockBalanceTrace.class, - BalanceContract.TransactionBalanceTrace.Operation.class, - BalanceContract.TransactionBalanceTrace.class - ); + public static final Set> MESSAGES = + ImmutableSet.of( + BalanceContract.AccountBalanceResponse.class, + BalanceContract.BlockBalanceTrace.class, + BalanceContract.TransactionBalanceTrace.Operation.class, + BalanceContract.TransactionBalanceTrace.class); /** * Outputs a textual representation of the Protocol Message supplied into the parameter output. @@ -104,9 +102,7 @@ public static void print(Message message, Appendable output, boolean selfType) generator.print("}"); } - /** - * Outputs a textual representation of {@code fields} to {@code output}. - */ + /** Outputs a textual representation of {@code fields} to {@code output}. */ public static void print(UnknownFieldSet fields, Appendable output, boolean selfType) throws IOException { JsonGenerator generator = new JsonGenerator(output); @@ -121,8 +117,7 @@ protected static void print(Message message, JsonGenerator generator, boolean se if (ALWAYS_OUTPUT_DEFAULT_VALUE_FIELDS && MESSAGES.contains(message.getClass())) { for (FieldDescriptor field : message.getDescriptorForType().getFields()) { if (field.isOptional()) { - if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE - && !message.hasField(field)) { + if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE && !message.hasField(field)) { // Always skip empty optional message fields. If not we will recurse indefinitely if // a message has itself as a sub-field. continue; @@ -139,9 +134,9 @@ protected static void print(Message message, JsonGenerator generator, boolean se } } - //for (Iterator> iter = message.getAllFields().entrySet() - for (Iterator> iter = fieldsToPrint.entrySet() - .iterator(); iter.hasNext(); ) { + // for (Iterator> iter = message.getAllFields().entrySet() + for (Iterator> iter = fieldsToPrint.entrySet().iterator(); + iter.hasNext(); ) { Map.Entry field = iter.next(); printField(field.getKey(), field.getValue(), generator, selfType); if (iter.hasNext()) { @@ -154,9 +149,7 @@ protected static void print(Message message, JsonGenerator generator, boolean se printUnknownFields(message.getUnknownFields(), generator, selfType); } - /** - * Like {@code print()}, but writes directly to a {@code String} and returns it. - */ + /** Like {@code print()}, but writes directly to a {@code String} and returns it. */ public static String printToString(Message message, boolean selfType) { try { StringBuilder text = new StringBuilder(); @@ -167,9 +160,7 @@ public static String printToString(Message message, boolean selfType) { } } - /** - * Like {@code print()}, but writes directly to a {@code String} and returns it. - */ + /** Like {@code print()}, but writes directly to a {@code String} and returns it. */ public static String printToString(Message message) { try { StringBuilder text = new StringBuilder(); @@ -180,9 +171,7 @@ public static String printToString(Message message) { } } - /** - * Like {@code print()}, but writes directly to a {@code String} and returns it. - */ + /** Like {@code print()}, but writes directly to a {@code String} and returns it. */ public static String printToString(UnknownFieldSet fields, boolean selfType) { try { StringBuilder text = new StringBuilder(); @@ -193,31 +182,23 @@ public static String printToString(UnknownFieldSet fields, boolean selfType) { } } - /** - * Parse a text-format message from {@code input} and merge the contents into {@code builder}. - */ + /** Parse a text-format message from {@code input} and merge the contents into {@code builder}. */ public static void merge(Readable input, Message.Builder builder) throws IOException { merge(input, ExtensionRegistry.getEmptyRegistry(), builder, true); } - /** - * Parse a text-format message from {@code input} and merge the contents into {@code builder}. - */ + /** Parse a text-format message from {@code input} and merge the contents into {@code builder}. */ public static void merge(CharSequence input, Message.Builder builder) throws ParseException { merge(input, ExtensionRegistry.getEmptyRegistry(), builder, true); } - /** - * Parse a text-format message from {@code input} and merge the contents into {@code builder}. - */ + /** Parse a text-format message from {@code input} and merge the contents into {@code builder}. */ public static void merge(Readable input, Message.Builder builder, boolean selfType) throws IOException { merge(input, ExtensionRegistry.getEmptyRegistry(), builder, selfType); } - /** - * Parse a text-format message from {@code input} and merge the contents into {@code builder}. - */ + /** Parse a text-format message from {@code input} and merge the contents into {@code builder}. */ public static void merge(CharSequence input, Message.Builder builder, boolean selfType) throws ParseException { merge(input, ExtensionRegistry.getEmptyRegistry(), builder, selfType); @@ -227,9 +208,12 @@ public static void merge(CharSequence input, Message.Builder builder, boolean se * Parse a text-format message from {@code input} and merge the contents into {@code builder}. * Extensions will be recognized if they are registered in {@code extensionRegistry}. */ - public static void merge(Readable input, + public static void merge( + Readable input, ExtensionRegistry extensionRegistry, - Message.Builder builder, boolean selfType) throws IOException { + Message.Builder builder, + boolean selfType) + throws IOException { // Read the entire input to a String then parse that. // If StreamTokenizer were not quite so crippled, or if there were a kind @@ -245,9 +229,12 @@ public static void merge(Readable input, * Parse a text-format message from {@code input} and merge the contents into {@code builder}. * Extensions will be recognized if they are registered in {@code extensionRegistry}. */ - public static void merge(CharSequence input, + public static void merge( + CharSequence input, ExtensionRegistry extensionRegistry, - Message.Builder builder, boolean selfType) throws ParseException { + Message.Builder builder, + boolean selfType) + throws ParseException { Tokenizer tokenizer = new Tokenizer(input); // Based on the state machine @ http://json.org/ @@ -275,20 +262,22 @@ public static String printErrorMsg(Exception ex) { return text.toString(); } - public static void printField(FieldDescriptor field, Object value, JsonGenerator generator, - boolean selfType) + public static void printField( + FieldDescriptor field, Object value, JsonGenerator generator, boolean selfType) throws IOException { printSingleField(field, value, generator, selfType); } - private static void printSingleField(FieldDescriptor field, - Object value, JsonGenerator generator, boolean selfType) throws IOException { + private static void printSingleField( + FieldDescriptor field, Object value, JsonGenerator generator, boolean selfType) + throws IOException { if (field.isExtension()) { generator.print("\""); // We special-case MessageSet elements for compatibility with proto1. if (field.getContainingType().getOptions().getMessageSetWireFormat() - && (field.getType() == FieldDescriptor.Type.MESSAGE) && (field.isOptional()) + && (field.getType() == FieldDescriptor.Type.MESSAGE) + && (field.isOptional()) // object equality && (field.getExtensionScope() == field.getMessageType())) { generator.print(field.getMessageType().getFullName()); @@ -334,8 +323,8 @@ private static void printSingleField(FieldDescriptor field, } } - private static void printFieldValue(FieldDescriptor field, Object value, - JsonGenerator generator, boolean selfType) + private static void printFieldValue( + FieldDescriptor field, Object value, JsonGenerator generator, boolean selfType) throws IOException { switch (field.getType()) { case INT32: @@ -367,14 +356,16 @@ private static void printFieldValue(FieldDescriptor field, Object value, generator.print("\""); break; - case BYTES: { + case BYTES: + { generator.print("\""); generator.print(escapeBytes((ByteString) value, field.getFullName(), selfType)); generator.print("\""); break; } - case ENUM: { + case ENUM: + { generator.print("\""); generator.print(((EnumValueDescriptor) value).getName()); generator.print("\""); @@ -391,8 +382,8 @@ private static void printFieldValue(FieldDescriptor field, Object value, } } - protected static void printUnknownFields(UnknownFieldSet unknownFields, JsonGenerator generator, - boolean selfType) throws IOException { + protected static void printUnknownFields( + UnknownFieldSet unknownFields, JsonGenerator generator, boolean selfType) throws IOException { boolean firstField = true; for (Map.Entry entry : unknownFields.asMap().entrySet()) { final UnknownFieldSet.Field field = entry.getValue(); @@ -439,7 +430,7 @@ protected static void printUnknownFields(UnknownFieldSet unknownFields, JsonGene generator.print(", "); } generator.print("\""); - generator.print(escapeBytes(value, "Hex", selfType)); //Just to HEX + generator.print(escapeBytes(value, "Hex", selfType)); // Just to HEX generator.print("\""); } for (UnknownFieldSet value : field.getGroupList()) { @@ -456,9 +447,7 @@ protected static void printUnknownFields(UnknownFieldSet unknownFields, JsonGene } } - /** - * Convert an unsigned 32-bit integer to a string. - */ + /** Convert an unsigned 32-bit integer to a string. */ private static String unsignedToString(int value) { if (value >= 0) { return Integer.toString(value); @@ -470,9 +459,7 @@ private static String unsignedToString(int value) { // ================================================================= // Parsing - /** - * Convert an unsigned 64-bit integer to a string. - */ + /** Convert an unsigned 64-bit integer to a string. */ private static String unsignedToString(long value) { if (value >= 0) { return Long.toString(value); @@ -483,7 +470,6 @@ private static String unsignedToString(long value) { } } - // TODO(chrisn): See if working around java.io.Reader#read(CharBuffer) // overhead is worthwhile protected static StringBuilder toStringBuilder(Readable input) throws IOException { @@ -504,9 +490,12 @@ protected static StringBuilder toStringBuilder(Readable input) throws IOExceptio * Parse a single field from {@code tokenizer} and merge it into {@code builder}. If a ',' is * detected after the field ends, the next field will be parsed automatically */ - protected static void mergeField(Tokenizer tokenizer, - ExtensionRegistry extensionRegistry, Message.Builder builder, - boolean selfType) throws ParseException { + protected static void mergeField( + Tokenizer tokenizer, + ExtensionRegistry extensionRegistry, + Message.Builder builder, + boolean selfType) + throws ParseException { FieldDescriptor field; Descriptor type = builder.getDescriptorForType(); final ExtensionRegistry.ExtensionInfo extension; @@ -529,7 +518,8 @@ protected static void mergeField(Tokenizer tokenizer, } } // Again, special-case group names as described above. - if ((field != null) && (field.getType() == FieldDescriptor.Type.GROUP) + if ((field != null) + && (field.getType() == FieldDescriptor.Type.GROUP) && !field.getMessageType().getName().equals(name)) { field = null; } @@ -545,9 +535,12 @@ protected static void mergeField(Tokenizer tokenizer, extension = extensionRegistry.findExtensionByName(name); if (extension != null) { if (extension.descriptor.getContainingType() != type) { - throw tokenizer.parseExceptionPreviousToken("Extension \"" + name - + "\" does not extend message type \"" - + type.getFullName() + "\"."); + throw tokenizer.parseExceptionPreviousToken( + "Extension \"" + + name + + "\" does not extend message type \"" + + type.getFullName() + + "\"."); } field = extension.descriptor; } @@ -555,7 +548,7 @@ protected static void mergeField(Tokenizer tokenizer, // Disabled throwing exception if field not found, since it could be a different version. if (field == null) { handleMissingField(tokenizer, extensionRegistry, builder); - //throw tokenizer.parseExceptionPreviousToken("Message type \"" + type.getFullName() + // throw tokenizer.parseExceptionPreviousToken("Message type \"" + type.getFullName() // + "\" has no field named \"" + name // + "\"."); } @@ -580,9 +573,9 @@ protected static void mergeField(Tokenizer tokenizer, } } - private static void handleMissingField(Tokenizer tokenizer, - ExtensionRegistry extensionRegistry, - Message.Builder builder) throws ParseException { + private static void handleMissingField( + Tokenizer tokenizer, ExtensionRegistry extensionRegistry, Message.Builder builder) + throws ParseException { tokenizer.tryConsume(":"); if ("{".equals(tokenizer.currentToken())) { // Message structure @@ -599,7 +592,7 @@ private static void handleMissingField(Tokenizer tokenizer, handleMissingField(tokenizer, extensionRegistry, builder); } while (tokenizer.tryConsume(",")); tokenizer.consume("]"); - } else { //if (!",".equals(tokenizer.currentToken)){ + } else { // if (!",".equals(tokenizer.currentToken)){ // Primitive value if ("null".equals(tokenizer.currentToken())) { tokenizer.consume("null"); @@ -613,17 +606,20 @@ private static void handleMissingField(Tokenizer tokenizer, } } - private static void handleValue(Tokenizer tokenizer, + private static void handleValue( + Tokenizer tokenizer, ExtensionRegistry extensionRegistry, Message.Builder builder, FieldDescriptor field, ExtensionRegistry.ExtensionInfo extension, - boolean unknown, boolean selfType) throws ParseException { + boolean unknown, + boolean selfType) + throws ParseException { Object value = null; if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { - value = handleObject(tokenizer, extensionRegistry, builder, field, extension, unknown, - selfType); + value = + handleObject(tokenizer, extensionRegistry, builder, field, extension, unknown, selfType); } else { value = handlePrimitive(tokenizer, field, selfType); } @@ -636,9 +632,8 @@ private static void handleValue(Tokenizer tokenizer, } } - private static Object handlePrimitive(Tokenizer tokenizer, FieldDescriptor field, - boolean selfType) - throws ParseException { + private static Object handlePrimitive( + Tokenizer tokenizer, FieldDescriptor field, boolean selfType) throws ParseException { Object value = null; if ("null".equals(tokenizer.currentToken())) { tokenizer.consume("null"); @@ -687,17 +682,20 @@ private static Object handlePrimitive(Tokenizer tokenizer, FieldDescriptor field value = tokenizer.consumeByteString(field.getFullName(), selfType); break; - case ENUM: { + case ENUM: + { EnumDescriptor enumType = field.getEnumType(); if (tokenizer.lookingAtInteger()) { int number = tokenizer.consumeInt32(); value = enumType.findValueByNumber(number); if (value == null) { - throw tokenizer.parseExceptionPreviousToken("Enum type \"" - + enumType.getFullName() - + "\" has no value with number " - + number + "."); + throw tokenizer.parseExceptionPreviousToken( + "Enum type \"" + + enumType.getFullName() + + "\" has no value with number " + + number + + "."); } } else { String id = tokenizer.consumeIdentifier(); @@ -709,10 +707,12 @@ private static Object handlePrimitive(Tokenizer tokenizer, FieldDescriptor field } value = enumType.findValueByName(id); if (value == null) { - throw tokenizer.parseExceptionPreviousToken("Enum type \"" - + enumType.getFullName() - + "\" has no value named \"" - + id + "\"."); + throw tokenizer.parseExceptionPreviousToken( + "Enum type \"" + + enumType.getFullName() + + "\" has no value named \"" + + id + + "\"."); } } @@ -727,12 +727,15 @@ private static Object handlePrimitive(Tokenizer tokenizer, FieldDescriptor field return value; } - private static Object handleObject(Tokenizer tokenizer, + private static Object handleObject( + Tokenizer tokenizer, ExtensionRegistry extensionRegistry, Message.Builder builder, FieldDescriptor field, ExtensionRegistry.ExtensionInfo extension, - boolean unknown, boolean selfType) throws ParseException { + boolean unknown, + boolean selfType) + throws ParseException { Message.Builder subBuilder; if (extension == null) { @@ -772,8 +775,7 @@ private static Object handleObject(Tokenizer tokenizer, * Escapes bytes in the format used in protocol buffer text format, which is the same as the * format used for C string literals. All bytes that are not printable 7-bit ASCII characters are * escaped, as well as backslash, single-quote, and double-quote characters. Characters for which - * no defined short-hand escape sequence is defined will be escaped using 3-digit octal - * sequences. + * no defined short-hand escape sequence is defined will be escaped using 3-digit octal sequences. */ static String escapeBytes(ByteString input) { return ByteArray.toHexString(input.toByteArray()); @@ -788,11 +790,11 @@ static String escapeBytes(ByteString input, final String fliedName, boolean self } static String escapeBytesSelfType(ByteString input, final String fliedName) { - //Address + // Address if (HttpSelfFormatFieldName.isAddressFormat(fliedName)) { return WalletClient.encode58Check(input.toByteArray()); } - //Normal String + // Normal String if (HttpSelfFormatFieldName.isNameStringFormat(fliedName)) { String result = new String(input.toByteArray()); result = result.replaceAll("\"", "\\\\\""); @@ -803,7 +805,7 @@ static String escapeBytesSelfType(ByteString input, final String fliedName) { return ByteArray.toHexString(input.toByteArray()); } } - //HEX + // HEX return ByteArray.toHexString(input.toByteArray()); } @@ -833,11 +835,16 @@ static ByteString unescapeBytes(CharSequence input) throws InvalidEscapeSequence // them. /** - * Implements JSON string escaping as specified here. - *

  • The following characters are escaped by prefixing them with a '\' : - * \b,\f,\n,\r,\t,\,"
  • Other control characters in the range 0x0000-0x001F are escaped - * using the \\uXXXX notation
  • UTF-16 surrogate pairs are encoded using the \\uXXXX\\uXXXX - * notation
  • any other character is printed as-is
+ * Implements JSON string escaping as specified here. + * + *
    + *
  • The following characters are escaped by prefixing them with a '\' : \b,\f,\n,\r,\t,\," + *
  • Other control characters in the range 0x0000-0x001F are escaped using the \\uXXXX + * notation + *
  • UTF-16 surrogate pairs are encoded using the \\uXXXX\\uXXXX notation + *
  • any other character is printed as-is + *
*/ static String escapeText(String input) { StringBuilder builder = new StringBuilder(input.length()); @@ -901,9 +908,7 @@ static void appendEscapedUnicode(StringBuilder builder, char ch) { builder.append(prefix).append(Integer.toHexString(ch)); } - /** - * Un-escape a text string as escaped using {@link #escapeText(String)}. - */ + /** Un-escape a text string as escaped using {@link #escapeText(String)}. */ static String unescapeText(String input) throws InvalidEscapeSequence { StringBuilder builder = new StringBuilder(); char[] array = input.toCharArray(); @@ -964,19 +969,14 @@ static String unescapeText(String input) throws InvalidEscapeSequence { return builder.toString(); } - /** - * Is this an octal digit. - */ + /** Is this an octal digit. */ private static boolean isOctal(char c) { return ('0' <= c) && (c <= '7'); } - /** - * Is this a hex digit. - */ + /** Is this a hex digit. */ private static boolean isHex(char c) { - return (('0' <= c) && (c <= '9')) || (('a' <= c) && (c <= 'f')) - || (('A' <= c) && (c <= 'F')); + return (('0' <= c) && (c <= '9')) || (('a' <= c) && (c <= 'f')) || (('A' <= c) && (c <= 'F')); } /** @@ -1068,13 +1068,13 @@ private static long parseInteger(String text, boolean isSigned, boolean isLong) if (!isLong) { if (isSigned) { if ((result > Integer.MAX_VALUE) || (result < Integer.MIN_VALUE)) { - throw new NumberFormatException("Number out of range for 32-bit signed integer: " - + text); + throw new NumberFormatException( + "Number out of range for 32-bit signed integer: " + text); } } else { if ((result >= (1L << 32)) || (result < 0)) { - throw new NumberFormatException("Number out of range for 32-bit unsigned integer: " - + text); + throw new NumberFormatException( + "Number out of range for 32-bit unsigned integer: " + text); } } } @@ -1088,25 +1088,25 @@ private static long parseInteger(String text, boolean isSigned, boolean isLong) if (!isLong) { if (isSigned) { if (bigValue.bitLength() > 31) { - throw new NumberFormatException("Number out of range for 32-bit signed integer: " - + text); + throw new NumberFormatException( + "Number out of range for 32-bit signed integer: " + text); } } else { if (bigValue.bitLength() > 32) { - throw new NumberFormatException("Number out of range for 32-bit unsigned integer: " - + text); + throw new NumberFormatException( + "Number out of range for 32-bit unsigned integer: " + text); } } } else { if (isSigned) { if (bigValue.bitLength() > 63) { - throw new NumberFormatException("Number out of range for 64-bit signed integer: " - + text); + throw new NumberFormatException( + "Number out of range for 64-bit signed integer: " + text); } } else { if (bigValue.bitLength() > 64) { - throw new NumberFormatException("Number out of range for 64-bit unsigned integer: " - + text); + throw new NumberFormatException( + "Number out of range for 64-bit unsigned integer: " + text); } } } @@ -1117,9 +1117,7 @@ private static long parseInteger(String text, boolean isSigned, boolean isLong) return result; } - /** - * An inner class for writing text to the output stream. - */ + /** An inner class for writing text to the output stream. */ protected static class JsonGenerator { private Appendable output; @@ -1139,9 +1137,7 @@ public void indent() { indent.append(" "); } - /** - * Reduces the current indent level by two spaces, or crashes if the indent level is zero. - */ + /** Reduces the current indent level by two spaces, or crashes if the indent level is zero. */ public void outdent() { int length = indent.length(); if (length == 0) { @@ -1150,9 +1146,7 @@ public void outdent() { indent.delete(length - 2, length); } - /** - * Print text to the output stream. - */ + /** Print text to the output stream. */ public void print(CharSequence text) throws IOException { int size = text.length(); int pos = 0; @@ -1181,22 +1175,29 @@ private void write(CharSequence data, int size) throws IOException { /** * Represents a stream of tokens parsed from a {@code String}. - *

+ * + *

* *

The Java standard library provides many classes that you might think would be useful for * implementing this, but aren't. For example: - *

- *

  • {@code java.io.StreamTokenizer}: This almost does what we want -- or, at least, - * something that would get us close to what we want -- except for one fatal flaw: It - * automatically un-escapes strings using Java escape sequences, which do not include all the - * escape sequences we need to support (e.g. '\x').
  • {@code java.util.Scanner}: This seems like - * a great way at least to parse regular expressions out of a stream (so we wouldn't have to load - * the entire input into a single string before parsing). Sadly, {@code Scanner} requires that - * tokens be delimited with some delimiter. Thus, although the text "foo:" should parse to two - * tokens ("foo" and ":"), {@code Scanner} would recognize it only as a single token. Furthermore, - * {@code Scanner} provides no way to inspect the contents of delimiters, making it impossible to - * keep track of line and column numbers.
- *

+ * + *

+ * + *

    + *
  • {@code java.io.StreamTokenizer}: This almost does what we want -- or, at least, something + * that would get us close to what we want -- except for one fatal flaw: It automatically + * un-escapes strings using Java escape sequences, which do not include all the escape + * sequences we need to support (e.g. '\x'). + *
  • {@code java.util.Scanner}: This seems like a great way at least to parse regular + * expressions out of a stream (so we wouldn't have to load the entire input into a single + * string before parsing). Sadly, {@code Scanner} requires that tokens be delimited with + * some delimiter. Thus, although the text "foo:" should parse to two tokens ("foo" and + * ":"), {@code Scanner} would recognize it only as a single token. Furthermore, {@code + * Scanner} provides no way to inspect the contents of delimiters, making it impossible to + * keep track of line and column numbers. + *
+ * + *

* *

Luckily, Java's regular expression support does manage to be useful to us. (Barely: We need * {@code Matcher.usePattern()}, which is new in Java 1.5.) So, we can use that, at least. @@ -1206,23 +1207,22 @@ protected static class Tokenizer { // We use possesive quantifiers (*+ and ++) because otherwise the Java // regex matcher has stack overflows on large inputs. - private static final Pattern WHITESPACE = - Pattern.compile("(\\s|(#.*$))++", Pattern.MULTILINE); - private static final Pattern TOKEN = Pattern.compile( - "[a-zA-Z_][0-9a-zA-Z_+-]*+|" + // an identifier - "[.]?[0-9+-][0-9a-zA-Z_.+-]*+|" + // a number - "\"([^\"\n\\\\]|\\\\.)*+(\"|\\\\?$)|" + // a double-quoted string - "\'([^\'\n\\\\]|\\\\.)*+(\'|\\\\?$)", // a single-quoted string - Pattern.MULTILINE); - private static final Pattern DOUBLE_INFINITY = Pattern.compile( - "-?inf(inity)?", - Pattern.CASE_INSENSITIVE); - private static final Pattern FLOAT_INFINITY = Pattern.compile( - "-?inf(inity)?f?", - Pattern.CASE_INSENSITIVE); - private static final Pattern FLOAT_NAN = Pattern.compile( - "nanf?", - Pattern.CASE_INSENSITIVE); + private static final Pattern WHITESPACE = Pattern.compile("(\\s|(#.*$))++", Pattern.MULTILINE); + private static final Pattern TOKEN = + Pattern.compile( + "[a-zA-Z_][0-9a-zA-Z_+-]*+|" + + // an identifier + "[.]?[0-9+-][0-9a-zA-Z_.+-]*+|" + + // a number + "\"([^\"\n\\\\]|\\\\.)*+(\"|\\\\?$)|" + + // a double-quoted string + "\'([^\'\n\\\\]|\\\\.)*+(\'|\\\\?$)", // a single-quoted string + Pattern.MULTILINE); + private static final Pattern DOUBLE_INFINITY = + Pattern.compile("-?inf(inity)?", Pattern.CASE_INSENSITIVE); + private static final Pattern FLOAT_INFINITY = + Pattern.compile("-?inf(inity)?f?", Pattern.CASE_INSENSITIVE); + private static final Pattern FLOAT_NAN = Pattern.compile("nanf?", Pattern.CASE_INSENSITIVE); private final CharSequence text; private final Matcher matcher; private String currentToken; @@ -1236,9 +1236,7 @@ protected static class Tokenizer { private int previousLine = 0; private int previousColumn = 0; - /** - * Construct a tokenizer that parses tokens from the given text. - */ + /** Construct a tokenizer that parses tokens from the given text. */ public Tokenizer(CharSequence text) { this.text = text; matcher = WHITESPACE.matcher(text); @@ -1257,28 +1255,24 @@ static ByteString unescapeBytes(CharSequence input) throws InvalidEscapeSequence static ByteString unescapeBytesSelfType(String input, final String fliedName) throws InvalidEscapeSequence { - //Address base58 -> ByteString + // Address base58 -> ByteString if (HttpSelfFormatFieldName.isAddressFormat(fliedName)) { return ByteString.copyFrom(WalletClient.decodeFromBase58Check(input)); } - //Normal String -> ByteString + // Normal String -> ByteString if (HttpSelfFormatFieldName.isNameStringFormat(fliedName)) { return ByteString.copyFromUtf8(input); } return unescapeBytes(input); } - /** - * Are we at the end of the input. - */ + /** Are we at the end of the input. */ public boolean atEnd() { return currentToken.length() == 0; } - /** - * Advance to the next token. - */ + /** Advance to the next token. */ public void nextToken() { previousLine = line; previousColumn = column; @@ -1313,9 +1307,7 @@ public void nextToken() { } } - /** - * Skip over any whitespace so that the matcher region starts at the next token. - */ + /** Skip over any whitespace so that the matcher region starts at the next token. */ private void skipWhitespace() { matcher.usePattern(WHITESPACE); if (matcher.lookingAt()) { @@ -1346,9 +1338,7 @@ public void consume(String token) throws ParseException { } } - /** - * Returns {@code true} if the next token is an integer, but does not consume it. - */ + /** Returns {@code true} if the next token is an integer, but does not consume it. */ public boolean lookingAtInteger() { if (currentToken.length() == 0) { return false; @@ -1369,9 +1359,7 @@ public boolean lookingAtBoolean() { return ("true".equals(currentToken) || "false".equals(currentToken)); } - /** - * @return currentToken to which the Tokenizer is pointing. - */ + /** @return currentToken to which the Tokenizer is pointing. */ public String currentToken() { return currentToken; } @@ -1383,8 +1371,12 @@ public String currentToken() { public String consumeIdentifier() throws ParseException { for (int i = 0; i < currentToken.length(); i++) { char c = currentToken.charAt(i); - if ((('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')) - || (('0' <= c) && (c <= '9')) || (c == '_') || (c == '.') || (c == '"')) { + if ((('a' <= c) && (c <= 'z')) + || (('A' <= c) && (c <= 'Z')) + || (('0' <= c) && (c <= '9')) + || (c == '_') + || (c == '.') + || (c == '"')) { // OK } else { throw parseException("Expected identifier. -" + c); @@ -1608,8 +1600,8 @@ public ParseException parseException(String description) { */ public ParseException parseExceptionPreviousToken(String description) { // Note: People generally prefer one-based line and column numbers. - return new ParseException((previousLine + 1) + ":" + (previousColumn + 1) + ": " - + description); + return new ParseException( + (previousLine + 1) + ":" + (previousColumn + 1) + ": " + description); } /** @@ -1629,9 +1621,7 @@ private ParseException floatParseException(NumberFormatException e) { } } - /** - * Thrown when parsing an invalid text format message. - */ + /** Thrown when parsing an invalid text format message. */ public static class ParseException extends IOException { private static final long serialVersionUID = 1L; diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/JsonRpcBase.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/JsonRpcBase.java index e0a4ea20..6aeca85c 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/JsonRpcBase.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/JsonRpcBase.java @@ -1,11 +1,9 @@ package stest.tron.wallet.common.client.utils; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.HashMap; import java.util.List; @@ -95,8 +93,7 @@ public class JsonRpcBase extends TronBaseTest { /** constructor. */ @BeforeSuite(enabled = true, description = "Deploy json rpc test case resource") public void deployJsonRpcUseResource() throws Exception { - maxFeeLimit = - Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit"); + maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit"); logger.info("maxFeeLimit: " + maxFeeLimit); // Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); @@ -116,10 +113,11 @@ public void deployJsonRpcUseResource() throws Exception { PublicMethod.waitProduceNextBlock(blockingStubFull); getCommitData(); openProposal(0, proposalMap); - waitMaxTime = secondProposalMap.get(0L) * 2 + 10000L; //reload max wait time from proposal list - waitProposalApprove(ProposalEnum.getMaxCpuTimeOfOneTx.getProposalName(), 80, blockingStubFull); + waitMaxTime = secondProposalMap.get(0L) * 2 + 10000L; // reload max wait time from proposal list + waitProposalApprove(ProposalEnum.getMaxCpuTimeOfOneTx.getProposalName(), 80, blockingStubFull); openProposal(1, secondProposalMap); - waitProposalApprove(ProposalEnum.getAllowCancelAllUnfreezeV2.getProposalName(), 1,blockingStubFull); + waitProposalApprove( + ProposalEnum.getAllowCancelAllUnfreezeV2.getProposalName(), 1, blockingStubFull); Assert.assertTrue( PublicMethod.sendcoin( jsonRpcOwnerAddress, @@ -171,48 +169,55 @@ public void deployJsonRpcUseResource() throws Exception { deployCreate2Contract(); } - //Protection excessive fluctuations when freeze to get resource - void freezeBeforeAllTest(){ + // Protection excessive fluctuations when freeze to get resource + void freezeBeforeAllTest() { ECKey ecKeyBefore = new ECKey(Utils.getRandom()); byte[] address = ecKeyBefore.getAddress(); String key = ByteArray.toHexString(ecKeyBefore.getPrivKeyBytes()); PublicMethod.printAddress(key); - Assert.assertTrue(PublicMethod.sendcoin(address, 201000000000L, foundationAccountAddress, - foundationAccountKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + address, + 201000000000L, + foundationAccountAddress, + foundationAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(address, 100000000000L, - 0, 0, key, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(address, 100000000000L, - 0, 1, key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy(address, 100000000000L, 0, 0, key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy(address, 100000000000L, 0, 1, key, blockingStubFull)); } void getCommitData() { - List commitList = Configuration.getByPath("testng.conf").getStringList("commitData.commit.list"); + List commitList = + Configuration.getByPath("testng.conf").getStringList("commitData.commit.list"); for (String ent : commitList) { String[] str = ent.split(":"); logger.info(str[0] + " : " + str[1]); proposalMap.put(Long.valueOf(str[0]), Long.valueOf(str[1])); } - List secondCommitList = Configuration.getByPath("testng.conf").getStringList("commitData.secondCommit.list"); + List secondCommitList = + Configuration.getByPath("testng.conf").getStringList("commitData.secondCommit.list"); for (String ent : secondCommitList) { String[] str = ent.split(":"); logger.info(str[0] + " : " + str[1]); secondProposalMap.put(Long.valueOf(str[0]), Long.valueOf(str[1])); } - } /** constructor. */ - public void waitProposalApprove(String proposalName, long proposalValue, - WalletGrpc.WalletBlockingStub blockingStubFull) { + public void waitProposalApprove( + String proposalName, long proposalValue, WalletGrpc.WalletBlockingStub blockingStubFull) { Long currentTime = System.currentTimeMillis(); while (System.currentTimeMillis() <= currentTime + waitMaxTime) { - //max wait time is 300s + 310s - ChainParameters chainParameters = blockingStubFull - .getChainParameters(GrpcAPI.EmptyMessage.newBuilder().build()); + // max wait time is 300s + 310s + ChainParameters chainParameters = + blockingStubFull.getChainParameters(GrpcAPI.EmptyMessage.newBuilder().build()); Optional getChainParameters = Optional.ofNullable(chainParameters); - for (Protocol.ChainParameters.ChainParameter op : getChainParameters.get().getChainParameterList()) { + for (Protocol.ChainParameters.ChainParameter op : + getChainParameters.get().getChainParameterList()) { if (proposalName.equalsIgnoreCase(op.getKey()) && (op.getValue() == proposalValue)) { logger.info(proposalName + ": Proposal has been approval"); return; @@ -223,8 +228,8 @@ public void waitProposalApprove(String proposalName, long proposalValue, } /** constructor. */ - public void openProposal(int openIndex, HashMap proposalMap) { - if(proposalMap.size() == 0) { + public void openProposal(int openIndex, HashMap proposalMap) { + if (proposalMap.size() == 0) { logger.info("proposalMap.size() == 0 , no need to open proposal"); return; } @@ -232,15 +237,20 @@ public void openProposal(int openIndex, HashMap proposalMap) { System.out.println("no need to open proposal"); return; } - if (openIndex == 1 && (ProposalGetAllowOldRewardOptIsOpen() - || ProposalGetMaxDelegateLockPeriodIsOpen())) { + if (openIndex == 1 + && (ProposalGetAllowOldRewardOptIsOpen() || ProposalGetMaxDelegateLockPeriodIsOpen())) { System.out.println("no need to open proposal"); return; } - PublicMethod.sendcoin(witnessAddress,10000000000L,foundationAccountAddress,foundationAccountKey,blockingStubFull); + PublicMethod.sendcoin( + witnessAddress, + 10000000000L, + foundationAccountAddress, + foundationAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.createProposal( - witnessAddress, witnessKey, proposalMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createProposal(witnessAddress, witnessKey, proposalMap, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); GrpcAPI.ProposalList proposalList = blockingStubFull.listProposals(GrpcAPI.EmptyMessage.newBuilder().build()); @@ -263,11 +273,12 @@ public void openProposal(int openIndex, HashMap proposalMap) { /** constructor. */ public boolean ProposalGetAllowMarketTransactionIsOpen() { - Protocol.ChainParameters chainParameters = blockingStubFull - .getChainParameters(GrpcAPI.EmptyMessage.newBuilder().build()); + Protocol.ChainParameters chainParameters = + blockingStubFull.getChainParameters(GrpcAPI.EmptyMessage.newBuilder().build()); Optional getChainParameters = Optional.ofNullable(chainParameters); - for (Protocol.ChainParameters.ChainParameter op : getChainParameters.get().getChainParameterList()) { - if("getAllowMarketTransaction".equalsIgnoreCase(op.getKey()) && (op.getValue() == 1)){ + for (Protocol.ChainParameters.ChainParameter op : + getChainParameters.get().getChainParameterList()) { + if ("getAllowMarketTransaction".equalsIgnoreCase(op.getKey()) && (op.getValue() == 1)) { logger.info("1111111: " + op.toString()); return true; } @@ -276,11 +287,13 @@ public boolean ProposalGetAllowMarketTransactionIsOpen() { } public boolean ProposalGetAllowOldRewardOptIsOpen() { - Protocol.ChainParameters chainParameters = blockingStubFull - .getChainParameters(GrpcAPI.EmptyMessage.newBuilder().build()); + Protocol.ChainParameters chainParameters = + blockingStubFull.getChainParameters(GrpcAPI.EmptyMessage.newBuilder().build()); Optional getChainParameters = Optional.ofNullable(chainParameters); - for (Protocol.ChainParameters.ChainParameter op : getChainParameters.get().getChainParameterList()) { - if("getAllowOldRewardOpt".equalsIgnoreCase(op.getKey()) && (op.getValue() == secondProposalMap.get(79L))){ + for (Protocol.ChainParameters.ChainParameter op : + getChainParameters.get().getChainParameterList()) { + if ("getAllowOldRewardOpt".equalsIgnoreCase(op.getKey()) + && (op.getValue() == secondProposalMap.get(79L))) { logger.info("getAllowOldRewardOpt: " + op); return true; } @@ -289,11 +302,13 @@ public boolean ProposalGetAllowOldRewardOptIsOpen() { } public boolean ProposalGetMaxDelegateLockPeriodIsOpen() { - Protocol.ChainParameters chainParameters = blockingStubFull - .getChainParameters(GrpcAPI.EmptyMessage.newBuilder().build()); + Protocol.ChainParameters chainParameters = + blockingStubFull.getChainParameters(GrpcAPI.EmptyMessage.newBuilder().build()); Optional getChainParameters = Optional.ofNullable(chainParameters); - for (Protocol.ChainParameters.ChainParameter op : getChainParameters.get().getChainParameterList()) { - if("getMaxDelegateLockPeriod".equalsIgnoreCase(op.getKey()) && (op.getValue() == secondProposalMap.get(78L))){ + for (Protocol.ChainParameters.ChainParameter op : + getChainParameters.get().getChainParameterList()) { + if ("getMaxDelegateLockPeriod".equalsIgnoreCase(op.getKey()) + && (op.getValue() == secondProposalMap.get(78L))) { logger.info("getMaxDelegateLockPeriod: " + op); return true; } @@ -414,8 +429,7 @@ public void triggerContract() throws Exception { org.junit.Assert.assertEquals(beforeTokenBalance - afterTokenBalance, -1L); org.junit.Assert.assertTrue(beforeBalance - afterBalance >= 5000); - blockNum = - (PublicMethod.getTransactionInfoById(txid, blockingStubFull).get().getBlockNumber()); + blockNum = (PublicMethod.getTransactionInfoById(txid, blockingStubFull).get().getBlockNumber()); PublicMethod.waitProduceNextBlock(blockingStubFull); response = HttpMethod.getBlockByNum(httpFullNode, blockNum); org.junit.Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); @@ -487,10 +501,7 @@ public void deployTrc20Contract() throws InterruptedException { blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); blockNumForTrc20 = - - (PublicMethod.getTransactionInfoById(trc20Txid, blockingStubFull) - .get() - .getBlockNumber()); + (PublicMethod.getTransactionInfoById(trc20Txid, blockingStubFull).get().getBlockNumber()); } /** constructor. */ @@ -501,12 +512,21 @@ public void deploySelfDestructContract() throws InterruptedException { String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - selfDestructAddressByte = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, jsonRpcOwnerKey, - jsonRpcOwnerAddress, blockingStubFull); + selfDestructAddressByte = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + jsonRpcOwnerKey, + jsonRpcOwnerAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.getContract(selfDestructAddressByte,blockingStubFull).hasAbi()); - + Assert.assertTrue(PublicMethod.getContract(selfDestructAddressByte, blockingStubFull).hasAbi()); } /** constructor. */ @@ -517,25 +537,46 @@ public void deployCreate2Contract() { String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - byte[] cAddressByte = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, jsonRpcOwnerKey, - jsonRpcOwnerAddress, blockingStubFull); + byte[] cAddressByte = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + jsonRpcOwnerKey, + jsonRpcOwnerAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(!PublicMethod.getContract(cAddressByte,blockingStubFull).getBytecode().isEmpty()); + Assert.assertTrue( + !PublicMethod.getContract(cAddressByte, blockingStubFull).getBytecode().isEmpty()); String methedStr = "createWithSalted(bytes32)"; String argsStr = "1232"; - String txid = PublicMethod.triggerContract(cAddressByte, methedStr, argsStr, - false, 0, maxFeeLimit, jsonRpcOwnerAddress, jsonRpcOwnerKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + cAddressByte, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + jsonRpcOwnerAddress, + jsonRpcOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Protocol.TransactionInfo infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("Trigger InfobyId: " + infoById); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, infoById.getResult()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, infoById.getReceipt().getResult()); - create2AddressFrom41 = "41" + ByteArray.toHexString(infoById.getContractResult(0).toByteArray()).substring(24); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, infoById.getReceipt().getResult()); + create2AddressFrom41 = + "41" + ByteArray.toHexString(infoById.getContractResult(0).toByteArray()).substring(24); logger.info("create2AddressFrom41: " + create2AddressFrom41); - } /** constructor. */ @@ -608,9 +649,9 @@ public Boolean stateRootIsOpen() { String resStr = responseContent.toJSONString(); logger.info(resStr); - if(resStr.contains("QUANTITY not supported, just support TAG as latest")){ + if (resStr.contains("QUANTITY not supported, just support TAG as latest")) { return false; - }else { + } else { return true; } } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/LeveldbBase.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/LeveldbBase.java index 95ba70fb..8722da32 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/LeveldbBase.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/LeveldbBase.java @@ -1,17 +1,15 @@ package stest.tron.wallet.common.client.utils; +import static org.fusesource.leveldbjni.JniDBFactory.factory; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.iq80.leveldb.DB; -import org.iq80.leveldb.DBFactory; import org.iq80.leveldb.DBIterator; import org.iq80.leveldb.Options; import org.iq80.leveldb.ReadOptions; -//import org.iq80.leveldb.impl.Iq80DBFactory; -import static org.fusesource.leveldbjni.JniDBFactory.factory; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeSuite; import org.tron.protos.Protocol; @@ -23,19 +21,18 @@ import org.tron.protos.contract.AssetIssueContractOuterClass.AssetIssueContract; import stest.tron.wallet.common.client.Configuration; - public class LeveldbBase { - private static String database = Configuration.getByPath("testng.conf") - .getString("leveldbParams.databasePath"); + private static String database = + Configuration.getByPath("testng.conf").getString("leveldbParams.databasePath"); private static String ACCOUNT_PATH = database + "/account"; - private static String ACCOUNT_ASSET_PATH = database + "/account-asset"; //地址+asseetid : 数量 - private static String ASSET_ISSUE_V2_PATH = database + "/asset-issue-v2"; //trc10资产的信息 + private static String ACCOUNT_ASSET_PATH = database + "/account-asset"; // 地址+asseetid : 数量 + private static String ASSET_ISSUE_V2_PATH = database + "/asset-issue-v2"; // trc10资产的信息 private static String TRANS_INDEX_PATH = database + "/trans"; private static String TRANS_RET_STORE_PATH = database + "/transactionRetStore"; private static String BLOCK_INDEX_PATH = database + "/block-index"; private static String BLOCK_PATH = database + "/block"; private static String RECENT_PATH = database + "/recent-transaction"; -// private static String RECENT_PATH = database + "/trans-cache"; + // private static String RECENT_PATH = database + "/trans-cache"; private DB accountDb; private DB accountAssetDb; private DB assetIssueV2Db; @@ -46,12 +43,10 @@ public class LeveldbBase { private DB recentDb; List dbList = new ArrayList<>(); - /** - * . - */ + /** . */ @BeforeSuite(enabled = true, description = "init db") public void initDb() { -// DBFactory factory = new Iq80DBFactory(); + // DBFactory factory = new Iq80DBFactory(); File accountFile = new File(ACCOUNT_PATH); File accountAssetFile = new File(ACCOUNT_ASSET_PATH); File assetIssueV2File = new File(ASSET_ISSUE_V2_PATH); @@ -83,11 +78,7 @@ public void initDb() { } } - - - /** - * get account from db, address is base58. - */ + /** get account from db, address is base58. */ public Account getAccountFromDb(String address) { try { Account account = Account.parseFrom(accountDb.get(PublicMethod.decode58Check(address))); @@ -98,13 +89,11 @@ public Account getAccountFromDb(String address) { } } - /** - *. - */ + /** . */ public long getAddressBalance(String address) { try { - long balance = Account.parseFrom(accountDb.get(PublicMethod.decode58Check(address))) - .getBalance(); + long balance = + Account.parseFrom(accountDb.get(PublicMethod.decode58Check(address))).getBalance(); return balance; } catch (IOException e) { e.printStackTrace(); @@ -112,14 +101,12 @@ public long getAddressBalance(String address) { } } - /** - * from account-asset. - */ - //@Test + /** from account-asset. */ + // @Test public int getAddressAssetCount(String address, String assetId) { try { - //String address = "TAsimLx1ZWc6epr5FjitmktrDqhJY2AZ5R"; - //String assetId = "1000005"; + // String address = "TAsimLx1ZWc6epr5FjitmktrDqhJY2AZ5R"; + // String assetId = "1000005"; String addressHex = ByteArray.toHexString(PublicMethod.decode58Check(address)); String assetIdHex = ByteArray.toHexString(assetId.getBytes()); String key = addressHex + assetIdHex; @@ -131,14 +118,12 @@ public int getAddressAssetCount(String address, String assetId) { } } - /** - * read from asset-issue-v2. - */ + /** read from asset-issue-v2. */ public AssetIssueContract getAssetIssueById(String assetId) { - //String assetId = "1000005"; + // String assetId = "1000005"; try { - AssetIssueContract assetIssue = AssetIssueContract - .parseFrom(assetIssueV2Db.get(assetId.getBytes())); + AssetIssueContract assetIssue = + AssetIssueContract.parseFrom(assetIssueV2Db.get(assetId.getBytes())); return assetIssue; } catch (Exception e) { e.printStackTrace(); @@ -146,9 +131,7 @@ public AssetIssueContract getAssetIssueById(String assetId) { } } - /** - * constructor. - */ + /** constructor. */ public Transaction getTransactionById(String txid) { try { byte[] transHash = getTransHash(txid); @@ -156,7 +139,7 @@ public Transaction getTransactionById(String txid) { long blockNumber = trans.getBlockNumber(); Block block = getBlockByNumber(blockNumber); List transList = block.getTransactionsList(); - for (Transaction tem: transList) { + for (Transaction tem : transList) { String txID = ByteArray.toHexString(Sha256Sm3Hash.hash(tem.getRawData().toByteArray())); if (txid.equals(txID)) { return tem; @@ -169,9 +152,7 @@ public Transaction getTransactionById(String txid) { } } - /** - * constructor. - */ + /** constructor. */ public byte[] getTransHash(String txid) { try { byte[] hash = transIndexDb.get(ByteArray.fromHexString(txid)); @@ -182,9 +163,7 @@ public byte[] getTransHash(String txid) { return null; } - /** - * constructor. - */ + /** constructor. */ public TransactionInfo getTransactionInfoById(String txid) { try { byte[] transHash = getTransHash(txid); @@ -202,9 +181,7 @@ public TransactionInfo getTransactionInfoById(String txid) { } } - /** - * constructor. - */ + /** constructor. */ public Protocol.Block getBlockByNumber(long number) { try { byte[] blockHash = getBlockHash(number); @@ -216,9 +193,7 @@ public Protocol.Block getBlockByNumber(long number) { } } - /** - * constructor. - */ + /** constructor. */ public byte[] getBlockHash(long number) { try { byte[] hash = blockIndexDb.get(ByteArray.fromLong(number)); @@ -229,9 +204,7 @@ public byte[] getBlockHash(long number) { return null; } - /** - * constructor. - */ + /** constructor. */ public long getTotal() { ReadOptions readOptions = new ReadOptions().fillCache(false); try (DBIterator iterator = blockDb.iterator(readOptions)) { @@ -246,9 +219,7 @@ public long getTotal() { } } - /** - * constructor. - */ + /** constructor. */ public long getRecenTotal() { ReadOptions readOptions = new ReadOptions().fillCache(false); try (DBIterator iterator = recentDb.iterator(readOptions)) { @@ -270,12 +241,10 @@ public Block getNowBlock() { return getBlockByNumber(nowNum); } - /** - * . - */ + /** . */ @AfterSuite public void destroyDb() { - for (DB tem: dbList) { + for (DB tem : dbList) { if (tem != null) { try { tem.close(); @@ -284,8 +253,5 @@ public void destroyDb() { } } } - } - - } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/MongoBase.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/MongoBase.java index d902ede3..23381b51 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/MongoBase.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/MongoBase.java @@ -5,11 +5,8 @@ import com.mongodb.MongoClient; import com.mongodb.MongoCredential; import com.mongodb.ServerAddress; - -import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import java.util.Arrays; - import lombok.extern.slf4j.Slf4j; import org.testng.Assert; import org.testng.annotations.AfterSuite; @@ -19,11 +16,10 @@ /** * Base class for MongoDB event query tests. * - *

Extends {@link TronBaseTest} so all Mongo tests inherit the standard gRPC - * channel management and foundation account configuration. The MongoDB connection - * is established in {@code @BeforeSuite} and cleaned up in {@code @AfterSuite}. - * If MongoDB is unavailable the suite will log a warning and skip gracefully - * rather than failing with a stack trace. + *

Extends {@link TronBaseTest} so all Mongo tests inherit the standard gRPC channel management + * and foundation account configuration. The MongoDB connection is established in + * {@code @BeforeSuite} and cleaned up in {@code @AfterSuite}. If MongoDB is unavailable the suite + * will log a warning and skip gracefully rather than failing with a stack trace. */ @Slf4j public class MongoBase extends TronBaseTest { @@ -55,8 +51,10 @@ public void createMongoDBConnection() throws Exception { mongoDatabase.getCollection("contractlog").drop(); mongoAvailable = true; } catch (Exception e) { - logger.warn("MongoDB is unavailable at {}, mongo tests will be skipped: {}", - mongoNode, e.getMessage()); + logger.warn( + "MongoDB is unavailable at {}, mongo tests will be skipped: {}", + mongoNode, + e.getMessage()); } } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/MultiNode.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/MultiNode.java index 09123d55..e677c806 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/MultiNode.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/MultiNode.java @@ -9,11 +9,12 @@ /** * Marks a test class as requiring a multi-node environment. * - *

Tests annotated with {@code @MultiNode} need at least two java-tron nodes running - * (e.g., separate FullNode + Solidity, or two SR witnesses). When only a single node is - * available, these tests are automatically skipped by {@link MultiNodeListener}. + *

Tests annotated with {@code @MultiNode} need at least two java-tron nodes running (e.g., + * separate FullNode + Solidity, or two SR witnesses). When only a single node is available, these + * tests are automatically skipped by {@link MultiNodeListener}. * *

Usage: + * *

  * {@literal @}MultiNode(reason = "Needs second FullNode for cross-node broadcast verification")
  * public class WalletTestTransfer003 extends TronBaseTest {
@@ -21,10 +22,9 @@
  * }
  * 
* - *

Detection: At suite start, {@link MultiNodeListener} probes - * {@code fullnode.ip.list[1]} from testng.conf. If it is the same as index [0] or - * unreachable, the environment is classified as single-node and all {@code @MultiNode} - * classes are skipped with a clear message. + *

Detection: At suite start, {@link MultiNodeListener} probes {@code fullnode.ip.list[1]} from + * testng.conf. If it is the same as index [0] or unreachable, the environment is classified as + * single-node and all {@code @MultiNode} classes are skipped with a clear message. * * @see MultiNodeListener */ @@ -34,8 +34,8 @@ public @interface MultiNode { /** - * Why this test needs multiple nodes. - * Examples: "cross-node sync", "solidity query", "PBFT finality". + * Why this test needs multiple nodes. Examples: "cross-node sync", "solidity query", "PBFT + * finality". */ String reason() default ""; } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/MultiNodeListener.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/MultiNodeListener.java index b7a09b77..1c4b2087 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/MultiNodeListener.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/MultiNodeListener.java @@ -15,18 +15,20 @@ import stest.tron.wallet.common.client.Configuration; /** - * TestNG listener that detects single-node vs multi-node environments - * and auto-skips {@link MultiNode @MultiNode} tests when only one node is available. + * TestNG listener that detects single-node vs multi-node environments and auto-skips {@link + * MultiNode @MultiNode} tests when only one node is available. * *

Detection logic (runs once at suite start): + * *

    - *
  1. Read {@code fullnode.ip.list} from testng.conf
  2. - *
  3. If index [0] and [1] have the same host:port → single-node
  4. - *
  5. If index [1] is different but unreachable (TCP probe fails) → single-node
  6. - *
  7. Otherwise → multi-node
  8. + *
  9. Read {@code fullnode.ip.list} from testng.conf + *
  10. If index [0] and [1] have the same host:port → single-node + *
  11. If index [1] is different but unreachable (TCP probe fails) → single-node + *
  12. Otherwise → multi-node *
* *

Register in TestNG XML: + * *

{@code
  * 
  *   
@@ -34,6 +36,7 @@
  * }
* *

Or run with system property to force a mode: + * *

  *   -Dtron.test.multinode=true   (force multi-node, fail instead of skip)
  *   -Dtron.test.multinode=false  (force single-node, skip @MultiNode tests)
@@ -55,8 +58,7 @@ public void onStart(ISuite suite) {
     multiNodeAvailable = detectMultiNode();
     String mode = multiNodeAvailable ? "MULTI-NODE" : "SINGLE-NODE";
     logger.info("=== Environment: {} ===", mode);
-    logger.info("@MultiNode tests will be: {}",
-        multiNodeAvailable ? "EXECUTED" : "SKIPPED");
+    logger.info("@MultiNode tests will be: {}", multiNodeAvailable ? "EXECUTED" : "SKIPPED");
   }
 
   @Override
@@ -73,11 +75,10 @@ public void onBeforeClass(ITestClass testClass) {
     Class realClass = testClass.getRealClass();
     if (realClass.isAnnotationPresent(MultiNode.class)) {
       MultiNode annotation = realClass.getAnnotation(MultiNode.class);
-      String reason = annotation.reason().isEmpty()
-          ? "requires multi-node environment"
-          : annotation.reason();
-      String msg = String.format(
-          "SKIP %s — %s (single-node detected)", realClass.getSimpleName(), reason);
+      String reason =
+          annotation.reason().isEmpty() ? "requires multi-node environment" : annotation.reason();
+      String msg =
+          String.format("SKIP %s — %s (single-node detected)", realClass.getSimpleName(), reason);
       logger.info(msg);
       throw new SkipException(msg);
     }
@@ -89,8 +90,8 @@ public void onAfterClass(ITestClass testClass) {
   }
 
   /**
-   * Returns true if a multi-node environment is available.
-   * Can be called from test code for conditional logic.
+   * Returns true if a multi-node environment is available. Can be called from test code for
+   * conditional logic.
    */
   public static boolean isMultiNodeAvailable() {
     if (multiNodeAvailable == null) {
@@ -142,9 +143,7 @@ private static boolean detectMultiNode() {
     }
   }
 
-  /**
-   * TCP connect probe to check if a host:port is reachable.
-   */
+  /** TCP connect probe to check if a host:port is reachable. */
   private static boolean probeEndpoint(String hostPort) {
     String[] parts = hostPort.split(":");
     if (parts.length != 2) {
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/PedersenHashCapsule.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/PedersenHashCapsule.java
index 74b3eeec..e584aaff 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/PedersenHashCapsule.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/PedersenHashCapsule.java
@@ -8,7 +8,6 @@
 import org.tron.protos.contract.ShieldContract.PedersenHash;
 import stest.tron.wallet.common.client.utils.exception.ZksnarkException;
 
-
 @Slf4j
 public class PedersenHashCapsule implements ProtoCapsule {
 
@@ -34,9 +33,9 @@ public static PedersenHashCapsule combine(final PedersenHash a, final PedersenHa
       throws ZksnarkException {
     byte[] res = new byte[32];
 
-
-    JLibrustzcash.librustzcashMerkleHash(new LibrustzcashParam.MerkleHashParams(depth, a.getContent().toByteArray(),
-        b.getContent().toByteArray(), res));
+    JLibrustzcash.librustzcashMerkleHash(
+        new LibrustzcashParam.MerkleHashParams(
+            depth, a.getContent().toByteArray(), b.getContent().toByteArray(), res));
 
     PedersenHashCapsule pedersenHashCapsule = new PedersenHashCapsule();
     pedersenHashCapsule.setContent(ByteString.copyFrom(res));
@@ -57,13 +56,13 @@ public static PedersenHashCapsule uncommitted() throws ZksnarkException {
 
   public static void main(String[] args) {
     try {
-      //all keys are for test
+      // all keys are for test
       byte[] a =
-          ByteArray
-              .fromHexString("05655316a07e6ec8c9769af54ef98b30667bfb6302b32987d552227dae86a087");
+          ByteArray.fromHexString(
+              "05655316a07e6ec8c9769af54ef98b30667bfb6302b32987d552227dae86a087");
       byte[] b =
-          ByteArray
-              .fromHexString("06041357de59ba64959d1b60f93de24dfe5ea1e26ed9e8a73d35b225a1845ba7");
+          ByteArray.fromHexString(
+              "06041357de59ba64959d1b60f93de24dfe5ea1e26ed9e8a73d35b225a1845ba7");
 
       PedersenHash sa = PedersenHash.newBuilder().setContent(ByteString.copyFrom(a)).build();
       PedersenHash sb = PedersenHash.newBuilder().setContent(ByteString.copyFrom(b)).build();
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ProposalEnum.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ProposalEnum.java
index 6b0c05cc..4fc236f6 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ProposalEnum.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ProposalEnum.java
@@ -1,7 +1,6 @@
 package stest.tron.wallet.common.client.utils;
 
 public enum ProposalEnum {
-
   GetAllowTvmSelfdestructRestriction("getAllowTvmSelfdestructRestriction"),
   GetAllowNewResourceModel("getAllowNewResourceModel"),
   GetUnfreezeDelayDays("getUnfreezeDelayDays"),
@@ -28,5 +27,4 @@ public enum ProposalEnum {
   public String getProposalName() {
     return proposalName;
   }
-
 }
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/PublicMethod.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/PublicMethod.java
index aeffdabb..3db4efbe 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/PublicMethod.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/PublicMethod.java
@@ -2,66 +2,45 @@
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.google.common.primitives.Longs;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import com.google.protobuf.Any;
 import com.google.protobuf.ByteString;
 import io.grpc.ManagedChannel;
 import io.grpc.ManagedChannelBuilder;
-import io.netty.util.internal.StringUtil;
-
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
 import java.math.BigInteger;
 import java.nio.charset.StandardCharsets;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.http.HttpResponse;
 import org.bouncycastle.util.encoders.Hex;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.Assert;
 import org.tron.api.GrpcAPI;
 import org.tron.api.GrpcAPI.AccountNetMessage;
 import org.tron.api.GrpcAPI.AccountResourceMessage;
 import org.tron.api.GrpcAPI.AssetIssueList;
 import org.tron.api.GrpcAPI.BlockExtention;
 import org.tron.api.GrpcAPI.BytesMessage;
-import org.tron.api.GrpcAPI.CanDelegatedMaxSizeRequestMessage;
 import org.tron.api.GrpcAPI.CanDelegatedMaxSizeResponseMessage;
-import org.tron.api.GrpcAPI.CanWithdrawUnfreezeAmountRequestMessage;
 import org.tron.api.GrpcAPI.CanWithdrawUnfreezeAmountResponseMessage;
 import org.tron.api.GrpcAPI.DecryptNotes;
 import org.tron.api.GrpcAPI.DecryptNotes.NoteTx;
 import org.tron.api.GrpcAPI.DecryptNotesMarked;
 import org.tron.api.GrpcAPI.DelegatedResourceList;
-import org.tron.api.GrpcAPI.DelegatedResourceMessage;
-import org.tron.api.GrpcAPI.EmptyMessage;
 import org.tron.api.GrpcAPI.ExchangeList;
-import org.tron.api.GrpcAPI.GetAvailableUnfreezeCountRequestMessage;
 import org.tron.api.GrpcAPI.GetAvailableUnfreezeCountResponseMessage;
-import org.tron.api.GrpcAPI.IvkDecryptAndMarkParameters;
-import org.tron.api.GrpcAPI.IvkDecryptParameters;
-import org.tron.api.GrpcAPI.NfParameters;
 import org.tron.api.GrpcAPI.Note;
-import org.tron.api.GrpcAPI.NoteParameters;
-import org.tron.api.GrpcAPI.NumberMessage;
-import org.tron.api.GrpcAPI.OvkDecryptParameters;
-import org.tron.api.GrpcAPI.PrivateParameters;
-import org.tron.api.GrpcAPI.PrivateParametersWithoutAsk;
-import org.tron.api.GrpcAPI.ReceiveNote;
 import org.tron.api.GrpcAPI.Return;
-import org.tron.api.GrpcAPI.Return.response_code;
-import org.tron.api.GrpcAPI.SpendAuthSigParameters;
-import org.tron.api.GrpcAPI.SpendNote;
 import org.tron.api.GrpcAPI.SpendResult;
 import org.tron.api.GrpcAPI.TransactionApprovedList;
 import org.tron.api.GrpcAPI.TransactionExtention;
@@ -71,91 +50,39 @@
 import org.tron.api.WalletSolidityGrpc;
 import org.tron.protos.Protocol;
 import org.tron.protos.Protocol.Account;
-
-import org.tron.protos.Protocol.Account.FreezeV2;
-import org.tron.protos.Protocol.Account.Frozen;
-import org.tron.protos.Protocol.Block;
-import org.tron.protos.Protocol.ChainParameters;
 import org.tron.protos.Protocol.DelegatedResourceAccountIndex;
 import org.tron.protos.Protocol.Exchange;
 import org.tron.protos.Protocol.Key;
 import org.tron.protos.Protocol.Permission;
 import org.tron.protos.Protocol.Transaction;
-import org.tron.protos.Protocol.Transaction.Contract.ContractType;
-import org.tron.protos.Protocol.Transaction.Result;
 import org.tron.protos.Protocol.TransactionInfo;
-import org.tron.protos.contract.AccountContract.AccountCreateContract;
-import org.tron.protos.contract.AccountContract.AccountPermissionUpdateContract;
-import org.tron.protos.contract.AccountContract.AccountUpdateContract;
-import org.tron.protos.contract.AccountContract.SetAccountIdContract;
 import org.tron.protos.contract.AssetIssueContractOuterClass.AssetIssueContract;
-import org.tron.protos.contract.AssetIssueContractOuterClass.ParticipateAssetIssueContract;
-import org.tron.protos.contract.AssetIssueContractOuterClass.TransferAssetContract;
-import org.tron.protos.contract.AssetIssueContractOuterClass.UpdateAssetContract;
 import org.tron.protos.contract.BalanceContract;
-import org.tron.protos.contract.BalanceContract.DelegateResourceContract;
-import org.tron.protos.contract.BalanceContract.FreezeBalanceContract;
-import org.tron.protos.contract.BalanceContract.FreezeBalanceV2Contract;
-import org.tron.protos.contract.BalanceContract.TransferContract;
-import org.tron.protos.contract.BalanceContract.UnDelegateResourceContract;
-import org.tron.protos.contract.BalanceContract.UnfreezeBalanceContract;
-import org.tron.protos.contract.BalanceContract.UnfreezeBalanceV2Contract;
-import org.tron.protos.contract.BalanceContract.WithdrawExpireUnfreezeContract;
-import org.tron.protos.contract.BalanceContract.CancelAllUnfreezeV2Contract;
-import org.tron.protos.contract.ExchangeContract.ExchangeCreateContract;
-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;
-import org.tron.protos.contract.ShieldContract.IncrementalMerkleVoucherInfo;
-import org.tron.protos.contract.ShieldContract.OutputPoint;
-import org.tron.protos.contract.ShieldContract.OutputPointInfo;
-import org.tron.protos.contract.ShieldContract.ShieldedTransferContract;
-import org.tron.protos.contract.ShieldContract.SpendDescription;
-import org.tron.protos.contract.SmartContractOuterClass.ClearABIContract;
-import org.tron.protos.contract.SmartContractOuterClass.CreateSmartContract;
-import org.tron.protos.contract.SmartContractOuterClass.CreateSmartContract.Builder;
 import org.tron.protos.contract.SmartContractOuterClass.SmartContract;
-import org.tron.protos.contract.SmartContractOuterClass.SmartContract.ABI;
 import org.tron.protos.contract.SmartContractOuterClass.SmartContractDataWrapper;
-import org.tron.protos.contract.SmartContractOuterClass.TriggerSmartContract;
-import org.tron.protos.contract.SmartContractOuterClass.UpdateEnergyLimitContract;
-import org.tron.protos.contract.SmartContractOuterClass.UpdateSettingContract;
-import org.tron.protos.contract.StorageContract.BuyStorageContract;
-import org.tron.protos.contract.StorageContract.SellStorageContract;
 import org.tron.protos.contract.StorageContract.UpdateBrokerageContract;
-import org.tron.protos.contract.WitnessContract.VoteWitnessContract;
 import stest.tron.wallet.common.client.Configuration;
 import stest.tron.wallet.common.client.WalletClient;
-import stest.tron.wallet.common.client.utils.BlockCapsule.BlockId;
-import stest.tron.wallet.common.client.utils.zen.address.DiversifierT;
-import stest.tron.wallet.common.client.utils.zen.address.ExpandedSpendingKey;
-import stest.tron.wallet.common.client.utils.zen.address.FullViewingKey;
-import stest.tron.wallet.common.client.utils.zen.address.IncomingViewingKey;
-import stest.tron.wallet.common.client.utils.zen.address.PaymentAddress;
-import stest.tron.wallet.common.client.utils.zen.address.SpendingKey;
 
 /**
  * Legacy facade class — delegates to specialized Helper classes.
  *
  * 

For new test code, use the Helper classes directly: + * *

    - *
  • {@link AccountHelper} — account queries, creation, permissions, sendcoin
  • - *
  • {@link ContractHelper} — contract deploy, trigger, ABI operations
  • - *
  • {@link ResourceHelper} — freeze, delegate, energy/bandwidth
  • - *
  • {@link AssetHelper} — TRC-10/TRC-20 token operations
  • - *
  • {@link GovernanceHelper} — proposals, voting, witness management
  • - *
  • {@link TransactionHelper} — transaction signing, broadcasting
  • - *
  • {@link BlockHelper} — block queries
  • - *
  • {@link ShieldHelper} — privacy/shielded operations
  • - *
  • {@link CommonHelper} — address/key utilities
  • + *
  • {@link AccountHelper} — account queries, creation, permissions, sendcoin + *
  • {@link ContractHelper} — contract deploy, trigger, ABI operations + *
  • {@link ResourceHelper} — freeze, delegate, energy/bandwidth + *
  • {@link AssetHelper} — TRC-10/TRC-20 token operations + *
  • {@link GovernanceHelper} — proposals, voting, witness management + *
  • {@link TransactionHelper} — transaction signing, broadcasting + *
  • {@link BlockHelper} — block queries + *
  • {@link ShieldHelper} — privacy/shielded operations + *
  • {@link CommonHelper} — address/key utilities *
* - *

This class is kept for backward compatibility with existing 600+ test classes. - * All delegating methods will be gradually marked {@code @Deprecated}. + *

This class is kept for backward compatibility with existing 600+ test classes. All delegating + * methods will be gradually marked {@code @Deprecated}. */ @Slf4j public class PublicMethod { @@ -164,7 +91,7 @@ public class PublicMethod { // //Wallet.setAddressPreFixByte()(); private static final String FilePath = "Wallet"; -// private static final Logger logger = LoggerFactory.getLogger("TestLogger"); + // private static final Logger logger = LoggerFactory.getLogger("TestLogger"); // private WalletGrpc.WalletBlockingStub blockingStubFull = null; // private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; public static Map utxoMapNote = new ConcurrentHashMap(); @@ -180,21 +107,20 @@ public class PublicMethod { public static AtomicInteger randomFreezeAmount = new AtomicInteger(1); - private static final String fullnode2 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private static ManagedChannel channelFull2 = ManagedChannelBuilder.forTarget(fullnode2).usePlaintext().build(); - private static WalletGrpc.WalletBlockingStub blockingStubFull2 = WalletGrpc.newBlockingStub(channelFull2); + private static final String fullnode2 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private static ManagedChannel channelFull2 = + ManagedChannelBuilder.forTarget(fullnode2).usePlaintext().build(); + private static WalletGrpc.WalletBlockingStub blockingStubFull2 = + WalletGrpc.newBlockingStub(channelFull2); private static final String gRPCurl = Configuration.getByPath("testng.conf").getString("defaultParameter.gRPCurl"); - - - /** constructor. */ public static Integer getWitnessNum(WalletGrpc.WalletBlockingStub blockingStubFull) { - //if (null == witnessNum) { - //witnessNum = PublicMethod.listWitnesses(blockingStubFull).get().getWitnessesList().size(); - //} + // if (null == witnessNum) { + // witnessNum = PublicMethod.listWitnesses(blockingStubFull).get().getWitnessesList().size(); + // } witnessNum = PublicMethod.listWitnesses(blockingStubFull).get().getWitnessesList().size(); return witnessNum; } @@ -218,9 +144,24 @@ public static String createAssetIssueGetTxid( Long frozenDay, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return AssetHelper.createAssetIssueGetTxid(address, name, abbreviation, totalSupply, trxNum, - icoNum, startTime, endTime, voteScore, description, url, freeAssetNetLimit, - publicFreeAssetNetLimit, fronzenAmount, frozenDay, priKey, blockingStubFull); + return AssetHelper.createAssetIssueGetTxid( + address, + name, + abbreviation, + totalSupply, + trxNum, + icoNum, + startTime, + endTime, + voteScore, + description, + url, + freeAssetNetLimit, + publicFreeAssetNetLimit, + fronzenAmount, + frozenDay, + priKey, + blockingStubFull); } /** constructor. */ @@ -241,9 +182,23 @@ public static Boolean createAssetIssue( Long frozenDay, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return AssetHelper.createAssetIssue(address, name, totalSupply, trxNum, icoNum, startTime, - endTime, voteScore, description, url, freeAssetNetLimit, publicFreeAssetNetLimit, - fronzenAmount, frozenDay, priKey, blockingStubFull); + return AssetHelper.createAssetIssue( + address, + name, + totalSupply, + trxNum, + icoNum, + startTime, + endTime, + voteScore, + description, + url, + freeAssetNetLimit, + publicFreeAssetNetLimit, + fronzenAmount, + frozenDay, + priKey, + blockingStubFull); } /** constructor. */ @@ -265,9 +220,24 @@ public static Boolean createAssetIssue( Long frozenDay, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return AssetHelper.createAssetIssue(address, name, abbreviation, totalSupply, trxNum, - icoNum, startTime, endTime, voteScore, description, url, freeAssetNetLimit, - publicFreeAssetNetLimit, fronzenAmount, frozenDay, priKey, blockingStubFull); + return AssetHelper.createAssetIssue( + address, + name, + abbreviation, + totalSupply, + trxNum, + icoNum, + startTime, + endTime, + voteScore, + description, + url, + freeAssetNetLimit, + publicFreeAssetNetLimit, + fronzenAmount, + frozenDay, + priKey, + blockingStubFull); } /** constructor. */ @@ -289,9 +259,24 @@ public static Boolean createAssetIssue( Long frozenDay, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return AssetHelper.createAssetIssue(address, name, totalSupply, trxNum, icoNum, precision, - startTime, endTime, voteScore, description, url, freeAssetNetLimit, - publicFreeAssetNetLimit, fronzenAmount, frozenDay, priKey, blockingStubFull); + return AssetHelper.createAssetIssue( + address, + name, + totalSupply, + trxNum, + icoNum, + precision, + startTime, + endTime, + voteScore, + description, + url, + freeAssetNetLimit, + publicFreeAssetNetLimit, + fronzenAmount, + frozenDay, + priKey, + blockingStubFull); } /** constructor. */ @@ -312,9 +297,23 @@ public static Return createAssetIssue2( Long frozenDay, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return AssetHelper.createAssetIssue2(address, name, totalSupply, trxNum, icoNum, startTime, - endTime, voteScore, description, url, freeAssetNetLimit, publicFreeAssetNetLimit, - fronzenAmount, frozenDay, priKey, blockingStubFull); + return AssetHelper.createAssetIssue2( + address, + name, + totalSupply, + trxNum, + icoNum, + startTime, + endTime, + voteScore, + description, + url, + freeAssetNetLimit, + publicFreeAssetNetLimit, + fronzenAmount, + frozenDay, + priKey, + blockingStubFull); } /** constructor. */ @@ -415,7 +414,8 @@ public static boolean participateAssetIssue( byte[] from, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return AssetHelper.participateAssetIssue(to, assertName, amount, from, priKey, blockingStubFull); + return AssetHelper.participateAssetIssue( + to, assertName, amount, from, priKey, blockingStubFull); } /** constructor. */ @@ -427,7 +427,8 @@ public static Return participateAssetIssue2( byte[] from, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return AssetHelper.participateAssetIssue2(to, assertName, amount, from, priKey, blockingStubFull); + return AssetHelper.participateAssetIssue2( + to, assertName, amount, from, priKey, blockingStubFull); } /** constructor. */ @@ -438,21 +439,29 @@ public static Boolean freezeBalance( long freezeDuration, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.freezeBalance(addRess, freezeBalance, freezeDuration, priKey, blockingStubFull); + return ResourceHelper.freezeBalance( + addRess, freezeBalance, freezeDuration, priKey, blockingStubFull); } @Deprecated - public static Boolean freezeBalanceV1ForReceiver(byte[] addRess, + public static Boolean freezeBalanceV1ForReceiver( + byte[] addRess, long freezeBalance, long freezeDuration, int resourceCode, byte[] receiverAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.freezeBalanceV1ForReceiver(addRess, freezeBalance, freezeDuration, resourceCode, receiverAddress, priKey, blockingStubFull); + return ResourceHelper.freezeBalanceV1ForReceiver( + addRess, + freezeBalance, + freezeDuration, + resourceCode, + receiverAddress, + priKey, + blockingStubFull); } - @Deprecated public static Boolean freezeBalanceV1( byte[] addRess, @@ -461,7 +470,8 @@ public static Boolean freezeBalanceV1( int resourceCode, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.freezeBalanceV1(addRess, freezeBalance, freezeDuration, resourceCode, priKey, blockingStubFull); + return ResourceHelper.freezeBalanceV1( + addRess, freezeBalance, freezeDuration, resourceCode, priKey, blockingStubFull); } /** constructor. */ @@ -472,7 +482,8 @@ public static Return freezeBalance2( long freezeDuration, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.freezeBalance2(addRess, freezeBalance, freezeDuration, priKey, blockingStubFull); + return ResourceHelper.freezeBalance2( + addRess, freezeBalance, freezeDuration, priKey, blockingStubFull); } /** constructor. */ @@ -483,10 +494,10 @@ public static Boolean unFreezeBalance( int resourceCode, byte[] receiverAddress, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.unFreezeBalance(address, priKey, resourceCode, receiverAddress, blockingStubFull); + return ResourceHelper.unFreezeBalance( + address, priKey, resourceCode, receiverAddress, blockingStubFull); } - /** constructor. */ @Deprecated public static Boolean unFreezeBalanceV1( @@ -495,10 +506,10 @@ public static Boolean unFreezeBalanceV1( int resourceCode, byte[] receiverAddress, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.unFreezeBalanceV1(address, priKey, resourceCode, receiverAddress, blockingStubFull); + return ResourceHelper.unFreezeBalanceV1( + address, priKey, resourceCode, receiverAddress, blockingStubFull); } - /** constructor. */ @Deprecated public static Boolean unFreezeBalanceV2( @@ -507,72 +518,64 @@ public static Boolean unFreezeBalanceV2( long unFreezeBalanceAmount, int resourceCode, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.unFreezeBalanceV2(address, priKey, unFreezeBalanceAmount, resourceCode, blockingStubFull); + return ResourceHelper.unFreezeBalanceV2( + address, priKey, unFreezeBalanceAmount, resourceCode, blockingStubFull); } + @Deprecated public static String unFreezeBalanceV2AndGetTxId( - byte[] address, - String priKey, - long unFreezeBalanceAmount, - int resourceCode, - WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.unFreezeBalanceV2AndGetTxId(address, priKey, unFreezeBalanceAmount, resourceCode, blockingStubFull); + byte[] address, + String priKey, + long unFreezeBalanceAmount, + int resourceCode, + WalletGrpc.WalletBlockingStub blockingStubFull) { + return ResourceHelper.unFreezeBalanceV2AndGetTxId( + address, priKey, unFreezeBalanceAmount, resourceCode, blockingStubFull); } /** constructor. */ @Deprecated public static Boolean cancelAllUnFreezeBalanceV2( - byte[] address, - String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull) { + byte[] address, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { return ResourceHelper.cancelAllUnFreezeBalanceV2(address, priKey, blockingStubFull); } + /** constructor. */ @Deprecated public static String cancelAllUnFreezeBalanceV2AndGetTxid( - byte[] address, - String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull) { + byte[] address, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { return ResourceHelper.cancelAllUnFreezeBalanceV2AndGetTxid(address, priKey, blockingStubFull); } - /** constructor. */ @Deprecated public static Boolean withdrawExpireUnfreeze( - byte[] address, - String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull) { + byte[] address, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { return ResourceHelper.withdrawExpireUnfreeze(address, priKey, blockingStubFull); } @Deprecated public static String withdrawExpireUnfreezeAndGetTxId( - byte[] address, - String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull) { + byte[] address, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { return ResourceHelper.withdrawExpireUnfreezeAndGetTxId(address, priKey, blockingStubFull); } - @Deprecated public static Boolean freezeV2ProposalIsOpen(WalletGrpc.WalletBlockingStub blockingStubFull) { return ResourceHelper.freezeV2ProposalIsOpen(blockingStubFull); } - @Deprecated public static Boolean tronPowerProposalIsOpen(WalletGrpc.WalletBlockingStub blockingStubFull) { return ResourceHelper.tronPowerProposalIsOpen(blockingStubFull); } @Deprecated - public static Boolean getAllowDynamicEnergyProposalIsOpen(WalletGrpc.WalletBlockingStub blockingStubFull) { + public static Boolean getAllowDynamicEnergyProposalIsOpen( + WalletGrpc.WalletBlockingStub blockingStubFull) { return ResourceHelper.getAllowDynamicEnergyProposalIsOpen(blockingStubFull); } - - @Deprecated public static Long getProposalMemoFee(WalletGrpc.WalletBlockingStub blockingStubFull) { return ResourceHelper.getProposalMemoFee(blockingStubFull); @@ -589,23 +592,22 @@ public static String getEnergyPrice(WalletGrpc.WalletBlockingStub blockingStubFu } @Deprecated - public static String getEnergyPriceSolidity(WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { + public static String getEnergyPriceSolidity( + WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { return ResourceHelper.getEnergyPriceSolidity(blockingStubFull); } - @Deprecated public static String getBandwidthPrices(WalletGrpc.WalletBlockingStub blockingStubFull) { return ResourceHelper.getBandwidthPrices(blockingStubFull); } @Deprecated - public static String getBandwidthPricesSolidity(WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { + public static String getBandwidthPricesSolidity( + WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { return ResourceHelper.getBandwidthPricesSolidity(blockingStubFull); } - - /** constructor. */ @Deprecated public static Boolean sendcoin( @@ -626,7 +628,8 @@ public static Boolean sendcoinWithScript( String priKey, int scriptLength, WalletGrpc.WalletBlockingStub blockingStubFull) { - return AccountHelper.sendcoinWithScript(to, amount, owner, priKey, scriptLength, blockingStubFull); + return AccountHelper.sendcoinWithScript( + to, amount, owner, priKey, scriptLength, blockingStubFull); } /** constructor. */ @@ -708,7 +711,8 @@ public static String sendcoinDelayedGetTxid( byte[] owner, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return AccountHelper.sendcoinDelayedGetTxid(to, amount, delaySeconds, owner, priKey, blockingStubFull); + return AccountHelper.sendcoinDelayedGetTxid( + to, amount, delaySeconds, owner, priKey, blockingStubFull); } /** constructor. */ @@ -742,7 +746,8 @@ public static String sendcoinWithMemoGetTransactionId( byte[] owner, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return AccountHelper.sendcoinWithMemoGetTransactionId(to, amount, memo, owner, priKey, blockingStubFull); + return AccountHelper.sendcoinWithMemoGetTransactionId( + to, amount, memo, owner, priKey, blockingStubFull); } /** constructor. */ @@ -753,7 +758,8 @@ public static String sendcoinGetTransactionIdForConstructData( byte[] owner, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return AccountHelper.sendcoinGetTransactionIdForConstructData(to, amount, owner, priKey, blockingStubFull); + return AccountHelper.sendcoinGetTransactionIdForConstructData( + to, amount, owner, priKey, blockingStubFull); } /** constructor. */ @@ -777,7 +783,6 @@ public static Long getAssetBalanceByAssetId( return AssetHelper.getAssetBalanceByAssetId(assetId, priKey, blockingStubFull); } - @Deprecated public static Long getAssetBalanceByAssetId( ByteString assetId, byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { @@ -826,7 +831,8 @@ public static boolean updateAsset( long newPublicLimit, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return AssetHelper.updateAsset(address, description, url, newLimit, newPublicLimit, priKey, blockingStubFull); + return AssetHelper.updateAsset( + address, description, url, newLimit, newPublicLimit, priKey, blockingStubFull); } /** constructor. */ @@ -839,7 +845,8 @@ public static Return updateAsset2( long newPublicLimit, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return AssetHelper.updateAsset2(address, description, url, newLimit, newPublicLimit, priKey, blockingStubFull); + return AssetHelper.updateAsset2( + address, description, url, newLimit, newPublicLimit, priKey, blockingStubFull); } /** constructor. */ @@ -878,17 +885,15 @@ public static boolean waitProduceNextBlock(WalletGrpc.WalletBlockingStub blockin return BlockHelper.waitProduceNextBlock(blockingStubFull); } - - /** - * if tx is found, return it - * if query timeout,assert failed then return false - * @param blockingStubFull - * @param txId - * @param timeout second - * @return + * if tx is found, return it if query timeout,assert failed then return false + * + * @param blockingStubFull the gRPC blocking stub + * @param txId transaction id to query + * @param timeout timeout in seconds */ - public static void waitUntilTransactionInfoFound(WalletGrpc.WalletBlockingStub blockingStubFull, String txId, int timeout) { + public static void waitUntilTransactionInfoFound( + WalletGrpc.WalletBlockingStub blockingStubFull, String txId, int timeout) { BlockHelper.waitUntilTransactionInfoFound(blockingStubFull, txId, timeout); } @@ -983,7 +988,8 @@ public static boolean approveProposal( long id, boolean isAddApproval, WalletGrpc.WalletBlockingStub blockingStubFull) { - return GovernanceHelper.approveProposal(ownerAddress, priKey, id, isAddApproval, blockingStubFull); + return GovernanceHelper.approveProposal( + ownerAddress, priKey, id, isAddApproval, blockingStubFull); } /** constructor. */ @@ -1031,27 +1037,44 @@ public static Boolean freezeBalanceGetTronPower( ByteString receiverAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.freezeBalanceGetTronPower(address, freezeBalance, freezeDuration, resourceCode, receiverAddress, priKey, blockingStubFull); + return ResourceHelper.freezeBalanceGetTronPower( + address, + freezeBalance, + freezeDuration, + resourceCode, + receiverAddress, + priKey, + blockingStubFull); } - @Deprecated - public static Long getChainParametersValue(String proposalName,WalletGrpc.WalletBlockingStub blockingStubFull) { + public static Long getChainParametersValue( + String proposalName, WalletGrpc.WalletBlockingStub blockingStubFull) { return GovernanceHelper.getChainParametersValue(proposalName, blockingStubFull); } - public static Boolean allowTvmSelfdestructRestrictionIsActive(WalletGrpc.WalletBlockingStub blockingStubFull) { - return PublicMethod.getChainParametersValue(ProposalEnum.GetAllowTvmSelfdestructRestriction.getProposalName(), - blockingStubFull) == 1; + public static Boolean allowTvmSelfdestructRestrictionIsActive( + WalletGrpc.WalletBlockingStub blockingStubFull) { + return PublicMethod.getChainParametersValue( + ProposalEnum.GetAllowTvmSelfdestructRestriction.getProposalName(), blockingStubFull) + == 1; } // TODO: Uncomment when proto supports getPaginatedNowWitnessList (v4.8.1+ API) - // public static GrpcAPI.WitnessList getPaginatedNowWitnessList(Long offset, Long limit, WalletGrpc.WalletBlockingStub blockingStubFull){ - // return blockingStubFull.getPaginatedNowWitnessList(GrpcAPI.PaginatedMessage.newBuilder().setLimit(limit).setOffset(offset).build()); + // public static GrpcAPI.WitnessList getPaginatedNowWitnessList(Long offset, Long limit, + // WalletGrpc.WalletBlockingStub blockingStubFull){ + // return + // blockingStubFull.getPaginatedNowWitnessList( + // GrpcAPI.PaginatedMessage.newBuilder() + // .setLimit(limit).setOffset(offset).build()); // } // - // public static GrpcAPI.WitnessList getPaginatedNowWitnessListSolidity(Long offset, Long limit, WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity){ - // return blockingStubSolidity.getPaginatedNowWitnessList(GrpcAPI.PaginatedMessage.newBuilder().setLimit(limit).setOffset(offset).build()); + // public static GrpcAPI.WitnessList getPaginatedNowWitnessListSolidity(Long offset, Long limit, + // WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity){ + // return + // blockingStubSolidity.getPaginatedNowWitnessList( + // GrpcAPI.PaginatedMessage.newBuilder() + // .setLimit(limit).setOffset(offset).build()); // } /** constructor. */ @@ -1063,7 +1086,8 @@ public static Boolean freezeBalanceGetEnergy( int resourceCode, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.freezeBalanceGetEnergy(addRess, freezeBalance, freezeDuration, resourceCode, priKey, blockingStubFull); + return ResourceHelper.freezeBalanceGetEnergy( + addRess, freezeBalance, freezeDuration, resourceCode, priKey, blockingStubFull); } /** constructor. */ @@ -1109,9 +1133,21 @@ public static byte[] deployContractFallbackReceive( String priKey, byte[] ownerAddress, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ContractHelper.deployContractFallbackReceive(contractName, abiString, code, data, - feeLimit, value, consumeUserResourcePercent, originEnergyLimit, tokenId, tokenValue, - libraryAddress, priKey, ownerAddress, blockingStubFull); + return ContractHelper.deployContractFallbackReceive( + contractName, + abiString, + code, + data, + feeLimit, + value, + consumeUserResourcePercent, + originEnergyLimit, + tokenId, + tokenValue, + libraryAddress, + priKey, + ownerAddress, + blockingStubFull); } /** constructor. */ @@ -1130,13 +1166,25 @@ public static byte[] deployContract( String priKey, byte[] ownerAddress, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ContractHelper.deployContract(contractName, abiString, code, data, - feeLimit, value, consumeUserResourcePercent, originEnergyLimit, tokenId, tokenValue, - libraryAddress, priKey, ownerAddress, blockingStubFull); + return ContractHelper.deployContract( + contractName, + abiString, + code, + data, + feeLimit, + value, + consumeUserResourcePercent, + originEnergyLimit, + tokenId, + tokenValue, + libraryAddress, + priKey, + ownerAddress, + blockingStubFull); } /** constructor. */ - public static Transaction deployContractWithoutBroadcast( + public static byte[] deployContract( String contractName, String abiString, String code, @@ -1144,20 +1192,29 @@ public static Transaction deployContractWithoutBroadcast( Long feeLimit, long value, long consumeUserResourcePercent, - long originEnergyLimit, - String tokenId, - long tokenValue, String libraryAddress, String priKey, byte[] ownerAddress, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ContractHelper.deployContractWithoutBroadcast(contractName, abiString, code, data, - feeLimit, value, consumeUserResourcePercent, originEnergyLimit, tokenId, tokenValue, - libraryAddress, priKey, ownerAddress, blockingStubFull); + return deployContract( + contractName, + abiString, + code, + data, + feeLimit, + value, + consumeUserResourcePercent, + 1000L, + "0", + 0L, + libraryAddress, + priKey, + ownerAddress, + blockingStubFull); } /** constructor. */ - public static byte[] deployContract( + public static Transaction deployContractWithoutBroadcast( String contractName, String abiString, String code, @@ -1165,11 +1222,14 @@ public static byte[] deployContract( Long feeLimit, long value, long consumeUserResourcePercent, + long originEnergyLimit, + String tokenId, + long tokenValue, String libraryAddress, String priKey, byte[] ownerAddress, WalletGrpc.WalletBlockingStub blockingStubFull) { - return deployContract( + return ContractHelper.deployContractWithoutBroadcast( contractName, abiString, code, @@ -1177,9 +1237,9 @@ public static byte[] deployContract( feeLimit, value, consumeUserResourcePercent, - 1000L, - "0", - 0L, + originEnergyLimit, + tokenId, + tokenValue, libraryAddress, priKey, ownerAddress, @@ -1200,9 +1260,18 @@ public static byte[] deployContractFallback( String priKey, byte[] ownerAddress, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ContractHelper.deployContractFallback(contractName, abiString, code, data, - feeLimit, value, consumeUserResourcePercent, libraryAddress, priKey, - ownerAddress, blockingStubFull); + return ContractHelper.deployContractFallback( + contractName, + abiString, + code, + data, + feeLimit, + value, + consumeUserResourcePercent, + libraryAddress, + priKey, + ownerAddress, + blockingStubFull); } /** constructor. */ @@ -1220,9 +1289,19 @@ public static byte[] deployContractForLibrary( byte[] ownerAddress, String compilerVersion, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ContractHelper.deployContractForLibrary(contractName, abiString, code, data, - feeLimit, value, consumeUserResourcePercent, libraryAddress, priKey, - ownerAddress, compilerVersion, blockingStubFull); + return ContractHelper.deployContractForLibrary( + contractName, + abiString, + code, + data, + feeLimit, + value, + consumeUserResourcePercent, + libraryAddress, + priKey, + ownerAddress, + compilerVersion, + blockingStubFull); } /** constructor. */ @@ -1239,9 +1318,18 @@ public static String deployContractAndGetTransactionInfoById( String priKey, byte[] ownerAddress, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ContractHelper.deployContractAndGetTransactionInfoById(contractName, abiString, - code, data, feeLimit, value, consumeUserResourcePercent, libraryAddress, priKey, - ownerAddress, blockingStubFull); + return ContractHelper.deployContractAndGetTransactionInfoById( + contractName, + abiString, + code, + data, + feeLimit, + value, + consumeUserResourcePercent, + libraryAddress, + priKey, + ownerAddress, + blockingStubFull); } /** constructor. */ @@ -1260,9 +1348,21 @@ public static String deployContractAndGetTransactionInfoById( String priKey, byte[] ownerAddress, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ContractHelper.deployContractAndGetTransactionInfoById(contractName, abiString, code, - data, feeLimit, value, consumeUserResourcePercent, originEnergyLimit, tokenId, tokenValue, - libraryAddress, priKey, ownerAddress, blockingStubFull); + return ContractHelper.deployContractAndGetTransactionInfoById( + contractName, + abiString, + code, + data, + feeLimit, + value, + consumeUserResourcePercent, + originEnergyLimit, + tokenId, + tokenValue, + libraryAddress, + priKey, + ownerAddress, + blockingStubFull); } /** constructor. */ @@ -1393,8 +1493,8 @@ public static boolean updateSetting( String priKey, byte[] ownerAddress, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ContractHelper.updateSetting(contractAddress, consumeUserResourcePercent, - priKey, ownerAddress, blockingStubFull); + return ContractHelper.updateSetting( + contractAddress, consumeUserResourcePercent, priKey, ownerAddress, blockingStubFull); } /** 61 constructor. */ @@ -1437,8 +1537,16 @@ public static String triggerContract( byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ContractHelper.triggerContract(contractAddress, method, argsStr, isHex, - callValue, feeLimit, ownerAddress, priKey, blockingStubFull); + return ContractHelper.triggerContract( + contractAddress, + method, + argsStr, + isHex, + callValue, + feeLimit, + ownerAddress, + priKey, + blockingStubFull); } /** constructor. */ @@ -1455,8 +1563,18 @@ public static String triggerContract( byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ContractHelper.triggerContract(contractAddress, method, argsStr, isHex, - callValue, feeLimit, tokenId, tokenValue, ownerAddress, priKey, blockingStubFull); + return ContractHelper.triggerContract( + contractAddress, + method, + argsStr, + isHex, + callValue, + feeLimit, + tokenId, + tokenValue, + ownerAddress, + priKey, + blockingStubFull); } /** constructor. */ @@ -1472,8 +1590,17 @@ public static String triggerContractBoth( String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, WalletGrpc.WalletBlockingStub blockingStubFull1) { - return ContractHelper.triggerContractBoth(contractAddress, method, argsStr, isHex, - callValue, feeLimit, ownerAddress, priKey, blockingStubFull, blockingStubFull1); + return ContractHelper.triggerContractBoth( + contractAddress, + method, + argsStr, + isHex, + callValue, + feeLimit, + ownerAddress, + priKey, + blockingStubFull, + blockingStubFull1); } /** constructor. */ @@ -1491,8 +1618,19 @@ public static String triggerContractBoth( String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, WalletGrpc.WalletBlockingStub blockingStubFull1) { - return ContractHelper.triggerContractBoth(contractAddress, method, argsStr, isHex, - callValue, feeLimit, tokenId, tokenValue, ownerAddress, priKey, blockingStubFull, blockingStubFull1); + return ContractHelper.triggerContractBoth( + contractAddress, + method, + argsStr, + isHex, + callValue, + feeLimit, + tokenId, + tokenValue, + ownerAddress, + priKey, + blockingStubFull, + blockingStubFull1); } /** constructor. */ @@ -1509,8 +1647,18 @@ public static String triggerParamListContract( byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ContractHelper.triggerParamListContract(contractAddress, method, params, isHex, - callValue, feeLimit, tokenId, tokenValue, ownerAddress, priKey, blockingStubFull); + return ContractHelper.triggerParamListContract( + contractAddress, + method, + params, + isHex, + callValue, + feeLimit, + tokenId, + tokenValue, + ownerAddress, + priKey, + blockingStubFull); } /** constructor. */ @@ -1523,8 +1671,14 @@ public static Boolean exchangeCreate( byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return AssetHelper.exchangeCreate(firstTokenId, firstTokenBalance, secondTokenId, - secondTokenBalance, ownerAddress, priKey, blockingStubFull); + return AssetHelper.exchangeCreate( + firstTokenId, + firstTokenBalance, + secondTokenId, + secondTokenBalance, + ownerAddress, + priKey, + blockingStubFull); } /** constructor. */ @@ -1536,7 +1690,8 @@ public static Boolean injectExchange( byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return AssetHelper.injectExchange(exchangeId, tokenId, quant, ownerAddress, priKey, blockingStubFull); + return AssetHelper.injectExchange( + exchangeId, tokenId, quant, ownerAddress, priKey, blockingStubFull); } @Deprecated @@ -1575,7 +1730,8 @@ public static boolean exchangeWithdraw( byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return AssetHelper.exchangeWithdraw(exchangeId, tokenId, quant, ownerAddress, priKey, blockingStubFull); + return AssetHelper.exchangeWithdraw( + exchangeId, tokenId, quant, ownerAddress, priKey, blockingStubFull); } /** constructor. */ @@ -1588,8 +1744,8 @@ public static boolean exchangeTransaction( byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return AssetHelper.exchangeTransaction(exchangeId, tokenId, quant, expected, ownerAddress, - priKey, blockingStubFull); + return AssetHelper.exchangeTransaction( + exchangeId, tokenId, quant, expected, ownerAddress, priKey, blockingStubFull); } /** constructor. */ @@ -1608,9 +1764,20 @@ public static String deployContractWithConstantParame( String priKey, byte[] ownerAddress, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ContractHelper.deployContractWithConstantParame(contractName, abiString, code, - constructorStr, argsStr, data, feeLimit, value, consumeUserResourcePercent, - libraryAddress, priKey, ownerAddress, blockingStubFull); + return ContractHelper.deployContractWithConstantParame( + contractName, + abiString, + code, + constructorStr, + argsStr, + data, + feeLimit, + value, + consumeUserResourcePercent, + libraryAddress, + priKey, + ownerAddress, + blockingStubFull); } /** constructor. */ @@ -1631,9 +1798,23 @@ public static String deployContractWithConstantParame( String priKey, byte[] ownerAddress, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ContractHelper.deployContractWithConstantParame(contractName, abiString, code, - constructorStr, argsStr, data, feeLimit, value, consumeUserResourcePercent, - originEnergyLimit, tokenId, tokenValue, libraryAddress, priKey, ownerAddress, blockingStubFull); + return ContractHelper.deployContractWithConstantParame( + contractName, + abiString, + code, + constructorStr, + argsStr, + data, + feeLimit, + value, + consumeUserResourcePercent, + originEnergyLimit, + tokenId, + tokenValue, + libraryAddress, + priKey, + ownerAddress, + blockingStubFull); } /** constructor. */ @@ -1646,7 +1827,14 @@ public static Boolean freezeBalanceForReceiver( ByteString receiverAddressBytes, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.freezeBalanceForReceiver(addRess, freezeBalance, freezeDuration, resourceCode, receiverAddressBytes, priKey, blockingStubFull); + return ResourceHelper.freezeBalanceForReceiver( + addRess, + freezeBalance, + freezeDuration, + resourceCode, + receiverAddressBytes, + priKey, + blockingStubFull); } /** constructor. */ @@ -1662,7 +1850,8 @@ public static Optional getDelegatedResourceFromSolidity( byte[] fromAddress, byte[] toAddress, WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { - return ResourceHelper.getDelegatedResourceFromSolidity(fromAddress, toAddress, blockingStubFull); + return ResourceHelper.getDelegatedResourceFromSolidity( + fromAddress, toAddress, blockingStubFull); } /** constructor. */ @@ -1672,7 +1861,6 @@ public static Optional getDelegatedResourceAccoun return ResourceHelper.getDelegatedResourceAccountIndex(address, blockingStubFull); } - /** constructor. */ @Deprecated public static Optional @@ -1680,24 +1868,30 @@ public static Optional getDelegatedResourceAccoun byte[] address, WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { return ResourceHelper.getDelegatedResourceAccountIndexFromSolidity(address, blockingStubFull); } + /** constructor. */ @Deprecated public static Optional getDelegatedResourceV2( byte[] fromAddress, byte[] toAddress, WalletGrpc.WalletBlockingStub blockingStubFull) { return ResourceHelper.getDelegatedResourceV2(fromAddress, toAddress, blockingStubFull); } + /** constructor. */ @Deprecated public static Optional getDelegatedResourceV2Solidity( - byte[] fromAddress, byte[] toAddress, WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { + byte[] fromAddress, + byte[] toAddress, + WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { return ResourceHelper.getDelegatedResourceV2Solidity(fromAddress, toAddress, blockingStubFull); } + /** constructor. */ @Deprecated public static Optional getDelegatedResourceAccountIndexV2( byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { return ResourceHelper.getDelegatedResourceAccountIndexV2(address, blockingStubFull); } + /** constructor. */ @Deprecated public static Optional getDelegatedResourceAccountIndexV2Solidity( @@ -1706,42 +1900,48 @@ public static Optional getDelegatedResourceAccoun } @Deprecated - public static Optional getCanDelegatedMaxSize(byte[] ownerAddress, int type, - WalletGrpc.WalletBlockingStub blockingStub) { + public static Optional getCanDelegatedMaxSize( + byte[] ownerAddress, int type, WalletGrpc.WalletBlockingStub blockingStub) { return ResourceHelper.getCanDelegatedMaxSize(ownerAddress, type, blockingStub); } @Deprecated - public static Optional getCanDelegatedMaxSizeSolidity(byte[] ownerAddress, int type, - WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { + public static Optional getCanDelegatedMaxSizeSolidity( + byte[] ownerAddress, + int type, + WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { return ResourceHelper.getCanDelegatedMaxSizeSolidity(ownerAddress, type, blockingStubFull); } - @Deprecated public static Optional getCanWithdrawUnfreezeAmount( - byte[] ownerAddress, long timestamp,WalletGrpc.WalletBlockingStub blockingStub) { + byte[] ownerAddress, long timestamp, WalletGrpc.WalletBlockingStub blockingStub) { return ResourceHelper.getCanWithdrawUnfreezeAmount(ownerAddress, timestamp, blockingStub); } + @Deprecated - public static Optional getCanWithdrawUnfreezeAmountSolidity( - byte[] ownerAddress, long timestamp,WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { - return ResourceHelper.getCanWithdrawUnfreezeAmountSolidity(ownerAddress, timestamp, blockingStubFull); + public static Optional + getCanWithdrawUnfreezeAmountSolidity( + byte[] ownerAddress, + long timestamp, + WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { + return ResourceHelper.getCanWithdrawUnfreezeAmountSolidity( + ownerAddress, timestamp, blockingStubFull); } - @Deprecated public static Optional getAvailableUnfreezeCount( - byte[] ownerAddress,WalletGrpc.WalletBlockingStub blockingStub) { + byte[] ownerAddress, WalletGrpc.WalletBlockingStub blockingStub) { return ResourceHelper.getAvailableUnfreezeCount(ownerAddress, blockingStub); } + @Deprecated - public static Optional getAvailableUnfreezeCountSolidity( - byte[] ownerAddress,WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { + public static Optional + getAvailableUnfreezeCountSolidity( + byte[] ownerAddress, WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { return ResourceHelper.getAvailableUnfreezeCountSolidity(ownerAddress, blockingStubFull); } - /** constructor. */ @Deprecated public static AssetIssueContract getAssetIssueByName( @@ -1869,7 +2069,8 @@ public static boolean accountPermissionUpdate( String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, String[] priKeys) { - return AccountHelper.accountPermissionUpdate(permissionJson, owner, priKey, blockingStubFull, priKeys); + return AccountHelper.accountPermissionUpdate( + permissionJson, owner, priKey, blockingStubFull, priKeys); } /** constructor. */ @@ -1879,7 +2080,8 @@ public static long getFreezeBalanceCount( String ecKey, Long targetEnergy, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.getFreezeBalanceCount(accountAddress, ecKey, targetEnergy, blockingStubFull); + return ResourceHelper.getFreezeBalanceCount( + accountAddress, ecKey, targetEnergy, blockingStubFull); } /** constructor. */ @@ -1926,9 +2128,21 @@ public static GrpcAPI.Return deployContractAndGetResponse( String priKey, byte[] ownerAddress, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ContractHelper.deployContractAndGetResponse(contractName, abiString, code, data, - feeLimit, value, consumeUserResourcePercent, originEnergyLimit, tokenId, tokenValue, - libraryAddress, priKey, ownerAddress, blockingStubFull); + return ContractHelper.deployContractAndGetResponse( + contractName, + abiString, + code, + data, + feeLimit, + value, + consumeUserResourcePercent, + originEnergyLimit, + tokenId, + tokenValue, + libraryAddress, + priKey, + ownerAddress, + blockingStubFull); } /** constructor. */ @@ -1945,8 +2159,17 @@ public static GrpcAPI.Return triggerContractAndGetResponse( byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ContractHelper.triggerContractAndGetResponse(contractAddress, method, argsStr, - isHex, callValue, feeLimit, tokenId, tokenValue, ownerAddress, priKey, + return ContractHelper.triggerContractAndGetResponse( + contractAddress, + method, + argsStr, + isHex, + callValue, + feeLimit, + tokenId, + tokenValue, + ownerAddress, + priKey, blockingStubFull); } @@ -1958,8 +2181,8 @@ public static boolean updateEnergyLimit( String priKey, byte[] ownerAddress, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ContractHelper.updateEnergyLimit(contractAddress, originEnergyLimit, - priKey, ownerAddress, blockingStubFull); + return ContractHelper.updateEnergyLimit( + contractAddress, originEnergyLimit, priKey, ownerAddress, blockingStubFull); } /** constructor. */ @@ -1969,7 +2192,8 @@ public static GrpcAPI.Return accountPermissionUpdateForResponse( byte[] owner, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return AccountHelper.accountPermissionUpdateForResponse(permissionJson, owner, priKey, blockingStubFull); + return AccountHelper.accountPermissionUpdateForResponse( + permissionJson, owner, priKey, blockingStubFull); } @Deprecated @@ -1985,7 +2209,8 @@ public static long getFreezeBalanceNetCount( String ecKey, Long targetNet, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.getFreezeBalanceNetCount(accountAddress, ecKey, targetNet, blockingStubFull); + return ResourceHelper.getFreezeBalanceNetCount( + accountAddress, ecKey, targetNet, blockingStubFull); } /** constructor. */ @@ -2001,11 +2226,12 @@ public static GrpcAPI.Return broadcastTransactionBoth( Transaction transaction, WalletGrpc.WalletBlockingStub blockingStubFull, WalletGrpc.WalletBlockingStub blockingStubFull1) { - return TransactionHelper.broadcastTransactionBoth(transaction, blockingStubFull, blockingStubFull1); + return TransactionHelper.broadcastTransactionBoth( + transaction, blockingStubFull, blockingStubFull1); } /** constructor. */ - public synchronized static String exec(String command) throws InterruptedException { + public static synchronized String exec(String command) throws InterruptedException { String returnString = ""; String errReturnString = ""; Process pro = null; @@ -2025,7 +2251,7 @@ public synchronized static String exec(String command) throws InterruptedExcepti InputStreamReader errReader = new InputStreamReader(stderr); BufferedReader br = new BufferedReader(errReader); String errLine = null; - while ((errLine = br.readLine())!=null) { + while ((errLine = br.readLine()) != null) { errReturnString = errReturnString + errLine + "\n"; } input.close(); @@ -2039,7 +2265,6 @@ public synchronized static String exec(String command) throws InterruptedExcepti return returnString.length() >= errReturnString.length() ? returnString : errReturnString; } - /** constructor. */ public static HashMap getBycodeAbiNoOptimize( String solFile, String contractName) { @@ -2099,7 +2324,8 @@ public static HashMap getBycodeAbiNoOptimize( } /** constructor. */ - public synchronized static HashMap getBycodeAbi(String solFile, String contractName) { + public static synchronized HashMap getBycodeAbi( + String solFile, String contractName) { final String compile = Configuration.getByPath("testng.conf").getString("defaultParameter.solidityCompile"); @@ -2135,7 +2361,6 @@ public synchronized static HashMap getBycodeAbi(String solFile, String byteCode = null; String abI = null; - // compile solidity file try { exec(cmd); @@ -2157,9 +2382,10 @@ public synchronized static HashMap getBycodeAbi(String solFile, } /** constructor. */ - public synchronized static HashMap getBycodeAbiWithParam(String solFile, String contractName, String param) { + public static synchronized HashMap getBycodeAbiWithParam( + String solFile, String contractName, String param) { final String compile = - Configuration.getByPath("testng.conf").getString("defaultParameter.solidityCompile"); + Configuration.getByPath("testng.conf").getString("defaultParameter.solidityCompile"); String dirPath = solFile.substring(solFile.lastIndexOf("/"), solFile.lastIndexOf(".")); String outputPath = "src/test/resources/soliditycode/output" + dirPath; @@ -2179,21 +2405,22 @@ public synchronized static HashMap getBycodeAbiWithParam(String logger.debug("solFile: " + solFile); logger.debug("outputPath: " + outputPath); String cmd = - compile - + " --optimize " + param + " --bin --abi --overwrite " - + absolutePath - + "/" - + solFile - + " -o " - + absolutePath - + "/" - + outputPath; + compile + + " --optimize " + + param + + " --bin --abi --overwrite " + + absolutePath + + "/" + + solFile + + " -o " + + absolutePath + + "/" + + outputPath; logger.info("cmd: " + cmd); String byteCode = null; String abI = null; - // compile solidity file try { exec(cmd); @@ -2252,8 +2479,18 @@ public static String triggerConstantContract( byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ContractHelper.triggerConstantContract(contractAddress, method, argsStr, isHex, - callValue, feeLimit, tokenId, tokenValue, ownerAddress, priKey, blockingStubFull); + return ContractHelper.triggerConstantContract( + contractAddress, + method, + argsStr, + isHex, + callValue, + feeLimit, + tokenId, + tokenValue, + ownerAddress, + priKey, + blockingStubFull); } /** constructor. */ @@ -2270,9 +2507,18 @@ public static TransactionExtention triggerConstantContractForExtentionOnSolidity byte[] ownerAddress, String priKey, WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity) { - return ContractHelper.triggerConstantContractForExtentionOnSolidity(contractAddress, - method, argsStr, isHex, callValue, feeLimit, tokenId, tokenValue, ownerAddress, - priKey, blockingStubSolidity); + return ContractHelper.triggerConstantContractForExtentionOnSolidity( + contractAddress, + method, + argsStr, + isHex, + callValue, + feeLimit, + tokenId, + tokenValue, + ownerAddress, + priKey, + blockingStubSolidity); } /** constructor. */ @@ -2282,8 +2528,7 @@ public static String clearContractAbi( byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ContractHelper.clearContractAbi(contractAddress, ownerAddress, priKey, - blockingStubFull); + return ContractHelper.clearContractAbi(contractAddress, ownerAddress, priKey, blockingStubFull); } /** constructor. */ @@ -2293,8 +2538,8 @@ public static TransactionExtention clearContractAbiForExtention( byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ContractHelper.clearContractAbiForExtention(contractAddress, ownerAddress, - priKey, blockingStubFull); + return ContractHelper.clearContractAbiForExtention( + contractAddress, ownerAddress, priKey, blockingStubFull); } /** constructor. */ @@ -2311,8 +2556,17 @@ public static TransactionExtention triggerConstantContractForExtention( byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ContractHelper.triggerConstantContractForExtention(contractAddress, method, - argsStr, isHex, callValue, feeLimit, tokenId, tokenValue, ownerAddress, priKey, + return ContractHelper.triggerConstantContractForExtention( + contractAddress, + method, + argsStr, + isHex, + callValue, + feeLimit, + tokenId, + tokenValue, + ownerAddress, + priKey, blockingStubFull); } @@ -2330,8 +2584,17 @@ public static TransactionExtention triggerSolidityContractForExtention( byte[] ownerAddress, String priKey, WalletSolidityGrpc.WalletSolidityBlockingStub solidityBlockingStubFull) { - return ContractHelper.triggerSolidityContractForExtention(contractAddress, method, - argsStr, isHex, callValue, feeLimit, tokenId, tokenValue, ownerAddress, priKey, + return ContractHelper.triggerSolidityContractForExtention( + contractAddress, + method, + argsStr, + isHex, + callValue, + feeLimit, + tokenId, + tokenValue, + ownerAddress, + priKey, solidityBlockingStubFull); } @@ -2349,8 +2612,17 @@ public static TransactionExtention triggerContractForExtention( byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ContractHelper.triggerContractForExtention(contractAddress, method, argsStr, - isHex, callValue, feeLimit, tokenId, tokenValue, ownerAddress, priKey, + return ContractHelper.triggerContractForExtention( + contractAddress, + method, + argsStr, + isHex, + callValue, + feeLimit, + tokenId, + tokenValue, + ownerAddress, + priKey, blockingStubFull); } @@ -2372,7 +2644,16 @@ public static boolean sendShieldCoin( long toAmount, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ShieldHelper.sendShieldCoin(publicZenTokenOwnerAddress, fromAmount, shieldAddressInfo, noteTx, shieldOutputList, publicZenTokenToAddress, toAmount, priKey, blockingStubFull); + return ShieldHelper.sendShieldCoin( + publicZenTokenOwnerAddress, + fromAmount, + shieldAddressInfo, + noteTx, + shieldOutputList, + publicZenTokenToAddress, + toAmount, + priKey, + blockingStubFull); } /** constructor. */ @@ -2387,14 +2668,24 @@ public static boolean sendShieldCoinWithoutAsk( long toAmount, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ShieldHelper.sendShieldCoinWithoutAsk(publicZenTokenOwnerAddress, fromAmount, shieldAddressInfo, noteTx, shieldOutputList, publicZenTokenToAddress, toAmount, priKey, blockingStubFull); + return ShieldHelper.sendShieldCoinWithoutAsk( + publicZenTokenOwnerAddress, + fromAmount, + shieldAddressInfo, + noteTx, + shieldOutputList, + publicZenTokenToAddress, + toAmount, + priKey, + blockingStubFull); } /** constructor. */ @Deprecated public static List addShieldOutputList( List shieldOutList, String shieldToAddress, String toAmountString, String menoString) { - return ShieldHelper.addShieldOutputList(shieldOutList, shieldToAddress, toAmountString, menoString); + return ShieldHelper.addShieldOutputList( + shieldOutList, shieldToAddress, toAmountString, menoString); } /** constructor. */ @@ -2432,7 +2723,8 @@ public static DecryptNotesMarked getShieldNotesAndMarkByIvk( public static DecryptNotesMarked getShieldNotesAndMarkByIvkOnSolidity( Optional shieldAddressInfo, WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity) { - return ShieldHelper.getShieldNotesAndMarkByIvkOnSolidity(shieldAddressInfo, blockingStubSolidity); + return ShieldHelper.getShieldNotesAndMarkByIvkOnSolidity( + shieldAddressInfo, blockingStubSolidity); } /** constructor. */ @@ -2504,7 +2796,16 @@ public static String sendShieldCoinGetTxid( long toAmount, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ShieldHelper.sendShieldCoinGetTxid(publicZenTokenOwnerAddress, fromAmount, shieldAddressInfo, noteTx, shieldOutputList, publicZenTokenToAddress, toAmount, priKey, blockingStubFull); + return ShieldHelper.sendShieldCoinGetTxid( + publicZenTokenOwnerAddress, + fromAmount, + shieldAddressInfo, + noteTx, + shieldOutputList, + publicZenTokenToAddress, + toAmount, + priKey, + blockingStubFull); } /** constructor. */ @@ -2543,7 +2844,8 @@ public static Return transferAssetForReturn( byte[] address, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return AssetHelper.transferAssetForReturn(to, assertName, amount, address, priKey, blockingStubFull); + return AssetHelper.transferAssetForReturn( + to, assertName, amount, address, priKey, blockingStubFull); } /** constructor. */ @@ -2578,8 +2880,14 @@ public static String marketSellAsset( byte[] buyTokenId, long buyTokenQuantity, WalletGrpc.WalletBlockingStub blockingStubFull) { - return AssetHelper.marketSellAsset(owner, priKey, sellTokenId, sellTokenQuantity, - buyTokenId, buyTokenQuantity, blockingStubFull); + return AssetHelper.marketSellAsset( + owner, + priKey, + sellTokenId, + sellTokenQuantity, + buyTokenId, + buyTokenQuantity, + blockingStubFull); } /** constructor. */ @@ -2592,8 +2900,14 @@ public static Return marketSellAssetGetResposne( byte[] buyTokenId, long buyTokenQuantity, WalletGrpc.WalletBlockingStub blockingStubFull) { - return AssetHelper.marketSellAssetGetResposne(owner, priKey, sellTokenId, sellTokenQuantity, - buyTokenId, buyTokenQuantity, blockingStubFull); + return AssetHelper.marketSellAssetGetResposne( + owner, + priKey, + sellTokenId, + sellTokenQuantity, + buyTokenId, + buyTokenQuantity, + blockingStubFull); } /** constructor. */ @@ -2658,7 +2972,8 @@ public static Optional getMarketOrderListByPairSolidit byte[] sellTokenId, byte[] buyTokenId, WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity) { - return AssetHelper.getMarketOrderListByPairSolidity(sellTokenId, buyTokenId, blockingStubSolidity); + return AssetHelper.getMarketOrderListByPairSolidity( + sellTokenId, buyTokenId, blockingStubSolidity); } /** constructor. */ @@ -2773,62 +3088,72 @@ public static Optional getTransactionFromPending( return Optional.ofNullable(transaction); } - /** constructor. */ @Deprecated - public static Boolean freezeBalanceV2(byte[] addressByte, + public static Boolean freezeBalanceV2( + byte[] addressByte, long freezeBalance, int resourceCode, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.freezeBalanceV2(addressByte, freezeBalance, resourceCode, priKey, blockingStubFull); + return ResourceHelper.freezeBalanceV2( + addressByte, freezeBalance, resourceCode, priKey, blockingStubFull); } + @Deprecated - public static String freezeBalanceV2AndGetTxId(byte[] addressByte, - long freezeBalance, - int resourceCode, - String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.freezeBalanceV2AndGetTxId(addressByte, freezeBalance, resourceCode, priKey, blockingStubFull); + public static String freezeBalanceV2AndGetTxId( + byte[] addressByte, + long freezeBalance, + int resourceCode, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull) { + return ResourceHelper.freezeBalanceV2AndGetTxId( + addressByte, freezeBalance, resourceCode, priKey, blockingStubFull); } - @Deprecated - public static Long getFrozenV2Amount(byte[] address, int resourceCode,WalletGrpc.WalletBlockingStub blockingStubFull) { + public static Long getFrozenV2Amount( + byte[] address, int resourceCode, WalletGrpc.WalletBlockingStub blockingStubFull) { return ResourceHelper.getFrozenV2Amount(address, resourceCode, blockingStubFull); } /** constructor. */ @Deprecated - public static Boolean delegateResourceForReceiver(byte[] addressByte, + public static Boolean delegateResourceForReceiver( + byte[] addressByte, long delegateAmount, int resourceCode, byte[] receiverAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.delegateResourceForReceiver(addressByte, delegateAmount, resourceCode, receiverAddress, priKey, blockingStubFull); + return ResourceHelper.delegateResourceForReceiver( + addressByte, delegateAmount, resourceCode, receiverAddress, priKey, blockingStubFull); } - /** constructor. */ @Deprecated - public static Boolean delegateResourceV2(byte[] addressByte, + public static Boolean delegateResourceV2( + byte[] addressByte, long delegateAmount, int resourceCode, byte[] receiverAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.delegateResourceV2(addressByte, delegateAmount, resourceCode, receiverAddress, priKey, blockingStubFull); + return ResourceHelper.delegateResourceV2( + addressByte, delegateAmount, resourceCode, receiverAddress, priKey, blockingStubFull); } + /** constructor. */ @Deprecated - public static String delegateResourceV2AndGetTxId(byte[] addressByte, - long delegateAmount, - int resourceCode, - byte[] receiverAddress, - String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.delegateResourceV2AndGetTxId(addressByte, delegateAmount, resourceCode, receiverAddress, priKey, blockingStubFull); + public static String delegateResourceV2AndGetTxId( + byte[] addressByte, + long delegateAmount, + int resourceCode, + byte[] receiverAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull) { + return ResourceHelper.delegateResourceV2AndGetTxId( + addressByte, delegateAmount, resourceCode, receiverAddress, priKey, blockingStubFull); } /** constructor. */ @@ -2842,14 +3167,21 @@ public static TransactionExtention delegateResourceV2AndGetTransactionExtention( byte[] receiverAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.delegateResourceV2AndGetTransactionExtention(addressByte, delegateAmount, resourceCode, lock, lockPeriod, receiverAddress, priKey, blockingStubFull); + return ResourceHelper.delegateResourceV2AndGetTransactionExtention( + addressByte, + delegateAmount, + resourceCode, + lock, + lockPeriod, + receiverAddress, + priKey, + blockingStubFull); } - - /** constructor. */ @Deprecated - public static Boolean delegateResourceV2Lock(byte[] addressByte, + public static Boolean delegateResourceV2Lock( + byte[] addressByte, long delegateAmount, int resourceCode, boolean lock, @@ -2857,54 +3189,75 @@ public static Boolean delegateResourceV2Lock(byte[] addressByte, byte[] receiverAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.delegateResourceV2Lock(addressByte, delegateAmount, resourceCode, lock, lockPeriod, receiverAddress, priKey, blockingStubFull); + return ResourceHelper.delegateResourceV2Lock( + addressByte, + delegateAmount, + resourceCode, + lock, + lockPeriod, + receiverAddress, + priKey, + blockingStubFull); } @Deprecated - public static String delegateResourceV2LockAndGetTxId(byte[] addressByte, - long delegateAmount, - int resourceCode, - boolean lock, - Long lockPeriod, - byte[] receiverAddress, - String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.delegateResourceV2LockAndGetTxId(addressByte, delegateAmount, resourceCode, lock, lockPeriod, receiverAddress, priKey, blockingStubFull); + public static String delegateResourceV2LockAndGetTxId( + byte[] addressByte, + long delegateAmount, + int resourceCode, + boolean lock, + Long lockPeriod, + byte[] receiverAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull) { + return ResourceHelper.delegateResourceV2LockAndGetTxId( + addressByte, + delegateAmount, + resourceCode, + lock, + lockPeriod, + receiverAddress, + priKey, + blockingStubFull); } - - /** constructor. */ @Deprecated - public static Boolean unDelegateResourceV2(byte[] addressByte, + public static Boolean unDelegateResourceV2( + byte[] addressByte, long delegateAmount, int resourceCode, byte[] receiverAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.unDelegateResourceV2(addressByte, delegateAmount, resourceCode, receiverAddress, priKey, blockingStubFull); + return ResourceHelper.unDelegateResourceV2( + addressByte, delegateAmount, resourceCode, receiverAddress, priKey, blockingStubFull); } @Deprecated - public static String unDelegateResourceV2AndGetTxId(byte[] addressByte, - long delegateAmount, - int resourceCode, - byte[] receiverAddress, - String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.unDelegateResourceV2AndGetTxId(addressByte, delegateAmount, resourceCode, receiverAddress, priKey, blockingStubFull); + public static String unDelegateResourceV2AndGetTxId( + byte[] addressByte, + long delegateAmount, + int resourceCode, + byte[] receiverAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull) { + return ResourceHelper.unDelegateResourceV2AndGetTxId( + addressByte, delegateAmount, resourceCode, receiverAddress, priKey, blockingStubFull); } + @Deprecated - public static TransactionExtention unDelegateResourceV2AndGetTransactionExtention(byte[] addressByte, - long delegateAmount, - int resourceCode, - byte[] receiverAddress, - String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull) { - return ResourceHelper.unDelegateResourceV2AndGetTransactionExtention(addressByte, delegateAmount, resourceCode, receiverAddress, priKey, blockingStubFull); + public static TransactionExtention unDelegateResourceV2AndGetTransactionExtention( + byte[] addressByte, + long delegateAmount, + int resourceCode, + byte[] receiverAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull) { + return ResourceHelper.unDelegateResourceV2AndGetTransactionExtention( + addressByte, delegateAmount, resourceCode, receiverAddress, priKey, blockingStubFull); } - /** constructor. */ @Deprecated public static Optional estimateEnergy( @@ -2916,10 +3269,17 @@ public static Optional estimateEnergy( String argsStr, Boolean isHex, long tokenValue, - String tokenId - ) { - return ContractHelper.estimateEnergy(blockingStubFull, owner, contractAddress, - callValue, method, argsStr, isHex, tokenValue, tokenId); + String tokenId) { + return ContractHelper.estimateEnergy( + blockingStubFull, + owner, + contractAddress, + callValue, + method, + argsStr, + isHex, + tokenValue, + tokenId); } /** constructor. */ @@ -2933,59 +3293,64 @@ public static Optional estimateEnergySolidity( String argsStr, Boolean isHex, long tokenValue, - String tokenId - ) { - return ContractHelper.estimateEnergySolidity(blockingStubFull, owner, contractAddress, - callValue, method, argsStr, isHex, tokenValue, tokenId); + String tokenId) { + return ContractHelper.estimateEnergySolidity( + blockingStubFull, + owner, + contractAddress, + callValue, + method, + argsStr, + isHex, + tokenValue, + tokenId); } @Deprecated public static Optional estimateEnergyDeployContract( - WalletGrpc.WalletBlockingStub blockingStubFull, - byte[] owner, - long callValue, - long tokenValue, - String tokenId, - String code - ) { - return ContractHelper.estimateEnergyDeployContract(blockingStubFull, owner, - callValue, tokenValue, tokenId, code); + WalletGrpc.WalletBlockingStub blockingStubFull, + byte[] owner, + long callValue, + long tokenValue, + String tokenId, + String code) { + return ContractHelper.estimateEnergyDeployContract( + blockingStubFull, owner, callValue, tokenValue, tokenId, code); } - public static void estimateDeployContractEnergy( - String code, - long value, - String tokenId, - long tokenValue, - byte[] ownerAddress, - WalletGrpc.WalletBlockingStub blockingStubFull - ) { - ContractHelper.estimateDeployContractEnergy(code, value, tokenId, tokenValue, - ownerAddress, blockingStubFull); + String code, + long value, + String tokenId, + long tokenValue, + byte[] ownerAddress, + WalletGrpc.WalletBlockingStub blockingStubFull) { + ContractHelper.estimateDeployContractEnergy( + code, value, tokenId, tokenValue, ownerAddress, blockingStubFull); } /** constructor. */ @Deprecated public static TransactionExtention triggerConstantContractDeployContract( - String code, - byte[] ownerAddress, - long callValue, - String tokenId, - long tokenValue, - WalletGrpc.WalletBlockingStub blockingStubFull) { - return ContractHelper.triggerConstantContractDeployContract(code, ownerAddress, - callValue, tokenId, tokenValue, blockingStubFull); + String code, + byte[] ownerAddress, + long callValue, + String tokenId, + long tokenValue, + WalletGrpc.WalletBlockingStub blockingStubFull) { + return ContractHelper.triggerConstantContractDeployContract( + code, ownerAddress, callValue, tokenId, tokenValue, blockingStubFull); } @Deprecated - public static Long getExchangeIdByCreatorAddress(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { + public static Long getExchangeIdByCreatorAddress( + byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { return AssetHelper.getExchangeIdByCreatorAddress(address, blockingStubFull); } public static String gRPCurlRequest(String data, String requestUrl, String node) { String cmd = gRPCurl + " " + "-plaintext"; - if (data!=null) { + if (data != null) { cmd = cmd + " -d " + data; } cmd = cmd + " " + node + " " + requestUrl; @@ -3001,9 +3366,4 @@ public static String gRPCurlRequest(String data, String requestUrl, String node) } return null; } - - - - - } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/PublicMethodForMultiSign.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/PublicMethodForMultiSign.java index c5a11ea6..ac93c653 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/PublicMethodForMultiSign.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/PublicMethodForMultiSign.java @@ -1,6 +1,5 @@ package stest.tron.wallet.common.client.utils; - import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.google.gson.JsonArray; @@ -94,23 +93,32 @@ import stest.tron.wallet.common.client.utils.zen.address.ExpandedSpendingKey; import stest.tron.wallet.common.client.utils.zen.address.SpendingKey; - public class PublicMethodForMultiSign { private static final Logger logger = LoggerFactory.getLogger("TestLogger"); - //Wallet wallet = new Wallet(); + // Wallet wallet = new Wallet(); public static volatile String freezeV2Txid; public static volatile String cancelUnfreezeTxId; - /** - * constructor. - */ - - public static Boolean createAssetIssue(byte[] address, String name, Long totalSupply, - Integer trxNum, Integer icoNum, Long startTime, Long endTime, Integer voteScore, - String description, String url, Long freeAssetNetLimit, Long publicFreeAssetNetLimit, - Long fronzenAmount, Long frozenDay, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static Boolean createAssetIssue( + byte[] address, + String name, + Long totalSupply, + Integer trxNum, + Integer icoNum, + Long startTime, + Long endTime, + Integer voteScore, + String description, + String url, + Long freeAssetNetLimit, + Long publicFreeAssetNetLimit, + Long fronzenAmount, + Long frozenDay, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -133,14 +141,14 @@ public static Boolean createAssetIssue(byte[] address, String name, Long totalSu builder.setUrl(ByteString.copyFrom(url.getBytes())); builder.setFreeAssetNetLimit(freeAssetNetLimit); builder.setPublicFreeAssetNetLimit(publicFreeAssetNetLimit); - AssetIssueContract.FrozenSupply.Builder frozenBuilder = AssetIssueContract.FrozenSupply - .newBuilder(); + AssetIssueContract.FrozenSupply.Builder frozenBuilder = + AssetIssueContract.FrozenSupply.newBuilder(); frozenBuilder.setFrozenAmount(fronzenAmount); frozenBuilder.setFrozenDays(frozenDay); builder.addFrozenSupply(0, frozenBuilder); - TransactionExtention transactionExtention = blockingStubFull - .createAssetIssue2(builder.build()); + TransactionExtention transactionExtention = + blockingStubFull.createAssetIssue2(builder.build()); Return ret = transactionExtention.getResult(); if (!ret.getResult()) { System.out.println("Code = " + ret.getCode()); @@ -162,16 +170,25 @@ public static Boolean createAssetIssue(byte[] address, String name, Long totalSu } } - - /** - * constructor. - */ - - public static Boolean createAssetIssueWithpermissionId(byte[] address, String name, - Long totalSupply, Integer trxNum, Integer icoNum, Long startTime, Long endTime, - Integer voteScore, String description, String url, Long freeAssetNetLimit, - Long publicFreeAssetNetLimit, Long fronzenAmount, Long frozenDay, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, int permissionId, + /** constructor. */ + public static Boolean createAssetIssueWithpermissionId( + byte[] address, + String name, + Long totalSupply, + Integer trxNum, + Integer icoNum, + Long startTime, + Long endTime, + Integer voteScore, + String description, + String url, + Long freeAssetNetLimit, + Long publicFreeAssetNetLimit, + Long fronzenAmount, + Long frozenDay, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + int permissionId, String[] permissionKeyString) { ECKey temKey = null; try { @@ -195,14 +212,14 @@ public static Boolean createAssetIssueWithpermissionId(byte[] address, String na builder.setUrl(ByteString.copyFrom(url.getBytes())); builder.setFreeAssetNetLimit(freeAssetNetLimit); builder.setPublicFreeAssetNetLimit(publicFreeAssetNetLimit); - AssetIssueContract.FrozenSupply.Builder frozenBuilder = AssetIssueContract.FrozenSupply - .newBuilder(); + AssetIssueContract.FrozenSupply.Builder frozenBuilder = + AssetIssueContract.FrozenSupply.newBuilder(); frozenBuilder.setFrozenAmount(fronzenAmount); frozenBuilder.setFrozenDays(frozenDay); builder.addFrozenSupply(0, frozenBuilder); - TransactionExtention transactionExtention = blockingStubFull - .createAssetIssue2(builder.build()); + TransactionExtention transactionExtention = + blockingStubFull.createAssetIssue2(builder.build()); Return ret = transactionExtention.getResult(); if (transactionExtention == null) { return false; @@ -233,15 +250,25 @@ public static Boolean createAssetIssueWithpermissionId(byte[] address, String na } } - /** - * constructor. - */ - - public static String createAssetIssueForTransactionId(byte[] address, String name, - Long totalSupply, Integer trxNum, Integer icoNum, Long startTime, Long endTime, - Integer voteScore, String description, String url, Long freeAssetNetLimit, - Long publicFreeAssetNetLimit, Long fronzenAmount, Long frozenDay, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static String createAssetIssueForTransactionId( + byte[] address, + String name, + Long totalSupply, + Integer trxNum, + Integer icoNum, + Long startTime, + Long endTime, + Integer voteScore, + String description, + String url, + Long freeAssetNetLimit, + Long publicFreeAssetNetLimit, + Long fronzenAmount, + Long frozenDay, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -264,8 +291,8 @@ public static String createAssetIssueForTransactionId(byte[] address, String nam builder.setUrl(ByteString.copyFrom(url.getBytes())); builder.setFreeAssetNetLimit(freeAssetNetLimit); builder.setPublicFreeAssetNetLimit(publicFreeAssetNetLimit); - AssetIssueContract.FrozenSupply.Builder frozenBuilder = AssetIssueContract.FrozenSupply - .newBuilder(); + AssetIssueContract.FrozenSupply.Builder frozenBuilder = + AssetIssueContract.FrozenSupply.newBuilder(); frozenBuilder.setFrozenAmount(fronzenAmount); frozenBuilder.setFrozenDays(frozenDay); builder.addFrozenSupply(0, frozenBuilder); @@ -281,8 +308,10 @@ public static String createAssetIssueForTransactionId(byte[] address, String nam if (!result) { return null; } else { - return ByteArray.toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray())); + return ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); } } catch (Exception ex) { ex.printStackTrace(); @@ -290,45 +319,33 @@ public static String createAssetIssueForTransactionId(byte[] address, String nam } } - /** - * constructor. - */ - public static boolean broadcastTransaction(Transaction transaction, - WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public static boolean broadcastTransaction( + Transaction transaction, WalletGrpc.WalletBlockingStub blockingStubFull) { Return response = PublicMethod.broadcastTransaction(transaction, blockingStubFull); return response.getResult(); } - - /** - * constructor. - */ - public static Account queryAccount(byte[] address, - WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public static Account queryAccount( + byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ - - public static Account queryAccount(byte[] address, - WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { + /** constructor. */ + public static Account queryAccount( + byte[] address, WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - - /** - * constructor. - */ - - public static Account queryAccount(String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public static Account queryAccount( + String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; ECKey temKey = null; try { @@ -339,7 +356,7 @@ public static Account queryAccount(String priKey, } ECKey ecKey = temKey; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; @@ -351,40 +368,28 @@ public static Account queryAccount(String priKey, return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - /** - * constructor. - */ - + /** constructor. */ public static byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ - - public static Account grpcQueryAccount(byte[] address, - WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public static Account grpcQueryAccount( + byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ - + /** constructor. */ public static Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { GrpcAPI.NumberMessage.Builder builder = GrpcAPI.NumberMessage.newBuilder(); @@ -392,10 +397,7 @@ public static Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blocki return blockingStubFull.getBlockByNum(builder.build()); } - /** - * constructor. - */ - + /** constructor. */ public static Transaction signTransaction(ECKey ecKey, Transaction transaction) { if (ecKey == null || ecKey.getPrivKey() == null) { @@ -405,19 +407,17 @@ public static Transaction signTransaction(ECKey ecKey, Transaction transaction) return TransactionUtils.sign(transaction, ecKey); } - /** - * constructor. - */ - private static Transaction signTransaction(Transaction transaction, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] priKeys) { + /** constructor. */ + private static Transaction signTransaction( + Transaction transaction, WalletGrpc.WalletBlockingStub blockingStubFull, String[] priKeys) { if (transaction.getRawData().getTimestamp() == 0) { transaction = TransactionUtils.setTimestamp(transaction); } - long currentTime = System.currentTimeMillis();//*1000000 + System.nanoTime()%1000000; + long currentTime = System.currentTimeMillis(); // *1000000 + System.nanoTime()%1000000; Transaction.Builder builder = transaction.toBuilder(); - org.tron.protos.Protocol.Transaction.raw.Builder rowBuilder = transaction.getRawData() - .toBuilder(); + org.tron.protos.Protocol.Transaction.raw.Builder rowBuilder = + transaction.getRawData().toBuilder(); rowBuilder.setTimestamp(currentTime); builder.setRawData(rowBuilder.build()); transaction = builder.build(); @@ -447,12 +447,14 @@ private static Transaction signTransaction(Transaction transaction, return transaction; } - - /** - * constructor. - */ - public static boolean participateAssetIssue(byte[] to, byte[] assertName, long amount, - byte[] from, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, + /** constructor. */ + public static boolean participateAssetIssue( + byte[] to, + byte[] assertName, + long amount, + byte[] from, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { ECKey temKey = null; try { @@ -478,12 +480,16 @@ public static boolean participateAssetIssue(byte[] to, byte[] assertName, long a return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - public static boolean participateAssetIssueWithPermissionId(byte[] to, byte[] assertName, - long amount, byte[] from, String priKey, int permissionId, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static boolean participateAssetIssueWithPermissionId( + byte[] to, + byte[] assertName, + long amount, + byte[] from, + String priKey, + int permissionId, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -513,12 +519,16 @@ public static boolean participateAssetIssueWithPermissionId(byte[] to, byte[] as return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - public static String participateAssetIssueForTransactionId(byte[] to, byte[] assertName, - long amount, byte[] from, String priKey, int permissionId, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static String participateAssetIssueForTransactionId( + byte[] to, + byte[] assertName, + long amount, + byte[] from, + String priKey, + int permissionId, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -549,20 +559,24 @@ public static String participateAssetIssueForTransactionId(byte[] to, byte[] ass if (!result) { return null; } - return ByteArray.toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray())); + return ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); } - /** - * constructor. - */ - - public static Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDuration, - String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static Boolean freezeBalance( + byte[] addRess, + long freezeBalance, + long freezeDuration, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { byte[] address = addRess; long frozenBalance = freezeBalance; long frozenDuration = freezeDuration; - //String priKey = testKey002; + // String priKey = testKey002; ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -575,18 +589,20 @@ public static Boolean freezeBalance(byte[] addRess, long freezeBalance, long fre final Long beforeBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Account beforeFronzen = queryAccount(priKey, blockingStubFull); Long beforeFrozenBalance = 0L; - //Long beforeBandwidth = beforeFronzen.getBandwidth(); + // Long beforeBandwidth = beforeFronzen.getBandwidth(); if (beforeFronzen.getFrozenCount() != 0) { beforeFrozenBalance = beforeFronzen.getFrozen(0).getFrozenBalance(); - //beforeBandwidth = beforeFronzen.getBandwidth(); - //logger.info(Long.toString(beforeFronzen.getBandwidth())); + // beforeBandwidth = beforeFronzen.getBandwidth(); + // logger.info(Long.toString(beforeFronzen.getBandwidth())); logger.info(Long.toString(beforeFronzen.getFrozen(0).getFrozenBalance())); } FreezeBalanceContract.Builder builder = FreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess).setFrozenBalance(frozenBalance) + builder + .setOwnerAddress(byteAddreess) + .setFrozenBalance(frozenBalance) .setFrozenDuration(frozenDuration); FreezeBalanceContract contract = builder.build(); @@ -601,38 +617,47 @@ public static Boolean freezeBalance(byte[] addRess, long freezeBalance, long fre transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); return broadcastTransaction(transaction, blockingStubFull); - } - - /** - * constructor. - */ - - public static Boolean freezeBalanceWithPermissionId(byte[] addRess, long freezeBalance, - long freezeDuration, int permissionId, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { - if(PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { - return freezeBalanceV2WithPermissionId(addRess,freezeBalance, - 0,permissionId,priKey,blockingStubFull,permissionKeyString); + /** constructor. */ + public static Boolean freezeBalanceWithPermissionId( + byte[] addRess, + long freezeBalance, + long freezeDuration, + int permissionId, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { + if (PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + return freezeBalanceV2WithPermissionId( + addRess, freezeBalance, 0, permissionId, priKey, blockingStubFull, permissionKeyString); } else { - return freezeBalanceV1WithPermissionId(addRess,freezeBalance,freezeDuration,0,permissionId, - priKey,blockingStubFull,permissionKeyString); + return freezeBalanceV1WithPermissionId( + addRess, + freezeBalance, + freezeDuration, + 0, + permissionId, + priKey, + blockingStubFull, + permissionKeyString); } - } - /** - * constructor. - */ - - public static Boolean freezeBalanceV1WithPermissionId(byte[] addRess, long freezeBalance, - long freezeDuration, int resourceCode, int permissionId, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static Boolean freezeBalanceV1WithPermissionId( + byte[] addRess, + long freezeBalance, + long freezeDuration, + int resourceCode, + int permissionId, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { byte[] address = addRess; long frozenBalance = freezeBalance; long frozenDuration = freezeDuration; - //String priKey = testKey002; + // String priKey = testKey002; ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -645,19 +670,22 @@ public static Boolean freezeBalanceV1WithPermissionId(byte[] addRess, long freez final Long beforeBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Account beforeFronzen = queryAccount(priKey, blockingStubFull); Long beforeFrozenBalance = 0L; - //Long beforeBandwidth = beforeFronzen.getBandwidth(); + // Long beforeBandwidth = beforeFronzen.getBandwidth(); if (beforeFronzen.getFrozenCount() != 0) { beforeFrozenBalance = beforeFronzen.getFrozen(0).getFrozenBalance(); - //beforeBandwidth = beforeFronzen.getBandwidth(); - //logger.info(Long.toString(beforeFronzen.getBandwidth())); + // beforeBandwidth = beforeFronzen.getBandwidth(); + // logger.info(Long.toString(beforeFronzen.getBandwidth())); logger.info(Long.toString(beforeFronzen.getFrozen(0).getFrozenBalance())); } FreezeBalanceContract.Builder builder = FreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess).setFrozenBalance(frozenBalance) - .setFrozenDuration(frozenDuration).setResourceValue(resourceCode); + builder + .setOwnerAddress(byteAddreess) + .setFrozenBalance(frozenBalance) + .setFrozenDuration(frozenDuration) + .setResourceValue(resourceCode); FreezeBalanceContract contract = builder.build(); Transaction transaction = blockingStubFull.freezeBalance(contract); @@ -677,16 +705,17 @@ public static Boolean freezeBalanceV1WithPermissionId(byte[] addRess, long freez transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); return broadcastTransaction(transaction, blockingStubFull); - } - - /** - * constructor. - */ - public static Boolean freezeBalanceV2WithPermissionId(byte[] addRess, long freezeBalance, - int resourceCode, int permissionId, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static Boolean freezeBalanceV2WithPermissionId( + byte[] addRess, + long freezeBalance, + int resourceCode, + int permissionId, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { byte[] address = addRess; long frozenBalance = freezeBalance; ECKey temKey = null; @@ -699,7 +728,10 @@ public static Boolean freezeBalanceV2WithPermissionId(byte[] addRess, long freez FreezeBalanceV2Contract.Builder builder = FreezeBalanceV2Contract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess).setFrozenBalance(frozenBalance).setResourceValue(resourceCode); + builder + .setOwnerAddress(byteAddreess) + .setFrozenBalance(frozenBalance) + .setResourceValue(resourceCode); FreezeBalanceV2Contract contract = builder.build(); TransactionExtention transactionExtention = blockingStubFull.freezeBalanceV2(contract); @@ -718,21 +750,23 @@ public static Boolean freezeBalanceV2WithPermissionId(byte[] addRess, long freez transaction = TransactionUtils.setTimestamp(transaction); transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); - freezeV2Txid = ByteArray.toHexString( - Sha256Hash.hash( - CommonParameter.getInstance().isECKeyCryptoEngine(), - transaction.getRawData().toByteArray())); + freezeV2Txid = + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); return broadcastTransaction(transaction, blockingStubFull); - } - - /** - * constructor. - */ - public static Boolean unFreezeBalanceV2WithPermissionId(byte[] addRess, long unFreezeBalance, - int resourceCode, int permissionId, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static Boolean unFreezeBalanceV2WithPermissionId( + byte[] addRess, + long unFreezeBalance, + int resourceCode, + int permissionId, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { byte[] address = addRess; ECKey temKey = null; try { @@ -744,7 +778,10 @@ public static Boolean unFreezeBalanceV2WithPermissionId(byte[] addRess, long unF UnfreezeBalanceV2Contract.Builder builder = UnfreezeBalanceV2Contract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess).setUnfreezeBalance(unFreezeBalance).setResourceValue(resourceCode); + builder + .setOwnerAddress(byteAddreess) + .setUnfreezeBalance(unFreezeBalance) + .setResourceValue(resourceCode); UnfreezeBalanceV2Contract contract = builder.build(); TransactionExtention transactionExtention = blockingStubFull.unfreezeBalanceV2(contract); @@ -763,21 +800,23 @@ public static Boolean unFreezeBalanceV2WithPermissionId(byte[] addRess, long unF transaction = TransactionUtils.setTimestamp(transaction); transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); - freezeV2Txid = ByteArray.toHexString( - Sha256Hash.hash( - CommonParameter.getInstance().isECKeyCryptoEngine(), - transaction.getRawData().toByteArray())); + freezeV2Txid = + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); return broadcastTransaction(transaction, blockingStubFull); - } - /** - * constructor. - */ - - public static Boolean unFreezeBalanceWithPermissionId(byte[] address, String priKey, - int resourceCode, byte[] receiverAddress, int permissionId, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static Boolean unFreezeBalanceWithPermissionId( + byte[] address, + String priKey, + int resourceCode, + byte[] receiverAddress, + int permissionId, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -806,12 +845,16 @@ public static Boolean unFreezeBalanceWithPermissionId(byte[] address, String pri return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - public static Boolean delegateResourceWithPermissionId(byte[] addRess, long delegateBalance, - int resourceCode, byte[] receiverAddress, int permissionId, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static Boolean delegateResourceWithPermissionId( + byte[] addRess, + long delegateBalance, + int resourceCode, + byte[] receiverAddress, + int permissionId, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { byte[] address = addRess; ECKey temKey = null; try { @@ -823,7 +866,10 @@ public static Boolean delegateResourceWithPermissionId(byte[] addRess, long dele DelegateResourceContract.Builder builder = DelegateResourceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess).setBalance(delegateBalance).setResourceValue(resourceCode) + builder + .setOwnerAddress(byteAddreess) + .setBalance(delegateBalance) + .setResourceValue(resourceCode) .setReceiverAddress(ByteString.copyFrom(receiverAddress)); DelegateResourceContract contract = builder.build(); @@ -843,21 +889,24 @@ public static Boolean delegateResourceWithPermissionId(byte[] addRess, long dele transaction = TransactionUtils.setTimestamp(transaction); transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); - freezeV2Txid = ByteArray.toHexString( - Sha256Hash.hash( - CommonParameter.getInstance().isECKeyCryptoEngine(), - transaction.getRawData().toByteArray())); + freezeV2Txid = + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); return broadcastTransaction(transaction, blockingStubFull); - } - - /** - * constructor. - */ - public static Boolean unDelegateResourceWithPermissionId(byte[] addRess, long delegateBalance, - int resourceCode, byte[] receiverAddress, int permissionId, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static Boolean unDelegateResourceWithPermissionId( + byte[] addRess, + long delegateBalance, + int resourceCode, + byte[] receiverAddress, + int permissionId, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { byte[] address = addRess; ECKey temKey = null; try { @@ -869,7 +918,10 @@ public static Boolean unDelegateResourceWithPermissionId(byte[] addRess, long de UnDelegateResourceContract.Builder builder = UnDelegateResourceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess).setBalance(delegateBalance).setResourceValue(resourceCode) + builder + .setOwnerAddress(byteAddreess) + .setBalance(delegateBalance) + .setResourceValue(resourceCode) .setReceiverAddress(ByteString.copyFrom(receiverAddress)); UnDelegateResourceContract contract = builder.build(); @@ -889,20 +941,21 @@ public static Boolean unDelegateResourceWithPermissionId(byte[] addRess, long de transaction = TransactionUtils.setTimestamp(transaction); transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); - freezeV2Txid = ByteArray.toHexString( - Sha256Hash.hash( - CommonParameter.getInstance().isECKeyCryptoEngine(), - transaction.getRawData().toByteArray())); + freezeV2Txid = + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); return broadcastTransaction(transaction, blockingStubFull); - } - - /** - * constructor. - */ - public static Boolean withdrawExpireUnfreezeBalanceWithPermissionId(byte[] addRess, int permissionId, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static Boolean withdrawExpireUnfreezeBalanceWithPermissionId( + byte[] addRess, + int permissionId, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { byte[] address = addRess; ECKey temKey = null; try { @@ -933,19 +986,20 @@ public static Boolean withdrawExpireUnfreezeBalanceWithPermissionId(byte[] addRe transaction = TransactionUtils.setTimestamp(transaction); transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); - freezeV2Txid = ByteArray.toHexString( - Sha256Hash.hash( - CommonParameter.getInstance().isECKeyCryptoEngine(), - transaction.getRawData().toByteArray())); + freezeV2Txid = + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); return broadcastTransaction(transaction, blockingStubFull); - } - /** - * constructor. - */ - public static Boolean cancelAllUnfreezeWithPermissionId(byte[] addRess, int permissionId, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static Boolean cancelAllUnfreezeWithPermissionId( + byte[] addRess, + int permissionId, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { byte[] address = addRess; CancelAllUnfreezeV2Contract.Builder builder = CancelAllUnfreezeV2Contract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); @@ -969,19 +1023,21 @@ public static Boolean cancelAllUnfreezeWithPermissionId(byte[] addRess, int perm transaction = TransactionUtils.setTimestamp(transaction); transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); - cancelUnfreezeTxId = ByteArray.toHexString( - Sha256Hash.hash( - CommonParameter.getInstance().isECKeyCryptoEngine(), - transaction.getRawData().toByteArray())); + cancelUnfreezeTxId = + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); return broadcastTransaction(transaction, blockingStubFull); - } - /** - * constructor. - */ - public static Boolean unFreezeBalance(byte[] address, String priKey, int resourceCode, - byte[] receiverAddress, WalletGrpc.WalletBlockingStub blockingStubFull, + /** constructor. */ + public static Boolean unFreezeBalance( + byte[] address, + String priKey, + int resourceCode, + byte[] receiverAddress, + WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { ECKey temKey = null; try { @@ -1006,12 +1062,14 @@ public static Boolean unFreezeBalance(byte[] address, String priKey, int resourc return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - - public static Boolean sendcoin(byte[] to, long amount, byte[] owner, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static Boolean sendcoin( + byte[] to, + long amount, + byte[] owner, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -1020,7 +1078,7 @@ public static Boolean sendcoin(byte[] to, long amount, byte[] owner, String priK ex.printStackTrace(); } final ECKey ecKey = temKey; - //Protocol.Account search = queryAccount(priKey, blockingStubFull); + // Protocol.Account search = queryAccount(priKey, blockingStubFull); TransferContract.Builder builder = TransferContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); @@ -1038,16 +1096,17 @@ public static Boolean sendcoin(byte[] to, long amount, byte[] owner, String priK transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); return broadcastTransaction(transaction, blockingStubFull); - } - /** - * constructor. - */ - - public static String sendcoinGetTransactionHex(byte[] to, long amount, byte[] owner, - String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { - //String priKey = testKey002; + /** constructor. */ + public static String sendcoinGetTransactionHex( + byte[] to, + long amount, + byte[] owner, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { + // String priKey = testKey002; ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -1056,7 +1115,7 @@ public static String sendcoinGetTransactionHex(byte[] to, long amount, byte[] ow ex.printStackTrace(); } final ECKey ecKey = temKey; - //Protocol.Account search = queryAccount(priKey, blockingStubFull); + // Protocol.Account search = queryAccount(priKey, blockingStubFull); TransferContract.Builder builder = TransferContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); @@ -1073,18 +1132,22 @@ public static String sendcoinGetTransactionHex(byte[] to, long amount, byte[] ow } transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); - logger.info("HEX transaction is : " + "transaction hex string is " + ByteArray - .toHexString(transaction.toByteArray())); + logger.info( + "HEX transaction is : " + + "transaction hex string is " + + ByteArray.toHexString(transaction.toByteArray())); return ByteArray.toHexString(transaction.toByteArray()); - } - - /** - * constructor. - */ - public static boolean updateAsset(byte[] address, byte[] description, byte[] url, long newLimit, - long newPublicLimit, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, + /** constructor. */ + public static boolean updateAsset( + byte[] address, + byte[] description, + byte[] url, + long newLimit, + long newPublicLimit, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { ECKey temKey = null; try { @@ -1114,12 +1177,17 @@ public static boolean updateAsset(byte[] address, byte[] description, byte[] url return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - public static boolean updateAssetWithPermissionId(byte[] address, byte[] description, byte[] url, - long newLimit, long newPublicLimit, String priKey, int permissionId, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static boolean updateAssetWithPermissionId( + byte[] address, + byte[] description, + byte[] url, + long newLimit, + long newPublicLimit, + String priKey, + int permissionId, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -1154,12 +1222,17 @@ public static boolean updateAssetWithPermissionId(byte[] address, byte[] descrip return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - public static String updateAssetForTransactionId(byte[] address, byte[] description, byte[] url, - long newLimit, long newPublicLimit, String priKey, int permissionId, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static String updateAssetForTransactionId( + byte[] address, + byte[] description, + byte[] url, + long newLimit, + long newPublicLimit, + String priKey, + int permissionId, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -1195,17 +1268,22 @@ public static String updateAssetForTransactionId(byte[] address, byte[] descript if (!result) { return null; } else { - return ByteArray.toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray())); + return ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); } } - /** - * constructor. - */ - - public static boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] address, - String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static boolean transferAsset( + byte[] to, + byte[] assertName, + long amount, + byte[] address, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -1240,13 +1318,16 @@ public static boolean transferAsset(byte[] to, byte[] assertName, long amount, b return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - - public static boolean transferAssetWithpermissionId(byte[] to, byte[] assertName, long amount, - byte[] address, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, - int permissionId, String[] permissionKeyString) { + /** constructor. */ + public static boolean transferAssetWithpermissionId( + byte[] to, + byte[] assertName, + long amount, + byte[] address, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + int permissionId, + String[] permissionKeyString) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -1290,12 +1371,14 @@ public static boolean transferAssetWithpermissionId(byte[] to, byte[] assertName return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - - public static String transferAssetForTransactionId(byte[] to, byte[] assertName, long amount, - byte[] address, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, + /** constructor. */ + public static String transferAssetForTransactionId( + byte[] to, + byte[] assertName, + long amount, + byte[] address, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { ECKey temKey = null; try { @@ -1332,17 +1415,20 @@ public static String transferAssetForTransactionId(byte[] to, byte[] assertName, if (!result) { return null; } else { - return ByteArray.toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray())); + return ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); } } - /** - * constructor. - */ - - public static boolean updateAccount(byte[] addressBytes, byte[] accountNameBytes, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static boolean updateAccount( + byte[] addressBytes, + byte[] accountNameBytes, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -1371,10 +1457,7 @@ public static boolean updateAccount(byte[] addressBytes, byte[] accountNameBytes return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ public static boolean waitProduceNextBlock(WalletGrpc.WalletBlockingStub blockingStubFull) { Block currentBlock = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()); final Long currentNum = currentBlock.getBlockHeader().getRawData().getNumber(); @@ -1404,12 +1487,13 @@ public static boolean waitProduceNextBlock(WalletGrpc.WalletBlockingStub blockin return true; } - /** - * constructor. - */ - - public static boolean createAccount(byte[] ownerAddress, byte[] newAddress, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static boolean createAccount( + byte[] ownerAddress, + byte[] newAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -1431,15 +1515,15 @@ public static boolean createAccount(byte[] ownerAddress, byte[] newAddress, Stri transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); return broadcastTransaction(transaction, blockingStubFull); - } - /** - * constructor. - */ - - public static boolean createAccountWhtiPermissionId(byte[] ownerAddress, byte[] newAddress, - String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, int permissionId, + /** constructor. */ + public static boolean createAccountWhtiPermissionId( + byte[] ownerAddress, + byte[] newAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + int permissionId, String[] permissionKeyString) { ECKey temKey = null; try { @@ -1480,15 +1564,14 @@ public static boolean createAccountWhtiPermissionId(byte[] ownerAddress, byte[] transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); return broadcastTransaction(transaction, blockingStubFull); - } - /** - * constructor. - */ - - public static boolean createProposal(byte[] ownerAddress, String priKey, - HashMap parametersMap, WalletGrpc.WalletBlockingStub blockingStubFull, + /** constructor. */ + public static boolean createProposal( + byte[] ownerAddress, + String priKey, + HashMap parametersMap, + WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { ECKey temKey = null; try { @@ -1527,13 +1610,14 @@ public static boolean createProposal(byte[] ownerAddress, String priKey, return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - - public static boolean createProposalWithPermissionId(byte[] ownerAddress, String priKey, - HashMap parametersMap, int permissionId, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static boolean createProposalWithPermissionId( + byte[] ownerAddress, + String priKey, + HashMap parametersMap, + int permissionId, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -1576,12 +1660,13 @@ public static boolean createProposalWithPermissionId(byte[] ownerAddress, String return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - - public static boolean approveProposal(byte[] ownerAddress, String priKey, long id, - boolean isAddApproval, WalletGrpc.WalletBlockingStub blockingStubFull, + /** constructor. */ + public static boolean approveProposal( + byte[] ownerAddress, + String priKey, + long id, + boolean isAddApproval, + WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { ECKey temKey = null; try { @@ -1620,12 +1705,14 @@ public static boolean approveProposal(byte[] ownerAddress, String priKey, long i return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - - public static boolean approveProposalWithPermission(byte[] ownerAddress, String priKey, long id, - boolean isAddApproval, int permissionId, WalletGrpc.WalletBlockingStub blockingStubFull, + /** constructor. */ + public static boolean approveProposalWithPermission( + byte[] ownerAddress, + String priKey, + long id, + boolean isAddApproval, + int permissionId, + WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { ECKey temKey = null; try { @@ -1669,12 +1756,13 @@ public static boolean approveProposalWithPermission(byte[] ownerAddress, String return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - - public static boolean deleteProposal(byte[] ownerAddress, String priKey, long id, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static boolean deleteProposal( + byte[] ownerAddress, + String priKey, + long id, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -1712,12 +1800,13 @@ public static boolean deleteProposal(byte[] ownerAddress, String priKey, long id return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - - public static boolean deleteProposalWithPermissionId(byte[] ownerAddress, String priKey, long id, - int permissionId, WalletGrpc.WalletBlockingStub blockingStubFull, + /** constructor. */ + public static boolean deleteProposalWithPermissionId( + byte[] ownerAddress, + String priKey, + long id, + int permissionId, + WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { ECKey temKey = null; try { @@ -1761,11 +1850,11 @@ public static boolean deleteProposalWithPermissionId(byte[] ownerAddress, String return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - - public static boolean setAccountId(byte[] accountIdBytes, byte[] ownerAddress, String priKey, + /** constructor. */ + public static boolean setAccountId( + byte[] accountIdBytes, + byte[] ownerAddress, + String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { @@ -1792,13 +1881,15 @@ public static boolean setAccountId(byte[] accountIdBytes, byte[] ownerAddress, S return response.getResult(); } - /** - * constructor. - */ - - public static Boolean freezeBalanceGetEnergy(byte[] addRess, long freezeBalance, - long freezeDuration, int resourceCode, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static Boolean freezeBalanceGetEnergy( + byte[] addRess, + long freezeBalance, + long freezeDuration, + int resourceCode, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { byte[] address = addRess; long frozenBalance = freezeBalance; long frozenDuration = freezeDuration; @@ -1814,8 +1905,11 @@ public static Boolean freezeBalanceGetEnergy(byte[] addRess, long freezeBalance, FreezeBalanceContract.Builder builder = FreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess).setFrozenBalance(frozenBalance) - .setFrozenDuration(frozenDuration).setResourceValue(resourceCode); + builder + .setOwnerAddress(byteAddreess) + .setFrozenBalance(frozenBalance) + .setFrozenDuration(frozenDuration) + .setResourceValue(resourceCode); FreezeBalanceContract contract = builder.build(); Transaction transaction = blockingStubFull.freezeBalance(contract); @@ -1830,26 +1924,54 @@ public static Boolean freezeBalanceGetEnergy(byte[] addRess, long freezeBalance, return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - public static byte[] deployContract(String contractName, String abiString, String code, - String data, Long feeLimit, long value, long consumeUserResourcePercent, - String libraryAddress, String priKey, byte[] ownerAddress, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { - return deployContract(contractName, abiString, code, data, feeLimit, value, - consumeUserResourcePercent, 1000L, "0", 0L, libraryAddress, priKey, ownerAddress, - blockingStubFull, permissionKeyString); + /** constructor. */ + public static byte[] deployContract( + String contractName, + String abiString, + String code, + String data, + Long feeLimit, + long value, + long consumeUserResourcePercent, + String libraryAddress, + String priKey, + byte[] ownerAddress, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { + return deployContract( + contractName, + abiString, + code, + data, + feeLimit, + value, + consumeUserResourcePercent, + 1000L, + "0", + 0L, + libraryAddress, + priKey, + ownerAddress, + blockingStubFull, + permissionKeyString); } - /** - * constructor. - */ - - public static byte[] deployContract(String contractName, String abiString, String code, - String data, Long feeLimit, long value, long consumeUserResourcePercent, - long originEnergyLimit, String tokenId, long tokenValue, String libraryAddress, String priKey, - byte[] ownerAddress, WalletGrpc.WalletBlockingStub blockingStubFull, + /** constructor. */ + public static byte[] deployContract( + String contractName, + String abiString, + String code, + String data, + Long feeLimit, + long value, + long consumeUserResourcePercent, + long originEnergyLimit, + String tokenId, + long tokenValue, + String libraryAddress, + String priKey, + byte[] ownerAddress, + WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { ECKey temKey = null; try { @@ -1866,7 +1988,7 @@ public static byte[] deployContract(String contractName, String abiString, Strin logger.error("abi is null"); return null; } - //byte[] codeBytes = Hex.decode(code); + // byte[] codeBytes = Hex.decode(code); SmartContract.Builder builder = SmartContract.newBuilder(); builder.setName(contractName); builder.setOriginAddress(ByteString.copyFrom(owner)); @@ -1891,25 +2013,25 @@ public static byte[] deployContract(String contractName, String abiString, Strin contractBuilder.setOwnerAddress(ByteString.copyFrom(owner)); contractBuilder.setCallTokenValue(tokenValue); contractBuilder.setTokenId(Long.parseLong(tokenId)); - CreateSmartContract contractDeployContract = contractBuilder.setNewContract(builder.build()) - .build(); + CreateSmartContract contractDeployContract = + contractBuilder.setNewContract(builder.build()).build(); - TransactionExtention transactionExtention = blockingStubFull - .deployContract(contractDeployContract); + TransactionExtention transactionExtention = + blockingStubFull.deployContract(contractDeployContract); if (transactionExtention == null || !transactionExtention.getResult().getResult()) { System.out.println("RPC create trx failed!"); if (transactionExtention != null) { System.out.println("Code = " + transactionExtention.getResult().getCode()); - System.out - .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + System.out.println( + "Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); } return null; } final TransactionExtention.Builder texBuilder = TransactionExtention.newBuilder(); Transaction.Builder transBuilder = Transaction.newBuilder(); - Transaction.raw.Builder rawBuilder = transactionExtention.getTransaction().getRawData() - .toBuilder(); + Transaction.raw.Builder rawBuilder = + transactionExtention.getTransaction().getRawData().toBuilder(); rawBuilder.setFeeLimit(feeLimit); transBuilder.setRawData(rawBuilder); for (int i = 0; i < transactionExtention.getTransaction().getSignatureCount(); i++) { @@ -1925,8 +2047,8 @@ public static byte[] deployContract(String contractName, String abiString, Strin texBuilder.setTxid(transactionExtention.getTxid()); transactionExtention = texBuilder.build(); - byte[] contractAddress = PublicMethod - .generateContractAddress(transactionExtention.getTransaction(), owner); + byte[] contractAddress = + PublicMethod.generateContractAddress(transactionExtention.getTransaction(), owner); System.out.println( "Your smart contract address will be: " + WalletClient.encode58Check(contractAddress)); if (transactionExtention == null) { @@ -1946,8 +2068,11 @@ public static byte[] deployContract(String contractName, String abiString, Strin transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); System.out.println( - "txid = " + ByteArray.toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()))); + "txid = " + + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()))); contractAddress = PublicMethod.generateContractAddress(transaction, owner); System.out.println( "Your smart contract address will be: " + WalletClient.encode58Check(contractAddress)); @@ -1955,27 +2080,57 @@ public static byte[] deployContract(String contractName, String abiString, Strin return contractAddress; } - /** - * constructor. - */ - - public static String deployContractAndGetTransactionInfoById(String contractName, - String abiString, String code, String data, Long feeLimit, long value, - long consumeUserResourcePercent, String libraryAddress, String priKey, byte[] ownerAddress - , int permissionId, String[] permissionKeyString, WalletGrpc.WalletBlockingStub blockingStubFull) { - return deployContractAndGetTransactionInfoById(contractName, abiString, code, data, feeLimit, - value, consumeUserResourcePercent, 1000L, "0", 0L, libraryAddress, priKey, ownerAddress, - permissionId, permissionKeyString, blockingStubFull); + /** constructor. */ + public static String deployContractAndGetTransactionInfoById( + String contractName, + String abiString, + String code, + String data, + Long feeLimit, + long value, + long consumeUserResourcePercent, + String libraryAddress, + String priKey, + byte[] ownerAddress, + int permissionId, + String[] permissionKeyString, + WalletGrpc.WalletBlockingStub blockingStubFull) { + return deployContractAndGetTransactionInfoById( + contractName, + abiString, + code, + data, + feeLimit, + value, + consumeUserResourcePercent, + 1000L, + "0", + 0L, + libraryAddress, + priKey, + ownerAddress, + permissionId, + permissionKeyString, + blockingStubFull); } - /** - * constructor. - */ - - public static String deployContractAndGetTransactionInfoById(String contractName, - String abiString, String code, String data, Long feeLimit, long value, - long consumeUserResourcePercent, long originEnergyLimit, String tokenId, long tokenValue, - String libraryAddress, String priKey, byte[] ownerAddress, int permissionId, String[] permissionKey, + /** constructor. */ + public static String deployContractAndGetTransactionInfoById( + String contractName, + String abiString, + String code, + String data, + Long feeLimit, + long value, + long consumeUserResourcePercent, + long originEnergyLimit, + String tokenId, + long tokenValue, + String libraryAddress, + String priKey, + byte[] ownerAddress, + int permissionId, + String[] permissionKey, WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { @@ -1992,7 +2147,7 @@ public static String deployContractAndGetTransactionInfoById(String contractName logger.error("abi is null"); return null; } - //byte[] codeBytes = Hex.decode(code); + // byte[] codeBytes = Hex.decode(code); SmartContract.Builder builder = SmartContract.newBuilder(); builder.setName(contractName); builder.setOriginAddress(ByteString.copyFrom(owner)); @@ -2017,28 +2172,25 @@ public static String deployContractAndGetTransactionInfoById(String contractName contractBuilder.setOwnerAddress(ByteString.copyFrom(owner)); contractBuilder.setCallTokenValue(tokenValue); contractBuilder.setTokenId(Long.parseLong(tokenId)); - CreateSmartContract contractDeployContract = contractBuilder.setNewContract(builder.build()) - .build(); + CreateSmartContract contractDeployContract = + contractBuilder.setNewContract(builder.build()).build(); - TransactionExtention transactionExtention = blockingStubFull - .deployContract(contractDeployContract); + TransactionExtention transactionExtention = + blockingStubFull.deployContract(contractDeployContract); if (transactionExtention == null || !transactionExtention.getResult().getResult()) { System.out.println("RPC create trx failed!"); if (transactionExtention != null) { System.out.println("Code = " + transactionExtention.getResult().getCode()); - System.out - .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + System.out.println( + "Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); } return null; } - - - final TransactionExtention.Builder texBuilder = TransactionExtention.newBuilder(); Transaction.Builder transBuilder = Transaction.newBuilder(); - Transaction.raw.Builder rawBuilder = transactionExtention.getTransaction().getRawData() - .toBuilder(); + Transaction.raw.Builder rawBuilder = + transactionExtention.getTransaction().getRawData().toBuilder(); rawBuilder.setFeeLimit(feeLimit); transBuilder.setRawData(rawBuilder); for (int i = 0; i < transactionExtention.getTransaction().getSignatureCount(); i++) { @@ -2075,8 +2227,11 @@ public static String deployContractAndGetTransactionInfoById(String contractName } transaction = signTransaction(transaction, blockingStubFull, permissionKey); System.out.println( - "txid = " + ByteArray.toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()))); + "txid = " + + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()))); byte[] contractAddress = PublicMethod.generateContractAddress(transaction, owner); System.out.println( "Your smart contract address will be: " + WalletClient.encode58Check(contractAddress)); @@ -2084,15 +2239,14 @@ public static String deployContractAndGetTransactionInfoById(String contractName if (response.getResult() == false) { return null; } else { - return ByteArray.toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray())); + return ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); } } - /** - * constructor. - */ - + /** constructor. */ public static SmartContract.ABI jsonStr2Abi(String jsonStr) { if (jsonStr == null) { return null; @@ -2105,29 +2259,37 @@ public static SmartContract.ABI jsonStr2Abi(String jsonStr) { for (int index = 0; index < jsonRoot.size(); index++) { JsonElement abiItem = jsonRoot.get(index); boolean anonymous = - abiItem.getAsJsonObject().get("anonymous") != null ? abiItem.getAsJsonObject() - .get("anonymous").getAsBoolean() : false; + abiItem.getAsJsonObject().get("anonymous") != null + ? abiItem.getAsJsonObject().get("anonymous").getAsBoolean() + : false; final boolean constant = - abiItem.getAsJsonObject().get("constant") != null ? abiItem.getAsJsonObject() - .get("constant").getAsBoolean() : false; + abiItem.getAsJsonObject().get("constant") != null + ? abiItem.getAsJsonObject().get("constant").getAsBoolean() + : false; final String name = - abiItem.getAsJsonObject().get("name") != null ? abiItem.getAsJsonObject().get("name") - .getAsString() : null; + abiItem.getAsJsonObject().get("name") != null + ? abiItem.getAsJsonObject().get("name").getAsString() + : null; JsonArray inputs = - abiItem.getAsJsonObject().get("inputs") != null ? abiItem.getAsJsonObject().get("inputs") - .getAsJsonArray() : null; + abiItem.getAsJsonObject().get("inputs") != null + ? abiItem.getAsJsonObject().get("inputs").getAsJsonArray() + : null; final JsonArray outputs = - abiItem.getAsJsonObject().get("outputs") != null ? abiItem.getAsJsonObject() - .get("outputs").getAsJsonArray() : null; + abiItem.getAsJsonObject().get("outputs") != null + ? abiItem.getAsJsonObject().get("outputs").getAsJsonArray() + : null; String type = - abiItem.getAsJsonObject().get("type") != null ? abiItem.getAsJsonObject().get("type") - .getAsString() : null; + abiItem.getAsJsonObject().get("type") != null + ? abiItem.getAsJsonObject().get("type").getAsString() + : null; final boolean payable = - abiItem.getAsJsonObject().get("payable") != null ? abiItem.getAsJsonObject() - .get("payable").getAsBoolean() : false; + abiItem.getAsJsonObject().get("payable") != null + ? abiItem.getAsJsonObject().get("payable").getAsBoolean() + : false; final String stateMutability = - abiItem.getAsJsonObject().get("stateMutability") != null ? abiItem.getAsJsonObject() - .get("stateMutability").getAsString() : null; + abiItem.getAsJsonObject().get("stateMutability") != null + ? abiItem.getAsJsonObject().get("stateMutability").getAsString() + : null; if (type == null) { logger.error("No type!"); return null; @@ -2155,8 +2317,8 @@ public static SmartContract.ABI jsonStr2Abi(String jsonStr) { } String inputName = inputItem.getAsJsonObject().get("name").getAsString(); String inputType = inputItem.getAsJsonObject().get("type").getAsString(); - SmartContract.ABI.Entry.Param.Builder paramBuilder = SmartContract.ABI.Entry.Param - .newBuilder(); + SmartContract.ABI.Entry.Param.Builder paramBuilder = + SmartContract.ABI.Entry.Param.newBuilder(); paramBuilder.setIndexed(false); paramBuilder.setName(inputName); paramBuilder.setType(inputType); @@ -2175,8 +2337,8 @@ public static SmartContract.ABI jsonStr2Abi(String jsonStr) { } String outputName = outputItem.getAsJsonObject().get("name").getAsString(); String outputType = outputItem.getAsJsonObject().get("type").getAsString(); - SmartContract.ABI.Entry.Param.Builder paramBuilder = SmartContract.ABI.Entry.Param - .newBuilder(); + SmartContract.ABI.Entry.Param.Builder paramBuilder = + SmartContract.ABI.Entry.Param.newBuilder(); paramBuilder.setIndexed(false); paramBuilder.setName(outputName); paramBuilder.setType(outputType); @@ -2196,10 +2358,7 @@ public static SmartContract.ABI jsonStr2Abi(String jsonStr) { return abiBuilder.build(); } - /** - * constructor. - */ - + /** constructor. */ public static SmartContract.ABI.Entry.EntryType getEntryType(String type) { switch (type) { case "constructor": @@ -2215,10 +2374,7 @@ public static SmartContract.ABI.Entry.EntryType getEntryType(String type) { } } - /** - * constructor. - */ - + /** constructor. */ public static SmartContract.ABI.Entry.StateMutabilityType getStateMutability( String stateMutability) { switch (stateMutability) { @@ -2235,12 +2391,9 @@ public static SmartContract.ABI.Entry.StateMutabilityType getStateMutability( } } - /** - * constructor. - */ - - public static SmartContract getContract(byte[] address, - WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public static SmartContract getContract( + byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString byteString = ByteString.copyFrom(address); BytesMessage bytesMessage = BytesMessage.newBuilder().setValue(byteString).build(); Integer i = 0; @@ -2269,8 +2422,8 @@ private static byte[] replaceLibraryAddress(String code, String libraryAddressPa } String libraryName = cur.substring(0, lastPosition); String addr = cur.substring(lastPosition + 1); - String libraryAddressHex = ByteArray.toHexString(WalletClient.decodeFromBase58Check(addr)) - .substring(2); + String libraryAddressHex = + ByteArray.toHexString(WalletClient.decodeFromBase58Check(addr)).substring(2); String repeated = new String(new char[40 - libraryName.length() - 2]).replace("\0", "_"); String beReplaced = "__" + libraryName + repeated; @@ -2290,12 +2443,13 @@ private static byte[] replaceLibraryAddress_1(String code, byte[] libraryAddress return Hex.decode(code); } - /** - * constructor. - */ - - public static boolean updateSetting(byte[] contractAddress, long consumeUserResourcePercent, - String priKey, byte[] ownerAddress, WalletGrpc.WalletBlockingStub blockingStubFull, + /** constructor. */ + public static boolean updateSetting( + byte[] contractAddress, + long consumeUserResourcePercent, + String priKey, + byte[] ownerAddress, + WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { ECKey temKey = null; try { @@ -2313,14 +2467,14 @@ public static boolean updateSetting(byte[] contractAddress, long consumeUserReso builder.setConsumeUserResourcePercent(consumeUserResourcePercent); UpdateSettingContract updateSettingContract = builder.build(); - TransactionExtention transactionExtention = blockingStubFull - .updateSetting(updateSettingContract); + TransactionExtention transactionExtention = + blockingStubFull.updateSetting(updateSettingContract); if (transactionExtention == null || !transactionExtention.getResult().getResult()) { System.out.println("RPC create trx failed!"); if (transactionExtention != null) { System.out.println("Code = " + transactionExtention.getResult().getCode()); - System.out - .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + System.out.println( + "Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); } return false; } @@ -2345,13 +2499,15 @@ public static boolean updateSetting(byte[] contractAddress, long consumeUserReso return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - - public static boolean updateSettingWithPermissionId(byte[] contractAddress, - long consumeUserResourcePercent, String priKey, byte[] ownerAddress, int permissionId, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static boolean updateSettingWithPermissionId( + byte[] contractAddress, + long consumeUserResourcePercent, + String priKey, + byte[] ownerAddress, + int permissionId, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -2368,14 +2524,14 @@ public static boolean updateSettingWithPermissionId(byte[] contractAddress, builder.setConsumeUserResourcePercent(consumeUserResourcePercent); UpdateSettingContract updateSettingContract = builder.build(); - TransactionExtention transactionExtention = blockingStubFull - .updateSetting(updateSettingContract); + TransactionExtention transactionExtention = + blockingStubFull.updateSetting(updateSettingContract); if (transactionExtention == null || !transactionExtention.getResult().getResult()) { System.out.println("RPC create trx failed!"); if (transactionExtention != null) { System.out.println("Code = " + transactionExtention.getResult().getCode()); - System.out - .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + System.out.println( + "Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); } return false; } @@ -2405,13 +2561,15 @@ public static boolean updateSettingWithPermissionId(byte[] contractAddress, return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - - public static boolean updateEnergyLimitWithPermissionId(byte[] contractAddress, - long originEnergyLimit, String priKey, byte[] ownerAddress, int permissionId, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static boolean updateEnergyLimitWithPermissionId( + byte[] contractAddress, + long originEnergyLimit, + String priKey, + byte[] ownerAddress, + int permissionId, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -2428,14 +2586,14 @@ public static boolean updateEnergyLimitWithPermissionId(byte[] contractAddress, builder.setOriginEnergyLimit(originEnergyLimit); UpdateEnergyLimitContract updateEnergyLimitContract = builder.build(); - TransactionExtention transactionExtention = blockingStubFull - .updateEnergyLimit(updateEnergyLimitContract); + TransactionExtention transactionExtention = + blockingStubFull.updateEnergyLimit(updateEnergyLimitContract); if (transactionExtention == null || !transactionExtention.getResult().getResult()) { System.out.println("RPC create trx failed!"); if (transactionExtention != null) { System.out.println("Code = " + transactionExtention.getResult().getCode()); - System.out - .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + System.out.println( + "Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); } return false; } @@ -2465,23 +2623,46 @@ public static boolean updateEnergyLimitWithPermissionId(byte[] contractAddress, return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - public static String triggerContract(byte[] contractAddress, String method, String argsStr, - Boolean isHex, long callValue, long feeLimit, byte[] ownerAddress, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { - return triggerContract(contractAddress, method, argsStr, isHex, callValue, feeLimit, "0", 0, - ownerAddress, priKey, blockingStubFull, permissionKeyString); + /** constructor. */ + public static String triggerContract( + byte[] contractAddress, + String method, + String argsStr, + Boolean isHex, + long callValue, + long feeLimit, + byte[] ownerAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { + return triggerContract( + contractAddress, + method, + argsStr, + isHex, + callValue, + feeLimit, + "0", + 0, + ownerAddress, + priKey, + blockingStubFull, + permissionKeyString); } - /** - * constructor. - */ - - public static String triggerContract(byte[] contractAddress, String method, String argsStr, - Boolean isHex, long callValue, long feeLimit, String tokenId, long tokenValue, - byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, + /** constructor. */ + public static String triggerContract( + byte[] contractAddress, + String method, + String argsStr, + Boolean isHex, + long callValue, + long feeLimit, + String tokenId, + long tokenValue, + byte[] ownerAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { ECKey temKey = null; try { @@ -2512,12 +2693,13 @@ public static String triggerContract(byte[] contractAddress, String method, Stri if (transactionExtention == null || !transactionExtention.getResult().getResult()) { System.out.println("RPC create call trx failed!"); System.out.println("Code = " + transactionExtention.getResult().getCode()); - System.out - .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + System.out.println( + "Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); return null; } Transaction transaction = transactionExtention.getTransaction(); - if (transaction.getRetCount() != 0 && transactionExtention.getConstantResult(0) != null + if (transaction.getRetCount() != 0 + && transactionExtention.getConstantResult(0) != null && transactionExtention.getResult() != null) { byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); @@ -2529,8 +2711,8 @@ public static String triggerContract(byte[] contractAddress, String method, Stri final TransactionExtention.Builder texBuilder = TransactionExtention.newBuilder(); Transaction.Builder transBuilder = Transaction.newBuilder(); - Transaction.raw.Builder rawBuilder = transactionExtention.getTransaction().getRawData() - .toBuilder(); + Transaction.raw.Builder rawBuilder = + transactionExtention.getTransaction().getRawData().toBuilder(); rawBuilder.setFeeLimit(feeLimit); transBuilder.setRawData(rawBuilder); for (int i = 0; i < transactionExtention.getTransaction().getSignatureCount(); i++) { @@ -2559,23 +2741,31 @@ public static String triggerContract(byte[] contractAddress, String method, Stri System.out.println("Transaction is empty"); return null; } - System.out.println("trigger txid = " + ByteArray - .toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()))); + System.out.println( + "trigger txid = " + + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()))); transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); broadcastTransaction(transaction, blockingStubFull); - return ByteArray.toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray())); + return ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); } - /** - * constructor. - */ - - public static Boolean exchangeCreate(byte[] firstTokenId, long firstTokenBalance, - byte[] secondTokenId, long secondTokenBalance, byte[] ownerAddress, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static Boolean exchangeCreate( + byte[] firstTokenId, + long firstTokenBalance, + byte[] secondTokenId, + long secondTokenBalance, + byte[] ownerAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -2588,8 +2778,10 @@ public static Boolean exchangeCreate(byte[] firstTokenId, long firstTokenBalance byte[] owner = ownerAddress; ExchangeCreateContract.Builder builder = ExchangeCreateContract.newBuilder(); - builder.setOwnerAddress(ByteString.copyFrom(owner)) - .setFirstTokenId(ByteString.copyFrom(firstTokenId)).setFirstTokenBalance(firstTokenBalance) + builder + .setOwnerAddress(ByteString.copyFrom(owner)) + .setFirstTokenId(ByteString.copyFrom(firstTokenId)) + .setFirstTokenBalance(firstTokenBalance) .setSecondTokenId(ByteString.copyFrom(secondTokenId)) .setSecondTokenBalance(secondTokenBalance); ExchangeCreateContract contract = builder.build(); @@ -2615,12 +2807,14 @@ public static Boolean exchangeCreate(byte[] firstTokenId, long firstTokenBalance return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - - public static Boolean injectExchange(long exchangeId, byte[] tokenId, long quant, - byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, + /** constructor. */ + public static Boolean injectExchange( + long exchangeId, + byte[] tokenId, + long quant, + byte[] ownerAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { ECKey temKey = null; @@ -2635,8 +2829,11 @@ public static Boolean injectExchange(long exchangeId, byte[] tokenId, long quant byte[] owner = ownerAddress; ExchangeInjectContract.Builder builder = ExchangeInjectContract.newBuilder(); - builder.setOwnerAddress(ByteString.copyFrom(owner)).setExchangeId(exchangeId) - .setTokenId(ByteString.copyFrom(tokenId)).setQuant(quant); + builder + .setOwnerAddress(ByteString.copyFrom(owner)) + .setExchangeId(exchangeId) + .setTokenId(ByteString.copyFrom(tokenId)) + .setQuant(quant); ExchangeInjectContract contract = builder.build(); TransactionExtention transactionExtention = blockingStubFull.exchangeInject(contract); if (transactionExtention == null) { @@ -2666,12 +2863,14 @@ public static Optional getExchangeList( return Optional.ofNullable(exchangeList); } - /** - * constructor. - */ - - public static boolean exchangeWithdraw(long exchangeId, byte[] tokenId, long quant, - byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, + /** constructor. */ + public static boolean exchangeWithdraw( + long exchangeId, + byte[] tokenId, + long quant, + byte[] ownerAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { ECKey temKey = null; try { @@ -2684,8 +2883,11 @@ public static boolean exchangeWithdraw(long exchangeId, byte[] tokenId, long qua byte[] owner = ownerAddress; ExchangeWithdrawContract.Builder builder = ExchangeWithdrawContract.newBuilder(); - builder.setOwnerAddress(ByteString.copyFrom(owner)).setExchangeId(exchangeId) - .setTokenId(ByteString.copyFrom(tokenId)).setQuant(quant); + builder + .setOwnerAddress(ByteString.copyFrom(owner)) + .setExchangeId(exchangeId) + .setTokenId(ByteString.copyFrom(tokenId)) + .setQuant(quant); ExchangeWithdrawContract contract = builder.build(); TransactionExtention transactionExtention = blockingStubFull.exchangeWithdraw(contract); if (transactionExtention == null) { @@ -2709,13 +2911,16 @@ public static boolean exchangeWithdraw(long exchangeId, byte[] tokenId, long qua return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - - public static boolean exchangeTransaction(long exchangeId, byte[] tokenId, long quant, - long expected, byte[] ownerAddress, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static boolean exchangeTransaction( + long exchangeId, + byte[] tokenId, + long quant, + long expected, + byte[] ownerAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -2727,8 +2932,12 @@ public static boolean exchangeTransaction(long exchangeId, byte[] tokenId, long byte[] owner = ownerAddress; ExchangeTransactionContract.Builder builder = ExchangeTransactionContract.newBuilder(); - builder.setOwnerAddress(ByteString.copyFrom(owner)).setExchangeId(exchangeId) - .setTokenId(ByteString.copyFrom(tokenId)).setQuant(quant).setExpected(expected); + builder + .setOwnerAddress(ByteString.copyFrom(owner)) + .setExchangeId(exchangeId) + .setTokenId(ByteString.copyFrom(tokenId)) + .setQuant(quant) + .setExpected(expected); ExchangeTransactionContract contract = builder.build(); TransactionExtention transactionExtention = blockingStubFull.exchangeTransaction(contract); if (transactionExtention == null) { @@ -2752,27 +2961,57 @@ public static boolean exchangeTransaction(long exchangeId, byte[] tokenId, long return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - - public static String deployContractWithConstantParame(String contractName, String abiString, - String code, String constructorStr, String argsStr, String data, Long feeLimit, long value, - long consumeUserResourcePercent, String libraryAddress, String priKey, byte[] ownerAddress, + /** constructor. */ + public static String deployContractWithConstantParame( + String contractName, + String abiString, + String code, + String constructorStr, + String argsStr, + String data, + Long feeLimit, + long value, + long consumeUserResourcePercent, + String libraryAddress, + String priKey, + byte[] ownerAddress, WalletGrpc.WalletBlockingStub blockingStubFull) { - return deployContractWithConstantParame(contractName, abiString, code, constructorStr, argsStr, - data, feeLimit, value, consumeUserResourcePercent, 1000L, "0", 0L, libraryAddress, priKey, - ownerAddress, blockingStubFull); + return deployContractWithConstantParame( + contractName, + abiString, + code, + constructorStr, + argsStr, + data, + feeLimit, + value, + consumeUserResourcePercent, + 1000L, + "0", + 0L, + libraryAddress, + priKey, + ownerAddress, + blockingStubFull); } - /** - * constructor. - */ - - public static String deployContractWithConstantParame(String contractName, String abiString, - String code, String constructorStr, String argsStr, String data, Long feeLimit, long value, - long consumeUserResourcePercent, long originEnergyLimit, String tokenId, long tokenValue, - String libraryAddress, String priKey, byte[] ownerAddress, + /** constructor. */ + public static String deployContractWithConstantParame( + String contractName, + String abiString, + String code, + String constructorStr, + String argsStr, + String data, + Long feeLimit, + long value, + long consumeUserResourcePercent, + long originEnergyLimit, + String tokenId, + long tokenValue, + String libraryAddress, + String priKey, + byte[] ownerAddress, WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { @@ -2815,25 +3054,25 @@ public static String deployContractWithConstantParame(String contractName, Strin contractBuilder.setOwnerAddress(ByteString.copyFrom(owner)); contractBuilder.setCallTokenValue(tokenValue); contractBuilder.setTokenId(Long.parseLong(tokenId)); - CreateSmartContract contractDeployContract = contractBuilder.setNewContract(builder.build()) - .build(); + CreateSmartContract contractDeployContract = + contractBuilder.setNewContract(builder.build()).build(); - TransactionExtention transactionExtention = blockingStubFull - .deployContract(contractDeployContract); + TransactionExtention transactionExtention = + blockingStubFull.deployContract(contractDeployContract); if (transactionExtention == null || !transactionExtention.getResult().getResult()) { System.out.println("RPC create trx failed!"); if (transactionExtention != null) { System.out.println("Code = " + transactionExtention.getResult().getCode()); - System.out - .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + System.out.println( + "Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); } return null; } final TransactionExtention.Builder texBuilder = TransactionExtention.newBuilder(); Transaction.Builder transBuilder = Transaction.newBuilder(); - Transaction.raw.Builder rawBuilder = transactionExtention.getTransaction().getRawData() - .toBuilder(); + Transaction.raw.Builder rawBuilder = + transactionExtention.getTransaction().getRawData().toBuilder(); rawBuilder.setFeeLimit(feeLimit); transBuilder.setRawData(rawBuilder); for (int i = 0; i < transactionExtention.getTransaction().getSignatureCount(); i++) { @@ -2865,8 +3104,11 @@ public static String deployContractWithConstantParame(String contractName, Strin } transaction = signTransaction(ecKey, transaction); System.out.println( - "txid = " + ByteArray.toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()))); + "txid = " + + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()))); byte[] contractAddress = PublicMethod.generateContractAddress(transaction, owner); System.out.println( "Your smart contract address will be: " + WalletClient.encode58Check(contractAddress)); @@ -2874,19 +3116,24 @@ public static String deployContractWithConstantParame(String contractName, Strin if (response.getResult() == false) { return null; } else { - //logger.info("brodacast succesfully"); - return ByteArray.toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray())); + // logger.info("brodacast succesfully"); + return ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); } } - /** - * constructor. - */ - - public static Boolean freezeBalanceForReceiver(byte[] addRess, long freezeBalance, - long freezeDuration, int resourceCode, ByteString receiverAddressBytes, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static Boolean freezeBalanceForReceiver( + byte[] addRess, + long freezeBalance, + long freezeDuration, + int resourceCode, + ByteString receiverAddressBytes, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { byte[] address = addRess; long frozenBalance = freezeBalance; long frozenDuration = freezeDuration; @@ -2902,8 +3149,11 @@ public static Boolean freezeBalanceForReceiver(byte[] addRess, long freezeBalanc FreezeBalanceContract.Builder builder = FreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess).setFrozenBalance(frozenBalance) - .setFrozenDuration(frozenDuration).setResourceValue(resourceCode); + builder + .setOwnerAddress(byteAddreess) + .setFrozenBalance(frozenBalance) + .setFrozenDuration(frozenDuration) + .setResourceValue(resourceCode); builder.setReceiverAddress(receiverAddressBytes); FreezeBalanceContract contract = builder.build(); Transaction transaction = blockingStubFull.freezeBalance(contract); @@ -2959,12 +3209,13 @@ private static Permission json2Permission(JSONObject json) { return permissionBuilder.build(); } - /** - * constructor. - */ - - public static boolean accountPermissionUpdate(String permissionJson, byte[] owner, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] priKeys) { + /** constructor. */ + public static boolean accountPermissionUpdate( + String permissionJson, + byte[] owner, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] priKeys) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -3018,18 +3269,23 @@ public static boolean accountPermissionUpdate(String permissionJson, byte[] owne } transaction = signTransaction(transaction, blockingStubFull, priKeys); - System.out.println("trigger txid = " + ByteArray - .toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()))); + System.out.println( + "trigger txid = " + + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()))); Return response = broadcastTransaction1(transaction, blockingStubFull); return response.getResult(); } - /** - * constructor. - */ - public static String accountPermissionUpdateForTransactionId(String permissionJson, byte[] owner, - String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, String[] priKeys) { + /** constructor. */ + public static String accountPermissionUpdateForTransactionId( + String permissionJson, + byte[] owner, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] priKeys) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -3089,17 +3345,20 @@ public static String accountPermissionUpdateForTransactionId(String permissionJs if (response.getResult() == false) { return null; } else { - return ByteArray.toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray())); + return ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); } } - - /** - * constructor. - */ - public static String accountPermissionUpdateForTransactionId1(String permissionJson, byte[] owner, - String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, int permissionId, + /** constructor. */ + public static String accountPermissionUpdateForTransactionId1( + String permissionJson, + byte[] owner, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + int permissionId, String[] priKeys) { ECKey temKey = null; try { @@ -3165,16 +3424,16 @@ public static String accountPermissionUpdateForTransactionId1(String permissionJ if (response.getResult() == false) { return null; } else { - return ByteArray.toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray())); + return ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); } } - /** - * constructor. - */ - public static Transaction addTransactionSign(Transaction transaction, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public static Transaction addTransactionSign( + Transaction transaction, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -3185,8 +3444,10 @@ public static Transaction addTransactionSign(Transaction transaction, String pri ECKey ecKey = temKey; Transaction.Builder transactionBuilderSigned = transaction.toBuilder(); - byte[] hash = Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()); + byte[] hash = + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()); ECDSASignature signature = ecKey.sign(hash); ByteString bsSign = ByteString.copyFrom(signature.toByteArray()); @@ -3195,11 +3456,13 @@ public static Transaction addTransactionSign(Transaction transaction, String pri return transaction; } - /** - * constructor. - */ - public static Boolean voteWitness(HashMap witness, byte[] addRess, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { + /** constructor. */ + public static Boolean voteWitness( + HashMap witness, + byte[] addRess, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { ECKey temKey = null; try { @@ -3237,9 +3500,7 @@ public static Boolean voteWitness(HashMap witness, byte[] addRes return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ public static void printPermissionList(List permissionList) { String result = "\n"; result += "["; @@ -3260,9 +3521,7 @@ public static void printPermissionList(List permissionList) { System.out.println(result); } - /** - * constructor. - */ + /** constructor. */ public static String printPermission(Permission permission) { StringBuffer result = new StringBuffer(); result.append("permission_type: "); @@ -3297,9 +3556,7 @@ public static String printPermission(Permission permission) { return result.toString(); } - /** - * constructor. - */ + /** constructor. */ public static String printKey(Key key) { StringBuffer result = new StringBuffer(); result.append("address: "); @@ -3311,26 +3568,25 @@ public static String printKey(Key key) { return result.toString(); } - /** - * constructor. - */ + /** constructor. */ public static String encode58Check(byte[] input) { - byte[] hash0 = Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), input); - byte[] hash1 = Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), hash0); + byte[] hash0 = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), input); + byte[] hash1 = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), hash0); byte[] inputCheck = new byte[input.length + 4]; System.arraycopy(input, 0, inputCheck, 0, input.length); System.arraycopy(hash1, 0, inputCheck, input.length, 4); return Base58.encode(inputCheck); } - /** - * constructor. - */ - public static Transaction sendcoinWithPermissionIdNotSign(byte[] to, long amount, byte[] owner, - int permissionId, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - //String priKey = testKey002; + /** constructor. */ + public static Transaction sendcoinWithPermissionIdNotSign( + byte[] to, + long amount, + byte[] owner, + int permissionId, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull) { + // String priKey = testKey002; ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -3339,7 +3595,7 @@ public static Transaction sendcoinWithPermissionIdNotSign(byte[] to, long amount ex.printStackTrace(); } final ECKey ecKey = temKey; - //Protocol.Account search = queryAccount(priKey, blockingStubFull); + // Protocol.Account search = queryAccount(priKey, blockingStubFull); TransferContract.Builder builder = TransferContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); @@ -3353,38 +3609,35 @@ public static Transaction sendcoinWithPermissionIdNotSign(byte[] to, long amount Transaction transaction = transactionExtention.getTransaction(); raw rawData = transaction.getRawData(); - Transaction.Contract contract1 = transactionExtention.getTransaction().getRawData() - .getContractList().get(0); + Transaction.Contract contract1 = + transactionExtention.getTransaction().getRawData().getContractList().get(0); contract1 = contract1.toBuilder().setPermissionId(permissionId).build(); rawData = rawData.toBuilder().clearContract().addContract(contract1).build(); transaction = transaction.toBuilder().setRawData(rawData).build(); return transaction; - } - /** - * constructor. - */ - public static TransactionSignWeight getTransactionSignWeight(Transaction transaction, - WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public static TransactionSignWeight getTransactionSignWeight( + Transaction transaction, WalletGrpc.WalletBlockingStub blockingStubFull) { return blockingStubFull.getTransactionSignWeight(transaction); } - /** - * constructor. - */ - public static Return broadcastTransaction1(Transaction transaction, - WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public static Return broadcastTransaction1( + Transaction transaction, WalletGrpc.WalletBlockingStub blockingStubFull) { return PublicMethod.broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - public static boolean accountPermissionUpdateWithPermissionId(String permissionJson, byte[] owner, - String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, int permissionId, + /** constructor. */ + public static boolean accountPermissionUpdateWithPermissionId( + String permissionJson, + byte[] owner, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + int permissionId, String[] priKeys) { ECKey temKey = null; try { @@ -3436,8 +3689,8 @@ public static boolean accountPermissionUpdateWithPermissionId(String permissionJ Transaction transaction = transactionExtention.getTransaction(); raw rawData = transaction.getRawData(); - Transaction.Contract contract1 = transactionExtention.getTransaction().getRawData() - .getContractList().get(0); + Transaction.Contract contract1 = + transactionExtention.getTransaction().getRawData().getContractList().get(0); contract1 = contract1.toBuilder().setPermissionId(permissionId).build(); rawData = rawData.toBuilder().clearContract().addContract(contract1).build(); transaction = transaction.toBuilder().setRawData(rawData).build(); @@ -3454,11 +3707,13 @@ public static boolean accountPermissionUpdateWithPermissionId(String permissionJ return response.getResult(); } - /** - * constructor. - */ - public static Transaction accountPermissionUpdateWithoutSign(String permissionJson, byte[] owner, - String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, String[] priKeys) { + /** constructor. */ + public static Transaction accountPermissionUpdateWithoutSign( + String permissionJson, + byte[] owner, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] priKeys) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -3515,11 +3770,12 @@ public static Transaction accountPermissionUpdateWithoutSign(String permissionJs return transaction; } - /** - * constructor. - */ - public static Transaction addTransactionSignWithPermissionId(Transaction transaction, - String priKey, int permissionId, WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public static Transaction addTransactionSignWithPermissionId( + Transaction transaction, + String priKey, + int permissionId, + WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -3528,17 +3784,19 @@ public static Transaction addTransactionSignWithPermissionId(Transaction transac ex.printStackTrace(); } - //transaction = setPermissionId(transaction, permissionId); + // transaction = setPermissionId(transaction, permissionId); Transaction.raw.Builder raw = transaction.getRawData().toBuilder(); - Transaction.Contract.Builder contract = raw.getContract(0).toBuilder() - .setPermissionId(permissionId); + Transaction.Contract.Builder contract = + raw.getContract(0).toBuilder().setPermissionId(permissionId); raw.clearContract(); raw.addContract(contract); transaction = transaction.toBuilder().setRawData(raw).build(); Transaction.Builder transactionBuilderSigned = transaction.toBuilder(); - byte[] hash = Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()); + byte[] hash = + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()); ECKey ecKey = temKey; ECDSASignature signature = ecKey.sign(hash); ByteString bsSign = ByteString.copyFrom(signature.toByteArray()); @@ -3547,9 +3805,7 @@ public static Transaction addTransactionSignWithPermissionId(Transaction transac return transaction; } - /** - * constructor. - */ + /** constructor. */ public static Transaction setPermissionId(Transaction transaction, int permissionId) throws CancelException { if (transaction.getSignatureCount() != 0 @@ -3561,8 +3817,8 @@ public static Transaction setPermissionId(Transaction transaction, int permissio } if (permissionId != 0) { Transaction.raw.Builder raw = transaction.getRawData().toBuilder(); - Transaction.Contract.Builder contract = raw.getContract(0).toBuilder() - .setPermissionId(permissionId); + Transaction.Contract.Builder contract = + raw.getContract(0).toBuilder().setPermissionId(permissionId); raw.clearContract(); raw.addContract(contract); transaction = transaction.toBuilder().setRawData(raw).build(); @@ -3570,9 +3826,7 @@ public static Transaction setPermissionId(Transaction transaction, int permissio return transaction; } - /** - * constructor. - */ + /** constructor. */ public static int getActivePermissionKeyCount(List permissionList) { int permissionCount = 0; for (Permission permission : permissionList) { @@ -3581,13 +3835,16 @@ public static int getActivePermissionKeyCount(List permissionList) { return permissionCount; } - /** - * constructor. - */ - public static Boolean sendcoinWithPermissionId(byte[] to, long amount, byte[] owner, - int permissionId, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, + /** constructor. */ + public static Boolean sendcoinWithPermissionId( + byte[] to, + long amount, + byte[] owner, + int permissionId, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { - //String priKey = testKey002; + // String priKey = testKey002; ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -3596,7 +3853,7 @@ public static Boolean sendcoinWithPermissionId(byte[] to, long amount, byte[] ow ex.printStackTrace(); } final ECKey ecKey = temKey; - //Protocol.Account search = queryAccount(priKey, blockingStubFull); + // Protocol.Account search = queryAccount(priKey, blockingStubFull); TransferContract.Builder builder = TransferContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); @@ -3610,8 +3867,8 @@ public static Boolean sendcoinWithPermissionId(byte[] to, long amount, byte[] ow Transaction transaction = transactionExtention.getTransaction(); raw rawData = transaction.getRawData(); - Transaction.Contract contract1 = transactionExtention.getTransaction().getRawData() - .getContractList().get(0); + Transaction.Contract contract1 = + transactionExtention.getTransaction().getRawData().getContractList().get(0); contract1 = contract1.toBuilder().setPermissionId(permissionId).build(); rawData = rawData.toBuilder().clearContract().addContract(contract1).build(); transaction = transaction.toBuilder().setRawData(rawData).build(); @@ -3624,13 +3881,12 @@ public static Boolean sendcoinWithPermissionId(byte[] to, long amount, byte[] ow transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); return broadcastTransaction(transaction, blockingStubFull); - } - /** - * constructor. - */ - public static void recoverWitnessPermission(String ownerKey, List ownerPermissionKeys, + /** constructor. */ + public static void recoverWitnessPermission( + String ownerKey, + List ownerPermissionKeys, WalletGrpc.WalletBlockingStub blockingStubFull) { PublicMethod.printAddress(ownerKey); @@ -3638,52 +3894,69 @@ public static void recoverWitnessPermission(String ownerKey, List ownerP String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," - + "\"threshold\":1,\"keys\":[" + "{\"address\":\"" + PublicMethod - .getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; Assert.assertTrue( - accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(1, getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 1, + getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() .getKeysCount()); } - /** - * constructor. - */ + /** constructor. */ public static String getOperations(Integer[] ints) { List list = new ArrayList<>(Arrays.asList(ints)); byte[] operations = new byte[32]; - list.forEach(e -> { - operations[e / 8] |= (1 << e % 8); - }); + list.forEach( + e -> { + operations[e / 8] |= (1 << e % 8); + }); System.out.println(ByteArray.toHexString(operations)); return ByteArray.toHexString(operations); } - /** - * constructor. - */ - public static GrpcAPI.Return accountPermissionUpdateForResponse(String permissionJson, - byte[] owner, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, + /** constructor. */ + public static GrpcAPI.Return accountPermissionUpdateForResponse( + String permissionJson, + byte[] owner, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, String[] priKeys) { ECKey temKey = null; try { @@ -3744,10 +4017,10 @@ public static GrpcAPI.Return accountPermissionUpdateForResponse(String permissio return response; } - /** - * constructor. - */ - public static void recoverAccountPermission(String ownerKey, List ownerPermissionKeys, + /** constructor. */ + public static void recoverAccountPermission( + String ownerKey, + List ownerPermissionKeys, WalletGrpc.WalletBlockingStub blockingStubFull) { PublicMethod.printAddress(ownerKey); @@ -3755,32 +4028,47 @@ public static void recoverAccountPermission(String ownerKey, List ownerP String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; Assert.assertTrue( - accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(1, getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 1, + getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); } - /** - * constructor. - */ - public static Transaction sendcoin2(byte[] to, long amount, byte[] owner, String priKey, + /** constructor. */ + public static Transaction sendcoin2( + byte[] to, + long amount, + byte[] owner, + String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - //String priKey = testKey002; + // String priKey = testKey002; ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -3789,7 +4077,7 @@ public static Transaction sendcoin2(byte[] to, long amount, byte[] owner, String ex.printStackTrace(); } final ECKey ecKey = temKey; - //Protocol.Account search = queryAccount(priKey, blockingStubFull); + // Protocol.Account search = queryAccount(priKey, blockingStubFull); TransferContract.Builder builder = TransferContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); @@ -3805,55 +4093,58 @@ public static Transaction sendcoin2(byte[] to, long amount, byte[] owner, String return null; } return transaction; - } - /** - * constructor. - */ - public static Protocol.Transaction createFakeTransaction(byte[] toAddrss, Long amount, - byte[] fromAddress) { + /** constructor. */ + public static Protocol.Transaction createFakeTransaction( + byte[] toAddrss, Long amount, byte[] fromAddress) { - TransferContract contract = TransferContract.newBuilder() - .setOwnerAddress(ByteString.copyFrom(fromAddress)) - .setToAddress(ByteString.copyFrom(toAddrss)).setAmount(amount).build(); + TransferContract contract = + TransferContract.newBuilder() + .setOwnerAddress(ByteString.copyFrom(fromAddress)) + .setToAddress(ByteString.copyFrom(toAddrss)) + .setAmount(amount) + .build(); Protocol.Transaction transaction = createTransaction(contract, ContractType.TransferContract); return transaction; } - /** - * constructor. - */ - private static Transaction setReference(Transaction transaction, long blockNum, - byte[] blockHash) { + /** constructor. */ + private static Transaction setReference( + Transaction transaction, long blockNum, byte[] blockHash) { byte[] refBlockNum = ByteArray.fromLong(blockNum); - Transaction.raw rawData = transaction.getRawData().toBuilder() - .setRefBlockHash(ByteString.copyFrom(blockHash)) - .setRefBlockBytes(ByteString.copyFrom(refBlockNum)).build(); + Transaction.raw rawData = + transaction + .getRawData() + .toBuilder() + .setRefBlockHash(ByteString.copyFrom(blockHash)) + .setRefBlockBytes(ByteString.copyFrom(refBlockNum)) + .build(); return transaction.toBuilder().setRawData(rawData).build(); } - /** - * constructor. - */ + /** constructor. */ public static Transaction setExpiration(Transaction transaction, long expiration) { - Transaction.raw rawData = transaction.getRawData().toBuilder().setExpiration(expiration) - .build(); + Transaction.raw rawData = + transaction.getRawData().toBuilder().setExpiration(expiration).build(); return transaction.toBuilder().setRawData(rawData).build(); } - /** - * constructor. - */ - public static Transaction createTransaction(com.google.protobuf.Message message, - ContractType contractType) { - Transaction.raw.Builder transactionBuilder = Transaction.raw.newBuilder().addContract( - Transaction.Contract.newBuilder().setType(contractType).setParameter(Any.pack(message)) - .build()); - - Transaction transaction = Transaction.newBuilder().setRawData(transactionBuilder.build()) - .build(); + /** constructor. */ + public static Transaction createTransaction( + com.google.protobuf.Message message, ContractType contractType) { + Transaction.raw.Builder transactionBuilder = + Transaction.raw + .newBuilder() + .addContract( + Transaction.Contract.newBuilder() + .setType(contractType) + .setParameter(Any.pack(message)) + .build()); + + Transaction transaction = + Transaction.newBuilder().setRawData(transactionBuilder.build()).build(); long time = System.currentTimeMillis(); AtomicLong count = new AtomicLong(); @@ -3867,14 +4158,21 @@ public static Transaction createTransaction(com.google.protobuf.Message message, return transaction; } - /** - * constructor. - */ - - public static String triggerContractWithPermissionId(byte[] contractAddress, String method, - String argsStr, Boolean isHex, long callValue, long feeLimit, String tokenId, long tokenValue, - byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, - String[] permissionKeyString, int permissionId) { + /** constructor. */ + public static String triggerContractWithPermissionId( + byte[] contractAddress, + String method, + String argsStr, + Boolean isHex, + long callValue, + long feeLimit, + String tokenId, + long tokenValue, + byte[] ownerAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString, + int permissionId) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -3904,12 +4202,13 @@ public static String triggerContractWithPermissionId(byte[] contractAddress, Str if (transactionExtention == null || !transactionExtention.getResult().getResult()) { System.out.println("RPC create call trx failed!"); System.out.println("Code = " + transactionExtention.getResult().getCode()); - System.out - .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + System.out.println( + "Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); return null; } Transaction transaction = transactionExtention.getTransaction(); - if (transaction.getRetCount() != 0 && transactionExtention.getConstantResult(0) != null + if (transaction.getRetCount() != 0 + && transactionExtention.getConstantResult(0) != null && transactionExtention.getResult() != null) { byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); @@ -3921,8 +4220,8 @@ public static String triggerContractWithPermissionId(byte[] contractAddress, Str final TransactionExtention.Builder texBuilder = TransactionExtention.newBuilder(); Transaction.Builder transBuilder = Transaction.newBuilder(); - Transaction.raw.Builder rawBuilder = transactionExtention.getTransaction().getRawData() - .toBuilder(); + Transaction.raw.Builder rawBuilder = + transactionExtention.getTransaction().getRawData().toBuilder(); rawBuilder.setFeeLimit(feeLimit); transBuilder.setRawData(rawBuilder); for (int i = 0; i < transactionExtention.getTransaction().getSignatureCount(); i++) { @@ -3958,20 +4257,22 @@ public static String triggerContractWithPermissionId(byte[] contractAddress, Str e.printStackTrace(); } - System.out.println("trigger txid = " + ByteArray - .toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()))); + System.out.println( + "trigger txid = " + + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()))); transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); broadcastTransaction(transaction, blockingStubFull); - return ByteArray.toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray())); + return ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); } - /** - * constructor. - */ - + /** constructor. */ public static byte[] generateContractAddress(Transaction trx, byte[] owneraddress) { // get owner address @@ -3979,8 +4280,10 @@ public static byte[] generateContractAddress(Transaction trx, byte[] owneraddres byte[] ownerAddress = owneraddress; // get tx hash - byte[] txRawDataHash = Sha256Hash.of(CommonParameter.getInstance() - .isECKeyCryptoEngine(), trx.getRawData().toByteArray()).getBytes(); + byte[] txRawDataHash = + Sha256Hash.of( + CommonParameter.getInstance().isECKeyCryptoEngine(), trx.getRawData().toByteArray()) + .getBytes(); // combine byte[] combined = new byte[txRawDataHash.length + ownerAddress.length]; @@ -3988,18 +4291,26 @@ public static byte[] generateContractAddress(Transaction trx, byte[] owneraddres System.arraycopy(ownerAddress, 0, combined, txRawDataHash.length, ownerAddress.length); return Hash.sha3omit12(combined); - } - /** - * constructor. - */ - - public static byte[] deployContractWithPermissionId(String contractName, String abiString, - String code, String data, Long feeLimit, long value, long consumeUserResourcePercent, - long originEnergyLimit, String tokenId, long tokenValue, String libraryAddress, String priKey, - byte[] ownerAddress, WalletGrpc.WalletBlockingStub blockingStubFull, - String[] permissionKeyString, int permissionId) { + /** constructor. */ + public static byte[] deployContractWithPermissionId( + String contractName, + String abiString, + String code, + String data, + Long feeLimit, + long value, + long consumeUserResourcePercent, + long originEnergyLimit, + String tokenId, + long tokenValue, + String libraryAddress, + String priKey, + byte[] ownerAddress, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString, + int permissionId) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -4015,7 +4326,7 @@ public static byte[] deployContractWithPermissionId(String contractName, String logger.error("abi is null"); return null; } - //byte[] codeBytes = Hex.decode(code); + // byte[] codeBytes = Hex.decode(code); SmartContract.Builder builder = SmartContract.newBuilder(); builder.setName(contractName); builder.setOriginAddress(ByteString.copyFrom(owner)); @@ -4040,25 +4351,25 @@ public static byte[] deployContractWithPermissionId(String contractName, String contractBuilder.setOwnerAddress(ByteString.copyFrom(owner)); contractBuilder.setCallTokenValue(tokenValue); contractBuilder.setTokenId(Long.parseLong(tokenId)); - CreateSmartContract contractDeployContract = contractBuilder.setNewContract(builder.build()) - .build(); + CreateSmartContract contractDeployContract = + contractBuilder.setNewContract(builder.build()).build(); - TransactionExtention transactionExtention = blockingStubFull - .deployContract(contractDeployContract); + TransactionExtention transactionExtention = + blockingStubFull.deployContract(contractDeployContract); if (transactionExtention == null || !transactionExtention.getResult().getResult()) { System.out.println("RPC create trx failed!"); if (transactionExtention != null) { System.out.println("Code = " + transactionExtention.getResult().getCode()); - System.out - .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + System.out.println( + "Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); } return null; } final TransactionExtention.Builder texBuilder = TransactionExtention.newBuilder(); Transaction.Builder transBuilder = Transaction.newBuilder(); - Transaction.raw.Builder rawBuilder = transactionExtention.getTransaction().getRawData() - .toBuilder(); + Transaction.raw.Builder rawBuilder = + transactionExtention.getTransaction().getRawData().toBuilder(); rawBuilder.setFeeLimit(feeLimit); transBuilder.setRawData(rawBuilder); for (int i = 0; i < transactionExtention.getTransaction().getSignatureCount(); i++) { @@ -4101,8 +4412,11 @@ public static byte[] deployContractWithPermissionId(String contractName, String transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); System.out.println( - "txid = " + ByteArray.toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()))); + "txid = " + + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()))); contractAddress = generateContractAddress(transaction, owner); System.out.println( "Your smart contract address will be: " + WalletClient.encode58Check(contractAddress)); @@ -4111,19 +4425,25 @@ public static byte[] deployContractWithPermissionId(String contractName, String if (response.getResult() == false) { return null; } else { - //logger.info("brodacast succesfully"); + // logger.info("brodacast succesfully"); return contractAddress; } } - - /** - * constructor. - */ - public static byte[] deployContract1(String contractName, String abiString, String code, - String data, Long feeLimit, long value, long consumeUserResourcePercent, - String libraryAddress, String priKey, byte[] ownerAddress, - WalletGrpc.WalletBlockingStub blockingStubFull, int permissionId, + /** constructor. */ + public static byte[] deployContract1( + String contractName, + String abiString, + String code, + String data, + Long feeLimit, + long value, + long consumeUserResourcePercent, + String libraryAddress, + String priKey, + byte[] ownerAddress, + WalletGrpc.WalletBlockingStub blockingStubFull, + int permissionId, String[] permissionKeyString) { ECKey temKey = null; @@ -4141,7 +4461,7 @@ public static byte[] deployContract1(String contractName, String abiString, Stri logger.error("abi is null"); return null; } - //byte[] codeBytes = Hex.decode(code); + // byte[] codeBytes = Hex.decode(code); SmartContract.Builder builder = SmartContract.newBuilder(); builder.setName(contractName); builder.setOriginAddress(ByteString.copyFrom(owner)); @@ -4166,25 +4486,25 @@ public static byte[] deployContract1(String contractName, String abiString, Stri contractBuilder.setOwnerAddress(ByteString.copyFrom(owner)); contractBuilder.setCallTokenValue(0L); contractBuilder.setTokenId(Long.parseLong("0")); - CreateSmartContract contractDeployContract = contractBuilder.setNewContract(builder.build()) - .build(); + CreateSmartContract contractDeployContract = + contractBuilder.setNewContract(builder.build()).build(); - TransactionExtention transactionExtention = blockingStubFull - .deployContract(contractDeployContract); + TransactionExtention transactionExtention = + blockingStubFull.deployContract(contractDeployContract); if (transactionExtention == null || !transactionExtention.getResult().getResult()) { System.out.println("RPC create trx failed!"); if (transactionExtention != null) { System.out.println("Code = " + transactionExtention.getResult().getCode()); - System.out - .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + System.out.println( + "Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); } return null; } final TransactionExtention.Builder texBuilder = TransactionExtention.newBuilder(); Transaction.Builder transBuilder = Transaction.newBuilder(); - Transaction.raw.Builder rawBuilder = transactionExtention.getTransaction().getRawData() - .toBuilder(); + Transaction.raw.Builder rawBuilder = + transactionExtention.getTransaction().getRawData().toBuilder(); rawBuilder.setFeeLimit(feeLimit); transBuilder.setRawData(rawBuilder); for (int i = 0; i < transactionExtention.getTransaction().getSignatureCount(); i++) { @@ -4200,8 +4520,8 @@ public static byte[] deployContract1(String contractName, String abiString, Stri texBuilder.setTxid(transactionExtention.getTxid()); transactionExtention = texBuilder.build(); - byte[] contractAddress = PublicMethod - .generateContractAddress(transactionExtention.getTransaction(), owner); + byte[] contractAddress = + PublicMethod.generateContractAddress(transactionExtention.getTransaction(), owner); System.out.println( "Your smart contract address will be: " + WalletClient.encode58Check(contractAddress)); if (transactionExtention == null) { @@ -4226,8 +4546,11 @@ public static byte[] deployContract1(String contractName, String abiString, Stri transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); System.out.println( - "txid = " + ByteArray.toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()))); + "txid = " + + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()))); contractAddress = PublicMethod.generateContractAddress(transaction, owner); System.out.println( "Your smart contract address will be: " + WalletClient.encode58Check(contractAddress)); @@ -4235,12 +4558,18 @@ public static byte[] deployContract1(String contractName, String abiString, Stri return contractAddress; } - /** - * constructor. - */ - public static String triggerContract1(byte[] contractAddress, String method, String argsStr, - Boolean isHex, long callValue, long feeLimit, byte[] ownerAddress, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, int permissionId, + /** constructor. */ + public static String triggerContract1( + byte[] contractAddress, + String method, + String argsStr, + Boolean isHex, + long callValue, + long feeLimit, + byte[] ownerAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + int permissionId, String[] permissionKeyString) { ECKey temKey = null; try { @@ -4271,12 +4600,13 @@ public static String triggerContract1(byte[] contractAddress, String method, Str if (transactionExtention == null || !transactionExtention.getResult().getResult()) { System.out.println("RPC create call trx failed!"); System.out.println("Code = " + transactionExtention.getResult().getCode()); - System.out - .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + System.out.println( + "Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); return null; } Transaction transaction = transactionExtention.getTransaction(); - if (transaction.getRetCount() != 0 && transactionExtention.getConstantResult(0) != null + if (transaction.getRetCount() != 0 + && transactionExtention.getConstantResult(0) != null && transactionExtention.getResult() != null) { byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); @@ -4288,8 +4618,8 @@ public static String triggerContract1(byte[] contractAddress, String method, Str final TransactionExtention.Builder texBuilder = TransactionExtention.newBuilder(); Transaction.Builder transBuilder = Transaction.newBuilder(); - Transaction.raw.Builder rawBuilder = transactionExtention.getTransaction().getRawData() - .toBuilder(); + Transaction.raw.Builder rawBuilder = + transactionExtention.getTransaction().getRawData().toBuilder(); rawBuilder.setFeeLimit(feeLimit); transBuilder.setRawData(rawBuilder); for (int i = 0; i < transactionExtention.getTransaction().getSignatureCount(); i++) { @@ -4323,22 +4653,28 @@ public static String triggerContract1(byte[] contractAddress, String method, Str } catch (CancelException e) { e.printStackTrace(); } - System.out.println("trigger txid = " + ByteArray - .toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()))); + System.out.println( + "trigger txid = " + + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()))); transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); broadcastTransaction(transaction, blockingStubFull); - return ByteArray.toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray())); + return ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); } - /** - * constructor. - */ - - public static boolean updateAccountWithPermissionId(byte[] addressBytes, byte[] accountNameBytes, - String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, int permissionId, + /** constructor. */ + public static boolean updateAccountWithPermissionId( + byte[] addressBytes, + byte[] accountNameBytes, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + int permissionId, String[] permissionKeyString) { ECKey temKey = null; try { @@ -4373,14 +4709,16 @@ public static boolean updateAccountWithPermissionId(byte[] addressBytes, byte[] return broadcastTransaction(transaction, blockingStubFull); } - - /** - * constructor. - */ - - public static String transferAssetForTransactionId1(byte[] to, byte[] assertName, long amount, - byte[] address, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, - int permissionId, String[] permissionKeyString) { + /** constructor. */ + public static String transferAssetForTransactionId1( + byte[] to, + byte[] assertName, + long amount, + byte[] address, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + int permissionId, + String[] permissionKeyString) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -4421,42 +4759,58 @@ public static String transferAssetForTransactionId1(byte[] to, byte[] assertName if (result == false) { return null; } else { - return ByteArray.toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray())); + return ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); } } - - /** - * constructor. - */ - - public static Boolean freezeBalanceGetEnergyWithPermissionId(byte[] addRess, long freezeBalance, - long freezeDuration, int resourceCode, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, int permissionId, + /** constructor. */ + public static Boolean freezeBalanceGetEnergyWithPermissionId( + byte[] addRess, + long freezeBalance, + long freezeDuration, + int resourceCode, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + int permissionId, String[] permissionKeyString) { - if(!PublicMethod.tronPowerProposalIsOpen(blockingStubFull) && resourceCode == 2) { + if (!PublicMethod.tronPowerProposalIsOpen(blockingStubFull) && resourceCode == 2) { resourceCode = 1; } - if(PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { - return freezeBalanceV2WithPermissionId(addRess,freezeBalance,resourceCode,permissionId,priKey, - blockingStubFull,permissionKeyString); + if (PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + return freezeBalanceV2WithPermissionId( + addRess, + freezeBalance, + resourceCode, + permissionId, + priKey, + blockingStubFull, + permissionKeyString); } else { - return freezeBalanceV1WithPermissionId(addRess,freezeBalance,freezeDuration,resourceCode,permissionId,priKey, - blockingStubFull,permissionKeyString); + return freezeBalanceV1WithPermissionId( + addRess, + freezeBalance, + freezeDuration, + resourceCode, + permissionId, + priKey, + blockingStubFull, + permissionKeyString); } } - - - - /** - * constructor. - */ - - public static Boolean freezeBalanceForReceiverWithPermissionId(byte[] addRess, long freezeBalance, - long freezeDuration, int resourceCode, ByteString receiverAddressBytes, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, int permissionId, + /** constructor. */ + public static Boolean freezeBalanceForReceiverWithPermissionId( + byte[] addRess, + long freezeBalance, + long freezeDuration, + int resourceCode, + ByteString receiverAddressBytes, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + int permissionId, String[] permissionKeyString) { byte[] address = addRess; long frozenBalance = freezeBalance; @@ -4473,8 +4827,11 @@ public static Boolean freezeBalanceForReceiverWithPermissionId(byte[] addRess, l FreezeBalanceContract.Builder builder = FreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess).setFrozenBalance(frozenBalance) - .setFrozenDuration(frozenDuration).setResourceValue(resourceCode); + builder + .setOwnerAddress(byteAddreess) + .setFrozenBalance(frozenBalance) + .setFrozenDuration(frozenDuration) + .setResourceValue(resourceCode); builder.setReceiverAddress(receiverAddressBytes); FreezeBalanceContract contract = builder.build(); Transaction transaction = blockingStubFull.freezeBalance(contract); @@ -4494,16 +4851,13 @@ public static Boolean freezeBalanceForReceiverWithPermissionId(byte[] addRess, l return broadcastTransaction(transaction, blockingStubFull); } - - - - - /** - * constructor. - */ - - public static boolean createAccount1(byte[] ownerAddress, byte[] newAddress, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, int permissionId, + /** constructor. */ + public static boolean createAccount1( + byte[] ownerAddress, + byte[] newAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + int permissionId, String[] permissionKeyString) { ECKey temKey = null; try { @@ -4531,15 +4885,15 @@ public static boolean createAccount1(byte[] ownerAddress, byte[] newAddress, Str transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); return broadcastTransaction(transaction, blockingStubFull); - } - /** - * constructor. - */ - - public static boolean setAccountId1(byte[] accountIdBytes, byte[] ownerAddress, String priKey, - int permissionId, WalletGrpc.WalletBlockingStub blockingStubFull, + /** constructor. */ + public static boolean setAccountId1( + byte[] accountIdBytes, + byte[] ownerAddress, + String priKey, + int permissionId, + WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { ECKey temKey = null; try { @@ -4568,22 +4922,23 @@ public static boolean setAccountId1(byte[] accountIdBytes, byte[] ownerAddress, } transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); return broadcastTransaction(transaction, blockingStubFull); - //Return response = broadcastTransaction1(transaction, blockingStubFull); - //if (response.getResult() == false) { + // Return response = broadcastTransaction1(transaction, blockingStubFull); + // if (response.getResult() == false) { // logger.info(ByteArray.toStr(response.getMessage().toByteArray())); // return false; - //} else { + // } else { // return true; - //} - //return response.getResult(); + // } + // return response.getResult(); } - - /** - * constructor. - */ - public static Boolean voteWitnessWithPermissionId(HashMap witness, byte[] addRess, - String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, int permissionId, + /** constructor. */ + public static Boolean voteWitnessWithPermissionId( + HashMap witness, + byte[] addRess, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + int permissionId, String[] permissionKeyString) { ECKey temKey = null; @@ -4636,15 +4991,25 @@ public static Boolean voteWitnessWithPermissionId(HashMap witnes return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - - public static String createAssetIssueForTransactionId1(byte[] address, String name, - Long totalSupply, Integer trxNum, Integer icoNum, Long startTime, Long endTime, - Integer voteScore, String description, String url, Long freeAssetNetLimit, - Long publicFreeAssetNetLimit, Long fronzenAmount, Long frozenDay, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, int permissionId, + /** constructor. */ + public static String createAssetIssueForTransactionId1( + byte[] address, + String name, + Long totalSupply, + Integer trxNum, + Integer icoNum, + Long startTime, + Long endTime, + Integer voteScore, + String description, + String url, + Long freeAssetNetLimit, + Long publicFreeAssetNetLimit, + Long fronzenAmount, + Long frozenDay, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + int permissionId, String[] permissionKeyString) { ECKey temKey = null; try { @@ -4668,8 +5033,8 @@ public static String createAssetIssueForTransactionId1(byte[] address, String na builder.setUrl(ByteString.copyFrom(url.getBytes())); builder.setFreeAssetNetLimit(freeAssetNetLimit); builder.setPublicFreeAssetNetLimit(publicFreeAssetNetLimit); - AssetIssueContract.FrozenSupply.Builder frozenBuilder = AssetIssueContract.FrozenSupply - .newBuilder(); + AssetIssueContract.FrozenSupply.Builder frozenBuilder = + AssetIssueContract.FrozenSupply.newBuilder(); frozenBuilder.setFrozenAmount(fronzenAmount); frozenBuilder.setFrozenDays(frozenDay); @@ -4691,8 +5056,10 @@ public static String createAssetIssueForTransactionId1(byte[] address, String na if (result == false) { return null; } else { - return ByteArray.toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray())); + return ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); } } catch (Exception ex) { ex.printStackTrace(); @@ -4700,13 +5067,16 @@ public static String createAssetIssueForTransactionId1(byte[] address, String na } } - /** - * constructor. - */ - - public static Boolean injectExchange1(long exchangeId, byte[] tokenId, long quant, - byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, - int permissionId, String[] permissionKeyString) { + /** constructor. */ + public static Boolean injectExchange1( + long exchangeId, + byte[] tokenId, + long quant, + byte[] ownerAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + int permissionId, + String[] permissionKeyString) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -4719,8 +5089,11 @@ public static Boolean injectExchange1(long exchangeId, byte[] tokenId, long quan byte[] owner = ownerAddress; ExchangeInjectContract.Builder builder = ExchangeInjectContract.newBuilder(); - builder.setOwnerAddress(ByteString.copyFrom(owner)).setExchangeId(exchangeId) - .setTokenId(ByteString.copyFrom(tokenId)).setQuant(quant); + builder + .setOwnerAddress(ByteString.copyFrom(owner)) + .setExchangeId(exchangeId) + .setTokenId(ByteString.copyFrom(tokenId)) + .setQuant(quant); ExchangeInjectContract contract = builder.build(); TransactionExtention transactionExtention = blockingStubFull.exchangeInject(contract); if (transactionExtention == null) { @@ -4749,14 +5122,16 @@ public static Boolean injectExchange1(long exchangeId, byte[] tokenId, long quan return broadcastTransaction(transaction, blockingStubFull); } - - /** - * constructor. - */ - - public static boolean exchangeWithdraw1(long exchangeId, byte[] tokenId, long quant, - byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, - int permissionId, String[] permissionKeyString) { + /** constructor. */ + public static boolean exchangeWithdraw1( + long exchangeId, + byte[] tokenId, + long quant, + byte[] ownerAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + int permissionId, + String[] permissionKeyString) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -4768,8 +5143,11 @@ public static boolean exchangeWithdraw1(long exchangeId, byte[] tokenId, long qu byte[] owner = ownerAddress; ExchangeWithdrawContract.Builder builder = ExchangeWithdrawContract.newBuilder(); - builder.setOwnerAddress(ByteString.copyFrom(owner)).setExchangeId(exchangeId) - .setTokenId(ByteString.copyFrom(tokenId)).setQuant(quant); + builder + .setOwnerAddress(ByteString.copyFrom(owner)) + .setExchangeId(exchangeId) + .setTokenId(ByteString.copyFrom(tokenId)) + .setQuant(quant); ExchangeWithdrawContract contract = builder.build(); TransactionExtention transactionExtention = blockingStubFull.exchangeWithdraw(contract); if (transactionExtention == null) { @@ -4798,14 +5176,16 @@ public static boolean exchangeWithdraw1(long exchangeId, byte[] tokenId, long qu return broadcastTransaction(transaction, blockingStubFull); } - - /** - * constructor. - */ - - public static boolean exchangeTransaction1(long exchangeId, byte[] tokenId, long quant, - long expected, byte[] ownerAddress, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, int permissionId, + /** constructor. */ + public static boolean exchangeTransaction1( + long exchangeId, + byte[] tokenId, + long quant, + long expected, + byte[] ownerAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + int permissionId, String[] permissionKeyString) { ECKey temKey = null; try { @@ -4818,8 +5198,12 @@ public static boolean exchangeTransaction1(long exchangeId, byte[] tokenId, long byte[] owner = ownerAddress; ExchangeTransactionContract.Builder builder = ExchangeTransactionContract.newBuilder(); - builder.setOwnerAddress(ByteString.copyFrom(owner)).setExchangeId(exchangeId) - .setTokenId(ByteString.copyFrom(tokenId)).setQuant(quant).setExpected(expected); + builder + .setOwnerAddress(ByteString.copyFrom(owner)) + .setExchangeId(exchangeId) + .setTokenId(ByteString.copyFrom(tokenId)) + .setQuant(quant) + .setExpected(expected); ExchangeTransactionContract contract = builder.build(); TransactionExtention transactionExtention = blockingStubFull.exchangeTransaction(contract); if (transactionExtention == null) { @@ -4848,13 +5232,16 @@ public static boolean exchangeTransaction1(long exchangeId, byte[] tokenId, long return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - - public static Boolean exchangeCreate1(byte[] firstTokenId, long firstTokenBalance, - byte[] secondTokenId, long secondTokenBalance, byte[] ownerAddress, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, int permissionId, + /** constructor. */ + public static Boolean exchangeCreate1( + byte[] firstTokenId, + long firstTokenBalance, + byte[] secondTokenId, + long secondTokenBalance, + byte[] ownerAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + int permissionId, String[] permissionKeyString) { ECKey temKey = null; try { @@ -4868,8 +5255,10 @@ public static Boolean exchangeCreate1(byte[] firstTokenId, long firstTokenBalanc byte[] owner = ownerAddress; ExchangeCreateContract.Builder builder = ExchangeCreateContract.newBuilder(); - builder.setOwnerAddress(ByteString.copyFrom(owner)) - .setFirstTokenId(ByteString.copyFrom(firstTokenId)).setFirstTokenBalance(firstTokenBalance) + builder + .setOwnerAddress(ByteString.copyFrom(owner)) + .setFirstTokenId(ByteString.copyFrom(firstTokenId)) + .setFirstTokenBalance(firstTokenBalance) .setSecondTokenId(ByteString.copyFrom(secondTokenId)) .setSecondTokenBalance(secondTokenBalance); ExchangeCreateContract contract = builder.build(); @@ -4900,11 +5289,13 @@ public static Boolean exchangeCreate1(byte[] firstTokenId, long firstTokenBalanc return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - public static boolean clearContractAbi(byte[] contractAddress, byte[] ownerAddress, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, int permissionId, + /** constructor. */ + public static boolean clearContractAbi( + byte[] contractAddress, + byte[] ownerAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + int permissionId, String[] permissionKeyString) { ECKey temKey = null; try { @@ -4927,12 +5318,13 @@ public static boolean clearContractAbi(byte[] contractAddress, byte[] ownerAddre if (transactionExtention == null || !transactionExtention.getResult().getResult()) { System.out.println("RPC create call trx failed!"); System.out.println("Code = " + transactionExtention.getResult().getCode()); - System.out - .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + System.out.println( + "Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); return false; } Transaction transaction = transactionExtention.getTransaction(); - if (transaction.getRetCount() != 0 && transactionExtention.getConstantResult(0) != null + if (transaction.getRetCount() != 0 + && transactionExtention.getConstantResult(0) != null && transactionExtention.getResult() != null) { byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); @@ -4944,8 +5336,8 @@ public static boolean clearContractAbi(byte[] contractAddress, byte[] ownerAddre final TransactionExtention.Builder texBuilder = TransactionExtention.newBuilder(); Transaction.Builder transBuilder = Transaction.newBuilder(); - Transaction.raw.Builder rawBuilder = transactionExtention.getTransaction().getRawData() - .toBuilder(); + Transaction.raw.Builder rawBuilder = + transactionExtention.getTransaction().getRawData().toBuilder(); transBuilder.setRawData(rawBuilder); for (int i = 0; i < transactionExtention.getTransaction().getSignatureCount(); i++) { ByteString s = transactionExtention.getTransaction().getSignature(i); @@ -4979,19 +5371,27 @@ public static boolean clearContractAbi(byte[] contractAddress, byte[] ownerAddre e.printStackTrace(); } transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); - System.out.println("trigger txid = " + ByteArray - .toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()))); + System.out.println( + "trigger txid = " + + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()))); return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - public static boolean sendShieldCoin(byte[] publicZenTokenOwnerAddress, long fromAmount, - ShieldAddressInfo shieldAddressInfo, NoteTx noteTx, List shieldOutputList, - byte[] publicZenTokenToAddress, long toAmount, String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull, Integer permission_id, + /** constructor. */ + public static boolean sendShieldCoin( + byte[] publicZenTokenOwnerAddress, + long fromAmount, + ShieldAddressInfo shieldAddressInfo, + NoteTx noteTx, + List shieldOutputList, + byte[] publicZenTokenToAddress, + long toAmount, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + Integer permission_id, String[] permissionKeyString) { ECKey temKey = null; try { @@ -5015,16 +5415,16 @@ public static boolean sendShieldCoin(byte[] publicZenTokenOwnerAddress, long fro if (shieldAddressInfo != null) { OutputPointInfo.Builder request = OutputPointInfo.newBuilder(); - //ShieldNoteInfo noteInfo = shieldWrapper.getUtxoMapNote().get(shieldInputList.get(i)); + // ShieldNoteInfo noteInfo = shieldWrapper.getUtxoMapNote().get(shieldInputList.get(i)); OutputPoint.Builder outPointBuild = OutputPoint.newBuilder(); outPointBuild.setHash(ByteString.copyFrom(noteTx.getTxid().toByteArray())); outPointBuild.setIndex(noteTx.getIndex()); request.addOutPoints(outPointBuild.build()); - //ShieldNoteInfo noteInfo = shieldWrapper.getUtxoMapNote().get(shieldInputList.get(i)); + // ShieldNoteInfo noteInfo = shieldWrapper.getUtxoMapNote().get(shieldInputList.get(i)); - //String shieldAddress = noteInfo.getPaymentAddress(); - //ShieldAddressInfo addressInfo = + // String shieldAddress = noteInfo.getPaymentAddress(); + // ShieldAddressInfo addressInfo = // shieldWrapper.getShieldAddressInfoMap().get(shieldAddress); SpendingKey spendingKey = new SpendingKey(shieldAddressInfo.getSk()); try { @@ -5042,44 +5442,46 @@ public static boolean sendShieldCoin(byte[] publicZenTokenOwnerAddress, long fro noteBuild.setRcm(ByteString.copyFrom(noteTx.getNote().getRcm().toByteArray())); noteBuild.setMemo(ByteString.copyFrom(noteTx.getNote().getMemo().toByteArray())); - //System.out.println("address " + noteInfo.getPaymentAddress()); - //System.out.println("value " + noteInfo.getValue()); - //System.out.println("rcm " + ByteArray.toHexString(noteInfo.getR())); - //System.out.println("trxId " + noteInfo.getTrxId()); - //System.out.println("index " + noteInfo.getIndex()); - //System.out.println("meno " + new String(noteInfo.getMemo())); + // System.out.println("address " + noteInfo.getPaymentAddress()); + // System.out.println("value " + noteInfo.getValue()); + // System.out.println("rcm " + ByteArray.toHexString(noteInfo.getR())); + // System.out.println("trxId " + noteInfo.getTrxId()); + // System.out.println("index " + noteInfo.getIndex()); + // System.out.println("meno " + new String(noteInfo.getMemo())); SpendNote.Builder spendNoteBuilder = SpendNote.newBuilder(); spendNoteBuilder.setNote(noteBuild.build()); try { - spendNoteBuilder.setAlpha(ByteString.copyFrom(stest.tron.wallet.common.client.utils.zen.note.Note.generateR())); + spendNoteBuilder.setAlpha( + ByteString.copyFrom(stest.tron.wallet.common.client.utils.zen.note.Note.generateR())); } catch (Exception e) { System.out.println(e); } - IncrementalMerkleVoucherInfo merkleVoucherInfo = blockingStubFull - .getMerkleTreeVoucherInfo(request.build()); + IncrementalMerkleVoucherInfo merkleVoucherInfo = + blockingStubFull.getMerkleTreeVoucherInfo(request.build()); spendNoteBuilder.setVoucher(merkleVoucherInfo.getVouchers(0)); spendNoteBuilder.setPath(merkleVoucherInfo.getPaths(0)); builder.addShieldedSpends(spendNoteBuilder.build()); } else { - byte[] ovk = ByteArray - .fromHexString("030c8c2bc59fb3eb8afb047a8ea4b028743d23e7d38c6fa30908358431e2314d"); + byte[] ovk = + ByteArray.fromHexString( + "030c8c2bc59fb3eb8afb047a8ea4b028743d23e7d38c6fa30908358431e2314d"); builder.setOvk(ByteString.copyFrom(ovk)); } if (shieldOutputList.size() > 0) { for (int i = 0; i < shieldOutputList.size(); ++i) { - builder - .addShieldedReceives(ReceiveNote.newBuilder().setNote(shieldOutputList.get(i)).build()); + builder.addShieldedReceives( + ReceiveNote.newBuilder().setNote(shieldOutputList.get(i)).build()); } } - TransactionExtention transactionExtention = blockingStubFull - .createShieldedTransaction(builder.build()); + TransactionExtention transactionExtention = + blockingStubFull.createShieldedTransaction(builder.build()); if (transactionExtention == null) { return false; } @@ -5099,24 +5501,30 @@ public static boolean sendShieldCoin(byte[] publicZenTokenOwnerAddress, long fro Any any = transaction.getRawData().getContract(0).getParameter(); try { - ShieldContract.ShieldedTransferContract shieldedTransferContract = any - .unpack(ShieldContract.ShieldedTransferContract.class); + ShieldContract.ShieldedTransferContract shieldedTransferContract = + any.unpack(ShieldContract.ShieldedTransferContract.class); if (shieldedTransferContract.getFromAmount() > 0 || fromAmount == 321321) { Transaction.raw.Builder raw = transaction.getRawData().toBuilder(); - Transaction.Contract.Builder contract = raw.getContract(0).toBuilder() - .setPermissionId(permission_id); + Transaction.Contract.Builder contract = + raw.getContract(0).toBuilder().setPermissionId(permission_id); raw.clearContract(); raw.addContract(contract); transaction = transaction.toBuilder().setRawData(raw).build(); transaction = signTransactionForShield(transaction, blockingStubFull, permissionKeyString); - System.out.println("trigger txid = " + ByteArray - .toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()))); + System.out.println( + "trigger txid = " + + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()))); } else { - System.out.println("trigger txid = " + ByteArray - .toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()))); + System.out.println( + "trigger txid = " + + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()))); } } catch (Exception e) { System.out.println(e); @@ -5124,23 +5532,20 @@ public static boolean sendShieldCoin(byte[] publicZenTokenOwnerAddress, long fro return broadcastTransaction(transaction, blockingStubFull); } - - /** - * constructor. - */ - private static Transaction signTransactionForShield(Transaction transaction, - WalletGrpc.WalletBlockingStub blockingStubFull, String[] priKeys) { + /** constructor. */ + private static Transaction signTransactionForShield( + Transaction transaction, WalletGrpc.WalletBlockingStub blockingStubFull, String[] priKeys) { /* if (transaction.getRawData().getTimestamp() == 0) { - transaction = TransactionUtils.setTimestamp(transaction); - } + transaction = TransactionUtils.setTimestamp(transaction); + } - long currentTime = System.currentTimeMillis();//*1000000 + System.nanoTime()%1000000; - Transaction.Builder builder = transaction.toBuilder(); - org.tron.protos.Protocol.Transaction.raw.Builder rowBuilder = transaction.getRawData() - .toBuilder(); - rowBuilder.setTimestamp(currentTime); - builder.setRawData(rowBuilder.build()); - transaction = builder.build();*/ + long currentTime = System.currentTimeMillis();//*1000000 + System.nanoTime()%1000000; + Transaction.Builder builder = transaction.toBuilder(); + org.tron.protos.Protocol.Transaction.raw.Builder rowBuilder = transaction.getRawData() + .toBuilder(); + rowBuilder.setTimestamp(currentTime); + builder.setRawData(rowBuilder.build()); + transaction = builder.build();*/ for (int i = 0; i < priKeys.length; i += 1) { String priKey = priKeys[i]; @@ -5168,11 +5573,14 @@ private static Transaction signTransactionForShield(Transaction transaction, return transaction; } - /** - * constructor. - */ - public static boolean createWitness(String url, byte[] owner, String priKey, int permissionId, - String[] permissionKeyString, WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public static boolean createWitness( + String url, + byte[] owner, + String priKey, + int permissionId, + String[] permissionKeyString, + WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -5193,8 +5601,8 @@ public static boolean createWitness(String url, byte[] owner, String priKey, int System.out.println("RPC create trx failed!"); if (transactionExtention != null) { System.out.println("Code = " + transactionExtention.getResult().getCode()); - System.out - .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + System.out.println( + "Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); } return false; } @@ -5224,12 +5632,14 @@ public static boolean createWitness(String url, byte[] owner, String priKey, int return broadcastTransaction(transaction, blockingStubFull); } - /** - * constructor. - */ - - public static boolean updateWitness2(byte[] owner, byte[] url, String priKey, int permissionId, - String[] permissionKeyString, WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public static boolean updateWitness2( + byte[] owner, + byte[] url, + String priKey, + int permissionId, + String[] permissionKeyString, + WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -5277,11 +5687,13 @@ public static boolean updateWitness2(byte[] owner, byte[] url, String priKey, in return true; } - /** - * constructor. - */ - public static boolean withdrawBalance(byte[] address, String priKey, int permissionId, - String[] permissionKeyString, WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public static boolean withdrawBalance( + byte[] address, + String priKey, + int permissionId, + String[] permissionKeyString, + WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -5315,11 +5727,13 @@ public static boolean withdrawBalance(byte[] address, String priKey, int permiss return true; } - /** - * constructor. - */ - public static boolean unFreezeAsset(byte[] addRess, String priKey, int permissionId, - String[] permissionKeyString, WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public static boolean unFreezeAsset( + byte[] addRess, + String priKey, + int permissionId, + String[] permissionKeyString, + WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address = addRess; ECKey temKey = null; try { @@ -5352,13 +5766,15 @@ public static boolean unFreezeAsset(byte[] addRess, String priKey, int permissio return true; } - /** - * constructor. - */ - - public static Transaction sendcoinGetTransaction(byte[] to, long amount, byte[] owner, - String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, String[] permissionKeyString) { - //String priKey = testKey002; + /** constructor. */ + public static Transaction sendcoinGetTransaction( + byte[] to, + long amount, + byte[] owner, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull, + String[] permissionKeyString) { + // String priKey = testKey002; ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -5367,7 +5783,7 @@ public static Transaction sendcoinGetTransaction(byte[] to, long amount, byte[] ex.printStackTrace(); } final ECKey ecKey = temKey; - //Protocol.Account search = queryAccount(priKey, blockingStubFull); + // Protocol.Account search = queryAccount(priKey, blockingStubFull); TransferContract.Builder builder = TransferContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); @@ -5385,14 +5801,16 @@ public static Transaction sendcoinGetTransaction(byte[] to, long amount, byte[] transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); return transaction; - } - /** - * constructor. - */ - public static boolean updateBrokerage(byte[] owner, int brokerage, String priKey, - int permissionId, String[] priKeys, WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public static boolean updateBrokerage( + byte[] owner, + int brokerage, + String priKey, + int permissionId, + String[] priKeys, + WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { @@ -5405,14 +5823,14 @@ public static boolean updateBrokerage(byte[] owner, int brokerage, String priKey UpdateBrokerageContract.Builder updateBrokerageContract = UpdateBrokerageContract.newBuilder(); updateBrokerageContract.setOwnerAddress(ByteString.copyFrom(owner)).setBrokerage(brokerage); - TransactionExtention transactionExtention = blockingStubFull - .updateBrokerage(updateBrokerageContract.build()); + TransactionExtention transactionExtention = + blockingStubFull.updateBrokerage(updateBrokerageContract.build()); Protocol.Transaction transaction = transactionExtention.getTransaction(); if (transactionExtention == null || !transactionExtention.getResult().getResult()) { if (transactionExtention != null) { System.out.println("Code = " + transactionExtention.getResult().getCode()); - System.out - .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + System.out.println( + "Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); } return false; } @@ -5423,22 +5841,29 @@ public static boolean updateBrokerage(byte[] owner, int brokerage, String priKey e.printStackTrace(); } - System.out.println("trigger txid = " + ByteArray - .toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()))); + System.out.println( + "trigger txid = " + + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()))); 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) { + /** 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(); + MarketContract.MarketSellAssetContract.Builder builder = + MarketContract.MarketSellAssetContract.newBuilder(); builder .setOwnerAddress(ByteString.copyFrom(owner)) .setSellTokenId(ByteString.copyFrom(sellTokenId)) @@ -5462,8 +5887,7 @@ public static boolean marketSellAsset(byte[] owner, byte[] sellTokenId, return false; } - if (transaction.getRawData().getContract(0).getType() - != ContractType.MarketSellAssetContract) { + if (transaction.getRawData().getContract(0).getType() != ContractType.MarketSellAssetContract) { return false; } @@ -5474,18 +5898,18 @@ public static boolean marketSellAsset(byte[] owner, byte[] sellTokenId, e.printStackTrace(); } return broadcastTransaction(transaction, blockingStubFull); - } - /** - * constructor. - */ - public static boolean marketCancelOrder(byte[] owner, byte[] orderId, - int permissionId, String[] priKeys, + /** constructor. */ + public static boolean marketCancelOrder( + byte[] owner, + byte[] orderId, + int permissionId, + String[] priKeys, WalletBlockingStub blockingStubFull) { - MarketContract.MarketCancelOrderContract.Builder builder = MarketContract - .MarketCancelOrderContract.newBuilder(); + MarketContract.MarketCancelOrderContract.Builder builder = + MarketContract.MarketCancelOrderContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(owner)).setOrderId(ByteString.copyFrom(orderId)); TransactionExtention transactionExtention = blockingStubFull.marketCancelOrder(builder.build()); @@ -5507,14 +5931,14 @@ public static boolean marketCancelOrder(byte[] owner, byte[] orderId, if (transaction.getRawData().getContract(0).getType() != ContractType.MarketCancelOrderContract) { - System.out.println("Wrong ContractType :" - + transaction.getRawData().getContract(0).getType()); + System.out.println( + "Wrong ContractType :" + transaction.getRawData().getContract(0).getType()); return false; } try { transaction = setPermissionId(transaction, permissionId); - transaction = signTransaction(transaction,blockingStubFull,priKeys); + transaction = signTransaction(transaction, blockingStubFull, priKeys); } catch (CancelException e) { e.printStackTrace(); } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ResourceHelper.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ResourceHelper.java index 15c08947..564d9dc1 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ResourceHelper.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ResourceHelper.java @@ -40,8 +40,8 @@ import org.tron.protos.contract.StorageContract.SellStorageContract; /** - * Helper class for resource and staking related operations including freeze, unfreeze, - * delegate, storage, and resource query methods extracted from PublicMethod. + * Helper class for resource and staking related operations including freeze, unfreeze, delegate, + * storage, and resource query methods extracted from PublicMethod. */ @Slf4j public class ResourceHelper { @@ -56,16 +56,18 @@ public static Boolean freezeBalance( String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - if(PublicMethod.getChainParametersValue(ProposalEnum.GetUnfreezeDelayDays.getProposalName(), - blockingStubFull) <= 0) { - return freezeBalanceV1(addRess,freezeBalance,freezeDuration,0,priKey,blockingStubFull); + if (PublicMethod.getChainParametersValue( + ProposalEnum.GetUnfreezeDelayDays.getProposalName(), blockingStubFull) + <= 0) { + return freezeBalanceV1(addRess, freezeBalance, freezeDuration, 0, priKey, blockingStubFull); } else { - return freezeBalanceV2(addRess,freezeBalance,0,priKey,blockingStubFull); + return freezeBalanceV2(addRess, freezeBalance, 0, priKey, blockingStubFull); } } /** Freeze balance V1 for a specific receiver address. */ - public static Boolean freezeBalanceV1ForReceiver(byte[] addRess, + public static Boolean freezeBalanceV1ForReceiver( + byte[] addRess, long freezeBalance, long freezeDuration, int resourceCode, @@ -84,7 +86,6 @@ public static Boolean freezeBalanceV1ForReceiver(byte[] addRess, } final ECKey ecKey = temKey; - FreezeBalanceContract.Builder builder = FreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); @@ -94,7 +95,7 @@ public static Boolean freezeBalanceV1ForReceiver(byte[] addRess, .setResourceValue(resourceCode) .setFrozenDuration(frozenDuration); - if(null != receiverAddress) { + if (null != receiverAddress) { builder.setReceiverAddress(ByteString.copyFrom(receiverAddress)); } @@ -113,7 +114,6 @@ public static Boolean freezeBalanceV1ForReceiver(byte[] addRess, return response.getResult(); } - /** Freeze balance V1 without a receiver (self-freeze). */ public static Boolean freezeBalanceV1( byte[] addRess, @@ -122,7 +122,8 @@ public static Boolean freezeBalanceV1( int resourceCode, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return freezeBalanceV1ForReceiver(addRess,freezeBalance,freezeDuration,resourceCode,null,priKey,blockingStubFull); + return freezeBalanceV1ForReceiver( + addRess, freezeBalance, freezeDuration, resourceCode, null, priKey, blockingStubFull); } /** Freeze balance using the freezeBalance2 RPC and return the gRPC Return result. */ @@ -219,7 +220,8 @@ public static Return freezeBalance2( // --- Freeze Balance V2 --- /** Freeze balance V2 and return success boolean. */ - public static Boolean freezeBalanceV2(byte[] addressByte, + public static Boolean freezeBalanceV2( + byte[] addressByte, long freezeBalance, int resourceCode, String priKey, @@ -232,7 +234,7 @@ public static Boolean freezeBalanceV2(byte[] addressByte, ex.printStackTrace(); } final ECKey ecKey = temKey; - FreezeBalanceV2Contract.Builder builder = FreezeBalanceV2Contract.newBuilder(); + FreezeBalanceV2Contract.Builder builder = FreezeBalanceV2Contract.newBuilder(); ByteString byteAddress = ByteString.copyFrom(addressByte); builder .setOwnerAddress(byteAddress) @@ -246,20 +248,22 @@ public static Boolean freezeBalanceV2(byte[] addressByte, return false; } transaction = TransactionUtils.sign(transaction, ecKey); - PublicMethod.freezeV2Txid = ByteArray.toHexString( - Sha256Hash.hash( - CommonParameter.getInstance().isECKeyCryptoEngine(), - transaction.getRawData().toByteArray())); + PublicMethod.freezeV2Txid = + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); GrpcAPI.Return response = PublicMethod.broadcastTransaction(transaction, blockingStubFull); return response.getResult(); } /** Freeze balance V2 and return the transaction ID string. */ - public static String freezeBalanceV2AndGetTxId(byte[] addressByte, - long freezeBalance, - int resourceCode, - String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull) { + public static String freezeBalanceV2AndGetTxId( + byte[] addressByte, + long freezeBalance, + int resourceCode, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -268,12 +272,12 @@ public static String freezeBalanceV2AndGetTxId(byte[] addressByte, ex.printStackTrace(); } final ECKey ecKey = temKey; - FreezeBalanceV2Contract.Builder builder = FreezeBalanceV2Contract.newBuilder(); + FreezeBalanceV2Contract.Builder builder = FreezeBalanceV2Contract.newBuilder(); ByteString byteAddress = ByteString.copyFrom(addressByte); builder - .setOwnerAddress(byteAddress) - .setFrozenBalance(freezeBalance) - .setResourceValue(resourceCode); + .setOwnerAddress(byteAddress) + .setFrozenBalance(freezeBalance) + .setResourceValue(resourceCode); FreezeBalanceV2Contract contract = builder.build(); TransactionExtention transactionExtention = blockingStubFull.freezeBalanceV2(contract); Protocol.Transaction transaction = transactionExtention.getTransaction(); @@ -282,24 +286,25 @@ public static String freezeBalanceV2AndGetTxId(byte[] addressByte, return null; } transaction = TransactionUtils.sign(transaction, ecKey); - String freezeV2Txid = ByteArray.toHexString( + String freezeV2Txid = + ByteArray.toHexString( Sha256Hash.hash( - CommonParameter.getInstance().isECKeyCryptoEngine(), - transaction.getRawData().toByteArray())); + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); GrpcAPI.Return response = PublicMethod.broadcastTransaction(transaction, blockingStubFull); return freezeV2Txid; } /** Get the frozen V2 amount for a specific resource code. */ - public static Long getFrozenV2Amount(byte[] address, int resourceCode,WalletGrpc.WalletBlockingStub blockingStubFull) { - List list = PublicMethod.queryAccount(address,blockingStubFull).getFrozenV2List(); - for(int i = 0; i < list.size();i++) { - if(list.get(i).getType().getNumber() == resourceCode) { + public static Long getFrozenV2Amount( + byte[] address, int resourceCode, WalletGrpc.WalletBlockingStub blockingStubFull) { + List list = PublicMethod.queryAccount(address, blockingStubFull).getFrozenV2List(); + for (int i = 0; i < list.size(); i++) { + if (list.get(i).getType().getNumber() == resourceCode) { return list.get(i).getAmount(); } } return 0L; - } // --- Unfreeze Balance --- @@ -311,14 +316,13 @@ public static Boolean unFreezeBalance( int resourceCode, byte[] receiverAddress, WalletGrpc.WalletBlockingStub blockingStubFull) { - if(freezeV2ProposalIsOpen(blockingStubFull)) { - return unFreezeBalanceV2(address,priKey,0,resourceCode,blockingStubFull); + if (freezeV2ProposalIsOpen(blockingStubFull)) { + return unFreezeBalanceV2(address, priKey, 0, resourceCode, blockingStubFull); } else { - return unFreezeBalanceV1(address,priKey,resourceCode,receiverAddress,blockingStubFull); + return unFreezeBalanceV1(address, priKey, resourceCode, receiverAddress, blockingStubFull); } } - /** Unfreeze balance V1 with optional receiver address. */ public static Boolean unFreezeBalanceV1( byte[] address, @@ -350,7 +354,6 @@ public static Boolean unFreezeBalanceV1( return response.getResult(); } - /** Unfreeze balance V2 with specified amount and resource code. */ public static Boolean unFreezeBalanceV2( byte[] address, @@ -368,17 +371,20 @@ public static Boolean unFreezeBalanceV2( final ECKey ecKey = temKey; UnfreezeBalanceV2Contract.Builder builder = UnfreezeBalanceV2Contract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess) - .setResourceValue(resourceCode).setUnfreezeBalance(unFreezeBalanceAmount); + builder + .setOwnerAddress(byteAddreess) + .setResourceValue(resourceCode) + .setUnfreezeBalance(unFreezeBalanceAmount); UnfreezeBalanceV2Contract contract = builder.build(); TransactionExtention transactionExtention = blockingStubFull.unfreezeBalanceV2(contract); Transaction transaction = transactionExtention.getTransaction(); transaction = PublicMethod.signTransaction(ecKey, transaction); - PublicMethod.freezeV2Txid = ByteArray.toHexString( - Sha256Hash.hash( - CommonParameter.getInstance().isECKeyCryptoEngine(), - transaction.getRawData().toByteArray())); + PublicMethod.freezeV2Txid = + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); GrpcAPI.Return response = PublicMethod.broadcastTransaction(transaction, blockingStubFull); return response.getResult(); @@ -386,11 +392,11 @@ public static Boolean unFreezeBalanceV2( /** Unfreeze balance V2 and return the transaction ID string. */ public static String unFreezeBalanceV2AndGetTxId( - byte[] address, - String priKey, - long unFreezeBalanceAmount, - int resourceCode, - WalletGrpc.WalletBlockingStub blockingStubFull) { + byte[] address, + String priKey, + long unFreezeBalanceAmount, + int resourceCode, + WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -401,17 +407,20 @@ public static String unFreezeBalanceV2AndGetTxId( final ECKey ecKey = temKey; UnfreezeBalanceV2Contract.Builder builder = UnfreezeBalanceV2Contract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess) - .setResourceValue(resourceCode).setUnfreezeBalance(unFreezeBalanceAmount); + builder + .setOwnerAddress(byteAddreess) + .setResourceValue(resourceCode) + .setUnfreezeBalance(unFreezeBalanceAmount); UnfreezeBalanceV2Contract contract = builder.build(); TransactionExtention transactionExtention = blockingStubFull.unfreezeBalanceV2(contract); Transaction transaction = transactionExtention.getTransaction(); transaction = PublicMethod.signTransaction(ecKey, transaction); - String txId = ByteArray.toHexString( + String txId = + ByteArray.toHexString( Sha256Hash.hash( - CommonParameter.getInstance().isECKeyCryptoEngine(), - transaction.getRawData().toByteArray())); + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); GrpcAPI.Return response = PublicMethod.broadcastTransaction(transaction, blockingStubFull); return txId; @@ -421,9 +430,7 @@ public static String unFreezeBalanceV2AndGetTxId( /** Cancel all pending unfreeze V2 operations and return success boolean. */ public static Boolean cancelAllUnFreezeBalanceV2( - byte[] address, - String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull) { + byte[] address, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -449,9 +456,7 @@ public static Boolean cancelAllUnFreezeBalanceV2( /** Cancel all pending unfreeze V2 operations and return the transaction ID. */ public static String cancelAllUnFreezeBalanceV2AndGetTxid( - byte[] address, - String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull) { + byte[] address, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -471,10 +476,11 @@ public static String cancelAllUnFreezeBalanceV2AndGetTxid( return null; } transaction = PublicMethod.signTransaction(ecKey, transaction); - String txId = ByteArray.toHexString( - Sha256Hash.hash( - CommonParameter.getInstance().isECKeyCryptoEngine(), - transaction.getRawData().toByteArray())); + String txId = + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); PublicMethod.broadcastTransaction(transaction, blockingStubFull); return txId; } @@ -483,9 +489,7 @@ public static String cancelAllUnFreezeBalanceV2AndGetTxid( /** Withdraw expired unfrozen balance and return success boolean. */ public static Boolean withdrawExpireUnfreeze( - byte[] address, - String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull) { + byte[] address, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -502,10 +506,11 @@ public static Boolean withdrawExpireUnfreeze( TransactionExtention transactionExtention = blockingStubFull.withdrawExpireUnfreeze(contract); Transaction transaction = transactionExtention.getTransaction(); transaction = PublicMethod.signTransaction(ecKey, transaction); - PublicMethod.freezeV2Txid = ByteArray.toHexString( - Sha256Hash.hash( - CommonParameter.getInstance().isECKeyCryptoEngine(), - transaction.getRawData().toByteArray())); + PublicMethod.freezeV2Txid = + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); GrpcAPI.Return response = PublicMethod.broadcastTransaction(transaction, blockingStubFull); return response.getResult(); @@ -513,9 +518,7 @@ public static Boolean withdrawExpireUnfreeze( /** Withdraw expired unfrozen balance and return the transaction ID. */ public static String withdrawExpireUnfreezeAndGetTxId( - byte[] address, - String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull) { + byte[] address, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -532,10 +535,11 @@ public static String withdrawExpireUnfreezeAndGetTxId( TransactionExtention transactionExtention = blockingStubFull.withdrawExpireUnfreeze(contract); Transaction transaction = transactionExtention.getTransaction(); transaction = PublicMethod.signTransaction(ecKey, transaction); - String freezeV2Txid = ByteArray.toHexString( + String freezeV2Txid = + ByteArray.toHexString( Sha256Hash.hash( - CommonParameter.getInstance().isECKeyCryptoEngine(), - transaction.getRawData().toByteArray())); + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); GrpcAPI.Return response = PublicMethod.broadcastTransaction(transaction, blockingStubFull); return freezeV2Txid; @@ -545,28 +549,32 @@ public static String withdrawExpireUnfreezeAndGetTxId( /** Check whether the freeze V2 proposal (unfreeze delay days) is active. */ public static Boolean freezeV2ProposalIsOpen(WalletGrpc.WalletBlockingStub blockingStubFull) { - return PublicMethod.getChainParametersValue(ProposalEnum.GetUnfreezeDelayDays - .getProposalName(), blockingStubFull) > 0; + return PublicMethod.getChainParametersValue( + ProposalEnum.GetUnfreezeDelayDays.getProposalName(), blockingStubFull) + > 0; } - /** Check whether the TRON Power proposal (new resource model) is active. */ public static Boolean tronPowerProposalIsOpen(WalletGrpc.WalletBlockingStub blockingStubFull) { - return PublicMethod.getChainParametersValue(ProposalEnum.GetAllowNewResourceModel - .getProposalName(), blockingStubFull) == 1; + return PublicMethod.getChainParametersValue( + ProposalEnum.GetAllowNewResourceModel.getProposalName(), blockingStubFull) + == 1; } /** Check whether the dynamic energy proposal is active. */ - public static Boolean getAllowDynamicEnergyProposalIsOpen(WalletGrpc.WalletBlockingStub blockingStubFull) { - return PublicMethod.getChainParametersValue(ProposalEnum.GetAllowDynamicEnergy - .getProposalName(), blockingStubFull) == 1; + public static Boolean getAllowDynamicEnergyProposalIsOpen( + WalletGrpc.WalletBlockingStub blockingStubFull) { + return PublicMethod.getChainParametersValue( + ProposalEnum.GetAllowDynamicEnergy.getProposalName(), blockingStubFull) + == 1; } // --- Price Queries --- /** Get the memo fee from chain parameters. */ public static Long getProposalMemoFee(WalletGrpc.WalletBlockingStub blockingStubFull) { - return PublicMethod.getChainParametersValue(ProposalEnum.GetMemoFee.getProposalName(),blockingStubFull); + return PublicMethod.getChainParametersValue( + ProposalEnum.GetMemoFee.getProposalName(), blockingStubFull); } /** Get the memo fee prices string from the full node. */ @@ -580,7 +588,8 @@ public static String getEnergyPrice(WalletGrpc.WalletBlockingStub blockingStubFu } /** Get the energy price history string from the solidity node. */ - public static String getEnergyPriceSolidity(WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { + public static String getEnergyPriceSolidity( + WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { return blockingStubFull.getEnergyPrices(EmptyMessage.newBuilder().build()).getPrices(); } @@ -590,7 +599,8 @@ public static String getBandwidthPrices(WalletGrpc.WalletBlockingStub blockingSt } /** Get the bandwidth price history string from the solidity node. */ - public static String getBandwidthPricesSolidity(WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { + public static String getBandwidthPricesSolidity( + WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { return blockingStubFull.getBandwidthPrices(EmptyMessage.newBuilder().build()).getPrices(); } @@ -605,7 +615,7 @@ public static Boolean freezeBalanceGetTronPower( ByteString receiverAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - if(tronPowerProposalIsOpen(blockingStubFull) && !freezeV2ProposalIsOpen(blockingStubFull)) { + if (tronPowerProposalIsOpen(blockingStubFull) && !freezeV2ProposalIsOpen(blockingStubFull)) { return freezeBalanceForReceiver( address, freezeBalance, @@ -616,28 +626,21 @@ public static Boolean freezeBalanceGetTronPower( blockingStubFull); } - - if(!tronPowerProposalIsOpen(blockingStubFull) && !freezeV2ProposalIsOpen(blockingStubFull)) { + if (!tronPowerProposalIsOpen(blockingStubFull) && !freezeV2ProposalIsOpen(blockingStubFull)) { return freezeBalanceForReceiver( - address, - freezeBalance, - freezeDuration, - 0, - receiverAddress, - priKey, - blockingStubFull); + address, freezeBalance, freezeDuration, 0, receiverAddress, priKey, blockingStubFull); } - - if(!tronPowerProposalIsOpen(blockingStubFull) && freezeV2ProposalIsOpen(blockingStubFull) + if (!tronPowerProposalIsOpen(blockingStubFull) + && freezeV2ProposalIsOpen(blockingStubFull) && null == receiverAddress) { - return freezeBalanceV2(address,freezeBalance,0,priKey,blockingStubFull); + return freezeBalanceV2(address, freezeBalance, 0, priKey, blockingStubFull); } - if(tronPowerProposalIsOpen(blockingStubFull) + if (tronPowerProposalIsOpen(blockingStubFull) && freezeV2ProposalIsOpen(blockingStubFull) && null == receiverAddress) { - return freezeBalanceV2(address,freezeBalance,resourceCode,priKey,blockingStubFull); + return freezeBalanceV2(address, freezeBalance, resourceCode, priKey, blockingStubFull); } return false; } @@ -650,11 +653,13 @@ public static Boolean freezeBalanceGetEnergy( int resourceCode, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - if(PublicMethod.getChainParametersValue(ProposalEnum.GetUnfreezeDelayDays.getProposalName(), - blockingStubFull) == 0) { - return freezeBalanceV1(addRess,freezeBalance,freezeDuration,resourceCode,priKey,blockingStubFull); + if (PublicMethod.getChainParametersValue( + ProposalEnum.GetUnfreezeDelayDays.getProposalName(), blockingStubFull) + == 0) { + return freezeBalanceV1( + addRess, freezeBalance, freezeDuration, resourceCode, priKey, blockingStubFull); } else { - return freezeBalanceV2(addRess,freezeBalance,resourceCode,priKey,blockingStubFull); + return freezeBalanceV2(addRess, freezeBalance, resourceCode, priKey, blockingStubFull); } } @@ -667,11 +672,25 @@ public static Boolean freezeBalanceForReceiver( ByteString receiverAddressBytes, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - if(PublicMethod.getChainParametersValue(ProposalEnum.GetUnfreezeDelayDays.getProposalName(), blockingStubFull) > 0) { - return delegateResourceForReceiver(addRess,freezeBalance,resourceCode,receiverAddressBytes.toByteArray(),priKey,blockingStubFull); + if (PublicMethod.getChainParametersValue( + ProposalEnum.GetUnfreezeDelayDays.getProposalName(), blockingStubFull) + > 0) { + return delegateResourceForReceiver( + addRess, + freezeBalance, + resourceCode, + receiverAddressBytes.toByteArray(), + priKey, + blockingStubFull); } else { - return freezeBalanceV1ForReceiver(addRess,freezeBalance,freezeDuration,resourceCode, - null == receiverAddressBytes ? null : receiverAddressBytes.toByteArray(),priKey,blockingStubFull); + return freezeBalanceV1ForReceiver( + addRess, + freezeBalance, + freezeDuration, + resourceCode, + null == receiverAddressBytes ? null : receiverAddressBytes.toByteArray(), + priKey, + blockingStubFull); } } @@ -888,14 +907,13 @@ public static Optional getDelegatedResource( .setFromAddress(fromAddressBs) .setToAddress(toAddressBs) .build(); - if(freezeV2ProposalIsOpen(blockingStubFull)) { + if (freezeV2ProposalIsOpen(blockingStubFull)) { DelegatedResourceList delegatedResource = blockingStubFull.getDelegatedResourceV2(request); return Optional.ofNullable(delegatedResource); } else { DelegatedResourceList delegatedResource = blockingStubFull.getDelegatedResource(request); return Optional.ofNullable(delegatedResource); } - } /** Get delegated resource list from solidity node. */ @@ -921,7 +939,7 @@ public static Optional getDelegatedResourceAccoun byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); BytesMessage bytesMessage = BytesMessage.newBuilder().setValue(addressBs).build(); - if(freezeV2ProposalIsOpen(blockingStubFull)) { + if (freezeV2ProposalIsOpen(blockingStubFull)) { DelegatedResourceAccountIndex accountIndex = blockingStubFull.getDelegatedResourceAccountIndexV2(bytesMessage); return Optional.ofNullable(accountIndex); @@ -932,7 +950,6 @@ public static Optional getDelegatedResourceAccoun } } - /** Get delegated resource account index from solidity node. */ public static Optional getDelegatedResourceAccountIndexFromSolidity( @@ -966,7 +983,9 @@ public static Optional getDelegatedResourceV2( /** Get delegated resource V2 list between two addresses from solidity node. */ public static Optional getDelegatedResourceV2Solidity( - byte[] fromAddress, byte[] toAddress, WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { + byte[] fromAddress, + byte[] toAddress, + WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { // Wallet.setAddressPreFixByte()(); ByteString fromAddressBs = ByteString.copyFrom(fromAddress); ByteString toAddressBs = ByteString.copyFrom(toAddress); @@ -988,7 +1007,7 @@ public static Optional getDelegatedResourceAccoun BytesMessage bytesMessage = BytesMessage.newBuilder().setValue(addressBs).build(); DelegatedResourceAccountIndex accountIndex = - blockingStubFull.getDelegatedResourceAccountIndexV2(bytesMessage); + blockingStubFull.getDelegatedResourceAccountIndexV2(bytesMessage); return Optional.ofNullable(accountIndex); } @@ -1006,26 +1025,32 @@ public static Optional getDelegatedResourceAccoun // --- Can Delegated Max Size --- /** Get the maximum delegatable resource size for the given address and type from full node. */ - public static Optional getCanDelegatedMaxSize(byte[] ownerAddress, int type, - WalletGrpc.WalletBlockingStub blockingStub) { + public static Optional getCanDelegatedMaxSize( + byte[] ownerAddress, int type, WalletGrpc.WalletBlockingStub blockingStub) { ByteString ownerAddressBS = ByteString.copyFrom(ownerAddress); - CanDelegatedMaxSizeRequestMessage request = CanDelegatedMaxSizeRequestMessage.newBuilder() - .setOwnerAddress(ownerAddressBS) - .setType(type) - .build(); + CanDelegatedMaxSizeRequestMessage request = + CanDelegatedMaxSizeRequestMessage.newBuilder() + .setOwnerAddress(ownerAddressBS) + .setType(type) + .build(); CanDelegatedMaxSizeResponseMessage canDelegatedMaxSizeResponseMessage; canDelegatedMaxSizeResponseMessage = blockingStub.getCanDelegatedMaxSize(request); return Optional.ofNullable(canDelegatedMaxSizeResponseMessage); } - /** Get the maximum delegatable resource size for the given address and type from solidity node. */ - public static Optional getCanDelegatedMaxSizeSolidity(byte[] ownerAddress, int type, - WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { + /** + * Get the maximum delegatable resource size for the given address and type from solidity node. + */ + public static Optional getCanDelegatedMaxSizeSolidity( + byte[] ownerAddress, + int type, + WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { ByteString ownerAddressBS = ByteString.copyFrom(ownerAddress); - CanDelegatedMaxSizeRequestMessage request = CanDelegatedMaxSizeRequestMessage.newBuilder() - .setOwnerAddress(ownerAddressBS) - .setType(type) - .build(); + CanDelegatedMaxSizeRequestMessage request = + CanDelegatedMaxSizeRequestMessage.newBuilder() + .setOwnerAddress(ownerAddressBS) + .setType(type) + .build(); CanDelegatedMaxSizeResponseMessage canDelegatedMaxSizeResponseMessage; canDelegatedMaxSizeResponseMessage = blockingStubFull.getCanDelegatedMaxSize(request); return Optional.ofNullable(canDelegatedMaxSizeResponseMessage); @@ -1035,25 +1060,32 @@ public static Optional getCanDelegatedMaxSiz /** Get the withdrawable unfrozen amount for the given address and timestamp from full node. */ public static Optional getCanWithdrawUnfreezeAmount( - byte[] ownerAddress, long timestamp,WalletGrpc.WalletBlockingStub blockingStub) { + byte[] ownerAddress, long timestamp, WalletGrpc.WalletBlockingStub blockingStub) { ByteString ownerAddressBS = ByteString.copyFrom(ownerAddress); - CanWithdrawUnfreezeAmountRequestMessage request = CanWithdrawUnfreezeAmountRequestMessage.newBuilder() - .setOwnerAddress(ownerAddressBS) - .setTimestamp(timestamp) - .build(); + CanWithdrawUnfreezeAmountRequestMessage request = + CanWithdrawUnfreezeAmountRequestMessage.newBuilder() + .setOwnerAddress(ownerAddressBS) + .setTimestamp(timestamp) + .build(); CanWithdrawUnfreezeAmountResponseMessage canDelegatedMaxSizeResponseMessage; canDelegatedMaxSizeResponseMessage = blockingStub.getCanWithdrawUnfreezeAmount(request); return Optional.ofNullable(canDelegatedMaxSizeResponseMessage); } - /** Get the withdrawable unfrozen amount for the given address and timestamp from solidity node. */ - public static Optional getCanWithdrawUnfreezeAmountSolidity( - byte[] ownerAddress, long timestamp,WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { + /** + * Get the withdrawable unfrozen amount for the given address and timestamp from solidity node. + */ + public static Optional + getCanWithdrawUnfreezeAmountSolidity( + byte[] ownerAddress, + long timestamp, + WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { ByteString ownerAddressBS = ByteString.copyFrom(ownerAddress); - CanWithdrawUnfreezeAmountRequestMessage request = CanWithdrawUnfreezeAmountRequestMessage.newBuilder() - .setOwnerAddress(ownerAddressBS) - .setTimestamp(timestamp) - .build(); + CanWithdrawUnfreezeAmountRequestMessage request = + CanWithdrawUnfreezeAmountRequestMessage.newBuilder() + .setOwnerAddress(ownerAddressBS) + .setTimestamp(timestamp) + .build(); CanWithdrawUnfreezeAmountResponseMessage canDelegatedMaxSizeResponseMessage; canDelegatedMaxSizeResponseMessage = blockingStubFull.getCanWithdrawUnfreezeAmount(request); return Optional.ofNullable(canDelegatedMaxSizeResponseMessage); @@ -1063,23 +1095,26 @@ public static Optional getCanWithdrawU /** Get the available unfreeze count for the given address from full node. */ public static Optional getAvailableUnfreezeCount( - byte[] ownerAddress,WalletGrpc.WalletBlockingStub blockingStub) { + byte[] ownerAddress, WalletGrpc.WalletBlockingStub blockingStub) { ByteString ownerAddressBS = ByteString.copyFrom(ownerAddress); - GetAvailableUnfreezeCountRequestMessage request = GetAvailableUnfreezeCountRequestMessage.newBuilder() - .setOwnerAddress(ownerAddressBS) - .build(); + GetAvailableUnfreezeCountRequestMessage request = + GetAvailableUnfreezeCountRequestMessage.newBuilder() + .setOwnerAddress(ownerAddressBS) + .build(); GetAvailableUnfreezeCountResponseMessage getAvailableUnfreezeCountResponseMessage; getAvailableUnfreezeCountResponseMessage = blockingStub.getAvailableUnfreezeCount(request); return Optional.ofNullable(getAvailableUnfreezeCountResponseMessage); } /** Get the available unfreeze count for the given address from solidity node. */ - public static Optional getAvailableUnfreezeCountSolidity( - byte[] ownerAddress,WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { + public static Optional + getAvailableUnfreezeCountSolidity( + byte[] ownerAddress, WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFull) { ByteString ownerAddressBS = ByteString.copyFrom(ownerAddress); - GetAvailableUnfreezeCountRequestMessage request = GetAvailableUnfreezeCountRequestMessage.newBuilder() - .setOwnerAddress(ownerAddressBS) - .build(); + GetAvailableUnfreezeCountRequestMessage request = + GetAvailableUnfreezeCountRequestMessage.newBuilder() + .setOwnerAddress(ownerAddressBS) + .build(); GetAvailableUnfreezeCountResponseMessage getAvailableUnfreezeCountResponseMessage; getAvailableUnfreezeCountResponseMessage = blockingStubFull.getAvailableUnfreezeCount(request); return Optional.ofNullable(getAvailableUnfreezeCountResponseMessage); @@ -1088,7 +1123,8 @@ public static Optional getAvailableUnf // --- Delegate Resource --- /** Freeze V2 and delegate resource to a receiver address. */ - public static Boolean delegateResourceForReceiver(byte[] addressByte, + public static Boolean delegateResourceForReceiver( + byte[] addressByte, long delegateAmount, int resourceCode, byte[] receiverAddress, @@ -1102,10 +1138,11 @@ public static Boolean delegateResourceForReceiver(byte[] addressByte, ex.printStackTrace(); } final ECKey ecKey = temKey; - Assert.assertTrue(freezeBalanceV2(addressByte,delegateAmount,resourceCode,priKey,blockingStubFull)); + Assert.assertTrue( + freezeBalanceV2(addressByte, delegateAmount, resourceCode, priKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - DelegateResourceContract.Builder builder = DelegateResourceContract.newBuilder(); + DelegateResourceContract.Builder builder = DelegateResourceContract.newBuilder(); ByteString byteAddress = ByteString.copyFrom(addressByte); ByteString byteReceiverAddress = ByteString.copyFrom(receiverAddress); builder @@ -1125,27 +1162,42 @@ public static Boolean delegateResourceForReceiver(byte[] addressByte, return response.getResult(); } - /** Delegate resource V2 to a receiver (without lock). */ - public static Boolean delegateResourceV2(byte[] addressByte, + public static Boolean delegateResourceV2( + byte[] addressByte, long delegateAmount, int resourceCode, byte[] receiverAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - return delegateResourceV2Lock(addressByte,delegateAmount,resourceCode,false, null, receiverAddress,priKey, + return delegateResourceV2Lock( + addressByte, + delegateAmount, + resourceCode, + false, + null, + receiverAddress, + priKey, blockingStubFull); } /** Delegate resource V2 and return the transaction ID. */ - public static String delegateResourceV2AndGetTxId(byte[] addressByte, - long delegateAmount, - int resourceCode, - byte[] receiverAddress, - String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull) { - return delegateResourceV2LockAndGetTxId(addressByte,delegateAmount,resourceCode,false, null, receiverAddress,priKey, - blockingStubFull); + public static String delegateResourceV2AndGetTxId( + byte[] addressByte, + long delegateAmount, + int resourceCode, + byte[] receiverAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull) { + return delegateResourceV2LockAndGetTxId( + addressByte, + delegateAmount, + resourceCode, + false, + null, + receiverAddress, + priKey, + blockingStubFull); } /** Delegate resource V2 and return the full TransactionExtention. */ @@ -1168,7 +1220,7 @@ public static TransactionExtention delegateResourceV2AndGetTransactionExtention( } final ECKey ecKey = temKey; - DelegateResourceContract.Builder builder = DelegateResourceContract.newBuilder(); + DelegateResourceContract.Builder builder = DelegateResourceContract.newBuilder(); ByteString byteAddress = ByteString.copyFrom(addressByte); ByteString byteReceiverAddress = ByteString.copyFrom(receiverAddress); builder @@ -1188,18 +1240,18 @@ public static TransactionExtention delegateResourceV2AndGetTransactionExtention( return transactionExtention; } transaction = TransactionUtils.sign(transaction, ecKey); - String freezeV2Txid = ByteArray.toHexString( - Sha256Hash.hash( - CommonParameter.getInstance().isECKeyCryptoEngine(), - transaction.getRawData().toByteArray())); + String freezeV2Txid = + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); GrpcAPI.Return response = PublicMethod.broadcastTransaction(transaction, blockingStubFull); return transactionExtention; } - - /** Delegate resource V2 with optional lock and lock period, return success boolean. */ - public static Boolean delegateResourceV2Lock(byte[] addressByte, + public static Boolean delegateResourceV2Lock( + byte[] addressByte, long delegateAmount, int resourceCode, boolean lock, @@ -1216,7 +1268,7 @@ public static Boolean delegateResourceV2Lock(byte[] addressByte, } final ECKey ecKey = temKey; - DelegateResourceContract.Builder builder = DelegateResourceContract.newBuilder(); + DelegateResourceContract.Builder builder = DelegateResourceContract.newBuilder(); ByteString byteAddress = ByteString.copyFrom(addressByte); ByteString byteReceiverAddress = ByteString.copyFrom(receiverAddress); builder @@ -1236,23 +1288,25 @@ public static Boolean delegateResourceV2Lock(byte[] addressByte, return false; } transaction = TransactionUtils.sign(transaction, ecKey); - PublicMethod.freezeV2Txid = ByteArray.toHexString( - Sha256Hash.hash( - CommonParameter.getInstance().isECKeyCryptoEngine(), - transaction.getRawData().toByteArray())); + PublicMethod.freezeV2Txid = + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); GrpcAPI.Return response = PublicMethod.broadcastTransaction(transaction, blockingStubFull); return response.getResult(); } /** Delegate resource V2 with optional lock and lock period, return the transaction ID. */ - public static String delegateResourceV2LockAndGetTxId(byte[] addressByte, - long delegateAmount, - int resourceCode, - boolean lock, - Long lockPeriod, - byte[] receiverAddress, - String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull) { + public static String delegateResourceV2LockAndGetTxId( + byte[] addressByte, + long delegateAmount, + int resourceCode, + boolean lock, + Long lockPeriod, + byte[] receiverAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -1262,15 +1316,15 @@ public static String delegateResourceV2LockAndGetTxId(byte[] addressByte, } final ECKey ecKey = temKey; - DelegateResourceContract.Builder builder = DelegateResourceContract.newBuilder(); + DelegateResourceContract.Builder builder = DelegateResourceContract.newBuilder(); ByteString byteAddress = ByteString.copyFrom(addressByte); ByteString byteReceiverAddress = ByteString.copyFrom(receiverAddress); builder - .setOwnerAddress(byteAddress) - .setBalance(delegateAmount) - .setReceiverAddress(byteReceiverAddress) - .setResourceValue(resourceCode) - .setLock(lock); + .setOwnerAddress(byteAddress) + .setBalance(delegateAmount) + .setReceiverAddress(byteReceiverAddress) + .setResourceValue(resourceCode) + .setLock(lock); if (null != lockPeriod) { builder.setLockPeriod(lockPeriod); } @@ -1282,10 +1336,11 @@ public static String delegateResourceV2LockAndGetTxId(byte[] addressByte, return null; } transaction = TransactionUtils.sign(transaction, ecKey); - String freezeV2Txid = ByteArray.toHexString( + String freezeV2Txid = + ByteArray.toHexString( Sha256Hash.hash( - CommonParameter.getInstance().isECKeyCryptoEngine(), - transaction.getRawData().toByteArray())); + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); GrpcAPI.Return response = PublicMethod.broadcastTransaction(transaction, blockingStubFull); return freezeV2Txid; } @@ -1293,7 +1348,8 @@ public static String delegateResourceV2LockAndGetTxId(byte[] addressByte, // --- Undelegate Resource --- /** Undelegate resource V2 from a receiver address, return success boolean. */ - public static Boolean unDelegateResourceV2(byte[] addressByte, + public static Boolean unDelegateResourceV2( + byte[] addressByte, long delegateAmount, int resourceCode, byte[] receiverAddress, @@ -1308,7 +1364,7 @@ public static Boolean unDelegateResourceV2(byte[] addressByte, } final ECKey ecKey = temKey; - UnDelegateResourceContract.Builder builder = UnDelegateResourceContract.newBuilder(); + UnDelegateResourceContract.Builder builder = UnDelegateResourceContract.newBuilder(); ByteString byteAddress = ByteString.copyFrom(addressByte); ByteString byteReceiverAddress = ByteString.copyFrom(receiverAddress); builder @@ -1324,21 +1380,23 @@ public static Boolean unDelegateResourceV2(byte[] addressByte, return false; } transaction = TransactionUtils.sign(transaction, ecKey); - PublicMethod.freezeV2Txid = ByteArray.toHexString( - Sha256Hash.hash( - CommonParameter.getInstance().isECKeyCryptoEngine(), - transaction.getRawData().toByteArray())); + PublicMethod.freezeV2Txid = + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); GrpcAPI.Return response = PublicMethod.broadcastTransaction(transaction, blockingStubFull); return response.getResult(); } /** Undelegate resource V2 and return the transaction ID. */ - public static String unDelegateResourceV2AndGetTxId(byte[] addressByte, - long delegateAmount, - int resourceCode, - byte[] receiverAddress, - String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull) { + public static String unDelegateResourceV2AndGetTxId( + byte[] addressByte, + long delegateAmount, + int resourceCode, + byte[] receiverAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -1348,14 +1406,14 @@ public static String unDelegateResourceV2AndGetTxId(byte[] addressByte, } final ECKey ecKey = temKey; - UnDelegateResourceContract.Builder builder = UnDelegateResourceContract.newBuilder(); + UnDelegateResourceContract.Builder builder = UnDelegateResourceContract.newBuilder(); ByteString byteAddress = ByteString.copyFrom(addressByte); ByteString byteReceiverAddress = ByteString.copyFrom(receiverAddress); builder - .setOwnerAddress(byteAddress) - .setBalance(delegateAmount) - .setReceiverAddress(byteReceiverAddress) - .setResourceValue(resourceCode); + .setOwnerAddress(byteAddress) + .setBalance(delegateAmount) + .setReceiverAddress(byteReceiverAddress) + .setResourceValue(resourceCode); UnDelegateResourceContract contract = builder.build(); TransactionExtention transactionExtention = blockingStubFull.unDelegateResource(contract); Protocol.Transaction transaction = transactionExtention.getTransaction(); @@ -1364,21 +1422,23 @@ public static String unDelegateResourceV2AndGetTxId(byte[] addressByte, return null; } transaction = TransactionUtils.sign(transaction, ecKey); - String freezeV2Txid = ByteArray.toHexString( + String freezeV2Txid = + ByteArray.toHexString( Sha256Hash.hash( - CommonParameter.getInstance().isECKeyCryptoEngine(), - transaction.getRawData().toByteArray())); + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); GrpcAPI.Return response = PublicMethod.broadcastTransaction(transaction, blockingStubFull); return freezeV2Txid; } /** Undelegate resource V2 and return the full TransactionExtention. */ - public static TransactionExtention unDelegateResourceV2AndGetTransactionExtention(byte[] addressByte, - long delegateAmount, - int resourceCode, - byte[] receiverAddress, - String priKey, - WalletGrpc.WalletBlockingStub blockingStubFull) { + public static TransactionExtention unDelegateResourceV2AndGetTransactionExtention( + byte[] addressByte, + long delegateAmount, + int resourceCode, + byte[] receiverAddress, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -1388,7 +1448,7 @@ public static TransactionExtention unDelegateResourceV2AndGetTransactionExtentio } final ECKey ecKey = temKey; - UnDelegateResourceContract.Builder builder = UnDelegateResourceContract.newBuilder(); + UnDelegateResourceContract.Builder builder = UnDelegateResourceContract.newBuilder(); ByteString byteAddress = ByteString.copyFrom(addressByte); ByteString byteReceiverAddress = ByteString.copyFrom(receiverAddress); builder @@ -1404,10 +1464,11 @@ public static TransactionExtention unDelegateResourceV2AndGetTransactionExtentio return transactionExtention; } transaction = TransactionUtils.sign(transaction, ecKey); - String freezeV2Txid = ByteArray.toHexString( - Sha256Hash.hash( - CommonParameter.getInstance().isECKeyCryptoEngine(), - transaction.getRawData().toByteArray())); + String freezeV2Txid = + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray())); GrpcAPI.Return response = PublicMethod.broadcastTransaction(transaction, blockingStubFull); return transactionExtention; } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/Retry.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/Retry.java index 49cb58a9..916711c7 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/Retry.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/Retry.java @@ -7,9 +7,10 @@ * TestNG retry analyzer for flaky tests. * *

Configurable via system properties: + * *

    - *
  • {@code tron.test.retry.max} - max retry count (default: 2)
  • - *
  • {@code tron.test.retry.interval} - sleep between retries in ms (default: 3000)
  • + *
  • {@code tron.test.retry.max} - max retry count (default: 2) + *
  • {@code tron.test.retry.interval} - sleep between retries in ms (default: 3000) *
* *

Example: {@code -Dtron.test.retry.max=3 -Dtron.test.retry.interval=5000} @@ -32,9 +33,15 @@ public Retry() { public boolean retry(ITestResult result) { if (retryCount < maxRetryCount) { retryCount++; - System.out.println("Retrying test " + result.getName() + " [" - + getResultStatusName(result.getStatus()) + "] attempt " + retryCount - + "/" + maxRetryCount); + System.out.println( + "Retrying test " + + result.getName() + + " [" + + getResultStatusName(result.getStatus()) + + "] attempt " + + retryCount + + "/" + + maxRetryCount); try { Thread.sleep(intervalMs); } catch (InterruptedException e) { @@ -47,10 +54,14 @@ public boolean retry(ITestResult result) { private static String getResultStatusName(int status) { switch (status) { - case ITestResult.SUCCESS: return "SUCCESS"; - case ITestResult.FAILURE: return "FAILURE"; - case ITestResult.SKIP: return "SKIP"; - default: return "UNKNOWN"; + case ITestResult.SUCCESS: + return "SUCCESS"; + case ITestResult.FAILURE: + return "FAILURE"; + case ITestResult.SKIP: + return "SKIP"; + default: + return "UNKNOWN"; } } } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/RetryListener.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/RetryListener.java index 1e2ac832..e97580f1 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/RetryListener.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/RetryListener.java @@ -9,8 +9,11 @@ public class RetryListener implements IAnnotationTransformer { @Override - public void transform(ITestAnnotation testannotation, Class testClass, - Constructor testConstructor, Method testMethod) { + public void transform( + ITestAnnotation testannotation, + Class testClass, + Constructor testConstructor, + Method testMethod) { IRetryAnalyzer retry = testannotation.getRetryAnalyzer(); if (retry == null) { diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/RetryUtil.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/RetryUtil.java index 3ae60c6f..e09cf1f0 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/RetryUtil.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/RetryUtil.java @@ -7,10 +7,11 @@ /** * Utility for retry/polling patterns commonly used in system tests. * - *

Replaces the scattered {@code while (retryTimes-- > 0)} + {@code Thread.sleep()} patterns - * with a reusable, configurable helper. + *

Replaces the scattered {@code while (retryTimes-- > 0)} + {@code Thread.sleep()} patterns with + * a reusable, configurable helper. * *

Example usage: + * *

{@code
  * // Wait until a condition becomes true
  * boolean ok = RetryUtil.waitUntil(() -> getBalance(addr) > 0, 10, 3000);
@@ -50,6 +51,11 @@ public static boolean waitUntil(BooleanSupplier condition, int maxAttempts, long
     return condition.getAsBoolean();
   }
 
+  /** Convenience: wait until condition is true, using block interval (3s) and 10 attempts. */
+  public static boolean waitUntil(BooleanSupplier condition) {
+    return waitUntil(condition, 10, 3000);
+  }
+
   /**
    * Polls the given supplier until it returns a non-null result.
    *
@@ -74,11 +80,4 @@ public static  T pollUntilNonNull(Supplier supplier, int maxAttempts, long
     }
     return supplier.get();
   }
-
-  /**
-   * Convenience: wait until condition is true, using block interval (3s) and 10 attempts.
-   */
-  public static boolean waitUntil(BooleanSupplier condition) {
-    return waitUntil(condition, 10, 3000);
-  }
 }
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/Sha256Hash.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/Sha256Hash.java
index f49d28ba..217f5ba8 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/Sha256Hash.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/Sha256Hash.java
@@ -33,8 +33,6 @@
 import java.util.Arrays;
 import org.bouncycastle.crypto.digests.SM3Digest;
 
-
-
 /**
  * A Sha256Hash just wraps a byte[] so that equals and hashcode work correctly, allowing it to be
  * used as keys in a map. It also checks that the length is correct and provides a bit more type
@@ -49,11 +47,7 @@ public class Sha256Hash implements Serializable, Comparable {
 
   private long blockNum;
 
-
-  /**
-   * constructor.
-   */
-
+  /** constructor. */
   public Sha256Hash(long num, byte[] hash) {
     byte[] rawHashBytes = this.generateBlockId(num, hash);
     checkArgument(rawHashBytes.length == LENGTH);
@@ -61,10 +55,7 @@ public Sha256Hash(long num, byte[] hash) {
     this.blockNum = num;
   }
 
-  /**
-   * constructor.
-   */
-
+  /** constructor. */
   public Sha256Hash(long num, Sha256Hash hash) {
     byte[] rawHashBytes = this.generateBlockId(num, hash);
     checkArgument(rawHashBytes.length == LENGTH);
@@ -72,9 +63,7 @@ public Sha256Hash(long num, Sha256Hash hash) {
     this.blockNum = num;
   }
 
-  /**
-   * Use {@link #wrap(byte[])} instead.
-   */
+  /** Use {@link #wrap(byte[])} instead. */
   @Deprecated
   public Sha256Hash(byte[] rawHashBytes) {
     checkArgument(rawHashBytes.length == LENGTH);
@@ -97,9 +86,7 @@ public static Sha256Hash wrap(ByteString rawHashByteString) {
     return wrap(rawHashByteString.toByteArray());
   }
 
-  /**
-   * Use {@link #of(byte[])} instead: this old name is ambiguous.
-   */
+  /** Use {@link #of(byte[])} instead: this old name is ambiguous. */
   @Deprecated
   public static Sha256Hash create(boolean isSha256, byte[] contents) {
     return of(isSha256, contents);
@@ -131,9 +118,7 @@ public static Sha256Hash of(boolean isSha256, File file) throws IOException {
     }
   }
 
-  /**
-   * Use {@link #twiceOf(byte[])} instead: this old name is ambiguous.
-   */
+  /** Use {@link #twiceOf(byte[])} instead: this old name is ambiguous. */
   @Deprecated
   public static Sha256Hash createDouble(boolean isSha256, byte[] contents) {
     return twiceOf(isSha256, contents);
@@ -159,7 +144,7 @@ public static MessageDigest newDigest() {
     try {
       return MessageDigest.getInstance("SHA-256");
     } catch (NoSuchAlgorithmException e) {
-      throw new RuntimeException(e);  // Can't happen.
+      throw new RuntimeException(e); // Can't happen.
     }
   }
 
@@ -244,8 +229,14 @@ public static byte[] hashTwice(boolean isSha256, byte[] input, int offset, int l
    * Calculates the hash of hash on the given byte ranges. This is equivalent to concatenating the
    * two ranges and then passing the result to {@link #hashTwice(byte[])}.
    */
-  public static byte[] hashTwice(boolean isSha256, byte[] input1, int offset1, int length1,
-      byte[] input2, int offset2, int length2) {
+  public static byte[] hashTwice(
+      boolean isSha256,
+      byte[] input1,
+      int offset1,
+      int length1,
+      byte[] input2,
+      int offset2,
+      int length2) {
     if (isSha256) {
       MessageDigest digest = newDigest();
       digest.update(input1, offset1, length1);
@@ -303,13 +294,11 @@ public String toString() {
   @Override
   public int hashCode() {
     // Use the last 4 bytes, not the first 4 which are often zeros in Bitcoin.
-    return Ints
-        .fromBytes(bytes[LENGTH - 4], bytes[LENGTH - 3], bytes[LENGTH - 2], bytes[LENGTH - 1]);
+    return Ints.fromBytes(
+        bytes[LENGTH - 4], bytes[LENGTH - 3], bytes[LENGTH - 2], bytes[LENGTH - 1]);
   }
 
-  /**
-   * Returns the bytes interpreted as a positive integer.
-   */
+  /** Returns the bytes interpreted as a positive integer. */
   public BigInteger toBigInteger() {
     return new BigInteger(1, bytes);
   }
@@ -322,9 +311,7 @@ public byte[] getBytes() {
     return bytes;
   }
 
-  /**
-   * For pb return ByteString.
-   */
+  /** For pb return ByteString. */
   public ByteString getByteString() {
     return ByteString.copyFrom(bytes);
   }
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/Sha256Sm3Hash.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/Sha256Sm3Hash.java
index cea818a0..84c5d543 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/Sha256Sm3Hash.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/Sha256Sm3Hash.java
@@ -33,8 +33,6 @@
 import java.util.Arrays;
 import org.bouncycastle.crypto.digests.SM3Digest;
 
-
-
 /**
  * A Sha256Sm3Hash just wraps a byte[] so that equals and hashcode work correctly, allowing it to be
  * used as keys in a map. It also checks that the length is correct and provides a bit more type
@@ -69,9 +67,7 @@ public Sha256Sm3Hash(long num, Sha256Sm3Hash hash) {
     this.bytes = rawHashBytes;
   }
 
-  /**
-   * Use {@link #wrap(byte[])} instead.
-   */
+  /** Use {@link #wrap(byte[])} instead. */
   @Deprecated
   public Sha256Sm3Hash(byte[] rawHashBytes) {
     checkArgument(rawHashBytes.length == LENGTH);
@@ -94,9 +90,7 @@ public static Sha256Sm3Hash wrap(ByteString rawHashByteString) {
     return wrap(rawHashByteString.toByteArray());
   }
 
-  /**
-   * Use {@link #of(byte[])} instead: this old name is ambiguous.
-   */
+  /** Use {@link #of(byte[])} instead: this old name is ambiguous. */
   @Deprecated
   public static Sha256Sm3Hash create(byte[] contents) {
     return of(contents);
@@ -128,9 +122,7 @@ public static Sha256Sm3Hash of(File file) throws IOException {
     }
   }
 
-  /**
-   * Use {@link #twiceOf(byte[])} instead: this old name is ambiguous.
-   */
+  /** Use {@link #twiceOf(byte[])} instead: this old name is ambiguous. */
   @Deprecated
   public static Sha256Sm3Hash createDouble(byte[] contents) {
     return twiceOf(contents);
@@ -156,7 +148,7 @@ public static MessageDigest newDigest() {
     try {
       return MessageDigest.getInstance("SHA-256");
     } catch (NoSuchAlgorithmException e) {
-      throw new RuntimeException(e);  // Can't happen.
+      throw new RuntimeException(e); // Can't happen.
     }
   }
 
@@ -200,7 +192,6 @@ public static byte[] hash(byte[] input, int offset, int length) {
       digest.doFinal(eHash, 0);
       return eHash;
     }
-
   }
 
   /**
@@ -236,15 +227,14 @@ public static byte[] hashTwice(byte[] input, int offset, int length) {
       digest.doFinal(eHash, 0);
       return eHash;
     }
-
   }
 
   /**
    * Calculates the hash of hash on the given byte ranges. This is equivalent to concatenating the
    * two ranges and then passing the result to {@link #hashTwice(byte[])}.
    */
-  public static byte[] hashTwice(byte[] input1, int offset1, int length1,
-      byte[] input2, int offset2, int length2) {
+  public static byte[] hashTwice(
+      byte[] input1, int offset1, int length1, byte[] input2, int offset2, int length2) {
     if (isEckey) {
       MessageDigest digest = newDigest();
       digest.update(input1, offset1, length1);
@@ -300,13 +290,11 @@ public String toString() {
   @Override
   public int hashCode() {
     // Use the last 4 bytes, not the first 4 which are often zeros in Bitcoin.
-    return Ints
-        .fromBytes(bytes[LENGTH - 4], bytes[LENGTH - 3], bytes[LENGTH - 2], bytes[LENGTH - 1]);
+    return Ints.fromBytes(
+        bytes[LENGTH - 4], bytes[LENGTH - 3], bytes[LENGTH - 2], bytes[LENGTH - 1]);
   }
 
-  /**
-   * Returns the bytes interpreted as a positive integer.
-   */
+  /** Returns the bytes interpreted as a positive integer. */
   public BigInteger toBigInteger() {
     return new BigInteger(1, bytes);
   }
@@ -319,9 +307,7 @@ public byte[] getBytes() {
     return bytes;
   }
 
-  /**
-   * For pb return ByteString.
-   */
+  /** For pb return ByteString. */
   public ByteString getByteString() {
     return ByteString.copyFrom(bytes);
   }
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldAddressInfo.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldAddressInfo.java
index ad255a6f..2bb605f7 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldAddressInfo.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldAddressInfo.java
@@ -13,28 +13,16 @@
 import stest.tron.wallet.common.client.utils.zen.address.PaymentAddress;
 import stest.tron.wallet.common.client.utils.zen.address.SpendingKey;
 
-
 @AllArgsConstructor
 public class ShieldAddressInfo {
 
-  @Setter
-  @Getter
-  public byte[] sk;
-  @Setter
-  @Getter
-  public byte[] ivk; // 256
-  @Setter
-  @Getter
-  public byte[] ovk; // 256
-  @Setter
-  @Getter
-  DiversifierT d;
-  @Setter
-  @Getter
-  byte[] pkD; // 256
+  @Setter @Getter public byte[] sk;
+  @Setter @Getter public byte[] ivk; // 256
+  @Setter @Getter public byte[] ovk; // 256
+  @Setter @Getter DiversifierT d;
+  @Setter @Getter byte[] pkD; // 256
 
-  public ShieldAddressInfo() {
-  }
+  public ShieldAddressInfo() {}
 
   public static String getShieldAddress(DiversifierT d, byte[] pkD) {
     try {
@@ -51,9 +39,7 @@ public FullViewingKey getFullViewingKey() throws ZksnarkException {
     return spendingKey.fullViewingKey();
   }
 
-  /**
-   * check parameters.
-   */
+  /** check parameters. */
   public boolean validateCheck() {
     try {
       SpendingKey spendingKey = new SpendingKey(sk);
@@ -104,9 +90,7 @@ public String getAddress() {
   //    return paymentAddress;
   //  }
 
-  /**
-   * format shield address info to a string.
-   */
+  /** format shield address info to a string. */
   public String encode() {
     String encodeString = ByteArray.toHexString(sk) + ";";
     encodeString += ByteArray.toHexString(ivk);
@@ -119,9 +103,7 @@ public String encode() {
     return encodeString;
   }
 
-  /**
-   * constructor.
-   */
+  /** constructor. */
   public boolean decode(final String data) {
     String[] sourceStrArray = data.split(";");
     if (sourceStrArray.length != 5) {
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldHelper.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldHelper.java
index 8d0b70ed..bd90106b 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldHelper.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldHelper.java
@@ -49,7 +49,10 @@
 import stest.tron.wallet.common.client.utils.zen.address.SpendingKey;
 
 @Slf4j
-/** Helper for shielded/privacy operations: note management, shield transfers, and zero-knowledge proofs. */
+/**
+ * Helper for shielded/privacy operations: note management, shield transfers, and zero-knowledge
+ * proofs.
+ */
 public class ShieldHelper {
 
   public static Map utxoMapNote = new ConcurrentHashMap();
@@ -354,7 +357,8 @@ public static boolean sendShieldCoinWithoutAsk(
       }
 
       Transaction.raw.Builder rawBuilder =
-          transaction.toBuilder()
+          transaction
+              .toBuilder()
               .getRawDataBuilder()
               .clearContract()
               .addContract(
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldNoteInfo.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldNoteInfo.java
index 71e2eb4b..66006cc4 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldNoteInfo.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldNoteInfo.java
@@ -4,41 +4,21 @@
 import lombok.Getter;
 import lombok.Setter;
 
-
 @AllArgsConstructor
 public class ShieldNoteInfo {
 
-  @Setter
-  @Getter
-  public long value = 0;
-  @Setter
-  @Getter
-  public String paymentAddress;
-  @Setter
-  @Getter
-  public byte[] r; // 256
-  @Setter
-  @Getter
-  public String trxId;
-  @Setter
-  @Getter
-  public int index;
-  @Setter
-  @Getter
-  public long noteIndex;
-  @Setter
-  @Getter
-  public byte[] memo;
-  @Setter
-  @Getter
-  public Boolean isSpend;
+  @Setter @Getter public long value = 0;
+  @Setter @Getter public String paymentAddress;
+  @Setter @Getter public byte[] r; // 256
+  @Setter @Getter public String trxId;
+  @Setter @Getter public int index;
+  @Setter @Getter public long noteIndex;
+  @Setter @Getter public byte[] memo;
+  @Setter @Getter public Boolean isSpend;
 
-  public ShieldNoteInfo() {
-  }
+  public ShieldNoteInfo() {}
 
-  /**
-   * format shield note to a string.
-   */
+  /** format shield note to a string. */
   public String encode() {
     String encodeString = noteIndex + ";";
     encodeString += paymentAddress;
@@ -57,9 +37,7 @@ public String encode() {
     return encodeString;
   }
 
-  /**
-   * constructor.
-   */
+  /** constructor. */
   public boolean decode(final String data) {
     String[] sourceStrArray = data.split(";");
     if (sourceStrArray.length != 8) {
@@ -76,6 +54,4 @@ public boolean decode(final String data) {
     isSpend = Boolean.valueOf(sourceStrArray[7]);
     return true;
   }
-
 }
-
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldWrapper.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldWrapper.java
index e040d85a..e0b3a082 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldWrapper.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldWrapper.java
@@ -27,7 +27,6 @@
 import org.tron.protos.contract.ShieldContract.OutputPointInfo;
 import stest.tron.wallet.common.client.Configuration;
 
-
 public class ShieldWrapper {
 
   private static final String PREFIX_FOLDER = "WalletShield";
@@ -35,31 +34,21 @@ public class ShieldWrapper {
   private static final String UNSPEND_NOTE_FILE_NAME = PREFIX_FOLDER + "/unspendnote";
   private static final String SPEND_NOTE_FILE_NAME = PREFIX_FOLDER + "/spendnote";
   private static final String SHIELD_ADDRESS_FILE_NAME = PREFIX_FOLDER + "/shieldaddress";
-  //private WalletApi wallet;
+  // private WalletApi wallet;
   private static AtomicLong nodeIndex = new AtomicLong(0L);
-  @Getter
-  @Setter
-  public Map ivkMapScanBlockNum = new ConcurrentHashMap();
-  @Getter
-  @Setter
-  public Map utxoMapNote = new ConcurrentHashMap();
-
-  //Wallet wallet = new Wallet();
-  @Getter
-  @Setter
-  public List spendUtxoList = new ArrayList<>();
-  @Setter
-  @Getter
-  Map shieldAddressInfoMap = new ConcurrentHashMap();
-  private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list")
-      .get(0);
-  private ManagedChannel channelFull = ManagedChannelBuilder.forTarget(fullnode)
-      .usePlaintext()
-      .build();
+  @Getter @Setter public Map ivkMapScanBlockNum = new ConcurrentHashMap();
+  @Getter @Setter public Map utxoMapNote = new ConcurrentHashMap();
+
+  // Wallet wallet = new Wallet();
+  @Getter @Setter public List spendUtxoList = new ArrayList<>();
+  @Setter @Getter Map shieldAddressInfoMap = new ConcurrentHashMap();
+  private String fullnode =
+      Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0);
+  private ManagedChannel channelFull =
+      ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build();
   private WalletGrpc.WalletBlockingStub blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
   private Thread thread;
-  @Setter
-  private boolean resetNote = false;
+  @Setter private boolean resetNote = false;
 
   /*  public void setWallet(WalletApi walletApi) {
     wallet = walletApi;
@@ -147,11 +136,11 @@ private void updateNoteWhetherSpend() {
         outPointBuild.setIndex(noteInfo.getIndex());
         request.addOutPoints(outPointBuild.build());
 
-        IncrementalMerkleVoucherInfo merkleVoucherInfo = blockingStubFull.getMerkleTreeVoucherInfo(
-            request.build());
+        IncrementalMerkleVoucherInfo merkleVoucherInfo =
+            blockingStubFull.getMerkleTreeVoucherInfo(request.build());
         if (merkleVoucherInfo.getVouchersCount() > 0) {
-          ShieldAddressInfo addressInfo = getShieldAddressInfoMap().get(
-              noteInfo.getPaymentAddress());
+          ShieldAddressInfo addressInfo =
+              getShieldAddressInfoMap().get(noteInfo.getPaymentAddress());
           NoteParameters.Builder builder = NoteParameters.newBuilder();
           builder.setAk(ByteString.copyFrom(addressInfo.getFullViewingKey().getAk()));
           builder.setNk(ByteString.copyFrom(addressInfo.getFullViewingKey().getNk()));
@@ -162,7 +151,7 @@ private void updateNoteWhetherSpend() {
           noteBuild.setRcm(ByteString.copyFrom(noteInfo.getR()));
           noteBuild.setMemo(ByteString.copyFrom(noteInfo.getMemo()));
           builder.setNote(noteBuild.build());
-          //builder.setVoucher(merkleVoucherInfo.getVouchers(0));
+          // builder.setVoucher(merkleVoucherInfo.getVouchers(0));
 
           SpendResult result = blockingStubFull.isSpend(builder.build());
 
@@ -188,9 +177,7 @@ public boolean init() {
     return true;
   }
 
-  /**
-   * constructor.
-   */
+  /** constructor. */
   public boolean spendNote(long noteIndex) {
     ShieldNoteInfo noteInfo = utxoMapNote.get(noteIndex);
     if (noteInfo != null) {
@@ -205,9 +192,7 @@ public boolean spendNote(long noteIndex) {
     return true;
   }
 
-  /**
-   * constructor.
-   */
+  /** constructor. */
   public boolean addNewShieldAddress(final ShieldAddressInfo addressInfo) {
     appendAddressInfoToFile(addressInfo);
     long blockNum = 0;
@@ -228,9 +213,7 @@ public boolean addNewShieldAddress(final ShieldAddressInfo addressInfo) {
     return true;
   }
 
-  /**
-   * constructor.
-   */
+  /** constructor. */
   private boolean updateIvkAndBlockNum(final String ivk, long blockNum) {
     synchronized (IVK_AND_NUM_FILE_NAME) {
       String date = ivk + ";" + blockNum;
@@ -239,9 +222,7 @@ private boolean updateIvkAndBlockNum(final String ivk, long blockNum) {
     return true;
   }
 
-  /**
-   * constructor.
-   */
+  /** constructor. */
   private boolean updateIvkAndBlockNumFile() {
     synchronized (IVK_AND_NUM_FILE_NAME) {
       ZenUtils.clearFile(IVK_AND_NUM_FILE_NAME);
@@ -253,9 +234,7 @@ private boolean updateIvkAndBlockNumFile() {
     return true;
   }
 
-  /**
-   * constructor.
-   */
+  /** constructor. */
   private boolean loadIvkFromFile() {
     ivkMapScanBlockNum.clear();
     List list = ZenUtils.getListFromFile(IVK_AND_NUM_FILE_NAME);
@@ -270,9 +249,7 @@ private boolean loadIvkFromFile() {
     return true;
   }
 
-  /**
-   * get shield address list.
-   */
+  /** get shield address list. */
   public List getShieldAddressList() {
     List addressList = new ArrayList<>();
     for (Entry entry : shieldAddressInfoMap.entrySet()) {
@@ -281,9 +258,7 @@ public List getShieldAddressList() {
     return addressList;
   }
 
-  /**
-   * update unspend note.
-   */
+  /** update unspend note. */
   private boolean saveUnspendNoteToFile() {
     ZenUtils.clearFile(UNSPEND_NOTE_FILE_NAME);
     for (Entry entry : utxoMapNote.entrySet()) {
@@ -293,9 +268,7 @@ private boolean saveUnspendNoteToFile() {
     return true;
   }
 
-  /**
-   * load unspend note from file.
-   */
+  /** load unspend note from file. */
   private boolean loadUnSpendNoteFromFile() {
     utxoMapNote.clear();
 
@@ -312,18 +285,14 @@ private boolean loadUnSpendNoteFromFile() {
     return true;
   }
 
-  /**
-   * append spend note to file tail.
-   */
+  /** append spend note to file tail. */
   private boolean saveSpendNoteToFile(ShieldNoteInfo noteInfo) {
     String date = noteInfo.encode();
     ZenUtils.appendToFileTail(SPEND_NOTE_FILE_NAME, date);
     return true;
   }
 
-  /**
-   * load spend note from file.
-   */
+  /** load spend note from file. */
   private boolean loadSpendNoteFromFile() {
     spendUtxoList.clear();
     List list = ZenUtils.getListFromFile(SPEND_NOTE_FILE_NAME);
@@ -335,9 +304,7 @@ private boolean loadSpendNoteFromFile() {
     return true;
   }
 
-  /**
-   * load shield address from file.
-   */
+  /** load shield address from file. */
   public boolean loadAddressFromFile() {
     List addressList = ZenUtils.getListFromFile(SHIELD_ADDRESS_FILE_NAME);
 
@@ -353,9 +320,7 @@ public boolean loadAddressFromFile() {
     return true;
   }
 
-  /**
-   * constructor.
-   */
+  /** constructor. */
   public boolean appendAddressInfoToFile(final ShieldAddressInfo addressInfo) {
     String shieldAddress = addressInfo.getAddress();
     if (!StringUtil.isNullOrEmpty(shieldAddress)) {
@@ -367,18 +332,18 @@ public boolean appendAddressInfoToFile(final ShieldAddressInfo addressInfo) {
     return true;
   }
 
-  /**
-   * sort by value of UTXO.
-   */
+  /** sort by value of UTXO. */
   public List getvalidateSortUtxoList() {
     List> list = new ArrayList<>(utxoMapNote.entrySet());
-    Collections.sort(list, (Entry o1, Entry o2) -> {
-      if (o1.getValue().getValue() < o2.getValue().getValue()) {
-        return 1;
-      } else {
-        return -1;
-      }
-    });
+    Collections.sort(
+        list,
+        (Entry o1, Entry o2) -> {
+          if (o1.getValue().getValue() < o2.getValue().getValue()) {
+            return 1;
+          } else {
+            return -1;
+          }
+        });
 
     List utxoList = new ArrayList<>();
     for (Map.Entry entry : list) {
@@ -404,7 +369,7 @@ public void run() {
         try {
           scanBlockByIvk();
           updateNoteWhetherSpend();
-          //wait for 2.5 seconds
+          // wait for 2.5 seconds
           for (int i = 0; i < 5; ++i) {
             Thread.sleep(500);
             if (resetNote) {
@@ -419,6 +384,4 @@ public void run() {
       }
     }
   }
-
-
 }
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldedAddressInfo.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldedAddressInfo.java
index 7eedbb0b..b34c3b95 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldedAddressInfo.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldedAddressInfo.java
@@ -16,33 +16,20 @@
 @AllArgsConstructor
 public class ShieldedAddressInfo {
 
-  @Setter
-  @Getter
-  public byte[] sk;
-  @Setter
-  @Getter
-  public byte[] ivk; // 256
-  @Setter
-  @Getter
-  public byte[] ovk; // 256
-  @Setter
-  @Getter
-  DiversifierT d;
-  @Setter
-  @Getter
-  byte[] pkD; // 256
+  @Setter @Getter public byte[] sk;
+  @Setter @Getter public byte[] ivk; // 256
+  @Setter @Getter public byte[] ovk; // 256
+  @Setter @Getter DiversifierT d;
+  @Setter @Getter byte[] pkD; // 256
 
-  public ShieldedAddressInfo() {
-  }
+  public ShieldedAddressInfo() {}
 
   public FullViewingKey getFullViewingKey() throws ZksnarkException {
     SpendingKey spendingKey = new SpendingKey(sk);
     return spendingKey.fullViewingKey();
   }
 
-  /**
-   * check parameters
-   */
+  /** check parameters */
   public boolean validateCheck() {
     try {
       SpendingKey spendingKey = new SpendingKey(sk);
@@ -83,25 +70,21 @@ public static String getShieldedAddress(DiversifierT d, byte[] pkD) {
     return "";
   }
 
-  /**
-   * format shielded address info to a string
-   */
+  /** format shielded address info to a string */
   public String encode(byte[] encryptKey) throws CipherException {
     byte[] text = new byte[sk.length + ivk.length + ovk.length + d.getData().length + pkD.length];
     System.arraycopy(sk, 0, text, 0, sk.length);
     System.arraycopy(ivk, 0, text, sk.length, ivk.length);
     System.arraycopy(ovk, 0, text, sk.length + ivk.length, ovk.length);
     System.arraycopy(d.getData(), 0, text, sk.length + ivk.length + ovk.length, d.getData().length);
-    System.arraycopy(pkD, 0, text, sk.length + ivk.length + ovk.length + d.getData().length,
-        pkD.length);
+    System.arraycopy(
+        pkD, 0, text, sk.length + ivk.length + ovk.length + d.getData().length, pkD.length);
 
     byte[] cipherText = ZenUtils.aesCtrEncrypt(text, encryptKey);
     return Base58.encode(cipherText);
   }
 
-  /**
-   * parse string to get a shielded address info
-   */
+  /** parse string to get a shielded address info */
   public boolean decode(final String data, byte[] encryptKey) throws CipherException {
     byte[] cipherText = Base58.decode(data);
     byte[] text = ZenUtils.aesCtrDecrypt(cipherText, encryptKey);
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldedTRC20NoteInfo.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldedTRC20NoteInfo.java
index 00688112..cd028649 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldedTRC20NoteInfo.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ShieldedTRC20NoteInfo.java
@@ -5,42 +5,21 @@
 import lombok.Getter;
 import lombok.Setter;
 
-
-
 @AllArgsConstructor
 public class ShieldedTRC20NoteInfo {
 
-  @Setter
-  @Getter
-  public long value = 0;
-  @Setter
-  @Getter
-  public String paymentAddress;
-  @Setter
-  @Getter
-  public byte[] r; // 256
-  @Setter
-  @Getter
-  public String trxId;
-  @Setter
-  @Getter
-  public int index;
-  @Setter
-  @Getter
-  public long noteIndex;
-  @Setter
-  @Getter
-  public long position;
-  @Setter
-  @Getter
-  public byte[] memo;
+  @Setter @Getter public long value = 0;
+  @Setter @Getter public String paymentAddress;
+  @Setter @Getter public byte[] r; // 256
+  @Setter @Getter public String trxId;
+  @Setter @Getter public int index;
+  @Setter @Getter public long noteIndex;
+  @Setter @Getter public long position;
+  @Setter @Getter public byte[] memo;
 
-  public ShieldedTRC20NoteInfo() {
-  }
+  public ShieldedTRC20NoteInfo() {}
 
-  /**
-   * format shieldedTRC20 note to a string
-   */
+  /** format shieldedTRC20 note to a string */
   public String encode(byte[] encryptKey) throws CipherException {
     String encodeString = noteIndex + ";";
     encodeString += paymentAddress;
@@ -66,9 +45,7 @@ public String encode(byte[] encryptKey) throws CipherException {
     return encodeString;
   }
 
-  /**
-   * parse string to get shieldedTRC20 note
-   */
+  /** parse string to get shieldedTRC20 note */
   public boolean decode(String data, byte[] encryptKey) throws CipherException {
     byte[] chipherText = Base58.decode(data);
     byte[] text = ZenUtils.aesCtrDecrypt(chipherText, encryptKey);
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/SignatureInterface.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/SignatureInterface.java
index 88f9bc6e..fc0cb37f 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/SignatureInterface.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/SignatureInterface.java
@@ -3,4 +3,4 @@
 public interface SignatureInterface {
 
   boolean validateComponents();
-}
\ No newline at end of file
+}
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/SpendDescriptionCapsule.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/SpendDescriptionCapsule.java
index a5b40cd1..06d4365f 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/SpendDescriptionCapsule.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/SpendDescriptionCapsule.java
@@ -114,8 +114,8 @@ public ByteString getSpendAuthoritySignature() {
   }
 
   public void setSpendAuthoritySignature(ByteString bytes) {
-    this.spendDescription = this.spendDescription.toBuilder().setSpendAuthoritySignature(bytes)
-        .build();
+    this.spendDescription =
+        this.spendDescription.toBuilder().setSpendAuthoritySignature(bytes).build();
   }
 
   @Override
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/TestAccountFactory.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/TestAccountFactory.java
index b93b99ec..7f941d88 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/TestAccountFactory.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/TestAccountFactory.java
@@ -6,6 +6,7 @@
  * Factory for creating funded test accounts.
  *
  * 

Reduces boilerplate in test {@code @BeforeClass} methods. Instead of: + * *

{@code
  * ECKey ecKey = new ECKey(Utils.getRandom());
  * byte[] addr = ecKey.getAddress();
@@ -15,6 +16,7 @@
  * }
* *

Use: + * *

{@code
  * TestAccount test = TestAccountFactory.funded(amount, foundation, foundationKey, stub);
  * // test.address, test.privateKey, test.ecKey are all available
@@ -29,15 +31,14 @@ private TestAccountFactory() {
   /**
    * Creates a new random account funded with the specified TRX amount.
    *
-   * @param amountSun  TRX amount in sun to transfer from foundation
+   * @param amountSun TRX amount in sun to transfer from foundation
    * @param foundation foundation account address (source of funds)
    * @param foundationKey foundation account private key
-   * @param stub       gRPC blocking stub
+   * @param stub gRPC blocking stub
    * @return a funded TestAccount ready for use in tests
    */
-  public static TestAccount funded(long amountSun,
-      byte[] foundation, String foundationKey,
-      WalletGrpc.WalletBlockingStub stub) {
+  public static TestAccount funded(
+      long amountSun, byte[] foundation, String foundationKey, WalletGrpc.WalletBlockingStub stub) {
     ECKey ecKey = new ECKey(Utils.getRandom());
     byte[] address = ecKey.getAddress();
     String privateKey = ByteArray.toHexString(ecKey.getPrivKeyBytes());
@@ -47,8 +48,8 @@ public static TestAccount funded(long amountSun,
   }
 
   /**
-   * Creates a new random account without funding.
-   * Useful for negative tests or when funding is done separately.
+   * Creates a new random account without funding. Useful for negative tests or when funding is done
+   * separately.
    */
   public static TestAccount unfunded() {
     ECKey ecKey = new ECKey(Utils.getRandom());
@@ -57,9 +58,7 @@ public static TestAccount unfunded() {
     return new TestAccount(ecKey, address, privateKey);
   }
 
-  /**
-   * Holds a test account's key material.
-   */
+  /** Holds a test account's key material. */
   public static class TestAccount {
     public final ECKey ecKey;
     public final byte[] address;
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/TransactionCapsule.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/TransactionCapsule.java
index 93cbba0d..40843f52 100755
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/TransactionCapsule.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/TransactionCapsule.java
@@ -15,90 +15,60 @@
 
 package stest.tron.wallet.common.client.utils;
 
-
-import com.google.common.primitives.Bytes;
 import com.google.protobuf.Any;
 import com.google.protobuf.ByteString;
 import com.google.protobuf.CodedInputStream;
 import com.google.protobuf.CodedOutputStream;
-import com.google.protobuf.GeneratedMessageV3;
 import com.google.protobuf.Internal;
 import com.google.protobuf.InvalidProtocolBufferException;
-import java.io.IOException;
 import java.security.SignatureException;
-import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.atomic.AtomicInteger;
 import lombok.Getter;
 import lombok.Setter;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.ArrayUtils;
 import org.tron.protos.Protocol.Key;
 import org.tron.protos.Protocol.Permission;
-import org.tron.protos.Protocol.Permission.PermissionType;
 import org.tron.protos.Protocol.Transaction;
 import org.tron.protos.Protocol.Transaction.Contract.ContractType;
 import org.tron.protos.Protocol.Transaction.Result;
 import org.tron.protos.Protocol.Transaction.Result.contractResult;
 import org.tron.protos.Protocol.Transaction.raw;
-import org.tron.protos.contract.AccountContract.AccountCreateContract;
 import org.tron.protos.contract.AssetIssueContractOuterClass.AssetIssueContract;
 import org.tron.protos.contract.AssetIssueContractOuterClass.ParticipateAssetIssueContract;
 import org.tron.protos.contract.AssetIssueContractOuterClass.TransferAssetContract;
 import org.tron.protos.contract.BalanceContract.TransferContract;
-import org.tron.protos.contract.ShieldContract.ShieldedTransferContract;
-import org.tron.protos.contract.ShieldContract.SpendDescription;
 import org.tron.protos.contract.SmartContractOuterClass.CreateSmartContract;
 import org.tron.protos.contract.SmartContractOuterClass.TriggerSmartContract;
 import org.tron.protos.contract.WitnessContract.VoteWitnessContract;
 import org.tron.protos.contract.WitnessContract.WitnessCreateContract;
 import org.tron.protos.contract.WitnessContract.WitnessUpdateContract;
-import stest.tron.wallet.common.client.utils.exception.BadItemException;
 
 @Slf4j(topic = "capsule")
 public class TransactionCapsule implements ProtoCapsule {
 
-  private static final ExecutorService executorService = Executors
-      .newFixedThreadPool(CommonParameter.getInstance()
-          .getValidContractProtoThreadNum());
+  private static final ExecutorService executorService =
+      Executors.newFixedThreadPool(CommonParameter.getInstance().getValidContractProtoThreadNum());
   private static final String OWNER_ADDRESS = "ownerAddress_";
 
   private Transaction transaction;
-  @Setter
-  private boolean isVerified = false;
-  @Setter
-  @Getter
-  private long blockNum = -1;
-
+  @Setter private boolean isVerified = false;
+  @Setter @Getter private long blockNum = -1;
 
   private StringBuilder toStringBuff = new StringBuilder();
-  @Getter
-  @Setter
-  private long time;
-  @Getter
-  @Setter
-  private long order;
+  @Getter @Setter private long time;
+  @Getter @Setter private long order;
   private byte[] ownerAddress;
   private Sha256Hash id;
 
-  @Getter
-  @Setter
-  private boolean isTransactionCreate = false;
-
-
+  @Getter @Setter private boolean isTransactionCreate = false;
 
-  /**
-   * constructor TransactionCapsule.
-   */
+  /** constructor TransactionCapsule. */
   public TransactionCapsule(Transaction trx) {
     this.transaction = trx;
   }
 
-
   public TransactionCapsule(VoteWitnessContract voteWitnessContract) {
     createTransaction(voteWitnessContract, ContractType.VoteWitnessContract);
   }
@@ -120,8 +90,8 @@ public TransactionCapsule(ParticipateAssetIssueContract participateAssetIssueCon
   }
 
   public TransactionCapsule(raw rawData, List signatureList) {
-    this.transaction = Transaction.newBuilder().setRawData(rawData).addAllSignature(signatureList)
-        .build();
+    this.transaction =
+        Transaction.newBuilder().setRawData(rawData).addAllSignature(signatureList).build();
   }
 
   @Deprecated
@@ -130,9 +100,13 @@ public TransactionCapsule(AssetIssueContract assetIssueContract) {
   }
 
   public TransactionCapsule(com.google.protobuf.Message message, ContractType contractType) {
-    raw.Builder transactionBuilder = raw.newBuilder().addContract(
-        Transaction.Contract.newBuilder().setType(contractType).setParameter(
-            (message instanceof Any ? (Any) message : Any.pack(message))).build());
+    raw.Builder transactionBuilder =
+        raw.newBuilder()
+            .addContract(
+                Transaction.Contract.newBuilder()
+                    .setType(contractType)
+                    .setParameter((message instanceof Any ? (Any) message : Any.pack(message)))
+                    .build());
     transaction = Transaction.newBuilder().setRawData(transactionBuilder.build()).build();
   }
 
@@ -146,14 +120,12 @@ public static long getWeight(Permission permission, byte[] address) {
     return 0;
   }
 
-
-  public static  T parse(Class clazz,
-      CodedInputStream codedInputStream) throws InvalidProtocolBufferException {
+  public static  T parse(
+      Class clazz, CodedInputStream codedInputStream) throws InvalidProtocolBufferException {
     T defaultInstance = Internal.getDefaultInstance(clazz);
     return (T) defaultInstance.getParserForType().parseFrom(codedInputStream);
   }
 
-
   // todo mv this static function to capsule util
   public static byte[] getToAddress(Transaction.Contract contract) {
     ByteString to;
@@ -189,7 +161,9 @@ public static long getCallValue(Transaction.Contract contract) {
           return contractParameter.unpack(TriggerSmartContract.class).getCallValue();
 
         case CreateSmartContract:
-          return contractParameter.unpack(CreateSmartContract.class).getNewContract()
+          return contractParameter
+              .unpack(CreateSmartContract.class)
+              .getNewContract()
               .getCallValue();
         default:
           return 0L;
@@ -200,20 +174,21 @@ public static long getCallValue(Transaction.Contract contract) {
     }
   }
 
-
   public void resetResult() {
     if (this.getInstance().getRetCount() > 0) {
       this.transaction = this.getInstance().toBuilder().clearRet().build();
     }
   }
 
-
   public void setReference(long blockNum, byte[] blockHash) {
     byte[] refBlockNum = ByteArray.fromLong(blockNum);
-    raw rawData = this.transaction.getRawData().toBuilder()
-        .setRefBlockHash(ByteString.copyFrom(ByteArray.subArray(blockHash, 8, 16)))
-        .setRefBlockBytes(ByteString.copyFrom(ByteArray.subArray(refBlockNum, 6, 8)))
-        .build();
+    raw rawData =
+        this.transaction
+            .getRawData()
+            .toBuilder()
+            .setRefBlockHash(ByteString.copyFrom(ByteArray.subArray(blockHash, 8, 16)))
+            .setRefBlockBytes(ByteString.copyFrom(ByteArray.subArray(refBlockNum, 6, 8)))
+            .build();
     setRawData(rawData);
   }
 
@@ -221,26 +196,20 @@ public long getExpiration() {
     return transaction.getRawData().getExpiration();
   }
 
-  /**
-   * @param expiration must be in milliseconds format
-   */
+  /** @param expiration must be in milliseconds format */
   public void setExpiration(long expiration) {
-    raw rawData = this.transaction.getRawData().toBuilder().setExpiration(expiration)
-        .build();
+    raw rawData = this.transaction.getRawData().toBuilder().setExpiration(expiration).build();
     setRawData(rawData);
   }
 
   public void setTimestamp() {
-    raw rawData = this.transaction.getRawData().toBuilder()
-        .setTimestamp(System.currentTimeMillis())
-        .build();
+    raw rawData =
+        this.transaction.getRawData().toBuilder().setTimestamp(System.currentTimeMillis()).build();
     setRawData(rawData);
   }
 
   public void setTimestamp(long timestamp) {
-    raw rawData = this.transaction.getRawData().toBuilder()
-        .setTimestamp(timestamp)
-        .build();
+    raw rawData = this.transaction.getRawData().toBuilder().setTimestamp(timestamp).build();
     setRawData(rawData);
   }
 
@@ -249,9 +218,7 @@ public long getTimestamp() {
   }
 
   public void setFeeLimit(long feeLimit) {
-    raw rawData = this.transaction.getRawData().toBuilder()
-        .setFeeLimit(feeLimit)
-        .build();
+    raw rawData = this.transaction.getRawData().toBuilder().setFeeLimit(feeLimit).build();
     setRawData(rawData);
   }
 
@@ -261,20 +228,24 @@ public long getFeeLimit() {
 
   @Deprecated
   public void createTransaction(com.google.protobuf.Message message, ContractType contractType) {
-    raw.Builder transactionBuilder = raw.newBuilder().addContract(
-        Transaction.Contract.newBuilder().setType(contractType).setParameter(
-            Any.pack(message)).build());
+    raw.Builder transactionBuilder =
+        raw.newBuilder()
+            .addContract(
+                Transaction.Contract.newBuilder()
+                    .setType(contractType)
+                    .setParameter(Any.pack(message))
+                    .build());
     transaction = Transaction.newBuilder().setRawData(transactionBuilder.build()).build();
   }
 
   public Sha256Hash getMerkleHash() {
     byte[] transBytes = this.transaction.toByteArray();
-    return Sha256Hash.of(CommonParameter.getInstance().isECKeyCryptoEngine(),
-        transBytes);
+    return Sha256Hash.of(CommonParameter.getInstance().isECKeyCryptoEngine(), transBytes);
   }
 
   private Sha256Hash getRawHash() {
-    return Sha256Hash.of(CommonParameter.getInstance().isECKeyCryptoEngine(),
+    return Sha256Hash.of(
+        CommonParameter.getInstance().isECKeyCryptoEngine(),
         this.transaction.getRawData().toByteArray());
   }
 
@@ -287,22 +258,22 @@ public static SignInterface fromPrivate(byte[] privKeyBytes, boolean isECKeyCryp
 
   public void sign(byte[] privateKey) {
     SignInterface cryptoEngine = fromPrivate(privateKey, true);
-    ByteString sig = ByteString.copyFrom(cryptoEngine.Base64toBytes(cryptoEngine
-        .signHash(getTransactionId().getBytes())));
+    ByteString sig =
+        ByteString.copyFrom(
+            cryptoEngine.Base64toBytes(cryptoEngine.signHash(getTransactionId().getBytes())));
     this.transaction = this.transaction.toBuilder().addSignature(sig).build();
   }
 
-  public void addSign(byte[] privateKey)
-      throws  SignatureException {
+  public void addSign(byte[] privateKey) throws SignatureException {
     Transaction.Contract contract = this.transaction.getRawData().getContract(0);
 
     SignInterface cryptoEngine = fromPrivate(privateKey, true);
 
-    ByteString sig = ByteString.copyFrom(cryptoEngine.Base64toBytes(cryptoEngine
-        .signHash(getTransactionId().getBytes())));
+    ByteString sig =
+        ByteString.copyFrom(
+            cryptoEngine.Base64toBytes(cryptoEngine.signHash(getTransactionId().getBytes())));
     this.transaction = this.transaction.toBuilder().addSignature(sig).build();
   }
-  
 
   public Sha256Hash getTransactionId() {
     if (this.id == null) {
@@ -328,11 +299,7 @@ public long getSerializedSize() {
 
   /**
    * Compute the number of bytes that would be needed to encode an embedded message field, including
-   * tag.
-   * message Block {
-   *   repeated Transaction transactions = 1;
-   *   BlockHeader block_header = 2;
-   * }
+   * tag. message Block { repeated Transaction transactions = 1; BlockHeader block_header = 2; }
    */
   public long computeTrxSizeForBlockMessage() {
     return CodedOutputStream.computeMessageSize(1, this.transaction);
@@ -351,7 +318,6 @@ public Transaction getInstance() {
     return this.transaction;
   }
 
-
   public void setResultCode(contractResult code) {
     Result ret;
     if (this.transaction.getRetCount() > 0) {
@@ -371,8 +337,6 @@ public contractResult getContractResult() {
     return null;
   }
 
-
-
   public contractResult getContractRet() {
     if (this.transaction.getRetCount() <= 0) {
       return null;
@@ -382,12 +346,14 @@ public contractResult getContractRet() {
 
   /**
    * Check if a transaction capsule contains a smart contract transaction or not.
+   *
    * @return
    */
   public boolean isContractType() {
     try {
       ContractType type = this.getInstance().getRawData().getContract(0).getType();
-      return  (type == ContractType.TriggerSmartContract || type == ContractType.CreateSmartContract);
+      return (type == ContractType.TriggerSmartContract
+          || type == ContractType.CreateSmartContract);
     } catch (Exception ex) {
       logger.warn("check contract type failed, reason {}", ex.getMessage());
       return false;
@@ -396,10 +362,7 @@ public boolean isContractType() {
 
   public TransferContract getTransferContract() {
     try {
-      return transaction.getRawData()
-          .getContract(0)
-          .getParameter()
-          .unpack(TransferContract.class);
+      return transaction.getRawData().getContract(0).getParameter().unpack(TransferContract.class);
     } catch (InvalidProtocolBufferException e) {
       return null;
     }
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/TransactionHelper.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/TransactionHelper.java
index 70a6f94e..09495bbb 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/TransactionHelper.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/TransactionHelper.java
@@ -183,10 +183,11 @@ public static TransactionApprovedList getTransactionApprovedList(
   /** Broadcast a signed transaction to the network, retrying on SERVER_BUSY. */
   public static GrpcAPI.Return broadcastTransaction(
       Transaction transaction, WalletGrpc.WalletBlockingStub blockingStubFull) {
-    String txid = ByteArray.toHexString(
-        Sha256Hash.hash(
-            CommonParameter.getInstance().isECKeyCryptoEngine(),
-            transaction.getRawData().toByteArray()));
+    String txid =
+        ByteArray.toHexString(
+            Sha256Hash.hash(
+                CommonParameter.getInstance().isECKeyCryptoEngine(),
+                transaction.getRawData().toByteArray()));
     logger.info("broadcastTransaction: " + txid);
     int i = 10;
     GrpcAPI.Return response = blockingStubFull.broadcastTransaction(transaction);
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/TransactionUtils.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/TransactionUtils.java
index 9dae8f9e..291525fc 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/TransactionUtils.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/TransactionUtils.java
@@ -17,25 +17,19 @@
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONException;
 import com.alibaba.fastjson.JSONObject;
 import com.google.protobuf.Any;
 import com.google.protobuf.ByteString;
 import com.google.protobuf.GeneratedMessageV3;
 import com.google.protobuf.InvalidProtocolBufferException;
 import com.google.protobuf.Message;
-import io.grpc.ManagedChannel;
 import java.lang.reflect.Constructor;
-import java.nio.charset.StandardCharsets;
 import java.security.SignatureException;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
-
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.tron.protos.Protocol.Transaction;
 import org.tron.protos.Protocol.Transaction.Contract;
 import org.tron.protos.Protocol.Transaction.Contract.ContractType;
@@ -83,73 +77,88 @@
 import org.tron.protos.contract.WitnessContract.WitnessCreateContract;
 import org.tron.protos.contract.WitnessContract.WitnessUpdateContract;
 import stest.tron.wallet.common.client.utils.ECKey.ECDSASignature;
+
 @Slf4j
 public class TransactionUtils {
 
   public static final int NORMALTRANSACTION = 0;
   public static final int UNEXECUTEDDEFERREDTRANSACTION = 1;
   public static final int EXECUTINGDEFERREDTRANSACTION = 2;
-//  private static final Logger logger = LoggerFactory.getLogger("Transaction");
+  //  private static final Logger logger = LoggerFactory.getLogger("Transaction");
   private static final int RESERVE_BALANCE = 10;
-  public static HashMap> transactionMap = new HashMap<>();
-
-  /**
-   * constructor.
-   */
+  public static HashMap> transactionMap = new HashMap<>();
 
+  /** constructor. */
   public static byte[] getHash(Transaction transaction) {
     Transaction.Builder tmp = transaction.toBuilder();
-    //tmp.clearId();
-    return Sha256Hash.hash(CommonParameter
-        .getInstance().isECKeyCryptoEngine(), tmp.build().toByteArray());
+    // tmp.clearId();
+    return Sha256Hash.hash(
+        CommonParameter.getInstance().isECKeyCryptoEngine(), tmp.build().toByteArray());
   }
 
-  /**
-   * constructor.
-   */
-
+  /** constructor. */
   public static byte[] getOwner(Transaction.Contract contract) {
     ByteString owner;
     try {
       switch (contract.getType()) {
         case AccountCreateContract:
-          owner = contract.getParameter()
-              .unpack(AccountCreateContract.class).getOwnerAddress();
+          owner = contract.getParameter().unpack(AccountCreateContract.class).getOwnerAddress();
           break;
         case TransferContract:
-          owner = contract.getParameter().unpack(BalanceContract.TransferContract.class)
-              .getOwnerAddress();
+          owner =
+              contract
+                  .getParameter()
+                  .unpack(BalanceContract.TransferContract.class)
+                  .getOwnerAddress();
           break;
         case TransferAssetContract:
-          owner = contract.getParameter()
-              .unpack(AssetIssueContractOuterClass.TransferAssetContract.class).getOwnerAddress();
+          owner =
+              contract
+                  .getParameter()
+                  .unpack(AssetIssueContractOuterClass.TransferAssetContract.class)
+                  .getOwnerAddress();
           break;
         case VoteAssetContract:
-          owner = contract.getParameter()
-              .unpack(VoteAssetContractOuterClass.VoteAssetContract.class)
-              .getOwnerAddress();
+          owner =
+              contract
+                  .getParameter()
+                  .unpack(VoteAssetContractOuterClass.VoteAssetContract.class)
+                  .getOwnerAddress();
           break;
         case VoteWitnessContract:
-          owner = contract.getParameter().unpack(WitnessContract.VoteWitnessContract.class)
-              .getOwnerAddress();
+          owner =
+              contract
+                  .getParameter()
+                  .unpack(WitnessContract.VoteWitnessContract.class)
+                  .getOwnerAddress();
           break;
         case WitnessCreateContract:
-          owner = contract.getParameter()
-              .unpack(WitnessContract.WitnessCreateContract.class).getOwnerAddress();
+          owner =
+              contract
+                  .getParameter()
+                  .unpack(WitnessContract.WitnessCreateContract.class)
+                  .getOwnerAddress();
           break;
         case AssetIssueContract:
-          owner = contract.getParameter()
-              .unpack(AssetIssueContractOuterClass.AssetIssueContract.class)
-              .getOwnerAddress();
+          owner =
+              contract
+                  .getParameter()
+                  .unpack(AssetIssueContractOuterClass.AssetIssueContract.class)
+                  .getOwnerAddress();
           break;
         case ParticipateAssetIssueContract:
-          owner = contract.getParameter()
-              .unpack(AssetIssueContractOuterClass.ParticipateAssetIssueContract.class)
-              .getOwnerAddress();
+          owner =
+              contract
+                  .getParameter()
+                  .unpack(AssetIssueContractOuterClass.ParticipateAssetIssueContract.class)
+                  .getOwnerAddress();
           break;
         case CreateSmartContract:
-          owner = contract.getParameter().unpack(SmartContractOuterClass.CreateSmartContract.class)
-              .getOwnerAddress();
+          owner =
+              contract
+                  .getParameter()
+                  .unpack(SmartContractOuterClass.CreateSmartContract.class)
+                  .getOwnerAddress();
           break;
         default:
           return null;
@@ -161,16 +170,13 @@ public static byte[] getOwner(Transaction.Contract contract) {
     }
   }
 
-  /**
-   * constructor.
-   */
-
+  /** constructor. */
   public static String getBase64FromByteString(ByteString sign) {
     byte[] r = sign.substring(0, 32).toByteArray();
     byte[] s = sign.substring(32, 64).toByteArray();
     byte v = sign.byteAt(64);
     if (v < 27) {
-      v += 27; //revId -> v
+      v += 27; // revId -> v
     }
     ECDSASignature signature = ECDSASignature.fromComponents(r, s, v);
     return signature.toBase64();
@@ -183,16 +189,15 @@ public static String getBase64FromByteString(ByteString sign) {
    * 4. check balance
    */
 
-  /**
-   * constructor.
-   */
-
+  /** constructor. */
   public static boolean validTransaction(Transaction signedTransaction) {
     assert (signedTransaction.getSignatureCount()
         == signedTransaction.getRawData().getContractCount());
     List listContract = signedTransaction.getRawData().getContractList();
-    byte[] hash = Sha256Hash.hash(CommonParameter
-        .getInstance().isECKeyCryptoEngine(), signedTransaction.getRawData().toByteArray());
+    byte[] hash =
+        Sha256Hash.hash(
+            CommonParameter.getInstance().isECKeyCryptoEngine(),
+            signedTransaction.getRawData().toByteArray());
     int count = signedTransaction.getSignatureCount();
     if (count == 0) {
       return false;
@@ -201,8 +206,9 @@ public static boolean validTransaction(Transaction signedTransaction) {
       try {
         Transaction.Contract contract = listContract.get(i);
         byte[] owner = getOwner(contract);
-        byte[] address = ECKey
-            .signatureToAddress(hash, getBase64FromByteString(signedTransaction.getSignature(i)));
+        byte[] address =
+            ECKey.signatureToAddress(
+                hash, getBase64FromByteString(signedTransaction.getSignature(i)));
         if (!Arrays.equals(owner, address)) {
           return false;
         }
@@ -214,44 +220,44 @@ public static boolean validTransaction(Transaction signedTransaction) {
     return true;
   }
 
-  /**
-   * constructor.
-   */
-
+  /** constructor. */
   public static Transaction sign(Transaction transaction, ECKey myKey) {
     ByteString lockSript = ByteString.copyFrom(myKey.getAddress());
     Transaction.Builder transactionBuilderSigned = transaction.toBuilder();
 
-    byte[] hash = Sha256Hash.hash(CommonParameter
-        .getInstance().isECKeyCryptoEngine(), transaction.getRawData().toByteArray());
+    byte[] hash =
+        Sha256Hash.hash(
+            CommonParameter.getInstance().isECKeyCryptoEngine(),
+            transaction.getRawData().toByteArray());
     List listContract = transaction.getRawData().getContractList();
     for (int i = 0; i < listContract.size(); i++) {
       ECDSASignature signature = myKey.sign(hash);
       ByteString bsSign = ByteString.copyFrom(signature.toByteArray());
       transactionBuilderSigned.addSignature(
-          bsSign);//Each contract may be signed with a different private key in the future.
+          bsSign); // Each contract may be signed with a different private key in the future.
     }
 
     transaction = transactionBuilderSigned.build();
     try {
-      String txId = ByteArray.toHexString(
+      String txId =
+          ByteArray.toHexString(
               Sha256Hash.hash(
-                      CommonParameter.getInstance().isECKeyCryptoEngine(),
-                      transaction.getRawData().toByteArray()));
+                  CommonParameter.getInstance().isECKeyCryptoEngine(),
+                  transaction.getRawData().toByteArray()));
       String txType = transaction.getRawData().getContract(0).getType().name();
-      logger.info("Transaction type: {}, id: {}" ,txType ,txId);
-    }catch (Exception e){
+      logger.info("Transaction type: {}, id: {}", txType, txId);
+    } catch (Exception e) {
       logger.warn("err transaction, please check, " + transaction + " err: " + e.getMessage());
     }
     return transaction;
   }
 
-
   public static byte[] generateContractAddress(Transaction trx, byte[] ownerAddress) {
     // get tx hash
-    byte[] txRawDataHash = Sha256Hash
-        .of(CommonParameter.getInstance().isECKeyCryptoEngine(), trx.getRawData().toByteArray())
-        .getBytes();
+    byte[] txRawDataHash =
+        Sha256Hash.of(
+                CommonParameter.getInstance().isECKeyCryptoEngine(), trx.getRawData().toByteArray())
+            .getBytes();
 
     // combine
     byte[] combined = new byte[txRawDataHash.length + ownerAddress.length];
@@ -261,25 +267,24 @@ public static byte[] generateContractAddress(Transaction trx, byte[] ownerAddres
     return Hash.sha3omit12(combined);
   }
 
-
   public static void initTransactionMap() {
-    if(transactionMap.isEmpty()) {
-      transactionMap.put(ContractType.TransferContract,TransferContract.class);
+    if (transactionMap.isEmpty()) {
+      transactionMap.put(ContractType.TransferContract, TransferContract.class);
       transactionMap.put(ContractType.AccountUpdateContract, AccountUpdateContract.class);
       transactionMap.put(ContractType.VoteWitnessContract, VoteWitnessContract.class);
       transactionMap.put(ContractType.WitnessUpdateContract, WitnessUpdateContract.class);
-      transactionMap.put(ContractType.AccountCreateContract,AccountCreateContract.class);
-      transactionMap.put(ContractType.AccountPermissionUpdateContract,
-          AccountPermissionUpdateContract.class);
+      transactionMap.put(ContractType.AccountCreateContract, AccountCreateContract.class);
+      transactionMap.put(
+          ContractType.AccountPermissionUpdateContract, AccountPermissionUpdateContract.class);
       transactionMap.put(ContractType.AssetIssueContract, AssetIssueContract.class);
       transactionMap.put(ContractType.ClearABIContract, ClearABIContract.class);
-      transactionMap.put(ContractType.CreateSmartContract,CreateSmartContract.class);
+      transactionMap.put(ContractType.CreateSmartContract, CreateSmartContract.class);
       transactionMap.put(ContractType.DelegateResourceContract, DelegateResourceContract.class);
       transactionMap.put(ContractType.ExchangeCreateContract, ExchangeCreateContract.class);
       transactionMap.put(ContractType.ExchangeInjectContract, ExchangeInjectContract.class);
       transactionMap.put(ContractType.ExchangeWithdrawContract, ExchangeWithdrawContract.class);
-      transactionMap.put(ContractType.ExchangeTransactionContract,
-          ExchangeTransactionContract.class);
+      transactionMap.put(
+          ContractType.ExchangeTransactionContract, ExchangeTransactionContract.class);
       transactionMap.put(ContractType.FreezeBalanceV2Contract, FreezeBalanceV2Contract.class);
       transactionMap.put(ContractType.UnfreezeBalanceV2Contract, UnfreezeBalanceV2Contract.class);
       transactionMap.put(ContractType.UnDelegateResourceContract, UnDelegateResourceContract.class);
@@ -288,7 +293,8 @@ public static void initTransactionMap() {
       transactionMap.put(ContractType.FreezeBalanceContract, FreezeBalanceContract.class);
       transactionMap.put(ContractType.MarketCancelOrderContract, MarketCancelOrderContract.class);
       transactionMap.put(ContractType.MarketSellAssetContract, MarketSellAssetContract.class);
-      transactionMap.put(ContractType.ParticipateAssetIssueContract, ParticipateAssetIssueContract.class);
+      transactionMap.put(
+          ContractType.ParticipateAssetIssueContract, ParticipateAssetIssueContract.class);
       transactionMap.put(ContractType.ShieldedTransferContract, ShieldedTransferContract.class);
       transactionMap.put(ContractType.SetAccountIdContract, SetAccountIdContract.class);
       transactionMap.put(ContractType.TransferAssetContract, TransferAssetContract.class);
@@ -299,77 +305,81 @@ public static void initTransactionMap() {
       transactionMap.put(ContractType.UpdateEnergyLimitContract, UpdateEnergyLimitContract.class);
       transactionMap.put(ContractType.UpdateSettingContract, UpdateSettingContract.class);
       transactionMap.put(ContractType.WithdrawBalanceContract, WithdrawBalanceContract.class);
-      transactionMap.put(ContractType.WithdrawExpireUnfreezeContract, WithdrawExpireUnfreezeContract.class);
+      transactionMap.put(
+          ContractType.WithdrawExpireUnfreezeContract, WithdrawExpireUnfreezeContract.class);
       transactionMap.put(ContractType.ProposalApproveContract, ProposalApproveContract.class);
       transactionMap.put(ContractType.ProposalDeleteContract, ProposalDeleteContract.class);
       transactionMap.put(ContractType.ProposalCreateContract, ProposalCreateContract.class);
       transactionMap.put(ContractType.VoteAssetContract, VoteAssetContract.class);
-      transactionMap.put(ContractType.CancelAllUnfreezeV2Contract, BalanceContract.CancelAllUnfreezeV2Contract.class);
+      transactionMap.put(
+          ContractType.CancelAllUnfreezeV2Contract,
+          BalanceContract.CancelAllUnfreezeV2Contract.class);
     }
   }
 
   public static JSONObject printTransactionToJSON(Transaction transaction, boolean selfType) {
     initTransactionMap();
-    JSONObject jsonTransaction = JSONObject
-        .parseObject(JsonFormat.printToString(transaction, selfType));
+    JSONObject jsonTransaction =
+        JSONObject.parseObject(JsonFormat.printToString(transaction, selfType));
     JSONArray contracts = new JSONArray();
-    transaction.getRawData().getContractList().stream().forEach(contract -> {
-      try {
-        JSONObject contractJson = null;
-        Any contractParameter = contract.getParameter();
-        switch (contract.getType()) {
-          case CreateSmartContract:
-            CreateSmartContract deployContract = contractParameter
-                .unpack(CreateSmartContract.class);
-            contractJson = JSONObject
-                .parseObject(JsonFormat.printToString(deployContract, selfType));
-            byte[] ownerAddress = deployContract.getOwnerAddress().toByteArray();
-            byte[] contractAddress = generateContractAddress(transaction, ownerAddress);
-            jsonTransaction.put("contract_address", ByteArray.toHexString(contractAddress));
-            break;
-          default:
-            Class clazz = transactionMap.get(contract.getType());
-            if (clazz != null) {
-              contractJson = JSONObject
-                  .parseObject(JsonFormat.printToString(contractParameter.unpack(clazz), selfType));
-            } else {
-              logger.error(
-                  "cannot find ContractType, do not forget add ContractType to transactionMap!!");
-            }
-            break;
-        }
-
-        JSONObject parameter = new JSONObject();
-        parameter.put("value", contractJson);
-        parameter.put("type_url", contract.getParameterOrBuilder().getTypeUrl());
-        JSONObject jsonContract = new JSONObject();
-        jsonContract.put("parameter", parameter);
-        jsonContract.put("type", contract.getType());
-        if (contract.getPermissionId() > 0) {
-          jsonContract.put("Permission_id", contract.getPermissionId());
-        }
-        contracts.add(jsonContract);
-      } catch (InvalidProtocolBufferException e) {
-        logger.debug("InvalidProtocolBufferException: {}", e.getMessage());
-      }
-    });
+    transaction.getRawData().getContractList().stream()
+        .forEach(
+            contract -> {
+              try {
+                JSONObject contractJson = null;
+                Any contractParameter = contract.getParameter();
+                switch (contract.getType()) {
+                  case CreateSmartContract:
+                    CreateSmartContract deployContract =
+                        contractParameter.unpack(CreateSmartContract.class);
+                    contractJson =
+                        JSONObject.parseObject(JsonFormat.printToString(deployContract, selfType));
+                    byte[] ownerAddress = deployContract.getOwnerAddress().toByteArray();
+                    byte[] contractAddress = generateContractAddress(transaction, ownerAddress);
+                    jsonTransaction.put("contract_address", ByteArray.toHexString(contractAddress));
+                    break;
+                  default:
+                    Class clazz = transactionMap.get(contract.getType());
+                    if (clazz != null) {
+                      contractJson =
+                          JSONObject.parseObject(
+                              JsonFormat.printToString(contractParameter.unpack(clazz), selfType));
+                    } else {
+                      logger.error(
+                          "cannot find ContractType, do not forget add ContractType to transactionM"
+                              + "ap!!");
+                    }
+                    break;
+                }
+
+                JSONObject parameter = new JSONObject();
+                parameter.put("value", contractJson);
+                parameter.put("type_url", contract.getParameterOrBuilder().getTypeUrl());
+                JSONObject jsonContract = new JSONObject();
+                jsonContract.put("parameter", parameter);
+                jsonContract.put("type", contract.getType());
+                if (contract.getPermissionId() > 0) {
+                  jsonContract.put("Permission_id", contract.getPermissionId());
+                }
+                contracts.add(jsonContract);
+              } catch (InvalidProtocolBufferException e) {
+                logger.debug("InvalidProtocolBufferException: {}", e.getMessage());
+              }
+            });
 
     JSONObject rawData = JSONObject.parseObject(jsonTransaction.get("raw_data").toString());
     rawData.put("contract", contracts);
     jsonTransaction.put("raw_data", rawData);
     String rawDataHex = ByteArray.toHexString(transaction.getRawData().toByteArray());
     jsonTransaction.put("raw_data_hex", rawDataHex);
-    String txID = ByteArray.toHexString(Sha256Hash
-        .hash(true,
-            transaction.getRawData().toByteArray()));
+    String txID =
+        ByteArray.toHexString(Sha256Hash.hash(true, transaction.getRawData().toByteArray()));
     jsonTransaction.put("txID", txID);
-    jsonTransaction.put("visible",selfType);
+    jsonTransaction.put("visible", selfType);
     return jsonTransaction;
   }
 
-  /**
-   * Note: the contracts of the returned transaction may be empty
-   */
+  /** Note: the contracts of the returned transaction may be empty */
   public static Transaction packTransaction(String strTransaction, boolean selfType) {
     initTransactionMap();
     JSONObject jsonTransaction = JSON.parseObject(strTransaction);
@@ -409,7 +419,6 @@ public static Transaction packTransaction(String strTransaction, boolean selfTyp
         }
       } catch (Exception e) {
         e.printStackTrace();
-
       }
     }
     rawData.put("contract", contracts);
@@ -424,39 +433,33 @@ public static Transaction packTransaction(String strTransaction, boolean selfTyp
     }
   }
 
-  public static String getTransactionSign(String transaction, String priKey,
-      boolean visible) {
+  public static String getTransactionSign(String transaction, String priKey, boolean visible) {
 
     byte[] privateKey = ByteArray.fromHexString(priKey);
     try {
-      TransactionCapsule trx = new TransactionCapsule(packTransaction(transaction,visible));
+      TransactionCapsule trx = new TransactionCapsule(packTransaction(transaction, visible));
       trx.sign(privateKey);
-      return printTransactionToJSON(trx.getInstance(),visible).toJSONString();
+      return printTransactionToJSON(trx.getInstance(), visible).toJSONString();
     } catch (Exception e) {
       logger.error("{}", e);
     }
     return null;
   }
 
-
-
-  /**
-   * constructor.
-   */
-
+  /** constructor. */
   public static Transaction setTimestamp(Transaction transaction) {
-    long currentTime = System.currentTimeMillis() + PublicMethod.randomTimeOffset.getAndAdd(1);//*1000000 + System.nanoTime()%1000000;
+    long currentTime =
+        System.currentTimeMillis()
+            + PublicMethod.randomTimeOffset.getAndAdd(1); // *1000000 + System.nanoTime()%1000000;
     Transaction.Builder builder = transaction.toBuilder();
-    org.tron.protos.Protocol.Transaction.raw.Builder rowBuilder = transaction.getRawData()
-        .toBuilder();
+    org.tron.protos.Protocol.Transaction.raw.Builder rowBuilder =
+        transaction.getRawData().toBuilder();
     rowBuilder.setTimestamp(currentTime);
     builder.setRawData(rowBuilder.build());
     return builder.build();
   }
 
-  /**
-   * constructor.
-   */
+  /** constructor. */
   /*  public static Transaction setDelaySeconds(Transaction transaction, long delaySeconds) {
     DeferredStage deferredStage = transaction.getRawData().toBuilder()
         .getDeferredStage().toBuilder().setDelaySeconds(delaySeconds)
@@ -466,9 +469,9 @@ public static Transaction setTimestamp(Transaction transaction) {
     return transaction.toBuilder().setRawData(rawData).build();
   }*/
 
-  /*  *//**
-   * constructor.
-   *//*
+  /*  */
+  /** constructor. */
+  /*
   public static GrpcAPI.TransactionExtention setDelaySecondsToExtension(GrpcAPI
       .TransactionExtention transactionExtention, long delaySeconds) {
     if (delaySeconds == 0) {
diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/TronBaseTest.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/TronBaseTest.java
index 1270d7cb..989a0399 100644
--- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/TronBaseTest.java
+++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/TronBaseTest.java
@@ -16,11 +16,12 @@
 /**
  * Abstract base class for TRON system tests.
  *
- * 

Provides common infrastructure: gRPC channel management, foundation/witness account - * loading, and node endpoint configuration. Subclasses get {@code channelFull} and - * {@code blockingStubFull} initialized automatically before each test class runs. + *

Provides common infrastructure: gRPC channel management, foundation/witness account loading, + * and node endpoint configuration. Subclasses get {@code channelFull} and {@code blockingStubFull} + * initialized automatically before each test class runs. * *

Usage: + * *

{@code
  * public class MyTest extends TronBaseTest {
  *   @BeforeClass
@@ -31,8 +32,8 @@
  * }
  * }
* - *

For tests needing solidity/PBFT channels, call {@link #initSolidityChannel()} - * or {@link #initPbftChannel()} in a subclass {@code @BeforeClass} method. + *

For tests needing solidity/PBFT channels, call {@link #initSolidityChannel()} or {@link + * #initPbftChannel()} in a subclass {@code @BeforeClass} method. */ @Slf4j public abstract class TronBaseTest { @@ -50,8 +51,8 @@ public abstract class TronBaseTest { protected final String foundationKey2 = config.getString("foundationAccount.key2"); protected final byte[] foundationAddress2 = PublicMethod.getFinalAddress(foundationKey2); /** - * Backward-compatible alias. Despite the name suggesting key2, the original code - * in most classes mapped testKey002 to foundationAccount.key1. + * Backward-compatible alias. Despite the name suggesting key2, the original code in most classes + * mapped testKey002 to foundationAccount.key1. */ protected final String testKey002 = foundationKey; @@ -86,21 +87,16 @@ public abstract class TronBaseTest { protected long maxFeeLimit = config.getLong("defaultParameter.maxFeeLimit"); /** - * Initializes the fullnode gRPC channel and stub. - * Runs before any subclass {@code @BeforeClass} method. + * Initializes the fullnode gRPC channel and stub. Runs before any subclass {@code @BeforeClass} + * method. */ @BeforeClass(alwaysRun = true) public void initChannels() { - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext() - .build(); + channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); blockingStubFull = WalletGrpc.newBlockingStub(channelFull); } - /** - * Shuts down all open gRPC channels. - * Runs after any subclass {@code @AfterClass} method. - */ + /** Shuts down all open gRPC channels. Runs after any subclass {@code @AfterClass} method. */ @AfterClass(alwaysRun = true) public void closeChannels() throws InterruptedException { shutdownChannel(channelFull); @@ -109,33 +105,28 @@ public void closeChannels() throws InterruptedException { } /** - * Initializes the solidity node channel and stub. - * Call this in a subclass {@code @BeforeClass} if solidity access is needed. + * Initializes the solidity node channel and stub. Call this in a subclass {@code @BeforeClass} if + * solidity access is needed. */ protected void initSolidityChannel() { String solidityNode = config.getStringList("solidityNode.ip.list").get(0); - channelSolidity = ManagedChannelBuilder.forTarget(solidityNode) - .usePlaintext() - .build(); + channelSolidity = ManagedChannelBuilder.forTarget(solidityNode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } /** - * Initializes the PBFT node channel and stub. - * Call this in a subclass {@code @BeforeClass} if PBFT access is needed. + * Initializes the PBFT node channel and stub. Call this in a subclass {@code @BeforeClass} if + * PBFT access is needed. */ protected void initPbftChannel() { String pbftNode = config.getStringList("solidityNode.ip.list").get(2); - channelPbft = ManagedChannelBuilder.forTarget(pbftNode) - .usePlaintext() - .build(); + channelPbft = ManagedChannelBuilder.forTarget(pbftNode).usePlaintext().build(); blockingStubPbft = WalletSolidityGrpc.newBlockingStub(channelPbft); } /** - * Returns the second fullnode endpoint if available, or throws SkipException. - * Call this in {@code @BeforeClass} of multi-node tests to safely skip - * when only a single node is running. + * Returns the second fullnode endpoint if available, or throws SkipException. Call this in + * {@code @BeforeClass} of multi-node tests to safely skip when only a single node is running. * * @return the second fullnode endpoint string (e.g. "127.0.0.1:50052") * @throws SkipException if no second node is configured or it equals the first @@ -161,12 +152,10 @@ protected static Object[] generateAccount() { ECKey ecKey = new ECKey(Utils.getRandom()); String key = ByteArray.toHexString(ecKey.getPrivKeyBytes()); byte[] address = ecKey.getAddress(); - return new Object[]{key, address}; + return new Object[] {key, address}; } - /** - * Safely shuts down a gRPC channel with a 5-second timeout. - */ + /** Safely shuts down a gRPC channel with a 5-second timeout. */ protected static void shutdownChannel(ManagedChannel channel) throws InterruptedException { if (channel != null) { channel.shutdown().awaitTermination(5, TimeUnit.SECONDS); diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/TronConstants.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/TronConstants.java index a5c86266..61e8f22b 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/TronConstants.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/TronConstants.java @@ -1,8 +1,8 @@ package stest.tron.wallet.common.client.utils; /** - * Common constants used across TRON system tests. - * Eliminates magic numbers scattered throughout test classes. + * Common constants used across TRON system tests. Eliminates magic numbers scattered throughout + * test classes. */ public final class TronConstants { diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/Utils.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/Utils.java index b7cd2c02..b1e27b25 100755 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/Utils.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/Utils.java @@ -58,7 +58,6 @@ static String align(String s, char fillChar, int targetLen, boolean alignRight) } String alignString = repeat("" + fillChar, targetLen - s.length()); return alignRight ? alignString + s : s + alignString; - } static String repeat(String s, int n) { diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ZenTrc20Base.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ZenTrc20Base.java index 04c9a588..6d63658f 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ZenTrc20Base.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ZenTrc20Base.java @@ -9,8 +9,11 @@ import io.grpc.Status; import io.netty.util.internal.StringUtil; import java.math.BigInteger; -import java.util.*; - +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.Random; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPost; @@ -33,17 +36,17 @@ import stest.tron.wallet.common.client.utils.zen.address.DiversifierT; @Slf4j -public class ZenTrc20Base extends JsonRpcBase{ +public class ZenTrc20Base extends JsonRpcBase { - public final String foundationKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); + public final String foundationKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key1"); public final byte[] foundationAddress = PublicMethod.getFinalAddress(foundationKey); - public static final String zenTrc20TokenOwnerKey = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTrc20TokenOwnerKey"); - public static final byte[] zenTrc20TokenOwnerAddress = PublicMethod - .getFinalAddress(zenTrc20TokenOwnerKey); - public static final String zenTrc20TokenOwnerAddressString = PublicMethod - .getAddressString(zenTrc20TokenOwnerKey); + public static final String zenTrc20TokenOwnerKey = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTrc20TokenOwnerKey"); + public static final byte[] zenTrc20TokenOwnerAddress = + PublicMethod.getFinalAddress(zenTrc20TokenOwnerKey); + public static final String zenTrc20TokenOwnerAddressString = + PublicMethod.getAddressString(zenTrc20TokenOwnerKey); public ManagedChannel channelFull = null; public WalletGrpc.WalletBlockingStub blockingStubFull = null; public ManagedChannel channelSolidity = null; @@ -63,108 +66,137 @@ public class ZenTrc20Base extends JsonRpcBase{ public static String mint = "mint(uint256,bytes32[9],bytes32[2],bytes32[21])"; public static String transfer = "transfer(bytes32[10][],bytes32[2][],bytes32[9][],bytes32[2],bytes32[21][])"; - public static String burn = "burn(bytes32[10],bytes32[2],uint256,bytes32[2],address," - + "bytes32[3],bytes32[9][],bytes32[21][])"; - //public Wallet wallet = new Wallet(); + public static String burn = + "burn(bytes32[10],bytes32[2],uint256,bytes32[2],address," + + "bytes32[3],bytes32[9][],bytes32[21][])"; + // public Wallet wallet = new Wallet(); static HttpResponse response; static HttpPost httppost; static JSONObject responseContent; public static Integer scalingFactorLogarithm = 0; public static Long totalSupply = 1000000000000L; - /** - * constructor. - */ + /** constructor. */ @BeforeSuite(enabled = true, description = "Deploy shield trc20 depend contract") public void deployShieldTrc20DependContract() { - maxFeeLimit = - Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit"); + maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit"); logger.info("maxFeeLimit:" + maxFeeLimit); - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext() - .build(); + channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); blockingStubFull = WalletGrpc.newBlockingStub(channelFull); getDailyBuildStartNum(); - Assert.assertTrue(PublicMethod.sendcoin(zenTrc20TokenOwnerAddress, 10000000000000L, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + zenTrc20TokenOwnerAddress, + 10000000000000L, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); String contractName = "shieldTrc20Token"; - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_shieldTrc20Token"); - String code = Configuration.getByPath("testng.conf") - .getString("code.code_shieldTrc20Token"); + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_shieldTrc20Token"); + String code = Configuration.getByPath("testng.conf").getString("code.code_shieldTrc20Token"); String constructorStr = "constructor(uint256,string,string)"; String data = totalSupply.toString() + "," + "\"TokenTRC20\"" + "," + "\"zen20\""; logger.info("data:" + data); - deployShieldTrc20Txid = PublicMethod - .deployContractWithConstantParame(contractName, abi, code, constructorStr, data, "", - maxFeeLimit, 0L, 100, null, - zenTrc20TokenOwnerKey, zenTrc20TokenOwnerAddress, blockingStubFull); + deployShieldTrc20Txid = + PublicMethod.deployContractWithConstantParame( + contractName, + abi, + code, + constructorStr, + data, + "", + maxFeeLimit, + 0L, + 100, + null, + zenTrc20TokenOwnerKey, + zenTrc20TokenOwnerAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info(deployShieldTrc20Txid); - Optional infoById = PublicMethod - .getTransactionInfoById(deployShieldTrc20Txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(deployShieldTrc20Txid, blockingStubFull); contractAddressByteString = infoById.get().getContractAddress(); contractAddressByte = infoById.get().getContractAddress().toByteArray(); contractAddress = Base58.encode58Check(contractAddressByte); logger.info(contractAddress); contractName = "shield"; - abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_shield"); - code = Configuration.getByPath("testng.conf") - .getString("code.code_shield"); + abi = Configuration.getByPath("testng.conf").getString("abi.abi_shield"); + code = Configuration.getByPath("testng.conf").getString("code.code_shield"); data = "\"" + contractAddress + "\"" + "," + scalingFactorLogarithm; constructorStr = "constructor(address,uint256)"; - deployShieldTxid = PublicMethod - .deployContractWithConstantParame(contractName, abi, code, constructorStr, data, "", - maxFeeLimit, 0L, 100, null, - zenTrc20TokenOwnerKey, zenTrc20TokenOwnerAddress, blockingStubFull); + deployShieldTxid = + PublicMethod.deployContractWithConstantParame( + contractName, + abi, + code, + constructorStr, + data, + "", + maxFeeLimit, + 0L, + 100, + null, + zenTrc20TokenOwnerKey, + zenTrc20TokenOwnerAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info(deployShieldTxid); - infoById = PublicMethod - .getTransactionInfoById(deployShieldTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(deployShieldTxid, blockingStubFull); shieldAddressByteString = infoById.get().getContractAddress(); shieldAddressByte = infoById.get().getContractAddress().toByteArray(); shieldAddress = Base58.encode58Check(shieldAddressByte); logger.info(shieldAddress); data = "\"" + shieldAddress + "\"" + "," + totalSupply.toString(); - String txid = PublicMethod.triggerContract(contractAddressByte, - "approve(address,uint256)", data, false, - 0, maxFeeLimit, zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddressByte, + "approve(address,uint256)", + data, + false, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("approve:" + txid); Assert.assertTrue(infoById.get().getReceipt().getResultValue() == 1); - } - /** - * constructor. - */ + /** constructor. */ public void getDailyBuildStartNum() { - DailyBuildReport.startBlockNum = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder() - .build()).getBlockHeader().getRawData().getNumber(); + DailyBuildReport.startBlockNum = + blockingStubFull + .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); System.out.println("!!!!!!! 222222222startnum:" + DailyBuildReport.startBlockNum); } - /** - * constructor. - */ - public GrpcAPI.ShieldedTRC20Parameters createShieldedTrc20Parameters(BigInteger publicFromAmount, - GrpcAPI.DecryptNotesTRC20 inputNoteList, List shieldedAddressInfoList, - List outputNoteList, String publicToAddress, Long pubicToAmount, + /** constructor. */ + public GrpcAPI.ShieldedTRC20Parameters createShieldedTrc20Parameters( + BigInteger publicFromAmount, + GrpcAPI.DecryptNotesTRC20 inputNoteList, + List shieldedAddressInfoList, + List outputNoteList, + String publicToAddress, + Long pubicToAmount, WalletGrpc.WalletBlockingStub blockingStubFull, - WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity) throws ZksnarkException { + WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity) + throws ZksnarkException { - GrpcAPI.PrivateShieldedTRC20Parameters.Builder builder - = GrpcAPI.PrivateShieldedTRC20Parameters.newBuilder(); + GrpcAPI.PrivateShieldedTRC20Parameters.Builder builder = + GrpcAPI.PrivateShieldedTRC20Parameters.newBuilder(); - //Mint type should set public from amount to parameter + // Mint type should set public from amount to parameter if (publicFromAmount.compareTo(BigInteger.ZERO) > 0) { builder.setFromAmount(publicFromAmount.toString()); } @@ -195,12 +227,14 @@ public GrpcAPI.ShieldedTRC20Parameters createShieldedTrc20Parameters(BigInteger String shieldedAddress = inputNoteList.getNoteTxs(i).getNote().getPaymentAddress(); String spendingKey = ByteArray.toHexString(shieldedAddressInfoList.get(0).getSk()); - BytesMessage sk = BytesMessage.newBuilder() - .setValue(ByteString.copyFrom(ByteArray.fromHexString(spendingKey))).build(); - Optional esk = Optional - .of(blockingStubFull.getExpandedSpendingKey(sk)); - - //ExpandedSpendingKey expandedSpendingKey = spendingKey.expandedSpendingKey(); + BytesMessage sk = + BytesMessage.newBuilder() + .setValue(ByteString.copyFrom(ByteArray.fromHexString(spendingKey))) + .build(); + Optional esk = + Optional.of(blockingStubFull.getExpandedSpendingKey(sk)); + + // ExpandedSpendingKey expandedSpendingKey = spendingKey.expandedSpendingKey(); builder.setAsk(esk.get().getAsk()); builder.setNsk(esk.get().getNsk()); builder.setOvk(esk.get().getOvk()); @@ -222,18 +256,22 @@ public GrpcAPI.ShieldedTRC20Parameters createShieldedTrc20Parameters(BigInteger byte[] path = Arrays.copyOfRange(eachRootAndPath, 32, 1056); GrpcAPI.SpendNoteTRC20.Builder spendTrc20NoteBuilder = GrpcAPI.SpendNoteTRC20.newBuilder(); spendTrc20NoteBuilder.setNote(noteBuild.build()); - spendTrc20NoteBuilder.setAlpha(ByteString.copyFrom(blockingStubFull.getRcm( - EmptyMessage.newBuilder().build()).getValue().toByteArray())); + spendTrc20NoteBuilder.setAlpha( + ByteString.copyFrom( + blockingStubFull + .getRcm(EmptyMessage.newBuilder().build()) + .getValue() + .toByteArray())); spendTrc20NoteBuilder.setRoot(ByteString.copyFrom(root)); spendTrc20NoteBuilder.setPath(ByteString.copyFrom(path)); spendTrc20NoteBuilder.setPos(inputNoteList.getNoteTxs(i).getPosition()); - valueBalance = Math.addExact(valueBalance, inputNoteList.getNoteTxs(i).getNote() - .getValue()); + valueBalance = + Math.addExact(valueBalance, inputNoteList.getNoteTxs(i).getNote().getValue()); builder.addShieldedSpends(spendTrc20NoteBuilder.build()); } } else { - //@TODO remove randomOvk by sha256.of(privateKey) + // @TODO remove randomOvk by sha256.of(privateKey) byte[] ovk = getRandomOvk(); if (ovk != null) { builder.setOvk(ByteString.copyFrom(ovk)); @@ -247,8 +285,7 @@ public GrpcAPI.ShieldedTRC20Parameters createShieldedTrc20Parameters(BigInteger for (int i = 0; i < outputNoteList.size(); i++) { GrpcAPI.Note note = outputNoteList.get(i); valueBalance = Math.subtractExact(valueBalance, note.getValue()); - builder.addShieldedReceives( - GrpcAPI.ReceiveNote.newBuilder().setNote(note).build()); + builder.addShieldedReceives(GrpcAPI.ReceiveNote.newBuilder().setNote(note).build()); } } @@ -265,27 +302,29 @@ public GrpcAPI.ShieldedTRC20Parameters createShieldedTrc20Parameters(BigInteger return blockingStubFull.createShieldedContractParameters(builder.build()); } catch (Exception e) { Status status = Status.fromThrowable(e); - System.out.println("createShieldedContractParameters failed,error " - + status.getDescription()); + System.out.println( + "createShieldedContractParameters failed,error " + status.getDescription()); } return null; } - /** - * constructor. - */ + /** constructor. */ public GrpcAPI.ShieldedTRC20Parameters createShieldedTrc20ParametersWithoutAsk( BigInteger publicFromAmount, - GrpcAPI.DecryptNotesTRC20 inputNoteList, List shieldedAddressInfoList, - List outputNoteList, String publicToAddress, byte[] receiverAddressbyte, + GrpcAPI.DecryptNotesTRC20 inputNoteList, + List shieldedAddressInfoList, + List outputNoteList, + String publicToAddress, + byte[] receiverAddressbyte, Long pubicToAmount, WalletGrpc.WalletBlockingStub blockingStubFull, - WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity) throws ZksnarkException { + WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity) + throws ZksnarkException { - GrpcAPI.PrivateShieldedTRC20ParametersWithoutAsk.Builder builder - = GrpcAPI.PrivateShieldedTRC20ParametersWithoutAsk.newBuilder(); + GrpcAPI.PrivateShieldedTRC20ParametersWithoutAsk.Builder builder = + GrpcAPI.PrivateShieldedTRC20ParametersWithoutAsk.newBuilder(); - //Mint type should set public from amount to parameter + // Mint type should set public from amount to parameter if (publicFromAmount.compareTo(BigInteger.ZERO) > 0) { builder.setFromAmount(publicFromAmount.toString()); } @@ -314,23 +353,26 @@ public GrpcAPI.ShieldedTRC20Parameters createShieldedTrc20ParametersWithoutAsk( for (int i = 0; i < inputNoteList.getNoteTxsCount(); ++i) { if (i == 0) { String spendingKey = ByteArray.toHexString(shieldedAddressInfoList.get(i).getSk()); - BytesMessage sk = BytesMessage.newBuilder() - .setValue(ByteString.copyFrom(ByteArray.fromHexString(spendingKey))).build(); - Optional esk = Optional - .of(blockingStubFull.getExpandedSpendingKey(sk)); + BytesMessage sk = + BytesMessage.newBuilder() + .setValue(ByteString.copyFrom(ByteArray.fromHexString(spendingKey))) + .build(); + Optional esk = + Optional.of(blockingStubFull.getExpandedSpendingKey(sk)); System.arraycopy(esk.get().getAsk().toByteArray(), 0, ask, 0, 32); String ask1 = ByteArray.toHexString(esk.get().getAsk().toByteArray()); - BytesMessage ask2 = BytesMessage.newBuilder() - .setValue(ByteString.copyFrom(ByteArray.fromHexString(ask1))).build(); + BytesMessage ask2 = + BytesMessage.newBuilder() + .setValue(ByteString.copyFrom(ByteArray.fromHexString(ask1))) + .build(); Optional ak = Optional.of(blockingStubFull.getAkFromAsk(ask2)); String akString = ByteArray.toHexString(ak.get().getValue().toByteArray()); builder.setAk(ByteString.copyFrom(ByteArray.fromHexString(akString))); builder.setOvk(esk.get().getOvk()); builder.setNsk(esk.get().getNsk()); - } Note.Builder noteBuild = Note.newBuilder(); noteBuild.setPaymentAddress(shieldedAddressInfoList.get(i).getAddress()); @@ -340,8 +382,8 @@ public GrpcAPI.ShieldedTRC20Parameters createShieldedTrc20ParametersWithoutAsk( System.out.println("address " + shieldedAddressInfoList.get(i).getAddress()); System.out.println("value " + inputNoteList.getNoteTxs(i).getNote().getValue()); - System.out.println("trxId " + ByteArray.toHexString(inputNoteList.getNoteTxs(i) - .getTxid().toByteArray())); + System.out.println( + "trxId " + ByteArray.toHexString(inputNoteList.getNoteTxs(i).getTxid().toByteArray())); System.out.println("index " + inputNoteList.getNoteTxs(i).getIndex()); System.out.println("position " + inputNoteList.getNoteTxs(i).getPosition()); @@ -350,18 +392,22 @@ public GrpcAPI.ShieldedTRC20Parameters createShieldedTrc20ParametersWithoutAsk( byte[] path = Arrays.copyOfRange(eachRootAndPath, 32, 1056); GrpcAPI.SpendNoteTRC20.Builder spendTrc20NoteBuilder = GrpcAPI.SpendNoteTRC20.newBuilder(); spendTrc20NoteBuilder.setNote(noteBuild.build()); - spendTrc20NoteBuilder.setAlpha(ByteString.copyFrom(blockingStubFull.getRcm( - EmptyMessage.newBuilder().build()).getValue().toByteArray())); + spendTrc20NoteBuilder.setAlpha( + ByteString.copyFrom( + blockingStubFull + .getRcm(EmptyMessage.newBuilder().build()) + .getValue() + .toByteArray())); spendTrc20NoteBuilder.setRoot(ByteString.copyFrom(root)); spendTrc20NoteBuilder.setPath(ByteString.copyFrom(path)); spendTrc20NoteBuilder.setPos(inputNoteList.getNoteTxs(i).getPosition()); builder.addShieldedSpends(spendTrc20NoteBuilder.build()); - valueBalance = Math.addExact(valueBalance, inputNoteList.getNoteTxs(i) - .getNote().getValue()); + valueBalance = + Math.addExact(valueBalance, inputNoteList.getNoteTxs(i).getNote().getValue()); } } else { - //@TODO remove randomOvk by sha256.of(privateKey) + // @TODO remove randomOvk by sha256.of(privateKey) byte[] ovk = getRandomOvk(); if (ovk != null) { builder.setOvk(ByteString.copyFrom(ovk)); @@ -375,8 +421,7 @@ public GrpcAPI.ShieldedTRC20Parameters createShieldedTrc20ParametersWithoutAsk( for (int i = 0; i < outputNoteList.size(); i++) { GrpcAPI.Note note = outputNoteList.get(i); valueBalance = Math.subtractExact(valueBalance, note.getValue()); - builder.addShieldedReceives( - GrpcAPI.ReceiveNote.newBuilder().setNote(note).build()); + builder.addShieldedReceives(GrpcAPI.ReceiveNote.newBuilder().setNote(note).build()); } } @@ -389,8 +434,8 @@ public GrpcAPI.ShieldedTRC20Parameters createShieldedTrc20ParametersWithoutAsk( builder.setToAmount(pubicToAmount.toString()); } - ShieldedTRC20Parameters parameters = blockingStubFull - .createShieldedContractParametersWithoutAsk(builder.build()); + ShieldedTRC20Parameters parameters = + blockingStubFull.createShieldedContractParametersWithoutAsk(builder.build()); if (parameters == null) { System.out.println("createShieldedContractParametersWithoutAsk failed!"); return null; @@ -416,15 +461,15 @@ public GrpcAPI.ShieldedTRC20Parameters createShieldedTrc20ParametersWithoutAsk( builder1.setAlpha(builder.build().getShieldedSpends(i).getAlpha()); BytesMessage authSig = blockingStubFull.createSpendAuthSig(builder1.build()); - newBuilder.getSpendDescriptionBuilder(i) - .setSpendAuthoritySignature( - ByteString.copyFrom(authSig.getValue().toByteArray())); + newBuilder + .getSpendDescriptionBuilder(i) + .setSpendAuthoritySignature(ByteString.copyFrom(authSig.getValue().toByteArray())); stBuilder.addSpendAuthoritySignature(authSig); BytesMessage triggerInputData; try { - triggerInputData = blockingStubFull.getTriggerInputForShieldedTRC20Contract(stBuilder - .build()); + triggerInputData = + blockingStubFull.getTriggerInputForShieldedTRC20Contract(stBuilder.build()); } catch (Exception e) { triggerInputData = null; System.out.println("getTriggerInputForShieldedTRC20Contract error, please retry!"); @@ -432,54 +477,56 @@ public GrpcAPI.ShieldedTRC20Parameters createShieldedTrc20ParametersWithoutAsk( if (triggerInputData == null) { return null; } - newBuilder.setTriggerContractInput(ByteArray.toHexString(triggerInputData.getValue() - .toByteArray())); - + newBuilder.setTriggerContractInput( + ByteArray.toHexString(triggerInputData.getValue().toByteArray())); } return newBuilder.build(); } - /** - * constructor. - */ - public String getRootAndPath(long position, WalletSolidityGrpc.WalletSolidityBlockingStub - blockingStubSolidity) { + /** constructor. */ + public String getRootAndPath( + long position, WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity) { String methodStr = "getPath(uint256)"; byte[] indexBytes = ByteArray.fromLong(position); String argsStr = ByteArray.toHexString(indexBytes); argsStr = "000000000000000000000000000000000000000000000000" + argsStr; - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtentionOnSolidity(shieldAddressByte, methodStr, argsStr, - true, 0, 1000000000L, "0", 0, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubSolidity); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtentionOnSolidity( + shieldAddressByte, + methodStr, + argsStr, + true, + 0, + 1000000000L, + "0", + 0, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubSolidity); byte[] result = transactionExtention.getConstantResult(0).toByteArray(); return ByteArray.toHexString(result); } - /** - * constructor. - */ - public String encodeMintParamsToHexString(GrpcAPI.ShieldedTRC20Parameters parameters, - BigInteger value) { + /** constructor. */ + public String encodeMintParamsToHexString( + GrpcAPI.ShieldedTRC20Parameters parameters, BigInteger value) { byte[] mergedBytes; ShieldContract.ReceiveDescription revDesc = parameters.getReceiveDescription(0); - mergedBytes = ByteUtil.merge( - ByteUtil.bigIntegerToBytes(value, 32), - revDesc.getNoteCommitment().toByteArray(), - revDesc.getValueCommitment().toByteArray(), - revDesc.getEpk().toByteArray(), - revDesc.getZkproof().toByteArray(), - parameters.getBindingSignature().toByteArray(), - revDesc.getCEnc().toByteArray(), - revDesc.getCOut().toByteArray(), - new byte[12] - ); + mergedBytes = + ByteUtil.merge( + ByteUtil.bigIntegerToBytes(value, 32), + revDesc.getNoteCommitment().toByteArray(), + revDesc.getValueCommitment().toByteArray(), + revDesc.getEpk().toByteArray(), + revDesc.getZkproof().toByteArray(), + parameters.getBindingSignature().toByteArray(), + revDesc.getCEnc().toByteArray(), + revDesc.getCOut().toByteArray(), + new byte[12]); return ByteArray.toHexString(mergedBytes); } - /** - * constructor. - */ + /** constructor. */ public static HttpResponse getNewShieldedAddress(String httpNode) { try { String requestUrl = "http://" + httpNode + "/wallet/getnewshieldedaddress"; @@ -492,22 +539,19 @@ public static HttpResponse getNewShieldedAddress(String httpNode) { return response; } - /** - * constructor. - */ - public Optional getNewShieldedAddress(WalletGrpc.WalletBlockingStub - blockingStubFull) { + /** constructor. */ + public Optional getNewShieldedAddress( + WalletGrpc.WalletBlockingStub blockingStubFull) { ShieldedAddressInfo addressInfo = new ShieldedAddressInfo(); try { - Optional sk = Optional.of(blockingStubFull - .getSpendingKey(EmptyMessage.newBuilder().build())); - final Optional d = Optional.of(blockingStubFull.getDiversifier( - EmptyMessage.newBuilder().build())); + Optional sk = + Optional.of(blockingStubFull.getSpendingKey(EmptyMessage.newBuilder().build())); + final Optional d = + Optional.of(blockingStubFull.getDiversifier(EmptyMessage.newBuilder().build())); - Optional expandedSpendingKeyMessage - = Optional.of(blockingStubFull - .getExpandedSpendingKey(sk.get())); + Optional expandedSpendingKeyMessage = + Optional.of(blockingStubFull.getExpandedSpendingKey(sk.get())); BytesMessage.Builder askBuilder = BytesMessage.newBuilder(); askBuilder.setValue(expandedSpendingKeyMessage.get().getAsk()); @@ -520,16 +564,15 @@ public Optional getNewShieldedAddress(WalletGrpc.WalletBloc GrpcAPI.ViewingKeyMessage.Builder viewBuilder = GrpcAPI.ViewingKeyMessage.newBuilder(); viewBuilder.setAk(ak.get().getValue()); viewBuilder.setNk(nk.get().getValue()); - Optional ivk = Optional.of(blockingStubFull - .getIncomingViewingKey(viewBuilder.build())); + Optional ivk = + Optional.of(blockingStubFull.getIncomingViewingKey(viewBuilder.build())); - GrpcAPI.IncomingViewingKeyDiversifierMessage.Builder builder - = GrpcAPI.IncomingViewingKeyDiversifierMessage - .newBuilder(); + GrpcAPI.IncomingViewingKeyDiversifierMessage.Builder builder = + GrpcAPI.IncomingViewingKeyDiversifierMessage.newBuilder(); builder.setD(d.get()); builder.setIvk(ivk.get()); - Optional addressMessage = Optional.of(blockingStubFull - .getZenPaymentAddress(builder.build())); + Optional addressMessage = + Optional.of(blockingStubFull.getZenPaymentAddress(builder.build())); addressInfo.setSk(sk.get().getValue().toByteArray()); addressInfo.setD(new DiversifierT(d.get().getD().toByteArray())); addressInfo.setIvk(ivk.get().getIvk().toByteArray()); @@ -537,8 +580,8 @@ public Optional getNewShieldedAddress(WalletGrpc.WalletBloc addressInfo.setPkD(addressMessage.get().getPkD().toByteArray()); System.out.println("ivk " + ByteArray.toHexString(ivk.get().getIvk().toByteArray())); - System.out.println("ovk " + ByteArray.toHexString(expandedSpendingKeyMessage.get() - .getOvk().toByteArray())); + System.out.println( + "ovk " + ByteArray.toHexString(expandedSpendingKeyMessage.get().getOvk().toByteArray())); return Optional.of(addressInfo); @@ -549,11 +592,12 @@ public Optional getNewShieldedAddress(WalletGrpc.WalletBloc return Optional.empty(); } - /** - * constructor. - */ - public static List addShieldTrc20OutputList(List shieldOutList, - String shieldToAddress, String toAmountString, String menoString, + /** constructor. */ + public static List addShieldTrc20OutputList( + List shieldOutList, + String shieldToAddress, + String toAmountString, + String menoString, WalletGrpc.WalletBlockingStub blockingStubFull) { String shieldAddress = shieldToAddress; String amountString = toAmountString; @@ -567,28 +611,38 @@ public static List addShieldTrc20OutputList(List shieldOutList, Note.Builder noteBuild = Note.newBuilder(); noteBuild.setPaymentAddress(shieldAddress); - //noteBuild.setPaymentAddress(shieldAddress); + // noteBuild.setPaymentAddress(shieldAddress); noteBuild.setValue(shieldAmount); - noteBuild.setRcm(ByteString.copyFrom(blockingStubFull.getRcm(EmptyMessage.newBuilder().build()) - .getValue().toByteArray())); + noteBuild.setRcm( + ByteString.copyFrom( + blockingStubFull.getRcm(EmptyMessage.newBuilder().build()).getValue().toByteArray())); noteBuild.setMemo(ByteString.copyFrom(menoString.getBytes())); shieldOutList.add(noteBuild.build()); return shieldOutList; } - /** - * constructor. - */ - public Long getBalanceOfShieldTrc20(String queryAddress, byte[] ownerAddress, - String ownerKey, WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public Long getBalanceOfShieldTrc20( + String queryAddress, + byte[] ownerAddress, + String ownerKey, + WalletGrpc.WalletBlockingStub blockingStubFull) { String paramStr = "\"" + queryAddress + "\""; - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddressByte, "balanceOf(address)", - paramStr, false, 0, 0, "0", 0, - ownerAddress, ownerKey, blockingStubFull); - - String hexBalance = Hex.toHexString(transactionExtention - .getConstantResult(0).toByteArray()); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddressByte, + "balanceOf(address)", + paramStr, + false, + 0, + 0, + "0", + 0, + ownerAddress, + ownerKey, + blockingStubFull); + + String hexBalance = Hex.toHexString(transactionExtention.getConstantResult(0).toByteArray()); for (int i = 0; i < hexBalance.length(); i++) { if (hexBalance.charAt(i) != '0') { hexBalance = hexBalance.substring(i); @@ -599,19 +653,28 @@ public Long getBalanceOfShieldTrc20(String queryAddress, byte[] ownerAddress, return Long.parseLong(hexBalance, 16); } - /** - * constructor. - */ - public String getBalanceOfShieldTrc20String(String queryAddress, byte[] ownerAddress, - String ownerKey, WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public String getBalanceOfShieldTrc20String( + String queryAddress, + byte[] ownerAddress, + String ownerKey, + WalletGrpc.WalletBlockingStub blockingStubFull) { String paramStr = "\"" + queryAddress + "\""; - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddressByte, "balanceOf(address)", - paramStr, false, 0, 0, "0", 0, - ownerAddress, ownerKey, blockingStubFull); - - String hexBalance = Hex.toHexString(transactionExtention - .getConstantResult(0).toByteArray()); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddressByte, + "balanceOf(address)", + paramStr, + false, + 0, + 0, + "0", + 0, + ownerAddress, + ownerKey, + blockingStubFull); + + String hexBalance = Hex.toHexString(transactionExtention.getConstantResult(0).toByteArray()); for (int i = 0; i < hexBalance.length(); i++) { if (hexBalance.charAt(i) != '0') { hexBalance = hexBalance.substring(i); @@ -622,14 +685,18 @@ public String getBalanceOfShieldTrc20String(String queryAddress, byte[] ownerAdd return hexBalance; } - /** - * constructor. - */ - public GrpcAPI.DecryptNotesTRC20 scanShieldedTrc20NoteByIvk(ShieldedAddressInfo - shieldedAddressInfo, WalletGrpc.WalletBlockingStub blockingStubFull, - WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity) throws Exception { - long currentBlockNum = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + /** constructor. */ + public GrpcAPI.DecryptNotesTRC20 scanShieldedTrc20NoteByIvk( + ShieldedAddressInfo shieldedAddressInfo, + WalletGrpc.WalletBlockingStub blockingStubFull, + WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity) + throws Exception { + long currentBlockNum = + blockingStubFull + .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); Long startNum = currentBlockNum - 90L; final Long endNum = currentBlockNum; @@ -638,63 +705,72 @@ public GrpcAPI.DecryptNotesTRC20 scanShieldedTrc20NoteByIvk(ShieldedAddressInfo } String spendingKey = ByteArray.toHexString(shieldedAddressInfo.getSk()); - BytesMessage sk = BytesMessage.newBuilder() - .setValue(ByteString.copyFrom(ByteArray.fromHexString(spendingKey))).build(); - Optional esk = Optional - .of(blockingStubFull.getExpandedSpendingKey(sk)); + BytesMessage sk = + BytesMessage.newBuilder() + .setValue(ByteString.copyFrom(ByteArray.fromHexString(spendingKey))) + .build(); + Optional esk = + Optional.of(blockingStubFull.getExpandedSpendingKey(sk)); String ask = ByteArray.toHexString(esk.get().getAsk().toByteArray()); - BytesMessage ask1 = BytesMessage.newBuilder() - .setValue(ByteString.copyFrom(ByteArray.fromHexString(ask))).build(); + BytesMessage ask1 = + BytesMessage.newBuilder() + .setValue(ByteString.copyFrom(ByteArray.fromHexString(ask))) + .build(); Optional ak = Optional.of(blockingStubFull.getAkFromAsk(ask1)); String akString = ByteArray.toHexString(ak.get().getValue().toByteArray()); - //System.out.println("ak:" + ByteArray.toHexString(ak.get().getValue().toByteArray())); + // System.out.println("ak:" + ByteArray.toHexString(ak.get().getValue().toByteArray())); String nsk = ByteArray.toHexString(esk.get().getNsk().toByteArray()); - BytesMessage nsk1 = BytesMessage.newBuilder() - .setValue(ByteString.copyFrom(ByteArray.fromHexString(nsk))).build(); + BytesMessage nsk1 = + BytesMessage.newBuilder() + .setValue(ByteString.copyFrom(ByteArray.fromHexString(nsk))) + .build(); Optional nk = Optional.of(blockingStubFull.getNkFromNsk(nsk1)); - //System.out.println("nk:" + ByteArray.toHexString(nk.get().getValue().toByteArray())); + // System.out.println("nk:" + ByteArray.toHexString(nk.get().getValue().toByteArray())); String nkString = ByteArray.toHexString(nk.get().getValue().toByteArray()); GrpcAPI.ViewingKeyMessage.Builder viewBuilder = GrpcAPI.ViewingKeyMessage.newBuilder(); viewBuilder.setAk(ak.get().getValue()); viewBuilder.setNk(nk.get().getValue()); - GrpcAPI.IncomingViewingKeyMessage ivk = blockingStubFull - .getIncomingViewingKey(viewBuilder.build()); + GrpcAPI.IncomingViewingKeyMessage ivk = + blockingStubFull.getIncomingViewingKey(viewBuilder.build()); - //ivk.getIvk() + // ivk.getIvk() String ivkString = ByteArray.toHexString(ivk.getIvk().toByteArray()); String ivkStringOld = ByteArray.toHexString(shieldedAddressInfo.getIvk()); - GrpcAPI.IvkDecryptTRC20Parameters parameters = GrpcAPI.IvkDecryptTRC20Parameters - .newBuilder() - .setStartBlockIndex(startNum) - .setEndBlockIndex(endNum) - .setShieldedTRC20ContractAddress(ByteString.copyFrom(WalletClient.decode58Check(shieldAddress))) - .setIvk(ByteString.copyFrom(ByteArray.fromHexString(ivkString))) - .setAk(ByteString.copyFrom(ByteArray.fromHexString(akString))) - .setNk(ByteString.copyFrom(ByteArray.fromHexString(nkString))) - .build(); + GrpcAPI.IvkDecryptTRC20Parameters parameters = + GrpcAPI.IvkDecryptTRC20Parameters.newBuilder() + .setStartBlockIndex(startNum) + .setEndBlockIndex(endNum) + .setShieldedTRC20ContractAddress( + ByteString.copyFrom(WalletClient.decode58Check(shieldAddress))) + .setIvk(ByteString.copyFrom(ByteArray.fromHexString(ivkString))) + .setAk(ByteString.copyFrom(ByteArray.fromHexString(akString))) + .setNk(ByteString.copyFrom(ByteArray.fromHexString(nkString))) + .build(); try { return blockingStubSolidity.scanShieldedTRC20NotesByIvk(parameters); } catch (Exception e) { System.out.println(e); Status status = Status.fromThrowable(e); System.out.println("ScanShieldedTRC20NoteByIvk failed,error " + status.getDescription()); - } return null; } - /** - * constructor. - */ - public GrpcAPI.DecryptNotesTRC20 scanShieldedTrc20NoteByIvk(ShieldedAddressInfo - shieldedAddressInfo, WalletGrpc.WalletBlockingStub blockingStubFull) throws Exception { - long currentBlockNum = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + /** constructor. */ + public GrpcAPI.DecryptNotesTRC20 scanShieldedTrc20NoteByIvk( + ShieldedAddressInfo shieldedAddressInfo, WalletGrpc.WalletBlockingStub blockingStubFull) + throws Exception { + long currentBlockNum = + blockingStubFull + .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); Long startNum = currentBlockNum - 90L; final Long endNum = currentBlockNum; @@ -703,100 +779,113 @@ public GrpcAPI.DecryptNotesTRC20 scanShieldedTrc20NoteByIvk(ShieldedAddressInfo } String spendingKey = ByteArray.toHexString(shieldedAddressInfo.getSk()); - BytesMessage sk = BytesMessage.newBuilder() - .setValue(ByteString.copyFrom(ByteArray.fromHexString(spendingKey))).build(); - Optional esk = Optional - .of(blockingStubFull.getExpandedSpendingKey(sk)); + BytesMessage sk = + BytesMessage.newBuilder() + .setValue(ByteString.copyFrom(ByteArray.fromHexString(spendingKey))) + .build(); + Optional esk = + Optional.of(blockingStubFull.getExpandedSpendingKey(sk)); String ask = ByteArray.toHexString(esk.get().getAsk().toByteArray()); - BytesMessage ask1 = BytesMessage.newBuilder() - .setValue(ByteString.copyFrom(ByteArray.fromHexString(ask))).build(); + BytesMessage ask1 = + BytesMessage.newBuilder() + .setValue(ByteString.copyFrom(ByteArray.fromHexString(ask))) + .build(); Optional ak = Optional.of(blockingStubFull.getAkFromAsk(ask1)); String akString = ByteArray.toHexString(ak.get().getValue().toByteArray()); String nsk = ByteArray.toHexString(esk.get().getNsk().toByteArray()); - BytesMessage nsk1 = BytesMessage.newBuilder() - .setValue(ByteString.copyFrom(ByteArray.fromHexString(nsk))).build(); + BytesMessage nsk1 = + BytesMessage.newBuilder() + .setValue(ByteString.copyFrom(ByteArray.fromHexString(nsk))) + .build(); Optional nk = Optional.of(blockingStubFull.getNkFromNsk(nsk1)); String nkString = ByteArray.toHexString(nk.get().getValue().toByteArray()); GrpcAPI.ViewingKeyMessage.Builder viewBuilder = GrpcAPI.ViewingKeyMessage.newBuilder(); viewBuilder.setAk(ak.get().getValue()); viewBuilder.setNk(nk.get().getValue()); - GrpcAPI.IncomingViewingKeyMessage ivk = blockingStubFull - .getIncomingViewingKey(viewBuilder.build()); + GrpcAPI.IncomingViewingKeyMessage ivk = + blockingStubFull.getIncomingViewingKey(viewBuilder.build()); String ivkString = ByteArray.toHexString(ivk.getIvk().toByteArray()); - GrpcAPI.IvkDecryptTRC20Parameters parameters = GrpcAPI.IvkDecryptTRC20Parameters - .newBuilder() - .setStartBlockIndex(startNum) - .setEndBlockIndex(endNum) - .setShieldedTRC20ContractAddress(ByteString.copyFrom(WalletClient.decode58Check(shieldAddress))) - .setIvk(ByteString.copyFrom(ByteArray.fromHexString(ivkString))) - .setAk(ByteString.copyFrom(ByteArray.fromHexString(akString))) - .setNk(ByteString.copyFrom(ByteArray.fromHexString(nkString))) - //.setEvents() - .build(); + GrpcAPI.IvkDecryptTRC20Parameters parameters = + GrpcAPI.IvkDecryptTRC20Parameters.newBuilder() + .setStartBlockIndex(startNum) + .setEndBlockIndex(endNum) + .setShieldedTRC20ContractAddress( + ByteString.copyFrom(WalletClient.decode58Check(shieldAddress))) + .setIvk(ByteString.copyFrom(ByteArray.fromHexString(ivkString))) + .setAk(ByteString.copyFrom(ByteArray.fromHexString(akString))) + .setNk(ByteString.copyFrom(ByteArray.fromHexString(nkString))) + // .setEvents() + .build(); try { return blockingStubFull.scanShieldedTRC20NotesByIvk(parameters); } catch (Exception e) { System.out.println(e); Status status = Status.fromThrowable(e); System.out.println("ScanShieldedTRC20NoteByIvk failed,error " + status.getDescription()); - } return null; } - /** - * constructor. - */ - public GrpcAPI.DecryptNotesTRC20 scanShieldedTrc20NoteByIvkWithRange(ShieldedAddressInfo - shieldedAddressInfo, Long startNum, Long endNum, - WalletGrpc.WalletBlockingStub blockingStubFull) throws Exception { + /** constructor. */ + public GrpcAPI.DecryptNotesTRC20 scanShieldedTrc20NoteByIvkWithRange( + ShieldedAddressInfo shieldedAddressInfo, + Long startNum, + Long endNum, + WalletGrpc.WalletBlockingStub blockingStubFull) + throws Exception { String spendingKey = ByteArray.toHexString(shieldedAddressInfo.getSk()); - BytesMessage sk = BytesMessage.newBuilder() - .setValue(ByteString.copyFrom(ByteArray.fromHexString(spendingKey))).build(); - Optional esk = Optional - .of(blockingStubFull.getExpandedSpendingKey(sk)); + BytesMessage sk = + BytesMessage.newBuilder() + .setValue(ByteString.copyFrom(ByteArray.fromHexString(spendingKey))) + .build(); + Optional esk = + Optional.of(blockingStubFull.getExpandedSpendingKey(sk)); String ask = ByteArray.toHexString(esk.get().getAsk().toByteArray()); - BytesMessage ask1 = BytesMessage.newBuilder() - .setValue(ByteString.copyFrom(ByteArray.fromHexString(ask))).build(); + BytesMessage ask1 = + BytesMessage.newBuilder() + .setValue(ByteString.copyFrom(ByteArray.fromHexString(ask))) + .build(); Optional ak = Optional.of(blockingStubFull.getAkFromAsk(ask1)); String akString = ByteArray.toHexString(ak.get().getValue().toByteArray()); String nsk = ByteArray.toHexString(esk.get().getNsk().toByteArray()); - BytesMessage nsk1 = BytesMessage.newBuilder() - .setValue(ByteString.copyFrom(ByteArray.fromHexString(nsk))).build(); + BytesMessage nsk1 = + BytesMessage.newBuilder() + .setValue(ByteString.copyFrom(ByteArray.fromHexString(nsk))) + .build(); Optional nk = Optional.of(blockingStubFull.getNkFromNsk(nsk1)); String nkString = ByteArray.toHexString(nk.get().getValue().toByteArray()); GrpcAPI.ViewingKeyMessage.Builder viewBuilder = GrpcAPI.ViewingKeyMessage.newBuilder(); viewBuilder.setAk(ak.get().getValue()); viewBuilder.setNk(nk.get().getValue()); - GrpcAPI.IncomingViewingKeyMessage ivk = blockingStubFull - .getIncomingViewingKey(viewBuilder.build()); + GrpcAPI.IncomingViewingKeyMessage ivk = + blockingStubFull.getIncomingViewingKey(viewBuilder.build()); String ivkString = ByteArray.toHexString(ivk.getIvk().toByteArray()); GrpcAPI.DecryptNotesTRC20 result = GrpcAPI.DecryptNotesTRC20.newBuilder().build(); GrpcAPI.DecryptNotesTRC20 tempNoteTxs; while (startNum < endNum) { - GrpcAPI.IvkDecryptTRC20Parameters parameters = GrpcAPI.IvkDecryptTRC20Parameters - .newBuilder() - .setStartBlockIndex(startNum) - .setEndBlockIndex(startNum + 99) - .setShieldedTRC20ContractAddress(ByteString - .copyFrom(WalletClient.decode58Check(shieldAddress))) - .setIvk(ByteString.copyFrom(ByteArray.fromHexString(ivkString))) - .setAk(ByteString.copyFrom(ByteArray.fromHexString(akString))) - .setNk(ByteString.copyFrom(ByteArray.fromHexString(nkString))) - .build(); + GrpcAPI.IvkDecryptTRC20Parameters parameters = + GrpcAPI.IvkDecryptTRC20Parameters.newBuilder() + .setStartBlockIndex(startNum) + .setEndBlockIndex(startNum + 99) + .setShieldedTRC20ContractAddress( + ByteString.copyFrom(WalletClient.decode58Check(shieldAddress))) + .setIvk(ByteString.copyFrom(ByteArray.fromHexString(ivkString))) + .setAk(ByteString.copyFrom(ByteArray.fromHexString(akString))) + .setNk(ByteString.copyFrom(ByteArray.fromHexString(nkString))) + .build(); tempNoteTxs = blockingStubFull.scanShieldedTRC20NotesByIvk(parameters); logger.info("tempNoteTxs size:" + tempNoteTxs.getNoteTxsCount()); @@ -810,18 +899,20 @@ public GrpcAPI.DecryptNotesTRC20 scanShieldedTrc20NoteByIvkWithRange(ShieldedAdd System.out.println(e); Status status = Status.fromThrowable(e); System.out.println("ScanShieldedTRC20NoteByIvk failed,error " + status.getDescription()); - } return null; } - /** - * constructor. - */ - public GrpcAPI.DecryptNotesTRC20 scanShieldedTrc20NoteByOvk(ShieldedAddressInfo - shieldedAddressInfo, WalletGrpc.WalletBlockingStub blockingStubFull) throws Exception { - long currentBlockNum = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + /** constructor. */ + public GrpcAPI.DecryptNotesTRC20 scanShieldedTrc20NoteByOvk( + ShieldedAddressInfo shieldedAddressInfo, WalletGrpc.WalletBlockingStub blockingStubFull) + throws Exception { + long currentBlockNum = + blockingStubFull + .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); Long startNum = currentBlockNum - 90L; Long endNum = currentBlockNum; if (currentBlockNum < 100) { @@ -829,12 +920,14 @@ public GrpcAPI.DecryptNotesTRC20 scanShieldedTrc20NoteByOvk(ShieldedAddressInfo } String ovkString = ByteArray.toHexString(shieldedAddressInfo.getOvk()); - GrpcAPI.OvkDecryptTRC20Parameters parameters = GrpcAPI.OvkDecryptTRC20Parameters.newBuilder() - .setStartBlockIndex(startNum) - .setEndBlockIndex(endNum) - .setOvk(ByteString.copyFrom(ByteArray.fromHexString(ovkString))) - .setShieldedTRC20ContractAddress(ByteString.copyFrom(WalletClient.decode58Check(shieldAddress))) - .build(); + GrpcAPI.OvkDecryptTRC20Parameters parameters = + GrpcAPI.OvkDecryptTRC20Parameters.newBuilder() + .setStartBlockIndex(startNum) + .setEndBlockIndex(endNum) + .setOvk(ByteString.copyFrom(ByteArray.fromHexString(ovkString))) + .setShieldedTRC20ContractAddress( + ByteString.copyFrom(WalletClient.decode58Check(shieldAddress))) + .build(); try { return blockingStubFull.scanShieldedTRC20NotesByOvk(parameters); @@ -842,19 +935,22 @@ public GrpcAPI.DecryptNotesTRC20 scanShieldedTrc20NoteByOvk(ShieldedAddressInfo System.out.println(e); Status status = Status.fromThrowable(e); System.out.println("ScanShieldedTRC20NoteByovk failed,error " + status.getDescription()); - } return null; } - /** - * constructor. - */ - public GrpcAPI.DecryptNotesTRC20 scanShieldedTrc20NoteByOvk(ShieldedAddressInfo - shieldedAddressInfo, WalletGrpc.WalletBlockingStub blockingStubFull, - WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity) throws Exception { - long currentBlockNum = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + /** constructor. */ + public GrpcAPI.DecryptNotesTRC20 scanShieldedTrc20NoteByOvk( + ShieldedAddressInfo shieldedAddressInfo, + WalletGrpc.WalletBlockingStub blockingStubFull, + WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity) + throws Exception { + long currentBlockNum = + blockingStubFull + .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); Long startNum = currentBlockNum - 90L; Long endNum = currentBlockNum; if (currentBlockNum < 100) { @@ -862,12 +958,14 @@ public GrpcAPI.DecryptNotesTRC20 scanShieldedTrc20NoteByOvk(ShieldedAddressInfo } String ovkString = ByteArray.toHexString(shieldedAddressInfo.getOvk()); - GrpcAPI.OvkDecryptTRC20Parameters parameters = GrpcAPI.OvkDecryptTRC20Parameters.newBuilder() - .setStartBlockIndex(startNum) - .setEndBlockIndex(endNum) - .setOvk(ByteString.copyFrom(ByteArray.fromHexString(ovkString))) - .setShieldedTRC20ContractAddress(ByteString.copyFrom(WalletClient.decode58Check(shieldAddress))) - .build(); + GrpcAPI.OvkDecryptTRC20Parameters parameters = + GrpcAPI.OvkDecryptTRC20Parameters.newBuilder() + .setStartBlockIndex(startNum) + .setEndBlockIndex(endNum) + .setOvk(ByteString.copyFrom(ByteArray.fromHexString(ovkString))) + .setShieldedTRC20ContractAddress( + ByteString.copyFrom(WalletClient.decode58Check(shieldAddress))) + .build(); try { return blockingStubSolidity.scanShieldedTRC20NotesByOvk(parameters); @@ -875,33 +973,37 @@ public GrpcAPI.DecryptNotesTRC20 scanShieldedTrc20NoteByOvk(ShieldedAddressInfo System.out.println(e); Status status = Status.fromThrowable(e); System.out.println("ScanShieldedTRC20NoteByovk failed,error " + status.getDescription()); - } return null; } - /** - * constructor. - */ + /** constructor. */ public static Boolean getTrc20SpendResult( - ShieldedAddressInfo shieldAddressInfo, GrpcAPI.DecryptNotesTRC20.NoteTx noteTx, + ShieldedAddressInfo shieldAddressInfo, + GrpcAPI.DecryptNotesTRC20.NoteTx noteTx, WalletGrpc.WalletBlockingStub blockingStubFull) { GrpcAPI.NfTRC20Parameters.Builder builder = GrpcAPI.NfTRC20Parameters.newBuilder(); String spendingKey = ByteArray.toHexString(shieldAddressInfo.getSk()); - BytesMessage sk = BytesMessage.newBuilder() - .setValue(ByteString.copyFrom(ByteArray.fromHexString(spendingKey))).build(); - Optional esk = Optional - .of(blockingStubFull.getExpandedSpendingKey(sk)); + BytesMessage sk = + BytesMessage.newBuilder() + .setValue(ByteString.copyFrom(ByteArray.fromHexString(spendingKey))) + .build(); + Optional esk = + Optional.of(blockingStubFull.getExpandedSpendingKey(sk)); String ask = ByteArray.toHexString(esk.get().getAsk().toByteArray()); - BytesMessage ask1 = BytesMessage.newBuilder() - .setValue(ByteString.copyFrom(ByteArray.fromHexString(ask))).build(); + BytesMessage ask1 = + BytesMessage.newBuilder() + .setValue(ByteString.copyFrom(ByteArray.fromHexString(ask))) + .build(); Optional ak = Optional.of(blockingStubFull.getAkFromAsk(ask1)); String nsk = ByteArray.toHexString(esk.get().getNsk().toByteArray()); - BytesMessage nsk1 = BytesMessage.newBuilder() - .setValue(ByteString.copyFrom(ByteArray.fromHexString(nsk))).build(); + BytesMessage nsk1 = + BytesMessage.newBuilder() + .setValue(ByteString.copyFrom(ByteArray.fromHexString(nsk))) + .build(); Optional nk = Optional.of(blockingStubFull.getNkFromNsk(nsk1)); builder.setAk(ak.get().getValue()); builder.setNk(nk.get().getValue()); @@ -915,34 +1017,39 @@ public static Boolean getTrc20SpendResult( noteBuild.setMemo(noteTx.getNote().getMemo()); builder.setNote(noteBuild.build()); - Optional result = Optional.of(blockingStubFull - .isShieldedTRC20ContractNoteSpent(builder.build())); + Optional result = + Optional.of(blockingStubFull.isShieldedTRC20ContractNoteSpent(builder.build())); return result.get().getIsSpent(); } - /** - * constructor. - */ + /** constructor. */ public static Boolean getTrc20SpendResult( - ShieldedAddressInfo shieldAddressInfo, GrpcAPI.DecryptNotesTRC20.NoteTx noteTx, + ShieldedAddressInfo shieldAddressInfo, + GrpcAPI.DecryptNotesTRC20.NoteTx noteTx, WalletGrpc.WalletBlockingStub blockingStubFull, WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity) { GrpcAPI.NfTRC20Parameters.Builder builder = GrpcAPI.NfTRC20Parameters.newBuilder(); String spendingKey = ByteArray.toHexString(shieldAddressInfo.getSk()); - BytesMessage sk = BytesMessage.newBuilder() - .setValue(ByteString.copyFrom(ByteArray.fromHexString(spendingKey))).build(); - Optional esk = Optional - .of(blockingStubFull.getExpandedSpendingKey(sk)); + BytesMessage sk = + BytesMessage.newBuilder() + .setValue(ByteString.copyFrom(ByteArray.fromHexString(spendingKey))) + .build(); + Optional esk = + Optional.of(blockingStubFull.getExpandedSpendingKey(sk)); String ask = ByteArray.toHexString(esk.get().getAsk().toByteArray()); - BytesMessage ask1 = BytesMessage.newBuilder() - .setValue(ByteString.copyFrom(ByteArray.fromHexString(ask))).build(); + BytesMessage ask1 = + BytesMessage.newBuilder() + .setValue(ByteString.copyFrom(ByteArray.fromHexString(ask))) + .build(); Optional ak = Optional.of(blockingStubFull.getAkFromAsk(ask1)); String nsk = ByteArray.toHexString(esk.get().getNsk().toByteArray()); - BytesMessage nsk1 = BytesMessage.newBuilder() - .setValue(ByteString.copyFrom(ByteArray.fromHexString(nsk))).build(); + BytesMessage nsk1 = + BytesMessage.newBuilder() + .setValue(ByteString.copyFrom(ByteArray.fromHexString(nsk))) + .build(); Optional nk = Optional.of(blockingStubFull.getNkFromNsk(nsk1)); builder.setAk(ak.get().getValue()); builder.setNk(nk.get().getValue()); @@ -956,21 +1063,18 @@ public static Boolean getTrc20SpendResult( noteBuild.setMemo(noteTx.getNote().getMemo()); builder.setNote(noteBuild.build()); - Optional result = Optional.of(blockingStubSolidity - .isShieldedTRC20ContractNoteSpent(builder.build())); + Optional result = + Optional.of(blockingStubSolidity.isShieldedTRC20ContractNoteSpent(builder.build())); return result.get().getIsSpent(); } - /** - * constructor. - */ + /** constructor. */ public byte[] getRandomOvk() { try { - Optional sk = Optional.of(blockingStubFull - .getSpendingKey(EmptyMessage.newBuilder().build())); - Optional expandedSpendingKeyMessage - = Optional.of(blockingStubFull - .getExpandedSpendingKey(sk.get())); + Optional sk = + Optional.of(blockingStubFull.getSpendingKey(EmptyMessage.newBuilder().build())); + Optional expandedSpendingKeyMessage = + Optional.of(blockingStubFull.getExpandedSpendingKey(sk.get())); return expandedSpendingKeyMessage.get().getOvk().toByteArray(); } catch (Exception e) { e.printStackTrace(); @@ -978,27 +1082,21 @@ public byte[] getRandomOvk() { return null; } - /** - * constructor. - */ + /** constructor. */ public BigInteger getRandomAmount() { Random random = new Random(); int x = random.nextInt(100000) + 100; return BigInteger.valueOf(x); } - /** - * constructor. - */ + /** constructor. */ public Long getRandomLongAmount() { Random random = new Random(); int x = random.nextInt(100000) + 100; return Long.valueOf(x); } - /** - * constructor. - */ + /** constructor. */ public String encodeTransferParamsToHexString(GrpcAPI.ShieldedTRC20Parameters parameters) { byte[] input = new byte[0]; byte[] spendAuthSig = new byte[0]; @@ -1008,15 +1106,16 @@ public String encodeTransferParamsToHexString(GrpcAPI.ShieldedTRC20Parameters pa final byte[] mergedBytes; List spendDescs = parameters.getSpendDescriptionList(); for (ShieldContract.SpendDescription spendDesc : spendDescs) { - input = ByteUtil.merge(input, - spendDesc.getNullifier().toByteArray(), - spendDesc.getAnchor().toByteArray(), - spendDesc.getValueCommitment().toByteArray(), - spendDesc.getRk().toByteArray(), - spendDesc.getZkproof().toByteArray() - ); - spendAuthSig = ByteUtil.merge( - spendAuthSig, spendDesc.getSpendAuthoritySignature().toByteArray()); + input = + ByteUtil.merge( + input, + spendDesc.getNullifier().toByteArray(), + spendDesc.getAnchor().toByteArray(), + spendDesc.getValueCommitment().toByteArray(), + spendDesc.getRk().toByteArray(), + spendDesc.getZkproof().toByteArray()); + spendAuthSig = + ByteUtil.merge(spendAuthSig, spendDesc.getSpendAuthoritySignature().toByteArray()); } byte[] inputOffsetbytes = longTo32Bytes(192); long spendCount = spendDescs.size(); @@ -1024,80 +1123,73 @@ public String encodeTransferParamsToHexString(GrpcAPI.ShieldedTRC20Parameters pa byte[] authOffsetBytes = longTo32Bytes(192 + 32 + 320 * spendCount); List recvDescs = parameters.getReceiveDescriptionList(); for (ShieldContract.ReceiveDescription recvDesc : recvDescs) { - output = ByteUtil.merge(output, - recvDesc.getNoteCommitment().toByteArray(), - recvDesc.getValueCommitment().toByteArray(), - recvDesc.getEpk().toByteArray(), - recvDesc.getZkproof().toByteArray() - ); - c = ByteUtil.merge(c, - recvDesc.getCEnc().toByteArray(), - recvDesc.getCOut().toByteArray(), - new byte[12] - ); + output = + ByteUtil.merge( + output, + recvDesc.getNoteCommitment().toByteArray(), + recvDesc.getValueCommitment().toByteArray(), + recvDesc.getEpk().toByteArray(), + recvDesc.getZkproof().toByteArray()); + c = + ByteUtil.merge( + c, recvDesc.getCEnc().toByteArray(), recvDesc.getCOut().toByteArray(), new byte[12]); } long recvCount = recvDescs.size(); byte[] recvCountBytes = longTo32Bytes(recvCount); byte[] outputOffsetbytes = longTo32Bytes(192 + 32 + 320 * spendCount + 32 + 64 * spendCount); - byte[] coffsetBytes = longTo32Bytes(192 + 32 + 320 * spendCount + 32 + 64 * spendCount + 32 - + 288 * recvCount); + byte[] coffsetBytes = + longTo32Bytes(192 + 32 + 320 * spendCount + 32 + 64 * spendCount + 32 + 288 * recvCount); bindingSig = parameters.getBindingSignature().toByteArray(); - mergedBytes = ByteUtil.merge(inputOffsetbytes, - authOffsetBytes, - outputOffsetbytes, - bindingSig, - coffsetBytes, - spendCountBytes, - input, - spendCountBytes, - spendAuthSig, - recvCountBytes, - output, - recvCountBytes, - c - ); + mergedBytes = + ByteUtil.merge( + inputOffsetbytes, + authOffsetBytes, + outputOffsetbytes, + bindingSig, + coffsetBytes, + spendCountBytes, + input, + spendCountBytes, + spendAuthSig, + recvCountBytes, + output, + recvCountBytes, + c); return ByteArray.toHexString(mergedBytes); } - /** - * constructor. - */ - public String encodeBurnParamsToHexString(GrpcAPI.ShieldedTRC20Parameters parameters, - BigInteger value, - String transparentToAddress) { + /** constructor. */ + public String encodeBurnParamsToHexString( + GrpcAPI.ShieldedTRC20Parameters parameters, BigInteger value, String transparentToAddress) { byte[] mergedBytes; byte[] payTo = new byte[32]; byte[] transparentToAddressBytes = WalletClient.decodeFromBase58Check(transparentToAddress); System.arraycopy(transparentToAddressBytes, 0, payTo, 11, 21); ShieldContract.SpendDescription spendDesc = parameters.getSpendDescription(0); - mergedBytes = ByteUtil.merge( - spendDesc.getNullifier().toByteArray(), - spendDesc.getAnchor().toByteArray(), - spendDesc.getValueCommitment().toByteArray(), - spendDesc.getRk().toByteArray(), - spendDesc.getZkproof().toByteArray(), - spendDesc.getSpendAuthoritySignature().toByteArray(), - ByteUtil.bigIntegerToBytes(value, 32), - parameters.getBindingSignature().toByteArray(), - payTo - ); + mergedBytes = + ByteUtil.merge( + spendDesc.getNullifier().toByteArray(), + spendDesc.getAnchor().toByteArray(), + spendDesc.getValueCommitment().toByteArray(), + spendDesc.getRk().toByteArray(), + spendDesc.getZkproof().toByteArray(), + spendDesc.getSpendAuthoritySignature().toByteArray(), + ByteUtil.bigIntegerToBytes(value, 32), + parameters.getBindingSignature().toByteArray(), + payTo); return ByteArray.toHexString(mergedBytes); } - /** - * constructor. - */ + /** constructor. */ public byte[] longTo32Bytes(long value) { byte[] longBytes = ByteArray.fromLong(value); byte[] zeroBytes = new byte[24]; return ByteUtil.merge(zeroBytes, longBytes); } - /** - * constructor. - */ - public JSONArray getHttpShieldedReceivesJsonArray(JSONArray shieldReceives, Long value, - String paymentAddress, String rcm) { + /** constructor. */ + public JSONArray getHttpShieldedReceivesJsonArray( + JSONArray shieldReceives, Long value, String paymentAddress, String rcm) { JSONObject note = new JSONObject(); note.put("value", value); note.put("payment_address", paymentAddress); @@ -1106,14 +1198,11 @@ public JSONArray getHttpShieldedReceivesJsonArray(JSONArray shieldReceives, Long noteIndex.put("note", note); shieldReceives.add(noteIndex); return shieldReceives; - } - /** - * constructor. - */ - public static HttpResponse createShieldContractParameters(String httpNode, Long fromAmount, - JSONObject shieldAccountInfo, JSONArray shiledReceives) { + /** constructor. */ + public static HttpResponse createShieldContractParameters( + String httpNode, Long fromAmount, JSONObject shieldAccountInfo, JSONArray shiledReceives) { try { final String requestUrl = "http://" + httpNode + "/wallet/createshieldedcontractparameters"; @@ -1134,21 +1223,24 @@ public static HttpResponse createShieldContractParameters(String httpNode, Long return response; } - /** - * constructor. - */ - public static HttpResponse createShieldContractParametersForBurn(String httpNode, - JSONObject shieldAccountInfo, JSONArray shieldedSpends, String toAddress, Long toAmount) { - return createShieldContractParametersForBurn(httpNode, shieldAccountInfo, shieldedSpends, - toAddress, toAmount, null); - + /** constructor. */ + public static HttpResponse createShieldContractParametersForBurn( + String httpNode, + JSONObject shieldAccountInfo, + JSONArray shieldedSpends, + String toAddress, + Long toAmount) { + return createShieldContractParametersForBurn( + httpNode, shieldAccountInfo, shieldedSpends, toAddress, toAmount, null); } - /** - * constructor. - */ - public static HttpResponse createShieldContractParametersForBurn(String httpNode, - JSONObject shieldAccountInfo, JSONArray shieldedSpends, String toAddress, Long toAmount, + /** constructor. */ + public static HttpResponse createShieldContractParametersForBurn( + String httpNode, + JSONObject shieldAccountInfo, + JSONArray shieldedSpends, + String toAddress, + Long toAmount, JSONArray shieldedReceiver) { try { final String requestUrl = "http://" + httpNode + "/wallet/createshieldedcontractparameters"; @@ -1175,24 +1267,28 @@ public static HttpResponse createShieldContractParametersForBurn(String httpNode return response; } - /** - * constructor. - */ - public static HttpResponse createShieldContractParametersWithoutAskForBurn(String httpNode, - JSONObject shieldAccountInfo, JSONArray shieldedSpends, String toAddress, Long toAmount) { - return createShieldContractParametersWithoutAskForBurn(httpNode, shieldAccountInfo, - shieldedSpends, toAddress, toAmount, null); + /** constructor. */ + public static HttpResponse createShieldContractParametersWithoutAskForBurn( + String httpNode, + JSONObject shieldAccountInfo, + JSONArray shieldedSpends, + String toAddress, + Long toAmount) { + return createShieldContractParametersWithoutAskForBurn( + httpNode, shieldAccountInfo, shieldedSpends, toAddress, toAmount, null); } - /** - * constructor. - */ - public static HttpResponse createShieldContractParametersWithoutAskForBurn(String httpNode, - JSONObject shieldAccountInfo, JSONArray shieldedSpends, String toAddress, Long toAmount, + /** constructor. */ + public static HttpResponse createShieldContractParametersWithoutAskForBurn( + String httpNode, + JSONObject shieldAccountInfo, + JSONArray shieldedSpends, + String toAddress, + Long toAmount, JSONArray shieldedReceiver) { try { - final String requestUrl - = "http://" + httpNode + "/wallet/createshieldedcontractparameterswithoutask"; + final String requestUrl = + "http://" + httpNode + "/wallet/createshieldedcontractparameterswithoutask"; JSONObject rawBody = new JSONObject(); rawBody.put("ovk", shieldAccountInfo.getString("ovk")); @@ -1217,11 +1313,12 @@ public static HttpResponse createShieldContractParametersWithoutAskForBurn(Strin return response; } - /** - * constructor. - */ - public static HttpResponse createShieldContractParametersForTransfer(String httpNode, - JSONObject shieldAccountInfo, JSONArray shieldedSpends, JSONArray shieldedReceives) { + /** constructor. */ + public static HttpResponse createShieldContractParametersForTransfer( + String httpNode, + JSONObject shieldAccountInfo, + JSONArray shieldedSpends, + JSONArray shieldedReceives) { try { final String requestUrl = "http://" + httpNode + "/wallet/createshieldedcontractparameters"; JSONObject rawBody = new JSONObject(); @@ -1242,14 +1339,15 @@ public static HttpResponse createShieldContractParametersForTransfer(String http return response; } - /** - * constructor. - */ - public static HttpResponse createShieldContractParametersWithoutAskForTransfer(String httpNode, - JSONObject shieldAccountInfo, JSONArray shieldedSpends, JSONArray shieldedReceives) { + /** constructor. */ + public static HttpResponse createShieldContractParametersWithoutAskForTransfer( + String httpNode, + JSONObject shieldAccountInfo, + JSONArray shieldedSpends, + JSONArray shieldedReceives) { try { - final String requestUrl = "http://" + httpNode - + "/wallet/createshieldedcontractparameterswithoutask"; + final String requestUrl = + "http://" + httpNode + "/wallet/createshieldedcontractparameterswithoutask"; JSONObject rawBody = new JSONObject(); rawBody.put("ovk", shieldAccountInfo.getString("ovk")); rawBody.put("ak", shieldAccountInfo.getString("ak")); @@ -1268,11 +1366,9 @@ public static HttpResponse createShieldContractParametersWithoutAskForTransfer(S return response; } - /** - * constructor. - */ - public static JSONObject createSpendAuthSig(String httpNode, - JSONObject shieldAccountInfo, String messageHash, String alpha) { + /** constructor. */ + public static JSONObject createSpendAuthSig( + String httpNode, JSONObject shieldAccountInfo, String messageHash, String alpha) { try { final String requestUrl = "http://" + httpNode + "/wallet/createspendauthsig"; JSONObject rawBody = new JSONObject(); @@ -1289,11 +1385,8 @@ public static JSONObject createSpendAuthSig(String httpNode, return HttpMethod.parseResponseContent(response); } - /** - * constructor. - */ - public static JSONArray scanShieldTrc20NoteByIvk(String httpNode, - JSONObject shieldAddressInfo) { + /** constructor. */ + public static JSONArray scanShieldTrc20NoteByIvk(String httpNode, JSONObject shieldAddressInfo) { try { Long endScanNumber = HttpMethod.getNowBlockNum(httpNode); Long startScanNumer = endScanNumber > 99 ? endScanNumber - 90 : 1; @@ -1322,11 +1415,9 @@ public static JSONArray scanShieldTrc20NoteByIvk(String httpNode, } } - /** - * constructor. - */ - public static JSONArray scanShieldTrc20NoteByIvkOnSolidity(String httpNode, - JSONObject shieldAddressInfo) { + /** constructor. */ + public static JSONArray scanShieldTrc20NoteByIvkOnSolidity( + String httpNode, JSONObject shieldAddressInfo) { try { Long endScanNumber = HttpMethod.getNowBlockNumOnSolidity(httpNode); Long startScanNumer = endScanNumber > 99 ? endScanNumber - 90 : 1; @@ -1356,20 +1447,21 @@ public static JSONArray scanShieldTrc20NoteByIvkOnSolidity(String httpNode, } } - /** - * constructor. - */ - public static JSONArray scanShieldTrc20NoteByIvkOnPbft(String httpPbftNode, - JSONObject shieldAddressInfo) { + /** constructor. */ + public static JSONArray scanShieldTrc20NoteByIvkOnPbft( + String httpPbftNode, JSONObject shieldAddressInfo) { try { response = HttpMethod.getNowBlockFromPbft(httpPbftNode); - Long endScanNumber = HttpMethod.parseResponseContent(response).getJSONObject("block_header") - .getJSONObject("raw_data").getLong("number"); + Long endScanNumber = + HttpMethod.parseResponseContent(response) + .getJSONObject("block_header") + .getJSONObject("raw_data") + .getLong("number"); Long startScanNumer = endScanNumber > 99 ? endScanNumber - 90 : 1; final String requestUrl = - "http://" + httpPbftNode + "/walletpbft/scanshieldedtrc20notesbyivk"; + "http://" + httpPbftNode + "/walletpbft/scanshieldedtrc20notesbyivk"; JsonObject userBaseObj2 = new JsonObject(); userBaseObj2.addProperty("start_block_index", startScanNumer); userBaseObj2.addProperty("end_block_index", endScanNumber); @@ -1393,11 +1485,8 @@ public static JSONArray scanShieldTrc20NoteByIvkOnPbft(String httpPbftNode, } } - /** - * constructor. - */ - public static JSONArray scanShieldTrc20NoteByOvk(String httpNode, - JSONObject shieldAddressInfo) { + /** constructor. */ + public static JSONArray scanShieldTrc20NoteByOvk(String httpNode, JSONObject shieldAddressInfo) { try { Long endScanNumber = HttpMethod.getNowBlockNum(httpNode); Long startScanNumer = endScanNumber > 99 ? endScanNumber - 90 : 1; @@ -1424,11 +1513,9 @@ public static JSONArray scanShieldTrc20NoteByOvk(String httpNode, } } - /** - * constructor. - */ - public static JSONArray scanShieldTrc20NoteByOvkOnSolidity(String httpNode, - JSONObject shieldAddressInfo) { + /** constructor. */ + public static JSONArray scanShieldTrc20NoteByOvkOnSolidity( + String httpNode, JSONObject shieldAddressInfo) { try { Long endScanNumber = HttpMethod.getNowBlockNumOnSolidity(httpNode); Long startScanNumer = endScanNumber > 99 ? endScanNumber - 90 : 1; @@ -1456,19 +1543,20 @@ public static JSONArray scanShieldTrc20NoteByOvkOnSolidity(String httpNode, } } - /** - * constructor. - */ - public static JSONArray scanShieldTrc20NoteByOvkOnPbft(String httpPbftNode, - JSONObject shieldAddressInfo) { + /** constructor. */ + public static JSONArray scanShieldTrc20NoteByOvkOnPbft( + String httpPbftNode, JSONObject shieldAddressInfo) { try { response = HttpMethod.getNowBlockFromPbft(httpPbftNode); - Long endScanNumber = HttpMethod.parseResponseContent(response).getJSONObject("block_header") - .getJSONObject("raw_data").getLong("number"); + Long endScanNumber = + HttpMethod.parseResponseContent(response) + .getJSONObject("block_header") + .getJSONObject("raw_data") + .getLong("number"); Long startScanNumer = endScanNumber > 99 ? endScanNumber - 90 : 1; final String requestUrl = - "http://" + httpPbftNode + "/walletpbft/scanshieldedtrc20notesbyovk"; + "http://" + httpPbftNode + "/walletpbft/scanshieldedtrc20notesbyovk"; JsonObject userBaseObj2 = new JsonObject(); userBaseObj2.addProperty("start_block_index", startScanNumer); userBaseObj2.addProperty("end_block_index", endScanNumber); @@ -1490,9 +1578,7 @@ public static JSONArray scanShieldTrc20NoteByOvkOnPbft(String httpPbftNode, } } - /** - * constructor. - */ + /** constructor. */ public static String getRootAndPathByHttp(String httpNode, Integer position) { try { final String requestUrl = "http://" + httpNode + "/wallet/triggerconstantcontract"; @@ -1517,11 +1603,9 @@ public static String getRootAndPathByHttp(String httpNode, Integer position) { return HttpMethod.parseResponseContent(response).getJSONArray("constant_result").getString(0); } - /** - * constructor. - */ - public static JSONArray createAndSetShieldedSpends(String httpNode, - JSONArray shieldedSpends, JSONObject noteTxs) { + /** constructor. */ + public static JSONArray createAndSetShieldedSpends( + String httpNode, JSONArray shieldedSpends, JSONObject noteTxs) { JSONObject shieldedSpend = new JSONObject(); shieldedSpend.put("note", noteTxs.getJSONObject("note")); shieldedSpend.put("alpha", noteTxs.getJSONObject("note").getString("rcm")); @@ -1536,9 +1620,7 @@ public static JSONArray createAndSetShieldedSpends(String httpNode, return shieldedSpends; } - /** - * constructor. - */ + /** constructor. */ public static String getRcm(String httpNode) { try { String requestUrl = "http://" + httpNode + "/wallet/getrcm"; @@ -1551,19 +1633,17 @@ public static String getRcm(String httpNode) { return HttpMethod.parseResponseContent(response).getString("value"); } - /** - * constructor. - */ - public static Boolean isShieldedTrc20ContractNoteSpent(String httpNode, - JSONObject accountInfo, JSONObject noteTxs) { + /** constructor. */ + public static Boolean isShieldedTrc20ContractNoteSpent( + String httpNode, JSONObject accountInfo, JSONObject noteTxs) { try { final String requestUrl = "http://" + httpNode + "/wallet/isshieldedtrc20contractnotespent"; JSONObject userBaseObj2 = new JSONObject(); userBaseObj2.put("note", noteTxs.getJSONObject("note")); userBaseObj2.put("ak", accountInfo.getString("ak")); userBaseObj2.put("nk", accountInfo.getString("nk")); - userBaseObj2.put("position", noteTxs.containsKey("position") - ? noteTxs.getInteger("position") : 0); + userBaseObj2.put( + "position", noteTxs.containsKey("position") ? noteTxs.getInteger("position") : 0); userBaseObj2.put("visible", true); userBaseObj2.put("shielded_TRC20_contract_address", shieldAddress); logger.info(userBaseObj2.toString()); @@ -1575,24 +1655,21 @@ public static Boolean isShieldedTrc20ContractNoteSpent(String httpNode, } responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - return responseContent.containsKey("is_spent") - ? responseContent.getBoolean("is_spent") : false; + return responseContent.containsKey("is_spent") ? responseContent.getBoolean("is_spent") : false; } - /** - * constructor. - */ - public static Boolean isShieldedTrc20ContractNoteSpentOnSolidity(String httpNode, - JSONObject accountInfo, JSONObject noteTxs) { + /** constructor. */ + public static Boolean isShieldedTrc20ContractNoteSpentOnSolidity( + String httpNode, JSONObject accountInfo, JSONObject noteTxs) { try { - final String requestUrl - = "http://" + httpNode + "/walletsolidity/isshieldedtrc20contractnotespent"; + final String requestUrl = + "http://" + httpNode + "/walletsolidity/isshieldedtrc20contractnotespent"; JSONObject userBaseObj2 = new JSONObject(); userBaseObj2.put("note", noteTxs.getJSONObject("note")); userBaseObj2.put("ak", accountInfo.getString("ak")); userBaseObj2.put("nk", accountInfo.getString("nk")); - userBaseObj2.put("position", noteTxs.containsKey("position") - ? noteTxs.getInteger("position") : 0); + userBaseObj2.put( + "position", noteTxs.containsKey("position") ? noteTxs.getInteger("position") : 0); userBaseObj2.put("visible", true); userBaseObj2.put("shielded_TRC20_contract_address", shieldAddress); logger.info(userBaseObj2.toString()); @@ -1607,20 +1684,18 @@ public static Boolean isShieldedTrc20ContractNoteSpentOnSolidity(String httpNode return responseContent.containsKey("is_spent") ? responseContent.getBoolean("is_spent") : false; } - /** - * constructor. - */ - public static Boolean isShieldedTrc20ContractNoteSpentOnPbft(String httpPbftNode, - JSONObject accountInfo, JSONObject noteTxs) { + /** constructor. */ + public static Boolean isShieldedTrc20ContractNoteSpentOnPbft( + String httpPbftNode, JSONObject accountInfo, JSONObject noteTxs) { try { - final String requestUrl - = "http://" + httpPbftNode + "/walletpbft/isshieldedtrc20contractnotespent"; + final String requestUrl = + "http://" + httpPbftNode + "/walletpbft/isshieldedtrc20contractnotespent"; JSONObject userBaseObj2 = new JSONObject(); userBaseObj2.put("note", noteTxs.getJSONObject("note")); userBaseObj2.put("ak", accountInfo.getString("ak")); userBaseObj2.put("nk", accountInfo.getString("nk")); - userBaseObj2.put("position", noteTxs.containsKey("position") - ? noteTxs.getInteger("position") : 0); + userBaseObj2.put( + "position", noteTxs.containsKey("position") ? noteTxs.getInteger("position") : 0); userBaseObj2.put("visible", true); userBaseObj2.put("shielded_TRC20_contract_address", shieldAddress); logger.info(userBaseObj2.toString()); @@ -1635,14 +1710,12 @@ public static Boolean isShieldedTrc20ContractNoteSpentOnPbft(String httpPbftNode return responseContent.containsKey("is_spent") ? responseContent.getBoolean("is_spent") : false; } - /** - * constructor. - */ - public static HttpResponse getTriggerInputForShieldedTrc20Contract(String httpNode, - JSONObject shieldedTrc20Parameters, JSONArray spendAuthoritySignature) { + /** constructor. */ + public static HttpResponse getTriggerInputForShieldedTrc20Contract( + String httpNode, JSONObject shieldedTrc20Parameters, JSONArray spendAuthoritySignature) { try { - final String requestUrl = "http://" + httpNode - + "/wallet/gettriggerinputforshieldedtrc20contract"; + final String requestUrl = + "http://" + httpNode + "/wallet/gettriggerinputforshieldedtrc20contract"; JSONObject userBaseObj2 = new JSONObject(); userBaseObj2.put("shielded_TRC20_Parameters", shieldedTrc20Parameters); userBaseObj2.put("spend_authority_signature", spendAuthoritySignature); @@ -1657,15 +1730,16 @@ public static HttpResponse getTriggerInputForShieldedTrc20Contract(String httpNo return response; } - /** - * constructor. - */ - public static HttpResponse getTriggerInputForShieldedTrc20BurnContract(String httpNode, - JSONObject shieldedTrc20Parameters, JSONArray spendAuthoritySignature, Long amount, + /** constructor. */ + public static HttpResponse getTriggerInputForShieldedTrc20BurnContract( + String httpNode, + JSONObject shieldedTrc20Parameters, + JSONArray spendAuthoritySignature, + Long amount, String toAddress) { try { - final String requestUrl = "http://" - + httpNode + "/wallet/gettriggerinputforshieldedtrc20contract"; + final String requestUrl = + "http://" + httpNode + "/wallet/gettriggerinputforshieldedtrc20contract"; JSONObject userBaseObj2 = new JSONObject(); userBaseObj2.put("shielded_TRC20_Parameters", shieldedTrc20Parameters); userBaseObj2.put("spend_authority_signature", spendAuthoritySignature); @@ -1682,5 +1756,4 @@ public static HttpResponse getTriggerInputForShieldedTrc20BurnContract(String ht } return response; } - } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ZenUtils.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ZenUtils.java index f14b9167..18b150c0 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/ZenUtils.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/ZenUtils.java @@ -110,7 +110,6 @@ public static String getMemo(byte[] memo) { return new String(inputCheck, Charset.forName("UTF-8")); } - public static byte[] aesCtrEncrypt(byte[] text, byte[] encryptKey) throws CipherException { try { byte[] iv = new byte[16]; @@ -125,9 +124,12 @@ public static byte[] aesCtrEncrypt(byte[] text, byte[] encryptKey) throws Cipher System.arraycopy(iv, 0, result, 0, iv.length); System.arraycopy(cipherText, 0, result, iv.length, cipherText.length); return result; - } catch (NoSuchPaddingException | NoSuchAlgorithmException - | InvalidAlgorithmParameterException | InvalidKeyException - | BadPaddingException | IllegalBlockSizeException e) { + } catch (NoSuchPaddingException + | NoSuchAlgorithmException + | InvalidAlgorithmParameterException + | InvalidKeyException + | BadPaddingException + | IllegalBlockSizeException e) { throw new CipherException("Error performing cipher operation", e); } } @@ -143,12 +145,13 @@ public static byte[] aesCtrDecrypt(byte[] cipherText, byte[] encryptKey) throws SecretKeySpec secretKeySpec = new SecretKeySpec(encryptKey, "AES"); cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec); return cipher.doFinal(cipherText); - } catch (NoSuchPaddingException | NoSuchAlgorithmException - | InvalidAlgorithmParameterException | InvalidKeyException - | BadPaddingException | IllegalBlockSizeException e) { + } catch (NoSuchPaddingException + | NoSuchAlgorithmException + | InvalidAlgorithmParameterException + | InvalidKeyException + | BadPaddingException + | IllegalBlockSizeException e) { throw new CipherException("Error performing cipher operation", e); } } - - } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/cryptohash/Digest.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/cryptohash/Digest.java index 365a18cc..678663b7 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/cryptohash/Digest.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/cryptohash/Digest.java @@ -19,25 +19,23 @@ package stest.tron.wallet.common.client.utils.cryptohash; /** - * Copyright (c) 2007-2010 Projet RNRT SAPHIR + * Copyright (c) 2007-2010 Projet RNRT SAPHIR * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and - * associated documentation files (the "Software"), to deal in the Software without restriction, + *

Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * - * The above copyright notice and this permission notice shall be included in all copies or + *

The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + *

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - - public interface Digest { /** @@ -115,22 +113,25 @@ public interface Digest { Digest copy(); /** - *

Return the "block length" for the hash function. This value is naturally defined for - * iterated hash functions (Merkle-Damgard). It is used in HMAC (that's what the HMAC specification names the "{@code B}" - * parameter).

If the function is "block-less" then this function may return {@code -n} - * where {@code n} is an integer such that the block length for HMAC ("{@code B}") will be - * inferred from the key length, by selecting the smallest multiple of {@code n} which is no - * smaller than the key length. For instance, for the Fugue-xxx hash functions, this function - * returns -4: the virtual block length B is the HMAC key length, rounded up to the next multiple - * of 4.

+ * parameter). + * + *

+ * + *

If the function is "block-less" then this function may return {@code -n} where {@code n} is + * an integer such that the block length for HMAC ("{@code B}") will be inferred from the key + * length, by selecting the smallest multiple of {@code n} which is no smaller than the key + * length. For instance, for the Fugue-xxx hash functions, this function returns -4: the virtual + * block length B is the HMAC key length, rounded up to the next multiple of 4. * * @return the internal block length (in bytes), or {@code -n} */ int getBlockLength(); /** - *

Get the display name for this function (e.g. {@code "SHA-1"} for SHA-1).

+ * Get the display name for this function (e.g. {@code "SHA-1"} for SHA-1). * * @see Object */ diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/cryptohash/DigestEngine.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/cryptohash/DigestEngine.java index c7f6dc29..64fab333 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/cryptohash/DigestEngine.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/cryptohash/DigestEngine.java @@ -22,13 +22,14 @@ public abstract class DigestEngine extends MessageDigest implements Digest { - private int digestLen, blockLen, inputLen; - private byte[] inputBuf, outputBuf; + private int digestLen; + private int blockLen; + private int inputLen; + private byte[] inputBuf; + private byte[] outputBuf; private long blockCount; - /** - * Instantiate the engine. - */ + /** Instantiate the engine. */ public DigestEngine(String alg) { super(alg); doInit(); @@ -40,9 +41,7 @@ public DigestEngine(String alg) { blockCount = 0; } - /** - * Reset the hash algorithm state. - */ + /** Reset the hash algorithm state. */ protected abstract void engineReset(); /** @@ -76,9 +75,7 @@ private void adjustDigestLen() { } } - /** - * @see Digest - */ + /** @see Digest */ public byte[] digest() { adjustDigestLen(); byte[] result = new byte[digestLen]; @@ -86,17 +83,13 @@ public byte[] digest() { return result; } - /** - * @see Digest - */ + /** @see Digest */ public byte[] digest(byte[] input) { update(input, 0, input.length); return digest(); } - /** - * @see Digest - */ + /** @see Digest */ public int digest(byte[] buf, int offset, int len) { adjustDigestLen(); if (len >= digestLen) { @@ -111,18 +104,14 @@ public int digest(byte[] buf, int offset, int len) { } } - /** - * @see Digest - */ + /** @see Digest */ public void reset() { engineReset(); inputLen = 0; blockCount = 0; } - /** - * @see Digest - */ + /** @see Digest */ public void update(byte input) { inputBuf[inputLen++] = input; if (inputLen == blockLen) { @@ -132,24 +121,19 @@ public void update(byte input) { } } - /** - * @see Digest - */ + /** @see Digest */ public void update(byte[] input) { update(input, 0, input.length); } - /** - * @see Digest - */ + /** @see Digest */ public void update(byte[] input, int offset, int len) { while (len > 0) { int copyLen = blockLen - inputLen; if (copyLen > len) { copyLen = len; } - System.arraycopy(input, offset, inputBuf, inputLen, - copyLen); + System.arraycopy(input, offset, inputBuf, inputLen, copyLen); offset += copyLen; inputLen += copyLen; len -= copyLen; @@ -218,12 +202,10 @@ protected long getBlockCount() { protected Digest copyState(DigestEngine dest) { dest.inputLen = inputLen; dest.blockCount = blockCount; - System.arraycopy(inputBuf, 0, dest.inputBuf, 0, - inputBuf.length); + System.arraycopy(inputBuf, 0, dest.inputBuf, 0, inputBuf.length); adjustDigestLen(); dest.adjustDigestLen(); - System.arraycopy(outputBuf, 0, dest.outputBuf, 0, - outputBuf.length); + System.arraycopy(outputBuf, 0, dest.outputBuf, 0, outputBuf.length); return dest; } } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/cryptohash/Keccak256.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/cryptohash/Keccak256.java index b47d7de9..bb4465c8 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/cryptohash/Keccak256.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/cryptohash/Keccak256.java @@ -20,9 +20,7 @@ public class Keccak256 extends KeccakCore { - /** - * Create the engine. - */ + /** Create the engine. */ public Keccak256() { super("tron-keccak-256"); } @@ -41,10 +39,8 @@ protected byte[] engineDigest() { } @Override - protected void engineUpdate(byte arg0) { - } + protected void engineUpdate(byte arg0) {} @Override - protected void engineUpdate(byte[] arg0, int arg1, int arg2) { - } + protected void engineUpdate(byte[] arg0, int arg1, int arg2) {} } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/cryptohash/Keccak512.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/cryptohash/Keccak512.java index 638b208a..07b85eef 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/cryptohash/Keccak512.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/cryptohash/Keccak512.java @@ -20,9 +20,7 @@ public class Keccak512 extends KeccakCore { - /** - * Create the engine. - */ + /** Create the engine. */ public Keccak512() { super("tron-keccak-512"); } @@ -41,10 +39,8 @@ protected byte[] engineDigest() { } @Override - protected void engineUpdate(byte input) { - } + protected void engineUpdate(byte input) {} @Override - protected void engineUpdate(byte[] input, int offset, int len) { - } + protected void engineUpdate(byte[] input, int offset, int len) {} } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/cryptohash/KeccakCore.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/cryptohash/KeccakCore.java index 47f6f535..88cf316e 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/cryptohash/KeccakCore.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/cryptohash/KeccakCore.java @@ -21,18 +21,18 @@ abstract class KeccakCore extends DigestEngine { private static final long[] RC = { - 0x0000000000000001L, 0x0000000000008082L, - 0x800000000000808AL, 0x8000000080008000L, - 0x000000000000808BL, 0x0000000080000001L, - 0x8000000080008081L, 0x8000000000008009L, - 0x000000000000008AL, 0x0000000000000088L, - 0x0000000080008009L, 0x000000008000000AL, - 0x000000008000808BL, 0x800000000000008BL, - 0x8000000000008089L, 0x8000000000008003L, - 0x8000000000008002L, 0x8000000000000080L, - 0x000000000000800AL, 0x800000008000000AL, - 0x8000000080008081L, 0x8000000000008080L, - 0x0000000080000001L, 0x8000000080008008L + 0x0000000000000001L, 0x0000000000008082L, + 0x800000000000808AL, 0x8000000080008000L, + 0x000000000000808BL, 0x0000000080000001L, + 0x8000000080008081L, 0x8000000000008009L, + 0x000000000000008AL, 0x0000000000000088L, + 0x0000000080008009L, 0x000000008000000AL, + 0x000000008000808BL, 0x800000000000008BL, + 0x8000000000008089L, 0x8000000000008003L, + 0x8000000000008002L, 0x8000000000000080L, + 0x000000000000800AL, 0x800000008000000AL, + 0x8000000080008081L, 0x8000000000008080L, + 0x0000000080000001L, 0x8000000080008008L }; private long[] A; private byte[] tmpOut; @@ -88,10 +88,24 @@ protected void processBlock(byte[] data) { A[i >>> 3] ^= decodeLELong(data, i); } - long t0, t1, t2, t3, t4; - long tt0, tt1, tt2, tt3, tt4; - long t, kt; - long c0, c1, c2, c3, c4, bnn; + long t0; + long t1; + long t2; + long t3; + long t4; + long tt0; + long tt1; + long tt2; + long tt3; + long tt4; + long t; + long kt; + long c0; + long c1; + long c2; + long c3; + long c4; + long bnn; /* * Unrolling four rounds kills performance big time diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/exception/CancelException.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/exception/CancelException.java index 3949b072..e0071b1a 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/exception/CancelException.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/exception/CancelException.java @@ -9,5 +9,4 @@ public CancelException() { public CancelException(String message) { super(message); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/exception/JsonRpcInvalidParamsException.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/exception/JsonRpcInvalidParamsException.java index 7339efe8..ccecad39 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/exception/JsonRpcInvalidParamsException.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/exception/JsonRpcInvalidParamsException.java @@ -13,4 +13,4 @@ public JsonRpcInvalidParamsException(String msg) { public JsonRpcInvalidParamsException(String message, Throwable cause) { super(message, cause); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/exception/TronException.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/exception/TronException.java index f9cbbfa2..13267d21 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/exception/TronException.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/exception/TronException.java @@ -13,5 +13,4 @@ public TronException(String message) { public TronException(String message, Throwable cause) { super(message, cause); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/jce/ECAlgorithmParameters.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/jce/ECAlgorithmParameters.java index 37f7453c..617fe2cf 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/jce/ECAlgorithmParameters.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/jce/ECAlgorithmParameters.java @@ -30,15 +30,13 @@ public final class ECAlgorithmParameters { public static final String ALGORITHM = "EC"; public static final String CURVE_NAME = "secp256k1"; - private ECAlgorithmParameters() { - } + private ECAlgorithmParameters() {} public static ECParameterSpec getParameterSpec() { try { return Holder.INSTANCE.getParameterSpec(ECParameterSpec.class); } catch (InvalidParameterSpecException ex) { - throw new AssertionError( - "Assumed correct key spec statically", ex); + throw new AssertionError("Assumed correct key spec statically", ex); } } @@ -46,8 +44,7 @@ public static byte[] getASN1Encoding() { try { return Holder.INSTANCE.getEncoded(); } catch (IOException ex) { - throw new AssertionError( - "Assumed algo params has been initialized", ex); + throw new AssertionError("Assumed algo params has been initialized", ex); } } @@ -55,19 +52,16 @@ private static class Holder { private static final AlgorithmParameters INSTANCE; - private static final ECGenParameterSpec SECP256K1_CURVE - = new ECGenParameterSpec(CURVE_NAME); + private static final ECGenParameterSpec SECP256K1_CURVE = new ECGenParameterSpec(CURVE_NAME); static { try { INSTANCE = AlgorithmParameters.getInstance(ALGORITHM); INSTANCE.init(SECP256K1_CURVE); } catch (NoSuchAlgorithmException ex) { - throw new AssertionError( - "Assumed the JRE supports EC algorithm params", ex); + throw new AssertionError("Assumed the JRE supports EC algorithm params", ex); } catch (InvalidParameterSpecException ex) { - throw new AssertionError( - "Assumed correct key spec statically", ex); + throw new AssertionError("Assumed correct key spec statically", ex); } } } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/jce/ECKeyAgreement.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/jce/ECKeyAgreement.java index b0ae54bd..78b142cc 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/jce/ECKeyAgreement.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/jce/ECKeyAgreement.java @@ -27,11 +27,9 @@ public final class ECKeyAgreement { public static final String ALGORITHM = "ECDH"; - private static final String algorithmAssertionMsg = - "Assumed the JRE supports EC key agreement"; + private static final String algorithmAssertionMsg = "Assumed the JRE supports EC key agreement"; - private ECKeyAgreement() { - } + private ECKeyAgreement() {} public static KeyAgreement getInstance() { try { @@ -41,8 +39,7 @@ public static KeyAgreement getInstance() { } } - public static KeyAgreement getInstance(final String provider) throws - NoSuchProviderException { + public static KeyAgreement getInstance(final String provider) throws NoSuchProviderException { try { return KeyAgreement.getInstance(ALGORITHM, provider); } catch (NoSuchAlgorithmException ex) { diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/jce/ECKeyFactory.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/jce/ECKeyFactory.java index 9ca8eaf4..cec9c8d8 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/jce/ECKeyFactory.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/jce/ECKeyFactory.java @@ -27,18 +27,15 @@ public final class ECKeyFactory { public static final String ALGORITHM = "EC"; - private static final String algorithmAssertionMsg = - "Assumed the JRE supports EC key factories"; + private static final String algorithmAssertionMsg = "Assumed the JRE supports EC key factories"; - private ECKeyFactory() { - } + private ECKeyFactory() {} public static KeyFactory getInstance() { return Holder.INSTANCE; } - public static KeyFactory getInstance(final String provider) throws - NoSuchProviderException { + public static KeyFactory getInstance(final String provider) throws NoSuchProviderException { try { return KeyFactory.getInstance(ALGORITHM, provider); } catch (NoSuchAlgorithmException ex) { diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/jce/ECKeyPairGenerator.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/jce/ECKeyPairGenerator.java index 39025cbe..889030ce 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/jce/ECKeyPairGenerator.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/jce/ECKeyPairGenerator.java @@ -32,27 +32,22 @@ public final class ECKeyPairGenerator { public static final String ALGORITHM = "EC"; public static final String CURVE_NAME = "secp256k1"; - private static final String algorithmAssertionMsg = - "Assumed JRE supports EC key pair generation"; + private static final String algorithmAssertionMsg = "Assumed JRE supports EC key pair generation"; - private static final String keySpecAssertionMsg = - "Assumed correct key spec statically"; + private static final String keySpecAssertionMsg = "Assumed correct key spec statically"; - private static final ECGenParameterSpec SECP256K1_CURVE - = new ECGenParameterSpec(CURVE_NAME); + private static final ECGenParameterSpec SECP256K1_CURVE = new ECGenParameterSpec(CURVE_NAME); - private ECKeyPairGenerator() { - } + private ECKeyPairGenerator() {} public static KeyPair generateKeyPair() { return Holder.INSTANCE.generateKeyPair(); } - public static KeyPairGenerator getInstance(final String provider, final - SecureRandom random) throws NoSuchProviderException { + public static KeyPairGenerator getInstance(final String provider, final SecureRandom random) + throws NoSuchProviderException { try { - final KeyPairGenerator gen = KeyPairGenerator.getInstance - (ALGORITHM, provider); + final KeyPairGenerator gen = KeyPairGenerator.getInstance(ALGORITHM, provider); gen.initialize(SECP256K1_CURVE, random); return gen; } catch (NoSuchAlgorithmException ex) { @@ -62,11 +57,9 @@ public static KeyPairGenerator getInstance(final String provider, final } } - public static KeyPairGenerator getInstance(final Provider provider, final - SecureRandom random) { + public static KeyPairGenerator getInstance(final Provider provider, final SecureRandom random) { try { - final KeyPairGenerator gen = KeyPairGenerator.getInstance - (ALGORITHM, provider); + final KeyPairGenerator gen = KeyPairGenerator.getInstance(ALGORITHM, provider); gen.initialize(SECP256K1_CURVE, random); return gen; } catch (NoSuchAlgorithmException ex) { diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/jce/ECSignatureFactory.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/jce/ECSignatureFactory.java index 6bf02e08..bbc27902 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/jce/ECSignatureFactory.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/jce/ECSignatureFactory.java @@ -30,8 +30,7 @@ public final class ECSignatureFactory { private static final String rawAlgorithmAssertionMsg = "Assumed the JRE supports NONEwithECDSA signatures"; - private ECSignatureFactory() { - } + private ECSignatureFactory() {} public static Signature getRawInstance() { try { @@ -41,8 +40,7 @@ public static Signature getRawInstance() { } } - public static Signature getRawInstance(final String provider) throws - NoSuchProviderException { + public static Signature getRawInstance(final String provider) throws NoSuchProviderException { try { return Signature.getInstance(RAW_ALGORITHM, provider); } catch (NoSuchAlgorithmException ex) { diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/services/Util.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/services/Util.java index 78a08fbf..52c97555 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/services/Util.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/services/Util.java @@ -1,6 +1,5 @@ package stest.tron.wallet.common.client.utils.services; - import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.google.protobuf.ByteString; @@ -24,7 +23,6 @@ import stest.tron.wallet.common.client.utils.JsonFormat; import stest.tron.wallet.common.client.utils.Sha256Hash; - @Slf4j(topic = "API") public class Util { @@ -49,7 +47,7 @@ public static String printErrorMsg(Exception e) { return jsonObject.toJSONString(); } -/* public static String printBlockList(BlockList list, boolean selfType) { + /* public static String printBlockList(BlockList list, boolean selfType) { List blocks = list.getBlockList(); JSONObject jsonObject = JSONObject.parseObject(JsonFormat.printToString(list, selfType)); JSONArray jsonArray = new JSONArray(); @@ -59,11 +57,11 @@ public static String printErrorMsg(Exception e) { return jsonObject.toJSONString(); }*/ -/* public static String printBlock(Block block, boolean selfType) { + /* public static String printBlock(Block block, boolean selfType) { return printBlockToJSON(block, selfType).toJSONString(); }*/ -/* public static JSONObject printBlockToJSON(Block block, boolean selfType) { + /* public static JSONObject printBlockToJSON(Block block, boolean selfType) { BlockCapsule blockCapsule = new BlockCapsule(block); String blockID = ByteArray.toHexString(blockCapsule.getBlockId().getBytes()); @@ -76,21 +74,18 @@ public static String printErrorMsg(Exception e) { return jsonObject; }*/ - public static String printTransactionIdList(TransactionIdList list, boolean selfType) { JSONObject jsonObject = JSONObject.parseObject(JsonFormat.printToString(list, selfType)); return jsonObject.toJSONString(); } - - - public static byte[] generateContractAddress(Transaction trx, byte[] ownerAddress) { // get tx hash - byte[] txRawDataHash = Sha256Hash - .of(CommonParameter.getInstance().isECKeyCryptoEngine(), trx.getRawData().toByteArray()) - .getBytes(); + byte[] txRawDataHash = + Sha256Hash.of( + CommonParameter.getInstance().isECKeyCryptoEngine(), trx.getRawData().toByteArray()) + .getBytes(); // combine byte[] combined = new byte[txRawDataHash.length + ownerAddress.length]; @@ -100,9 +95,6 @@ public static byte[] generateContractAddress(Transaction trx, byte[] ownerAddres return Hash.sha3omit12(combined); } - - - public static boolean getVisible(final HttpServletRequest request) { boolean visible = false; if (StringUtil.isNotBlank(request.getParameter(VISIBLE))) { @@ -145,8 +137,8 @@ public static String getHexString(final String string) { return ByteArray.toHexString(ByteString.copyFromUtf8(string).toByteArray()); } - public static Transaction setTransactionPermissionId(JSONObject jsonObject, - Transaction transaction) { + public static Transaction setTransactionPermissionId( + JSONObject jsonObject, Transaction transaction) { if (jsonObject.containsKey(PERMISSION_ID)) { int permissionId = jsonObject.getInteger(PERMISSION_ID); return setTransactionPermissionId(permissionId, transaction); @@ -158,8 +150,8 @@ public static Transaction setTransactionPermissionId(JSONObject jsonObject, public static Transaction setTransactionPermissionId(int permissionId, Transaction transaction) { if (permissionId > 0) { Transaction.raw.Builder raw = transaction.getRawData().toBuilder(); - Transaction.Contract.Builder contract = raw.getContract(0).toBuilder() - .setPermissionId(permissionId); + Transaction.Contract.Builder contract = + raw.getContract(0).toBuilder().setPermissionId(permissionId); raw.clearContract(); raw.addContract(contract); return transaction.toBuilder().setRawData(raw).build(); @@ -168,8 +160,8 @@ public static Transaction setTransactionPermissionId(int permissionId, Transacti return transaction; } - public static Transaction setTransactionExtraData(JSONObject jsonObject, - Transaction transaction, boolean visible) { + public static Transaction setTransactionExtraData( + JSONObject jsonObject, Transaction transaction, boolean visible) { if (jsonObject.containsKey(EXTRA_DATA)) { String data = jsonObject.getString(EXTRA_DATA); return setTransactionExtraData(data, transaction, visible); @@ -178,8 +170,8 @@ public static Transaction setTransactionExtraData(JSONObject jsonObject, return transaction; } - public static Transaction setTransactionExtraData(String data, Transaction transaction, - boolean visible) { + public static Transaction setTransactionExtraData( + String data, Transaction transaction, boolean visible) { if (data.length() > 0) { Transaction.raw.Builder raw = transaction.getRawData().toBuilder(); if (visible) { @@ -206,7 +198,7 @@ public static boolean getVisibleOnlyForSign(JSONObject jsonObject) { public static String parseMethod(String methodSign, String input) { byte[] selector = new byte[4]; System.arraycopy(Hash.sha3(methodSign.getBytes()), 0, selector, 0, 4); - //System.out.println(methodSign + ":" + Hex.toHexString(selector)); + // System.out.println(methodSign + ":" + Hex.toHexString(selector)); if (StringUtils.isEmpty(input)) { return Hex.toHexString(selector); } @@ -254,8 +246,8 @@ public static String convertOutput(Account account) { } else { JSONObject accountJson = JSONObject.parseObject(JsonFormat.printToString(account, false)); String assetId = accountJson.get("asset_issued_ID").toString(); - accountJson.put("asset_issued_ID", - ByteString.copyFrom(ByteArray.fromHexString(assetId)).toStringUtf8()); + accountJson.put( + "asset_issued_ID", ByteString.copyFrom(ByteArray.fromHexString(assetId)).toStringUtf8()); return accountJson.toJSONString(); } } @@ -272,7 +264,4 @@ public static void printAccount(Account reply, HttpServletResponse response, Boo response.getWriter().println("{}"); } } - - - } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/ShieldedTRC20ParametersBuilder.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/ShieldedTRC20ParametersBuilder.java index 61e60f9d..7285fe7e 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/ShieldedTRC20ParametersBuilder.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/ShieldedTRC20ParametersBuilder.java @@ -33,38 +33,24 @@ import stest.tron.wallet.common.client.utils.zen.note.NoteEncryption; import stest.tron.wallet.common.client.utils.zen.note.OutgoingPlaintext; - @Slf4j public class ShieldedTRC20ParametersBuilder { private static final int MERKLE_TREE_PATH_LENGTH = 1024; // 32*32 private static final String MERKLE_TREE_PATH_LENGTH_ERROR = "Merkle tree path format is wrong"; - @Setter - private List spends = new ArrayList<>(); - @Setter - private List receives = new ArrayList<>(); - @Getter - private ShieldedTRC20Parameters.Builder builder = ShieldedTRC20Parameters.newBuilder(); - @Getter - private long valueBalance = 0; - @Getter - @Setter - private ShieldedTRC20ParametersType shieldedTRC20ParametersType; - @Setter - private byte[] shieldedTRC20Address; - @Setter - private BigInteger transparentFromAmount; - @Setter - private byte[] transparentToAddress; - @Setter - private BigInteger transparentToAmount; - @Setter - private byte[] burnCiphertext = new byte[80]; - - public ShieldedTRC20ParametersBuilder() { + @Setter private List spends = new ArrayList<>(); + @Setter private List receives = new ArrayList<>(); + @Getter private ShieldedTRC20Parameters.Builder builder = ShieldedTRC20Parameters.newBuilder(); + @Getter private long valueBalance = 0; + @Getter @Setter private ShieldedTRC20ParametersType shieldedTRC20ParametersType; + @Setter private byte[] shieldedTRC20Address; + @Setter private BigInteger transparentFromAmount; + @Setter private byte[] transparentToAddress; + @Setter private BigInteger transparentToAmount; + @Setter private byte[] burnCiphertext = new byte[80]; - } + public ShieldedTRC20ParametersBuilder() {} public ShieldedTRC20ParametersBuilder(String type) throws ZksnarkException { switch (type) { @@ -101,8 +87,8 @@ private byte[] formatPath(byte[] path, long position) throws ZksnarkException { } // Note: should call librustzcashSaplingProvingCtxFree in the caller - private SpendDescriptionCapsule generateSpendProof(SpendDescriptionInfo spend, - long ctx) throws ZksnarkException { + private SpendDescriptionCapsule generateSpendProof(SpendDescriptionInfo spend, long ctx) + throws ZksnarkException { byte[] cm = spend.note.cm(); // check if ak exists byte[] ak; @@ -128,7 +114,8 @@ private SpendDescriptionCapsule generateSpendProof(SpendDescriptionInfo spend, byte[] rk = new byte[32]; byte[] zkproof = new byte[192]; if (!JLibrustzcash.librustzcashSaplingSpendProof( - new LibrustzcashParam.SpendProofParams(ctx, + new LibrustzcashParam.SpendProofParams( + ctx, ak, nsk, spend.note.getD().getData(), @@ -171,7 +158,8 @@ private ReceiveDescriptionCapsule generateOutputProof(ReceiveDescriptionInfo out byte[] cv = new byte[32]; byte[] zkProof = new byte[192]; if (!JLibrustzcash.librustzcashSaplingOutputProof( - new LibrustzcashParam.OutputProofParams(ctx, + new LibrustzcashParam.OutputProofParams( + ctx, encryptor.getEsk(), output.getNote().getD().getData(), output.getNote().getPkD(), @@ -186,12 +174,9 @@ private ReceiveDescriptionCapsule generateOutputProof(ReceiveDescriptionInfo out throw new ZksnarkException("ovk is null or invalid and ovk should be 32 bytes (256 bit)"); } - OutgoingPlaintext outPlaintext = new OutgoingPlaintext(output.getNote().getPkD(), - encryptor.getEsk()); - byte[] cOut = outPlaintext.encrypt(output.ovk, - cv, - cm, - encryptor).getData(); + OutgoingPlaintext outPlaintext = + new OutgoingPlaintext(output.getNote().getPkD(), encryptor.getEsk()); + byte[] cOut = outPlaintext.encrypt(output.ovk, cv, cm, encryptor).getData(); ReceiveDescriptionCapsule receiveDescriptionCapsule = new ReceiveDescriptionCapsule(); receiveDescriptionCapsule.setValueCommitment(cv); @@ -208,18 +193,16 @@ private void createSpendAuth(byte[] dataToBeSigned) throws ZksnarkException { for (int i = 0; i < spends.size(); i++) { byte[] result = new byte[64]; JLibrustzcash.librustzcashSaplingSpendSig( - new LibrustzcashParam.SpendSigParams(spends.get(i).expsk.getAsk(), - spends.get(i).alpha, - dataToBeSigned, - result)); - builder.getSpendDescriptionBuilder(i) - .setSpendAuthoritySignature(ByteString.copyFrom(result)); + new LibrustzcashParam.SpendSigParams( + spends.get(i).expsk.getAsk(), spends.get(i).alpha, dataToBeSigned, result)); + builder.getSpendDescriptionBuilder(i).setSpendAuthoritySignature(ByteString.copyFrom(result)); } } private byte[] encodeSpendDescriptionWithoutSpendAuthSig( ShieldContract.SpendDescription spendDescription) { - return ByteUtil.merge(spendDescription.getNullifier().toByteArray(), + return ByteUtil.merge( + spendDescription.getNullifier().toByteArray(), spendDescription.getAnchor().toByteArray(), spendDescription.getValueCommitment().toByteArray(), spendDescription.getRk().toByteArray(), @@ -228,7 +211,8 @@ private byte[] encodeSpendDescriptionWithoutSpendAuthSig( private byte[] encodeReceiveDescriptionWithoutC( ShieldContract.ReceiveDescription receiveDescription) { - return ByteUtil.merge(receiveDescription.getNoteCommitment().toByteArray(), + return ByteUtil.merge( + receiveDescription.getNoteCommitment().toByteArray(), receiveDescription.getValueCommitment().toByteArray(), receiveDescription.getEpk().toByteArray(), receiveDescription.getZkproof().toByteArray()); @@ -236,7 +220,8 @@ private byte[] encodeReceiveDescriptionWithoutC( private byte[] encodeCencCout(ShieldContract.ReceiveDescription receiveDescription) { byte[] padding = new byte[12]; - return ByteUtil.merge(receiveDescription.getCEnc().toByteArray(), + return ByteUtil.merge( + receiveDescription.getCEnc().toByteArray(), receiveDescription.getCOut().toByteArray(), padding); } @@ -244,7 +229,7 @@ private byte[] encodeCencCout(ShieldContract.ReceiveDescription receiveDescripti public ShieldedTRC20Parameters build(boolean withAsk) throws ZksnarkException { // Empty output script byte[] mergedBytes; - byte[] dataHashToBeSigned; //256 + byte[] dataHashToBeSigned; // 256 BigInteger value = BigInteger.ZERO; ShieldContract.SpendDescription spendDescription; ShieldContract.ReceiveDescription receiveDescription; @@ -258,10 +243,12 @@ public ShieldedTRC20Parameters build(boolean withAsk) throws ZksnarkException { receiveDescription = generateOutputProof(receive, ctx).getInstance(); builder.addReceiveDescription(receiveDescription); - mergedBytes = ByteUtil.merge(shieldedTRC20Address, - ByteArray.fromLong(receive.getNote().getValue()), - encodeReceiveDescriptionWithoutC(receiveDescription), - encodeCencCout(receiveDescription)); + mergedBytes = + ByteUtil.merge( + shieldedTRC20Address, + ByteArray.fromLong(receive.getNote().getValue()), + encodeReceiveDescriptionWithoutC(receiveDescription), + encodeCencCout(receiveDescription)); value = transparentFromAmount; builder.setParameterType("mint"); break; @@ -271,8 +258,9 @@ public ShieldedTRC20Parameters build(boolean withAsk) throws ZksnarkException { for (SpendDescriptionInfo spend : spends) { spendDescription = generateSpendProof(spend, ctx).getInstance(); builder.addSpendDescription(spendDescription); - mergedBytes = ByteUtil.merge(mergedBytes, - encodeSpendDescriptionWithoutSpendAuthSig(spendDescription)); + mergedBytes = + ByteUtil.merge( + mergedBytes, encodeSpendDescriptionWithoutSpendAuthSig(spendDescription)); } // Create OutputDescriptions @@ -280,8 +268,8 @@ public ShieldedTRC20Parameters build(boolean withAsk) throws ZksnarkException { for (ReceiveDescriptionInfo receiveD : receives) { receiveDescription = generateOutputProof(receiveD, ctx).getInstance(); builder.addReceiveDescription(receiveDescription); - mergedBytes = ByteUtil.merge(mergedBytes, - encodeReceiveDescriptionWithoutC(receiveDescription)); + mergedBytes = + ByteUtil.merge(mergedBytes, encodeReceiveDescriptionWithoutC(receiveDescription)); cencCout = ByteUtil.merge(cencCout, encodeCencCout(receiveDescription)); } mergedBytes = ByteUtil.merge(mergedBytes, cencCout); @@ -291,17 +279,21 @@ public ShieldedTRC20Parameters build(boolean withAsk) throws ZksnarkException { SpendDescriptionInfo spend = spends.get(0); spendDescription = generateSpendProof(spend, ctx).getInstance(); builder.addSpendDescription(spendDescription); - mergedBytes = ByteUtil.merge(shieldedTRC20Address, - encodeSpendDescriptionWithoutSpendAuthSig(spendDescription)); + mergedBytes = + ByteUtil.merge( + shieldedTRC20Address, + encodeSpendDescriptionWithoutSpendAuthSig(spendDescription)); if (receives.size() == 1) { receiveDescription = generateOutputProof(receives.get(0), ctx).getInstance(); builder.addReceiveDescription(receiveDescription); - mergedBytes = ByteUtil - .merge(mergedBytes, encodeReceiveDescriptionWithoutC(receiveDescription), + mergedBytes = + ByteUtil.merge( + mergedBytes, + encodeReceiveDescriptionWithoutC(receiveDescription), encodeCencCout(receiveDescription)); } - mergedBytes = ByteUtil - .merge(mergedBytes, transparentToAddress, ByteArray.fromLong(valueBalance)); + mergedBytes = + ByteUtil.merge(mergedBytes, transparentToAddress, ByteArray.fromLong(valueBalance)); value = transparentToAmount; builder.setParameterType("burn"); break; @@ -321,11 +313,8 @@ public ShieldedTRC20Parameters build(boolean withAsk) throws ZksnarkException { byte[] bindingSig = new byte[64]; JLibrustzcash.librustzcashSaplingBindingSig( - new LibrustzcashParam.BindingSigParams(ctx, - valueBalance, - dataHashToBeSigned, - bindingSig) - ); + new LibrustzcashParam.BindingSigParams( + ctx, valueBalance, dataHashToBeSigned, bindingSig)); builder.setBindingSignature(ByteString.copyFrom(bindingSig)); } catch (Exception e) { throw new ZksnarkException("build the shielded TRC-20 parameters error: " + e.getMessage()); @@ -336,8 +325,8 @@ public ShieldedTRC20Parameters build(boolean withAsk) throws ZksnarkException { if (withAsk || shieldedTRC20ParametersType == ShieldedTRC20ParametersType.MINT) { shieldedTRC20Parameters = builder.build(); builder.setTriggerContractInput( - getTriggerContractInput(shieldedTRC20Parameters, null, value, true, - transparentToAddress)); + getTriggerContractInput( + shieldedTRC20Parameters, null, value, true, transparentToAddress)); } if (!withAsk && shieldedTRC20ParametersType == ShieldedTRC20ParametersType.BURN) { @@ -346,9 +335,11 @@ public ShieldedTRC20Parameters build(boolean withAsk) throws ZksnarkException { return builder.build(); } - public String getTriggerContractInput(ShieldedTRC20Parameters shieldedTRC20Parameters, + public String getTriggerContractInput( + ShieldedTRC20Parameters shieldedTRC20Parameters, List spendAuthoritySignature, - BigInteger value, boolean withAsk, + BigInteger value, + boolean withAsk, byte[] transparentToAddress) { switch (shieldedTRC20ParametersType) { case MINT: @@ -356,36 +347,37 @@ public String getTriggerContractInput(ShieldedTRC20Parameters shieldedTRC20Param case TRANSFER: return transferParamsToHexString(shieldedTRC20Parameters, spendAuthoritySignature, withAsk); case BURN: - return burnParamsToHexString(shieldedTRC20Parameters, spendAuthoritySignature, value, - transparentToAddress, withAsk); + return burnParamsToHexString( + shieldedTRC20Parameters, spendAuthoritySignature, value, transparentToAddress, withAsk); default: return null; } } - private String mintParamsToHexString(GrpcAPI.ShieldedTRC20Parameters mintParams, - BigInteger value) { + private String mintParamsToHexString( + GrpcAPI.ShieldedTRC20Parameters mintParams, BigInteger value) { if (value.compareTo(BigInteger.ZERO) <= 0) { throw new IllegalArgumentException("require the value be positive"); } ShieldContract.ReceiveDescription revDesc = mintParams.getReceiveDescription(0); byte[] zeros = new byte[12]; - byte[] mergedBytes = ByteUtil.merge( - ByteUtil.bigIntegerToBytes(value, 32), - revDesc.getNoteCommitment().toByteArray(), - revDesc.getValueCommitment().toByteArray(), - revDesc.getEpk().toByteArray(), - revDesc.getZkproof().toByteArray(), - mintParams.getBindingSignature().toByteArray(), - revDesc.getCEnc().toByteArray(), - revDesc.getCOut().toByteArray(), - zeros - ); + byte[] mergedBytes = + ByteUtil.merge( + ByteUtil.bigIntegerToBytes(value, 32), + revDesc.getNoteCommitment().toByteArray(), + revDesc.getValueCommitment().toByteArray(), + revDesc.getEpk().toByteArray(), + revDesc.getZkproof().toByteArray(), + mintParams.getBindingSignature().toByteArray(), + revDesc.getCEnc().toByteArray(), + revDesc.getCOut().toByteArray(), + zeros); return Hex.toHexString(mergedBytes); } - private String transferParamsToHexString(GrpcAPI.ShieldedTRC20Parameters transferParams, + private String transferParamsToHexString( + GrpcAPI.ShieldedTRC20Parameters transferParams, List spendAuthoritySignature, boolean withAsk) { byte[] input = new byte[0]; @@ -395,16 +387,17 @@ private String transferParamsToHexString(GrpcAPI.ShieldedTRC20Parameters transfe byte[] bindingSig; List spendDescs = transferParams.getSpendDescriptionList(); for (ShieldContract.SpendDescription spendDesc : spendDescs) { - input = ByteUtil.merge(input, - spendDesc.getNullifier().toByteArray(), - spendDesc.getAnchor().toByteArray(), - spendDesc.getValueCommitment().toByteArray(), - spendDesc.getRk().toByteArray(), - spendDesc.getZkproof().toByteArray() - ); + input = + ByteUtil.merge( + input, + spendDesc.getNullifier().toByteArray(), + spendDesc.getAnchor().toByteArray(), + spendDesc.getValueCommitment().toByteArray(), + spendDesc.getRk().toByteArray(), + spendDesc.getZkproof().toByteArray()); if (withAsk) { - spendAuthSig = ByteUtil.merge( - spendAuthSig, spendDesc.getSpendAuthoritySignature().toByteArray()); + spendAuthSig = + ByteUtil.merge(spendAuthSig, spendDesc.getSpendAuthoritySignature().toByteArray()); } } long spendCount = spendDescs.size(); @@ -415,8 +408,10 @@ private String transferParamsToHexString(GrpcAPI.ShieldedTRC20Parameters transfe if (spendCount == 1) { spendAuthSig = spendAuthoritySignature.get(0).getValue().toByteArray(); } else { - spendAuthSig = ByteUtil.merge(spendAuthoritySignature.get(0).getValue().toByteArray(), - spendAuthoritySignature.get(1).getValue().toByteArray()); + spendAuthSig = + ByteUtil.merge( + spendAuthoritySignature.get(0).getValue().toByteArray(), + spendAuthoritySignature.get(1).getValue().toByteArray()); } } @@ -426,49 +421,50 @@ private String transferParamsToHexString(GrpcAPI.ShieldedTRC20Parameters transfe List recvDescs = transferParams.getReceiveDescriptionList(); for (ShieldContract.ReceiveDescription recvDesc : recvDescs) { - output = ByteUtil.merge(output, - recvDesc.getNoteCommitment().toByteArray(), - recvDesc.getValueCommitment().toByteArray(), - recvDesc.getEpk().toByteArray(), - recvDesc.getZkproof().toByteArray() - ); + output = + ByteUtil.merge( + output, + recvDesc.getNoteCommitment().toByteArray(), + recvDesc.getValueCommitment().toByteArray(), + recvDesc.getEpk().toByteArray(), + recvDesc.getZkproof().toByteArray()); byte[] zeros = new byte[12]; - c = ByteUtil.merge(c, - recvDesc.getCEnc().toByteArray(), - recvDesc.getCOut().toByteArray(), - zeros - ); + c = + ByteUtil.merge( + c, recvDesc.getCEnc().toByteArray(), recvDesc.getCOut().toByteArray(), zeros); } long recvCount = recvDescs.size(); byte[] recvCountBytes = ByteUtil.longTo32Bytes(recvCount); - byte[] outputOffsetbytes = ByteUtil - .longTo32Bytes(192 + 32 + 320 * spendCount + 32 + 64 * spendCount); - byte[] coffsetBytes = ByteUtil - .longTo32Bytes(192 + 32 + 320 * spendCount + 32 + 64 * spendCount + 32 - + 288 * recvCount); + byte[] outputOffsetbytes = + ByteUtil.longTo32Bytes(192 + 32 + 320 * spendCount + 32 + 64 * spendCount); + byte[] coffsetBytes = + ByteUtil.longTo32Bytes( + 192 + 32 + 320 * spendCount + 32 + 64 * spendCount + 32 + 288 * recvCount); bindingSig = transferParams.getBindingSignature().toByteArray(); - return Hex.toHexString(ByteUtil.merge( - inputOffsetbytes, - authOffsetBytes, - outputOffsetbytes, - bindingSig, - coffsetBytes, - spendCountBytes, - input, - spendCountBytes, - spendAuthSig, - recvCountBytes, - output, - recvCountBytes, - c - )); + return Hex.toHexString( + ByteUtil.merge( + inputOffsetbytes, + authOffsetBytes, + outputOffsetbytes, + bindingSig, + coffsetBytes, + spendCountBytes, + input, + spendCountBytes, + spendAuthSig, + recvCountBytes, + output, + recvCountBytes, + c)); } - private String burnParamsToHexString(GrpcAPI.ShieldedTRC20Parameters burnParams, + private String burnParamsToHexString( + GrpcAPI.ShieldedTRC20Parameters burnParams, List spendAuthoritySignature, - BigInteger value, byte[] transparentToAddress, + BigInteger value, + byte[] transparentToAddress, boolean withAsk) { byte[] payTo = new byte[32]; if (value.compareTo(BigInteger.ZERO) <= 0) { @@ -491,19 +487,19 @@ private String burnParamsToHexString(GrpcAPI.ShieldedTRC20Parameters burnParams, byte[] mergedBytes; byte[] zeros = new byte[16]; - mergedBytes = ByteUtil.merge( - spendDesc.getNullifier().toByteArray(), - spendDesc.getAnchor().toByteArray(), - spendDesc.getValueCommitment().toByteArray(), - spendDesc.getRk().toByteArray(), - spendDesc.getZkproof().toByteArray(), - spendAuthSign, - ByteUtil.bigIntegerToBytes(value, 32), - burnParams.getBindingSignature().toByteArray(), - payTo, - burnCiphertext, - zeros - ); + mergedBytes = + ByteUtil.merge( + spendDesc.getNullifier().toByteArray(), + spendDesc.getAnchor().toByteArray(), + spendDesc.getValueCommitment().toByteArray(), + spendDesc.getRk().toByteArray(), + spendDesc.getZkproof().toByteArray(), + spendAuthSign, + ByteUtil.bigIntegerToBytes(value, 32), + burnParams.getBindingSignature().toByteArray(), + payTo, + burnCiphertext, + zeros); byte[] outputOffsetBytes; // 32 byte[] coffsetBytes; // 32 @@ -514,8 +510,9 @@ private String burnParamsToHexString(GrpcAPI.ShieldedTRC20Parameters burnParams, outputCountBytes = ByteUtil.longTo32Bytes(0L); coffsetBytes = ByteUtil.longTo32Bytes(mergedBytes.length + 32L * 3); countBytes = ByteUtil.longTo32Bytes(0L); - mergedBytes = ByteUtil - .merge(mergedBytes, outputOffsetBytes, coffsetBytes, outputCountBytes, countBytes); + mergedBytes = + ByteUtil.merge( + mergedBytes, outputOffsetBytes, coffsetBytes, outputCountBytes, countBytes); } else { outputOffsetBytes = ByteUtil.longTo32Bytes(mergedBytes.length + 32L * 2); outputCountBytes = ByteUtil.longTo32Bytes(1L); @@ -523,8 +520,9 @@ private String burnParamsToHexString(GrpcAPI.ShieldedTRC20Parameters burnParams, countBytes = ByteUtil.longTo32Bytes(1L); ReceiveDescription recvDesc = burnParams.getReceiveDescription(0); zeros = new byte[12]; - mergedBytes = ByteUtil - .merge(mergedBytes, + mergedBytes = + ByteUtil.merge( + mergedBytes, outputOffsetBytes, coffsetBytes, outputCountBytes, @@ -541,11 +539,8 @@ private String burnParamsToHexString(GrpcAPI.ShieldedTRC20Parameters burnParams, } public void addSpend( - ExpandedSpendingKey expsk, - Note note, - byte[] anchor, - byte[] path, - long position) throws ZksnarkException { + ExpandedSpendingKey expsk, Note note, byte[] anchor, byte[] path, long position) + throws ZksnarkException { spends.add(new SpendDescriptionInfo(expsk, note, anchor, path, position)); valueBalance += note.getValue(); } @@ -562,13 +557,7 @@ public void addSpend( } public void addSpend( - byte[] ak, - byte[] nsk, - Note note, - byte[] alpha, - byte[] anchor, - byte[] path, - long position) { + byte[] ak, byte[] nsk, Note note, byte[] alpha, byte[] anchor, byte[] path, long position) { spends.add(new SpendDescriptionInfo(ak, nsk, note, alpha, anchor, path, position)); valueBalance += note.getValue(); } @@ -600,11 +589,8 @@ public static class SpendDescriptionInfo { private byte[] nsk; private SpendDescriptionInfo( - ExpandedSpendingKey expsk, - Note note, - byte[] anchor, - byte[] path, - long position) throws ZksnarkException { + ExpandedSpendingKey expsk, Note note, byte[] anchor, byte[] path, long position) + throws ZksnarkException { this.expsk = expsk; this.note = note; this.anchor = anchor; @@ -630,13 +616,7 @@ private SpendDescriptionInfo( } private SpendDescriptionInfo( - byte[] ak, - byte[] nsk, - Note note, - byte[] alpha, - byte[] anchor, - byte[] path, - long position) { + byte[] ak, byte[] nsk, Note note, byte[] alpha, byte[] anchor, byte[] path, long position) { this.ak = ak; this.nsk = nsk; this.note = note; @@ -651,8 +631,7 @@ private SpendDescriptionInfo( private class ReceiveDescriptionInfo { private byte[] ovk; - @Getter - private Note note; + @Getter private Note note; } public enum ShieldedTRC20ParametersType { diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/DiversifierT.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/DiversifierT.java index bd34e5fd..d0253918 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/DiversifierT.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/DiversifierT.java @@ -8,16 +8,12 @@ import stest.tron.wallet.common.client.utils.Constant; import stest.tron.wallet.common.client.utils.exception.ZksnarkException; - @AllArgsConstructor public class DiversifierT { - @Setter - @Getter - private byte[] data = new byte[Constant.ZC_DIVERSIFIER_SIZE]; + @Setter @Getter private byte[] data = new byte[Constant.ZC_DIVERSIFIER_SIZE]; - public DiversifierT() { - } + public DiversifierT() {} public static DiversifierT random() throws ZksnarkException { byte[] d; diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/ExpandedSpendingKey.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/ExpandedSpendingKey.java index f5af1131..8eeddcd4 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/ExpandedSpendingKey.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/ExpandedSpendingKey.java @@ -8,24 +8,16 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.exception.ZksnarkException; - @Slf4j(topic = "shieldTransaction") @AllArgsConstructor public class ExpandedSpendingKey { - @Setter - @Getter - private byte[] ask; // the spend authorizing key,256 - @Setter - @Getter - private byte[] nsk; // the proof authorizing key (ak, nsk),256 + @Setter @Getter private byte[] ask; // the spend authorizing key,256 + @Setter @Getter private byte[] nsk; // the proof authorizing key (ak, nsk),256 // Let ovk be an outgoing viewing key that is intended to be able to decrypt this payment - @Setter - @Getter - private byte[] ovk; // the outgoing viewing key,256 + @Setter @Getter private byte[] ovk; // the outgoing viewing key,256 - public ExpandedSpendingKey() { - } + public ExpandedSpendingKey() {} public static byte[] getAkFromAsk(byte[] ask) throws ZksnarkException { return JLibrustzcash.librustzcashAskToAk(ask); // 256 diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/FullViewingKey.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/FullViewingKey.java index e8d06d80..953544fd 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/FullViewingKey.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/FullViewingKey.java @@ -13,15 +13,9 @@ @AllArgsConstructor public class FullViewingKey { - @Getter - @Setter - private byte[] ak; // 256 - @Getter - @Setter - private byte[] nk; // 256 - @Getter - @Setter - private byte[] ovk; // 256,the outgoing viewing key + @Getter @Setter private byte[] ak; // 256 + @Getter @Setter private byte[] nk; // 256 + @Getter @Setter private byte[] ovk; // 256,the outgoing viewing key public static FullViewingKey decode(byte[] data) { byte[] ak = new byte[32]; diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/IncomingViewingKey.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/IncomingViewingKey.java index 1af4d163..0899729d 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/IncomingViewingKey.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/IncomingViewingKey.java @@ -9,20 +9,18 @@ import org.tron.common.zksnark.LibrustzcashParam; import stest.tron.wallet.common.client.utils.exception.ZksnarkException; - // ivk @Slf4j(topic = "shieldTransaction") @AllArgsConstructor public class IncomingViewingKey { - @Setter - @Getter - public byte[] value; // 256 + @Setter @Getter public byte[] value; // 256 public Optional address(DiversifierT d) throws ZksnarkException { byte[] pkD = new byte[32]; // 32 if (JLibrustzcash.librustzcashCheckDiversifier(d.getData())) { - if (!JLibrustzcash.librustzcashIvkToPkd(new LibrustzcashParam.IvkToPkdParams(value, d.getData(), pkD))) { + if (!JLibrustzcash.librustzcashIvkToPkd( + new LibrustzcashParam.IvkToPkdParams(value, d.getData(), pkD))) { throw new ZksnarkException("librustzcashIvkToPkd error"); } return Optional.of(new PaymentAddress(d, pkD)); diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/KeyIo.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/KeyIo.java index 715e42a2..ec2bb667 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/KeyIo.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/KeyIo.java @@ -22,7 +22,6 @@ import stest.tron.wallet.common.client.utils.Bech32; import stest.tron.wallet.common.client.utils.Bech32.Bech32Data; - public class KeyIo { private static int CONVERTED_SAPLING_PAYMENT_ADDRESS_SIZE = ((32 + 11) * 8 + 4) / 5; @@ -49,9 +48,7 @@ public static String encodePaymentAddress(PaymentAddress zaddr) { return Bech32.encode(SAPLING_PAYMENT_ADDRESS, prog); } - /** - * Helper for re-arranging bits into groups. - */ + /** Helper for re-arranging bits into groups. */ private static byte[] convertBits( final byte[] in, final int inStart, @@ -127,4 +124,4 @@ private static byte[] convertBits(List data, int fromBits, int toBits, boo return buf; } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/PaymentAddress.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/PaymentAddress.java index 45b4de63..f4171eb5 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/PaymentAddress.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/PaymentAddress.java @@ -8,12 +8,8 @@ public class PaymentAddress { // diversified payment address addrd = (d, pkd) - @Setter - @Getter - private DiversifierT d; - @Setter - @Getter - private byte[] pkD; // 256 + @Setter @Getter private DiversifierT d; + @Setter @Getter private byte[] pkD; // 256 public static PaymentAddress decode(byte[] data) { DiversifierT d = new DiversifierT(); diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/SpendingKey.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/SpendingKey.java index b18e6913..bc6ffaa0 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/SpendingKey.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/address/SpendingKey.java @@ -15,13 +15,10 @@ import stest.tron.wallet.common.client.utils.exception.BadItemException; import stest.tron.wallet.common.client.utils.exception.ZksnarkException; - @AllArgsConstructor public class SpendingKey { - @Setter - @Getter - public byte[] value; + @Setter @Getter public byte[] value; private static SecureRandom random = new SecureRandom(); public static SpendingKey random() throws ZksnarkException { @@ -72,7 +69,7 @@ public PaymentAddress defaultAddress() throws BadItemException, ZksnarkException public DiversifierT defaultDiversifier() throws BadItemException, ZksnarkException { byte[] res = new byte[Constant.ZC_DIVERSIFIER_SIZE]; byte[] blob = new byte[34]; - //ZksnarkUtils.sort(this.value); + // ZksnarkUtils.sort(this.value); System.arraycopy(this.value, 0, blob, 0, 32); blob[32] = 3; blob[33] = 0; @@ -80,8 +77,8 @@ public DiversifierT defaultDiversifier() throws BadItemException, ZksnarkExcepti long state = JLibsodium.initState(); try { JLibsodium.cryptoGenerichashBlake2bInitSaltPersonal( - new Blake2bInitSaltPersonalParams(state, null, 0, 64, null, - Constant.ZTRON_EXPANDSEED_PERSONALIZATION)); + new Blake2bInitSaltPersonalParams( + state, null, 0, 64, null, Constant.ZTRON_EXPANDSEED_PERSONALIZATION)); JLibsodium.cryptoGenerichashBlake2bUpdate(new Blake2bUpdateParams(state, blob, 34)); JLibsodium.cryptoGenerichashBlake2bFinal(new Blake2bFinalParams(state, res, 11)); if (JLibrustzcash.librustzcashCheckDiversifier(res)) { @@ -133,9 +130,9 @@ private static byte[] prfExpand(byte[] sk, byte t) throws ZksnarkException { blob[32] = t; long state = JLibsodium.initState(); try { - JLibsodium.cryptoGenerichashBlake2bInitSaltPersonal(new Blake2bInitSaltPersonalParams( - state, null, 0, 64, null, - Constant.ZTRON_EXPANDSEED_PERSONALIZATION)); + JLibsodium.cryptoGenerichashBlake2bInitSaltPersonal( + new Blake2bInitSaltPersonalParams( + state, null, 0, 64, null, Constant.ZTRON_EXPANDSEED_PERSONALIZATION)); JLibsodium.cryptoGenerichashBlake2bUpdate(new Blake2bUpdateParams(state, blob, 33)); JLibsodium.cryptoGenerichashBlake2bFinal(new Blake2bFinalParams(state, res, 64)); } finally { diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/note/Note.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/note/Note.java index 94d194a2..b9b2601c 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/note/Note.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/note/Note.java @@ -1,6 +1,5 @@ package stest.tron.wallet.common.client.utils.zen.note; - import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Optional; @@ -19,23 +18,13 @@ import stest.tron.wallet.common.client.utils.zen.address.IncomingViewingKey; import stest.tron.wallet.common.client.utils.zen.address.PaymentAddress; - public class Note { - @Getter - @Setter - private DiversifierT d; - @Getter - @Setter - private byte[] pkD; // 256 - @Getter - @Setter - private long value = 0; - @Getter - @Setter - private byte[] rcm; // 256 - @Getter - private byte[] memo = new byte[ZenChainParams.ZC_MEMO_SIZE]; + @Getter @Setter private DiversifierT d; + @Getter @Setter private byte[] pkD; // 256 + @Getter @Setter private long value = 0; + @Getter @Setter private byte[] rcm; // 256 + @Getter private byte[] memo = new byte[ZenChainParams.ZC_MEMO_SIZE]; public Note() { d = new DiversifierT(); @@ -71,9 +60,7 @@ public static byte[] generateR() throws ZksnarkException { return r; } - /** - * decode plain_enc to note - */ + /** decode plain_enc to note */ public static Note decode(NoteEncryption.Encryption.EncPlaintext encPlaintext) throws ZksnarkException { byte[] data = encPlaintext.getData(); @@ -85,11 +72,21 @@ public static Note decode(NoteEncryption.Encryption.EncPlaintext encPlaintext) Note ret = new Note(); byte[] noteD = new byte[ZenChainParams.ZC_DIVERSIFIER_SIZE]; - System.arraycopy(data, ZenChainParams.ZC_NOTEPLAINTEXT_LEADING, noteD, 0, ZenChainParams.ZC_DIVERSIFIER_SIZE); + System.arraycopy( + data, + ZenChainParams.ZC_NOTEPLAINTEXT_LEADING, + noteD, + 0, + ZenChainParams.ZC_DIVERSIFIER_SIZE); ret.d.setData(noteD); byte[] valueLong = new byte[ZenChainParams.ZC_V_SIZE]; - System.arraycopy(data, ZenChainParams.ZC_NOTEPLAINTEXT_LEADING + ZenChainParams.ZC_DIVERSIFIER_SIZE, valueLong, 0, ZenChainParams.ZC_V_SIZE); + System.arraycopy( + data, + ZenChainParams.ZC_NOTEPLAINTEXT_LEADING + ZenChainParams.ZC_DIVERSIFIER_SIZE, + valueLong, + 0, + ZenChainParams.ZC_V_SIZE); for (int i = 0; i < valueLong.length / 2; i++) { byte temp = valueLong[i]; valueLong[i] = valueLong[valueLong.length - 1 - i]; @@ -101,13 +98,22 @@ public static Note decode(NoteEncryption.Encryption.EncPlaintext encPlaintext) byte[] noteRcm = new byte[ZenChainParams.ZC_R_SIZE]; System.arraycopy( - data, ZenChainParams.ZC_NOTEPLAINTEXT_LEADING + ZenChainParams.ZC_DIVERSIFIER_SIZE + ZenChainParams.ZC_V_SIZE, noteRcm, 0, ZenChainParams.ZC_R_SIZE); + data, + ZenChainParams.ZC_NOTEPLAINTEXT_LEADING + + ZenChainParams.ZC_DIVERSIFIER_SIZE + + ZenChainParams.ZC_V_SIZE, + noteRcm, + 0, + ZenChainParams.ZC_R_SIZE); ret.rcm = noteRcm; byte[] noteMemo = new byte[ZenChainParams.ZC_MEMO_SIZE]; System.arraycopy( data, - ZenChainParams.ZC_NOTEPLAINTEXT_LEADING + ZenChainParams.ZC_DIVERSIFIER_SIZE + ZenChainParams.ZC_V_SIZE + ZenChainParams.ZC_R_SIZE, + ZenChainParams.ZC_NOTEPLAINTEXT_LEADING + + ZenChainParams.ZC_DIVERSIFIER_SIZE + + ZenChainParams.ZC_V_SIZE + + ZenChainParams.ZC_R_SIZE, noteMemo, 0, ZenChainParams.ZC_MEMO_SIZE); @@ -116,11 +122,9 @@ public static Note decode(NoteEncryption.Encryption.EncPlaintext encPlaintext) return ret; } - /** - * decrypt c_enc with ivk to plain_enc - */ - public static Optional decrypt( - byte[] ciphertext, byte[] ivk, byte[] epk, byte[] cmu) throws ZksnarkException { + /** decrypt c_enc with ivk to plain_enc */ + public static Optional decrypt(byte[] ciphertext, byte[] ivk, byte[] epk, byte[] cmu) + throws ZksnarkException { Optional pt = NoteEncryption.Encryption.attemptEncDecryption(ciphertext, ivk, epk); if (!pt.isPresent()) { @@ -128,8 +132,7 @@ public static Optional decrypt( } Note ret = decode(pt.get()); byte[] pkD = new byte[32]; - if (!JLibrustzcash - .librustzcashIvkToPkd(new IvkToPkdParams(ivk, ret.d.getData(), pkD))) { + if (!JLibrustzcash.librustzcashIvkToPkd(new IvkToPkdParams(ivk, ret.d.getData(), pkD))) { return Optional.empty(); } byte[] cmuExpected = new byte[32]; @@ -143,11 +146,12 @@ public static Optional decrypt( return Optional.of(ret); } - /** - * decrypt c_enc with ovk to plain_enc - */ + /** decrypt c_enc with ovk to plain_enc */ public static Optional decrypt( - NoteEncryption.Encryption.EncCiphertext ciphertext, byte[] epk, byte[] esk, byte[] pkD, + NoteEncryption.Encryption.EncCiphertext ciphertext, + byte[] epk, + byte[] esk, + byte[] pkD, byte[] cmu) throws ZksnarkException { Optional pt = @@ -167,14 +171,13 @@ public static Optional decrypt( return Optional.of(ret); } - /** - * add the judgement of memo size - */ + /** add the judgement of memo size */ public void setMemo(byte[] memo) { if (ByteArray.isEmpty(memo)) { return; } - int memoSize = memo.length < ZenChainParams.ZC_MEMO_SIZE ? memo.length : ZenChainParams.ZC_MEMO_SIZE; + int memoSize = + memo.length < ZenChainParams.ZC_MEMO_SIZE ? memo.length : ZenChainParams.ZC_MEMO_SIZE; System.arraycopy(memo, 0, this.memo, 0, memoSize); } @@ -208,9 +211,7 @@ public byte[] nullifier(byte[] ak, byte[] nk, long position) throws ZksnarkExcep return result; } - /** - * filling pkD generated by ivk - */ + /** filling pkD generated by ivk */ public Optional note(IncomingViewingKey ivk) throws ZksnarkException { Optional addr = ivk.address(d); if (addr.isPresent()) { @@ -220,9 +221,7 @@ public Optional note(IncomingViewingKey ivk) throws ZksnarkException { } } - /** - * encrypt plain_enc to c_enc with by k_enc - */ + /** encrypt plain_enc to c_enc with by k_enc */ public Optional encrypt(byte[] pkD) throws ZksnarkException { // Get the encryptor Optional sne = NoteEncryption.fromDiversifier(d); @@ -233,17 +232,15 @@ public Optional encrypt(byte[] pkD) throws Zksnar // Create the plaintext NoteEncryption.Encryption.EncPlaintext pt = this.encode(); // Encrypt the plaintext - Optional encciphertext = enc - .encryptToRecipient(pkD, pt); + Optional encciphertext = + enc.encryptToRecipient(pkD, pt); if (!encciphertext.isPresent()) { return Optional.empty(); } return Optional.of(new NotePlaintextEncryptionResult(encciphertext.get().getData(), enc)); } - /** - * construct plain_enc with columns of note - */ + /** construct plain_enc with columns of note */ public NoteEncryption.Encryption.EncPlaintext encode() { ByteBuffer buffer = ByteBuffer.allocate(ZenChainParams.ZC_V_SIZE); buffer.putLong(0, value); @@ -256,15 +253,34 @@ public NoteEncryption.Encryption.EncPlaintext encode() { byte[] data = new byte[ZenChainParams.ZC_ENCPLAINTEXT_SIZE]; data[0] = 0x01; - System.arraycopy(d.getData(), 0, data, ZenChainParams.ZC_NOTEPLAINTEXT_LEADING, ZenChainParams.ZC_DIVERSIFIER_SIZE); - System.arraycopy(valueLong, 0, data, ZenChainParams.ZC_NOTEPLAINTEXT_LEADING + ZenChainParams.ZC_DIVERSIFIER_SIZE, ZenChainParams.ZC_V_SIZE); - System.arraycopy(rcm, 0, data, ZenChainParams.ZC_NOTEPLAINTEXT_LEADING + ZenChainParams.ZC_DIVERSIFIER_SIZE + ZenChainParams.ZC_V_SIZE, + System.arraycopy( + d.getData(), + 0, + data, + ZenChainParams.ZC_NOTEPLAINTEXT_LEADING, + ZenChainParams.ZC_DIVERSIFIER_SIZE); + System.arraycopy( + valueLong, + 0, + data, + ZenChainParams.ZC_NOTEPLAINTEXT_LEADING + ZenChainParams.ZC_DIVERSIFIER_SIZE, + ZenChainParams.ZC_V_SIZE); + System.arraycopy( + rcm, + 0, + data, + ZenChainParams.ZC_NOTEPLAINTEXT_LEADING + + ZenChainParams.ZC_DIVERSIFIER_SIZE + + ZenChainParams.ZC_V_SIZE, ZenChainParams.ZC_R_SIZE); System.arraycopy( memo, 0, data, - ZenChainParams.ZC_NOTEPLAINTEXT_LEADING + ZenChainParams.ZC_DIVERSIFIER_SIZE + ZenChainParams.ZC_V_SIZE + ZenChainParams.ZC_R_SIZE, + ZenChainParams.ZC_NOTEPLAINTEXT_LEADING + + ZenChainParams.ZC_DIVERSIFIER_SIZE + + ZenChainParams.ZC_V_SIZE + + ZenChainParams.ZC_R_SIZE, ZenChainParams.ZC_MEMO_SIZE); NoteEncryption.Encryption.EncPlaintext ret = new NoteEncryption.Encryption.EncPlaintext(); @@ -275,11 +291,7 @@ public NoteEncryption.Encryption.EncPlaintext encode() { @AllArgsConstructor public class NotePlaintextEncryptionResult { - @Getter - @Setter - private byte[] encCiphertext; - @Getter - @Setter - private NoteEncryption noteEncryption; + @Getter @Setter private byte[] encCiphertext; + @Getter @Setter private NoteEncryption noteEncryption; } } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/note/NoteEncryption.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/note/NoteEncryption.java index 161f2f0c..35abf385 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/note/NoteEncryption.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/note/NoteEncryption.java @@ -27,11 +27,9 @@ public class NoteEncryption { // Ephemeral public key - @Getter - private byte[] epk; + @Getter private byte[] epk; // Ephemeral secret key - @Getter - private byte[] esk; + @Getter private byte[] esk; private boolean alreadyEncryptedEnc; private boolean alreadyEncryptedOut; @@ -41,15 +39,13 @@ public NoteEncryption(byte[] epk, byte[] esk) { this.esk = esk; } - /** - * generate pair of (esk,epk). epk = esk * d - */ + /** generate pair of (esk,epk). epk = esk * d */ public static Optional fromDiversifier(DiversifierT d) throws ZksnarkException { byte[] epk = new byte[32]; byte[] esk = new byte[32]; JLibrustzcash.librustzcashSaplingGenerateR(esk); - if (!JLibrustzcash - .librustzcashSaplingKaDerivepublic(new KaDerivepublicParams(d.getData(), esk, epk))) { + if (!JLibrustzcash.librustzcashSaplingKaDerivepublic( + new KaDerivepublicParams(d.getData(), esk, epk))) { return Optional.empty(); } return Optional.of(new NoteEncryption(epk, esk)); @@ -71,22 +67,28 @@ public Optional encryptToRecipient(byte[] pkD, EncPlaintext messa } byte[] kEnc = new byte[Encryption.NOTEENCRYPTION_CIPHER_KEYSIZE]; - //generate kEnc by sharedsecret and epk + // generate kEnc by sharedsecret and epk Encryption.kdfSapling(kEnc, dhsecret, epk); byte[] cipherNonce = new byte[CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES]; EncCiphertext ciphertext = new EncCiphertext(); - JLibsodium.cryptoAeadChacha20Poly1305IetfEncrypt(new Chacha20Poly1305IetfEncryptParams( - ciphertext.data, null, message.data, - ZenChainParams.ZC_ENCPLAINTEXT_SIZE, null, 0, null, cipherNonce, kEnc)); + JLibsodium.cryptoAeadChacha20Poly1305IetfEncrypt( + new Chacha20Poly1305IetfEncryptParams( + ciphertext.data, + null, + message.data, + ZenChainParams.ZC_ENCPLAINTEXT_SIZE, + null, + 0, + null, + cipherNonce, + kEnc)); alreadyEncryptedEnc = true; return Optional.of(ciphertext); } - /** - * encrypt plain_out with ock to c_out, use this epk - */ - public OutCiphertext encryptToOurselves( - byte[] ovk, byte[] cv, byte[] cm, OutPlaintext message) throws ZksnarkException { + /** encrypt plain_out with ock to c_out, use this epk */ + public OutCiphertext encryptToOurselves(byte[] ovk, byte[] cv, byte[] cm, OutPlaintext message) + throws ZksnarkException { if (alreadyEncryptedOut) { throw new ZksnarkException("already encrypted to the recipient using this key"); } @@ -96,9 +98,17 @@ public OutCiphertext encryptToOurselves( byte[] cipherNonce = new byte[CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES]; OutCiphertext ciphertext = new OutCiphertext(); - JLibsodium.cryptoAeadChacha20Poly1305IetfEncrypt(new Chacha20Poly1305IetfEncryptParams( - ciphertext.data, null, message.data, - ZenChainParams.ZC_OUTPLAINTEXT_SIZE, null, 0, null, cipherNonce, ock)); + JLibsodium.cryptoAeadChacha20Poly1305IetfEncrypt( + new Chacha20Poly1305IetfEncryptParams( + ciphertext.data, + null, + message.data, + ZenChainParams.ZC_OUTPLAINTEXT_SIZE, + null, + 0, + null, + cipherNonce, + ock)); alreadyEncryptedOut = true; return ciphertext; } @@ -107,9 +117,7 @@ public static class Encryption { public static final int NOTEENCRYPTION_CIPHER_KEYSIZE = 32; - /** - * generate ock by ovk, cv, cm, epk - */ + /** generate ock by ovk, cv, cm, epk */ public static void prfOck(byte[] ock, byte[] ovk, byte[] cv, byte[] cm, byte[] epk) throws ZksnarkException { byte[] block = new byte[128]; @@ -121,20 +129,22 @@ public static void prfOck(byte[] ock, byte[] ovk, byte[] cv, byte[] cm, byte[] e byte[] personalization = new byte[JLibsodium.CRYPTO_GENERICHASH_BLAKE2B_PERSONALBYTES]; byte[] temp = "Ztron_Derive_ock".getBytes(); System.arraycopy(temp, 0, personalization, 0, temp.length); - if (JLibsodium.cryptoGenerichashBlack2bSaltPersonal(new Black2bSaltPersonalParams( - ock, NOTEENCRYPTION_CIPHER_KEYSIZE, - block, 128, - null, 0, // No key. - null, // No salt. - personalization) - ) != 0) { + if (JLibsodium.cryptoGenerichashBlack2bSaltPersonal( + new Black2bSaltPersonalParams( + ock, + NOTEENCRYPTION_CIPHER_KEYSIZE, + block, + 128, + null, + 0, // No key. + null, // No salt. + personalization)) + != 0) { throw new ZksnarkException("hash function failure"); } } - /** - * generate kEnc by sharedsecret and epk - */ + /** generate kEnc by sharedsecret and epk */ public static void kdfSapling(byte[] kEnc, byte[] sharedsecret, byte[] epk) throws ZksnarkException { byte[] block = new byte[64]; @@ -143,13 +153,17 @@ public static void kdfSapling(byte[] kEnc, byte[] sharedsecret, byte[] epk) byte[] personalization = new byte[JLibsodium.CRYPTO_GENERICHASH_BLAKE2B_PERSONALBYTES]; byte[] temp = "Ztron_SaplingKDF".getBytes(); System.arraycopy(temp, 0, personalization, 0, temp.length); - if (JLibsodium.cryptoGenerichashBlack2bSaltPersonal(new Black2bSaltPersonalParams( - kEnc, NOTEENCRYPTION_CIPHER_KEYSIZE, - block, 64, - null, 0, // No key. - null, // No salt. - personalization) - ) != 0) { + if (JLibsodium.cryptoGenerichashBlack2bSaltPersonal( + new Black2bSaltPersonalParams( + kEnc, + NOTEENCRYPTION_CIPHER_KEYSIZE, + block, + 64, + null, + 0, // No key. + null, // No salt. + personalization)) + != 0) { throw new ZksnarkException(("hash function failure")); } } @@ -161,24 +175,29 @@ public static void kdfSapling(byte[] kEnc, byte[] sharedsecret, byte[] epk) public static Optional attemptEncDecryption( byte[] ciphertext, byte[] ivk, byte[] epk) throws ZksnarkException { byte[] sharedsecret = new byte[32]; - //generate sharedsecret by epk and ivk + // generate sharedsecret by epk and ivk if (!JLibrustzcash.librustzcashKaAgree(new KaAgreeParams(epk, ivk, sharedsecret))) { return Optional.empty(); } byte[] kEnc = new byte[NOTEENCRYPTION_CIPHER_KEYSIZE]; - //generate kEnc by sharedsecret and epk + // generate kEnc by sharedsecret and epk kdfSapling(kEnc, sharedsecret, epk); byte[] cipher_nonce = new byte[CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES]; EncPlaintext plaintext = new EncPlaintext(); plaintext.data = new byte[ZenChainParams.ZC_ENCPLAINTEXT_SIZE]; - //decrypt cEnc by kEnc - if (JLibsodium.cryptoAeadChacha20poly1305IetfDecrypt(new Chacha20poly1305IetfDecryptParams( - plaintext.data, null, - null, - ciphertext, ZenChainParams.ZC_ENCCIPHERTEXT_SIZE, - null, - 0, - cipher_nonce, kEnc)) != 0) { + // decrypt cEnc by kEnc + if (JLibsodium.cryptoAeadChacha20poly1305IetfDecrypt( + new Chacha20poly1305IetfDecryptParams( + plaintext.data, + null, + null, + ciphertext, + ZenChainParams.ZC_ENCCIPHERTEXT_SIZE, + null, + 0, + cipher_nonce, + kEnc)) + != 0) { return Optional.empty(); } return Optional.of(plaintext); @@ -191,92 +210,92 @@ public static Optional attemptEncDecryption( public static Optional attemptEncDecryption( EncCiphertext ciphertext, byte[] epk, byte[] esk, byte[] pkD) throws ZksnarkException { byte[] sharedsecret = new byte[32]; - //generate sharedsecret by esk and pkD. esk + pkD = sharedsecret = epk + ivk + // generate sharedsecret by esk and pkD. esk + pkD = sharedsecret = epk + ivk if (!JLibrustzcash.librustzcashKaAgree(new KaAgreeParams(pkD, esk, sharedsecret))) { return Optional.empty(); } byte[] kEnc = new byte[NOTEENCRYPTION_CIPHER_KEYSIZE]; - //generate kEnc by sharedsecret and epk + // generate kEnc by sharedsecret and epk kdfSapling(kEnc, sharedsecret, epk); byte[] cipherNonce = new byte[CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES]; EncPlaintext plaintext = new EncPlaintext(); plaintext.data = new byte[ZenChainParams.ZC_ENCPLAINTEXT_SIZE]; - //decrypt cEnc by kEnc. - if (JLibsodium.cryptoAeadChacha20poly1305IetfDecrypt(new Chacha20poly1305IetfDecryptParams( - plaintext.data, null, - null, - ciphertext.data, ZenChainParams.ZC_ENCCIPHERTEXT_SIZE, - null, - 0, - cipherNonce, kEnc)) != 0) { + // decrypt cEnc by kEnc. + if (JLibsodium.cryptoAeadChacha20poly1305IetfDecrypt( + new Chacha20poly1305IetfDecryptParams( + plaintext.data, + null, + null, + ciphertext.data, + ZenChainParams.ZC_ENCCIPHERTEXT_SIZE, + null, + 0, + cipherNonce, + kEnc)) + != 0) { return Optional.empty(); } return Optional.of(plaintext); } - /** - * decrypt c_out to plain_out with ock generate ovk - */ + /** decrypt c_out to plain_out with ock generate ovk */ public static Optional attemptOutDecryption( OutCiphertext ciphertext, byte[] ovk, byte[] cv, byte[] cm, byte[] epk) throws ZksnarkException { byte[] ock = new byte[NOTEENCRYPTION_CIPHER_KEYSIZE]; - //generate ock by ovk, cv, cm, epk + // generate ock by ovk, cv, cm, epk prfOck(ock, ovk, cv, cm, epk); byte[] cipherNonce = new byte[CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES]; OutPlaintext plaintext = new OutPlaintext(); plaintext.data = new byte[ZenChainParams.ZC_OUTPLAINTEXT_SIZE]; - //decrypt out by ock, get esk, pkD - if (JLibsodium.cryptoAeadChacha20poly1305IetfDecrypt(new Chacha20poly1305IetfDecryptParams( - plaintext.data, null, - null, - ciphertext.data, ZenChainParams.ZC_OUTCIPHERTEXT_SIZE, - null, - 0, - cipherNonce, ock)) != 0) { + // decrypt out by ock, get esk, pkD + if (JLibsodium.cryptoAeadChacha20poly1305IetfDecrypt( + new Chacha20poly1305IetfDecryptParams( + plaintext.data, + null, + null, + ciphertext.data, + ZenChainParams.ZC_OUTCIPHERTEXT_SIZE, + null, + 0, + cipherNonce, + ock)) + != 0) { return Optional.empty(); } return Optional.of(plaintext); } - /** - * encrypt the message by ovk used for scanning - */ - public static Optional encryptBurnMessageByOvk(byte[] ovk, BigInteger toAmount, - byte[] transparentToAddress) - throws ZksnarkException { + /** encrypt the message by ovk used for scanning */ + public static Optional encryptBurnMessageByOvk( + byte[] ovk, BigInteger toAmount, byte[] transparentToAddress) throws ZksnarkException { byte[] plaintext = new byte[64]; byte[] amountArray = ByteUtil.bigIntegerToBytes(toAmount, 32); byte[] cipherNonce = new byte[12]; byte[] cipher = new byte[80]; System.arraycopy(amountArray, 0, plaintext, 0, 32); - System.arraycopy(transparentToAddress, 0, plaintext, 32, - 21); + System.arraycopy(transparentToAddress, 0, plaintext, 32, 21); - if (JLibsodium.cryptoAeadChacha20Poly1305IetfEncrypt(new Chacha20Poly1305IetfEncryptParams( - cipher, null, plaintext, - 64, null, 0, null, cipherNonce, ovk)) != 0) { + if (JLibsodium.cryptoAeadChacha20Poly1305IetfEncrypt( + new Chacha20Poly1305IetfEncryptParams( + cipher, null, plaintext, 64, null, 0, null, cipherNonce, ovk)) + != 0) { return Optional.empty(); } return Optional.of(cipher); } - /** - * decrypt the message by ovk used for scanning - */ + /** decrypt the message by ovk used for scanning */ public static Optional decryptBurnMessageByOvk(byte[] ovk, byte[] ciphertext) throws ZksnarkException { byte[] outPlaintext = new byte[64]; byte[] cipherNonce = new byte[12]; - if (JLibsodium.cryptoAeadChacha20poly1305IetfDecrypt(new Chacha20poly1305IetfDecryptParams( - outPlaintext, null, - null, - ciphertext, 80, - null, - 0, - cipherNonce, ovk)) != 0) { + if (JLibsodium.cryptoAeadChacha20poly1305IetfDecrypt( + new Chacha20poly1305IetfDecryptParams( + outPlaintext, null, null, ciphertext, 80, null, 0, cipherNonce, ovk)) + != 0) { return Optional.empty(); } return Optional.of(outPlaintext); @@ -284,29 +303,25 @@ public static Optional decryptBurnMessageByOvk(byte[] ovk, byte[] cipher public static class EncCiphertext { - @Getter - @Setter + @Getter @Setter private byte[] data = new byte[ZenChainParams.ZC_ENCCIPHERTEXT_SIZE]; // ZC_ENCCIPHERTEXT_SIZE } public static class EncPlaintext { - @Getter - @Setter + @Getter @Setter private byte[] data = new byte[ZenChainParams.ZC_ENCPLAINTEXT_SIZE]; // ZC_ENCPLAINTEXT_SIZE } public static class OutCiphertext { - @Getter - @Setter + @Getter @Setter private byte[] data = new byte[ZenChainParams.ZC_OUTCIPHERTEXT_SIZE]; // ZC_OUTCIPHERTEXT_SIZE } public static class OutPlaintext { - @Getter - @Setter + @Getter @Setter private byte[] data = new byte[ZenChainParams.ZC_OUTPLAINTEXT_SIZE]; // ZC_OUTPLAINTEXT_SIZE } } diff --git a/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/note/OutgoingPlaintext.java b/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/note/OutgoingPlaintext.java index 93931fcd..36eb2509 100644 --- a/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/note/OutgoingPlaintext.java +++ b/testcase/src/test/java/stest/tron/wallet/common/client/utils/zen/note/OutgoingPlaintext.java @@ -1,6 +1,5 @@ package stest.tron.wallet.common.client.utils.zen.note; - import java.util.Optional; import lombok.AllArgsConstructor; import lombok.Getter; @@ -13,26 +12,29 @@ @AllArgsConstructor public class OutgoingPlaintext { - @Getter - @Setter - private byte[] pkD; - @Getter - @Setter - private byte[] esk; + @Getter @Setter private byte[] pkD; + @Getter @Setter private byte[] esk; private static OutgoingPlaintext decode(Encryption.OutPlaintext outPlaintext) { byte[] data = outPlaintext.getData(); - OutgoingPlaintext ret = new OutgoingPlaintext(new byte[ZenChainParams.ZC_JUBJUB_SCALAR_SIZE], - new byte[ZenChainParams.ZC_JUBJUB_POINT_SIZE]); + OutgoingPlaintext ret = + new OutgoingPlaintext( + new byte[ZenChainParams.ZC_JUBJUB_SCALAR_SIZE], + new byte[ZenChainParams.ZC_JUBJUB_POINT_SIZE]); System.arraycopy(data, 0, ret.pkD, 0, ZenChainParams.ZC_JUBJUB_SCALAR_SIZE); - System.arraycopy(data, ZenChainParams.ZC_JUBJUB_SCALAR_SIZE, ret.esk, 0, ZenChainParams.ZC_JUBJUB_POINT_SIZE); + System.arraycopy( + data, + ZenChainParams.ZC_JUBJUB_SCALAR_SIZE, + ret.esk, + 0, + ZenChainParams.ZC_JUBJUB_POINT_SIZE); return ret; } - public static Optional decrypt(Encryption.OutCiphertext ciphertext, byte[] ovk, - byte[] cv, byte[] cm, byte[] epk) throws ZksnarkException { - Optional pt = Encryption - .attemptOutDecryption(ciphertext, ovk, cv, cm, epk); + public static Optional decrypt( + Encryption.OutCiphertext ciphertext, byte[] ovk, byte[] cv, byte[] cm, byte[] epk) + throws ZksnarkException { + Optional pt = Encryption.attemptOutDecryption(ciphertext, ovk, cv, cm, epk); if (!pt.isPresent()) { return Optional.empty(); } @@ -45,13 +47,16 @@ private OutPlaintext encode() { ret.setData(new byte[ZenChainParams.ZC_OUTPLAINTEXT_SIZE]); // ZC_OUTPLAINTEXT_SIZE = (ZC_JUBJUB_POINT_SIZE + ZC_JUBJUB_SCALAR_SIZE) System.arraycopy(pkD, 0, ret.getData(), 0, ZenChainParams.ZC_JUBJUB_SCALAR_SIZE); - System.arraycopy(esk, 0, ret.getData(), ZenChainParams.ZC_JUBJUB_SCALAR_SIZE, ZenChainParams.ZC_JUBJUB_POINT_SIZE); + System.arraycopy( + esk, + 0, + ret.getData(), + ZenChainParams.ZC_JUBJUB_SCALAR_SIZE, + ZenChainParams.ZC_JUBJUB_POINT_SIZE); return ret; } - /** - * encrypt plain_out with ock to c_out, use NoteEncryption.epk - */ + /** encrypt plain_out with ock to c_out, use NoteEncryption.epk */ public Encryption.OutCiphertext encrypt(byte[] ovk, byte[] cv, byte[] cm, NoteEncryption enc) throws ZksnarkException { OutPlaintext pt = this.encode(); diff --git a/testcase/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage002.java b/testcase/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage002.java index 136f21f4..b5c20ffa 100644 --- a/testcase/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage002.java +++ b/testcase/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage002.java @@ -8,7 +8,6 @@ import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.AccountResourceMessage; @@ -19,55 +18,56 @@ import org.tron.protos.Protocol.TransactionInfo; import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; -import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; @Slf4j @MultiNode -public class ContractLinkage002 extends TronBaseTest { ECKey ecKey1 = new ECKey(Utils.getRandom()); +public class ContractLinkage002 extends TronBaseTest { + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] linkage002Address = ecKey1.getAddress(); - String linkage002Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; + String linkage002Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ + @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(linkage002Key); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(linkage002Key); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } @Test(enabled = true) public void updateSetting() { - String sendcoin = PublicMethod - .sendcoinGetTransactionId(linkage002Address, 200000000000L, fromAddress, - foundationKey2, blockingStubFull); + String sendcoin = + PublicMethod.sendcoinGetTransactionId( + linkage002Address, 200000000000L, foundationAddress2, foundationKey2, blockingStubFull); Account info; PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById0 = null; infoById0 = PublicMethod.getTransactionInfoById(sendcoin, blockingStubFull); logger.info("infoById0 " + infoById0.get()); - Assert.assertEquals(ByteArray.toHexString(infoById0.get().getContractResult(0).toByteArray()), - ""); + Assert.assertEquals( + ByteArray.toHexString(infoById0.get().getContractResult(0).toByteArray()), ""); Assert.assertEquals(infoById0.get().getResult().getNumber(), 0); Optional ById = PublicMethod.getTransactionById(sendcoin, blockingStubFull); - Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(), - SUCCESS_VALUE); + Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(), SUCCESS_VALUE); Assert.assertEquals(ById.get().getRet(0).getContractRetValue(), SUCCESS_VALUE); Assert.assertEquals(ById.get().getRet(0).getContractRet(), contractResult.SUCCESS); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(linkage002Address, 50000000L, - 3, 1, linkage002Key, blockingStubFull)); - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(linkage002Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + linkage002Address, 50000000L, 3, 1, linkage002Key, blockingStubFull)); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(linkage002Address, blockingStubFull); info = PublicMethod.queryAccount(linkage002Address, blockingStubFull); Long beforeBalance = info.getBalance(); Long beforeEnergyLimit = resourceInfo.getEnergyLimit(); @@ -91,14 +91,25 @@ public void updateSetting() { String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - //Set the consumeUserResourcePercent is -1,Nothing change. + // Set the consumeUserResourcePercent is -1,Nothing change. byte[] contractAddress; - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", - maxFeeLimit, 0L, -1, null, linkage002Key, linkage002Address, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + -1, + null, + linkage002Key, + linkage002Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account infoafter = PublicMethod.queryAccount(linkage002Address, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(linkage002Address, - blockingStubFull1); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(linkage002Address, blockingStubFull1); Long afterBalance = infoafter.getBalance(); Long afterEnergyLimit = resourceInfoafter.getEnergyLimit(); Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); @@ -118,9 +129,9 @@ public void updateSetting() { Assert.assertTrue(afterEnergyUsed == 0); Assert.assertTrue(afterFreeNetUsed > 0); - //Set the consumeUserResourcePercent is 101,Nothing change. - AccountResourceMessage resourceInfo3 = PublicMethod.getAccountResource(linkage002Address, - blockingStubFull); + // Set the consumeUserResourcePercent is 101,Nothing change. + AccountResourceMessage resourceInfo3 = + PublicMethod.getAccountResource(linkage002Address, blockingStubFull); Account info3 = PublicMethod.queryAccount(linkage002Address, blockingStubFull); Long beforeBalance3 = info3.getBalance(); Long beforeEnergyLimit3 = resourceInfo3.getEnergyLimit(); @@ -137,11 +148,23 @@ public void updateSetting() { logger.info("beforeNetUsed3:" + beforeNetUsed3); logger.info("beforeFreeNetUsed3:" + beforeFreeNetUsed3); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 101, null, linkage002Key, linkage002Address, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 101, + null, + linkage002Key, + linkage002Address, + blockingStubFull); + PublicMethod.waitProduceNextBlock(blockingStubFull); Account infoafter3 = PublicMethod.queryAccount(linkage002Address, blockingStubFull1); - AccountResourceMessage resourceInfoafter3 = PublicMethod.getAccountResource(linkage002Address, - blockingStubFull1); + AccountResourceMessage resourceInfoafter3 = + PublicMethod.getAccountResource(linkage002Address, blockingStubFull1); Long afterBalance3 = infoafter3.getBalance(); Long afterEnergyLimit3 = resourceInfoafter3.getEnergyLimit(); Long afterEnergyUsed3 = resourceInfoafter3.getEnergyUsed(); @@ -162,16 +185,29 @@ public void updateSetting() { Assert.assertTrue(afterEnergyUsed3 == 0); Assert.assertTrue(afterFreeNetUsed3 > 0); - //Set consumeUserResourcePercent is 100,balance not change,use FreeNet freezeBalanceGetEnergy. + // Set consumeUserResourcePercent is 100,balance not change,use FreeNet freezeBalanceGetEnergy. - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, linkage002Key, linkage002Address, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + linkage002Key, + linkage002Address, + blockingStubFull); + PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getConsumeUserResourcePercent() == 100); - //Set the consumeUserResourcePercent is 0,balance not change,use FreeNet freezeBalanceGetEnergy. - AccountResourceMessage resourceInfo2 = PublicMethod.getAccountResource(linkage002Address, - blockingStubFull); + // Set the consumeUserResourcePercent is 0,balance not change,use FreeNet + // freezeBalanceGetEnergy. + AccountResourceMessage resourceInfo2 = + PublicMethod.getAccountResource(linkage002Address, blockingStubFull); Account info2 = PublicMethod.queryAccount(linkage002Address, blockingStubFull); Long beforeBalance2 = info2.getBalance(); Long beforeEnergyLimit2 = resourceInfo2.getEnergyLimit(); @@ -188,12 +224,23 @@ public void updateSetting() { logger.info("beforeNetUsed2:" + beforeNetUsed2); logger.info("beforeFreeNetUsed2:" + beforeFreeNetUsed2); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 0, null, linkage002Key, linkage002Address, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + null, + linkage002Key, + linkage002Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account infoafter2 = PublicMethod.queryAccount(linkage002Address, blockingStubFull1); - AccountResourceMessage resourceInfoafter2 = PublicMethod.getAccountResource(linkage002Address, - blockingStubFull1); + AccountResourceMessage resourceInfoafter2 = + PublicMethod.getAccountResource(linkage002Address, blockingStubFull1); Long afterBalance2 = infoafter2.getBalance(); Long afterEnergyLimit2 = resourceInfoafter2.getEnergyLimit(); Long afterEnergyUsed2 = resourceInfoafter2.getEnergyUsed(); @@ -216,18 +263,19 @@ public void updateSetting() { smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getConsumeUserResourcePercent() == 0); - //Update the consumeUserResourcePercent setting. - Assert.assertTrue(PublicMethod.updateSetting(contractAddress, 66L, - linkage002Key, linkage002Address, blockingStubFull)); + // Update the consumeUserResourcePercent setting. + Assert.assertTrue( + PublicMethod.updateSetting( + contractAddress, 66L, linkage002Key, linkage002Address, blockingStubFull)); smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getConsumeUserResourcePercent() == 66); - //Updaate the consumeUserResourcePercent setting with -1 and 101 - Assert.assertFalse(PublicMethod.updateSetting(contractAddress, -1L, - linkage002Key, linkage002Address, blockingStubFull)); - Assert.assertFalse(PublicMethod.updateSetting(contractAddress, 101L, - linkage002Key, linkage002Address, blockingStubFull)); - + // Updaate the consumeUserResourcePercent setting with -1 and 101 + Assert.assertFalse( + PublicMethod.updateSetting( + contractAddress, -1L, linkage002Key, linkage002Address, blockingStubFull)); + Assert.assertFalse( + PublicMethod.updateSetting( + contractAddress, 101L, linkage002Key, linkage002Address, blockingStubFull)); } } - diff --git a/testcase/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage003.java b/testcase/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage003.java index 41d2ff66..43c8e755 100644 --- a/testcase/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage003.java +++ b/testcase/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage003.java @@ -6,7 +6,6 @@ import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.AccountResourceMessage; @@ -15,44 +14,45 @@ import org.tron.protos.Protocol.TransactionInfo; import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; -import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; @Slf4j @MultiNode public class ContractLinkage003 extends TronBaseTest { - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key1"); private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey003); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] linkage003Address = ecKey1.getAddress(); - String linkage002Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; + String linkage002Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(linkage002Key); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(linkage002Key); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } @Test(enabled = true) public void deployWhenNoEnergy() { - Assert.assertTrue(PublicMethod.sendcoin(linkage003Address, 200000000L, fromAddress, - testKey003, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + linkage003Address, 200000000L, fromAddress, testKey003, blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(linkage003Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(linkage003Address, blockingStubFull); info = PublicMethod.queryAccount(linkage003Address, blockingStubFull); Long beforeBalance = info.getBalance(); Long beforeEnergyLimit = resourceInfo.getEnergyLimit(); @@ -76,10 +76,20 @@ public void deployWhenNoEnergy() { String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - //use FreeNet and balance,EnergyUsed==0. - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 0L, 0, null, linkage002Key, linkage003Address, blockingStubFull); + // use FreeNet and balance,EnergyUsed==0. + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + null, + linkage002Key, + linkage003Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -98,8 +108,8 @@ public void deployWhenNoEnergy() { logger.info("netFee:" + netFee); Account infoafter = PublicMethod.queryAccount(linkage003Address, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(linkage003Address, - blockingStubFull1); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(linkage003Address, blockingStubFull1); Long afterBalance = infoafter.getBalance(); Long afterEnergyLimit = resourceInfoafter.getEnergyLimit(); Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); @@ -121,7 +131,5 @@ public void deployWhenNoEnergy() { Assert.assertTrue(afterEnergyUsed == 0L); Assert.assertTrue(afterFreeNetUsed > 0L); Assert.assertTrue(afterNetUsed == 0L); - } } - diff --git a/testcase/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage004.java b/testcase/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage004.java index 0aa62621..78fd6d1f 100644 --- a/testcase/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage004.java +++ b/testcase/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage004.java @@ -6,7 +6,6 @@ import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.AccountResourceMessage; @@ -14,19 +13,19 @@ import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.TransactionInfo; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; -import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; @Slf4j @MultiNode public class ContractLinkage004 extends TronBaseTest { - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key1"); private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey003); String contractName; String code; @@ -55,17 +54,17 @@ public class ContractLinkage004 extends TronBaseTest { Long netFee; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] linkage004Address = ecKey1.getAddress(); - String linkage004Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; + String linkage004Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ + @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(linkage004Key); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(linkage004Key); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } @@ -75,13 +74,16 @@ public void test1GetTransactionInfoById() { linkage004Address = ecKey1.getAddress(); linkage004Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(linkage004Address, 2000000000000L, fromAddress, - testKey003, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalance(linkage004Address, 10000000L, - 3, linkage004Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + linkage004Address, 2000000000000L, fromAddress, testKey003, blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalance( + linkage004Address, 10000000L, 3, linkage004Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(linkage004Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(linkage004Address, blockingStubFull); info = PublicMethod.queryAccount(linkage004Address, blockingStubFull); beforeBalance = info.getBalance(); beforeEnergyLimit = resourceInfo.getEnergyLimit(); @@ -104,9 +106,20 @@ public void test1GetTransactionInfoById() { String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - //use freezeBalanceGetNet,Balance .No freezeBalanceGetenergy - String txid = PublicMethod.deployContractAndGetTransactionInfoById(contractName, abi, code, - "", maxFeeLimit, 0L, 50, null, linkage004Key, linkage004Address, blockingStubFull); + // use freezeBalanceGetNet,Balance .No freezeBalanceGetenergy + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 50, + null, + linkage004Key, + linkage004Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull1); Optional infoById = null; @@ -126,8 +139,8 @@ public void test1GetTransactionInfoById() { logger.info("netFee:" + netFee); Account infoafter = PublicMethod.queryAccount(linkage004Address, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(linkage004Address, - blockingStubFull1); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(linkage004Address, blockingStubFull1); afterBalance = infoafter.getBalance(); afterEnergyLimit = resourceInfoafter.getEnergyLimit(); afterEnergyUsed = resourceInfoafter.getEnergyUsed(); @@ -152,10 +165,10 @@ public void test1GetTransactionInfoById() { @Test(enabled = true) public void test2FeeLimitIsTooSmall() { - //When the fee limit is only short with 1 sun,failed.use freezeBalanceGetNet. + // When the fee limit is only short with 1 sun,failed.use freezeBalanceGetNet. maxFeeLimit = currentFee - 1L; - AccountResourceMessage resourceInfo1 = PublicMethod.getAccountResource(linkage004Address, - blockingStubFull); + AccountResourceMessage resourceInfo1 = + PublicMethod.getAccountResource(linkage004Address, blockingStubFull); Account info1 = PublicMethod.queryAccount(linkage004Address, blockingStubFull); Long beforeBalance1 = info1.getBalance(); Long beforeEnergyLimit1 = resourceInfo1.getEnergyLimit(); @@ -179,13 +192,24 @@ public void test2FeeLimitIsTooSmall() { String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - String txid = PublicMethod.deployContractAndGetTransactionInfoById(contractName, abi, code, - "", maxFeeLimit, 0L, 50, null, linkage004Key, linkage004Address, blockingStubFull); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 50, + null, + linkage004Key, + linkage004Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull1); - Optional infoById1 = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById1 = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); Long fee1 = infoById1.get().getFee(); Long energyFee1 = infoById1.get().getReceipt().getEnergyFee(); @@ -200,8 +224,8 @@ public void test2FeeLimitIsTooSmall() { logger.info("netFee1:" + netFee1); Account infoafter1 = PublicMethod.queryAccount(linkage004Address, blockingStubFull1); - AccountResourceMessage resourceInfoafter1 = PublicMethod.getAccountResource(linkage004Address, - blockingStubFull1); + AccountResourceMessage resourceInfoafter1 = + PublicMethod.getAccountResource(linkage004Address, blockingStubFull1); Long afterBalance1 = infoafter1.getBalance(); Long afterEnergyLimit1 = resourceInfoafter1.getEnergyLimit(); Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); @@ -223,10 +247,10 @@ public void test2FeeLimitIsTooSmall() { Assert.assertTrue(afterEnergyUsed1 == 0); Assert.assertTrue(beforeNetUsed1 < afterNetUsed1); - //When the fee limit is just ok.use energyFee,freezeBalanceGetNet,balance change. + // When the fee limit is just ok.use energyFee,freezeBalanceGetNet,balance change. maxFeeLimit = currentFee; - AccountResourceMessage resourceInfo2 = PublicMethod.getAccountResource(linkage004Address, - blockingStubFull); + AccountResourceMessage resourceInfo2 = + PublicMethod.getAccountResource(linkage004Address, blockingStubFull); Account info2 = PublicMethod.queryAccount(linkage004Address, blockingStubFull); Long beforeBalance2 = info2.getBalance(); Long beforeEnergyLimit2 = resourceInfo2.getEnergyLimit(); @@ -242,12 +266,23 @@ public void test2FeeLimitIsTooSmall() { logger.info("beforeNetLimit2:" + beforeNetLimit2); logger.info("beforeNetUsed2:" + beforeNetUsed2); logger.info("beforeFreeNetUsed2:" + beforeFreeNetUsed2); - txid = PublicMethod.deployContractAndGetTransactionInfoById(contractName, abi, code, - "", maxFeeLimit, 0L, 50, null, linkage004Key, linkage004Address, blockingStubFull); - //logger.info("testFeeLimitIsTooSmall, the txid is " + txid); + txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 50, + null, + linkage004Key, + linkage004Address, + blockingStubFull); + // logger.info("testFeeLimitIsTooSmall, the txid is " + txid); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById2 = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById2 = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Long energyUsageTotal2 = infoById2.get().getReceipt().getEnergyUsageTotal(); Long fee2 = infoById2.get().getFee(); Long energyFee2 = infoById2.get().getReceipt().getEnergyFee(); @@ -261,8 +296,8 @@ public void test2FeeLimitIsTooSmall() { logger.info("energyUsed2:" + energyUsed2); logger.info("netFee2:" + netFee2); Account infoafter2 = PublicMethod.queryAccount(linkage004Address, blockingStubFull1); - AccountResourceMessage resourceInfoafter2 = PublicMethod.getAccountResource(linkage004Address, - blockingStubFull1); + AccountResourceMessage resourceInfoafter2 = + PublicMethod.getAccountResource(linkage004Address, blockingStubFull1); Long afterBalance2 = infoafter2.getBalance(); Long afterEnergyLimit2 = resourceInfoafter2.getEnergyLimit(); Long afterEnergyUsed2 = resourceInfoafter2.getEnergyUsed(); @@ -286,4 +321,3 @@ public void test2FeeLimitIsTooSmall() { currentFee = fee2; } } - diff --git a/testcase/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage007.java b/testcase/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage007.java index 4626c60a..16c5c048 100644 --- a/testcase/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage007.java +++ b/testcase/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage007.java @@ -6,7 +6,6 @@ import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.AccountResourceMessage; @@ -14,46 +13,46 @@ import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.TransactionInfo; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; -import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; @Slf4j @MultiNode -public class ContractLinkage007 extends TronBaseTest { String contractName; +public class ContractLinkage007 extends TronBaseTest { + String contractName; String code; String abi; byte[] contractAddress; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] linkage007Address = ecKey1.getAddress(); - String linkage007Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; + String linkage007Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(linkage007Key); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(linkage007Key); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - } @Test(enabled = true) public void testRangeOfFeeLimit() { - //Now the feelimit range is 0-1000000000,including 0 and 1000000000 - Assert.assertTrue(PublicMethod.sendcoin(linkage007Address, 2000000000L, fromAddress, - foundationKey2, blockingStubFull)); - - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(linkage007Address, - blockingStubFull); + // Now the feelimit range is 0-1000000000,including 0 and 1000000000 + Assert.assertTrue( + PublicMethod.sendcoin( + linkage007Address, 2000000000L, foundationAddress2, foundationKey2, blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(linkage007Address, blockingStubFull); Account info; info = PublicMethod.queryAccount(linkage007Address, blockingStubFull); Long beforeBalance = info.getBalance(); @@ -70,7 +69,7 @@ public void testRangeOfFeeLimit() { logger.info("beforeNetLimit:" + beforeNetLimit); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - //When the feelimit is large, the deploy will be failed,No used everything. + // When the feelimit is large, the deploy will be failed,No used everything. String filePath = "./src/test/resources/soliditycode/contractLinkage002.sol"; String contractName = "divideIHaveArgsReturnStorage"; @@ -80,13 +79,23 @@ public void testRangeOfFeeLimit() { String abi = retMap.get("abI").toString(); String txid; - txid = PublicMethod.deployContractAndGetTransactionInfoById(contractName, abi, code, - "", maxFeeLimit + 1, 0L, 100, null, linkage007Key, - linkage007Address, blockingStubFull); + txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit + 1, + 0L, + 100, + null, + linkage007Key, + linkage007Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account infoafter = PublicMethod.queryAccount(linkage007Address, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(linkage007Address, - blockingStubFull1); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(linkage007Address, blockingStubFull1); Long afterBalance = infoafter.getBalance(); Long afterEnergyLimit = resourceInfoafter.getEnergyLimit(); Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); @@ -107,8 +116,8 @@ public void testRangeOfFeeLimit() { Assert.assertTrue(afterFreeNetUsed == 0); Assert.assertTrue(txid == null); - AccountResourceMessage resourceInfo1 = PublicMethod.getAccountResource(linkage007Address, - blockingStubFull); + AccountResourceMessage resourceInfo1 = + PublicMethod.getAccountResource(linkage007Address, blockingStubFull); Account info1 = PublicMethod.queryAccount(linkage007Address, blockingStubFull); Long beforeBalance1 = info1.getBalance(); Long beforeEnergyLimit1 = resourceInfo1.getEnergyLimit(); @@ -124,14 +133,24 @@ public void testRangeOfFeeLimit() { logger.info("beforeNetLimit1:" + beforeNetLimit1); logger.info("beforeNetUsed1:" + beforeNetUsed1); logger.info("beforeFreeNetUsed1:" + beforeFreeNetUsed1); - //When the feelimit is 0, the deploy will be failed.Only use FreeNet,balance not change. - txid = PublicMethod.deployContractAndGetTransactionInfoById(contractName, abi, code, - "", 0L, 0L, 100, null, linkage007Key, - linkage007Address, blockingStubFull); + // When the feelimit is 0, the deploy will be failed.Only use FreeNet,balance not change. + txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + 0L, + 0L, + 100, + null, + linkage007Key, + linkage007Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account infoafter1 = PublicMethod.queryAccount(linkage007Address, blockingStubFull1); - AccountResourceMessage resourceInfoafter1 = PublicMethod.getAccountResource(linkage007Address, - blockingStubFull1); + AccountResourceMessage resourceInfoafter1 = + PublicMethod.getAccountResource(linkage007Address, blockingStubFull1); Long afterBalance1 = infoafter1.getBalance(); Long afterEnergyLimit1 = resourceInfoafter1.getEnergyLimit(); Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); @@ -156,9 +175,9 @@ public void testRangeOfFeeLimit() { infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 1); - //Deploy the contract.success.use FreeNet,EnergyFee.balcne change - AccountResourceMessage resourceInfo2 = PublicMethod.getAccountResource(linkage007Address, - blockingStubFull); + // Deploy the contract.success.use FreeNet,EnergyFee.balcne change + AccountResourceMessage resourceInfo2 = + PublicMethod.getAccountResource(linkage007Address, blockingStubFull); Account info2 = PublicMethod.queryAccount(linkage007Address, blockingStubFull); Long beforeBalance2 = info2.getBalance(); Long beforeEnergyLimit2 = resourceInfo2.getEnergyLimit(); @@ -174,12 +193,22 @@ public void testRangeOfFeeLimit() { logger.info("beforeNetLimit2:" + beforeNetLimit2); logger.info("beforeNetUsed2:" + beforeNetUsed2); logger.info("beforeFreeNetUsed2:" + beforeFreeNetUsed2); - txid = PublicMethod.deployContractAndGetTransactionInfoById(contractName, abi, code, - "", maxFeeLimit, 0L, 100, null, linkage007Key, - linkage007Address, blockingStubFull); + txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + linkage007Key, + linkage007Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById2 = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById2 = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Long energyUsageTotal2 = infoById2.get().getReceipt().getEnergyUsageTotal(); Long fee2 = infoById2.get().getFee(); Long energyFee2 = infoById2.get().getReceipt().getEnergyFee(); @@ -193,8 +222,8 @@ public void testRangeOfFeeLimit() { logger.info("energyUsed2:" + energyUsed2); logger.info("netFee2:" + netFee2); Account infoafter2 = PublicMethod.queryAccount(linkage007Address, blockingStubFull1); - AccountResourceMessage resourceInfoafter2 = PublicMethod.getAccountResource(linkage007Address, - blockingStubFull1); + AccountResourceMessage resourceInfoafter2 = + PublicMethod.getAccountResource(linkage007Address, blockingStubFull1); Long afterBalance2 = infoafter2.getBalance(); Long afterEnergyLimit2 = resourceInfoafter2.getEnergyLimit(); Long afterEnergyUsed2 = resourceInfoafter2.getEnergyUsed(); @@ -216,9 +245,10 @@ public void testRangeOfFeeLimit() { Assert.assertTrue(infoById2.get().getResultValue() == 0); contractAddress = infoById2.get().getContractAddress().toByteArray(); - //When the feelimit is large, the trigger will be failed.Only use FreeNetUsed,Balance not change - AccountResourceMessage resourceInfo3 = PublicMethod.getAccountResource(linkage007Address, - blockingStubFull); + // When the feelimit is large, the trigger will be failed.Only use FreeNetUsed,Balance not + // change + AccountResourceMessage resourceInfo3 = + PublicMethod.getAccountResource(linkage007Address, blockingStubFull); Account info3 = PublicMethod.queryAccount(linkage007Address, blockingStubFull); Long beforeBalance3 = info3.getBalance(); Long beforeEnergyLimit3 = resourceInfo3.getEnergyLimit(); @@ -234,15 +264,23 @@ public void testRangeOfFeeLimit() { logger.info("beforeNetLimit3:" + beforeNetLimit3); logger.info("beforeNetUsed3:" + beforeNetUsed3); logger.info("beforeFreeNetUsed3:" + beforeFreeNetUsed3); - //String initParmes = "\"" + Base58.encode58Check(fromAddress) + "\",\"63\""; + // String initParmes = "\"" + Base58.encode58Check(fromAddress) + "\",\"63\""; String num = "4" + "," + "2"; - txid = PublicMethod.triggerContract(contractAddress, - "divideIHaveArgsReturn(int256,int256)", num, false, - 1000, maxFeeLimit + 1, linkage007Address, linkage007Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "divideIHaveArgsReturn(int256,int256)", + num, + false, + 1000, + maxFeeLimit + 1, + linkage007Address, + linkage007Key, + blockingStubFull); Account infoafter3 = PublicMethod.queryAccount(linkage007Address, blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage resourceInfoafter3 = PublicMethod.getAccountResource(linkage007Address, - blockingStubFull1); + AccountResourceMessage resourceInfoafter3 = + PublicMethod.getAccountResource(linkage007Address, blockingStubFull1); Long afterBalance3 = infoafter3.getBalance(); Long afterEnergyLimit3 = resourceInfoafter3.getEnergyLimit(); Long afterEnergyUsed3 = resourceInfoafter3.getEnergyUsed(); @@ -263,9 +301,9 @@ public void testRangeOfFeeLimit() { Assert.assertTrue(afterFreeNetUsed3 > beforeNetUsed3); Assert.assertTrue(afterNetUsed3 == 0); Assert.assertTrue(afterEnergyUsed3 == 0); - //When the feelimit is 0, the trigger will be failed.Only use FreeNetUsed,Balance not change - AccountResourceMessage resourceInfo4 = PublicMethod.getAccountResource(linkage007Address, - blockingStubFull); + // When the feelimit is 0, the trigger will be failed.Only use FreeNetUsed,Balance not change + AccountResourceMessage resourceInfo4 = + PublicMethod.getAccountResource(linkage007Address, blockingStubFull); Account info4 = PublicMethod.queryAccount(linkage007Address, blockingStubFull); Long beforeBalance4 = info4.getBalance(); Long beforeEnergyLimit4 = resourceInfo4.getEnergyLimit(); @@ -281,12 +319,21 @@ public void testRangeOfFeeLimit() { logger.info("beforeNetLimit4:" + beforeNetLimit4); logger.info("beforeNetUsed4:" + beforeNetUsed4); logger.info("beforeFreeNetUsed4:" + beforeFreeNetUsed4); - txid = PublicMethod.triggerContract(contractAddress, - "divideIHaveArgsReturn(int256,int256)", num, false, - 1000, maxFeeLimit + 1, linkage007Address, linkage007Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "divideIHaveArgsReturn(int256,int256)", + num, + false, + 1000, + maxFeeLimit + 1, + linkage007Address, + linkage007Key, + blockingStubFull); + PublicMethod.waitProduceNextBlock(blockingStubFull); Account infoafter4 = PublicMethod.queryAccount(linkage007Address, blockingStubFull1); - AccountResourceMessage resourceInfoafter4 = PublicMethod.getAccountResource(linkage007Address, - blockingStubFull1); + AccountResourceMessage resourceInfoafter4 = + PublicMethod.getAccountResource(linkage007Address, blockingStubFull1); Long afterBalance4 = infoafter4.getBalance(); Long afterEnergyLimit4 = resourceInfoafter4.getEnergyLimit(); Long afterEnergyUsed4 = resourceInfoafter4.getEnergyUsed(); @@ -311,4 +358,3 @@ public void testRangeOfFeeLimit() { Assert.assertTrue(infoById.get().getFee() == 0); } } - diff --git a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario001.java b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario001.java index 603575f4..7e250d47 100644 --- a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario001.java +++ b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario001.java @@ -5,34 +5,35 @@ import java.util.HashMap; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.AccountResourceMessage; import org.tron.api.WalletGrpc; import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; -import stest.tron.wallet.common.client.utils.TronBaseTest; @Slf4j -public class ContractScenario001 extends TronBaseTest { private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); +public class ContractScenario001 extends TronBaseTest { + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contract001Address = ecKey1.getAddress(); - String contract001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(0); /** - * constructor. - */ + String contract001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + public void beforeClass() { + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } @@ -43,13 +44,16 @@ public void deployAddressDemo() { contract001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); PublicMethod.printAddress(contract001Key); - Assert.assertTrue(PublicMethod.sendcoin(contract001Address, 20000000L, toAddress, - testKey003, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(contract001Address, 15000000L, - 3, 1, contract001Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + contract001Address, 20000000L, toAddress, testKey003, blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + contract001Address, 15000000L, 3, 1, contract001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull1); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(contract001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(contract001Address, blockingStubFull); Long energyLimit = accountResource.getEnergyLimit(); Long energyUsage = accountResource.getEnergyUsed(); Long balanceBefore = PublicMethod.queryAccount(contract001Key, blockingStubFull).getBalance(); @@ -64,8 +68,20 @@ public void deployAddressDemo() { String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - byte[] contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contract001Key, contract001Address, blockingStubFull); + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contract001Key, + contract001Address, + blockingStubFull); + PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi() != null); @@ -85,4 +101,3 @@ public void deployAddressDemo() { Assert.assertEquals(balanceBefore, balanceAfter); } } - diff --git a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario003.java b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario003.java index e49f026d..cfc838e3 100644 --- a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario003.java +++ b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario003.java @@ -6,7 +6,6 @@ import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.AccountResourceMessage; @@ -16,28 +15,29 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; -import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; @Slf4j @MultiNode -public class ContractScenario003 extends TronBaseTest { ECKey ecKey1 = new ECKey(Utils.getRandom()); +public class ContractScenario003 extends TronBaseTest { + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contract003Address = ecKey1.getAddress(); - String contract003Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; - private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); /** - * constructor. - */ + String contract003Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contract003Key); logger.info(Long.toString(PublicMethod.queryAccount(contract003Key, blockingStubFull) - .getBalance())); - channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contract003Key); + logger.info( + Long.toString(PublicMethod.queryAccount(contract003Key, blockingStubFull).getBalance())); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } @@ -47,11 +47,12 @@ public void deployErc223() { contract003Address = ecKey1.getAddress(); contract003Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(contract003Address, 500000000L, foundationAddress2, - foundationKey2, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + contract003Address, 500000000L, foundationAddress2, foundationKey2, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(contract003Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(contract003Address, blockingStubFull); Long energyLimit = accountResource.getEnergyLimit(); Long energyUsage = accountResource.getEnergyUsed(); Long balanceBefore = PublicMethod.queryAccount(contract003Key, blockingStubFull).getBalance(); @@ -67,17 +68,28 @@ public void deployErc223() { String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - String txid = PublicMethod.deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 100, null, contract003Key, contract003Address, blockingStubFull); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contract003Key, + contract003Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull1); logger.info(txid); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); com.google.protobuf.ByteString contractAddress = infoById.get().getContractAddress(); - SmartContract smartContract = PublicMethod - .getContract(contractAddress.toByteArray(), blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(contractAddress.toByteArray(), blockingStubFull); Assert.assertTrue(smartContract.getAbi() != null); Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); @@ -86,8 +98,8 @@ public void deployErc223() { accountResource = PublicMethod.getAccountResource(contract003Address, blockingStubFull1); energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); - Long balanceAfter = PublicMethod.queryAccount(contract003Address, blockingStubFull1) - .getBalance(); + Long balanceAfter = + PublicMethod.queryAccount(contract003Address, blockingStubFull1).getBalance(); logger.info("after energy limit is " + Long.toString(energyLimit)); logger.info("after energy usage is " + Long.toString(energyUsage)); @@ -99,4 +111,3 @@ public void deployErc223() { Assert.assertTrue(balanceBefore == balanceAfter + infoById.get().getFee()); } } - diff --git a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario004.java b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario004.java index f90483e1..2a6eac7c 100644 --- a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario004.java +++ b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario004.java @@ -13,84 +13,109 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class ContractScenario004 extends TronBaseTest { ECKey ecKey1 = new ECKey(Utils.getRandom()); +public class ContractScenario004 extends TronBaseTest { + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contract004Address = ecKey1.getAddress(); - String contract004Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); /** - * constructor. - */ + String contract004Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contract004Key); } + PublicMethod.printAddress(contract004Key); + } - @Test(enabled = true, groups = {"contract", "smoke"}) + @Test( + enabled = true, + groups = {"contract", "smoke"}) public void deployErc20TronTokenWithoutData() { - Assert.assertTrue(PublicMethod.sendcoin(contract004Address, 200000000L, foundationAddress, - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(contract004Address, 100000000L, - 3, 1, contract004Key, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(contract004Address, - blockingStubFull); - Long energyLimit = accountResource.getEnergyLimit(); - Long energyUsage = accountResource.getEnergyUsed(); + Assert.assertTrue( + PublicMethod.sendcoin( + contract004Address, 200000000L, foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + contract004Address, 100000000L, 3, 1, contract004Key, blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(contract004Address, blockingStubFull); + Long energyLimit = accountResource.getEnergyLimit(); + Long energyUsage = accountResource.getEnergyUsed(); logger.info("before energy limit is " + Long.toString(energyLimit)); logger.info("before energy usage is " + Long.toString(energyUsage)); - String filePath = "./src/test/resources/soliditycode//contractScenario004.sol"; - String contractName = "TronToken"; + String filePath = "./src/test/resources/soliditycode//contractScenario004.sol"; + String contractName = "TronToken"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contract004Key, contract004Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contract004Key, + contract004Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - System.out.println(info); + Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(info.get().getResultValue() == 1); } - @Test(enabled = true, groups = {"contract", "smoke"}) + @Test( + enabled = true, + groups = {"contract", "smoke"}) public void deployErc20TronTokenWithData() { - Assert.assertTrue(PublicMethod - .sendcoin(contract004Address, 200000000L, foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(contract004Address, 100000000L, - 3, 1, contract004Key, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(contract004Address, - blockingStubFull); - Long energyLimit = accountResource.getEnergyLimit(); - Long energyUsage = accountResource.getEnergyUsed(); + Assert.assertTrue( + PublicMethod.sendcoin( + contract004Address, 200000000L, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + contract004Address, 100000000L, 3, 1, contract004Key, blockingStubFull)); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(contract004Address, blockingStubFull); + Long energyLimit = accountResource.getEnergyLimit(); + Long energyUsage = accountResource.getEnergyUsed(); logger.info("before energy limit is " + Long.toString(energyLimit)); logger.info("before energy usage is " + Long.toString(energyUsage)); - String filePath = "./src/test/resources/soliditycode//contractScenario004.sol"; - String contractName = "TronToken"; + String filePath = "./src/test/resources/soliditycode//contractScenario004.sol"; + String contractName = "TronToken"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String constructorStr = "constructor(address)"; - String data = "\"" + Base58.encode58Check(contract004Address) + "\""; - String txid = PublicMethod - .deployContractWithConstantParame(contractName, abi, code, constructorStr, data, "", - maxFeeLimit, 0L, 100, null, contract004Key, contract004Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String constructorStr = "constructor(address)"; + String data = "\"" + Base58.encode58Check(contract004Address) + "\""; + String txid = + PublicMethod.deployContractWithConstantParame( + contractName, + abi, + code, + constructorStr, + data, + "", + maxFeeLimit, + 0L, + 100, + null, + contract004Key, + contract004Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); System.out.println(info); Assert.assertTrue(info.get().getResultValue() == 0); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario005.java b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario005.java index d174b982..84b728b9 100644 --- a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario005.java +++ b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario005.java @@ -9,50 +9,63 @@ import org.testng.annotations.Test; import org.tron.api.GrpcAPI.AccountResourceMessage; import org.tron.protos.Protocol.TransactionInfo; -import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class ContractScenario005 extends TronBaseTest { ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contract005Address = ecKey1.getAddress(); - String contract005Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); /** - * constructor. - */ + String contract005Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contract005Key); } + PublicMethod.printAddress(contract005Key); + } - @Test(enabled = false, groups = {"contract", "smoke"}) + @Test( + enabled = false, + groups = {"contract", "smoke"}) public void deployIcoContract() { - Assert.assertTrue(PublicMethod.sendcoin(contract005Address, 200000000L, foundationAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(contract005Address, 10000000L, - 3, 1, contract005Key, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(contract005Address, - blockingStubFull); - Long energyLimit = accountResource.getEnergyLimit(); - Long energyUsage = accountResource.getEnergyUsed(); + Assert.assertTrue( + PublicMethod.sendcoin( + contract005Address, 200000000L, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + contract005Address, 10000000L, 3, 1, contract005Key, blockingStubFull)); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(contract005Address, blockingStubFull); + Long energyLimit = accountResource.getEnergyLimit(); + Long energyUsage = accountResource.getEnergyUsed(); logger.info("before energy limit is " + Long.toString(energyLimit)); logger.info("before energy usage is " + Long.toString(energyUsage)); - String filePath = "./src/test/resources/soliditycode/contractScenario005.sol"; - String contractName = "Crowdsale"; + String filePath = "./src/test/resources/soliditycode/contractScenario005.sol"; + String contractName = "Crowdsale"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contract005Key, contract005Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contract005Key, + contract005Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("Txid is " + txid); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); Assert.assertEquals(1, infoById.get().getResultValue()); @@ -65,12 +78,7 @@ public void deployIcoContract() { logger.info("after energy usage is " + Long.toString(energyUsage)); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario006.java b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario006.java index df5a70b8..6640acf2 100644 --- a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario006.java +++ b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario006.java @@ -13,62 +13,73 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode -public class ContractScenario006 extends TronBaseTest { private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); +public class ContractScenario006 extends TronBaseTest { + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contract006Address = ecKey1.getAddress(); String contract006Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, groups = {"contract", "smoke"}) + @Test( + enabled = true, + groups = {"contract", "smoke"}) public void deployFomo3D() { ecKey1 = new ECKey(Utils.getRandom()); contract006Address = ecKey1.getAddress(); contract006Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); PublicMethod.printAddress(contract006Key); - PublicMethod.sendcoin(contract006Address, 2000000000L, toAddress, - testKey003, blockingStubFull); - logger.info(Long.toString(PublicMethod.queryAccount(contract006Key, blockingStubFull) - .getBalance())); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(contract006Address, 100000000L, - 3, 1, contract006Key, blockingStubFull)); + PublicMethod.sendcoin(contract006Address, 2000000000L, toAddress, testKey003, blockingStubFull); + logger.info( + Long.toString(PublicMethod.queryAccount(contract006Key, blockingStubFull).getBalance())); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(contract006Address, - blockingStubFull); - Long energyLimit = accountResource.getEnergyLimit(); - Long energyUsage = accountResource.getEnergyUsed(); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + contract006Address, 100000000L, 3, 1, contract006Key, blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(contract006Address, blockingStubFull); + Long energyLimit = accountResource.getEnergyLimit(); + Long energyUsage = accountResource.getEnergyUsed(); logger.info("before energy limit is " + Long.toString(energyLimit)); logger.info("before energy usage is " + Long.toString(energyUsage)); - String filePath = "./src/test/resources/soliditycode/contractScenario006.sol"; - String contractName = "FoMo3Dlong"; + String filePath = "./src/test/resources/soliditycode/contractScenario006.sol"; + String contractName = "FoMo3Dlong"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] contractAddress; - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contract006Key, contract006Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress; + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contract006Key, + contract006Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); contractAddress = infoById.get().getContractAddress().toByteArray(); Assert.assertTrue(infoById.get().getResultValue() == 0); @@ -85,12 +96,7 @@ public void deployFomo3D() { logger.info("after energy usage is " + Long.toString(energyUsage)); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario007.java b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario007.java index 35c03f02..c64757a6 100644 --- a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario007.java +++ b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario007.java @@ -12,45 +12,64 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class ContractScenario007 extends TronBaseTest { ECKey ecKey1 = new ECKey(Utils.getRandom()); +public class ContractScenario007 extends TronBaseTest { + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contract007Address = ecKey1.getAddress(); - String contract007Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); /** - * constructor. - */ + String contract007Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contract007Key); } + PublicMethod.printAddress(contract007Key); + } - @Test(enabled = true, groups = {"contract", "smoke"}) + @Test( + enabled = true, + groups = {"contract", "smoke"}) public void deployErc721CardMigration() { ecKey1 = new ECKey(Utils.getRandom()); contract007Address = ecKey1.getAddress(); contract007Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(contract007Address, 20000000000L, foundationAddress, - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(contract007Address, 100000000L, - 3, 1, contract007Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + contract007Address, 20000000000L, foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + contract007Address, 100000000L, 3, 1, contract007Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(contract007Address, - blockingStubFull); - Long energyLimit = accountResource.getEnergyLimit(); - Long energyUsage = accountResource.getEnergyUsed(); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(contract007Address, blockingStubFull); + Long energyLimit = accountResource.getEnergyLimit(); + Long energyUsage = accountResource.getEnergyUsed(); Account account = PublicMethod.queryAccount(contract007Key, blockingStubFull); logger.info("before balance is " + Long.toString(account.getBalance())); logger.info("before energy limit is " + Long.toString(energyLimit)); logger.info("before energy usage is " + Long.toString(energyUsage)); - String contractName = "ERC721Token"; - String code = Configuration.getByPath("testng.conf") - .getString("code.code_ContractScenario007_deployErc721CardMigration"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_ContractScenario007_deployErc721CardMigration"); - byte[] contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contract007Key, contract007Address, blockingStubFull); + String contractName = "ERC721Token"; + String code = + Configuration.getByPath("testng.conf") + .getString("code.code_ContractScenario007_deployErc721CardMigration"); + String abi = + Configuration.getByPath("testng.conf") + .getString("abi.abi_ContractScenario007_deployErc721CardMigration"); + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contract007Key, + contract007Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); @@ -65,15 +84,9 @@ public void deployErc721CardMigration() { logger.info("after energy usage is " + Long.toString(energyUsage)); Assert.assertTrue(energyLimit > 0); Assert.assertTrue(energyUsage > 0); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario008.java b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario008.java index d2d241b7..b6d2584a 100644 --- a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario008.java +++ b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario008.java @@ -9,11 +9,11 @@ import org.tron.protos.Protocol.Account; import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode @@ -27,13 +27,9 @@ public class ContractScenario008 extends TronBaseTest { byte[] contract008Address = ecKey1.getAddress(); String contract008Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { - } + public void beforeClass() {} @Test(enabled = true) public void deployErc721CryptoKitties() { @@ -41,12 +37,16 @@ public void deployErc721CryptoKitties() { contract008Address = ecKey1.getAddress(); contract008Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); PublicMethod.printAddress(contract008Key); - Assert.assertTrue(PublicMethod.sendcoin(contract008Address, 5000000000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(contract008Address, 1000000L, - 3, 1, contract008Key, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(contract008Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.sendcoin( + contract008Address, 5000000000L, fromAddress, testKey002, blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + contract008Address, 10000000L, 3, 1, contract008Key, blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(contract008Address, blockingStubFull); Long energyLimit = accountResource.getEnergyLimit(); Long energyUsage = accountResource.getEnergyUsed(); Account account = PublicMethod.queryAccount(contract008Key, blockingStubFull); @@ -61,11 +61,34 @@ public void deployErc721CryptoKitties() { String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - byte[] contractAddress = PublicMethod.deployContract(contractName, abi, code, "", shortFeeLimit, - 0L, 100, null, contract008Key, contract008Address, blockingStubFull); + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + shortFeeLimit, + 0L, + 100, + null, + contract008Key, + contract008Address, + blockingStubFull); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contract008Key, contract008Address, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contract008Key, + contract008Address, + blockingStubFull); + PublicMethod.waitProduceNextBlock(blockingStubFull); final SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); accountResource = PublicMethod.getAccountResource(contract008Address, blockingStubFull); diff --git a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario009.java b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario009.java index 49e89027..e2ba6e4b 100644 --- a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario009.java +++ b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario009.java @@ -11,63 +11,87 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class ContractScenario009 extends TronBaseTest { ECKey ecKey1 = new ECKey(Utils.getRandom()); +public class ContractScenario009 extends TronBaseTest { + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contract009Address = ecKey1.getAddress(); String contract009Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - private String compilerVersion = Configuration.getByPath("testng.conf") - .getString("defaultParameter.solidityCompilerVersion"); - - /** - * constructor. - */ + private String compilerVersion = + Configuration.getByPath("testng.conf").getString("defaultParameter.solidityCompilerVersion"); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contract009Key); } + PublicMethod.printAddress(contract009Key); + } - @Test(enabled = true, groups = {"contract", "smoke"}) + @Test( + enabled = true, + groups = {"contract", "smoke"}) public void deployContainLibraryContract() { - Assert.assertTrue(PublicMethod.sendcoin(contract009Address, 20000000L, foundationAddress, - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(contract009Address, 1000000L, - 3, 1, contract009Key, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(contract009Address, - blockingStubFull); - Long energyLimit = accountResource.getEnergyLimit(); - Long energyUsage = accountResource.getEnergyUsed(); + Assert.assertTrue( + PublicMethod.sendcoin( + contract009Address, 20000000L, foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + contract009Address, 1000000L, 3, 1, contract009Key, blockingStubFull)); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(contract009Address, blockingStubFull); + Long energyLimit = accountResource.getEnergyLimit(); + Long energyUsage = accountResource.getEnergyUsed(); logger.info("before energy limit is " + Long.toString(energyLimit)); logger.info("before energy usage is " + Long.toString(energyUsage)); - String filePath = "./src/test/resources/soliditycode/contractScenario009.sol"; - String contractName = "Set"; + String filePath = "./src/test/resources/soliditycode/contractScenario009.sol"; + String contractName = "Set"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] libraryContractAddress; - libraryContractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contract009Key, contract009Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] libraryContractAddress; + libraryContractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contract009Key, + contract009Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); contractName = "C"; retMap = PublicMethod.getBycodeAbiForLibrary(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - String library = retMap.get("library").toString(); - //String libraryAddress = + String library = retMap.get("library").toString(); + // String libraryAddress = // "browser/TvmTest_p1_Grammar_002.sol:Set:" + Base58.encode58Check(libraryContractAddress); - String libraryAddress; - libraryAddress = library - + Base58.encode58Check(libraryContractAddress); - byte[] contractAddress = PublicMethod - .deployContractForLibrary(contractName, abi, code, "", maxFeeLimit, 0L, 100, libraryAddress, - contract009Key, contract009Address, compilerVersion, blockingStubFull); + String libraryAddress; + libraryAddress = library + Base58.encode58Check(libraryContractAddress); + byte[] contractAddress = + PublicMethod.deployContractForLibrary( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + libraryAddress, + contract009Key, + contract009Address, + compilerVersion, + blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); @@ -84,12 +108,7 @@ public void deployContainLibraryContract() { logger.info("after energy usage is " + Long.toString(energyUsage)); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario010.java b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario010.java index 05d7a52b..9f35a6b2 100644 --- a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario010.java +++ b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario010.java @@ -8,11 +8,11 @@ import org.tron.api.GrpcAPI.AccountResourceMessage; import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode @@ -26,10 +26,7 @@ public class ContractScenario010 extends TronBaseTest { byte[] contract009Address = ecKey1.getAddress(); String contract009Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(contract009Key); @@ -40,13 +37,16 @@ public void deployContainLibraryContract() { ecKey1 = new ECKey(Utils.getRandom()); contract009Address = ecKey1.getAddress(); contract009Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(contract009Address, 600000000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(contract009Address, 10000000L, - 3, 1, contract009Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + contract009Address, 600000000L, foundationAddress2, foundationKey2, blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + contract009Address, 30000000L, 3, 1, contract009Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(contract009Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(contract009Address, blockingStubFull); Long energyLimit = accountResource.getEnergyLimit(); Long energyUsage = accountResource.getEnergyUsed(); Long netUsage = accountResource.getNetUsed(); @@ -61,8 +61,19 @@ public void deployContainLibraryContract() { String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - byte[] libraryAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contract009Key, contract009Address, blockingStubFull); + byte[] libraryAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contract009Key, + contract009Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(libraryAddress, blockingStubFull); diff --git a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario012.java b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario012.java index b311b6f5..85c55db1 100644 --- a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario012.java +++ b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario012.java @@ -14,15 +14,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode -public class ContractScenario012 extends TronBaseTest { private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); +public class ContractScenario012 extends TronBaseTest { + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); byte[] contractAddress = null; String txid = ""; @@ -34,41 +36,53 @@ public class ContractScenario012 extends TronBaseTest { private final String te ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] receiverAddress = ecKey2.getAddress(); String receiverKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(contract012Key); - PublicMethod.printAddress(receiverKey); } + PublicMethod.printAddress(receiverKey); + } - @Test(enabled = true, groups = {"contract", "smoke"}) + @Test( + enabled = true, + groups = {"contract", "smoke"}) public void test1DeployTransactionCoin() { ecKey1 = new ECKey(Utils.getRandom()); contract012Address = ecKey1.getAddress(); contract012Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(contract012Address, 2000000000L, foundationAddress, - foundationKey, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(contract012Address, - blockingStubFull); - Long energyLimit = accountResource.getEnergyLimit(); - Long energyUsage = accountResource.getEnergyUsed(); + Assert.assertTrue( + PublicMethod.sendcoin( + contract012Address, 2000000000L, foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(contract012Address, blockingStubFull); + Long energyLimit = accountResource.getEnergyLimit(); + Long energyUsage = accountResource.getEnergyUsed(); logger.info("before energy limit is " + Long.toString(energyLimit)); logger.info("before energy usage is " + Long.toString(energyUsage)); - String filePath = "./src/test/resources/soliditycode/contractScenario012.sol"; - String contractName = "PayTest"; + String filePath = "./src/test/resources/soliditycode/contractScenario012.sol"; + String contractName = "PayTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100, - null, contract012Key, contract012Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contract012Key, + contract012Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); @@ -80,17 +94,25 @@ public void test1DeployTransactionCoin() { Assert.assertTrue(smartContract.getAbi() != null); } - - @Test(enabled = true, groups = {"contract", "smoke"}) + @Test( + enabled = true, + groups = {"contract", "smoke"}) public void test2TriggerTransactionCoin() { Account account = PublicMethod.queryAccount(contractAddress, blockingStubFull); logger.info("contract Balance : -- " + account.getBalance()); - receiveAddressParam = "\"" + Base58.encode58Check(foundationAddress) - + "\""; - //When the contract has no money,transaction coin failed. - txid = PublicMethod.triggerContract(contractAddress, - "sendToAddress2(address)", receiveAddressParam, false, - 0, 100000000L, contract012Address, contract012Key, blockingStubFull); + receiveAddressParam = "\"" + Base58.encode58Check(foundationAddress) + "\""; + // When the contract has no money,transaction coin failed. + txid = + PublicMethod.triggerContract( + contractAddress, + "sendToAddress2(address)", + receiveAddressParam, + false, + 0, + 100000000L, + contract012Address, + contract012Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info(txid); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -102,21 +124,29 @@ public void test2TriggerTransactionCoin() { Assert.assertFalse(infoById.get().getContractAddress().isEmpty()); } - - @Test(enabled = true, groups = {"contract", "smoke"}) + @Test( + enabled = true, + groups = {"contract", "smoke"}) public void test3TriggerTransactionCanNotCreateAccount() { ecKey2 = new ECKey(Utils.getRandom()); receiverAddress = ecKey2.getAddress(); receiverKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - //Send some trx to the contract account. + // Send some trx to the contract account. Account account = PublicMethod.queryAccount(contractAddress, blockingStubFull); logger.info("contract Balance : -- " + account.getBalance()); - receiveAddressParam = "\"" + Base58.encode58Check(receiverAddress) - + "\""; - //In smart contract, you can create account - txid = PublicMethod.triggerContract(contractAddress, - "sendToAddress2(address)", receiveAddressParam, false, - 1000000000L, 100000000L, contract012Address, contract012Key, blockingStubFull); + receiveAddressParam = "\"" + Base58.encode58Check(receiverAddress) + "\""; + // In smart contract, you can create account + txid = + PublicMethod.triggerContract( + contractAddress, + "sendToAddress2(address)", + receiveAddressParam, + false, + 1000000000L, + 100000000L, + contract012Address, + contract012Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info(txid); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -130,22 +160,30 @@ public void test3TriggerTransactionCanNotCreateAccount() { Account account2 = PublicMethod.queryAccount(receiverAddress, blockingStubFull); Assert.assertEquals(5L, account2.getBalance()); - } - - @Test(enabled = true, groups = {"contract", "smoke"}) + @Test( + enabled = true, + groups = {"contract", "smoke"}) public void test4TriggerTransactionCoin() { - receiveAddressParam = "\"" + Base58.encode58Check(receiverAddress) - + "\""; + receiveAddressParam = "\"" + Base58.encode58Check(receiverAddress) + "\""; Account account = PublicMethod.queryAccount(contractAddress, blockingStubFull); logger.info("contract Balance : -- " + account.getBalance()); - //This time, trigger the methed sendToAddress2 is OK. - Assert.assertTrue(PublicMethod.sendcoin(receiverAddress, 10000000L, toAddress, - testKey003, blockingStubFull)); - txid = PublicMethod.triggerContract(contractAddress, - "sendToAddress2(address)", receiveAddressParam, false, - 0, 100000000L, contract012Address, contract012Key, blockingStubFull); + // This time, trigger the methed sendToAddress2 is OK. + Assert.assertTrue( + PublicMethod.sendcoin(receiverAddress, 10000000L, toAddress, testKey003, blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "sendToAddress2(address)", + receiveAddressParam, + false, + 0, + 100000000L, + contract012Address, + contract012Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info(txid); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -156,16 +194,9 @@ public void test4TriggerTransactionCoin() { Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() > 0); Assert.assertTrue(infoById.get().getFee() == infoById.get().getReceipt().getEnergyFee()); Assert.assertFalse(infoById.get().getContractAddress().isEmpty()); - } - - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario013.java b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario013.java index 2ca6716d..5c80f449 100644 --- a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario013.java +++ b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario013.java @@ -10,43 +10,60 @@ import org.tron.api.GrpcAPI.AccountResourceMessage; import org.tron.protos.Protocol.TransactionInfo; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j -public class ContractScenario013 extends TronBaseTest { byte[] contractAddress = null; +public class ContractScenario013 extends TronBaseTest { + byte[] contractAddress = null; String txid = ""; Optional infoById = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contract013Address = ecKey1.getAddress(); - String contract013Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); /** - * constructor. - */ + String contract013Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contract013Key); } + PublicMethod.printAddress(contract013Key); + } - @Test(enabled = true, groups = {"contract", "smoke"}) + @Test( + enabled = true, + groups = {"contract", "smoke"}) public void deployTronTrxAndSunContract() { - Assert.assertTrue(PublicMethod.sendcoin(contract013Address, 20000000000L, foundationAddress, - foundationKey, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(contract013Address, - blockingStubFull); - Long energyLimit = accountResource.getEnergyLimit(); - Long energyUsage = accountResource.getEnergyUsed(); + Assert.assertTrue( + PublicMethod.sendcoin( + contract013Address, 20000000000L, foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(contract013Address, blockingStubFull); + Long energyLimit = accountResource.getEnergyLimit(); + Long energyUsage = accountResource.getEnergyUsed(); logger.info("before energy limit is " + Long.toString(energyLimit)); logger.info("before energy usage is " + Long.toString(energyUsage)); - String filePath = "./src/test/resources/soliditycode/contractScenario013.sol"; - String contractName = "timetest"; + String filePath = "./src/test/resources/soliditycode/contractScenario013.sol"; + String contractName = "timetest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); - txid = PublicMethod.deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 100, null, contract013Key, contract013Address, blockingStubFull); + txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contract013Key, + contract013Address, + blockingStubFull); logger.info(txid); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -56,23 +73,35 @@ public void deployTronTrxAndSunContract() { Assert.assertFalse(infoById.get().getContractAddress().isEmpty()); } - @Test(enabled = true, groups = {"contract", "smoke"}) + @Test( + enabled = true, + groups = {"contract", "smoke"}) public void triggerTronTrxAndSunContract() { - AccountResourceMessage accountResource = PublicMethod.getAccountResource(contract013Address, - blockingStubFull); - Long energyLimit = accountResource.getEnergyLimit(); - Long energyUsage = accountResource.getEnergyUsed(); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(contract013Address, blockingStubFull); + Long energyLimit = accountResource.getEnergyLimit(); + Long energyUsage = accountResource.getEnergyUsed(); logger.info("before energy limit is " + Long.toString(energyLimit)); logger.info("before energy usage is " + Long.toString(energyUsage)); - String filePath = "./src/test/resources/soliditycode/contractScenario013.sol"; - String contractName = "timetest"; + String filePath = "./src/test/resources/soliditycode/contractScenario013.sol"; + String contractName = "timetest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contract013Key, contract013Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contract013Key, + contract013Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); @@ -80,9 +109,17 @@ public void triggerTronTrxAndSunContract() { contractAddress = infoById.get().getContractAddress().toByteArray(); - txid = PublicMethod.triggerContract(contractAddress, - "time()", "#", false, - 0, 100000000L, contract013Address, contract013Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "time()", + "#", + false, + 0, + 100000000L, + contract013Address, + contract013Key, + blockingStubFull); logger.info(txid); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -94,12 +131,7 @@ public void triggerTronTrxAndSunContract() { Assert.assertFalse(infoById.get().getContractAddress().isEmpty()); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario014.java b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario014.java index 68b75f68..399ec4a1 100644 --- a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario014.java +++ b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario014.java @@ -8,7 +8,6 @@ import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.AccountResourceMessage; @@ -21,42 +20,48 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ContractScenario014 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); - String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelSolidity = null; private ManagedChannel channelFull1 = null; + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + private ManagedChannel channelSolidity = null; + private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); /** - * constructor. - */ + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); - blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + } @Test(enabled = true, description = "Clear a contract with ABI created by itself") public void testClearAbi() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); - PublicMethod.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; String contractName = "testConstantContract"; @@ -64,9 +69,19 @@ public void testClearAbi() { String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); @@ -74,8 +89,8 @@ public void testClearAbi() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); Long beforeBalance = info.getBalance(); Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); @@ -86,19 +101,17 @@ public void testClearAbi() { logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = PublicMethod - .clearContractAbi(contractAddress, contractExcAddress, contractExcKey, - blockingStubFull); + String txid = + PublicMethod.clearContractAbi( + contractAddress, contractExcAddress, contractExcKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); - Assert.assertEquals("", - ByteArray.toHexString(infoById.get().getResMessage().toByteArray())); + Assert.assertEquals("", ByteArray.toHexString(infoById.get().getResMessage().toByteArray())); Optional byId = PublicMethod.getTransactionById(txid, blockingStubFull); - Assert.assertEquals(byId.get().getRet(0).getContractRet().getNumber(), - SUCCESS_VALUE); + Assert.assertEquals(byId.get().getRet(0).getContractRet().getNumber(), SUCCESS_VALUE); Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), SUCCESS_VALUE); Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.SUCCESS); @@ -106,6 +119,5 @@ public void testClearAbi() { Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - } } diff --git a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario015.java b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario015.java index dd535695..142d16bc 100644 --- a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario015.java +++ b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario015.java @@ -6,7 +6,6 @@ import lombok.extern.slf4j.Slf4j; import org.bouncycastle.util.encoders.Hex; import org.junit.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.AccountResourceMessage; @@ -17,40 +16,47 @@ import org.tron.protos.Protocol.Transaction; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ContractScenario015 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); - String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelSolidity = null; private ManagedChannel channelFull1 = null; + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + private ManagedChannel channelSolidity = null; + private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); /** - * constructor. - */ + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); - blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + } @Test(enabled = true, description = "TriggerConstantContract a constant function ") public void testTriggerConstantContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; @@ -59,14 +65,24 @@ public void testTriggerConstantContract() { String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); Long beforeBalance = info.getBalance(); Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); @@ -76,21 +92,27 @@ public void testTriggerConstantContract() { logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "testPayable()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPayable()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); byte[] result = transactionExtention.getConstantResult(0).toByteArray(); logger.info("message:" + transaction.getRet(0).getRet()); - logger.info(":" + ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray())); + logger.info(":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); logger.info("Result:" + Hex.toHexString(result)); logger.info("getCode" + transactionExtention.getResult().getCode().getNumber()); Assert.assertEquals("SUCESS", transaction.getRet(0).getRet().toString()); - Assert.assertEquals(1, ByteArray.toLong(ByteArray - .fromHexString(Hex - .toHexString(result)))); + Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); } } diff --git a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario016.java b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario016.java index c48677c3..2d329d88 100644 --- a/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario016.java +++ b/testcase/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario016.java @@ -9,7 +9,6 @@ import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.WalletGrpc; @@ -20,74 +19,108 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j public class ContractScenario016 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] grammarAddress = ecKey1.getAddress(); - String testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelSolidity = null; private ManagedChannel channelFull1 = null; + String testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + private ManagedChannel channelSolidity = null; + private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(0); - private String compilerVersion = Configuration.getByPath("testng.conf") - .getString("defaultParameter.solidityCompilerVersion"); - - /** - * constructor. - */ + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0); + private String compilerVersion = + Configuration.getByPath("testng.conf").getString("defaultParameter.solidityCompilerVersion"); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(testKeyForGrammarAddress); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(testKeyForGrammarAddress); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } @Test(enabled = true, description = "ContractResult is BAD_JUMP_DESTINATION") public void test1Grammar001() { - Assert.assertTrue(PublicMethod - .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + grammarAddress, + 100000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); String contractName = "Test"; - String code = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a57600" - + "080fd5b5061011f8061003a6000396000f30060806040526004361060485763ffffffff7c01000000000000" - + "000000000000000000000000000000000000000000006000350416634ef5a0088114604d5780639093b95b1" - + "4608c575b600080fd5b348015605857600080fd5b50d38015606457600080fd5b50d28015607057600080fd" - + "5b50607a60043560b8565b60408051918252519081900360200190f35b348015609757600080fd5b50d3801" - + "560a357600080fd5b50d2801560af57600080fd5b5060b660ee565b005b6000606082604051908082528060" - + "20026020018201604052801560e5578160200160208202803883390190505b50905050919050565b6001805" - + "600a165627a7a7230582092ba162087e13f41c6d6c00ba493edc5a5a6250a3840ece5f99aa38b66366a7000" - + "29"; - String abi = "[{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\"" - + ":\"testOutOfMem\",\"outputs\":[{\"name\":\"r\",\"type\":\"bytes32\"}],\"payable\":false" - + ",\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs" - + "\":[],\"name\":\"testBadJumpDestination\",\"outputs\":[],\"payable\":false,\"stateMutab" - + "ility\":\"nonpayable\",\"type\":\"function\"}]"; - - byte[] contractAddress = PublicMethod.deployContract(contractName, abi, code, - "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress, grammarAddress, blockingStubFull); + String code = + "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a57600" + + "080fd5b5061011f8061003a6000396000f30060806040526004361060485763ffffffff7c01000000000" + + "000" + + "000000000000000000000000000000000000000000006000350416634ef5a0088114604d5780639093b9" + + "5b1" + + "4608c575b600080fd5b348015605857600080fd5b50d38015606457600080fd5b50d2801560705760008" + + "0fd" + + "5b50607a60043560b8565b60408051918252519081900360200190f35b348015609757600080fd5b50d3" + + "801" + + "560a357600080fd5b50d2801560af57600080fd5b5060b660ee565b005b6000606082604051908082528" + + "060" + + "20026020018201604052801560e5578160200160208202803883390190505b50905050919050565b6001" + + "805" + + "600a165627a7a7230582092ba162087e13f41c6d6c00ba493edc5a5a6250a3840ece5f99aa38b66366a7" + + "000" + + "29"; + String abi = + "[{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\"" + + ":\"testOutOfMem\",\"outputs\":[{\"name\":\"r\",\"type\":\"bytes32\"}],\"payable\":fa" + + "lse" + + ",\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inp" + + "uts" + + "\":[],\"name\":\"testBadJumpDestination\",\"outputs\":[],\"payable\":false,\"stateMu" + + "tab" + + "ility\":\"nonpayable\",\"type\":\"function\"}]"; + + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress, + grammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); org.testng.Assert.assertTrue(smartContract.getAbi().toString() != null); String txid = null; Optional infoById = null; - txid = PublicMethod.triggerContract(contractAddress, - "testBadJumpDestination()", "#", false, - 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "testBadJumpDestination()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("Txid is " + txid); @@ -105,14 +138,13 @@ public void test1Grammar001() { Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), BAD_JUMP_DESTINATION_VALUE); Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.BAD_JUMP_DESTINATION); - Assert - .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); - Assert - .assertEquals(contractResult.BAD_JUMP_DESTINATION, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); + Assert.assertEquals( + contractResult.BAD_JUMP_DESTINATION, infoById.get().getReceipt().getResult()); Assert.assertEquals(byId.get().getRet(0).getRet().getNumber(), 0); Assert.assertEquals(byId.get().getRet(0).getRetValue(), 0); - } @Test(enabled = true, description = "ContractResult is OUT_OF_ENERGY") @@ -123,10 +155,20 @@ public void test2Grammar002() { HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 20L, 100, null, testKeyForGrammarAddress, - grammarAddress, blockingStubFull); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 20L, + 100, + null, + testKeyForGrammarAddress, + grammarAddress, + blockingStubFull); + PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -145,14 +187,12 @@ public void test2Grammar002() { Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), REVERT_VALUE); Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.REVERT); - Assert - .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), - "4e487b710000000000000000000000000000000000000000000000000000000000000001"); - Assert - .assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), + "4e487b710000000000000000000000000000000000000000000000000000000000000001"); + Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); Assert.assertEquals(byId.get().getRet(0).getRet().getNumber(), 0); Assert.assertEquals(byId.get().getRet(0).getRetValue(), 0); - } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/account/DelegateResourceTimestampTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/account/DelegateResourceTimestampTest.java index c78c1a32..55b5149d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/account/DelegateResourceTimestampTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/account/DelegateResourceTimestampTest.java @@ -31,106 +31,120 @@ public class DelegateResourceTimestampTest extends TronBaseTest { byte[] receiver2Address = ecKey3.getAddress(); String receiver2Key = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() throws Exception{ + public void beforeClass() throws Exception { PublicMethod.printAddress(frozen1Key); PublicMethod.printAddress(receiver1Key); PublicMethod.printAddress(receiver2Key); PublicMethod.printAddress(receiver3Key); - if(PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + if (PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { throw new SkipException("Skipping freezeV1 test case"); } - - Assert.assertTrue(PublicMethod.sendcoin(frozen1Address, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); - - Assert.assertTrue(PublicMethod.sendcoin(receiver1Address, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(receiver2Address, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(receiver3Address, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + frozen1Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.sendcoin( + receiver1Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + receiver2Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + receiver3Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceV1ForReceiver(frozen1Address,frozenAmount, - 0,0,receiver1Address,frozen1Key,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV1ForReceiver( + frozen1Address, frozenAmount, 0, 0, receiver1Address, frozen1Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceV1ForReceiver(frozen1Address,frozenAmount, - 0,0,receiver2Address,frozen1Key,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV1ForReceiver( + frozen1Address, frozenAmount, 0, 0, receiver2Address, frozen1Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceV1ForReceiver(frozen1Address,frozenAmount, - 0,0,receiver3Address,frozen1Key,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV1ForReceiver( + frozen1Address, frozenAmount, 0, 0, receiver3Address, frozen1Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceV1ForReceiver(receiver1Address,frozenAmount, - 0,0,frozen1Address,receiver1Key,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV1ForReceiver( + receiver1Address, frozenAmount, 0, 0, frozen1Address, receiver1Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceV1ForReceiver(receiver2Address,frozenAmount, - 0,0,frozen1Address,receiver2Key,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV1ForReceiver( + receiver2Address, frozenAmount, 0, 0, frozen1Address, receiver2Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceV1ForReceiver(receiver3Address,frozenAmount, - 0,0,frozen1Address,receiver3Key,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV1ForReceiver( + receiver3Address, frozenAmount, 0, 0, frozen1Address, receiver3Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "GetDelegateResource to account sort by timestamp", groups = {"daily"}) + @Test( + enabled = true, + description = "GetDelegateResource to account sort by timestamp", + groups = {"daily"}) public void test01GetDelegateResourceToAccountTimestamp() { - List toAccountList = PublicMethod.getDelegatedResourceAccountIndex(frozen1Address,blockingStubFull).get().getToAccountsList(); + List toAccountList = + PublicMethod.getDelegatedResourceAccountIndex(frozen1Address, blockingStubFull) + .get() + .getToAccountsList(); Assert.assertTrue(toAccountList.size() == 3); - Assert.assertEquals(toAccountList.get(0).toByteArray(),receiver1Address); - Assert.assertEquals(toAccountList.get(1).toByteArray(),receiver2Address); - Assert.assertEquals(toAccountList.get(2).toByteArray(),receiver3Address); + Assert.assertEquals(toAccountList.get(0).toByteArray(), receiver1Address); + Assert.assertEquals(toAccountList.get(1).toByteArray(), receiver2Address); + Assert.assertEquals(toAccountList.get(2).toByteArray(), receiver3Address); - - Assert.assertTrue(PublicMethod.freezeBalanceV1ForReceiver(frozen1Address,frozenAmount, - 0,0,receiver1Address,frozen1Key,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV1ForReceiver( + frozen1Address, frozenAmount, 0, 0, receiver1Address, frozen1Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - - toAccountList = PublicMethod.getDelegatedResourceAccountIndex(frozen1Address,blockingStubFull).get().getToAccountsList(); + toAccountList = + PublicMethod.getDelegatedResourceAccountIndex(frozen1Address, blockingStubFull) + .get() + .getToAccountsList(); Assert.assertTrue(toAccountList.size() == 3); - Assert.assertEquals(toAccountList.get(0).toByteArray(),receiver2Address); - Assert.assertEquals(toAccountList.get(1).toByteArray(),receiver3Address); - Assert.assertEquals(toAccountList.get(2).toByteArray(),receiver1Address); - - + Assert.assertEquals(toAccountList.get(0).toByteArray(), receiver2Address); + Assert.assertEquals(toAccountList.get(1).toByteArray(), receiver3Address); + Assert.assertEquals(toAccountList.get(2).toByteArray(), receiver1Address); } - - @Test(enabled = true, description = "GetDelegateResource from account sort by timestamp", groups = {"daily"}) + @Test( + enabled = true, + description = "GetDelegateResource from account sort by timestamp", + groups = {"daily"}) public void test02GetDelegateResourceFromAccountTimestamp() { - List fromAccountList = PublicMethod.getDelegatedResourceAccountIndex(frozen1Address,blockingStubFull).get().getFromAccountsList(); + List fromAccountList = + PublicMethod.getDelegatedResourceAccountIndex(frozen1Address, blockingStubFull) + .get() + .getFromAccountsList(); Assert.assertTrue(fromAccountList.size() == 3); - Assert.assertEquals(fromAccountList.get(0).toByteArray(),receiver1Address); - Assert.assertEquals(fromAccountList.get(1).toByteArray(),receiver2Address); - Assert.assertEquals(fromAccountList.get(2).toByteArray(),receiver3Address); - + Assert.assertEquals(fromAccountList.get(0).toByteArray(), receiver1Address); + Assert.assertEquals(fromAccountList.get(1).toByteArray(), receiver2Address); + Assert.assertEquals(fromAccountList.get(2).toByteArray(), receiver3Address); - Assert.assertTrue(PublicMethod.freezeBalanceV1ForReceiver(receiver1Address,frozenAmount, - 0,0,frozen1Address,receiver1Key,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV1ForReceiver( + receiver1Address, frozenAmount, 0, 0, frozen1Address, receiver1Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - - fromAccountList = PublicMethod.getDelegatedResourceAccountIndex(frozen1Address,blockingStubFull).get().getToAccountsList(); + fromAccountList = + PublicMethod.getDelegatedResourceAccountIndex(frozen1Address, blockingStubFull) + .get() + .getToAccountsList(); Assert.assertTrue(fromAccountList.size() == 3); - Assert.assertEquals(fromAccountList.get(0).toByteArray(),receiver2Address); - Assert.assertEquals(fromAccountList.get(1).toByteArray(),receiver3Address); - Assert.assertEquals(fromAccountList.get(2).toByteArray(),receiver1Address); - - + Assert.assertEquals(fromAccountList.get(0).toByteArray(), receiver2Address); + Assert.assertEquals(fromAccountList.get(1).toByteArray(), receiver3Address); + Assert.assertEquals(fromAccountList.get(2).toByteArray(), receiver1Address); } - - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { PublicMethod.freeResource(frozen1Address, frozen1Key, foundationAddress, blockingStubFull); @@ -139,5 +153,3 @@ public void shutdown() throws InterruptedException { PublicMethod.freeResource(receiver3Address, receiver3Key, foundationAddress, blockingStubFull); } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/account/FreezeWeightDeflationTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/account/FreezeWeightDeflationTest.java index acf8ab47..0a5eb677 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/account/FreezeWeightDeflationTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/account/FreezeWeightDeflationTest.java @@ -1,20 +1,16 @@ package stest.tron.wallet.dailybuild.account; -import com.google.protobuf.ByteString; -import java.util.HashMap; import lombok.extern.slf4j.Slf4j; import org.testng.Assert; import org.testng.SkipException; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.tron.api.GrpcAPI.AccountResourceMessage; -import org.tron.protos.Protocol.Account; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class FreezeWeightDeflationTest extends TronBaseTest { @@ -33,200 +29,248 @@ public class FreezeWeightDeflationTest extends TronBaseTest { byte[] receiver2Address = ecKey3.getAddress(); String receiver2Key = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() throws Exception{ + public void beforeClass() throws Exception { PublicMethod.printAddress(frozen1Key); PublicMethod.printAddress(frozen2Key); PublicMethod.printAddress(receiver1Key); - PublicMethod.printAddress(receiver2Key); if(PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { throw new SkipException("Skipping freezeV1 test case"); + PublicMethod.printAddress(receiver2Key); + if (PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + throw new SkipException("Skipping freezeV1 test case"); } - - Assert.assertTrue(PublicMethod.sendcoin(frozen1Address, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(frozen2Address, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(receiver1Address, 1L, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(receiver2Address, 1L, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + frozen1Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + frozen2Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + receiver1Address, 1L, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + receiver2Address, 1L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceV1ForReceiver(foundationAddress,frozenAmount * 8, - 0,0,receiver1Address,foundationKey,blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceV1ForReceiver(foundationAddress,frozenAmount * 8, - 0,1,receiver1Address,foundationKey,blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceV1ForReceiver(foundationAddress,frozenAmount * 8, - 0,0,receiver2Address,foundationKey,blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceV1ForReceiver(foundationAddress,frozenAmount * 8, - 0,1,receiver2Address,foundationKey,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV1ForReceiver( + foundationAddress, + frozenAmount * 8, + 0, + 0, + receiver1Address, + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV1ForReceiver( + foundationAddress, + frozenAmount * 8, + 0, + 1, + receiver1Address, + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV1ForReceiver( + foundationAddress, + frozenAmount * 8, + 0, + 0, + receiver2Address, + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV1ForReceiver( + foundationAddress, + frozenAmount * 8, + 0, + 1, + receiver2Address, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Freeze net cause weight deflation issue fix test", groups = {"daily"}) + @Test( + enabled = true, + description = "Freeze net cause weight deflation issue fix test", + groups = {"daily"}) public void test01FreezeNetCauseWeightDeflationTest() { - final Long beforeNetWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalNetWeight(); - final Long beforeEnergyWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalEnergyWeight(); + final Long beforeNetWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalNetWeight(); + final Long beforeEnergyWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalEnergyWeight(); logger.info("before:" + beforeNetWeight); - PublicMethod.freezeBalance(frozen1Address,frozenAmount,0,frozen1Key,blockingStubFull); + PublicMethod.freezeBalance(frozen1Address, frozenAmount, 0, frozen1Key, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long afterNetWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalNetWeight(); + Long afterNetWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalNetWeight(); Assert.assertTrue(afterNetWeight - beforeNetWeight == 1); - - Assert.assertTrue(PublicMethod.freezeBalance(frozen1Address,frozenAmount,0,frozen1Key,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance(frozen1Address, frozenAmount, 0, frozen1Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - afterNetWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalNetWeight(); - Long afterEnergyWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalEnergyWeight(); + afterNetWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalNetWeight(); + Long afterEnergyWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalEnergyWeight(); Assert.assertTrue(afterNetWeight - beforeNetWeight == 3); Assert.assertTrue(afterEnergyWeight - beforeEnergyWeight == 0); - - PublicMethod.unFreezeBalance(frozen1Address,frozen1Key,0,null,blockingStubFull); + PublicMethod.unFreezeBalance(frozen1Address, frozen1Key, 0, null, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - afterNetWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalNetWeight(); + afterNetWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalNetWeight(); logger.info("afterNetWeight:" + afterNetWeight); - afterEnergyWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalEnergyWeight(); + afterEnergyWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalEnergyWeight(); Assert.assertTrue(afterEnergyWeight - beforeEnergyWeight == 0); Assert.assertTrue(afterNetWeight - beforeNetWeight == 0); - - } - - @Test(enabled = true, description = "Freeze energy cause weight deflation issue fix test", groups = {"daily"}) + @Test( + enabled = true, + description = "Freeze energy cause weight deflation issue fix test", + groups = {"daily"}) public void test02FreezeEnergyCauseWeightDeflationTest() { - final Long beforeEnergyWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalEnergyWeight(); - final Long beforeNetWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalNetWeight(); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(frozen1Address,frozenAmount,0,1,frozen1Key,blockingStubFull)); + final Long beforeEnergyWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalEnergyWeight(); + final Long beforeNetWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalNetWeight(); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + frozen1Address, frozenAmount, 0, 1, frozen1Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long afterEnergyWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalEnergyWeight(); + Long afterEnergyWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalEnergyWeight(); Assert.assertTrue(afterEnergyWeight - beforeEnergyWeight == 1); - Long afterNetWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalNetWeight(); + Long afterNetWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalNetWeight(); Assert.assertTrue(afterNetWeight - beforeNetWeight == 0); - - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(frozen1Address,frozenAmount,0,1,frozen1Key,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + frozen1Address, frozenAmount, 0, 1, frozen1Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - afterEnergyWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalEnergyWeight(); + afterEnergyWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalEnergyWeight(); Assert.assertTrue(afterEnergyWeight - beforeEnergyWeight == 3); - afterNetWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalNetWeight(); + afterNetWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalNetWeight(); Assert.assertTrue(afterNetWeight - beforeNetWeight == 0); - - Assert.assertTrue(PublicMethod.unFreezeBalance(frozen1Address,frozen1Key,1,null,blockingStubFull)); + Assert.assertTrue( + PublicMethod.unFreezeBalance(frozen1Address, frozen1Key, 1, null, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - afterEnergyWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalEnergyWeight(); + afterEnergyWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalEnergyWeight(); Assert.assertTrue(afterEnergyWeight - beforeEnergyWeight == 0); - afterNetWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalNetWeight(); + afterNetWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalNetWeight(); Assert.assertTrue(afterNetWeight - beforeNetWeight == 0); } - - @Test(enabled = true, description = "Delegate energy to two receiver cause weight deflation test", groups = {"daily"}) + @Test( + enabled = true, + description = "Delegate energy to two receiver cause weight deflation test", + groups = {"daily"}) public void test03DelegateEnergyToTwoReceiverCauseWeightDeflationTest() { - //pre account status - Assert.assertTrue(PublicMethod.freezeBalance(frozen1Address,frozenAmount * 4,0,frozen1Key,blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(frozen1Address,frozenAmount * 5,0,1,frozen1Key,blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalance(frozen2Address,frozenAmount * 6,0,frozen2Key,blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(frozen2Address,frozenAmount * 7,0,1,frozen2Key,blockingStubFull)); + // pre account status + Assert.assertTrue( + PublicMethod.freezeBalance( + frozen1Address, frozenAmount * 4, 0, frozen1Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + frozen1Address, frozenAmount * 5, 0, 1, frozen1Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance( + frozen2Address, frozenAmount * 6, 0, frozen2Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + frozen2Address, frozenAmount * 7, 0, 1, frozen2Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - final Long beforeEnergyWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalEnergyWeight(); - final Long beforeNetWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalNetWeight(); + final Long beforeEnergyWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalEnergyWeight(); + final Long beforeNetWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalNetWeight(); logger.info("beforeEnergyWeight:" + beforeEnergyWeight); - Assert.assertTrue(PublicMethod.freezeBalanceV1ForReceiver(frozen1Address,frozenAmount, - 0,1,receiver1Address,frozen1Key,blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceV1ForReceiver(frozen1Address,frozenAmount, - 0,1,receiver2Address,frozen1Key,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV1ForReceiver( + frozen1Address, frozenAmount, 0, 1, receiver1Address, frozen1Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV1ForReceiver( + frozen1Address, frozenAmount, 0, 1, receiver2Address, frozen1Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long afterEnergyWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalEnergyWeight(); + Long afterEnergyWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalEnergyWeight(); logger.info("afterEnergyWeight:" + afterEnergyWeight); Assert.assertTrue(afterEnergyWeight - beforeEnergyWeight == 2); - Long afterNetWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalNetWeight(); + Long afterNetWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalNetWeight(); Assert.assertTrue(afterNetWeight - beforeNetWeight == 0); - - Assert.assertTrue(PublicMethod.unFreezeBalance(frozen1Address,frozen1Key, - 1,receiver1Address,blockingStubFull)); - Assert.assertTrue(PublicMethod.unFreezeBalance(frozen1Address,frozen1Key, - 1,receiver2Address,blockingStubFull)); + Assert.assertTrue( + PublicMethod.unFreezeBalance( + frozen1Address, frozen1Key, 1, receiver1Address, blockingStubFull)); + Assert.assertTrue( + PublicMethod.unFreezeBalance( + frozen1Address, frozen1Key, 1, receiver2Address, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - afterEnergyWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalEnergyWeight(); + afterEnergyWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalEnergyWeight(); Assert.assertTrue(afterEnergyWeight - beforeEnergyWeight == 0); - afterNetWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalNetWeight(); + afterNetWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalNetWeight(); Assert.assertTrue(afterNetWeight - beforeNetWeight == 0); - } - - @Test(enabled = true, description = "Two account delegate net to one receiver cause weight deflation test", groups = {"daily"}) + @Test( + enabled = true, + description = "Two account delegate net to one receiver cause weight deflation test", + groups = {"daily"}) public void test04TwoAccountDelegateNetToOneReceiverCauseWeightDeflationTest() { - final Long beforeEnergyWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalEnergyWeight(); - final Long beforeNetWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalNetWeight(); - - Assert.assertTrue(PublicMethod.freezeBalanceV1ForReceiver(frozen1Address,frozenAmount, - 0,0,receiver2Address,frozen1Key,blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceV1ForReceiver(frozen2Address,frozenAmount, - 0,0,receiver2Address,frozen2Key,blockingStubFull)); + final Long beforeEnergyWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalEnergyWeight(); + final Long beforeNetWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalNetWeight(); + + Assert.assertTrue( + PublicMethod.freezeBalanceV1ForReceiver( + frozen1Address, frozenAmount, 0, 0, receiver2Address, frozen1Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV1ForReceiver( + frozen2Address, frozenAmount, 0, 0, receiver2Address, frozen2Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long afterNetWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalNetWeight(); + Long afterNetWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalNetWeight(); Assert.assertTrue(afterNetWeight - beforeNetWeight == 3); - Long afterEnergyWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalEnergyWeight(); + Long afterEnergyWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalEnergyWeight(); Assert.assertTrue(afterEnergyWeight - beforeEnergyWeight == 0); - - Assert.assertTrue(PublicMethod.unFreezeBalance(frozen1Address,frozen1Key, - 0,receiver2Address,blockingStubFull)); - Assert.assertTrue(PublicMethod.unFreezeBalance(frozen2Address,frozen2Key, - 0,receiver2Address,blockingStubFull)); + Assert.assertTrue( + PublicMethod.unFreezeBalance( + frozen1Address, frozen1Key, 0, receiver2Address, blockingStubFull)); + Assert.assertTrue( + PublicMethod.unFreezeBalance( + frozen2Address, frozen2Key, 0, receiver2Address, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - afterNetWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalNetWeight(); + afterNetWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalNetWeight(); Assert.assertTrue(afterNetWeight - beforeNetWeight == 0); - afterEnergyWeight = PublicMethod.getAccountResource(frozen1Address,blockingStubFull) - .getTotalEnergyWeight(); + afterEnergyWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalEnergyWeight(); Assert.assertTrue(afterEnergyWeight - beforeEnergyWeight == 0); } - - - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { PublicMethod.freeResource(frozen1Address, frozen1Key, foundationAddress, blockingStubFull); - PublicMethod.freeResource(frozen2Address, frozen2Key, foundationAddress, blockingStubFull); } + PublicMethod.freeResource(frozen2Address, frozen2Key, foundationAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/account/WalletTestAccount012.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/account/WalletTestAccount012.java index 70c694fb..e8c217a1 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/account/WalletTestAccount012.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/account/WalletTestAccount012.java @@ -25,151 +25,160 @@ public class WalletTestAccount012 extends TronBaseTest { byte[] frozenAddress = ecKey1.getAddress(); String frozenKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() throws Exception{ + public void beforeClass() throws Exception { PublicMethod.printAddress(frozenKey); - if(!PublicMethod.tronPowerProposalIsOpen(blockingStubFull) || !PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + if (!PublicMethod.tronPowerProposalIsOpen(blockingStubFull) + || !PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { throw new SkipException("Skipping tronPower or freezeV2 test case"); } - - } - @Test(enabled = true, priority = 100,description = "Freeze balance to get tron power", groups = {"daily"}) + @Test( + enabled = true, + priority = 100, + description = "Freeze balance to get tron power", + groups = {"daily"}) public void test01FreezeBalanceGetTronPower() { - final Long beforeFrozenTime = System.currentTimeMillis(); - Assert.assertTrue(PublicMethod.sendcoin(frozenAddress, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + frozenAddress, sendAmount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(frozenAddress, blockingStubFull); + final Long beforeTotalTronPowerWeight = accountResource.getTotalTronPowerWeight(); + final Long beforeTronPowerLimit = accountResource.getTronPowerLimit(); - AccountResourceMessage accountResource = PublicMethod - .getAccountResource(frozenAddress, blockingStubFull); - final Long beforeTotalTronPowerWeight = accountResource.getTotalTronPowerWeight(); - final Long beforeTronPowerLimit = accountResource.getTronPowerLimit(); - - - Assert.assertTrue(PublicMethod.freezeBalanceGetTronPower(frozenAddress,frozenAmountForTronPower, - 0,2,null,frozenKey,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetTronPower( + frozenAddress, frozenAmountForTronPower, 0, 2, null, frozenKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long afterFrozenTime = System.currentTimeMillis(); - Account account = PublicMethod.queryAccount(frozenAddress,blockingStubFull); - Assert.assertEquals(PublicMethod.freezeV2ProposalIsOpen(blockingStubFull) - ? account.getFrozenV2(2).getAmount() : account.getTronPower().getFrozenBalance(),frozenAmountForTronPower); - Assert.assertTrue(PublicMethod.freezeV2ProposalIsOpen(blockingStubFull) ? true : account.getTronPower().getExpireTime() > beforeFrozenTime - && account.getTronPower().getExpireTime() < afterFrozenTime); - accountResource = PublicMethod - .getAccountResource(frozenAddress, blockingStubFull); - Long afterTotalTronPowerWeight = accountResource.getTotalTronPowerWeight(); - Long afterTronPowerLimit = accountResource.getTronPowerLimit(); - Long afterTronPowerUsed = accountResource.getTronPowerUsed(); - Assert.assertEquals(afterTotalTronPowerWeight - beforeTotalTronPowerWeight, + Long afterFrozenTime = System.currentTimeMillis(); + Account account = PublicMethod.queryAccount(frozenAddress, blockingStubFull); + Assert.assertEquals( + PublicMethod.freezeV2ProposalIsOpen(blockingStubFull) + ? account.getFrozenV2(2).getAmount() + : account.getTronPower().getFrozenBalance(), + frozenAmountForTronPower); + Assert.assertTrue( + PublicMethod.freezeV2ProposalIsOpen(blockingStubFull) + ? true + : account.getTronPower().getExpireTime() > beforeFrozenTime + && account.getTronPower().getExpireTime() < afterFrozenTime); + accountResource = PublicMethod.getAccountResource(frozenAddress, blockingStubFull); + Long afterTotalTronPowerWeight = accountResource.getTotalTronPowerWeight(); + Long afterTronPowerLimit = accountResource.getTronPowerLimit(); + Long afterTronPowerUsed = accountResource.getTronPowerUsed(); + Assert.assertEquals( + afterTotalTronPowerWeight - beforeTotalTronPowerWeight, frozenAmountForTronPower / 1000000L); - Assert.assertEquals(afterTronPowerLimit - beforeTronPowerLimit, - frozenAmountForTronPower / 1000000L); - - - Assert.assertTrue(PublicMethod.freezeBalanceGetTronPower(frozenAddress, - 6000000 - frozenAmountForTronPower, - 0,2,null,frozenKey,blockingStubFull)); + Assert.assertEquals( + afterTronPowerLimit - beforeTronPowerLimit, frozenAmountForTronPower / 1000000L); + + Assert.assertTrue( + PublicMethod.freezeBalanceGetTronPower( + frozenAddress, + 6000000 - frozenAmountForTronPower, + 0, + 2, + null, + frozenKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - accountResource = PublicMethod - .getAccountResource(frozenAddress, blockingStubFull); + accountResource = PublicMethod.getAccountResource(frozenAddress, blockingStubFull); afterTronPowerLimit = accountResource.getTronPowerLimit(); - Assert.assertEquals(afterTronPowerLimit - beforeTronPowerLimit, - 6); - - + Assert.assertEquals(afterTronPowerLimit - beforeTronPowerLimit, 6); } - - @Test(enabled = true,priority = 100,description = "Vote witness by tron power", groups = {"daily"}) + @Test( + enabled = true, + priority = 100, + description = "Vote witness by tron power", + groups = {"daily"}) public void test02VotePowerOnlyComeFromTronPower() { - AccountResourceMessage accountResource = PublicMethod - .getAccountResource(frozenAddress, blockingStubFull); - final Long beforeTronPowerUsed = accountResource.getTronPowerUsed(); - - - HashMap witnessMap = new HashMap<>(); - witnessMap.put(witnessAddress,frozenAmountForNet / 1000000L); - Assert.assertFalse(PublicMethod.voteWitness(frozenAddress,frozenKey,witnessMap, - blockingStubFull)); - witnessMap.put(witnessAddress,frozenAmountForTronPower / 1000000L); - Assert.assertTrue(PublicMethod.voteWitness(frozenAddress,frozenKey,witnessMap, - blockingStubFull)); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(frozenAddress, blockingStubFull); + final Long beforeTronPowerUsed = accountResource.getTronPowerUsed(); + + HashMap witnessMap = new HashMap<>(); + witnessMap.put(witnessAddress, frozenAmountForNet / 1000000L); + Assert.assertFalse( + PublicMethod.voteWitness(frozenAddress, frozenKey, witnessMap, blockingStubFull)); + witnessMap.put(witnessAddress, frozenAmountForTronPower / 1000000L); + Assert.assertTrue( + PublicMethod.voteWitness(frozenAddress, frozenKey, witnessMap, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - accountResource = PublicMethod - .getAccountResource(frozenAddress, blockingStubFull); - Long afterTronPowerUsed = accountResource.getTronPowerUsed(); - Assert.assertEquals(afterTronPowerUsed - beforeTronPowerUsed, - frozenAmountForTronPower / 1000000L); - final Long secondBeforeTronPowerUsed = afterTronPowerUsed; - witnessMap.put(witnessAddress,(frozenAmountForTronPower / 1000000L) - 1); - Assert.assertTrue(PublicMethod.voteWitness(frozenAddress,frozenKey,witnessMap, - blockingStubFull)); + accountResource = PublicMethod.getAccountResource(frozenAddress, blockingStubFull); + Long afterTronPowerUsed = accountResource.getTronPowerUsed(); + Assert.assertEquals( + afterTronPowerUsed - beforeTronPowerUsed, frozenAmountForTronPower / 1000000L); + final Long secondBeforeTronPowerUsed = afterTronPowerUsed; + witnessMap.put(witnessAddress, (frozenAmountForTronPower / 1000000L) - 1); + Assert.assertTrue( + PublicMethod.voteWitness(frozenAddress, frozenKey, witnessMap, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - accountResource = PublicMethod - .getAccountResource(frozenAddress, blockingStubFull); + accountResource = PublicMethod.getAccountResource(frozenAddress, blockingStubFull); afterTronPowerUsed = accountResource.getTronPowerUsed(); - Assert.assertEquals(secondBeforeTronPowerUsed - afterTronPowerUsed, - 1); - - + Assert.assertEquals(secondBeforeTronPowerUsed - afterTronPowerUsed, 1); } - @Test(enabled = true,priority = 100,description = "Tron power is not allow to others", groups = {"daily"}) - public void test03TronPowerIsNotAllowToOthers() throws Exception{ - Assert.assertFalse(PublicMethod.freezeBalanceGetTronPower(frozenAddress, - frozenAmountForTronPower, 0,2, - ByteString.copyFrom(foundationAddress),frozenKey,blockingStubFull)); + @Test( + enabled = true, + priority = 100, + description = "Tron power is not allow to others", + groups = {"daily"}) + public void test03TronPowerIsNotAllowToOthers() throws Exception { + Assert.assertFalse( + PublicMethod.freezeBalanceGetTronPower( + frozenAddress, + frozenAmountForTronPower, + 0, + 2, + ByteString.copyFrom(foundationAddress), + frozenKey, + blockingStubFull)); } - - @Test(enabled = true,priority = 100,description = "Unfreeze balance for tron power", groups = {"daily"}) + @Test( + enabled = true, + priority = 100, + description = "Unfreeze balance for tron power", + groups = {"daily"}) public void test04UnfreezeBalanceForTronPower() { - AccountResourceMessage accountResource = PublicMethod - .getAccountResource(foundationAddress, blockingStubFull); - final Long beforeTotalTronPowerWeight = accountResource.getTotalTronPowerWeight(); - Long canUnfreezeAmount = PublicMethod.getFrozenV2Amount(frozenAddress,2,blockingStubFull); - Assert.assertTrue(PublicMethod.unFreezeBalanceV2(frozenAddress,frozenKey,canUnfreezeAmount,2,blockingStubFull)); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(foundationAddress, blockingStubFull); + final Long beforeTotalTronPowerWeight = accountResource.getTotalTronPowerWeight(); + Long canUnfreezeAmount = PublicMethod.getFrozenV2Amount(frozenAddress, 2, blockingStubFull); + Assert.assertTrue( + PublicMethod.unFreezeBalanceV2( + frozenAddress, frozenKey, canUnfreezeAmount, 2, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - accountResource = PublicMethod - .getAccountResource(frozenAddress, blockingStubFull); - Long afterTotalTronPowerWeight = accountResource.getTotalTronPowerWeight(); - Assert.assertTrue(beforeTotalTronPowerWeight - afterTotalTronPowerWeight == canUnfreezeAmount / 1000000); - - Assert.assertEquals(accountResource.getTronPowerLimit(),0L); - Assert.assertEquals(accountResource.getTronPowerUsed(),0L); - - Account account = PublicMethod.queryAccount(frozenAddress,blockingStubFull); - Assert.assertTrue(PublicMethod.getFrozenV2Amount(frozenAddress,2,blockingStubFull) == 0); + accountResource = PublicMethod.getAccountResource(frozenAddress, blockingStubFull); + Long afterTotalTronPowerWeight = accountResource.getTotalTronPowerWeight(); + Assert.assertTrue( + beforeTotalTronPowerWeight - afterTotalTronPowerWeight == canUnfreezeAmount / 1000000); + Assert.assertEquals(accountResource.getTronPowerLimit(), 0L); + Assert.assertEquals(accountResource.getTronPowerUsed(), 0L); + Account account = PublicMethod.queryAccount(frozenAddress, blockingStubFull); + Assert.assertTrue(PublicMethod.getFrozenV2Amount(frozenAddress, 2, blockingStubFull) == 0); } - - - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - PublicMethod.unFreezeBalance(frozenAddress, frozenKey, 2, null, - blockingStubFull); - PublicMethod.unFreezeBalance(frozenAddress, frozenKey, 0, null, - blockingStubFull); + PublicMethod.unFreezeBalance(frozenAddress, frozenKey, 2, null, blockingStubFull); + PublicMethod.unFreezeBalance(frozenAddress, frozenKey, 0, null, blockingStubFull); PublicMethod.freeResource(frozenAddress, frozenKey, foundationAddress, blockingStubFull); } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletExchange001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletExchange001.java index fbd5abab..7f30570c 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletExchange001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletExchange001.java @@ -1,7 +1,6 @@ package stest.tron.wallet.dailybuild.assetissue; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.Optional; import lombok.extern.slf4j.Slf4j; @@ -18,8 +17,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletExchange001 extends TronBaseTest { @@ -28,8 +27,8 @@ public class WalletExchange001 extends TronBaseTest { private static final long totalSupply = 1000000001L; private static String name1 = "exchange001_1_" + Long.toString(now); private static String name2 = "exchange001_2_" + Long.toString(now); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); String description = "just-test"; String url = "https://github.com/tronprotocol/wallet-cli/"; @@ -49,28 +48,25 @@ public class WalletExchange001 extends TronBaseTest { Integer exchangeRate = 10; Long firstTokenInitialBalance = 10000L; Long secondTokenInitialBalance = firstTokenInitialBalance * exchangeRate; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1); - private String soliInPbft = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(2); - - /** - * constructor. - */ + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); + private String soliInPbft = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(2); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - channelPbft = ManagedChannelBuilder.forTarget(soliInPbft) - .usePlaintext() - .build(); + channelPbft = ManagedChannelBuilder.forTarget(soliInPbft).usePlaintext().build(); blockingStubPbft = WalletSolidityGrpc.newBlockingStub(channelPbft); } - @Test(enabled = false,description = "Create two asset issue to create exchange", groups = {"daily"}) + @Test( + enabled = false, + description = "Create two asset issue to create exchange", + groups = {"daily"}) public void test1CreateUsedAsset() { ecKey1 = new ECKey(Utils.getRandom()); exchange001Address = ecKey1.getAddress(); @@ -83,54 +79,98 @@ public void test1CreateUsedAsset() { PublicMethod.printAddress(exchange001Key); PublicMethod.printAddress(secondExchange001Key); - Assert.assertTrue(PublicMethod.sendcoin(exchange001Address, 10240000000L, foundationAddress, - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(secondExchange001Address, 10240000000L, toAddress, - testKey003, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + exchange001Address, 10240000000L, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + secondExchange001Address, 10240000000L, toAddress, testKey003, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long start = System.currentTimeMillis() + 5000L; - Long end = System.currentTimeMillis() + 5000000L; - Assert.assertTrue(PublicMethod.createAssetIssue(exchange001Address, name1, totalSupply, 1, - 1, start, end, 1, description, url, 10000L, 10000L, - 1L, 1L, exchange001Key, blockingStubFull)); - Assert.assertTrue(PublicMethod.createAssetIssue(secondExchange001Address, name2, totalSupply, 1, - 1, start, end, 1, description, url, 10000L, 10000L, - 1L, 1L, secondExchange001Key, blockingStubFull)); + Long start = System.currentTimeMillis() + 5000L; + Long end = System.currentTimeMillis() + 5000000L; + Assert.assertTrue( + PublicMethod.createAssetIssue( + exchange001Address, + name1, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + exchange001Key, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.createAssetIssue( + secondExchange001Address, + name2, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + secondExchange001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = false,description = "Test create exchange", groups = {"daily"}) + @Test( + enabled = false, + description = "Test create exchange", + groups = {"daily"}) public void test2CreateExchange() { listExchange = PublicMethod.getExchangeList(blockingStubFull); - final Integer beforeCreateExchangeNum = listExchange.get().getExchangesCount(); + final Integer beforeCreateExchangeNum = listExchange.get().getExchangesCount(); exchangeId = listExchange.get().getExchangesCount(); Account getAssetIdFromThisAccount; getAssetIdFromThisAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); assetAccountId1 = getAssetIdFromThisAccount.getAssetIssuedID(); - getAssetIdFromThisAccount = PublicMethod - .queryAccount(secondExchange001Address, blockingStubFull); + getAssetIdFromThisAccount = + PublicMethod.queryAccount(secondExchange001Address, blockingStubFull); assetAccountId2 = getAssetIdFromThisAccount.getAssetIssuedID(); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long token1BeforeBalance = 0L; + Long token1BeforeBalance = 0L; for (String name : firstAccount.getAssetMap().keySet()) { token1BeforeBalance = firstAccount.getAssetMap().get(name); } - Assert.assertTrue(PublicMethod.transferAsset(exchange001Address, assetAccountId2.toByteArray(), - secondTransferAssetToFirstAccountNum, secondExchange001Address, - secondExchange001Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + exchange001Address, + assetAccountId2.toByteArray(), + secondTransferAssetToFirstAccountNum, + secondExchange001Address, + secondExchange001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long token2BeforeBalance = secondTransferAssetToFirstAccountNum; - //logger.info("name1 is " + name1); - //logger.info("name2 is " + name2); - //logger.info("first balance is " + Long.toString(token1BeforeBalance)); - //logger.info("second balance is " + token2BeforeBalance.toString()); - //CreateExchange + Long token2BeforeBalance = secondTransferAssetToFirstAccountNum; + // logger.info("name1 is " + name1); + // logger.info("name2 is " + name2); + // logger.info("first balance is " + Long.toString(token1BeforeBalance)); + // logger.info("second balance is " + token2BeforeBalance.toString()); + // CreateExchange Assert.assertTrue( - PublicMethod.exchangeCreate(assetAccountId1.toByteArray(), firstTokenInitialBalance, - assetAccountId2.toByteArray(), secondTokenInitialBalance, exchange001Address, + PublicMethod.exchangeCreate( + assetAccountId1.toByteArray(), + firstTokenInitialBalance, + assetAccountId2.toByteArray(), + secondTokenInitialBalance, + exchange001Address, exchange001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -138,31 +178,39 @@ public void test2CreateExchange() { Integer afterCreateExchangeNum = listExchange.get().getExchangesCount(); Assert.assertTrue(afterCreateExchangeNum - beforeCreateExchangeNum == 1); exchangeId = listExchange.get().getExchangesCount(); - } - @Test(enabled = false,description = "Test list exchange api", groups = {"daily"}) + @Test( + enabled = false, + description = "Test list exchange api", + groups = {"daily"}) public void test3ListExchange() { listExchange = PublicMethod.getExchangeList(blockingStubFull); for (Integer i = 0; i < listExchange.get().getExchangesCount(); i++) { - Assert.assertFalse(ByteArray.toHexString(listExchange.get().getExchanges(i) - .getCreatorAddress().toByteArray()).isEmpty()); + Assert.assertFalse( + ByteArray.toHexString( + listExchange.get().getExchanges(i).getCreatorAddress().toByteArray()) + .isEmpty()); Assert.assertTrue(listExchange.get().getExchanges(i).getExchangeId() > 0); - Assert.assertFalse(ByteArray.toStr(listExchange.get().getExchanges(i).getFirstTokenId() - .toByteArray()).isEmpty()); + Assert.assertFalse( + ByteArray.toStr(listExchange.get().getExchanges(i).getFirstTokenId().toByteArray()) + .isEmpty()); Assert.assertTrue(listExchange.get().getExchanges(i).getFirstTokenBalance() > 0); } } - @Test(enabled = false,description = "Test inject exchange", groups = {"daily"}) + @Test( + enabled = false, + description = "Test inject exchange", + groups = {"daily"}) public void test4InjectExchange() { exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long beforeToken1Balance = 0L; - Long beforeToken2Balance = 0L; + Long beforeToken1Balance = 0L; + Long beforeToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { beforeToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -175,12 +223,17 @@ public void test4InjectExchange() { logger.info("before token 2 balance is " + Long.toString(beforeToken2Balance)); Integer injectBalance = 100; Assert.assertTrue( - PublicMethod.injectExchange(exchangeId, assetAccountId1.toByteArray(), injectBalance, - exchange001Address, exchange001Key, blockingStubFull)); + PublicMethod.injectExchange( + exchangeId, + assetAccountId1.toByteArray(), + injectBalance, + exchange001Address, + exchange001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long afterToken1Balance = 0L; - Long afterToken2Balance = 0L; + Long afterToken1Balance = 0L; + Long afterToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { afterToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -193,27 +246,28 @@ public void test4InjectExchange() { logger.info("before token 2 balance is " + Long.toString(afterToken2Balance)); Assert.assertTrue(beforeToken1Balance - afterToken1Balance == injectBalance); - Assert.assertTrue(beforeToken2Balance - afterToken2Balance == injectBalance - * exchangeRate); + Assert.assertTrue(beforeToken2Balance - afterToken2Balance == injectBalance * exchangeRate); exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); - Assert.assertTrue(afterExchangeToken1Balance - beforeExchangeToken1Balance - == injectBalance); - Assert.assertTrue(afterExchangeToken2Balance - beforeExchangeToken2Balance - == injectBalance * exchangeRate); + Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + Assert.assertTrue(afterExchangeToken1Balance - beforeExchangeToken1Balance == injectBalance); + Assert.assertTrue( + afterExchangeToken2Balance - beforeExchangeToken2Balance == injectBalance * exchangeRate); } - @Test(enabled = false,description = "Test withdraw exchange", groups = {"daily"}) + @Test( + enabled = false, + description = "Test withdraw exchange", + groups = {"daily"}) public void test5WithdrawExchange() { exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long beforeToken1Balance = 0L; - Long beforeToken2Balance = 0L; + Long beforeToken1Balance = 0L; + Long beforeToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { beforeToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -227,12 +281,17 @@ public void test5WithdrawExchange() { logger.info("before token 2 balance is " + Long.toString(beforeToken2Balance)); Integer withdrawNum = 200; Assert.assertTrue( - PublicMethod.exchangeWithdraw(exchangeId, assetAccountId1.toByteArray(), withdrawNum, - exchange001Address, exchange001Key, blockingStubFull)); + PublicMethod.exchangeWithdraw( + exchangeId, + assetAccountId1.toByteArray(), + withdrawNum, + exchange001Address, + exchange001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long afterToken1Balance = 0L; - Long afterToken2Balance = 0L; + Long afterToken1Balance = 0L; + Long afterToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { afterToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -246,30 +305,29 @@ public void test5WithdrawExchange() { logger.info("before token 2 balance is " + Long.toString(afterToken2Balance)); Assert.assertTrue(afterToken1Balance - beforeToken1Balance == withdrawNum); - Assert.assertTrue(afterToken2Balance - beforeToken2Balance == withdrawNum - * exchangeRate); + Assert.assertTrue(afterToken2Balance - beforeToken2Balance == withdrawNum * exchangeRate); exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); - Assert.assertTrue(afterExchangeToken1Balance - beforeExchangeToken1Balance - == -withdrawNum); - Assert.assertTrue(afterExchangeToken2Balance - beforeExchangeToken2Balance - == -withdrawNum * exchangeRate); - - + Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + Assert.assertTrue(afterExchangeToken1Balance - beforeExchangeToken1Balance == -withdrawNum); + Assert.assertTrue( + afterExchangeToken2Balance - beforeExchangeToken2Balance == -withdrawNum * exchangeRate); } - @Test(enabled = false,description = "Test exchange transaction", groups = {"daily"}) + @Test( + enabled = false, + description = "Test exchange transaction", + groups = {"daily"}) public void test6TransactionExchange() { exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); logger.info("beforeExchangeToken1Balance" + beforeExchangeToken1Balance); logger.info("beforeExchangeToken2Balance" + beforeExchangeToken2Balance); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long beforeToken1Balance = 0L; - Long beforeToken2Balance = 0L; + Long beforeToken1Balance = 0L; + Long beforeToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { beforeToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -283,13 +341,18 @@ public void test6TransactionExchange() { logger.info("before token 2 balance is " + Long.toString(beforeToken2Balance)); Integer transactionNum = 50; Assert.assertTrue( - PublicMethod - .exchangeTransaction(exchangeId, assetAccountId1.toByteArray(), transactionNum, 1, - exchange001Address, exchange001Key, blockingStubFull)); + PublicMethod.exchangeTransaction( + exchangeId, + assetAccountId1.toByteArray(), + transactionNum, + 1, + exchange001Address, + exchange001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long afterToken1Balance = 0L; - Long afterToken2Balance = 0L; + Long afterToken1Balance = 0L; + Long afterToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { afterToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -302,58 +365,63 @@ public void test6TransactionExchange() { logger.info("before token 2 balance is " + Long.toString(afterToken2Balance)); exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); logger.info("afterExchangeToken1Balance" + afterExchangeToken1Balance); logger.info("afterExchangeToken2Balance" + afterExchangeToken2Balance); - Assert.assertTrue(afterExchangeToken1Balance - beforeExchangeToken1Balance - == beforeToken1Balance - afterToken1Balance); - Assert.assertTrue(afterExchangeToken2Balance - beforeExchangeToken2Balance - == beforeToken2Balance - afterToken2Balance); + Assert.assertTrue( + afterExchangeToken1Balance - beforeExchangeToken1Balance + == beforeToken1Balance - afterToken1Balance); + Assert.assertTrue( + afterExchangeToken2Balance - beforeExchangeToken2Balance + == beforeToken2Balance - afterToken2Balance); } - @Test(enabled = false,description = "Test GetExchangeListPaginated api", groups = {"daily"}) + @Test( + enabled = false, + description = "Test GetExchangeListPaginated api", + groups = {"daily"}) public void test7GetExchangeListPaginated() { PaginatedMessage.Builder pageMessageBuilder = PaginatedMessage.newBuilder(); pageMessageBuilder.setOffset(0); pageMessageBuilder.setLimit(100); - ExchangeList exchangeList = blockingStubFull - .getPaginatedExchangeList(pageMessageBuilder.build()); + ExchangeList exchangeList = + blockingStubFull.getPaginatedExchangeList(pageMessageBuilder.build()); Assert.assertTrue(exchangeList.getExchangesCount() >= 1); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); - //Solidity support getExchangeId + // Solidity support getExchangeId exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubSolidity); logger.info("createtime is" + exchangeIdInfo.get().getCreateTime()); Assert.assertTrue(exchangeIdInfo.get().getCreateTime() > 0); - //Solidity support listexchange + // Solidity support listexchange listExchange = PublicMethod.getExchangeList(blockingStubSolidity); Assert.assertTrue(listExchange.get().getExchangesCount() > 0); } - /** - * constructor. - */ - @Test(enabled = false,description = "Test get exchange list from pbft", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = false, + description = "Test get exchange list from pbft", + groups = {"daily"}) public void test8GetExchangeListFromPbft() { - //Pbft support listexchange + // Pbft support listexchange listExchange = PublicMethod.getExchangeList(blockingStubPbft); Assert.assertTrue(listExchange.get().getExchangesCount() > 0); } - /** - * constructor. - */ - @Test(enabled = false,description = "Test get exchange by id from pbft", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = false, + description = "Test get exchange by id from pbft", + groups = {"daily"}) public void test9GetExchangeByIdFromPbft() { - Assert.assertEquals(PublicMethod.getExchange(exchangeId.toString(), blockingStubPbft), + Assert.assertEquals( + PublicMethod.getExchange(exchangeId.toString(), blockingStubPbft), PublicMethod.getExchange(exchangeId.toString(), blockingStubSolidity)); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue001.java index 36ee2b5e..a7af62d3 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue001.java @@ -24,8 +24,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestAssetIssue001 extends TronBaseTest { @@ -33,77 +33,96 @@ public class WalletTestAssetIssue001 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final long totalSupply = now; private static String name = "testAssetIssue001_" + Long.toString(now); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ECKey ecKey = new ECKey(Utils.getRandom()); byte[] noBandwitchAddress = ecKey.getAddress(); String noBandwitch = ByteArray.toHexString(ecKey.getPrivKeyBytes()); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Transfer asset use Bandwitch", groups = {"daily"}) + @Test( + enabled = true, + description = "Transfer asset use Bandwitch", + groups = {"daily"}) public void testTransferAssetBandwitchDecreaseWithin10Second() { - //get account + // get account ecKey = new ECKey(Utils.getRandom()); noBandwitchAddress = ecKey.getAddress(); noBandwitch = ByteArray.toHexString(ecKey.getPrivKeyBytes()); PublicMethod.printAddress(noBandwitch); - Assert.assertTrue(PublicMethod.sendcoin(noBandwitchAddress, 2048000000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + noBandwitchAddress, 2048000000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long start = System.currentTimeMillis() + 5000; - Long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(noBandwitchAddress, name, totalSupply, 1, - 100, start, end, 1, description, url, 10000L, 10000L, - 1L, 1L, noBandwitch, blockingStubFull)); + Long start = System.currentTimeMillis() + 5000; + Long end = System.currentTimeMillis() + 1000000000; + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + noBandwitchAddress, + name, + totalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + noBandwitch, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account getAssetIdFromThisAccount; getAssetIdFromThisAccount = PublicMethod.queryAccount(noBandwitch, blockingStubFull); ByteString assetAccountId = getAssetIdFromThisAccount.getAssetIssuedID(); - Assert.assertTrue(transferAsset(toAddress, assetAccountId.toByteArray(), 100L, - noBandwitchAddress, noBandwitch)); + Assert.assertTrue( + transferAsset( + toAddress, assetAccountId.toByteArray(), 100L, noBandwitchAddress, noBandwitch)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Transfer Asset failed when transfer to yourself - Assert.assertFalse(transferAsset(toAddress, assetAccountId.toByteArray(), 100L, - toAddress, testKey003)); - //Transfer Asset failed when the transfer amount is large than the asset balance you have. + // Transfer Asset failed when transfer to yourself + Assert.assertFalse( + transferAsset(toAddress, assetAccountId.toByteArray(), 100L, toAddress, testKey003)); + // Transfer Asset failed when the transfer amount is large than the asset balance you have. Assert.assertFalse( - transferAsset(foundationAddress, assetAccountId.toByteArray(), 9100000000000000000L, - toAddress, testKey003)); - //Transfer Asset failed when the transfer amount is 0 - Assert.assertFalse(transferAsset(foundationAddress, assetAccountId.toByteArray(), 0L, - toAddress, testKey003)); - //Transfer Asset failed when the transfer amount is -1 - Assert.assertFalse(transferAsset(foundationAddress, assetAccountId.toByteArray(), -1L, - toAddress, testKey003)); - //Transfer success. - Assert.assertTrue(transferAsset(foundationAddress, assetAccountId.toByteArray(), 1L, - toAddress, testKey003)); - //No freeze asset, try to unfreeze asset failed. + transferAsset( + foundationAddress, + assetAccountId.toByteArray(), + 9100000000000000000L, + toAddress, + testKey003)); + // Transfer Asset failed when the transfer amount is 0 + Assert.assertFalse( + transferAsset(foundationAddress, assetAccountId.toByteArray(), 0L, toAddress, testKey003)); + // Transfer Asset failed when the transfer amount is -1 + Assert.assertFalse( + transferAsset(foundationAddress, assetAccountId.toByteArray(), -1L, toAddress, testKey003)); + // Transfer success. + Assert.assertTrue( + transferAsset(foundationAddress, assetAccountId.toByteArray(), 1L, toAddress, testKey003)); + // No freeze asset, try to unfreeze asset failed. Assert.assertFalse(unFreezeAsset(noBandwitchAddress, noBandwitch)); - //Not create asset, try to unfreeze asset failed.No exception. + // Not create asset, try to unfreeze asset failed.No exception. Assert.assertFalse(unFreezeAsset(toAddress, testKey003)); - - } @AfterMethod @@ -111,19 +130,23 @@ public void aftertest() { PublicMethod.freeResource(noBandwitchAddress, noBandwitch, foundationAddress, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } - - /** - * constructor. - */ - public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, Integer trxNum, - Integer icoNum, Long startTime, Long endTime, - Integer voteScore, String description, String url, String priKey) { + public void shutdown() throws InterruptedException {} + + /** constructor. */ + public Boolean createAssetIssue( + byte[] address, + String name, + Long totalSupply, + Integer trxNum, + Integer icoNum, + Long startTime, + Long endTime, + Integer voteScore, + String description, + String url, + String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -167,19 +190,17 @@ public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, I } } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -189,23 +210,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -217,11 +233,9 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } - /** - * constructor. - */ - public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] address, - String priKey) { + /** constructor. */ + public boolean transferAsset( + byte[] to, byte[] assertName, long amount, byte[] address, String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -255,15 +269,12 @@ public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] a Account search = queryAccount(ecKey, blockingStubFull); return true; } - } - /** - * constructor. - */ + /** constructor. */ public boolean unFreezeAsset(byte[] addRess, String priKey) { byte[] address = addRess; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -272,8 +283,7 @@ public boolean unFreezeAsset(byte[] addRess, String priKey) { } final ECKey ecKey = temKey; - UnfreezeAssetContract.Builder builder = UnfreezeAssetContract - .newBuilder(); + UnfreezeAssetContract.Builder builder = UnfreezeAssetContract.newBuilder(); ByteString byteAddress = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddress); @@ -294,5 +304,3 @@ public boolean unFreezeAsset(byte[] addRess, String priKey) { return response.getResult(); } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue002.java index 592f41a5..a08b42eb 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue002.java @@ -23,8 +23,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestAssetIssue002 extends TronBaseTest { @@ -32,95 +32,135 @@ public class WalletTestAssetIssue002 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final long totalSupply = now; private static String name = "testAssetIssue002_" + Long.toString(now); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Participate token", groups = {"daily"}) + @Test( + enabled = true, + description = "Participate token", + groups = {"daily"}) public void testParticipateAssetissue() { - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] participateAccountAddress = ecKey1.getAddress(); - final String participateAccountKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - ECKey ecKey2 = new ECKey(Utils.getRandom()); - byte[] toAddress = ecKey2.getAddress(); - final String testKey003 = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - //send coin to the new account - Assert.assertTrue(PublicMethod.sendcoin(participateAccountAddress, 2048000000, foundationAddress, - foundationKey, blockingStubFull)); + byte[] participateAccountAddress = ecKey1.getAddress(); + final String participateAccountKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] toAddress = ecKey2.getAddress(); + final String testKey003 = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + // send coin to the new account + Assert.assertTrue( + PublicMethod.sendcoin( + participateAccountAddress, + 2048000000, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.sendcoin(toAddress, 2048000000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + toAddress, 2048000000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Create a new Asset Issue - Assert.assertTrue(PublicMethod.createAssetIssue(participateAccountAddress, - name, totalSupply, 1, 1, System.currentTimeMillis() + 5000, - System.currentTimeMillis() + 1000000000, 1, description, url, - 2000L, 2000L, 1L, 1L, - participateAccountKey, blockingStubFull)); + // Create a new Asset Issue + Assert.assertTrue( + PublicMethod.createAssetIssue( + participateAccountAddress, + name, + totalSupply, + 1, + 1, + System.currentTimeMillis() + 5000, + System.currentTimeMillis() + 1000000000, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + participateAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account getAssetIdFromThisAccount; getAssetIdFromThisAccount = PublicMethod.queryAccount(participateAccountKey, blockingStubFull); - final ByteString assetAccountId = getAssetIdFromThisAccount.getAssetIssuedID(); - //Participate AssetIssue success + final ByteString assetAccountId = getAssetIdFromThisAccount.getAssetIssuedID(); + // Participate AssetIssue success logger.info(name); - //Freeze amount to get bandwitch. - logger.info("toaddress balance is " - + PublicMethod.queryAccount(toAddress, blockingStubFull).getBalance()); - Assert.assertTrue(PublicMethod.freezeBalance(toAddress, 10000000, 3, testKey003, - blockingStubFull)); + // Freeze amount to get bandwitch. + logger.info( + "toaddress balance is " + + PublicMethod.queryAccount(toAddress, blockingStubFull).getBalance()); + Assert.assertTrue( + PublicMethod.freezeBalance(toAddress, 10000000, 3, testKey003, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.participateAssetIssue(participateAccountAddress, - assetAccountId.toByteArray(), - 100L, toAddress, testKey003, blockingStubFull)); + Assert.assertTrue( + PublicMethod.participateAssetIssue( + participateAccountAddress, + assetAccountId.toByteArray(), + 100L, + toAddress, + testKey003, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //The amount is large than the total supply, participate failed. - Assert.assertFalse(PublicMethod.participateAssetIssue(participateAccountAddress, - assetAccountId.toByteArray(), 9100000000000000000L, toAddress, testKey003, - blockingStubFull)); - //The amount is 0, participate asset issue failed. - Assert.assertFalse(PublicMethod.participateAssetIssue(participateAccountAddress, - assetAccountId.toByteArray(), 0L, toAddress, testKey003, blockingStubFull)); - //The amount is -1, participate asset issue failed. - Assert.assertFalse(PublicMethod.participateAssetIssue(participateAccountAddress, - assetAccountId.toByteArray(), -1L, toAddress, testKey003, blockingStubFull)); - //The asset issue owner address is not correct, participate asset issue failed. - Assert.assertFalse(PublicMethod.participateAssetIssue(foundationAddress, - assetAccountId.toByteArray(), 100L, - toAddress, testKey003, blockingStubFull)); + // The amount is large than the total supply, participate failed. + Assert.assertFalse( + PublicMethod.participateAssetIssue( + participateAccountAddress, + assetAccountId.toByteArray(), + 9100000000000000000L, + toAddress, + testKey003, + blockingStubFull)); + // The amount is 0, participate asset issue failed. + Assert.assertFalse( + PublicMethod.participateAssetIssue( + participateAccountAddress, + assetAccountId.toByteArray(), + 0L, + toAddress, + testKey003, + blockingStubFull)); + // The amount is -1, participate asset issue failed. + Assert.assertFalse( + PublicMethod.participateAssetIssue( + participateAccountAddress, + assetAccountId.toByteArray(), + -1L, + toAddress, + testKey003, + blockingStubFull)); + // The asset issue owner address is not correct, participate asset issue failed. + Assert.assertFalse( + PublicMethod.participateAssetIssue( + foundationAddress, + assetAccountId.toByteArray(), + 100L, + toAddress, + testKey003, + blockingStubFull)); - PublicMethod.freeResource(participateAccountAddress, participateAccountKey, foundationAddress, - blockingStubFull); + PublicMethod.freeResource( + participateAccountAddress, participateAccountKey, foundationAddress, blockingStubFull); PublicMethod.freeResource(toAddress, testKey003, foundationAddress, blockingStubFull); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ - public boolean participateAssetIssue(byte[] to, byte[] assertName, long amount, byte[] from, - String priKey) { + /** constructor. */ + public boolean participateAssetIssue( + byte[] to, byte[] assertName, long amount, byte[] from, String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -130,8 +170,7 @@ public boolean participateAssetIssue(byte[] to, byte[] assertName, long amount, } final ECKey ecKey = temKey; - ParticipateAssetIssueContract.Builder builder = ParticipateAssetIssueContract - .newBuilder(); + ParticipateAssetIssueContract.Builder builder = ParticipateAssetIssueContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); ByteString bsName = ByteString.copyFrom(assertName); ByteString bsOwner = ByteString.copyFrom(from); @@ -152,12 +191,20 @@ public boolean participateAssetIssue(byte[] to, byte[] assertName, long amount, } } - /** - * constructor. - */ - public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, Integer trxNum, - Integer icoNum, Long startTime, Long endTime, - Integer voteScore, String description, String url, Long fronzenAmount, Long frozenDay, + /** constructor. */ + public Boolean createAssetIssue( + byte[] address, + String name, + Long totalSupply, + Integer trxNum, + Integer icoNum, + Long startTime, + Long endTime, + Integer voteScore, + String description, + String url, + Long fronzenAmount, + Long frozenDay, String priKey) { ECKey temKey = null; try { @@ -204,12 +251,10 @@ public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, I } } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -218,13 +263,13 @@ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockin } ECKey ecKey = temKey; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -234,23 +279,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -262,11 +302,9 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } - /** - * constructor. - */ - public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] address, - String priKey) { + /** constructor. */ + public boolean transferAsset( + byte[] to, byte[] assertName, long amount, byte[] address, String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -297,11 +335,8 @@ public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] a logger.info(ByteArray.toStr(response.getMessage().toByteArray())); return false; } else { - //Account search = queryAccount(ecKey, blockingStubFull); + // Account search = queryAccount(ecKey, blockingStubFull); return true; } - } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue003.java index bc9435d2..f2cb87f5 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue003.java @@ -25,8 +25,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestAssetIssue003 extends TronBaseTest { @@ -48,139 +48,505 @@ public class WalletTestAssetIssue003 extends TronBaseTest { + "vqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqaz" + "xswedcvqazxswedcvqazxswedcvqazxswedcv"; private static final long totalSupply = now; - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - //get account + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + // get account ECKey ecKey = new ECKey(Utils.getRandom()); byte[] asset003Address = ecKey.getAddress(); String asset003Key = ByteArray.toHexString(ecKey.getPrivKeyBytes()); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Create token with exception condition", groups = {"daily"}) + @Test( + enabled = true, + description = "Create token with exception condition", + groups = {"daily"}) public void testExceptionOfAssetIssuew() { - PublicMethod.sendcoin(asset003Address, 2048000000L, foundationAddress, foundationKey, blockingStubFull); + PublicMethod.sendcoin( + asset003Address, 2048000000L, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long start = System.currentTimeMillis() + 100000; - Long end = System.currentTimeMillis() + 1000000000; - //Freeze amount is large than total supply, create asset issue failed. - Assert.assertFalse(PublicMethod.createAssetIssue(asset003Address, name, totalSupply, 1, 10, - start, end, 2, description, url, 10000L, 10000L, - 9000000000000000000L, 1L, asset003Key, blockingStubFull)); - //Freeze day is 0, create failed - Assert.assertFalse(PublicMethod.createAssetIssue(asset003Address, name, totalSupply, 1, 10, - start, end, 2, description, url, 10000L, 10000L, - 100L, 0L, asset003Key, blockingStubFull)); - //Freeze amount is 0, create failed - Assert.assertFalse(PublicMethod.createAssetIssue(asset003Address, name, totalSupply, 1, 10, - start, end, 2, description, url, 10000L, 10000L, - 0L, 1L, asset003Key, blockingStubFull)); - //Freeze day is -1, create failed - Assert.assertFalse(PublicMethod.createAssetIssue(asset003Address, name, totalSupply, 1, 10, - start, end, 2, description, url, 1000L, 1000L, - 1000L, -1L, asset003Key, blockingStubFull)); - //Freeze amount is -1, create failed - Assert.assertFalse(PublicMethod.createAssetIssue(asset003Address, name, totalSupply, 1, 10, - start, end, 2, description, url, 10000L, 10000L, - -1L, 1L, asset003Key, blockingStubFull)); - //Freeze day is 3653(10 years + 1 day), create failed - Assert.assertFalse(PublicMethod.createAssetIssue(foundationAddress, name, totalSupply, 1, 10, - start, end, 2, description, url, 10000L, 10000L, - 1L, 3653L, asset003Key, blockingStubFull)); - //Start time is late than end time. - Assert.assertFalse(PublicMethod.createAssetIssue(foundationAddress, name, totalSupply, 1, 10, - end, start, 2, description, url, 10000L, 10000L, - 1L, 2L, asset003Key, blockingStubFull)); - //Start time is early than currently time. - Assert.assertFalse(PublicMethod.createAssetIssue(foundationAddress, name, totalSupply, 1, 10, - start - 1000000L, end, 2, description, url, 10000L, - 10000L, 1L, 2L, asset003Key, blockingStubFull)); - //totalSupply is zero. - Assert.assertFalse(PublicMethod.createAssetIssue(foundationAddress, name, 0L, 1, 10, - start, end, 2, description, url, 10000L, 10000L, - 1L, 3652L, asset003Key, blockingStubFull)); - //Total supply is -1. - Assert.assertFalse(PublicMethod.createAssetIssue(foundationAddress, name, -1L, 1, 10, - start, end, 2, description, url, 10000L, 10000L, - 1L, 3652L, asset003Key, blockingStubFull)); - //TrxNum is zero. - Assert.assertFalse(PublicMethod.createAssetIssue(foundationAddress, name, totalSupply, 0, 10, - start, end, 2, description, url, 10000L, 10000L, - 1L, 3652L, asset003Key, blockingStubFull)); - //TrxNum is -1. - Assert.assertFalse(PublicMethod.createAssetIssue(foundationAddress, name, totalSupply, -1, 10, - start, end, 2, description, url, 10000L, 10000L, - 1L, 3652L, asset003Key, blockingStubFull)); - //IcoNum is 0. - Assert.assertFalse(PublicMethod.createAssetIssue(foundationAddress, name, totalSupply, 1, 0, - start, end, 2, description, url, 10000L, 10000L, - 1L, 3652L, asset003Key, blockingStubFull)); - //IcoNum is -1. - Assert.assertFalse(PublicMethod.createAssetIssue(foundationAddress, name, totalSupply, 1, -1, - start, end, 2, description, url, 10000L, 10000L, - 1L, 3652L, asset003Key, blockingStubFull)); - //The asset issue name is null. - Assert.assertFalse(PublicMethod.createAssetIssue(foundationAddress, "", totalSupply, 1, 10, - start, end, 2, description, url, 10000L, 10000L, - 1L, 3652L, asset003Key, blockingStubFull)); - //The asset issue name is large than 33 char. - Assert.assertFalse(PublicMethod.createAssetIssue(foundationAddress, tooLongName, totalSupply, 1, 10, - start, end, 2, description, url, 10000L, 10000L, - 1L, 3652L, asset003Key, blockingStubFull)); - //The asset issue name is chinese name. - Assert.assertFalse(PublicMethod.createAssetIssue(foundationAddress, chineseAssetIssuename, - totalSupply, 1, 10, start, end, 2, description, url, 10000L, - 10000L, 1L, 3652L, asset003Key, blockingStubFull)); - //The abbreviation is null. - Assert.assertFalse(PublicMethod.createAssetIssue(foundationAddress, name, "", totalSupply, - 1, 10, start, end, 2, description, url, 10000L, 10000L, - 1L, 3652L, asset003Key, blockingStubFull)); - //The abbreviation is large than 33 char. - Assert.assertFalse(PublicMethod.createAssetIssue(foundationAddress, name, tooLongAbbreviation, - totalSupply, 1, 10, start, end, 2, description, url, 10000L, - 10000L, 1L, 3652L, asset003Key, blockingStubFull)); - //The abbreviation is chinese name. - Assert.assertFalse(PublicMethod.createAssetIssue(foundationAddress, name, chineseAbbreviation, - totalSupply, 1, 10, start, end, 2, description, url, 10000L, - 10000L, 1L, 3652L, asset003Key, blockingStubFull)); - //The URL is null. - Assert.assertFalse(PublicMethod.createAssetIssue(foundationAddress, name, totalSupply, 1, 10, - start, end, 2, description, "", 10000L, 10000L, - 1L, 3652L, asset003Key, blockingStubFull)); - //The URL is too long. - Assert.assertFalse(PublicMethod.createAssetIssue(foundationAddress, name, totalSupply, - 1, 10, start, end, 2, description, tooLongUrl, 10000L, - 10000L, 1L, 3652L, asset003Key, blockingStubFull)); - //The description is null. - Assert.assertFalse(PublicMethod.createAssetIssue(foundationAddress, name, totalSupply, - 1, 10, start, end, 2, "", url, 10000L, - 10000L, 1L, 3652L, asset003Key, blockingStubFull)); - //The description is too long, create failed. - Assert.assertFalse(PublicMethod.createAssetIssue(foundationAddress, name, totalSupply, 1, 10, - start, end, 2, tooLongDescription, url, 10000L, - 10000L, 1L, 3652L, asset003Key, blockingStubFull)); + Long start = System.currentTimeMillis() + 100000; + Long end = System.currentTimeMillis() + 1000000000; + // Freeze amount is large than total supply, create asset issue failed. + Assert.assertFalse( + PublicMethod.createAssetIssue( + asset003Address, + name, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 9000000000000000000L, + 1L, + asset003Key, + blockingStubFull)); + // Freeze day is 0, create failed + Assert.assertFalse( + PublicMethod.createAssetIssue( + asset003Address, + name, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 100L, + 0L, + asset003Key, + blockingStubFull)); + // Freeze amount is 0, create failed + Assert.assertFalse( + PublicMethod.createAssetIssue( + asset003Address, + name, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 0L, + 1L, + asset003Key, + blockingStubFull)); + // Freeze day is -1, create failed + Assert.assertFalse( + PublicMethod.createAssetIssue( + asset003Address, + name, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 1000L, + 1000L, + 1000L, + -1L, + asset003Key, + blockingStubFull)); + // Freeze amount is -1, create failed + Assert.assertFalse( + PublicMethod.createAssetIssue( + asset003Address, + name, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + -1L, + 1L, + asset003Key, + blockingStubFull)); + // Freeze day is 3653(10 years + 1 day), create failed + Assert.assertFalse( + PublicMethod.createAssetIssue( + foundationAddress, + name, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3653L, + asset003Key, + blockingStubFull)); + // Start time is late than end time. + Assert.assertFalse( + PublicMethod.createAssetIssue( + foundationAddress, + name, + totalSupply, + 1, + 10, + end, + start, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 2L, + asset003Key, + blockingStubFull)); + // Start time is early than currently time. + Assert.assertFalse( + PublicMethod.createAssetIssue( + foundationAddress, + name, + totalSupply, + 1, + 10, + start - 1000000L, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 2L, + asset003Key, + blockingStubFull)); + // totalSupply is zero. + Assert.assertFalse( + PublicMethod.createAssetIssue( + foundationAddress, + name, + 0L, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + asset003Key, + blockingStubFull)); + // Total supply is -1. + Assert.assertFalse( + PublicMethod.createAssetIssue( + foundationAddress, + name, + -1L, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + asset003Key, + blockingStubFull)); + // TrxNum is zero. + Assert.assertFalse( + PublicMethod.createAssetIssue( + foundationAddress, + name, + totalSupply, + 0, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + asset003Key, + blockingStubFull)); + // TrxNum is -1. + Assert.assertFalse( + PublicMethod.createAssetIssue( + foundationAddress, + name, + totalSupply, + -1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + asset003Key, + blockingStubFull)); + // IcoNum is 0. + Assert.assertFalse( + PublicMethod.createAssetIssue( + foundationAddress, + name, + totalSupply, + 1, + 0, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + asset003Key, + blockingStubFull)); + // IcoNum is -1. + Assert.assertFalse( + PublicMethod.createAssetIssue( + foundationAddress, + name, + totalSupply, + 1, + -1, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + asset003Key, + blockingStubFull)); + // The asset issue name is null. + Assert.assertFalse( + PublicMethod.createAssetIssue( + foundationAddress, + "", + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + asset003Key, + blockingStubFull)); + // The asset issue name is large than 33 char. + Assert.assertFalse( + PublicMethod.createAssetIssue( + foundationAddress, + tooLongName, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + asset003Key, + blockingStubFull)); + // The asset issue name is chinese name. + Assert.assertFalse( + PublicMethod.createAssetIssue( + foundationAddress, + chineseAssetIssuename, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + asset003Key, + blockingStubFull)); + // The abbreviation is null. + Assert.assertFalse( + PublicMethod.createAssetIssue( + foundationAddress, + name, + "", + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + asset003Key, + blockingStubFull)); + // The abbreviation is large than 33 char. + Assert.assertFalse( + PublicMethod.createAssetIssue( + foundationAddress, + name, + tooLongAbbreviation, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + asset003Key, + blockingStubFull)); + // The abbreviation is chinese name. + Assert.assertFalse( + PublicMethod.createAssetIssue( + foundationAddress, + name, + chineseAbbreviation, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + asset003Key, + blockingStubFull)); + // The URL is null. + Assert.assertFalse( + PublicMethod.createAssetIssue( + foundationAddress, + name, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + "", + 10000L, + 10000L, + 1L, + 3652L, + asset003Key, + blockingStubFull)); + // The URL is too long. + Assert.assertFalse( + PublicMethod.createAssetIssue( + foundationAddress, + name, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + tooLongUrl, + 10000L, + 10000L, + 1L, + 3652L, + asset003Key, + blockingStubFull)); + // The description is null. + Assert.assertFalse( + PublicMethod.createAssetIssue( + foundationAddress, + name, + totalSupply, + 1, + 10, + start, + end, + 2, + "", + url, + 10000L, + 10000L, + 1L, + 3652L, + asset003Key, + blockingStubFull)); + // The description is too long, create failed. + Assert.assertFalse( + PublicMethod.createAssetIssue( + foundationAddress, + name, + totalSupply, + 1, + 10, + start, + end, + 2, + tooLongDescription, + url, + 10000L, + 10000L, + 1L, + 3652L, + asset003Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Get asset issue list", groups = {"daily"}) + @Test( + enabled = true, + description = "Get asset issue list", + groups = {"daily"}) public void testGetAllAssetIssue() { - GrpcAPI.AssetIssueList assetIssueList = blockingStubFull - .getAssetIssueList(GrpcAPI.EmptyMessage.newBuilder().build()); + GrpcAPI.AssetIssueList assetIssueList = + blockingStubFull.getAssetIssueList(GrpcAPI.EmptyMessage.newBuilder().build()); Assert.assertTrue(assetIssueList.getAssetIssueCount() >= 1); Integer times = assetIssueList.getAssetIssueCount(); if (assetIssueList.getAssetIssueCount() >= 10) { @@ -194,15 +560,14 @@ public void testGetAllAssetIssue() { logger.info("test get all assetissue"); } - //Improve coverage. + // Improve coverage. assetIssueList.equals(assetIssueList); assetIssueList.equals(null); - GrpcAPI.AssetIssueList newAssetIssueList = blockingStubFull - .getAssetIssueList(GrpcAPI.EmptyMessage.newBuilder().build()); + GrpcAPI.AssetIssueList newAssetIssueList = + blockingStubFull.getAssetIssueList(GrpcAPI.EmptyMessage.newBuilder().build()); assetIssueList.equals(newAssetIssueList); assetIssueList.hashCode(); assetIssueList.getSerializedSize(); - } @AfterMethod @@ -210,26 +575,21 @@ public void aftertest() { PublicMethod.freeResource(asset003Address, asset003Key, foundationAddress, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -239,23 +599,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -267,11 +622,9 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } - /** - * constructor. - */ - public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] address, - String priKey) { + /** constructor. */ + public boolean transferAsset( + byte[] to, byte[] assertName, long amount, byte[] address, String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -303,15 +656,12 @@ public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] a Account search = queryAccount(ecKey, blockingStubFull); return true; } - } - /** - * constructor. - */ + /** constructor. */ public boolean unFreezeAsset(byte[] addRess, String priKey) { byte[] address = addRess; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -320,8 +670,7 @@ public boolean unFreezeAsset(byte[] addRess, String priKey) { } final ECKey ecKey = temKey; - UnfreezeAssetContract.Builder builder = UnfreezeAssetContract - .newBuilder(); + UnfreezeAssetContract.Builder builder = UnfreezeAssetContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddreess); @@ -344,11 +693,9 @@ public boolean unFreezeAsset(byte[] addRess, String priKey) { } } - /** - * constructor. - */ - public boolean participateAssetIssue(byte[] to, byte[] assertName, long amount, byte[] from, - String priKey) { + /** constructor. */ + public boolean participateAssetIssue( + byte[] to, byte[] assertName, long amount, byte[] from, String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -358,8 +705,7 @@ public boolean participateAssetIssue(byte[] to, byte[] assertName, long amount, } final ECKey ecKey = temKey; - ParticipateAssetIssueContract.Builder builder = ParticipateAssetIssueContract - .newBuilder(); + ParticipateAssetIssueContract.Builder builder = ParticipateAssetIssueContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); ByteString bsName = ByteString.copyFrom(assertName); ByteString bsOwner = ByteString.copyFrom(from); @@ -379,7 +725,4 @@ public boolean participateAssetIssue(byte[] to, byte[] assertName, long amount, return true; } } - } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue004.java index 00c67e7a..0f8eaf22 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue004.java @@ -29,64 +29,77 @@ @Slf4j public class WalletTestAssetIssue004 extends TronBaseTest { - //testng001、testng002、testng003、testng004 + // testng001、testng002、testng003、testng004 /* private static final byte[] foundationAddress = Base58 - .decodeFromBase58Check("THph9K2M2nLvkianrMGswRhz5hjSA9fuH7");*/ - private static final byte[] NO_ASSET_ADDRESS = Base58 - .decodeFromBase58Check("27XeWZUtufGk8jdjF3m1tuPnnRqqKgzS3pT"); - private static final byte[] INVALID_ADDRESS = Base58 - .decodeFromBase58Check("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48"); + .decodeFromBase58Check("THph9K2M2nLvkianrMGswRhz5hjSA9fuH7");*/ + private static final byte[] NO_ASSET_ADDRESS = + Base58.decodeFromBase58Check("27XeWZUtufGk8jdjF3m1tuPnnRqqKgzS3pT"); + private static final byte[] INVALID_ADDRESS = + Base58.decodeFromBase58Check("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48"); private static final long now = System.currentTimeMillis(); private static final String name = "testAssetIssue004_" + Long.toString(now); private static final long totalSupply = now; - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); String description = "just-test"; String url = "https://github.com/tronprotocol/wallet-cli/"; + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { ByteString addressBs1 = ByteString.copyFrom(foundationAddress); + public void beforeClass() { + ByteString addressBs1 = ByteString.copyFrom(foundationAddress); Account request1 = Account.newBuilder().setAddress(addressBs1).build(); - GrpcAPI.AssetIssueList assetIssueList1 = blockingStubFull - .getAssetIssueByAccount(request1); + GrpcAPI.AssetIssueList assetIssueList1 = blockingStubFull.getAssetIssueByAccount(request1); Optional queryAssetByAccount = Optional.ofNullable(assetIssueList1); if (queryAssetByAccount.get().getAssetIssueCount() == 0) { Long start = System.currentTimeMillis() + 2000; - Long end = System.currentTimeMillis() + 1000000000; - //Create a new asset issue - Assert.assertTrue(PublicMethod.createAssetIssue(foundationAddress, name, totalSupply, 6, 1000, - start, end, 2, description, url, 10000L, 10000L, - 1L, 1L, foundationKey, blockingStubFull)); + Long end = System.currentTimeMillis() + 1000000000; + // Create a new asset issue + Assert.assertTrue( + PublicMethod.createAssetIssue( + foundationAddress, + name, + totalSupply, + 6, + 1000, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } else { logger.info("This account already create an assetisue"); } - } - @Test(enabled = true, description = "Get asset issue by account", groups = {"daily"}) + @Test( + enabled = true, + description = "Get asset issue by account", + groups = {"daily"}) public void testGetAssetIssueByAccount() { ByteString addressBs = ByteString.copyFrom(foundationAddress); Account request = Account.newBuilder().setAddress(addressBs).build(); - GrpcAPI.AssetIssueList assetIssueList = blockingStubFull - .getAssetIssueByAccount(request); + GrpcAPI.AssetIssueList assetIssueList = blockingStubFull.getAssetIssueByAccount(request); Optional queryAssetIssueByAccount = Optional.ofNullable(assetIssueList); logger.info(Integer.toString(queryAssetIssueByAccount.get().getAssetIssueCount())); Assert.assertTrue(queryAssetIssueByAccount.get().getAssetIssueCount() == 1); for (Integer j = 0; j < queryAssetIssueByAccount.get().getAssetIssueCount(); j++) { if (queryAssetIssueByAccount.get().getAssetIssue(j).getTotalSupply() == totalSupply) { Assert.assertTrue(queryAssetIssueByAccount.isPresent()); - //Assert.assertTrue(queryAssetIssueByAccount.get().getAssetIssue(j).getDecayRatio() > 0); + // Assert.assertTrue(queryAssetIssueByAccount.get().getAssetIssue(j).getDecayRatio() > 0); Assert.assertTrue(queryAssetIssueByAccount.get().getAssetIssue(j).getTrxNum() > 0); Assert.assertTrue(queryAssetIssueByAccount.get().getAssetIssue(j).getVoteScore() > 0); Assert.assertFalse(queryAssetIssueByAccount.get().getAssetIssue(j).getUrl().isEmpty()); @@ -94,38 +107,40 @@ public void testGetAssetIssueByAccount() { } } - //No exception when the address didn't create asset issue. + // No exception when the address didn't create asset issue. ByteString addressBS1 = ByteString.copyFrom(NO_ASSET_ADDRESS); Account request1 = Account.newBuilder().setAddress(addressBS1).build(); - GrpcAPI.AssetIssueList assetIssueList1 = blockingStubFull - .getAssetIssueByAccount(request1); + GrpcAPI.AssetIssueList assetIssueList1 = blockingStubFull.getAssetIssueByAccount(request1); Optional queryNoAssetByAccount = Optional.ofNullable(assetIssueList1); Assert.assertTrue(queryNoAssetByAccount.get().getAssetIssueCount() == 0); logger.info("No asset account queryed nothing"); - //No exception when the address is invalid. + // No exception when the address is invalid. addressBS1 = ByteString.copyFrom(INVALID_ADDRESS); request1 = Account.newBuilder().setAddress(addressBS1).build(); - assetIssueList1 = blockingStubFull - .getAssetIssueByAccount(request1); + assetIssueList1 = blockingStubFull.getAssetIssueByAccount(request1); queryNoAssetByAccount = Optional.ofNullable(assetIssueList1); Assert.assertTrue(queryNoAssetByAccount.get().getAssetIssueCount() == 0); logger.info("No asset account queryed nothing"); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ - public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, Integer trxNum, - Integer icoNum, Long startTime, Long endTime, - Integer voteScore, String description, String url, Long fronzenAmount, Long frozenDay, + /** constructor. */ + public Boolean createAssetIssue( + byte[] address, + String name, + Long totalSupply, + Integer trxNum, + Integer icoNum, + Long startTime, + Long endTime, + Integer voteScore, + String description, + String url, + Long fronzenAmount, + Long frozenDay, String priKey) { ECKey temKey = null; try { @@ -150,9 +165,8 @@ public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, I builder.setUrl(ByteString.copyFrom(url.getBytes())); builder.setFreeAssetNetLimit(20000); builder.setPublicFreeAssetNetLimit(20000); - AssetIssueContract.FrozenSupply.Builder - frozenBuilder = AssetIssueContract.FrozenSupply - .newBuilder(); + AssetIssueContract.FrozenSupply.Builder frozenBuilder = + AssetIssueContract.FrozenSupply.newBuilder(); frozenBuilder.setFrozenAmount(fronzenAmount); frozenBuilder.setFrozenDays(frozenDay); builder.addFrozenSupply(0, frozenBuilder); @@ -173,19 +187,17 @@ public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, I } } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -195,23 +207,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -223,11 +230,9 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } - /** - * constructor. - */ - public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] address, - String priKey) { + /** constructor. */ + public boolean transferAsset( + byte[] to, byte[] assertName, long amount, byte[] address, String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -259,5 +264,3 @@ public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] a return response.getResult(); } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue005.java index 1840c5ed..6ca0ea56 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue005.java @@ -1,7 +1,6 @@ package stest.tron.wallet.dailybuild.assetissue; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.math.BigInteger; import java.util.Optional; @@ -35,44 +34,57 @@ public class WalletTestAssetIssue005 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final long totalSupply = now; private static String name = "testAssetIssue005_" + Long.toString(now); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); String description = "just-test"; String url = "https://github.com/tronprotocol/wallet-cli/"; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "Get asset issue by name", groups = {"daily"}) + @Test( + enabled = true, + description = "Get asset issue by name", + groups = {"daily"}) public void testGetAssetIssueByName() { ByteString addressBS1 = ByteString.copyFrom(foundationAddress); Account request1 = Account.newBuilder().setAddress(addressBS1).build(); - GrpcAPI.AssetIssueList assetIssueList1 = blockingStubFull - .getAssetIssueByAccount(request1); + GrpcAPI.AssetIssueList assetIssueList1 = blockingStubFull.getAssetIssueByAccount(request1); Optional queryAssetByAccount = Optional.ofNullable(assetIssueList1); if (queryAssetByAccount.get().getAssetIssueCount() == 0) { Long start = System.currentTimeMillis() + 2000; - Long end = System.currentTimeMillis() + 1000000000; - //Create a new asset issue - Assert.assertTrue(PublicMethod.createAssetIssue(foundationAddress, name, totalSupply, 1, 100, - start, end, 1, description, url, 10000L, 10000L, - 1L, 1L, foundationKey, blockingStubFull)); + Long end = System.currentTimeMillis() + 1000000000; + // Create a new asset issue + Assert.assertTrue( + PublicMethod.createAssetIssue( + foundationAddress, + name, + totalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } else { logger.info("This account already create an assetisue"); @@ -83,18 +95,17 @@ public void testGetAssetIssueByName() { Account getAssetIdFromThisAccount; getAssetIdFromThisAccount = PublicMethod.queryAccount(foundationKey, blockingStubFull); ByteString assetAccountId = getAssetIdFromThisAccount.getAssetIssuedID(); - //Get asset issue by name success. + // Get asset issue by name success. - GrpcAPI.BytesMessage request = GrpcAPI.BytesMessage.newBuilder().setValue(assetAccountId) - .build(); - AssetIssueContract assetIssueByName = - blockingStubFull.getAssetIssueByName(request); + GrpcAPI.BytesMessage request = + GrpcAPI.BytesMessage.newBuilder().setValue(assetAccountId).build(); + AssetIssueContract assetIssueByName = blockingStubFull.getAssetIssueByName(request); Assert.assertFalse(assetIssueByName.getUrl().isEmpty()); Assert.assertFalse(assetIssueByName.getDescription().isEmpty()); Assert.assertTrue(assetIssueByName.getTotalSupply() > 0); Assert.assertTrue(assetIssueByName.getTrxNum() > 0); - //Get asset issue by name failed when the name is not correct.There is no exception. + // Get asset issue by name failed when the name is not correct.There is no exception. String wrongName = name + "_wrong"; ByteString assetNameBs = ByteString.copyFrom(name.getBytes()); assetNameBs = ByteString.copyFrom(wrongName.getBytes()); @@ -107,19 +118,24 @@ public void testGetAssetIssueByName() { Assert.assertTrue(assetIssueByName.getDescription().isEmpty()); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ - public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, Integer trxNum, - Integer icoNum, Long startTime, Long endTime, - Integer voteScore, String description, String url, Long fronzenAmount, Long frozenDay, + /** constructor. */ + public Boolean createAssetIssue( + byte[] address, + String name, + Long totalSupply, + Integer trxNum, + Integer icoNum, + Long startTime, + Long endTime, + Integer voteScore, + String description, + String url, + Long fronzenAmount, + Long frozenDay, String priKey) { ECKey temKey = null; try { @@ -145,8 +161,7 @@ public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, I builder.setFreeAssetNetLimit(20000); builder.setPublicFreeAssetNetLimit(20000); AssetIssueContract.FrozenSupply.Builder frozenBuilder = - AssetIssueContract.FrozenSupply - .newBuilder(); + AssetIssueContract.FrozenSupply.newBuilder(); frozenBuilder.setFrozenAmount(fronzenAmount); frozenBuilder.setFrozenDays(frozenDay); builder.addFrozenSupply(0, frozenBuilder); @@ -167,19 +182,17 @@ public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, I } } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -189,23 +202,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -217,11 +225,9 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } - /** - * constructor. - */ - public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] address, - String priKey) { + /** constructor. */ + public boolean transferAsset( + byte[] to, byte[] assertName, long amount, byte[] address, String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -255,8 +261,5 @@ public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] a Account search = queryAccount(ecKey, blockingStubFull); return true; } - } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue006.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue006.java index a800dfe5..f9e0abf8 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue006.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue006.java @@ -1,7 +1,6 @@ package stest.tron.wallet.dailybuild.assetissue; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -17,8 +16,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestAssetIssue006 extends TronBaseTest { @@ -26,29 +25,30 @@ public class WalletTestAssetIssue006 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final long totalSupply = now; private static String name = "assetissue006" + Long.toString(now); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); String description = "test query assetissue by timestamp from soliditynode"; String url = "https://testqueryassetissue.com/bytimestamp/from/soliditynode/"; - //get account + // get account ECKey ecKey = new ECKey(Utils.getRandom()); byte[] queryAssetIssueFromSoliAddress = ecKey.getAddress(); String queryAssetIssueKey = ByteArray.toHexString(ecKey.getPrivKeyBytes()); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - /* @Test(enabled = true, groups = {"daily"}) public void testGetAssetIssueListByTimestamp() { Assert.assertTrue(PublicMethod.freezeBalance(foundationAddress,10000000,3,foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(queryAssetIssueFromSoliAddress,2048000000,foundationAddress, - foundationKey,blockingStubFull)); + Assert.assertTrue(PublicMethod.sendcoin( + queryAssetIssueFromSoliAddress, 2048000000, + foundationAddress, foundationKey, blockingStubFull)); Long start = System.currentTimeMillis() + 2000; Long end = System.currentTimeMillis() + 1000000000; //Create a new AssetIssue success. @@ -118,39 +118,28 @@ public void testExceptionGetAssetIssueListByTimestamp() { }*/ - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = false) - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = false) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -160,24 +149,17 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue007.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue007.java index 0e15af79..48221911 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue007.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue007.java @@ -13,8 +13,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestAssetIssue007 extends TronBaseTest { @@ -26,15 +26,15 @@ public class WalletTestAssetIssue007 extends TronBaseTest { private static final Integer trxNum = 1; private static final Integer icoNum = 1; private static String name = "AssetIssue007_" + Long.toString(now); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); Long freeAssetNetLimit = 10000L; Long publicFreeAssetNetLimit = 10000L; - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] asset007Address = ecKey1.getAddress(); String testKeyForAssetIssue007 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -42,67 +42,98 @@ public class WalletTestAssetIssue007 extends TronBaseTest { byte[] participateAssetAddress = ecKey2.getAddress(); String participateAssetCreateKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(testKeyForAssetIssue007); - PublicMethod.printAddress(participateAssetCreateKey); } + PublicMethod.printAddress(participateAssetCreateKey); + } - @Test(enabled = true, description = "Participate asset issue use participate bandwidth", groups = {"daily"}) + @Test( + enabled = true, + description = "Participate asset issue use participate bandwidth", + groups = {"daily"}) public void testParticipateAssetIssueUseParticipateBandwidth() { - Assert.assertTrue(PublicMethod - .sendcoin(asset007Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + asset007Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long start = System.currentTimeMillis() + 5000; - Long end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod - .createAssetIssue(asset007Address, name, totalSupply, trxNum, icoNum, start, end, 1, - description, url, freeAssetNetLimit, publicFreeAssetNetLimit, 1L, 1L, - testKeyForAssetIssue007, blockingStubFull)); + Long start = System.currentTimeMillis() + 5000; + Long end = System.currentTimeMillis() + 1000000000; + Assert.assertTrue( + PublicMethod.createAssetIssue( + asset007Address, + name, + totalSupply, + trxNum, + icoNum, + start, + end, + 1, + description, + url, + freeAssetNetLimit, + publicFreeAssetNetLimit, + 1L, + 1L, + testKeyForAssetIssue007, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info(name); - //Assert.assertTrue(PublicMethod.waitProduceNextBlock(blockingStubFull)); - //When no balance, participate an asset issue - Assert.assertFalse(PublicMethod - .participateAssetIssue(asset007Address, name.getBytes(), 1L, participateAssetAddress, - participateAssetCreateKey, blockingStubFull)); + // Assert.assertTrue(PublicMethod.waitProduceNextBlock(blockingStubFull)); + // When no balance, participate an asset issue + Assert.assertFalse( + PublicMethod.participateAssetIssue( + asset007Address, + name.getBytes(), + 1L, + participateAssetAddress, + participateAssetCreateKey, + blockingStubFull)); ByteString addressBs = ByteString.copyFrom(asset007Address); Account request = Account.newBuilder().setAddress(addressBs).build(); AccountNetMessage asset007NetMessage = blockingStubFull.getAccountNet(request); - final Long asset007BeforeFreeNetUsed = asset007NetMessage.getFreeNetUsed(); - //SendCoin to participate account. - Assert.assertTrue(PublicMethod - .sendcoin(participateAssetAddress, 10000000L, foundationAddress, foundationKey, blockingStubFull)); + final Long asset007BeforeFreeNetUsed = asset007NetMessage.getFreeNetUsed(); + // SendCoin to participate account. + Assert.assertTrue( + PublicMethod.sendcoin( + participateAssetAddress, + 10000000L, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); addressBs = ByteString.copyFrom(participateAssetAddress); request = Account.newBuilder().setAddress(addressBs).build(); AccountNetMessage participateAccountNetMessage = blockingStubFull.getAccountNet(request); - final Long participateAccountBeforeNetUsed = participateAccountNetMessage.getFreeNetUsed(); + final Long participateAccountBeforeNetUsed = participateAccountNetMessage.getFreeNetUsed(); Assert.assertTrue(participateAccountBeforeNetUsed == 0); Account getAssetIdFromThisAccount; getAssetIdFromThisAccount = PublicMethod.queryAccount(asset007Address, blockingStubFull); ByteString assetAccountId = getAssetIdFromThisAccount.getAssetIssuedID(); logger.info(assetAccountId.toString()); - //Participate an assetIssue, then query the net information. - Assert.assertTrue(PublicMethod - .participateAssetIssue(asset007Address, assetAccountId.toByteArray(), 1L, - participateAssetAddress, participateAssetCreateKey, blockingStubFull)); + // Participate an assetIssue, then query the net information. + Assert.assertTrue( + PublicMethod.participateAssetIssue( + asset007Address, + assetAccountId.toByteArray(), + 1L, + participateAssetAddress, + participateAssetCreateKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); addressBs = ByteString.copyFrom(asset007Address); request = Account.newBuilder().setAddress(addressBs).build(); asset007NetMessage = blockingStubFull.getAccountNet(request); - final Long asset007AfterFreeNetUsed = asset007NetMessage.getFreeNetUsed(); + final Long asset007AfterFreeNetUsed = asset007NetMessage.getFreeNetUsed(); addressBs = ByteString.copyFrom(participateAssetAddress); request = Account.newBuilder().setAddress(addressBs).build(); participateAccountNetMessage = blockingStubFull.getAccountNet(request); - final Long participateAccountAfterNetUsed = participateAccountNetMessage.getFreeNetUsed(); + final Long participateAccountAfterNetUsed = participateAccountNetMessage.getFreeNetUsed(); logger.info(Long.toString(asset007BeforeFreeNetUsed)); logger.info(Long.toString(asset007AfterFreeNetUsed)); @@ -111,38 +142,48 @@ public void testParticipateAssetIssueUseParticipateBandwidth() { Assert.assertTrue(asset007AfterFreeNetUsed <= asset007BeforeFreeNetUsed); Assert.assertTrue(participateAccountAfterNetUsed - participateAccountBeforeNetUsed > 150); - Assert.assertTrue(PublicMethod - .participateAssetIssue(asset007Address, assetAccountId.toByteArray(), 1L, - participateAssetAddress, participateAssetCreateKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.participateAssetIssue( + asset007Address, + assetAccountId.toByteArray(), + 1L, + participateAssetAddress, + participateAssetCreateKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod - .participateAssetIssue(asset007Address, assetAccountId.toByteArray(), 1L, - participateAssetAddress, participateAssetCreateKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.participateAssetIssue( + asset007Address, + assetAccountId.toByteArray(), + 1L, + participateAssetAddress, + participateAssetCreateKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Account participateInfo = PublicMethod - .queryAccount(participateAssetCreateKey, blockingStubFull); - final Long beforeBalance = participateInfo.getBalance(); - Assert.assertTrue(PublicMethod - .participateAssetIssue(asset007Address, assetAccountId.toByteArray(), 1L, - participateAssetAddress, participateAssetCreateKey, blockingStubFull)); + Account participateInfo = + PublicMethod.queryAccount(participateAssetCreateKey, blockingStubFull); + final Long beforeBalance = participateInfo.getBalance(); + Assert.assertTrue( + PublicMethod.participateAssetIssue( + asset007Address, + assetAccountId.toByteArray(), + 1L, + participateAssetAddress, + participateAssetCreateKey, + blockingStubFull)); participateInfo = PublicMethod.queryAccount(participateAssetCreateKey, blockingStubFull); - final Long afterBalance = participateInfo.getBalance(); + final Long afterBalance = participateInfo.getBalance(); Assert.assertTrue(beforeBalance - trxNum * 1 * icoNum >= afterBalance); } @AfterMethod public void aftertest() { - PublicMethod - .freeResource(asset007Address, testKeyForAssetIssue007, foundationAddress, blockingStubFull); + PublicMethod.freeResource( + asset007Address, testKeyForAssetIssue007, foundationAddress, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue008.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue008.java index 11ef50c7..679692c3 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue008.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue008.java @@ -1,7 +1,6 @@ package stest.tron.wallet.dailybuild.assetissue; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.math.BigInteger; import lombok.extern.slf4j.Slf4j; @@ -26,8 +25,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestAssetIssue008 extends TronBaseTest { @@ -35,64 +34,86 @@ public class WalletTestAssetIssue008 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final long totalSupply = now; private static String name = "assetissue008" + Long.toString(now); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); String description = "test query assetissue from soliditynode"; String url = "https://testqueryassetissue.com/from/soliditynode/"; - //get account + // get account ECKey ecKey = new ECKey(Utils.getRandom()); byte[] queryAssetIssueFromSoliAddress = ecKey.getAddress(); String queryAssetIssueKey = ByteArray.toHexString(ecKey.getPrivKeyBytes()); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - logger.info(ByteArray.toHexString(ecKey.getPrivKeyBytes())); channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + logger.info(ByteArray.toHexString(ecKey.getPrivKeyBytes())); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = true, description = "Get asset issue list from Solidity", groups = {"daily"}) + @Test( + enabled = true, + description = "Get asset issue list from Solidity", + groups = {"daily"}) public void testGetAllAssetIssueFromSolidity() { - Assert.assertTrue(PublicMethod.sendcoin(queryAssetIssueFromSoliAddress, 2048000000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + queryAssetIssueFromSoliAddress, + 2048000000, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long start = System.currentTimeMillis() + 2000; - Long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(queryAssetIssueFromSoliAddress, name, - totalSupply, 1, 100, start, end, 1, description, url, 10000L, - 10000L, 1L, 1L, queryAssetIssueKey, blockingStubFull)); + Long start = System.currentTimeMillis() + 2000; + Long end = System.currentTimeMillis() + 1000000000; + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + queryAssetIssueFromSoliAddress, + name, + totalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + queryAssetIssueKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - GrpcAPI.AssetIssueList assetIssueList = blockingStubSolidity - .getAssetIssueList(GrpcAPI.EmptyMessage.newBuilder().build()); + GrpcAPI.AssetIssueList assetIssueList = + blockingStubSolidity.getAssetIssueList(GrpcAPI.EmptyMessage.newBuilder().build()); logger.info(Long.toString(assetIssueList.getAssetIssueCount())); if (assetIssueList.getAssetIssueCount() == 0) { - Assert.assertTrue(PublicMethod.freezeBalance(foundationAddress, 10000000L, 3, - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(toAddress, 999999L, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance( + foundationAddress, 10000000L, 3, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + toAddress, 999999L, foundationAddress, foundationKey, blockingStubFull)); Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - logger.info("fullnode block num is " + Long.toString(currentBlock.getBlockHeader() - .getRawData().getNumber())); + logger.info( + "fullnode block num is " + + Long.toString(currentBlock.getBlockHeader().getRawData().getNumber())); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); } - assetIssueList = blockingStubSolidity - .getAssetIssueList(GrpcAPI.EmptyMessage.newBuilder().build()); + assetIssueList = + blockingStubSolidity.getAssetIssueList(GrpcAPI.EmptyMessage.newBuilder().build()); Assert.assertTrue(assetIssueList.getAssetIssueCount() >= 1); for (Integer j = 0; j < assetIssueList.getAssetIssueCount(); j++) { Assert.assertFalse(assetIssueList.getAssetIssue(j).getOwnerAddress().isEmpty()); @@ -101,35 +122,29 @@ public void testGetAllAssetIssueFromSolidity() { Assert.assertTrue(assetIssueList.getAssetIssue(j).getTotalSupply() > 0); logger.info("test get all assetissue from solidity"); } - } @AfterMethod public void aftertest() { - PublicMethod.freeResource(queryAssetIssueFromSoliAddress, queryAssetIssueKey, foundationAddress, - blockingStubFull); + PublicMethod.freeResource( + queryAssetIssueFromSoliAddress, queryAssetIssueKey, foundationAddress, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -139,23 +154,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -167,11 +177,9 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } - /** - * constructor. - */ - public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] address, - String priKey) { + /** constructor. */ + public boolean transferAsset( + byte[] to, byte[] assertName, long amount, byte[] address, String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -203,15 +211,12 @@ public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] a Account search = queryAccount(ecKey, blockingStubFull); return true; } - } - /** - * constructor. - */ + /** constructor. */ public boolean unFreezeAsset(byte[] addRess, String priKey) { byte[] address = addRess; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -219,10 +224,9 @@ public boolean unFreezeAsset(byte[] addRess, String priKey) { ex.printStackTrace(); } final ECKey ecKey = temKey; - //Account search = queryAccount(ecKey, blockingStubFull); + // Account search = queryAccount(ecKey, blockingStubFull); - UnfreezeAssetContract.Builder builder = UnfreezeAssetContract - .newBuilder(); + UnfreezeAssetContract.Builder builder = UnfreezeAssetContract.newBuilder(); ByteString byteAddress = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddress); @@ -243,5 +247,3 @@ public boolean unFreezeAsset(byte[] addRess, String priKey) { return response.getResult(); } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue009.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue009.java index b241ffed..a3bc4245 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue009.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue009.java @@ -1,7 +1,6 @@ package stest.tron.wallet.dailybuild.assetissue; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -21,17 +20,18 @@ import stest.tron.wallet.common.client.utils.TronBaseTest; @Slf4j -public class WalletTestAssetIssue009 extends TronBaseTest { private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); +public class WalletTestAssetIssue009 extends TronBaseTest { + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - /* @Test(enabled = true, groups = {"daily"}) public void testGetAssetIssueByAccountOrNameFromSolidity() { //By name @@ -64,37 +64,28 @@ public void testGetAssetIssueByAccountOrNameFromSolidity() { logger.info("TestGetAssetIssueByNameFromSolidity"); }*/ - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = false) - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = false) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -104,23 +95,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -132,5 +118,3 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue010.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue010.java index a6958ac4..b8068fdb 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue010.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue010.java @@ -26,8 +26,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestAssetIssue010 extends TronBaseTest { @@ -39,13 +39,14 @@ public class WalletTestAssetIssue010 extends TronBaseTest { "1qazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcv" + "qazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswe" + "dcvqazxswedcvqazxswedcvqazxswedcvqazxswedcv"; - private static final String tooLongUrl = "qaswqaswqaswqaswqaswqaswqaswqaswqaswqaswqaswqas" - + "wqaswqasw1qazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazx" - + "swedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedc" - + "vqazxswedcvqazxswedcvqazxswedcvqazxswedcv"; + private static final String tooLongUrl = + "qaswqaswqaswqaswqaswqaswqaswqaswqaswqaswqaswqas" + + "wqaswqasw1qazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazx" + + "swedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedc" + + "vqazxswedcvqazxswedcvqazxswedcvqazxswedcv"; private static String name = "testAssetIssue010_" + Long.toString(now); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); String description = "just-test"; String url = "https://github.com/tronprotocol/wallet-cli/"; @@ -55,51 +56,67 @@ public class WalletTestAssetIssue010 extends TronBaseTest { Long publicFreeAssetNetLimit = 1000L; Long updateFreeAssetNetLimit = 10001L; Long updatePublicFreeAssetNetLimit = 10001L; - //get account + // get account ECKey ecKey = new ECKey(Utils.getRandom()); byte[] asset010Address = ecKey.getAddress(); String testKeyForAssetIssue010 = ByteArray.toHexString(ecKey.getPrivKeyBytes()); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Update asset issue", groups = {"daily"}) + @Test( + enabled = true, + description = "Update asset issue", + groups = {"daily"}) public void testUpdateAssetIssue() { ecKey = new ECKey(Utils.getRandom()); asset010Address = ecKey.getAddress(); testKeyForAssetIssue010 = ByteArray.toHexString(ecKey.getPrivKeyBytes()); PublicMethod.printAddress(testKeyForAssetIssue010); - Assert.assertTrue(PublicMethod - .sendcoin(asset010Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + asset010Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalance(asset010Address, 200000000L, 0, testKeyForAssetIssue010, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance( + asset010Address, 200000000L, 0, testKeyForAssetIssue010, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long start = System.currentTimeMillis() + 2000; - Long end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod.createAssetIssue(asset010Address, name, totalSupply, 1, 1, - start, end, 1, description, url, freeAssetNetLimit, publicFreeAssetNetLimit, - 1L, 1L, testKeyForAssetIssue010, blockingStubFull)); + Long start = System.currentTimeMillis() + 2000; + Long end = System.currentTimeMillis() + 1000000000; + Assert.assertTrue( + PublicMethod.createAssetIssue( + asset010Address, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + freeAssetNetLimit, + publicFreeAssetNetLimit, + 1L, + 1L, + testKeyForAssetIssue010, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account getAssetIdFromThisAccount; - getAssetIdFromThisAccount = PublicMethod - .queryAccount(testKeyForAssetIssue010, blockingStubFull); + getAssetIdFromThisAccount = + PublicMethod.queryAccount(testKeyForAssetIssue010, blockingStubFull); ByteString assetAccountId = getAssetIdFromThisAccount.getAssetIssuedID(); - //Query the description and url,freeAssetNetLimit and publicFreeAssetNetLimit - GrpcAPI.BytesMessage request = GrpcAPI.BytesMessage.newBuilder() - .setValue(assetAccountId).build(); + // Query the description and url,freeAssetNetLimit and publicFreeAssetNetLimit + GrpcAPI.BytesMessage request = + GrpcAPI.BytesMessage.newBuilder().setValue(assetAccountId).build(); AssetIssueContract assetIssueByName = blockingStubFull.getAssetIssueByName(request); Assert.assertTrue( @@ -107,13 +124,18 @@ public void testUpdateAssetIssue() { Assert.assertTrue(ByteArray.toStr(assetIssueByName.getUrl().toByteArray()).equals(url)); Assert.assertTrue(assetIssueByName.getFreeAssetNetLimit() == freeAssetNetLimit); Assert.assertTrue(assetIssueByName.getPublicFreeAssetNetLimit() == publicFreeAssetNetLimit); - //Test update asset issue - Assert.assertTrue(PublicMethod - .updateAsset(asset010Address, updateDescription.getBytes(), updateUrl.getBytes(), + // Test update asset issue + Assert.assertTrue( + PublicMethod.updateAsset( + asset010Address, + updateDescription.getBytes(), + updateUrl.getBytes(), updateFreeAssetNetLimit, - updatePublicFreeAssetNetLimit, testKeyForAssetIssue010, blockingStubFull)); + updatePublicFreeAssetNetLimit, + testKeyForAssetIssue010, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //After update asset issue ,query the description and url, + // After update asset issue ,query the description and url, // freeAssetNetLimit and publicFreeAssetNetLimit assetIssueByName = blockingStubFull.getAssetIssueByName(request); @@ -121,74 +143,126 @@ public void testUpdateAssetIssue() { ByteArray.toStr(assetIssueByName.getDescription().toByteArray()).equals(updateDescription)); Assert.assertTrue(ByteArray.toStr(assetIssueByName.getUrl().toByteArray()).equals(updateUrl)); Assert.assertTrue(assetIssueByName.getFreeAssetNetLimit() == updateFreeAssetNetLimit); - Assert - .assertTrue(assetIssueByName.getPublicFreeAssetNetLimit() == updatePublicFreeAssetNetLimit); + Assert.assertTrue( + assetIssueByName.getPublicFreeAssetNetLimit() == updatePublicFreeAssetNetLimit); } - @Test(enabled = true, description = "Update asset issue with exception condition", groups = {"daily"}) + @Test( + enabled = true, + description = "Update asset issue with exception condition", + groups = {"daily"}) public void testUpdateAssetIssueException() { - //Test update asset issue for wrong parameter - //publicFreeAssetNetLimit is -1 - Assert.assertFalse(PublicMethod - .updateAsset(asset010Address, updateDescription.getBytes(), updateUrl.getBytes(), + // Test update asset issue for wrong parameter + // publicFreeAssetNetLimit is -1 + Assert.assertFalse( + PublicMethod.updateAsset( + asset010Address, + updateDescription.getBytes(), + updateUrl.getBytes(), updateFreeAssetNetLimit, - -1L, testKeyForAssetIssue010, blockingStubFull)); - //publicFreeAssetNetLimit is 0 - Assert.assertTrue(PublicMethod - .updateAsset(asset010Address, updateDescription.getBytes(), updateUrl.getBytes(), + -1L, + testKeyForAssetIssue010, + blockingStubFull)); + // publicFreeAssetNetLimit is 0 + Assert.assertTrue( + PublicMethod.updateAsset( + asset010Address, + updateDescription.getBytes(), + updateUrl.getBytes(), updateFreeAssetNetLimit, - 0, testKeyForAssetIssue010, blockingStubFull)); + 0, + testKeyForAssetIssue010, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //FreeAssetNetLimit is -1 - Assert.assertFalse(PublicMethod - .updateAsset(asset010Address, updateDescription.getBytes(), updateUrl.getBytes(), -1, - publicFreeAssetNetLimit, testKeyForAssetIssue010, blockingStubFull)); - //FreeAssetNetLimit is 0 - Assert.assertTrue(PublicMethod - .updateAsset(asset010Address, updateDescription.getBytes(), updateUrl.getBytes(), 0, - publicFreeAssetNetLimit, testKeyForAssetIssue010, blockingStubFull)); + // FreeAssetNetLimit is -1 + Assert.assertFalse( + PublicMethod.updateAsset( + asset010Address, + updateDescription.getBytes(), + updateUrl.getBytes(), + -1, + publicFreeAssetNetLimit, + testKeyForAssetIssue010, + blockingStubFull)); + // FreeAssetNetLimit is 0 + Assert.assertTrue( + PublicMethod.updateAsset( + asset010Address, + updateDescription.getBytes(), + updateUrl.getBytes(), + 0, + publicFreeAssetNetLimit, + testKeyForAssetIssue010, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Description is null - Assert.assertTrue(PublicMethod - .updateAsset(asset010Address, "".getBytes(), updateUrl.getBytes(), freeAssetNetLimit, - publicFreeAssetNetLimit, testKeyForAssetIssue010, blockingStubFull)); - //Url is null - Assert.assertFalse(PublicMethod - .updateAsset(asset010Address, description.getBytes(), "".getBytes(), freeAssetNetLimit, - publicFreeAssetNetLimit, testKeyForAssetIssue010, blockingStubFull)); - //Too long discription - Assert.assertFalse(PublicMethod - .updateAsset(asset010Address, tooLongDescription.getBytes(), url.getBytes(), + // Description is null + Assert.assertTrue( + PublicMethod.updateAsset( + asset010Address, + "".getBytes(), + updateUrl.getBytes(), freeAssetNetLimit, - publicFreeAssetNetLimit, testKeyForAssetIssue010, blockingStubFull)); - //Too long URL - Assert.assertFalse(PublicMethod - .updateAsset(asset010Address, description.getBytes(), tooLongUrl.getBytes(), + publicFreeAssetNetLimit, + testKeyForAssetIssue010, + blockingStubFull)); + // Url is null + Assert.assertFalse( + PublicMethod.updateAsset( + asset010Address, + description.getBytes(), + "".getBytes(), freeAssetNetLimit, - publicFreeAssetNetLimit, testKeyForAssetIssue010, blockingStubFull)); + publicFreeAssetNetLimit, + testKeyForAssetIssue010, + blockingStubFull)); + // Too long discription + Assert.assertFalse( + PublicMethod.updateAsset( + asset010Address, + tooLongDescription.getBytes(), + url.getBytes(), + freeAssetNetLimit, + publicFreeAssetNetLimit, + testKeyForAssetIssue010, + blockingStubFull)); + // Too long URL + Assert.assertFalse( + PublicMethod.updateAsset( + asset010Address, + description.getBytes(), + tooLongUrl.getBytes(), + freeAssetNetLimit, + publicFreeAssetNetLimit, + testKeyForAssetIssue010, + blockingStubFull)); } @AfterMethod public void aftertest() { - PublicMethod - .freeResource(asset010Address, testKeyForAssetIssue010, foundationAddress, blockingStubFull); - PublicMethod.unFreezeBalance(asset010Address, testKeyForAssetIssue010, 0, asset010Address, - blockingStubFull); + PublicMethod.freeResource( + asset010Address, testKeyForAssetIssue010, foundationAddress, blockingStubFull); + PublicMethod.unFreezeBalance( + asset010Address, testKeyForAssetIssue010, 0, asset010Address, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } - - /** - * constructor. - */ - public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, Integer trxNum, - Integer icoNum, Long startTime, Long endTime, - Integer voteScore, String description, String url, Long fronzenAmount, Long frozenDay, + public void shutdown() throws InterruptedException {} + + /** constructor. */ + public Boolean createAssetIssue( + byte[] address, + String name, + Long totalSupply, + Integer trxNum, + Integer icoNum, + Long startTime, + Long endTime, + Integer voteScore, + String description, + String url, + Long fronzenAmount, + Long frozenDay, String priKey) { ECKey temKey = null; try { @@ -213,8 +287,7 @@ public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, I builder.setDescription(ByteString.copyFrom(description.getBytes())); builder.setUrl(ByteString.copyFrom(url.getBytes())); AssetIssueContract.FrozenSupply.Builder frozenBuilder = - AssetIssueContract.FrozenSupply - .newBuilder(); + AssetIssueContract.FrozenSupply.newBuilder(); frozenBuilder.setFrozenAmount(fronzenAmount); frozenBuilder.setFrozenDays(frozenDay); builder.addFrozenSupply(0, frozenBuilder); @@ -239,19 +312,17 @@ public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, I } } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -261,23 +332,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -289,11 +355,9 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } - /** - * constructor. - */ - public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] address, - String priKey) { + /** constructor. */ + public boolean transferAsset( + byte[] to, byte[] assertName, long amount, byte[] address, String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -325,15 +389,12 @@ public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] a Account search = queryAccount(ecKey, blockingStubFull); return true; } - } - /** - * constructor. - */ + /** constructor. */ public boolean unFreezeAsset(byte[] addRess, String priKey) { byte[] address = addRess; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -342,8 +403,7 @@ public boolean unFreezeAsset(byte[] addRess, String priKey) { } final ECKey ecKey = temKey; - UnfreezeAssetContract.Builder builder = UnfreezeAssetContract - .newBuilder(); + UnfreezeAssetContract.Builder builder = UnfreezeAssetContract.newBuilder(); ByteString byteAddress = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddress); @@ -366,11 +426,9 @@ public boolean unFreezeAsset(byte[] addRess, String priKey) { } } - /** - * constructor. - */ - public boolean participateAssetIssue(byte[] to, byte[] assertName, long amount, byte[] from, - String priKey) { + /** constructor. */ + public boolean participateAssetIssue( + byte[] to, byte[] assertName, long amount, byte[] from, String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -380,8 +438,7 @@ public boolean participateAssetIssue(byte[] to, byte[] assertName, long amount, } final ECKey ecKey = temKey; - ParticipateAssetIssueContract.Builder builder = ParticipateAssetIssueContract - .newBuilder(); + ParticipateAssetIssueContract.Builder builder = ParticipateAssetIssueContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); ByteString bsName = ByteString.copyFrom(assertName); ByteString bsOwner = ByteString.copyFrom(from); @@ -401,7 +458,4 @@ public boolean participateAssetIssue(byte[] to, byte[] assertName, long amount, return true; } } - } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue011.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue011.java index 2d433ac0..c837b120 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue011.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue011.java @@ -11,8 +11,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestAssetIssue011 extends TronBaseTest { @@ -22,14 +22,14 @@ public class WalletTestAssetIssue011 extends TronBaseTest { private static final long sendAmount = 10000000000L; private static final String updateMostLongName = Long.toString(now) + "w234567890123456789"; private static String name = "testAssetIssue011_" + Long.toString(now); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); Long freeAssetNetLimit = 10000L; Long publicFreeAssetNetLimit = 10000L; String description = "just-test"; String url = "https://github.com/tronprotocol/wallet-cli/"; - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] asset011Address = ecKey1.getAddress(); String testKeyForAssetIssue011 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -37,18 +37,19 @@ public class WalletTestAssetIssue011 extends TronBaseTest { byte[] transferAssetCreateAddress = ecKey2.getAddress(); String transferAssetCreateKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(testKeyForAssetIssue011); - PublicMethod.printAddress(transferAssetCreateKey); } + PublicMethod.printAddress(transferAssetCreateKey); + } - @Test(enabled = true, description = "Transfer asset to create account", groups = {"daily"}) + @Test( + enabled = true, + description = "Transfer asset to create account", + groups = {"daily"}) public void testTransferAssetCreateAccount() { - //get account + // get account ecKey1 = new ECKey(Utils.getRandom()); asset011Address = ecKey1.getAddress(); testKeyForAssetIssue011 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -57,51 +58,73 @@ public void testTransferAssetCreateAccount() { transferAssetCreateAddress = ecKey2.getAddress(); transferAssetCreateKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod - .sendcoin(asset011Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + asset011Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalance(asset011Address, 100000000L, 3, testKeyForAssetIssue011, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance( + asset011Address, 100000000L, 3, testKeyForAssetIssue011, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long start = System.currentTimeMillis() + 2000; - Long end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod - .createAssetIssue(asset011Address, name, totalSupply, 1, 1, start, end, 1, description, - url, freeAssetNetLimit, publicFreeAssetNetLimit, 1L, 1L, testKeyForAssetIssue011, + Long start = System.currentTimeMillis() + 2000; + Long end = System.currentTimeMillis() + 1000000000; + Assert.assertTrue( + PublicMethod.createAssetIssue( + asset011Address, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + freeAssetNetLimit, + publicFreeAssetNetLimit, + 1L, + 1L, + testKeyForAssetIssue011, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account getAssetIdFromThisAccount; getAssetIdFromThisAccount = PublicMethod.queryAccount(asset011Address, blockingStubFull); ByteString assetAccountId = getAssetIdFromThisAccount.getAssetIssuedID(); - //Transfer asset to create an account. - Assert.assertTrue(PublicMethod - .transferAsset(transferAssetCreateAddress, assetAccountId.toByteArray(), 1L, - asset011Address, testKeyForAssetIssue011, blockingStubFull)); + // Transfer asset to create an account. + Assert.assertTrue( + PublicMethod.transferAsset( + transferAssetCreateAddress, + assetAccountId.toByteArray(), + 1L, + asset011Address, + testKeyForAssetIssue011, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Account queryTransferAssetAccount = PublicMethod - .queryAccount(transferAssetCreateKey, blockingStubFull); + Account queryTransferAssetAccount = + PublicMethod.queryAccount(transferAssetCreateKey, blockingStubFull); Assert.assertTrue(queryTransferAssetAccount.getAssetV2Count() == 1); - Assert.assertTrue(PublicMethod.updateAccount(asset011Address, Long.toString(now) - .getBytes(), testKeyForAssetIssue011, blockingStubFull)); - Assert.assertTrue(PublicMethod.updateAccount(transferAssetCreateAddress, updateMostLongName - .getBytes(), transferAssetCreateKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.updateAccount( + asset011Address, + Long.toString(now).getBytes(), + testKeyForAssetIssue011, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.updateAccount( + transferAssetCreateAddress, + updateMostLongName.getBytes(), + transferAssetCreateKey, + blockingStubFull)); queryTransferAssetAccount = PublicMethod.queryAccount(transferAssetCreateKey, blockingStubFull); Assert.assertFalse(queryTransferAssetAccount.getAccountName().isEmpty()); - PublicMethod - .freeResource(asset011Address, testKeyForAssetIssue011, foundationAddress, blockingStubFull); - PublicMethod.unFreezeBalance(asset011Address, testKeyForAssetIssue011, 0, asset011Address, - blockingStubFull); - + PublicMethod.freeResource( + asset011Address, testKeyForAssetIssue011, foundationAddress, blockingStubFull); + PublicMethod.unFreezeBalance( + asset011Address, testKeyForAssetIssue011, 0, asset011Address, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue012.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue012.java index 73ebe55d..8779831d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue012.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue012.java @@ -12,8 +12,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestAssetIssue012 extends TronBaseTest { @@ -23,14 +23,14 @@ public class WalletTestAssetIssue012 extends TronBaseTest { private static final long sendAmount = 10000000000L; private static final long netCostMeasure = 200L; private static String name = "AssetIssue012_" + Long.toString(now); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); Long freeAssetNetLimit = 10000L; Long publicFreeAssetNetLimit = 10000L; String description = "for case assetissue012"; String url = "https://stest.assetissue012.url"; - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] asset012Address = ecKey1.getAddress(); String testKeyForAssetIssue012 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -38,18 +38,19 @@ public class WalletTestAssetIssue012 extends TronBaseTest { byte[] transferAssetAddress = ecKey2.getAddress(); String transferAssetCreateKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { logger.info(testKeyForAssetIssue012); - logger.info(transferAssetCreateKey); } + logger.info(transferAssetCreateKey); + } - @Test(enabled = true, description = "Transfer asset use token owner net", groups = {"daily"}) + @Test( + enabled = true, + description = "Transfer asset use token owner net", + groups = {"daily"}) public void testTransferAssetUseCreatorNet() { - //get account + // get account ecKey1 = new ECKey(Utils.getRandom()); asset012Address = ecKey1.getAddress(); testKeyForAssetIssue012 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -61,67 +62,86 @@ public void testTransferAssetUseCreatorNet() { PublicMethod.printAddress(testKeyForAssetIssue012); PublicMethod.printAddress(transferAssetCreateKey); - Assert.assertTrue(PublicMethod - .sendcoin(asset012Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + asset012Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalance(asset012Address, 100000000L, 3, testKeyForAssetIssue012, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance( + asset012Address, 100000000L, 3, testKeyForAssetIssue012, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long start = System.currentTimeMillis() + 2000; - Long end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod - .createAssetIssue(asset012Address, name, totalSupply, 1, 1, start, end, 1, description, - url, freeAssetNetLimit, publicFreeAssetNetLimit, 1L, 1L, testKeyForAssetIssue012, + Long start = System.currentTimeMillis() + 2000; + Long end = System.currentTimeMillis() + 1000000000; + Assert.assertTrue( + PublicMethod.createAssetIssue( + asset012Address, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + freeAssetNetLimit, + publicFreeAssetNetLimit, + 1L, + 1L, + testKeyForAssetIssue012, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account getAssetIdFromThisAccount; getAssetIdFromThisAccount = PublicMethod.queryAccount(asset012Address, blockingStubFull); ByteString assetAccountId = getAssetIdFromThisAccount.getAssetIssuedID(); - //Transfer asset to an account. - Assert.assertTrue(PublicMethod.transferAsset( - transferAssetAddress, assetAccountId.toByteArray(), 10000000L, asset012Address, - testKeyForAssetIssue012, blockingStubFull)); + // Transfer asset to an account. + Assert.assertTrue( + PublicMethod.transferAsset( + transferAssetAddress, + assetAccountId.toByteArray(), + 10000000L, + asset012Address, + testKeyForAssetIssue012, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Before transfer asset issue, query the net used from creator and transfer. - AccountNetMessage assetCreatorNet = PublicMethod - .getAccountNet(asset012Address, blockingStubFull); - AccountNetMessage assetTransferNet = PublicMethod - .getAccountNet(transferAssetAddress, blockingStubFull); - Long creatorBeforeNetUsed = assetCreatorNet.getNetUsed(); - Long transferBeforeFreeNetUsed = assetTransferNet.getFreeNetUsed(); + // Before transfer asset issue, query the net used from creator and transfer. + AccountNetMessage assetCreatorNet = + PublicMethod.getAccountNet(asset012Address, blockingStubFull); + AccountNetMessage assetTransferNet = + PublicMethod.getAccountNet(transferAssetAddress, blockingStubFull); + Long creatorBeforeNetUsed = assetCreatorNet.getNetUsed(); + Long transferBeforeFreeNetUsed = assetTransferNet.getFreeNetUsed(); logger.info(Long.toString(creatorBeforeNetUsed)); logger.info(Long.toString(transferBeforeFreeNetUsed)); - //Transfer send some asset issue to default account, to test if this + // Transfer send some asset issue to default account, to test if this // transaction use the creator net. - Assert.assertTrue(PublicMethod.transferAsset(toAddress, assetAccountId.toByteArray(), 1L, - transferAssetAddress, transferAssetCreateKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + toAddress, + assetAccountId.toByteArray(), + 1L, + transferAssetAddress, + transferAssetCreateKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - assetCreatorNet = PublicMethod - .getAccountNet(asset012Address, blockingStubFull); - assetTransferNet = PublicMethod - .getAccountNet(transferAssetAddress, blockingStubFull); - Long creatorAfterNetUsed = assetCreatorNet.getNetUsed(); - Long transferAfterFreeNetUsed = assetTransferNet.getFreeNetUsed(); + assetCreatorNet = PublicMethod.getAccountNet(asset012Address, blockingStubFull); + assetTransferNet = PublicMethod.getAccountNet(transferAssetAddress, blockingStubFull); + Long creatorAfterNetUsed = assetCreatorNet.getNetUsed(); + Long transferAfterFreeNetUsed = assetTransferNet.getFreeNetUsed(); logger.info(Long.toString(creatorAfterNetUsed)); logger.info(Long.toString(transferAfterFreeNetUsed)); Assert.assertTrue(creatorAfterNetUsed - creatorBeforeNetUsed > netCostMeasure); Assert.assertTrue(transferAfterFreeNetUsed - transferBeforeFreeNetUsed < netCostMeasure); - PublicMethod - .freeResource(asset012Address, testKeyForAssetIssue012, foundationAddress, blockingStubFull); - PublicMethod.unFreezeBalance(asset012Address, testKeyForAssetIssue012, 0, asset012Address, - blockingStubFull); + PublicMethod.freeResource( + asset012Address, testKeyForAssetIssue012, foundationAddress, blockingStubFull); + PublicMethod.unFreezeBalance( + asset012Address, testKeyForAssetIssue012, 0, asset012Address, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue013.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue013.java index 80774ec1..e648dc1d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue013.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue013.java @@ -12,8 +12,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestAssetIssue013 extends TronBaseTest { @@ -23,14 +23,14 @@ public class WalletTestAssetIssue013 extends TronBaseTest { private static final long sendAmount = 10000000000L; private static final long netCostMeasure = 200L; private static String name = "AssetIssue013_" + Long.toString(now); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); Long freeAssetNetLimit = 300L; Long publicFreeAssetNetLimit = 3000L; String description = "for case assetissue013"; String url = "https://stest.assetissue013.url"; - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] asset013Address = ecKey1.getAddress(); String testKeyForAssetIssue013 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -38,92 +38,117 @@ public class WalletTestAssetIssue013 extends TronBaseTest { byte[] transferAssetAddress = ecKey2.getAddress(); String transferAssetCreateKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Use transfer net when token owner has no enough net", groups = {"daily"}) + @Test( + enabled = true, + description = "Use transfer net when token owner has no enough net", + groups = {"daily"}) public void testWhenNoEnoughFreeAssetNetLimitUseTransferNet() { - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] asset013Address = ecKey1.getAddress(); - final String testKeyForAssetIssue013 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - ECKey ecKey2 = new ECKey(Utils.getRandom()); - final byte[] transferAssetAddress = ecKey2.getAddress(); - final String transferAssetCreateKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + byte[] asset013Address = ecKey1.getAddress(); + final String testKeyForAssetIssue013 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + final byte[] transferAssetAddress = ecKey2.getAddress(); + final String transferAssetCreateKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); logger.info(testKeyForAssetIssue013); logger.info(transferAssetCreateKey); - Assert.assertTrue(PublicMethod - .sendcoin(asset013Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + asset013Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalance(asset013Address, 100000000L, 3, testKeyForAssetIssue013, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance( + asset013Address, 100000000L, 3, testKeyForAssetIssue013, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long start = System.currentTimeMillis() + 2000; - Long end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod - .createAssetIssue(asset013Address, name, totalSupply, 1, 1, start, end, 1, description, - url, freeAssetNetLimit, publicFreeAssetNetLimit, 1L, 1L, testKeyForAssetIssue013, + Long start = System.currentTimeMillis() + 2000; + Long end = System.currentTimeMillis() + 1000000000; + Assert.assertTrue( + PublicMethod.createAssetIssue( + asset013Address, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + freeAssetNetLimit, + publicFreeAssetNetLimit, + 1L, + 1L, + testKeyForAssetIssue013, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account getAssetIdFromThisAccount; getAssetIdFromThisAccount = PublicMethod.queryAccount(asset013Address, blockingStubFull); ByteString assetAccountId = getAssetIdFromThisAccount.getAssetIssuedID(); - //Transfer asset to an account. - Assert.assertTrue(PublicMethod.transferAsset( - transferAssetAddress, assetAccountId.toByteArray(), - 10000000L, asset013Address, testKeyForAssetIssue013, blockingStubFull)); + // Transfer asset to an account. + Assert.assertTrue( + PublicMethod.transferAsset( + transferAssetAddress, + assetAccountId.toByteArray(), + 10000000L, + asset013Address, + testKeyForAssetIssue013, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Transfer send some asset issue to default account, to test if this + // Transfer send some asset issue to default account, to test if this // transaction use the creator net. - Assert.assertTrue(PublicMethod.transferAsset(toAddress, assetAccountId.toByteArray(), 1L, - transferAssetAddress, transferAssetCreateKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + toAddress, + assetAccountId.toByteArray(), + 1L, + transferAssetAddress, + transferAssetCreateKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Before use transfer net, query the net used from creator and transfer. - AccountNetMessage assetCreatorNet = PublicMethod - .getAccountNet(asset013Address, blockingStubFull); - AccountNetMessage assetTransferNet = PublicMethod - .getAccountNet(transferAssetAddress, blockingStubFull); - Long creatorBeforeNetUsed = assetCreatorNet.getNetUsed(); - Long transferBeforeFreeNetUsed = assetTransferNet.getFreeNetUsed(); + // Before use transfer net, query the net used from creator and transfer. + AccountNetMessage assetCreatorNet = + PublicMethod.getAccountNet(asset013Address, blockingStubFull); + AccountNetMessage assetTransferNet = + PublicMethod.getAccountNet(transferAssetAddress, blockingStubFull); + Long creatorBeforeNetUsed = assetCreatorNet.getNetUsed(); + Long transferBeforeFreeNetUsed = assetTransferNet.getFreeNetUsed(); logger.info(Long.toString(creatorBeforeNetUsed)); logger.info(Long.toString(transferBeforeFreeNetUsed)); - //Transfer send some asset issue to default account, to test if this + // Transfer send some asset issue to default account, to test if this // transaction use the transaction free net. - Assert.assertTrue(PublicMethod.transferAsset(toAddress, assetAccountId.toByteArray(), 1L, - transferAssetAddress, transferAssetCreateKey, blockingStubFull)); - assetCreatorNet = PublicMethod - .getAccountNet(asset013Address, blockingStubFull); - assetTransferNet = PublicMethod - .getAccountNet(transferAssetAddress, blockingStubFull); - Long creatorAfterNetUsed = assetCreatorNet.getNetUsed(); - Long transferAfterFreeNetUsed = assetTransferNet.getFreeNetUsed(); + Assert.assertTrue( + PublicMethod.transferAsset( + toAddress, + assetAccountId.toByteArray(), + 1L, + transferAssetAddress, + transferAssetCreateKey, + blockingStubFull)); + assetCreatorNet = PublicMethod.getAccountNet(asset013Address, blockingStubFull); + assetTransferNet = PublicMethod.getAccountNet(transferAssetAddress, blockingStubFull); + Long creatorAfterNetUsed = assetCreatorNet.getNetUsed(); + Long transferAfterFreeNetUsed = assetTransferNet.getFreeNetUsed(); logger.info(Long.toString(creatorAfterNetUsed)); logger.info(Long.toString(transferAfterFreeNetUsed)); Assert.assertTrue(creatorAfterNetUsed - creatorBeforeNetUsed < netCostMeasure); Assert.assertTrue(transferAfterFreeNetUsed - transferBeforeFreeNetUsed > netCostMeasure); - PublicMethod - .freeResource(asset013Address, testKeyForAssetIssue013, foundationAddress, blockingStubFull); - PublicMethod.unFreezeBalance(asset013Address, testKeyForAssetIssue013, 0, asset013Address, - blockingStubFull); + PublicMethod.freeResource( + asset013Address, testKeyForAssetIssue013, foundationAddress, blockingStubFull); + PublicMethod.unFreezeBalance( + asset013Address, testKeyForAssetIssue013, 0, asset013Address, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue014.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue014.java index e81341c8..ad93ad30 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue014.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue014.java @@ -12,8 +12,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestAssetIssue014 extends TronBaseTest { @@ -23,14 +23,14 @@ public class WalletTestAssetIssue014 extends TronBaseTest { private static final long sendAmount = 10000000000L; private static final long netCostMeasure = 200L; private static String name = "AssetIssue014_" + Long.toString(now); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); Long freeAssetNetLimit = 3000L; Long publicFreeAssetNetLimit = 300L; String description = "for case assetissue014"; String url = "https://stest.assetissue014.url"; - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] asset014Address = ecKey1.getAddress(); String testKeyForAssetIssue014 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -38,18 +38,19 @@ public class WalletTestAssetIssue014 extends TronBaseTest { byte[] transferAssetAddress = ecKey2.getAddress(); String transferAssetCreateKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { logger.info(testKeyForAssetIssue014); - logger.info(transferAssetCreateKey); } + logger.info(transferAssetCreateKey); + } - @Test(enabled = true, description = "Use transfer net when no enough public free asset net", groups = {"daily"}) + @Test( + enabled = true, + description = "Use transfer net when no enough public free asset net", + groups = {"daily"}) public void testWhenNoEnoughPublicFreeAssetNetLimitUseTransferNet() { - //get account + // get account ecKey1 = new ECKey(Utils.getRandom()); asset014Address = ecKey1.getAddress(); testKeyForAssetIssue014 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -58,69 +59,94 @@ public void testWhenNoEnoughPublicFreeAssetNetLimitUseTransferNet() { transferAssetAddress = ecKey2.getAddress(); transferAssetCreateKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod - .sendcoin(asset014Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + asset014Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long start = System.currentTimeMillis() + 2000; - Long end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod - .createAssetIssue(asset014Address, name, totalSupply, 1, 1, start, end, 1, description, - url, freeAssetNetLimit, publicFreeAssetNetLimit, 1L, 1L, testKeyForAssetIssue014, + Long start = System.currentTimeMillis() + 2000; + Long end = System.currentTimeMillis() + 1000000000; + Assert.assertTrue( + PublicMethod.createAssetIssue( + asset014Address, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + freeAssetNetLimit, + publicFreeAssetNetLimit, + 1L, + 1L, + testKeyForAssetIssue014, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account getAssetIdFromThisAccount; getAssetIdFromThisAccount = PublicMethod.queryAccount(asset014Address, blockingStubFull); ByteString assetAccountId = getAssetIdFromThisAccount.getAssetIssuedID(); - //Transfer asset to an account. + // Transfer asset to an account. PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod - .transferAsset(transferAssetAddress, assetAccountId.toByteArray(), 10000000L, - asset014Address, testKeyForAssetIssue014, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + transferAssetAddress, + assetAccountId.toByteArray(), + 10000000L, + asset014Address, + testKeyForAssetIssue014, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Transfer send some asset issue to default account, to test if this + // Transfer send some asset issue to default account, to test if this // transaction use the creator net. - Assert.assertTrue(PublicMethod.transferAsset(toAddress, assetAccountId.toByteArray(), 1L, - transferAssetAddress, transferAssetCreateKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + toAddress, + assetAccountId.toByteArray(), + 1L, + transferAssetAddress, + transferAssetCreateKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Before use transfer net, query the net used from creator and transfer. - AccountNetMessage assetCreatorNet = PublicMethod - .getAccountNet(asset014Address, blockingStubFull); - AccountNetMessage assetTransferNet = PublicMethod - .getAccountNet(transferAssetAddress, blockingStubFull); - Long creatorBeforeNetUsed = assetCreatorNet.getNetUsed(); - Long transferBeforeFreeNetUsed = assetTransferNet.getFreeNetUsed(); + // Before use transfer net, query the net used from creator and transfer. + AccountNetMessage assetCreatorNet = + PublicMethod.getAccountNet(asset014Address, blockingStubFull); + AccountNetMessage assetTransferNet = + PublicMethod.getAccountNet(transferAssetAddress, blockingStubFull); + Long creatorBeforeNetUsed = assetCreatorNet.getNetUsed(); + Long transferBeforeFreeNetUsed = assetTransferNet.getFreeNetUsed(); logger.info(Long.toString(creatorBeforeNetUsed)); logger.info(Long.toString(transferBeforeFreeNetUsed)); - //Transfer send some asset issue to default account, to test if this + // Transfer send some asset issue to default account, to test if this // transaction use the transaction free net. - Assert.assertTrue(PublicMethod.transferAsset(toAddress, assetAccountId.toByteArray(), 1L, - transferAssetAddress, transferAssetCreateKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + toAddress, + assetAccountId.toByteArray(), + 1L, + transferAssetAddress, + transferAssetCreateKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - assetCreatorNet = PublicMethod - .getAccountNet(asset014Address, blockingStubFull); - assetTransferNet = PublicMethod - .getAccountNet(transferAssetAddress, blockingStubFull); - Long creatorAfterNetUsed = assetCreatorNet.getNetUsed(); - Long transferAfterFreeNetUsed = assetTransferNet.getFreeNetUsed(); + assetCreatorNet = PublicMethod.getAccountNet(asset014Address, blockingStubFull); + assetTransferNet = PublicMethod.getAccountNet(transferAssetAddress, blockingStubFull); + Long creatorAfterNetUsed = assetCreatorNet.getNetUsed(); + Long transferAfterFreeNetUsed = assetTransferNet.getFreeNetUsed(); logger.info(Long.toString(creatorAfterNetUsed)); logger.info(Long.toString(transferAfterFreeNetUsed)); Assert.assertTrue(creatorAfterNetUsed - creatorBeforeNetUsed < netCostMeasure); Assert.assertTrue(transferAfterFreeNetUsed - transferBeforeFreeNetUsed > netCostMeasure); - PublicMethod - .freeResource(asset014Address, testKeyForAssetIssue014, foundationAddress, blockingStubFull); - PublicMethod.unFreezeBalance(asset014Address, testKeyForAssetIssue014, 0, asset014Address, - blockingStubFull); + PublicMethod.freeResource( + asset014Address, testKeyForAssetIssue014, foundationAddress, blockingStubFull); + PublicMethod.unFreezeBalance( + asset014Address, testKeyForAssetIssue014, 0, asset014Address, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue015.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue015.java index 382932f6..be763d66 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue015.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue015.java @@ -12,8 +12,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestAssetIssue015 extends TronBaseTest { @@ -23,15 +23,15 @@ public class WalletTestAssetIssue015 extends TronBaseTest { private static final long sendAmount = 10000000000L; private static final long netCostMeasure = 200L; private static String name = "AssetIssue015_" + Long.toString(now); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); Long freeAssetNetLimit = 30000L; Long publicFreeAssetNetLimit = 30000L; String description = "for case assetissue015"; String url = "https://stest.assetissue015.url"; ByteString assetAccountId; - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] asset015Address = ecKey1.getAddress(); String testKeyForAssetIssue015 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -42,17 +42,18 @@ public class WalletTestAssetIssue015 extends TronBaseTest { byte[] newAddress = ecKey3.getAddress(); String testKeyForNewAddress = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { logger.info(testKeyForAssetIssue015); logger.info(transferAssetCreateKey); - logger.info(testKeyForNewAddress); } + logger.info(testKeyForNewAddress); + } - @Test(enabled = true, description = "Use transfer net when token owner has not enough bandwidth", groups = {"daily"}) + @Test( + enabled = true, + description = "Use transfer net when token owner has not enough bandwidth", + groups = {"daily"}) public void atestWhenCreatorHasNoEnoughBandwidthUseTransferNet() { ecKey1 = new ECKey(Utils.getRandom()); asset015Address = ecKey1.getAddress(); @@ -66,45 +67,69 @@ public void atestWhenCreatorHasNoEnoughBandwidthUseTransferNet() { newAddress = ecKey3.getAddress(); testKeyForNewAddress = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod - .sendcoin(asset015Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + asset015Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long start = System.currentTimeMillis() + 2000; - Long end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod - .createAssetIssue(asset015Address, name, totalSupply, 1, 1, start, end, 1, description, - url, freeAssetNetLimit, publicFreeAssetNetLimit, 1L, 1L, testKeyForAssetIssue015, + Long start = System.currentTimeMillis() + 2000; + Long end = System.currentTimeMillis() + 1000000000; + Assert.assertTrue( + PublicMethod.createAssetIssue( + asset015Address, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + freeAssetNetLimit, + publicFreeAssetNetLimit, + 1L, + 1L, + testKeyForAssetIssue015, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account getAssetIdFromThisAccount; getAssetIdFromThisAccount = PublicMethod.queryAccount(asset015Address, blockingStubFull); assetAccountId = getAssetIdFromThisAccount.getAssetIssuedID(); - //Transfer asset to an account. - Assert.assertTrue(PublicMethod - .transferAsset(transferAssetAddress, assetAccountId.toByteArray(), 10000000L, - asset015Address, testKeyForAssetIssue015, blockingStubFull)); + // Transfer asset to an account. + Assert.assertTrue( + PublicMethod.transferAsset( + transferAssetAddress, + assetAccountId.toByteArray(), + 10000000L, + asset015Address, + testKeyForAssetIssue015, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Before use transfer net, query the net used from creator and transfer. - AccountNetMessage assetCreatorNet = PublicMethod - .getAccountNet(asset015Address, blockingStubFull); - AccountNetMessage assetTransferNet = PublicMethod - .getAccountNet(transferAssetAddress, blockingStubFull); - Long creatorBeforeFreeNetUsed = assetCreatorNet.getFreeNetUsed(); - Long transferBeforeFreeNetUsed = assetTransferNet.getFreeNetUsed(); + // Before use transfer net, query the net used from creator and transfer. + AccountNetMessage assetCreatorNet = + PublicMethod.getAccountNet(asset015Address, blockingStubFull); + AccountNetMessage assetTransferNet = + PublicMethod.getAccountNet(transferAssetAddress, blockingStubFull); + Long creatorBeforeFreeNetUsed = assetCreatorNet.getFreeNetUsed(); + Long transferBeforeFreeNetUsed = assetTransferNet.getFreeNetUsed(); logger.info(Long.toString(creatorBeforeFreeNetUsed)); logger.info(Long.toString(transferBeforeFreeNetUsed)); - //Transfer send some asset issue to default account, to test if this + // Transfer send some asset issue to default account, to test if this // transaction use the transaction free net. - Assert.assertTrue(PublicMethod.transferAsset(toAddress, assetAccountId.toByteArray(), 1L, - transferAssetAddress, transferAssetCreateKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + toAddress, + assetAccountId.toByteArray(), + 1L, + transferAssetAddress, + transferAssetCreateKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - assetCreatorNet = PublicMethod - .getAccountNet(asset015Address, blockingStubFull); - assetTransferNet = PublicMethod - .getAccountNet(transferAssetAddress, blockingStubFull); - Long creatorAfterFreeNetUsed = assetCreatorNet.getFreeNetUsed(); - Long transferAfterFreeNetUsed = assetTransferNet.getFreeNetUsed(); + assetCreatorNet = PublicMethod.getAccountNet(asset015Address, blockingStubFull); + assetTransferNet = PublicMethod.getAccountNet(transferAssetAddress, blockingStubFull); + Long creatorAfterFreeNetUsed = assetCreatorNet.getFreeNetUsed(); + Long transferAfterFreeNetUsed = assetTransferNet.getFreeNetUsed(); logger.info(Long.toString(creatorAfterFreeNetUsed)); logger.info(Long.toString(transferAfterFreeNetUsed)); @@ -112,79 +137,95 @@ public void atestWhenCreatorHasNoEnoughBandwidthUseTransferNet() { Assert.assertTrue(transferAfterFreeNetUsed - transferBeforeFreeNetUsed > netCostMeasure); } - @Test(enabled = true, description = "Use balance when transfer has not enough net", groups = {"daily"}) + @Test( + enabled = true, + description = "Use balance when transfer has not enough net", + groups = {"daily"}) public void btestWhenTransferHasNoEnoughBandwidthUseBalance() { Integer i = 0; - AccountNetMessage assetTransferNet = PublicMethod - .getAccountNet(transferAssetAddress, blockingStubFull); + AccountNetMessage assetTransferNet = + PublicMethod.getAccountNet(transferAssetAddress, blockingStubFull); while (assetTransferNet.getNetUsed() < 1300 && i++ < 10) { - PublicMethod.transferAsset(toAddress, assetAccountId.toByteArray(), 1L, - transferAssetAddress, transferAssetCreateKey, blockingStubFull); - assetTransferNet = PublicMethod - .getAccountNet(transferAssetAddress, blockingStubFull); + PublicMethod.transferAsset( + toAddress, + assetAccountId.toByteArray(), + 1L, + transferAssetAddress, + transferAssetCreateKey, + blockingStubFull); + assetTransferNet = PublicMethod.getAccountNet(transferAssetAddress, blockingStubFull); } logger.info(Long.toString(assetTransferNet.getFreeNetUsed())); Assert.assertTrue(assetTransferNet.getFreeNetUsed() >= 1300); - Assert.assertTrue(PublicMethod.sendcoin(transferAssetAddress, - 20000000, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + transferAssetAddress, 20000000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account transferAccount = PublicMethod.queryAccount(transferAssetCreateKey, blockingStubFull); - Long beforeBalance = transferAccount.getBalance(); + Long beforeBalance = transferAccount.getBalance(); logger.info(Long.toString(beforeBalance)); - Assert.assertTrue(PublicMethod.transferAsset(toAddress, assetAccountId.toByteArray(), 1L, - transferAssetAddress, transferAssetCreateKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + toAddress, + assetAccountId.toByteArray(), + 1L, + transferAssetAddress, + transferAssetCreateKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); transferAccount = PublicMethod.queryAccount(transferAssetCreateKey, blockingStubFull); - Long afterBalance = transferAccount.getBalance(); + Long afterBalance = transferAccount.getBalance(); logger.info(Long.toString(afterBalance)); Assert.assertTrue(beforeBalance - afterBalance > 2000); } - @Test(enabled = true, description = "Transfer asset use bandwidth when freeze balance", groups = {"daily"}) + @Test( + enabled = true, + description = "Transfer asset use bandwidth when freeze balance", + groups = {"daily"}) public void ctestWhenFreezeBalanceUseNet() { - Assert.assertTrue(PublicMethod.freezeBalance(transferAssetAddress, 5000000, - 3, transferAssetCreateKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance( + transferAssetAddress, 5000000, 3, transferAssetCreateKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountNetMessage assetTransferNet = PublicMethod - .getAccountNet(transferAssetAddress, blockingStubFull); + AccountNetMessage assetTransferNet = + PublicMethod.getAccountNet(transferAssetAddress, blockingStubFull); Account transferAccount = PublicMethod.queryAccount(transferAssetCreateKey, blockingStubFull); - final Long transferNetUsedBefore = assetTransferNet.getNetUsed(); - final Long transferBalanceBefore = transferAccount.getBalance(); + final Long transferNetUsedBefore = assetTransferNet.getNetUsed(); + final Long transferBalanceBefore = transferAccount.getBalance(); logger.info("before " + Long.toString(transferBalanceBefore)); - Assert.assertTrue(PublicMethod.transferAsset(toAddress, assetAccountId.toByteArray(), 1L, - transferAssetAddress, transferAssetCreateKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + toAddress, + assetAccountId.toByteArray(), + 1L, + transferAssetAddress, + transferAssetCreateKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - assetTransferNet = PublicMethod - .getAccountNet(transferAssetAddress, blockingStubFull); + assetTransferNet = PublicMethod.getAccountNet(transferAssetAddress, blockingStubFull); transferAccount = PublicMethod.queryAccount(transferAssetCreateKey, blockingStubFull); - final Long transferNetUsedAfter = assetTransferNet.getNetUsed(); - final Long transferBalanceAfter = transferAccount.getBalance(); + final Long transferNetUsedAfter = assetTransferNet.getNetUsed(); + final Long transferBalanceAfter = transferAccount.getBalance(); logger.info("after " + Long.toString(transferBalanceAfter)); Assert.assertTrue(transferBalanceAfter - transferBalanceBefore == 0); Assert.assertTrue(transferNetUsedAfter - transferNetUsedBefore > 200); - - } - - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(asset015Address, testKeyForAssetIssue015, foundationAddress, blockingStubFull); - PublicMethod - .freeResource(transferAssetAddress, transferAssetCreateKey, foundationAddress, blockingStubFull); } + PublicMethod.freeResource( + asset015Address, testKeyForAssetIssue015, foundationAddress, blockingStubFull); + PublicMethod.freeResource( + transferAssetAddress, transferAssetCreateKey, foundationAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue016.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue016.java index 9070a5a4..52ab5976 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue016.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue016.java @@ -5,7 +5,6 @@ import io.grpc.ManagedChannelBuilder; import lombok.extern.slf4j.Slf4j; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI; @@ -17,9 +16,9 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; -import stest.tron.wallet.common.client.utils.TronBaseTest; @Slf4j public class WalletTestAssetIssue016 extends TronBaseTest { @@ -28,47 +27,48 @@ public class WalletTestAssetIssue016 extends TronBaseTest { private static final long sendAmount = 10000000000L; private static final long netCostMeasure = 200L; private static String name = "AssetIssue016_" + Long.toString(now); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); + private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); Long freeAssetNetLimit = 30000L; Long publicFreeAssetNetLimit = 30000L; String description = "for case assetissue016"; String url = "https://stest.assetissue016.url"; ByteString assetAccountId; - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] asset016Address = ecKey1.getAddress(); String testKeyForAssetIssue016 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] transferAssetAddress = ecKey2.getAddress(); - String transferAssetCreateKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); private ManagedChannel channelSoliInFull = null; - private ManagedChannel channelPbft = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSoliInFull = null; - private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubPbft = null; private String soliInFullnode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1); - private String soliInPbft = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(2); - - /** - * constructor. - */ - + String transferAssetCreateKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + private ManagedChannel channelSoliInFull = null; + private ManagedChannel channelPbft = null; + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSoliInFull = null; + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubPbft = null; + private String soliInFullnode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); + private String soliInPbft = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(2); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { channelSoliInFull = ManagedChannelBuilder.forTarget(soliInFullnode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSoliInFull = ManagedChannelBuilder.forTarget(soliInFullnode).usePlaintext().build(); blockingStubSoliInFull = WalletSolidityGrpc.newBlockingStub(channelSoliInFull); - channelPbft = ManagedChannelBuilder.forTarget(soliInPbft) - .usePlaintext() - .build(); + channelPbft = ManagedChannelBuilder.forTarget(soliInPbft).usePlaintext().build(); blockingStubPbft = WalletSolidityGrpc.newBlockingStub(channelPbft); } - @Test(enabled = true, description = "Get asset issue net resource", groups = {"daily"}) + @Test( + enabled = true, + description = "Get asset issue net resource", + groups = {"daily"}) public void test01GetAssetIssueNet() { initPbftChannel(); initSolidityChannel(); - //get account + // get account ecKey1 = new ECKey(Utils.getRandom()); asset016Address = ecKey1.getAddress(); testKeyForAssetIssue016 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -80,15 +80,30 @@ public void test01GetAssetIssueNet() { PublicMethod.printAddress(testKeyForAssetIssue016); PublicMethod.printAddress(transferAssetCreateKey); - Assert.assertTrue(PublicMethod - .sendcoin(asset016Address, sendAmount, foundationAddress2, foundationKey2, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + asset016Address, sendAmount, foundationAddress2, foundationKey2, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Long start = System.currentTimeMillis() + 2000; Long end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod - .createAssetIssue(asset016Address, name, totalSupply, 1, 1, start, end, 1, description, - url, freeAssetNetLimit, publicFreeAssetNetLimit, 1L, 1L, testKeyForAssetIssue016, + Assert.assertTrue( + PublicMethod.createAssetIssue( + asset016Address, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + freeAssetNetLimit, + publicFreeAssetNetLimit, + 1L, + 1L, + testKeyForAssetIssue016, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -96,15 +111,15 @@ public void test01GetAssetIssueNet() { getAssetIdFromThisAccount = PublicMethod.queryAccount(asset016Address, blockingStubFull); assetAccountId = getAssetIdFromThisAccount.getAssetIssuedID(); - AccountNetMessage assetIssueInfo = PublicMethod - .getAccountNet(asset016Address, blockingStubFull); + AccountNetMessage assetIssueInfo = + PublicMethod.getAccountNet(asset016Address, blockingStubFull); Assert.assertTrue(assetIssueInfo.getAssetNetLimitCount() == 1); Assert.assertTrue(assetIssueInfo.getAssetNetUsedCount() == 1); Assert.assertFalse(assetIssueInfo.getAssetNetLimitMap().isEmpty()); Assert.assertFalse(assetIssueInfo.getAssetNetUsedMap().isEmpty()); - GrpcAPI.BytesMessage request = GrpcAPI.BytesMessage.newBuilder() - .setValue(assetAccountId).build(); + GrpcAPI.BytesMessage request = + GrpcAPI.BytesMessage.newBuilder().setValue(assetAccountId).build(); AssetIssueContract assetIssueByName = blockingStubFull.getAssetIssueByName(request); Assert.assertTrue(assetIssueByName.getFreeAssetNetLimit() == freeAssetNetLimit); Assert.assertTrue(assetIssueByName.getPublicFreeAssetNetLimit() == publicFreeAssetNetLimit); @@ -113,11 +128,21 @@ public void test01GetAssetIssueNet() { assetIssueInfo.getSerializedSize(); assetIssueInfo.equals(assetIssueInfo); - PublicMethod.transferAsset(transferAssetAddress, assetAccountId.toByteArray(), 1000L, - asset016Address, testKeyForAssetIssue016, blockingStubFull); + PublicMethod.transferAsset( + transferAssetAddress, + assetAccountId.toByteArray(), + 1000L, + asset016Address, + testKeyForAssetIssue016, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.transferAsset(toAddress, assetAccountId.toByteArray(), 100L, - transferAssetAddress, transferAssetCreateKey, blockingStubFull); + PublicMethod.transferAsset( + toAddress, + assetAccountId.toByteArray(), + 100L, + transferAssetAddress, + transferAssetCreateKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -125,60 +150,96 @@ public void test01GetAssetIssueNet() { Assert.assertTrue(assetIssueByName.getPublicLatestFreeNetTime() == 0); Assert.assertTrue(assetIssueByName.getPublicFreeAssetNetUsage() == 0); - Assert.assertTrue(PublicMethod.freezeBalance(asset016Address, 30000000L, - 3, testKeyForAssetIssue016, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance( + asset016Address, 30000000L, 3, testKeyForAssetIssue016, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.transferAsset(toAddress, assetAccountId.toByteArray(), 100L, - transferAssetAddress, transferAssetCreateKey, blockingStubFull); + PublicMethod.transferAsset( + toAddress, + assetAccountId.toByteArray(), + 100L, + transferAssetAddress, + transferAssetCreateKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); assetIssueByName = blockingStubFull.getAssetIssueByName(request); Assert.assertTrue(assetIssueByName.getPublicLatestFreeNetTime() > 0); Assert.assertTrue(assetIssueByName.getPublicFreeAssetNetUsage() > 150); - PublicMethod - .freeResource(asset016Address, testKeyForAssetIssue016, fromAddress, blockingStubFull); - + PublicMethod.freeResource( + asset016Address, testKeyForAssetIssue016, fromAddress, blockingStubFull); } - @Test(enabled = true, description = "Get asset issue by name from Solidity", groups = {"daily"}) + @Test( + enabled = true, + description = "Get asset issue by name from Solidity", + groups = {"daily"}) public void test02GetAssetIssueByNameFromSolidity() { - PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity); - Assert.assertEquals(PublicMethod.getAssetIssueByNameFromSolidity(name, - blockingStubSolidity).getTotalSupply(), totalSupply); + PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); + Assert.assertEquals( + PublicMethod.getAssetIssueByNameFromSolidity(name, blockingStubSolidity).getTotalSupply(), + totalSupply); } - @Test(enabled = true, description = "Get asset issue by name from PBFT", groups = {"daily"}) + @Test( + enabled = true, + description = "Get asset issue by name from PBFT", + groups = {"daily"}) public void test03GetAssetIssueByNameFromPbft() { - Assert.assertEquals(PublicMethod.getAssetIssueByNameFromSolidity(name, - blockingStubPbft).getTotalSupply(), totalSupply); + Assert.assertEquals( + PublicMethod.getAssetIssueByNameFromSolidity(name, blockingStubPbft).getTotalSupply(), + totalSupply); } - @Test(enabled = true, description = "Get asset issue list from PBFT", groups = {"daily"}) + @Test( + enabled = true, + description = "Get asset issue list from PBFT", + groups = {"daily"}) public void test04GetAssetIssueListFromPbft() { - Assert.assertTrue(PublicMethod.listAssetIssueFromSolidity( - blockingStubPbft).get().getAssetIssueCount() >= 1); + Assert.assertTrue( + PublicMethod.listAssetIssueFromSolidity(blockingStubPbft).get().getAssetIssueCount() >= 1); } - @Test(enabled = true, description = "Get asset issue list from Solidity", groups = {"daily"}) + @Test( + enabled = true, + description = "Get asset issue list from Solidity", + groups = {"daily"}) public void test05GetAssetIssueListFromSolidity() { - Assert.assertTrue(PublicMethod.listAssetIssueFromSolidity( - blockingStubSoliInFull).get().getAssetIssueCount() >= 1); - Assert.assertTrue(PublicMethod.listAssetIssueFromSolidity( - blockingStubSolidity).get().getAssetIssueCount() >= 1); + Assert.assertTrue( + PublicMethod.listAssetIssueFromSolidity(blockingStubSoliInFull).get().getAssetIssueCount() + >= 1); + Assert.assertTrue( + PublicMethod.listAssetIssueFromSolidity(blockingStubSolidity).get().getAssetIssueCount() + >= 1); } - @Test(enabled = true, description = "Get asset issue list paginated from PBFT", groups = {"daily"}) + @Test( + enabled = true, + description = "Get asset issue list paginated from PBFT", + groups = {"daily"}) public void test06GetAssetIssetListPaginatedFromPbft() { - Assert.assertTrue(PublicMethod.listAssetIssuepaginatedFromSolidity( - blockingStubPbft, 0L, 1L).get().getAssetIssueCount() == 1); + Assert.assertTrue( + PublicMethod.listAssetIssuepaginatedFromSolidity(blockingStubPbft, 0L, 1L) + .get() + .getAssetIssueCount() + == 1); } - @Test(enabled = true, description = "Get asset issue list paginated from Solidity", groups = {"daily"}) + @Test( + enabled = true, + description = "Get asset issue list paginated from Solidity", + groups = {"daily"}) public void test05GetAssetIssueListPaginatedFromSolidity() { - Assert.assertTrue(PublicMethod.listAssetIssuepaginatedFromSolidity( - blockingStubSolidity, 0L, 1L).get().getAssetIssueCount() == 1); - Assert.assertTrue(PublicMethod.listAssetIssuepaginatedFromSolidity( - blockingStubSoliInFull, 0L, 1L).get().getAssetIssueCount() == 1); + Assert.assertTrue( + PublicMethod.listAssetIssuepaginatedFromSolidity(blockingStubSolidity, 0L, 1L) + .get() + .getAssetIssueCount() + == 1); + Assert.assertTrue( + PublicMethod.listAssetIssuepaginatedFromSolidity(blockingStubSoliInFull, 0L, 1L) + .get() + .getAssetIssueCount() + == 1); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue020.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue020.java index cdc9d812..5547c45e 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue020.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/WalletTestAssetIssue020.java @@ -5,7 +5,6 @@ import io.grpc.ManagedChannelBuilder; import lombok.extern.slf4j.Slf4j; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.WalletSolidityGrpc; @@ -15,9 +14,9 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; -import stest.tron.wallet.common.client.utils.TronBaseTest; @Slf4j public class WalletTestAssetIssue020 extends TronBaseTest { @@ -25,46 +24,47 @@ public class WalletTestAssetIssue020 extends TronBaseTest { private static final String name = "Assetissue020_" + Long.toString(now); private static final String char33Name = "To_long_asset_name_a" + Long.toString(now); private static final long totalSupply = now; - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); + private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); String description = "just-test"; String url = "https://github.com/tronprotocol/wallet-cli/"; Account assetIssue020Account; ByteString assetAccountId; - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] asset020Address = ecKey1.getAddress(); String asset020Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] asset020SecondAddress = ecKey2.getAddress(); - String asset020SecondKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); private ManagedChannel channelSoliInFull = null; - private ManagedChannel channelPbft = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSoliInFull = null; - private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubPbft = null; private String soliInFullnode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1); - private String soliInPbft = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(2); - - /** - * constructor. - */ + String asset020SecondKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + private ManagedChannel channelSoliInFull = null; + private ManagedChannel channelPbft = null; + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSoliInFull = null; + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubPbft = null; + private String soliInFullnode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); + private String soliInPbft = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(2); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { channelSoliInFull = ManagedChannelBuilder.forTarget(soliInFullnode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSoliInFull = ManagedChannelBuilder.forTarget(soliInFullnode).usePlaintext().build(); blockingStubSoliInFull = WalletSolidityGrpc.newBlockingStub(channelSoliInFull); - channelPbft = ManagedChannelBuilder.forTarget(soliInPbft) - .usePlaintext() - .build(); + channelPbft = ManagedChannelBuilder.forTarget(soliInPbft).usePlaintext().build(); blockingStubPbft = WalletSolidityGrpc.newBlockingStub(channelPbft); } - @Test(enabled = true, description = "Asset issue support precision", groups = {"daily"}) + @Test( + enabled = true, + description = "Asset issue support precision", + groups = {"daily"}) public void test01AssetIssueSupportPrecision() { initPbftChannel(); initSolidityChannel(); - //get account + // get account ecKey1 = new ECKey(Utils.getRandom()); asset020Address = ecKey1.getAddress(); asset020Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -76,48 +76,103 @@ public void test01AssetIssueSupportPrecision() { PublicMethod.printAddress(asset020SecondKey); logger.info(name); - Assert.assertTrue(PublicMethod.sendcoin(asset020Address, 204800000000L, foundationAddress2, - foundationKey2, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(asset020SecondAddress, 204800000000L, foundationAddress2, - foundationKey2, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + asset020Address, 204800000000L, foundationAddress2, foundationKey2, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + asset020SecondAddress, + 204800000000L, + foundationAddress2, + foundationKey2, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Can create 32 char token name. + // Can create 32 char token name. Long start = System.currentTimeMillis() + 2000000; Long end = System.currentTimeMillis() + 1000000000; - //When precision is -1, can not create asset issue - Assert.assertFalse(PublicMethod.createAssetIssue(asset020Address, - name, totalSupply, 1, 1, -1, start, end, 1, description, url, - 2000L, 2000L, 1L, 1L, asset020Key, blockingStubFull)); + // When precision is -1, can not create asset issue + Assert.assertFalse( + PublicMethod.createAssetIssue( + asset020Address, + name, + totalSupply, + 1, + 1, + -1, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + asset020Key, + blockingStubFull)); - //When precision is 7, can not create asset issue - Assert.assertFalse(PublicMethod.createAssetIssue(asset020Address, - name, totalSupply, 1, 1, 7, start, end, 1, description, url, - 2000L, 2000L, 1L, 1L, asset020Key, blockingStubFull)); + // When precision is 7, can not create asset issue + Assert.assertFalse( + PublicMethod.createAssetIssue( + asset020Address, + name, + totalSupply, + 1, + 1, + 7, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + asset020Key, + blockingStubFull)); - //When precision is 6, is equal to default. - Assert.assertTrue(PublicMethod.createAssetIssue(asset020Address, - name, totalSupply, 1, 1, 6, start, end, 1, description, url, - 2000L, 2000L, 1L, 1L, asset020Key, blockingStubFull)); + // When precision is 6, is equal to default. + Assert.assertTrue( + PublicMethod.createAssetIssue( + asset020Address, + name, + totalSupply, + 1, + 1, + 6, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + asset020Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account getAssetIdFromThisAccount; getAssetIdFromThisAccount = PublicMethod.queryAccount(asset020Address, blockingStubFull); assetAccountId = getAssetIdFromThisAccount.getAssetIssuedID(); - AssetIssueContractOuterClass.AssetIssueContract assetIssueInfo = PublicMethod - .getAssetIssueByName(name, blockingStubFull); + AssetIssueContractOuterClass.AssetIssueContract assetIssueInfo = + PublicMethod.getAssetIssueByName(name, blockingStubFull); final Integer preCisionByName = assetIssueInfo.getPrecision(); final Long TotalSupplyByName = assetIssueInfo.getTotalSupply(); - assetIssueInfo = PublicMethod.getAssetIssueById(ByteArray.toStr(assetAccountId - .toByteArray()), blockingStubFull); + assetIssueInfo = + PublicMethod.getAssetIssueById( + ByteArray.toStr(assetAccountId.toByteArray()), blockingStubFull); final Integer preCisionById = assetIssueInfo.getPrecision(); final Long TotalSupplyById = assetIssueInfo.getTotalSupply(); - assetIssueInfo = PublicMethod.getAssetIssueListByName(name, blockingStubFull) - .get().getAssetIssue(0); + assetIssueInfo = + PublicMethod.getAssetIssueListByName(name, blockingStubFull).get().getAssetIssue(0); final Integer preCisionByListName = assetIssueInfo.getPrecision(); final Long TotalSupplyByListName = assetIssueInfo.getTotalSupply(); @@ -132,109 +187,202 @@ public void test01AssetIssueSupportPrecision() { Assert.assertEquals(TotalSupplyById, TotalSupplyByListName); Assert.assertEquals(TotalSupplyById, TotalSupplyByName); - //When precision is 6, is equal to default. - Assert.assertTrue(PublicMethod.createAssetIssue(asset020SecondAddress, - name, totalSupply, 1, 1, 1, start, end, 1, description, url, - 2000L, 2000L, 1L, 1L, asset020SecondKey, blockingStubFull)); + // When precision is 6, is equal to default. + Assert.assertTrue( + PublicMethod.createAssetIssue( + asset020SecondAddress, + name, + totalSupply, + 1, + 1, + 1, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + asset020SecondKey, + blockingStubFull)); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSoliInFull); assetIssueInfo = PublicMethod.getAssetIssueByName(name, blockingStubFull); Assert.assertTrue(assetIssueInfo.getName().isEmpty()); - } - @Test(enabled = true, description = "Get asset issue by id from Solidity", groups = {"daily"}) + @Test( + enabled = true, + description = "Get asset issue by id from Solidity", + groups = {"daily"}) public void test02GetAssetIssueByidFromSolidity() { - Assert.assertEquals(PublicMethod.getAssetIssueById(ByteArray.toStr(assetAccountId - .toByteArray()), blockingStubFull), - PublicMethod.getAssetIssueByIdFromSolidity(ByteArray.toStr(assetAccountId - .toByteArray()), blockingStubSolidity)); - Assert.assertEquals(PublicMethod.getAssetIssueById(ByteArray.toStr(assetAccountId - .toByteArray()), blockingStubFull), - PublicMethod.getAssetIssueByIdFromSolidity(ByteArray.toStr(assetAccountId - .toByteArray()), blockingStubSoliInFull)); + Assert.assertEquals( + PublicMethod.getAssetIssueById( + ByteArray.toStr(assetAccountId.toByteArray()), blockingStubFull), + PublicMethod.getAssetIssueByIdFromSolidity( + ByteArray.toStr(assetAccountId.toByteArray()), blockingStubSolidity)); + Assert.assertEquals( + PublicMethod.getAssetIssueById( + ByteArray.toStr(assetAccountId.toByteArray()), blockingStubFull), + PublicMethod.getAssetIssueByIdFromSolidity( + ByteArray.toStr(assetAccountId.toByteArray()), blockingStubSoliInFull)); } - @Test(enabled = true, description = "Get asset issue by id from PBFT", groups = {"daily"}) + @Test( + enabled = true, + description = "Get asset issue by id from PBFT", + groups = {"daily"}) public void test03GetAssetIssueByIdFromPbft() { - Assert.assertEquals(PublicMethod.getAssetIssueById(ByteArray.toStr(assetAccountId - .toByteArray()), blockingStubFull), - PublicMethod.getAssetIssueByIdFromSolidity(ByteArray.toStr(assetAccountId - .toByteArray()), blockingStubPbft)); + Assert.assertEquals( + PublicMethod.getAssetIssueById( + ByteArray.toStr(assetAccountId.toByteArray()), blockingStubFull), + PublicMethod.getAssetIssueByIdFromSolidity( + ByteArray.toStr(assetAccountId.toByteArray()), blockingStubPbft)); } - @Test(enabled = true, description = "Get asset issue list by name from Solidity", groups = {"daily"}) + @Test( + enabled = true, + description = "Get asset issue list by name from Solidity", + groups = {"daily"}) public void test04GetAssetIssueListByNameFromSolidity() { - Assert.assertEquals(PublicMethod.getAssetIssueListByNameFromSolidity(name, - blockingStubSolidity).get().getAssetIssueList().get(0).getTotalSupply(), totalSupply); + Assert.assertEquals( + PublicMethod.getAssetIssueListByNameFromSolidity(name, blockingStubSolidity) + .get() + .getAssetIssueList() + .get(0) + .getTotalSupply(), + totalSupply); } - @Test(enabled = true, description = "Get asset issue list by name from PBFT", groups = {"daily"}) + @Test( + enabled = true, + description = "Get asset issue list by name from PBFT", + groups = {"daily"}) public void test05GetAssetIssueListByNameFromPbft() { - Assert.assertEquals(PublicMethod.getAssetIssueListByNameFromSolidity(name, - blockingStubPbft).get().getAssetIssue(0).getTotalSupply(), totalSupply); + Assert.assertEquals( + PublicMethod.getAssetIssueListByNameFromSolidity(name, blockingStubPbft) + .get() + .getAssetIssue(0) + .getTotalSupply(), + totalSupply); } - @Test(enabled = true, description = "freeAssetNetUsed decreasing " - + "in getAssetIssueById and getAccount", groups = {"daily"}) + + @Test( + enabled = true, + description = "freeAssetNetUsed decreasing " + "in getAssetIssueById and getAccount", + groups = {"daily"}) public void test06NetUsedDecrease() { ECKey ecKeyOwner = new ECKey(Utils.getRandom()); byte[] assetOwnerAddress = ecKeyOwner.getAddress(); String assetOwnerKey = ByteArray.toHexString(ecKeyOwner.getPrivKeyBytes()); PublicMethod.printAddress(assetOwnerKey); - Assert.assertTrue(PublicMethod.sendcoin(assetOwnerAddress, 200000000000L, foundationAddress2, - foundationKey2, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + assetOwnerAddress, + 200000000000L, + foundationAddress2, + foundationKey2, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(foundationAddress2, - PublicMethod.getFreezeBalanceCount(assetOwnerAddress, assetOwnerKey, 500000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(assetOwnerAddress), foundationKey2, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(foundationAddress2, 10_0000_00000L, - 0, 0, ByteString.copyFrom(assetOwnerAddress), foundationKey2, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress2, + PublicMethod.getFreezeBalanceCount( + assetOwnerAddress, assetOwnerKey, 500000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(assetOwnerAddress), + foundationKey2, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress2, + 10_0000_00000L, + 0, + 0, + ByteString.copyFrom(assetOwnerAddress), + foundationKey2, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Long start = System.currentTimeMillis() + 2000000; Long end = System.currentTimeMillis() + 1000000000; String name1 = "Assetissue020_" + Long.toString(now); - Assert.assertTrue(PublicMethod.createAssetIssue(assetOwnerAddress, - name1, totalSupply, 1, 200, 6, start, end, 1, description, url, - 7000L, 7000L, 1L, 1L, assetOwnerKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createAssetIssue( + assetOwnerAddress, + name1, + totalSupply, + 1, + 200, + 6, + start, + end, + 1, + description, + url, + 7000L, + 7000L, + 1L, + 1L, + assetOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Account getAssetIdFromThisAccount = PublicMethod - .queryAccount(assetOwnerAddress, blockingStubFull); + Account getAssetIdFromThisAccount = + PublicMethod.queryAccount(assetOwnerAddress, blockingStubFull); assetAccountId = getAssetIdFromThisAccount.getAssetIssuedID(); final String strAssetId = assetAccountId.toStringUtf8(); ECKey ecKeyFrom = new ECKey(Utils.getRandom()); byte[] assetFromAddress = ecKeyFrom.getAddress(); String assetFromKey = ByteArray.toHexString(ecKeyFrom.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(assetFromAddress, 100000000000L, foundationAddress2, - foundationKey2, blockingStubFull)); - PublicMethod.transferAsset(assetFromAddress, - assetAccountId.toByteArray(), 100L, assetOwnerAddress, assetOwnerKey, blockingStubFull); + Assert.assertTrue( + PublicMethod.sendcoin( + assetFromAddress, 100000000000L, foundationAddress2, foundationKey2, blockingStubFull)); + PublicMethod.transferAsset( + assetFromAddress, + assetAccountId.toByteArray(), + 100L, + assetOwnerAddress, + assetOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); ECKey ecKeyTo = new ECKey(Utils.getRandom()); byte[] assetToAddress = ecKeyTo.getAddress(); String assetToKey = ByteArray.toHexString(ecKeyTo.getPrivKeyBytes()); for (int i = 0; i < 16; i++) { - PublicMethod.transferAsset(assetToAddress, - assetAccountId.toByteArray(), 1L, assetFromAddress, assetFromKey, blockingStubFull); + PublicMethod.transferAsset( + assetToAddress, + assetAccountId.toByteArray(), + 1L, + assetFromAddress, + assetFromKey, + blockingStubFull); } PublicMethod.waitProduceNextBlock(blockingStubFull); - Long fromBeginNetUsed = PublicMethod.queryAccount(assetFromAddress, blockingStubFull) - .getFreeAssetNetUsageV2Map().get(strAssetId).longValue(); - Long assetBeginNetUsed = PublicMethod.getAssetIssueById(strAssetId, blockingStubFull) - .getPublicFreeAssetNetUsage(); + Long fromBeginNetUsed = + PublicMethod.queryAccount(assetFromAddress, blockingStubFull) + .getFreeAssetNetUsageV2Map() + .get(strAssetId) + .longValue(); + Long assetBeginNetUsed = + PublicMethod.getAssetIssueById(strAssetId, blockingStubFull).getPublicFreeAssetNetUsage(); Long fromEndNetUsed = fromBeginNetUsed; Long assetEndNetUsed = assetBeginNetUsed; System.out.println("fromBeginNetUsed: " + fromBeginNetUsed); System.out.println("assetBeginNetUsed: " + assetBeginNetUsed); int count = 0; while (count < 11) { - fromEndNetUsed = PublicMethod.queryAccount(assetFromAddress, blockingStubFull) - .getFreeAssetNetUsageV2Map().get(strAssetId).longValue(); - assetEndNetUsed = PublicMethod.getAssetIssueById(strAssetId, blockingStubFull) - .getPublicFreeAssetNetUsage(); + fromEndNetUsed = + PublicMethod.queryAccount(assetFromAddress, blockingStubFull) + .getFreeAssetNetUsageV2Map() + .get(strAssetId) + .longValue(); + assetEndNetUsed = + PublicMethod.getAssetIssueById(strAssetId, blockingStubFull).getPublicFreeAssetNetUsage(); System.out.println("fromEndNetUsed: " + fromEndNetUsed); System.out.println("assetEndNetUsed: " + assetEndNetUsed); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -249,4 +397,4 @@ public void test06NetUsedDecrease() { Assert.assertTrue(false); } } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/exchangeandtoken/WalletTestAssetIssue017.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/exchangeandtoken/WalletTestAssetIssue017.java index 1f5ba322..716491c9 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/exchangeandtoken/WalletTestAssetIssue017.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/exchangeandtoken/WalletTestAssetIssue017.java @@ -1,7 +1,6 @@ package stest.tron.wallet.dailybuild.assetissue.exchangeandtoken; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.math.BigInteger; import java.util.Optional; @@ -21,8 +20,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestAssetIssue017 extends TronBaseTest { @@ -34,28 +33,38 @@ public class WalletTestAssetIssue017 extends TronBaseTest { private static long now = System.currentTimeMillis(); private static String name = "AssetIssue017_" + Long.toString(now); private static long totalSupply = now; - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); Long freeAssetNetLimit = 30000L; Long publicFreeAssetNetLimit = 30000L; String description = "for case assetissue017"; String url = "https://stest.assetissue016.url"; - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] asset017Address = ecKey1.getAddress(); String testKeyForAssetIssue017 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - //private Manager dbManager; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + // private Manager dbManager; + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); - /** - * constructor. - */ - public static Boolean createAssetIssue(byte[] address, String name, Long totalSupply, - Integer trxNum, Integer icoNum, Long startTime, Long endTime, Integer voteScore, - String description, String url, Long freeAssetNetLimit, Long publicFreeAssetNetLimit, - Long fronzenAmount, Long frozenDay, String priKey, + /** constructor. */ + public static Boolean createAssetIssue( + byte[] address, + String name, + Long totalSupply, + Integer trxNum, + Integer icoNum, + Long startTime, + Long endTime, + Integer voteScore, + String description, + String url, + Long freeAssetNetLimit, + Long publicFreeAssetNetLimit, + Long fronzenAmount, + Long frozenDay, + String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { @@ -65,11 +74,10 @@ public static Boolean createAssetIssue(byte[] address, String name, Long totalSu ex.printStackTrace(); } ECKey ecKey = temKey; - //Protocol.Account search = queryAccount(ecKey, blockingStubFull); + // Protocol.Account search = queryAccount(ecKey, blockingStubFull); try { AssetIssueContractOuterClass.AssetIssueContract.Builder builder = - AssetIssueContractOuterClass.AssetIssueContract - .newBuilder(); + AssetIssueContractOuterClass.AssetIssueContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(address)); builder.setName(ByteString.copyFrom(name.getBytes())); builder.setTotalSupply(totalSupply); @@ -108,50 +116,60 @@ public static Boolean createAssetIssue(byte[] address, String name, Long totalSu } } - /** - * constructor. - */ - public static Protocol.Transaction signTransaction(ECKey ecKey, - Protocol.Transaction transaction) { + /** constructor. */ + public static Protocol.Transaction signTransaction( + ECKey ecKey, Protocol.Transaction transaction) { if (ecKey == null || ecKey.getPrivKey() == null) { - //logger.warn("Warning: Can't sign,there is no private key !!"); + // logger.warn("Warning: Can't sign,there is no private key !!"); return null; } transaction = TransactionUtils.setTimestamp(transaction); return TransactionUtils.sign(transaction, ecKey); } - - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - logger.info(testKeyForAssetIssue017); channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + logger.info(testKeyForAssetIssue017); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = true, groups = {"daily"}) + @Test( + enabled = true, + groups = {"daily"}) public void atestGetPaginatedAssetIssueList() { - //get account + // get account ecKey1 = new ECKey(Utils.getRandom()); asset017Address = ecKey1.getAddress(); testKeyForAssetIssue017 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod - .sendcoin(asset017Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + asset017Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); start = System.currentTimeMillis() + 2000; end = System.currentTimeMillis() + 1000000000; now = System.currentTimeMillis(); name = "AssetIssue017_" + Long.toString(now); totalSupply = now; - Assert.assertTrue(createAssetIssue(asset017Address, name, totalSupply, 1, 1, - start, end, 1, description, url, freeAssetNetLimit, publicFreeAssetNetLimit, 1L, - 1L, testKeyForAssetIssue017, blockingStubFull)); + Assert.assertTrue( + createAssetIssue( + asset017Address, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + freeAssetNetLimit, + publicFreeAssetNetLimit, + 1L, + 1L, + testKeyForAssetIssue017, + blockingStubFull)); Integer offset = 0; Integer limit = 100; @@ -160,8 +178,8 @@ public void atestGetPaginatedAssetIssueList() { pageMessageBuilder.setOffset(offset); pageMessageBuilder.setLimit(limit); - AssetIssueList assetIssueList = blockingStubFull - .getPaginatedAssetIssueList(pageMessageBuilder.build()); + AssetIssueList assetIssueList = + blockingStubFull.getPaginatedAssetIssueList(pageMessageBuilder.build()); Optional assetIssueListPaginated = Optional.ofNullable(assetIssueList); logger.info(Long.toString(assetIssueListPaginated.get().getAssetIssueCount())); Assert.assertTrue(assetIssueListPaginated.get().getAssetIssueCount() >= 1); @@ -171,55 +189,56 @@ public void atestGetPaginatedAssetIssueList() { PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); } - @Test(enabled = true, groups = {"daily"}) + @Test( + enabled = true, + groups = {"daily"}) public void btestGetPaginatedAssetIssueListException() { - //offset is 0, limit is 0. + // offset is 0, limit is 0. Integer offset = 0; Integer limit = 0; PaginatedMessage.Builder pageMessageBuilder = PaginatedMessage.newBuilder(); pageMessageBuilder.setOffset(offset); pageMessageBuilder.setLimit(limit); - AssetIssueList assetIssueList = blockingStubFull - .getPaginatedAssetIssueList(pageMessageBuilder.build()); + AssetIssueList assetIssueList = + blockingStubFull.getPaginatedAssetIssueList(pageMessageBuilder.build()); Optional assetIssueListPaginated = Optional.ofNullable(assetIssueList); logger.info(Long.toString(assetIssueListPaginated.get().getAssetIssueCount())); Assert.assertTrue(assetIssueListPaginated.get().getAssetIssueCount() == 0); - //offset is -1, limit is 100. + // offset is -1, limit is 100. offset = -1; limit = 100; pageMessageBuilder = PaginatedMessage.newBuilder(); pageMessageBuilder.setOffset(offset); pageMessageBuilder.setLimit(limit); - assetIssueList = blockingStubFull - .getPaginatedAssetIssueList(pageMessageBuilder.build()); + assetIssueList = blockingStubFull.getPaginatedAssetIssueList(pageMessageBuilder.build()); assetIssueListPaginated = Optional.ofNullable(assetIssueList); logger.info(Long.toString(assetIssueListPaginated.get().getAssetIssueCount())); Assert.assertTrue(assetIssueListPaginated.get().getAssetIssueCount() == 0); - //offset is 0, limit is -1. + // offset is 0, limit is -1. offset = 0; limit = -1; pageMessageBuilder = PaginatedMessage.newBuilder(); pageMessageBuilder.setOffset(offset); pageMessageBuilder.setLimit(limit); - assetIssueList = blockingStubFull - .getPaginatedAssetIssueList(pageMessageBuilder.build()); + assetIssueList = blockingStubFull.getPaginatedAssetIssueList(pageMessageBuilder.build()); assetIssueListPaginated = Optional.ofNullable(assetIssueList); logger.info(Long.toString(assetIssueListPaginated.get().getAssetIssueCount())); Assert.assertTrue(assetIssueListPaginated.get().getAssetIssueCount() == 0); - //offset is 0, limit is 50. + // offset is 0, limit is 50. offset = 0; limit = 50; pageMessageBuilder = PaginatedMessage.newBuilder(); pageMessageBuilder.setOffset(offset); pageMessageBuilder.setLimit(limit); - assetIssueList = blockingStubFull - .getPaginatedAssetIssueList(pageMessageBuilder.build()); + assetIssueList = blockingStubFull.getPaginatedAssetIssueList(pageMessageBuilder.build()); assetIssueListPaginated = Optional.ofNullable(assetIssueList); logger.info(Long.toString(assetIssueListPaginated.get().getAssetIssueCount())); Assert.assertTrue(assetIssueListPaginated.get().getAssetIssueCount() >= 1); } - @Test(enabled = true, groups = {"daily"}) + @Test( + enabled = true, + groups = {"daily"}) public void ctestGetPaginatedAssetIssueListOnSolidityNode() { Integer offset = 0; @@ -228,10 +247,10 @@ public void ctestGetPaginatedAssetIssueListOnSolidityNode() { PaginatedMessage.Builder pageMessageBuilder = PaginatedMessage.newBuilder(); pageMessageBuilder.setOffset(offset); pageMessageBuilder.setLimit(limit); - Assert.assertTrue(PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, - blockingStubSolidity)); - AssetIssueList assetIssueList = blockingStubSolidity - .getPaginatedAssetIssueList(pageMessageBuilder.build()); + Assert.assertTrue( + PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity)); + AssetIssueList assetIssueList = + blockingStubSolidity.getPaginatedAssetIssueList(pageMessageBuilder.build()); Optional assetIssueListPaginated = Optional.ofNullable(assetIssueList); logger.info(Long.toString(assetIssueListPaginated.get().getAssetIssueCount())); @@ -241,69 +260,64 @@ public void ctestGetPaginatedAssetIssueListOnSolidityNode() { } } - @Test(enabled = true, groups = {"daily"}) + @Test( + enabled = true, + groups = {"daily"}) public void dtestGetPaginatedAssetIssueListExceptionOnSolidityNode() { - //offset is 0, limit is 0. + // offset is 0, limit is 0. Integer offset = 0; Integer limit = 0; PaginatedMessage.Builder pageMessageBuilder = PaginatedMessage.newBuilder(); pageMessageBuilder.setOffset(offset); pageMessageBuilder.setLimit(limit); - AssetIssueList assetIssueList = blockingStubSolidity - .getPaginatedAssetIssueList(pageMessageBuilder.build()); + AssetIssueList assetIssueList = + blockingStubSolidity.getPaginatedAssetIssueList(pageMessageBuilder.build()); Optional assetIssueListPaginated = Optional.ofNullable(assetIssueList); logger.info(Long.toString(assetIssueListPaginated.get().getAssetIssueCount())); Assert.assertTrue(assetIssueListPaginated.get().getAssetIssueCount() == 0); - //offset is 0, limit is -1. + // offset is 0, limit is -1. offset = 0; limit = -1; pageMessageBuilder = PaginatedMessage.newBuilder(); pageMessageBuilder.setOffset(offset); pageMessageBuilder.setLimit(limit); - assetIssueList = blockingStubSolidity - .getPaginatedAssetIssueList(pageMessageBuilder.build()); + assetIssueList = blockingStubSolidity.getPaginatedAssetIssueList(pageMessageBuilder.build()); assetIssueListPaginated = Optional.ofNullable(assetIssueList); logger.info(Long.toString(assetIssueListPaginated.get().getAssetIssueCount())); Assert.assertTrue(assetIssueListPaginated.get().getAssetIssueCount() == 0); - //offset is 0, limit is 50. + // offset is 0, limit is 50. offset = 0; limit = 50; pageMessageBuilder = PaginatedMessage.newBuilder(); pageMessageBuilder.setOffset(offset); pageMessageBuilder.setLimit(limit); - assetIssueList = blockingStubSolidity - .getPaginatedAssetIssueList(pageMessageBuilder.build()); + assetIssueList = blockingStubSolidity.getPaginatedAssetIssueList(pageMessageBuilder.build()); assetIssueListPaginated = Optional.ofNullable(assetIssueList); logger.info(Long.toString(assetIssueListPaginated.get().getAssetIssueCount())); Assert.assertTrue(assetIssueListPaginated.get().getAssetIssueCount() >= 1); - //offset is 0, limit is 1000. + // offset is 0, limit is 1000. offset = 0; limit = 1000; pageMessageBuilder = PaginatedMessage.newBuilder(); pageMessageBuilder.setOffset(offset); pageMessageBuilder.setLimit(limit); - assetIssueList = blockingStubSolidity - .getPaginatedAssetIssueList(pageMessageBuilder.build()); + assetIssueList = blockingStubSolidity.getPaginatedAssetIssueList(pageMessageBuilder.build()); assetIssueListPaginated = Optional.ofNullable(assetIssueList); logger.info(Long.toString(assetIssueListPaginated.get().getAssetIssueCount())); Assert.assertTrue(assetIssueListPaginated.get().getAssetIssueCount() >= 1); - //offset is -1, limit is 100. + // offset is -1, limit is 100. offset = -1; limit = 100; pageMessageBuilder = PaginatedMessage.newBuilder(); pageMessageBuilder.setOffset(offset); pageMessageBuilder.setLimit(limit); - assetIssueList = blockingStubSolidity - .getPaginatedAssetIssueList(pageMessageBuilder.build()); + assetIssueList = blockingStubSolidity.getPaginatedAssetIssueList(pageMessageBuilder.build()); assetIssueListPaginated = Optional.ofNullable(assetIssueList); logger.info(Long.toString(assetIssueListPaginated.get().getAssetIssueCount())); Assert.assertTrue(assetIssueListPaginated.get().getAssetIssueCount() == 0); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } -} \ No newline at end of file + public void shutdown() throws InterruptedException {} +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/exchangeandtoken/WalletTestAssetIssue018.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/exchangeandtoken/WalletTestAssetIssue018.java index a6d68298..504f52d9 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/exchangeandtoken/WalletTestAssetIssue018.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/exchangeandtoken/WalletTestAssetIssue018.java @@ -14,8 +14,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestAssetIssue018 extends TronBaseTest { @@ -25,12 +25,12 @@ public class WalletTestAssetIssue018 extends TronBaseTest { private static final String char32Name = "To_long_asset_name_" + Long.toString(now); private static final String char33Name = "To_long_asset_name_a" + Long.toString(now); private static final long totalSupply = now; - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); String description = "just-test"; String url = "https://github.com/tronprotocol/wallet-cli/"; - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] assetAccount1Address = ecKey1.getAddress(); String assetAccount1Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -50,12 +50,10 @@ public class WalletTestAssetIssue018 extends TronBaseTest { byte[] assetAccount6Address = ecKey6.getAddress(); String assetAccount6Key = ByteArray.toHexString(ecKey6.getPrivKeyBytes()); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(assetAccount1Key); + public void beforeClass() { + PublicMethod.printAddress(assetAccount1Key); PublicMethod.printAddress(assetAccount2Key); PublicMethod.printAddress(assetAccount3Key); PublicMethod.printAddress(assetAccount4Key); @@ -63,7 +61,9 @@ public class WalletTestAssetIssue018 extends TronBaseTest { PublicMethod.printAddress(assetAccount6Key); } - @Test(enabled = true, groups = {"daily"}) + @Test( + enabled = true, + groups = {"daily"}) public void test1AssetIssueNameBelow32Char() { ecKey4 = new ECKey(Utils.getRandom()); @@ -78,38 +78,87 @@ public void test1AssetIssueNameBelow32Char() { assetAccount6Address = ecKey6.getAddress(); assetAccount6Key = ByteArray.toHexString(ecKey6.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(assetAccount4Address, 2048000000, foundationAddress, - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(assetAccount5Address, 2048000000, foundationAddress, - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(assetAccount6Address, 2048000000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + assetAccount4Address, 2048000000, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + assetAccount5Address, 2048000000, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + assetAccount6Address, 2048000000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Can create 32 char token name. + // Can create 32 char token name. Long start = System.currentTimeMillis() + 2000; - Long end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod.createAssetIssue(assetAccount4Address, - char32Name, totalSupply, 1, 1, start, end, 1, description, url, - 2000L, 2000L, 1L, 1L, assetAccount4Key, blockingStubFull)); - //Can't create 33 char token name. + Long end = System.currentTimeMillis() + 1000000000; + Assert.assertTrue( + PublicMethod.createAssetIssue( + assetAccount4Address, + char32Name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + assetAccount4Key, + blockingStubFull)); + // Can't create 33 char token name. start = System.currentTimeMillis() + 2000; end = System.currentTimeMillis() + 1000000000; - Assert.assertFalse(PublicMethod.createAssetIssue(assetAccount5Address, - char33Name, totalSupply, 1, 1, start, end, 1, description, url, - 2000L, 2000L, 1L, 1L, assetAccount5Key, blockingStubFull)); - // + Assert.assertFalse( + PublicMethod.createAssetIssue( + assetAccount5Address, + char33Name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + assetAccount5Key, + blockingStubFull)); + // start = System.currentTimeMillis() + 2000; end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod.createAssetIssue(assetAccount6Address, - char32Name, totalSupply, 1, 1, start, end, 1, description, url, - 2000L, 2000L, 1L, 1L, assetAccount6Key, blockingStubFull)); - + Assert.assertTrue( + PublicMethod.createAssetIssue( + assetAccount6Address, + char32Name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + assetAccount6Key, + blockingStubFull)); } - @Test(enabled = true, groups = {"daily"}) + @Test( + enabled = true, + groups = {"daily"}) public void test2SameAssetissueName() { - //get account + // get account ecKey1 = new ECKey(Utils.getRandom()); assetAccount1Address = ecKey1.getAddress(); assetAccount1Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -124,33 +173,81 @@ public void test2SameAssetissueName() { logger.info(name); logger.info("total supply is " + Long.toString(totalSupply)); - //send coin to the new account - Assert.assertTrue(PublicMethod.sendcoin(assetAccount1Address, 2048000000, foundationAddress, - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(assetAccount2Address, 2048000000, foundationAddress, - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(assetAccount3Address, 2048000000, foundationAddress, - foundationKey, blockingStubFull)); + // send coin to the new account + Assert.assertTrue( + PublicMethod.sendcoin( + assetAccount1Address, 2048000000, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + assetAccount2Address, 2048000000, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + assetAccount3Address, 2048000000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Create 3 the same name token. + // Create 3 the same name token. Long start = System.currentTimeMillis() + 2000; - Long end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod.createAssetIssue(assetAccount1Address, - name, totalSupply, 1, 1, start, end, 1, description, url, - 2000L, 2000L, 1L, 1L, assetAccount1Key, blockingStubFull)); + Long end = System.currentTimeMillis() + 1000000000; + Assert.assertTrue( + PublicMethod.createAssetIssue( + assetAccount1Address, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + assetAccount1Key, + blockingStubFull)); start = System.currentTimeMillis() + 2000; end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod.createAssetIssue(assetAccount2Address, - name, totalSupply, 2, 2, start, end, 2, description, url, - 3000L, 3000L, 2L, 2L, assetAccount2Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createAssetIssue( + assetAccount2Address, + name, + totalSupply, + 2, + 2, + start, + end, + 2, + description, + url, + 3000L, + 3000L, + 2L, + 2L, + assetAccount2Key, + blockingStubFull)); start = System.currentTimeMillis() + 2000; end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod.createAssetIssue(assetAccount3Address, - name, totalSupply, 3, 3, start, end, 3, description, url, - 4000L, 4000L, 3L, 3L, assetAccount3Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createAssetIssue( + assetAccount3Address, + name, + totalSupply, + 3, + 3, + start, + end, + 3, + description, + url, + 4000L, + 4000L, + 3L, + 3L, + assetAccount3Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Get asset issue by name + // Get asset issue by name String asset1Name = name; ByteString assetNameBs = ByteString.copyFrom(asset1Name.getBytes()); @@ -159,54 +256,96 @@ public void test2SameAssetissueName() { Assert.assertTrue(assetIssueList.getAssetIssueCount() == 3); for (AssetIssueContract assetIssue : assetIssueList.getAssetIssueList()) { Assert.assertTrue(assetIssue.getTotalSupply() == totalSupply); - } Account getAssetIdFromThisAccount; getAssetIdFromThisAccount = PublicMethod.queryAccount(assetAccount1Key, blockingStubFull); - final ByteString assetAccount1Id = getAssetIdFromThisAccount.getAssetIssuedID(); + final ByteString assetAccount1Id = getAssetIdFromThisAccount.getAssetIssuedID(); getAssetIdFromThisAccount = PublicMethod.queryAccount(assetAccount2Key, blockingStubFull); - final ByteString assetAccount2Id = getAssetIdFromThisAccount.getAssetIssuedID(); + final ByteString assetAccount2Id = getAssetIdFromThisAccount.getAssetIssuedID(); getAssetIdFromThisAccount = PublicMethod.queryAccount(assetAccount3Key, blockingStubFull); - final ByteString assetAccount3Id = getAssetIdFromThisAccount.getAssetIssuedID(); + final ByteString assetAccount3Id = getAssetIdFromThisAccount.getAssetIssuedID(); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Transfer asset issue. - Assert.assertTrue(PublicMethod.transferAsset(assetAccount2Address, assetAccount1Id - .toByteArray(), 1L, assetAccount1Address, assetAccount1Key, blockingStubFull)); - - Assert.assertTrue(PublicMethod.transferAsset(assetAccount3Address, assetAccount2Id - .toByteArray(), 2L, assetAccount2Address, assetAccount2Key, blockingStubFull)); - - Assert.assertTrue(PublicMethod.transferAsset(assetAccount1Address, assetAccount3Id - .toByteArray(), 3L, assetAccount3Address, assetAccount3Key, blockingStubFull)); - - Assert.assertFalse(PublicMethod.transferAsset(assetAccount1Address, assetAccount2Id - .toByteArray(), 3L, assetAccount3Address, assetAccount3Key, blockingStubFull)); + // Transfer asset issue. + Assert.assertTrue( + PublicMethod.transferAsset( + assetAccount2Address, + assetAccount1Id.toByteArray(), + 1L, + assetAccount1Address, + assetAccount1Key, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.transferAsset( + assetAccount3Address, + assetAccount2Id.toByteArray(), + 2L, + assetAccount2Address, + assetAccount2Key, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.transferAsset( + assetAccount1Address, + assetAccount3Id.toByteArray(), + 3L, + assetAccount3Address, + assetAccount3Key, + blockingStubFull)); + + Assert.assertFalse( + PublicMethod.transferAsset( + assetAccount1Address, + assetAccount2Id.toByteArray(), + 3L, + assetAccount3Address, + assetAccount3Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Participate asset issue. - Assert.assertTrue(PublicMethod.participateAssetIssue(assetAccount3Address, assetAccount3Id - .toByteArray(), 1L, assetAccount2Address, assetAccount2Key, blockingStubFull)); - - Assert.assertTrue(PublicMethod.participateAssetIssue(assetAccount1Address, assetAccount1Id - .toByteArray(), 2L, assetAccount3Address, assetAccount3Key, blockingStubFull)); - - Assert.assertTrue(PublicMethod.participateAssetIssue(assetAccount2Address, assetAccount2Id - .toByteArray(), 3L, assetAccount1Address, assetAccount1Key, blockingStubFull)); - - Assert.assertFalse(PublicMethod.participateAssetIssue(assetAccount2Address, assetAccount3Id - .toByteArray(), 3L, assetAccount1Address, assetAccount1Key, blockingStubFull)); - - + // Participate asset issue. + Assert.assertTrue( + PublicMethod.participateAssetIssue( + assetAccount3Address, + assetAccount3Id.toByteArray(), + 1L, + assetAccount2Address, + assetAccount2Key, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.participateAssetIssue( + assetAccount1Address, + assetAccount1Id.toByteArray(), + 2L, + assetAccount3Address, + assetAccount3Key, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.participateAssetIssue( + assetAccount2Address, + assetAccount2Id.toByteArray(), + 3L, + assetAccount1Address, + assetAccount1Key, + blockingStubFull)); + + Assert.assertFalse( + PublicMethod.participateAssetIssue( + assetAccount2Address, + assetAccount3Id.toByteArray(), + 3L, + assetAccount1Address, + assetAccount1Key, + blockingStubFull)); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } -} \ No newline at end of file + public void shutdown() throws InterruptedException {} +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/exchangeandtoken/WalletTestAssetIssue019.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/exchangeandtoken/WalletTestAssetIssue019.java index 77a1ad24..1950f022 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/exchangeandtoken/WalletTestAssetIssue019.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/exchangeandtoken/WalletTestAssetIssue019.java @@ -11,19 +11,19 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestAssetIssue019 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final long totalSupply = now; - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); String description = "just-test"; String url = "https://github.com/tronprotocol/wallet-cli/"; - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] asset019Address = ecKey1.getAddress(); @@ -32,16 +32,15 @@ public class WalletTestAssetIssue019 extends TronBaseTest { byte[] asset019SecondAddress = ecKey2.getAddress(); String asset019SecondKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, groups = {"daily"}) + @Test( + enabled = true, + groups = {"daily"}) public void testCanNotCreateTokenNameByTrx() { - //get account + // get account ecKey1 = new ECKey(Utils.getRandom()); asset019Address = ecKey1.getAddress(); asset019Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -52,60 +51,215 @@ public void testCanNotCreateTokenNameByTrx() { asset019SecondKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); PublicMethod.printAddress(asset019SecondKey); - Assert.assertTrue(PublicMethod.sendcoin(asset019Address, 2048000000, foundationAddress, - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(asset019SecondAddress, 2048000000, foundationAddress, - foundationKey, blockingStubFull)); - //Can create 32 char token name. + Assert.assertTrue( + PublicMethod.sendcoin( + asset019Address, 2048000000, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + asset019SecondAddress, 2048000000, foundationAddress, foundationKey, blockingStubFull)); + // Can create 32 char token name. Long start = System.currentTimeMillis() + 20000000; - Long end = System.currentTimeMillis() + 1000000000; - Assert.assertFalse(PublicMethod.createAssetIssue(asset019Address, - "trx", totalSupply, 1, 1, start, end, 1, description, url, - 2000L, 2000L, 1L, 1L, asset019Key, blockingStubFull)); - - Assert.assertFalse(PublicMethod.createAssetIssue(asset019Address, - "TRX", totalSupply, 1, 1, start, end, 1, description, url, - 2000L, 2000L, 1L, 1L, asset019Key, blockingStubFull)); - - Assert.assertFalse(PublicMethod.createAssetIssue(asset019Address, - "Trx", totalSupply, 1, 1, start, end, 1, description, url, - 2000L, 2000L, 1L, 1L, asset019Key, blockingStubFull)); - - Assert.assertFalse(PublicMethod.createAssetIssue(asset019Address, - "tRx", totalSupply, 1, 1, start, end, 1, description, url, - 2000L, 2000L, 1L, 1L, asset019Key, blockingStubFull)); - - Assert.assertFalse(PublicMethod.createAssetIssue(asset019Address, - "trX", totalSupply, 1, 1, start, end, 1, description, url, - 2000L, 2000L, 1L, 1L, asset019Key, blockingStubFull)); - - Assert.assertFalse(PublicMethod.createAssetIssue(asset019Address, - "TRx", totalSupply, 1, 1, start, end, 1, description, url, - 2000L, 2000L, 1L, 1L, asset019Key, blockingStubFull)); - - Assert.assertFalse(PublicMethod.createAssetIssue(asset019Address, - "TrX", totalSupply, 1, 1, start, end, 1, description, url, - 2000L, 2000L, 1L, 1L, asset019Key, blockingStubFull)); - - Assert.assertFalse(PublicMethod.createAssetIssue(asset019Address, - "tRX", totalSupply, 1, 1, start, end, 1, description, url, - 2000L, 2000L, 1L, 1L, asset019Key, blockingStubFull)); - - Assert.assertTrue(PublicMethod.createAssetIssue(asset019Address, - "trxtrx", totalSupply, 1, 1, start, end, 1, description, url, - 2000L, 2000L, 1L, 1L, asset019Key, blockingStubFull)); - - Assert.assertTrue(PublicMethod.createAssetIssue(asset019SecondAddress, - "_", totalSupply, 1, 1, start, end, 1, description, url, - 2000L, 2000L, 1L, 1L, asset019SecondKey, blockingStubFull)); + Long end = System.currentTimeMillis() + 1000000000; + Assert.assertFalse( + PublicMethod.createAssetIssue( + asset019Address, + "trx", + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + asset019Key, + blockingStubFull)); + + Assert.assertFalse( + PublicMethod.createAssetIssue( + asset019Address, + "TRX", + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + asset019Key, + blockingStubFull)); + + Assert.assertFalse( + PublicMethod.createAssetIssue( + asset019Address, + "Trx", + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + asset019Key, + blockingStubFull)); + + Assert.assertFalse( + PublicMethod.createAssetIssue( + asset019Address, + "tRx", + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + asset019Key, + blockingStubFull)); + + Assert.assertFalse( + PublicMethod.createAssetIssue( + asset019Address, + "trX", + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + asset019Key, + blockingStubFull)); + + Assert.assertFalse( + PublicMethod.createAssetIssue( + asset019Address, + "TRx", + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + asset019Key, + blockingStubFull)); + + Assert.assertFalse( + PublicMethod.createAssetIssue( + asset019Address, + "TrX", + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + asset019Key, + blockingStubFull)); + + Assert.assertFalse( + PublicMethod.createAssetIssue( + asset019Address, + "tRX", + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + asset019Key, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.createAssetIssue( + asset019Address, + "trxtrx", + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + asset019Key, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.createAssetIssue( + asset019SecondAddress, + "_", + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + asset019SecondKey, + blockingStubFull)); } - @Test(enabled = true, groups = {"daily"}) + @Test( + enabled = true, + groups = {"daily"}) public void testGetAssetLastOperationTimeAndAssetIssueFreeNetUsed() { - Assert.assertTrue(PublicMethod.freezeBalance(asset019Address, 100000000L, 3, - asset019Key, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalance(asset019SecondAddress, 100000000L, 3, - asset019SecondKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance(asset019Address, 100000000L, 3, asset019Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance( + asset019SecondAddress, 100000000L, 3, asset019SecondKey, blockingStubFull)); Account getAssetIdFromThisAccount; getAssetIdFromThisAccount = PublicMethod.queryAccount(asset019Address, blockingStubFull); ByteString asset019AccountId = getAssetIdFromThisAccount.getAssetIssuedID(); @@ -113,15 +267,35 @@ public void testGetAssetLastOperationTimeAndAssetIssueFreeNetUsed() { getAssetIdFromThisAccount = PublicMethod.queryAccount(asset019SecondAddress, blockingStubFull); ByteString asset019SecondAccountId = getAssetIdFromThisAccount.getAssetIssuedID(); - PublicMethod.transferAsset(asset019SecondAddress, asset019AccountId.toByteArray(), 100L, - asset019Address, asset019Key, blockingStubFull); - PublicMethod.transferAsset(asset019Address, asset019SecondAccountId.toByteArray(), 100L, - asset019SecondAddress, asset019SecondKey, blockingStubFull); + PublicMethod.transferAsset( + asset019SecondAddress, + asset019AccountId.toByteArray(), + 100L, + asset019Address, + asset019Key, + blockingStubFull); + PublicMethod.transferAsset( + asset019Address, + asset019SecondAccountId.toByteArray(), + 100L, + asset019SecondAddress, + asset019SecondKey, + blockingStubFull); - PublicMethod.transferAsset(asset019Address, asset019AccountId.toByteArray(), 10L, - asset019SecondAddress, asset019SecondKey, blockingStubFull); - PublicMethod.transferAsset(asset019SecondAddress, asset019SecondAccountId.toByteArray(), - 10L, asset019Address, asset019Key, blockingStubFull); + PublicMethod.transferAsset( + asset019Address, + asset019AccountId.toByteArray(), + 10L, + asset019SecondAddress, + asset019SecondKey, + blockingStubFull); + PublicMethod.transferAsset( + asset019SecondAddress, + asset019SecondAccountId.toByteArray(), + 10L, + asset019Address, + asset019Key, + blockingStubFull); getAssetIdFromThisAccount = PublicMethod.queryAccount(asset019Address, blockingStubFull); for (String id : getAssetIdFromThisAccount.getFreeAssetNetUsageV2Map().keySet()) { @@ -138,10 +312,7 @@ public void testGetAssetLastOperationTimeAndAssetIssueFreeNetUsed() { } } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } -} \ No newline at end of file + public void shutdown() throws InterruptedException {} +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/grammar/ContractGrammar001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/grammar/ContractGrammar001.java index bff3559e..e5a9afdb 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/grammar/ContractGrammar001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/grammar/ContractGrammar001.java @@ -18,18 +18,17 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class ContractGrammar001 extends TronBaseTest { - - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,61 +36,92 @@ public class ContractGrammar001 extends TronBaseTest { String testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(0); - private String compilerVersion = Configuration.getByPath("testng.conf") - .getString("defaultParameter.solidityCompilerVersion"); - - /** - * constructor. - */ - + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0); + private String compilerVersion = + Configuration.getByPath("testng.conf").getString("defaultParameter.solidityCompilerVersion"); + + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(testKeyForGrammarAddress); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(testKeyForGrammarAddress); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } - @Test(enabled = true, description = "Support function type", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Support function type", + groups = {"contract", "daily"}) public void test1Grammar001() { ecKey1 = new ECKey(Utils.getRandom()); grammarAddress = ecKey1.getAddress(); testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod - .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + grammarAddress, + 100000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/contractGrammar001test1Grammar001.sol"; - String contractName = "FunctionSelector"; + String filePath = "src/test/resources/soliditycode/contractGrammar001test1Grammar001.sol"; + String contractName = "FunctionSelector"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress, - grammarAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress, + grammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = ""; - String num = "true" + "," + "10"; - txid = PublicMethod.triggerContract(contractAddress, - "select(bool,uint256)", num, false, - 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + String txid = ""; + String num = "true" + "," + "10"; + txid = + PublicMethod.triggerContract( + contractAddress, + "select(bool,uint256)", + num, + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long returnnumber = ByteArray.toLong(ByteArray.fromHexString(ByteArray.toHexString( - infoById.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(returnnumber == 20); - String num2 = "false" + "," + "10"; - txid = PublicMethod.triggerContract(contractAddress, - "select(bool,uint256)", num2, false, - 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + String num2 = "false" + "," + "10"; + txid = + PublicMethod.triggerContract( + contractAddress, + "select(bool,uint256)", + num2, + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -102,55 +132,88 @@ public void test1Grammar001() { logger.info("getContractRetValue:" + ById.get().getRet(0).getContractRetValue()); logger.info("getContractRet:" + ById.get().getRet(0).getContractRet()); - Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(), - contractResult.SUCCESS_VALUE); + Assert.assertEquals( + ById.get().getRet(0).getContractRet().getNumber(), contractResult.SUCCESS_VALUE); Assert.assertEquals(ById.get().getRet(0).getContractRetValue(), 1); Assert.assertEquals(ById.get().getRet(0).getContractRet(), contractResult.SUCCESS); - Assert - .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), - "0000000000000000000000000000000000000000000000000000000000000064"); + Assert.assertEquals( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), + "0000000000000000000000000000000000000000000000000000000000000064"); Assert.assertEquals(contractResult.SUCCESS, infoById.get().getReceipt().getResult()); logger.info("ById:" + ById); Assert.assertEquals(ById.get().getRet(0).getRet().getNumber(), 0); Assert.assertEquals(ById.get().getRet(0).getRetValue(), 0); - Long returnnumber2 = ByteArray.toLong(ByteArray.fromHexString( - ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Long returnnumber2 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(returnnumber2 == 100); } - @Test(enabled = true, description = "Ordinary library contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Ordinary library contract", + groups = {"contract", "daily"}) public void test2Grammar002() { String filePath = "src/test/resources/soliditycode/contractGrammar001test2Grammar002.sol"; - String contractName = "Set"; + String contractName = "Set"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress, - grammarAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress, + grammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = ""; - String num = "1"; - byte[] contractAddress1 = null; - String filePath1 = "src/test/resources/soliditycode/contractGrammar001test2Grammar002.sol"; - String contractName1 = "C"; + String txid = ""; + String num = "1"; + byte[] contractAddress1 = null; + String filePath1 = "src/test/resources/soliditycode/contractGrammar001test2Grammar002.sol"; + String contractName1 = "C"; HashMap retMap1 = PublicMethod.getBycodeAbiForLibrary(filePath1, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - String library = retMap1.get("library").toString(); - String libraryAddress = library + Base58.encode58Check(contractAddress); - contractAddress1 = PublicMethod - .deployContractForLibrary(contractName1, abi1, code1, "", maxFeeLimit, - 0L, 100, libraryAddress, testKeyForGrammarAddress, - grammarAddress, compilerVersion, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String library = retMap1.get("library").toString(); + String libraryAddress = library + Base58.encode58Check(contractAddress); + contractAddress1 = + PublicMethod.deployContractForLibrary( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 0L, + 100, + libraryAddress, + testKeyForGrammarAddress, + grammarAddress, + compilerVersion, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - txid = PublicMethod.triggerContract(contractAddress1, - "register(uint256)", num, false, - 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress1, + "register(uint256)", + num, + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull1); Optional infoById = null; @@ -159,35 +222,65 @@ public void test2Grammar002() { Assert.assertTrue(infoById.get().getResultValue() == 0); } - @Test(enabled = true, description = "Library contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Library contract", + groups = {"contract", "daily"}) public void test3Grammar003() { String filePath = "src/test/resources/soliditycode/contractGrammar001test3Grammar003.sol"; - String contractName = "Set"; + String contractName = "Set"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress, - grammarAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress, + grammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = ""; - String num = "1"; - byte[] contractAddress1 = null; - String contractName1 = "C"; + String txid = ""; + String num = "1"; + byte[] contractAddress1 = null; + String contractName1 = "C"; HashMap retMap1 = PublicMethod.getBycodeAbiForLibrary(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - String library = retMap1.get("library").toString(); - String libraryAddress = library - + Base58.encode58Check(contractAddress); - contractAddress1 = PublicMethod - .deployContractForLibrary(contractName1, abi1, code1, "", maxFeeLimit, - 0L, 100, libraryAddress, testKeyForGrammarAddress, - grammarAddress, compilerVersion, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String library = retMap1.get("library").toString(); + String libraryAddress = library + Base58.encode58Check(contractAddress); + contractAddress1 = + PublicMethod.deployContractForLibrary( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 0L, + 100, + libraryAddress, + testKeyForGrammarAddress, + grammarAddress, + compilerVersion, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - txid = PublicMethod.triggerContract(contractAddress1, - "register(uint256)", num, false, - 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress1, + "register(uint256)", + num, + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull1); Optional infoById = null; @@ -196,158 +289,283 @@ public void test3Grammar003() { Assert.assertTrue(infoById.get().getResultValue() == 0); } - - @Test(enabled = true, description = "Extended type", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Extended type", + groups = {"contract", "daily"}) public void test4Grammar004() { ecKey1 = new ECKey(Utils.getRandom()); grammarAddress = ecKey1.getAddress(); testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod - .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + grammarAddress, + 100000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/contractGrammar001test4Grammar004.sol"; - String contractName = "Search"; + String filePath = "src/test/resources/soliditycode/contractGrammar001test4Grammar004.sol"; + String contractName = "Search"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress, - grammarAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress, + grammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - byte[] contractAddress1 = null; - String contractName1 = "C"; + byte[] contractAddress1 = null; + String contractName1 = "C"; HashMap retMap1 = PublicMethod.getBycodeAbiForLibrary(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - String library = retMap1.get("library").toString(); - String libraryAddress = null; - libraryAddress = library - + Base58.encode58Check(contractAddress); - contractAddress1 = PublicMethod - .deployContractForLibrary(contractName1, abi1, code1, "", maxFeeLimit, - 0L, 100, libraryAddress, testKeyForGrammarAddress, - grammarAddress, compilerVersion, blockingStubFull); - String txid = ""; - String num = "1"; + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String library = retMap1.get("library").toString(); + String libraryAddress = null; + libraryAddress = library + Base58.encode58Check(contractAddress); + contractAddress1 = + PublicMethod.deployContractForLibrary( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 0L, + 100, + libraryAddress, + testKeyForGrammarAddress, + grammarAddress, + compilerVersion, + blockingStubFull); + String txid = ""; + String num = "1"; PublicMethod.waitProduceNextBlock(blockingStubFull); - txid = PublicMethod.triggerContract(contractAddress1, - "append(uint256)", num, false, - 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress1, + "append(uint256)", + num, + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String num1 = "0"; - String txid1 = PublicMethod.triggerContract(contractAddress1, - "getData(uint256)", num1, false, - 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + String num1 = "0"; + String txid1 = + PublicMethod.triggerContract( + contractAddress1, + "getData(uint256)", + num1, + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(returnnumber == 1); - String num2 = "1" + "," + "2"; - String txid2 = PublicMethod.triggerContract(contractAddress1, - "replace(uint256,uint256)", num2, false, - 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + String num2 = "1" + "," + "2"; + String txid2 = + PublicMethod.triggerContract( + contractAddress1, + "replace(uint256,uint256)", + num2, + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById2 = null; infoById2 = PublicMethod.getTransactionInfoById(txid2, blockingStubFull); Assert.assertTrue(infoById2.get().getResultValue() == 0); - String txid3 = PublicMethod.triggerContract(contractAddress1, - "getData(uint256)", num1, false, - 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + String txid3 = + PublicMethod.triggerContract( + contractAddress1, + "getData(uint256)", + num1, + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid3, blockingStubFull); - Long returnnumber1 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Long returnnumber1 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(returnnumber1 == 2); - } - @Test(enabled = true, description = "Solidity assembly", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Solidity assembly", + groups = {"contract", "daily"}) public void test5Grammar006() { String filePath = "src/test/resources/soliditycode/contractGrammar001test5Grammar006.sol"; - String contractName = "InfoFeed"; + String contractName = "InfoFeed"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress, - grammarAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress, + grammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = ""; - String number = "1"; - final String txid1 = PublicMethod.triggerContract(contractAddress, - "f(uint256)", number, false, - 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); - final String txid2 = PublicMethod.triggerContract(contractAddress, - "d(uint256)", number, false, - 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); - final String txid3 = PublicMethod.triggerContract(contractAddress, - "d1(uint256)", number, false, - 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); - final String txid4 = PublicMethod.triggerContract(contractAddress, - "d2(uint256)", number, false, - 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); - final String txid5 = PublicMethod.triggerContract(contractAddress, - "d5(uint256)", number, false, - 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); - final String txid6 = PublicMethod.triggerContract(contractAddress, - "d4(uint256)", number, false, - 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); - final String txid8 = PublicMethod.triggerContract(contractAddress, - "d6(uint256)", number, false, - 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + String txid = ""; + String number = "1"; + final String txid1 = + PublicMethod.triggerContract( + contractAddress, + "f(uint256)", + number, + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); + final String txid2 = + PublicMethod.triggerContract( + contractAddress, + "d(uint256)", + number, + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); + final String txid3 = + PublicMethod.triggerContract( + contractAddress, + "d1(uint256)", + number, + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); + final String txid4 = + PublicMethod.triggerContract( + contractAddress, + "d2(uint256)", + number, + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); + final String txid5 = + PublicMethod.triggerContract( + contractAddress, + "d5(uint256)", + number, + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); + final String txid6 = + PublicMethod.triggerContract( + contractAddress, + "d4(uint256)", + number, + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); + final String txid8 = + PublicMethod.triggerContract( + contractAddress, + "d6(uint256)", + number, + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull1); - Optional infoById1 = PublicMethod - .getTransactionInfoById(txid1, blockingStubFull1); + Optional infoById1 = + PublicMethod.getTransactionInfoById(txid1, blockingStubFull1); Assert.assertTrue(infoById1.get().getResultValue() == 0); - Optional infoById2 = PublicMethod - .getTransactionInfoById(txid2, blockingStubFull1); + Optional infoById2 = + PublicMethod.getTransactionInfoById(txid2, blockingStubFull1); Assert.assertTrue(infoById2.get().getResultValue() == 0); - Assert.assertEquals(133,ByteArray.toInt(infoById2.get().getContractResult(0).toByteArray())); + Assert.assertEquals(133, ByteArray.toInt(infoById2.get().getContractResult(0).toByteArray())); - Optional infoById3 = PublicMethod - .getTransactionInfoById(txid3, blockingStubFull1); + Optional infoById3 = + PublicMethod.getTransactionInfoById(txid3, blockingStubFull1); Assert.assertTrue(infoById3.get().getResultValue() == 0); - Optional infoById4 = PublicMethod - .getTransactionInfoById(txid4, blockingStubFull1); + Optional infoById4 = + PublicMethod.getTransactionInfoById(txid4, blockingStubFull1); Assert.assertTrue(infoById4.get().getResultValue() == 0); - Optional infoById5 = PublicMethod - .getTransactionInfoById(txid5, blockingStubFull1); + Optional infoById5 = + PublicMethod.getTransactionInfoById(txid5, blockingStubFull1); Assert.assertTrue(infoById5.get().getResultValue() == 0); - Optional infoById6 = PublicMethod - .getTransactionInfoById(txid6, blockingStubFull1); + Optional infoById6 = + PublicMethod.getTransactionInfoById(txid6, blockingStubFull1); Assert.assertTrue(infoById6.get().getResultValue() == 0); - Optional infoById8 = PublicMethod - .getTransactionInfoById(txid8, blockingStubFull1); + Optional infoById8 = + PublicMethod.getTransactionInfoById(txid8, blockingStubFull1); Assert.assertTrue(infoById8.get().getResultValue() == 0); - - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(grammarAddress, testKeyForGrammarAddress, testNetAccountAddress, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + grammarAddress, testKeyForGrammarAddress, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/grammar/ContractGrammar002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/grammar/ContractGrammar002.java index edbce00b..2dd5db5f 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/grammar/ContractGrammar002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/grammar/ContractGrammar002.java @@ -16,19 +16,17 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; -import stest.tron.wallet.common.client.utils.ProposalEnum; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class ContractGrammar002 extends TronBaseTest { - - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -36,144 +34,248 @@ public class ContractGrammar002 extends TronBaseTest { String testKeyForGrammarAddress2 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(testKeyForGrammarAddress2); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(testKeyForGrammarAddress2); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - logger.info(Long.toString(PublicMethod.queryAccount(testNetAccountKey, blockingStubFull) - .getBalance())); + logger.info( + Long.toString(PublicMethod.queryAccount(testNetAccountKey, blockingStubFull).getBalance())); } - - @Test(enabled = true, description = "Interface type function", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Interface type function", + groups = {"contract", "daily"}) public void test1Grammar007() { PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod - .sendcoin(grammarAddress2, 100000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + grammarAddress2, + 100000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/contractGrammar002test1Grammar007_1.sol"; - String contractName = "Doug"; + String filePath = "src/test/resources/soliditycode/contractGrammar002test1Grammar007_1.sol"; + String contractName = "Doug"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress2, - grammarAddress2, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress2, + grammarAddress2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String initParmes = ByteArray.toHexString(contractAddress); - String filePath1 = "src/test/resources/soliditycode/contractGrammar002test1Grammar007_2.sol"; - String contractName1 = "main"; + String initParmes = ByteArray.toHexString(contractAddress); + String filePath1 = "src/test/resources/soliditycode/contractGrammar002test1Grammar007_2.sol"; + String contractName1 = "main"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath1, contractName1); - String code1 = retMap1.get("byteCode").toString() + "0000000000000000000000" - + initParmes; - String abi1 = retMap1.get("abI").toString(); - byte[] contractAddress1 = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress2, - grammarAddress2, blockingStubFull); + String code1 = retMap1.get("byteCode").toString() + "0000000000000000000000" + initParmes; + String abi1 = retMap1.get("abI").toString(); + byte[] contractAddress1 = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress2, + grammarAddress2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull1); - String txid = ""; - String number = "1"; - String txid1 = PublicMethod.triggerContract(contractAddress1, - "dougOfage(uint256)", number, false, - 0, maxFeeLimit, grammarAddress2, testKeyForGrammarAddress2, blockingStubFull); + String txid = ""; + String number = "1"; + String txid1 = + PublicMethod.triggerContract( + contractAddress1, + "dougOfage(uint256)", + number, + false, + 0, + maxFeeLimit, + grammarAddress2, + testKeyForGrammarAddress2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull1); - Optional infoById1 = PublicMethod - .getTransactionInfoById(txid1, blockingStubFull1); + Optional infoById1 = + PublicMethod.getTransactionInfoById(txid1, blockingStubFull1); Assert.assertTrue(infoById1.get().getResultValue() == 0); - String number1 = "687777"; - String txid2 = PublicMethod.triggerContract(contractAddress1, - "uintOfName(bytes32)", number1, false, - 0, maxFeeLimit, grammarAddress2, testKeyForGrammarAddress2, blockingStubFull); - // PublicMethod.waitProduceNextBlock(blockingStubFull); - // PublicMethod.waitProduceNextBlock(blockingStubFull1); - Optional infoById2 = PublicMethod - .getTransactionInfoById(txid2, blockingStubFull1); + String number1 = "687777"; + String txid2 = + PublicMethod.triggerContract( + contractAddress1, + "uintOfName(bytes32)", + number1, + false, + 0, + maxFeeLimit, + grammarAddress2, + testKeyForGrammarAddress2, + blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull1); + Optional infoById2 = + PublicMethod.getTransactionInfoById(txid2, blockingStubFull1); Assert.assertTrue(infoById2.get().getResultValue() == 0); } - @Test(enabled = true, description = "Abstract function", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Abstract function", + groups = {"contract", "daily"}) public void test2Grammar008() { String filePath = "src/test/resources/soliditycode/contractGrammar002test2Grammar008.sol"; - String contractName = "Cat"; + String contractName = "Cat"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress2, - grammarAddress2, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress2, + grammarAddress2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = ""; - txid = PublicMethod.triggerContract(contractAddress, - "getContractName()", "#", false, - 0, maxFeeLimit, grammarAddress2, testKeyForGrammarAddress2, blockingStubFull); + String txid = ""; + txid = + PublicMethod.triggerContract( + contractAddress, + "getContractName()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress2, + testKeyForGrammarAddress2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - String returnString = ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); - Assert.assertEquals(returnString, + String returnString = ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); + Assert.assertEquals( + returnString, "0000000000000000000000000000000000000000000000000000000000000020000000000000000000" + "000000000000000000000000000000000000000000000646656c696e650000000000000000000000000" + "000000000000000000000000000"); - String txid1 = PublicMethod.triggerContract(contractAddress, - "utterance()", "#", false, - 0, maxFeeLimit, grammarAddress2, testKeyForGrammarAddress2, blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + contractAddress, + "utterance()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress2, + testKeyForGrammarAddress2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); - String returnString1 = ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); - Assert.assertEquals(returnString1, - "6d69616f77000000000000000000000000000000000000000000000000000000"); + String returnString1 = ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); + Assert.assertEquals( + returnString1, "6d69616f77000000000000000000000000000000000000000000000000000000"); } - @Test(enabled = true, description = "Gas, value test", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Gas, value test", + groups = {"contract", "daily"}) public void test3Grammar010() { String filePath = "src/test/resources/soliditycode/contractGrammar002test3Grammar010.sol"; - String contractName = "Consumer"; + String contractName = "Consumer"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 2000L, 100, null, testKeyForGrammarAddress2, - grammarAddress2, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 2000L, + 100, + null, + testKeyForGrammarAddress2, + grammarAddress2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName1 = "InfoFeed"; + String contractName1 = "InfoFeed"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - byte[] contractAddress1 = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, - 0, 100, null, testKeyForGrammarAddress2, - grammarAddress2, blockingStubFull); - String txid = ""; - String initParmes = "\"" + Base58.encode58Check(contractAddress1) + "\""; - txid = PublicMethod.triggerContract(contractAddress, - "setFeed(address)", initParmes, false, - 0, maxFeeLimit, grammarAddress2, testKeyForGrammarAddress2, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + byte[] contractAddress1 = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 0, + 100, + null, + testKeyForGrammarAddress2, + grammarAddress2, + blockingStubFull); + String txid = ""; + String initParmes = "\"" + Base58.encode58Check(contractAddress1) + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "setFeed(address)", + initParmes, + false, + 0, + maxFeeLimit, + grammarAddress2, + testKeyForGrammarAddress2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid1 = PublicMethod.triggerContract(contractAddress, - "callFeed()", "#", false, - 0, maxFeeLimit, grammarAddress2, testKeyForGrammarAddress2, blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + contractAddress, + "callFeed()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress2, + testKeyForGrammarAddress2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull1); Optional infoById = null; @@ -181,140 +283,246 @@ public void test3Grammar010() { Assert.assertTrue(infoById.get().getResultValue() == 0); } - - @Test(enabled = true, description = "Call a named function", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Call a named function", + groups = {"contract", "daily"}) public void test4Grammar011() { String filePath = "src/test/resources/soliditycode/contractGrammar002test4Grammar011.sol"; - String contractName = "C"; + String contractName = "C"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress2, - grammarAddress2, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress2, + grammarAddress2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; - String number = "1" + "," + "2"; - String txid = PublicMethod.triggerContract(contractAddress, - "f(uint256,uint256)", number, false, - 0, maxFeeLimit, grammarAddress2, testKeyForGrammarAddress2, blockingStubFull); + String number = "1" + "," + "2"; + String txid = + PublicMethod.triggerContract( + contractAddress, + "f(uint256,uint256)", + number, + false, + 0, + maxFeeLimit, + grammarAddress2, + testKeyForGrammarAddress2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertTrue(returnnumber == 1); Optional infoById1 = null; - String txid1 = PublicMethod.triggerContract(contractAddress, - "g()", "#", false, - 0, maxFeeLimit, grammarAddress2, testKeyForGrammarAddress2, blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + contractAddress, + "g()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress2, + testKeyForGrammarAddress2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); Assert.assertTrue(infoById1.get().getResultValue() == 0); } - - @Test(enabled = true, description = "Call a native function", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Call a native function", + groups = {"contract", "daily"}) public void test5Grammar012() { String filePath = "src/test/resources/soliditycode/contractGrammar002test4Grammar012.sol"; - String contractName = "rTest"; + String contractName = "rTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress2, - grammarAddress2, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress2, + grammarAddress2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; - String txid = PublicMethod.triggerContract(contractAddress, - "info()", "#", false, - 0, maxFeeLimit, grammarAddress2, testKeyForGrammarAddress2, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + "info()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress2, + testKeyForGrammarAddress2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - } - @Test(enabled = true, description = "Call a Destructor function", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Call a Destructor function", + groups = {"contract", "daily"}) public void test6Grammar013() { String filePath = "src/test/resources/soliditycode/contractGrammar002test6Grammar013.sol"; - String contractName = "Counter"; + String contractName = "Counter"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress2, - grammarAddress2, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress2, + grammarAddress2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; - String txid = PublicMethod.triggerContract(contractAddress, - "getCount()", "#", false, - 0, maxFeeLimit, grammarAddress2, testKeyForGrammarAddress2, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + "getCount()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress2, + testKeyForGrammarAddress2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertTrue(returnnumber == 0); Optional infoById1 = null; - String txid1 = PublicMethod.triggerContract(contractAddress, - "increment()", "#", false, - 0, maxFeeLimit, grammarAddress2, testKeyForGrammarAddress2, blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + contractAddress, + "increment()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress2, + testKeyForGrammarAddress2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); Assert.assertTrue(infoById1.get().getResultValue() == 0); Optional infoById2 = null; - String txid2 = PublicMethod.triggerContract(contractAddress, - "getCount()", "#", false, - 0, maxFeeLimit, grammarAddress2, testKeyForGrammarAddress2, blockingStubFull); + String txid2 = + PublicMethod.triggerContract( + contractAddress, + "getCount()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress2, + testKeyForGrammarAddress2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById2 = PublicMethod.getTransactionInfoById(txid2, blockingStubFull); Assert.assertTrue(infoById2.get().getResultValue() == 0); - Long returnnumber1 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById2.get().getContractResult(0).toByteArray()))); + Long returnnumber1 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById2.get().getContractResult(0).toByteArray()))); Assert.assertTrue(returnnumber1 == 10); Optional infoById3 = null; - String txid3 = PublicMethod.triggerContract(contractAddress, - "kill()", "#", false, - 0, maxFeeLimit, grammarAddress2, testKeyForGrammarAddress2, blockingStubFull); + String txid3 = + PublicMethod.triggerContract( + contractAddress, + "kill()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress2, + testKeyForGrammarAddress2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById3 = PublicMethod.getTransactionInfoById(txid3, blockingStubFull); Assert.assertTrue(infoById3.get().getResultValue() == 0); Optional infoById4 = null; - String txid4 = PublicMethod.triggerContract(contractAddress, - "getCount()", "#", false, - 0, maxFeeLimit, grammarAddress2, testKeyForGrammarAddress2, blockingStubFull); + String txid4 = + PublicMethod.triggerContract( + contractAddress, + "getCount()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress2, + testKeyForGrammarAddress2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { infoById4 = PublicMethod.getTransactionInfoById(txid4, blockingStubFull); Assert.assertTrue(infoById4.get().getResultValue() == 0); - returnnumber1 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById2.get().getContractResult(0).toByteArray()))); + returnnumber1 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById2.get().getContractResult(0).toByteArray()))); Assert.assertTrue(returnnumber1 == 10); - }else { + } else { Assert.assertTrue(txid4 == null); } } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(grammarAddress2, testKeyForGrammarAddress2, testNetAccountAddress, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + grammarAddress2, testKeyForGrammarAddress2, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/grammar/ContractGrammar003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/grammar/ContractGrammar003.java index 470d7914..a9dcb373 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/grammar/ContractGrammar003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/grammar/ContractGrammar003.java @@ -17,18 +17,17 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.Hash; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class ContractGrammar003 extends TronBaseTest { - - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -36,374 +35,704 @@ public class ContractGrammar003 extends TronBaseTest { String testKeyForGrammarAddress3 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(testKeyForGrammarAddress3); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(testKeyForGrammarAddress3); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } - - @Test(enabled = true, description = "Complex structure", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Complex structure", + groups = {"contract", "daily"}) public void test1Grammar014() { ecKey1 = new ECKey(Utils.getRandom()); grammarAddress3 = ecKey1.getAddress(); testKeyForGrammarAddress3 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod - .sendcoin(grammarAddress3, 100000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + grammarAddress3, + 100000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/contractGrammar003test1Grammar014.sol"; - String contractName = "A"; + String filePath = "src/test/resources/soliditycode/contractGrammar003test1Grammar014.sol"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress3, - grammarAddress3, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress3, + grammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName1 = "B"; + String contractName1 = "B"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - byte[] contractAddress1 = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress3, - grammarAddress3, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + byte[] contractAddress1 = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress3, + grammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = PublicMethod.triggerContract(contractAddress, - "getnumberForB()", "#", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + "getnumberForB()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid1 = PublicMethod.triggerContract(contractAddress1, - "getnumberForB()", "#", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + contractAddress1, + "getnumberForB()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertTrue(returnnumber == 0); - Long returnnumber1 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Long returnnumber1 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(infoById1.get().getResultValue() == 0); Assert.assertTrue(returnnumber1 == 0); Optional infoById4 = null; - String initParmes = "\"" + Base58.encode58Check(contractAddress1) + "\",\"1\""; - String txid4 = PublicMethod.triggerContract(contractAddress, - "callTest(address,uint256)", initParmes, false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String initParmes = "\"" + Base58.encode58Check(contractAddress1) + "\",\"1\""; + String txid4 = + PublicMethod.triggerContract( + contractAddress, + "callTest(address,uint256)", + initParmes, + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById4 = PublicMethod.getTransactionInfoById(txid4, blockingStubFull); Assert.assertTrue(infoById4.get().getResultValue() == 0); - String txid5 = PublicMethod.triggerContract(contractAddress, - "getnumberForB()", "#", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String txid5 = + PublicMethod.triggerContract( + contractAddress, + "getnumberForB()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById5 = null; infoById5 = PublicMethod.getTransactionInfoById(txid5, blockingStubFull); - Long returnnumber5 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById5.get().getContractResult(0).toByteArray()))); + Long returnnumber5 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById5.get().getContractResult(0).toByteArray()))); Assert.assertTrue(returnnumber5 == 0); - String txid6 = PublicMethod.triggerContract(contractAddress1, - "getnumberForB()", "#", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String txid6 = + PublicMethod.triggerContract( + contractAddress1, + "getnumberForB()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById6 = null; infoById6 = PublicMethod.getTransactionInfoById(txid6, blockingStubFull); - Long returnnumber6 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById6.get().getContractResult(0).toByteArray()))); + Long returnnumber6 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById6.get().getContractResult(0).toByteArray()))); Assert.assertTrue(returnnumber6 == 1); - String txid7 = PublicMethod.triggerContract(contractAddress, - "callcodeTest(address,uint256)", initParmes, false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String txid7 = + PublicMethod.triggerContract( + contractAddress, + "callcodeTest(address,uint256)", + initParmes, + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById7 = null; infoById7 = PublicMethod.getTransactionInfoById(txid7, blockingStubFull); Assert.assertTrue(infoById7.get().getResultValue() == 0); - String txid8 = PublicMethod.triggerContract(contractAddress, - "getnumberForB()", "#", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String txid8 = + PublicMethod.triggerContract( + contractAddress, + "getnumberForB()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById8 = null; infoById8 = PublicMethod.getTransactionInfoById(txid8, blockingStubFull); - Long returnnumber8 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById8.get().getContractResult(0).toByteArray()))); + Long returnnumber8 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById8.get().getContractResult(0).toByteArray()))); Assert.assertTrue(returnnumber8 == 1); - String txid9 = PublicMethod.triggerContract(contractAddress1, - "getnumberForB()", "#", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String txid9 = + PublicMethod.triggerContract( + contractAddress1, + "getnumberForB()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById9 = null; infoById9 = PublicMethod.getTransactionInfoById(txid9, blockingStubFull); - Long returnnumber9 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById9.get().getContractResult(0).toByteArray()))); + Long returnnumber9 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById9.get().getContractResult(0).toByteArray()))); Assert.assertTrue(returnnumber9 == 1); - String txid10 = PublicMethod.triggerContract(contractAddress, - "delegatecallTest(address,uint256)", initParmes, false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String txid10 = + PublicMethod.triggerContract( + contractAddress, + "delegatecallTest(address,uint256)", + initParmes, + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById10 = null; infoById10 = PublicMethod.getTransactionInfoById(txid10, blockingStubFull); Assert.assertTrue(infoById10.get().getResultValue() == 0); - String txid11 = PublicMethod.triggerContract(contractAddress, - "getnumberForB()", "#", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String txid11 = + PublicMethod.triggerContract( + contractAddress, + "getnumberForB()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById11 = null; infoById11 = PublicMethod.getTransactionInfoById(txid11, blockingStubFull); - Long returnnumber11 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById11.get().getContractResult(0).toByteArray()))); + Long returnnumber11 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById11.get().getContractResult(0).toByteArray()))); Assert.assertTrue(returnnumber11 == 1); - String txid12 = PublicMethod.triggerContract(contractAddress1, - "getnumberForB()", "#", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String txid12 = + PublicMethod.triggerContract( + contractAddress1, + "getnumberForB()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById12 = null; infoById12 = PublicMethod.getTransactionInfoById(txid12, blockingStubFull); - Long returnnumber12 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById12.get().getContractResult(0).toByteArray()))); + Long returnnumber12 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById12.get().getContractResult(0).toByteArray()))); Assert.assertTrue(returnnumber12 == 1); - String initParmes1 = "\"" + Base58.encode58Check(contractAddress1) + "\""; - String txid13 = PublicMethod.triggerContract(contractAddress, - "callAddTest(address)", initParmes1, false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String initParmes1 = "\"" + Base58.encode58Check(contractAddress1) + "\""; + String txid13 = + PublicMethod.triggerContract( + contractAddress, + "callAddTest(address)", + initParmes1, + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById13 = null; infoById13 = PublicMethod.getTransactionInfoById(txid13, blockingStubFull); Assert.assertTrue(infoById13.get().getResultValue() == 0); - String txid14 = PublicMethod.triggerContract(contractAddress, - "getnumberForB()", "#", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String txid14 = + PublicMethod.triggerContract( + contractAddress, + "getnumberForB()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById14 = null; infoById14 = PublicMethod.getTransactionInfoById(txid14, blockingStubFull); - Long returnnumber14 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById14.get().getContractResult(0).toByteArray()))); + Long returnnumber14 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById14.get().getContractResult(0).toByteArray()))); Assert.assertTrue(returnnumber14 == 1); - String txid15 = PublicMethod.triggerContract(contractAddress1, - "getnumberForB()", "#", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String txid15 = + PublicMethod.triggerContract( + contractAddress1, + "getnumberForB()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById15 = null; infoById15 = PublicMethod.getTransactionInfoById(txid15, blockingStubFull); - Long returnnumber15 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById15.get().getContractResult(0).toByteArray()))); + Long returnnumber15 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById15.get().getContractResult(0).toByteArray()))); Assert.assertTrue(returnnumber15 == 3); } - - @Test(enabled = true, description = "Fallback function ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Fallback function ", + groups = {"contract", "daily"}) public void test2Grammar015() { String filePath = "src/test/resources/soliditycode/contractGrammar003test2Grammar015.sol"; - String contractName = "ExecuteFallback"; + String contractName = "ExecuteFallback"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress3, - grammarAddress3, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress3, + grammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = null; - String txid = PublicMethod.triggerContract(contractAddress, - "callExistFunc()", "#", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + "callExistFunc()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); Optional infoById1 = null; - String txid1 = PublicMethod.triggerContract(contractAddress, - "callNonExistFunc()", "#", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + contractAddress, + "callNonExistFunc()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - String i = ByteArray.toHexString(Hash.sha3("ExistFuncCalled(bytes,uint256)".getBytes())); - String resultvalue = ByteArray - .toHexString(infoById.get().getLogList().get(0).getTopicsList().get(0).toByteArray()); + String i = ByteArray.toHexString(Hash.sha3("ExistFuncCalled(bytes,uint256)".getBytes())); + String resultvalue = + ByteArray.toHexString( + infoById.get().getLogList().get(0).getTopicsList().get(0).toByteArray()); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertEquals(i, resultvalue); - infoById1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); - String value = ByteArray.toHexString(Hash.sha3("FallbackCalled(bytes)".getBytes())); - String resultvalue1 = ByteArray - .toHexString(infoById1.get().getLogList().get(0).getTopicsList().get(0).toByteArray()); + String value = ByteArray.toHexString(Hash.sha3("FallbackCalled(bytes)".getBytes())); + String resultvalue1 = + ByteArray.toHexString( + infoById1.get().getLogList().get(0).getTopicsList().get(0).toByteArray()); Assert.assertTrue(infoById1.get().getResultValue() == 0); Assert.assertEquals(value, resultvalue1); - } - @Test(enabled = true, description = "Permission control ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Permission control ", + groups = {"contract", "daily"}) public void test3Grammar016() { String filePath = "src/test/resources/soliditycode/contractGrammar003test3Grammar016.sol"; - String contractName = "D"; + String contractName = "D"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress3, - grammarAddress3, blockingStubFull); - - String contractName1 = "E"; + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress3, + grammarAddress3, + blockingStubFull); + + String contractName1 = "E"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - byte[] contractAddress1 = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress3, - grammarAddress3, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + byte[] contractAddress1 = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress3, + grammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; - String txid = PublicMethod.triggerContract(contractAddress, - "readData()", "#", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + "readData()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); Optional infoById1 = null; - String txid1 = PublicMethod.triggerContract(contractAddress1, - "g()", "#", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + contractAddress1, + "g()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); Optional infoById2 = null; - String num = "3"; - String txid2 = PublicMethod.triggerContract(contractAddress1, - "setData(uint256)", num, false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); - - String txid3 = PublicMethod.triggerContract(contractAddress1, - "getData()", "#", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String num = "3"; + String txid2 = + PublicMethod.triggerContract( + contractAddress1, + "setData(uint256)", + num, + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - PublicMethod.waitProduceNextBlock(blockingStubFull); infoById1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); Assert.assertTrue(infoById1.get().getResultValue() == 0); - infoById2 = PublicMethod.getTransactionInfoById(txid2, blockingStubFull); Assert.assertTrue(infoById2.get().getResultValue() == 0); + String txid3 = + PublicMethod.triggerContract( + contractAddress1, + "getData()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); + PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById3 = null; infoById3 = PublicMethod.getTransactionInfoById(txid3, blockingStubFull); - Long returnnumber3 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById3.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(infoById3.get().getResultValue() == 0); + Long returnnumber3 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById3.get().getContractResult(0).toByteArray()))); logger.info("test3Grammar016 returnnumber3 : " + returnnumber3); Assert.assertTrue(returnnumber3 == 3); Assert.assertTrue(infoById3.get().getResultValue() == 0); - } - @Test(enabled = true, description = "Structure", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Structure", + groups = {"contract", "daily"}) public void test4Grammar017() { String filePath = "src/test/resources/soliditycode/contractGrammar003test4Grammar017.sol"; - String contractName = "CrowdFunding"; + String contractName = "CrowdFunding"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] contractAddress1 = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress3, - grammarAddress3, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress1 = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress3, + grammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String initParmes = "\"" + Base58.encode58Check(grammarAddress3) + "\",\"1\""; + String initParmes = "\"" + Base58.encode58Check(grammarAddress3) + "\",\"1\""; Optional infoById = null; - String txid = PublicMethod.triggerContract(contractAddress1, - "candidate(address,uint256)", initParmes, false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); - String txid1 = PublicMethod.triggerContract(contractAddress1, - "check(uint256)", "1", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); - String txid2 = PublicMethod.triggerContract(contractAddress1, - "vote(uint256)", "1", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress1, + "candidate(address,uint256)", + initParmes, + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + contractAddress1, + "check(uint256)", + "1", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); + String txid2 = + PublicMethod.triggerContract( + contractAddress1, + "vote(uint256)", + "1", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long returnnumber1 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Long returnnumber1 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(returnnumber1 == 1); - Optional infoById1 = PublicMethod - .getTransactionInfoById(txid1, blockingStubFull1); - Long returnnumber2 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Optional infoById1 = + PublicMethod.getTransactionInfoById(txid1, blockingStubFull1); + Long returnnumber2 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(returnnumber2 == 1); - Optional infoById2 = PublicMethod - .getTransactionInfoById(txid2, blockingStubFull); + Optional infoById2 = + PublicMethod.getTransactionInfoById(txid2, blockingStubFull); Assert.assertTrue(infoById2.get().getResultValue() == 0); - } - @Test(enabled = true, description = "Built-in function", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Built-in function", + groups = {"contract", "daily"}) public void test5Grammar018() { String filePath = "src/test/resources/soliditycode/contractGrammar003test5Grammar018.sol"; - String contractName = "Grammar18"; + String contractName = "Grammar18"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress3, - grammarAddress3, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress3, + grammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; - String txid = PublicMethod.triggerContract(contractAddress, - "testAddmod()", "#", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); - String txid1 = PublicMethod.triggerContract(contractAddress, - "testMulmod()", "#", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); - String txid2 = PublicMethod.triggerContract(contractAddress, - "testKeccak256()", "#", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); - String txid3 = PublicMethod.triggerContract(contractAddress, - "testSha256()", "#", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); - String txid4 = PublicMethod.triggerContract(contractAddress, - "testSha3()", "#", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + "testAddmod()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + contractAddress, + "testMulmod()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); + String txid2 = + PublicMethod.triggerContract( + contractAddress, + "testKeccak256()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); + String txid3 = + PublicMethod.triggerContract( + contractAddress, + "testSha256()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); + String txid4 = + PublicMethod.triggerContract( + contractAddress, + "testSha3()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertTrue(returnnumber == 1); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); - Long returnnumber1 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Long returnnumber1 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(infoById1.get().getResultValue() == 0); Assert.assertTrue(returnnumber1 == 2); @@ -420,58 +749,95 @@ public void test5Grammar018() { Assert.assertTrue(infoById4.get().getResultValue() == 0); } - - @Test(enabled = true, description = "Time unit", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Time unit", + groups = {"contract", "daily"}) public void test6Grammar019() { String filePath = "src/test/resources/soliditycode/contractGrammar003test6Grammar019.sol"; - String contractName = "timetest"; + String contractName = "timetest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress3, - grammarAddress3, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress3, + grammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = PublicMethod.triggerContract(contractAddress, - "timetest()", "#", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + "timetest()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 1); - } - - @Test(enabled = true, description = "Trx and sun unit conversion.", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trx and sun unit conversion.", + groups = {"contract", "daily"}) public void test7Grammar020() { String filePath = "src/test/resources/soliditycode/contractGrammar003test7Grammar020.sol"; - String contractName = "trxtest"; + String contractName = "trxtest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress3, - grammarAddress3, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress3, + grammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; - String txid = PublicMethod.triggerContract(contractAddress, - "test()", "#", false, - 0, maxFeeLimit, grammarAddress3, testKeyForGrammarAddress3, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + "test()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress3, + testKeyForGrammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(grammarAddress3, testKeyForGrammarAddress3, testNetAccountAddress, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + grammarAddress3, testKeyForGrammarAddress3, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/grammar/ContractGrammar004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/grammar/ContractGrammar004.java index cb28f03f..fcd7d6b8 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/grammar/ContractGrammar004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetissue/grammar/ContractGrammar004.java @@ -29,15 +29,14 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class ContractGrammar004 extends TronBaseTest { - - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -45,46 +44,69 @@ public class ContractGrammar004 extends TronBaseTest { String testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String compilerVersion = Configuration.getByPath("testng.conf") - .getString("defaultParameter.solidityCompilerVersion"); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String compilerVersion = + Configuration.getByPath("testng.conf").getString("defaultParameter.solidityCompilerVersion"); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(testKeyForGrammarAddress); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + PublicMethod.printAddress(testKeyForGrammarAddress); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } - @Test(enabled = true, description = "ContractResult is OUT_OF_TIME", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "ContractResult is OUT_OF_TIME", + groups = {"contract", "daily"}) public void test1Grammar001() { - Assert.assertTrue(PublicMethod - .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + grammarAddress, + 100000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull1)); PublicMethod.waitProduceNextBlock(blockingStubFull1); - String filePath = "./src/test/resources/soliditycode/walletTestMultiSign004.sol"; - String contractName = "timeoutTest"; + String filePath = "./src/test/resources/soliditycode/walletTestMultiSign004.sol"; + String contractName = "timeoutTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, - testKeyForGrammarAddress, grammarAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress, + grammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); org.testng.Assert.assertTrue(smartContract.getAbi().toString() != null); - String txid = null; + String txid = null; Optional infoById = null; - String initParmes = "\"" + "100000" + "\""; - txid = PublicMethod - .triggerContract(contractAddress, "testUseCpu(uint256)", initParmes, false, 0, maxFeeLimit, - grammarAddress, testKeyForGrammarAddress, blockingStubFull); + String initParmes = "\"" + "100000" + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testUseCpu(uint256)", + initParmes, + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("Txid is " + txid); @@ -100,37 +122,55 @@ public void test1Grammar001() { Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), OUT_OF_TIME_VALUE); Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.OUT_OF_TIME); - Assert - .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); + Assert.assertEquals( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); Assert.assertEquals(contractResult.OUT_OF_TIME, infoById.get().getReceipt().getResult()); Assert.assertEquals(byId.get().getRet(0).getRet().getNumber(), 0); Assert.assertEquals(byId.get().getRet(0).getRetValue(), 0); - - } - - @Test(enabled = true, description = "ContractResult is OUT_OF_MEMORY", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "ContractResult is OUT_OF_MEMORY", + groups = {"contract", "daily"}) public void test2Grammar002() { String filePath = "./src/test/resources/soliditycode/testOutOfMem.sol"; - String contractName = "Test"; + String contractName = "Test"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, - testKeyForGrammarAddress, grammarAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress, + grammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); org.testng.Assert.assertTrue(smartContract.getAbi().toString() != null); - String txid = null; + String txid = null; Optional infoById = null; - String initParmes = "\"" + "31457280" + "\""; - txid = PublicMethod - .triggerContract(contractAddress, "testOutOfMem(uint256)", initParmes, false, 0, - maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + String initParmes = "\"" + "31457280" + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testOutOfMem(uint256)", + initParmes, + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("Txid is " + txid); @@ -148,46 +188,76 @@ public void test2Grammar002() { Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), OUT_OF_MEMORY_VALUE); Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.OUT_OF_MEMORY); - Assert - .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); + Assert.assertEquals( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); Assert.assertEquals(contractResult.OUT_OF_MEMORY, infoById.get().getReceipt().getResult()); Assert.assertEquals(byId.get().getRet(0).getRet().getNumber(), 0); Assert.assertEquals(byId.get().getRet(0).getRetValue(), 0); - - } - - @Test(enabled = true, description = "ContractResult is BAD_JUMP_DESTINATION", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "ContractResult is BAD_JUMP_DESTINATION", + groups = {"contract", "daily"}) public void test3Grammar003() { String contractName = "Test"; - String code = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a57600" - + "080fd5b5061011f8061003a6000396000f30060806040526004361060485763ffffffff7c01000000000000" - + "000000000000000000000000000000000000000000006000350416634ef5a0088114604d5780639093b95b1" - + "4608c575b600080fd5b348015605857600080fd5b50d38015606457600080fd5b50d28015607057600080fd" - + "5b50607a60043560b8565b60408051918252519081900360200190f35b348015609757600080fd5b50d3801" - + "560a357600080fd5b50d2801560af57600080fd5b5060b660ee565b005b6000606082604051908082528060" - + "20026020018201604052801560e5578160200160208202803883390190505b50905050919050565b6001805" - + "600a165627a7a7230582092ba162087e13f41c6d6c00ba493edc5a5a6250a3840ece5f99aa38b66366a7000" - + "29"; - String abi = "[{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\"" - + ":\"testOutOfMem\",\"outputs\":[{\"name\":\"r\",\"type\":\"bytes32\"}],\"payable\":false" - + ",\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs" - + "\":[],\"name\":\"testBadJumpDestination\",\"outputs\":[],\"payable\":false,\"stateMutab" - + "ility\":\"nonpayable\",\"type\":\"function\"}]"; - byte[] contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, - testKeyForGrammarAddress, grammarAddress, blockingStubFull); + String code = + "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a57600" + + "080fd5b5061011f8061003a6000396000f30060806040526004361060485763ffffffff7c01000000000" + + "000" + + "000000000000000000000000000000000000000000006000350416634ef5a0088114604d5780639093b9" + + "5b1" + + "4608c575b600080fd5b348015605857600080fd5b50d38015606457600080fd5b50d2801560705760008" + + "0fd" + + "5b50607a60043560b8565b60408051918252519081900360200190f35b348015609757600080fd5b50d3" + + "801" + + "560a357600080fd5b50d2801560af57600080fd5b5060b660ee565b005b6000606082604051908082528" + + "060" + + "20026020018201604052801560e5578160200160208202803883390190505b50905050919050565b6001" + + "805" + + "600a165627a7a7230582092ba162087e13f41c6d6c00ba493edc5a5a6250a3840ece5f99aa38b66366a7" + + "000" + + "29"; + String abi = + "[{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\"" + + ":\"testOutOfMem\",\"outputs\":[{\"name\":\"r\",\"type\":\"bytes32\"}],\"payable\":fa" + + "lse" + + ",\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inp" + + "uts" + + "\":[],\"name\":\"testBadJumpDestination\",\"outputs\":[],\"payable\":false,\"stateMu" + + "tab" + + "ility\":\"nonpayable\",\"type\":\"function\"}]"; + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress, + grammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); org.testng.Assert.assertTrue(smartContract.getAbi().toString() != null); - String txid = null; + String txid = null; Optional infoById = null; - txid = PublicMethod - .triggerContract(contractAddress, "testBadJumpDestination()", "#", false, 0, maxFeeLimit, - grammarAddress, testKeyForGrammarAddress, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "testBadJumpDestination()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("Txid is " + txid); @@ -205,29 +275,39 @@ public void test3Grammar003() { Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), BAD_JUMP_DESTINATION_VALUE); Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.BAD_JUMP_DESTINATION); - Assert - .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); - Assert - .assertEquals(contractResult.BAD_JUMP_DESTINATION, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); + Assert.assertEquals( + contractResult.BAD_JUMP_DESTINATION, infoById.get().getReceipt().getResult()); Assert.assertEquals(byId.get().getRet(0).getRet().getNumber(), 0); Assert.assertEquals(byId.get().getRet(0).getRetValue(), 0); - - } - - @Test(enabled = true, description = "ContractResult is OUT_OF_ENERGY", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "ContractResult is OUT_OF_ENERGY", + groups = {"contract", "daily"}) public void test4Grammar004() { String filePath = "src/test/resources/soliditycode/contractUnknownException.sol"; - String contractName = "testC"; + String contractName = "testC"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 20L, 100, - null, testKeyForGrammarAddress, grammarAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 20L, + 100, + null, + testKeyForGrammarAddress, + grammarAddress, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -246,36 +326,55 @@ public void test4Grammar004() { Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), REVERT_VALUE); Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.REVERT); - Assert.assertEquals(ByteArray.toHexString(infoById.get() - .getContractResult(0).toByteArray()), + Assert.assertEquals( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), "4e487b710000000000000000000000000000000000000000000000000000000000000001"); Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); Assert.assertEquals(byId.get().getRet(0).getRet().getNumber(), 0); Assert.assertEquals(byId.get().getRet(0).getRetValue(), 0); - } - - @Test(enabled = true, description = "ContractResult is ILLEGAL_OPERATION", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "ContractResult is ILLEGAL_OPERATION", + groups = {"contract", "daily"}) public void test5Grammar005() { String filePath = "src/test/resources/soliditycode/assertExceptiontest1DivideInt.sol"; - String contractName = "divideIHaveArgsReturnStorage"; + String contractName = "divideIHaveArgsReturnStorage"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, - testKeyForGrammarAddress, grammarAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress, + grammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = ""; - String num = "4" + "," + "0"; - - txid = PublicMethod - .triggerContract(contractAddress, "divideIHaveArgsReturn(int256,int256)", num, false, 0, - maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + String txid = ""; + String num = "4" + "," + "0"; + + txid = + PublicMethod.triggerContract( + contractAddress, + "divideIHaveArgsReturn(int256,int256)", + num, + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -290,30 +389,49 @@ public void test5Grammar005() { Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), REVERT_VALUE); Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.REVERT); - Assert - .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), - "4e487b710000000000000000000000000000000000000000000000000000000000000012"); + Assert.assertEquals( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), + "4e487b710000000000000000000000000000000000000000000000000000000000000012"); Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); - } - - @Test(enabled = true, description = "ContractResult is REVERT", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "ContractResult is REVERT", + groups = {"contract", "daily"}) public void test6Grammar006() { String filePath = "src/test/resources/soliditycode/requireExceptiontest1TestRequireContract.sol"; - String contractName = "TestThrowsContract"; + String contractName = "TestThrowsContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, - testKeyForGrammarAddress, grammarAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress, + grammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - final String txid = PublicMethod - .triggerContract(contractAddress, "testRequire()", "#", false, 0, maxFeeLimit, - grammarAddress, testKeyForGrammarAddress, blockingStubFull); + final String txid = + PublicMethod.triggerContract( + contractAddress, + "testRequire()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -328,31 +446,51 @@ public void test6Grammar006() { Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), REVERT_VALUE); Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.REVERT); - Assert - .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); + Assert.assertEquals( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); - } - @Test(enabled = true, description = "ContractResult is SUCCESS", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "ContractResult is SUCCESS", + groups = {"contract", "daily"}) public void test7Grammar007() { String filePath = "src/test/resources/soliditycode/assertExceptiontest1DivideInt.sol"; - String contractName = "divideIHaveArgsReturnStorage"; + String contractName = "divideIHaveArgsReturnStorage"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, - testKeyForGrammarAddress, grammarAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress, + grammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = ""; - String num = "4" + "," + "2"; - - txid = PublicMethod - .triggerContract(contractAddress, "divideIHaveArgsReturn(int256,int256)", num, false, 0, - maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + String txid = ""; + String num = "4" + "," + "2"; + + txid = + PublicMethod.triggerContract( + contractAddress, + "divideIHaveArgsReturn(int256,int256)", + num, + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -363,60 +501,80 @@ public void test7Grammar007() { logger.info("getContractRetValue:" + byId.get().getRet(0).getContractRetValue()); logger.info("getContractRet:" + byId.get().getRet(0).getContractRet()); - Assert.assertEquals(byId.get().getRet(0).getContractRet().getNumber(), - contractResult.SUCCESS_VALUE); + Assert.assertEquals( + byId.get().getRet(0).getContractRet().getNumber(), contractResult.SUCCESS_VALUE); Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), contractResult.SUCCESS_VALUE); Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.SUCCESS); Assert.assertEquals(contractResult.SUCCESS, infoById.get().getReceipt().getResult()); - Assert.assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), + Assert.assertEquals( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), "0000000000000000000000000000000000000000000000000000000000000002"); - } - - @Test(enabled = true, description = "ContractResult is TRANSFER_FAILED", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "ContractResult is TRANSFER_FAILED", + groups = {"contract", "daily"}) public void test8Grammar008() { String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; + String contractName = "EnergyOfTransferFailedTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 1000000L, 100, null, - testKeyForGrammarAddress, grammarAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForGrammarAddress, + grammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(grammarAddress, blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(grammarAddress, blockingStubFull); info = PublicMethod.queryAccount(testKeyForGrammarAddress, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - ECKey ecKey2 = new ECKey(Utils.getRandom()); - byte[] nonexistentAddress = ecKey2.getAddress(); - String txid = ""; - String num = "1" + ",\"" + Base58.encode58Check(nonexistentAddress) + "\""; - - txid = PublicMethod - .triggerContract(contractAddress, "testTransferTrxNonexistentTarget(uint256,address)", num, - false, 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] nonexistentAddress = ecKey2.getAddress(); + String txid = ""; + String num = "1" + ",\"" + Base58.encode58Check(nonexistentAddress) + "\""; + + txid = + PublicMethod.triggerContract( + contractAddress, + "testTransferTrxNonexistentTarget(uint256,address)", + num, + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -425,12 +583,12 @@ public void test8Grammar008() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(testKeyForGrammarAddress, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(grammarAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(grammarAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -439,39 +597,61 @@ public void test8Grammar008() { Assert.assertTrue(infoById.get().getResultValue() == 0); logger.info( "infoById.get().getReceipt().getResult(): " + infoById.get().getReceipt().getResult()); - logger.info("ByteArray.toStr(infoById.get().getResMessage().toByteArray()): " + ByteArray - .toStr(infoById.get().getResMessage().toByteArray())); + logger.info( + "ByteArray.toStr(infoById.get().getResMessage().toByteArray()): " + + ByteArray.toStr(infoById.get().getResMessage().toByteArray())); /*Assert.assertEquals( - "transfer trx failed: Validate InternalTransfer error, no ToAccount." - + " And not allowed to create account in smart contract.", - ByteArray.toStr(infoById.get().getResMessage().toByteArray()));*/ + "transfer trx failed: Validate InternalTransfer error, no ToAccount." + + " And not allowed to create account in smart contract.", + ByteArray.toStr(infoById.get().getResMessage().toByteArray()));*/ Assert.assertTrue(afterBalance + fee == beforeBalance); Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Assert.assertNotEquals(10000000, energyUsageTotal); - - } - - @Test(enabled = true, description = "ContractResult is STACK_TOO_SMALL", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "ContractResult is STACK_TOO_SMALL", + groups = {"contract", "daily"}) public void test9Grammar009() { String contractName = "TestThrowsContract"; - String abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"testStackTooSmall\",\"outputs\":[]" - + ",\"payable\":false,\"type\":\"function\",\"stateMutability\":\"nonpayable\"}]"; - String code = "60606040523415600b57fe5b5b60608060196000396000f300606060405263ffffffff60e060020" - + "a6000350416632f3a24cc81146020575bfe5b3415602757fe5b602d602f565b005b50505b5600a165627a7a" - + "723058208184f2ff2627a8a490bfd1233a891f2f4605375d0fec375e237ffc188cdd7ec70029"; - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, - testKeyForGrammarAddress, grammarAddress, blockingStubFull); + String abi = + "[{\"constant\":false,\"inputs\":[],\"name\":\"testStackTooSmall\",\"outputs\":[]" + + ",\"payable\":false,\"type\":\"function\",\"stateMutability\":\"nonpayable\"}]"; + String code = + "60606040523415600b57fe5b5b60608060196000396000f300606060405263ffffffff60e060020" + + "a6000350416632f3a24cc81146020575bfe5b3415602757fe5b602d602f565b005b50505b5600a165627" + + "a7a" + + "723058208184f2ff2627a8a490bfd1233a891f2f4605375d0fec375e237ffc188cdd7ec70029"; + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress, + grammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - final String txid = PublicMethod - .triggerContract(contractAddress, "testStackTooSmall()", "#", false, 0, maxFeeLimit, - grammarAddress, testKeyForGrammarAddress, blockingStubFull); + final String txid = + PublicMethod.triggerContract( + contractAddress, + "testStackTooSmall()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -486,93 +666,181 @@ public void test9Grammar009() { Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), STACK_TOO_SMALL_VALUE); Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.STACK_TOO_SMALL); - Assert - .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); + Assert.assertEquals( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); Assert.assertEquals(contractResult.STACK_TOO_SMALL, infoById.get().getReceipt().getResult()); - } - @Test(enabled = true, description = "ContractResult is STACK_TOO_LARGE", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "ContractResult is STACK_TOO_LARGE", + groups = {"contract", "daily"}) public void test9Grammar010() { String contractName = "TestThrowsContract"; - String abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"testStackTooLarge\",\"outputs\":[]" - + ",\"payable\":false,\"type\":\"function\",\"stateMutability\":\"nonpayable\"}]"; - String code = "6060604052341561000c57fe5b5b610b658061001c6000396000f300606060405263ffffffff60e" - + "060020a600035041663f7d9c5c68114610021575bfe5b341561002957fe5b610031610033565b005b600060" - + "0160026003600460056006600760086009600a600b600c600d600e600f60106011601260136014601560166" - + "01760186019601a601b601c601d601e601f6020602160226023602460256026602760286029602a602b602c" - + "602d602e602f6030603160326033603460356036603760386039603a603b603c603d603e603f60406041604" - + "26043604460456046604760486049604a604b604c604d604e604f6050605160526053605460556056605760" - + "586059605a605b605c605d605e605f6060606160626063606460656066606760686069606a606b606c606d6" - + "06e606f6070607160726073607460756076607760786079607a607b607c607d607e607f6080608160826083" - + "608460856086608760886089608a608b608c608d608e608f609060916092609360946095609660976098609" - + "9609a609b609c609d609e609f60a060a160a260a360a460a560a660a760a860a960aa60ab60ac60ad60ae60" - + "af60b060b160b260b360b460b560b660b760b860b960ba60bb60bc60bd60be60bf60c060c160c260c360c46" - + "0c560c660c760c860c960ca60cb60cc60cd60ce60cf60d060d160d260d360d460d560d660d760d860d960da" - + "60db60dc60dd60de60df60e060e160e260e360e460e560e660e760e860e960ea60eb60ec60ed60ee60ef60f" - + "060f160f260f360f460f560f660f760f860f960fa60fb60fc60fd60fe60ff61010061010161010261010361" - + "010461010561010661010761010861010961010a61010b61010c61010d61010e61010f61011061011161011" - + "261011361011461011561011661011761011861011961011a61011b61011c61011d61011e61011f61012061" - + "012161012261012361012461012561012661012761012861012961012a61012b61012c61012d61012e61012" - + "f61013061013161013261013361013461013561013661013761013861013961013a61013b61013c61013d61" - + "013e61013f61014061014161014261014361014461014561014661014761014861014961014a61014b61014" - + "c61014d61014e61014f61015061015161015261015361015461015561015661015761015861015961015a61" - + "015b61015c61015d61015e61015f61016061016161016261016361016461016561016661016761016861016" - + "961016a61016b61016c61016d61016e61016f61017061017161017261017361017461017561017661017761" - + "017861017961017a61017b61017c61017d61017e61017f61018061018161018261018361018461018561018" - + "661018761018861018961018a61018b61018c61018d61018e61018f61019061019161019261019361019461" - + "019561019661019761019861019961019a61019b61019c61019d61019e61019f6101a06101a16101a26101a" - + "36101a46101a56101a66101a76101a86101a96101aa6101ab6101ac6101ad6101ae6101af6101b06101b161" - + "01b26101b36101b46101b56101b66101b76101b86101b96101ba6101bb6101bc6101bd6101be6101bf6101c" - + "06101c16101c26101c36101c46101c56101c66101c76101c86101c96101ca6101cb6101cc6101cd6101ce61" - + "01cf6101d06101d16101d26101d36101d46101d56101d66101d76101d86101d96101da6101db6101dc6101d" - + "d6101de6101df6101e06101e16101e26101e36101e46101e56101e66101e76101e86101e96101ea6101eb61" - + "01ec6101ed6101ee6101ef6101f06101f16101f26101f36101f46101f56101f66101f76101f86101f96101f" - + "a6101fb6101fc6101fd6101fe6101ff61020061020161020261020361020461020561020661020761020861" - + "020961020a61020b61020c61020d61020e61020f61021061021161021261021361021461021561021661021" - + "761021861021961021a61021b61021c61021d61021e61021f61022061022161022261022361022461022561" - + "022661022761022861022961022a61022b61022c61022d61022e61022f61023061023161023261023361023" - + "461023561023661023761023861023961023a61023b61023c61023d61023e61023f61024061024161024261" - + "024361024461024561024661024761024861024961024a61024b61024c61024d61024e61024f61025061025" - + "161025261025361025461025561025661025761025861025961025a61025b61025c61025d61025e61025f61" - + "026061026161026261026361026461026561026661026761026861026961026a61026b61026c61026d61026" - + "e61026f61027061027161027261027361027461027561027661027761027861027961027a61027b61027c61" - + "027d61027e61027f61028061028161028261028361028461028561028661028761028861028961028a61028" - + "b61028c61028d61028e61028f61029061029161029261029361029461029561029661029761029861029961" - + "029a61029b61029c61029d61029e61029f6102a06102a16102a26102a36102a46102a56102a66102a76102a" - + "86102a96102aa6102ab6102ac6102ad6102ae6102af6102b06102b16102b26102b36102b46102b56102b661" - + "02b76102b86102b96102ba6102bb6102bc6102bd6102be6102bf6102c06102c16102c26102c36102c46102c" - + "56102c66102c76102c86102c96102ca6102cb6102cc6102cd6102ce6102cf6102d06102d16102d26102d361" - + "02d46102d56102d66102d76102d86102d96102da6102db6102dc6102dd6102de6102df6102e06102e16102e" - + "26102e36102e46102e56102e66102e76102e86102e96102ea6102eb6102ec6102ed6102ee6102ef6102f061" - + "02f16102f26102f36102f46102f56102f66102f76102f86102f96102fa6102fb6102fc6102fd6102fe6102f" - + "f61030061030161030261030361030461030561030661030761030861030961030a61030b61030c61030d61" - + "030e61030f61031061031161031261031361031461031561031661031761031861031961031a61031b61031" - + "c61031d61031e61031f61032061032161032261032361032461032561032661032761032861032961032a61" - + "032b61032c61032d61032e61032f61033061033161033261033361033461033561033661033761033861033" - + "961033a61033b61033c61033d61033e61033f61034061034161034261034361034461034561034661034761" - + "034861034961034a61034b61034c61034d61034e61034f61035061035161035261035361035461035561035" - + "661035761035861035961035a61035b61035c61035d61035e61035f61036061036161036261036361036461" - + "036561036661036761036861036961036a61036b61036c61036d61036e61036f61037061037161037261037" - + "361037461037561037661037761037861037961037a61037b61037c61037d61037e61037f61038061038161" - + "038261038361038461038561038661038761038861038961038a61038b61038c61038d61038e61038f61039" - + "061039161039261039361039461039561039661039761039861039961039a61039b61039c61039d61039e61" - + "039f6103a06103a16103a26103a36103a46103a56103a66103a76103a86103a96103aa6103ab6103ac6103a" - + "d6103ae6103af6103b06103b16103b26103b36103b46103b56103b66103b76103b86103b96103ba6103bb61" - + "03bc6103bd6103be6103bf6103c06103c16103c26103c36103c46103c56103c66103c76103c86103c96103c" - + "a6103cb6103cc6103cd6103ce6103cf6103d06103d16103d26103d36103d46103d56103d66103d76103d861" - + "03d96103da6103db6103dc6103dd6103de6103df6103e06103e16103e26103e36103e46103e56103e66103e" - + "76103e86103e96103ea6103eb6103ec6103ed6103ee6103ef6103f06103f16103f26103f36103f46103f561" - + "03f66103f76103f86103f96103fa6103fb6103fc6103fd6103fe6103ff6104005b5600a165627a7a7230582" - + "0998f09cc267db91352a3d0a4ab60ea08fc306fa8bc6dd78dc324a06109dcf0420029"; - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, - testKeyForGrammarAddress, grammarAddress, blockingStubFull); + String abi = + "[{\"constant\":false,\"inputs\":[],\"name\":\"testStackTooLarge\",\"outputs\":[]" + + ",\"payable\":false,\"type\":\"function\",\"stateMutability\":\"nonpayable\"}]"; + String code = + "6060604052341561000c57fe5b5b610b658061001c6000396000f300606060405263ffffffff60e" + + "060020a600035041663f7d9c5c68114610021575bfe5b341561002957fe5b610031610033565b005b600" + + "060" + + "0160026003600460056006600760086009600a600b600c600d600e600f60106011601260136014601560" + + "166" + + "01760186019601a601b601c601d601e601f6020602160226023602460256026602760286029602a602b6" + + "02c" + + "602d602e602f6030603160326033603460356036603760386039603a603b603c603d603e603f60406041" + + "604" + + "26043604460456046604760486049604a604b604c604d604e604f6050605160526053605460556056605" + + "760" + + "586059605a605b605c605d605e605f6060606160626063606460656066606760686069606a606b606c60" + + "6d6" + + "06e606f6070607160726073607460756076607760786079607a607b607c607d607e607f6080608160826" + + "083" + + "608460856086608760886089608a608b608c608d608e608f609060916092609360946095609660976098" + + "609" + + "9609a609b609c609d609e609f60a060a160a260a360a460a560a660a760a860a960aa60ab60ac60ad60a" + + "e60" + + "af60b060b160b260b360b460b560b660b760b860b960ba60bb60bc60bd60be60bf60c060c160c260c360" + + "c46" + + "0c560c660c760c860c960ca60cb60cc60cd60ce60cf60d060d160d260d360d460d560d660d760d860d96" + + "0da" + + "60db60dc60dd60de60df60e060e160e260e360e460e560e660e760e860e960ea60eb60ec60ed60ee60ef" + + "60f" + + "060f160f260f360f460f560f660f760f860f960fa60fb60fc60fd60fe60ff61010061010161010261010" + + "361" + + "010461010561010661010761010861010961010a61010b61010c61010d61010e61010f61011061011161" + + "011" + + "261011361011461011561011661011761011861011961011a61011b61011c61011d61011e61011f61012" + + "061" + + "012161012261012361012461012561012661012761012861012961012a61012b61012c61012d61012e61" + + "012" + + "f61013061013161013261013361013461013561013661013761013861013961013a61013b61013c61013" + + "d61" + + "013e61013f61014061014161014261014361014461014561014661014761014861014961014a61014b61" + + "014" + + "c61014d61014e61014f61015061015161015261015361015461015561015661015761015861015961015" + + "a61" + + "015b61015c61015d61015e61015f61016061016161016261016361016461016561016661016761016861" + + "016" + + "961016a61016b61016c61016d61016e61016f61017061017161017261017361017461017561017661017" + + "761" + + "017861017961017a61017b61017c61017d61017e61017f61018061018161018261018361018461018561" + + "018" + + "661018761018861018961018a61018b61018c61018d61018e61018f61019061019161019261019361019" + + "461" + + "019561019661019761019861019961019a61019b61019c61019d61019e61019f6101a06101a16101a261" + + "01a" + + "36101a46101a56101a66101a76101a86101a96101aa6101ab6101ac6101ad6101ae6101af6101b06101b" + + "161" + + "01b26101b36101b46101b56101b66101b76101b86101b96101ba6101bb6101bc6101bd6101be6101bf61" + + "01c" + + "06101c16101c26101c36101c46101c56101c66101c76101c86101c96101ca6101cb6101cc6101cd6101c" + + "e61" + + "01cf6101d06101d16101d26101d36101d46101d56101d66101d76101d86101d96101da6101db6101dc61" + + "01d" + + "d6101de6101df6101e06101e16101e26101e36101e46101e56101e66101e76101e86101e96101ea6101e" + + "b61" + + "01ec6101ed6101ee6101ef6101f06101f16101f26101f36101f46101f56101f66101f76101f86101f961" + + "01f" + + "a6101fb6101fc6101fd6101fe6101ff61020061020161020261020361020461020561020661020761020" + + "861" + + "020961020a61020b61020c61020d61020e61020f61021061021161021261021361021461021561021661" + + "021" + + "761021861021961021a61021b61021c61021d61021e61021f61022061022161022261022361022461022" + + "561" + + "022661022761022861022961022a61022b61022c61022d61022e61022f61023061023161023261023361" + + "023" + + "461023561023661023761023861023961023a61023b61023c61023d61023e61023f61024061024161024" + + "261" + + "024361024461024561024661024761024861024961024a61024b61024c61024d61024e61024f61025061" + + "025" + + "161025261025361025461025561025661025761025861025961025a61025b61025c61025d61025e61025" + + "f61" + + "026061026161026261026361026461026561026661026761026861026961026a61026b61026c61026d61" + + "026" + + "e61026f61027061027161027261027361027461027561027661027761027861027961027a61027b61027" + + "c61" + + "027d61027e61027f61028061028161028261028361028461028561028661028761028861028961028a61" + + "028" + + "b61028c61028d61028e61028f61029061029161029261029361029461029561029661029761029861029" + + "961" + + "029a61029b61029c61029d61029e61029f6102a06102a16102a26102a36102a46102a56102a66102a761" + + "02a" + + "86102a96102aa6102ab6102ac6102ad6102ae6102af6102b06102b16102b26102b36102b46102b56102b" + + "661" + + "02b76102b86102b96102ba6102bb6102bc6102bd6102be6102bf6102c06102c16102c26102c36102c461" + + "02c" + + "56102c66102c76102c86102c96102ca6102cb6102cc6102cd6102ce6102cf6102d06102d16102d26102d" + + "361" + + "02d46102d56102d66102d76102d86102d96102da6102db6102dc6102dd6102de6102df6102e06102e161" + + "02e" + + "26102e36102e46102e56102e66102e76102e86102e96102ea6102eb6102ec6102ed6102ee6102ef6102f" + + "061" + + "02f16102f26102f36102f46102f56102f66102f76102f86102f96102fa6102fb6102fc6102fd6102fe61" + + "02f" + + "f61030061030161030261030361030461030561030661030761030861030961030a61030b61030c61030" + + "d61" + + "030e61030f61031061031161031261031361031461031561031661031761031861031961031a61031b61" + + "031" + + "c61031d61031e61031f61032061032161032261032361032461032561032661032761032861032961032" + + "a61" + + "032b61032c61032d61032e61032f61033061033161033261033361033461033561033661033761033861" + + "033" + + "961033a61033b61033c61033d61033e61033f61034061034161034261034361034461034561034661034" + + "761" + + "034861034961034a61034b61034c61034d61034e61034f61035061035161035261035361035461035561" + + "035" + + "661035761035861035961035a61035b61035c61035d61035e61035f61036061036161036261036361036" + + "461" + + "036561036661036761036861036961036a61036b61036c61036d61036e61036f61037061037161037261" + + "037" + + "361037461037561037661037761037861037961037a61037b61037c61037d61037e61037f61038061038" + + "161" + + "038261038361038461038561038661038761038861038961038a61038b61038c61038d61038e61038f61" + + "039" + + "061039161039261039361039461039561039661039761039861039961039a61039b61039c61039d61039" + + "e61" + + "039f6103a06103a16103a26103a36103a46103a56103a66103a76103a86103a96103aa6103ab6103ac61" + + "03a" + + "d6103ae6103af6103b06103b16103b26103b36103b46103b56103b66103b76103b86103b96103ba6103b" + + "b61" + + "03bc6103bd6103be6103bf6103c06103c16103c26103c36103c46103c56103c66103c76103c86103c961" + + "03c" + + "a6103cb6103cc6103cd6103ce6103cf6103d06103d16103d26103d36103d46103d56103d66103d76103d" + + "861" + + "03d96103da6103db6103dc6103dd6103de6103df6103e06103e16103e26103e36103e46103e56103e661" + + "03e" + + "76103e86103e96103ea6103eb6103ec6103ed6103ee6103ef6103f06103f16103f26103f36103f46103f" + + "561" + + "03f66103f76103f86103f96103fa6103fb6103fc6103fd6103fe6103ff6104005b5600a165627a7a7230" + + "582" + + "0998f09cc267db91352a3d0a4ab60ea08fc306fa8bc6dd78dc324a06109dcf0420029"; + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress, + grammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - final String txid = PublicMethod - .triggerContract(contractAddress, "testStackTooLarge()", "#", false, 0, maxFeeLimit, - grammarAddress, testKeyForGrammarAddress, blockingStubFull); + final String txid = + PublicMethod.triggerContract( + contractAddress, + "testStackTooLarge()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -587,21 +855,18 @@ public void test9Grammar010() { Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), STACK_TOO_LARGE_VALUE); Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.STACK_TOO_LARGE); - Assert - .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); + Assert.assertEquals( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); Assert.assertEquals(contractResult.STACK_TOO_LARGE, infoById.get().getReceipt().getResult()); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(grammarAddress, testKeyForGrammarAddress, testNetAccountAddress, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + grammarAddress, testKeyForGrammarAddress, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset001.java index c2f79064..021e4bd9 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset001.java @@ -1,6 +1,5 @@ package stest.tron.wallet.dailybuild.assetmarket; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.Optional; import lombok.extern.slf4j.Slf4j; @@ -18,8 +17,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MarketSellAsset001 extends TronBaseTest { @@ -50,27 +49,20 @@ public class MarketSellAsset001 extends TronBaseTest { /** constructor. */ @BeforeClass public void beforeClass() { - initSolidityChannel(); channelSolidity = ManagedChannelBuilder.forTarget(solidityNode).usePlaintext().build(); + initSolidityChannel(); + channelSolidity = ManagedChannelBuilder.forTarget(solidityNode).usePlaintext().build(); PublicMethod.printAddress(testKey001); PublicMethod.printAddress(testKey002); Assert.assertTrue( PublicMethod.sendcoin( - testAddress001, - 20000_000000L, - foundationAddress, - foundationKey, - blockingStubFull)); + testAddress001, 20000_000000L, foundationAddress, foundationKey, blockingStubFull)); Assert.assertTrue( PublicMethod.sendcoin( - testAddress002, - 20000_000000L, - foundationAddress, - foundationKey, - blockingStubFull)); + testAddress002, 20000_000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long start = System.currentTimeMillis() + 5000; - Long end = System.currentTimeMillis() + 1000000000; + Long start = System.currentTimeMillis() + 5000; + Long end = System.currentTimeMillis() + 1000000000; Assert.assertTrue( PublicMethod.createAssetIssue( testAddress001, @@ -123,7 +115,10 @@ public void beforeClass() { .toByteArray(); } - @Test(enabled = false, description = "create sellOrder", groups = {"daily"}) + @Test( + enabled = false, + description = "create sellOrder", + groups = {"daily"}) void marketSellAssetTest001() { String txid = @@ -146,7 +141,7 @@ void marketSellAssetTest001() { Optional orderList = PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull); Assert.assertTrue(orderList.get().getOrdersCount() > 0); - byte[] orderId = orderList.get().getOrders(0).getOrderId().toByteArray(); + byte[] orderId = orderList.get().getOrders(0).getOrderId().toByteArray(); MarketOrder order = PublicMethod.getMarketOrderById(orderId, blockingStubFull).get(); @@ -163,12 +158,15 @@ void marketSellAssetTest001() { Assert.assertEquals(transaction, transactionFromSolidity); } - @Test(enabled = false, description = "create sellOrder with value excption", groups = {"daily"}) + @Test( + enabled = false, + description = "create sellOrder with value excption", + groups = {"daily"}) void marketSellAssetTest002() { ECKey ecKey = new ECKey(Utils.getRandom()); - byte[] testAddress = ecKey.getAddress(); - String testKey = ByteArray.toHexString(ecKey.getPrivKeyBytes()); + byte[] testAddress = ecKey.getAddress(); + String testKey = ByteArray.toHexString(ecKey.getPrivKeyBytes()); long sendCoinValue = 10000_000000L; Assert.assertTrue( @@ -211,7 +209,10 @@ void marketSellAssetTest002() { Assert.assertEquals(account.getBalance(), sendCoinValue); } - @Test(enabled = false, description = "create sellOrder with tokenId excption", groups = {"daily"}) + @Test( + enabled = false, + description = "create sellOrder with tokenId excption", + groups = {"daily"}) void marketSellAssetTest003() { long beforeBalance = PublicMethod.queryAccount(testAddress001, blockingStubFull).getBalance(); diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset002.java index 988cf3c7..22613de5 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset002.java @@ -16,8 +16,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MarketSellAsset002 extends TronBaseTest { @@ -25,13 +25,12 @@ public class MarketSellAsset002 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final String name = "testAssetIssue003_" + Long.toString(now); private static final String shortname = "a"; - private final String foundationKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String foundationKey002 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] foundationAddress002 = PublicMethod.getFinalAddress(foundationKey002); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ECKey ecKey001 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey001.getAddress(); String testKey001 = ByteArray.toHexString(ecKey001.getPrivKeyBytes()); @@ -44,291 +43,377 @@ public class MarketSellAsset002 extends TronBaseTest { long sellTokenQuantity = 100; long buyTokenQuantity = 50; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(testKey001); + public void beforeClass() { + PublicMethod.printAddress(testKey001); PublicMethod.printAddress(testKey002); - Assert.assertTrue(PublicMethod.sendcoin(testAddress001, 20000_000000L, foundationAddress, - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(testAddress002, 20000_000000L, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress001, 20000_000000L, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress002, 20000_000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long start = System.currentTimeMillis() + 5000; - Long end = System.currentTimeMillis() + 1000000000; - Assert - .assertTrue(PublicMethod.createAssetIssue(testAddress001, name, 10000_000000L, 1, 1, start, - end, 1, description, url, 10000L, 10000L, 1L, 1L, testKey001, blockingStubFull)); + Long start = System.currentTimeMillis() + 5000; + Long end = System.currentTimeMillis() + 1000000000; + Assert.assertTrue( + PublicMethod.createAssetIssue( + testAddress001, + name, + 10000_000000L, + 1, + 1, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + testKey001, + blockingStubFull)); start = System.currentTimeMillis() + 5000; end = System.currentTimeMillis() + 1000000000; - Assert - .assertTrue(PublicMethod.createAssetIssue(testAddress002, name, 10000_000000L, 1, 1, start, - end, 1, description, url, 10000L, 10000L, 1L, 1L, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createAssetIssue( + testAddress002, + name, + 10000_000000L, + 1, + 1, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId001 = - PublicMethod.queryAccount(testAddress001, blockingStubFull).getAssetIssuedID() + PublicMethod.queryAccount(testAddress001, blockingStubFull) + .getAssetIssuedID() .toByteArray(); assetAccountId002 = - PublicMethod.queryAccount(testAddress002, blockingStubFull).getAssetIssuedID() + PublicMethod.queryAccount(testAddress002, blockingStubFull) + .getAssetIssuedID() .toByteArray(); } - - @Test(enabled = false, description = "create sellOrder and Match Order", groups = {"daily"}) + @Test( + enabled = false, + description = "create sellOrder and Match Order", + groups = {"daily"}) void marketSellAssetTest001() { - Map beforeAsset001 = PublicMethod - .queryAccount(testAddress001, blockingStubFull).getAssetV2Map(); - Map beforeAsset002 = PublicMethod - .queryAccount(testAddress002, blockingStubFull).getAssetV2Map(); + Map beforeAsset001 = + PublicMethod.queryAccount(testAddress001, blockingStubFull).getAssetV2Map(); + Map beforeAsset002 = + PublicMethod.queryAccount(testAddress002, blockingStubFull).getAssetV2Map(); logger.info("beforeAsset001: " + beforeAsset001); logger.info("beforeAsset002: " + beforeAsset002); - String txid = PublicMethod - .marketSellAsset(testAddress001, testKey001, assetAccountId001, sellTokenQuantity, - assetAccountId002, buyTokenQuantity, blockingStubFull); + String txid = + PublicMethod.marketSellAsset( + testAddress001, + testKey001, + assetAccountId001, + sellTokenQuantity, + assetAccountId002, + buyTokenQuantity, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - Optional transaction = PublicMethod - .getTransactionById(txid, blockingStubFull); + Optional transaction = PublicMethod.getTransactionById(txid, blockingStubFull); Assert.assertEquals(transaction.get().getRet(0).getRet(), code.SUCESS); - Optional orderList = PublicMethod - .getMarketOrderByAccount(testAddress001, blockingStubFull); + Optional orderList = + PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull); Assert.assertTrue(orderList.get().getOrdersCount() > 0); - byte[] orderId = orderList.get().getOrders(0).getOrderId().toByteArray(); - String txid2 = PublicMethod.marketSellAsset(testAddress002, testKey002, assetAccountId002, - buyTokenQuantity, assetAccountId001, sellTokenQuantity, blockingStubFull); + byte[] orderId = orderList.get().getOrders(0).getOrderId().toByteArray(); + String txid2 = + PublicMethod.marketSellAsset( + testAddress002, + testKey002, + assetAccountId002, + buyTokenQuantity, + assetAccountId001, + sellTokenQuantity, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid2); - transaction = PublicMethod - .getTransactionById(txid2, blockingStubFull); + transaction = PublicMethod.getTransactionById(txid2, blockingStubFull); Assert.assertEquals(transaction.get().getRet(0).getRet(), code.SUCESS); - Map afterAsset001 = PublicMethod.queryAccount(testAddress001, blockingStubFull) - .getAssetV2Map(); - Map afterAsset002 = PublicMethod.queryAccount(testAddress002, blockingStubFull) - .getAssetV2Map(); + Map afterAsset001 = + PublicMethod.queryAccount(testAddress001, blockingStubFull).getAssetV2Map(); + Map afterAsset002 = + PublicMethod.queryAccount(testAddress002, blockingStubFull).getAssetV2Map(); logger.info("afterAsset001: " + afterAsset001); logger.info("afterAsset002: " + afterAsset002); - String assetId001 = ByteArray.toStr(assetAccountId001); - String assetId002 = ByteArray.toStr(assetAccountId002); - Assert.assertEquals((beforeAsset001.get(assetId001) - sellTokenQuantity), + String assetId001 = ByteArray.toStr(assetAccountId001); + String assetId002 = ByteArray.toStr(assetAccountId002); + Assert.assertEquals( + (beforeAsset001.get(assetId001) - sellTokenQuantity), afterAsset001.get(assetId001).longValue()); Assert.assertEquals((buyTokenQuantity), afterAsset001.get(assetId002).longValue()); - Assert.assertEquals(beforeAsset002.get(assetId002) - buyTokenQuantity, + Assert.assertEquals( + beforeAsset002.get(assetId002) - buyTokenQuantity, afterAsset002.get(assetId002).longValue()); Assert.assertEquals(sellTokenQuantity, afterAsset002.get(assetId001).longValue()); - - } - @Test(enabled = false, description = "create sellOrder and Match Order twice", groups = {"daily"}) + @Test( + enabled = false, + description = "create sellOrder and Match Order twice", + groups = {"daily"}) void marketSellAssetTest002() { - Map beforeAsset001 = PublicMethod.queryAccount(testAddress001, blockingStubFull) - .getAssetV2Map(); - Map beforeAsset002 = PublicMethod.queryAccount(testAddress002, blockingStubFull) - .getAssetV2Map(); + Map beforeAsset001 = + PublicMethod.queryAccount(testAddress001, blockingStubFull).getAssetV2Map(); + Map beforeAsset002 = + PublicMethod.queryAccount(testAddress002, blockingStubFull).getAssetV2Map(); logger.info("beforeAsset001: " + beforeAsset001); logger.info("beforeAsset002: " + beforeAsset002); - String txid = PublicMethod.marketSellAsset(testAddress001, testKey001, assetAccountId001, - sellTokenQuantity * 2, - assetAccountId002, buyTokenQuantity * 2, blockingStubFull); + String txid = + PublicMethod.marketSellAsset( + testAddress001, + testKey001, + assetAccountId001, + sellTokenQuantity * 2, + assetAccountId002, + buyTokenQuantity * 2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - logger.info("beforeAsset001 :" - + PublicMethod.queryAccount(testAddress001, blockingStubFull).getAssetV2Map()); - logger.info("beforeAsset002 :" - + PublicMethod.queryAccount(testAddress002, blockingStubFull).getAssetV2Map()); + logger.info( + "beforeAsset001 :" + + PublicMethod.queryAccount(testAddress001, blockingStubFull).getAssetV2Map()); + logger.info( + "beforeAsset002 :" + + PublicMethod.queryAccount(testAddress002, blockingStubFull).getAssetV2Map()); - Optional transaction = PublicMethod - .getTransactionById(txid, blockingStubFull); + Optional transaction = PublicMethod.getTransactionById(txid, blockingStubFull); Assert.assertEquals(transaction.get().getRet(0).getRet(), code.SUCESS); - Optional orderList = PublicMethod - .getMarketOrderByAccount(testAddress001, blockingStubFull); + Optional orderList = + PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull); Assert.assertTrue(orderList.get().getOrdersCount() > 0); - byte[] orderId; + byte[] orderId; orderId = orderList.get().getOrders(0).getOrderId().toByteArray(); - String txid2 = PublicMethod.marketSellAsset(testAddress002, testKey002, assetAccountId002, - buyTokenQuantity, assetAccountId001, sellTokenQuantity, blockingStubFull); + String txid2 = + PublicMethod.marketSellAsset( + testAddress002, + testKey002, + assetAccountId002, + buyTokenQuantity, + assetAccountId001, + sellTokenQuantity, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid2); - transaction = PublicMethod - .getTransactionById(txid2, blockingStubFull); + transaction = PublicMethod.getTransactionById(txid2, blockingStubFull); Assert.assertEquals(transaction.get().getRet(0).getRet(), code.SUCESS); - // get order Message and RemainSellTokenQuantity - MarketOrder order001 = PublicMethod - .getMarketOrderById(orderId, blockingStubFull).get(); + // get order Message and RemainSellTokenQuantity + MarketOrder order001 = PublicMethod.getMarketOrderById(orderId, blockingStubFull).get(); Assert.assertEquals(order001.getSellTokenQuantityRemain(), sellTokenQuantity); - Map afterAsset001 = PublicMethod.queryAccount(testAddress001, blockingStubFull) - .getAssetV2Map(); - Map afterAsset002 = PublicMethod.queryAccount(testAddress002, blockingStubFull) - .getAssetV2Map(); + Map afterAsset001 = + PublicMethod.queryAccount(testAddress001, blockingStubFull).getAssetV2Map(); + Map afterAsset002 = + PublicMethod.queryAccount(testAddress002, blockingStubFull).getAssetV2Map(); logger.info("afterAsset001: " + afterAsset001); logger.info("afterAsset002: " + afterAsset002); - String assetId001 = ByteArray.toStr(assetAccountId001); - String assetId002 = ByteArray.toStr(assetAccountId002); - Assert.assertEquals((beforeAsset001.get(assetId001) - sellTokenQuantity * 2), + String assetId001 = ByteArray.toStr(assetAccountId001); + String assetId002 = ByteArray.toStr(assetAccountId002); + Assert.assertEquals( + (beforeAsset001.get(assetId001) - sellTokenQuantity * 2), afterAsset001.get(assetId001).longValue()); - Assert.assertEquals((beforeAsset001.get(assetId002) + buyTokenQuantity), + Assert.assertEquals( + (beforeAsset001.get(assetId002) + buyTokenQuantity), afterAsset001.get(assetId002).longValue()); - Assert.assertEquals(beforeAsset002.get(assetId002) - buyTokenQuantity, + Assert.assertEquals( + beforeAsset002.get(assetId002) - buyTokenQuantity, afterAsset002.get(assetId002).longValue()); - Assert.assertEquals(beforeAsset002.get(assetId001) + sellTokenQuantity, + Assert.assertEquals( + beforeAsset002.get(assetId001) + sellTokenQuantity, afterAsset002.get(assetId001).longValue()); - String txid3 = PublicMethod.marketSellAsset(testAddress002, testKey002, assetAccountId002, - buyTokenQuantity, assetAccountId001, sellTokenQuantity, blockingStubFull); + String txid3 = + PublicMethod.marketSellAsset( + testAddress002, + testKey002, + assetAccountId002, + buyTokenQuantity, + assetAccountId001, + sellTokenQuantity, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid3); - transaction = PublicMethod - .getTransactionById(txid3, blockingStubFull); + transaction = PublicMethod.getTransactionById(txid3, blockingStubFull); Assert.assertEquals(transaction.get().getRet(0).getRet(), code.SUCESS); - // get order Message and RemainSellTokenQuantity - order001 = PublicMethod - .getMarketOrderById(orderId, blockingStubFull).get(); + // get order Message and RemainSellTokenQuantity + order001 = PublicMethod.getMarketOrderById(orderId, blockingStubFull).get(); Assert.assertEquals(order001.getSellTokenQuantityRemain(), 0); - afterAsset001 = PublicMethod.queryAccount(testAddress001, blockingStubFull) - .getAssetV2Map(); - afterAsset002 = PublicMethod.queryAccount(testAddress002, blockingStubFull) - .getAssetV2Map(); + afterAsset001 = PublicMethod.queryAccount(testAddress001, blockingStubFull).getAssetV2Map(); + afterAsset002 = PublicMethod.queryAccount(testAddress002, blockingStubFull).getAssetV2Map(); logger.info("afterAsset001: " + afterAsset001); logger.info("afterAsset002: " + afterAsset002); - Assert.assertEquals((beforeAsset001.get(assetId001) - sellTokenQuantity * 2), + Assert.assertEquals( + (beforeAsset001.get(assetId001) - sellTokenQuantity * 2), afterAsset001.get(assetId001).longValue()); - Assert.assertEquals((beforeAsset001.get(assetId002) + buyTokenQuantity * 2), + Assert.assertEquals( + (beforeAsset001.get(assetId002) + buyTokenQuantity * 2), afterAsset001.get(assetId002).longValue()); - Assert.assertEquals(beforeAsset002.get(assetId002) - buyTokenQuantity * 2, + Assert.assertEquals( + beforeAsset002.get(assetId002) - buyTokenQuantity * 2, afterAsset002.get(assetId002).longValue()); - Assert.assertEquals(beforeAsset002.get(assetId001) + sellTokenQuantity * 2, + Assert.assertEquals( + beforeAsset002.get(assetId001) + sellTokenQuantity * 2, afterAsset002.get(assetId001).longValue()); - - } - @Test(enabled = false, description = "create sellOrder and not Match Order", groups = {"daily"}) + @Test( + enabled = false, + description = "create sellOrder and not Match Order", + groups = {"daily"}) void marketSellAssetTest003() { - Map beforeAsset001 = PublicMethod - .queryAccount(testAddress001, blockingStubFull).getAssetV2Map(); - Map beforeAsset002 = PublicMethod - .queryAccount(testAddress002, blockingStubFull).getAssetV2Map(); + Map beforeAsset001 = + PublicMethod.queryAccount(testAddress001, blockingStubFull).getAssetV2Map(); + Map beforeAsset002 = + PublicMethod.queryAccount(testAddress002, blockingStubFull).getAssetV2Map(); logger.info("beforeAsset001: " + beforeAsset001); logger.info("beforeAsset002: " + beforeAsset002); - String txid = PublicMethod - .marketSellAsset(testAddress001, testKey001, assetAccountId001, sellTokenQuantity, - assetAccountId002, buyTokenQuantity, blockingStubFull); + String txid = + PublicMethod.marketSellAsset( + testAddress001, + testKey001, + assetAccountId001, + sellTokenQuantity, + assetAccountId002, + buyTokenQuantity, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - Optional transaction = PublicMethod - .getTransactionById(txid, blockingStubFull); + Optional transaction = PublicMethod.getTransactionById(txid, blockingStubFull); Assert.assertEquals(transaction.get().getRet(0).getRet(), code.SUCESS); - Optional orderList = PublicMethod - .getMarketOrderByAccount(testAddress001, blockingStubFull); + Optional orderList = + PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull); Assert.assertTrue(orderList.get().getOrdersCount() > 0); - byte[] orderId = orderList.get().getOrders(0).getOrderId().toByteArray(); - String txid2 = PublicMethod.marketSellAsset(testAddress002, testKey002, assetAccountId002, - buyTokenQuantity * 2, assetAccountId001, sellTokenQuantity * 5, blockingStubFull); + byte[] orderId = orderList.get().getOrders(0).getOrderId().toByteArray(); + String txid2 = + PublicMethod.marketSellAsset( + testAddress002, + testKey002, + assetAccountId002, + buyTokenQuantity * 2, + assetAccountId001, + sellTokenQuantity * 5, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid2); - transaction = PublicMethod - .getTransactionById(txid2, blockingStubFull); + transaction = PublicMethod.getTransactionById(txid2, blockingStubFull); Assert.assertEquals(transaction.get().getRet(0).getRet(), code.SUCESS); - Map afterAsset001 = PublicMethod.queryAccount(testAddress001, blockingStubFull) - .getAssetV2Map(); - Map afterAsset002 = PublicMethod.queryAccount(testAddress002, blockingStubFull) - .getAssetV2Map(); + Map afterAsset001 = + PublicMethod.queryAccount(testAddress001, blockingStubFull).getAssetV2Map(); + Map afterAsset002 = + PublicMethod.queryAccount(testAddress002, blockingStubFull).getAssetV2Map(); logger.info("afterAsset001: " + afterAsset001); logger.info("afterAsset002: " + afterAsset002); - String assetId001 = ByteArray.toStr(assetAccountId001); - String assetId002 = ByteArray.toStr(assetAccountId002); - Assert.assertEquals((beforeAsset001.get(assetId001) - sellTokenQuantity), + String assetId001 = ByteArray.toStr(assetAccountId001); + String assetId002 = ByteArray.toStr(assetAccountId002); + Assert.assertEquals( + (beforeAsset001.get(assetId001) - sellTokenQuantity), afterAsset001.get(assetId001).longValue()); - Assert.assertEquals((beforeAsset001.get(assetId002).longValue()), - afterAsset001.get(assetId002).longValue()); + Assert.assertEquals( + (beforeAsset001.get(assetId002).longValue()), afterAsset001.get(assetId002).longValue()); - Assert.assertEquals(beforeAsset002.get(assetId002) - buyTokenQuantity * 2, + Assert.assertEquals( + beforeAsset002.get(assetId002) - buyTokenQuantity * 2, afterAsset002.get(assetId002).longValue()); - Assert.assertEquals(beforeAsset002.get(assetId001).longValue(), - afterAsset002.get(assetId001).longValue()); + Assert.assertEquals( + beforeAsset002.get(assetId001).longValue(), afterAsset002.get(assetId001).longValue()); } - @Test(enabled = false, description = "CancelOrder", groups = {"daily"}) + @Test( + enabled = false, + description = "CancelOrder", + groups = {"daily"}) void marketSellAssetTest004() { - Map beforeAsset001 = PublicMethod - .queryAccount(testAddress001, blockingStubFull).getAssetV2Map(); + Map beforeAsset001 = + PublicMethod.queryAccount(testAddress001, blockingStubFull).getAssetV2Map(); logger.info("beforeAsset001: " + beforeAsset001); - Optional orderList = PublicMethod - .getMarketOrderByAccount(testAddress001, blockingStubFull); + Optional orderList = + PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull); Assert.assertTrue(orderList.get().getOrdersCount() > 0); - Long sellTokenQuantity001; - byte[] tokenId; - byte[] orderId001; + Long sellTokenQuantity001; + byte[] tokenId; + byte[] orderId001; orderId001 = orderList.get().getOrders(0).getOrderId().toByteArray(); tokenId = orderList.get().getOrders(0).getSellTokenId().toByteArray(); sellTokenQuantity001 = orderList.get().getOrders(0).getSellTokenQuantityRemain(); - String txid = PublicMethod.marketCancelOrder(testAddress001, testKey001, orderId001, - blockingStubFull); + String txid = + PublicMethod.marketCancelOrder(testAddress001, testKey001, orderId001, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - Optional transaction = PublicMethod - .getTransactionById(txid, blockingStubFull); + Optional transaction = PublicMethod.getTransactionById(txid, blockingStubFull); Assert.assertEquals(transaction.get().getRet(0).getRet(), code.SUCESS); - Map afterAsset001 = PublicMethod.queryAccount(testAddress001, blockingStubFull) - .getAssetV2Map(); + Map afterAsset001 = + PublicMethod.queryAccount(testAddress001, blockingStubFull).getAssetV2Map(); logger.info("afterAsset001: " + afterAsset001); - String assetId001 = ByteArray.toStr(tokenId); + String assetId001 = ByteArray.toStr(tokenId); - Assert.assertEquals(beforeAsset001.get(assetId001) + sellTokenQuantity001, + Assert.assertEquals( + beforeAsset001.get(assetId001) + sellTokenQuantity001, afterAsset001.get(assetId001).longValue()); - Return response = PublicMethod - .marketCancelOrderGetResposne(testAddress001, testKey001, orderId001, - blockingStubFull); + Return response = + PublicMethod.marketCancelOrderGetResposne( + testAddress001, testKey001, orderId001, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(response); Assert.assertEquals(response.getCode(), response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ByteArray.toStr(response.getMessage().toByteArray()).toLowerCase(), + Assert.assertEquals( + ByteArray.toStr(response.getMessage().toByteArray()).toLowerCase(), "contract validate error : Order is not active!".toLowerCase()); - - } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset003.java index e956e4bd..4105452f 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset003.java @@ -11,25 +11,23 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j - public class MarketSellAsset003 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final String name = "testAssetIssue003_" + Long.toString(now); private static final String shortname = "a"; - private final String foundationKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String foundationKey002 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] foundationAddress002 = PublicMethod.getFinalAddress(foundationKey002); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); - byte [] trx = ByteArray.fromString("_"); + byte[] trx = ByteArray.fromString("_"); ECKey ecKey001 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey001.getAddress(); String testKey001 = ByteArray.toHexString(ecKey001.getPrivKeyBytes()); @@ -37,96 +35,133 @@ public class MarketSellAsset003 extends TronBaseTest { ECKey ecKey002 = new ECKey(Utils.getRandom()); byte[] testAddress002 = ecKey002.getAddress(); String testKey002 = ByteArray.toHexString(ecKey002.getPrivKeyBytes()); - byte[] assetAccountId002; @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(testKey001); + byte[] assetAccountId002; + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethod.printAddress(testKey001); PublicMethod.printAddress(testKey002); - Assert.assertTrue(PublicMethod.sendcoin(testAddress001, 20000_000000L, foundationAddress, - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(testAddress002, 20000_000000L, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress001, 20000_000000L, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress002, 20000_000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long start = System.currentTimeMillis() + 5000; - Long end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod.createAssetIssue(testAddress001, name, 10000_000000L, - 1, 1, start, end, 1, description, url, 10000L, - 10000L, 1L, 1L, testKey001, blockingStubFull)); + Long start = System.currentTimeMillis() + 5000; + Long end = System.currentTimeMillis() + 1000000000; + Assert.assertTrue( + PublicMethod.createAssetIssue( + testAddress001, + name, + 10000_000000L, + 1, + 1, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + testKey001, + blockingStubFull)); start = System.currentTimeMillis() + 5000; end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod.createAssetIssue(testAddress002, name, 10000_000000L, - 1, 1, start, end, 1, description, url, 10000L, - 10000L, 1L, 1L, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createAssetIssue( + testAddress002, + name, + 10000_000000L, + 1, + 1, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - assetAccountId001 = PublicMethod.queryAccount(testAddress001, blockingStubFull) - .getAssetIssuedID().toByteArray(); + assetAccountId001 = + PublicMethod.queryAccount(testAddress001, blockingStubFull) + .getAssetIssuedID() + .toByteArray(); - assetAccountId002 = PublicMethod.queryAccount(testAddress002, blockingStubFull) - .getAssetIssuedID().toByteArray(); + assetAccountId002 = + PublicMethod.queryAccount(testAddress002, blockingStubFull) + .getAssetIssuedID() + .toByteArray(); } - - @Test(enabled = false, description = "CancelOrder", groups = {"daily"}) + @Test( + enabled = false, + description = "CancelOrder", + groups = {"daily"}) void marketCancelAssetTest001() { - String txid = PublicMethod.marketSellAsset(testAddress001, testKey001, assetAccountId001, 100, - trx, 50, blockingStubFull); + String txid = + PublicMethod.marketSellAsset( + testAddress001, testKey001, assetAccountId001, 100, trx, 50, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transaction = PublicMethod - .getTransactionById(txid, blockingStubFull); + Optional transaction = PublicMethod.getTransactionById(txid, blockingStubFull); logger.info("transaction: " + transaction); Assert.assertEquals(transaction.get().getRet(0).getRet().toString(), "SUCESS"); - Optional orderList = PublicMethod - .getMarketOrderByAccount(testAddress001, blockingStubFull); + Optional orderList = + PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(orderList.get().getOrdersCount() > 0); - byte[] orderId = orderList.get().getOrders(0).getOrderId().toByteArray(); + byte[] orderId = orderList.get().getOrders(0).getOrderId().toByteArray(); txid = PublicMethod.marketCancelOrder(testAddress001, testKey001, orderId, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - transaction = PublicMethod - .getTransactionById(txid, blockingStubFull); + transaction = PublicMethod.getTransactionById(txid, blockingStubFull); Assert.assertEquals(transaction.get().getRet(0).getRet().toString(), "SUCESS"); - orderList = PublicMethod - .getMarketOrderByAccount(testAddress001, blockingStubFull); + orderList = PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull); Assert.assertTrue(orderList.get().getOrdersCount() == 0); - } - @Test(enabled = false, description = "Cancel a cancelled order ", groups = {"daily"}) + @Test( + enabled = false, + description = "Cancel a cancelled order ", + groups = {"daily"}) void marketCancelAssetTest002() { - String txid = PublicMethod.marketSellAsset(testAddress001, testKey001, assetAccountId001, 100, - trx, 50, blockingStubFull); + String txid = + PublicMethod.marketSellAsset( + testAddress001, testKey001, assetAccountId001, 100, trx, 50, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transaction = PublicMethod - .getTransactionById(txid, blockingStubFull); + Optional transaction = PublicMethod.getTransactionById(txid, blockingStubFull); logger.info("transaction: " + transaction); Assert.assertEquals(transaction.get().getRet(0).getRet().toString(), "SUCESS"); - Optional orderList = PublicMethod - .getMarketOrderByAccount(testAddress001, blockingStubFull); + Optional orderList = + PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(orderList.get().getOrdersCount() > 0); - byte[] orderId = orderList.get().getOrders(0).getOrderId().toByteArray(); + byte[] orderId = orderList.get().getOrders(0).getOrderId().toByteArray(); txid = PublicMethod.marketCancelOrder(testAddress001, testKey001, orderId, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - transaction = PublicMethod - .getTransactionById(txid, blockingStubFull); + transaction = PublicMethod.getTransactionById(txid, blockingStubFull); Assert.assertEquals(transaction.get().getRet(0).getRet().toString(), "SUCESS"); - orderList = PublicMethod - .getMarketOrderByAccount(testAddress001, blockingStubFull); + orderList = PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull); Assert.assertTrue(orderList.get().getOrdersCount() == 0); - Assert.assertEquals(PublicMethod.marketCancelOrder(testAddress001, testKey001, orderId, - blockingStubFull).toLowerCase(), + Assert.assertEquals( + PublicMethod.marketCancelOrder(testAddress001, testKey001, orderId, blockingStubFull) + .toLowerCase(), "contract validate error : Order is not active!".toLowerCase()); - - } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset004.java index 85ec28db..6fe67e86 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset004.java @@ -11,24 +11,22 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j - public class MarketSellAsset004 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final String name = "testAssetIssue003_" + Long.toString(now); private static final String shortname = "a"; - private final String foundationKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String foundationKey002 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] foundationAddress002 = PublicMethod.getFinalAddress(foundationKey002); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); - byte [] trx = ByteArray.fromString("_"); + byte[] trx = ByteArray.fromString("_"); ECKey ecKey001 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey001.getAddress(); String testKey001 = ByteArray.toHexString(ecKey001.getPrivKeyBytes()); @@ -36,54 +34,94 @@ public class MarketSellAsset004 extends TronBaseTest { ECKey ecKey002 = new ECKey(Utils.getRandom()); byte[] testAddress002 = ecKey002.getAddress(); String testKey002 = ByteArray.toHexString(ecKey002.getPrivKeyBytes()); - byte[] assetAccountId002; @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(testKey001); + byte[] assetAccountId002; + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethod.printAddress(testKey001); PublicMethod.printAddress(testKey002); - Assert.assertTrue(PublicMethod.sendcoin(testAddress001,20000_000000L,foundationAddress, - foundationKey,blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(testAddress002,20000_000000L,foundationAddress, - foundationKey,blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress001, 20000_000000L, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress002, 20000_000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long start = System.currentTimeMillis() + 5000; - Long end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod.createAssetIssue(testAddress001,name,10000_000000L,1,1,start, - end,1,description,url,10000L,10000L,1L, 1L,testKey001,blockingStubFull)); + Long start = System.currentTimeMillis() + 5000; + Long end = System.currentTimeMillis() + 1000000000; + Assert.assertTrue( + PublicMethod.createAssetIssue( + testAddress001, + name, + 10000_000000L, + 1, + 1, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + testKey001, + blockingStubFull)); start = System.currentTimeMillis() + 5000; end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod.createAssetIssue(testAddress002,name,10000_000000L,1,1,start, - end,1,description,url,10000L,10000L,1L, 1L,testKey002,blockingStubFull)); + Assert.assertTrue( + PublicMethod.createAssetIssue( + testAddress002, + name, + 10000_000000L, + 1, + 1, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - assetAccountId001 = PublicMethod.queryAccount(testAddress001, blockingStubFull) - .getAssetIssuedID().toByteArray(); + assetAccountId001 = + PublicMethod.queryAccount(testAddress001, blockingStubFull) + .getAssetIssuedID() + .toByteArray(); - assetAccountId002 = PublicMethod.queryAccount(testAddress002, blockingStubFull) - .getAssetIssuedID().toByteArray(); + assetAccountId002 = + PublicMethod.queryAccount(testAddress002, blockingStubFull) + .getAssetIssuedID() + .toByteArray(); } - - @Test(enabled = false,description = "The order amount exceeds the balance", groups = {"daily"}) + @Test( + enabled = false, + description = "The order amount exceeds the balance", + groups = {"daily"}) void marketCancelAssetTest002() { - String txid = PublicMethod.marketSellAsset(testAddress001,testKey001,assetAccountId001,100, - trx,50,blockingStubFull); + String txid = + PublicMethod.marketSellAsset( + testAddress001, testKey001, assetAccountId001, 100, trx, 50, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transaction = PublicMethod - .getTransactionById(txid, blockingStubFull); + Optional transaction = PublicMethod.getTransactionById(txid, blockingStubFull); logger.info("transaction: " + transaction); Assert.assertEquals(transaction.get().getRet(0).getRet().toString(), "SUCESS"); - Optional orderList = PublicMethod - .getMarketOrderByAccount(testAddress001, blockingStubFull); + Optional orderList = + PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(orderList.get().getOrdersCount() > 0); - byte[] orderId = orderList.get().getOrders(0).getOrderId().toByteArray(); - txid = PublicMethod.marketCancelOrder(testAddress001,testKey001,orderId,blockingStubFull); + byte[] orderId = orderList.get().getOrders(0).getOrderId().toByteArray(); + txid = PublicMethod.marketCancelOrder(testAddress001, testKey001, orderId, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - - } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset005.java index ac4ea0ad..7ac2caed 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset005.java @@ -12,26 +12,24 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j - public class MarketSellAsset005 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final String name = "testAssetIssue003_" + Long.toString(now); private static final String shortname = "a"; - private final String foundationKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String foundationKey002 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] foundationAddress002 = PublicMethod.getFinalAddress(foundationKey002); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); long sellTokenQuantity = 100; long buyTokenQuantity = 50; - byte [] trx = ByteArray.fromString("_"); + byte[] trx = ByteArray.fromString("_"); ECKey ecKey001 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey001.getAddress(); String testKey001 = ByteArray.toHexString(ecKey001.getPrivKeyBytes()); @@ -40,92 +38,135 @@ public class MarketSellAsset005 extends TronBaseTest { ECKey ecKey002 = new ECKey(Utils.getRandom()); byte[] testAddress002 = ecKey002.getAddress(); String testKey002 = ByteArray.toHexString(ecKey002.getPrivKeyBytes()); - byte[] assetAccountId002; @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(testKey001); + byte[] assetAccountId002; + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethod.printAddress(testKey001); PublicMethod.printAddress(testKey002); - Assert.assertTrue(PublicMethod.sendcoin(testAddress001,2024_000000L,foundationAddress, - foundationKey,blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(testAddress002,2024_000000L,foundationAddress, - foundationKey,blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress001, 2024_000000L, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress002, 2024_000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long start = System.currentTimeMillis() + 5000; - Long end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod.createAssetIssue(testAddress001,name,10000_000000L,1,1,start, - end,1,description,url,10000L,10000L,1L, 1L,testKey001,blockingStubFull)); + Long start = System.currentTimeMillis() + 5000; + Long end = System.currentTimeMillis() + 1000000000; + Assert.assertTrue( + PublicMethod.createAssetIssue( + testAddress001, + name, + 10000_000000L, + 1, + 1, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + testKey001, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - assetAccountId001 = PublicMethod.queryAccount(testAddress001, blockingStubFull) - .getAssetIssuedID().toByteArray(); + assetAccountId001 = + PublicMethod.queryAccount(testAddress001, blockingStubFull) + .getAssetIssuedID() + .toByteArray(); assetAccountId = PublicMethod.queryAccount(testAddress001, blockingStubFull).getAssetIssuedID(); - - } - - @Test(enabled = false,description = "Create an order to sell Trx and buy Trc10", groups = {"daily"}) + @Test( + enabled = false, + description = "Create an order to sell Trx and buy Trc10", + groups = {"daily"}) void test01SellTrxBuyTrc10() { long balanceAfter = PublicMethod.queryAccount(testKey001, blockingStubFull).getBalance(); - PublicMethod.transferAsset(testAddress002, assetAccountId001, 10000, testAddress001, - testKey001, blockingStubFull); + PublicMethod.transferAsset( + testAddress002, assetAccountId001, 10000, testAddress001, testKey001, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - final Map beforeAsset001 = PublicMethod.queryAccount(testAddress001, - blockingStubFull).getAssetV2Map(); - String txid = PublicMethod.marketSellAsset(testAddress002,testKey002,trx, - sellTokenQuantity,assetAccountId001, - buyTokenQuantity,blockingStubFull); + final Map beforeAsset001 = + PublicMethod.queryAccount(testAddress001, blockingStubFull).getAssetV2Map(); + String txid = + PublicMethod.marketSellAsset( + testAddress002, + testKey002, + trx, + sellTokenQuantity, + assetAccountId001, + buyTokenQuantity, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transaction = PublicMethod - .getTransactionById(txid, blockingStubFull); + Optional transaction = PublicMethod.getTransactionById(txid, blockingStubFull); logger.info("transaction: " + transaction); Assert.assertEquals(transaction.get().getRet(0).getRet().toString(), "SUCESS"); logger.info("beforeAsset001: " + beforeAsset001); - txid = PublicMethod.marketSellAsset(testAddress001, testKey001, assetAccountId001, + txid = + PublicMethod.marketSellAsset( + testAddress001, + testKey001, + assetAccountId001, sellTokenQuantity * 2, - trx, buyTokenQuantity * 2, blockingStubFull); + trx, + buyTokenQuantity * 2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - - Map afterAsset001 = PublicMethod.queryAccount(testAddress001, blockingStubFull) - .getAssetV2Map(); + Map afterAsset001 = + PublicMethod.queryAccount(testAddress001, blockingStubFull).getAssetV2Map(); logger.info("afterAsset001: " + afterAsset001); - String assetId001 = ByteArray.toStr(assetAccountId001); - Assert.assertEquals((beforeAsset001.get(assetId001) - sellTokenQuantity * 2), - afterAsset001.get(assetId001).longValue()); - + String assetId001 = ByteArray.toStr(assetAccountId001); + Assert.assertEquals( + (beforeAsset001.get(assetId001) - sellTokenQuantity * 2), + afterAsset001.get(assetId001).longValue()); } - @Test(enabled = false,description = "Create an order to sell Trc10 and buy Trx", groups = {"daily"}) + @Test( + enabled = false, + description = "Create an order to sell Trc10 and buy Trx", + groups = {"daily"}) void test02SellTrc10BuyTrx() { long balanceAfter = PublicMethod.queryAccount(testKey001, blockingStubFull).getBalance(); - final Map beforeAsset001 = PublicMethod.queryAccount(testAddress001, - blockingStubFull).getAssetV2Map(); - String txid = PublicMethod.marketSellAsset(testAddress002,testKey002,assetAccountId001, - sellTokenQuantity,trx, - buyTokenQuantity,blockingStubFull); + final Map beforeAsset001 = + PublicMethod.queryAccount(testAddress001, blockingStubFull).getAssetV2Map(); + String txid = + PublicMethod.marketSellAsset( + testAddress002, + testKey002, + assetAccountId001, + sellTokenQuantity, + trx, + buyTokenQuantity, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transaction = PublicMethod - .getTransactionById(txid, blockingStubFull); + Optional transaction = PublicMethod.getTransactionById(txid, blockingStubFull); logger.info("transaction: " + transaction); Assert.assertEquals(transaction.get().getRet(0).getRet().toString(), "SUCESS"); logger.info("beforeAsset001: " + beforeAsset001); - txid = PublicMethod.marketSellAsset(testAddress001, testKey001, trx, + txid = + PublicMethod.marketSellAsset( + testAddress001, + testKey001, + trx, sellTokenQuantity * 2, - assetAccountId001, buyTokenQuantity * 2, blockingStubFull); + assetAccountId001, + buyTokenQuantity * 2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - - } - - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset006.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset006.java index 803872f5..c8dc5034 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset006.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/assetmarket/MarketSellAsset006.java @@ -1,6 +1,5 @@ package stest.tron.wallet.dailybuild.assetmarket; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.Optional; import lombok.extern.slf4j.Slf4j; @@ -17,24 +16,21 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j - - public class MarketSellAsset006 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final String name = "testAssetIssue003_" + Long.toString(now); private static final String shortname = "a"; - private final String foundationKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String foundationKey002 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] foundationAddress002 = PublicMethod.getFinalAddress(foundationKey002); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ECKey ecKey001 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey001.getAddress(); String testKey001 = ByteArray.toHexString(ecKey001.getPrivKeyBytes()); @@ -47,76 +43,113 @@ public class MarketSellAsset006 extends TronBaseTest { long sellTokenQuantity = 100; long buyTokenQuantity = 50; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubRealSolidity = null; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - private String realSoliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1); - private String soliInPbft = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(2); - - /** - * constructor. - */ - + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + private String realSoliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); + private String soliInPbft = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(2); + + /** constructor. */ @BeforeClass - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - channelPbft = ManagedChannelBuilder.forTarget(soliInPbft) - .usePlaintext() - .build(); + channelPbft = ManagedChannelBuilder.forTarget(soliInPbft).usePlaintext().build(); blockingStubPbft = WalletSolidityGrpc.newBlockingStub(channelPbft); PublicMethod.printAddress(testKey001); PublicMethod.printAddress(testKey002); - Assert.assertTrue(PublicMethod.sendcoin(testAddress001, 20000_000000L, foundationAddress, - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(testAddress002, 20000_000000L, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress001, 20000_000000L, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress002, 20000_000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long start = System.currentTimeMillis() + 5000; - Long end = System.currentTimeMillis() + 1000000000; - Assert - .assertTrue(PublicMethod.createAssetIssue(testAddress001, name, 10000_000000L, 1, 1, start, - end, 1, description, url, 10000L, 10000L, 1L, 1L, testKey001, blockingStubFull)); + Long start = System.currentTimeMillis() + 5000; + Long end = System.currentTimeMillis() + 1000000000; + Assert.assertTrue( + PublicMethod.createAssetIssue( + testAddress001, + name, + 10000_000000L, + 1, + 1, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + testKey001, + blockingStubFull)); start = System.currentTimeMillis() + 5000; end = System.currentTimeMillis() + 1000000000; - Assert - .assertTrue(PublicMethod.createAssetIssue(testAddress002, name, 10000_000000L, 1, 1, start, - end, 1, description, url, 10000L, 10000L, 1L, 1L, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createAssetIssue( + testAddress002, + name, + 10000_000000L, + 1, + 1, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - assetAccountId001 = PublicMethod.queryAccount(testAddress001, blockingStubFull) - .getAssetIssuedID().toByteArray(); + assetAccountId001 = + PublicMethod.queryAccount(testAddress001, blockingStubFull) + .getAssetIssuedID() + .toByteArray(); - assetAccountId002 = PublicMethod.queryAccount(testAddress002, blockingStubFull) - .getAssetIssuedID().toByteArray(); + assetAccountId002 = + PublicMethod.queryAccount(testAddress002, blockingStubFull) + .getAssetIssuedID() + .toByteArray(); } - - @Test(enabled = false, description = "create sellOrder", groups = {"daily"}) + @Test( + enabled = false, + description = "create sellOrder", + groups = {"daily"}) void marketSellAssetTest001() { - String txid = PublicMethod.marketSellAsset(testAddress001, testKey001, assetAccountId001, - sellTokenQuantity, assetAccountId002, buyTokenQuantity, blockingStubFull); + String txid = + PublicMethod.marketSellAsset( + testAddress001, + testKey001, + assetAccountId001, + sellTokenQuantity, + assetAccountId002, + buyTokenQuantity, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - Optional transaction = PublicMethod - .getTransactionById(txid, blockingStubFull); + Optional transaction = PublicMethod.getTransactionById(txid, blockingStubFull); Assert.assertEquals(transaction.get().getRet(0).getRet(), code.SUCESS); - Optional orderList = PublicMethod - .getMarketOrderByAccount(testAddress001, blockingStubFull); + Optional orderList = + PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull); Assert.assertTrue(orderList.get().getOrdersCount() > 0); - byte[] orderId = orderList.get().getOrders(0).getOrderId().toByteArray(); + byte[] orderId = orderList.get().getOrders(0).getOrderId().toByteArray(); - MarketOrder order = PublicMethod - .getMarketOrderById(orderId, blockingStubFull).get(); + MarketOrder order = PublicMethod.getMarketOrderById(orderId, blockingStubFull).get(); Assert.assertEquals(order.getOrderId().toByteArray(), orderId); Assert.assertEquals(order.getOwnerAddress().toByteArray(), testAddress001); @@ -124,104 +157,111 @@ void marketSellAssetTest001() { Assert.assertEquals(order.getSellTokenQuantity(), sellTokenQuantity); Assert.assertEquals(order.getBuyTokenId().toByteArray(), assetAccountId002); Assert.assertEquals(order.getBuyTokenQuantity(), buyTokenQuantity); - } - @Test(enabled = false, description = "getMarketPairList from solidity and pbft", groups = {"daily"}) + @Test( + enabled = false, + description = "getMarketPairList from solidity and pbft", + groups = {"daily"}) void marketSellAssetTest002() { - Optional pairList = PublicMethod - .getMarketPairList(blockingStubFull); - - PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity); + Optional pairList = PublicMethod.getMarketPairList(blockingStubFull); - Optional pairList2 = PublicMethod - .getMarketPairListSolidity(blockingStubSolidity); + PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); + Optional pairList2 = + PublicMethod.getMarketPairListSolidity(blockingStubSolidity); - Optional pairList3 = PublicMethod - .getMarketPairListSolidity(blockingStubPbft); - - Assert.assertEquals(pairList,pairList2); - Assert.assertEquals(pairList,pairList3); - + Optional pairList3 = + PublicMethod.getMarketPairListSolidity(blockingStubPbft); + Assert.assertEquals(pairList, pairList2); + Assert.assertEquals(pairList, pairList3); } - @Test(enabled = false, description = "getMarketOrderListByPair from solidity and pbft", groups = {"daily"}) + @Test( + enabled = false, + description = "getMarketOrderListByPair from solidity and pbft", + groups = {"daily"}) void marketSellAssetTest003() { - Optional orderList = PublicMethod - .getMarketOrderListByPair(assetAccountId001,assetAccountId002,blockingStubFull); - - PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity); + Optional orderList = + PublicMethod.getMarketOrderListByPair( + assetAccountId001, assetAccountId002, blockingStubFull); - Optional orderList2 = PublicMethod - .getMarketOrderListByPairSolidity(assetAccountId001,assetAccountId002,blockingStubSolidity); + PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); + Optional orderList2 = + PublicMethod.getMarketOrderListByPairSolidity( + assetAccountId001, assetAccountId002, blockingStubSolidity); - Optional orderList3 = PublicMethod - .getMarketOrderListByPairSolidity(assetAccountId001,assetAccountId002,blockingStubPbft); + Optional orderList3 = + PublicMethod.getMarketOrderListByPairSolidity( + assetAccountId001, assetAccountId002, blockingStubPbft); System.out.println(orderList3); - Assert.assertEquals(orderList,orderList2); - Assert.assertEquals(orderList,orderList3); - + Assert.assertEquals(orderList, orderList2); + Assert.assertEquals(orderList, orderList3); } - - @Test(enabled = false, description = "GetMarketOrderById from solidity and pbft", groups = {"daily"}) + @Test( + enabled = false, + description = "GetMarketOrderById from solidity and pbft", + groups = {"daily"}) void marketSellAssetTest004() { - Optional orderList = PublicMethod - .getMarketOrderListByPair(assetAccountId001,assetAccountId002,blockingStubFull); - - PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity); + Optional orderList = + PublicMethod.getMarketOrderListByPair( + assetAccountId001, assetAccountId002, blockingStubFull); - Optional orderList2 = PublicMethod - .getMarketOrderListByPairSolidity(assetAccountId001,assetAccountId002,blockingStubSolidity); + PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); + Optional orderList2 = + PublicMethod.getMarketOrderListByPairSolidity( + assetAccountId001, assetAccountId002, blockingStubSolidity); - Optional orderList3 = PublicMethod - .getMarketOrderListByPairSolidity(assetAccountId001,assetAccountId002,blockingStubPbft); + Optional orderList3 = + PublicMethod.getMarketOrderListByPairSolidity( + assetAccountId001, assetAccountId002, blockingStubPbft); System.out.println(orderList3); - Assert.assertEquals(orderList,orderList2); - Assert.assertEquals(orderList,orderList3); - + Assert.assertEquals(orderList, orderList2); + Assert.assertEquals(orderList, orderList3); } - - @Test(enabled = false, description = "GetMarketOrderByAccount from solidity and pbft", groups = {"daily"}) + @Test( + enabled = false, + description = "GetMarketOrderByAccount from solidity and pbft", + groups = {"daily"}) void marketSellAssetTest005() { - Optional orderList = PublicMethod - .getMarketOrderByAccount(testAddress001, blockingStubFull); + Optional orderList = + PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull); Assert.assertTrue(orderList.get().getOrdersCount() > 0); - PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity); + PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); - Optional orderList2 = PublicMethod - .getMarketOrderByAccountSolidity(testAddress001, blockingStubSolidity); + Optional orderList2 = + PublicMethod.getMarketOrderByAccountSolidity(testAddress001, blockingStubSolidity); Assert.assertTrue(orderList2.get().getOrdersCount() > 0); - - Optional orderList3 = PublicMethod - .getMarketOrderByAccountSolidity(testAddress001, blockingStubPbft); + Optional orderList3 = + PublicMethod.getMarketOrderByAccountSolidity(testAddress001, blockingStubPbft); Assert.assertTrue(orderList3.get().getOrdersCount() > 0); - Assert.assertEquals(orderList,orderList2); - Assert.assertEquals(orderList,orderList3); - + Assert.assertEquals(orderList, orderList2); + Assert.assertEquals(orderList, orderList3); } - @Test(enabled = false, description = "GetMarketOrderById from solidity and pbft", groups = {"daily"}) + @Test( + enabled = false, + description = "GetMarketOrderById from solidity and pbft", + groups = {"daily"}) void marketSellAssetTest006() { - Optional orderList = PublicMethod - .getMarketOrderByAccount(testAddress001, blockingStubFull); - byte[] orderId = orderList.get().getOrders(0).getOrderId().toByteArray(); + Optional orderList = + PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull); + byte[] orderId = orderList.get().getOrders(0).getOrderId().toByteArray(); - MarketOrder order = PublicMethod - .getMarketOrderById(orderId, blockingStubFull).get(); + MarketOrder order = PublicMethod.getMarketOrderById(orderId, blockingStubFull).get(); Assert.assertEquals(order.getOrderId().toByteArray(), orderId); Assert.assertEquals(order.getOwnerAddress().toByteArray(), testAddress001); @@ -230,8 +270,8 @@ void marketSellAssetTest006() { Assert.assertEquals(order.getBuyTokenId().toByteArray(), assetAccountId002); Assert.assertEquals(order.getBuyTokenQuantity(), buyTokenQuantity); - MarketOrder order2 = PublicMethod - .getMarketOrderByIdSolidity(orderId, blockingStubSolidity).get(); + MarketOrder order2 = + PublicMethod.getMarketOrderByIdSolidity(orderId, blockingStubSolidity).get(); Assert.assertEquals(order2.getOrderId().toByteArray(), orderId); Assert.assertEquals(order2.getOwnerAddress().toByteArray(), testAddress001); @@ -240,8 +280,7 @@ void marketSellAssetTest006() { Assert.assertEquals(order2.getBuyTokenId().toByteArray(), assetAccountId002); Assert.assertEquals(order2.getBuyTokenQuantity(), buyTokenQuantity); - MarketOrder order3 = PublicMethod - .getMarketOrderByIdSolidity(orderId, blockingStubPbft).get(); + MarketOrder order3 = PublicMethod.getMarketOrderByIdSolidity(orderId, blockingStubPbft).get(); Assert.assertEquals(order3.getOrderId().toByteArray(), orderId); Assert.assertEquals(order3.getOwnerAddress().toByteArray(), testAddress001); @@ -249,9 +288,5 @@ void marketSellAssetTest006() { Assert.assertEquals(order3.getSellTokenQuantity(), sellTokenQuantity); Assert.assertEquals(order3.getBuyTokenId().toByteArray(), assetAccountId002); Assert.assertEquals(order3.getBuyTokenQuantity(), buyTokenQuantity); - - } - - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/consensus/BlockProductionTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/consensus/BlockProductionTest.java index abc749da..143e2b9f 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/consensus/BlockProductionTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/consensus/BlockProductionTest.java @@ -18,8 +18,8 @@ /** * Block production tests. * - *

Validates that blocks are produced at the expected interval (~3s), - * by valid witnesses, and that block numbers increment monotonically. + *

Validates that blocks are produced at the expected interval (~3s), by valid witnesses, and + * that block numbers increment monotonically. */ @Slf4j public class BlockProductionTest extends TronBaseTest { @@ -41,68 +41,87 @@ public void beforeClass() { logger.info("Loaded {} valid witness addresses", validWitnessAddresses.size()); } - @Test(enabled = true, description = "Blocks should have incrementing block numbers", + @Test( + enabled = true, + description = "Blocks should have incrementing block numbers", groups = {"daily"}) public void test01BlockNumbersIncrement() { - Block block1 = blockingStubFull.getNowBlock(org.tron.api.GrpcAPI.EmptyMessage.newBuilder().build()); + Block block1 = + blockingStubFull.getNowBlock(org.tron.api.GrpcAPI.EmptyMessage.newBuilder().build()); long num1 = block1.getBlockHeader().getRawData().getNumber(); Assert.assertTrue(num1 > 0, "Current block number should be positive"); PublicMethod.waitProduceNextBlock(blockingStubFull); - Block block2 = blockingStubFull.getNowBlock(org.tron.api.GrpcAPI.EmptyMessage.newBuilder().build()); + Block block2 = + blockingStubFull.getNowBlock(org.tron.api.GrpcAPI.EmptyMessage.newBuilder().build()); long num2 = block2.getBlockHeader().getRawData().getNumber(); Assert.assertTrue(num2 > num1, "Block number should increase after waiting"); logger.info("Block numbers: {} -> {}", num1, num2); } - @Test(enabled = true, description = "Block producer should be a valid witness", + @Test( + enabled = true, + description = "Block producer should be a valid witness", groups = {"daily"}) public void test02BlockProducerIsValidWitness() { - Block block = blockingStubFull.getNowBlock(org.tron.api.GrpcAPI.EmptyMessage.newBuilder().build()); + Block block = + blockingStubFull.getNowBlock(org.tron.api.GrpcAPI.EmptyMessage.newBuilder().build()); BlockHeader.raw rawData = block.getBlockHeader().getRawData(); String producerAddr = ByteArray.toHexString(rawData.getWitnessAddress().toByteArray()); logger.info("Block {} produced by {}", rawData.getNumber(), producerAddr); - Assert.assertTrue(validWitnessAddresses.contains(producerAddr), + Assert.assertTrue( + validWitnessAddresses.contains(producerAddr), "Block producer should be a registered witness"); } - @Test(enabled = true, description = "Block timestamps should be ~3 seconds apart", + @Test( + enabled = true, + description = "Block timestamps should be ~3 seconds apart", groups = {"daily"}) public void test03BlockTimestampInterval() { - Block block1 = blockingStubFull.getNowBlock(org.tron.api.GrpcAPI.EmptyMessage.newBuilder().build()); + Block block1 = + blockingStubFull.getNowBlock(org.tron.api.GrpcAPI.EmptyMessage.newBuilder().build()); long ts1 = block1.getBlockHeader().getRawData().getTimestamp(); PublicMethod.waitProduceNextBlock(blockingStubFull); - Block block2 = blockingStubFull.getNowBlock(org.tron.api.GrpcAPI.EmptyMessage.newBuilder().build()); + Block block2 = + blockingStubFull.getNowBlock(org.tron.api.GrpcAPI.EmptyMessage.newBuilder().build()); long ts2 = block2.getBlockHeader().getRawData().getTimestamp(); long intervalMs = ts2 - ts1; logger.info("Block interval: {} ms", intervalMs); // TRON produces blocks every 3 seconds; allow 1-12s tolerance - Assert.assertTrue(intervalMs >= 1000 && intervalMs <= 12000, + Assert.assertTrue( + intervalMs >= 1000 && intervalMs <= 12000, "Block interval should be roughly 3 seconds, got " + intervalMs + " ms"); } - @Test(enabled = true, description = "Multiple consecutive blocks produced by different witnesses", + @Test( + enabled = true, + description = "Multiple consecutive blocks produced by different witnesses", groups = {"daily"}) public void test04WitnessRotation() { Set producers = new HashSet<>(); - long currentNum = blockingStubFull.getNowBlock(org.tron.api.GrpcAPI.EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + long currentNum = + blockingStubFull + .getNowBlock(org.tron.api.GrpcAPI.EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); // Look back at last 27 blocks (one full SR round) int lookback = Math.min(27, (int) currentNum); for (long i = currentNum - lookback + 1; i <= currentNum; i++) { Block block = PublicMethod.getBlock(i, blockingStubFull); if (block != null && block.getBlockHeader().getRawData().getNumber() > 0) { - String producer = ByteArray.toHexString( - block.getBlockHeader().getRawData().getWitnessAddress().toByteArray()); + String producer = + ByteArray.toHexString( + block.getBlockHeader().getRawData().getWitnessAddress().toByteArray()); producers.add(producer); } } logger.info("Unique producers in last {} blocks: {}", lookback, producers.size()); // In a multi-node DPoS setup, should have more than 1 producer - Assert.assertTrue(producers.size() >= 1, - "Should have at least 1 distinct block producer"); + Assert.assertTrue(producers.size() >= 1, "Should have at least 1 distinct block producer"); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/consensus/MaintenancePeriodTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/consensus/MaintenancePeriodTest.java index a4933964..d07d3159 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/consensus/MaintenancePeriodTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/consensus/MaintenancePeriodTest.java @@ -14,17 +14,19 @@ /** * Maintenance period tests. * - *

Validates that the maintenance period mechanism is active and that - * the next maintenance time is in the future relative to the latest block. + *

Validates that the maintenance period mechanism is active and that the next maintenance time + * is in the future relative to the latest block. */ @Slf4j public class MaintenancePeriodTest extends TronBaseTest { - @Test(enabled = true, description = "Next maintenance time should be in the future", + @Test( + enabled = true, + description = "Next maintenance time should be in the future", groups = {"daily"}) public void test01NextMaintenanceTimeInFuture() { - NumberMessage nextMaintenance = blockingStubFull.getNextMaintenanceTime( - EmptyMessage.newBuilder().build()); + NumberMessage nextMaintenance = + blockingStubFull.getNextMaintenanceTime(EmptyMessage.newBuilder().build()); long nextMaintenanceMs = nextMaintenance.getNum(); logger.info("Next maintenance time: {}", nextMaintenanceMs); @@ -32,13 +34,15 @@ public void test01NextMaintenanceTimeInFuture() { long blockTimestamp = currentBlock.getBlockHeader().getRawData().getTimestamp(); logger.info("Current block timestamp: {}", blockTimestamp); - Assert.assertTrue(nextMaintenanceMs > 0, - "Next maintenance time should be positive"); - Assert.assertTrue(nextMaintenanceMs >= blockTimestamp, + Assert.assertTrue(nextMaintenanceMs > 0, "Next maintenance time should be positive"); + Assert.assertTrue( + nextMaintenanceMs >= blockTimestamp, "Next maintenance time should be >= current block timestamp"); } - @Test(enabled = true, description = "Witness list should be available and non-empty after maintenance", + @Test( + enabled = true, + description = "Witness list should be available and non-empty after maintenance", groups = {"daily"}) public void test02WitnessListAfterMaintenance() { Optional witnessList = PublicMethod.listWitnesses(blockingStubFull); @@ -48,14 +52,15 @@ public void test02WitnessListAfterMaintenance() { logger.info("Active witnesses after maintenance: {}", witnessCount); } - @Test(enabled = true, description = "Total vote count across all witnesses should be positive", + @Test( + enabled = true, + description = "Total vote count across all witnesses should be positive", groups = {"daily"}) public void test03TotalVoteCountPositive() { Optional witnessList = PublicMethod.listWitnesses(blockingStubFull); Assert.assertTrue(witnessList.isPresent()); - long totalVotes = witnessList.get().getWitnessesList().stream() - .mapToLong(w -> w.getVoteCount()) - .sum(); + long totalVotes = + witnessList.get().getWitnessesList().stream().mapToLong(w -> w.getVoteCount()).sum(); logger.info("Total votes across all witnesses: {}", totalVotes); Assert.assertTrue(totalVotes > 0, "Total vote count should be positive"); } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/consensus/VoteWeightTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/consensus/VoteWeightTest.java index 38c7d499..bc3bd5d9 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/consensus/VoteWeightTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/consensus/VoteWeightTest.java @@ -17,8 +17,8 @@ /** * Vote weight and delegation tests. * - *

Verifies that voting power is proportional to frozen TRX (Tron Power), - * and that votes can be updated and revoked. + *

Verifies that voting power is proportional to frozen TRX (Tron Power), and that votes can be + * updated and revoked. */ @Slf4j public class VoteWeightTest extends TronBaseTest { @@ -41,73 +41,99 @@ public void beforeClass() { voter2KeyStr = ByteArray.toHexString(voter2Key.getPrivKeyBytes()); // Fund both voters - Assert.assertTrue(PublicMethod.sendcoin(voter1Address, TronConstants.TEN_THOUSAND_TRX, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(voter2Address, 5 * TronConstants.THOUSAND_TRX, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + voter1Address, + TronConstants.TEN_THOUSAND_TRX, + foundationAddress, + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + voter2Address, + 5 * TronConstants.THOUSAND_TRX, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Freeze more TRX = more vote weight (Stake 2.0)", + @Test( + enabled = true, + description = "Freeze more TRX = more vote weight (Stake 2.0)", groups = {"daily"}) public void test01MoreFreezeMoreVotes() { // Use FreezeBalanceV2 (Stake 2.0) — freezing for BANDWIDTH gives Tron Power - Assert.assertTrue(PublicMethod.freezeBalanceV2( - voter1Address, TronConstants.TEN_THOUSAND_TRX, - TronConstants.FREEZE_BANDWIDTH, voter1KeyStr, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceV2( - voter2Address, 5 * TronConstants.THOUSAND_TRX, - TronConstants.FREEZE_BANDWIDTH, voter2KeyStr, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + voter1Address, + TronConstants.TEN_THOUSAND_TRX, + TronConstants.FREEZE_BANDWIDTH, + voter1KeyStr, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + voter2Address, + 5 * TronConstants.THOUSAND_TRX, + TronConstants.FREEZE_BANDWIDTH, + voter2KeyStr, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account acc1 = PublicMethod.queryAccount(voter1Address, blockingStubFull); Account acc2 = PublicMethod.queryAccount(voter2Address, blockingStubFull); // In Stake 2.0, tron power = total frozen amount across all resource types - long power1 = acc1.getFrozenV2List().stream() - .mapToLong(Account.FreezeV2::getAmount).sum(); - long power2 = acc2.getFrozenV2List().stream() - .mapToLong(Account.FreezeV2::getAmount).sum(); + long power1 = acc1.getFrozenV2List().stream().mapToLong(Account.FreezeV2::getAmount).sum(); + long power2 = acc2.getFrozenV2List().stream().mapToLong(Account.FreezeV2::getAmount).sum(); logger.info("Voter1 frozenV2: {}, Voter2 frozenV2: {}", power1, power2); - Assert.assertTrue(power1 > power2, - "Voter1 (10000 TRX) should have more tron power than Voter2 (5000 TRX)"); + Assert.assertTrue( + power1 > power2, "Voter1 (10000 TRX) should have more tron power than Voter2 (5000 TRX)"); } - @Test(enabled = true, dependsOnMethods = "test01MoreFreezeMoreVotes", + @Test( + enabled = true, + dependsOnMethods = "test01MoreFreezeMoreVotes", description = "Vote and verify vote count matches", groups = {"daily"}) public void test02VoteCountMatchesFrozenAmount() { long voter1Amount = TronConstants.TEN_THOUSAND_TRX / TronConstants.ONE_TRX; HashMap voteMap1 = new HashMap<>(); voteMap1.put(witnessAddress, voter1Amount); - Assert.assertTrue(PublicMethod.voteWitness(voter1Address, voter1KeyStr, - voteMap1, blockingStubFull)); + Assert.assertTrue( + PublicMethod.voteWitness(voter1Address, voter1KeyStr, voteMap1, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account acc1 = PublicMethod.queryAccount(voter1Address, blockingStubFull); Assert.assertTrue(acc1.getVotesCount() > 0); - Assert.assertEquals(acc1.getVotes(0).getVoteCount(), voter1Amount, + Assert.assertEquals( + acc1.getVotes(0).getVoteCount(), + voter1Amount, "Vote count should match frozen TRX in sun / 1_000_000"); } - @Test(enabled = true, dependsOnMethods = "test02VoteCountMatchesFrozenAmount", + @Test( + enabled = true, + dependsOnMethods = "test02VoteCountMatchesFrozenAmount", description = "Re-voting should update the vote count", groups = {"daily"}) public void test03ReVoteUpdatesCount() { long newAmount = 5000L; // 5000 votes (less than max tron power) HashMap voteMap = new HashMap<>(); voteMap.put(witnessAddress, newAmount); - Assert.assertTrue(PublicMethod.voteWitness(voter1Address, voter1KeyStr, - voteMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.voteWitness(voter1Address, voter1KeyStr, voteMap, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account acc = PublicMethod.queryAccount(voter1Address, blockingStubFull); - Assert.assertEquals(acc.getVotes(0).getVoteCount(), newAmount, - "Re-voting should update vote count"); + Assert.assertEquals( + acc.getVotes(0).getVoteCount(), newAmount, "Re-voting should update vote count"); } - @Test(enabled = true, dependsOnMethods = "test03ReVoteUpdatesCount", + @Test( + enabled = true, + dependsOnMethods = "test03ReVoteUpdatesCount", description = "Re-voting with different amount should update", groups = {"daily"}) public void test04ReVoteWithDifferentAmount() { @@ -115,13 +141,15 @@ public void test04ReVoteWithDifferentAmount() { long smallAmount = 100L; HashMap voteMap = new HashMap<>(); voteMap.put(witnessAddress, smallAmount); - Assert.assertTrue(PublicMethod.voteWitness(voter1Address, voter1KeyStr, - voteMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.voteWitness(voter1Address, voter1KeyStr, voteMap, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account acc = PublicMethod.queryAccount(voter1Address, blockingStubFull); Assert.assertTrue(acc.getVotesCount() > 0, "Should have votes"); - Assert.assertEquals(acc.getVotes(0).getVoteCount(), smallAmount, + Assert.assertEquals( + acc.getVotes(0).getVoteCount(), + smallAmount, "Vote count should be updated to " + smallAmount); } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/consensus/WitnessElectionTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/consensus/WitnessElectionTest.java index 7758c2bf..42b68aa4 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/consensus/WitnessElectionTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/consensus/WitnessElectionTest.java @@ -20,8 +20,8 @@ /** * DPoS witness election tests. * - *

Verifies the SR witness list, voting mechanics, and vote-count - * reflection in the witness schedule. + *

Verifies the SR witness list, voting mechanics, and vote-count reflection in the witness + * schedule. */ @Slf4j public class WitnessElectionTest extends TronBaseTest { @@ -37,22 +37,31 @@ public void beforeClass() { voterKeyStr1 = ByteArray.toHexString(voterKey1.getPrivKeyBytes()); PublicMethod.printAddress(voterKeyStr1); - Assert.assertTrue(PublicMethod.sendcoin(voterAddress1, TronConstants.TEN_THOUSAND_TRX, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + voterAddress1, + TronConstants.TEN_THOUSAND_TRX, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Witness list should not be empty", + @Test( + enabled = true, + description = "Witness list should not be empty", groups = {"daily"}) public void test01WitnessListNotEmpty() { Optional witnessList = PublicMethod.listWitnesses(blockingStubFull); Assert.assertTrue(witnessList.isPresent(), "Witness list should be present"); - Assert.assertTrue(witnessList.get().getWitnessesCount() > 0, - "Should have at least one witness"); + Assert.assertTrue( + witnessList.get().getWitnessesCount() > 0, "Should have at least one witness"); logger.info("Total witnesses: {}", witnessList.get().getWitnessesCount()); } - @Test(enabled = true, description = "All witnesses should have valid addresses", + @Test( + enabled = true, + description = "All witnesses should have valid addresses", groups = {"daily"}) public void test02WitnessAddressesValid() { Optional witnessList = PublicMethod.listWitnesses(blockingStubFull); @@ -61,12 +70,13 @@ public void test02WitnessAddressesValid() { byte[] addr = witness.getAddress().toByteArray(); Assert.assertEquals(addr.length, 21, "Witness address should be 21 bytes"); Assert.assertEquals(addr[0], (byte) 0x41, "Witness address should start with 0x41"); - logger.info("Witness: {} voteCount={}", ByteArray.toHexString(addr), - witness.getVoteCount()); + logger.info("Witness: {} voteCount={}", ByteArray.toHexString(addr), witness.getVoteCount()); } } - @Test(enabled = true, description = "Vote for witness and verify vote count increases", + @Test( + enabled = true, + description = "Vote for witness and verify vote count increases", groups = {"daily"}) public void test03VoteIncreasesWitnessVoteCount() { // Get initial vote count for our test witness @@ -83,16 +93,20 @@ public void test03VoteIncreasesWitnessVoteCount() { logger.info("Initial vote count for witness: {}", initialVoteCount); // Freeze (Stake 2.0) and vote - Assert.assertTrue(PublicMethod.freezeBalanceV2( - voterAddress1, TronConstants.THOUSAND_TRX, - TronConstants.FREEZE_BANDWIDTH, voterKeyStr1, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + voterAddress1, + TronConstants.THOUSAND_TRX, + TronConstants.FREEZE_BANDWIDTH, + voterKeyStr1, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long voteAmount = TronConstants.THOUSAND_TRX / TronConstants.ONE_TRX; HashMap voteMap = new HashMap<>(); voteMap.put(witnessAddress, voteAmount); - Assert.assertTrue(PublicMethod.voteWitness(voterAddress1, voterKeyStr1, - voteMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.voteWitness(voterAddress1, voterKeyStr1, voteMap, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); // Verify voter account recorded the vote @@ -101,7 +115,9 @@ public void test03VoteIncreasesWitnessVoteCount() { Assert.assertEquals(voterAccount.getVotes(0).getVoteCount(), voteAmount); } - @Test(enabled = true, description = "Witnesses all have non-negative vote counts", + @Test( + enabled = true, + description = "Witnesses all have non-negative vote counts", groups = {"daily"}) public void test04WitnessVoteCountsValid() { Optional witnessList = PublicMethod.listWitnesses(blockingStubFull); @@ -109,10 +125,11 @@ public void test04WitnessVoteCountsValid() { // Note: ListWitnesses API does not guarantee descending sort order. // Verify all vote counts are non-negative and log them for inspection. for (Witness w : witnessList.get().getWitnessesList()) { - Assert.assertTrue(w.getVoteCount() >= 0, - "Witness vote count should be non-negative"); - logger.info("Witness {} voteCount={}", - ByteArray.toHexString(w.getAddress().toByteArray()), w.getVoteCount()); + Assert.assertTrue(w.getVoteCount() >= 0, "Witness vote count should be non-negative"); + logger.info( + "Witness {} voteCount={}", + ByteArray.toHexString(w.getAddress().toByteArray()), + w.getVoteCount()); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/dynamicenergy/DynamicEnergyTest002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/dynamicenergy/DynamicEnergyTest002.java index 32f76746..e5d8041f 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/dynamicenergy/DynamicEnergyTest002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/dynamicenergy/DynamicEnergyTest002.java @@ -8,7 +8,6 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.tron.protos.Protocol.ChainParameters; import org.tron.protos.Protocol.TransactionInfo; import org.tron.protos.contract.SmartContractOuterClass.ContractState; import stest.tron.wallet.common.client.utils.ByteArray; @@ -22,8 +21,8 @@ /** * TIP-586: Dynamic Energy model tests. * - *

Tests the dynamic energy pricing mechanism where frequently-called - * contracts pay higher energy costs to prevent resource abuse. + *

Tests the dynamic energy pricing mechanism where frequently-called contracts pay higher energy + * costs to prevent resource abuse. */ @Slf4j public class DynamicEnergyTest002 extends TronBaseTest { @@ -42,16 +41,22 @@ public void beforeClass() throws Exception { throw new SkipException("Skipping dynamic energy test - proposal not open"); } - energyFee = PublicMethod.getChainParametersValue( - ProposalEnum.GetEnergyFee.getProposalName(), blockingStubFull); - - Assert.assertTrue(PublicMethod.sendcoin(testAddress, - 100 * TronConstants.THOUSAND_TRX, - foundationAddress, foundationKey, blockingStubFull)); + energyFee = + PublicMethod.getChainParametersValue( + ProposalEnum.GetEnergyFee.getProposalName(), blockingStubFull); + + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress, + 100 * TronConstants.THOUSAND_TRX, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(testAddress, - 50 * TronConstants.THOUSAND_TRX, 0, 0, testKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + testAddress, 50 * TronConstants.THOUSAND_TRX, 0, 0, testKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); // Deploy a simple test contract @@ -60,9 +65,19 @@ public void beforeClass() throws Exception { HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - String txid = PublicMethod.deployContractAndGetTransactionInfoById( - contractName, abi, code, "", maxFeeLimit, 0L, 100, null, - testKey, testAddress, blockingStubFull); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKey, + testAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -70,46 +85,59 @@ public void beforeClass() throws Exception { Assert.assertNotNull(contractAddress, "Contract deployment should succeed"); } - @Test(enabled = true, description = "Query dynamic energy chain parameters", + @Test( + enabled = true, + description = "Query dynamic energy chain parameters", groups = {"daily"}) public void test01QueryDynamicEnergyParams() { - long dynamicEnergyThreshold = PublicMethod.getChainParametersValue( - "getDynamicEnergyThreshold", blockingStubFull); - long dynamicEnergyIncreaseFactor = PublicMethod.getChainParametersValue( - "getDynamicEnergyIncreaseFactor", blockingStubFull); - long dynamicEnergyMaxFactor = PublicMethod.getChainParametersValue( - "getDynamicEnergyMaxFactor", blockingStubFull); + long dynamicEnergyThreshold = + PublicMethod.getChainParametersValue("getDynamicEnergyThreshold", blockingStubFull); + long dynamicEnergyIncreaseFactor = + PublicMethod.getChainParametersValue("getDynamicEnergyIncreaseFactor", blockingStubFull); + long dynamicEnergyMaxFactor = + PublicMethod.getChainParametersValue("getDynamicEnergyMaxFactor", blockingStubFull); logger.info("Dynamic energy threshold: {}", dynamicEnergyThreshold); logger.info("Dynamic energy increase factor: {}", dynamicEnergyIncreaseFactor); logger.info("Dynamic energy max factor: {}", dynamicEnergyMaxFactor); - Assert.assertTrue(dynamicEnergyThreshold >= 0, - "Dynamic energy threshold should be non-negative"); - Assert.assertTrue(dynamicEnergyMaxFactor >= 0, - "Dynamic energy max factor should be non-negative"); + Assert.assertTrue( + dynamicEnergyThreshold >= 0, "Dynamic energy threshold should be non-negative"); + Assert.assertTrue( + dynamicEnergyMaxFactor >= 0, "Dynamic energy max factor should be non-negative"); } - @Test(enabled = true, description = "Query contract energy usage state", + @Test( + enabled = true, + description = "Query contract energy usage state", groups = {"daily"}) public void test02QueryContractState() { - ContractState state = PublicMethod.getContractInfo(contractAddress, blockingStubFull) - .getContractState(); + ContractState state = + PublicMethod.getContractInfo(contractAddress, blockingStubFull).getContractState(); logger.info("Contract energy usage: {}", state.getEnergyUsage()); logger.info("Contract energy factor: {}", state.getEnergyFactor()); logger.info("Contract update cycle: {}", state.getUpdateCycle()); // New contract should have default energy factor - Assert.assertTrue(state.getEnergyFactor() >= 0, - "Energy factor should be non-negative"); + Assert.assertTrue(state.getEnergyFactor() >= 0, "Energy factor should be non-negative"); } - @Test(enabled = true, description = "Trigger contract and verify energy consumption recorded", + @Test( + enabled = true, + description = "Trigger contract and verify energy consumption recorded", groups = {"daily"}) public void test03TriggerAndCheckEnergyUsage() { - String txid = PublicMethod.triggerContract(contractAddress, - "timeout()", "#", false, 0, maxFeeLimit, - testAddress, testKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + "timeout()", + "#", + false, + 0, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventLog2.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventLog2.java index dd8c66fd..86253aec 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventLog2.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventLog2.java @@ -13,71 +13,91 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class EventLog2 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] mapKeyContract = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 300100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 300100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/eventLog2.sol"; - String contractName = "Event"; + String filePath = "src/test/resources/soliditycode/eventLog2.sol"; + String contractName = "Event"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - mapKeyContract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + mapKeyContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(mapKeyContract, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(mapKeyContract, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - - @Test(enabled = true, description = "test opcode log2", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "test opcode log2", + groups = {"daily", "serial"}) public void test01EmitLog2() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "messageI()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "messageI()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - String logStr1 = ByteArray.toHexString(transactionExtention.getLogs(0).getData().toByteArray()); - Assert.assertTrue(logStr1.contains("000000000000000000000000000000000000000" - + "000000000000000000000000100000000000000000" - + "000000000000000000000000000000000000000000000010000000000000000" - + "000000000000000000000000000000000000000000000001")); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + String logStr1 = ByteArray.toHexString(transactionExtention.getLogs(0).getData().toByteArray()); + Assert.assertTrue( + logStr1.contains( + "000000000000000000000000000000000000000" + + "000000000000000000000000100000000000000000" + + "000000000000000000000000000000000000000000000010000000000000000" + + "000000000000000000000000000000000000000000000001")); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); Assert.assertEquals(1, trueRes); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventQuery001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventQuery001.java index 5f5fed98..27ac6e69 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventQuery001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventQuery001.java @@ -13,7 +13,8 @@ import zmq.ZMQ.Event; @Slf4j -public class EventQuery001 extends TronBaseTest { private final String testKey003 = +public class EventQuery001 extends TronBaseTest { + private final String testKey003 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); private String eventnode = @@ -21,28 +22,32 @@ public class EventQuery001 extends TronBaseTest { private final String testKey0 /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } - @Test(enabled = true, description = "Event query for block", groups = {"daily", "serial"}) + public void beforeClass() {} + + @Test( + enabled = true, + description = "Event query for block", + groups = {"daily", "serial"}) public void test01EventQueryForBlock() { ZMQ.Context context = ZMQ.context(1); ZMQ.Socket req = context.socket(ZMQ.SUB); req.subscribe("blockTrigger"); - final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); + final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); moniter.connect("inproc://reqmoniter"); new Thread( - new Runnable() { - public void run() { - while (true) { - Event event = Event.read(moniter.base()); - System.out.println(event.event + " " + event.addr); - } - } - }) + new Runnable() { + public void run() { + while (true) { + Event event = Event.read(moniter.base()); + System.out.println(event.event + " " + event.addr); + } + } + }) .start(); req.connect(eventnode); req.setReceiveTimeOut(10000); - String blockMessage = ""; + String blockMessage = ""; Integer retryTimes = 20; while (retryTimes-- > 0) { @@ -66,27 +71,30 @@ public void run() { Assert.assertTrue(blockObject.getInteger("transactionSize") >= 0); } - @Test(enabled = true, description = "Event query for block on solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Event query for block on solidity", + groups = {"daily", "serial"}) public void test02EventQueryForBlockOnSolidity() { ZMQ.Context context = ZMQ.context(1); ZMQ.Socket req = context.socket(ZMQ.SUB); req.subscribe("solidityTrigger"); - final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); + final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); moniter.connect("inproc://reqmoniter"); new Thread( - new Runnable() { - public void run() { - while (true) { - Event event = Event.read(moniter.base()); - System.out.println(event.event + " " + event.addr); - } - } - }) + new Runnable() { + public void run() { + while (true) { + Event event = Event.read(moniter.base()); + System.out.println(event.event + " " + event.addr); + } + } + }) .start(); req.connect(eventnode); req.setReceiveTimeOut(10000); - String blockMessage = ""; + String blockMessage = ""; Integer retryTimes = 20; @@ -111,5 +119,5 @@ public void run() { /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventQuery002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventQuery002.java index 526a1238..c33f1939 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventQuery002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventQuery002.java @@ -1,7 +1,6 @@ package stest.tron.wallet.dailybuild.eventquery; import com.alibaba.fastjson.JSONObject; - import java.util.ArrayList; import java.util.List; import lombok.extern.slf4j.Slf4j; @@ -14,12 +13,13 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; import zmq.ZMQ.Event; @Slf4j -public class EventQuery002 extends TronBaseTest { private final String testKey003 = +public class EventQuery002 extends TronBaseTest { + private final String testKey003 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); private String eventnode = @@ -33,7 +33,8 @@ public class EventQuery002 extends TronBaseTest { private final String testKey0 /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { ecKey1 = new ECKey(Utils.getRandom()); + public void beforeClass() { + ecKey1 = new ECKey(Utils.getRandom()); event001Address = ecKey1.getAddress(); event001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); PublicMethod.printAddress(event001Key); @@ -42,10 +43,10 @@ public class EventQuery002 extends TronBaseTest { private final String testKey0 PublicMethod.sendcoin( event001Address, maxFeeLimit * 30, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName = "addressDemo"; - String code = + String contractName = "addressDemo"; + String code = Configuration.getByPath("testng.conf").getString("code.code_ContractEventAndLog1"); - String abi = Configuration.getByPath("testng.conf").getString("abi.abi_ContractEventAndLog1"); + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_ContractEventAndLog1"); contractAddress = PublicMethod.deployContract( contractName, @@ -62,27 +63,30 @@ public class EventQuery002 extends TronBaseTest { private final String testKey0 PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Event query for transaction", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Event query for transaction", + groups = {"daily", "serial"}) public void test01EventQueryForTransaction() { ZMQ.Context context = ZMQ.context(1); ZMQ.Socket req = context.socket(ZMQ.SUB); req.subscribe("transactionTrigger"); - final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); + final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); moniter.connect("inproc://reqmoniter"); new Thread( - new Runnable() { - public void run() { - while (true) { - Event event = Event.read(moniter.base()); - System.out.println(event.event + " " + event.addr); - } - } - }) + new Runnable() { + public void run() { + while (true) { + Event event = Event.read(moniter.base()); + System.out.println(event.event + " " + event.addr); + } + } + }) .start(); req.connect(eventnode); req.setReceiveTimeOut(10000); - String transactionMessage = ""; + String transactionMessage = ""; Boolean sendTransaction = true; Integer retryTimes = 20; transactionIdList = new ArrayList<>(); @@ -108,7 +112,6 @@ public void run() { } byte[] message = req.recv(); - if (message != null) { transactionMessage = new String(message); logger.info("transaction message:" + transactionMessage); @@ -116,7 +119,7 @@ public void run() { if (!transactionMessage.equals("transactionTrigger") && !transactionMessage.isEmpty() && transactionMessage.contains("transactionId")) { - break; + break; } } else { sendTransaction = true; @@ -132,5 +135,5 @@ public void run() { /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventQuery003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventQuery003.java index a58b84cb..ef8a8ac9 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventQuery003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventQuery003.java @@ -1,7 +1,6 @@ package stest.tron.wallet.dailybuild.eventquery; import com.alibaba.fastjson.JSONObject; - import java.util.ArrayList; import java.util.List; import lombok.extern.slf4j.Slf4j; @@ -14,12 +13,13 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; import zmq.ZMQ.Event; @Slf4j -public class EventQuery003 extends TronBaseTest { private final String testKey003 = +public class EventQuery003 extends TronBaseTest { + private final String testKey003 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); private String eventnode = @@ -36,7 +36,8 @@ public class EventQuery003 extends TronBaseTest { private final String testKey0 /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - initSolidityChannel(); ecKey1 = new ECKey(Utils.getRandom()); + initSolidityChannel(); + ecKey1 = new ECKey(Utils.getRandom()); event001Address = ecKey1.getAddress(); event001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); PublicMethod.printAddress(event001Key); @@ -45,10 +46,10 @@ public void beforeClass() { PublicMethod.sendcoin( event001Address, maxFeeLimit * 30, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName = "addressDemo"; - String code = + String contractName = "addressDemo"; + String code = Configuration.getByPath("testng.conf").getString("code.code_ContractEventAndLog1"); - String abi = Configuration.getByPath("testng.conf").getString("abi.abi_ContractEventAndLog1"); + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_ContractEventAndLog1"); contractAddress = PublicMethod.deployContract( contractName, @@ -65,27 +66,30 @@ public void beforeClass() { PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Event query for contract event", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Event query for contract event", + groups = {"daily", "serial"}) public void test01EventQueryForContractEvent() { ZMQ.Context context = ZMQ.context(1); ZMQ.Socket req = context.socket(ZMQ.SUB); req.subscribe("contractEventTrigger"); - final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); + final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); moniter.connect("inproc://reqmoniter"); new Thread( - new Runnable() { - public void run() { - while (true) { - Event event = Event.read(moniter.base()); - System.out.println(event.event + " " + event.addr); - } - } - }) + new Runnable() { + public void run() { + while (true) { + Event event = Event.read(moniter.base()); + System.out.println(event.event + " " + event.addr); + } + } + }) .start(); req.connect(eventnode); req.setReceiveTimeOut(10000); - String transactionMessage = ""; + String transactionMessage = ""; Boolean sendTransaction = true; Integer retryTimes = 10; transactionIdList = new ArrayList<>(); @@ -112,7 +116,6 @@ public void run() { } byte[] message = req.recv(); - if (message != null) { transactionMessage = new String(message); logger.info("transaction message:" + transactionMessage); @@ -134,28 +137,31 @@ public void run() { Assert.assertEquals(blockObject.getString("triggerName"), "contractEventTrigger"); } - @Test(enabled = true, description = "Event query for solidity contract event", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Event query for solidity contract event", + groups = {"daily", "serial"}) public void test02EventQueryForContractSolidityEvent() { PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); ZMQ.Context context = ZMQ.context(1); ZMQ.Socket req = context.socket(ZMQ.SUB); req.subscribe("solidityEventTrigger"); - final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); + final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); moniter.connect("inproc://reqmoniter"); new Thread( - new Runnable() { - public void run() { - while (true) { - Event event = Event.read(moniter.base()); - System.out.println(event.event + " " + event.addr); - } - } - }) + new Runnable() { + public void run() { + while (true) { + Event event = Event.read(moniter.base()); + System.out.println(event.event + " " + event.addr); + } + } + }) .start(); req.connect(eventnode); req.setReceiveTimeOut(10000); - String transactionMessage = ""; + String transactionMessage = ""; Boolean sendTransaction = true; transactionIdList = new ArrayList<>(); Integer retryTimes = 40; @@ -208,5 +214,5 @@ public void run() { /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventQuery004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventQuery004.java index 510f4ce8..2db04877 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventQuery004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventQuery004.java @@ -1,7 +1,6 @@ package stest.tron.wallet.dailybuild.eventquery; import com.alibaba.fastjson.JSONObject; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -15,12 +14,13 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; import zmq.ZMQ.Event; @Slf4j -public class EventQuery004 extends TronBaseTest { private final String testKey003 = +public class EventQuery004 extends TronBaseTest { + private final String testKey003 = Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); byte[] contractAddress; @@ -32,12 +32,14 @@ public class EventQuery004 extends TronBaseTest { private final String testKey0 private String eventnode = Configuration.getByPath("testng.conf").getStringList("eventnode.ip.list").get(0); private String soliditynode = - Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); List transactionIdList = null; + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + List transactionIdList = null; /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - initSolidityChannel(); ecKey1 = new ECKey(Utils.getRandom()); + initSolidityChannel(); + ecKey1 = new ECKey(Utils.getRandom()); event001Address = ecKey1.getAddress(); event001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); PublicMethod.printAddress(event001Key); @@ -46,10 +48,10 @@ public void beforeClass() { PublicMethod.sendcoin( event001Address, maxFeeLimit * 30, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName = "addressDemo"; - String code = + String contractName = "addressDemo"; + String code = Configuration.getByPath("testng.conf").getString("code.code_ContractEventAndLog1"); - String abi = Configuration.getByPath("testng.conf").getString("abi.abi_ContractEventAndLog1"); + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_ContractEventAndLog1"); contractAddress = PublicMethod.deployContract( contractName, @@ -63,11 +65,11 @@ public void beforeClass() { event001Key, event001Address, blockingStubFull); - String filePath2 = "src/test/resources/soliditycode/contractTestLog.sol"; - String contractName1 = "C"; + String filePath2 = "src/test/resources/soliditycode/contractTestLog.sol"; + String contractName1 = "C"; HashMap retMap2 = PublicMethod.getBycodeAbi(filePath2, contractName1); - String code1 = retMap2.get("byteCode").toString(); - String abi1 = retMap2.get("abI").toString(); + String code1 = retMap2.get("byteCode").toString(); + String abi1 = retMap2.get("abI").toString(); contractAddress1 = PublicMethod.deployContract( contractName, @@ -83,26 +85,28 @@ public void beforeClass() { blockingStubFull); } - @Test(enabled = true, priority=3, description = "Filter contractTopic event query for contract log", groups = {"daily", "serial"}) + @Test( + enabled = true, + priority = 3, + description = "Filter contractTopic event query for contract log", + groups = {"daily", "serial"}) public void test01filterContractTopicEventQueryForContractLog() { ZMQ.Context context = ZMQ.context(1); ZMQ.Socket req = context.socket(ZMQ.SUB); req.subscribe("contractLogTrigger"); - final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); + final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); moniter.connect("inproc://reqmoniter"); - new Thread( - new Runnable() { - public void run() { - while (true) { - Event event = Event.read(moniter.base()); - System.out.println(event.event + " " + event.addr); - } - } - }) - .start(); + Runnable moniterTask = + () -> { + while (true) { + Event event = Event.read(moniter.base()); + System.out.println(event.event + " " + event.addr); + } + }; + new Thread(moniterTask).start(); req.connect(eventnode); req.setReceiveTimeOut(5000); - String transactionMessage = ""; + String transactionMessage = ""; Boolean sendTransaction = true; Integer retryTimes = 3; @@ -121,10 +125,12 @@ public void run() { blockingStubFull); logger.info(txid); -/* if (PublicMethod.getTransactionInfoById(txid, blockingStubFull).get().getResultValue() - == 0) { - sendTransaction = false; - }*/ + /* + * if (PublicMethod.getTransactionInfoById(txid, blockingStubFull) + * .get().getResultValue() == 0) { + * sendTransaction = false; + * } + */ } byte[] message = req.recv(); @@ -136,35 +142,37 @@ public void run() { } } } - //test native event filter function , should not find message in zmq + // test native event filter function , should not find message in zmq Assert.assertTrue(retryTimes < 0); } - @Test(enabled = true, priority=3, description = "Filter contractTopic event query for solidity contract log", groups = {"daily", "serial"}) + @Test( + enabled = true, + priority = 3, + description = "Filter contractTopic event query for solidity contract log", + groups = {"daily", "serial"}) public void test02filterContractTopicEventQueryForContractSolidityLog() { PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); ZMQ.Context context = ZMQ.context(1); ZMQ.Socket req = context.socket(ZMQ.SUB); req.subscribe("solidityLogTrigger"); - final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); + final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); moniter.connect("inproc://reqmoniter"); - new Thread( - new Runnable() { - public void run() { - while (true) { - Event event = Event.read(moniter.base()); - System.out.println(event.event + " " + event.addr); - } - } - }) - .start(); + Runnable moniterTask = + () -> { + while (true) { + Event event = Event.read(moniter.base()); + System.out.println(event.event + " " + event.addr); + } + }; + new Thread(moniterTask).start(); req.connect(eventnode); req.setReceiveTimeOut(5000); - String transactionMessage = ""; + String transactionMessage = ""; Boolean sendTransaction = true; Integer retryTimes = 3; - String txid1 = ""; + String txid1 = ""; while (retryTimes-- > 0) { if (sendTransaction) { @@ -180,14 +188,16 @@ public void run() { event001Key, blockingStubFull); logger.info(txid1); -/* if (PublicMethod.getTransactionInfoById(txid, blockingStubFull).get().getResultValue() - == 0) { - sendTransaction = false; - }*/ + /* + * if (PublicMethod.getTransactionInfoById(txid, + * blockingStubFull).get().getResultValue() + * == 0) { + * sendTransaction = false; + * } + */ } byte[] message = req.recv(); - if (message != null) { transactionMessage = new String(message); @@ -197,31 +207,33 @@ public void run() { } } } - //test native event filter function, should not find message in zmq + // test native event filter function, should not find message in zmq Assert.assertTrue(retryTimes < 0); } - @Test(enabled = true, priority=3, description = "Event query for contract log", groups = {"daily", "serial"}) + @Test( + enabled = true, + priority = 3, + description = "Event query for contract log", + groups = {"daily", "serial"}) public void test03EventQueryForContractLog() { ZMQ.Context context = ZMQ.context(1); ZMQ.Socket req = context.socket(ZMQ.SUB); req.subscribe("contractLogTrigger"); - final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); + final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); moniter.connect("inproc://reqmoniter"); - new Thread( - new Runnable() { - public void run() { - while (true) { - Event event = Event.read(moniter.base()); - System.out.println(event.event + " " + event.addr); - } - } - }) - .start(); + Runnable moniterTask = + () -> { + while (true) { + Event event = Event.read(moniter.base()); + System.out.println(event.event + " " + event.addr); + } + }; + new Thread(moniterTask).start(); req.connect(eventnode); req.setReceiveTimeOut(10000); - String transactionMessage = ""; + String transactionMessage = ""; Boolean sendTransaction = true; Integer retryTimes = 20; transactionIdList = new ArrayList<>(); @@ -268,33 +280,35 @@ public void run() { Assert.assertEquals(blockObject.getString("triggerName"), "contractLogTrigger"); } - @Test(enabled = true, priority=3, description = "Event query for solidity contract log", groups = {"daily", "serial"}) + @Test( + enabled = true, + priority = 3, + description = "Event query for solidity contract log", + groups = {"daily", "serial"}) public void test04EventQueryForContractSolidityLog() { PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); ZMQ.Context context = ZMQ.context(1); ZMQ.Socket req = context.socket(ZMQ.SUB); req.subscribe("solidityLogTrigger"); - final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); + final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); moniter.connect("inproc://reqmoniter"); - new Thread( - new Runnable() { - public void run() { - while (true) { - Event event = Event.read(moniter.base()); - System.out.println(event.event + " " + event.addr); - } - } - }) - .start(); + Runnable moniterTask = + () -> { + while (true) { + Event event = Event.read(moniter.base()); + System.out.println(event.event + " " + event.addr); + } + }; + new Thread(moniterTask).start(); req.connect(eventnode); req.setReceiveTimeOut(10000); - String transactionMessage = ""; + String transactionMessage = ""; Boolean sendTransaction = true; Integer retryTimes = 20; - String txid1 = ""; - String txid2 = ""; - String txid3 = ""; + String txid1 = ""; + String txid2 = ""; + String txid3 = ""; transactionIdList = new ArrayList<>(); while (retryTimes-- > 0) { if (sendTransaction) { @@ -369,5 +383,5 @@ public void run() { /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventQuery005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventQuery005.java index 1651d44a..f26853db 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventQuery005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventQuery005.java @@ -2,20 +2,24 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import java.util.ArrayList; +import java.util.List; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.zeromq.ZMQ; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; - -import java.util.ArrayList; -import java.util.List; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class EventQuery005 extends TronBaseTest { private final byte[] foundationAddress = PublicMethod.getFinalAddress(foundationKey); +public class EventQuery005 extends TronBaseTest { + private final byte[] foundationAddress = PublicMethod.getFinalAddress(foundationKey); private String eventnode = Configuration.getByPath("testng.conf").getStringList("eventnode.ip.list").get(0); private String soliditynode = @@ -24,15 +28,18 @@ public class EventQuery005 extends TronBaseTest { private final byte[] foundati /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - initSolidityChannel(); } - + initSolidityChannel(); + } - @Test(enabled = true, description = "Test new Field for FreezeBalanceV2 in NativeQueue", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Test new Field for FreezeBalanceV2 in NativeQueue", + groups = {"daily", "serial"}) public void test01EventQueryForTransactionFreezeBalanceV2() throws InterruptedException { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] freezeAccount = ecKey1.getAddress(); - String freezeAccountKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Long freezeAmount = maxFeeLimit * 40; + byte[] freezeAccount = ecKey1.getAddress(); + String freezeAccountKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + Long freezeAmount = maxFeeLimit * 40; Assert.assertTrue( PublicMethod.sendcoin( freezeAccount, freezeAmount, foundationAddress, foundationKey, blockingStubFull)); @@ -44,14 +51,14 @@ public void test01EventQueryForTransactionFreezeBalanceV2() throws InterruptedEx ZMQ.Socket req = context.socket(ZMQ.SUB); req.subscribe("transactionTrigger"); - final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); + final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); moniter.connect("inproc://reqmoniter"); new Thread( new Runnable() { public void run() { while (true) { zmq.ZMQ.Event event = zmq.ZMQ.Event.read(moniter.base()); - logger.info("!!!!{} {}", event.event, event.addr); + logger.info("!!!!{} {}", event.event, event.addr); System.out.println(event.event + " " + event.addr); } } @@ -59,12 +66,13 @@ public void run() { .start(); req.connect(eventnode); req.setReceiveTimeOut(10000); - String transactionMessage = ""; + String transactionMessage = ""; Boolean sendTransaction = true; Integer retryTimes = 40; transactionIdList = new ArrayList<>(); ArrayList messageArray = new ArrayList(); - Thread readLoopThread = new Thread( + Thread readLoopThread = + new Thread( new Runnable() { public void run() { while (true) { @@ -77,16 +85,17 @@ public void run() { boolean success = false; while (retryTimes-- > 0) { - if(success){ + if (success) { break; } - String txid = PublicMethod.freezeBalanceV2AndGetTxId(freezeAccount, - maxFeeLimit, 0, freezeAccountKey, blockingStubFull); + String txid = + PublicMethod.freezeBalanceV2AndGetTxId( + freezeAccount, maxFeeLimit, 0, freezeAccountKey, blockingStubFull); transactionIdList.add(txid); PublicMethod.waitProduceNextBlock(blockingStubFull); try { - for(byte[] message: messageArray){ + for (byte[] message : messageArray) { if (message != null) { transactionMessage = new String(message); logger.info("transaction message:" + transactionMessage); @@ -100,7 +109,8 @@ public void run() { if (transactionIdList.contains(id)) { logger.info("find target tx, begin to Assert and abort loop"); Assert.assertEquals(data.getString("contractType"), "FreezeBalanceV2Contract"); - Assert.assertEquals(data.getString("fromAddress"), Base58.encode58Check(freezeAccount)); + Assert.assertEquals( + data.getString("fromAddress"), Base58.encode58Check(freezeAccount)); Assert.assertEquals(data.getString("assetName"), "trx"); Assert.assertEquals(data.getLongValue("assetAmount"), maxFeeLimit); success = true; @@ -109,29 +119,30 @@ public void run() { } } } - } catch (Exception e) { - + } catch (Exception expected) { + // expected } - } logger.info("Final transaction message:" + transactionMessage); logger.info("retryTimes: " + retryTimes); Assert.assertTrue(retryTimes >= 0); } - - @Test(enabled = true, description = "Test new Field for UnfreezeBalanceV2 in NativeQueue", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Test new Field for UnfreezeBalanceV2 in NativeQueue", + groups = {"daily", "serial"}) public void test02EventQueryForTransactionUnfreezeBalanceV2() throws InterruptedException { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] freezeAccount = ecKey1.getAddress(); - String freezeAccountKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Long freezeAmount = maxFeeLimit * 20; + byte[] freezeAccount = ecKey1.getAddress(); + String freezeAccountKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + Long freezeAmount = maxFeeLimit * 20; Assert.assertTrue( PublicMethod.sendcoin( freezeAccount, freezeAmount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.freezeBalanceV2AndGetTxId(freezeAccount, - maxFeeLimit, 0, freezeAccountKey, blockingStubFull); + PublicMethod.freezeBalanceV2AndGetTxId( + freezeAccount, maxFeeLimit, 0, freezeAccountKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); List transactionIdList = new ArrayList<>(); @@ -140,7 +151,7 @@ public void test02EventQueryForTransactionUnfreezeBalanceV2() throws Interrupted ZMQ.Socket req = context.socket(ZMQ.SUB); req.subscribe("transactionTrigger"); - final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); + final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); moniter.connect("inproc://reqmoniter"); new Thread( new Runnable() { @@ -154,12 +165,13 @@ public void run() { .start(); req.connect(eventnode); req.setReceiveTimeOut(10000); - String transactionMessage = ""; + String transactionMessage = ""; Boolean sendTransaction = true; Integer retryTimes = 40; transactionIdList = new ArrayList<>(); ArrayList messageArray = new ArrayList(); - Thread readLoopThread = new Thread( + Thread readLoopThread = + new Thread( new Runnable() { public void run() { while (true) { @@ -170,20 +182,20 @@ public void run() { }); readLoopThread.start(); boolean success = false; - Long unfreezeAmount = 10000000L; + Long unfreezeAmount = 10000000L; while (retryTimes-- > 0) { - if (success){ + if (success) { break; } - String txid = PublicMethod.unFreezeBalanceV2AndGetTxId(freezeAccount, - freezeAccountKey, unfreezeAmount, 0, blockingStubFull); + String txid = + PublicMethod.unFreezeBalanceV2AndGetTxId( + freezeAccount, freezeAccountKey, unfreezeAmount, 0, blockingStubFull); transactionIdList.add(txid); PublicMethod.waitProduceNextBlock(blockingStubFull); - try { - for(byte[] message: messageArray){ + for (byte[] message : messageArray) { if (message != null) { transactionMessage = new String(message); logger.info("transaction message:" + transactionMessage); @@ -193,11 +205,12 @@ public void run() { && transactionMessage.contains("transactionId")) { JSONObject data = JSON.parseObject(transactionMessage); String id = data.getString("transactionId"); - if(transactionIdList.contains(id)) { + if (transactionIdList.contains(id)) { logger.info("find target tx, begin to Assert and abort loop"); logger.info("trxId : " + data.getString("transactionId")); Assert.assertEquals(data.getString("contractType"), "UnfreezeBalanceV2Contract"); - Assert.assertEquals(data.getString("fromAddress"), Base58.encode58Check(freezeAccount)); + Assert.assertEquals( + data.getString("fromAddress"), Base58.encode58Check(freezeAccount)); Assert.assertEquals(data.getString("assetName"), "trx"); Assert.assertEquals(data.getLong("assetAmount"), unfreezeAmount); success = true; @@ -206,28 +219,29 @@ public void run() { } } } - }catch (Exception e){ - + } catch (Exception expected) { + // expected } - } logger.info("Final transaction message:" + transactionMessage); logger.info("retryTimes: " + retryTimes); Assert.assertTrue(retryTimes >= 0); } - - @Test(enabled = true, description = "Test new Field for DelegateResource in NativeQueue", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Test new Field for DelegateResource in NativeQueue", + groups = {"daily", "serial"}) public void test03EventQueryForTransactionDelegateResource() throws InterruptedException { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] freezeAccount = ecKey1.getAddress(); - String freezeAccountKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + byte[] freezeAccount = ecKey1.getAddress(); + String freezeAccountKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); PublicMethod.printAddress(freezeAccountKey); - ECKey ecKey2 = new ECKey(Utils.getRandom()); - byte[] receiverAddress = ecKey2.getAddress(); - String receiverKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] receiverAddress = ecKey2.getAddress(); + String receiverKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); PublicMethod.printAddress(receiverKey); - Long freezeAmount = maxFeeLimit * 20; + Long freezeAmount = maxFeeLimit * 20; Assert.assertTrue( PublicMethod.sendcoin( freezeAccount, freezeAmount, foundationAddress, foundationKey, blockingStubFull)); @@ -235,17 +249,16 @@ public void test03EventQueryForTransactionDelegateResource() throws InterruptedE PublicMethod.sendcoin( receiverAddress, freezeAmount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.freezeBalanceV2AndGetTxId(freezeAccount, - maxFeeLimit, 0, freezeAccountKey, blockingStubFull); + PublicMethod.freezeBalanceV2AndGetTxId( + freezeAccount, maxFeeLimit, 0, freezeAccountKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); ZMQ.Context context = ZMQ.context(1); ZMQ.Socket req = context.socket(ZMQ.SUB); List transactionIdList = new ArrayList<>(); - req.subscribe("transactionTrigger"); - final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); + final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); moniter.connect("inproc://reqmoniter"); new Thread( new Runnable() { @@ -259,12 +272,13 @@ public void run() { .start(); req.connect(eventnode); req.setReceiveTimeOut(10000); - String transactionMessage = ""; + String transactionMessage = ""; Boolean sendTransaction = true; Integer retryTimes = 20; transactionIdList = new ArrayList<>(); ArrayList messageArray = new ArrayList(); - Thread readLoopThread = new Thread( + Thread readLoopThread = + new Thread( new Runnable() { public void run() { while (true) { @@ -275,19 +289,25 @@ public void run() { }); readLoopThread.start(); boolean success = false; - Long delegateAmount = 10000000L; + Long delegateAmount = 10000000L; while (retryTimes-- > 0) { - if(success) { + if (success) { break; } - String txid = PublicMethod.delegateResourceV2AndGetTxId(freezeAccount, - delegateAmount, 0, receiverAddress, freezeAccountKey, blockingStubFull); + String txid = + PublicMethod.delegateResourceV2AndGetTxId( + freezeAccount, + delegateAmount, + 0, + receiverAddress, + freezeAccountKey, + blockingStubFull); transactionIdList.add(txid); PublicMethod.waitProduceNextBlock(blockingStubFull); try { - for(byte[] message: messageArray) { + for (byte[] message : messageArray) { if (message != null) { transactionMessage = new String(message); logger.info("transaction message:" + transactionMessage); @@ -301,39 +321,41 @@ public void run() { logger.info("find target tx, begin to Assert and abort loop"); logger.info("trxId : " + id); Assert.assertEquals(data.getString("contractType"), "DelegateResourceContract"); - Assert.assertEquals(data.getString("fromAddress"), Base58.encode58Check(freezeAccount)); - Assert.assertEquals(data.getString("toAddress"), Base58.encode58Check(receiverAddress)); + Assert.assertEquals( + data.getString("fromAddress"), Base58.encode58Check(freezeAccount)); + Assert.assertEquals( + data.getString("toAddress"), Base58.encode58Check(receiverAddress)); Assert.assertEquals(data.getString("assetName"), "trx"); Assert.assertEquals(data.getLong("assetAmount"), delegateAmount); success = true; break; } - } } } - } catch (Exception e) { - + } catch (Exception expected) { + // expected } - } logger.info("Final transaction message:" + transactionMessage); logger.info("retryTimes: " + retryTimes); Assert.assertTrue(retryTimes >= 0); } - - @Test(enabled = false, description = "Test new Field for UnDelegateResource in NativeQueue", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Test new Field for UnDelegateResource in NativeQueue", + groups = {"daily", "serial"}) public void test04EventQueryForTransactionUnDelegateResource() throws InterruptedException { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] freezeAccount = ecKey1.getAddress(); - String freezeAccountKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + byte[] freezeAccount = ecKey1.getAddress(); + String freezeAccountKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); PublicMethod.printAddress(freezeAccountKey); - ECKey ecKey2 = new ECKey(Utils.getRandom()); - byte[] receiverAddress = ecKey2.getAddress(); - String receiverKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] receiverAddress = ecKey2.getAddress(); + String receiverKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); PublicMethod.printAddress(receiverKey); - Long freezeAmount = maxFeeLimit * 20; + Long freezeAmount = maxFeeLimit * 20; Assert.assertTrue( PublicMethod.sendcoin( freezeAccount, freezeAmount, foundationAddress, foundationKey, blockingStubFull)); @@ -342,14 +364,14 @@ public void test04EventQueryForTransactionUnDelegateResource() throws Interrupte PublicMethod.sendcoin( receiverAddress, freezeAmount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.freezeBalanceV2AndGetTxId(freezeAccount, - maxFeeLimit, 1, freezeAccountKey, blockingStubFull); + PublicMethod.freezeBalanceV2AndGetTxId( + freezeAccount, maxFeeLimit, 1, freezeAccountKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long delegateAmount = 20000000L; - Long unDelegateAmount = 1000000L; + Long delegateAmount = 20000000L; + Long unDelegateAmount = 1000000L; - PublicMethod.delegateResourceV2AndGetTxId(freezeAccount, - delegateAmount, 1, receiverAddress, freezeAccountKey, blockingStubFull); + PublicMethod.delegateResourceV2AndGetTxId( + freezeAccount, delegateAmount, 1, receiverAddress, freezeAccountKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); List transactionIdList = new ArrayList<>(); @@ -358,7 +380,7 @@ public void test04EventQueryForTransactionUnDelegateResource() throws Interrupte ZMQ.Socket req = context.socket(ZMQ.SUB); req.subscribe("transactionTrigger"); - final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); + final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); moniter.connect("inproc://reqmoniter"); new Thread( new Runnable() { @@ -372,14 +394,20 @@ public void run() { .start(); req.connect(eventnode); req.setReceiveTimeOut(10000); - String transactionMessage = ""; + String transactionMessage = ""; Boolean sendTransaction = true; Integer retryTimes = 20; transactionIdList = new ArrayList<>(); while (retryTimes-- > 0) { if (sendTransaction) { - String txid = PublicMethod.unDelegateResourceV2AndGetTxId(freezeAccount, - unDelegateAmount, 1, receiverAddress, freezeAccountKey, blockingStubFull); + String txid = + PublicMethod.unDelegateResourceV2AndGetTxId( + freezeAccount, + unDelegateAmount, + 1, + receiverAddress, + freezeAccountKey, + blockingStubFull); transactionIdList.add(txid); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -404,26 +432,24 @@ public void run() { logger.info("find target tx, begin to Assert and abort loop"); logger.info("trxId : " + data.getString("transactionId")); Assert.assertEquals(data.getString("contractType"), "UnDelegateResourceContract"); - Assert.assertEquals(data.getString("fromAddress"), Base58.encode58Check(freezeAccount)); - Assert.assertEquals(data.getString("toAddress"), Base58.encode58Check(receiverAddress)); + Assert.assertEquals( + data.getString("fromAddress"), Base58.encode58Check(freezeAccount)); + Assert.assertEquals( + data.getString("toAddress"), Base58.encode58Check(receiverAddress)); Assert.assertEquals(data.getString("assetName"), "trx"); Assert.assertEquals(data.getLong("assetAmount"), unDelegateAmount); break; } - } } else { sendTransaction = true; } - } catch (Exception e) { - + } catch (Exception expected) { + // expected } - } logger.info("Final transaction message:" + transactionMessage); logger.info("retryTimes: " + retryTimes); Assert.assertTrue(retryTimes >= 0); } - - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/MongoEventQuery001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/MongoEventQuery001.java index b6882520..d6b6d539 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/MongoEventQuery001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/MongoEventQuery001.java @@ -4,7 +4,6 @@ import com.mongodb.BasicDBObject; import com.mongodb.client.FindIterable; import com.mongodb.client.MongoCursor; - import java.util.ArrayList; import java.util.List; import lombok.extern.slf4j.Slf4j; @@ -29,7 +28,10 @@ public class MongoEventQuery001 extends MongoBase { private HttpResponse response; List transactionIdList = null; - @Test(enabled = true, description = "Event query for block on mongoDB", groups = {"daily"}) + @Test( + enabled = true, + description = "Event query for block on mongoDB", + groups = {"daily"}) public void test01MongoDbEventQueryForBlock() { FindIterable findIterable = mongoDatabase.getCollection("block").find(); MongoCursor mongoCursor = findIterable.iterator(); @@ -66,16 +68,16 @@ public void test01MongoDbEventQueryForBlock() { Assert.assertTrue(hasTransactions); } - @Test(enabled = true, description = "Event query for solidity on mongoDB", groups = {"daily"}) + @Test( + enabled = true, + description = "Event query for solidity on mongoDB", + groups = {"daily"}) public void test02MongoDbEventQueryForSolidity() { response = HttpMethod.getNowBlockFromSolidity(httpsolidityNode); responseContent = HttpMethod.parseResponseContent(response); Long blockNumber = - responseContent - .getJSONObject("block_header") - .getJSONObject("raw_data") - .getLong("number"); + responseContent.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); BasicDBObject query = new BasicDBObject(); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -98,5 +100,4 @@ public void test02MongoDbEventQueryForSolidity() { logger.info("timeStampFromHttp:" + timeStampFromHttp); Assert.assertEquals(timeStampFromHttp, document.get("timeStamp").toString()); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/MongoEventQuery002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/MongoEventQuery002.java index ffd912c1..26311407 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/MongoEventQuery002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/MongoEventQuery002.java @@ -7,14 +7,16 @@ import com.mongodb.BasicDBObject; import com.mongodb.client.FindIterable; import com.mongodb.client.MongoCursor; - -import java.util.*; +import java.util.HashMap; +import java.util.List; import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; import org.bson.Document; import org.junit.Assert; -import org.testng.annotations.*; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; import org.tron.api.GrpcAPI; import org.tron.protos.Protocol; import stest.tron.wallet.common.client.Configuration; @@ -24,9 +26,7 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.HttpMethod; import stest.tron.wallet.common.client.utils.MongoBase; -import stest.tron.wallet.common.client.utils.ProposalEnum; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Retry; import stest.tron.wallet.common.client.utils.Utils; @Slf4j @@ -220,7 +220,10 @@ public void beforeClass() { PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "MongoDB Event query for transaction", groups = {"daily"}) + @Test( + enabled = true, + description = "MongoDB Event query for transaction", + groups = {"daily"}) public void test01EventQueryForTransaction() throws InterruptedException { BasicDBObject query = new BasicDBObject(); logger.info("deployContractTxId:" + deployContractTxId); @@ -296,23 +299,23 @@ public void test01EventQueryForTransaction() throws InterruptedException { response = HttpMethod.getBlockByNum(httpFullNode, blockNumber); responseContent = HttpMethod.parseResponseContent(response); -/* - index = 2; - transactionIdList = new ArrayList<>(); - for (int i = 0; i < responseContent.getJSONArray("transactions").size(); i++) { - transactionIdList.add( - i, responseContent.getJSONArray("transactions").getJSONObject(i).getString("txID")); - } - txIdIndex0 = transactionIdList.get(0); - logger.info("txIDIndex0:" + txIdIndex0); - txIdIndex2 = transactionIdList.get(2); - logger.info("txIDIndex2:" + txIdIndex2); -*/ + /* + index = 2; + transactionIdList = new ArrayList<>(); + for (int i = 0; i < responseContent.getJSONArray("transactions").size(); i++) { + transactionIdList.add( + i, responseContent.getJSONArray("transactions").getJSONObject(i).getString("txID")); + } + txIdIndex0 = transactionIdList.get(0); + logger.info("txIDIndex0:" + txIdIndex0); + txIdIndex2 = transactionIdList.get(2); + logger.info("txIDIndex2:" + txIdIndex2); + */ query = new BasicDBObject(); - //PublicMethod.waitProduceNextBlock(blockingStubFull); - //txIdIndex0 = txId; - //txIdIndex2 = txId; + // PublicMethod.waitProduceNextBlock(blockingStubFull); + // txIdIndex0 = txId; + // txIdIndex2 = txId; query.put("transactionId", txIdIndex2); findIterable = mongoDatabase.getCollection("transaction").find(query); mongoCursor = findIterable.iterator(); @@ -334,7 +337,7 @@ public void test01EventQueryForTransaction() throws InterruptedException { contractAddressFromHttp, jsonObjectTxIdIndex2, txIdIndex2); query = new BasicDBObject(); - //PublicMethod.waitProduceNextBlock(blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull); query.put("transactionId", txIdIndex0); findIterable = mongoDatabase.getCollection("transaction").find(query); mongoCursor = findIterable.iterator(); @@ -353,7 +356,7 @@ public void test01EventQueryForTransaction() throws InterruptedException { } Assert.assertTrue(retryTimes > 0); JSONObject jsonObjectTxIdIndex0 = JSON.parseObject(document.toJson()); - //expectInformationFromGetTransactionInfoById( + // expectInformationFromGetTransactionInfoById( // jsonObjectTxIdIndex0, jsonObjectTxIdIndex2, txIdIndex0); testNetFee(); @@ -361,7 +364,8 @@ public void test01EventQueryForTransaction() throws InterruptedException { @Test( enabled = true, - description = "MongoDB Event query for transaction of internalTransactionList", groups = {"daily"}) + description = "MongoDB Event query for transaction of internalTransactionList", + groups = {"daily"}) public void test02EventQueryForTransaction() throws InterruptedException { response = HttpMethod.getTransactionInfoById(httpFullNode, txIdForInternalTransaction); responseContent = HttpMethod.parseResponseContent(response); @@ -380,57 +384,62 @@ public void test02EventQueryForTransaction() throws InterruptedException { } catch (Exception e) { Assert.assertTrue(e instanceof NullPointerException); } -// Assert.assertEquals( -// responseContent.getJSONArray("internal_transactions").size(), -// jsonObject.getJSONArray("internalTransactionList").size()); -// -// Optional infoById = null; -// infoById = PublicMethod.getTransactionInfoById(txIdForInternalTransaction, blockingStubFull); -// for (int i = 0; i < size; i++) { -// logger.info("i:" + i); -// JSONObject jsonObjectFromHttp = -// responseContent.getJSONArray("internal_transactions").getJSONObject(i); -// JSONObject jsonObjectFromMongoDb = -// jsonObject.getJSONArray("internalTransactionList").getJSONObject(i); -// Assert.assertEquals( -// jsonObjectFromHttp.getString("hash"), jsonObjectFromMongoDb.getString("hash")); -// if (jsonObjectFromHttp.getJSONArray("callValueInfo").getJSONObject(0).getString("callValue") -// == null) { -// Assert.assertEquals("0", jsonObjectFromMongoDb.getString("callValue")); -// } else { -// Assert.assertEquals( -// jsonObjectFromHttp -// .getJSONArray("callValueInfo") -// .getJSONObject(0) -// .getString("callValue"), -// jsonObjectFromMongoDb.getString("callValue")); -// } -// -// Assert.assertEquals("{}", jsonObjectFromMongoDb.getString("tokenInfo")); -// Assert.assertEquals( -// jsonObjectFromHttp.getString("transferTo_address"), -// jsonObjectFromMongoDb.getString("transferTo_address")); -// Assert.assertEquals( -// jsonObjectFromHttp.getString("caller_address"), -// jsonObjectFromMongoDb.getString("caller_address")); -// Assert.assertEquals("", jsonObjectFromMongoDb.getString("extra")); -// Assert.assertEquals(false, jsonObjectFromMongoDb.getBoolean("rejected")); -// -// Assert.assertEquals( -// ByteArray.toStr(infoById.get().getInternalTransactions(i).getNote().toByteArray()), -// jsonObjectFromMongoDb.getString("note")); -// } + // Assert.assertEquals( + // responseContent.getJSONArray("internal_transactions").size(), + // jsonObject.getJSONArray("internalTransactionList").size()); + // + // Optional infoById = null; + // infoById = PublicMethod.getTransactionInfoById(txIdForInternalTransaction, + // blockingStubFull); + // for (int i = 0; i < size; i++) { + // logger.info("i:" + i); + // JSONObject jsonObjectFromHttp = + // responseContent.getJSONArray("internal_transactions").getJSONObject(i); + // JSONObject jsonObjectFromMongoDb = + // jsonObject.getJSONArray("internalTransactionList").getJSONObject(i); + // Assert.assertEquals( + // jsonObjectFromHttp.getString("hash"), jsonObjectFromMongoDb.getString("hash")); + // if + // (jsonObjectFromHttp.getJSONArray("callValueInfo").getJSONObject(0).getString("callValue") + // == null) { + // Assert.assertEquals("0", jsonObjectFromMongoDb.getString("callValue")); + // } else { + // Assert.assertEquals( + // jsonObjectFromHttp + // .getJSONArray("callValueInfo") + // .getJSONObject(0) + // .getString("callValue"), + // jsonObjectFromMongoDb.getString("callValue")); + // } + // + // Assert.assertEquals("{}", jsonObjectFromMongoDb.getString("tokenInfo")); + // Assert.assertEquals( + // jsonObjectFromHttp.getString("transferTo_address"), + // jsonObjectFromMongoDb.getString("transferTo_address")); + // Assert.assertEquals( + // jsonObjectFromHttp.getString("caller_address"), + // jsonObjectFromMongoDb.getString("caller_address")); + // Assert.assertEquals("", jsonObjectFromMongoDb.getString("extra")); + // Assert.assertEquals(false, jsonObjectFromMongoDb.getBoolean("rejected")); + // + // Assert.assertEquals( + // ByteArray.toStr(infoById.get().getInternalTransactions(i).getNote().toByteArray()), + // jsonObjectFromMongoDb.getString("note")); + // } } - @Test(enabled = true, description = "MongoDB Event query for transaction of transfer TRX.", groups = {"daily"}) + @Test( + enabled = true, + description = "MongoDB Event query for transaction of transfer TRX.", + groups = {"daily"}) public void test03EventQueryForTransaction() throws InterruptedException { txId = HttpMethod.sendCoinGetTxid(httpFullNode, fromAddress, event002Address, amount, testKey002); logger.info("transfer trx Id:" + txId); - //HttpMethod.waitToProduceOneBlock(httpFullNode); + // HttpMethod.waitToProduceOneBlock(httpFullNode); BasicDBObject query = new BasicDBObject(); - //PublicMethod.waitProduceNextBlock(blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull); query.put("transactionId", txId); FindIterable findIterable = mongoDatabase.getCollection("transaction").find(query); @@ -457,7 +466,10 @@ public void test03EventQueryForTransaction() throws InterruptedException { responseContent = HttpMethod.parseResponseContent(response); Long latestSolidifiedBlockNumber = responseContent.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); - logger.info("mongo latestSolidifiedBlockNumber = {}, block chain solid num = {}", jsonObject.getLong("latestSolidifiedBlockNumber"), latestSolidifiedBlockNumber); + logger.info( + "mongo latestSolidifiedBlockNumber = {}, block chain solid num = {}", + jsonObject.getLong("latestSolidifiedBlockNumber"), + latestSolidifiedBlockNumber); Assert.assertTrue( jsonObject.getLong("latestSolidifiedBlockNumber") <= latestSolidifiedBlockNumber); @@ -465,7 +477,10 @@ public void test03EventQueryForTransaction() throws InterruptedException { (latestSolidifiedBlockNumber - jsonObject.getLong("latestSolidifiedBlockNumber")) < 7); } - @Test(enabled = true, description = "MongoDB Event query for transaction of contractCallValue.", groups = {"daily"}) + @Test( + enabled = true, + description = "MongoDB Event query for transaction of contractCallValue.", + groups = {"daily"}) public void test04EventQueryForTransaction() throws InterruptedException { ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] dev001Address = ecKey1.getAddress(); @@ -551,8 +566,9 @@ public void test04EventQueryForTransaction() throws InterruptedException { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); } - Assert.assertTrue(PublicMethod.sendcoin( - user001Address, 2000000000, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 2000000000, fromAddress, testKey002, blockingStubFull)); Assert.assertTrue( PublicMethod.transferAsset( @@ -564,9 +580,9 @@ public void test04EventQueryForTransaction() throws InterruptedException { blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); byte[] transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); - //Assert.assertTrue(PublicMethod.sendcoin( + // Assert.assertTrue(PublicMethod.sendcoin( // transferTokenContractAddress, 5000000, fromAddress, testKey002, blockingStubFull)); - //PublicMethod.waitProduceNextBlock(blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull); tokenId = assetAccountId.toStringUtf8(); tokenValue = 10; @@ -633,7 +649,8 @@ public void test04EventQueryForTransaction() throws InterruptedException { @Test( enabled = true, - description = "MongoDB Event query for transaction of result and contractResult.", groups = {"daily"}) + description = "MongoDB Event query for transaction of result and contractResult.", + groups = {"daily"}) public void test05EventQueryForTransaction() throws InterruptedException { ECKey ecKey3 = new ECKey(Utils.getRandom()); byte[] event003Address = ecKey3.getAddress(); @@ -705,7 +722,10 @@ public void test05EventQueryForTransaction() throws InterruptedException { jsonObject.getString("result")); } - @Test(enabled = true, description = "MongoDB Event query for transaction of data.", groups = {"daily"}) + @Test( + enabled = true, + description = "MongoDB Event query for transaction of data.", + groups = {"daily"}) public void test06EventQueryForTransaction() throws InterruptedException { ECKey ecKey3 = new ECKey(Utils.getRandom()); byte[] event003Address = ecKey3.getAddress(); @@ -746,9 +766,13 @@ private void testNetFee() { useUpFreeBandwidth = 20; while (useUpFreeBandwidth-- > 0) { - PublicMethod.sendcoin( - fromAddress, 1000000L + PublicMethod.randomFreezeAmount.addAndGet(1), event002Address, event002Key, blockingStubFull); - //PublicMethod.waitProduceNextBlock(blockingStubFull); + PublicMethod.sendcoin( + fromAddress, + 1000000L + PublicMethod.randomFreezeAmount.addAndGet(1), + event002Address, + event002Key, + blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull); } PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -811,9 +835,14 @@ private void expectInformationFromGetTransactionInfoById( response = HttpMethod.getTransactionInfoById(httpFullNode, txIdIndex); responseContent = HttpMethod.parseResponseContent(response); - logger.info("expectInformationFromGetTransactionInfoById jsonObjectTxIdIndex0: " + jsonObjectTxIdIndex0.toJSONString()); - //logger.info("expectInformationFromGetTransactionInfoById jsonObjectTxIdIndex2: " + jsonObjectTxIdIndex2.toJSONString()); - logger.info("expectInformationFromGetTransactionInfoById responseContent: " + responseContent.toJSONString()); + logger.info( + "expectInformationFromGetTransactionInfoById jsonObjectTxIdIndex0: " + + jsonObjectTxIdIndex0.toJSONString()); + // logger.info("expectInformationFromGetTransactionInfoById jsonObjectTxIdIndex2: " + + // jsonObjectTxIdIndex2.toJSONString()); + logger.info( + "expectInformationFromGetTransactionInfoById responseContent: " + + responseContent.toJSONString()); logger.info("timestamp:" + responseContent.getString("blockTimeStamp")); logger.info("timestamp:" + jsonObjectTxIdIndex0.getString("timeStamp")); logger.info("contractRetFromHttp:" + responseContent.getJSONArray("contractResult").size()); @@ -840,10 +869,10 @@ private void expectInformationFromGetTransactionInfoById( responseContent.getJSONObject("receipt").getString("energy_usage_total"), jsonObjectTxIdIndex0.getString("energyUsageTotal")); -/* Assert.assertEquals( - String.valueOf( - responseContent.getJSONObject("receipt").getLong("energy_usage_total") * (index + 1)), - jsonObjectTxIdIndex2.getString("cumulativeEnergyUsed"));*/ + /* Assert.assertEquals( + String.valueOf( + responseContent.getJSONObject("receipt").getLong("energy_usage_total") * (index + 1)), + jsonObjectTxIdIndex2.getString("cumulativeEnergyUsed"));*/ Assert.assertEquals( responseContent.getJSONObject("receipt").getString("net_usage"), @@ -888,22 +917,24 @@ private void expectInformationFromGetTransactionInfoById( response = HttpMethod.getBlockByNum(httpFullNode, blockNumber); responseContent = HttpMethod.parseResponseContent(response); -/* - Assert.assertEquals( - String.valueOf(index), - jsonObjectTxIdIndex2 - .getJSONArray("logList") - .getJSONObject(0) - .getString("transactionIndex")); - - Assert.assertEquals(String.valueOf(index), jsonObjectTxIdIndex2.getString("transactionIndex")); - - Assert.assertEquals( - String.valueOf(index * runTimes), jsonObjectTxIdIndex2.getString("preCumulativeLogCount")); - Assert.assertEquals( - String.valueOf(index * runTimes), - jsonObjectTxIdIndex2.getJSONArray("logList").getJSONObject(0).getString("logIndex")); -*/ + /* + Assert.assertEquals( + String.valueOf(index), + jsonObjectTxIdIndex2 + .getJSONArray("logList") + .getJSONObject(0) + .getString("transactionIndex")); + + Assert.assertEquals(String.valueOf(index), + jsonObjectTxIdIndex2.getString("transactionIndex")); + + Assert.assertEquals( + String.valueOf(index * runTimes), jsonObjectTxIdIndex2 + .getString("preCumulativeLogCount")); + Assert.assertEquals( + String.valueOf(index * runTimes), + jsonObjectTxIdIndex2.getJSONArray("logList").getJSONObject(0).getString("logIndex")); + */ Assert.assertEquals( responseContent.getString("blockID"), jsonObjectTxIdIndex0.getString("blockHash")); diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/MongoEventQuery003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/MongoEventQuery003.java index f7ef410c..648adef5 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/MongoEventQuery003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/MongoEventQuery003.java @@ -5,7 +5,6 @@ import com.mongodb.BasicDBObject; import com.mongodb.client.FindIterable; import com.mongodb.client.MongoCursor; - import java.util.HashMap; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; @@ -76,7 +75,11 @@ public void beforeClass() { logger.info("contractAddress:" + contractAddress); } - @Test(enabled = true, priority = 4, description = "MongoDB Event query for contract event", groups = {"daily", "serial"}) + @Test( + enabled = true, + priority = 4, + description = "MongoDB Event query for contract event", + groups = {"daily", "serial"}) public void test01MongoDbEventQueryForContractEvent() { logger.info("event001Key:" + event001Key); ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -126,7 +129,7 @@ public void test01MongoDbEventQueryForContractEvent() { JSONObject jsonObject = JSON.parseObject(document.toJson()); Assert.assertEquals(txid, jsonObject.getString("transactionId")); - //query contractlog to prove redundancy=true is valid + // query contractlog to prove redundancy=true is valid retryTimes = 5; while (retryTimes-- > 0) { PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -141,7 +144,6 @@ public void test01MongoDbEventQueryForContractEvent() { JSONObject jsonObjectLog = JSON.parseObject(documentLog.toJson()); Assert.assertEquals(txid, jsonObjectLog.getString("transactionId")); - Assert.assertEquals("storedNumber", jsonObject.getString("eventName")); Assert.assertEquals( "storedNumber(uint256,uint256,uint256,address)", jsonObject.getString("eventSignature")); @@ -167,8 +169,11 @@ public void test01MongoDbEventQueryForContractEvent() { testLatestSolidifiedBlockNumber(jsonObject); } - @Test(enabled = true, priority = 4, description - = "MongoDb Event query for solidity contract event", groups = {"daily", "serial"}) + @Test( + enabled = true, + priority = 4, + description = "MongoDb Event query for solidity contract event", + groups = {"daily", "serial"}) public void test02MongoDbEventQueryForContractSolidityEvent() { logger.info("event001Key:" + event001Key); ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -196,8 +201,8 @@ public void test02MongoDbEventQueryForContractSolidityEvent() { PublicMethod.waitProduceNextBlock(blockingStubFull); query.put("uniqueId", txid + "_1"); FindIterable findIterable = mongoDatabase.getCollection("solidityevent").find(query); - FindIterable findIterableSolidityLog - = mongoDatabase.getCollection("soliditylog").find(query); + FindIterable findIterableSolidityLog = + mongoDatabase.getCollection("soliditylog").find(query); MongoCursor mongoCursor = findIterable.iterator(); MongoCursor mongoCursorSolidityLog = findIterableSolidityLog.iterator(); @@ -219,8 +224,7 @@ public void test02MongoDbEventQueryForContractSolidityEvent() { JSONObject jsonObject = JSON.parseObject(document.toJson()); Assert.assertEquals(txid, jsonObject.getString("transactionId")); - - //query soliditylog to prove redundancy=true is valid + // query soliditylog to prove redundancy=true is valid retryTimes = 5; while (retryTimes-- > 0) { PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -263,7 +267,6 @@ public void test02MongoDbEventQueryForContractSolidityEvent() { testLatestSolidifiedBlockNumber(jsonObject); } - private void testLatestSolidifiedBlockNumber(JSONObject jsonObject) { HttpMethod.printJsonContent(jsonObject); response = HttpMethod.getNowBlockFromSolidity(httpsolidityNode); @@ -275,8 +278,9 @@ private void testLatestSolidifiedBlockNumber(JSONObject jsonObject) { jsonObject.getLong("latestSolidifiedBlockNumber") < latestSolidifiedBlockNumber); logger.info("latestSolidifiedBlockNumber:" + latestSolidifiedBlockNumber); - logger.info("jsonObject.getLong(\"latestSolidifiedBlockNumber\"):" - + jsonObject.getLong("latestSolidifiedBlockNumber")); + logger.info( + "jsonObject.getLong(\"latestSolidifiedBlockNumber\"):" + + jsonObject.getLong("latestSolidifiedBlockNumber")); Assert.assertTrue( (latestSolidifiedBlockNumber - jsonObject.getLong("latestSolidifiedBlockNumber")) < 10); } @@ -349,5 +353,4 @@ private void expectInformationFromGetBlockByNum(JSONObject jsonObject, String tx responseContent = HttpMethod.parseResponseContent(response); Assert.assertEquals(responseContent.getString("blockID"), jsonObject.getString("blockHash")); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/MongoEventQuery004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/MongoEventQuery004.java index a18fb4cf..e69347b7 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/MongoEventQuery004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/MongoEventQuery004.java @@ -96,7 +96,10 @@ public void beforeClass() { PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "MongoDB log query for contract log", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "MongoDB log query for contract log", + groups = {"daily", "serial"}) public void test01MongoDbEventQueryForContractEvent() { logger.info("event001Key:" + event001Key); ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -166,7 +169,10 @@ public void test01MongoDbEventQueryForContractEvent() { testLatestSolidifiedBlockNumber(jsonObject); } - @Test(enabled = true, description = "MongoDb log query for solidity contract log", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "MongoDb log query for solidity contract log", + groups = {"daily", "serial"}) public void test02MongoDbEventQueryForContractEvent() { logger.info("event001Key:" + event001Key); ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -230,7 +236,8 @@ private void testLatestSolidifiedBlockNumber(JSONObject jsonObject) { Assert.assertTrue( jsonObject.getLong("latestSolidifiedBlockNumber") < latestSolidifiedBlockNumber); logger.info("API latestSolidifiedBlockNumber: " + latestSolidifiedBlockNumber); - logger.info("Event latestSolidifiedBlockNumber: " + jsonObject.getLong("latestSolidifiedBlockNumber")); + logger.info( + "Event latestSolidifiedBlockNumber: " + jsonObject.getLong("latestSolidifiedBlockNumber")); Assert.assertTrue( (latestSolidifiedBlockNumber - jsonObject.getLong("latestSolidifiedBlockNumber")) < 10); } @@ -307,5 +314,4 @@ private void expectInformationFromGetBlockByNum(JSONObject jsonObject, String tx responseContent = HttpMethod.parseResponseContent(response); Assert.assertEquals(responseContent.getString("blockID"), jsonObject.getString("blockHash")); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/MongoEventQuery005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/MongoEventQuery005.java index 0974e9a9..47ac54ba 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/MongoEventQuery005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/MongoEventQuery005.java @@ -5,13 +5,17 @@ import com.mongodb.BasicDBObject; import com.mongodb.client.FindIterable; import com.mongodb.client.MongoCursor; - import lombok.extern.slf4j.Slf4j; import org.bson.Document; import org.junit.Assert; -import org.testng.annotations.*; +import org.testng.annotations.Test; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MongoBase; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MongoEventQuery005 extends MongoBase { @@ -19,9 +23,10 @@ public class MongoEventQuery005 extends MongoBase { public static String httpFullNode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); - - @Test(enabled = true, description = - "MongoDB Event query for new Field in FreezeBalanceV2Contract", groups = {"daily"}) + @Test( + enabled = true, + description = "MongoDB Event query for new Field in FreezeBalanceV2Contract", + groups = {"daily"}) public void test01EventQueryForTransactionFreezeBalanceV2() throws InterruptedException { ECKey ecKey = new ECKey(Utils.getRandom()); byte[] freezeAccount = ecKey.getAddress(); @@ -32,8 +37,9 @@ public void test01EventQueryForTransactionFreezeBalanceV2() throws InterruptedEx freezeAccount, freezeAmount, foundationAddress2, foundationKey2, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = PublicMethod.freezeBalanceV2AndGetTxId(freezeAccount, - maxFeeLimit, 0, freezeAccountKey, blockingStubFull); + String txid = + PublicMethod.freezeBalanceV2AndGetTxId( + freezeAccount, maxFeeLimit, 0, freezeAccountKey, blockingStubFull); BasicDBObject query = new BasicDBObject(); query.put("transactionId", txid); FindIterable findIterable = @@ -60,9 +66,10 @@ public void test01EventQueryForTransactionFreezeBalanceV2() throws InterruptedEx Assert.assertEquals(maxFeeLimit, jsonObject.getLongValue("assetAmount")); } - - @Test(enabled = true, - description = "MongoDB Event query for new Field in UnFreezeBalanceV2Contract", groups = {"daily"}) + @Test( + enabled = true, + description = "MongoDB Event query for new Field in UnFreezeBalanceV2Contract", + groups = {"daily"}) public void test02EventQueryForTransactionUnFreezeBalanceV2() throws InterruptedException { ECKey ecKey = new ECKey(Utils.getRandom()); byte[] freezeAccount = ecKey.getAddress(); @@ -72,11 +79,12 @@ public void test02EventQueryForTransactionUnFreezeBalanceV2() throws Interrupted PublicMethod.sendcoin( freezeAccount, freezeAmount, foundationAddress2, foundationKey2, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.freezeBalanceV2AndGetTxId(freezeAccount, - maxFeeLimit, 0, freezeAccountKey, blockingStubFull); + PublicMethod.freezeBalanceV2AndGetTxId( + freezeAccount, maxFeeLimit, 0, freezeAccountKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = PublicMethod.unFreezeBalanceV2AndGetTxId(freezeAccount, - freezeAccountKey, maxFeeLimit, 0, blockingStubFull); + String txid = + PublicMethod.unFreezeBalanceV2AndGetTxId( + freezeAccount, freezeAccountKey, maxFeeLimit, 0, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); BasicDBObject query = new BasicDBObject(); query.put("transactionId", txid); @@ -105,8 +113,10 @@ public void test02EventQueryForTransactionUnFreezeBalanceV2() throws Interrupted Assert.assertEquals(maxFeeLimit, jsonObject.getLongValue("assetAmount")); } - @Test(enabled = true, - description = "MongoDB Event query for new Field in CancelAllUnFreezeV2Contract", groups = {"daily"}) + @Test( + enabled = true, + description = "MongoDB Event query for new Field in CancelAllUnFreezeV2Contract", + groups = {"daily"}) public void test03EventQueryForTransactionCancelAllUnFreezeV2() throws InterruptedException { ECKey ecKey = new ECKey(Utils.getRandom()); byte[] freezeAccount = ecKey.getAddress(); @@ -117,17 +127,18 @@ public void test03EventQueryForTransactionCancelAllUnFreezeV2() throws Interrupt freezeAccount, freezeAmount, foundationAddress2, foundationKey2, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.freezeBalanceV2AndGetTxId(freezeAccount, - maxFeeLimit, 0, freezeAccountKey, blockingStubFull); + PublicMethod.freezeBalanceV2AndGetTxId( + freezeAccount, maxFeeLimit, 0, freezeAccountKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.unFreezeBalanceV2AndGetTxId(freezeAccount, - freezeAccountKey, maxFeeLimit, 0, blockingStubFull); + PublicMethod.unFreezeBalanceV2AndGetTxId( + freezeAccount, freezeAccountKey, maxFeeLimit, 0, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = PublicMethod.cancelAllUnFreezeBalanceV2AndGetTxid(freezeAccount, freezeAccountKey, - blockingStubFull); + String txid = + PublicMethod.cancelAllUnFreezeBalanceV2AndGetTxid( + freezeAccount, freezeAccountKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - BasicDBObject query = new BasicDBObject(); + BasicDBObject query = new BasicDBObject(); query.put("transactionId", txid); FindIterable findIterable = mongoDatabase.getCollection("transaction").find(query); @@ -151,12 +162,13 @@ public void test03EventQueryForTransactionCancelAllUnFreezeV2() throws Interrupt Assert.assertEquals("CancelAllUnfreezeV2Contract", jsonObject.getString("contractType")); Assert.assertEquals(Base58.encode58Check(freezeAccount), jsonObject.getString("fromAddress")); Assert.assertEquals("trx", jsonObject.getString("assetName")); - Assert.assertEquals(maxFeeLimit, - jsonObject.getJSONObject("extMap").getLongValue("BANDWIDTH")); + Assert.assertEquals(maxFeeLimit, jsonObject.getJSONObject("extMap").getLongValue("BANDWIDTH")); } - @Test(enabled = true, - description = "MongoDB Event query for new Field in DelegateResourceContract", groups = {"daily"}) + @Test( + enabled = true, + description = "MongoDB Event query for new Field in DelegateResourceContract", + groups = {"daily"}) public void test04EventQueryForTransactionDelegateResource() throws InterruptedException { ECKey ecKey = new ECKey(Utils.getRandom()); byte[] freezeAccount = ecKey.getAddress(); @@ -178,11 +190,12 @@ public void test04EventQueryForTransactionDelegateResource() throws InterruptedE receiverAddress, freezeAmount, foundationAddress2, foundationKey2, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.freezeBalanceV2AndGetTxId(freezeAccount, - maxFeeLimit, 0, freezeAccountKey, blockingStubFull); + PublicMethod.freezeBalanceV2AndGetTxId( + freezeAccount, maxFeeLimit, 0, freezeAccountKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = PublicMethod.delegateResourceV2AndGetTxId(freezeAccount, - delegateAmount, 0, receiverAddress, freezeAccountKey, blockingStubFull); + String txid = + PublicMethod.delegateResourceV2AndGetTxId( + freezeAccount, delegateAmount, 0, receiverAddress, freezeAccountKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); BasicDBObject query = new BasicDBObject(); @@ -214,8 +227,10 @@ public void test04EventQueryForTransactionDelegateResource() throws InterruptedE Assert.assertEquals(delegateAmount.longValue(), jsonObject.getLongValue("assetAmount")); } - @Test(enabled = true, - description = "MongoDB Event query for new Field in UnDelegateResourceContract", groups = {"daily"}) + @Test( + enabled = true, + description = "MongoDB Event query for new Field in UnDelegateResourceContract", + groups = {"daily"}) public void test05EventQueryForTransactionUnDelegateResource() throws InterruptedException { ECKey ecKey = new ECKey(Utils.getRandom()); byte[] freezeAccount = ecKey.getAddress(); @@ -237,14 +252,15 @@ public void test05EventQueryForTransactionUnDelegateResource() throws Interrupte receiverAddress, freezeAmount, foundationAddress2, foundationKey2, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.freezeBalanceV2AndGetTxId(freezeAccount, - maxFeeLimit, 0, freezeAccountKey, blockingStubFull); + PublicMethod.freezeBalanceV2AndGetTxId( + freezeAccount, maxFeeLimit, 0, freezeAccountKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.delegateResourceV2AndGetTxId(freezeAccount, - delegateAmount, 0, receiverAddress, freezeAccountKey, blockingStubFull); + PublicMethod.delegateResourceV2AndGetTxId( + freezeAccount, delegateAmount, 0, receiverAddress, freezeAccountKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = PublicMethod.unDelegateResourceV2AndGetTxId(freezeAccount, - delegateAmount, 0, receiverAddress, freezeAccountKey, blockingStubFull); + String txid = + PublicMethod.unDelegateResourceV2AndGetTxId( + freezeAccount, delegateAmount, 0, receiverAddress, freezeAccountKey, blockingStubFull); BasicDBObject query = new BasicDBObject(); query.put("transactionId", txid); @@ -275,8 +291,10 @@ public void test05EventQueryForTransactionUnDelegateResource() throws Interrupte Assert.assertEquals(delegateAmount.longValue(), jsonObject.getLongValue("assetAmount")); } - @Test(enabled = true, - description = "MongoDB Event query for new Field in WithdrawExpireUnfreezeContract", groups = {"daily"}) + @Test( + enabled = true, + description = "MongoDB Event query for new Field in WithdrawExpireUnfreezeContract", + groups = {"daily"}) public void test06EventQueryForTransactionWithdrawExpireUnfreeze() throws InterruptedException { ECKey ecKey = new ECKey(Utils.getRandom()); byte[] freezeAccount = ecKey.getAddress(); @@ -289,16 +307,17 @@ public void test06EventQueryForTransactionWithdrawExpireUnfreeze() throws Interr PublicMethod.sendcoin( freezeAccount, freezeAmount, foundationAddress2, foundationKey2, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.freezeBalanceV2AndGetTxId(freezeAccount, - maxFeeLimit, 0, freezeAccountKey, blockingStubFull); + PublicMethod.freezeBalanceV2AndGetTxId( + freezeAccount, maxFeeLimit, 0, freezeAccountKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.unFreezeBalanceV2AndGetTxId(freezeAccount, - freezeAccountKey, maxFeeLimit, 0, blockingStubFull); + PublicMethod.unFreezeBalanceV2AndGetTxId( + freezeAccount, freezeAccountKey, maxFeeLimit, 0, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Thread.sleep(60000); - String txid = PublicMethod.withdrawExpireUnfreezeAndGetTxId(freezeAccount, - freezeAccountKey, blockingStubFull); + String txid = + PublicMethod.withdrawExpireUnfreezeAndGetTxId( + freezeAccount, freezeAccountKey, blockingStubFull); BasicDBObject query = new BasicDBObject(); query.put("transactionId", txid); FindIterable findIterable = @@ -325,6 +344,4 @@ public void test06EventQueryForTransactionWithdrawExpireUnfreeze() throws Interr Assert.assertEquals("trx", jsonObject.getString("assetName")); Assert.assertEquals(maxFeeLimit, jsonObject.getLongValue("assetAmount")); } - - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/example/ExampleTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/example/ExampleTest.java index e281c728..385bf69d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/example/ExampleTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/example/ExampleTest.java @@ -18,13 +18,14 @@ * Example test class demonstrating best practices for TRON system tests. * *

Key patterns shown: + * *

    *
  • Extend {@link TronBaseTest} - provides channelFull, blockingStubFull, - * foundationKey/Address, witnessKey/Address, maxFeeLimit
  • - *
  • Use {@link TronConstants} - eliminates magic numbers
  • - *
  • Use {@link RetryUtil} - replaces manual retry loops
  • - *
  • Use Helper classes - AccountHelper, ContractHelper, etc.
  • - *
  • Use TestNG groups - for selective test execution
  • + * foundationKey/Address, witnessKey/Address, maxFeeLimit + *
  • Use {@link TronConstants} - eliminates magic numbers + *
  • Use {@link RetryUtil} - replaces manual retry loops + *
  • Use Helper classes - AccountHelper, ContractHelper, etc. + *
  • Use TestNG groups - for selective test execution *
*/ @Slf4j @@ -36,47 +37,59 @@ public class ExampleTest extends TronBaseTest { private String testKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); /** - * Setup: fund the test account from foundation. - * Note: channelFull and blockingStubFull are already initialized by TronBaseTest. + * Setup: fund the test account from foundation. Note: channelFull and blockingStubFull are + * already initialized by TronBaseTest. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(testKey); - Assert.assertTrue(PublicMethod.sendcoin(testAddress, TronConstants.TEN_TRX, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress, + TronConstants.TEN_TRX, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Verify test account received funds", + @Test( + enabled = true, + description = "Verify test account received funds", groups = {"daily", "smoke"}) public void test01AccountBalance() { Account account = PublicMethod.queryAccount(testAddress, blockingStubFull); - Assert.assertTrue(account.getBalance() > 0, - "Test account should have positive balance after funding"); + Assert.assertTrue( + account.getBalance() > 0, "Test account should have positive balance after funding"); logger.info("Test account balance: {} sun", account.getBalance()); } - @Test(enabled = true, description = "Transfer TRX and verify with RetryUtil", + @Test( + enabled = true, + description = "Transfer TRX and verify with RetryUtil", groups = {"daily"}) public void test02TransferWithRetry() { ECKey receiver = new ECKey(Utils.getRandom()); long amount = TronConstants.ONE_TRX; - Assert.assertTrue(PublicMethod.sendcoin(receiver.getAddress(), amount, - testAddress, testKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + receiver.getAddress(), amount, testAddress, testKey, blockingStubFull)); // Use RetryUtil instead of manual while + Thread.sleep loops - boolean confirmed = RetryUtil.waitUntil(() -> { - Account account = PublicMethod.queryAccount(receiver.getAddress(), blockingStubFull); - return account.getBalance() >= amount; - }); + boolean confirmed = + RetryUtil.waitUntil( + () -> { + Account account = PublicMethod.queryAccount(receiver.getAddress(), blockingStubFull); + return account.getBalance() >= amount; + }); Assert.assertTrue(confirmed, "Receiver should have received TRX within retry window"); } /** - * Cleanup: return remaining funds to foundation. - * Note: channel shutdown is handled automatically by TronBaseTest.closeChannels(). + * Cleanup: return remaining funds to foundation. Note: channel shutdown is handled automatically + * by TronBaseTest.closeChannels(). */ @AfterClass(enabled = true) public void afterClass() { diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/exceptionfee/AssertException.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/exceptionfee/AssertException.java index 13854e34..a15ce794 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/exceptionfee/AssertException.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/exceptionfee/AssertException.java @@ -20,17 +20,17 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class AssertException extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -38,64 +38,83 @@ public class AssertException extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = true, description = "Trigger contract Divide 0", groups = {"daily"}) + @Test( + enabled = true, + description = "Trigger contract Divide 0", + groups = {"daily"}) public void test1DivideInt() { PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 100000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/assertExceptiontest1DivideInt.sol"; - String contractName = "divideIHaveArgsReturnStorage"; + String filePath = "src/test/resources/soliditycode/assertExceptiontest1DivideInt.sol"; + String contractName = "divideIHaveArgsReturnStorage"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); Account info; PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - String num = "4" + "," + "0"; - - txid = PublicMethod.triggerContract(contractAddress, - "divideIHaveArgsReturn(int256,int256)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "4" + "," + "0"; + + txid = + PublicMethod.triggerContract( + contractAddress, + "divideIHaveArgsReturn(int256,int256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull1); Optional infoById = null; @@ -107,31 +126,31 @@ public void test1DivideInt() { logger.info("getContractRetValue:" + ById.get().getRet(0).getContractRetValue()); logger.info("getContractRet:" + ById.get().getRet(0).getContractRet()); - Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(), - contractResult.REVERT.getNumber()); + Assert.assertEquals( + ById.get().getRet(0).getContractRet().getNumber(), contractResult.REVERT.getNumber()); Assert.assertEquals(ById.get().getRet(0).getContractRetValue(), 2); Assert.assertEquals(ById.get().getRet(0).getContractRet(), contractResult.REVERT); - Assert - .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), - "4e487b710000000000000000000000000000000000000000000000000000000000000012"); + Assert.assertEquals( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), + "4e487b710000000000000000000000000000000000000000000000000000000000000012"); Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("energyUsed:" + energyUsed); logger.info("netFee:" + netFee); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -143,44 +162,65 @@ public void test1DivideInt() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "Trigger contract index out of bounds", groups = {"daily"}) + @Test( + enabled = true, + description = "Trigger contract index out of bounds", + groups = {"daily"}) public void test2FindArgsContractMinTest() { String filePath = "src/test/resources/soliditycode/assertExceptiontest2FindArgsContractMinTest.sol"; - String contractName = "findArgsIContract"; + String contractName = "findArgsIContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("11:" + Base58.encode58Check(contractAddress)); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; + String txid = ""; Integer triggerNum = -1; - txid = PublicMethod.triggerContract(contractAddress, - "findArgsByIndex1(uint256)", triggerNum.toString(), false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "findArgsByIndex1(uint256)", + triggerNum.toString(), + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull1); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -188,12 +228,12 @@ public void test2FindArgsContractMinTest() { logger.info("netFee:" + netFee); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -203,45 +243,65 @@ public void test2FindArgsContractMinTest() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - } - @Test(enabled = true, description = "Trigger contract Bytes array index out of bounds", groups = {"daily"}) + @Test( + enabled = true, + description = "Trigger contract Bytes array index out of bounds", + groups = {"daily"}) public void test3ByteMinContract() { String filePath = "src/test/resources/soliditycode/assertExceptiontest3ByteMinContract.sol"; - String contractName = "byteContract"; + String contractName = "byteContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; + String txid = ""; Integer triggerNum = -1; - txid = PublicMethod.triggerContract(contractAddress, - "testBytesGet(uint256)", triggerNum.toString(), false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "testBytesGet(uint256)", + triggerNum.toString(), + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull1); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -249,13 +309,13 @@ public void test3ByteMinContract() { logger.info("netFee:" + netFee); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -265,47 +325,67 @@ public void test3ByteMinContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - } - @Test(enabled = true, description = "Trigger contract convert too large value to enumerated type", groups = {"daily"}) + @Test( + enabled = true, + description = "Trigger contract convert too large value to enumerated type", + groups = {"daily"}) public void test4Enum() { String filePath = "src/test/resources/soliditycode/assertExceptiontest4Enum.sol"; - String contractName = "enumContract"; + String contractName = "enumContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; + String txid = ""; Integer triggerNum = 22; - txid = PublicMethod.triggerContract(contractAddress, - "setGoStraight(uint8)", triggerNum.toString(), false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "setGoStraight(uint8)", + triggerNum.toString(), + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull1); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -313,12 +393,12 @@ public void test4Enum() { logger.info("netFee:" + netFee); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -331,46 +411,67 @@ public void test4Enum() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = false, description = "Trigger contract move a negative value to a binary", groups = {"daily"}) + @Test( + enabled = false, + description = "Trigger contract move a negative value to a binary", + groups = {"daily"}) public void test5MoveRight() { String filePath = "src/test/resources/soliditycode/assertExceptiontest5MoveRight.sol"; - String contractName = "binaryRightContract"; + String contractName = "binaryRightContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull1); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; + String txid = ""; Integer triggerNum = -1; - txid = PublicMethod.triggerContract(contractAddress, - "binaryMoveR(uint256)", triggerNum.toString(), false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "binaryMoveR(uint256)", + triggerNum.toString(), + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -378,12 +479,12 @@ public void test5MoveRight() { logger.info("netFee:" + netFee); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -396,45 +497,65 @@ public void test5MoveRight() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "Trigger contract Call an uninitialized " - + "internal function type variable", groups = {"daily"}) + @Test( + enabled = true, + description = "Trigger contract Call an uninitialized " + "internal function type variable", + groups = {"daily"}) public void test6UninitializedContract() { String filePath = "src/test/resources/soliditycode/assertExceptiontest6UninitializedContract.sol"; - String contractName = "uni"; + String contractName = "uni"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - - txid = PublicMethod.triggerContract(contractAddress, - "test2()", "#", false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + + txid = + PublicMethod.triggerContract( + contractAddress, + "test2()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -442,12 +563,12 @@ public void test6UninitializedContract() { logger.info("netFee:" + netFee); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -458,45 +579,65 @@ public void test6UninitializedContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - } - @Test(enabled = true, description = "Trigger contract assert exception", groups = {"daily"}) + @Test( + enabled = true, + description = "Trigger contract assert exception", + groups = {"daily"}) public void test7TestAssertContract() { String filePath = "src/test/resources/soliditycode/assertExceptiontest7TestAssertContract.sol"; - String contractName = "TestThrowsContract"; + String contractName = "TestThrowsContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - txid = PublicMethod.triggerContract(contractAddress, - "testAssert()", "#", false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testAssert()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -504,13 +645,13 @@ public void test7TestAssertContract() { logger.info("netFee:" + netFee); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -522,15 +663,13 @@ public void test7TestAssertContract() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/DelegateResourceEdgeTest001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/DelegateResourceEdgeTest001.java index 4dec9fbd..d935dbbc 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/DelegateResourceEdgeTest001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/DelegateResourceEdgeTest001.java @@ -6,7 +6,6 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.tron.api.GrpcAPI.AccountResourceMessage; import org.tron.protos.Protocol.Account; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; @@ -18,8 +17,8 @@ /** * TIP-157: Resource delegation edge case tests. * - *

Tests boundary conditions for delegating bandwidth/energy resources - * including zero amounts, self-delegation, and insufficient balance. + *

Tests boundary conditions for delegating bandwidth/energy resources including zero amounts, + * self-delegation, and insufficient balance. */ @Slf4j public class DelegateResourceEdgeTest001 extends TronBaseTest { @@ -38,80 +37,151 @@ public void beforeClass() { throw new SkipException("Skipping FreezeV2 delegation test - proposal not open"); } - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, TronConstants.TEN_THOUSAND_TRX, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(receiverAddress, TronConstants.TEN_TRX, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, + TronConstants.TEN_THOUSAND_TRX, + foundationAddress, + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + receiverAddress, + TronConstants.TEN_TRX, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); // Freeze bandwidth for delegation - Assert.assertTrue(PublicMethod.freezeBalanceV2(ownerAddress, TronConstants.THOUSAND_TRX, - TronConstants.FREEZE_BANDWIDTH, ownerKeyStr, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + ownerAddress, + TronConstants.THOUSAND_TRX, + TronConstants.FREEZE_BANDWIDTH, + ownerKeyStr, + blockingStubFull)); // Freeze energy for delegation - Assert.assertTrue(PublicMethod.freezeBalanceV2(ownerAddress, TronConstants.THOUSAND_TRX, - TronConstants.FREEZE_ENERGY, ownerKeyStr, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + ownerAddress, + TronConstants.THOUSAND_TRX, + TronConstants.FREEZE_ENERGY, + ownerKeyStr, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Delegate bandwidth resource to another account", + @Test( + enabled = true, + description = "Delegate bandwidth resource to another account", groups = {"daily", "staking"}) public void test01DelegateBandwidth() { long delegateAmount = TronConstants.HUNDRED_TRX; - Assert.assertTrue(PublicMethod.delegateResourceV2(ownerAddress, delegateAmount, - TronConstants.FREEZE_BANDWIDTH, receiverAddress, ownerKeyStr, blockingStubFull)); + Assert.assertTrue( + PublicMethod.delegateResourceV2( + ownerAddress, + delegateAmount, + TronConstants.FREEZE_BANDWIDTH, + receiverAddress, + ownerKeyStr, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account receiverAccount = PublicMethod.queryAccount(receiverAddress, blockingStubFull); - Assert.assertTrue(receiverAccount.getAcquiredDelegatedFrozenV2BalanceForBandwidth() > 0, + Assert.assertTrue( + receiverAccount.getAcquiredDelegatedFrozenV2BalanceForBandwidth() > 0, "Receiver should have acquired delegated bandwidth"); - logger.info("Receiver acquired bandwidth: {}", + logger.info( + "Receiver acquired bandwidth: {}", receiverAccount.getAcquiredDelegatedFrozenV2BalanceForBandwidth()); } - @Test(enabled = true, description = "Delegate energy resource to another account", + @Test( + enabled = true, + description = "Delegate energy resource to another account", groups = {"daily", "staking"}) public void test02DelegateEnergy() { long delegateAmount = TronConstants.HUNDRED_TRX; - Assert.assertTrue(PublicMethod.delegateResourceV2(ownerAddress, delegateAmount, - TronConstants.FREEZE_ENERGY, receiverAddress, ownerKeyStr, blockingStubFull)); + Assert.assertTrue( + PublicMethod.delegateResourceV2( + ownerAddress, + delegateAmount, + TronConstants.FREEZE_ENERGY, + receiverAddress, + ownerKeyStr, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account receiverAccount = PublicMethod.queryAccount(receiverAddress, blockingStubFull); - Assert.assertTrue(receiverAccount.getAccountResource().getAcquiredDelegatedFrozenV2BalanceForEnergy() > 0, + Assert.assertTrue( + receiverAccount.getAccountResource().getAcquiredDelegatedFrozenV2BalanceForEnergy() > 0, "Receiver should have acquired delegated energy"); } - @Test(enabled = true, description = "Delegate zero amount should fail", + @Test( + enabled = true, + description = "Delegate zero amount should fail", groups = {"daily", "staking"}) public void test03DelegateZeroAmount() { - Assert.assertFalse(PublicMethod.delegateResourceV2(ownerAddress, 0, - TronConstants.FREEZE_BANDWIDTH, receiverAddress, ownerKeyStr, blockingStubFull), + Assert.assertFalse( + PublicMethod.delegateResourceV2( + ownerAddress, + 0, + TronConstants.FREEZE_BANDWIDTH, + receiverAddress, + ownerKeyStr, + blockingStubFull), "Delegating zero amount should fail"); } - @Test(enabled = true, description = "Delegate to self should fail", + @Test( + enabled = true, + description = "Delegate to self should fail", groups = {"daily", "staking"}) public void test04DelegateToSelf() { - Assert.assertFalse(PublicMethod.delegateResourceV2(ownerAddress, TronConstants.ONE_TRX, - TronConstants.FREEZE_BANDWIDTH, ownerAddress, ownerKeyStr, blockingStubFull), + Assert.assertFalse( + PublicMethod.delegateResourceV2( + ownerAddress, + TronConstants.ONE_TRX, + TronConstants.FREEZE_BANDWIDTH, + ownerAddress, + ownerKeyStr, + blockingStubFull), "Delegating to self should fail"); } - @Test(enabled = true, description = "Delegate more than frozen should fail", + @Test( + enabled = true, + description = "Delegate more than frozen should fail", groups = {"daily", "staking"}) public void test05DelegateExceedingFrozen() { long excessiveAmount = TronConstants.TEN_THOUSAND_TRX; - Assert.assertFalse(PublicMethod.delegateResourceV2(ownerAddress, excessiveAmount, - TronConstants.FREEZE_BANDWIDTH, receiverAddress, ownerKeyStr, blockingStubFull), + Assert.assertFalse( + PublicMethod.delegateResourceV2( + ownerAddress, + excessiveAmount, + TronConstants.FREEZE_BANDWIDTH, + receiverAddress, + ownerKeyStr, + blockingStubFull), "Delegating more than frozen amount should fail"); } - @Test(enabled = true, description = "Undelegate resource", + @Test( + enabled = true, + description = "Undelegate resource", groups = {"daily", "staking"}) public void test06UndelegateResource() { long undelegateAmount = TronConstants.HUNDRED_TRX; - Assert.assertTrue(PublicMethod.unDelegateResourceV2(ownerAddress, undelegateAmount, - TronConstants.FREEZE_BANDWIDTH, receiverAddress, ownerKeyStr, blockingStubFull), + Assert.assertTrue( + PublicMethod.unDelegateResourceV2( + ownerAddress, + undelegateAmount, + TronConstants.FREEZE_BANDWIDTH, + receiverAddress, + ownerKeyStr, + blockingStubFull), "Undelegating should succeed"); PublicMethod.waitProduceNextBlock(blockingStubFull); } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/DelegateResourceV2TimestampTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/DelegateResourceV2TimestampTest.java index 39decc3d..e1a7647a 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/DelegateResourceV2TimestampTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/DelegateResourceV2TimestampTest.java @@ -1,7 +1,6 @@ package stest.tron.wallet.dailybuild.freezeV2; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.List; import lombok.extern.slf4j.Slf4j; @@ -15,12 +14,10 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; - /** - * - */ +/** */ @Slf4j public class DelegateResourceV2TimestampTest extends TronBaseTest { private static final long sendAmount = 100000000L; @@ -38,16 +35,12 @@ public class DelegateResourceV2TimestampTest extends TronBaseTest { byte[] receiver2Address = ecKey3.getAddress(); String receiver2Key = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); private String soliditynode = - Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list") - .get(0); + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFullSolidity = null; private String pbftnode = - Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list") - .get(2); + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(2); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() throws Exception { initPbftChannel(); @@ -56,79 +49,108 @@ public void beforeClass() throws Exception { PublicMethod.printAddress(receiver1Key); PublicMethod.printAddress(receiver2Key); - PublicMethod.printAddress(receiver3Key); if (!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { throw new SkipException("Skipping freezeV2 test case"); + PublicMethod.printAddress(receiver3Key); + if (!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + throw new SkipException("Skipping freezeV2 test case"); } - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubFullSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - channelPbft = ManagedChannelBuilder.forTarget(pbftnode) - .usePlaintext() - .build(); - Assert.assertTrue(PublicMethod.sendcoin(frozen1Address, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); - - Assert.assertTrue(PublicMethod.sendcoin(receiver1Address, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(receiver2Address, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(receiver3Address, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); + channelPbft = ManagedChannelBuilder.forTarget(pbftnode).usePlaintext().build(); + Assert.assertTrue( + PublicMethod.sendcoin( + frozen1Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.sendcoin( + receiver1Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + receiver2Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + receiver3Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceV2(frozen1Address, frozenAmount, 0, - frozen1Key, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceV2(receiver1Address, frozenAmount, 0, - receiver1Key, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceV2(receiver2Address, frozenAmount, 0, - receiver2Key, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceV2(receiver3Address, frozenAmount, 0, - receiver3Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + frozen1Address, frozenAmount, 0, frozen1Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + receiver1Address, frozenAmount, 0, receiver1Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + receiver2Address, frozenAmount, 0, receiver2Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + receiver3Address, frozenAmount, 0, receiver3Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.delegateResourceV2(frozen1Address, frozenAmount / 10, - 0, receiver1Address, frozen1Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.delegateResourceV2( + frozen1Address, frozenAmount / 10, 0, receiver1Address, frozen1Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.delegateResourceV2(frozen1Address, frozenAmount / 10, - 0, receiver2Address, frozen1Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.delegateResourceV2( + frozen1Address, frozenAmount / 10, 0, receiver2Address, frozen1Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.delegateResourceV2(frozen1Address, frozenAmount / 10, - 0, receiver3Address, frozen1Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.delegateResourceV2( + frozen1Address, frozenAmount / 10, 0, receiver3Address, frozen1Key, blockingStubFull)); - Assert.assertTrue(PublicMethod.delegateResourceV2(receiver1Address, frozenAmount / 10, - 0, frozen1Address, receiver1Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.delegateResourceV2( + receiver1Address, + frozenAmount / 10, + 0, + frozen1Address, + receiver1Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.delegateResourceV2(receiver2Address, frozenAmount / 10, - 0, frozen1Address, receiver2Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.delegateResourceV2( + receiver2Address, + frozenAmount / 10, + 0, + frozen1Address, + receiver2Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.delegateResourceV2(receiver3Address, frozenAmount / 10, - 0, frozen1Address, receiver3Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.delegateResourceV2( + receiver3Address, + frozenAmount / 10, + 0, + frozen1Address, + receiver3Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "GetDelegateResource to account sort by timestamp", groups = {"daily", "staking"}) + @Test( + enabled = true, + description = "GetDelegateResource to account sort by timestamp", + groups = {"daily", "staking"}) public void test01GetDelegateResourceToAccountTimestamp() { - List toAccountList = PublicMethod.getDelegatedResourceAccountIndex( - frozen1Address, - blockingStubFull - ).get().getToAccountsList(); - //query solidity + List toAccountList = + PublicMethod.getDelegatedResourceAccountIndex(frozen1Address, blockingStubFull) + .get() + .getToAccountsList(); + // query solidity PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubFullSolidity); List toAccountListSolidity = PublicMethod.getDelegatedResourceAccountIndexV2Solidity( - frozen1Address, - blockingStubFullSolidity - ).get().getToAccountsList(); + frozen1Address, blockingStubFullSolidity) + .get() + .getToAccountsList(); Assert.assertEquals(toAccountListSolidity, toAccountList); - //query pbft + // query pbft PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubPbft); List toAccountListPbft = - PublicMethod.getDelegatedResourceAccountIndexV2Solidity( - frozen1Address, - blockingStubPbft - ).get().getToAccountsList(); + PublicMethod.getDelegatedResourceAccountIndexV2Solidity(frozen1Address, blockingStubPbft) + .get() + .getToAccountsList(); Assert.assertEquals(toAccountListPbft, toAccountList); Assert.assertTrue(toAccountList.size() == 3); @@ -136,47 +158,45 @@ public void test01GetDelegateResourceToAccountTimestamp() { Assert.assertEquals(toAccountList.get(1).toByteArray(), receiver2Address); Assert.assertEquals(toAccountList.get(2).toByteArray(), receiver3Address); - - Assert.assertTrue(PublicMethod.delegateResourceV2(frozen1Address, frozenAmount / 10, - 0, receiver1Address, frozen1Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.delegateResourceV2( + frozen1Address, frozenAmount / 10, 0, receiver1Address, frozen1Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - - toAccountList = PublicMethod.getDelegatedResourceAccountIndex( - frozen1Address, - blockingStubFull - ).get().getToAccountsList(); + toAccountList = + PublicMethod.getDelegatedResourceAccountIndex(frozen1Address, blockingStubFull) + .get() + .getToAccountsList(); Assert.assertTrue(toAccountList.size() == 3); Assert.assertEquals(toAccountList.get(0).toByteArray(), receiver2Address); Assert.assertEquals(toAccountList.get(1).toByteArray(), receiver3Address); Assert.assertEquals(toAccountList.get(2).toByteArray(), receiver1Address); - - } - - @Test(enabled = true, description = "GetDelegateResource from account sort by timestamp", groups = {"daily", "staking"}) + @Test( + enabled = true, + description = "GetDelegateResource from account sort by timestamp", + groups = {"daily", "staking"}) public void test02GetDelegateResourceFromAccountTimestamp() { - List fromAccountList = PublicMethod.getDelegatedResourceAccountIndex( - frozen1Address, - blockingStubFull - ).get().getFromAccountsList(); - //query solidity + List fromAccountList = + PublicMethod.getDelegatedResourceAccountIndex(frozen1Address, blockingStubFull) + .get() + .getFromAccountsList(); + // query solidity PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubFullSolidity); List fromAccountListSolidity = PublicMethod.getDelegatedResourceAccountIndexV2Solidity( - frozen1Address, - blockingStubFullSolidity - ).get().getFromAccountsList(); + frozen1Address, blockingStubFullSolidity) + .get() + .getFromAccountsList(); Assert.assertEquals(fromAccountListSolidity, fromAccountList); - //query pbft + // query pbft PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubPbft); List fromAccountListPbft = - PublicMethod.getDelegatedResourceAccountIndexV2Solidity( - frozen1Address, - blockingStubPbft - ).get().getFromAccountsList(); + PublicMethod.getDelegatedResourceAccountIndexV2Solidity(frozen1Address, blockingStubPbft) + .get() + .getFromAccountsList(); Assert.assertEquals(fromAccountListPbft, fromAccountList); Assert.assertTrue(fromAccountList.size() == 3); @@ -184,41 +204,31 @@ public void test02GetDelegateResourceFromAccountTimestamp() { Assert.assertEquals(fromAccountList.get(1).toByteArray(), receiver2Address); Assert.assertEquals(fromAccountList.get(2).toByteArray(), receiver3Address); - Assert.assertTrue( PublicMethod.delegateResourceV2( - receiver1Address, - frozenAmount / 10, - 0, - frozen1Address, - receiver1Key, - blockingStubFull - ) - ); + receiver1Address, + frozenAmount / 10, + 0, + frozen1Address, + receiver1Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - fromAccountList = PublicMethod.getDelegatedResourceAccountIndex( - frozen1Address, - blockingStubFull - ).get().getToAccountsList(); + fromAccountList = + PublicMethod.getDelegatedResourceAccountIndex(frozen1Address, blockingStubFull) + .get() + .getToAccountsList(); Assert.assertTrue(fromAccountList.size() == 3); Assert.assertEquals(fromAccountList.get(0).toByteArray(), receiver2Address); Assert.assertEquals(fromAccountList.get(1).toByteArray(), receiver3Address); Assert.assertEquals(fromAccountList.get(2).toByteArray(), receiver1Address); - - } - - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { PublicMethod.freeResource(frozen1Address, frozen1Key, foundationAddress, blockingStubFull); PublicMethod.freeResource(receiver1Address, receiver1Key, foundationAddress, blockingStubFull); PublicMethod.freeResource(receiver2Address, receiver2Key, foundationAddress, blockingStubFull); - PublicMethod.freeResource(receiver3Address, receiver3Key, foundationAddress, blockingStubFull); } + PublicMethod.freeResource(receiver3Address, receiver3Key, foundationAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test001.java index 6e62ffcb..d6a195c1 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test001.java @@ -1,10 +1,7 @@ package stest.tron.wallet.dailybuild.freezeV2; import com.google.protobuf.Any; -import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; -import java.util.HashMap; import lombok.extern.slf4j.Slf4j; import org.testng.Assert; import org.testng.SkipException; @@ -16,20 +13,20 @@ import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.TransactionInfo; -import org.tron.protos.contract.AccountContract.AccountPermissionUpdateContract; import org.tron.protos.contract.BalanceContract.FreezeBalanceV2Contract; import org.tron.protos.contract.BalanceContract.UnfreezeBalanceV2Contract; import org.tron.protos.contract.BalanceContract.WithdrawExpireUnfreezeContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.Flaky; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -@Flaky(reason = "Timing-sensitive: depends on maintenance interval and unfreeze wait period", +@Flaky( + reason = "Timing-sensitive: depends on maintenance interval and unfreeze wait period", since = "2026-04-03") public class FreezeBalanceV2Test001 extends TronBaseTest { private static final long sendAmount = 10000000000L; @@ -43,60 +40,61 @@ public class FreezeBalanceV2Test001 extends TronBaseTest { Long freezeBandwidthBalance = 2000000L; Long freezeEnergyBalance = 3000000L; private String soliditynode = - Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list") - .get(0); + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFullSolidity = null; private String pbftnode = - Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list") - .get(2); + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(2); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() throws Exception { initPbftChannel(); initSolidityChannel(); - PublicMethod.printAddress(frozenBandwidthKey); if (!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { throw new SkipException("Skipping freezeV2 test case"); + PublicMethod.printAddress(frozenBandwidthKey); + if (!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + throw new SkipException("Skipping freezeV2 test case"); } - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubFullSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - channelPbft = ManagedChannelBuilder.forTarget(pbftnode) - .usePlaintext() - .build(); - Assert.assertTrue(PublicMethod.sendcoin(frozenBandwidthAddress, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(frozenEnergyAddress, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); + channelPbft = ManagedChannelBuilder.forTarget(pbftnode).usePlaintext().build(); + Assert.assertTrue( + PublicMethod.sendcoin( + frozenBandwidthAddress, + sendAmount, + foundationAddress, + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + frozenEnergyAddress, sendAmount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - - } - - /** - * constructor. - */ - @Test(enabled = true, description = "Freeze balance to get bandwidth", groups = {"daily", "staking"}) + /** constructor. */ + @Test( + enabled = true, + description = "Freeze balance to get bandwidth", + groups = {"daily", "staking"}) public void test01FreezeBalanceV2GetBandwidth() throws Exception { - AccountResourceMessage accountResource = PublicMethod - .getAccountResource(frozenBandwidthAddress, blockingStubFull); - final Long beforeTotalNetWeight = accountResource.getTotalNetWeight(); - String txId = PublicMethod.freezeBalanceV2AndGetTxId(frozenBandwidthAddress, - freezeBandwidthBalance, 0, frozenBandwidthKey, blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(frozenBandwidthAddress, blockingStubFull); + final Long beforeTotalNetWeight = accountResource.getTotalNetWeight(); + String txId = + PublicMethod.freezeBalanceV2AndGetTxId( + frozenBandwidthAddress, + freezeBandwidthBalance, + 0, + frozenBandwidthKey, + blockingStubFull); Assert.assertNotNull(txId); PublicMethod.waitProduceNextBlock(blockingStubFull); - Transaction transaction = - PublicMethod.getTransactionById(txId, blockingStubFull).get(); + Transaction transaction = PublicMethod.getTransactionById(txId, blockingStubFull).get(); Any any = transaction.getRawData().getContract(0).getParameter(); - FreezeBalanceV2Contract freezeBalanceV2Contract - = any.unpack(FreezeBalanceV2Contract.class); + FreezeBalanceV2Contract freezeBalanceV2Contract = any.unpack(FreezeBalanceV2Contract.class); Assert.assertTrue(freezeBalanceV2Contract.getFrozenBalance() == freezeBandwidthBalance); - Assert.assertEquals(freezeBalanceV2Contract.getOwnerAddress().toByteArray(), - frozenBandwidthAddress); + Assert.assertEquals( + freezeBalanceV2Contract.getOwnerAddress().toByteArray(), frozenBandwidthAddress); Assert.assertTrue(freezeBalanceV2Contract.getResourceValue() == 0); Account account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); @@ -105,233 +103,232 @@ public void test01FreezeBalanceV2GetBandwidth() throws Exception { Assert.assertTrue(account.getFrozenV2(0).getAmount() == freezeBandwidthBalance); Assert.assertTrue(account.getFrozenV2(0).getTypeValue() == 0); - accountResource = PublicMethod - .getAccountResource(frozenBandwidthAddress, blockingStubFull); - final Long afterTotalNetWeight = accountResource.getTotalNetWeight(); - final Long afterNetLimit = accountResource.getNetLimit(); + accountResource = PublicMethod.getAccountResource(frozenBandwidthAddress, blockingStubFull); + final Long afterTotalNetWeight = accountResource.getTotalNetWeight(); + final Long afterNetLimit = accountResource.getNetLimit(); Assert.assertTrue(afterNetLimit > 0); } - /** - * constructor. - */ - @Test(enabled = true, description = "Freeze balance to get energy", groups = {"daily", "staking"}) + /** constructor. */ + @Test( + enabled = true, + description = "Freeze balance to get energy", + groups = {"daily", "staking"}) public void test02FreezeBalanceV2GetEnergy() throws Exception { - AccountResourceMessage accountResource = PublicMethod - .getAccountResource(frozenEnergyAddress, blockingStubFull); - final Long beforeTotalEnergyWeight = accountResource.getTotalEnergyWeight(); - String txId = PublicMethod.freezeBalanceV2AndGetTxId(frozenEnergyAddress, - freezeEnergyBalance, 1, frozenEnergyKey, blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(frozenEnergyAddress, blockingStubFull); + final Long beforeTotalEnergyWeight = accountResource.getTotalEnergyWeight(); + String txId = + PublicMethod.freezeBalanceV2AndGetTxId( + frozenEnergyAddress, freezeEnergyBalance, 1, frozenEnergyKey, blockingStubFull); Assert.assertNotNull(txId); PublicMethod.waitProduceNextBlock(blockingStubFull); - - Transaction transaction = - PublicMethod.getTransactionById(txId, blockingStubFull).get(); + Transaction transaction = PublicMethod.getTransactionById(txId, blockingStubFull).get(); Any any = transaction.getRawData().getContract(0).getParameter(); - FreezeBalanceV2Contract freezeBalanceV2Contract - = any.unpack(FreezeBalanceV2Contract.class); + FreezeBalanceV2Contract freezeBalanceV2Contract = any.unpack(FreezeBalanceV2Contract.class); Assert.assertTrue(freezeBalanceV2Contract.getFrozenBalance() == freezeEnergyBalance); Assert.assertEquals( freezeBalanceV2Contract.getOwnerAddress().toByteArray(), frozenEnergyAddress); Assert.assertTrue(freezeBalanceV2Contract.getResourceValue() == 1); - Account account = PublicMethod.queryAccount(frozenEnergyAddress, blockingStubFull); Assert.assertEquals(account.getFrozenV2Count(), 3); Assert.assertTrue(account.getFrozenV2(1).getAmount() == freezeEnergyBalance); Assert.assertTrue(account.getFrozenV2(1).getTypeValue() == 1); - accountResource = PublicMethod - .getAccountResource(frozenEnergyAddress, blockingStubFull); - final Long afterTotalEnergyWeight = accountResource.getTotalEnergyWeight(); - final Long afterEnergyLimit = accountResource.getEnergyLimit(); + accountResource = PublicMethod.getAccountResource(frozenEnergyAddress, blockingStubFull); + final Long afterTotalEnergyWeight = accountResource.getTotalEnergyWeight(); + final Long afterEnergyLimit = accountResource.getEnergyLimit(); Assert.assertTrue(afterEnergyLimit > 0); } - - /** - * constructor. - */ - @Test(enabled = true, description = "Unfreeze balance to release bandwidth", groups = {"daily", "staking"}) + /** constructor. */ + @Test( + enabled = true, + description = "Unfreeze balance to release bandwidth", + groups = {"daily", "staking"}) public void test03UnFreezeBalanceV2ToReleaseBandwidth() throws Exception { Account account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); - final Long beforeUnfreezeBalance = account.getBalance(); - AccountResourceMessage accountResource = PublicMethod - .getAccountResource(frozenBandwidthAddress, blockingStubFull); - final Long beforeTotalNetWeight = accountResource.getTotalNetWeight(); - String txId = PublicMethod.unFreezeBalanceV2AndGetTxId(frozenBandwidthAddress, - frozenBandwidthKey, freezeBandwidthBalance, 0, blockingStubFull); + final Long beforeUnfreezeBalance = account.getBalance(); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(frozenBandwidthAddress, blockingStubFull); + final Long beforeTotalNetWeight = accountResource.getTotalNetWeight(); + String txId = + PublicMethod.unFreezeBalanceV2AndGetTxId( + frozenBandwidthAddress, + frozenBandwidthKey, + freezeBandwidthBalance, + 0, + blockingStubFull); Assert.assertNotNull(txId); PublicMethod.waitProduceNextBlock(blockingStubFull); - Transaction transaction = - PublicMethod.getTransactionById(txId, blockingStubFull).get(); + Transaction transaction = PublicMethod.getTransactionById(txId, blockingStubFull).get(); Any any = transaction.getRawData().getContract(0).getParameter(); - UnfreezeBalanceV2Contract unfreezeBalanceV2Contract - = any.unpack(UnfreezeBalanceV2Contract.class); + UnfreezeBalanceV2Contract unfreezeBalanceV2Contract = + any.unpack(UnfreezeBalanceV2Contract.class); Assert.assertTrue(unfreezeBalanceV2Contract.getUnfreezeBalance() == freezeBandwidthBalance); - Assert.assertEquals(unfreezeBalanceV2Contract.getOwnerAddress().toByteArray(), - frozenBandwidthAddress); + Assert.assertEquals( + unfreezeBalanceV2Contract.getOwnerAddress().toByteArray(), frozenBandwidthAddress); Assert.assertTrue(unfreezeBalanceV2Contract.getResourceValue() == 0); - account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); Assert.assertEquals(account.getFrozenV2Count(), 3); Assert.assertTrue(account.getFrozenV2(0).getAmount() == 0); Assert.assertTrue(account.getFrozenV2(0).getTypeValue() == 0); - accountResource = PublicMethod - .getAccountResource(frozenBandwidthAddress, blockingStubFull); - final Long afterTotalNetWeight = accountResource.getTotalNetWeight(); - final Long afterNetLimit = accountResource.getNetLimit(); - final Long afterNetUsage = accountResource.getNetUsed(); - final Long afterUnfreezeBalance = account.getBalance(); - final Long afterUnfreezeTimestamp = System.currentTimeMillis(); + accountResource = PublicMethod.getAccountResource(frozenBandwidthAddress, blockingStubFull); + final Long afterTotalNetWeight = accountResource.getTotalNetWeight(); + final Long afterNetLimit = accountResource.getNetLimit(); + final Long afterNetUsage = accountResource.getNetUsed(); + final Long afterUnfreezeBalance = account.getBalance(); + final Long afterUnfreezeTimestamp = System.currentTimeMillis(); Assert.assertTrue(afterNetLimit == 0L); Assert.assertTrue(afterNetUsage > 0); Assert.assertEquals(beforeUnfreezeBalance, afterUnfreezeBalance); Assert.assertTrue(account.getUnfrozenV2Count() == 1); - Assert.assertTrue(account.getUnfrozenV2(0).getUnfreezeExpireTime() > afterUnfreezeTimestamp - && account.getUnfrozenV2(0).getUnfreezeExpireTime() <= afterUnfreezeTimestamp + periodTime); + Assert.assertTrue( + account.getUnfrozenV2(0).getUnfreezeExpireTime() > afterUnfreezeTimestamp + && account.getUnfrozenV2(0).getUnfreezeExpireTime() + <= afterUnfreezeTimestamp + periodTime); } - - /** - * constructor. - */ - @Test(enabled = true, description = "Freeze balance to release energy", groups = {"daily", "staking"}) + /** constructor. */ + @Test( + enabled = true, + description = "Freeze balance to release energy", + groups = {"daily", "staking"}) public void test04UnFreezeBalanceV2ToReleaseEnergy() throws Exception { - AccountResourceMessage accountResource = PublicMethod - .getAccountResource(frozenEnergyAddress, blockingStubFull); - final Long beforeTotalEnergyWeight = accountResource.getTotalEnergyWeight(); - String txId = PublicMethod.unFreezeBalanceV2AndGetTxId(frozenEnergyAddress, - frozenEnergyKey, freezeEnergyBalance, 1, blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(frozenEnergyAddress, blockingStubFull); + final Long beforeTotalEnergyWeight = accountResource.getTotalEnergyWeight(); + String txId = + PublicMethod.unFreezeBalanceV2AndGetTxId( + frozenEnergyAddress, frozenEnergyKey, freezeEnergyBalance, 1, blockingStubFull); Assert.assertNotNull(txId); PublicMethod.waitProduceNextBlock(blockingStubFull); - Transaction transaction = PublicMethod.getTransactionById(txId, - blockingStubFull).get(); + Transaction transaction = PublicMethod.getTransactionById(txId, blockingStubFull).get(); Any any = transaction.getRawData().getContract(0).getParameter(); - UnfreezeBalanceV2Contract unfreezeBalanceV2Contract - = any.unpack(UnfreezeBalanceV2Contract.class); + UnfreezeBalanceV2Contract unfreezeBalanceV2Contract = + any.unpack(UnfreezeBalanceV2Contract.class); Assert.assertTrue(unfreezeBalanceV2Contract.getUnfreezeBalance() == freezeEnergyBalance); - Assert.assertEquals(unfreezeBalanceV2Contract.getOwnerAddress().toByteArray(), - frozenEnergyAddress); + Assert.assertEquals( + unfreezeBalanceV2Contract.getOwnerAddress().toByteArray(), frozenEnergyAddress); Assert.assertTrue(unfreezeBalanceV2Contract.getResourceValue() == 1); - Account account = PublicMethod.queryAccount(frozenEnergyAddress, blockingStubFull); Assert.assertEquals(account.getFrozenV2Count(), 3); Assert.assertTrue(account.getFrozenV2(1).getAmount() == 0); Assert.assertTrue(account.getFrozenV2(1).getTypeValue() == 1); - accountResource = PublicMethod - .getAccountResource(frozenEnergyAddress, blockingStubFull); - final Long afterTotalEnergyWeight = accountResource.getTotalEnergyWeight(); - final Long afterEnergyLimit = accountResource.getEnergyLimit(); - final Long afterUnfreezeTimestamp = System.currentTimeMillis(); + accountResource = PublicMethod.getAccountResource(frozenEnergyAddress, blockingStubFull); + final Long afterTotalEnergyWeight = accountResource.getTotalEnergyWeight(); + final Long afterEnergyLimit = accountResource.getEnergyLimit(); + final Long afterUnfreezeTimestamp = System.currentTimeMillis(); Assert.assertTrue(afterEnergyLimit == 0); logger.info( "account.getUnfrozenV2(0).getUnfreezeExpireTime():" - + account.getUnfrozenV2(0).getUnfreezeExpireTime() - ); + + account.getUnfrozenV2(0).getUnfreezeExpireTime()); logger.info("afterUnfreezeTimestamp:" + afterUnfreezeTimestamp); - Assert.assertTrue(account.getUnfrozenV2(0).getUnfreezeExpireTime() > afterUnfreezeTimestamp - && account.getUnfrozenV2(0).getUnfreezeExpireTime() <= afterUnfreezeTimestamp + periodTime); + Assert.assertTrue( + account.getUnfrozenV2(0).getUnfreezeExpireTime() > afterUnfreezeTimestamp + && account.getUnfrozenV2(0).getUnfreezeExpireTime() + <= afterUnfreezeTimestamp + periodTime); } - - /** - * constructor. - */ - @Test(enabled = true, description = "Withdraw expire unfreeze to release balance", groups = {"daily", "staking"}) + /** constructor. */ + @Test( + enabled = true, + description = "Withdraw expire unfreeze to release balance", + groups = {"daily", "staking"}) public void test05WithdrawExpireUnfreezeToReleaseBalance() throws Exception { Account account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); - final Long bandwidthAccountBeforeBalance = account.getBalance(); + final Long bandwidthAccountBeforeBalance = account.getBalance(); account = PublicMethod.queryAccount(frozenEnergyAddress, blockingStubFull); - final Long energyAccountBeforeBalance = account.getBalance(); - + final Long energyAccountBeforeBalance = account.getBalance(); if (System.currentTimeMillis() - 2000L < account.getUnfrozenV2(0).getUnfreezeExpireTime()) { - Assert.assertFalse(PublicMethod.withdrawExpireUnfreeze(frozenEnergyAddress, - frozenEnergyKey, blockingStubFull)); + Assert.assertFalse( + PublicMethod.withdrawExpireUnfreeze( + frozenEnergyAddress, frozenEnergyKey, blockingStubFull)); logger.info("Check before expire time ,can't withdraw, function pass"); - int retryTimes = 0; - Long unfreezeExpireTime = account.getUnfrozenV2(0).getUnfreezeExpireTime(); - while ( - retryTimes++ <= periodTime / 6000L && System.currentTimeMillis() < unfreezeExpireTime - ) { + int retryTimes = 0; + Long unfreezeExpireTime = account.getUnfrozenV2(0).getUnfreezeExpireTime(); + while (retryTimes++ <= periodTime / 6000L + && System.currentTimeMillis() < unfreezeExpireTime) { PublicMethod.waitProduceNextBlock(blockingStubFull); } } - Long canWithdrawUnFreezeAmount = PublicMethod - .getCanWithdrawUnfreezeAmount(frozenEnergyAddress, - System.currentTimeMillis(), blockingStubFull).get().getAmount(); - //query solidity + Long canWithdrawUnFreezeAmount = + PublicMethod.getCanWithdrawUnfreezeAmount( + frozenEnergyAddress, System.currentTimeMillis(), blockingStubFull) + .get() + .getAmount(); + // query solidity PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubFullSolidity); - Long canWithdrawUnFreezeAmountSolidity = PublicMethod - .getCanWithdrawUnfreezeAmountSolidity(frozenEnergyAddress, - System.currentTimeMillis(), blockingStubFullSolidity).get().getAmount(); + Long canWithdrawUnFreezeAmountSolidity = + PublicMethod.getCanWithdrawUnfreezeAmountSolidity( + frozenEnergyAddress, System.currentTimeMillis(), blockingStubFullSolidity) + .get() + .getAmount(); Assert.assertEquals(canWithdrawUnFreezeAmount, canWithdrawUnFreezeAmountSolidity); - //query pbft + // query pbft PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubPbft); - Long canWithdrawUnFreezeAmountPbft = PublicMethod - .getCanWithdrawUnfreezeAmountSolidity(frozenEnergyAddress, - System.currentTimeMillis(), blockingStubPbft).get().getAmount(); + Long canWithdrawUnFreezeAmountPbft = + PublicMethod.getCanWithdrawUnfreezeAmountSolidity( + frozenEnergyAddress, System.currentTimeMillis(), blockingStubPbft) + .get() + .getAmount(); Assert.assertEquals(canWithdrawUnFreezeAmount, canWithdrawUnFreezeAmountPbft); - String txIdBandwidth = PublicMethod.withdrawExpireUnfreezeAndGetTxId(frozenBandwidthAddress, - frozenBandwidthKey, blockingStubFull); - String txIdEnergy = PublicMethod.withdrawExpireUnfreezeAndGetTxId(frozenEnergyAddress, - frozenEnergyKey, blockingStubFull); + String txIdBandwidth = + PublicMethod.withdrawExpireUnfreezeAndGetTxId( + frozenBandwidthAddress, frozenBandwidthKey, blockingStubFull); + String txIdEnergy = + PublicMethod.withdrawExpireUnfreezeAndGetTxId( + frozenEnergyAddress, frozenEnergyKey, blockingStubFull); Assert.assertNotNull(txIdBandwidth); Assert.assertNotNull(txIdEnergy); - PublicMethod.waitProduceNextBlock(blockingStubFull); - Transaction transaction = PublicMethod.getTransactionById(txIdEnergy, - blockingStubFull).get(); + Transaction transaction = PublicMethod.getTransactionById(txIdEnergy, blockingStubFull).get(); Any any = transaction.getRawData().getContract(0).getParameter(); - WithdrawExpireUnfreezeContract withdrawExpireUnfreezeContract - = any.unpack(WithdrawExpireUnfreezeContract.class); - Assert.assertEquals(withdrawExpireUnfreezeContract.getOwnerAddress().toByteArray(), - frozenEnergyAddress); - + WithdrawExpireUnfreezeContract withdrawExpireUnfreezeContract = + any.unpack(WithdrawExpireUnfreezeContract.class); + Assert.assertEquals( + withdrawExpireUnfreezeContract.getOwnerAddress().toByteArray(), frozenEnergyAddress); account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); - final Long bandwidthAccountAfterBalance = account.getBalance(); + final Long bandwidthAccountAfterBalance = account.getBalance(); account = PublicMethod.queryAccount(frozenEnergyAddress, blockingStubFull); - final Long energyAccountAfterBalance = account.getBalance(); + final Long energyAccountAfterBalance = account.getBalance(); Assert.assertTrue( bandwidthAccountAfterBalance - bandwidthAccountBeforeBalance == freezeBandwidthBalance); Assert.assertTrue( energyAccountAfterBalance - energyAccountBeforeBalance == freezeEnergyBalance); - - TransactionInfo transactionInfo = PublicMethod.getTransactionInfoById(txIdEnergy, - blockingStubFull).get(); + TransactionInfo transactionInfo = + PublicMethod.getTransactionInfoById(txIdEnergy, blockingStubFull).get(); Assert.assertTrue(transactionInfo.getWithdrawExpireAmount() == freezeEnergyBalance); Assert.assertTrue(transactionInfo.getUnfreezeAmount() == 0); Assert.assertEquals(freezeEnergyBalance, canWithdrawUnFreezeAmount); } - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - PublicMethod.freeResource(frozenBandwidthAddress, - frozenBandwidthKey, foundationAddress, blockingStubFull); } + PublicMethod.freeResource( + frozenBandwidthAddress, frozenBandwidthKey, foundationAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test002.java index dc40b022..023e70df 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test002.java @@ -1,7 +1,6 @@ package stest.tron.wallet.dailybuild.freezeV2; import com.google.protobuf.Any; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import lombok.extern.slf4j.Slf4j; import org.testng.Assert; @@ -12,18 +11,15 @@ import org.tron.api.GrpcAPI.AccountResourceMessage; import org.tron.api.WalletSolidityGrpc; import org.tron.protos.Protocol.Account; -import org.tron.protos.Protocol.Account.AccountResource; import org.tron.protos.Protocol.Transaction; import org.tron.protos.contract.BalanceContract.DelegateResourceContract; -import org.tron.protos.contract.BalanceContract.FreezeBalanceV2Contract; import org.tron.protos.contract.BalanceContract.UnDelegateResourceContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import zmq.socket.pubsub.Pub; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class FreezeBalanceV2Test002 extends TronBaseTest { @@ -53,12 +49,9 @@ public class FreezeBalanceV2Test002 extends TronBaseTest { Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFullSolidity = null; private String pbftnode = - Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list") - .get(2); + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(2); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() throws Exception { initPbftChannel(); @@ -67,230 +60,244 @@ public void beforeClass() throws Exception { PublicMethod.printAddress(frozenEnergyKey); PublicMethod.printAddress(receiveBandwidthKey); PublicMethod.printAddress(receiveBandwidthKey); - PublicMethod.printAddress(delegateFromKey); if (!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { throw new SkipException("Skipping freezeV2 test case"); + PublicMethod.printAddress(delegateFromKey); + if (!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + throw new SkipException("Skipping freezeV2 test case"); } - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubFullSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - channelPbft = ManagedChannelBuilder.forTarget(pbftnode) - .usePlaintext() - .build(); - Assert.assertTrue(PublicMethod.sendcoin(frozenBandwidthAddress, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(frozenEnergyAddress, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(receiveBandwidthAddress, 1L, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(receiveEnergyAddress, 1L, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(delegateFromAddress, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); + channelPbft = ManagedChannelBuilder.forTarget(pbftnode).usePlaintext().build(); + Assert.assertTrue( + PublicMethod.sendcoin( + frozenBandwidthAddress, + sendAmount, + foundationAddress, + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + frozenEnergyAddress, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + receiveBandwidthAddress, 1L, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + receiveEnergyAddress, 1L, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + delegateFromAddress, sendAmount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceV2(frozenBandwidthAddress, freezeBandwidthBalance, - 0, frozenBandwidthKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceV2(frozenEnergyAddress, freezeEnergyBalance, - 1, frozenEnergyKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + frozenBandwidthAddress, + freezeBandwidthBalance, + 0, + frozenBandwidthKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + frozenEnergyAddress, freezeEnergyBalance, 1, frozenEnergyKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - - } - - /** - * constructor. - */ - @Test(enabled = true, description = "Delegate resource of bandwidth", groups = {"daily", "staking"}) + /** constructor. */ + @Test( + enabled = true, + description = "Delegate resource of bandwidth", + groups = {"daily", "staking"}) public void test01DelegateResourceOfBandwidth() throws Exception { Account account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); - AccountResourceMessage accountResource = PublicMethod - .getAccountResource(frozenBandwidthAddress, blockingStubFull); - final Long beforeLenderFrozenAmount = account.getFrozenV2(0).getAmount(); - final Long beforeLenderNetLimit = accountResource.getNetLimit(); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(frozenBandwidthAddress, blockingStubFull); + final Long beforeLenderFrozenAmount = account.getFrozenV2(0).getAmount(); + final Long beforeLenderNetLimit = accountResource.getNetLimit(); logger.info("beforeLenderNetLimit: " + beforeLenderNetLimit); beforeDelegateBandwidthNetLimit = beforeLenderNetLimit; - String txId = PublicMethod.delegateResourceV2AndGetTxId(frozenBandwidthAddress, - delegateBandwidthAmount, 0, receiveBandwidthAddress, frozenBandwidthKey, blockingStubFull); + String txId = + PublicMethod.delegateResourceV2AndGetTxId( + frozenBandwidthAddress, + delegateBandwidthAmount, + 0, + receiveBandwidthAddress, + frozenBandwidthKey, + blockingStubFull); Assert.assertNotNull(txId); PublicMethod.waitProduceNextBlock(blockingStubFull); - Transaction transaction = PublicMethod.getTransactionById(txId, blockingStubFull).get(); Any any = transaction.getRawData().getContract(0).getParameter(); - DelegateResourceContract delegateResourceContract - = any.unpack(DelegateResourceContract.class); + DelegateResourceContract delegateResourceContract = any.unpack(DelegateResourceContract.class); Assert.assertTrue(delegateResourceContract.getBalance() == delegateBandwidthAmount); - Assert.assertEquals(delegateResourceContract.getOwnerAddress().toByteArray(), - frozenBandwidthAddress); + Assert.assertEquals( + delegateResourceContract.getOwnerAddress().toByteArray(), frozenBandwidthAddress); Assert.assertTrue(delegateResourceContract.getResourceValue() == 0); - Assert.assertEquals(delegateResourceContract.getReceiverAddress().toByteArray(), - receiveBandwidthAddress); - + Assert.assertEquals( + delegateResourceContract.getReceiverAddress().toByteArray(), receiveBandwidthAddress); - account = PublicMethod.queryAccount(frozenBandwidthAddress, - blockingStubFull); - accountResource = PublicMethod - .getAccountResource(frozenBandwidthAddress, blockingStubFull); - final Long afterLenderFrozenAmount = account.getFrozenV2(0).getAmount(); - final Long afterLenderNetLimit = accountResource.getNetLimit(); + account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); + accountResource = PublicMethod.getAccountResource(frozenBandwidthAddress, blockingStubFull); + final Long afterLenderFrozenAmount = account.getFrozenV2(0).getAmount(); + final Long afterLenderNetLimit = accountResource.getNetLimit(); logger.info("afterLenderNetLimit: " + afterLenderNetLimit); - final Long afterLenderAmount = account.getAcquiredDelegatedFrozenBalanceForBandwidth() - + account.getAcquiredDelegatedFrozenV2BalanceForBandwidth() + afterLenderFrozenAmount; - + final Long afterLenderAmount = + account.getAcquiredDelegatedFrozenBalanceForBandwidth() + + account.getAcquiredDelegatedFrozenV2BalanceForBandwidth() + + afterLenderFrozenAmount; Assert.assertTrue( beforeLenderFrozenAmount - afterLenderFrozenAmount == delegateBandwidthAmount); Assert.assertTrue(account.getDelegatedFrozenV2BalanceForBandwidth() == delegateBandwidthAmount); - Long netTotalWeight = accountResource.getTotalNetWeight(); - Long netTotalLimit = accountResource.getTotalNetLimit(); - final double afterLenderNetLimitDouble = + Long netTotalWeight = accountResource.getTotalNetWeight(); + Long netTotalLimit = accountResource.getTotalNetLimit(); + final double afterLenderNetLimitDouble = ((double) afterLenderAmount / (double) (netTotalWeight * 1000000)) * netTotalLimit; logger.info("afterLenderNetLimitDouble: " + afterLenderNetLimitDouble); - final Long afterLenderNetLimitShouldBe = Math.round(afterLenderNetLimitDouble); + final Long afterLenderNetLimitShouldBe = Math.round(afterLenderNetLimitDouble); Assert.assertTrue(Math.abs(afterLenderNetLimitShouldBe - afterLenderNetLimit) <= 1); - - accountResource = PublicMethod - .getAccountResource(receiveBandwidthAddress, blockingStubFull); - final Long afterReceiverNetLimit = accountResource.getNetLimit(); + accountResource = PublicMethod.getAccountResource(receiveBandwidthAddress, blockingStubFull); + final Long afterReceiverNetLimit = accountResource.getNetLimit(); logger.info("afterReceiverNetLimit: " + afterReceiverNetLimit); account = PublicMethod.queryAccount(receiveBandwidthAddress, blockingStubFull); - final Long receiverAcquiredDelegatedFrozenBalanceForBandwidth = account - .getAcquiredDelegatedFrozenV2BalanceForBandwidth(); - final Long afterReceiverAmount = account.getAcquiredDelegatedFrozenBalanceForBandwidth() - + account.getAcquiredDelegatedFrozenV2BalanceForBandwidth() - + account.getFrozenV2(0).getAmount(); + final Long receiverAcquiredDelegatedFrozenBalanceForBandwidth = + account.getAcquiredDelegatedFrozenV2BalanceForBandwidth(); + final Long afterReceiverAmount = + account.getAcquiredDelegatedFrozenBalanceForBandwidth() + + account.getAcquiredDelegatedFrozenV2BalanceForBandwidth() + + account.getFrozenV2(0).getAmount(); netTotalWeight = accountResource.getTotalNetWeight(); netTotalLimit = accountResource.getTotalNetLimit(); - final double afterReceiverNetLimitDouble = + final double afterReceiverNetLimitDouble = ((double) afterReceiverAmount / (double) (netTotalWeight * 1000000)) * netTotalLimit; logger.info("afterReceiverNetLimitDouble: " + afterReceiverNetLimitDouble); - final Long afterReceiverNetLimitShouldBe = Math.round(afterReceiverNetLimitDouble); + final Long afterReceiverNetLimitShouldBe = Math.round(afterReceiverNetLimitDouble); logger.info("afterReceiverNetLimitShouldBe: " + afterReceiverNetLimitShouldBe); - Assert.assertTrue( - Math.abs(afterReceiverNetLimitShouldBe - afterReceiverNetLimit) <= 1); + Assert.assertTrue(Math.abs(afterReceiverNetLimitShouldBe - afterReceiverNetLimit) <= 1); Assert.assertEquals( receiverAcquiredDelegatedFrozenBalanceForBandwidth, delegateBandwidthAmount); } - /** - * constructor. - */ - @Test(enabled = true, description = "Undelegate resource of bandwidth", groups = {"daily", "staking"}) + /** constructor. */ + @Test( + enabled = true, + description = "Undelegate resource of bandwidth", + groups = {"daily", "staking"}) public void test02UnDelegateResourceOfBandwidth() throws Exception { Account account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); - AccountResourceMessage accountResource = PublicMethod - .getAccountResource(frozenBandwidthAddress, blockingStubFull); - final Long beforeLenderFrozenAmount = account.getFrozenV2(0).getAmount(); - final Long beforeLenderNetLimit = accountResource.getNetLimit(); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(frozenBandwidthAddress, blockingStubFull); + final Long beforeLenderFrozenAmount = account.getFrozenV2(0).getAmount(); + final Long beforeLenderNetLimit = accountResource.getNetLimit(); - accountResource = PublicMethod - .getAccountResource(receiveBandwidthAddress, blockingStubFull); - final Long beforeReceiverNetLimit = accountResource.getNetLimit(); + accountResource = PublicMethod.getAccountResource(receiveBandwidthAddress, blockingStubFull); + final Long beforeReceiverNetLimit = accountResource.getNetLimit(); account = PublicMethod.queryAccount(receiveBandwidthAddress, blockingStubFull); - final Long beforeAcquiredDelegatedFrozenBalanceForBandwidth = account - .getAcquiredDelegatedFrozenBalanceForBandwidth(); - String txId = PublicMethod.unDelegateResourceV2AndGetTxId(frozenBandwidthAddress, - delegateBandwidthAmount, 0, receiveBandwidthAddress, frozenBandwidthKey, blockingStubFull); + final Long beforeAcquiredDelegatedFrozenBalanceForBandwidth = + account.getAcquiredDelegatedFrozenBalanceForBandwidth(); + String txId = + PublicMethod.unDelegateResourceV2AndGetTxId( + frozenBandwidthAddress, + delegateBandwidthAmount, + 0, + receiveBandwidthAddress, + frozenBandwidthKey, + blockingStubFull); Assert.assertNotNull(txId); PublicMethod.waitProduceNextBlock(blockingStubFull); - Transaction transaction = PublicMethod.getTransactionById(txId, blockingStubFull).get(); Any any = transaction.getRawData().getContract(0).getParameter(); - UnDelegateResourceContract unDelegateResourceContract - = any.unpack(UnDelegateResourceContract.class); + UnDelegateResourceContract unDelegateResourceContract = + any.unpack(UnDelegateResourceContract.class); Assert.assertTrue(unDelegateResourceContract.getBalance() == delegateBandwidthAmount); - Assert.assertEquals(unDelegateResourceContract.getOwnerAddress().toByteArray(), - frozenBandwidthAddress); + Assert.assertEquals( + unDelegateResourceContract.getOwnerAddress().toByteArray(), frozenBandwidthAddress); Assert.assertTrue(unDelegateResourceContract.getResourceValue() == 0); - Assert.assertEquals(unDelegateResourceContract.getReceiverAddress().toByteArray(), - receiveBandwidthAddress); - + Assert.assertEquals( + unDelegateResourceContract.getReceiverAddress().toByteArray(), receiveBandwidthAddress); account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); - accountResource = PublicMethod - .getAccountResource(frozenBandwidthAddress, blockingStubFull); - final Long afterLenderFrozenAmount = account.getFrozenV2(0).getAmount(); - final Long afterDelegateResourceAmount = account.getDelegatedFrozenBalanceForBandwidth(); - final Long afterLenderNetLimit = accountResource.getNetLimit(); - final Long afterLenderAmount = account.getAcquiredDelegatedFrozenBalanceForBandwidth() + accountResource = PublicMethod.getAccountResource(frozenBandwidthAddress, blockingStubFull); + final Long afterLenderFrozenAmount = account.getFrozenV2(0).getAmount(); + final Long afterDelegateResourceAmount = account.getDelegatedFrozenBalanceForBandwidth(); + final Long afterLenderNetLimit = accountResource.getNetLimit(); + final Long afterLenderAmount = + account.getAcquiredDelegatedFrozenBalanceForBandwidth() + account.getAcquiredDelegatedFrozenV2BalanceForBandwidth() + account.getFrozenV2(0).getAmount(); Assert.assertTrue( beforeLenderFrozenAmount - afterLenderFrozenAmount == -delegateBandwidthAmount); - final Long netTotalWeight = accountResource.getTotalNetWeight(); - final Long netTotalLimit = accountResource.getTotalNetLimit(); - final double netLimitDouble = + final Long netTotalWeight = accountResource.getTotalNetWeight(); + final Long netTotalLimit = accountResource.getTotalNetLimit(); + final double netLimitDouble = ((double) afterLenderAmount / (double) (netTotalWeight * 1000000)) * (double) netTotalLimit; logger.info("netLimitDouble: " + netLimitDouble); logger.info("afterLenderNetLimit: " + afterLenderNetLimit); - Long netLimitShouldBe = Math.round(netLimitDouble); + Long netLimitShouldBe = Math.round(netLimitDouble); Assert.assertTrue(Math.abs(netLimitShouldBe - afterLenderNetLimit) <= 1); - accountResource = PublicMethod - .getAccountResource(receiveBandwidthAddress, blockingStubFull); - final Long afterReceiverNetLimit = accountResource.getNetLimit(); + accountResource = PublicMethod.getAccountResource(receiveBandwidthAddress, blockingStubFull); + final Long afterReceiverNetLimit = accountResource.getNetLimit(); account = PublicMethod.queryAccount(receiveBandwidthAddress, blockingStubFull); - final Long receiverAcquiredDelegatedFrozenBalanceForBandwidth = account - .getAcquiredDelegatedFrozenBalanceForBandwidth(); + final Long receiverAcquiredDelegatedFrozenBalanceForBandwidth = + account.getAcquiredDelegatedFrozenBalanceForBandwidth(); Assert.assertEquals((long) receiverAcquiredDelegatedFrozenBalanceForBandwidth, 0); Assert.assertEquals((long) afterReceiverNetLimit, 0); Assert.assertEquals((long) afterDelegateResourceAmount, 0); - } - /** - * constructor. - */ - @Test(enabled = true, description = "Test GetCanDelegatedMaxSize api", groups = {"daily", "staking"}) + /** constructor. */ + @Test( + enabled = true, + description = "Test GetCanDelegatedMaxSize api", + groups = {"daily", "staking"}) public void test03TestGetCanDelegatedMaxSizeApi() throws Exception { - Long canDelegatedMaxSizeWithNoNetUsed = PublicMethod - .getCanDelegatedMaxSize(frozenBandwidthAddress, 0, blockingStubFull) - .get() - .getMaxSize(); + Long canDelegatedMaxSizeWithNoNetUsed = + PublicMethod.getCanDelegatedMaxSize(frozenBandwidthAddress, 0, blockingStubFull) + .get() + .getMaxSize(); logger.info("canDelegatedMaxSizeWithNoNetUsed" + canDelegatedMaxSizeWithNoNetUsed); - //query solidity + // query solidity PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubFullSolidity); - Long canDelegatedMaxSizeWithNoNetUsedSolidity = PublicMethod - .getCanDelegatedMaxSizeSolidity(frozenBandwidthAddress, 0, blockingStubFullSolidity) - .get() - .getMaxSize(); + Long canDelegatedMaxSizeWithNoNetUsedSolidity = + PublicMethod.getCanDelegatedMaxSizeSolidity( + frozenBandwidthAddress, 0, blockingStubFullSolidity) + .get() + .getMaxSize(); logger.info( - "canDelegatedMaxSizeWithNoNetUsedSolidity" + canDelegatedMaxSizeWithNoNetUsedSolidity - ); - //query pbft + "canDelegatedMaxSizeWithNoNetUsedSolidity" + canDelegatedMaxSizeWithNoNetUsedSolidity); + // query pbft PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubPbft); - Long canDelegatedMaxSizeWithNoNetUsedPbft = PublicMethod - .getCanDelegatedMaxSizeSolidity(frozenBandwidthAddress, 0, blockingStubPbft) - .get() - .getMaxSize(); - logger.info( - "canDelegatedMaxSizeWithNoNetUsedPbft" - + canDelegatedMaxSizeWithNoNetUsedPbft - ); - int retryTimes = 0; - while (PublicMethod.getCanDelegatedMaxSize(frozenBandwidthAddress, 0, blockingStubFull).get() - .getMaxSize() + 1100000 > canDelegatedMaxSizeWithNoNetUsed && retryTimes++ <= 5000) { + Long canDelegatedMaxSizeWithNoNetUsedPbft = + PublicMethod.getCanDelegatedMaxSizeSolidity(frozenBandwidthAddress, 0, blockingStubPbft) + .get() + .getMaxSize(); + logger.info("canDelegatedMaxSizeWithNoNetUsedPbft" + canDelegatedMaxSizeWithNoNetUsedPbft); + int retryTimes = 0; + while (PublicMethod.getCanDelegatedMaxSize(frozenBandwidthAddress, 0, blockingStubFull) + .get() + .getMaxSize() + + 1100000 + > canDelegatedMaxSizeWithNoNetUsed + && retryTimes++ <= 5000) { logger.info( - "Current" + PublicMethod - .getCanDelegatedMaxSize(frozenBandwidthAddress, 0, blockingStubFull) - .get() - .getMaxSize() - ); - PublicMethod.sendcoinGetTransactionIdForConstructData(foundationAddress, - 1L, frozenBandwidthAddress, frozenBandwidthKey, blockingStubFull); + "Current" + + PublicMethod.getCanDelegatedMaxSize(frozenBandwidthAddress, 0, blockingStubFull) + .get() + .getMaxSize()); + PublicMethod.sendcoinGetTransactionIdForConstructData( + foundationAddress, 1L, frozenBandwidthAddress, frozenBandwidthKey, blockingStubFull); Thread.sleep(10L); } PublicMethod.waitProduceNextBlock(blockingStubFull); - Long canDelegatedMaxSizeWithNetUsed = PublicMethod.getCanDelegatedMaxSize( - frozenBandwidthAddress, 0, blockingStubFull) - .get() - .getMaxSize(); + Long canDelegatedMaxSizeWithNetUsed = + PublicMethod.getCanDelegatedMaxSize(frozenBandwidthAddress, 0, blockingStubFull) + .get() + .getMaxSize(); Assert.assertTrue(canDelegatedMaxSizeWithNoNetUsed > canDelegatedMaxSizeWithNetUsed + 1000000); Assert.assertFalse( @@ -300,73 +307,73 @@ public void test03TestGetCanDelegatedMaxSizeApi() throws Exception { 0, receiveBandwidthAddress, frozenBandwidthKey, - blockingStubFull - ) - ); - Assert.assertTrue(PublicMethod.delegateResourceV2( - frozenBandwidthAddress, - canDelegatedMaxSizeWithNetUsed, - 0, - receiveBandwidthAddress, - frozenBandwidthKey, - blockingStubFull) - ); - //query solidity + blockingStubFull)); + Assert.assertTrue( + PublicMethod.delegateResourceV2( + frozenBandwidthAddress, + canDelegatedMaxSizeWithNetUsed, + 0, + receiveBandwidthAddress, + frozenBandwidthKey, + blockingStubFull)); + // query solidity PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubFullSolidity); - Long canDelegatedMaxSizeWithNetUsedSolidity = PublicMethod.getCanDelegatedMaxSizeSolidity( - frozenBandwidthAddress, 0, blockingStubFullSolidity) - .get() - .getMaxSize(); - logger.info("canDelegatedMaxSizeWithNetUsedSolidity: " + canDelegatedMaxSizeWithNetUsedSolidity); - //query pbft + Long canDelegatedMaxSizeWithNetUsedSolidity = + PublicMethod.getCanDelegatedMaxSizeSolidity( + frozenBandwidthAddress, 0, blockingStubFullSolidity) + .get() + .getMaxSize(); + logger.info( + "canDelegatedMaxSizeWithNetUsedSolidity: " + canDelegatedMaxSizeWithNetUsedSolidity); + // query pbft PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubPbft); - Long canDelegatedMaxSizeWithNetUsedPbft = PublicMethod.getCanDelegatedMaxSizeSolidity( - frozenBandwidthAddress, 0, blockingStubPbft) - .get() - .getMaxSize(); + Long canDelegatedMaxSizeWithNetUsedPbft = + PublicMethod.getCanDelegatedMaxSizeSolidity(frozenBandwidthAddress, 0, blockingStubPbft) + .get() + .getMaxSize(); logger.info("canDelegatedMaxSizeWithNetUsedPbft: " + canDelegatedMaxSizeWithNetUsedPbft); - Assert.assertEquals(canDelegatedMaxSizeWithNetUsedPbft.longValue(), canDelegatedMaxSizeWithNetUsedSolidity.longValue()); + Assert.assertEquals( + canDelegatedMaxSizeWithNetUsedPbft.longValue(), + canDelegatedMaxSizeWithNetUsedSolidity.longValue()); - Assert.assertTrue(PublicMethod.freezeBalanceV2(delegateFromAddress, - freezeBandwidthBalance, 0, delegateFromKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + delegateFromAddress, freezeBandwidthBalance, 0, delegateFromKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.delegateResourceV2(delegateFromAddress, - PublicMethod.getCanDelegatedMaxSize(delegateFromAddress, 0, blockingStubFull) - .get() - .getMaxSize(), - 0, - frozenBandwidthAddress, - delegateFromKey, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.delegateResourceV2( + delegateFromAddress, + PublicMethod.getCanDelegatedMaxSize(delegateFromAddress, 0, blockingStubFull) + .get() + .getMaxSize(), + 0, + frozenBandwidthAddress, + delegateFromKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long canDelegatedMaxSizeWithOtherDelegatedToMe = PublicMethod.getCanDelegatedMaxSize( - frozenBandwidthAddress, 0, blockingStubFull) - .get() - .getMaxSize(); + Long canDelegatedMaxSizeWithOtherDelegatedToMe = + PublicMethod.getCanDelegatedMaxSize(frozenBandwidthAddress, 0, blockingStubFull) + .get() + .getMaxSize(); Assert.assertEquals( (long) freezeBandwidthBalance, canDelegatedMaxSizeWithNetUsed + canDelegatedMaxSizeWithOtherDelegatedToMe); - Assert.assertTrue(PublicMethod.delegateResourceV2( - frozenBandwidthAddress, - canDelegatedMaxSizeWithOtherDelegatedToMe, - 0, - receiveBandwidthAddress, - frozenBandwidthKey, - blockingStubFull) - ); - - + Assert.assertTrue( + PublicMethod.delegateResourceV2( + frozenBandwidthAddress, + canDelegatedMaxSizeWithOtherDelegatedToMe, + 0, + receiveBandwidthAddress, + frozenBandwidthKey, + blockingStubFull)); } - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - PublicMethod.freeResource(frozenBandwidthAddress, - frozenBandwidthKey, foundationAddress, blockingStubFull); } + PublicMethod.freeResource( + frozenBandwidthAddress, frozenBandwidthKey, foundationAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test003.java index c8a326b0..046286cb 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test003.java @@ -1,10 +1,7 @@ package stest.tron.wallet.dailybuild.freezeV2; -import com.google.protobuf.ByteString; - import java.util.ArrayList; import java.util.List; -import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.testng.Assert; import org.testng.SkipException; @@ -18,25 +15,23 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.Flaky; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; -import stest.tron.wallet.common.client.utils.Flaky; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -@Flaky(reason = "Timing-sensitive: depends on maintenance interval", - since = "2026-04-03") +@Flaky(reason = "Timing-sensitive: depends on maintenance interval", since = "2026-04-03") public class FreezeBalanceV2Test003 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final long totalSupply = now; private static String name = "MultiSign001_" + Long.toString(now); - private final String testKey001 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey001 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] foundationAddress01 = PublicMethod.getFinalAddress(testKey001); - private final String operations = Configuration.getByPath("testng.conf") - .getString("defaultParameter.operations"); - + private final String operations = + Configuration.getByPath("testng.conf").getString("defaultParameter.operations"); String[] permissionKeyString = new String[2]; String[] ownerKeyString = new String[2]; @@ -53,19 +48,18 @@ public class FreezeBalanceV2Test003 extends TronBaseTest { ECKey ecKey4 = new ECKey(Utils.getRandom()); byte[] receiverAddress = ecKey4.getAddress(); String receiverKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private long freezeBalance = 100000000L; private long delegateBalance = freezeBalance / 2; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() throws Exception { if (!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { throw new SkipException("Skipping freezeV2 test case"); + public void beforeClass() throws Exception { + if (!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + throw new SkipException("Skipping freezeV2 test case"); } ecKey1 = new ECKey(Utils.getRandom()); @@ -84,11 +78,15 @@ public class FreezeBalanceV2Test003 extends TronBaseTest { long needCoin = updateAccountPermissionFee * 1 + multiSignFee * 3; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, - needCoin + 2048000000L, foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue( - PublicMethod.sendcoin(receiverAddress, 1L, foundationAddress, foundationKey, + PublicMethod.sendcoin( + ownerAddress, + needCoin + 2048000000L, + foundationAddress, + foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + receiverAddress, 1L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); permissionKeyString[0] = manager1Key; @@ -99,148 +97,204 @@ public class FreezeBalanceV2Test003 extends TronBaseTest { permissionKeyString1[0] = ownerKey; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - String txid = PublicMethodForMultiSign - .accountPermissionUpdateForTransactionId(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerKeyString); + String txid = + PublicMethodForMultiSign.accountPermissionUpdateForTransactionId( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.getTransactionById(txid, blockingStubFull).get() - .getSignatureCount() == 1); - + Assert.assertTrue( + PublicMethod.getTransactionById(txid, blockingStubFull).get().getSignatureCount() == 1); } - @Test(enabled = true, description = "MultiSign for freeze balance V2", groups = {"daily", "staking"}) + @Test( + enabled = true, + description = "MultiSign for freeze balance V2", + groups = {"daily", "staking"}) public void test01MultiSignForFreezeBalanceV2() { Assert.assertTrue( - PublicMethodForMultiSign.freezeBalanceV2WithPermissionId(ownerAddress, freezeBalance, - 0, 2, ownerKey, blockingStubFull, permissionKeyString)); + PublicMethodForMultiSign.freezeBalanceV2WithPermissionId( + ownerAddress, freezeBalance, 0, 2, ownerKey, blockingStubFull, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Transaction transaction = PublicMethod.getTransactionById(PublicMethodForMultiSign - .freezeV2Txid, blockingStubFull).get(); + Transaction transaction = + PublicMethod.getTransactionById(PublicMethodForMultiSign.freezeV2Txid, blockingStubFull) + .get(); logger.info("FreezeBalanceV2 txid:" + PublicMethodForMultiSign.freezeV2Txid); Assert.assertTrue(transaction.getSignatureCount() == 2); - Assert.assertEquals(transaction.getRawData().getContract(0).getType(), - ContractType.FreezeBalanceV2Contract); + Assert.assertEquals( + transaction.getRawData().getContract(0).getType(), ContractType.FreezeBalanceV2Contract); Assert.assertTrue( PublicMethod.getTransactionInfoById(PublicMethodForMultiSign.freezeV2Txid, blockingStubFull) - .get().getFee() >= multiSignFee); + .get() + .getFee() + >= multiSignFee); } - - @Test(enabled = true, description = "MultiSign for delegate resource", groups = {"daily", "staking"}) + @Test( + enabled = true, + description = "MultiSign for delegate resource", + groups = {"daily", "staking"}) public void test02MultiSignForDelegateResource() { - Assert.assertTrue(PublicMethodForMultiSign.delegateResourceWithPermissionId(ownerAddress, - delegateBalance, 0, receiverAddress, 2, ownerKey, - blockingStubFull, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.delegateResourceWithPermissionId( + ownerAddress, + delegateBalance, + 0, + receiverAddress, + 2, + ownerKey, + blockingStubFull, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Transaction transaction = PublicMethod.getTransactionById(PublicMethodForMultiSign - .freezeV2Txid, blockingStubFull).get(); + Transaction transaction = + PublicMethod.getTransactionById(PublicMethodForMultiSign.freezeV2Txid, blockingStubFull) + .get(); Assert.assertTrue(transaction.getSignatureCount() == 2); - Assert.assertEquals(transaction.getRawData().getContract(0).getType(), - ContractType.DelegateResourceContract); - Assert.assertTrue(PublicMethod.getTransactionInfoById(PublicMethodForMultiSign.freezeV2Txid, - blockingStubFull).get().getFee() >= multiSignFee); + Assert.assertEquals( + transaction.getRawData().getContract(0).getType(), ContractType.DelegateResourceContract); + Assert.assertTrue( + PublicMethod.getTransactionInfoById(PublicMethodForMultiSign.freezeV2Txid, blockingStubFull) + .get() + .getFee() + >= multiSignFee); } - - @Test(enabled = true, description = "MultiSign for release delegate resource", groups = {"daily", "staking"}) + @Test( + enabled = true, + description = "MultiSign for release delegate resource", + groups = {"daily", "staking"}) public void test03MultiSignForUnDelegateResource() { - Assert.assertTrue(PublicMethodForMultiSign.unDelegateResourceWithPermissionId(ownerAddress, - delegateBalance, 0, receiverAddress, 2, ownerKey, blockingStubFull, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.unDelegateResourceWithPermissionId( + ownerAddress, + delegateBalance, + 0, + receiverAddress, + 2, + ownerKey, + blockingStubFull, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Transaction transaction = PublicMethod.getTransactionById(PublicMethodForMultiSign - .freezeV2Txid, blockingStubFull).get(); + Transaction transaction = + PublicMethod.getTransactionById(PublicMethodForMultiSign.freezeV2Txid, blockingStubFull) + .get(); Assert.assertTrue(transaction.getSignatureCount() == 2); - Assert.assertEquals(transaction.getRawData().getContract(0).getType(), - ContractType.UnDelegateResourceContract); - Assert.assertTrue(PublicMethod.getTransactionInfoById(PublicMethodForMultiSign.freezeV2Txid, - blockingStubFull).get().getFee() >= multiSignFee); + Assert.assertEquals( + transaction.getRawData().getContract(0).getType(), ContractType.UnDelegateResourceContract); + Assert.assertTrue( + PublicMethod.getTransactionInfoById(PublicMethodForMultiSign.freezeV2Txid, blockingStubFull) + .get() + .getFee() + >= multiSignFee); } - - @Test(enabled = true, description = "MultiSign for unFreezeBalanceV2", groups = {"daily", "staking"}) + @Test( + enabled = true, + description = "MultiSign for unFreezeBalanceV2", + groups = {"daily", "staking"}) public void test04MultiSignForUnFreezeBalanceV2() { - Assert.assertTrue(PublicMethodForMultiSign.unFreezeBalanceV2WithPermissionId(ownerAddress, - delegateBalance, 0, 2, ownerKey, blockingStubFull, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.unFreezeBalanceV2WithPermissionId( + ownerAddress, delegateBalance, 0, 2, ownerKey, blockingStubFull, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Transaction transaction = PublicMethod.getTransactionById(PublicMethodForMultiSign - .freezeV2Txid, blockingStubFull).get(); + Transaction transaction = + PublicMethod.getTransactionById(PublicMethodForMultiSign.freezeV2Txid, blockingStubFull) + .get(); Assert.assertTrue(transaction.getSignatureCount() == 2); - Assert.assertEquals(transaction.getRawData().getContract(0).getType(), - ContractType.UnfreezeBalanceV2Contract); - Assert.assertTrue(PublicMethod.getTransactionInfoById(PublicMethodForMultiSign.freezeV2Txid, - blockingStubFull).get().getFee() >= multiSignFee); + Assert.assertEquals( + transaction.getRawData().getContract(0).getType(), ContractType.UnfreezeBalanceV2Contract); + Assert.assertTrue( + PublicMethod.getTransactionInfoById(PublicMethodForMultiSign.freezeV2Txid, blockingStubFull) + .get() + .getFee() + >= multiSignFee); } - - @Test(enabled = true, description = "MultiSign for withdrawExpireUnfreezeBalance", groups = {"daily", "staking"}) + @Test( + enabled = true, + description = "MultiSign for withdrawExpireUnfreezeBalance", + groups = {"daily", "staking"}) public void test05WithdrawExpireUnfreezeBalance() { Account account = PublicMethod.queryAccount(ownerAddress, blockingStubFull); if (System.currentTimeMillis() - 2000L < account.getUnfrozenV2(0).getUnfreezeExpireTime()) { - Assert.assertFalse(PublicMethodForMultiSign - .withdrawExpireUnfreezeBalanceWithPermissionId(ownerAddress, 2, - ownerKey, blockingStubFull, permissionKeyString)); + Assert.assertFalse( + PublicMethodForMultiSign.withdrawExpireUnfreezeBalanceWithPermissionId( + ownerAddress, 2, ownerKey, blockingStubFull, permissionKeyString)); logger.info("Check before expire time ,can't withdraw, function pass"); - int retryTimes = 0; - Long unfreezeExpireTime = account.getUnfrozenV2(0).getUnfreezeExpireTime(); + int retryTimes = 0; + Long unfreezeExpireTime = account.getUnfrozenV2(0).getUnfreezeExpireTime(); while (retryTimes++ <= 10 && System.currentTimeMillis() < unfreezeExpireTime) { PublicMethod.waitProduceNextBlock(blockingStubFull); } } - Assert.assertTrue(PublicMethodForMultiSign - .withdrawExpireUnfreezeBalanceWithPermissionId(ownerAddress, 2, - ownerKey, blockingStubFull, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.withdrawExpireUnfreezeBalanceWithPermissionId( + ownerAddress, 2, ownerKey, blockingStubFull, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Transaction transaction = PublicMethod.getTransactionById(PublicMethodForMultiSign - .freezeV2Txid, blockingStubFull).get(); + Transaction transaction = + PublicMethod.getTransactionById(PublicMethodForMultiSign.freezeV2Txid, blockingStubFull) + .get(); Assert.assertTrue(transaction.getSignatureCount() == 2); - Assert.assertEquals(transaction.getRawData().getContract(0).getType(), + Assert.assertEquals( + transaction.getRawData().getContract(0).getType(), ContractType.WithdrawExpireUnfreezeContract); - Assert.assertTrue(PublicMethod.getTransactionInfoById(PublicMethodForMultiSign.freezeV2Txid, - blockingStubFull).get().getFee() >= multiSignFee); + Assert.assertTrue( + PublicMethod.getTransactionInfoById(PublicMethodForMultiSign.freezeV2Txid, blockingStubFull) + .get() + .getFee() + >= multiSignFee); } - @Test(enabled = true, description = "MultiSign for cancelUnfreeze", groups = {"daily", "staking"}) + @Test( + enabled = true, + description = "MultiSign for cancelUnfreeze", + groups = {"daily", "staking"}) public void test06MultiSignForCancelUnfreeze() { - logger.info(PublicMethod.queryAccount(ownerAddress,blockingStubFull).toString()); - Assert.assertTrue(PublicMethodForMultiSign.unFreezeBalanceV2WithPermissionId(ownerAddress, - 1, 0, 2, ownerKey, blockingStubFull, permissionKeyString)); + logger.info(PublicMethod.queryAccount(ownerAddress, blockingStubFull).toString()); + Assert.assertTrue( + PublicMethodForMultiSign.unFreezeBalanceV2WithPermissionId( + ownerAddress, 1, 0, 2, ownerKey, blockingStubFull, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Account account0 = PublicMethod.queryAccount(ownerAddress,blockingStubFull); + Account account0 = PublicMethod.queryAccount(ownerAddress, blockingStubFull); Assert.assertEquals(account0.getUnfrozenV2Count(), 1); logger.info(account0.toString()); List li = new ArrayList<>(); li.add(0); - Assert.assertTrue(PublicMethodForMultiSign - .cancelAllUnfreezeWithPermissionId(ownerAddress, 2, blockingStubFull, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.cancelAllUnfreezeWithPermissionId( + ownerAddress, 2, blockingStubFull, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo info = PublicMethod.getTransactionInfoById(PublicMethodForMultiSign.cancelUnfreezeTxId, - blockingStubFull).get(); + TransactionInfo info = + PublicMethod.getTransactionInfoById( + PublicMethodForMultiSign.cancelUnfreezeTxId, blockingStubFull) + .get(); Assert.assertTrue(info.getFee() >= multiSignFee); - Account account1 = PublicMethod.queryAccount(ownerAddress,blockingStubFull); + Account account1 = PublicMethod.queryAccount(ownerAddress, blockingStubFull); logger.info(account1.toString()); Assert.assertEquals(account1.getUnfrozenV2Count(), 0); - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test004.java index b08fbadd..c44f44ed 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test004.java @@ -1,7 +1,5 @@ package stest.tron.wallet.dailybuild.freezeV2; -import com.google.protobuf.Any; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.HashMap; import java.util.List; @@ -11,24 +9,22 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.tron.api.GrpcAPI.AccountResourceMessage; import org.tron.api.WalletSolidityGrpc; import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.Account.UnFreezeV2; -import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.TransactionInfo; import org.tron.protos.Protocol.Vote; -import org.tron.protos.contract.BalanceContract.FreezeBalanceV2Contract; -import org.tron.protos.contract.BalanceContract.UnfreezeBalanceV2Contract; -import org.tron.protos.contract.BalanceContract.WithdrawExpireUnfreezeContract; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.Flaky; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -@Flaky(reason = "Timing-sensitive: unfreeze wait period race condition", - since = "2026-04-03") +@Flaky(reason = "Timing-sensitive: unfreeze wait period race condition", since = "2026-04-03") public class FreezeBalanceV2Test004 extends TronBaseTest { private static final long sendAmount = 10000000000L; private final byte[] witnessAddress = PublicMethod.getFinalAddress(witnessKey); @@ -43,195 +39,255 @@ public class FreezeBalanceV2Test004 extends TronBaseTest { Long unfreezeBalance = 1000000L; Long freezeEnergyBalance = 300000L; Integer maxUnfreezeListCount = 32; - private String soliditynode = Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list") - .get(0); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFullSolidity = null; private String pbftnode = - Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list") - .get(2); + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(2); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() throws Exception{ + public void beforeClass() throws Exception { initPbftChannel(); initSolidityChannel(); - PublicMethod.printAddress(frozenBandwidthKey); if(!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { throw new SkipException("Skipping freezeV2 test case"); + PublicMethod.printAddress(frozenBandwidthKey); + if (!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + throw new SkipException("Skipping freezeV2 test case"); } - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubFullSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - channelPbft = ManagedChannelBuilder.forTarget(pbftnode) - .usePlaintext() - .build(); - Assert.assertTrue(PublicMethod.sendcoin(frozenBandwidthAddress, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(frozenEnergyAddress, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); + channelPbft = ManagedChannelBuilder.forTarget(pbftnode).usePlaintext().build(); + Assert.assertTrue( + PublicMethod.sendcoin( + frozenBandwidthAddress, + sendAmount, + foundationAddress, + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + frozenEnergyAddress, sendAmount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceV2(frozenBandwidthAddress, - freezeBandwidthBalance,0,frozenBandwidthKey,blockingStubFull)); - if(PublicMethod.tronPowerProposalIsOpen(blockingStubFull)) { - Assert.assertTrue(PublicMethod.freezeBalanceV2(frozenBandwidthAddress, - freezeBandwidthBalance,2,frozenBandwidthKey,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + frozenBandwidthAddress, + freezeBandwidthBalance, + 0, + frozenBandwidthKey, + blockingStubFull)); + if (PublicMethod.tronPowerProposalIsOpen(blockingStubFull)) { + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + frozenBandwidthAddress, + freezeBandwidthBalance, + 2, + frozenBandwidthKey, + blockingStubFull)); } - PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubFullSolidity); - + PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubFullSolidity); } - /** - * constructor. - */ - @Test(enabled = true, description = "Max unfreeze balance list is 32", groups = {"daily", "staking"}) - public void test01MaxUnfreezeBalanceListIs32() throws Exception{ - Account account = PublicMethod.queryAccount(frozenBandwidthAddress,blockingStubFull); - Long beforeBalance = account.getBalance(); - - PublicMethod.getAvailableUnfreezeCount(frozenBandwidthAddress,blockingStubFull); - Assert.assertTrue(PublicMethod.getAvailableUnfreezeCount(frozenBandwidthAddress - ,blockingStubFull).get().getCount() == 32); - //query solidity - Assert.assertTrue(PublicMethod.getAvailableUnfreezeCountSolidity(frozenBandwidthAddress - ,blockingStubFullSolidity).get().getCount() == 32); - int unfreezeTimes = 0; + /** constructor. */ + @Test( + enabled = true, + description = "Max unfreeze balance list is 32", + groups = {"daily", "staking"}) + public void test01MaxUnfreezeBalanceListIs32() throws Exception { + Account account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); + Long beforeBalance = account.getBalance(); + + PublicMethod.getAvailableUnfreezeCount(frozenBandwidthAddress, blockingStubFull); + Assert.assertTrue( + PublicMethod.getAvailableUnfreezeCount(frozenBandwidthAddress, blockingStubFull) + .get() + .getCount() + == 32); + // query solidity + Assert.assertTrue( + PublicMethod.getAvailableUnfreezeCountSolidity( + frozenBandwidthAddress, blockingStubFullSolidity) + .get() + .getCount() + == 32); + int unfreezeTimes = 0; while (unfreezeTimes++ <= 50) { - PublicMethod.unFreezeBalanceV2(frozenBandwidthAddress,frozenBandwidthKey,unfreezeBalance,0,blockingStubFull); + PublicMethod.unFreezeBalanceV2( + frozenBandwidthAddress, frozenBandwidthKey, unfreezeBalance, 0, blockingStubFull); Thread.sleep(100L); } PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("frozenBandwidthAddress111: " + Base58.encode58Check(frozenBandwidthAddress)); - Long count = PublicMethod.getAvailableUnfreezeCount(frozenBandwidthAddress - , blockingStubFull).get().getCount(); - Account accountFrozenBandwidthAddress = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); + Long count = + PublicMethod.getAvailableUnfreezeCount(frozenBandwidthAddress, blockingStubFull) + .get() + .getCount(); + Account accountFrozenBandwidthAddress = + PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); logger.info("account++: "); logger.info(accountFrozenBandwidthAddress.toString()); Assert.assertEquals(count.longValue(), 0L); - //query solidity - PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubFullSolidity); - //query pbft - Assert.assertTrue(PublicMethod.getAvailableUnfreezeCountSolidity(frozenBandwidthAddress - ,blockingStubPbft).get().getCount() == 0); - Assert.assertTrue(PublicMethod.getAvailableUnfreezeCountSolidity(frozenBandwidthAddress - ,blockingStubFullSolidity).get().getCount() == 0); - - account = PublicMethod.queryAccount(frozenBandwidthAddress,blockingStubFull); + // query solidity + PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubFullSolidity); + // query pbft + Assert.assertTrue( + PublicMethod.getAvailableUnfreezeCountSolidity(frozenBandwidthAddress, blockingStubPbft) + .get() + .getCount() + == 0); + Assert.assertTrue( + PublicMethod.getAvailableUnfreezeCountSolidity( + frozenBandwidthAddress, blockingStubFullSolidity) + .get() + .getCount() + == 0); + + account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); Assert.assertTrue(account.getUnfrozenV2Count() == maxUnfreezeListCount); - Long maxUnfreezeExpireTime = Long.MIN_VALUE; - Long totalUnfreezeBalance = 0L; + Long maxUnfreezeExpireTime = Long.MIN_VALUE; + Long totalUnfreezeBalance = 0L; List list = account.getUnfrozenV2List(); - for(UnFreezeV2 unFreezeV2 : list) { + for (UnFreezeV2 unFreezeV2 : list) { totalUnfreezeBalance += unFreezeV2.getUnfreezeAmount(); - maxUnfreezeExpireTime = Math.max(maxUnfreezeExpireTime,unFreezeV2.getUnfreezeExpireTime()); + maxUnfreezeExpireTime = Math.max(maxUnfreezeExpireTime, unFreezeV2.getUnfreezeExpireTime()); } logger.info("maxUnfreezeExpireTime" + maxUnfreezeExpireTime); Assert.assertTrue(totalUnfreezeBalance == maxUnfreezeListCount * unfreezeBalance); - int retryTimes = 0; - while (retryTimes++ <= periodTime / 3000L && System.currentTimeMillis() - 4000 <= maxUnfreezeExpireTime) { + int retryTimes = 0; + while (retryTimes++ <= periodTime / 3000L + && System.currentTimeMillis() - 4000 <= maxUnfreezeExpireTime) { logger.info("System.currentTimeMillis()" + System.currentTimeMillis()); PublicMethod.waitProduceNextBlock(blockingStubFull); } logger.info("Final System.currentTimeMillis()" + System.currentTimeMillis()); - String txId = PublicMethod.unFreezeBalanceV2AndGetTxId(frozenBandwidthAddress,frozenBandwidthKey,unfreezeBalance,0,blockingStubFull); + String txId = + PublicMethod.unFreezeBalanceV2AndGetTxId( + frozenBandwidthAddress, frozenBandwidthKey, unfreezeBalance, 0, blockingStubFull); Assert.assertNotNull(txId); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo transactionInfo = PublicMethod.getTransactionInfoById(txId, blockingStubFull).get(); + TransactionInfo transactionInfo = + PublicMethod.getTransactionInfoById(txId, blockingStubFull).get(); - account = PublicMethod.queryAccount(frozenBandwidthAddress,blockingStubFull); - Long afterBalance = account.getBalance(); - Assert.assertEquals(account.getUnfrozenV2Count(),1); + account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); + Long afterBalance = account.getBalance(); + Assert.assertEquals(account.getUnfrozenV2Count(), 1); Assert.assertTrue((afterBalance - beforeBalance) == totalUnfreezeBalance); Assert.assertTrue(transactionInfo.getWithdrawExpireAmount() == totalUnfreezeBalance); Assert.assertTrue(transactionInfo.getUnfreezeAmount() == 0); - } - /** - * constructor. - */ - @Test(enabled = true, description = "Unfreeze cause dynamic decrease of vote", groups = {"daily", "staking"}) - public void test02UnfreezeCaseDynamicDecreaseOfVote() throws Exception{ + /** constructor. */ + @Test( + enabled = true, + description = "Unfreeze cause dynamic decrease of vote", + groups = {"daily", "staking"}) + public void test02UnfreezeCaseDynamicDecreaseOfVote() throws Exception { Long witness1ReceiveVote = 10L; - Long witness2ReceiveVote = 20L; - Account account = PublicMethod.queryAccount(frozenBandwidthAddress,blockingStubFull); - Long votePower = !PublicMethod.tronPowerProposalIsOpen(blockingStubFull) ? - account.getFrozenV2(0).getAmount() / 1000000L : - account.getFrozenV2(2).getAmount() / 1000000L; + Long witness2ReceiveVote = 20L; + Account account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); + Long votePower = + !PublicMethod.tronPowerProposalIsOpen(blockingStubFull) + ? account.getFrozenV2(0).getAmount() / 1000000L + : account.getFrozenV2(2).getAmount() / 1000000L; - HashMap voteMap = new HashMap<>(); - voteMap.put(PublicMethod.getFinalAddress(witnessKey),witness1ReceiveVote); - voteMap.put(PublicMethod.getFinalAddress(witnessKey),witness2ReceiveVote); + HashMap voteMap = new HashMap<>(); + voteMap.put(PublicMethod.getFinalAddress(witnessKey), witness1ReceiveVote); + voteMap.put(PublicMethod.getFinalAddress(witnessKey), witness2ReceiveVote); - Assert.assertTrue(PublicMethod.voteWitness(frozenBandwidthAddress,frozenBandwidthKey,voteMap,blockingStubFull)); + Assert.assertTrue( + PublicMethod.voteWitness( + frozenBandwidthAddress, frozenBandwidthKey, voteMap, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long unfreezeBalance = (votePower - witness1ReceiveVote - witness2ReceiveVote) * 1000000L; - Assert.assertTrue(PublicMethod.unFreezeBalanceV2(frozenBandwidthAddress,frozenBandwidthKey,unfreezeBalance, - PublicMethod.tronPowerProposalIsOpen(blockingStubFull) ? 2 : 0,blockingStubFull)); + Long unfreezeBalance = (votePower - witness1ReceiveVote - witness2ReceiveVote) * 1000000L; + Assert.assertTrue( + PublicMethod.unFreezeBalanceV2( + frozenBandwidthAddress, + frozenBandwidthKey, + unfreezeBalance, + PublicMethod.tronPowerProposalIsOpen(blockingStubFull) ? 2 : 0, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - account = PublicMethod.queryAccount(frozenBandwidthAddress,blockingStubFull); + account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); List list = account.getVotesList(); Assert.assertTrue(list.size() == 2); - Long currentVote = 0L; - for(Vote vote : list) { + Long currentVote = 0L; + for (Vote vote : list) { currentVote += vote.getVoteCount(); } Assert.assertTrue(currentVote == witness1ReceiveVote + witness2ReceiveVote); - Assert.assertTrue(PublicMethod.unFreezeBalanceV2(frozenBandwidthAddress,frozenBandwidthKey,(currentVote - witness1ReceiveVote / 10 - witness2ReceiveVote / 10) * 1000000L, - PublicMethod.tronPowerProposalIsOpen(blockingStubFull) ? 2 : 0,blockingStubFull)); + Assert.assertTrue( + PublicMethod.unFreezeBalanceV2( + frozenBandwidthAddress, + frozenBandwidthKey, + (currentVote - witness1ReceiveVote / 10 - witness2ReceiveVote / 10) * 1000000L, + PublicMethod.tronPowerProposalIsOpen(blockingStubFull) ? 2 : 0, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - account = PublicMethod.queryAccount(frozenBandwidthAddress,blockingStubFull); + account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); list = account.getVotesList(); Assert.assertTrue(list.size() == 2); currentVote = 0L; - for(Vote vote : list) { + for (Vote vote : list) { currentVote += vote.getVoteCount(); } - Assert.assertTrue(currentVote * 10 == witness1ReceiveVote + witness2ReceiveVote); + Assert.assertTrue(currentVote * 10 == witness1ReceiveVote + witness2ReceiveVote); - PublicMethod.unFreezeBalanceV2(frozenBandwidthAddress,frozenBandwidthKey,1L, - PublicMethod.tronPowerProposalIsOpen(blockingStubFull) ? 2 : 0,blockingStubFull); + PublicMethod.unFreezeBalanceV2( + frozenBandwidthAddress, + frozenBandwidthKey, + 1L, + PublicMethod.tronPowerProposalIsOpen(blockingStubFull) ? 2 : 0, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - account = PublicMethod.queryAccount(frozenBandwidthAddress,blockingStubFull); + account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); list = account.getVotesList(); Assert.assertTrue(list.size() == 1); currentVote = 0L; - for(Vote vote : list) { + for (Vote vote : list) { currentVote += vote.getVoteCount(); } Assert.assertTrue(currentVote == 1L); - if(PublicMethod.tronPowerProposalIsOpen(blockingStubFull)) { - Assert.assertTrue(PublicMethod.freezeBalanceV2(frozenBandwidthAddress, - (witness1ReceiveVote + witness2ReceiveVote) * 1000000L,2,frozenBandwidthKey,blockingStubFull)); + if (PublicMethod.tronPowerProposalIsOpen(blockingStubFull)) { + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + frozenBandwidthAddress, + (witness1ReceiveVote + witness2ReceiveVote) * 1000000L, + 2, + frozenBandwidthKey, + blockingStubFull)); } else { - Assert.assertTrue(PublicMethod.freezeBalanceV2(frozenBandwidthAddress, - (witness1ReceiveVote + witness2ReceiveVote) * 1000000L,0,frozenBandwidthKey,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + frozenBandwidthAddress, + (witness1ReceiveVote + witness2ReceiveVote) * 1000000L, + 0, + frozenBandwidthKey, + blockingStubFull)); } PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.voteWitness(frozenBandwidthAddress,frozenBandwidthKey,voteMap,blockingStubFull)); + Assert.assertTrue( + PublicMethod.voteWitness( + frozenBandwidthAddress, frozenBandwidthKey, voteMap, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - account = PublicMethod.queryAccount(frozenBandwidthAddress,blockingStubFull); + account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); list = account.getVotesList(); Assert.assertTrue(list.size() == 2); currentVote = 0L; - for(Vote vote : list) { + for (Vote vote : list) { currentVote += vote.getVoteCount(); } Assert.assertTrue(currentVote == witness1ReceiveVote + witness2ReceiveVote); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - PublicMethod.freeResource(frozenBandwidthAddress, frozenBandwidthKey, foundationAddress, blockingStubFull); } + PublicMethod.freeResource( + frozenBandwidthAddress, frozenBandwidthKey, foundationAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test005.java index e0ae3045..78153d84 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test005.java @@ -1,7 +1,6 @@ package stest.tron.wallet.dailybuild.freezeV2; import java.util.HashMap; -import java.util.List; import lombok.extern.slf4j.Slf4j; import org.testng.Assert; import org.testng.SkipException; @@ -10,16 +9,13 @@ import org.testng.annotations.Test; import org.tron.api.GrpcAPI.AccountResourceMessage; import org.tron.protos.Protocol.Account; -import org.tron.protos.Protocol.Account.UnFreezeV2; import org.tron.protos.Protocol.AccountType; import org.tron.protos.Protocol.Transaction.Result.contractResult; -import org.tron.protos.Protocol.TransactionInfo; -import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class FreezeBalanceV2Test005 extends TronBaseTest { @@ -40,72 +36,117 @@ public class FreezeBalanceV2Test005 extends TronBaseTest { Integer maxUnfreezeListCount = 32; byte[] contractAddress; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() throws Exception{ + public void beforeClass() throws Exception { PublicMethod.printAddress(frozenBandwidthKey); - PublicMethod.printAddress(frozenEnergyKey); if(!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { throw new SkipException("Skipping freezeV2 test case"); + PublicMethod.printAddress(frozenEnergyKey); + if (!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + throw new SkipException("Skipping freezeV2 test case"); } - Assert.assertTrue(PublicMethod.sendcoin(frozenBandwidthAddress, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(frozenEnergyAddress, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(frozenEnergyRevertAddress, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + frozenBandwidthAddress, + sendAmount, + foundationAddress, + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + frozenEnergyAddress, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + frozenEnergyRevertAddress, + sendAmount, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/contractLinkage005.sol"; - String contractName = "timeoutTest"; + String filePath = "./src/test/resources/soliditycode/contractLinkage005.sol"; + String contractName = "timeoutTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod.deployContractAndGetTransactionInfoById(contractName, abi, code, - "", maxFeeLimit, 0L, 100, null, frozenEnergyKey, - frozenEnergyAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + frozenEnergyKey, + frozenEnergyAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - contractAddress = PublicMethod.getTransactionInfoById(txid,blockingStubFull).get().getContractAddress().toByteArray(); - Assert.assertEquals(PublicMethod.queryAccount(contractAddress,blockingStubFull).getType(),AccountType.Contract); + contractAddress = + PublicMethod.getTransactionInfoById(txid, blockingStubFull) + .get() + .getContractAddress() + .toByteArray(); + Assert.assertEquals( + PublicMethod.queryAccount(contractAddress, blockingStubFull).getType(), + AccountType.Contract); - Assert.assertTrue(PublicMethod.freezeBalanceV2(frozenBandwidthAddress, - freezeBandwidthBalance,0,frozenBandwidthKey,blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceV2(frozenEnergyAddress, - freezeEnergyBalance,1,frozenEnergyKey,blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceV2(frozenEnergyRevertAddress, - freezeEnergyBalance,1,frozenEnergyRevertKey,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + frozenBandwidthAddress, + freezeBandwidthBalance, + 0, + frozenBandwidthKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + frozenEnergyAddress, freezeEnergyBalance, 1, frozenEnergyKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + frozenEnergyRevertAddress, + freezeEnergyBalance, + 1, + frozenEnergyRevertKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - } - /** - * constructor. - */ - @Test(enabled = true, description = "Bandwidth NetUsage change net_window_size", groups = {"daily", "staking"}) - public void test01BandwidthNetUsageChangeNetWindowSIze() throws Exception{ - Account account = PublicMethod.queryAccount(frozenBandwidthAddress,blockingStubFull); - AccountResourceMessage accountResourceMessage = PublicMethod.getAccountResource(frozenBandwidthAddress,blockingStubFull); - Long beforeNetUsage = account.getNetUsage(); - Long beforeNetUsageFromAccountResource = accountResourceMessage.getNetUsed(); - Long beforeNetWindowSize = account.getNetWindowSize(); + /** constructor. */ + @Test( + enabled = true, + description = "Bandwidth NetUsage change net_window_size", + groups = {"daily", "staking"}) + public void test01BandwidthNetUsageChangeNetWindowSIze() throws Exception { + Account account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); + AccountResourceMessage accountResourceMessage = + PublicMethod.getAccountResource(frozenBandwidthAddress, blockingStubFull); + Long beforeNetUsage = account.getNetUsage(); + Long beforeNetUsageFromAccountResource = accountResourceMessage.getNetUsed(); + Long beforeNetWindowSize = account.getNetWindowSize(); Assert.assertTrue(beforeNetWindowSize == 28800 * 1000); - Assert.assertEquals(beforeNetUsage,beforeNetUsageFromAccountResource); + Assert.assertEquals(beforeNetUsage, beforeNetUsageFromAccountResource); Assert.assertTrue(beforeNetUsage == 0); - String txid = PublicMethod.sendcoinGetTransactionId(foundationAddress,1L, - frozenBandwidthAddress,frozenBandwidthKey,blockingStubFull); + String txid = + PublicMethod.sendcoinGetTransactionId( + foundationAddress, 1L, frozenBandwidthAddress, frozenBandwidthKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - account = PublicMethod.queryAccount(frozenBandwidthAddress,blockingStubFull); - accountResourceMessage = PublicMethod.getAccountResource(frozenBandwidthAddress,blockingStubFull); - Long afterNetUsage = account.getNetUsage(); - Long afterNetUsageFromAccountResource = accountResourceMessage.getNetUsed(); - Assert.assertEquals(afterNetUsage,afterNetUsageFromAccountResource); - Long transactionNetUsage = PublicMethod.getTransactionInfoById(txid,blockingStubFull) - .get().getReceipt().getNetUsage(); - Assert.assertTrue(afterNetUsage <= transactionNetUsage - && afterNetUsage + 2 >= transactionNetUsage - && transactionNetUsage > 200); - Long beforeLatestConsumeTime = account.getLatestConsumeTime(); + account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); + accountResourceMessage = + PublicMethod.getAccountResource(frozenBandwidthAddress, blockingStubFull); + Long afterNetUsage = account.getNetUsage(); + Long afterNetUsageFromAccountResource = accountResourceMessage.getNetUsed(); + Assert.assertEquals(afterNetUsage, afterNetUsageFromAccountResource); + Long transactionNetUsage = + PublicMethod.getTransactionInfoById(txid, blockingStubFull) + .get() + .getReceipt() + .getNetUsage(); + Assert.assertTrue( + afterNetUsage <= transactionNetUsage + && afterNetUsage + 2 >= transactionNetUsage + && transactionNetUsage > 200); + Long beforeLatestConsumeTime = account.getLatestConsumeTime(); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -113,66 +154,85 @@ public void test01BandwidthNetUsageChangeNetWindowSIze() throws Exception{ PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - account = PublicMethod.queryAccount(frozenBandwidthAddress,blockingStubFull); - Long afterLatestConsumeTime = account.getLatestConsumeTime(); - //getLatestConsumeTime means this user latest use consume net Time,not current timestamp - Assert.assertEquals(beforeLatestConsumeTime,afterLatestConsumeTime); + account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); + Long afterLatestConsumeTime = account.getLatestConsumeTime(); + // getLatestConsumeTime means this user latest use consume net Time,not current timestamp + Assert.assertEquals(beforeLatestConsumeTime, afterLatestConsumeTime); beforeNetWindowSize = account.getNetWindowSize(); logger.info("beforeNetWindowSize:" + beforeNetWindowSize); Assert.assertTrue(beforeNetWindowSize < 28800 * 1000); beforeNetUsage = account.getNetUsage(); Assert.assertTrue(beforeNetUsage > 200); - txid = PublicMethod.sendcoinGetTransactionId(foundationAddress,1L, - frozenBandwidthAddress,frozenBandwidthKey,blockingStubFull); + txid = + PublicMethod.sendcoinGetTransactionId( + foundationAddress, 1L, frozenBandwidthAddress, frozenBandwidthKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - account = PublicMethod.queryAccount(frozenBandwidthAddress,blockingStubFull); - Long afterNetWindowSize = account.getNetWindowSize(); + account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); + Long afterNetWindowSize = account.getNetWindowSize(); logger.info("afterNetWindowSize:" + afterNetWindowSize); Assert.assertTrue( - afterNetWindowSize > beforeNetWindowSize - && afterNetWindowSize <= 28795 * 1000); + afterNetWindowSize > beforeNetWindowSize && afterNetWindowSize <= 28795 * 1000); afterNetUsage = account.getNetUsage(); - transactionNetUsage = PublicMethod.getTransactionInfoById(txid,blockingStubFull) - .get().getReceipt().getNetUsage(); - Assert.assertTrue(afterNetUsage - beforeNetUsage <= transactionNetUsage - && afterNetUsage - beforeNetUsage + 2 >= transactionNetUsage - && transactionNetUsage > 200 && afterNetUsage > 400); - + transactionNetUsage = + PublicMethod.getTransactionInfoById(txid, blockingStubFull) + .get() + .getReceipt() + .getNetUsage(); + Assert.assertTrue( + afterNetUsage - beforeNetUsage <= transactionNetUsage + && afterNetUsage - beforeNetUsage + 2 >= transactionNetUsage + && transactionNetUsage > 200 + && afterNetUsage > 400); } - /** - * constructor. - */ - @Test(enabled = true, description = "EnergyUsage change energy_window_size when trigger is success", groups = {"daily", "staking"}) - public void test02EnergyUsageChangeEnergyWindowSizeWithTriggerSuccess() throws Exception{ - Account account = PublicMethod.queryAccount(frozenEnergyAddress,blockingStubFull); - AccountResourceMessage accountResourceMessage = PublicMethod.getAccountResource(frozenEnergyAddress,blockingStubFull); - Long beforeEnergyUsage = account.getAccountResource().getEnergyUsage(); - Long beforeEnergyUsageFromAccountResource = accountResourceMessage.getEnergyUsed(); - Long beforeEnergyWindowSize = account.getAccountResource().getEnergyWindowSize(); + /** constructor. */ + @Test( + enabled = true, + description = "EnergyUsage change energy_window_size when trigger is success", + groups = {"daily", "staking"}) + public void test02EnergyUsageChangeEnergyWindowSizeWithTriggerSuccess() throws Exception { + Account account = PublicMethod.queryAccount(frozenEnergyAddress, blockingStubFull); + AccountResourceMessage accountResourceMessage = + PublicMethod.getAccountResource(frozenEnergyAddress, blockingStubFull); + Long beforeEnergyUsage = account.getAccountResource().getEnergyUsage(); + Long beforeEnergyUsageFromAccountResource = accountResourceMessage.getEnergyUsed(); + Long beforeEnergyWindowSize = account.getAccountResource().getEnergyWindowSize(); Assert.assertTrue(beforeEnergyWindowSize == 28800 * 1000); - Assert.assertEquals(beforeEnergyUsage,beforeEnergyUsageFromAccountResource); + Assert.assertEquals(beforeEnergyUsage, beforeEnergyUsageFromAccountResource); Assert.assertTrue(beforeEnergyUsage == 0); - Long cycleTime = 1L; - String txid = PublicMethod.triggerContract(contractAddress, - "testUseCpu(uint256)", cycleTime.toString(), false, - 0, maxFeeLimit,frozenEnergyAddress, frozenEnergyKey, blockingStubFull); + Long cycleTime = 1L; + String txid = + PublicMethod.triggerContract( + contractAddress, + "testUseCpu(uint256)", + cycleTime.toString(), + false, + 0, + maxFeeLimit, + frozenEnergyAddress, + frozenEnergyKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - account = PublicMethod.queryAccount(frozenEnergyAddress,blockingStubFull); - accountResourceMessage = PublicMethod.getAccountResource(frozenEnergyAddress,blockingStubFull); - Long afterEnergyUsage = account.getAccountResource().getEnergyUsage(); - Long afterEnergyUsageFromAccountResource = accountResourceMessage.getEnergyUsed(); - Assert.assertEquals(afterEnergyUsage,afterEnergyUsageFromAccountResource); - Long transactionEnergyUsage = PublicMethod.getTransactionInfoById(txid,blockingStubFull) - .get().getReceipt().getEnergyUsage(); - Assert.assertEquals(PublicMethod.getTransactionInfoById(txid,blockingStubFull) - .get().getReceipt().getResult(), contractResult.SUCCESS); + account = PublicMethod.queryAccount(frozenEnergyAddress, blockingStubFull); + accountResourceMessage = PublicMethod.getAccountResource(frozenEnergyAddress, blockingStubFull); + Long afterEnergyUsage = account.getAccountResource().getEnergyUsage(); + Long afterEnergyUsageFromAccountResource = accountResourceMessage.getEnergyUsed(); + Assert.assertEquals(afterEnergyUsage, afterEnergyUsageFromAccountResource); + Long transactionEnergyUsage = + PublicMethod.getTransactionInfoById(txid, blockingStubFull) + .get() + .getReceipt() + .getEnergyUsage(); + Assert.assertEquals( + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get().getReceipt().getResult(), + contractResult.SUCCESS); logger.info("transactionEnergyUsage:" + transactionEnergyUsage); - Assert.assertTrue(afterEnergyUsage <= transactionEnergyUsage - && afterEnergyUsage + 2 >= transactionEnergyUsage - && transactionEnergyUsage > 550); + Assert.assertTrue( + afterEnergyUsage <= transactionEnergyUsage + && afterEnergyUsage + 2 >= transactionEnergyUsage + && transactionEnergyUsage > 550); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -180,66 +240,95 @@ public void test02EnergyUsageChangeEnergyWindowSizeWithTriggerSuccess() throws E PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - account = PublicMethod.queryAccount(frozenEnergyAddress,blockingStubFull); + account = PublicMethod.queryAccount(frozenEnergyAddress, blockingStubFull); beforeEnergyWindowSize = account.getAccountResource().getEnergyWindowSize(); logger.info("beforeEnergyUsage:" + beforeEnergyUsage); Assert.assertTrue(beforeEnergyWindowSize < 28800 * 1000); beforeEnergyUsage = account.getAccountResource().getEnergyUsage(); logger.info("beforeEnergyUsage2:" + beforeEnergyUsage); Assert.assertTrue(beforeEnergyUsage > 550); - txid = PublicMethod.triggerContract(contractAddress, - "testUseCpu(uint256)", cycleTime.toString(), false, - 0, 100000000L,frozenEnergyAddress, frozenEnergyKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "testUseCpu(uint256)", + cycleTime.toString(), + false, + 0, + 100000000L, + frozenEnergyAddress, + frozenEnergyKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(PublicMethod.getTransactionInfoById(txid,blockingStubFull) - .get().getReceipt().getResult(), contractResult.SUCCESS); - account = PublicMethod.queryAccount(frozenEnergyAddress,blockingStubFull); - Long afterEnergyWindowSize = account.getAccountResource().getEnergyWindowSize(); + Assert.assertEquals( + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get().getReceipt().getResult(), + contractResult.SUCCESS); + account = PublicMethod.queryAccount(frozenEnergyAddress, blockingStubFull); + Long afterEnergyWindowSize = account.getAccountResource().getEnergyWindowSize(); logger.info("beforeEnergyWindowSize:" + beforeEnergyWindowSize); logger.info("afterEnergyWindowSize:" + afterEnergyWindowSize); - Assert.assertTrue(afterEnergyWindowSize <= 28795 * 1000 - && afterEnergyWindowSize > beforeEnergyWindowSize); + Assert.assertTrue( + afterEnergyWindowSize <= 28795 * 1000 && afterEnergyWindowSize > beforeEnergyWindowSize); afterEnergyUsage = account.getAccountResource().getEnergyUsage(); - transactionEnergyUsage = PublicMethod.getTransactionInfoById(txid,blockingStubFull) - .get().getReceipt().getEnergyUsage(); - Assert.assertTrue(afterEnergyUsage - beforeEnergyUsage <= transactionEnergyUsage - && afterEnergyUsage - beforeEnergyUsage + 8 >= transactionEnergyUsage - && transactionEnergyUsage > 550 && afterEnergyUsage > 550 * 2); - + transactionEnergyUsage = + PublicMethod.getTransactionInfoById(txid, blockingStubFull) + .get() + .getReceipt() + .getEnergyUsage(); + Assert.assertTrue( + afterEnergyUsage - beforeEnergyUsage <= transactionEnergyUsage + && afterEnergyUsage - beforeEnergyUsage + 8 >= transactionEnergyUsage + && transactionEnergyUsage > 550 + && afterEnergyUsage > 550 * 2); } - /** - * constructor. - */ - @Test(enabled = true, description = "EnergyUsage change energy_window_size when trigger is revert", groups = {"daily", "staking"}) - public void test03EnergyUsageChangeEnergyWindowSizeWithTriggerRevert() throws Exception{ - Account account = PublicMethod.queryAccount(frozenEnergyRevertAddress,blockingStubFull); - AccountResourceMessage accountResourceMessage = PublicMethod.getAccountResource(frozenEnergyRevertAddress,blockingStubFull); - Long beforeEnergyUsage = account.getAccountResource().getEnergyUsage(); - Long beforeEnergyUsageFromAccountResource = accountResourceMessage.getEnergyUsed(); - Long beforeEnergyWindowSize = account.getAccountResource().getEnergyWindowSize(); + /** constructor. */ + @Test( + enabled = true, + description = "EnergyUsage change energy_window_size when trigger is revert", + groups = {"daily", "staking"}) + public void test03EnergyUsageChangeEnergyWindowSizeWithTriggerRevert() throws Exception { + Account account = PublicMethod.queryAccount(frozenEnergyRevertAddress, blockingStubFull); + AccountResourceMessage accountResourceMessage = + PublicMethod.getAccountResource(frozenEnergyRevertAddress, blockingStubFull); + Long beforeEnergyUsage = account.getAccountResource().getEnergyUsage(); + Long beforeEnergyUsageFromAccountResource = accountResourceMessage.getEnergyUsed(); + Long beforeEnergyWindowSize = account.getAccountResource().getEnergyWindowSize(); Assert.assertTrue(beforeEnergyWindowSize == 28800 * 1000); - Assert.assertEquals(beforeEnergyUsage,beforeEnergyUsageFromAccountResource); + Assert.assertEquals(beforeEnergyUsage, beforeEnergyUsageFromAccountResource); Assert.assertTrue(beforeEnergyUsage == 0); - //Wrong method cause result is revert - String txid = PublicMethod.triggerContract(contractAddress, - "getRevertTransaction()", "", false, - 0, maxFeeLimit,frozenEnergyRevertAddress, frozenEnergyRevertKey, blockingStubFull); + // Wrong method cause result is revert + String txid = + PublicMethod.triggerContract( + contractAddress, + "getRevertTransaction()", + "", + false, + 0, + maxFeeLimit, + frozenEnergyRevertAddress, + frozenEnergyRevertKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - account = PublicMethod.queryAccount(frozenEnergyRevertAddress,blockingStubFull); - accountResourceMessage = PublicMethod.getAccountResource(frozenEnergyRevertAddress,blockingStubFull); - Long afterEnergyUsage = account.getAccountResource().getEnergyUsage(); - Long afterEnergyUsageFromAccountResource = accountResourceMessage.getEnergyUsed(); - Assert.assertEquals(afterEnergyUsage,afterEnergyUsageFromAccountResource); - Long transactionEnergyUsage = PublicMethod.getTransactionInfoById(txid,blockingStubFull) - .get().getReceipt().getEnergyUsage(); - Assert.assertEquals(PublicMethod.getTransactionInfoById(txid,blockingStubFull) - .get().getReceipt().getResult(), contractResult.REVERT); + account = PublicMethod.queryAccount(frozenEnergyRevertAddress, blockingStubFull); + accountResourceMessage = + PublicMethod.getAccountResource(frozenEnergyRevertAddress, blockingStubFull); + Long afterEnergyUsage = account.getAccountResource().getEnergyUsage(); + Long afterEnergyUsageFromAccountResource = accountResourceMessage.getEnergyUsed(); + Assert.assertEquals(afterEnergyUsage, afterEnergyUsageFromAccountResource); + Long transactionEnergyUsage = + PublicMethod.getTransactionInfoById(txid, blockingStubFull) + .get() + .getReceipt() + .getEnergyUsage(); + Assert.assertEquals( + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get().getReceipt().getResult(), + contractResult.REVERT); logger.info("transactionEnergyUsage:" + transactionEnergyUsage); - Assert.assertTrue(afterEnergyUsage <= transactionEnergyUsage - && afterEnergyUsage + 2 >= transactionEnergyUsage - && transactionEnergyUsage > 150); + Assert.assertTrue( + afterEnergyUsage <= transactionEnergyUsage + && afterEnergyUsage + 2 >= transactionEnergyUsage + && transactionEnergyUsage > 150); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -247,42 +336,54 @@ public void test03EnergyUsageChangeEnergyWindowSizeWithTriggerRevert() throws Ex PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - account = PublicMethod.queryAccount(frozenEnergyRevertAddress,blockingStubFull); + account = PublicMethod.queryAccount(frozenEnergyRevertAddress, blockingStubFull); beforeEnergyWindowSize = account.getAccountResource().getEnergyWindowSize(); logger.info("beforeEnergyUsage:" + beforeEnergyUsage); Assert.assertTrue(beforeEnergyWindowSize < 28800 * 1000); beforeEnergyUsage = account.getAccountResource().getEnergyUsage(); Assert.assertTrue(beforeEnergyUsage > 50); - txid = PublicMethod.triggerContract(contractAddress, - "getRevertTransaction()", "", false, - 0, maxFeeLimit,frozenEnergyRevertAddress, frozenEnergyRevertKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "getRevertTransaction()", + "", + false, + 0, + maxFeeLimit, + frozenEnergyRevertAddress, + frozenEnergyRevertKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(PublicMethod.getTransactionInfoById(txid,blockingStubFull) - .get().getReceipt().getResult(), contractResult.REVERT); - account = PublicMethod.queryAccount(frozenEnergyRevertAddress,blockingStubFull); - Long afterEnergyWindowSize = account.getAccountResource().getEnergyWindowSize(); + Assert.assertEquals( + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get().getReceipt().getResult(), + contractResult.REVERT); + account = PublicMethod.queryAccount(frozenEnergyRevertAddress, blockingStubFull); + Long afterEnergyWindowSize = account.getAccountResource().getEnergyWindowSize(); logger.info("beforeEnergyWindowSize:" + beforeEnergyWindowSize); logger.info("afterEnergyWindowSize:" + afterEnergyWindowSize); - Assert.assertTrue(afterEnergyWindowSize <= 28795 * 1000 - && afterEnergyWindowSize > beforeEnergyWindowSize); + Assert.assertTrue( + afterEnergyWindowSize <= 28795 * 1000 && afterEnergyWindowSize > beforeEnergyWindowSize); afterEnergyUsage = account.getAccountResource().getEnergyUsage(); - transactionEnergyUsage = PublicMethod.getTransactionInfoById(txid,blockingStubFull) - .get().getReceipt().getEnergyUsage(); - Assert.assertTrue(afterEnergyUsage - beforeEnergyUsage <= transactionEnergyUsage - && afterEnergyUsage - beforeEnergyUsage + 8 >= transactionEnergyUsage - && transactionEnergyUsage > 150 && afterEnergyUsage > 150 * 2); + transactionEnergyUsage = + PublicMethod.getTransactionInfoById(txid, blockingStubFull) + .get() + .getReceipt() + .getEnergyUsage(); + Assert.assertTrue( + afterEnergyUsage - beforeEnergyUsage <= transactionEnergyUsage + && afterEnergyUsage - beforeEnergyUsage + 8 >= transactionEnergyUsage + && transactionEnergyUsage > 150 + && afterEnergyUsage > 150 * 2); Assert.assertTrue(account.getNetWindowOptimized()); Assert.assertTrue(account.getAccountResource().getEnergyWindowOptimized()); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - PublicMethod.freeResource(frozenBandwidthAddress, frozenBandwidthKey, foundationAddress, blockingStubFull); } + PublicMethod.freeResource( + frozenBandwidthAddress, frozenBandwidthKey, foundationAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test006.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test006.java index dfbaa998..d05820ba 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test006.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test006.java @@ -1,8 +1,5 @@ package stest.tron.wallet.dailybuild.freezeV2; -import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.google.protobuf.Any; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.Optional; import lombok.extern.slf4j.Slf4j; @@ -12,25 +9,22 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI; -import org.tron.api.GrpcAPI.AccountResourceMessage; import org.tron.api.GrpcAPI.DelegatedResourceList; import org.tron.api.WalletSolidityGrpc; import org.tron.protos.Protocol.Account; -import org.tron.protos.Protocol.DelegatedResource; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.TransactionInfo; -import org.tron.protos.contract.BalanceContract.FreezeBalanceV2Contract; -import org.tron.protos.contract.BalanceContract.UnfreezeBalanceV2Contract; -import org.tron.protos.contract.BalanceContract.WithdrawExpireUnfreezeContract; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; -import zmq.socket.pubsub.Pub; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.Flaky; +import stest.tron.wallet.common.client.utils.ProposalEnum; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -@Flaky(reason = "Timing-sensitive: delegate resource expiry timing", - since = "2026-04-03") +@Flaky(reason = "Timing-sensitive: delegate resource expiry timing", since = "2026-04-03") public class FreezeBalanceV2Test006 extends TronBaseTest { private static final long sendAmount = 10000000000L; private final Long periodTime = 60_000L; @@ -44,202 +38,259 @@ public class FreezeBalanceV2Test006 extends TronBaseTest { Long freezeBandwidthBalance = 6000000L; Long delegateBalance = 1000000L; private String soliditynode = - Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list") - .get(0); + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFullSolidity = null; private String pbftnode = - Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list") - .get(2); + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(2); private Long maxDelegateLockPeriod = null; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() throws Exception { initPbftChannel(); initSolidityChannel(); - PublicMethod.printAddress(frozenBandwidthKey); if (!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { throw new SkipException("Skipping freezeV2 test case"); + PublicMethod.printAddress(frozenBandwidthKey); + if (!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + throw new SkipException("Skipping freezeV2 test case"); } - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubFullSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - channelPbft = ManagedChannelBuilder.forTarget(pbftnode) - .usePlaintext() - .build(); + channelPbft = ManagedChannelBuilder.forTarget(pbftnode).usePlaintext().build(); PublicMethod.printAddress(frozenBandwidthKey); PublicMethod.printAddress(receiverKey); - Assert.assertTrue(PublicMethod.sendcoin(frozenBandwidthAddress, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(receiverAddress, 1L, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + frozenBandwidthAddress, + sendAmount, + foundationAddress, + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + receiverAddress, 1L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceV2(frozenBandwidthAddress, freezeBandwidthBalance, - 0, frozenBandwidthKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + frozenBandwidthAddress, + freezeBandwidthBalance, + 0, + frozenBandwidthKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - maxDelegateLockPeriod - = PublicMethod - .getChainParametersValue( - ProposalEnum.getMaxDelegateLockPeriod.getProposalName(), blockingStubFull - ); - + maxDelegateLockPeriod = + PublicMethod.getChainParametersValue( + ProposalEnum.getMaxDelegateLockPeriod.getProposalName(), blockingStubFull); } - - /** - * constructor. - */ - @Test(enabled = true, description = "Delegate lock value is true.", groups = {"daily", "staking"}) + /** constructor. */ + @Test( + enabled = true, + description = "Delegate lock value is true.", + groups = {"daily", "staking"}) public void test01DelegateResourceLockValueIsTrueTest() throws Exception { - Assert.assertTrue(PublicMethod.delegateResourceV2Lock(frozenBandwidthAddress, - delegateBalance, 0, false, null, - receiverAddress, frozenBandwidthKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.delegateResourceV2Lock( + frozenBandwidthAddress, + delegateBalance, + 0, + false, + null, + receiverAddress, + frozenBandwidthKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - final long beforeLockTrueTime = System.currentTimeMillis(); + final long beforeLockTrueTime = System.currentTimeMillis(); - Assert.assertTrue(PublicMethod.delegateResourceV2Lock(frozenBandwidthAddress, - delegateBalance, 0, true, null, - receiverAddress, frozenBandwidthKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.delegateResourceV2Lock( + frozenBandwidthAddress, + delegateBalance, + 0, + true, + null, + receiverAddress, + frozenBandwidthKey, + blockingStubFull)); ; PublicMethod.waitProduceNextBlock(blockingStubFull); - DelegatedResourceList delegatedResourceList = PublicMethod - .getDelegatedResource(frozenBandwidthAddress, receiverAddress, blockingStubFull).get(); + DelegatedResourceList delegatedResourceList = + PublicMethod.getDelegatedResource(frozenBandwidthAddress, receiverAddress, blockingStubFull) + .get(); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubFullSolidity); - //query solidity - DelegatedResourceList delegatedResourceListSolidity = PublicMethod - .getDelegatedResourceV2Solidity(frozenBandwidthAddress, - receiverAddress, blockingStubFullSolidity).get(); + // query solidity + DelegatedResourceList delegatedResourceListSolidity = + PublicMethod.getDelegatedResourceV2Solidity( + frozenBandwidthAddress, receiverAddress, blockingStubFullSolidity) + .get(); Assert.assertEquals(delegatedResourceListSolidity, delegatedResourceList); - //query pbft + // query pbft PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubPbft); - DelegatedResourceList delegatedResourceListPbft = PublicMethod - .getDelegatedResourceV2Solidity(frozenBandwidthAddress, - receiverAddress, blockingStubPbft).get(); + DelegatedResourceList delegatedResourceListPbft = + PublicMethod.getDelegatedResourceV2Solidity( + frozenBandwidthAddress, receiverAddress, blockingStubPbft) + .get(); Assert.assertEquals(delegatedResourceListPbft, delegatedResourceList); - long unlockTimeStamp = delegatedResourceList.getDelegatedResource(1).getExpireTimeForBandwidth(); Assert.assertTrue( delegatedResourceList.getDelegatedResource(0).getExpireTimeForBandwidth() == 0L); Assert.assertTrue( unlockTimeStamp > beforeLockTrueTime - && - unlockTimeStamp <= System.currentTimeMillis() + delegateLockTime); - - - Assert.assertFalse(PublicMethod.unDelegateResourceV2(frozenBandwidthAddress, - delegateBalance + 1, 0, - receiverAddress, frozenBandwidthKey, blockingStubFull)); + && unlockTimeStamp <= System.currentTimeMillis() + delegateLockTime); + Assert.assertFalse( + PublicMethod.unDelegateResourceV2( + frozenBandwidthAddress, + delegateBalance + 1, + 0, + receiverAddress, + frozenBandwidthKey, + blockingStubFull)); - Assert.assertTrue(PublicMethod.unDelegateResourceV2(frozenBandwidthAddress, - delegateBalance, 0, - receiverAddress, frozenBandwidthKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.unDelegateResourceV2( + frozenBandwidthAddress, + delegateBalance, + 0, + receiverAddress, + frozenBandwidthKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - delegatedResourceList = PublicMethod - .getDelegatedResource(frozenBandwidthAddress, receiverAddress, blockingStubFull).get(); + delegatedResourceList = + PublicMethod.getDelegatedResource(frozenBandwidthAddress, receiverAddress, blockingStubFull) + .get(); Assert.assertEquals(delegatedResourceList.getDelegatedResourceCount(), 1); Assert.assertTrue( delegatedResourceList.getDelegatedResource(0).getExpireTimeForBandwidth() > 0L); - - Assert.assertFalse(PublicMethod.unDelegateResourceV2(frozenBandwidthAddress, - delegateBalance, 0, - receiverAddress, frozenBandwidthKey, blockingStubFull)); - int retryTimes = 0; + Assert.assertFalse( + PublicMethod.unDelegateResourceV2( + frozenBandwidthAddress, + delegateBalance, + 0, + receiverAddress, + frozenBandwidthKey, + blockingStubFull)); + int retryTimes = 0; while (retryTimes++ <= 50 && System.currentTimeMillis() <= unlockTimeStamp + 3000L) { PublicMethod.waitProduceNextBlock(blockingStubFull); } - Assert.assertTrue(PublicMethod.unDelegateResourceV2(frozenBandwidthAddress, - delegateBalance, 0, - receiverAddress, frozenBandwidthKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.unDelegateResourceV2( + frozenBandwidthAddress, + delegateBalance, + 0, + receiverAddress, + frozenBandwidthKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - delegatedResourceList = PublicMethod - .getDelegatedResource(frozenBandwidthAddress, receiverAddress, blockingStubFull).get(); + delegatedResourceList = + PublicMethod.getDelegatedResource(frozenBandwidthAddress, receiverAddress, blockingStubFull) + .get(); Assert.assertEquals(delegatedResourceList.getDelegatedResourceCount(), 0); - - } - @Test(enabled = true, description = - "delegateResource bandwidth lock = true and lockPeriod is a non-zero value", groups = {"daily", "staking"}) + @Test( + enabled = true, + description = "delegateResource bandwidth lock = true and lockPeriod is a non-zero value", + groups = {"daily", "staking"}) public void test02DelegateResourceBandWidthLockPeriodValueIsNonZeroTest() { ECKey from = new ECKey(Utils.getRandom()); - byte[] fromAddress = from.getAddress(); - String fromKey = ByteArray.toHexString(from.getPrivKeyBytes()); - PublicMethod.sendcoin(fromAddress, sendAmount, foundationAddress, foundationKey, - blockingStubFull); + byte[] fromAddress = from.getAddress(); + String fromKey = ByteArray.toHexString(from.getPrivKeyBytes()); + PublicMethod.sendcoin( + fromAddress, sendAmount, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.freezeBalanceV2(fromAddress, freezeBandwidthBalance, 0, fromKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - final Long lockPeriod = 3L; - Account beforeDelegateAccount = PublicMethod.queryAccount(fromAddress, blockingStubFull); - String txId = PublicMethod.delegateResourceV2LockAndGetTxId( - fromAddress, delegateBalance, 0, true, - lockPeriod, receiverAddress, fromKey, blockingStubFull); + final Long lockPeriod = 3L; + Account beforeDelegateAccount = PublicMethod.queryAccount(fromAddress, blockingStubFull); + String txId = + PublicMethod.delegateResourceV2LockAndGetTxId( + fromAddress, + delegateBalance, + 0, + true, + lockPeriod, + receiverAddress, + fromKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txId, blockingStubFull).get(); - Long currentTime = info.getBlockTimeStamp() - 3000L; + Long currentTime = info.getBlockTimeStamp() - 3000L; logger.info("nowTime: " + currentTime); Account afterDelegateAccount = PublicMethod.queryAccount(fromAddress, blockingStubFull); Assert.assertEquals( beforeDelegateAccount.getFrozenV2(0).getAmount() - afterDelegateAccount.getFrozenV2(0).getAmount(), delegateBalance.longValue()); - Optional delegatedResourceList - = PublicMethod.getDelegatedResourceV2(fromAddress, receiverAddress, blockingStubFull); - Long expireTimeForBandwidth - = delegatedResourceList.get().getDelegatedResource(0).getExpireTimeForBandwidth(); + Optional delegatedResourceList = + PublicMethod.getDelegatedResourceV2(fromAddress, receiverAddress, blockingStubFull); + Long expireTimeForBandwidth = + delegatedResourceList.get().getDelegatedResource(0).getExpireTimeForBandwidth(); logger.info("delegatedResourceList: " + delegatedResourceList.get()); Assert.assertEquals(expireTimeForBandwidth - currentTime, lockPeriod * 3 * 1000L); } - @Test(enabled = true, description = "unDelegateResource energy after lockPeriod", groups = {"daily", "staking"}) + @Test( + enabled = true, + description = "unDelegateResource energy after lockPeriod", + groups = {"daily", "staking"}) public void test03unDelegateEnergyAfterLockPeriod() { ECKey from = new ECKey(Utils.getRandom()); - byte[] fromAddress = from.getAddress(); - String fromKey = ByteArray.toHexString(from.getPrivKeyBytes()); - PublicMethod.sendcoin(fromAddress, sendAmount, foundationAddress, foundationKey, - blockingStubFull); + byte[] fromAddress = from.getAddress(); + String fromKey = ByteArray.toHexString(from.getPrivKeyBytes()); + PublicMethod.sendcoin( + fromAddress, sendAmount, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.freezeBalanceV2(fromAddress, freezeBandwidthBalance, 1, fromKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - final long lockPeriod = 3L; - String txId = PublicMethod.delegateResourceV2LockAndGetTxId(fromAddress, - delegateBalance, 1, true, lockPeriod, receiverAddress, fromKey, blockingStubFull); + final long lockPeriod = 3L; + String txId = + PublicMethod.delegateResourceV2LockAndGetTxId( + fromAddress, + delegateBalance, + 1, + true, + lockPeriod, + receiverAddress, + fromKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txId, blockingStubFull).get(); - Long currentTime = info.getBlockTimeStamp() - 3000L; + Long currentTime = info.getBlockTimeStamp() - 3000L; logger.info("nowTime: " + currentTime); Optional delegatedResourceList = PublicMethod.getDelegatedResourceV2(fromAddress, receiverAddress, blockingStubFull); - Long expireTimeForEnergy - = delegatedResourceList.get().getDelegatedResource(0).getExpireTimeForEnergy(); + Long expireTimeForEnergy = + delegatedResourceList.get().getDelegatedResource(0).getExpireTimeForEnergy(); logger.info("delegatedResourceList: " + delegatedResourceList.get()); - Assert.assertEquals( - expireTimeForEnergy - currentTime, lockPeriod * 3 * 1000L); - // It can not unDelegated before expire time - GrpcAPI.TransactionExtention ext - = PublicMethod.unDelegateResourceV2AndGetTransactionExtention( + Assert.assertEquals(expireTimeForEnergy - currentTime, lockPeriod * 3 * 1000L); + // It can not unDelegated before expire time + GrpcAPI.TransactionExtention ext = + PublicMethod.unDelegateResourceV2AndGetTransactionExtention( fromAddress, delegateBalance, 1, receiverAddress, fromKey, blockingStubFull); logger.info("ext: " + ext); Assert.assertTrue(ext.toString().contains("CONTRACT_VALIDATE_ERROR")); - Assert.assertTrue(ext.toString().contains( - "Contract validate error : insufficient delegateFrozenBalance(Energy), request=" - + delegateBalance + ", unlock_balance=0")); - int retryTimes = 3; + Assert.assertTrue( + ext.toString() + .contains( + "Contract validate error : insufficient delegateFrozenBalance(Energy), request=" + + delegateBalance + + ", unlock_balance=0")); + int retryTimes = 3; while (retryTimes-- > 0) { PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("wait one block..."); } - String txId2 = PublicMethod.unDelegateResourceV2AndGetTxId( - fromAddress, delegateBalance, 1, receiverAddress, fromKey, blockingStubFull); + String txId2 = + PublicMethod.unDelegateResourceV2AndGetTxId( + fromAddress, delegateBalance, 1, receiverAddress, fromKey, blockingStubFull); logger.info("txId2:" + txId2); Assert.assertNotNull(txId2); Transaction transaction = PublicMethod.getTransactionById(txId2, blockingStubFull).get(); @@ -247,27 +298,30 @@ public void test03unDelegateEnergyAfterLockPeriod() { transaction.getRet(0).getContractRet(), Transaction.Result.contractResult.SUCCESS); } - @Test(enabled = true, description - = "lock = false an lockPeriod = non-zero value, lockPeriod is invalid", groups = {"daily", "staking"}) + @Test( + enabled = true, + description = "lock = false an lockPeriod = non-zero value, lockPeriod is invalid", + groups = {"daily", "staking"}) public void test04InvalidLockPeriodValueWhenLockIsFalse() { ECKey from = new ECKey(Utils.getRandom()); - byte[] fromAddress = from.getAddress(); - String fromKey = ByteArray.toHexString(from.getPrivKeyBytes()); - PublicMethod.sendcoin(fromAddress, sendAmount, foundationAddress, foundationKey, - blockingStubFull); + byte[] fromAddress = from.getAddress(); + String fromKey = ByteArray.toHexString(from.getPrivKeyBytes()); + PublicMethod.sendcoin( + fromAddress, sendAmount, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.freezeBalanceV2(fromAddress, freezeBandwidthBalance, 1, fromKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.delegateResourceV2Lock(fromAddress, delegateBalance, 1, false, 50L, - receiverAddress, fromKey, blockingStubFull); + PublicMethod.delegateResourceV2Lock( + fromAddress, delegateBalance, 1, false, 50L, receiverAddress, fromKey, blockingStubFull); logger.info("nowTime: " + System.currentTimeMillis()); - Optional delegatedResourceList - = PublicMethod.getDelegatedResourceV2(fromAddress, receiverAddress, blockingStubFull); - long expireTimeForEnergy - = delegatedResourceList.get().getDelegatedResource(0).getExpireTimeForEnergy(); + Optional delegatedResourceList = + PublicMethod.getDelegatedResourceV2(fromAddress, receiverAddress, blockingStubFull); + long expireTimeForEnergy = + delegatedResourceList.get().getDelegatedResource(0).getExpireTimeForEnergy(); Assert.assertEquals(expireTimeForEnergy, 0); - String txId1 = PublicMethod.unDelegateResourceV2AndGetTxId(fromAddress, delegateBalance, 1, - receiverAddress, fromKey, blockingStubFull); + String txId1 = + PublicMethod.unDelegateResourceV2AndGetTxId( + fromAddress, delegateBalance, 1, receiverAddress, fromKey, blockingStubFull); logger.info("unDelegateResourceV2AndGetTxId: " + txId1); Assert.assertNotNull(txId1); Transaction transaction = PublicMethod.getTransactionById(txId1, blockingStubFull).get(); @@ -275,156 +329,217 @@ public void test04InvalidLockPeriodValueWhenLockIsFalse() { transaction.getRet(0).getContractRet(), Transaction.Result.contractResult.SUCCESS); } - @Test(enabled = true, description = "only lock = true equals lock = true and lockPeriod = 0", groups = {"daily", "staking"}) + @Test( + enabled = true, + description = "only lock = true equals lock = true and lockPeriod = 0", + groups = {"daily", "staking"}) public void test05LockPeriodIsZero() { ECKey from = new ECKey(Utils.getRandom()); - byte[] fromAddress = from.getAddress(); - String fromKey = ByteArray.toHexString(from.getPrivKeyBytes()); - PublicMethod.sendcoin(fromAddress, sendAmount, foundationAddress, foundationKey, - blockingStubFull); + byte[] fromAddress = from.getAddress(); + String fromKey = ByteArray.toHexString(from.getPrivKeyBytes()); + PublicMethod.sendcoin( + fromAddress, sendAmount, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.freezeBalanceV2(fromAddress, freezeBandwidthBalance, 1, fromKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txId = PublicMethod.delegateResourceV2LockAndGetTxId(fromAddress, - delegateBalance, 1, true, 0L, receiverAddress, fromKey, blockingStubFull); + String txId = + PublicMethod.delegateResourceV2LockAndGetTxId( + fromAddress, delegateBalance, 1, true, 0L, receiverAddress, fromKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txId, blockingStubFull).get(); - Long currentTime = info.getBlockTimeStamp() - 3000L; - Optional delegatedResourceList - = PublicMethod.getDelegatedResourceV2(fromAddress, receiverAddress, blockingStubFull); - Long unlockTimeStamp - = delegatedResourceList.get().getDelegatedResource(0).getExpireTimeForEnergy(); + Long currentTime = info.getBlockTimeStamp() - 3000L; + Optional delegatedResourceList = + PublicMethod.getDelegatedResourceV2(fromAddress, receiverAddress, blockingStubFull); + Long unlockTimeStamp = + delegatedResourceList.get().getDelegatedResource(0).getExpireTimeForEnergy(); logger.info("beforeLockTrueTime: " + currentTime); logger.info("unlockTimeStamp: " + unlockTimeStamp); Assert.assertEquals(unlockTimeStamp - currentTime, delegateLockTime.longValue()); } - @Test(enabled = true, description = "Period boundary test", groups = {"daily", "staking"}) + @Test( + enabled = true, + description = "Period boundary test", + groups = {"daily", "staking"}) public void test06LockPeriodBoundaryTest() { Long maxPeriod = maxDelegateLockPeriod; - ECKey from = new ECKey(Utils.getRandom()); - byte[] fromAddress = from.getAddress(); - String fromKey = ByteArray.toHexString(from.getPrivKeyBytes()); - PublicMethod.sendcoin(fromAddress, sendAmount, foundationAddress, foundationKey, - blockingStubFull); + ECKey from = new ECKey(Utils.getRandom()); + byte[] fromAddress = from.getAddress(); + String fromKey = ByteArray.toHexString(from.getPrivKeyBytes()); + PublicMethod.sendcoin( + fromAddress, sendAmount, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.freezeBalanceV2(fromAddress, freezeBandwidthBalance, 1, fromKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - GrpcAPI.TransactionExtention ext = PublicMethod.delegateResourceV2AndGetTransactionExtention( - fromAddress, delegateBalance, 1, true, maxPeriod + 1, - receiverAddress, fromKey, blockingStubFull); + GrpcAPI.TransactionExtention ext = + PublicMethod.delegateResourceV2AndGetTransactionExtention( + fromAddress, + delegateBalance, + 1, + true, + maxPeriod + 1, + receiverAddress, + fromKey, + blockingStubFull); logger.info("ext.toString(): " + ext); Assert.assertTrue(ext.toString().contains("CONTRACT_VALIDATE_ERROR")); - Assert.assertTrue(ext.toString().contains( - "The lock period of delegate resource cannot be less than 0 and cannot exceed " - + maxPeriod + "!") - ); + Assert.assertTrue( + ext.toString() + .contains( + "The lock period of delegate resource cannot be less than 0 and cannot exceed " + + maxPeriod + + "!")); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txId2 = PublicMethod.delegateResourceV2LockAndGetTxId( - fromAddress, delegateBalance, 1, true, maxPeriod, - receiverAddress, fromKey, blockingStubFull); + String txId2 = + PublicMethod.delegateResourceV2LockAndGetTxId( + fromAddress, + delegateBalance, + 1, + true, + maxPeriod, + receiverAddress, + fromKey, + blockingStubFull); Assert.assertNotNull(txId2); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txId2, blockingStubFull).get(); long lastBlockNumber = info.getBlockNumber() - 1; - Long lockStartTime = PublicMethod.getBlock2(lastBlockNumber, blockingStubFull).getBlockHeader().getRawData().getTimestamp(); - Optional delegatedResourceList - = PublicMethod.getDelegatedResourceV2(fromAddress, receiverAddress, blockingStubFull); - long unlockTimeStamp - = delegatedResourceList.get().getDelegatedResource(0).getExpireTimeForEnergy(); + Long lockStartTime = + PublicMethod.getBlock2(lastBlockNumber, blockingStubFull) + .getBlockHeader() + .getRawData() + .getTimestamp(); + Optional delegatedResourceList = + PublicMethod.getDelegatedResourceV2(fromAddress, receiverAddress, blockingStubFull); + long unlockTimeStamp = + delegatedResourceList.get().getDelegatedResource(0).getExpireTimeForEnergy(); logger.info("beforeLockTrueTime: " + lockStartTime); logger.info("unlockTimeStamp: " + unlockTimeStamp); Assert.assertEquals(unlockTimeStamp - lockStartTime, maxPeriod * 3 * 1000L); - } - @Test(enabled = true, description - = "Period less than current expire time and bigger than expire time", groups = {"daily", "staking"}) + @Test( + enabled = true, + description = "Period less than current expire time and bigger than expire time", + groups = {"daily", "staking"}) public void test07LockPeriodLessAndBiggerThanCurrentExpireTime() { long lockPeriod = 5000L; - ECKey from = new ECKey(Utils.getRandom()); - byte[] fromAddress = from.getAddress(); - String fromKey = ByteArray.toHexString(from.getPrivKeyBytes()); - PublicMethod.sendcoin(fromAddress, sendAmount, foundationAddress, foundationKey, - blockingStubFull); + ECKey from = new ECKey(Utils.getRandom()); + byte[] fromAddress = from.getAddress(); + String fromKey = ByteArray.toHexString(from.getPrivKeyBytes()); + PublicMethod.sendcoin( + fromAddress, sendAmount, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.freezeBalanceV2(fromAddress, freezeBandwidthBalance, 1, fromKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long beforeDelegateTime = System.currentTimeMillis(); - PublicMethod.delegateResourceV2LockAndGetTxId(fromAddress, delegateBalance, 1, true, lockPeriod, - receiverAddress, fromKey, blockingStubFull); + Long beforeDelegateTime = System.currentTimeMillis(); + PublicMethod.delegateResourceV2LockAndGetTxId( + fromAddress, + delegateBalance, + 1, + true, + lockPeriod, + receiverAddress, + fromKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional beforeDelegatedResourceList - = PublicMethod.getDelegatedResourceV2(fromAddress, receiverAddress, blockingStubFull); - Long beforeUnlockTimeStamp - = beforeDelegatedResourceList.get().getDelegatedResource(0).getExpireTimeForEnergy(); + Optional beforeDelegatedResourceList = + PublicMethod.getDelegatedResourceV2(fromAddress, receiverAddress, blockingStubFull); + Long beforeUnlockTimeStamp = + beforeDelegatedResourceList.get().getDelegatedResource(0).getExpireTimeForEnergy(); Assert.assertTrue( Math.abs((beforeUnlockTimeStamp - beforeDelegateTime) - (lockPeriod * 3 * 1000)) < 5000L); PublicMethod.waitProduceNextBlock(blockingStubFull); - GrpcAPI.TransactionExtention ext = PublicMethod.delegateResourceV2AndGetTransactionExtention( - fromAddress, delegateBalance, 1, true, lockPeriod - 1000L, - receiverAddress, fromKey, blockingStubFull); + GrpcAPI.TransactionExtention ext = + PublicMethod.delegateResourceV2AndGetTransactionExtention( + fromAddress, + delegateBalance, + 1, + true, + lockPeriod - 1000L, + receiverAddress, + fromKey, + blockingStubFull); logger.info("ext.toString(): " + ext); Assert.assertTrue(ext.toString().contains("CONTRACT_VALIDATE_ERROR")); - Assert.assertTrue(ext.toString().contains( - "The lock period for ENERGY this time cannot be less than the remaining time") - ); - String txId = PublicMethod.delegateResourceV2LockAndGetTxId( - fromAddress, delegateBalance, 1, true, lockPeriod + 1000, - receiverAddress, fromKey, blockingStubFull); + Assert.assertTrue( + ext.toString() + .contains( + "The lock period for ENERGY this time cannot be less than the remaining time")); + String txId = + PublicMethod.delegateResourceV2LockAndGetTxId( + fromAddress, + delegateBalance, + 1, + true, + lockPeriod + 1000, + receiverAddress, + fromKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txId, blockingStubFull).get(); - Long afterDelegateTime = info.getBlockTimeStamp() - 3000L; + Long afterDelegateTime = info.getBlockTimeStamp() - 3000L; - Optional afterDelegatedResourceList - = PublicMethod.getDelegatedResourceV2(fromAddress, receiverAddress, blockingStubFull); - Long afterUnlockTimeStamp - = afterDelegatedResourceList.get().getDelegatedResource(0).getExpireTimeForEnergy(); + Optional afterDelegatedResourceList = + PublicMethod.getDelegatedResourceV2(fromAddress, receiverAddress, blockingStubFull); + Long afterUnlockTimeStamp = + afterDelegatedResourceList.get().getDelegatedResource(0).getExpireTimeForEnergy(); Assert.assertEquals(afterUnlockTimeStamp - afterDelegateTime, (lockPeriod + 1000) * 3 * 1000); Long normalInterval = (lockPeriod + 1000) * 3 * 1000; Long maintenanceInterval = (lockPeriod + 1000) * 3 * 1000; } - @Test(enabled = true, description = "Delegate twice in same block and lock = true,lockPeriod=0L", groups = {"daily", "staking"}) + @Test( + enabled = true, + description = "Delegate twice in same block and lock = true,lockPeriod=0L", + groups = {"daily", "staking"}) public void test08DelegateLockTwiceInSameBlock() { ECKey from = new ECKey(Utils.getRandom()); - byte[] fromAddress = from.getAddress(); - String fromKey = ByteArray.toHexString(from.getPrivKeyBytes()); + byte[] fromAddress = from.getAddress(); + String fromKey = ByteArray.toHexString(from.getPrivKeyBytes()); PublicMethod.printAddress(fromKey); PublicMethod.sendcoin( fromAddress, 1000000000L, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.freezeBalanceV2(fromAddress, 200000000L, 0, fromKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - GrpcAPI.CanDelegatedMaxSizeResponseMessage message - = PublicMethod.getCanDelegatedMaxSize(fromAddress, 0, blockingStubFull).get(); + GrpcAPI.CanDelegatedMaxSizeResponseMessage message = + PublicMethod.getCanDelegatedMaxSize(fromAddress, 0, blockingStubFull).get(); logger.info("canDelegateResource:" + message); - Long canDelegateResource = message.getMaxSize(); - String txId1 = PublicMethod.delegateResourceV2LockAndGetTxId(fromAddress, - canDelegateResource / 3, 0, true, null, receiverAddress, fromKey, blockingStubFull); - String txId2 = PublicMethod.delegateResourceV2LockAndGetTxId(fromAddress, - canDelegateResource / 4, 0, true, null, receiverAddress, fromKey, blockingStubFull); + Long canDelegateResource = message.getMaxSize(); + String txId1 = + PublicMethod.delegateResourceV2LockAndGetTxId( + fromAddress, + canDelegateResource / 3, + 0, + true, + null, + receiverAddress, + fromKey, + blockingStubFull); + String txId2 = + PublicMethod.delegateResourceV2LockAndGetTxId( + fromAddress, + canDelegateResource / 4, + 0, + true, + null, + receiverAddress, + fromKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Transaction transaction1 - = PublicMethod.getTransactionById(txId1, blockingStubFull).get(); - Transaction transaction2 - = PublicMethod.getTransactionById(txId2, blockingStubFull).get(); + Transaction transaction1 = PublicMethod.getTransactionById(txId1, blockingStubFull).get(); + Transaction transaction2 = PublicMethod.getTransactionById(txId2, blockingStubFull).get(); Assert.assertNotNull(transaction1); Assert.assertNotNull(transaction2); - Assert.assertEquals( - transaction1.getRet(0).getContractRet().name(), "SUCCESS"); - Assert.assertEquals( - transaction2.getRet(0).getContractRet().name(), "SUCCESS"); + Assert.assertEquals(transaction1.getRet(0).getContractRet().name(), "SUCCESS"); + Assert.assertEquals(transaction2.getRet(0).getContractRet().name(), "SUCCESS"); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - PublicMethod.freeResource(frozenBandwidthAddress, - frozenBandwidthKey, foundationAddress, blockingStubFull); } + PublicMethod.freeResource( + frozenBandwidthAddress, frozenBandwidthKey, foundationAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test007.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test007.java index 1965e9e1..80c915fa 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test007.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/freezeV2/FreezeBalanceV2Test007.java @@ -1,7 +1,7 @@ package stest.tron.wallet.dailybuild.freezeV2; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; import lombok.extern.slf4j.Slf4j; import org.testng.Assert; import org.testng.SkipException; @@ -12,74 +12,80 @@ import org.tron.api.WalletSolidityGrpc; import org.tron.protos.Protocol; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; - -import java.util.HashMap; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.Flaky; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -@Flaky(reason = "Timing-sensitive: cancel unfreeze wait period", - since = "2026-04-03") +@Flaky(reason = "Timing-sensitive: cancel unfreeze wait period", since = "2026-04-03") public class FreezeBalanceV2Test007 extends TronBaseTest { ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey1.getAddress(); String testKey001 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private String soliditynode = - Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list") - .get(0); + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFullSolidity = null; private String pbftnode = - Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list") - .get(2); + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(2); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() throws Exception { if (!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { throw new SkipException("Skipping freezeV2 test case"); + public void beforeClass() throws Exception { + if (!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + throw new SkipException("Skipping freezeV2 test case"); } - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubFullSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - channelPbft = ManagedChannelBuilder.forTarget(pbftnode) - .usePlaintext() - .build(); - blockingStubPbft= WalletSolidityGrpc.newBlockingStub(channelPbft); + channelPbft = ManagedChannelBuilder.forTarget(pbftnode).usePlaintext().build(); + blockingStubPbft = WalletSolidityGrpc.newBlockingStub(channelPbft); PublicMethod.printAddress(testKey001); - Assert.assertTrue(PublicMethod.sendcoin(testAddress001,200_000000L, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress001, 200_000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceV2(testAddress001,20000000L,0,testKey001,blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceV2(testAddress001,20000000L,1,testKey001,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2(testAddress001, 20000000L, 0, testKey001, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2(testAddress001, 20000000L, 1, testKey001, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - /** - * constructor. - */ - @Test(enabled = true, description = "cancel unexpired unfreeze net, unfreeze count=1", groups = {"daily", "staking"}) + /** constructor. */ + @Test( + enabled = true, + description = "cancel unexpired unfreeze net, unfreeze count=1", + groups = {"daily", "staking"}) public void test01CancelAllUnfreezeNet() { - GrpcAPI.AccountResourceMessage resource1 = PublicMethod.getAccountResource(testAddress001, blockingStubFull); - Assert.assertEquals(resource1.getTronPowerLimit(),40); + GrpcAPI.AccountResourceMessage resource1 = + PublicMethod.getAccountResource(testAddress001, blockingStubFull); + Assert.assertEquals(resource1.getTronPowerLimit(), 40); logger.info(resource1.toString()); - Assert.assertTrue(PublicMethod.unFreezeBalanceV2(testAddress001,testKey001,1000000L,0, blockingStubFull)); + Assert.assertTrue( + PublicMethod.unFreezeBalanceV2(testAddress001, testKey001, 1000000L, 0, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - GrpcAPI.AccountResourceMessage resource2 = PublicMethod.getAccountResource(testAddress001, blockingStubFull); + GrpcAPI.AccountResourceMessage resource2 = + PublicMethod.getAccountResource(testAddress001, blockingStubFull); Assert.assertEquals(resource2.getTronPowerLimit(), 39); logger.info(resource2.toString()); Protocol.Account account2 = PublicMethod.queryAccount(testAddress001, blockingStubFull); long balance2 = account2.getBalance(); - String txid = PublicMethod.cancelAllUnFreezeBalanceV2AndGetTxid(testAddress001, testKey001, blockingStubFull); + String txid = + PublicMethod.cancelAllUnFreezeBalanceV2AndGetTxid( + testAddress001, testKey001, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("test01CancelAllUnfreezeNet info: " + info.toString()); Assert.assertEquals(info.getCancelUnfreezeV2AmountMap().get("BANDWIDTH").longValue(), 1000000L); Assert.assertEquals(info.getWithdrawExpireAmount(), 0); - GrpcAPI.AccountResourceMessage resource3 = PublicMethod.getAccountResource(testAddress001, blockingStubFull); + GrpcAPI.AccountResourceMessage resource3 = + PublicMethod.getAccountResource(testAddress001, blockingStubFull); logger.info(resource3.toString()); Assert.assertEquals(resource3.getTronPowerLimit(), 40); Protocol.Account account3 = PublicMethod.queryAccount(testAddress001, blockingStubFull); @@ -90,22 +96,28 @@ public void test01CancelAllUnfreezeNet() { Assert.assertEquals(account3.getFrozenV2(1).getAmount(), 20000000); } - /** - * constructor. - */ - @Test(enabled = true, description = "cancel all unexpired unfreeze energy", groups = {"daily", "staking"}) + /** constructor. */ + @Test( + enabled = true, + description = "cancel all unexpired unfreeze energy", + groups = {"daily", "staking"}) public void test02CancelAllUnfreezeEnergy() { logger.info(PublicMethod.getAccountResource(testAddress001, blockingStubFull).toString()); - Assert.assertTrue(PublicMethod.unFreezeBalanceV2(testAddress001,testKey001,1000000L,1, blockingStubFull)); + Assert.assertTrue( + PublicMethod.unFreezeBalanceV2(testAddress001, testKey001, 1000000L, 1, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long balance1 = PublicMethod.queryAccount(testAddress001, blockingStubFull).getBalance(); - String txid = PublicMethod.cancelAllUnFreezeBalanceV2AndGetTxid(testAddress001, testKey001, blockingStubFull); + String txid = + PublicMethod.cancelAllUnFreezeBalanceV2AndGetTxid( + testAddress001, testKey001, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("test02CancelAllUnfreezeEnergy info: " + info.toString()); Assert.assertEquals(info.getWithdrawExpireAmount(), 0); Assert.assertEquals(info.getCancelUnfreezeV2AmountMap().get("ENERGY").longValue(), 1000000L); - GrpcAPI.AccountResourceMessage resource2 = PublicMethod.getAccountResource(testAddress001, blockingStubFull); + GrpcAPI.AccountResourceMessage resource2 = + PublicMethod.getAccountResource(testAddress001, blockingStubFull); logger.info(resource2.toString()); Assert.assertEquals(resource2.getTronPowerLimit(), 40); Protocol.Account account2 = PublicMethod.queryAccount(testAddress001, blockingStubFull); @@ -116,24 +128,34 @@ public void test02CancelAllUnfreezeEnergy() { Assert.assertEquals(balance1 - info.getReceipt().getNetFee(), account2.getBalance()); } - @Test(enabled = true, description = "cancel all unexpired unfreeze net and energy", groups = {"daily", "staking"}) + @Test( + enabled = true, + description = "cancel all unexpired unfreeze net and energy", + groups = {"daily", "staking"}) public void test03CancelAllUnfreezeNetAndEnergy() { logger.info(PublicMethod.getAccountResource(testAddress001, blockingStubFull).toString()); - Assert.assertTrue(PublicMethod.unFreezeBalanceV2(testAddress001, testKey001,1000000L,0, blockingStubFull)); - Assert.assertTrue(PublicMethod.unFreezeBalanceV2(testAddress001, testKey001,1000000L,1, blockingStubFull)); + Assert.assertTrue( + PublicMethod.unFreezeBalanceV2(testAddress001, testKey001, 1000000L, 0, blockingStubFull)); + Assert.assertTrue( + PublicMethod.unFreezeBalanceV2(testAddress001, testKey001, 1000000L, 1, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - GrpcAPI.AccountResourceMessage resource1 = PublicMethod.getAccountResource(testAddress001, blockingStubFull); + GrpcAPI.AccountResourceMessage resource1 = + PublicMethod.getAccountResource(testAddress001, blockingStubFull); Assert.assertEquals(resource1.getTronPowerLimit(), 38); long balance1 = PublicMethod.queryAccount(testAddress001, blockingStubFull).getBalance(); - String txid = PublicMethod.cancelAllUnFreezeBalanceV2AndGetTxid(testAddress001, testKey001, blockingStubFull); + String txid = + PublicMethod.cancelAllUnFreezeBalanceV2AndGetTxid( + testAddress001, testKey001, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("test03CancelAllUnfreezeNetAndEnergy info: " + info.toString()); Assert.assertEquals(info.getWithdrawExpireAmount(), 0); Assert.assertEquals(info.getCancelUnfreezeV2AmountMap().get("ENERGY").longValue(), 1000000L); Assert.assertEquals(info.getCancelUnfreezeV2AmountMap().get("BANDWIDTH").longValue(), 1000000L); - GrpcAPI.AccountResourceMessage resource2 = PublicMethod.getAccountResource(testAddress001, blockingStubFull); + GrpcAPI.AccountResourceMessage resource2 = + PublicMethod.getAccountResource(testAddress001, blockingStubFull); logger.info(resource2.toString()); Assert.assertEquals(resource2.getTronPowerLimit(), 40); Protocol.Account account2 = PublicMethod.queryAccount(testAddress001, blockingStubFull); @@ -144,24 +166,34 @@ public void test03CancelAllUnfreezeNetAndEnergy() { Assert.assertEquals(balance1 - info.getReceipt().getNetFee(), account2.getBalance()); } - @Test(enabled = true, description = "cancel 32 unexpired unfreeze", groups = {"daily", "staking"}) + @Test( + enabled = true, + description = "cancel 32 unexpired unfreeze", + groups = {"daily", "staking"}) public void test04CancelAll32Unfreeze() { logger.info(PublicMethod.queryAccount(testAddress001, blockingStubFull).toString()); - for(int i=0;i<32;i++){ - Assert.assertTrue(PublicMethod.unFreezeBalanceV2(testAddress001, testKey001, i + 1,i%2, blockingStubFull)); + for (int i = 0; i < 32; i++) { + Assert.assertTrue( + PublicMethod.unFreezeBalanceV2( + testAddress001, testKey001, i + 1, i % 2, blockingStubFull)); } PublicMethod.waitProduceNextBlock(blockingStubFull); - GrpcAPI.AccountResourceMessage resource1 = PublicMethod.getAccountResource(testAddress001, blockingStubFull); - Assert.assertEquals( resource1.getTronPowerLimit(), 39); + GrpcAPI.AccountResourceMessage resource1 = + PublicMethod.getAccountResource(testAddress001, blockingStubFull); + Assert.assertEquals(resource1.getTronPowerLimit(), 39); long balance1 = PublicMethod.queryAccount(testAddress001, blockingStubFull).getBalance(); - String txid = PublicMethod.cancelAllUnFreezeBalanceV2AndGetTxid(testAddress001, testKey001, blockingStubFull); + String txid = + PublicMethod.cancelAllUnFreezeBalanceV2AndGetTxid( + testAddress001, testKey001, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("test04CancelAll32Unfreeze info: " + info.toString()); Assert.assertEquals(info.getCancelUnfreezeV2AmountMap().get("ENERGY").longValue(), 272L); Assert.assertEquals(info.getCancelUnfreezeV2AmountMap().get("BANDWIDTH").longValue(), 256L); Assert.assertEquals(info.getWithdrawExpireAmount(), 0); - GrpcAPI.AccountResourceMessage resource2 = PublicMethod.getAccountResource(testAddress001, blockingStubFull); + GrpcAPI.AccountResourceMessage resource2 = + PublicMethod.getAccountResource(testAddress001, blockingStubFull); logger.info(resource2.toString()); Assert.assertEquals(resource2.getTronPowerLimit(), 40); Protocol.Account account2 = PublicMethod.queryAccount(testAddress001, blockingStubFull); @@ -172,13 +204,19 @@ public void test04CancelAll32Unfreeze() { Assert.assertEquals(balance1 - info.getReceipt().getNetFee(), account2.getBalance()); } - @Test(enabled = true, description = "cancel all net and energy include expired and unexpired", + @Test( + enabled = true, + description = "cancel all net and energy include expired and unexpired", groups = {"daily", "staking"}) public void test05CancelAllUnfreeze() { logger.info(PublicMethod.getAccountResource(testAddress001, blockingStubFull).toString()); for (int i = 0; i < 2; i++) { - Assert.assertTrue(PublicMethod.unFreezeBalanceV2(testAddress001, testKey001, 1000000L*(i+1), 0, blockingStubFull)); - Assert.assertTrue(PublicMethod.unFreezeBalanceV2(testAddress001, testKey001, 1000000L*(i+1), 1, blockingStubFull)); + Assert.assertTrue( + PublicMethod.unFreezeBalanceV2( + testAddress001, testKey001, 1000000L * (i + 1), 0, blockingStubFull)); + Assert.assertTrue( + PublicMethod.unFreezeBalanceV2( + testAddress001, testKey001, 1000000L * (i + 1), 1, blockingStubFull)); try { Thread.sleep(30000); } catch (InterruptedException e) { @@ -188,26 +226,33 @@ public void test05CancelAllUnfreeze() { Protocol.Account account1 = PublicMethod.queryAccount(testAddress001, blockingStubFull); long expireTime = account1.getUnfrozenV2(0).getUnfreezeExpireTime(); while (true) { - Protocol.Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - long nowTime=currentBlock.getBlockHeader().getRawData().getTimestamp(); + Protocol.Block currentBlock = + blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); + long nowTime = currentBlock.getBlockHeader().getRawData().getTimestamp(); if (nowTime > expireTime) { break; } PublicMethod.waitProduceNextBlock(blockingStubFull); } long balanceBeforeCancel = account1.getBalance(); - String txid = PublicMethod.cancelAllUnFreezeBalanceV2AndGetTxid(testAddress001, testKey001, blockingStubFull); + String txid = + PublicMethod.cancelAllUnFreezeBalanceV2AndGetTxid( + testAddress001, testKey001, blockingStubFull); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubFullSolidity); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("test05CancelAllUnfreeze info: " + info.toString()); Assert.assertEquals(info.getCancelUnfreezeV2AmountMap().get("ENERGY").longValue(), 2000000L); Assert.assertEquals(info.getCancelUnfreezeV2AmountMap().get("BANDWIDTH").longValue(), 2000000L); Assert.assertEquals(info.getWithdrawExpireAmount(), 2000000); - Protocol.TransactionInfo info1 = PublicMethod.getTransactionInfoByIdFromSolidity(txid, blockingStubFullSolidity).get(); - Protocol.TransactionInfo info2 = PublicMethod.getTransactionInfoByIdFromSolidity(txid, blockingStubPbft).get(); + Protocol.TransactionInfo info1 = + PublicMethod.getTransactionInfoByIdFromSolidity(txid, blockingStubFullSolidity).get(); + Protocol.TransactionInfo info2 = + PublicMethod.getTransactionInfoByIdFromSolidity(txid, blockingStubPbft).get(); - GrpcAPI.AccountResourceMessage resource2 = PublicMethod.getAccountResource(testAddress001, blockingStubFull); + GrpcAPI.AccountResourceMessage resource2 = + PublicMethod.getAccountResource(testAddress001, blockingStubFull); logger.info(resource2.toString()); Assert.assertEquals(resource2.getTronPowerLimit(), 38); @@ -217,17 +262,22 @@ public void test05CancelAllUnfreeze() { Assert.assertEquals(account2.getFrozenV2(0).getAmount(), 19000000); Assert.assertEquals(account2.getFrozenV2(1).getAmount(), 19000000); long balanceAfterCancel = account2.getBalance(); - Assert.assertEquals(balanceBeforeCancel - info.getReceipt().getNetFee() + info.getWithdrawExpireAmount(), - balanceAfterCancel ); + Assert.assertEquals( + balanceBeforeCancel - info.getReceipt().getNetFee() + info.getWithdrawExpireAmount(), + balanceAfterCancel); Assert.assertEquals(info, info1); Assert.assertEquals(info, info2); } - @Test(enabled = true, description = "vote after cancel all unfreeze", groups = {"daily", "staking"}) + @Test( + enabled = true, + description = "vote after cancel all unfreeze", + groups = {"daily", "staking"}) public void test06VoteAfterCancelAllUnfreeze() { HashMap voteMap = new HashMap<>(); voteMap.put(witnessAddress, 38L); - Assert.assertTrue(PublicMethod.voteWitness(testAddress001, testKey001, voteMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.voteWitness(testAddress001, testKey001, voteMap, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Protocol.Account account1 = PublicMethod.queryAccount(testAddress001, blockingStubFull); Assert.assertEquals(account1.getVotesCount(), 1); @@ -235,14 +285,19 @@ public void test06VoteAfterCancelAllUnfreeze() { long voteCount = account1.getVotes(0).getVoteCount(); Assert.assertEquals(witness, witnessAddress); Assert.assertEquals(voteCount, 38); - GrpcAPI.AccountResourceMessage resource1 = PublicMethod.getAccountResource(testAddress001, blockingStubFull); + GrpcAPI.AccountResourceMessage resource1 = + PublicMethod.getAccountResource(testAddress001, blockingStubFull); Assert.assertEquals(resource1.getTronPowerLimit(), 38); Assert.assertEquals(resource1.getTronPowerLimit(), resource1.getTronPowerUsed()); } - @Test(enabled = true, description = "all freeze vote, then unfreeze some , then cancel unfreeze. expect vote desc", groups = {"daily", "staking"}) + @Test( + enabled = true, + description = "all freeze vote, then unfreeze some , then cancel unfreeze. expect vote desc", + groups = {"daily", "staking"}) public void test07UnfreezeWithVotedAndCancelAllUnfreeze() { - Assert.assertTrue(PublicMethod.unFreezeBalanceV2(testAddress001, testKey001, 19000000L, 0, blockingStubFull)); + Assert.assertTrue( + PublicMethod.unFreezeBalanceV2(testAddress001, testKey001, 19000000L, 0, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Protocol.Account account1 = PublicMethod.queryAccount(testAddress001, blockingStubFull); long balance1 = account1.getBalance(); @@ -251,20 +306,25 @@ public void test07UnfreezeWithVotedAndCancelAllUnfreeze() { long voteCount = account1.getVotes(0).getVoteCount(); Assert.assertEquals(witness, witnessAddress); Assert.assertEquals(voteCount, 19); - GrpcAPI.AccountResourceMessage resource1 = PublicMethod.getAccountResource(testAddress001, blockingStubFull); + GrpcAPI.AccountResourceMessage resource1 = + PublicMethod.getAccountResource(testAddress001, blockingStubFull); Assert.assertEquals(resource1.getTronPowerLimit(), 19); Assert.assertEquals(resource1.getTronPowerLimit(), resource1.getTronPowerUsed()); Assert.assertEquals(account1.getFrozenV2(1).getAmount(), 19000000); Assert.assertEquals(account1.getFrozenV2(0).getAmount(), 0); - String txid = PublicMethod.cancelAllUnFreezeBalanceV2AndGetTxid(testAddress001, testKey001, blockingStubFull); + String txid = + PublicMethod.cancelAllUnFreezeBalanceV2AndGetTxid( + testAddress001, testKey001, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("test06UnfreezeWithVotedAndCancelAllUnfreeze info: " + info.toString()); - Assert.assertEquals(info.getCancelUnfreezeV2AmountMap().get("BANDWIDTH").longValue(), 19000000L); + Assert.assertEquals( + info.getCancelUnfreezeV2AmountMap().get("BANDWIDTH").longValue(), 19000000L); Assert.assertEquals(info.getWithdrawExpireAmount(), 0); Protocol.Account account2 = PublicMethod.queryAccount(testAddress001, blockingStubFull); long balance2 = account2.getBalance(); - Assert.assertEquals(balance1 - info.getReceipt().getNetFee(), balance2 ); + Assert.assertEquals(balance1 - info.getReceipt().getNetFee(), balance2); Assert.assertEquals(account1.getVotesCount(), 1); witness = account1.getVotes(0).getVoteAddress().toByteArray(); voteCount = account1.getVotes(0).getVoteCount(); @@ -275,11 +335,9 @@ public void test07UnfreezeWithVotedAndCancelAllUnfreeze() { Assert.assertEquals(account1.getFrozenV2(0).getAmount(), 0); } - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - PublicMethod.freeResource(testAddress001, testKey001, foundationAddress, blockingStubFull); } + PublicMethod.freeResource(testAddress001, testKey001, foundationAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/grpcurl/GrpcReflectionTest001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/grpcurl/GrpcReflectionTest001.java index b6fb5f3a..dac3ad8e 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/grpcurl/GrpcReflectionTest001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/grpcurl/GrpcReflectionTest001.java @@ -3,10 +3,11 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.parser.ParserConfig; -import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.google.protobuf.ByteString; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; +import java.util.Base64; +import java.util.HashMap; +import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.testng.Assert; import org.testng.annotations.BeforeClass; @@ -14,314 +15,385 @@ import org.tron.api.GrpcAPI; import org.tron.api.WalletGrpc; import org.tron.api.WalletSolidityGrpc; -import org.tron.protos.Protocol; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - -import java.util.Base64; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class GrpcReflectionTest001 extends TronBaseTest { ECKey key = new ECKey(Utils.getRandom()); +public class GrpcReflectionTest001 extends TronBaseTest { + ECKey key = new ECKey(Utils.getRandom()); private final byte[] receiverAddress = key.getAddress(); private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; private ManagedChannel channelRealSolidity = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubRealSolidity = null; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); private String realSoliditynode = Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); private String pbftnode = - Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list") - .get(3); - private String fullnode2 = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list") - .get(1); - private String contractBase64Address = null; //use for some cases query + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(3); + private String fullnode2 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String contractBase64Address = null; // use for some cases query private String contractOwnerBase64Address = null; - private String transferTxIdBase64 = null; //use for some cases query - + private String transferTxIdBase64 = null; // use for some cases query @BeforeClass(enabled = true) - public void beforeClass() throws Exception { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() throws Exception { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - channelRealSolidity = - ManagedChannelBuilder.forTarget(realSoliditynode).usePlaintext().build(); + channelRealSolidity = ManagedChannelBuilder.forTarget(realSoliditynode).usePlaintext().build(); blockingStubRealSolidity = WalletSolidityGrpc.newBlockingStub(channelRealSolidity); ParserConfig.getGlobalInstance().setAutoTypeSupport(true); } - @Test(enabled = true, description = "test GetAccount use gRPCurl", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetAccount use gRPCurl", + groups = {"daily"}) public void test001GetAccount() { Long transferValue = 1000000000L; - PublicMethod.sendcoin(receiverAddress, transferValue, foundationAddress, foundationKey, blockingStubFull); + PublicMethod.sendcoin( + receiverAddress, transferValue, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String receiverAddressBase64 = Base64.getEncoder().encodeToString(receiverAddress); + String receiverAddressBase64 = Base64.getEncoder().encodeToString(receiverAddress); /* - important!data can not contain space " " in json String - */ + important!data can not contain space " " in json String + */ String data = String.format("{\"address\":\"%s\"}", receiverAddressBase64); - String requestUrl = "protocol.Wallet/GetAccount"; - String returnData = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String requestUrl = "protocol.Wallet/GetAccount"; + String returnData = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); JSONObject accountData = JSONObject.parseObject(returnData); Assert.assertEquals(accountData.getLong("balance").longValue(), transferValue.longValue()); } - @Test(enabled = true, description = "test getChainParameter use gRPCurl", groups = {"daily"}) + @Test( + enabled = true, + description = "test getChainParameter use gRPCurl", + groups = {"daily"}) public void test002GetChainParameters() { String requestUrl = "protocol.Wallet.GetChainParameters"; - String returnData = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); + String returnData = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); logger.info("parameters data: " + returnData); JSONObject parametersData = JSONObject.parseObject(returnData); Assert.assertTrue(parametersData.toJSONString().contains("getMaintenanceTimeInterval")); } - @Test(enabled = true, description = "test getNowBlock use gRPCurl", groups = {"daily"}) + @Test( + enabled = true, + description = "test getNowBlock use gRPCurl", + groups = {"daily"}) public void test003GetNowBlock() { String requestUrl = "protocol.Wallet/GetNowBlock"; - String returnData = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); + String returnData = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); logger.info("block data : " + returnData); JSONObject parametersData = JSONObject.parseObject(returnData); - Long blockId = parametersData.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); + Long blockId = + parametersData.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); Assert.assertTrue(blockId > 0); - String requestUrlSolidity = "protocol.WalletSolidity/GetNowBlock"; - String returnDataSolidity = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetNowBlock"; + String returnDataSolidity = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, soliditynode); logger.info("block data : " + returnDataSolidity); JSONObject parametersDataSolidity = JSONObject.parseObject(returnDataSolidity); - Long blockIdSolidity = parametersDataSolidity.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); + Long blockIdSolidity = + parametersDataSolidity + .getJSONObject("block_header") + .getJSONObject("raw_data") + .getLong("number"); Assert.assertTrue(blockIdSolidity > 0); - String returnDataRealSolidity = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, realSoliditynode); + String returnDataRealSolidity = + PublicMethod.gRPCurlRequest(null, requestUrlSolidity, realSoliditynode); logger.info("block data : " + returnDataRealSolidity); JSONObject parametersDataRealSolidity = JSONObject.parseObject(returnDataRealSolidity); - Long blockIdRealSolidity = parametersDataRealSolidity.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); + Long blockIdRealSolidity = + parametersDataRealSolidity + .getJSONObject("block_header") + .getJSONObject("raw_data") + .getLong("number"); Assert.assertTrue(blockIdRealSolidity > 0); - String returnDataPbft = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, pbftnode); + String returnDataPbft = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, pbftnode); logger.info("block data : " + returnDataPbft); JSONObject parametersDataPbft = JSONObject.parseObject(returnDataPbft); - Long blockIdPbft = parametersDataPbft.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); + Long blockIdPbft = + parametersDataPbft + .getJSONObject("block_header") + .getJSONObject("raw_data") + .getLong("number"); Assert.assertTrue(blockIdPbft > 0); } - @Test(enabled = true, description = "test TriggerConstantContract use gRPCurl", groups = {"daily"}) + @Test( + enabled = true, + description = "test TriggerConstantContract use gRPCurl", + groups = {"daily"}) public void test004TriggerConstantContract() { ECKey deployer = new ECKey(Utils.getRandom()); - String deployerKey = ByteArray.toHexString(deployer.getPrivKeyBytes()); - PublicMethod.sendcoin(deployer.getAddress(), 1000000000L, foundationAddress, - foundationKey, blockingStubFull); + String deployerKey = ByteArray.toHexString(deployer.getPrivKeyBytes()); + PublicMethod.sendcoin( + deployer.getAddress(), 1000000000L, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String abi = "[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"value\"," - + "\"type\":\"uint256\"}],\"name\":\"foo\",\"outputs\":[{\"internalType\":\"uint256\"," - + "\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\"" - + ":\"nonpayable\",\"type\":\"function\"}]"; - String code = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a5760" - + "0080fd5b5060b8806100396000396000f3fe6080604052348015600f57600080fd5b50d38015601b576000" - + "80fd5b50d28015602757600080fd5b506004361060405760003560e01c80632fbebd38146045575b600080f" - + "d5b60586050366004606a565b600081905590565b60405190815260200160405180910390f35b60006020828" - + "4031215607b57600080fd5b503591905056fea26474726f6e58221220c8669715fe95381ee315e1119" - + "064ff80a8121ddfc52747a55161d0d4f4dda2a564736f6c63430008120033"; - byte[] contractAddress = PublicMethod.deployContract( - "MyContract", abi, code,"", maxFeeLimit, 0L, - 100, null, deployerKey, - deployer.getAddress(), blockingStubFull - ); + String abi = + "[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"value\"," + + "\"type\":\"uint256\"}],\"name\":\"foo\",\"outputs\":[{\"internalType\":\"uint256\"," + + "\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\"" + + ":\"nonpayable\",\"type\":\"function\"}]"; + String code = + "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a5760" + + "0080fd5b5060b8806100396000396000f3fe6080604052348015600f57600080fd5b50d38015601b5760" + + "00" + + "80fd5b50d28015602757600080fd5b506004361060405760003560e01c80632fbebd38146045575b6000" + + "80f" + + "d5b60586050366004606a565b600081905590565b60405190815260200160405180910390f35b6000602" + + "0828" + + "4031215607b57600080fd5b503591905056fea26474726f6e58221220c8669715fe95381ee315e1119" + + "064ff80a8121ddfc52747a55161d0d4f4dda2a564736f6c63430008120033"; + byte[] contractAddress = + PublicMethod.deployContract( + "MyContract", + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + deployerKey, + deployer.getAddress(), + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractAddressBase64 = Base64.getEncoder().encodeToString(contractAddress); + String contractAddressBase64 = Base64.getEncoder().encodeToString(contractAddress); contractBase64Address = contractAddressBase64; // for other cases easily test String ownerAddressBase64 = Base64.getEncoder().encodeToString(deployer.getAddress()); contractOwnerBase64Address = ownerAddressBase64; - String data = String - .format( - "{\"owner_address\":\"%s\",\"contract_address\":\"%s\",\"data\":\"aH2qOgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB\"}", + String data = + String.format( + "{\"owner_address\":\"%s\",\"contract_address\":\"%s\",\"data\":\"aH2qOgAAAAAAAAAAAAAAA" + + "AAAAAAAAAAAAAAAAAAAAAAAAAAB\"}", ownerAddressBase64, contractAddressBase64); - String requestUrl = "protocol.Wallet/TriggerConstantContract"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String requestUrl = "protocol.Wallet/TriggerConstantContract"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); logger.info(returnString); JSONObject triggerResult = JSONObject.parseObject(returnString).getJSONObject("result"); Assert.assertTrue(triggerResult.getBoolean("result")); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); - String requestUrlSolidity = "protocol.WalletSolidity/TriggerConstantContract"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/TriggerConstantContract"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); triggerResult = JSONObject.parseObject(returnStringSolidity).getJSONObject("result"); Assert.assertTrue(triggerResult.getBoolean("result")); - String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); triggerResult = JSONObject.parseObject(returnStringPBFT).getJSONObject("result"); Assert.assertTrue(triggerResult.getBoolean("result")); } - @Test(enabled = true, description = "test getTransactionById", groups = {"daily"}) + @Test( + enabled = true, + description = "test getTransactionById", + groups = {"daily"}) public void test005GetTransactionById() { ECKey newAccount = new ECKey(Utils.getRandom()); - String txId = PublicMethod - .sendcoinGetTransactionId(newAccount.getAddress(), - 10000000L, foundationAddress, foundationKey, blockingStubFull); + String txId = + PublicMethod.sendcoinGetTransactionId( + newAccount.getAddress(), 10000000L, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String requestUrl = "protocol.Wallet/GetTransactionById"; - String txIdBase64 = Base64.getEncoder().encodeToString(ByteArray.fromHexString(txId)); + String requestUrl = "protocol.Wallet/GetTransactionById"; + String txIdBase64 = Base64.getEncoder().encodeToString(ByteArray.fromHexString(txId)); transferTxIdBase64 = txIdBase64; - String data = String.format("{\"value\":\"%s\"}", txIdBase64); - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = String.format("{\"value\":\"%s\"}", txIdBase64); + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); JSONObject txData = JSONObject.parseObject(returnString); logger.info(txData.toJSONString()); Assert.assertEquals( - txData.getJSONArray("ret") - .getJSONObject(0) - .getString("contractRet"), - "SUCCESS"); - // query solidity + txData.getJSONArray("ret").getJSONObject(0).getString("contractRet"), "SUCCESS"); + // query solidity PublicMethod.waitProduceNextBlock(blockingStubFull); - String requestUrlSolidity = "protocol.WalletSolidity/GetTransactionById"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetTransactionById"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); JSONObject txDataSolidity = JSONObject.parseObject(returnStringSolidity); logger.info(txDataSolidity.toJSONString()); Assert.assertEquals( - txDataSolidity.getJSONArray("ret") - .getJSONObject(0) - .getString("contractRet"), - "SUCCESS"); - String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); + txDataSolidity.getJSONArray("ret").getJSONObject(0).getString("contractRet"), "SUCCESS"); + String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); Assert.assertEquals(returnStringPBFT, returnStringSolidity); } - @Test(enabled = true, description = "test getContract ", groups = {"daily"}) + @Test( + enabled = true, + description = "test getContract ", + groups = {"daily"}) public void test006GetContract() { String data = String.format("{\"value\":\"%s\"}", contractBase64Address); - String requestUrl = "protocol.Wallet/GetContract"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String requestUrl = "protocol.Wallet/GetContract"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); JSONObject contractData = JSONObject.parseObject(returnString); logger.info(contractData.toJSONString()); Assert.assertTrue(contractData.getString("contract_address").equals(contractBase64Address)); } - @Test(enabled = true, description = "test getBlock2", groups = {"daily"}) + @Test( + enabled = true, + description = "test getBlock2", + groups = {"daily"}) public void test007GetNowBlock2() { String requestUrl = "protocol.Wallet/GetNowBlock2"; - String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); + String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); JSONObject blockData = JSONObject.parseObject(returnString); logger.info(blockData.toJSONString()); - Long blockId = blockData.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); + Long blockId = + blockData.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); Assert.assertTrue(blockId > 0); - String requestUrlSolidity = "protocol.WalletSolidity/GetNowBlock2"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetNowBlock2"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(null, requestUrlSolidity, soliditynode); blockData = JSONObject.parseObject(returnStringSolidity); logger.info(blockData.toJSONString()); blockId = blockData.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); Assert.assertTrue(blockId > 0); - String returnStringPBFT = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, pbftnode); blockData = JSONObject.parseObject(returnStringPBFT); logger.info(blockData.toJSONString()); blockId = blockData.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); Assert.assertTrue(blockId > 0); } - @Test(enabled = true, description = "test GetBlockByNum", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetBlockByNum", + groups = {"daily"}) public void test008GetBlockByNum() { String data = "{\"num\":1}"; - String requestUrl = "protocol.Wallet/GetBlockByNum"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String requestUrl = "protocol.Wallet/GetBlockByNum"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); JSONObject blockData = JSONObject.parseObject(returnString); logger.info(blockData.toJSONString()); - Long blockId = blockData.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); + Long blockId = + blockData.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); Assert.assertEquals(blockId.longValue(), 1L); } - @Test(enabled = true, description = "test GetBlockByNum2", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetBlockByNum2", + groups = {"daily"}) public void test008GetBlockByNum2() { String data = "{\"num\":1}"; - String requestUrl = "protocol.Wallet/GetBlockByNum2"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String requestUrl = "protocol.Wallet/GetBlockByNum2"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); JSONObject blockData = JSONObject.parseObject(returnString); logger.info(blockData.toJSONString()); - Long blockId = blockData.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); + Long blockId = + blockData.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); Assert.assertEquals(blockId.longValue(), 1L); - String requestUrlSolidity = "protocol.WalletSolidity/GetBlockByNum2"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetBlockByNum2"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); JSONObject blockDataSolidity = JSONObject.parseObject(returnStringSolidity); - Long blockIdSolidity = blockDataSolidity.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); + Long blockIdSolidity = + blockDataSolidity.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); Assert.assertEquals(blockIdSolidity.longValue(), 1L); - String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); Assert.assertEquals(returnStringPBFT, returnString); } - @Test(enabled = true, description = "test getNodeInfo", groups = {"daily"}) + @Test( + enabled = true, + description = "test getNodeInfo", + groups = {"daily"}) public void test009GetNodeInfo() { String requestUrl = "protocol.Wallet/GetNodeInfo"; - String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); + String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); JSONObject nodeData = JSONObject.parseObject(returnString); logger.info(nodeData.toJSONString()); Assert.assertNotNull(nodeData); Assert.assertTrue(nodeData.getLongValue("currentConnectCount") > 0L); } - @Test(enabled = true, description = "test GetBlockByLimitNext2", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetBlockByLimitNext2", + groups = {"daily"}) public void test010GetBlockByLimitNext2() { String requestUrl = "protocol.Wallet/GetBlockByLimitNext2"; - String data = "{\"startNum\":0,\"endNum\":1}"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = "{\"startNum\":0,\"endNum\":1}"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); JSONObject blockData = JSONObject.parseObject(returnString); logger.info(blockData.toJSONString()); JSONArray blocks = blockData.getJSONArray("block"); Assert.assertTrue(blocks.size() > 0L); } - @Test(enabled = true, description = "test GetTransactionInfoById", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetTransactionInfoById", + groups = {"daily"}) public void test011GetTransactionInfoById() { String requestUrl = "protocol.Wallet/GetTransactionInfoById"; - String data = String.format("{\"value\":\"%s\"}", transferTxIdBase64); - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = String.format("{\"value\":\"%s\"}", transferTxIdBase64); + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); JSONObject txData = JSONObject.parseObject(returnString); logger.info(txData.toJSONString()); Assert.assertEquals(txData.getString("id"), transferTxIdBase64); - String requestUrlSolidity = "protocol.WalletSolidity/GetTransactionInfoById"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetTransactionInfoById"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); Assert.assertEquals(returnStringSolidity, returnString); - String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); Assert.assertEquals(returnStringPBFT, returnString); } - @Test(enabled = true, description = "test CreateTransaction2", groups = {"daily"}) + @Test( + enabled = true, + description = "test CreateTransaction2", + groups = {"daily"}) public void test012CreateTransaction2() { ECKey newAccount = new ECKey(Utils.getRandom()); - String requestUrl = "protocol.Wallet/CreateTransaction2"; - String from = Base64.getEncoder().encodeToString(foundationAddress); - String to = Base64.getEncoder().encodeToString(newAccount.getAddress()); - String data = String - .format("{\"owner_address\":\"%s\",\"to_address\":\"%s\",\"amount\":100000000}", - from, - to); - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String requestUrl = "protocol.Wallet/CreateTransaction2"; + String from = Base64.getEncoder().encodeToString(foundationAddress); + String to = Base64.getEncoder().encodeToString(newAccount.getAddress()); + String data = + String.format( + "{\"owner_address\":\"%s\",\"to_address\":\"%s\",\"amount\":100000000}", from, to); + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); JSONObject txData = JSONObject.parseObject(returnString); logger.info(txData.toJSONString()); Assert.assertTrue(txData.getJSONObject("result").getBoolean("result")); } - @Test(enabled = true, description = "test TriggerContract", groups = {"daily"}) + @Test( + enabled = true, + description = "test TriggerContract", + groups = {"daily"}) public void test013TriggerContract() { ECKey owner = new ECKey(Utils.getRandom()); - String ownerAddressBase64 = Base64.getEncoder().encodeToString(owner.getAddress()); - String data = String - .format( - "{\"owner_address\":\"%s\",\"contract_address\":\"%s\",\"data\":\"aH2qOgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB\"}", + String ownerAddressBase64 = Base64.getEncoder().encodeToString(owner.getAddress()); + String data = + String.format( + "{\"owner_address\":\"%s\",\"contract_address\":\"%s\",\"data\":\"aH2qOgAAAAAAAAAAAAAAA" + + "AAAAAAAAAAAAAAAAAAAAAAAAAAB\"}", ownerAddressBase64, contractBase64Address); - String requestUrl = "protocol.Wallet/TriggerContract"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String requestUrl = "protocol.Wallet/TriggerContract"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info("tx is :" + returnString); Assert.assertTrue(returnString.contains("transaction")); } - @Test(enabled = true, description = "test ClearContractABI", groups = {"daily"}) - public void test014ClearContractABI(){ - String data = String.format("{\"owner_address\":\"%s\",\"contract_address\":\"%s\"}",contractOwnerBase64Address, contractBase64Address); - String requestUrl = "protocol.Wallet/ClearContractABI"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + @Test( + enabled = true, + description = "test ClearContractABI", + groups = {"daily"}) + public void test014ClearContractABI() { + String data = + String.format( + "{\"owner_address\":\"%s\",\"contract_address\":\"%s\"}", + contractOwnerBase64Address, contractBase64Address); + String requestUrl = "protocol.Wallet/ClearContractABI"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("transaction")); @@ -330,17 +402,19 @@ public void test014ClearContractABI(){ Assert.assertTrue(returnString.contains("raw_data")); } - @Test(enabled = true, description = "test CreateTransaction", groups = {"daily"}) + @Test( + enabled = true, + description = "test CreateTransaction", + groups = {"daily"}) public void test015CreateTransaction() { ECKey newAccount = new ECKey(Utils.getRandom()); - String requestUrl = "protocol.Wallet/CreateTransaction"; - String from = Base64.getEncoder().encodeToString(foundationAddress); - String to = Base64.getEncoder().encodeToString(newAccount.getAddress()); - String data = String - .format("{\"owner_address\":\"%s\",\"to_address\":\"%s\",\"amount\":100000000}", - from, - to); - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String requestUrl = "protocol.Wallet/CreateTransaction"; + String from = Base64.getEncoder().encodeToString(foundationAddress); + String to = Base64.getEncoder().encodeToString(newAccount.getAddress()); + String data = + String.format( + "{\"owner_address\":\"%s\",\"to_address\":\"%s\",\"amount\":100000000}", from, to); + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); JSONObject txData = JSONObject.parseObject(returnString); logger.info(txData.toJSONString()); Assert.assertTrue(returnString.contains("ref_block_bytes")); @@ -348,101 +422,128 @@ public void test015CreateTransaction() { Assert.assertTrue(returnString.contains("raw_data")); } - @Test(enabled = true, description = "test EstimateEnergy", groups = {"daily"}) + @Test( + enabled = true, + description = "test EstimateEnergy", + groups = {"daily"}) public void test016EstimateEnergy() { - String data = String - .format( - "{\"owner_address\":\"%s\",\"contract_address\":\"%s\",\"data\":\"aH2qOgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB\"}", + String data = + String.format( + "{\"owner_address\":\"%s\",\"contract_address\":\"%s\",\"data\":\"aH2qOgAAAAAAAAAAAAAAA" + + "AAAAAAAAAAAAAAAAAAAAAAAAAAB\"}", contractOwnerBase64Address, contractBase64Address); - String requestUrl = "protocol.Wallet/EstimateEnergy"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode2); + String requestUrl = "protocol.Wallet/EstimateEnergy"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode2); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("CONTRACT_EXE_ERROR")); - Assert.assertTrue(returnString.contains("UkVWRVJUIG9wY29kZSBleGVjdXRlZA=="));// REVERT + Assert.assertTrue(returnString.contains("UkVWRVJUIG9wY29kZSBleGVjdXRlZA==")); // REVERT PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); - String requestUrlSolidity = "protocol.WalletSolidity/EstimateEnergy"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); - Assert.assertTrue(returnStringSolidity.contains("" + - "Q29udHJhY3QgdmFsaWRhdGUgZXJyb3IgOiB0aGlzIG5vZGUgZG9lcyBub3Qgc3VwcG9ydCBlc3RpbWF0ZSBlbmVyZ3k=")); - // this node does not support estimateEnergy + String requestUrlSolidity = "protocol.WalletSolidity/EstimateEnergy"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); + Assert.assertTrue( + returnStringSolidity.contains( + "" + + "Q29udHJhY3QgdmFsaWRhdGUgZXJyb3IgOiB0aGlzIG5vZGUgZG9lcyBub3Qgc3VwcG9ydCBlc3RpbWF0" + + "ZSBlbmVyZ3k=")); + // this node does not support estimateEnergy String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); Assert.assertEquals(returnStringPBFT, returnString); - } - @Test(enabled = true, description = "test GetContractInfo", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetContractInfo", + groups = {"daily"}) public void test017GetContractInfo() { String data = String.format("{\"value\":\"%s\"}", contractBase64Address); - String requestUrl = "protocol.Wallet/GetContractInfo"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String requestUrl = "protocol.Wallet/GetContractInfo"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("smart_contract")); Assert.assertTrue(returnString.contains("contract_state")); } - @Test(enabled = true, description = "test GetEnergyPrices", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetEnergyPrices", + groups = {"daily"}) public void test018GetGetEnergyPrices() { String requestUrl = "protocol.Wallet/GetEnergyPrices"; - String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); + String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("prices")); Assert.assertTrue(returnString.contains("420")); - String requestUrlSolidity = "protocol.WalletSolidity/GetEnergyPrices"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetEnergyPrices"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(null, requestUrlSolidity, soliditynode); Assert.assertEquals(returnStringSolidity, returnString); - String returnStringPBFT = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, pbftnode); Assert.assertEquals(returnStringPBFT, returnString); } - @Test(enabled = true, description = "test GetMemoFee", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetMemoFee", + groups = {"daily"}) public void test019GetMemoFee() { String requestUrl = "protocol.Wallet/GetMemoFee"; - String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); + String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("prices")); } - @Test(enabled = true, description = "test GetNextMaintenanceTime", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetNextMaintenanceTime", + groups = {"daily"}) public void test020GetNextMaintenanceTime() { String requestUrl = "protocol.Wallet/GetNextMaintenanceTime"; - String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); + String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("num")); JSONObject timeInfo = JSONObject.parseObject(returnString); - Long time = timeInfo.getLong("num"); + Long time = timeInfo.getLong("num"); Assert.assertTrue(time > System.currentTimeMillis()); } - @Test(enabled = true, description = "test GetPaginatedAssetIssueList", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetPaginatedAssetIssueList", + groups = {"daily"}) public void test021GetPaginatedAssetIssueList() { String data = "{\"offset\":0,\"limit\":10}"; - String requestUrl = "protocol.Wallet/GetPaginatedAssetIssueList"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String requestUrl = "protocol.Wallet/GetPaginatedAssetIssueList"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("assetIssue")); Assert.assertTrue(returnString.contains("total_supply")); - String requestUrlSolidity = "protocol.WalletSolidity/GetPaginatedAssetIssueList"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetPaginatedAssetIssueList"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); logger.info(returnStringSolidity); Assert.assertTrue(returnStringSolidity.contains("assetIssue")); Assert.assertTrue(returnStringSolidity.contains("total_supply")); - String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); logger.info(returnStringPBFT); Assert.assertTrue(returnStringPBFT.contains("assetIssue")); Assert.assertTrue(returnStringPBFT.contains("total_supply")); } - @Test(enabled = true, description = "test GetPaginatedProposalList", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetPaginatedProposalList", + groups = {"daily"}) public void test022GetPaginatedProposalList() { String data = "{\"offset\":0,\"limit\":10}"; - String requestUrl = "protocol.Wallet/GetPaginatedProposalList"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String requestUrl = "protocol.Wallet/GetPaginatedProposalList"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("proposals")); @@ -450,112 +551,137 @@ public void test022GetPaginatedProposalList() { Assert.assertTrue(returnString.contains("parameters")); } - @Test(enabled = true, description = "test GetPendingSize", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetPendingSize", + groups = {"daily"}) public void test023GetPendingSize() { String requestUrl = "protocol.Wallet/GetPendingSize"; - String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); + String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.startsWith("{")); } - @Test(enabled = true, description = "test GetRewardInfo", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetRewardInfo", + groups = {"daily"}) public void test023GetRewardInfo() { Optional witnesses = PublicMethod.listWitnesses(blockingStubFull); - byte[] witnessAddress = witnesses.get().getWitnessesList().get(0).getAddress().toByteArray(); - String ownerAddressBase64 = Base64.getEncoder().encodeToString(witnessAddress); - String data = String.format("{\"value\":\"%s\"}", ownerAddressBase64); - String requestUrl = "protocol.Wallet/GetRewardInfo"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + byte[] witnessAddress = witnesses.get().getWitnessesList().get(0).getAddress().toByteArray(); + String ownerAddressBase64 = Base64.getEncoder().encodeToString(witnessAddress); + String data = String.format("{\"value\":\"%s\"}", ownerAddressBase64); + String requestUrl = "protocol.Wallet/GetRewardInfo"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("num")); JSONObject rewardData = JSONObject.parseObject(returnString); Assert.assertTrue(rewardData.getLongValue("num") > 0); - String requestUrlSolidity = "protocol.WalletSolidity/GetRewardInfo"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetRewardInfo"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); logger.info(returnStringSolidity); Assert.assertTrue(returnStringSolidity.contains("num")); rewardData = JSONObject.parseObject(returnStringSolidity); Assert.assertTrue(rewardData.getLongValue("num") > 0); - String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); rewardData = JSONObject.parseObject(returnStringPBFT); Assert.assertTrue(rewardData.getLongValue("num") > 0); } - @Test(enabled = true, description = "test GetTransactionApprovedList", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetTransactionApprovedList", + groups = {"daily"}) public void test024GetTransactionApprovedList() { String requestUrl = "protocol.Wallet/GetTransactionById"; - String data = String.format("{\"value\":\"%s\"}", transferTxIdBase64); - String trxData = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = String.format("{\"value\":\"%s\"}", transferTxIdBase64); + String trxData = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(trxData); JSONObject returnTrx = JSONObject.parseObject(trxData); requestUrl = "protocol.Wallet/GetTransactionApprovedList"; - String returnString = PublicMethod.gRPCurlRequest(returnTrx.toJSONString(), requestUrl, fullnode); + String returnString = + PublicMethod.gRPCurlRequest(returnTrx.toJSONString(), requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("approved_list")); } - - @Test(enabled = true, description = "test GetTransactionFromPending", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetTransactionFromPending", + groups = {"daily"}) public void test025GetTransactionFromPending() { String requestUrl = "protocol.Wallet/GetTransactionFromPending"; - String data = String.format("{\"value\":\"%s\"}", "K0bj5EjrlNB8BNWh1Jmg/Bybke87zZJCIJmu8Zwz9xg="); - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = + String.format("{\"value\":\"%s\"}", "K0bj5EjrlNB8BNWh1Jmg/Bybke87zZJCIJmu8Zwz9xg="); + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.startsWith("{")); } - @Test(enabled = true, description = "test GetTransactionCountByBlockNum", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetTransactionCountByBlockNum", + groups = {"daily"}) public void test026GetTransactionCountByBlockNum() { String requestUrl = "protocol.Wallet/GetTransactionCountByBlockNum"; - String data = String.format("{\"num\":\"%d\"}", 0); - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = String.format("{\"num\":\"%d\"}", 0); + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("num")); - String requestUrlSolidity = "protocol.WalletSolidity/GetTransactionCountByBlockNum"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetTransactionCountByBlockNum"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); Assert.assertTrue(returnStringSolidity.contains("num")); - String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); Assert.assertTrue(returnStringPBFT.contains("num")); - } - @Test(enabled = true, description = "test GetTransactionInfoByBlockNum", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetTransactionInfoByBlockNum", + groups = {"daily"}) public void test027GetTransactionInfoByBlockNum() { String requestUrl = "protocol.Wallet/GetTransactionInfoById"; - String data = String.format("{\"value\":\"%s\"}", transferTxIdBase64); - String trxData = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = String.format("{\"value\":\"%s\"}", transferTxIdBase64); + String trxData = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); JSONObject trx = JSONObject.parseObject(trxData); logger.info(trxData); - Long blockNumber = trx.getLongValue("blockNumber"); + Long blockNumber = trx.getLongValue("blockNumber"); requestUrl = "protocol.Wallet/GetTransactionInfoByBlockNum"; data = String.format("{\"num\":\"%d\"}", blockNumber); - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("transactionInfo")); Assert.assertTrue(returnString.contains(blockNumber.toString())); - String requestUrlSolidity = "protocol.WalletSolidity/GetTransactionInfoByBlockNum"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetTransactionInfoByBlockNum"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); logger.info(returnStringSolidity); Assert.assertTrue(returnStringSolidity.contains("transactionInfo")); -// String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); -// Assert.assertEquals(returnStringPBFT, returnString); + // String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); + // Assert.assertEquals(returnStringPBFT, returnString); } - @Test(enabled = true, description = "test GetTransactionSignWeight", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetTransactionSignWeight", + groups = {"daily"}) public void test028GetTransactionSignWeight() { String requestUrl = "protocol.Wallet/GetTransactionById"; - String data = String.format("{\"value\":\"%s\"}", transferTxIdBase64); - String trxData = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = String.format("{\"value\":\"%s\"}", transferTxIdBase64); + String trxData = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(trxData); JSONObject returnTrx = JSONObject.parseObject(trxData); requestUrl = "protocol.Wallet/GetTransactionSignWeight"; - String returnString = PublicMethod.gRPCurlRequest(returnTrx.toJSONString(), requestUrl, fullnode); + String returnString = + PublicMethod.gRPCurlRequest(returnTrx.toJSONString(), requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("current_weight")); @@ -564,266 +690,323 @@ public void test028GetTransactionSignWeight() { Assert.assertEquals(weightData.getLongValue("current_weight"), 1L); } - - @Test(enabled = true, description = "test ListProposals", groups = {"daily"}) + @Test( + enabled = true, + description = "test ListProposals", + groups = {"daily"}) public void test029ListProposals() { String requestUrl = "protocol.Wallet/ListProposals"; - String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); + String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("proposals")); Assert.assertTrue(returnString.contains("APPROVED")); } - - @Test(enabled = true, description = "test ListWitnesses", groups = {"daily"}) + @Test( + enabled = true, + description = "test ListWitnesses", + groups = {"daily"}) public void test030ListWitnesses() { String requestUrl = "protocol.Wallet/ListWitnesses"; - String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); + String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("witnesses")); Assert.assertTrue(returnString.contains("voteCount")); Assert.assertTrue(returnString.contains("totalProduced")); - String requestUrlSolidity = "protocol.WalletSolidity/ListWitnesses"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/ListWitnesses"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(null, requestUrlSolidity, soliditynode); Assert.assertTrue(returnStringSolidity.contains("witnesses")); Assert.assertTrue(returnStringSolidity.contains("voteCount")); Assert.assertTrue(returnStringSolidity.contains("totalProduced")); - String returnStringPBFT = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, pbftnode); Assert.assertTrue(returnStringPBFT.contains("witnesses")); Assert.assertTrue(returnStringPBFT.contains("voteCount")); Assert.assertTrue(returnStringPBFT.contains("totalProduced")); } - - @Test(enabled = true, description = "test ProposalCreate", groups = {"daily"}) + @Test( + enabled = true, + description = "test ProposalCreate", + groups = {"daily"}) public void test031ProposalCreate() { String ownerAddressBase64 = Base64.getEncoder().encodeToString(witnessAddress); - String requestUrl = "protocol.Wallet/ProposalCreate"; - String data =String.format("{\"owner_address\":\"%s\",\"parameters\":{\"62\":43200000000}}", ownerAddressBase64) ; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String requestUrl = "protocol.Wallet/ProposalCreate"; + String data = + String.format( + "{\"owner_address\":\"%s\",\"parameters\":{\"62\":43200000000}}", ownerAddressBase64); + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("type.googleapis.com/protocol.ProposalCreateContract")); Assert.assertTrue(returnString.contains("43200000000")); } - - @Test(enabled = true, description = "test ProposalApprove", groups = {"daily"}) + @Test( + enabled = true, + description = "test ProposalApprove", + groups = {"daily"}) public void test031ProposalApprove() { HashMap proposalMap = new HashMap(); proposalMap.put(62L, 43200000000L); PublicMethod.createProposal(witnessAddress, witnessKey, proposalMap, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - GrpcAPI.ProposalList proposalList = blockingStubFull.listProposals(GrpcAPI.EmptyMessage.newBuilder().build()); - Long newProposalId = proposalList.getProposals(0).getProposalId(); - String ownerAddressBase64 = Base64.getEncoder().encodeToString(witnessAddress); - String requestUrl = "protocol.Wallet/ProposalApprove"; - String data =String.format("{\"owner_address\":\"%s\",\"proposal_id\":\"%d\",\"is_add_approval\":true}", - ownerAddressBase64, - newProposalId - ); - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); - Assert.assertNotNull(returnString); - logger.info(returnString); - Assert.assertTrue(returnString.contains("type.googleapis.com/protocol.ProposalApproveContract")); + GrpcAPI.ProposalList proposalList = + blockingStubFull.listProposals(GrpcAPI.EmptyMessage.newBuilder().build()); + Long newProposalId = proposalList.getProposals(0).getProposalId(); + String ownerAddressBase64 = Base64.getEncoder().encodeToString(witnessAddress); + String requestUrl = "protocol.Wallet/ProposalApprove"; + String data = + String.format( + "{\"owner_address\":\"%s\",\"proposal_id\":\"%d\",\"is_add_approval\":true}", + ownerAddressBase64, newProposalId); + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + Assert.assertNotNull(returnString); + logger.info(returnString); + Assert.assertTrue( + returnString.contains("type.googleapis.com/protocol.ProposalApproveContract")); Assert.assertTrue(returnString.contains("is_add_approval")); } - @Test(enabled = true, description = "test ProposalDelete", groups = {"daily"}) + @Test( + enabled = true, + description = "test ProposalDelete", + groups = {"daily"}) public void test032ProposalDelete() { - GrpcAPI.ProposalList proposalList = blockingStubFull.listProposals(GrpcAPI.EmptyMessage.newBuilder().build()); - Long newProposalId = proposalList.getProposals(0).getProposalId(); - String ownerAddressBase64 = Base64.getEncoder().encodeToString(witnessAddress); - String requestUrl = "protocol.Wallet/ProposalDelete"; - String data =String.format("{\"owner_address\":\"%s\",\"proposal_id\":\"%d\"}", - ownerAddressBase64, - newProposalId - ); - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + GrpcAPI.ProposalList proposalList = + blockingStubFull.listProposals(GrpcAPI.EmptyMessage.newBuilder().build()); + Long newProposalId = proposalList.getProposals(0).getProposalId(); + String ownerAddressBase64 = Base64.getEncoder().encodeToString(witnessAddress); + String requestUrl = "protocol.Wallet/ProposalDelete"; + String data = + String.format( + "{\"owner_address\":\"%s\",\"proposal_id\":\"%d\"}", ownerAddressBase64, newProposalId); + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("type.googleapis.com/protocol.ProposalDeleteContract")); Assert.assertTrue(returnString.contains("proposal_id")); } - - @Test(enabled = true, description = "test SetAccountId", groups = {"daily"}) + @Test( + enabled = true, + description = "test SetAccountId", + groups = {"daily"}) public void test033SetAccountId() { String ownerAddressBase64 = Base64.getEncoder().encodeToString(foundationAddress); - String requestUrl = "protocol.Wallet/SetAccountId"; - String data =String.format("{\"owner_address\":\"%s\",\"account_id\":\"dGVzdEdycGN1cmw=\"}", - ownerAddressBase64 - ); - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String requestUrl = "protocol.Wallet/SetAccountId"; + String data = + String.format( + "{\"owner_address\":\"%s\",\"account_id\":\"dGVzdEdycGN1cmw=\"}", ownerAddressBase64); + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("type.googleapis.com/protocol.SetAccountIdContract")); Assert.assertTrue(returnString.contains("raw_data")); } - @Test(enabled = true, description = "test UpdateAccount2", groups = {"daily"}) + @Test( + enabled = true, + description = "test UpdateAccount2", + groups = {"daily"}) public void test034UpdateAccount2() { ECKey newAccount = new ECKey(Utils.getRandom()); - PublicMethod.sendcoin(newAccount.getAddress(), 10000000, foundationAddress,foundationKey,blockingStubFull); - String ownerAddressBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); - String data = String.format("{\"owner_address\":\"%s\",\"account_name\":\"Y2NjdGVzdA==\"}", ownerAddressBase64) ; - String requestUrl = "protocol.Wallet/UpdateAccount2"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + PublicMethod.sendcoin( + newAccount.getAddress(), 10000000, foundationAddress, foundationKey, blockingStubFull); + String ownerAddressBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); + String data = + String.format( + "{\"owner_address\":\"%s\",\"account_name\":\"Y2NjdGVzdA==\"}", ownerAddressBase64); + String requestUrl = "protocol.Wallet/UpdateAccount2"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("transaction")); Assert.assertTrue(returnString.contains("type.googleapis.com/protocol.AccountUpdateContract")); - String requestUrl2 = "protocol.Wallet/UpdateAccount"; - String returnString2 = PublicMethod.gRPCurlRequest(data, requestUrl2, fullnode); + String requestUrl2 = "protocol.Wallet/UpdateAccount"; + String returnString2 = PublicMethod.gRPCurlRequest(data, requestUrl2, fullnode); Assert.assertNotNull(returnString2); logger.info(returnString2); Assert.assertTrue(returnString2.contains("type.googleapis.com/protocol.AccountUpdateContract")); } - @Test(enabled = true, description = "test UpdateAccount", groups = {"daily"}) + @Test( + enabled = true, + description = "test UpdateAccount", + groups = {"daily"}) public void test035UpdateAccount() { ECKey newAccount = new ECKey(Utils.getRandom()); - PublicMethod.sendcoin(newAccount.getAddress(), 10000000, foundationAddress,foundationKey,blockingStubFull); - String ownerAddressBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); - String data = String.format("{\"owner_address\":\"%s\",\"account_name\":\"Y2NjdGVzdA==\"}", ownerAddressBase64) ; - String requestUrl = "protocol.Wallet/UpdateAccount"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + PublicMethod.sendcoin( + newAccount.getAddress(), 10000000, foundationAddress, foundationKey, blockingStubFull); + String ownerAddressBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); + String data = + String.format( + "{\"owner_address\":\"%s\",\"account_name\":\"Y2NjdGVzdA==\"}", ownerAddressBase64); + String requestUrl = "protocol.Wallet/UpdateAccount"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("type.googleapis.com/protocol.AccountUpdateContract")); } - - @Test(enabled = true, description = "test UpdateBrokerage", groups = {"daily"}) + @Test( + enabled = true, + description = "test UpdateBrokerage", + groups = {"daily"}) public void test036UpdateBrokerage() { String ownerAddressBase64 = Base64.getEncoder().encodeToString(witnessAddress); - String data = String.format("{\"owner_address\":\"%s\",\"brokerage\":1}", ownerAddressBase64) ; - String requestUrl = "protocol.Wallet/UpdateBrokerage"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = String.format("{\"owner_address\":\"%s\",\"brokerage\":1}", ownerAddressBase64); + String requestUrl = "protocol.Wallet/UpdateBrokerage"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("transaction")); - Assert.assertTrue(returnString.contains("type.googleapis.com/protocol.UpdateBrokerageContract")); + Assert.assertTrue( + returnString.contains("type.googleapis.com/protocol.UpdateBrokerageContract")); } - - @Test(enabled = true, description = "test UpdateEnergyLimit", groups = {"daily"}) + @Test( + enabled = true, + description = "test UpdateEnergyLimit", + groups = {"daily"}) public void test037UpdateEnergyLimit() { - String data = String.format("{\"owner_address\":\"%s\",\"contract_address\":\"%s\",\"origin_energy_limit\":1000}", - contractOwnerBase64Address, - contractBase64Address - ); - String requestUrl = "protocol.Wallet/UpdateEnergyLimit"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = + String.format( + "{\"owner_address\":\"%s\",\"contract_address\":\"%s\",\"origin_energy_limit\":1000}", + contractOwnerBase64Address, contractBase64Address); + String requestUrl = "protocol.Wallet/UpdateEnergyLimit"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("transaction")); - Assert.assertTrue(returnString.contains("type.googleapis.com/protocol.UpdateEnergyLimitContract")); + Assert.assertTrue( + returnString.contains("type.googleapis.com/protocol.UpdateEnergyLimitContract")); } - @Test(enabled = true, description = "test UpdateSetting", groups = {"daily"}) + @Test( + enabled = true, + description = "test UpdateSetting", + groups = {"daily"}) public void test038UpdateSetting() { - String data = String.format("{\"owner_address\":\"%s\",\"contract_address\":\"%s\",\"consume_user_resource_percent\":37}", - contractOwnerBase64Address, - contractBase64Address - ); - String requestUrl = "protocol.Wallet/UpdateSetting"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = + String.format( + "{\"owner_address\":\"%s\",\"contract_address\":\"%s\"," + + "\"consume_user_resource_percent\":37}", + contractOwnerBase64Address, contractBase64Address); + String requestUrl = "protocol.Wallet/UpdateSetting"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("transaction")); Assert.assertTrue(returnString.contains("type.googleapis.com/protocol.UpdateSettingContract")); } - @Test(enabled = true, description = "test UpdateWitness", groups = {"daily"}) + @Test( + enabled = true, + description = "test UpdateWitness", + groups = {"daily"}) public void test039UpdateWitness() { String ownerAddressBase64 = Base64.getEncoder().encodeToString(witnessAddress); - String data = String.format("{\"owner_address\":\"%s\",\"update_url\":\"d3d3LmNjLmNvbQ==\"}", - ownerAddressBase64 - ); - String requestUrl = "protocol.Wallet/UpdateWitness"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = + String.format( + "{\"owner_address\":\"%s\",\"update_url\":\"d3d3LmNjLmNvbQ==\"}", ownerAddressBase64); + String requestUrl = "protocol.Wallet/UpdateWitness"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("type.googleapis.com/protocol.WitnessUpdateContract")); Assert.assertTrue(returnString.contains("update_url")); } - @Test(enabled = true, description = "test UpdateWitness2", groups = {"daily"}) + @Test( + enabled = true, + description = "test UpdateWitness2", + groups = {"daily"}) public void test040UpdateWitness2() { String ownerAddressBase64 = Base64.getEncoder().encodeToString(witnessAddress); - String data = String.format("{\"owner_address\":\"%s\",\"update_url\":\"d3d3LmNjLmNvbQ==\"}", - ownerAddressBase64 - ); - String requestUrl = "protocol.Wallet/UpdateWitness2"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = + String.format( + "{\"owner_address\":\"%s\",\"update_url\":\"d3d3LmNjLmNvbQ==\"}", ownerAddressBase64); + String requestUrl = "protocol.Wallet/UpdateWitness2"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("transaction")); Assert.assertTrue(returnString.contains("type.googleapis.com/protocol.WitnessUpdateContract")); } - @Test(enabled = true, description = "test WithdrawBalance2", groups = {"daily"}) + @Test( + enabled = true, + description = "test WithdrawBalance2", + groups = {"daily"}) public void test041WithdrawBalance2() { String ownerAddressBase64 = Base64.getEncoder().encodeToString(witnessAddress); - String data = String.format("{\"owner_address\":\"%s\"}", - ownerAddressBase64 - ); - String requestUrl = "protocol.Wallet/WithdrawBalance2"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = String.format("{\"owner_address\":\"%s\"}", ownerAddressBase64); + String requestUrl = "protocol.Wallet/WithdrawBalance2"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); - Assert.assertTrue(returnString.contains( - "Q29udHJhY3QgdmFsaWRhdGUgZXJyb3IgOiBBY2NvdW50WzQxMGJlODhhOTE4ZDc0ZDBkZ" + - "mQ3MWRjODRiZDRhYmYwMzZkMDU2Mjk5MV0gaXMgYSBndWFyZCByZXByZXNlbnRhdGl2" + - "ZSBhbmQgaXMgbm90IGFsbG93ZWQgdG8gd2l0aGRyYXcgQmFsYW5jZQ")); + Assert.assertTrue( + returnString.contains( + "Q29udHJhY3QgdmFsaWRhdGUgZXJyb3IgOiBBY2NvdW50WzQxMGJlODhhOTE4ZDc0ZDBkZ" + + "mQ3MWRjODRiZDRhYmYwMzZkMDU2Mjk5MV0gaXMgYSBndWFyZCByZXByZXNlbnRhdGl2" + + "ZSBhbmQgaXMgbm90IGFsbG93ZWQgdG8gd2l0aGRyYXcgQmFsYW5jZQ")); } - @Test(enabled = true, description = "test WithdrawBalance", groups = {"daily"}) + @Test( + enabled = true, + description = "test WithdrawBalance", + groups = {"daily"}) public void test042WithdrawBalance() { String ownerAddressBase64 = Base64.getEncoder().encodeToString(witnessAddress); - String data = String.format("{\"owner_address\":\"%s\"}", - ownerAddressBase64 - ); - String requestUrl = "protocol.Wallet/WithdrawBalance"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = String.format("{\"owner_address\":\"%s\"}", ownerAddressBase64); + String requestUrl = "protocol.Wallet/WithdrawBalance"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("{}")); } - @Test(enabled = true, description = "test WithdrawExpireUnfreeze", groups = {"daily"}) + @Test( + enabled = true, + description = "test WithdrawExpireUnfreeze", + groups = {"daily"}) public void test043WithdrawExpireUnfreeze() { String ownerAddressBase64 = Base64.getEncoder().encodeToString(witnessAddress2); - String data = String.format("{\"owner_address\":\"%s\"}", - ownerAddressBase64 - ); - String requestUrl = "protocol.Wallet/WithdrawExpireUnfreeze"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = String.format("{\"owner_address\":\"%s\"}", ownerAddressBase64); + String requestUrl = "protocol.Wallet/WithdrawExpireUnfreeze"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("CONTRACT_VALIDATE_ERROR")); } - @Test(enabled = true, description = "test VoteWitnessAccount2", groups = {"daily"}) + @Test( + enabled = true, + description = "test VoteWitnessAccount2", + groups = {"daily"}) public void test044VoteWitnessAccount2() { ECKey newAccount = new ECKey(Utils.getRandom()); - PublicMethod.sendcoin(newAccount.getAddress(), 100000000L, foundationAddress, foundationKey, blockingStubFull); + PublicMethod.sendcoin( + newAccount.getAddress(), 100000000L, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.freezeBalanceV2(newAccount.getAddress(), 100000000L, 1, + PublicMethod.freezeBalanceV2( + newAccount.getAddress(), + 100000000L, + 1, ByteArray.toHexString(newAccount.getPrivKeyBytes()), blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String ownerAddressBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); - String voteAddressBase64 = Base64.getEncoder().encodeToString(witnessAddress); - String data = String.format("{\"owner_address\":\"%s\",\"votes\":[{\"vote_address\":\"%s\",\"vote_count\":1}]}", - ownerAddressBase64, - voteAddressBase64 - ); - String requestUrl = "protocol.Wallet/VoteWitnessAccount2"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String ownerAddressBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); + String voteAddressBase64 = Base64.getEncoder().encodeToString(witnessAddress); + String data = + String.format( + "{\"owner_address\":\"%s\",\"votes\":[{\"vote_address\":\"%s\",\"vote_count\":1}]}", + ownerAddressBase64, voteAddressBase64); + String requestUrl = "protocol.Wallet/VoteWitnessAccount2"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("transaction")); @@ -837,45 +1020,58 @@ public void test044VoteWitnessAccount2() { Assert.assertTrue(returnString.contains("type.googleapis.com/protocol.VoteWitnessContract")); } - @Test(enabled = true, description = "test Database.GetBlockByNum", groups = {"daily"}) + @Test( + enabled = true, + description = "test Database.GetBlockByNum", + groups = {"daily"}) public void test045GetBlockByNum() { String data = "{\"num\":1}"; - String requestUrl = "protocol.Database/GetBlockByNum"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String requestUrl = "protocol.Database/GetBlockByNum"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); JSONObject blockData = JSONObject.parseObject(returnString); logger.info(blockData.toJSONString()); - Long blockId = blockData.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); + Long blockId = + blockData.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); Assert.assertEquals(blockId.longValue(), 1L); } - @Test(enabled = true, description = "test Database.GetNowBlock", groups = {"daily"}) + @Test( + enabled = true, + description = "test Database.GetNowBlock", + groups = {"daily"}) public void test046GetNowBlock() { String requestUrl = "protocol.Database/GetNowBlock"; - String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); + String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); JSONObject blockData = JSONObject.parseObject(returnString); logger.info(blockData.toJSONString()); - Long blockId = blockData.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); + Long blockId = + blockData.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); Assert.assertTrue(blockId.longValue() > 0L); } - @Test(enabled = true, description = "test Database.GetDynamicProperties", groups = {"daily"}) + @Test( + enabled = true, + description = "test Database.GetDynamicProperties", + groups = {"daily"}) public void test047GetDynamicProperties() { String requestUrl = "protocol.Database/GetDynamicProperties"; - String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); + String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); JSONObject blockData = JSONObject.parseObject(returnString); logger.info(blockData.toJSONString()); Assert.assertTrue(returnString.contains("last_solidity_block_num")); } - @Test(enabled = true, description = "test Database.getBlockReference", groups = {"daily"}) + @Test( + enabled = true, + description = "test Database.getBlockReference", + groups = {"daily"}) public void test048getBlockReference() { String requestUrl = "protocol.Database/getBlockReference"; - String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); + String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); Assert.assertNotNull(returnString); JSONObject blockData = JSONObject.parseObject(returnString); logger.info(blockData.toJSONString()); - Long blockId = blockData.getLongValue("block_num"); + Long blockId = blockData.getLongValue("block_num"); Assert.assertTrue(blockId > 0L); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/grpcurl/GrpcReflectionTest002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/grpcurl/GrpcReflectionTest002.java index ff6de8ef..d619dbd5 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/grpcurl/GrpcReflectionTest002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/grpcurl/GrpcReflectionTest002.java @@ -3,10 +3,10 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.parser.ParserConfig; -import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.google.protobuf.ByteString; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; +import java.util.Base64; +import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.testng.Assert; import org.testng.annotations.BeforeClass; @@ -15,135 +15,140 @@ import org.tron.api.WalletSolidityGrpc; import org.tron.protos.Protocol; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; - -import java.util.Base64; -import java.util.Optional; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TransactionCapsule; +import stest.tron.wallet.common.client.utils.TransactionUtils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class GrpcReflectionTest002 extends TronBaseTest { ECKey key = new ECKey(Utils.getRandom()); +public class GrpcReflectionTest002 extends TronBaseTest { + ECKey key = new ECKey(Utils.getRandom()); private final byte[] receiverAddress = key.getAddress(); private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; private ManagedChannel channelRealSolidity = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubRealSolidity = null; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); private String realSoliditynode = Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); private String pbftnode = - Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list") - .get(3); - private String contractBase64Address = null; //use for some cases query - private String transferTxIdBase64 = null; //use for some cases query + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(3); + private String contractBase64Address = null; // use for some cases query + private String transferTxIdBase64 = null; // use for some cases query - private String blockHashBase64 = null; //use for some cases query + private String blockHashBase64 = null; // use for some cases query public static final String jsonRpcOwnerKey = Configuration.getByPath("testng.conf").getString("defaultParameter.jsonRpcOwnerKey"); public static final byte[] jsonRpcOwnerAddress = PublicMethod.getFinalAddress(jsonRpcOwnerKey); - @BeforeClass(enabled = true) - public void beforeClass() throws Exception { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() throws Exception { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - channelRealSolidity = - ManagedChannelBuilder.forTarget(realSoliditynode).usePlaintext().build(); + channelRealSolidity = ManagedChannelBuilder.forTarget(realSoliditynode).usePlaintext().build(); blockingStubRealSolidity = WalletSolidityGrpc.newBlockingStub(channelRealSolidity); ParserConfig.getGlobalInstance().setAutoTypeSupport(true); } - - @Test(enabled = true, description = "test GetTransactionInfoByBlockNum with grpcurl", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetTransactionInfoByBlockNum with grpcurl", + groups = {"daily"}) public void test001GetTransactionInfoByBlockNum() { ECKey receiver = new ECKey(Utils.getRandom()); - String txId = PublicMethod.sendcoinGetTransactionId(receiver.getAddress(), 10000000, foundationAddress, foundationKey, blockingStubFull); + String txId = + PublicMethod.sendcoinGetTransactionId( + receiver.getAddress(), 10000000, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional trx = PublicMethod.getTransactionInfoById(txId, blockingStubFull); + Optional trx = + PublicMethod.getTransactionInfoById(txId, blockingStubFull); long blockNumber = trx.get().getBlockNumber(); Assert.assertTrue(blockNumber > 0L); - String txIdBase64 = Base64.getEncoder().encodeToString(ByteArray.fromHexString(txId)); + String txIdBase64 = Base64.getEncoder().encodeToString(ByteArray.fromHexString(txId)); transferTxIdBase64 = txIdBase64; - String data = String.format("{\"num\":%s}", blockNumber); - String requestUrl = "protocol.Wallet/GetTransactionInfoByBlockNum"; - String returnData = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = String.format("{\"num\":%s}", blockNumber); + String requestUrl = "protocol.Wallet/GetTransactionInfoByBlockNum"; + String returnData = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); JSONObject trxData = JSONObject.parseObject(returnData); Assert.assertNotNull(trxData); logger.info("trxData: " + trxData.toJSONString()); Assert.assertNotNull(trxData.getJSONArray("transactionInfo")); Assert.assertTrue(trxData.getJSONArray("transactionInfo").size() > 0); Assert.assertTrue(trxData.toJSONString().contains(transferTxIdBase64)); - } - @Test(enabled = true, description = "test BroadcastTransaction with grpcurl", groups = {"daily"}) + @Test( + enabled = true, + description = "test BroadcastTransaction with grpcurl", + groups = {"daily"}) public void test002BroadcastTransaction() { ECKey receiver = new ECKey(Utils.getRandom()); - Protocol.Transaction trx = PublicMethod.sendcoinForTransaction( - receiver.getAddress(), - 10000000L, - foundationAddress, - foundationKey, - blockingStubFull - ); + Protocol.Transaction trx = + PublicMethod.sendcoinForTransaction( + receiver.getAddress(), 10000000L, foundationAddress, foundationKey, blockingStubFull); TransactionCapsule trxCapsule = new TransactionCapsule(trx); trxCapsule.sign(ByteArray.fromHexString(foundationKey)); JSONObject trxSign = TransactionUtils.printTransactionToJSON(trxCapsule.getInstance(), false); logger.info("before changeBase64 : "); logger.info(trxSign.toJSONString()); - // change signature to Base64 + // change signature to Base64 String signHex = trxSign.getJSONArray("signature").get(0).toString(); - String signBase64 = Base64.getEncoder().encodeToString(ByteArray.fromHexString(signHex)); + String signBase64 = Base64.getEncoder().encodeToString(ByteArray.fromHexString(signHex)); JSONArray signatureBase64 = new JSONArray(); signatureBase64.add(signBase64); trxSign.put("signature", signatureBase64); - // change txID to Base64 + // change txID to Base64 String txID = trxSign.getString("txID"); - String txIDBase64 = Base64.getEncoder().encodeToString(ByteArray.fromHexString(txID)); + String txIDBase64 = Base64.getEncoder().encodeToString(ByteArray.fromHexString(txID)); trxSign.put("txID", txIDBase64); - // change owner_address and to_address - String ownerAddress = trxSign - .getJSONObject("raw_data") - .getJSONArray("contract") - .getJSONObject(0) - .getJSONObject("parameter") - .getJSONObject("value") - .getString("owner_address"); - String toAddress = trxSign - .getJSONObject("raw_data") - .getJSONArray("contract") - .getJSONObject(0) - .getJSONObject("parameter") - .getJSONObject("value") - .getString("to_address"); - String ownerAddressBase64 = Base64.getEncoder().encodeToString(ByteArray.fromHexString(ownerAddress)); - String toAddressBase64 = Base64.getEncoder().encodeToString(ByteArray.fromHexString(toAddress)); - JSONObject value = trxSign - .getJSONObject("raw_data") - .getJSONArray("contract") - .getJSONObject(0) - .getJSONObject("parameter") - .getJSONObject("value"); + // change owner_address and to_address + String ownerAddress = + trxSign + .getJSONObject("raw_data") + .getJSONArray("contract") + .getJSONObject(0) + .getJSONObject("parameter") + .getJSONObject("value") + .getString("owner_address"); + String toAddress = + trxSign + .getJSONObject("raw_data") + .getJSONArray("contract") + .getJSONObject(0) + .getJSONObject("parameter") + .getJSONObject("value") + .getString("to_address"); + String ownerAddressBase64 = + Base64.getEncoder().encodeToString(ByteArray.fromHexString(ownerAddress)); + String toAddressBase64 = Base64.getEncoder().encodeToString(ByteArray.fromHexString(toAddress)); + JSONObject value = + trxSign + .getJSONObject("raw_data") + .getJSONArray("contract") + .getJSONObject(0) + .getJSONObject("parameter") + .getJSONObject("value"); value.put("owner_address", ownerAddressBase64); value.put("to_address", toAddressBase64); - JSONObject parameter = trxSign - .getJSONObject("raw_data") - .getJSONArray("contract") - .getJSONObject(0) - .getJSONObject("parameter"); - String type = parameter.getString("type_url"); + JSONObject parameter = + trxSign + .getJSONObject("raw_data") + .getJSONArray("contract") + .getJSONObject(0) + .getJSONObject("parameter"); + String type = parameter.getString("type_url"); parameter.remove("value"); parameter.put("owner_address", ownerAddressBase64); parameter.put("to_address", toAddressBase64); parameter.put("amount", value.getLongValue("amount")); parameter.put("@type", type); parameter.remove("type_url"); - JSONArray contract = trxSign - .getJSONObject("raw_data") - .getJSONArray("contract"); + JSONArray contract = trxSign.getJSONObject("raw_data").getJSONArray("contract"); JSONObject contractObj = new JSONObject(); contractObj.put("type", contract.getJSONObject(0).getString("type")); contractObj.put("parameter", parameter); @@ -152,11 +157,13 @@ public void test002BroadcastTransaction() { JSONObject rawData = trxSign.getJSONObject("raw_data"); rawData.put("contract", contract); trxSign.put("raw_data", rawData); - // change ref_block_bytes to base64 + // change ref_block_bytes to base64 String refBlockBytes = trxSign.getJSONObject("raw_data").getString("ref_block_bytes"); - String refBlockBytesBase64 = Base64.getEncoder().encodeToString(ByteArray.fromHexString(refBlockBytes)); - String refBlockHash = trxSign.getJSONObject("raw_data").getString("ref_block_hash"); - String reBlockHashBase64 = Base64.getEncoder().encodeToString(ByteArray.fromHexString(refBlockHash)); + String refBlockBytesBase64 = + Base64.getEncoder().encodeToString(ByteArray.fromHexString(refBlockBytes)); + String refBlockHash = trxSign.getJSONObject("raw_data").getString("ref_block_hash"); + String reBlockHashBase64 = + Base64.getEncoder().encodeToString(ByteArray.fromHexString(refBlockHash)); JSONObject raw = trxSign.getJSONObject("raw_data"); raw.put("ref_block_bytes", refBlockBytesBase64); raw.put("ref_block_hash", reBlockHashBase64); @@ -166,20 +173,23 @@ public void test002BroadcastTransaction() { trxSign.remove("raw_data_hex"); logger.info("afterChangeBase64: "); logger.info(trxSign.toJSONString()); - // request gRPCUrl + // request gRPCUrl String data = trxSign.toJSONString(); - String requestUrl = "protocol.Wallet/BroadcastTransaction"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String requestUrl = "protocol.Wallet/BroadcastTransaction"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); logger.info(returnString); JSONObject returnJson = JSONObject.parseObject(returnString); Assert.assertTrue(returnJson.getBoolean("result")); } - @Test(enabled = true, description = "test GetBlockByLatestNum2", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetBlockByLatestNum2", + groups = {"daily"}) public void test003GetBlockByLatestNum2() { String data = "{\"num\":1}"; - String requestUrl = "protocol.Wallet/GetBlockByLatestNum2"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String requestUrl = "protocol.Wallet/GetBlockByLatestNum2"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); logger.info(returnString); Assert.assertNotNull(returnString); Assert.assertTrue(returnString.contains("block_header")); @@ -187,150 +197,184 @@ public void test003GetBlockByLatestNum2() { Assert.assertTrue(returnString.contains("number")); } - @Test(enabled = true, description = "test TransferAsset2", groups = {"daily"}) + @Test( + enabled = true, + description = "test TransferAsset2", + groups = {"daily"}) public void test004TransferAsset2() { ECKey receiver = new ECKey(Utils.getRandom()); - String receiverBase64 = Base64.getEncoder().encodeToString(receiver.getAddress()); - String fromBase64 = Base64.getEncoder().encodeToString(jsonRpcOwnerAddress); + String receiverBase64 = Base64.getEncoder().encodeToString(receiver.getAddress()); + String fromBase64 = Base64.getEncoder().encodeToString(jsonRpcOwnerAddress); Protocol.Account accountInfo = PublicMethod.queryAccount(jsonRpcOwnerAddress, blockingStubFull); - String assetName = accountInfo.getAssetIssuedID().toStringUtf8(); - String assetNameBase64 = Base64.getEncoder().encodeToString(ByteArray.fromString(assetName)); + String assetName = accountInfo.getAssetIssuedID().toStringUtf8(); + String assetNameBase64 = Base64.getEncoder().encodeToString(ByteArray.fromString(assetName)); logger.info(assetName); - String data = String.format( - "{\"asset_name\":\"%s\",\"owner_address\":\"%s\",\"to_address\":\"%s\",\"amount\":1}", - assetNameBase64, - fromBase64, - receiverBase64 - ); - String requestUrl = "protocol.Wallet/TransferAsset2"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = + String.format( + "{\"asset_name\":\"%s\",\"owner_address\":\"%s\",\"to_address\":\"%s\",\"amount\":1}", + assetNameBase64, fromBase64, receiverBase64); + String requestUrl = "protocol.Wallet/TransferAsset2"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); logger.info(returnString); Assert.assertTrue(returnString.contains("transaction")); } - @Test(enabled = true, description = "GetAccountNet", groups = {"daily"}) + @Test( + enabled = true, + description = "GetAccountNet", + groups = {"daily"}) public void test005GetAccountNet() { String addressBase64 = Base64.getEncoder().encodeToString(foundationAddress); - String data = String.format("{\"address\":\"%s\"}", addressBase64); - String requestUrl = "protocol.Wallet/GetAccountNet"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = String.format("{\"address\":\"%s\"}", addressBase64); + String requestUrl = "protocol.Wallet/GetAccountNet"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); logger.info(returnString); Assert.assertNotNull(returnString); Assert.assertTrue(returnString.contains("TotalNetLimit")); } - @Test(enabled = true, description = "test Solidity GetBlockByNum", groups = {"daily"}) + @Test( + enabled = true, + description = "test Solidity GetBlockByNum", + groups = {"daily"}) public void test006GetBlockByNum() { String data = "{\"num\":1}"; - String requestUrl = "protocol.WalletSolidity/GetBlockByNum"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, soliditynode); + String requestUrl = "protocol.WalletSolidity/GetBlockByNum"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, soliditynode); JSONObject blockData = JSONObject.parseObject(returnString); logger.info(blockData.toJSONString()); - Long blockId = blockData.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); + Long blockId = + blockData.getJSONObject("block_header").getJSONObject("raw_data").getLong("number"); Assert.assertEquals(blockId.longValue(), 1L); - blockHashBase64 = blockData.getJSONObject("block_header").getJSONObject("raw_data").getString("parentHash"); - String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrl, pbftnode); + blockHashBase64 = + blockData.getJSONObject("block_header").getJSONObject("raw_data").getString("parentHash"); + String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrl, pbftnode); Assert.assertEquals(returnStringPBFT, returnString); } - @Test(enabled = true, description = "test GetAccountResource", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetAccountResource", + groups = {"daily"}) public void test007GetAccountResource() { String addressBase64 = Base64.getEncoder().encodeToString(foundationAddress); - String data = String.format("{\"address\":\"%s\"}", addressBase64); - String requestUrl = "protocol.Wallet/GetAccountResource"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = String.format("{\"address\":\"%s\"}", addressBase64); + String requestUrl = "protocol.Wallet/GetAccountResource"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); JSONObject resourceData = JSONObject.parseObject(returnString); logger.info(resourceData.toJSONString()); Assert.assertNotNull(resourceData); Assert.assertTrue(resourceData.toJSONString().contains("TotalNetLimit")); } - @Test(enabled = true, description = "test GetBlockById", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetBlockById", + groups = {"daily"}) public void test008GetBlockById() { String data = String.format("{\"value\":\"%s\"}", blockHashBase64); - String requestUrl = "protocol.Wallet/GetBlockById"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String requestUrl = "protocol.Wallet/GetBlockById"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); logger.info(returnString); Assert.assertNotNull(returnString); Assert.assertTrue(returnString.contains("block_header")); } - @Test(enabled = true, description = "test GetAccount ", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetAccount ", + groups = {"daily"}) public void test009GetAccount() { String addressBase64 = Base64.getEncoder().encodeToString(foundationAddress); - String data = String.format("{\"address\":\"%s\"}", addressBase64); - String requestUrl = "protocol.WalletSolidity/GetAccount"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, soliditynode); + String data = String.format("{\"address\":\"%s\"}", addressBase64); + String requestUrl = "protocol.WalletSolidity/GetAccount"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, soliditynode); logger.info(returnString); Assert.assertTrue(returnString.contains("balance")); Assert.assertTrue(returnString.contains(addressBase64)); - String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrl, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrl, pbftnode); logger.info("Account: " + returnStringPBFT); Assert.assertTrue(returnStringPBFT.contains("balance")); Assert.assertTrue(returnStringPBFT.contains(addressBase64)); } - @Test(enabled = true, description = "test GetBlockByLimitNext", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetBlockByLimitNext", + groups = {"daily"}) public void test010GetBlockByLimitNext() { String requestUrl = "protocol.Wallet/GetBlockByLimitNext"; - String data = "{\"startNum\":0,\"endNum\":1}"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = "{\"startNum\":0,\"endNum\":1}"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); JSONObject blockData = JSONObject.parseObject(returnString); logger.info(blockData.toJSONString()); JSONArray blocks = blockData.getJSONArray("block"); Assert.assertTrue(blocks.size() > 0L); } - @Test(enabled = true, description = "test GetTransactionListFromPending", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetTransactionListFromPending", + groups = {"daily"}) public void test011GetTransactionListFromPending() { String requestUrl = "protocol.Wallet/GetTransactionListFromPending"; - String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); + String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info("TransactionList: " + returnString); Assert.assertTrue(returnString.contains("{")); } - @Test(enabled = true, description = "test ListNodes", groups = {"daily"}) + @Test( + enabled = true, + description = "test ListNodes", + groups = {"daily"}) public void test012ListNodes() { String requestUrl = "protocol.Wallet/ListNodes"; - String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); + String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); Assert.assertNotNull(returnString); Assert.assertTrue(returnString.contains("nodes")); } - @Test(enabled = true, description = "test CreateAccount2", groups = {"daily"}) + @Test( + enabled = true, + description = "test CreateAccount2", + groups = {"daily"}) public void test013CreateAccount2() { ECKey newAccount = new ECKey(Utils.getRandom()); - String newAccountBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); - String ownerAddressBase64 = Base64.getEncoder().encodeToString(foundationAddress); - String requestUrl = "protocol.Wallet/CreateAccount2"; - String data = String - .format( - "{\"owner_address\":\"%s\",\"account_address\":\"%s\",\"type\":0}", - ownerAddressBase64, - newAccountBase64 - ); - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String newAccountBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); + String ownerAddressBase64 = Base64.getEncoder().encodeToString(foundationAddress); + String requestUrl = "protocol.Wallet/CreateAccount2"; + String data = + String.format( + "{\"owner_address\":\"%s\",\"account_address\":\"%s\",\"type\":0}", + ownerAddressBase64, newAccountBase64); + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info("tx is: " + returnString); Assert.assertTrue(returnString.contains("transaction")); } - @Test(enabled = true, description = "test AccountPermissionUpdate", groups = {"daily"}) + @Test( + enabled = true, + description = "test AccountPermissionUpdate", + groups = {"daily"}) public void test014AccountPermissionUpdate() { ECKey newAccount = new ECKey(Utils.getRandom()); - String newAccountBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); - PublicMethod.sendcoin(newAccount.getAddress(), 1000000000, foundationAddress, foundationKey, blockingStubFull); - String data = String.format("{\"owner_address\":\"%s\",\"owner\":{\"type\":0,\"id\":0,\"permission_name\":\"owner\"," + - "\"threshold\":1,\"keys\":[{\"address\":\"%s\",\"weight\":1}]},\"actives\":[{\"type\":2,\"id\":2," + - "\"permission_name\":\"active\",\"threshold\":1,\"operations\":\"f/8fwAM+ww8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\"," + - "\"keys\":[{\"address\":\"%s\",\"weight\":1}]}]}", - newAccountBase64, - newAccountBase64, - newAccountBase64 - ); - String requestUrl = "protocol.Wallet/AccountPermissionUpdate"; - String returnString =PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String newAccountBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); + PublicMethod.sendcoin( + newAccount.getAddress(), 1000000000, foundationAddress, foundationKey, blockingStubFull); + String data = + String.format( + "{\"owner_address\":\"%s\",\"owner\":{\"type\":0,\"id\":0,\"permission_name\":\"owner\"" + + "," + + "\"threshold\":1,\"keys\":[{\"address\":\"%s\",\"weight\":1}]},\"actives\":[{\"ty" + + "pe\":2,\"id\":2," + + "\"permission_name\":\"active\",\"threshold\":1,\"operations\":\"f/8fwAM+ww8AAAAA" + + "AAAAAAAAAAAAAAAAAAAAAAAAAAA=\"," + + "\"keys\":[{\"address\":\"%s\",\"weight\":1}]}]}", + newAccountBase64, newAccountBase64, newAccountBase64); + String requestUrl = "protocol.Wallet/AccountPermissionUpdate"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains(newAccountBase64)); @@ -340,20 +384,26 @@ public void test014AccountPermissionUpdate() { Assert.assertTrue(returnString.contains("raw_data")); } - @Test(enabled = true, description = "test CancelAllUnfreezeV2", groups = {"daily"}) - public void test015CancelAllUnfreezeV2(){ + @Test( + enabled = true, + description = "test CancelAllUnfreezeV2", + groups = {"daily"}) + public void test015CancelAllUnfreezeV2() { ECKey newAccount = new ECKey(Utils.getRandom()); - String newAccountKey = ByteArray.toHexString(newAccount.getPrivKeyBytes()); - PublicMethod.sendcoin(newAccount.getAddress(), 100000000, foundationAddress, foundationKey, blockingStubFull); + String newAccountKey = ByteArray.toHexString(newAccount.getPrivKeyBytes()); + PublicMethod.sendcoin( + newAccount.getAddress(), 100000000, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.freezeBalanceV2(newAccount.getAddress(), 50000000, 1, newAccountKey, blockingStubFull); + PublicMethod.freezeBalanceV2( + newAccount.getAddress(), 50000000, 1, newAccountKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.unFreezeBalanceV2(newAccount.getAddress(), newAccountKey, 25000000, 1, blockingStubFull); + PublicMethod.unFreezeBalanceV2( + newAccount.getAddress(), newAccountKey, 25000000, 1, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String ownerAddressBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); - String data = String.format("{\"owner_address\":\"%s\"}", ownerAddressBase64); - String requestUrl = "protocol.Wallet/CancelAllUnfreezeV2"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String ownerAddressBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); + String data = String.format("{\"owner_address\":\"%s\"}", ownerAddressBase64); + String requestUrl = "protocol.Wallet/CancelAllUnfreezeV2"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains(ownerAddressBase64)); @@ -363,41 +413,47 @@ public void test015CancelAllUnfreezeV2(){ Assert.assertTrue(returnString.contains("raw_data")); } - @Test(enabled = true, description = "test CreateAccount", groups = {"daily"}) + @Test( + enabled = true, + description = "test CreateAccount", + groups = {"daily"}) public void test016CreateAccount() { ECKey newAccount = new ECKey(Utils.getRandom()); - String newAccountBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); - String ownerAddressBase64 = Base64.getEncoder().encodeToString(foundationAddress); - String requestUrl = "protocol.Wallet/CreateAccount"; - String data = String - .format( + String newAccountBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); + String ownerAddressBase64 = Base64.getEncoder().encodeToString(foundationAddress); + String requestUrl = "protocol.Wallet/CreateAccount"; + String data = + String.format( "{\"owner_address\":\"%s\",\"account_address\":\"%s\",\"type\":0}", - ownerAddressBase64, - newAccountBase64 - ); - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + ownerAddressBase64, newAccountBase64); + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info("tx is: " + returnString); Assert.assertTrue(returnString.contains("raw_data")); } - @Test(enabled = true, description = "test CreateAssetIssue", groups = {"daily"}) - public void test017CreateAssetIssue(){ + @Test( + enabled = true, + description = "test CreateAssetIssue", + groups = {"daily"}) + public void test017CreateAssetIssue() { ECKey newAccount = new ECKey(Utils.getRandom()); - String newAccountBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); - PublicMethod.sendcoin(newAccount.getAddress(), 2000000000, foundationAddress, foundationKey, blockingStubFull); + String newAccountBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); + PublicMethod.sendcoin( + newAccount.getAddress(), 2000000000, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String data = String.format("{\"owner_address\":\"%s\",\"name\":\"Qml0VG9ycmVudA==\",\"abbr\":\"QkNU\"," + - "\"total_supply\":1000000,\"frozen_supply\":[{\"frozen_amount\":1,\"frozen_days\":1}]," + - "\"trx_num\":1,\"precision\":6,\"num\":1,\"start_time\":%d,\"end_time\":%d," + - "\"description\":\"Z1JQQ3VybEFzc2V0\",\"url\":\"d3d3LnVybC5jb20=\",\"free_asset_net_limit\":1000," + - "\"public_free_asset_net_limit\":2000}", - newAccountBase64, - System.currentTimeMillis(), - System.currentTimeMillis() + 100000L - ); - String requestUrl = "protocol.Wallet/CreateAssetIssue"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = + String.format( + "{\"owner_address\":\"%s\",\"name\":\"Qml0VG9ycmVudA==\",\"abbr\":\"QkNU\"," + + "\"total_supply\":1000000,\"frozen_supply\":[{\"frozen_amount\":1,\"frozen_days\"" + + ":1}]," + + "\"trx_num\":1,\"precision\":6,\"num\":1,\"start_time\":%d,\"end_time\":%d," + + "\"description\":\"Z1JQQ3VybEFzc2V0\",\"url\":\"d3d3LnVybC5jb20=\",\"free_asset_n" + + "et_limit\":1000," + + "\"public_free_asset_net_limit\":2000}", + newAccountBase64, System.currentTimeMillis(), System.currentTimeMillis() + 100000L); + String requestUrl = "protocol.Wallet/CreateAssetIssue"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertFalse(returnString.contains("transaction")); @@ -406,24 +462,28 @@ public void test017CreateAssetIssue(){ Assert.assertTrue(returnString.contains("raw_data")); } - - @Test(enabled = true, description = "test CreateAssetIssue2", groups = {"daily"}) - public void test018CreateAssetIssue2(){ + @Test( + enabled = true, + description = "test CreateAssetIssue2", + groups = {"daily"}) + public void test018CreateAssetIssue2() { ECKey newAccount = new ECKey(Utils.getRandom()); - String newAccountBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); - PublicMethod.sendcoin(newAccount.getAddress(), 2000000000, foundationAddress, foundationKey, blockingStubFull); + String newAccountBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); + PublicMethod.sendcoin( + newAccount.getAddress(), 2000000000, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String data = String.format("{\"owner_address\":\"%s\",\"name\":\"Qml0VG9ycmVudA==\",\"abbr\":\"QkNU\"," + - "\"total_supply\":1000000,\"frozen_supply\":[{\"frozen_amount\":1,\"frozen_days\":1}]," + - "\"trx_num\":1,\"precision\":6,\"num\":1,\"start_time\":%d,\"end_time\":%d," + - "\"description\":\"Z1JQQ3VybEFzc2V0\",\"url\":\"d3d3LnVybC5jb20=\",\"free_asset_net_limit\":1000," + - "\"public_free_asset_net_limit\":2000}", - newAccountBase64, - System.currentTimeMillis(), - System.currentTimeMillis() + 100000L - ); - String requestUrl = "protocol.Wallet/CreateAssetIssue2"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = + String.format( + "{\"owner_address\":\"%s\",\"name\":\"Qml0VG9ycmVudA==\",\"abbr\":\"QkNU\"," + + "\"total_supply\":1000000,\"frozen_supply\":[{\"frozen_amount\":1,\"frozen_days\"" + + ":1}]," + + "\"trx_num\":1,\"precision\":6,\"num\":1,\"start_time\":%d,\"end_time\":%d," + + "\"description\":\"Z1JQQ3VybEFzc2V0\",\"url\":\"d3d3LnVybC5jb20=\",\"free_asset_n" + + "et_limit\":1000," + + "\"public_free_asset_net_limit\":2000}", + newAccountBase64, System.currentTimeMillis(), System.currentTimeMillis() + 100000L); + String requestUrl = "protocol.Wallet/CreateAssetIssue2"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("transaction")); @@ -432,18 +492,24 @@ public void test018CreateAssetIssue2(){ Assert.assertTrue(returnString.contains("raw_data")); } - @Test(enabled = true, description = "test CreateCommonTransaction", groups = {"daily"}) + @Test( + enabled = true, + description = "test CreateCommonTransaction", + groups = {"daily"}) public void test019CreateCommonTransaction() { ECKey newAccount = new ECKey(Utils.getRandom()); - String newAccountBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); - String ownerAddressBase64 = Base64.getEncoder().encodeToString(foundationAddress); - String data = String.format( - "{\"raw_data\":[{\"contract\":{\"type\":\"TransferContract\",\"parameter\":{\"@type\":\"type.googleapis.com/protocol.TransferContract\",\"owner_address\":\"%s\",\"to_address\":\"%s\",\"amount\":100000000}}}]}", - ownerAddressBase64, - newAccountBase64 - ); - String requestUrl = "protocol.Wallet/CreateCommonTransaction"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String newAccountBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); + String ownerAddressBase64 = Base64.getEncoder().encodeToString(foundationAddress); + String data = + String.format( + "{\"raw_data\":[{\"contract\":{\"type\":\"TransferContract\"," + + "\"parameter\":{\"@type\":" + + "\"type.googleapis.com/protocol.TransferContract\"," + + "\"owner_address\":\"%s\"," + + "\"to_address\":\"%s\",\"amount\":100000000}}}]}", + ownerAddressBase64, newAccountBase64); + String requestUrl = "protocol.Wallet/CreateCommonTransaction"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("transaction")); @@ -452,15 +518,19 @@ public void test019CreateCommonTransaction() { Assert.assertTrue(returnString.contains("raw_data")); } - @Test(enabled = true, description = "test CreateWitness", groups = {"daily"}) + @Test( + enabled = true, + description = "test CreateWitness", + groups = {"daily"}) public void test020CreateWitness() { String ownerAddressBase64 = Base64.getEncoder().encodeToString(foundationAddress); PublicMethod.waitProduceNextBlock(blockingStubFull); - String data = String.format("{\"owner_address\":\"%s\",\"url\":\"d3d3LmdycGN1cmx0ZXN0LmNvbQ==\"}", - ownerAddressBase64 - ); - String requestUrl = "protocol.Wallet/CreateWitness"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = + String.format( + "{\"owner_address\":\"%s\",\"url\":\"d3d3LmdycGN1cmx0ZXN0LmNvbQ==\"}", + ownerAddressBase64); + String requestUrl = "protocol.Wallet/CreateWitness"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("ref_block_bytes")); @@ -468,15 +538,19 @@ public void test020CreateWitness() { Assert.assertTrue(returnString.contains("raw_data")); } - @Test(enabled = true, description = "test CreateWitness2", groups = {"daily"}) + @Test( + enabled = true, + description = "test CreateWitness2", + groups = {"daily"}) public void test021CreateWitness2() { String ownerAddressBase64 = Base64.getEncoder().encodeToString(foundationAddress); PublicMethod.waitProduceNextBlock(blockingStubFull); - String data = String.format("{\"owner_address\":\"%s\",\"url\":\"d3d3LmdycGN1cmx0ZXN0LmNvbQ==\"}", - ownerAddressBase64 - ); - String requestUrl = "protocol.Wallet/CreateWitness2"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = + String.format( + "{\"owner_address\":\"%s\",\"url\":\"d3d3LmdycGN1cmx0ZXN0LmNvbQ==\"}", + ownerAddressBase64); + String requestUrl = "protocol.Wallet/CreateWitness2"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("transaction")); @@ -485,22 +559,31 @@ public void test021CreateWitness2() { Assert.assertTrue(returnString.contains("raw_data")); } - @Test(enabled = true, description = "test DelegateResource", groups = {"daily"}) + @Test( + enabled = true, + description = "test DelegateResource", + groups = {"daily"}) public void test022DelegateResource() { ECKey newAccount = new ECKey(Utils.getRandom()); - String newAccountBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); - String ownerAddressBase64 = Base64.getEncoder().encodeToString(foundationAddress); - PublicMethod.sendcoin(newAccount.getAddress(), 100000000, foundationAddress, foundationKey, blockingStubFull); + String newAccountBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); + String ownerAddressBase64 = Base64.getEncoder().encodeToString(foundationAddress); + PublicMethod.sendcoin( + newAccount.getAddress(), 100000000, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.freezeBalanceV2(newAccount.getAddress(), 50000000, - 1, ByteArray.toHexString(newAccount.getPrivKeyBytes()),blockingStubFull); + PublicMethod.freezeBalanceV2( + newAccount.getAddress(), + 50000000, + 1, + ByteArray.toHexString(newAccount.getPrivKeyBytes()), + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String data = String.format("{\"owner_address\":\"%s\",\"resource\":\"ENERGY\",\"balance\":50000000,\"receiver_address\":\"%s\"}", - newAccountBase64, - ownerAddressBase64 - ); - String requestUrl = "protocol.Wallet/DelegateResource"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = + String.format( + "{\"owner_address\":\"%s\",\"resource\":\"ENERGY\",\"balance\":50000000,\"receiver_addr" + + "ess\":\"%s\"}", + newAccountBase64, ownerAddressBase64); + String requestUrl = "protocol.Wallet/DelegateResource"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("transaction")); @@ -509,23 +592,46 @@ public void test022DelegateResource() { Assert.assertTrue(returnString.contains("raw_data")); } - @Test(enabled = true, description = "DeployContract", groups = {"daily"}) + @Test( + enabled = true, + description = "DeployContract", + groups = {"daily"}) public void test023DeployContract() { String ownerAddressBase64 = Base64.getEncoder().encodeToString(foundationAddress); - String data = String.format("{\"owner_address\":\"%s\",\"new_contract\":{\"abi\":{\"entrys\":[{\"inputs\":[{" + - "\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"foo\",\"outputs\":[{\"name\":\"\",\"type\":" + - "\"uint256\"}],\"stateMutability\":\"Nonpayable\",\"type\":\"Function\"}]},\"bytecode\":" + - "\"NjA4MDYwNDA1MjM0ODAxNTYxMDAxMDU3NjAwMDgwZmQ1YjUwZDM4MDE1NjEwMDFkNTc2MDAwODBmZDViNTBkMjgwMTU2MTAwMmE" + - "1NzYwMDA4MGZkNWI1MDYwYjg4MDYxMDAzOTYwMDAzOTYwMDBmM2ZlNjA4MDYwNDA1MjM0ODAxNTYwMGY1NzYwMDA4MGZkNWI1MGQzOD" + - "AxNTYwMWI1NzYwMDA4MGZkNWI1MGQyODAxNTYwMjc1NzYwMDA4MGZkNWI1MDYwMDQzNjEwNjA0MDU3NjAwMDM1NjBlMDFjODA2MzJmY" + - "mViZDM4MTQ2MDQ1NTc1YjYwMDA4MGZkNWI2MDU4NjA1MDM2NjAwNDYwNmE1NjViNjAwMDgxOTA1NTkwNTY1YjYwNDA1MTkwODE1MjY" + - "wMjAwMTYwNDA1MTgwOTEwMzkwZjM1YjYwMDA2MDIwODI4NDAzMTIxNTYwN2I1NzYwMDA4MGZkNWI1MDM1OTE5MDUwNTZmZWEyNjQ3ND" + - "cyNmY2ZTU4MjIxMjIwYzg2Njk3MTVmZTk1MzgxZWUzMTVlMTExOTA2NGZmODBhODEyMWRkZmM1Mjc0N2E1NTE2MWQwZDRmNGRkYTJh" + - "NTY0NzM2ZjZjNjM0MzAwMDgxMjAwMzM=\",\"name\":\"MyContract\",\"consume_user_resource_percent\":100}}", - ownerAddressBase64 - ); - String requestUrl = "protocol.Wallet/DeployContract"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = + String.format( + "{\"owner_address\":\"%s\",\"new_contract\":" + + "{\"abi\":{\"entrys\":[{\"inputs\":[{" + + "\"name\":\"value\",\"type\":\"uint256\"}]," + + "\"name\":\"foo\",\"outputs\":[{\"name\"" + + ":\"\",\"type\":" + + "\"uint256\"}],\"stateMutability\":" + + "\"Nonpayable\",\"type\":\"Function\"}]}," + + "\"bytecode\":" + + "\"NjA4MDYwNDA1MjM0ODAxNTYxMDAxMDU3Nj" + + "AwMDgwZmQ1YjUwZDM4MDE1NjEwMDFkNTc2MD" + + "AwODBmZDViNTBkMjgwMTU2MTAwMmE" + + "1NzYwMDA4MGZkNWI1MDYwYjg4MDYxMDAzOTYw" + + "MDAzOTYwMDBmM2ZlNjA4MDYwNDA1MjM0ODAxN" + + "TYwMGY1NzYwMDA4MGZkNWI1MGQzOD" + + "AxNTYwMWI1NzYwMDA4MGZkNWI1MGQyODAxNTYw" + + "Mjc1NzYwMDA4MGZkNWI1MDYwMDQzNjEwNjA0MD" + + "U3NjAwMDM1NjBlMDFjODA2MzJmY" + + "mViZDM4MTQ2MDQ1NTc1YjYwMDA4MGZkNWI2MDU4" + + "NjA1MDM2NjAwNDYwNmE1NjViNjAwMDgxOTA1NT" + + "kwNTY1YjYwNDA1MTkwODE1MjY" + + "wMjAwMTYwNDA1MTgwOTEwMzkwZjM1YjYwMDA2MDI" + + "wODI4NDAzMTIxNTYwN2I1NzYwMDA4MGZkNWI1MD" + + "M1OTE5MDUwNTZmZWEyNjQ3ND" + + "cyNmY2ZTU4MjIxMjIwYzg2Njk3MTVmZTk1MzgxZW" + + "UzMTVlMTExOTA2NGZmODBhODEyMWRkZmM1Mjc0" + + "N2E1NTE2MWQwZDRmNGRkYTJh" + + "NTY0NzM2ZjZjNjM0MzAwMDgxMjAwMzM=\"," + + "\"name\":\"MyContract\"," + + "\"consume_user_resource_percent\":100}}", + ownerAddressBase64); + String requestUrl = "protocol.Wallet/DeployContract"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("transaction")); @@ -534,12 +640,18 @@ public void test023DeployContract() { Assert.assertTrue(returnString.contains("raw_data")); } - @Test(enabled = true, description = "test FreezeBalanceV2", groups = {"daily"}) + @Test( + enabled = true, + description = "test FreezeBalanceV2", + groups = {"daily"}) public void test024FreezeBalanceV2() { String ownerAddressBase64 = Base64.getEncoder().encodeToString(foundationAddress); - String data = String.format("{\"owner_address\":\"%s\",\"frozen_balance\":100000000,\"resource\":1}", ownerAddressBase64); - String requestUrl = "protocol.Wallet/FreezeBalanceV2"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = + String.format( + "{\"owner_address\":\"%s\",\"frozen_balance\":100000000,\"resource\":1}", + ownerAddressBase64); + String requestUrl = "protocol.Wallet/FreezeBalanceV2"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("transaction")); @@ -548,206 +660,252 @@ public void test024FreezeBalanceV2() { Assert.assertTrue(returnString.contains("raw_data")); } - @Test(enabled = true, description = "test GetAccountBalance", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetAccountBalance", + groups = {"daily"}) public void test025GetAccountBalance() { String ownerAddressBase64 = Base64.getEncoder().encodeToString(foundationAddress); - Protocol.Block block = PublicMethod.getBlock(2L, blockingStubFull); - byte[] hash = block.getBlockHeader().getRawData().getParentHash().toByteArray(); - String hashBase64 = Base64.getEncoder().encodeToString(hash); - String data = String.format("{\"account_identifier\":{\"address\":\"%s\"},\"block_identifier\":{\"number\":1,\"hash\":\"%s\"}}", - ownerAddressBase64, - hashBase64 - ); - String requestUrl = "protocol.Wallet/GetAccountBalance"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + Protocol.Block block = PublicMethod.getBlock(2L, blockingStubFull); + byte[] hash = block.getBlockHeader().getRawData().getParentHash().toByteArray(); + String hashBase64 = Base64.getEncoder().encodeToString(hash); + String data = + String.format( + "{\"account_identifier\":{\"address\":\"%s\"},\"block_identifier\":{\"number\":1,\"hash" + + "\":\"%s\"}}", + ownerAddressBase64, hashBase64); + String requestUrl = "protocol.Wallet/GetAccountBalance"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("balance")); Assert.assertTrue(returnString.contains("10000000000000000")); } - @Test(enabled = true, description = "test GetAccountById", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetAccountById", + groups = {"daily"}) public void test026GetAccountById() { ECKey newAccount = new ECKey(Utils.getRandom()); - PublicMethod.sendcoin(newAccount.getAddress(), 100000000, foundationAddress, foundationKey, blockingStubFull); + PublicMethod.sendcoin( + newAccount.getAddress(), 100000000, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String utf8AccountId = "grpcUrlTest"; - PublicMethod.setAccountId(utf8AccountId.getBytes(), newAccount.getAddress(),ByteArray.toHexString(newAccount.getPrivKeyBytes()), blockingStubFull); + String utf8AccountId = "grpcUrlTest"; + PublicMethod.setAccountId( + utf8AccountId.getBytes(), + newAccount.getAddress(), + ByteArray.toHexString(newAccount.getPrivKeyBytes()), + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String data = "{\"account_id\":\"Z3JwY1VybFRlc3Q=\"}"; - String requestUrl = "protocol.Wallet/GetAccountById"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = "{\"account_id\":\"Z3JwY1VybFRlc3Q=\"}"; + String requestUrl = "protocol.Wallet/GetAccountById"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); JSONObject accountInfo = JSONObject.parseObject(returnString); Assert.assertEquals(accountInfo.getLongValue("balance"), 100000000L); Assert.assertTrue(returnString.contains("account_id")); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); - String requestUrlSolidity = "protocol.WalletSolidity/GetAccountById"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetAccountById"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); Assert.assertTrue(returnStringSolidity.contains("account_id")); Assert.assertTrue(returnStringSolidity.contains("Z3JwY1VybFRlc3Q=")); - String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); Assert.assertTrue(returnStringPBFT.contains("account_id")); Assert.assertTrue(returnStringPBFT.contains("Z3JwY1VybFRlc3Q=")); - - } - @Test(enabled = true, description = "test GetAssetIssueByAccount", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetAssetIssueByAccount", + groups = {"daily"}) public void test027GetAssetIssueByAccount() { String ownerAddressBase64 = Base64.getEncoder().encodeToString(jsonRpcOwnerAddress); - String data = String.format("{\"address\":\"%s\"}", ownerAddressBase64); - String requestUrl = "protocol.Wallet/GetAssetIssueByAccount"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = String.format("{\"address\":\"%s\"}", ownerAddressBase64); + String requestUrl = "protocol.Wallet/GetAssetIssueByAccount"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("assetIssue")); Assert.assertTrue(returnString.contains("public_free_asset_net_limit")); } - @Test(enabled = true, description = "test GetAssetIssueById", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetAssetIssueById", + groups = {"daily"}) public void test028GetAssetIssueById() { String data = "{\"value\":\"MTAwMDAwMQ==\"}"; - String requestUrl = "protocol.Wallet/GetAssetIssueById"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String requestUrl = "protocol.Wallet/GetAssetIssueById"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("owner_address")); Assert.assertTrue(returnString.contains("total_supply")); Assert.assertTrue(returnString.contains("description")); - String requestUrlSolidity = "protocol.WalletSolidity/GetAssetIssueById"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetAssetIssueById"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); Assert.assertEquals(returnStringSolidity, returnString); - String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); Assert.assertEquals(returnStringPBFT, returnString); } - @Test(enabled = true, description = "test GetAssetIssueByName", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetAssetIssueByName", + groups = {"daily"}) public void test029GetAssetIssueByName() { String data = "{\"value\":\"anNvbnJwYy10ZXN0\"}"; - String requestUrl = "protocol.Wallet/GetAssetIssueByName"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String requestUrl = "protocol.Wallet/GetAssetIssueByName"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("owner_address")); Assert.assertTrue(returnString.contains("total_supply")); Assert.assertTrue(returnString.contains("description")); - String requestUrlSolidity = "protocol.WalletSolidity/GetAssetIssueByName"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetAssetIssueByName"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); Assert.assertEquals(returnStringSolidity, returnString); - String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); Assert.assertEquals(returnStringPBFT, returnString); } - @Test(enabled = true, description = "test GetAssetIssueList", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetAssetIssueList", + groups = {"daily"}) public void test030GetAssetIssueList() { String requestUrl = "protocol.Wallet/GetAssetIssueList"; - String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); + String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("owner_address")); Assert.assertTrue(returnString.contains("total_supply")); Assert.assertTrue(returnString.contains("description")); - String requestUrlSolidity = "protocol.WalletSolidity/GetAssetIssueList"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetAssetIssueList"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(null, requestUrlSolidity, soliditynode); logger.info(returnStringSolidity); Assert.assertTrue(returnStringSolidity.contains("owner_address")); Assert.assertTrue(returnStringSolidity.contains("total_supply")); Assert.assertTrue(returnStringSolidity.contains("description")); - String returnStringPBFT = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, pbftnode); logger.info(returnStringPBFT); Assert.assertTrue(returnStringPBFT.contains("owner_address")); Assert.assertTrue(returnStringPBFT.contains("total_supply")); Assert.assertTrue(returnStringPBFT.contains("description")); } - @Test(enabled = true, description = "test GetAssetIssueListByName", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetAssetIssueListByName", + groups = {"daily"}) public void test031GetAssetIssueListByName() { String data = "{\"value\":\"anNvbnJwYy10ZXN0\"}"; - String requestUrl = "protocol.Wallet/GetAssetIssueListByName"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String requestUrl = "protocol.Wallet/GetAssetIssueListByName"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("owner_address")); Assert.assertTrue(returnString.contains("total_supply")); Assert.assertTrue(returnString.contains("description")); - String requestUrlSolidity = "protocol.WalletSolidity/GetAssetIssueListByName"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetAssetIssueListByName"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); Assert.assertEquals(returnStringSolidity, returnString); - String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); Assert.assertEquals(returnStringPBFT, returnString); } - @Test(enabled = true, description = "test GetAvailableUnfreezeCount", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetAvailableUnfreezeCount", + groups = {"daily"}) public void test032GetAvailableUnfreezeCount() { String ownerAddressBase64 = Base64.getEncoder().encodeToString(jsonRpcOwnerAddress); - String data = String.format("{\"owner_address\":\"%s\"}", ownerAddressBase64); - String requestUrl = "protocol.Wallet/GetAvailableUnfreezeCount"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = String.format("{\"owner_address\":\"%s\"}", ownerAddressBase64); + String requestUrl = "protocol.Wallet/GetAvailableUnfreezeCount"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("count")); Assert.assertTrue(returnString.contains("32")); - String requestUrlSolidity = "protocol.WalletSolidity/GetAvailableUnfreezeCount"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetAvailableUnfreezeCount"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); Assert.assertEquals(returnStringSolidity, returnString); - String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); Assert.assertEquals(returnStringPBFT, returnString); } - @Test(enabled = true, description = "test GetBandwidthPrices", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetBandwidthPrices", + groups = {"daily"}) public void test033GetBandwidthPrices() { String requestUrl = "protocol.Wallet/GetBandwidthPrices"; - String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); + String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("prices")); - String requestUrlSolidity = "protocol.WalletSolidity/GetBandwidthPrices"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetBandwidthPrices"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(null, requestUrlSolidity, soliditynode); Assert.assertEquals(returnStringSolidity, returnString); - String returnStringPBFT = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, pbftnode); Assert.assertEquals(returnStringPBFT, returnString); } - @Test(enabled = true, description = "test GetBlock", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetBlock", + groups = {"daily"}) public void test034GetBlock() { String data = "{\"id_or_num\":\"1\",\"detail\":true}"; - String requestUrl = "protocol.Wallet/GetBlock"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String requestUrl = "protocol.Wallet/GetBlock"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("block_header")); Assert.assertTrue(returnString.contains("raw_data")); Assert.assertTrue(returnString.contains("witness_address")); - String requestUrlSolidity = "protocol.WalletSolidity/GetBlock"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetBlock"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); Assert.assertEquals(returnStringSolidity, returnString); - String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); Assert.assertEquals(returnStringPBFT, returnString); } - @Test(enabled = true, description = "test GetBlockBalanceTrace", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetBlockBalanceTrace", + groups = {"daily"}) public void test035GetBlockBalanceTrace() { - Protocol.Block block = PublicMethod.getBlock(2L, blockingStubFull); - byte[] hash = block.getBlockHeader().getRawData().getParentHash().toByteArray(); - String hashBase64 = Base64.getEncoder().encodeToString(hash); - String data = String.format("{\"number\":1,\"hash\":\"%s\"}", - hashBase64 - ); - String requestUrl = "protocol.Wallet/GetBlockBalanceTrace"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + Protocol.Block block = PublicMethod.getBlock(2L, blockingStubFull); + byte[] hash = block.getBlockHeader().getRawData().getParentHash().toByteArray(); + String hashBase64 = Base64.getEncoder().encodeToString(hash); + String data = String.format("{\"number\":1,\"hash\":\"%s\"}", hashBase64); + String requestUrl = "protocol.Wallet/GetBlockBalanceTrace"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("block_identifier")); Assert.assertTrue(returnString.contains("timestamp")); } - @Test(enabled = true, description = "test GetBlockByLatestNum", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetBlockByLatestNum", + groups = {"daily"}) public void test036GetBlockByLatestNum() { String data = "{\"num\":1}"; - String requestUrl = "protocol.Wallet/GetBlockByLatestNum"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String requestUrl = "protocol.Wallet/GetBlockByLatestNum"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); logger.info(returnString); Assert.assertNotNull(returnString); Assert.assertTrue(returnString.contains("block_header")); @@ -755,154 +913,203 @@ public void test036GetBlockByLatestNum() { Assert.assertTrue(returnString.contains("number")); } - @Test(enabled = true, description = "test GetBrokerageInfo", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetBrokerageInfo", + groups = {"daily"}) public void test037GetBrokerageInfo() { String ownerAddressBase64 = Base64.getEncoder().encodeToString(foundationAddress); - String data = String.format("{\"value\":\"%s\"}", ownerAddressBase64) ; - String requestUrl = "protocol.Wallet/GetBrokerageInfo"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = String.format("{\"value\":\"%s\"}", ownerAddressBase64); + String requestUrl = "protocol.Wallet/GetBrokerageInfo"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("num")); Assert.assertTrue(returnString.contains("20")); - String requestUrlSolidity = "protocol.WalletSolidity/GetBrokerageInfo"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetBrokerageInfo"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); Assert.assertEquals(returnStringSolidity, returnString); - String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); Assert.assertEquals(returnStringPBFT, returnString); } - @Test(enabled = true, description = "test GetBurnTrx", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetBurnTrx", + groups = {"daily"}) public void test038GetBurnTrx() { String requestUrl = "protocol.Wallet/GetBurnTrx"; - String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); + String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("num")); JSONObject burnInfo = JSONObject.parseObject(returnString); - Long burnNum = burnInfo.getLong("num"); + Long burnNum = burnInfo.getLong("num"); Assert.assertTrue(burnNum > 0L); - String requestUrlSolidity = "protocol.WalletSolidity/GetBurnTrx"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetBurnTrx"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(null, requestUrlSolidity, soliditynode); Assert.assertTrue(returnStringSolidity.contains("num")); - String returnStringPBFT = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(null, requestUrlSolidity, pbftnode); Assert.assertTrue(returnStringPBFT.contains("num")); } - @Test(enabled = true, description = "test GetCanDelegatedMaxSize", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetCanDelegatedMaxSize", + groups = {"daily"}) public void test039GetCanDelegatedMaxSize() { ECKey newAccount = new ECKey(Utils.getRandom()); - String newAccountBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); - PublicMethod.sendcoin(newAccount.getAddress(), 100000000, foundationAddress, foundationKey, blockingStubFull); + String newAccountBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); + PublicMethod.sendcoin( + newAccount.getAddress(), 100000000, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.freezeBalanceV2(newAccount.getAddress(), 50000000, - 1, ByteArray.toHexString(newAccount.getPrivKeyBytes()),blockingStubFull); + PublicMethod.freezeBalanceV2( + newAccount.getAddress(), + 50000000, + 1, + ByteArray.toHexString(newAccount.getPrivKeyBytes()), + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String data = String.format("{\"type\":\"1\",\"owner_address\":\"%s\"}", newAccountBase64); - String requestUrl = "protocol.Wallet/GetCanDelegatedMaxSize"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = String.format("{\"type\":\"1\",\"owner_address\":\"%s\"}", newAccountBase64); + String requestUrl = "protocol.Wallet/GetCanDelegatedMaxSize"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("max_size")); Assert.assertTrue(returnString.contains("50000000")); PublicMethod.waitProduceNextBlock(blockingStubFull); - String requestUrlSolidity = "protocol.WalletSolidity/GetCanDelegatedMaxSize"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetCanDelegatedMaxSize"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); Assert.assertEquals(returnStringSolidity, returnString); - String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); Assert.assertEquals(returnStringPBFT, returnString); } - - @Test(enabled = true, description = "test GetCanWithdrawUnfreezeAmount", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetCanWithdrawUnfreezeAmount", + groups = {"daily"}) public void test040GetCanWithdrawUnfreezeAmount() { Long sendAmount = 100000000L; - ECKey newAccount = new ECKey(Utils.getRandom()); - String newAccountBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); - PublicMethod.sendcoin(newAccount.getAddress(), sendAmount, foundationAddress, foundationKey, blockingStubFull); + ECKey newAccount = new ECKey(Utils.getRandom()); + String newAccountBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); + PublicMethod.sendcoin( + newAccount.getAddress(), sendAmount, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.freezeBalanceV2(newAccount.getAddress(), sendAmount/2, - 1, ByteArray.toHexString(newAccount.getPrivKeyBytes()),blockingStubFull); + PublicMethod.freezeBalanceV2( + newAccount.getAddress(), + sendAmount / 2, + 1, + ByteArray.toHexString(newAccount.getPrivKeyBytes()), + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.unFreezeBalanceV2(newAccount.getAddress(),ByteArray.toHexString(newAccount.getPrivKeyBytes()), - sendAmount/4, + PublicMethod.unFreezeBalanceV2( + newAccount.getAddress(), + ByteArray.toHexString(newAccount.getPrivKeyBytes()), + sendAmount / 4, 1, - blockingStubFull - ); + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long queryTime = System.currentTimeMillis() + 1000000000L; - String data = String.format("{\"timestamp\":\"%s\",\"owner_address\":\"%s\"}", queryTime, newAccountBase64); - String requestUrl = "protocol.Wallet/GetCanWithdrawUnfreezeAmount"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + Long queryTime = System.currentTimeMillis() + 1000000000L; + String data = + String.format( + "{\"timestamp\":\"%s\",\"owner_address\":\"%s\"}", queryTime, newAccountBase64); + String requestUrl = "protocol.Wallet/GetCanWithdrawUnfreezeAmount"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("amount")); Assert.assertTrue(returnString.contains("25000000")); PublicMethod.waitProduceNextBlock(blockingStubFull); - String requestUrlSolidity = "protocol.WalletSolidity/GetCanWithdrawUnfreezeAmount"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetCanWithdrawUnfreezeAmount"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); Assert.assertEquals(returnStringSolidity, returnString); - String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); Assert.assertEquals(returnStringPBFT, returnString); - String requestUrl2 = "protocol.Wallet/UnfreezeBalanceV2"; - String data2 = String.format("{\"owner_address\":\"%s\",\"unfreeze_balance\":\"%d\",\"resource\":1}", - newAccountBase64, - sendAmount/4 - ); - String returnString2 = PublicMethod.gRPCurlRequest(data2, requestUrl2, fullnode); + String requestUrl2 = "protocol.Wallet/UnfreezeBalanceV2"; + String data2 = + String.format( + "{\"owner_address\":\"%s\",\"unfreeze_balance\":\"%d\",\"resource\":1}", + newAccountBase64, sendAmount / 4); + String returnString2 = PublicMethod.gRPCurlRequest(data2, requestUrl2, fullnode); Assert.assertNotNull(returnString2); logger.info(returnString2); Assert.assertTrue(returnString2.contains("UnfreezeBalanceV2Contract")); - Assert.assertTrue(returnString2.contains(String.valueOf(sendAmount/4))); + Assert.assertTrue(returnString2.contains(String.valueOf(sendAmount / 4))); } - @Test(enabled = true, description = "test GetChainParameters", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetChainParameters", + groups = {"daily"}) public void test041GetChainParameters() { String requestUrl = "protocol.Wallet/GetChainParameters"; - String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); + String returnString = PublicMethod.gRPCurlRequest(null, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("chainParameter")); Assert.assertTrue(returnString.contains("getUnfreezeDelayDays")); } - @Test(enabled = true, description = "test GetDelegatedResourceAccountIndexV2", groups = {"daily"}) + @Test( + enabled = true, + description = "test GetDelegatedResourceAccountIndexV2", + groups = {"daily"}) public void test042GetDelegatedResourceAccountIndexV2() { Long sendAmount = 100000000L; - ECKey newAccount = new ECKey(Utils.getRandom()); - String newAccountBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); - ECKey resourceReceiver = new ECKey(Utils.getRandom()); - String receiverAccountBase64 = Base64.getEncoder().encodeToString(resourceReceiver.getAddress()); - PublicMethod.sendcoin(newAccount.getAddress(), sendAmount, foundationAddress, foundationKey, blockingStubFull); - PublicMethod.sendcoin(resourceReceiver.getAddress(), sendAmount, foundationAddress, foundationKey, blockingStubFull); + ECKey newAccount = new ECKey(Utils.getRandom()); + String newAccountBase64 = Base64.getEncoder().encodeToString(newAccount.getAddress()); + ECKey resourceReceiver = new ECKey(Utils.getRandom()); + String receiverAccountBase64 = + Base64.getEncoder().encodeToString(resourceReceiver.getAddress()); + PublicMethod.sendcoin( + newAccount.getAddress(), sendAmount, foundationAddress, foundationKey, blockingStubFull); + PublicMethod.sendcoin( + resourceReceiver.getAddress(), + sendAmount, + foundationAddress, + foundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.freezeBalanceV2(newAccount.getAddress(), sendAmount/2, - 1, ByteArray.toHexString(newAccount.getPrivKeyBytes()),blockingStubFull); + PublicMethod.freezeBalanceV2( + newAccount.getAddress(), + sendAmount / 2, + 1, + ByteArray.toHexString(newAccount.getPrivKeyBytes()), + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.delegateResourceV2(newAccount.getAddress(), - sendAmount/4, + PublicMethod.delegateResourceV2( + newAccount.getAddress(), + sendAmount / 4, 1, resourceReceiver.getAddress(), ByteArray.toHexString(newAccount.getPrivKeyBytes()), - blockingStubFull - ); + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String data = String.format("{\"value\":\"%s\"}", newAccountBase64); - String requestUrl = "protocol.Wallet/GetDelegatedResourceAccountIndexV2"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = String.format("{\"value\":\"%s\"}", newAccountBase64); + String requestUrl = "protocol.Wallet/GetDelegatedResourceAccountIndexV2"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains(receiverAccountBase64)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String requestUrlSolidity = "protocol.WalletSolidity/GetDelegatedResourceAccountIndexV2"; - String returnStringSolidity = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); + String requestUrlSolidity = "protocol.WalletSolidity/GetDelegatedResourceAccountIndexV2"; + String returnStringSolidity = + PublicMethod.gRPCurlRequest(data, requestUrlSolidity, soliditynode); Assert.assertEquals(returnStringSolidity, returnString); - String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); + String returnStringPBFT = PublicMethod.gRPCurlRequest(data, requestUrlSolidity, pbftnode); Assert.assertEquals(returnStringPBFT, returnString); - String data2 = String.format("{\"fromAddress\":\"%s\",\"toAddress\":\"%s\"}", newAccountBase64, receiverAccountBase64); - String requestUrl2 = "protocol.Wallet/GetDelegatedResourceV2"; - String returnString2 = PublicMethod.gRPCurlRequest(data2, requestUrl2, fullnode); + String data2 = + String.format( + "{\"fromAddress\":\"%s\",\"toAddress\":\"%s\"}", + newAccountBase64, receiverAccountBase64); + String requestUrl2 = "protocol.Wallet/GetDelegatedResourceV2"; + String returnString2 = PublicMethod.gRPCurlRequest(data2, requestUrl2, fullnode); Assert.assertNotNull(returnString2); logger.info(returnString2); Assert.assertTrue(returnString2.contains("frozen_balance_for_energy")); @@ -913,138 +1120,159 @@ public void test042GetDelegatedResourceAccountIndexV2() { Assert.assertEquals(returnStringSolidity, returnString2); returnStringPBFT = PublicMethod.gRPCurlRequest(data2, requestUrlSolidity, pbftnode); Assert.assertEquals(returnStringPBFT, returnString2); - String requestUrl3 = "protocol.Wallet/UnDelegateResource"; - String data3 = String.format("{\"owner_address\":\"%s\",\"resource\":\"ENERGY\",\"balance\":%d,\"receiver_address\":\"%s\"}", - newAccountBase64, - sendAmount/4, - receiverAccountBase64 - ); - String returnString3 = PublicMethod.gRPCurlRequest(data3, requestUrl3, fullnode); + String requestUrl3 = "protocol.Wallet/UnDelegateResource"; + String data3 = + String.format( + "{\"owner_address\":\"%s\",\"resource\":\"ENERGY\",\"balance\":%d,\"receiver_address\":" + + "\"%s\"}", + newAccountBase64, sendAmount / 4, receiverAccountBase64); + String returnString3 = PublicMethod.gRPCurlRequest(data3, requestUrl3, fullnode); Assert.assertNotNull(returnString3); logger.info(returnString3); Assert.assertTrue(returnString3.contains("UnDelegateResourceContract")); Assert.assertTrue(returnString3.contains("25000000")); } - @Test(enabled = true, description = "test ParticipateAssetIssue", groups = {"daily"}) + @Test( + enabled = true, + description = "test ParticipateAssetIssue", + groups = {"daily"}) public void test043ParticipateAssetIssue() { String trc10OwnerBase64 = Base64.getEncoder().encodeToString(jsonRpcOwnerAddress); Protocol.Account accountInfo = PublicMethod.queryAccount(jsonRpcOwnerAddress, blockingStubFull); - String assetNameBase64 = Base64.getEncoder().encodeToString(accountInfo.getAssetIssuedID().toByteArray()); - String partnerBase64 = Base64.getEncoder().encodeToString(foundationAddress); - String requestUrl = "protocol.Wallet/ParticipateAssetIssue"; - String data = String.format("{\"owner_address\":\"%s\",\"to_address\":\"%s\",\"asset_name\":\"%s\",\"amount\":1}", - partnerBase64, - trc10OwnerBase64, - assetNameBase64 - ); - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String assetNameBase64 = + Base64.getEncoder().encodeToString(accountInfo.getAssetIssuedID().toByteArray()); + String partnerBase64 = Base64.getEncoder().encodeToString(foundationAddress); + String requestUrl = "protocol.Wallet/ParticipateAssetIssue"; + String data = + String.format( + "{\"owner_address\":\"%s\",\"to_address\":\"%s\",\"asset_name\":\"%s\",\"amount\":1}", + partnerBase64, trc10OwnerBase64, assetNameBase64); + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("raw_data")); Assert.assertTrue(returnString.contains("asset_name")); - Assert.assertTrue(returnString.contains("type.googleapis.com/protocol.ParticipateAssetIssueContract")); + Assert.assertTrue( + returnString.contains("type.googleapis.com/protocol.ParticipateAssetIssueContract")); } - - @Test(enabled = true, description = "test ParticipateAssetIssue2", groups = {"daily"}) + @Test( + enabled = true, + description = "test ParticipateAssetIssue2", + groups = {"daily"}) public void test044ParticipateAssetIssue2() { String trc10OwnerBase64 = Base64.getEncoder().encodeToString(jsonRpcOwnerAddress); Protocol.Account accountInfo = PublicMethod.queryAccount(jsonRpcOwnerAddress, blockingStubFull); - String assetNameBase64 = Base64.getEncoder().encodeToString(accountInfo.getAssetIssuedID().toByteArray()); - String partnerBase64 = Base64.getEncoder().encodeToString(foundationAddress); - String requestUrl = "protocol.Wallet/ParticipateAssetIssue2"; - String data = String.format("{\"owner_address\":\"%s\",\"to_address\":\"%s\",\"asset_name\":\"%s\",\"amount\":1}", - partnerBase64, - trc10OwnerBase64, - assetNameBase64 - ); - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String assetNameBase64 = + Base64.getEncoder().encodeToString(accountInfo.getAssetIssuedID().toByteArray()); + String partnerBase64 = Base64.getEncoder().encodeToString(foundationAddress); + String requestUrl = "protocol.Wallet/ParticipateAssetIssue2"; + String data = + String.format( + "{\"owner_address\":\"%s\",\"to_address\":\"%s\",\"asset_name\":\"%s\",\"amount\":1}", + partnerBase64, trc10OwnerBase64, assetNameBase64); + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("raw_data")); Assert.assertTrue(returnString.contains("asset_name")); - Assert.assertTrue(returnString.contains("type.googleapis.com/protocol.ParticipateAssetIssueContract")); + Assert.assertTrue( + returnString.contains("type.googleapis.com/protocol.ParticipateAssetIssueContract")); } - @Test(enabled = true, description = "test TransferAsset", groups = {"daily"}) + @Test( + enabled = true, + description = "test TransferAsset", + groups = {"daily"}) public void test045TransferAsset() { ECKey receiver = new ECKey(Utils.getRandom()); - String receiverBase64 = Base64.getEncoder().encodeToString(receiver.getAddress()); - String fromBase64 = Base64.getEncoder().encodeToString(jsonRpcOwnerAddress); + String receiverBase64 = Base64.getEncoder().encodeToString(receiver.getAddress()); + String fromBase64 = Base64.getEncoder().encodeToString(jsonRpcOwnerAddress); Protocol.Account accountInfo = PublicMethod.queryAccount(jsonRpcOwnerAddress, blockingStubFull); - String assetName = accountInfo.getAssetIssuedID().toStringUtf8(); - String assetNameBase64 = Base64.getEncoder().encodeToString(ByteArray.fromString(assetName)); + String assetName = accountInfo.getAssetIssuedID().toStringUtf8(); + String assetNameBase64 = Base64.getEncoder().encodeToString(ByteArray.fromString(assetName)); logger.info(assetName); - String data = String.format( - "{\"asset_name\":\"%s\",\"owner_address\":\"%s\",\"to_address\":\"%s\",\"amount\":1}", - assetNameBase64, - fromBase64, - receiverBase64 - ); - String requestUrl = "protocol.Wallet/TransferAsset"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = + String.format( + "{\"asset_name\":\"%s\",\"owner_address\":\"%s\",\"to_address\":\"%s\",\"amount\":1}", + assetNameBase64, fromBase64, receiverBase64); + String requestUrl = "protocol.Wallet/TransferAsset"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); logger.info(returnString); Assert.assertTrue(returnString.contains("raw_data")); Assert.assertTrue(returnString.contains("TransferAssetContract")); } - @Test(enabled = true, description = "test UnfreezeAsset", groups = {"daily"}) + @Test( + enabled = true, + description = "test UnfreezeAsset", + groups = {"daily"}) public void test046UnfreezeAsset() { String fromBase64 = Base64.getEncoder().encodeToString(jsonRpcOwnerAddress); Protocol.Account accountInfo = PublicMethod.queryAccount(jsonRpcOwnerAddress, blockingStubFull); - String assetName = accountInfo.getAssetIssuedID().toStringUtf8(); + String assetName = accountInfo.getAssetIssuedID().toStringUtf8(); logger.info(assetName); - String data = String.format( - "{\"owner_address\":\"%s\"}", - fromBase64 - ); - String requestUrl = "protocol.Wallet/UnfreezeAsset"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = String.format("{\"owner_address\":\"%s\"}", fromBase64); + String requestUrl = "protocol.Wallet/UnfreezeAsset"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); logger.info(returnString); Assert.assertTrue(returnString.contains("raw_data")); Assert.assertTrue(returnString.contains("type.googleapis.com/protocol.UnfreezeAssetContract")); } - @Test(enabled = true, description = "test UnfreezeAsset2", groups = {"daily"}) + @Test( + enabled = true, + description = "test UnfreezeAsset2", + groups = {"daily"}) public void test047UnfreezeAsset2() { String fromBase64 = Base64.getEncoder().encodeToString(jsonRpcOwnerAddress); Protocol.Account accountInfo = PublicMethod.queryAccount(jsonRpcOwnerAddress, blockingStubFull); - String assetName = accountInfo.getAssetIssuedID().toStringUtf8(); + String assetName = accountInfo.getAssetIssuedID().toStringUtf8(); logger.info(assetName); - String data = String.format( - "{\"owner_address\":\"%s\"}", - fromBase64 - ); - String requestUrl = "protocol.Wallet/UnfreezeAsset2"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = String.format("{\"owner_address\":\"%s\"}", fromBase64); + String requestUrl = "protocol.Wallet/UnfreezeAsset2"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); logger.info(returnString); Assert.assertTrue(returnString.contains("transaction")); Assert.assertTrue(returnString.contains("raw_data")); Assert.assertTrue(returnString.contains("type.googleapis.com/protocol.UnfreezeAssetContract")); } - @Test(enabled = true, description = "test UpdateAsset2", groups = {"daily"}) + @Test( + enabled = true, + description = "test UpdateAsset2", + groups = {"daily"}) public void test048UpdateAsset2() { String ownerAddressBase64 = Base64.getEncoder().encodeToString(jsonRpcOwnerAddress); - String data = String.format("{\"owner_address\":\"%s\",\"description\":\"dGVzdEdycGN1cmw=\",\"url\":\"d3d3LmNjLmNvbQ==\"}", ownerAddressBase64) ; - String requestUrl = "protocol.Wallet/UpdateAsset2"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = + String.format( + "{\"owner_address\":\"%s\",\"description\":\"dGVzdEdycGN1cmw=\",\"url\":\"d3d3LmNjLmNvb" + + "Q==\"}", + ownerAddressBase64); + String requestUrl = "protocol.Wallet/UpdateAsset2"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("transaction")); Assert.assertTrue(returnString.contains("type.googleapis.com/protocol.UpdateAssetContract")); } - @Test(enabled = true, description = "test UpdateAsset", groups = {"daily"}) + @Test( + enabled = true, + description = "test UpdateAsset", + groups = {"daily"}) public void test049UpdateAsset() { String ownerAddressBase64 = Base64.getEncoder().encodeToString(jsonRpcOwnerAddress); - String data = String.format("{\"owner_address\":\"%s\",\"description\":\"dGVzdEdycGN1cmw=\",\"url\":\"d3d3LmNjLmNvbQ==\"}", ownerAddressBase64) ; - String requestUrl = "protocol.Wallet/UpdateAsset"; - String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); + String data = + String.format( + "{\"owner_address\":\"%s\",\"description\":\"dGVzdEdycGN1cmw=\",\"url\":\"d3d3LmNjLmNvb" + + "Q==\"}", + ownerAddressBase64); + String requestUrl = "protocol.Wallet/UpdateAsset"; + String returnString = PublicMethod.gRPCurlRequest(data, requestUrl, fullnode); Assert.assertNotNull(returnString); logger.info(returnString); Assert.assertTrue(returnString.contains("type.googleapis.com/protocol.UpdateAssetContract")); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpShieldTrc20Token001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpShieldTrc20Token001.java index 8dd9cde4..d0554ab7 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpShieldTrc20Token001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpShieldTrc20Token001.java @@ -54,34 +54,37 @@ public class HttpShieldTrc20Token001 extends ZenTrc20Base { ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] zenTokenOwnerAddress = ecKey1.getAddress(); String zenTokenOwnerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - private String httpnode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(0); - private String httpSolidityNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); + private String httpSolidityNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); private JSONObject responseContent; private HttpResponse response; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - //Args.getInstance().setFullNodeAllowShieldedTransaction(true); - //PublicMethod.printAddress(foundationZenTokenKey); - //PublicMethod.printAddress(zenTokenOwnerKey); + // Args.getInstance().setFullNodeAllowShieldedTransaction(true); + // PublicMethod.printAddress(foundationZenTokenKey); + // PublicMethod.printAddress(zenTokenOwnerKey); } - @Test(enabled = true, description = "Get spending key by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get spending key by http", + groups = {"daily", "serial"}) public void test01GetSpendingKey() { response = HttpMethod.getSpendingKey(httpnode); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); sk = responseContent.getString("value"); logger.info("sk: " + sk); - } - @Test(enabled = true, description = "Get diversifier by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get diversifier by http", + groups = {"daily", "serial"}) public void test02GetDiversifier() { response = HttpMethod.getDiversifier(httpnode); responseContent = HttpMethod.parseResponseContent(response); @@ -102,7 +105,10 @@ public void test02GetDiversifier() { logger.info("d3: " + d3); } - @Test(enabled = true, description = "Get expanded spending key by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get expanded spending key by http", + groups = {"daily", "serial"}) public void test03GetExpandedSpendingKey() { response = HttpMethod.getExpandedSpendingKey(httpnode, sk); responseContent = HttpMethod.parseResponseContent(response); @@ -115,7 +121,10 @@ public void test03GetExpandedSpendingKey() { logger.info("ovk: " + ovk); } - @Test(enabled = true, description = "Get AK from ASK by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get AK from ASK by http", + groups = {"daily", "serial"}) public void test04GetAkFromAsk() { response = HttpMethod.getAkFromAsk(httpnode, ask); responseContent = HttpMethod.parseResponseContent(response); @@ -124,7 +133,10 @@ public void test04GetAkFromAsk() { logger.info("ak: " + ak); } - @Test(enabled = true, description = "Get Nk from Nsk by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get Nk from Nsk by http", + groups = {"daily", "serial"}) public void test05GetNkFromNsk() { response = HttpMethod.getNkFromNsk(httpnode, nsk); responseContent = HttpMethod.parseResponseContent(response); @@ -133,7 +145,10 @@ public void test05GetNkFromNsk() { logger.info("nk: " + nk); } - @Test(enabled = true, description = "Get incoming viewing Key by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get incoming viewing Key by http", + groups = {"daily", "serial"}) public void test06GetIncomingViewingKey() { response = HttpMethod.getIncomingViewingKey(httpnode, ak, nk); responseContent = HttpMethod.parseResponseContent(response); @@ -142,7 +157,10 @@ public void test06GetIncomingViewingKey() { logger.info("ivk: " + ivk); } - @Test(enabled = true, description = "Get Zen Payment Address by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get Zen Payment Address by http", + groups = {"daily", "serial"}) public void test07GetZenPaymentAddress() { response = HttpMethod.getZenPaymentAddress(httpnode, ivk, d1); responseContent = HttpMethod.parseResponseContent(response); @@ -187,7 +205,10 @@ public void test07GetZenPaymentAddress() { shieldAddressOptionalInfo3 = Optional.of(shieldAddressInfo3); } - @Test(enabled = true, description = "Get rcm by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get rcm by http", + groups = {"daily", "serial"}) public void test08GetRcm() { response = HttpMethod.getRcm(httpnode); responseContent = HttpMethod.parseResponseContent(response); @@ -196,10 +217,7 @@ public void test08GetRcm() { logger.info("rcm: " + rcm); } - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { - } -} \ No newline at end of file + public void shutdown() throws InterruptedException {} +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpShieldTrc20Token002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpShieldTrc20Token002.java index c1f66eca..de227c6e 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpShieldTrc20Token002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpShieldTrc20Token002.java @@ -16,19 +16,22 @@ public class HttpShieldTrc20Token002 extends ZenTrc20Base { JSONArray shieldedReceives = new JSONArray(); String txid; - private String httpnode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(0); - private String anotherHttpnode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(1); - private String httpSolidityNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); + private String anotherHttpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(1); + private String httpSolidityNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); private JSONObject responseContent; private HttpResponse response; private JSONObject shieldAccountInfo; private JSONArray noteTxs; private Long publicFromAmount = getRandomLongAmount(); - @Test(enabled = true, description = "Get new shield account by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get new shield account by http", + groups = {"daily", "serial"}) public void test01GetNewShieldAccountByHttp() { response = getNewShieldedAddress(httpnode); shieldAccountInfo = HttpMethod.parseResponseContent(response); @@ -49,110 +52,157 @@ public void test01GetNewShieldAccountByHttp() { HttpMethod.printJsonContent(responseContent); } - @Test(enabled = true, description = "Create mint parameters by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Create mint parameters by http", + groups = {"daily", "serial"}) public void test02MintByHttp() { - shieldedReceives = getHttpShieldedReceivesJsonArray(shieldedReceives, publicFromAmount, - shieldAccountInfo.getString("payment_address"), getRcm((httpnode))); - response = createShieldContractParameters(httpnode, publicFromAmount, shieldAccountInfo, - shieldedReceives); + shieldedReceives = + getHttpShieldedReceivesJsonArray( + shieldedReceives, + publicFromAmount, + shieldAccountInfo.getString("payment_address"), + getRcm((httpnode))); + response = + createShieldContractParameters( + httpnode, publicFromAmount, shieldAccountInfo, shieldedReceives); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - txid = HttpMethod.triggerContractGetTxidWithVisibleTrue(httpnode,anotherHttpnode, - zenTrc20TokenOwnerAddressString, shieldAddress, mint, responseContent - .getString("trigger_contract_input"), maxFeeLimit, 0L, 0, 0L, - zenTrc20TokenOwnerKey); + txid = + HttpMethod.triggerContractGetTxidWithVisibleTrue( + httpnode, + anotherHttpnode, + zenTrc20TokenOwnerAddressString, + shieldAddress, + mint, + responseContent.getString("trigger_contract_input"), + maxFeeLimit, + 0L, + 0, + 0L, + zenTrc20TokenOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getTransactionInfoById(httpnode, txid, true); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - Assert.assertTrue(responseContent.getJSONObject("receipt") - .getLong("energy_usage_total") > 250000L); + Assert.assertTrue( + responseContent.getJSONObject("receipt").getLong("energy_usage_total") > 250000L); Assert.assertEquals(responseContent.getString("contract_address"), shieldAddress); - Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), - "SUCCESS"); + Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), "SUCCESS"); shieldedReceives.clear(); - shieldedReceives = getHttpShieldedReceivesJsonArray(shieldedReceives, publicFromAmount, - shieldAccountInfo.getString("payment_address"), getRcm(httpnode)); - response = createShieldContractParameters(httpnode, publicFromAmount, shieldAccountInfo, - shieldedReceives); + shieldedReceives = + getHttpShieldedReceivesJsonArray( + shieldedReceives, + publicFromAmount, + shieldAccountInfo.getString("payment_address"), + getRcm(httpnode)); + response = + createShieldContractParameters( + httpnode, publicFromAmount, shieldAccountInfo, shieldedReceives); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - txid = HttpMethod.triggerContractGetTxidWithVisibleTrue(httpnode,anotherHttpnode, - zenTrc20TokenOwnerAddressString, shieldAddress, mint, responseContent - .getString("trigger_contract_input"), maxFeeLimit, 0L, 0, 0L, - zenTrc20TokenOwnerKey); + txid = + HttpMethod.triggerContractGetTxidWithVisibleTrue( + httpnode, + anotherHttpnode, + zenTrc20TokenOwnerAddressString, + shieldAddress, + mint, + responseContent.getString("trigger_contract_input"), + maxFeeLimit, + 0L, + 0, + 0L, + zenTrc20TokenOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getTransactionInfoById(httpnode, txid, true); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - Assert.assertTrue(responseContent.getJSONObject("receipt") - .getLong("energy_usage_total") > 250000L); + Assert.assertTrue( + responseContent.getJSONObject("receipt").getLong("energy_usage_total") > 250000L); Assert.assertEquals(responseContent.getString("contract_address"), shieldAddress); - Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), - "SUCCESS"); - - + Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), "SUCCESS"); } - - @Test(enabled = true, description = "Scan shield TRC20 note by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Scan shield TRC20 note by http", + groups = {"daily", "serial"}) public void test03ScanTrc20NodeByHttp() { noteTxs = scanShieldTrc20NoteByIvk(httpnode, shieldAccountInfo); logger.info(noteTxs.toJSONString()); Assert.assertEquals(noteTxs.size(), 2); - Assert.assertEquals(noteTxs.getJSONObject(1) - .getJSONObject("note").getLong("value"), publicFromAmount); - Assert.assertEquals(noteTxs.getJSONObject(1) - .getJSONObject("note").getString("payment_address"), + Assert.assertEquals( + noteTxs.getJSONObject(1).getJSONObject("note").getLong("value"), publicFromAmount); + Assert.assertEquals( + noteTxs.getJSONObject(1).getJSONObject("note").getString("payment_address"), shieldAccountInfo.getString("payment_address")); - Assert.assertEquals(noteTxs.getJSONObject(1) - .getString("txid"), txid); + Assert.assertEquals(noteTxs.getJSONObject(1).getString("txid"), txid); } - @Test(enabled = true, description = "Shield trc20 burn by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Shield trc20 burn by http", + groups = {"daily", "serial"}) public void test04ShiledTrc20BurnByHttp() { JSONArray shieldSpends = new JSONArray(); shieldSpends = createAndSetShieldedSpends(httpnode, shieldSpends, noteTxs.getJSONObject(0)); logger.info(shieldSpends.toJSONString()); - response = createShieldContractParametersForBurn(httpnode, shieldAccountInfo, shieldSpends, - zenTrc20TokenOwnerAddressString, publicFromAmount); + response = + createShieldContractParametersForBurn( + httpnode, + shieldAccountInfo, + shieldSpends, + zenTrc20TokenOwnerAddressString, + publicFromAmount); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - txid = HttpMethod.triggerContractGetTxidWithVisibleTrue(httpnode,anotherHttpnode, - zenTrc20TokenOwnerAddressString, shieldAddress, burn, responseContent - .getString("trigger_contract_input"), maxFeeLimit, 0L, 0, 0L, - zenTrc20TokenOwnerKey); + txid = + HttpMethod.triggerContractGetTxidWithVisibleTrue( + httpnode, + anotherHttpnode, + zenTrc20TokenOwnerAddressString, + shieldAddress, + burn, + responseContent.getString("trigger_contract_input"), + maxFeeLimit, + 0L, + 0, + 0L, + zenTrc20TokenOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getTransactionInfoById(httpnode, txid, true); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - Assert.assertTrue(responseContent.getJSONObject("receipt") - .getLong("energy_usage_total") > 150000L); + Assert.assertTrue( + responseContent.getJSONObject("receipt").getLong("energy_usage_total") > 150000L); Assert.assertEquals(responseContent.getString("contract_address"), shieldAddress); - Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), - "SUCCESS"); + Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), "SUCCESS"); noteTxs = scanShieldTrc20NoteByOvk(httpnode, shieldAccountInfo); logger.info("noteTxs ovk:" + noteTxs); Assert.assertEquals(noteTxs.getJSONObject(0).getLong("to_amount"), publicFromAmount); - Assert.assertEquals(noteTxs.getJSONObject(0).getString("transparent_to_address"), + Assert.assertEquals( + noteTxs.getJSONObject(0).getString("transparent_to_address"), zenTrc20TokenOwnerAddressString); Assert.assertEquals(noteTxs.getJSONObject(0).getString("txid"), txid); } - - @Test(enabled = true, description = "Shield trc20 burn with ask by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Shield trc20 burn with ask by http", + groups = {"daily", "serial"}) public void test05ShiledTrc20BurnWithoutAskByHttp() { noteTxs = scanShieldTrc20NoteByIvk(httpnode, shieldAccountInfo); JSONArray shieldSpends = new JSONArray(); @@ -160,41 +210,59 @@ public void test05ShiledTrc20BurnWithoutAskByHttp() { logger.info(shieldSpends.toJSONString()); - response = createShieldContractParametersWithoutAskForBurn(httpnode, shieldAccountInfo, - shieldSpends, zenTrc20TokenOwnerAddressString, publicFromAmount); + response = + createShieldContractParametersWithoutAskForBurn( + httpnode, + shieldAccountInfo, + shieldSpends, + zenTrc20TokenOwnerAddressString, + publicFromAmount); JSONObject shieldedTrc20Parameters = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(shieldedTrc20Parameters); - JSONObject spendAuthSig = createSpendAuthSig(httpnode, shieldAccountInfo, - shieldedTrc20Parameters.getString("message_hash"), noteTxs.getJSONObject(1) - .getJSONObject("note").getString("rcm")); + JSONObject spendAuthSig = + createSpendAuthSig( + httpnode, + shieldAccountInfo, + shieldedTrc20Parameters.getString("message_hash"), + noteTxs.getJSONObject(1).getJSONObject("note").getString("rcm")); HttpMethod.printJsonContent(spendAuthSig); JSONArray spendAuthSigArray = new JSONArray(); spendAuthSigArray.add(spendAuthSig); - response = getTriggerInputForShieldedTrc20BurnContract(httpnode, - shieldedTrc20Parameters, spendAuthSigArray, publicFromAmount, - zenTrc20TokenOwnerAddressString); + response = + getTriggerInputForShieldedTrc20BurnContract( + httpnode, + shieldedTrc20Parameters, + spendAuthSigArray, + publicFromAmount, + zenTrc20TokenOwnerAddressString); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - txid = HttpMethod.triggerContractGetTxidWithVisibleTrue(httpnode,anotherHttpnode, - zenTrc20TokenOwnerAddressString, shieldAddress, burn, responseContent - .getString("value"), maxFeeLimit, 0L, 0, 0L, - zenTrc20TokenOwnerKey); + txid = + HttpMethod.triggerContractGetTxidWithVisibleTrue( + httpnode, + anotherHttpnode, + zenTrc20TokenOwnerAddressString, + shieldAddress, + burn, + responseContent.getString("value"), + maxFeeLimit, + 0L, + 0, + 0L, + zenTrc20TokenOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getTransactionInfoById(httpnode, txid, true); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - Assert.assertTrue(responseContent.getJSONObject("receipt") - .getLong("energy_usage_total") > 150000L); + Assert.assertTrue( + responseContent.getJSONObject("receipt").getLong("energy_usage_total") > 150000L); Assert.assertEquals(responseContent.getString("contract_address"), shieldAddress); Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), "SUCCESS"); - } - @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { - } -} \ No newline at end of file + public void shutdown() throws InterruptedException {} +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpShieldTrc20Token003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpShieldTrc20Token003.java index 7635fd38..4720ff13 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpShieldTrc20Token003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpShieldTrc20Token003.java @@ -18,12 +18,12 @@ public class HttpShieldTrc20Token003 extends ZenTrc20Base { JSONArray shieldedReceives = new JSONArray(); String txid; JSONArray shieldSpends = new JSONArray(); - private String httpnode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(0); - private String anotherHttpnode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(1); - private String httpSolidityNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); + private String anotherHttpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(1); + private String httpSolidityNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); private JSONObject responseContent; private HttpResponse response; private JSONObject shieldAccountInfo1; @@ -36,15 +36,13 @@ public class HttpShieldTrc20Token003 extends ZenTrc20Base { private Long account1Receive1V2Amount = 10L; private Long account2Receive1V2Amount = publicFromAmount - account1Receive1V2Amount; private Long account1Receive2V2Amount = 13L; - private Long account2Receive2V2Amount = publicFromAmount - + account2Receive1V2Amount - account1Receive2V2Amount; + private Long account2Receive2V2Amount = + publicFromAmount + account2Receive1V2Amount - account1Receive2V2Amount; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true, description = "Prepare for transfer") public void prepareForTransfer() { - //Create two shield account + // Create two shield account response = getNewShieldedAddress(httpnode); shieldAccountInfo1 = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(shieldAccountInfo1); @@ -52,238 +50,343 @@ public void prepareForTransfer() { response = getNewShieldedAddress(httpnode); shieldAccountInfo2 = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(shieldAccountInfo2); - //Send two mint to shield account 1 + // Send two mint to shield account 1 shieldedReceives.clear(); - shieldedReceives = getHttpShieldedReceivesJsonArray(shieldedReceives, publicFromAmount, - shieldAccountInfo1.getString("payment_address"), getRcm(httpnode)); - response = createShieldContractParameters(httpnode, publicFromAmount, shieldAccountInfo1, - shieldedReceives); + shieldedReceives = + getHttpShieldedReceivesJsonArray( + shieldedReceives, + publicFromAmount, + shieldAccountInfo1.getString("payment_address"), + getRcm(httpnode)); + response = + createShieldContractParameters( + httpnode, publicFromAmount, shieldAccountInfo1, shieldedReceives); responseContent = HttpMethod.parseResponseContent(response); - //HttpMethod.printJsonContent(responseContent); - - txid = HttpMethod.triggerContractGetTxidWithVisibleTrue(httpnode,anotherHttpnode, - zenTrc20TokenOwnerAddressString, shieldAddress, mint, responseContent - .getString("trigger_contract_input"), maxFeeLimit, 0L, 0, 0L, - zenTrc20TokenOwnerKey); + // HttpMethod.printJsonContent(responseContent); + + txid = + HttpMethod.triggerContractGetTxidWithVisibleTrue( + httpnode, + anotherHttpnode, + zenTrc20TokenOwnerAddressString, + shieldAddress, + mint, + responseContent.getString("trigger_contract_input"), + maxFeeLimit, + 0L, + 0, + 0L, + zenTrc20TokenOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); shieldedReceives.clear(); - shieldedReceives = getHttpShieldedReceivesJsonArray(shieldedReceives, publicFromAmount, - shieldAccountInfo1.getString("payment_address"), getRcm(httpnode)); - response = createShieldContractParameters(httpnode, publicFromAmount, shieldAccountInfo1, - shieldedReceives); + shieldedReceives = + getHttpShieldedReceivesJsonArray( + shieldedReceives, + publicFromAmount, + shieldAccountInfo1.getString("payment_address"), + getRcm(httpnode)); + response = + createShieldContractParameters( + httpnode, publicFromAmount, shieldAccountInfo1, shieldedReceives); responseContent = HttpMethod.parseResponseContent(response); - //HttpMethod.printJsonContent(responseContent); - - txid = HttpMethod.triggerContractGetTxidWithVisibleTrue(httpnode,anotherHttpnode, - zenTrc20TokenOwnerAddressString, shieldAddress, mint, responseContent - .getString("trigger_contract_input"), maxFeeLimit, 0L, 0, 0L, - zenTrc20TokenOwnerKey); + // HttpMethod.printJsonContent(responseContent); + + txid = + HttpMethod.triggerContractGetTxidWithVisibleTrue( + httpnode, + anotherHttpnode, + zenTrc20TokenOwnerAddressString, + shieldAddress, + mint, + responseContent.getString("trigger_contract_input"), + maxFeeLimit, + 0L, + 0, + 0L, + zenTrc20TokenOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); } - - @Test(enabled = true, description = "Transfer type with 1V1 by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Transfer type with 1V1 by http", + groups = {"daily", "serial"}) public void test01TransferTypeWith1V1ByHttp() { account1IvkNoteTxs = scanShieldTrc20NoteByIvk(httpnode, shieldAccountInfo1); shieldSpends.clear(); - shieldSpends = createAndSetShieldedSpends(httpnode, shieldSpends, account1IvkNoteTxs - .getJSONObject(0)); + shieldSpends = + createAndSetShieldedSpends(httpnode, shieldSpends, account1IvkNoteTxs.getJSONObject(0)); shieldedReceives.clear(); - shieldedReceives = getHttpShieldedReceivesJsonArray(shieldedReceives, publicFromAmount, - shieldAccountInfo2.getString("payment_address"), getRcm(httpnode)); - response = createShieldContractParametersForTransfer(httpnode, shieldAccountInfo1, - shieldSpends, shieldedReceives); + shieldedReceives = + getHttpShieldedReceivesJsonArray( + shieldedReceives, + publicFromAmount, + shieldAccountInfo2.getString("payment_address"), + getRcm(httpnode)); + response = + createShieldContractParametersForTransfer( + httpnode, shieldAccountInfo1, shieldSpends, shieldedReceives); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - txid = HttpMethod.triggerContractGetTxidWithVisibleTrue(httpnode,anotherHttpnode, - zenTrc20TokenOwnerAddressString, shieldAddress, transfer, responseContent - .getString("trigger_contract_input"), maxFeeLimit, 0L, 0, 0L, - zenTrc20TokenOwnerKey); + txid = + HttpMethod.triggerContractGetTxidWithVisibleTrue( + httpnode, + anotherHttpnode, + zenTrc20TokenOwnerAddressString, + shieldAddress, + transfer, + responseContent.getString("trigger_contract_input"), + maxFeeLimit, + 0L, + 0, + 0L, + zenTrc20TokenOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getTransactionInfoById(httpnode, txid, true); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - Assert.assertTrue(responseContent.getJSONObject("receipt") - .getLong("energy_usage_total") > 300000L); + Assert.assertTrue( + responseContent.getJSONObject("receipt").getLong("energy_usage_total") > 300000L); Assert.assertEquals(responseContent.getString("contract_address"), shieldAddress); - Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), - "SUCCESS"); + Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), "SUCCESS"); account1OvkNoteTxs = scanShieldTrc20NoteByOvk(httpnode, shieldAccountInfo1); logger.info(account1OvkNoteTxs.toJSONString()); Assert.assertEquals(account1OvkNoteTxs.size(), 1); } - @Test(enabled = true, description = "Transfer type with 1V2 by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Transfer type with 1V2 by http", + groups = {"daily", "serial"}) public void test02TransferTypeWith1V2ByHttp() { account1IvkNoteTxs = scanShieldTrc20NoteByIvk(httpnode, shieldAccountInfo1); - Assert.assertTrue(isShieldedTrc20ContractNoteSpent(httpnode, shieldAccountInfo1, - account1IvkNoteTxs.getJSONObject(0))); - Assert.assertFalse(isShieldedTrc20ContractNoteSpent(httpnode, shieldAccountInfo1, - account1IvkNoteTxs.getJSONObject(1))); + Assert.assertTrue( + isShieldedTrc20ContractNoteSpent( + httpnode, shieldAccountInfo1, account1IvkNoteTxs.getJSONObject(0))); + Assert.assertFalse( + isShieldedTrc20ContractNoteSpent( + httpnode, shieldAccountInfo1, account1IvkNoteTxs.getJSONObject(1))); shieldSpends.clear(); - shieldSpends = createAndSetShieldedSpends(httpnode, shieldSpends, account1IvkNoteTxs - .getJSONObject(1)); + shieldSpends = + createAndSetShieldedSpends(httpnode, shieldSpends, account1IvkNoteTxs.getJSONObject(1)); shieldedReceives.clear(); - shieldedReceives = getHttpShieldedReceivesJsonArray(shieldedReceives, account1Receive1V2Amount, - shieldAccountInfo1.getString("payment_address"), getRcm(httpnode)); - shieldedReceives = getHttpShieldedReceivesJsonArray(shieldedReceives, account2Receive1V2Amount, - shieldAccountInfo2.getString("payment_address"), getRcm(httpnode)); - response = createShieldContractParametersForTransfer(httpnode, shieldAccountInfo1, shieldSpends, - shieldedReceives); + shieldedReceives = + getHttpShieldedReceivesJsonArray( + shieldedReceives, + account1Receive1V2Amount, + shieldAccountInfo1.getString("payment_address"), + getRcm(httpnode)); + shieldedReceives = + getHttpShieldedReceivesJsonArray( + shieldedReceives, + account2Receive1V2Amount, + shieldAccountInfo2.getString("payment_address"), + getRcm(httpnode)); + response = + createShieldContractParametersForTransfer( + httpnode, shieldAccountInfo1, shieldSpends, shieldedReceives); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); Assert.assertTrue(responseContent.containsKey("trigger_contract_input")); - txid = HttpMethod.triggerContractGetTxidWithVisibleTrue(httpnode,anotherHttpnode, - zenTrc20TokenOwnerAddressString, shieldAddress, transfer, responseContent - .getString("trigger_contract_input"), maxFeeLimit, 0L, 0, 0L, - zenTrc20TokenOwnerKey); + txid = + HttpMethod.triggerContractGetTxidWithVisibleTrue( + httpnode, + anotherHttpnode, + zenTrc20TokenOwnerAddressString, + shieldAddress, + transfer, + responseContent.getString("trigger_contract_input"), + maxFeeLimit, + 0L, + 0, + 0L, + zenTrc20TokenOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getTransactionInfoById(httpnode, txid, true); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - Assert.assertTrue(responseContent.getJSONObject("receipt") - .getLong("energy_usage_total") > 300000L); + Assert.assertTrue( + responseContent.getJSONObject("receipt").getLong("energy_usage_total") > 300000L); Assert.assertEquals(responseContent.getString("contract_address"), shieldAddress); - Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), - "SUCCESS"); + Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), "SUCCESS"); account1OvkNoteTxs = scanShieldTrc20NoteByOvk(httpnode, shieldAccountInfo1); logger.info(account1OvkNoteTxs.toJSONString()); Assert.assertEquals(account1OvkNoteTxs.size(), 3); } - - @Test(enabled = true, description = "Transfer type with 2V2 by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Transfer type with 2V2 by http", + groups = {"daily", "serial"}) public void test03TransferTypeWith2V2ByHttp() { account2IvkNoteTxs = scanShieldTrc20NoteByIvk(httpnode, shieldAccountInfo2); - Assert.assertFalse(isShieldedTrc20ContractNoteSpent(httpnode, shieldAccountInfo2, - account2IvkNoteTxs.getJSONObject(0))); - Assert.assertFalse(isShieldedTrc20ContractNoteSpent(httpnode, shieldAccountInfo2, - account2IvkNoteTxs.getJSONObject(1))); + Assert.assertFalse( + isShieldedTrc20ContractNoteSpent( + httpnode, shieldAccountInfo2, account2IvkNoteTxs.getJSONObject(0))); + Assert.assertFalse( + isShieldedTrc20ContractNoteSpent( + httpnode, shieldAccountInfo2, account2IvkNoteTxs.getJSONObject(1))); shieldSpends.clear(); - shieldSpends = createAndSetShieldedSpends(httpnode, shieldSpends, account2IvkNoteTxs - .getJSONObject(0)); - shieldSpends = createAndSetShieldedSpends(httpnode, shieldSpends, account2IvkNoteTxs - .getJSONObject(1)); + shieldSpends = + createAndSetShieldedSpends(httpnode, shieldSpends, account2IvkNoteTxs.getJSONObject(0)); + shieldSpends = + createAndSetShieldedSpends(httpnode, shieldSpends, account2IvkNoteTxs.getJSONObject(1)); shieldedReceives.clear(); - shieldedReceives = getHttpShieldedReceivesJsonArray(shieldedReceives, account1Receive2V2Amount, - shieldAccountInfo1.getString("payment_address"), getRcm(httpnode)); - shieldedReceives = getHttpShieldedReceivesJsonArray(shieldedReceives, account2Receive2V2Amount, - shieldAccountInfo2.getString("payment_address"), getRcm(httpnode)); - response = createShieldContractParametersForTransfer(httpnode, shieldAccountInfo2, shieldSpends, - shieldedReceives); + shieldedReceives = + getHttpShieldedReceivesJsonArray( + shieldedReceives, + account1Receive2V2Amount, + shieldAccountInfo1.getString("payment_address"), + getRcm(httpnode)); + shieldedReceives = + getHttpShieldedReceivesJsonArray( + shieldedReceives, + account2Receive2V2Amount, + shieldAccountInfo2.getString("payment_address"), + getRcm(httpnode)); + response = + createShieldContractParametersForTransfer( + httpnode, shieldAccountInfo2, shieldSpends, shieldedReceives); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); Assert.assertTrue(responseContent.containsKey("trigger_contract_input")); - txid = HttpMethod.triggerContractGetTxidWithVisibleTrue(httpnode,anotherHttpnode, - zenTrc20TokenOwnerAddressString, shieldAddress, transfer, responseContent - .getString("trigger_contract_input"), maxFeeLimit, 0L, 0, 0L, - zenTrc20TokenOwnerKey); + txid = + HttpMethod.triggerContractGetTxidWithVisibleTrue( + httpnode, + anotherHttpnode, + zenTrc20TokenOwnerAddressString, + shieldAddress, + transfer, + responseContent.getString("trigger_contract_input"), + maxFeeLimit, + 0L, + 0, + 0L, + zenTrc20TokenOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getTransactionInfoById(httpnode, txid, true); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - Assert.assertTrue(responseContent.getJSONObject("receipt") - .getLong("energy_usage_total") > 300000L); + Assert.assertTrue( + responseContent.getJSONObject("receipt").getLong("energy_usage_total") > 300000L); Assert.assertEquals(responseContent.getString("contract_address"), shieldAddress); - Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), - "SUCCESS"); + Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), "SUCCESS"); account2OvkNoteTxs = scanShieldTrc20NoteByOvk(httpnode, shieldAccountInfo2); logger.info(account1OvkNoteTxs.toJSONString()); Assert.assertEquals(account2OvkNoteTxs.size(), 2); - Assert.assertTrue(isShieldedTrc20ContractNoteSpent(httpnode, shieldAccountInfo2, - account2IvkNoteTxs.getJSONObject(0))); - Assert.assertTrue(isShieldedTrc20ContractNoteSpent(httpnode, shieldAccountInfo2, - account2IvkNoteTxs.getJSONObject(1))); - + Assert.assertTrue( + isShieldedTrc20ContractNoteSpent( + httpnode, shieldAccountInfo2, account2IvkNoteTxs.getJSONObject(0))); + Assert.assertTrue( + isShieldedTrc20ContractNoteSpent( + httpnode, shieldAccountInfo2, account2IvkNoteTxs.getJSONObject(1))); } - @Test(enabled = true, description = "Transfer type with 2V1 by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Transfer type with 2V1 by http", + groups = {"daily", "serial"}) public void test04TransferTypeWith2V1ByHttp() { account1IvkNoteTxs = scanShieldTrc20NoteByIvk(httpnode, shieldAccountInfo1); - Assert.assertFalse(isShieldedTrc20ContractNoteSpent(httpnode, shieldAccountInfo1, - account1IvkNoteTxs.getJSONObject(2))); - Assert.assertFalse(isShieldedTrc20ContractNoteSpent(httpnode, shieldAccountInfo1, - account1IvkNoteTxs.getJSONObject(3))); + Assert.assertFalse( + isShieldedTrc20ContractNoteSpent( + httpnode, shieldAccountInfo1, account1IvkNoteTxs.getJSONObject(2))); + Assert.assertFalse( + isShieldedTrc20ContractNoteSpent( + httpnode, shieldAccountInfo1, account1IvkNoteTxs.getJSONObject(3))); shieldSpends.clear(); - shieldSpends = createAndSetShieldedSpends(httpnode, shieldSpends, account1IvkNoteTxs - .getJSONObject(2)); - shieldSpends = createAndSetShieldedSpends(httpnode, shieldSpends, account1IvkNoteTxs - .getJSONObject(3)); - Long account1Receive2V1Amount = account1IvkNoteTxs.getJSONObject(2) - .getJSONObject("note").getLong("value") - + account1IvkNoteTxs.getJSONObject(3).getJSONObject("note").getLong("value"); + shieldSpends = + createAndSetShieldedSpends(httpnode, shieldSpends, account1IvkNoteTxs.getJSONObject(2)); + shieldSpends = + createAndSetShieldedSpends(httpnode, shieldSpends, account1IvkNoteTxs.getJSONObject(3)); + Long account1Receive2V1Amount = + account1IvkNoteTxs.getJSONObject(2).getJSONObject("note").getLong("value") + + account1IvkNoteTxs.getJSONObject(3).getJSONObject("note").getLong("value"); shieldedReceives.clear(); - shieldedReceives = getHttpShieldedReceivesJsonArray(shieldedReceives, account1Receive2V1Amount, - shieldAccountInfo1.getString("payment_address"), getRcm(httpnode)); - response = createShieldContractParametersForTransfer(httpnode, shieldAccountInfo1, shieldSpends, - shieldedReceives); + shieldedReceives = + getHttpShieldedReceivesJsonArray( + shieldedReceives, + account1Receive2V1Amount, + shieldAccountInfo1.getString("payment_address"), + getRcm(httpnode)); + response = + createShieldContractParametersForTransfer( + httpnode, shieldAccountInfo1, shieldSpends, shieldedReceives); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); Assert.assertTrue(responseContent.containsKey("trigger_contract_input")); - txid = HttpMethod.triggerContractGetTxidWithVisibleTrue(httpnode,anotherHttpnode, - zenTrc20TokenOwnerAddressString, shieldAddress, transfer, responseContent - .getString("trigger_contract_input"), maxFeeLimit, 0L, 0, 0L, - zenTrc20TokenOwnerKey); + txid = + HttpMethod.triggerContractGetTxidWithVisibleTrue( + httpnode, + anotherHttpnode, + zenTrc20TokenOwnerAddressString, + shieldAddress, + transfer, + responseContent.getString("trigger_contract_input"), + maxFeeLimit, + 0L, + 0, + 0L, + zenTrc20TokenOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getTransactionInfoById(httpnode, txid, true); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - Assert.assertTrue(responseContent.getJSONObject("receipt") - .getLong("energy_usage_total") > 300000L); + Assert.assertTrue( + responseContent.getJSONObject("receipt").getLong("energy_usage_total") > 300000L); Assert.assertEquals(responseContent.getString("contract_address"), shieldAddress); - Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), - "SUCCESS"); + Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), "SUCCESS"); account1OvkNoteTxs = scanShieldTrc20NoteByOvk(httpnode, shieldAccountInfo1); logger.info(account1OvkNoteTxs.toJSONString()); Assert.assertEquals(account1OvkNoteTxs.size(), 4); account1IvkNoteTxs = scanShieldTrc20NoteByIvk(httpnode, shieldAccountInfo1); - Assert.assertTrue(isShieldedTrc20ContractNoteSpent(httpnode, shieldAccountInfo1, - account1IvkNoteTxs.getJSONObject(2))); - Assert.assertTrue(isShieldedTrc20ContractNoteSpent(httpnode, shieldAccountInfo1, - account1IvkNoteTxs.getJSONObject(3))); - + Assert.assertTrue( + isShieldedTrc20ContractNoteSpent( + httpnode, shieldAccountInfo1, account1IvkNoteTxs.getJSONObject(2))); + Assert.assertTrue( + isShieldedTrc20ContractNoteSpent( + httpnode, shieldAccountInfo1, account1IvkNoteTxs.getJSONObject(3))); } - - @Test(enabled = true, description = "Query is shielded trc20 contract note spent on " - + "solidity by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Query is shielded trc20 contract note spent on " + "solidity by http", + groups = {"daily", "serial"}) public void test05QueryIsShieldedTrc20ContractNoteSpentByHttp() { HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSolidityNode); - Assert.assertTrue(isShieldedTrc20ContractNoteSpentOnSolidity(httpSolidityNode, - shieldAccountInfo1, account1IvkNoteTxs.getJSONObject(2))); - Assert.assertTrue(isShieldedTrc20ContractNoteSpentOnSolidity(httpSolidityNode, - shieldAccountInfo1, account1IvkNoteTxs.getJSONObject(3))); + Assert.assertTrue( + isShieldedTrc20ContractNoteSpentOnSolidity( + httpSolidityNode, shieldAccountInfo1, account1IvkNoteTxs.getJSONObject(2))); + Assert.assertTrue( + isShieldedTrc20ContractNoteSpentOnSolidity( + httpSolidityNode, shieldAccountInfo1, account1IvkNoteTxs.getJSONObject(3))); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { - } -} \ No newline at end of file + public void shutdown() throws InterruptedException {} +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpShieldTrc20Token004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpShieldTrc20Token004.java index 1e5108fe..4e9c889e 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpShieldTrc20Token004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpShieldTrc20Token004.java @@ -18,14 +18,14 @@ public class HttpShieldTrc20Token004 extends ZenTrc20Base { JSONArray shieldedReceives = new JSONArray(); String txid; JSONArray shieldSpends = new JSONArray(); - private String httpnode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(0); - private String anotherHttpnode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(1); - private String httpSolidityNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); - private String httpPbftNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(4); + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); + private String anotherHttpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(1); + private String httpSolidityNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); + private String httpPbftNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(4); private JSONObject responseContent; private HttpResponse response; private JSONObject shieldAccountInfo1; @@ -38,15 +38,13 @@ public class HttpShieldTrc20Token004 extends ZenTrc20Base { private Long account1Receive1V2Amount = 10L; private Long account2Receive1V2Amount = publicFromAmount - account1Receive1V2Amount; private Long account1Receive2V2Amount = 13L; - private Long account2Receive2V2Amount = publicFromAmount + account2Receive1V2Amount - - account1Receive2V2Amount; + private Long account2Receive2V2Amount = + publicFromAmount + account2Receive1V2Amount - account1Receive2V2Amount; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true, description = "Prepare for transfer without ask") public void prepareForTransfer() { - //Create two shield account + // Create two shield account response = getNewShieldedAddress(httpnode); shieldAccountInfo1 = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(shieldAccountInfo1); @@ -54,78 +52,126 @@ public void prepareForTransfer() { response = getNewShieldedAddress(httpnode); shieldAccountInfo2 = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(shieldAccountInfo2); - //Send two mint to shield account 1 + // Send two mint to shield account 1 shieldedReceives.clear(); - shieldedReceives = getHttpShieldedReceivesJsonArray(shieldedReceives, publicFromAmount, - shieldAccountInfo1.getString("payment_address"), getRcm(httpnode)); + shieldedReceives = + getHttpShieldedReceivesJsonArray( + shieldedReceives, + publicFromAmount, + shieldAccountInfo1.getString("payment_address"), + getRcm(httpnode)); HttpMethod.waitToProduceOneBlock(httpnode); - response = createShieldContractParameters(httpnode, publicFromAmount, shieldAccountInfo1, - shieldedReceives); + response = + createShieldContractParameters( + httpnode, publicFromAmount, shieldAccountInfo1, shieldedReceives); responseContent = HttpMethod.parseResponseContent(response); - //HttpMethod.printJsonContent(responseContent); - - txid = HttpMethod.triggerContractGetTxidWithVisibleTrue(httpnode,anotherHttpnode, - zenTrc20TokenOwnerAddressString, shieldAddress, mint, responseContent - .getString("trigger_contract_input"), maxFeeLimit, 0L, 0, 0L, - zenTrc20TokenOwnerKey); + // HttpMethod.printJsonContent(responseContent); + + txid = + HttpMethod.triggerContractGetTxidWithVisibleTrue( + httpnode, + anotherHttpnode, + zenTrc20TokenOwnerAddressString, + shieldAddress, + mint, + responseContent.getString("trigger_contract_input"), + maxFeeLimit, + 0L, + 0, + 0L, + zenTrc20TokenOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); shieldedReceives.clear(); - shieldedReceives = getHttpShieldedReceivesJsonArray(shieldedReceives, publicFromAmount, - shieldAccountInfo1.getString("payment_address"), getRcm(httpnode)); - response = createShieldContractParameters(httpnode, publicFromAmount, shieldAccountInfo1, - shieldedReceives); + shieldedReceives = + getHttpShieldedReceivesJsonArray( + shieldedReceives, + publicFromAmount, + shieldAccountInfo1.getString("payment_address"), + getRcm(httpnode)); + response = + createShieldContractParameters( + httpnode, publicFromAmount, shieldAccountInfo1, shieldedReceives); responseContent = HttpMethod.parseResponseContent(response); - //HttpMethod.printJsonContent(responseContent); - - txid = HttpMethod.triggerContractGetTxidWithVisibleTrue(httpnode,anotherHttpnode, - zenTrc20TokenOwnerAddressString, shieldAddress, mint, responseContent - .getString("trigger_contract_input"), maxFeeLimit, 0L, 0, 0L, - zenTrc20TokenOwnerKey); + // HttpMethod.printJsonContent(responseContent); + + txid = + HttpMethod.triggerContractGetTxidWithVisibleTrue( + httpnode, + anotherHttpnode, + zenTrc20TokenOwnerAddressString, + shieldAddress, + mint, + responseContent.getString("trigger_contract_input"), + maxFeeLimit, + 0L, + 0, + 0L, + zenTrc20TokenOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); } - - @Test(enabled = true, description = "Transfer type with 1V1 without ask by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Transfer type with 1V1 without ask by http", + groups = {"daily", "serial"}) public void test01TransferTypeWith1V1WithoutAskByHttp() { account1IvkNoteTxs = scanShieldTrc20NoteByIvk(httpnode, shieldAccountInfo1); shieldSpends.clear(); - shieldSpends = createAndSetShieldedSpends(httpnode, shieldSpends, account1IvkNoteTxs - .getJSONObject(0)); + shieldSpends = + createAndSetShieldedSpends(httpnode, shieldSpends, account1IvkNoteTxs.getJSONObject(0)); HttpMethod.waitToProduceOneBlock(httpnode); shieldedReceives.clear(); - shieldedReceives = getHttpShieldedReceivesJsonArray(shieldedReceives, publicFromAmount, - shieldAccountInfo2.getString("payment_address"), getRcm(httpnode)); - response = createShieldContractParametersWithoutAskForTransfer(httpnode, shieldAccountInfo1, - shieldSpends, shieldedReceives); + shieldedReceives = + getHttpShieldedReceivesJsonArray( + shieldedReceives, + publicFromAmount, + shieldAccountInfo2.getString("payment_address"), + getRcm(httpnode)); + response = + createShieldContractParametersWithoutAskForTransfer( + httpnode, shieldAccountInfo1, shieldSpends, shieldedReceives); JSONObject shieldedTrc20Parameters = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(shieldedTrc20Parameters); - JSONObject spendAuthSig = createSpendAuthSig(httpnode, shieldAccountInfo1, - shieldedTrc20Parameters.getString("message_hash"), account1IvkNoteTxs - .getJSONObject(0).getJSONObject("note").getString("rcm")); + JSONObject spendAuthSig = + createSpendAuthSig( + httpnode, + shieldAccountInfo1, + shieldedTrc20Parameters.getString("message_hash"), + account1IvkNoteTxs.getJSONObject(0).getJSONObject("note").getString("rcm")); HttpMethod.printJsonContent(spendAuthSig); JSONArray spendAuthSigArray = new JSONArray(); spendAuthSigArray.add(spendAuthSig); - response = getTriggerInputForShieldedTrc20Contract(httpnode, shieldedTrc20Parameters, - spendAuthSigArray); + response = + getTriggerInputForShieldedTrc20Contract( + httpnode, shieldedTrc20Parameters, spendAuthSigArray); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - txid = HttpMethod.triggerContractGetTxidWithVisibleTrue(httpnode,anotherHttpnode, - zenTrc20TokenOwnerAddressString, shieldAddress, transfer, responseContent - .getString("value"), maxFeeLimit, 0L, 0, 0L, - zenTrc20TokenOwnerKey); + txid = + HttpMethod.triggerContractGetTxidWithVisibleTrue( + httpnode, + anotherHttpnode, + zenTrc20TokenOwnerAddressString, + shieldAddress, + transfer, + responseContent.getString("value"), + maxFeeLimit, + 0L, + 0, + 0L, + zenTrc20TokenOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getTransactionInfoById(httpnode, txid, true); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - Assert.assertTrue(responseContent.getJSONObject("receipt") - .getLong("energy_usage_total") > 300000L); + Assert.assertTrue( + responseContent.getJSONObject("receipt").getLong("energy_usage_total") > 300000L); Assert.assertEquals(responseContent.getString("contract_address"), shieldAddress); Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), "SUCCESS"); @@ -134,113 +180,168 @@ public void test01TransferTypeWith1V1WithoutAskByHttp() { Assert.assertEquals(account1OvkNoteTxs.size(), 1); } - @Test(enabled = true, description = "Transfer type with 1V2 without ask by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Transfer type with 1V2 without ask by http", + groups = {"daily", "serial"}) public void test02TransferTypeWith1V2WithoutAskByHttp() { account1IvkNoteTxs = scanShieldTrc20NoteByIvk(httpnode, shieldAccountInfo1); - Assert.assertTrue(isShieldedTrc20ContractNoteSpent(httpnode, shieldAccountInfo1, - account1IvkNoteTxs.getJSONObject(0))); - Assert.assertFalse(isShieldedTrc20ContractNoteSpent(httpnode, shieldAccountInfo1, - account1IvkNoteTxs.getJSONObject(1))); + Assert.assertTrue( + isShieldedTrc20ContractNoteSpent( + httpnode, shieldAccountInfo1, account1IvkNoteTxs.getJSONObject(0))); + Assert.assertFalse( + isShieldedTrc20ContractNoteSpent( + httpnode, shieldAccountInfo1, account1IvkNoteTxs.getJSONObject(1))); shieldSpends.clear(); - shieldSpends = createAndSetShieldedSpends(httpnode, shieldSpends, account1IvkNoteTxs - .getJSONObject(1)); + shieldSpends = + createAndSetShieldedSpends(httpnode, shieldSpends, account1IvkNoteTxs.getJSONObject(1)); shieldedReceives.clear(); - shieldedReceives = getHttpShieldedReceivesJsonArray(shieldedReceives, account1Receive1V2Amount, - shieldAccountInfo1.getString("payment_address"), getRcm(httpnode)); - shieldedReceives = getHttpShieldedReceivesJsonArray(shieldedReceives, account2Receive1V2Amount, - shieldAccountInfo2.getString("payment_address"), getRcm(httpnode)); - response = createShieldContractParametersWithoutAskForTransfer(httpnode, shieldAccountInfo1, - shieldSpends, shieldedReceives); + shieldedReceives = + getHttpShieldedReceivesJsonArray( + shieldedReceives, + account1Receive1V2Amount, + shieldAccountInfo1.getString("payment_address"), + getRcm(httpnode)); + shieldedReceives = + getHttpShieldedReceivesJsonArray( + shieldedReceives, + account2Receive1V2Amount, + shieldAccountInfo2.getString("payment_address"), + getRcm(httpnode)); + response = + createShieldContractParametersWithoutAskForTransfer( + httpnode, shieldAccountInfo1, shieldSpends, shieldedReceives); JSONObject shieldedTrc20Parameters = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(shieldedTrc20Parameters); - JSONObject spendAuthSig1 = createSpendAuthSig(httpnode, shieldAccountInfo1, - shieldedTrc20Parameters.getString("message_hash"), account1IvkNoteTxs.getJSONObject(1) - .getJSONObject("note").getString("rcm")); + JSONObject spendAuthSig1 = + createSpendAuthSig( + httpnode, + shieldAccountInfo1, + shieldedTrc20Parameters.getString("message_hash"), + account1IvkNoteTxs.getJSONObject(1).getJSONObject("note").getString("rcm")); HttpMethod.printJsonContent(spendAuthSig1); JSONArray spendAuthSigArray = new JSONArray(); spendAuthSigArray.add(spendAuthSig1); - //spendAuthSigArray.add(spendAuthSig2); + // spendAuthSigArray.add(spendAuthSig2); - response = getTriggerInputForShieldedTrc20Contract(httpnode, shieldedTrc20Parameters, - spendAuthSigArray); + response = + getTriggerInputForShieldedTrc20Contract( + httpnode, shieldedTrc20Parameters, spendAuthSigArray); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - txid = HttpMethod.triggerContractGetTxidWithVisibleTrue(httpnode,anotherHttpnode, - zenTrc20TokenOwnerAddressString, shieldAddress, transfer, responseContent - .getString("value"), maxFeeLimit, 0L, 0, 0L, - zenTrc20TokenOwnerKey); + txid = + HttpMethod.triggerContractGetTxidWithVisibleTrue( + httpnode, + anotherHttpnode, + zenTrc20TokenOwnerAddressString, + shieldAddress, + transfer, + responseContent.getString("value"), + maxFeeLimit, + 0L, + 0, + 0L, + zenTrc20TokenOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getTransactionInfoById(httpnode, txid, true); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - Assert.assertTrue(responseContent.getJSONObject("receipt") - .getLong("energy_usage_total") > 300000L); + Assert.assertTrue( + responseContent.getJSONObject("receipt").getLong("energy_usage_total") > 300000L); Assert.assertEquals(responseContent.getString("contract_address"), shieldAddress); - Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), - "SUCCESS"); + Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), "SUCCESS"); account1OvkNoteTxs = scanShieldTrc20NoteByOvk(httpnode, shieldAccountInfo1); logger.info(account1OvkNoteTxs.toJSONString()); Assert.assertEquals(account1OvkNoteTxs.size(), 3); } - - @Test(enabled = true, description = "Transfer type with 2V2 without ask by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Transfer type with 2V2 without ask by http", + groups = {"daily", "serial"}) public void test03TransferTypeWith2V2WithoutAskByHttp() { account2IvkNoteTxs = scanShieldTrc20NoteByIvk(httpnode, shieldAccountInfo2); - Assert.assertFalse(isShieldedTrc20ContractNoteSpent(httpnode, shieldAccountInfo2, - account2IvkNoteTxs.getJSONObject(0))); - Assert.assertFalse(isShieldedTrc20ContractNoteSpent(httpnode, shieldAccountInfo2, - account2IvkNoteTxs.getJSONObject(1))); + Assert.assertFalse( + isShieldedTrc20ContractNoteSpent( + httpnode, shieldAccountInfo2, account2IvkNoteTxs.getJSONObject(0))); + Assert.assertFalse( + isShieldedTrc20ContractNoteSpent( + httpnode, shieldAccountInfo2, account2IvkNoteTxs.getJSONObject(1))); shieldSpends.clear(); - shieldSpends = createAndSetShieldedSpends(httpnode, shieldSpends, account2IvkNoteTxs - .getJSONObject(0)); - shieldSpends = createAndSetShieldedSpends(httpnode, shieldSpends, account2IvkNoteTxs - .getJSONObject(1)); + shieldSpends = + createAndSetShieldedSpends(httpnode, shieldSpends, account2IvkNoteTxs.getJSONObject(0)); + shieldSpends = + createAndSetShieldedSpends(httpnode, shieldSpends, account2IvkNoteTxs.getJSONObject(1)); shieldedReceives.clear(); - shieldedReceives = getHttpShieldedReceivesJsonArray(shieldedReceives, account1Receive2V2Amount, - shieldAccountInfo1.getString("payment_address"), getRcm(httpnode)); - shieldedReceives = getHttpShieldedReceivesJsonArray(shieldedReceives, account2Receive2V2Amount, - shieldAccountInfo2.getString("payment_address"), getRcm(httpnode)); - response = createShieldContractParametersWithoutAskForTransfer(httpnode, shieldAccountInfo2, - shieldSpends, shieldedReceives); + shieldedReceives = + getHttpShieldedReceivesJsonArray( + shieldedReceives, + account1Receive2V2Amount, + shieldAccountInfo1.getString("payment_address"), + getRcm(httpnode)); + shieldedReceives = + getHttpShieldedReceivesJsonArray( + shieldedReceives, + account2Receive2V2Amount, + shieldAccountInfo2.getString("payment_address"), + getRcm(httpnode)); + response = + createShieldContractParametersWithoutAskForTransfer( + httpnode, shieldAccountInfo2, shieldSpends, shieldedReceives); JSONObject shieldedTrc20Parameters = HttpMethod.parseResponseContent(response); - JSONObject spendAuthSig1 = createSpendAuthSig(httpnode, shieldAccountInfo2, - shieldedTrc20Parameters.getString("message_hash"), account2IvkNoteTxs.getJSONObject(0) - .getJSONObject("note").getString("rcm")); + JSONObject spendAuthSig1 = + createSpendAuthSig( + httpnode, + shieldAccountInfo2, + shieldedTrc20Parameters.getString("message_hash"), + account2IvkNoteTxs.getJSONObject(0).getJSONObject("note").getString("rcm")); HttpMethod.printJsonContent(spendAuthSig1); - JSONObject spendAuthSig2 = createSpendAuthSig(httpnode, shieldAccountInfo2, - shieldedTrc20Parameters.getString("message_hash"), account2IvkNoteTxs.getJSONObject(1) - .getJSONObject("note").getString("rcm")); + JSONObject spendAuthSig2 = + createSpendAuthSig( + httpnode, + shieldAccountInfo2, + shieldedTrc20Parameters.getString("message_hash"), + account2IvkNoteTxs.getJSONObject(1).getJSONObject("note").getString("rcm")); JSONArray spendAuthSigArray = new JSONArray(); spendAuthSigArray.add(spendAuthSig1); spendAuthSigArray.add(spendAuthSig2); - response = getTriggerInputForShieldedTrc20Contract(httpnode, shieldedTrc20Parameters, - spendAuthSigArray); + response = + getTriggerInputForShieldedTrc20Contract( + httpnode, shieldedTrc20Parameters, spendAuthSigArray); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - txid = HttpMethod.triggerContractGetTxidWithVisibleTrue(httpnode,anotherHttpnode, - zenTrc20TokenOwnerAddressString, shieldAddress, transfer, responseContent - .getString("value"), maxFeeLimit, 0L, 0, 0L, - zenTrc20TokenOwnerKey); + txid = + HttpMethod.triggerContractGetTxidWithVisibleTrue( + httpnode, + anotherHttpnode, + zenTrc20TokenOwnerAddressString, + shieldAddress, + transfer, + responseContent.getString("value"), + maxFeeLimit, + 0L, + 0, + 0L, + zenTrc20TokenOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getTransactionInfoById(httpnode, txid, true); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - Assert.assertTrue(responseContent.getJSONObject("receipt") - .getLong("energy_usage_total") > 300000L); + Assert.assertTrue( + responseContent.getJSONObject("receipt").getLong("energy_usage_total") > 300000L); Assert.assertEquals(responseContent.getString("contract_address"), shieldAddress); Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), "SUCCESS"); @@ -248,66 +349,93 @@ public void test03TransferTypeWith2V2WithoutAskByHttp() { logger.info(account1OvkNoteTxs.toJSONString()); Assert.assertEquals(account2OvkNoteTxs.size(), 2); - Assert.assertTrue(isShieldedTrc20ContractNoteSpent(httpnode, shieldAccountInfo2, - account2IvkNoteTxs.getJSONObject(0))); - Assert.assertTrue(isShieldedTrc20ContractNoteSpent(httpnode, shieldAccountInfo2, - account2IvkNoteTxs.getJSONObject(1))); - + Assert.assertTrue( + isShieldedTrc20ContractNoteSpent( + httpnode, shieldAccountInfo2, account2IvkNoteTxs.getJSONObject(0))); + Assert.assertTrue( + isShieldedTrc20ContractNoteSpent( + httpnode, shieldAccountInfo2, account2IvkNoteTxs.getJSONObject(1))); } - @Test(enabled = true, description = "Transfer type with 2V1 without ask by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Transfer type with 2V1 without ask by http", + groups = {"daily", "serial"}) public void test04TransferTypeWith2V1WithoutAskByHttp() { account1IvkNoteTxs = scanShieldTrc20NoteByIvk(httpnode, shieldAccountInfo1); - Assert.assertFalse(isShieldedTrc20ContractNoteSpent(httpnode, shieldAccountInfo1, - account1IvkNoteTxs.getJSONObject(2))); - Assert.assertFalse(isShieldedTrc20ContractNoteSpent(httpnode, shieldAccountInfo1, - account1IvkNoteTxs.getJSONObject(3))); + Assert.assertFalse( + isShieldedTrc20ContractNoteSpent( + httpnode, shieldAccountInfo1, account1IvkNoteTxs.getJSONObject(2))); + Assert.assertFalse( + isShieldedTrc20ContractNoteSpent( + httpnode, shieldAccountInfo1, account1IvkNoteTxs.getJSONObject(3))); shieldSpends.clear(); - shieldSpends = createAndSetShieldedSpends(httpnode, shieldSpends, account1IvkNoteTxs - .getJSONObject(2)); - shieldSpends = createAndSetShieldedSpends(httpnode, shieldSpends, account1IvkNoteTxs - .getJSONObject(3)); - Long account1Receive2V1Amount = account1IvkNoteTxs.getJSONObject(2) - .getJSONObject("note").getLong("value") - + account1IvkNoteTxs.getJSONObject(3).getJSONObject("note").getLong("value"); + shieldSpends = + createAndSetShieldedSpends(httpnode, shieldSpends, account1IvkNoteTxs.getJSONObject(2)); + shieldSpends = + createAndSetShieldedSpends(httpnode, shieldSpends, account1IvkNoteTxs.getJSONObject(3)); + Long account1Receive2V1Amount = + account1IvkNoteTxs.getJSONObject(2).getJSONObject("note").getLong("value") + + account1IvkNoteTxs.getJSONObject(3).getJSONObject("note").getLong("value"); shieldedReceives.clear(); - shieldedReceives = getHttpShieldedReceivesJsonArray(shieldedReceives, account1Receive2V1Amount, - shieldAccountInfo1.getString("payment_address"), getRcm(httpnode)); - response = createShieldContractParametersWithoutAskForTransfer(httpnode, shieldAccountInfo1, - shieldSpends, shieldedReceives); + shieldedReceives = + getHttpShieldedReceivesJsonArray( + shieldedReceives, + account1Receive2V1Amount, + shieldAccountInfo1.getString("payment_address"), + getRcm(httpnode)); + response = + createShieldContractParametersWithoutAskForTransfer( + httpnode, shieldAccountInfo1, shieldSpends, shieldedReceives); JSONObject shieldedTrc20Parameters = HttpMethod.parseResponseContent(response); - JSONObject spendAuthSig1 = createSpendAuthSig(httpnode, shieldAccountInfo1, - shieldedTrc20Parameters.getString("message_hash"), account1IvkNoteTxs.getJSONObject(2) - .getJSONObject("note").getString("rcm")); + JSONObject spendAuthSig1 = + createSpendAuthSig( + httpnode, + shieldAccountInfo1, + shieldedTrc20Parameters.getString("message_hash"), + account1IvkNoteTxs.getJSONObject(2).getJSONObject("note").getString("rcm")); HttpMethod.printJsonContent(spendAuthSig1); - JSONObject spendAuthSig2 = createSpendAuthSig(httpnode, shieldAccountInfo1, - shieldedTrc20Parameters.getString("message_hash"), account1IvkNoteTxs.getJSONObject(3) - .getJSONObject("note").getString("rcm")); + JSONObject spendAuthSig2 = + createSpendAuthSig( + httpnode, + shieldAccountInfo1, + shieldedTrc20Parameters.getString("message_hash"), + account1IvkNoteTxs.getJSONObject(3).getJSONObject("note").getString("rcm")); HttpMethod.printJsonContent(spendAuthSig2); JSONArray spendAuthSigArray = new JSONArray(); spendAuthSigArray.add(spendAuthSig1); spendAuthSigArray.add(spendAuthSig2); - response = getTriggerInputForShieldedTrc20Contract(httpnode, shieldedTrc20Parameters, - spendAuthSigArray); + response = + getTriggerInputForShieldedTrc20Contract( + httpnode, shieldedTrc20Parameters, spendAuthSigArray); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - txid = HttpMethod.triggerContractGetTxidWithVisibleTrue(httpnode,anotherHttpnode, - zenTrc20TokenOwnerAddressString, shieldAddress, transfer, responseContent - .getString("value"), maxFeeLimit, 0L, 0, 0L, - zenTrc20TokenOwnerKey); + txid = + HttpMethod.triggerContractGetTxidWithVisibleTrue( + httpnode, + anotherHttpnode, + zenTrc20TokenOwnerAddressString, + shieldAddress, + transfer, + responseContent.getString("value"), + maxFeeLimit, + 0L, + 0, + 0L, + zenTrc20TokenOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getTransactionInfoById(httpnode, txid, true); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - Assert.assertTrue(responseContent.getJSONObject("receipt") - .getLong("energy_usage_total") > 300000L); + Assert.assertTrue( + responseContent.getJSONObject("receipt").getLong("energy_usage_total") > 300000L); Assert.assertEquals(responseContent.getString("contract_address"), shieldAddress); Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), "SUCCESS"); @@ -316,61 +444,61 @@ public void test04TransferTypeWith2V1WithoutAskByHttp() { Assert.assertEquals(account1OvkNoteTxs.size(), 4); account1IvkNoteTxs = scanShieldTrc20NoteByIvk(httpnode, shieldAccountInfo1); - Assert.assertTrue(isShieldedTrc20ContractNoteSpent(httpnode, shieldAccountInfo1, - account1IvkNoteTxs.getJSONObject(2))); - Assert.assertTrue(isShieldedTrc20ContractNoteSpentOnPbft(httpPbftNode, shieldAccountInfo1, - account1IvkNoteTxs.getJSONObject(2))); - Assert.assertTrue(isShieldedTrc20ContractNoteSpent(httpnode, shieldAccountInfo1, - account1IvkNoteTxs.getJSONObject(3))); - Assert.assertTrue(isShieldedTrc20ContractNoteSpentOnPbft(httpPbftNode, shieldAccountInfo1, - account1IvkNoteTxs.getJSONObject(3))); - + Assert.assertTrue( + isShieldedTrc20ContractNoteSpent( + httpnode, shieldAccountInfo1, account1IvkNoteTxs.getJSONObject(2))); + Assert.assertTrue( + isShieldedTrc20ContractNoteSpentOnPbft( + httpPbftNode, shieldAccountInfo1, account1IvkNoteTxs.getJSONObject(2))); + Assert.assertTrue( + isShieldedTrc20ContractNoteSpent( + httpnode, shieldAccountInfo1, account1IvkNoteTxs.getJSONObject(3))); + Assert.assertTrue( + isShieldedTrc20ContractNoteSpentOnPbft( + httpPbftNode, shieldAccountInfo1, account1IvkNoteTxs.getJSONObject(3))); } - - @Test(enabled = true, description = "Scan note by ivk and ovk on solidity and pbft by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Scan note by ivk and ovk on solidity and pbft by http", + groups = {"daily", "serial"}) public void test05ScanNoteByIvkAndOvkOnSOlidityAndPbftByHttp() { HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSolidityNode); account1IvkNoteTxs = scanShieldTrc20NoteByIvk(httpnode, shieldAccountInfo1); - JSONArray account1IvkNoteTxsOnSolidity = scanShieldTrc20NoteByIvkOnSolidity(httpSolidityNode, - shieldAccountInfo1); + JSONArray account1IvkNoteTxsOnSolidity = + scanShieldTrc20NoteByIvkOnSolidity(httpSolidityNode, shieldAccountInfo1); Assert.assertEquals(account1IvkNoteTxs, account1IvkNoteTxsOnSolidity); - JSONArray account1IvkNoteTxsOnPbft = scanShieldTrc20NoteByIvkOnPbft(httpPbftNode, - shieldAccountInfo1); + JSONArray account1IvkNoteTxsOnPbft = + scanShieldTrc20NoteByIvkOnPbft(httpPbftNode, shieldAccountInfo1); Assert.assertEquals(account1IvkNoteTxs, account1IvkNoteTxsOnPbft); account1OvkNoteTxs = scanShieldTrc20NoteByOvk(httpnode, shieldAccountInfo1); - JSONArray account1OvkNoteTxsOnSolidity = scanShieldTrc20NoteByOvkOnSolidity(httpSolidityNode, - shieldAccountInfo1); + JSONArray account1OvkNoteTxsOnSolidity = + scanShieldTrc20NoteByOvkOnSolidity(httpSolidityNode, shieldAccountInfo1); Assert.assertEquals(account1OvkNoteTxs, account1OvkNoteTxsOnSolidity); - JSONArray account1OvkNoteTxsOnPbft = scanShieldTrc20NoteByOvkOnPbft(httpPbftNode, - shieldAccountInfo1); + JSONArray account1OvkNoteTxsOnPbft = + scanShieldTrc20NoteByOvkOnPbft(httpPbftNode, shieldAccountInfo1); Assert.assertEquals(account1OvkNoteTxs, account1OvkNoteTxsOnPbft); account2IvkNoteTxs = scanShieldTrc20NoteByIvk(httpnode, shieldAccountInfo2); - JSONArray account2IvkNoteTxsOnSolidity = scanShieldTrc20NoteByIvkOnSolidity(httpSolidityNode, - shieldAccountInfo2); + JSONArray account2IvkNoteTxsOnSolidity = + scanShieldTrc20NoteByIvkOnSolidity(httpSolidityNode, shieldAccountInfo2); Assert.assertEquals(account2IvkNoteTxs, account2IvkNoteTxsOnSolidity); - JSONArray account2IvkNoteTxsOnPbft = scanShieldTrc20NoteByIvkOnPbft(httpPbftNode, - shieldAccountInfo2); + JSONArray account2IvkNoteTxsOnPbft = + scanShieldTrc20NoteByIvkOnPbft(httpPbftNode, shieldAccountInfo2); Assert.assertEquals(account2IvkNoteTxs, account2IvkNoteTxsOnPbft); account2OvkNoteTxs = scanShieldTrc20NoteByOvk(httpnode, shieldAccountInfo2); - JSONArray account2OvkNoteTxsOnSolidity = scanShieldTrc20NoteByOvkOnSolidity(httpSolidityNode, - shieldAccountInfo2); + JSONArray account2OvkNoteTxsOnSolidity = + scanShieldTrc20NoteByOvkOnSolidity(httpSolidityNode, shieldAccountInfo2); Assert.assertEquals(account2OvkNoteTxs, account2OvkNoteTxsOnSolidity); - JSONArray account2OvkNoteTxsOnPbft = scanShieldTrc20NoteByOvkOnPbft(httpPbftNode, - shieldAccountInfo2); + JSONArray account2OvkNoteTxsOnPbft = + scanShieldTrc20NoteByOvkOnPbft(httpPbftNode, shieldAccountInfo2); Assert.assertEquals(account2OvkNoteTxs, account2OvkNoteTxsOnPbft); - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { - } -} \ No newline at end of file + public void shutdown() throws InterruptedException {} +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpShieldTrc20Token005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpShieldTrc20Token005.java index 389b36b6..4d28218a 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpShieldTrc20Token005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpShieldTrc20Token005.java @@ -17,12 +17,12 @@ public class HttpShieldTrc20Token005 extends ZenTrc20Base { JSONArray shieldedReceives = new JSONArray(); String txid; - private String httpnode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(0); - private String anotherHttpnode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(1); - private String httpSolidityNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); + private String anotherHttpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(1); + private String httpSolidityNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); private JSONObject responseContent; private HttpResponse response; private JSONObject shieldAccountInfo; @@ -30,46 +30,71 @@ public class HttpShieldTrc20Token005 extends ZenTrc20Base { private JSONArray noteTxs; private Long publicFromAmount = getRandomLongAmount(); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true, description = "Get new shield account by http") public void createTwoNote() { response = getNewShieldedAddress(httpnode); shieldAccountInfo = HttpMethod.parseResponseContent(response); - shieldedReceives = getHttpShieldedReceivesJsonArray(shieldedReceives, publicFromAmount, - shieldAccountInfo.getString("payment_address"), getRcm((httpnode))); - response = createShieldContractParameters(httpnode, publicFromAmount, shieldAccountInfo, - shieldedReceives); + shieldedReceives = + getHttpShieldedReceivesJsonArray( + shieldedReceives, + publicFromAmount, + shieldAccountInfo.getString("payment_address"), + getRcm((httpnode))); + response = + createShieldContractParameters( + httpnode, publicFromAmount, shieldAccountInfo, shieldedReceives); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - txid = HttpMethod.triggerContractGetTxidWithVisibleTrue(httpnode,anotherHttpnode, - zenTrc20TokenOwnerAddressString, shieldAddress, mint, responseContent - .getString("trigger_contract_input"), maxFeeLimit, 0L, 0, 0L, - zenTrc20TokenOwnerKey); + txid = + HttpMethod.triggerContractGetTxidWithVisibleTrue( + httpnode, + anotherHttpnode, + zenTrc20TokenOwnerAddressString, + shieldAddress, + mint, + responseContent.getString("trigger_contract_input"), + maxFeeLimit, + 0L, + 0, + 0L, + zenTrc20TokenOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getTransactionInfoById(httpnode, txid, true); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); shieldedReceives.clear(); - shieldedReceives = getHttpShieldedReceivesJsonArray(shieldedReceives, publicFromAmount, - shieldAccountInfo.getString("payment_address"), getRcm(httpnode)); - response = createShieldContractParameters(httpnode, publicFromAmount, shieldAccountInfo, - shieldedReceives); + shieldedReceives = + getHttpShieldedReceivesJsonArray( + shieldedReceives, + publicFromAmount, + shieldAccountInfo.getString("payment_address"), + getRcm(httpnode)); + response = + createShieldContractParameters( + httpnode, publicFromAmount, shieldAccountInfo, shieldedReceives); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - txid = HttpMethod.triggerContractGetTxidWithVisibleTrue(httpnode,anotherHttpnode, - zenTrc20TokenOwnerAddressString, shieldAddress, mint, responseContent - .getString("trigger_contract_input"), maxFeeLimit, 0L, 0, 0L, - zenTrc20TokenOwnerKey); + txid = + HttpMethod.triggerContractGetTxidWithVisibleTrue( + httpnode, + anotherHttpnode, + zenTrc20TokenOwnerAddressString, + shieldAddress, + mint, + responseContent.getString("trigger_contract_input"), + maxFeeLimit, + 0L, + 0, + 0L, + zenTrc20TokenOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getTransactionInfoById(httpnode, txid, true); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); @@ -77,7 +102,10 @@ public void createTwoNote() { noteTxs = scanShieldTrc20NoteByIvk(httpnode, shieldAccountInfo); } - @Test(enabled = true, description = "Shield trc20 burn to one T and one S by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Shield trc20 burn to one T and one S by http", + groups = {"daily", "serial"}) public void test01ShiledTrc20BurnToOnePublicAndOneShieldByHttp() { response = getNewShieldedAddress(httpnode); shieldReceiverAccountInfo = HttpMethod.parseResponseContent(response); @@ -90,47 +118,68 @@ public void test01ShiledTrc20BurnToOnePublicAndOneShieldByHttp() { Long toShieldAmount = 9L; Long toPublicAmount = publicFromAmount - toShieldAmount; shieldedReceives.clear(); - shieldedReceives = getHttpShieldedReceivesJsonArray(shieldedReceives, toShieldAmount, - shieldReceiverAccountInfo.getString("payment_address"), getRcm(httpnode)); - - response = createShieldContractParametersForBurn(httpnode, shieldAccountInfo, shieldSpends, - zenTrc20TokenOwnerAddressString, toPublicAmount, shieldedReceives); + shieldedReceives = + getHttpShieldedReceivesJsonArray( + shieldedReceives, + toShieldAmount, + shieldReceiverAccountInfo.getString("payment_address"), + getRcm(httpnode)); + + response = + createShieldContractParametersForBurn( + httpnode, + shieldAccountInfo, + shieldSpends, + zenTrc20TokenOwnerAddressString, + toPublicAmount, + shieldedReceives); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - txid = HttpMethod.triggerContractGetTxidWithVisibleTrue(httpnode,anotherHttpnode, - zenTrc20TokenOwnerAddressString, shieldAddress, burn, responseContent - .getString("trigger_contract_input"), maxFeeLimit, 0L, 0, 0L, - zenTrc20TokenOwnerKey); + txid = + HttpMethod.triggerContractGetTxidWithVisibleTrue( + httpnode, + anotherHttpnode, + zenTrc20TokenOwnerAddressString, + shieldAddress, + burn, + responseContent.getString("trigger_contract_input"), + maxFeeLimit, + 0L, + 0, + 0L, + zenTrc20TokenOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getTransactionInfoById(httpnode, txid, true); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - Assert.assertTrue(responseContent.getJSONObject("receipt") - .getLong("energy_usage_total") > 150000L); + Assert.assertTrue( + responseContent.getJSONObject("receipt").getLong("energy_usage_total") > 150000L); Assert.assertEquals(responseContent.getString("contract_address"), shieldAddress); - Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), - "SUCCESS"); + Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), "SUCCESS"); noteTxs = scanShieldTrc20NoteByOvk(httpnode, shieldAccountInfo); logger.info("noteTxs ovk:" + noteTxs); - Assert.assertEquals(noteTxs.getJSONObject(0).getJSONObject("note") - .getLong("value"), toShieldAmount); - Assert.assertEquals(noteTxs.getJSONObject(0).getJSONObject("note") - .getString("payment_address"), shieldReceiverAccountInfo.getString("payment_address")); + Assert.assertEquals( + noteTxs.getJSONObject(0).getJSONObject("note").getLong("value"), toShieldAmount); + Assert.assertEquals( + noteTxs.getJSONObject(0).getJSONObject("note").getString("payment_address"), + shieldReceiverAccountInfo.getString("payment_address")); Assert.assertEquals(noteTxs.getJSONObject(1).getLong("to_amount"), toPublicAmount); - Assert.assertEquals(noteTxs.getJSONObject(1).getString("transparent_to_address"), + Assert.assertEquals( + noteTxs.getJSONObject(1).getString("transparent_to_address"), zenTrc20TokenOwnerAddressString); Assert.assertEquals(noteTxs.getJSONObject(1).getString("txid"), txid); } - - @Test(enabled = true, description = "Shield trc20 burn without ask to one " - + "public and one shield by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Shield trc20 burn without ask to one " + "public and one shield by http", + groups = {"daily", "serial"}) public void test02ShiledTrc20BurnWithoutAskToOnePublicAndOneShieldByHttp() { noteTxs = scanShieldTrc20NoteByIvk(httpnode, shieldAccountInfo); JSONArray shieldSpends = new JSONArray(); @@ -139,59 +188,84 @@ public void test02ShiledTrc20BurnWithoutAskToOnePublicAndOneShieldByHttp() { Long toShieldAmount = 8L; Long toPublicAmount = publicFromAmount - toShieldAmount; shieldedReceives.clear(); - shieldedReceives = getHttpShieldedReceivesJsonArray(shieldedReceives, toShieldAmount, - shieldReceiverAccountInfo.getString("payment_address"), getRcm(httpnode)); - - response = createShieldContractParametersWithoutAskForBurn(httpnode, shieldAccountInfo, - shieldSpends, zenTrc20TokenOwnerAddressString, toPublicAmount, shieldedReceives); + shieldedReceives = + getHttpShieldedReceivesJsonArray( + shieldedReceives, + toShieldAmount, + shieldReceiverAccountInfo.getString("payment_address"), + getRcm(httpnode)); + + response = + createShieldContractParametersWithoutAskForBurn( + httpnode, + shieldAccountInfo, + shieldSpends, + zenTrc20TokenOwnerAddressString, + toPublicAmount, + shieldedReceives); JSONObject shieldedTrc20Parameters = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(shieldedTrc20Parameters); - JSONObject spendAuthSig = createSpendAuthSig(httpnode, shieldAccountInfo, - shieldedTrc20Parameters.getString("message_hash"), noteTxs.getJSONObject(1) - .getJSONObject("note").getString("rcm")); + JSONObject spendAuthSig = + createSpendAuthSig( + httpnode, + shieldAccountInfo, + shieldedTrc20Parameters.getString("message_hash"), + noteTxs.getJSONObject(1).getJSONObject("note").getString("rcm")); HttpMethod.printJsonContent(spendAuthSig); JSONArray spendAuthSigArray = new JSONArray(); spendAuthSigArray.add(spendAuthSig); - response = getTriggerInputForShieldedTrc20BurnContract(httpnode, - shieldedTrc20Parameters, spendAuthSigArray, toPublicAmount, - zenTrc20TokenOwnerAddressString); + response = + getTriggerInputForShieldedTrc20BurnContract( + httpnode, + shieldedTrc20Parameters, + spendAuthSigArray, + toPublicAmount, + zenTrc20TokenOwnerAddressString); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - txid = HttpMethod.triggerContractGetTxidWithVisibleTrue(httpnode,anotherHttpnode, - zenTrc20TokenOwnerAddressString, shieldAddress, burn, responseContent - .getString("value"), maxFeeLimit, 0L, 0, 0L, - zenTrc20TokenOwnerKey); + txid = + HttpMethod.triggerContractGetTxidWithVisibleTrue( + httpnode, + anotherHttpnode, + zenTrc20TokenOwnerAddressString, + shieldAddress, + burn, + responseContent.getString("value"), + maxFeeLimit, + 0L, + 0, + 0L, + zenTrc20TokenOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getTransactionInfoById(httpnode, txid, true); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - Assert.assertTrue(responseContent.getJSONObject("receipt") - .getLong("energy_usage_total") > 150000L); + Assert.assertTrue( + responseContent.getJSONObject("receipt").getLong("energy_usage_total") > 150000L); Assert.assertEquals(responseContent.getString("contract_address"), shieldAddress); Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), "SUCCESS"); noteTxs = scanShieldTrc20NoteByOvk(httpnode, shieldAccountInfo); logger.info("noteTxs ovk:" + noteTxs); - Assert.assertEquals(noteTxs.getJSONObject(2).getJSONObject("note") - .getLong("value"), toShieldAmount); - Assert.assertEquals(noteTxs.getJSONObject(2).getJSONObject("note") - .getString("payment_address"), shieldReceiverAccountInfo.getString("payment_address")); + Assert.assertEquals( + noteTxs.getJSONObject(2).getJSONObject("note").getLong("value"), toShieldAmount); + Assert.assertEquals( + noteTxs.getJSONObject(2).getJSONObject("note").getString("payment_address"), + shieldReceiverAccountInfo.getString("payment_address")); Assert.assertEquals(noteTxs.getJSONObject(3).getLong("to_amount"), toPublicAmount); - Assert.assertEquals(noteTxs.getJSONObject(3).getString("transparent_to_address"), + Assert.assertEquals( + noteTxs.getJSONObject(3).getString("transparent_to_address"), zenTrc20TokenOwnerAddressString); Assert.assertEquals(noteTxs.getJSONObject(3).getString("txid"), txid); - } - @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { - } -} \ No newline at end of file + public void shutdown() throws InterruptedException {} +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAccount001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAccount001.java index 65cef8d5..9bdd40fa 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAccount001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAccount001.java @@ -13,22 +13,23 @@ @Slf4j public class HttpTestAccount001 { - private final String testKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); + private final String testKey002 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key1"); private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); private JSONObject responseContent; private HttpResponse response; - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(0); - private String httpSoliditynode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); - private String httpPbftNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(4); + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); + private String httpSoliditynode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); + private String httpPbftNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(4); - /** - * constructor. - */ - @Test(enabled = true, description = "Get account by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get account by http", + groups = {"daily", "serial"}) public void getAccount() { response = HttpMethod.getAccount(httpnode, fromAddress); logger.info("code is " + response.getStatusLine().getStatusCode()); @@ -38,10 +39,11 @@ public void getAccount() { Assert.assertTrue(responseContent.size() > 3); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get account from solidity by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get account from solidity by http", + groups = {"daily", "serial"}) public void getAccountFromSolidity() { response = HttpMethod.getAccountFromSolidity(httpSoliditynode, fromAddress); logger.info("code is " + response.getStatusLine().getStatusCode()); @@ -51,10 +53,11 @@ public void getAccountFromSolidity() { Assert.assertTrue(responseContent.size() > 3); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get accountNet by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get accountNet by http", + groups = {"daily", "serial"}) public void getAccountNet() { response = HttpMethod.getAccountNet(httpnode, fromAddress); logger.info("code is " + response.getStatusLine().getStatusCode()); @@ -62,15 +65,16 @@ public void getAccountNet() { responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); Assert.assertEquals(Integer.parseInt(responseContent.get("freeNetLimit").toString()), 1500); - Assert.assertEquals(Long.parseLong(responseContent.get("TotalNetLimit").toString()), - 43200000000L); + Assert.assertEquals( + Long.parseLong(responseContent.get("TotalNetLimit").toString()), 43200000000L); Assert.assertTrue(responseContent.size() >= 2); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get accountResource by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get accountResource by http", + groups = {"daily", "serial"}) public void getAccountResource() { response = HttpMethod.getAccountReource(httpnode, fromAddress); logger.info("code is " + response.getStatusLine().getStatusCode()); @@ -82,12 +86,9 @@ public void getAccountResource() { Assert.assertTrue(responseContent.size() >= 3); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { HttpMethod.disConnect(); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAccount002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAccount002.java index 734518c9..fb5e2f76 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAccount002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAccount002.java @@ -19,8 +19,8 @@ @Slf4j public class HttpTestAccount002 { - private final String testKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); + private final String testKey002 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key1"); private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] freezeBalanceAddress = ecKey1.getAddress(); @@ -34,114 +34,138 @@ public class HttpTestAccount002 { Long frozenBalance = 2000000L; private JSONObject responseContent; private HttpResponse response; - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(1); - private String httpSoliditynode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); - private String httpPbftNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(4); - - /** - * constructor. - */ - @Test(enabled = true, description = "FreezeBalance for bandwidth by http", groups = {"daily", "serial"}) + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(1); + private String httpSoliditynode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); + private String httpPbftNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(4); + + /** constructor. */ + @Test( + enabled = true, + description = "FreezeBalance for bandwidth by http", + groups = {"daily", "serial"}) public void test001FreezeBalanceForBandwidth() { PublicMethod.printAddress(freezeBalanceKey); - //Send trx to test account + // Send trx to test account response = HttpMethod.sendCoin(httpnode, fromAddress, freezeBalanceAddress, amount, testKey002); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); berforeBalance = HttpMethod.getBalance(httpnode, freezeBalanceAddress); - //Freeze balance - response = HttpMethod - .freezeBalance(httpnode, freezeBalanceAddress, frozenBalance, 0, 0, freezeBalanceKey); + // Freeze balance + response = + HttpMethod.freezeBalance( + httpnode, freezeBalanceAddress, frozenBalance, 0, 0, freezeBalanceKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); afterBalance = HttpMethod.getBalance(httpnode, freezeBalanceAddress); Assert.assertTrue(berforeBalance - afterBalance == frozenBalance); } - /** - * constructor. - */ - @Test(enabled = true, description = "UnFreezeBalance for bandwidth by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "UnFreezeBalance for bandwidth by http", + groups = {"daily", "serial"}) public void test002UnFreezeBalanceForBandwidth() { berforeBalance = HttpMethod.getBalance(httpnode, freezeBalanceAddress); - //UnFreeze balance for bandwidth - if(HttpMethod.getProposalValue(httpnode,ProposalEnum.GetUnfreezeDelayDays.getProposalName()) > 0) { - response = HttpMethod.unFreezeBalanceV2(httpnode, freezeBalanceAddress, frozenBalance,0, freezeBalanceKey); + // UnFreeze balance for bandwidth + if (HttpMethod.getProposalValue(httpnode, ProposalEnum.GetUnfreezeDelayDays.getProposalName()) + > 0) { + response = + HttpMethod.unFreezeBalanceV2( + httpnode, freezeBalanceAddress, frozenBalance, 0, freezeBalanceKey); } else { - response = HttpMethod.unFreezeBalance(httpnode, freezeBalanceAddress, frozenBalance,0, freezeBalanceKey); + response = + HttpMethod.unFreezeBalance( + httpnode, freezeBalanceAddress, frozenBalance, 0, freezeBalanceKey); } Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); afterBalance = HttpMethod.getBalance(httpnode, freezeBalanceAddress); - if(HttpMethod.getProposalValue(httpnode,ProposalEnum.GetUnfreezeDelayDays.getProposalName()) > 0) { - Assert.assertEquals(afterBalance,berforeBalance); + if (HttpMethod.getProposalValue(httpnode, ProposalEnum.GetUnfreezeDelayDays.getProposalName()) + > 0) { + Assert.assertEquals(afterBalance, berforeBalance); } else { Assert.assertTrue(afterBalance - berforeBalance == frozenBalance); } - } - /** - * constructor. - */ - @Test(enabled = true, description = "FreezeBalance for energy by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "FreezeBalance for energy by http", + groups = {"daily", "serial"}) public void test003FreezeBalanceForEnergy() { berforeBalance = HttpMethod.getBalance(httpnode, freezeBalanceAddress); - //Freeze balance for energy - response = HttpMethod - .freezeBalance(httpnode, freezeBalanceAddress, frozenBalance, 0, 1, freezeBalanceKey); + // Freeze balance for energy + response = + HttpMethod.freezeBalance( + httpnode, freezeBalanceAddress, frozenBalance, 0, 1, freezeBalanceKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); afterBalance = HttpMethod.getBalance(httpnode, freezeBalanceAddress); Assert.assertTrue(berforeBalance - afterBalance == frozenBalance); } - /** - * constructor. - */ - @Test(enabled = true, description = "UnFreezeBalance for energy by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "UnFreezeBalance for energy by http", + groups = {"daily", "serial"}) public void test004UnFreezeBalanceForEnergy() { berforeBalance = HttpMethod.getBalance(httpnode, freezeBalanceAddress); HttpMethod.waitToProduceOneBlock(httpnode); - //UnFreeze balance for energy - if(HttpMethod.getProposalValue(httpnode,ProposalEnum.GetUnfreezeDelayDays.getProposalName()) > 0) { - response = HttpMethod.unFreezeBalanceV2(httpnode, freezeBalanceAddress, frozenBalance,1, freezeBalanceKey); + // UnFreeze balance for energy + if (HttpMethod.getProposalValue(httpnode, ProposalEnum.GetUnfreezeDelayDays.getProposalName()) + > 0) { + response = + HttpMethod.unFreezeBalanceV2( + httpnode, freezeBalanceAddress, frozenBalance, 1, freezeBalanceKey); } else { - response = HttpMethod.unFreezeBalance(httpnode, freezeBalanceAddress, frozenBalance,1, freezeBalanceKey); + response = + HttpMethod.unFreezeBalance( + httpnode, freezeBalanceAddress, frozenBalance, 1, freezeBalanceKey); } Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); afterBalance = HttpMethod.getBalance(httpnode, freezeBalanceAddress); - if(HttpMethod.getProposalValue(httpnode,ProposalEnum.GetUnfreezeDelayDays.getProposalName()) > 0) { - Assert.assertEquals(afterBalance,berforeBalance); + if (HttpMethod.getProposalValue(httpnode, ProposalEnum.GetUnfreezeDelayDays.getProposalName()) + > 0) { + Assert.assertEquals(afterBalance, berforeBalance); } else { Assert.assertTrue(afterBalance - berforeBalance == frozenBalance); } } - /** - * constructor. - */ - @Test(enabled = true, description = "FreezeBalance with bandwidth for others by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "FreezeBalance with bandwidth for others by http", + groups = {"daily", "serial"}) public void test005FreezeBalanceOfBandwidthForOthers() { - response = HttpMethod - .sendCoin(httpnode, fromAddress, receiverResourceAddress, amount, testKey002); + response = + HttpMethod.sendCoin(httpnode, fromAddress, receiverResourceAddress, amount, testKey002); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); berforeBalance = HttpMethod.getBalance(httpnode, freezeBalanceAddress); - //Freeze balance with bandwidth for others - response = HttpMethod - .freezeBalance(httpnode, freezeBalanceAddress, frozenBalance, 0, 0, receiverResourceAddress, + // Freeze balance with bandwidth for others + response = + HttpMethod.freezeBalance( + httpnode, + freezeBalanceAddress, + frozenBalance, + 0, + 0, + receiverResourceAddress, freezeBalanceKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); @@ -153,83 +177,87 @@ public void test005FreezeBalanceOfBandwidthForOthers() { Assert.assertTrue(berforeBalance - afterBalance == frozenBalance); } - - /** - * constructor. - */ - @Test(enabled = true, description = "Get Delegated Resource by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get Delegated Resource by http", + groups = {"daily", "serial"}) public void test006GetDelegatedResource() { - if(HttpMethod.proposalFreezeV2IsOpen(httpnode)) { + if (HttpMethod.proposalFreezeV2IsOpen(httpnode)) { throw new SkipException("Skipping this freezeV1 test case"); } - response = HttpMethod - .getDelegatedResource(httpnode, freezeBalanceAddress, receiverResourceAddress); + response = + HttpMethod.getDelegatedResource(httpnode, freezeBalanceAddress, receiverResourceAddress); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); JSONArray jsonArray = JSONArray.parseArray(responseContent.get("delegatedResource").toString()); Assert.assertTrue(jsonArray.size() >= 1); - Assert.assertEquals(jsonArray.getJSONObject(0).getString("from"), - ByteArray.toHexString(freezeBalanceAddress)); - Assert.assertEquals(jsonArray.getJSONObject(0).getString("to"), - ByteArray.toHexString(receiverResourceAddress)); - Assert.assertEquals(jsonArray.getJSONObject(0).getLong("frozen_balance_for_bandwidth"), - frozenBalance); + Assert.assertEquals( + jsonArray.getJSONObject(0).getString("from"), ByteArray.toHexString(freezeBalanceAddress)); + Assert.assertEquals( + jsonArray.getJSONObject(0).getString("to"), ByteArray.toHexString(receiverResourceAddress)); + Assert.assertEquals( + jsonArray.getJSONObject(0).getLong("frozen_balance_for_bandwidth"), frozenBalance); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get Delegated Resource from solidity by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get Delegated Resource from solidity by http", + groups = {"daily", "serial"}) public void test007GetDelegatedResourceFromSolidity() { - if(HttpMethod.proposalFreezeV2IsOpen(httpnode)) { + if (HttpMethod.proposalFreezeV2IsOpen(httpnode)) { throw new SkipException("Skipping this freezeV1 test case"); } HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); HttpMethod.waitToProduceOneBlockFromPbft(httpnode, httpPbftNode); - response = HttpMethod.getDelegatedResourceFromSolidity(httpSoliditynode, freezeBalanceAddress, - receiverResourceAddress); + response = + HttpMethod.getDelegatedResourceFromSolidity( + httpSoliditynode, freezeBalanceAddress, receiverResourceAddress); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); JSONArray jsonArray = JSONArray.parseArray(responseContent.get("delegatedResource").toString()); Assert.assertTrue(jsonArray.size() >= 1); - Assert.assertEquals(jsonArray.getJSONObject(0).getString("from"), - ByteArray.toHexString(freezeBalanceAddress)); - Assert.assertEquals(jsonArray.getJSONObject(0).getString("to"), - ByteArray.toHexString(receiverResourceAddress)); - Assert.assertEquals(jsonArray.getJSONObject(0).getLong("frozen_balance_for_bandwidth"), - frozenBalance); + Assert.assertEquals( + jsonArray.getJSONObject(0).getString("from"), ByteArray.toHexString(freezeBalanceAddress)); + Assert.assertEquals( + jsonArray.getJSONObject(0).getString("to"), ByteArray.toHexString(receiverResourceAddress)); + Assert.assertEquals( + jsonArray.getJSONObject(0).getLong("frozen_balance_for_bandwidth"), frozenBalance); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get Delegated Resource from PBFT by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get Delegated Resource from PBFT by http", + groups = {"daily", "serial"}) public void test008GetDelegatedResourceFromPbft() { - if(HttpMethod.proposalFreezeV2IsOpen(httpnode)) { + if (HttpMethod.proposalFreezeV2IsOpen(httpnode)) { throw new SkipException("Skipping this freezeV1 test case"); } HttpMethod.waitToProduceOneBlockFromPbft(httpnode, httpPbftNode); - response = HttpMethod - .getDelegatedResourceFromPbft(httpPbftNode, freezeBalanceAddress, receiverResourceAddress); + response = + HttpMethod.getDelegatedResourceFromPbft( + httpPbftNode, freezeBalanceAddress, receiverResourceAddress); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); JSONArray jsonArray = JSONArray.parseArray(responseContent.get("delegatedResource").toString()); Assert.assertTrue(jsonArray.size() >= 1); - Assert.assertEquals(jsonArray.getJSONObject(0).getString("from"), - ByteArray.toHexString(freezeBalanceAddress)); - Assert.assertEquals(jsonArray.getJSONObject(0).getString("to"), - ByteArray.toHexString(receiverResourceAddress)); - Assert.assertEquals(jsonArray.getJSONObject(0).getLong("frozen_balance_for_bandwidth"), - frozenBalance); + Assert.assertEquals( + jsonArray.getJSONObject(0).getString("from"), ByteArray.toHexString(freezeBalanceAddress)); + Assert.assertEquals( + jsonArray.getJSONObject(0).getString("to"), ByteArray.toHexString(receiverResourceAddress)); + Assert.assertEquals( + jsonArray.getJSONObject(0).getLong("frozen_balance_for_bandwidth"), frozenBalance); } - - /** - * constructor. - */ - @Test(enabled = true, description = "Get Delegated Resource Account Index by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get Delegated Resource Account Index by http", + groups = {"daily", "serial"}) public void test009GetDelegatedResourceAccountIndex() { - if(HttpMethod.proposalFreezeV2IsOpen(httpnode)) { + if (HttpMethod.proposalFreezeV2IsOpen(httpnode)) { throw new SkipException("Skipping this freezeV1 test case"); } response = HttpMethod.getDelegatedResourceAccountIndex(httpnode, freezeBalanceAddress); @@ -240,16 +268,18 @@ public void test009GetDelegatedResourceAccountIndex() { Assert.assertEquals(toAddress, ByteArray.toHexString(receiverResourceAddress)); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get Delegated Resource Account Index from solidity by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get Delegated Resource Account Index from solidity by http", + groups = {"daily", "serial"}) public void test010GetDelegatedResourceAccountIndexFromSolidity() { - if(HttpMethod.proposalFreezeV2IsOpen(httpnode)) { + if (HttpMethod.proposalFreezeV2IsOpen(httpnode)) { throw new SkipException("Skipping this freezeV1 test case"); } - response = HttpMethod - .getDelegatedResourceAccountIndexFromSolidity(httpSoliditynode, freezeBalanceAddress); + response = + HttpMethod.getDelegatedResourceAccountIndexFromSolidity( + httpSoliditynode, freezeBalanceAddress); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); Assert.assertFalse(responseContent.get("toAccounts").toString().isEmpty()); @@ -257,16 +287,17 @@ public void test010GetDelegatedResourceAccountIndexFromSolidity() { Assert.assertEquals(toAddress, ByteArray.toHexString(receiverResourceAddress)); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get Delegated Resource Account Index from PBFT by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get Delegated Resource Account Index from PBFT by http", + groups = {"daily", "serial"}) public void test011GetDelegatedResourceAccountIndexFromPbft() { - if(HttpMethod.proposalFreezeV2IsOpen(httpnode)) { + if (HttpMethod.proposalFreezeV2IsOpen(httpnode)) { throw new SkipException("Skipping this freezeV1 test case"); } - response = HttpMethod - .getDelegatedResourceAccountIndexFromPbft(httpPbftNode, freezeBalanceAddress); + response = + HttpMethod.getDelegatedResourceAccountIndexFromPbft(httpPbftNode, freezeBalanceAddress); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); Assert.assertFalse(responseContent.get("toAccounts").toString().isEmpty()); @@ -274,52 +305,64 @@ public void test011GetDelegatedResourceAccountIndexFromPbft() { Assert.assertEquals(toAddress, ByteArray.toHexString(receiverResourceAddress)); } - /** - * constructor. - */ - @Test(enabled = true, description = "UnFreezeBalance with bandwidth for others by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "UnFreezeBalance with bandwidth for others by http", + groups = {"daily", "serial"}) public void test012UnFreezeBalanceOfBandwidthForOthers() { HttpMethod.waitToProduceOneBlock(httpnode); HttpMethod.waitToProduceOneBlock(httpnode); HttpMethod.waitToProduceOneBlock(httpnode); berforeBalance = HttpMethod.getBalance(httpnode, freezeBalanceAddress); - //UnFreeze balance with bandwidth for others - response = HttpMethod - .unFreezeBalance(httpnode, freezeBalanceAddress, frozenBalance,0, receiverResourceAddress, + // UnFreeze balance with bandwidth for others + response = + HttpMethod.unFreezeBalance( + httpnode, + freezeBalanceAddress, + frozenBalance, + 0, + receiverResourceAddress, freezeBalanceKey); logger.info(HttpMethod.parseResponseContent(response).toJSONString()); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); afterBalance = HttpMethod.getBalance(httpnode, freezeBalanceAddress); - if(HttpMethod.getProposalValue(httpnode,ProposalEnum.GetUnfreezeDelayDays.getProposalName()) == 0) { + if (HttpMethod.getProposalValue(httpnode, ProposalEnum.GetUnfreezeDelayDays.getProposalName()) + == 0) { Assert.assertTrue(afterBalance - berforeBalance == frozenBalance); } else { logger.info("afterBalance:" + afterBalance); logger.info("berforeBalance:" + berforeBalance); - //another case's unfreeze balance has been expired + // another case's unfreeze balance has been expired Assert.assertTrue(afterBalance == berforeBalance + frozenBalance); - } } - - /** - * constructor. - */ - @Test(enabled = true, description = "FreezeBalance with energy for others by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "FreezeBalance with energy for others by http", + groups = {"daily", "serial"}) public void test013FreezeBalanceOfEnergyForOthers() { - response = HttpMethod - .sendCoin(httpnode, fromAddress, receiverResourceAddress, amount, testKey002); + response = + HttpMethod.sendCoin(httpnode, fromAddress, receiverResourceAddress, amount, testKey002); Assert.assertTrue(HttpMethod.verificationResult(response)); - response = HttpMethod - .freezeBalance(httpnode, fromAddress, 1000000000L, 0, 0, freezeBalanceAddress, - testKey002); + response = + HttpMethod.freezeBalance( + httpnode, fromAddress, 1000000000L, 0, 0, freezeBalanceAddress, testKey002); HttpMethod.waitToProduceOneBlock(httpnode); berforeBalance = HttpMethod.getBalance(httpnode, freezeBalanceAddress); - //Freeze balance with energy for others - response = HttpMethod - .freezeBalance(httpnode, freezeBalanceAddress, frozenBalance, 0, 1, receiverResourceAddress, + // Freeze balance with energy for others + response = + HttpMethod.freezeBalance( + httpnode, + freezeBalanceAddress, + frozenBalance, + 0, + 1, + receiverResourceAddress, freezeBalanceKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); @@ -327,47 +370,62 @@ public void test013FreezeBalanceOfEnergyForOthers() { Assert.assertTrue(berforeBalance - afterBalance == frozenBalance); } - /** - * constructor. - */ - @Test(enabled = true, description = "UnFreezeBalance with energy for others by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "UnFreezeBalance with energy for others by http", + groups = {"daily", "serial"}) public void test014UnFreezeBalanceOfEnergyForOthers() { - if(HttpMethod.proposalFreezeV2IsOpen(httpnode)) { + if (HttpMethod.proposalFreezeV2IsOpen(httpnode)) { throw new SkipException("Skipping this freezeV1 test case"); } berforeBalance = HttpMethod.getBalance(httpnode, freezeBalanceAddress); - //UnFreeze balance with energy for others - response = HttpMethod - .unFreezeBalance(httpnode, freezeBalanceAddress, frozenBalance,1, receiverResourceAddress, + // UnFreeze balance with energy for others + response = + HttpMethod.unFreezeBalance( + httpnode, + freezeBalanceAddress, + frozenBalance, + 1, + receiverResourceAddress, freezeBalanceKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); afterBalance = HttpMethod.getBalance(httpnode, freezeBalanceAddress); - if(HttpMethod.getProposalValue(httpnode,ProposalEnum.GetUnfreezeDelayDays.getProposalName()) == 0) { + if (HttpMethod.getProposalValue(httpnode, ProposalEnum.GetUnfreezeDelayDays.getProposalName()) + == 0) { Assert.assertTrue(afterBalance - berforeBalance == frozenBalance); } else { Assert.assertEquals(afterBalance, berforeBalance); } } - /** - * constructor. - */ - @Test(enabled = true, description = "FreezeBalance for tron power by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "FreezeBalance for tron power by http", + groups = {"daily", "serial"}) public void test015FreezeTronPower() { - if(HttpMethod.proposalFreezeV2IsOpen(httpnode)) { + if (HttpMethod.proposalFreezeV2IsOpen(httpnode)) { throw new SkipException("Skipping this freezeV1 test case"); } - if(HttpMethod.getProposalValue(httpnode, ProposalEnum.GetAllowNewResourceModel.getProposalName()) == 1) { + if (HttpMethod.getProposalValue( + httpnode, ProposalEnum.GetAllowNewResourceModel.getProposalName()) + == 1) { return; } HttpMethod.waitToProduceOneBlock(httpnode); berforeBalance = HttpMethod.getBalance(httpnode, freezeBalanceAddress); - response = HttpMethod - .freezeBalance(httpnode, freezeBalanceAddress, frozenBalance, 0, - HttpMethod.proposalTronPowerIsOpen(httpnode) ? 2 : 0, null, + response = + HttpMethod.freezeBalance( + httpnode, + freezeBalanceAddress, + frozenBalance, + 0, + HttpMethod.proposalTronPowerIsOpen(httpnode) ? 2 : 0, + null, freezeBalanceKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); @@ -375,23 +433,31 @@ public void test015FreezeTronPower() { Assert.assertTrue(berforeBalance - afterBalance == frozenBalance); } - /** - * constructor. - */ - @Test(enabled = true, description = "UnFreezeBalance for tron power by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "UnFreezeBalance for tron power by http", + groups = {"daily", "serial"}) public void test016UnFreezeBalanceForTronPower() { - if(HttpMethod.proposalFreezeV2IsOpen(httpnode)) { + if (HttpMethod.proposalFreezeV2IsOpen(httpnode)) { throw new SkipException("Skipping this freezeV1 test case"); } - if(HttpMethod.getProposalValue(httpnode, ProposalEnum.GetAllowNewResourceModel.getProposalName()) == 1) { + if (HttpMethod.getProposalValue( + httpnode, ProposalEnum.GetAllowNewResourceModel.getProposalName()) + == 1) { return; } berforeBalance = HttpMethod.getBalance(httpnode, freezeBalanceAddress); - //UnFreeze balance with energy for others + // UnFreeze balance with energy for others - response = HttpMethod - .unFreezeBalance(httpnode, freezeBalanceAddress, frozenBalance,HttpMethod.proposalTronPowerIsOpen(httpnode) ? 2 : 0, null, + response = + HttpMethod.unFreezeBalance( + httpnode, + freezeBalanceAddress, + frozenBalance, + HttpMethod.proposalTronPowerIsOpen(httpnode) ? 2 : 0, + null, freezeBalanceKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); @@ -399,19 +465,14 @@ public void test016UnFreezeBalanceForTronPower() { Assert.assertTrue(afterBalance - berforeBalance == frozenBalance); } - - - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - response = HttpMethod - .unFreezeBalance(httpnode, fromAddress, frozenBalance,0, freezeBalanceAddress, - testKey002); + response = + HttpMethod.unFreezeBalance( + httpnode, fromAddress, frozenBalance, 0, freezeBalanceAddress, testKey002); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.freeResource(httpnode, freezeBalanceAddress, fromAddress, freezeBalanceKey); HttpMethod.disConnect(); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAccount003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAccount003.java index eac3dba3..2f65a39a 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAccount003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAccount003.java @@ -4,9 +4,6 @@ import com.alibaba.fastjson.JSONObject; import com.google.gson.JsonArray; import com.google.gson.JsonObject; - -import java.util.HashMap; -import java.util.List; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; import org.junit.Assert; @@ -56,7 +53,10 @@ public class HttpTestAccount003 { Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(4); /** constructor. */ - @Test(enabled = true, description = "Update account by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Update account by http", + groups = {"daily", "serial"}) public void test01UpdateAccount() { response = HttpMethod.sendCoin(httpnode, fromAddress, updateAccountAddress, amount, testKey002); responseContent = HttpMethod.parseResponseContent(response); @@ -82,12 +82,20 @@ public void test01UpdateAccount() { } /** constructor. */ - @Test(enabled = true, description = "Vote witness account by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Vote witness account by http", + groups = {"daily", "serial"}) public void test02VoteWitnessAccount() { // Freeze balance response = - HttpMethod.freezeBalance(httpnode, updateAccountAddress, frozenBalance, 0, - HttpMethod.proposalTronPowerIsOpen(httpnode) ? 2 : 0, updateAccountKey); + HttpMethod.freezeBalance( + httpnode, + updateAccountAddress, + frozenBalance, + 0, + HttpMethod.proposalTronPowerIsOpen(httpnode) ? 2 : 0, + updateAccountKey); responseContent = HttpMethod.parseResponseContent(response); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.printJsonContent(responseContent); @@ -113,7 +121,10 @@ public void test02VoteWitnessAccount() { } /** constructor. */ - @Test(enabled = true, description = "List witnesses by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "List witnesses by http", + groups = {"daily", "serial"}) public void test03ListWitness() { response = HttpMethod.listwitnesses(httpnode); responseContent = HttpMethod.parseResponseContent(response); @@ -125,7 +136,10 @@ public void test03ListWitness() { } /** constructor. */ - @Test(enabled = true, description = "List witnesses by http with visible is true", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "List witnesses by http with visible is true", + groups = {"daily", "serial"}) public void test04ListWitness() { response = HttpMethod.listwitnesses(httpnode, true); responseContent = HttpMethod.parseResponseContent(response); @@ -137,7 +151,10 @@ public void test04ListWitness() { } /** constructor. */ - @Test(enabled = true, description = "List witnesses from solidity by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "List witnesses from solidity by http", + groups = {"daily", "serial"}) public void test05ListWitnessFromSolidity() { HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); response = HttpMethod.listwitnessesFromSolidity(httpSoliditynode); @@ -148,7 +165,10 @@ public void test05ListWitnessFromSolidity() { } /** constructor. */ - @Test(enabled = true, description = "List witnesses from PBFT by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "List witnesses from PBFT by http", + groups = {"daily", "serial"}) public void test06ListWitnessFromPbft() { HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); response = HttpMethod.listwitnessesFromPbft(httpPbftNode); @@ -159,7 +179,10 @@ public void test06ListWitnessFromPbft() { } /** constructor. */ - @Test(enabled = true, description = "Update witness by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Update witness by http", + groups = {"daily", "serial"}) public void test07UpdateWitness() { response = HttpMethod.updateWitness(httpnode, witness2Address, updateUrl, witnessKey002); Assert.assertTrue(HttpMethod.verificationResult(response)); @@ -173,7 +196,10 @@ public void test07UpdateWitness() { } /** constructor. */ - @Test(enabled = true, description = "Create account by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Create account by http", + groups = {"daily", "serial"}) public void test08CreateAccount() { PublicMethod.printAddress(newAccountKey); response = HttpMethod.createAccount(httpnode, fromAddress, newAccountAddress, testKey002); @@ -186,7 +212,10 @@ public void test08CreateAccount() { } /** constructor. */ - @Test(enabled = true, description = "Create witness by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Create witness by http", + groups = {"daily", "serial"}) public void test09CreateWitness() { response = HttpMethod.sendCoin( @@ -202,7 +231,10 @@ public void test09CreateWitness() { } /** constructor. */ - @Test(enabled = true, description = "Withdraw by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Withdraw by http", + groups = {"daily", "serial"}) public void test10Withdraw() { response = HttpMethod.withdrawBalance(httpnode, witness1Address); responseContent = HttpMethod.parseResponseContent(response); @@ -212,19 +244,26 @@ public void test10Withdraw() { } /** constructor. */ - @Test(enabled = true, description = "Unfreeze balance for tron power by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Unfreeze balance for tron power by http", + groups = {"daily", "serial"}) public void test11UnfreezeTronPower() { - response = HttpMethod.unFreezeBalance(httpnode, updateAccountAddress, frozenBalance,2, updateAccountKey); + response = + HttpMethod.unFreezeBalance( + httpnode, updateAccountAddress, frozenBalance, 2, updateAccountKey); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); } - // TODO: Enable when HttpMethod supports getPaginatedNowWitnessList (v4.8.1+ API) // This test calls methods that don't exist yet in HttpMethod. // Commented out to allow compilation. Uncomment when the API is available. /* - @Test(enabled = false, description = "List witness realTime vote data", groups = {"daily", "serial"}) + @Test(enabled = false, + description = "List witness realTime vote data", + groups = {"daily", + "serial"}) public void test12CheckVoteChangesRealtimeAfterVote(){ // Uses HttpMethod.getPaginatedNowWitnessList / getPaginatedNowWitnessListSolidity // which are not yet implemented. diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAccount004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAccount004.java index 1baabe19..ea436b50 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAccount004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAccount004.java @@ -16,8 +16,8 @@ @Slf4j public class HttpTestAccount004 { - private final String testKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); + private final String testKey002 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key1"); private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] setAccountIdAddress = ecKey1.getAddress(); @@ -26,41 +26,45 @@ public class HttpTestAccount004 { String accountId; private JSONObject responseContent; private HttpResponse response; - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(0); - private String httpSoliditynode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); - - - private String httpPbftNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(4); - - - /** - * constructor. - */ - @Test(enabled = true, description = "Set account by http", groups = {"daily", "serial"}) + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); + private String httpSoliditynode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); + + private String httpPbftNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(4); + + /** constructor. */ + @Test( + enabled = true, + description = "Set account by http", + groups = {"daily", "serial"}) public void test1setAccountId() { response = HttpMethod.sendCoin(httpnode, fromAddress, setAccountIdAddress, amount, testKey002); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - response = HttpMethod - .setAccountId(httpnode, setAccountIdAddress, System.currentTimeMillis() + "id", false, + response = + HttpMethod.setAccountId( + httpnode, + setAccountIdAddress, + System.currentTimeMillis() + "id", + false, setAccountIdKey); Assert.assertFalse(HttpMethod.verificationResult(response)); - //Set account id. + // Set account id. accountId = System.currentTimeMillis() + "id"; - response = HttpMethod - .setAccountId(httpnode, setAccountIdAddress, accountId, true, setAccountIdKey); + response = + HttpMethod.setAccountId(httpnode, setAccountIdAddress, accountId, true, setAccountIdKey); Assert.assertTrue(HttpMethod.verificationResult(response)); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get account by id via http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get account by id via http", + groups = {"daily", "serial"}) public void test2getAccountId() { response = HttpMethod.getAccountById(httpnode, accountId, true); responseContent = HttpMethod.parseResponseContent(response); @@ -72,14 +76,13 @@ public void test2getAccountId() { responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); Assert.assertTrue(responseContent.size() <= 1); - - } - /** - * constructor. - */ - @Test(enabled = true, description = "Get account by id via http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get account by id via http", + groups = {"daily", "serial"}) public void test3getAccountIdFromSolidity() { HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); response = HttpMethod.getAccountByIdFromSolidity(httpSoliditynode, accountId, true); @@ -89,10 +92,11 @@ public void test3getAccountIdFromSolidity() { Assert.assertTrue(responseContent.size() >= 10); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get account by id via PBFT http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get account by id via PBFT http", + groups = {"daily", "serial"}) public void test4getAccountIdFromPbft() { HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); response = HttpMethod.getAccountByIdFromPbft(httpPbftNode, accountId, true); @@ -102,14 +106,10 @@ public void test4getAccountIdFromPbft() { Assert.assertTrue(responseContent.size() >= 10); } - - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { HttpMethod.freeResource(httpnode, setAccountIdAddress, fromAddress, setAccountIdKey); HttpMethod.disConnect(); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAccount005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAccount005.java index 59aa18c2..d18e91a5 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAccount005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAccount005.java @@ -18,8 +18,8 @@ @Slf4j public class HttpTestAccount005 { - private final String testKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); + private final String testKey002 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key1"); private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] toAddress = ecKey1.getAddress(); @@ -27,18 +27,19 @@ public class HttpTestAccount005 { Long amount = 1L; String sendText = "Decentralize the WEB!"; private JSONObject responseContent; - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(0); + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); - /** - * constructor. - */ - @Test(enabled = true, description = "Test transfer with notes by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Test transfer with notes by http", + groups = {"daily", "serial"}) public void test01TransferWithNotes() { PublicMethod.printAddress(toAddressKey); - //Send trx to test account - String txid = HttpMethod - .sendCoin(httpnode, fromAddress, toAddress, amount, sendText, testKey002); + // Send trx to test account + String txid = + HttpMethod.sendCoin(httpnode, fromAddress, toAddress, amount, sendText, testKey002); HttpMethod.waitToProduceOneBlock(httpnode); HttpResponse response = HttpMethod.getTransactionById(httpnode, txid); responseContent = HttpMethod.parseResponseContent(response); @@ -51,9 +52,7 @@ public void test01TransferWithNotes() { Assert.assertEquals(sendText, recoveredString); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { HttpMethod.freeResource(httpnode, toAddress, fromAddress, toAddressKey); diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAsset001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAsset001.java index 75f99f9a..23911dc3 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAsset001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestAsset001.java @@ -8,12 +8,12 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.Test; import stest.tron.wallet.common.client.Configuration; +import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.HttpMethod; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.Utils; -import stest.tron.wallet.common.client.utils.Base58; @Slf4j public class HttpTestAsset001 { @@ -24,8 +24,8 @@ public class HttpTestAsset001 { private static String assetIssueId; private static String updateDescription = "Description_update_" + now; private static String updateUrl = "Url_update_" + now; - private final String testKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); + private final String testKey002 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key1"); private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] assetAddress = ecKey1.getAddress(); @@ -37,37 +37,52 @@ public class HttpTestAsset001 { Long amount = 2048000000L; - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private JSONObject responseContent; private JSONObject getAssetIssueByIdContent; private JSONObject getAssetIssueByNameContent; private HttpResponse response; - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(1); - private String httpSoliditynode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); - private String httpPbftNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(4); - - - /** - * constructor. - */ - @Test(enabled = true, description = "Create asset issue by http", groups = {"daily", "serial"}) + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(1); + private String httpSoliditynode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); + private String httpPbftNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(4); + + /** constructor. */ + @Test( + enabled = true, + description = "Create asset issue by http", + groups = {"daily", "serial"}) public void test01CreateAssetIssue() { response = HttpMethod.sendCoin(httpnode, fromAddress, assetAddress, amount, testKey002); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - response = HttpMethod - .sendCoin(httpnode, fromAddress, participateAddress, 10000000L, testKey002); + response = + HttpMethod.sendCoin(httpnode, fromAddress, participateAddress, 10000000L, testKey002); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - //Create an asset issue - response = HttpMethod.assetIssue(httpnode, assetAddress, name, name, totalSupply, 1, 1, - System.currentTimeMillis() + 5000, System.currentTimeMillis() + 50000000, 2, 3, description, - url, 1000L, 1000L, assetKey); + // Create an asset issue + response = + HttpMethod.assetIssue( + httpnode, + assetAddress, + name, + name, + totalSupply, + 1, + 1, + System.currentTimeMillis() + 5000, + System.currentTimeMillis() + 50000000, + 2, + 3, + description, + url, + 1000L, + 1000L, + assetKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getAccount(httpnode, assetAddress); @@ -79,10 +94,11 @@ public void test01CreateAssetIssue() { Assert.assertTrue(Integer.parseInt(assetIssueId) > 1000000); } - /** - * constructor. - */ - @Test(enabled = true, description = "GetAssetIssueById by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "GetAssetIssueById by http", + groups = {"daily", "serial"}) public void test02GetAssetIssueById() { HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getAssetIssueById(httpnode, assetIssueId); @@ -91,10 +107,11 @@ public void test02GetAssetIssueById() { Assert.assertTrue(totalSupply == getAssetIssueByIdContent.getLong("total_supply")); } - /** - * constructor. - */ - @Test(enabled = true, description = "GetAssetIssueById from solidity by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "GetAssetIssueById from solidity by http", + groups = {"daily", "serial"}) public void test03GetAssetIssueByIdFromSolidity() { HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); response = HttpMethod.getAssetIssueByIdFromSolidity(httpSoliditynode, assetIssueId); @@ -103,10 +120,11 @@ public void test03GetAssetIssueByIdFromSolidity() { Assert.assertTrue(totalSupply == getAssetIssueByIdContent.getLong("total_supply")); } - /** - * constructor. - */ - @Test(enabled = true, description = "GetAssetIssueById from PBFT by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "GetAssetIssueById from PBFT by http", + groups = {"daily", "serial"}) public void test04GetAssetIssueByIdFromPbft() { HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); response = HttpMethod.getAssetIssueByIdFromPbft(httpPbftNode, assetIssueId); @@ -115,11 +133,11 @@ public void test04GetAssetIssueByIdFromPbft() { Assert.assertTrue(totalSupply == getAssetIssueByIdContent.getLong("total_supply")); } - - /** - * constructor. - */ - @Test(enabled = true, description = "GetAssetIssueByName by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "GetAssetIssueByName by http", + groups = {"daily", "serial"}) public void test05GetAssetIssueByName() { response = HttpMethod.getAssetIssueByName(httpnode, name); getAssetIssueByNameContent = HttpMethod.parseResponseContent(response); @@ -127,10 +145,11 @@ public void test05GetAssetIssueByName() { Assert.assertTrue(totalSupply == getAssetIssueByNameContent.getLong("total_supply")); } - /** - * constructor. - */ - @Test(enabled = true, description = "GetAssetIssueByName from solidity by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "GetAssetIssueByName from solidity by http", + groups = {"daily", "serial"}) public void test06GetAssetIssueByNameFromSolidity() { response = HttpMethod.getAssetIssueByNameFromSolidity(httpSoliditynode, name); getAssetIssueByNameContent = HttpMethod.parseResponseContent(response); @@ -138,10 +157,11 @@ public void test06GetAssetIssueByNameFromSolidity() { Assert.assertTrue(totalSupply == getAssetIssueByNameContent.getLong("total_supply")); } - /** - * constructor. - */ - @Test(enabled = true, description = "GetAssetIssueByName from PBFT by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "GetAssetIssueByName from PBFT by http", + groups = {"daily", "serial"}) public void test07GetAssetIssueByNameFromPbft() { response = HttpMethod.getAssetIssueByNameFromPbft(httpPbftNode, name); getAssetIssueByNameContent = HttpMethod.parseResponseContent(response); @@ -149,50 +169,52 @@ public void test07GetAssetIssueByNameFromPbft() { Assert.assertTrue(totalSupply == getAssetIssueByNameContent.getLong("total_supply")); } - - /** - * constructor. - */ - @Test(enabled = true, description = "TransferAsset by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "TransferAsset by http", + groups = {"daily", "serial"}) public void test08TransferAsset() { logger.info("Transfer asset."); - response = HttpMethod - .transferAsset(httpnode, assetAddress, participateAddress, assetIssueId, 100L, assetKey); + response = + HttpMethod.transferAsset( + httpnode, assetAddress, participateAddress, assetIssueId, 100L, assetKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getAccount(httpnode, participateAddress); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); Assert.assertTrue(!responseContent.getString("assetV2").isEmpty()); - //logger.info(responseContent.get("assetV2").toString()); + // logger.info(responseContent.get("assetV2").toString()); } - /** - * constructor. - */ - @Test(enabled = true, description = "Participate asset issue by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Participate asset issue by http", + groups = {"daily", "serial"}) public void test09ParticipateAssetIssue() { HttpMethod.waitToProduceOneBlock(httpnode); - response = HttpMethod - .participateAssetIssue(httpnode, assetAddress, participateAddress, assetIssueId, 1000L, - participateKey); + response = + HttpMethod.participateAssetIssue( + httpnode, assetAddress, participateAddress, assetIssueId, 1000L, participateKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getAccount(httpnode, participateAddress); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - } - /** - * constructor. - */ - @Test(enabled = true, description = "Update asset issue by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Update asset issue by http", + groups = {"daily", "serial"}) public void test10UpdateAssetIssue() { - response = HttpMethod - .updateAssetIssue(httpnode, assetAddress, updateDescription, updateUrl, 290L, 390L, - assetKey); + response = + HttpMethod.updateAssetIssue( + httpnode, assetAddress, updateDescription, updateUrl, 290L, 390L, assetKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getAssetIssueById(httpnode, assetIssueId); @@ -201,17 +223,19 @@ public void test10UpdateAssetIssue() { Assert.assertTrue(getAssetIssueByIdContent.getLong("public_free_asset_net_limit") == 390L); Assert.assertTrue(getAssetIssueByIdContent.getLong("free_asset_net_limit") == 290L); - Assert.assertTrue(getAssetIssueByIdContent.getString("description") - .equalsIgnoreCase(HttpMethod.str2hex(updateDescription))); + Assert.assertTrue( + getAssetIssueByIdContent + .getString("description") + .equalsIgnoreCase(HttpMethod.str2hex(updateDescription))); Assert.assertTrue( getAssetIssueByIdContent.getString("url").equalsIgnoreCase(HttpMethod.str2hex(updateUrl))); } - - /** - * * constructor. * - */ - @Test(enabled = true, description = "Get asset issue list by http", groups = {"daily", "serial"}) + /** * constructor. * */ + @Test( + enabled = true, + description = "Get asset issue list by http", + groups = {"daily", "serial"}) public void test11GetAssetissueList() { response = HttpMethod.getAssetissueList(httpnode); @@ -223,11 +247,11 @@ public void test11GetAssetissueList() { Assert.assertTrue(jsonArray.size() >= 1); } - - /** - * * constructor. * - */ - @Test(enabled = true, description = "Get asset issue list from solidity by http", groups = {"daily", "serial"}) + /** * constructor. * */ + @Test( + enabled = true, + description = "Get asset issue list from solidity by http", + groups = {"daily", "serial"}) public void test12GetAssetissueListFromSolidity() { HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); response = HttpMethod.getAssetIssueListFromSolidity(httpSoliditynode); @@ -239,10 +263,11 @@ public void test12GetAssetissueListFromSolidity() { Assert.assertTrue(jsonArray.size() >= 1); } - /** - * * constructor. * - */ - @Test(enabled = true, description = "Get asset issue list from PBFT by http", groups = {"daily", "serial"}) + /** * constructor. * */ + @Test( + enabled = true, + description = "Get asset issue list from PBFT by http", + groups = {"daily", "serial"}) public void test13GetAssetissueListFromPbft() { HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); response = HttpMethod.getAssetIssueListFromPbft(httpPbftNode); @@ -254,11 +279,11 @@ public void test13GetAssetissueListFromPbft() { Assert.assertTrue(jsonArray.size() >= 1); } - - /** - * * constructor. * - */ - @Test(enabled = true, description = "Get paginated asset issue list by http", groups = {"daily", "serial"}) + /** * constructor. * */ + @Test( + enabled = true, + description = "Get paginated asset issue list by http", + groups = {"daily", "serial"}) public void test14GetPaginatedAssetissueList() { response = HttpMethod.getPaginatedAssetissueList(httpnode, 0, 1); responseContent = HttpMethod.parseResponseContent(response); @@ -269,11 +294,11 @@ public void test14GetPaginatedAssetissueList() { Assert.assertTrue(jsonArray.size() == 1); } - - /** - * * constructor. * - */ - @Test(enabled = true, description = "Get paginated asset issue list from solidity by http", groups = {"daily", "serial"}) + /** * constructor. * */ + @Test( + enabled = true, + description = "Get paginated asset issue list from solidity by http", + groups = {"daily", "serial"}) public void test15GetPaginatedAssetissueListFromSolidity() { response = HttpMethod.getPaginatedAssetissueListFromSolidity(httpSoliditynode, 0, 1); responseContent = HttpMethod.parseResponseContent(response); @@ -284,11 +309,11 @@ public void test15GetPaginatedAssetissueListFromSolidity() { Assert.assertTrue(jsonArray.size() == 1); } - - /** - * * constructor. * - */ - @Test(enabled = true, description = "Get paginated asset issue list from PBFT by http", groups = {"daily", "serial"}) + /** * constructor. * */ + @Test( + enabled = true, + description = "Get paginated asset issue list from PBFT by http", + groups = {"daily", "serial"}) public void test16GetPaginatedAssetissueListFromPbft() { response = HttpMethod.getPaginatedAssetissueListFromPbft(httpPbftNode, 0, 1); responseContent = HttpMethod.parseResponseContent(response); @@ -299,18 +324,26 @@ public void test16GetPaginatedAssetissueListFromPbft() { Assert.assertTrue(jsonArray.size() == 1); } - /** - * constructor. - */ - @Test(enabled = true, description = "TransferAsset visible true,then broadcast hex", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "TransferAsset visible true,then broadcast hex", + groups = {"daily", "serial"}) public void test17TransferAssetVisible() { logger.info("Transfer asset visible true,then broadcast hex"); response = HttpMethod.getAccount(httpnode, participateAddress); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - int amountBefore = responseContent.getJSONArray("assetV2").getJSONObject(0).getIntValue("value"); - response = HttpMethod.transferAsset(httpnode, Base58.encode58Check(assetAddress), - Base58.encode58Check(participateAddress), assetIssueId, 1L, assetKey); + int amountBefore = + responseContent.getJSONArray("assetV2").getJSONObject(0).getIntValue("value"); + response = + HttpMethod.transferAsset( + httpnode, + Base58.encode58Check(assetAddress), + Base58.encode58Check(participateAddress), + assetIssueId, + 1L, + assetKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getAccount(httpnode, participateAddress); @@ -318,16 +351,13 @@ public void test17TransferAssetVisible() { HttpMethod.printJsonContent(responseContent); int amountAfter = responseContent.getJSONArray("assetV2").getJSONObject(0).getIntValue("value"); Assert.assertEquals(1, amountAfter - amountBefore); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { HttpMethod.freeResource(httpnode, assetAddress, fromAddress, assetKey); HttpMethod.freeResource(httpnode, participateAddress, fromAddress, participateKey); HttpMethod.disConnect(); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestBlock001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestBlock001.java index 97838b94..511ac9e8 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestBlock001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestBlock001.java @@ -1,6 +1,5 @@ package stest.tron.wallet.dailybuild.http; -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import java.util.HashMap; @@ -16,8 +15,6 @@ import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.Utils; - - @Slf4j public class HttpTestBlock001 { @@ -66,7 +63,10 @@ public void beforeClass() throws InterruptedException { } /** constructor. */ - @Test(enabled = true, description = "Get now block by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get now block by http", + groups = {"daily", "serial"}) public void get01NowBlock() { response = HttpMethod.getNowBlock(httpnode); logger.info("code is " + response.getStatusLine().getStatusCode()); @@ -89,7 +89,10 @@ public void get01NowBlock() { } /** constructor. */ - @Test(enabled = true, description = "Get now block from solidity by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get now block from solidity by http", + groups = {"daily", "serial"}) public void get02NowBlockFromSolidity() { response = HttpMethod.getNowBlockFromSolidity(httpSoliditynode); logger.info("code is " + response.getStatusLine().getStatusCode()); @@ -112,7 +115,10 @@ public void get02NowBlockFromSolidity() { } /** constructor. */ - @Test(enabled = true, description = "Get now block from pbft by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get now block from pbft by http", + groups = {"daily", "serial"}) public void get03NowBlockFromPbft() { response = HttpMethod.getNowBlockFromPbft(httpPbftNode); logger.info("code is " + response.getStatusLine().getStatusCode()); @@ -135,7 +141,10 @@ public void get03NowBlockFromPbft() { } /** constructor. */ - @Test(enabled = true, description = "Get block by num by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get block by num by http", + groups = {"daily", "serial"}) public void get04BlockByNum() { response = HttpMethod.getBlockByNum(httpnode, currentBlockNum); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); @@ -150,20 +159,26 @@ public void get04BlockByNum() { } /** constructor. */ - @Test(enabled = true, description = "Get block equals getNowBlock", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get block equals getNowBlock", + groups = {"daily", "serial"}) public void get05GetBlockGetNowBlock() throws InterruptedException { Boolean getBlockEqualGetNowBlock = false; Integer retryTimes = 5; while (retryTimes-- >= 0) { - HttpResponse response1 = HttpMethod.getBlock(httpnode, null,null); + HttpResponse response1 = HttpMethod.getBlock(httpnode, null, null); HttpResponse response2 = HttpMethod.getNowBlock(httpnode); JSONObject getBlockObject = HttpMethod.parseResponseContent(response1); JSONObject getNowBlockObject = HttpMethod.parseResponseContent(response2); logger.info("get05GetBlockGetNowBlock getBlockObject: " + getBlockObject.toJSONString()); - logger.info("get05GetBlockGetNowBlock getNowBlockObject: " + getNowBlockObject.toJSONString()); - if (getBlockObject.getJSONObject("block_header").equals(getNowBlockObject.getJSONObject("block_header")) - &&getBlockObject.getString("blockID").equals(getNowBlockObject.getString("blockID"))) { + logger.info( + "get05GetBlockGetNowBlock getNowBlockObject: " + getNowBlockObject.toJSONString()); + if (getBlockObject + .getJSONObject("block_header") + .equals(getNowBlockObject.getJSONObject("block_header")) + && getBlockObject.getString("blockID").equals(getNowBlockObject.getString("blockID"))) { getBlockEqualGetNowBlock = true; break; } @@ -171,46 +186,41 @@ public void get05GetBlockGetNowBlock() throws InterruptedException { } Assert.assertTrue(getBlockEqualGetNowBlock); - - } /** constructor. */ - @Test(enabled = true, description = "Get block with block num and detail true from http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get block with block num and detail true from http", + groups = {"daily", "serial"}) public void get06GetBlockWithGetblockNumFromHttp() { - response = HttpMethod.getBlock(httpnode, String.valueOf(blockNumForType),true); + response = HttpMethod.getBlock(httpnode, String.valueOf(blockNumForType), true); JSONObject getBlockObject = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(getBlockObject); response = HttpMethod.getBlockByNum(httpnode, blockNumForType); JSONObject getBlockByNum = HttpMethod.parseResponseContent(response); - Assert.assertEquals(getBlockObject,getBlockByNum); + Assert.assertEquals(getBlockObject, getBlockByNum); - response = HttpMethod.getBlock(httpnode, blockIdForNoType,true); + response = HttpMethod.getBlock(httpnode, blockIdForNoType, true); getBlockObject = HttpMethod.parseResponseContent(response); - Assert.assertEquals(getBlockObject,getBlockByNum); + Assert.assertEquals(getBlockObject, getBlockByNum); - - response = HttpMethod.getBlock(httpnode, String.valueOf(blockNumForType),false); + response = HttpMethod.getBlock(httpnode, String.valueOf(blockNumForType), false); getBlockObject = HttpMethod.parseResponseContent(response); - Assert.assertNotEquals(getBlockObject,getBlockByNum); - + Assert.assertNotEquals(getBlockObject, getBlockByNum); - response = HttpMethod.getBlock(httpnode, String.valueOf(blockNumForType),false); + response = HttpMethod.getBlock(httpnode, String.valueOf(blockNumForType), false); JSONObject getBlockWithNumObject = HttpMethod.parseResponseContent(response); - response = HttpMethod.getBlock(httpnode, blockIdForNoType,false); + response = HttpMethod.getBlock(httpnode, blockIdForNoType, false); JSONObject getBlockWithIdObject = HttpMethod.parseResponseContent(response); - Assert.assertEquals(getBlockWithNumObject,getBlockWithIdObject); - - - - - - - + Assert.assertEquals(getBlockWithNumObject, getBlockWithIdObject); } /** constructor. */ - @Test(enabled = true, description = "Get block by num from solidity by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get block by num from solidity by http", + groups = {"daily", "serial"}) public void get07BlockByNumFromSolidity() { HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); response = HttpMethod.getBlockByNumFromSolidity(httpSoliditynode, currentBlockNum); @@ -220,7 +230,10 @@ public void get07BlockByNumFromSolidity() { } /** constructor. */ - @Test(enabled = true, description = "Get block by num from PBFT by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get block by num from PBFT by http", + groups = {"daily", "serial"}) public void get08BlockByNumFromPbft() { response = HttpMethod.getBlockByNumFromPbft(httpPbftNode, currentBlockNum); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); @@ -229,7 +242,10 @@ public void get08BlockByNumFromPbft() { } /** constructor. */ - @Test(enabled = true, description = "GetBlockByLimitNext by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "GetBlockByLimitNext by http", + groups = {"daily", "serial"}) public void get09BlockByLimitNext() { response = HttpMethod.getBlockByLimitNext(httpnode, currentBlockNum - 10, currentBlockNum); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); @@ -241,7 +257,10 @@ public void get09BlockByLimitNext() { } /** constructor. */ - @Test(enabled = true, description = "GetBlockByLastNum by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "GetBlockByLastNum by http", + groups = {"daily", "serial"}) public void get10BlockByLastNum() { response = HttpMethod.getBlockByLastNum(httpnode, 8); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); @@ -253,7 +272,10 @@ public void get10BlockByLastNum() { } /** constructor. */ - @Test(enabled = true, description = "GetBlockById by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "GetBlockById by http", + groups = {"daily", "serial"}) public void get11BlockById() { response = HttpMethod.getBlockById(httpnode, blockId); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); @@ -263,7 +285,10 @@ public void get11BlockById() { } /** constructor. */ - @Test(enabled = true, description = "GetBlockById by Solidity http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "GetBlockById by Solidity http", + groups = {"daily", "serial"}) public void get12BlockByIdFromSolidity() { response = HttpMethod.getBlockByIdFromSolidity(httpSoliditynode, blockId); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); @@ -273,7 +298,10 @@ public void get12BlockByIdFromSolidity() { } /** constructor. */ - @Test(enabled = true, description = "GetBlockById for type is 0 by Solidity http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "GetBlockById for type is 0 by Solidity http", + groups = {"daily", "serial"}) public void get13BlockByIdForTypeIsZeroFromSolidity() { response = HttpMethod.getBlockByIdFromSolidity(httpSoliditynode, blockIdForNoType, 0); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); @@ -284,7 +312,10 @@ public void get13BlockByIdForTypeIsZeroFromSolidity() { } /** constructor. */ - @Test(enabled = false, description = "GetBlockById type is 1 by Solidity http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "GetBlockById type is 1 by Solidity http", + groups = {"daily", "serial"}) public void get14BlockByIdForTypeIsOneFromSolidity() { response = HttpMethod.getBlockByIdFromSolidity(httpSoliditynode, blockIdForNoType, 1); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); @@ -295,7 +326,10 @@ public void get14BlockByIdForTypeIsOneFromSolidity() { } /** constructor. */ - @Test(enabled = true, description = "GetBlockById by PBFT http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "GetBlockById by PBFT http", + groups = {"daily", "serial"}) public void get15BlockByIdFromPbft() { response = HttpMethod.getBlockByIdFromPbft(httpPbftNode, blockId); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); @@ -305,7 +339,10 @@ public void get15BlockByIdFromPbft() { } /** constructor. */ - @Test(enabled = true, description = "List nodes by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "List nodes by http", + groups = {"daily", "serial"}) public void get16ListNodes() { response = HttpMethod.listNodes(httpnode); responseContent = HttpMethod.parseResponseContent(response); @@ -313,7 +350,10 @@ public void get16ListNodes() { } /** constructor. */ - @Test(enabled = true, description = "get next maintenance time by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "get next maintenance time by http", + groups = {"daily", "serial"}) public void get17NextMaintenanceTime() { response = HttpMethod.getNextmaintenanceTime(httpnode); responseContent = HttpMethod.parseResponseContent(response); @@ -323,7 +363,10 @@ public void get17NextMaintenanceTime() { } /** constructor. */ - @Test(enabled = true, description = "get chain parameter by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "get chain parameter by http", + groups = {"daily", "serial"}) public void get18ChainParameter() { response = HttpMethod.getChainParameter(httpnode); responseContent = HttpMethod.parseResponseContent(response); @@ -341,7 +384,10 @@ public void get18ChainParameter() { } /** constructor. */ - @Test(enabled = true, description = "get Node Info by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "get Node Info by http", + groups = {"daily", "serial"}) public void get19NodeInfo() { response = HttpMethod.getNodeInfo(httpnode); responseContent = HttpMethod.parseResponseContent(response); @@ -351,7 +397,10 @@ public void get19NodeInfo() { } /** constructor. */ - @Test(enabled = true, description = "Get transaction count by blocknum from solidity by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get transaction count by blocknum from solidity by http", + groups = {"daily", "serial"}) public void get20TransactionCountByBlocknumFromSolidity() { response = HttpMethod.getTransactionCountByBlocknumFromSolidity(httpSoliditynode, currentBlockNum); @@ -363,7 +412,10 @@ public void get20TransactionCountByBlocknumFromSolidity() { } /** constructor. */ - @Test(enabled = true, description = "Get transaction count by blocknum from PBFT by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get transaction count by blocknum from PBFT by http", + groups = {"daily", "serial"}) public void get21TransactionCountByBlocknumFromPbft() { response = HttpMethod.getTransactionCountByBlocknumFromPbft(httpPbftNode, currentBlockNum); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); @@ -374,7 +426,10 @@ public void get21TransactionCountByBlocknumFromPbft() { } /** constructor. */ - @Test(enabled = true, description = "GetBlockByLimitNext by Solidity http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "GetBlockByLimitNext by Solidity http", + groups = {"daily", "serial"}) public void get22BlockByLimitNextFromSolidity() { response = HttpMethod.getBlockByLimitNextFromSolidity( @@ -388,7 +443,10 @@ public void get22BlockByLimitNextFromSolidity() { } /** constructor. */ - @Test(enabled = true, description = "GetBlockByLimitNext by PBFT http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "GetBlockByLimitNext by PBFT http", + groups = {"daily", "serial"}) public void get23BlockByLimitNextFromPbft() { response = HttpMethod.getBlockByLimitNextFromPbft(httpPbftNode, currentBlockNum - 10, currentBlockNum); @@ -401,7 +459,10 @@ public void get23BlockByLimitNextFromPbft() { } /** constructor. */ - @Test(enabled = true, description = "GetBlockByLastNum by solidity http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "GetBlockByLastNum by solidity http", + groups = {"daily", "serial"}) public void get24BlockByLastNumFromSolidity() { response = HttpMethod.getBlockByLastNumFromSolidity(httpSoliditynode, 8); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); @@ -413,7 +474,10 @@ public void get24BlockByLastNumFromSolidity() { } /** constructor. */ - @Test(enabled = true, description = "GetBlockByLastNum by PBFT http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "GetBlockByLastNum by PBFT http", + groups = {"daily", "serial"}) public void get25BlockByLastNumFromPbft() { response = HttpMethod.getBlockByLastNumFromPbft(httpPbftNode, 8); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); @@ -425,10 +489,13 @@ public void get25BlockByLastNumFromPbft() { } /** constructor. */ - @Test(enabled = false, description = "Get block by num by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Get block by num by http", + groups = {"daily", "serial"}) public void get26TestResponse() { Integer times = 1000; - //just test key + // just test key String testKey002 = "7400E3D0727F8A61041A8E8BF86599FE5597CE19DE451E59AED07D60967A5E25"; byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); Long duration = HttpMethod.getBlockByNumForResponse(httpnode, 4942435, times); diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestClearAbiContract001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestClearAbiContract001.java index 111b05cf..8e2fee9e 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestClearAbiContract001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestClearAbiContract001.java @@ -24,8 +24,8 @@ public class HttpTestClearAbiContract001 { private static String name = "testAssetIssue002_" + now; private static String assetIssueId; private static String contractName; - private final String testKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); + private final String testKey002 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key1"); private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] assetOwnerAddress = ecKey2.getAddress(); @@ -34,22 +34,23 @@ public class HttpTestClearAbiContract001 { String abi; int blockNum; Long amount = 2048000000L; - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private JSONObject responseContent; private HttpResponse response; - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(0); - private String httpSoliditynode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); - private String httpPbftnode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(4); - - /** - * constructor. - */ - @Test(enabled = true, description = "Deploy smart contract by http", groups = {"daily", "serial"}) + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); + private String httpSoliditynode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); + private String httpPbftnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(4); + + /** constructor. */ + @Test( + enabled = true, + description = "Deploy smart contract by http", + groups = {"daily", "serial"}) public void test1DeployContract() { PublicMethod.printAddress(assetOwnerKey); response = HttpMethod.sendCoin(httpnode, fromAddress, assetOwnerAddress, amount, testKey002); @@ -68,9 +69,21 @@ public void test1DeployContract() { logger.info("abi:" + abi); logger.info("code:" + code); - String txid = HttpMethod - .deployContractGetTxid(httpnode, contractName, abi, code, 1000000L, 1000000000L, 100, - 11111111111111L, 0L, 0, 0L, assetOwnerAddress, assetOwnerKey); + String txid = + HttpMethod.deployContractGetTxid( + httpnode, + contractName, + abi, + code, + 1000000L, + 1000000000L, + 100, + 11111111111111L, + 0L, + 0, + 0L, + assetOwnerAddress, + assetOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); logger.info(txid); @@ -82,72 +95,80 @@ public void test1DeployContract() { response = HttpMethod.getTransactionInfoById(httpnode, txid); responseContent = HttpMethod.parseResponseContent(response); - Assert - .assertEquals(responseContent.getJSONObject("receipt").getString("result"), "SUCCESS"); + Assert.assertEquals(responseContent.getJSONObject("receipt").getString("result"), "SUCCESS"); blockNum = responseContent.getIntValue("blockNumber") + 1; } - /** - * constructor. - */ - @Test(enabled = true, description = "Get contract by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get contract by http", + groups = {"daily", "serial"}) public void test2GetContract() { response = HttpMethod.getContract(httpnode, contractAddress); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); Assert.assertEquals(responseContent.getString("consume_user_resource_percent"), "100"); Assert.assertEquals(responseContent.getString("contract_address"), contractAddress); - Assert.assertEquals(responseContent.getString("origin_address"), - ByteArray.toHexString(assetOwnerAddress)); + Assert.assertEquals( + responseContent.getString("origin_address"), ByteArray.toHexString(assetOwnerAddress)); Assert.assertThat(responseContent.getString("abi"), containsString("testView")); Assert.assertEquals(responseContent.getString("origin_energy_limit"), "11111111111111"); Assert.assertEquals(responseContent.getString("name"), contractName); } - /** - * constructor. - */ - @Test(enabled = true, description = "Trigger contract by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Trigger contract by http", + groups = {"daily", "serial"}) public void test3TriggerConstantContract() { - HttpResponse httpResponse = HttpMethod - .triggerConstantContract(httpnode, assetOwnerAddress, contractAddress, "testView()", ""); + HttpResponse httpResponse = + HttpMethod.triggerConstantContract( + httpnode, assetOwnerAddress, contractAddress, "testView()", ""); responseContent = HttpMethod.parseResponseContent(httpResponse); HttpMethod.printJsonContent(responseContent); Assert.assertEquals(responseContent.getString("result"), "{\"result\":true}"); - Assert.assertEquals(responseContent.getString("constant_result"), + Assert.assertEquals( + responseContent.getString("constant_result"), "[\"0000000000000000000000000000000000000000000000000000000000000001\"]"); HttpMethod.waitUntilFixedBlockFromSolidity(blockNum, httpSoliditynode); - httpResponse = HttpMethod.triggerConstantContractFromSolidity(httpSoliditynode, - assetOwnerAddress, contractAddress, "testView()", ""); + httpResponse = + HttpMethod.triggerConstantContractFromSolidity( + httpSoliditynode, assetOwnerAddress, contractAddress, "testView()", ""); responseContent = HttpMethod.parseResponseContent(httpResponse); HttpMethod.printJsonContent(responseContent); Assert.assertEquals(responseContent.getString("result"), "{\"result\":true}"); - Assert.assertEquals(responseContent.getString("constant_result"), - "[\"0000000000000000000000000000000000000000000000000000000000000001\"]"); + Assert.assertEquals( + responseContent.getString("constant_result"), + "[\"0000000000000000000000000000000000000000000000000000000000000001\"]"); - httpResponse = HttpMethod.triggerConstantContractFromPbft(httpPbftnode, assetOwnerAddress, - contractAddress, "testView()", ""); + httpResponse = + HttpMethod.triggerConstantContractFromPbft( + httpPbftnode, assetOwnerAddress, contractAddress, "testView()", ""); responseContent = HttpMethod.parseResponseContent(httpResponse); HttpMethod.printJsonContent(responseContent); Assert.assertEquals(responseContent.getString("result"), "{\"result\":true}"); - Assert.assertEquals(responseContent.getString("constant_result"), - "[\"0000000000000000000000000000000000000000000000000000000000000001\"]"); + Assert.assertEquals( + responseContent.getString("constant_result"), + "[\"0000000000000000000000000000000000000000000000000000000000000001\"]"); } - /** - * constructor. - */ - @Test(enabled = true, description = "Trigger contract by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Trigger contract by http", + groups = {"daily", "serial"}) public void test4ClearAbiContract() { - HttpResponse httpResponse = HttpMethod - .clearABiGetTxid(httpnode, assetOwnerAddress, contractAddress, assetOwnerKey); + HttpResponse httpResponse = + HttpMethod.clearABiGetTxid(httpnode, assetOwnerAddress, contractAddress, assetOwnerKey); responseContent = HttpMethod.parseResponseContent(httpResponse); HttpMethod.printJsonContent(responseContent); @@ -155,26 +176,25 @@ public void test4ClearAbiContract() { HttpMethod.waitToProduceOneBlock(httpnode); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get contract by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get contract by http", + groups = {"daily", "serial"}) public void test5GetContract() { response = HttpMethod.getContract(httpnode, contractAddress); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); Assert.assertEquals(responseContent.getString("consume_user_resource_percent"), "100"); Assert.assertEquals(responseContent.getString("contract_address"), contractAddress); - Assert.assertEquals(responseContent.getString("origin_address"), - ByteArray.toHexString(assetOwnerAddress)); + Assert.assertEquals( + responseContent.getString("origin_address"), ByteArray.toHexString(assetOwnerAddress)); Assert.assertEquals(responseContent.getString("abi"), "{}"); Assert.assertEquals(responseContent.getString("origin_energy_limit"), "11111111111111"); Assert.assertEquals(responseContent.getString("name"), contractName); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { HttpMethod.freeResource(httpnode, assetOwnerAddress, fromAddress, assetOwnerKey); diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestConstantContract001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestConstantContract001.java index d48a5337..e9af82e4 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestConstantContract001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestConstantContract001.java @@ -2,15 +2,18 @@ import com.alibaba.fastjson.JSONObject; import java.util.HashMap; - import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; import org.junit.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.HttpMethod; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class HttpTestConstantContract001 extends TronBaseTest { @@ -23,37 +26,53 @@ public class HttpTestConstantContract001 extends TronBaseTest { Long amount = 2048000000L; private JSONObject responseContent; private HttpResponse response; - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(0); - private String httpnode1 = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(1); - - /** - * constructor. - */ - @Test(enabled = true, description = "Deploy constant contract by http", groups = {"daily", "serial"}) + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); + private String httpnode1 = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(1); + + /** constructor. */ + @Test( + enabled = true, + description = "Deploy constant contract by http", + groups = {"daily", "serial"}) public void test1DeployConstantContract() { PublicMethod.printAddress(assetOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); - response = HttpMethod.sendCoin(httpnode, foundationAddress, assetOwnerAddress, amount, foundationKey); - String jsonRpcOwnerKey = + response = + HttpMethod.sendCoin(httpnode, foundationAddress, assetOwnerAddress, amount, foundationKey); + String jsonRpcOwnerKey = Configuration.getByPath("testng.conf").getString("defaultParameter.jsonRpcOwnerKey"); - byte[] jsonRpcOwnerAddress = PublicMethod.getFinalAddress(jsonRpcOwnerKey); + byte[] jsonRpcOwnerAddress = PublicMethod.getFinalAddress(jsonRpcOwnerKey); response = HttpMethod.getAccount(httpnode, jsonRpcOwnerAddress); responseContent = HttpMethod.parseResponseContent(response); - String tokenId = responseContent.getString("asset_issued_ID"); - response = HttpMethod.transferAsset(httpnode, jsonRpcOwnerAddress, assetOwnerAddress, tokenId, 10L, jsonRpcOwnerKey); + String tokenId = responseContent.getString("asset_issued_ID"); + response = + HttpMethod.transferAsset( + httpnode, jsonRpcOwnerAddress, assetOwnerAddress, tokenId, 10L, jsonRpcOwnerKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - String filePath = "src/test/resources/soliditycode/constantContract001.sol"; + String filePath = "src/test/resources/soliditycode/constantContract001.sol"; contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = HttpMethod - .deployContractGetTxid(httpnode, contractName, abi, code, 1000000L, 1000000000L, 100, - 11111111111111L, 100L, Integer.valueOf(tokenId), 5L, assetOwnerAddress, assetOwnerKey); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + HttpMethod.deployContractGetTxid( + httpnode, + contractName, + abi, + code, + 1000000L, + 1000000000L, + 100, + 11111111111111L, + 100L, + Integer.valueOf(tokenId), + 5L, + assetOwnerAddress, + assetOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); logger.info(txid); @@ -65,63 +84,74 @@ public void test1DeployConstantContract() { response = HttpMethod.getTransactionInfoById(httpnode, txid); responseContent = HttpMethod.parseResponseContent(response); - String receiptString = responseContent.getString("receipt"); - Assert - .assertEquals(HttpMethod.parseStringContent(receiptString).getString("result"), "SUCCESS"); + String receiptString = responseContent.getString("receipt"); + Assert.assertEquals( + HttpMethod.parseStringContent(receiptString).getString("result"), "SUCCESS"); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get constant contract by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get constant contract by http", + groups = {"daily", "serial"}) public void test2GetConstantContract() { response = HttpMethod.getContract(httpnode, contractAddress); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); Assert.assertEquals(responseContent.getString("consume_user_resource_percent"), "100"); Assert.assertEquals(responseContent.getString("contract_address"), contractAddress); - Assert.assertEquals(responseContent.getString("origin_address"), - ByteArray.toHexString(assetOwnerAddress)); + Assert.assertEquals( + responseContent.getString("origin_address"), ByteArray.toHexString(assetOwnerAddress)); Assert.assertEquals(responseContent.getString("origin_energy_limit"), "11111111111111"); Assert.assertEquals(responseContent.getString("name"), contractName); } - /** - * constructor. - */ - @Test(enabled = true, description = "Trigger constant contract without parameterString by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Trigger constant contract without parameterString by http", + groups = {"daily", "serial"}) public void test3TriggerConstantContract() { String param1 = "000000000000000000000000000000000000000000000000000000000000000" + Integer.toHexString(3); - String param2 = + String param2 = "00000000000000000000000000000000000000000000000000000000000000" + Integer.toHexString(30); logger.info(param1); logger.info(param2); - String param = param1 + param2; + String param = param1 + param2; logger.info(ByteArray.toHexString(assetOwnerAddress)); - response = HttpMethod.triggerConstantContract(httpnode, assetOwnerAddress, contractAddress, - "testPure(uint256,uint256)", param, 1000000000L, assetOwnerKey); + response = + HttpMethod.triggerConstantContract( + httpnode, + assetOwnerAddress, + contractAddress, + "testPure(uint256,uint256)", + param, + 1000000000L, + assetOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); Assert.assertTrue(!responseContent.getString("transaction").isEmpty()); - JSONObject transactionObject = HttpMethod - .parseStringContent(responseContent.getString("transaction")); + JSONObject transactionObject = + HttpMethod.parseStringContent(responseContent.getString("transaction")); Assert.assertTrue(!transactionObject.getString("raw_data").isEmpty()); Assert.assertTrue(!transactionObject.getString("raw_data_hex").isEmpty()); - Assert.assertTrue(responseContent.getIntValue("energy_used") > 400 - && responseContent.getIntValue("energy_used") < 500); + Assert.assertTrue( + responseContent.getIntValue("energy_used") > 400 + && responseContent.getIntValue("energy_used") < 500); } - /** - * constructor. - */ - @Test(enabled = true, description = "Trigger constant contract with call_value", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Trigger constant contract with call_value", + groups = {"daily", "serial"}) public void test4TriggerConstantContract() { String method = "testCallValue()"; - String param = null; - response = HttpMethod - .triggerConstantContractWithData( + String param = null; + response = + HttpMethod.triggerConstantContractWithData( httpnode, foundationAddress, contractAddress, method, param, null, 10, 0, 0); HttpMethod.waitToProduceOneBlock(httpnode); responseContent = HttpMethod.parseResponseContent(response); @@ -133,19 +163,20 @@ public void test4TriggerConstantContract() { Assert.assertTrue(result); Assert.assertTrue(!transactionObject.getString("raw_data").isEmpty()); Assert.assertTrue(!transactionObject.getString("raw_data_hex").isEmpty()); - Assert.assertEquals(209, responseContent.getIntValue("energy_used") ); + Assert.assertEquals(209, responseContent.getIntValue("energy_used")); } - /** - * constructor. - */ - @Test(enabled = true, description = " estimate kill function by triggerconstant", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = " estimate kill function by triggerconstant", + groups = {"daily", "serial"}) public void test5TriggerConstantContract() { String assetOwnerAddress41 = ByteArray.toHexString(assetOwnerAddress); - String method = "killme(address)"; - String param = "0000000000000000000000"+assetOwnerAddress41; - response = HttpMethod - .triggerConstantContractWithData( + String method = "killme(address)"; + String param = "0000000000000000000000" + assetOwnerAddress41; + response = + HttpMethod.triggerConstantContractWithData( httpnode, foundationAddress, contractAddress, method, param, null, 0, 0, 0); responseContent = HttpMethod.parseResponseContent(response); logger.info("triggerconstant result: " + responseContent); @@ -157,23 +188,32 @@ public void test5TriggerConstantContract() { Assert.assertTrue(result); Assert.assertTrue(!transactionObject.getString("raw_data").isEmpty()); Assert.assertTrue(!transactionObject.getString("raw_data_hex").isEmpty()); - long energyRequiredTriggerConstant = responseContent.getIntValue("energy_used"); - - response = HttpMethod - .getEstimateEnergy(httpnode1, foundationAddress, ByteArray.fromHexString(contractAddress), method, param, null,false, 0, 0, 0); + long energyRequiredTriggerConstant = responseContent.getIntValue("energy_used"); + + response = + HttpMethod.getEstimateEnergy( + httpnode1, + foundationAddress, + ByteArray.fromHexString(contractAddress), + method, + param, + null, + false, + 0, + 0, + 0); responseContent = HttpMethod.parseResponseContent(response); logger.info("estimate result: " + responseContent.toJSONString()); long energyRequiredEstimate = responseContent.getLong("energy_required"); final Long energyFee = PublicMethod.getChainParametersValue("getEnergyFee", blockingStubFull); - Assert.assertTrue((energyRequiredEstimate - energyRequiredTriggerConstant) * energyFee <= 1000000L); + Assert.assertTrue( + (energyRequiredEstimate - energyRequiredTriggerConstant) * energyFee <= 1000000L); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { HttpMethod.freeResource(httpnode, assetOwnerAddress, foundationAddress, assetOwnerKey); HttpMethod.disConnect(); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestContentLength.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestContentLength.java index ab20de02..c216e390 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestContentLength.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestContentLength.java @@ -1,52 +1,51 @@ package stest.tron.wallet.dailybuild.http; -import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; -import org.apache.http.HttpResponse; import org.junit.Assert; import org.testng.annotations.Test; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.HttpMethod; import stest.tron.wallet.common.client.utils.PublicMethod; -import java.io.*; -import java.net.Socket; -import java.net.UnknownHostException; - @Slf4j public class HttpTestContentLength { - - private final String testKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); + private final String testKey002 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key1"); private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(0); - private String httpSoliditynode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); - private String httpPbftNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(4); - - - @Test(enabled = true, description = "http request with Negative content-length", groups = {"daily", "serial"}) + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); + private String httpSoliditynode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); + private String httpPbftNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(4); + + @Test( + enabled = true, + description = "http request with Negative content-length", + groups = {"daily", "serial"}) public void test001RequestWithNegativeContentLength() { try { - String cmd = String.format("curl -s --location http://%s/wallet/getnowblock --header Content-Length:-1", httpnode); + String cmd = + String.format( + "curl -s --location http://%s/wallet/getnowblock --header Content-Length:-1", + httpnode); String returnString = PublicMethod.exec(cmd); logger.info(returnString); - Assert.assertTrue(returnString - .contains("

Bad Message 400

reason: Invalid Content-Length Value
")); - - String cmd2 = String.format("curl -s --location http://%s/wallet/getnowblock --header Content-Length:+100", httpnode); + Assert.assertTrue( + returnString.contains( + "

Bad Message 400

reason: Invalid Content-Length Value
")); + + String cmd2 = + String.format( + "curl -s --location http://%s/wallet/getnowblock --header Content-Length:+100", + httpnode); String returnString2 = PublicMethod.exec(cmd2); logger.info(returnString2); - Assert.assertTrue(returnString2 - .contains("

Bad Message 400

reason: Invalid Content-Length Value
")); - }catch (Exception e) { + Assert.assertTrue( + returnString2.contains( + "

Bad Message 400

reason: Invalid Content-Length Value
")); + } catch (Exception e) { e.printStackTrace(); } } - - - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestEasyAccount001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestEasyAccount001.java index ba619d19..34501801 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestEasyAccount001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestEasyAccount001.java @@ -18,11 +18,11 @@ public class HttpTestEasyAccount001 { private static String assetIssueId; - private final String testKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); + private final String testKey002 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key1"); private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); long beforeEasyBalance = 0L; long afterEasyBalance = 0L; @@ -37,8 +37,8 @@ public class HttpTestEasyAccount001 { String assetKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private JSONObject responseContent; private HttpResponse response; - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(0); + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); private long now = System.currentTimeMillis(); private final long totalSupply = now; private String userPassword = "ps_" + now; @@ -48,10 +48,11 @@ public class HttpTestEasyAccount001 { private String generateAddress = null; private String generateHexAddress = null; - /** - * constructor. - */ - @Test(enabled = false, description = "Create address by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "Create address by http", + groups = {"daily", "serial"}) public void test01CreateAddress() { logger.info(userPassword); response = HttpMethod.createAddress(httpnode, userPassword); @@ -61,22 +62,27 @@ public void test01CreateAddress() { HttpMethod.printJsonContent(responseContent); easyAddress = responseContent.get("base58checkAddress").toString(); - //Send trx to easy account - response = HttpMethod - .sendCoin(httpnode, fromAddress, WalletClient.decodeFromBase58Check(easyAddress), 5000000L, + // Send trx to easy account + response = + HttpMethod.sendCoin( + httpnode, + fromAddress, + WalletClient.decodeFromBase58Check(easyAddress), + 5000000L, testKey002); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - beforeEasyBalance = HttpMethod.getBalance(httpnode, WalletClient.decodeFromBase58Check(easyAddress)); + beforeEasyBalance = + HttpMethod.getBalance(httpnode, WalletClient.decodeFromBase58Check(easyAddress)); logger.info("beforeEasyBalance: " + beforeEasyBalance); - } - /** - * constructor. - */ - @Test(enabled = false, description = "Generate address by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "Generate address by http", + groups = {"daily", "serial"}) public void test02GenerateAddress() { response = HttpMethod.generateAddress(httpnode); logger.info("code is " + response.getStatusLine().getStatusCode()); @@ -87,23 +93,27 @@ public void test02GenerateAddress() { generateHexAddress = responseContent.get("hexAddress").toString(); generatePriKey = responseContent.get("privateKey").toString(); - //Send trx to easy account - response = HttpMethod - .sendCoin(httpnode, fromAddress, WalletClient.decodeFromBase58Check(generateAddress), 5000000L, + // Send trx to easy account + response = + HttpMethod.sendCoin( + httpnode, + fromAddress, + WalletClient.decodeFromBase58Check(generateAddress), + 5000000L, testKey002); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - beforeGenerateBalance = HttpMethod - .getBalance(httpnode, WalletClient.decodeFromBase58Check(generateAddress)); + beforeGenerateBalance = + HttpMethod.getBalance(httpnode, WalletClient.decodeFromBase58Check(generateAddress)); logger.info("beforeGenerateBalance: " + beforeGenerateBalance); } - - /** - * constructor. - */ - @Test(enabled = true, description = "Validate address by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Validate address by http", + groups = {"daily", "serial"}) public void test03ValideteAddress() { // Base58check format response = HttpMethod.validateAddress(httpnode, generateAddress); @@ -120,73 +130,91 @@ public void test03ValideteAddress() { HttpMethod.printJsonContent(responseContent); } - - /** - * constructor. - */ - @Test(enabled = false, description = "Easy transfer by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "Easy transfer by http", + groups = {"daily", "serial"}) public void test04EasyTransfer() { - response = HttpMethod - .easyTransfer(httpnode, userPassword, WalletClient.decodeFromBase58Check(generateAddress), - 1000000L); + response = + HttpMethod.easyTransfer( + httpnode, userPassword, WalletClient.decodeFromBase58Check(generateAddress), 1000000L); logger.info("code is " + response.getStatusLine().getStatusCode()); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); HttpMethod.waitToProduceOneBlock(httpnode); - //Send trx to easy account - afterEasyBalance = HttpMethod.getBalance(httpnode, WalletClient.decodeFromBase58Check(easyAddress)); + // Send trx to easy account + afterEasyBalance = + HttpMethod.getBalance(httpnode, WalletClient.decodeFromBase58Check(easyAddress)); logger.info("afterEasyBalance: " + afterEasyBalance); - afterGenerateBalance = HttpMethod - .getBalance(httpnode, WalletClient.decodeFromBase58Check(generateAddress)); + afterGenerateBalance = + HttpMethod.getBalance(httpnode, WalletClient.decodeFromBase58Check(generateAddress)); logger.info("afterGenerateBalance: " + afterGenerateBalance); - Assert.assertEquals(beforeEasyBalance - afterEasyBalance, - afterGenerateBalance - beforeGenerateBalance); + Assert.assertEquals( + beforeEasyBalance - afterEasyBalance, afterGenerateBalance - beforeGenerateBalance); beforeEasyBalance = afterEasyBalance; beforeGenerateBalance = afterGenerateBalance; } - /** - * constructor. - */ - @Test(enabled = false, description = "Easy transfer by privateKey by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "Easy transfer by privateKey by http", + groups = {"daily", "serial"}) public void test05EasyTransferByPrivateKey() { - response = HttpMethod - .easyTransferByPrivate(httpnode, generatePriKey, WalletClient.decodeFromBase58Check(easyAddress), - 1000000L); + response = + HttpMethod.easyTransferByPrivate( + httpnode, generatePriKey, WalletClient.decodeFromBase58Check(easyAddress), 1000000L); logger.info("code is " + response.getStatusLine().getStatusCode()); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); HttpMethod.waitToProduceOneBlock(httpnode); - //Send trx to easy account - afterEasyBalance = HttpMethod.getBalance(httpnode, WalletClient.decodeFromBase58Check(easyAddress)); + // Send trx to easy account + afterEasyBalance = + HttpMethod.getBalance(httpnode, WalletClient.decodeFromBase58Check(easyAddress)); logger.info("beforeEasyBalance: " + beforeEasyBalance); logger.info("afterEasyBalance: " + afterEasyBalance); - afterGenerateBalance = HttpMethod - .getBalance(httpnode, WalletClient.decodeFromBase58Check(generateAddress)); + afterGenerateBalance = + HttpMethod.getBalance(httpnode, WalletClient.decodeFromBase58Check(generateAddress)); logger.info("beforeGenerateBalance: " + beforeGenerateBalance); logger.info("afterGenerateBalance: " + afterGenerateBalance); - Assert.assertEquals(beforeGenerateBalance - afterGenerateBalance, - afterEasyBalance - beforeEasyBalance); + Assert.assertEquals( + beforeGenerateBalance - afterGenerateBalance, afterEasyBalance - beforeEasyBalance); } - /** - * constructor. - */ - @Test(enabled = false, description = "Create asset issue by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "Create asset issue by http", + groups = {"daily", "serial"}) public void test06CreateAssetIssue() { Long amount = 2048000000L; response = HttpMethod.sendCoin(httpnode, fromAddress, assetAddress, amount, testKey002); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - //Create an asset issue - response = HttpMethod - .assetIssue(httpnode, assetAddress, assetName, assetName, totalSupply, 1, 1, - System.currentTimeMillis() + 5000, System.currentTimeMillis() + 50000000, 2, 3, - description, url, 1000L, 1000L, assetKey); + // Create an asset issue + response = + HttpMethod.assetIssue( + httpnode, + assetAddress, + assetName, + assetName, + totalSupply, + 1, + 1, + System.currentTimeMillis() + 5000, + System.currentTimeMillis() + 50000000, + 2, + 3, + description, + url, + 1000L, + 1000L, + assetKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); @@ -198,28 +226,38 @@ public void test06CreateAssetIssue() { logger.info(assetIssueId); Assert.assertTrue(Integer.parseInt(assetIssueId) > 1000000); - response = HttpMethod - .transferAsset(httpnode, assetAddress, WalletClient.decodeFromBase58Check(easyAddress), - assetIssueId, 100L, assetKey); + response = + HttpMethod.transferAsset( + httpnode, + assetAddress, + WalletClient.decodeFromBase58Check(easyAddress), + assetIssueId, + 100L, + assetKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getAccount(httpnode, WalletClient.decodeFromBase58Check(easyAddress)); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - beforeEasyAsset = responseContent.getJSONArray("assetV2").getJSONObject(0) - .getLongValue("value"); + beforeEasyAsset = + responseContent.getJSONArray("assetV2").getJSONObject(0).getLongValue("value"); logger.info("beforeEasyAsset:" + beforeEasyAsset); } - /** - * constructor. - */ - @Test(enabled = false, description = "Easy transfer asset by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "Easy transfer asset by http", + groups = {"daily", "serial"}) public void test07EasyTransferAsset() { - response = HttpMethod - .easyTransferAsset(httpnode, userPassword, WalletClient.decodeFromBase58Check(generateAddress), - 10L, assetIssueId); + response = + HttpMethod.easyTransferAsset( + httpnode, + userPassword, + WalletClient.decodeFromBase58Check(generateAddress), + 10L, + assetIssueId); logger.info("code is " + response.getStatusLine().getStatusCode()); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); HttpMethod.waitToProduceOneBlock(httpnode); @@ -233,20 +271,26 @@ public void test07EasyTransferAsset() { response = HttpMethod.getAccount(httpnode, WalletClient.decodeFromBase58Check(generateAddress)); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - beforeGenerateAsset = responseContent.getJSONArray("assetV2").getJSONObject(0) - .getLongValue("value"); + beforeGenerateAsset = + responseContent.getJSONArray("assetV2").getJSONObject(0).getLongValue("value"); logger.info("beforeGenerateAsset:" + beforeGenerateAsset); Assert.assertEquals(beforeEasyAsset - afterEasyAsset, beforeGenerateAsset); beforeEasyAsset = afterEasyAsset; } - /** - * constructor. - */ - @Test(enabled = false, description = "Easy transfer asset by private key by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "Easy transfer asset by private key by http", + groups = {"daily", "serial"}) public void test08EasyTransferAssetByPrivateKey() { - response = HttpMethod.easyTransferAssetByPrivate(httpnode, generatePriKey, - WalletClient.decodeFromBase58Check(easyAddress), 5L, assetIssueId); + response = + HttpMethod.easyTransferAssetByPrivate( + httpnode, + generatePriKey, + WalletClient.decodeFromBase58Check(easyAddress), + 5L, + assetIssueId); logger.info("code is " + response.getStatusLine().getStatusCode()); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); HttpMethod.waitToProduceOneBlock(httpnode); @@ -261,21 +305,18 @@ public void test08EasyTransferAssetByPrivateKey() { response = HttpMethod.getAccount(httpnode, WalletClient.decodeFromBase58Check(generateAddress)); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - afterGenerateAsset = responseContent.getJSONArray("assetV2").getJSONObject(0) - .getLongValue("value"); + afterGenerateAsset = + responseContent.getJSONArray("assetV2").getJSONObject(0).getLongValue("value"); logger.info("afterGenerateAsset:" + afterGenerateAsset); Assert.assertEquals(beforeGenerateAsset - afterGenerateAsset, afterEasyAsset - beforeEasyAsset); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - HttpMethod.freeResource(httpnode, WalletClient.decodeFromBase58Check(generateAddress), fromAddress, - generatePriKey); + HttpMethod.freeResource( + httpnode, WalletClient.decodeFromBase58Check(generateAddress), fromAddress, generatePriKey); HttpMethod.freeResource(httpnode, assetAddress, fromAddress, assetKey); HttpMethod.disConnect(); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestEstimateEnergy.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestEstimateEnergy.java index 51d6f8b1..488cb6cf 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestEstimateEnergy.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestEstimateEnergy.java @@ -1,35 +1,32 @@ package stest.tron.wallet.dailybuild.http; -import java.util.HashMap; import com.alibaba.fastjson.JSONObject; import com.google.protobuf.ByteString; -import java.util.Optional; +import java.util.HashMap; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; import org.junit.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.tron.protos.Protocol; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.HttpMethod; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class HttpTestEstimateEnergy extends TronBaseTest { private JSONObject responseContent; +public class HttpTestEstimateEnergy extends TronBaseTest { + private JSONObject responseContent; private HttpResponse response; - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(1); - private String httpSoliditynode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(5); - private String httpPbftNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(6); + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(1); + private String httpSoliditynode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(5); + private String httpPbftNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(6); private byte[] contractAddress = null; long deployContractEnergy = 0; long energyFee; @@ -39,19 +36,32 @@ public class HttpTestEstimateEnergy extends TronBaseTest { private JSONObject r byte[] triggerAddress = triggerECKey.getAddress(); String triggerKey = ByteArray.toHexString(triggerECKey.getPrivKeyBytes()); - @BeforeClass - public void beforeClass() { Assert.assertTrue(PublicMethod.sendcoin(triggerAddress, 10000000000L, - foundationAddress, foundationKey, blockingStubFull)); + public void beforeClass() { + Assert.assertTrue( + PublicMethod.sendcoin( + triggerAddress, 10000000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/estimateenergy.sol"; - String contractName = "TCtoken"; + String filePath = "src/test/resources/soliditycode/estimateenergy.sol"; + String contractName = "TCtoken"; HashMap retMap = PublicMethod.getBycodeAbiNoOptimize(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - String txid = HttpMethod.deployContractGetTxid(httpnode, contractName, abi, code, 10000L, - 1000000000L, 100, 10000L, - 0L, null, 0L, triggerAddress, triggerKey); + String txid = + HttpMethod.deployContractGetTxid( + httpnode, + contractName, + abi, + code, + 10000L, + 1000000000L, + 100, + 10000L, + 0L, + null, + 0L, + triggerAddress, + triggerKey); HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getTransactionInfoById(httpnode, txid); responseContent = HttpMethod.parseResponseContent(response); @@ -60,199 +70,246 @@ public void beforeClass() { Assert.assertTrue(PublicMethod.sendcoin(triggerAd deployContractEnergy = responseContent.getJSONObject("receipt").getLong("energy_usage_total"); HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); energyFee = PublicMethod.getChainParametersValue("getEnergyFee", blockingStubFull); - } - /** - * constructor. - */ - @Test(enabled = true, description = "EstimateEnergy request fullnode,solidity,pbft", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "EstimateEnergy request fullnode,solidity,pbft", + groups = {"daily", "serial"}) public void test01EstimateCanGetValue() { String method = "writeNumber(uint256)"; - String param = "0000000000000000000000000000000000000000000000000000000000000006"; - response = HttpMethod - .getEstimateEnergy(httpnode, foundationAddress, contractAddress, method, param, null,false, 0, 0, 0); - Long energyRequired = HttpMethod.parseResponseContent(response).getLong("energy_required"); + String param = "0000000000000000000000000000000000000000000000000000000000000006"; + response = + HttpMethod.getEstimateEnergy( + httpnode, foundationAddress, contractAddress, method, param, null, false, 0, 0, 0); + Long energyRequired = HttpMethod.parseResponseContent(response).getLong("energy_required"); Assert.assertTrue(energyRequired >= 0); HttpMethod.waitToProduceOneBlock(httpnode); - response = HttpMethod - .getEstimateEnergySolidity( + response = + HttpMethod.getEstimateEnergySolidity( httpSoliditynode, foundationAddress, contractAddress, method, param, false); - Long energyRequiredSolidity = + Long energyRequiredSolidity = HttpMethod.parseResponseContent(response).getLong("energy_required"); Assert.assertTrue(energyRequiredSolidity >= 0); - response = HttpMethod - .getEstimateEnergyPBFT( + response = + HttpMethod.getEstimateEnergyPBFT( httpPbftNode, foundationAddress, contractAddress, method, param, false); - Long energyRequiredPbft = HttpMethod.parseResponseContent(response).getLong("energy_required"); + Long energyRequiredPbft = HttpMethod.parseResponseContent(response).getLong("energy_required"); Assert.assertTrue(energyRequiredPbft >= 0); Assert.assertEquals(energyRequired.longValue(), energyRequiredSolidity.longValue()); Assert.assertEquals(energyRequired.longValue(), energyRequiredPbft.longValue()); } - /** - * constructor. - */ - @Test(enabled = true, description = "EstimateEnergy value compare to TriggerConstantContract", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "EstimateEnergy value compare to TriggerConstantContract", + groups = {"daily", "serial"}) public void test02CompareToTriggerConstantContract() { String method = "writeNumber(uint256)"; - String param = "0000000000000000000000000000000000000000000000000000000000000006"; - response = HttpMethod - .getEstimateEnergy(httpnode, foundationAddress, contractAddress, method, param, null,true, 0, 0, 0); - Long energyRequired = HttpMethod.parseResponseContent(response).getLong("energy_required"); + String param = "0000000000000000000000000000000000000000000000000000000000000006"; + response = + HttpMethod.getEstimateEnergy( + httpnode, foundationAddress, contractAddress, method, param, null, true, 0, 0, 0); + Long energyRequired = HttpMethod.parseResponseContent(response).getLong("energy_required"); Assert.assertTrue(energyRequired >= 0); - response = HttpMethod - .triggerConstantContract( + response = + HttpMethod.triggerConstantContract( httpnode, foundationAddress, ByteArray.toHexString(contractAddress), method, param); - Long energyRequiredConstant = - HttpMethod.parseResponseContent(response).getLong("energy_used"); - final Long energyFee = PublicMethod.getChainParametersValue("getEnergyFee", blockingStubFull); + Long energyRequiredConstant = HttpMethod.parseResponseContent(response).getLong("energy_used"); + final Long energyFee = PublicMethod.getChainParametersValue("getEnergyFee", blockingStubFull); logger.info("energyRequired: " + energyRequired); logger.info("energyRequiredConstant: " + energyRequiredConstant); Assert.assertTrue(energyRequired >= energyRequiredConstant); Assert.assertTrue((energyRequired - energyRequiredConstant) * energyFee <= 1000000L); } - /** - * constructor. - */ - @Test(enabled = true, description = "Estimate energy deploy contract", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Estimate energy deploy contract", + groups = {"daily", "serial"}) public void test03EstimateDeployContract() { String method = null; - String param = null; - response = HttpMethod - .getEstimateEnergy(httpnode, foundationAddress, null, method, param, code,true, 0, 0, 0); - Long energyRequired = HttpMethod.parseResponseContent(response).getLong("energy_required"); + String param = null; + response = + HttpMethod.getEstimateEnergy( + httpnode, foundationAddress, null, method, param, code, true, 0, 0, 0); + Long energyRequired = HttpMethod.parseResponseContent(response).getLong("energy_required"); Assert.assertTrue(energyRequired >= 0); - response = HttpMethod - .triggerConstantContractWithData( + response = + HttpMethod.triggerConstantContractWithData( httpnode, foundationAddress, null, method, param, code, 0, 0, 0); - Long energyRequiredConstant = - HttpMethod.parseResponseContent(response).getLong("energy_used"); + Long energyRequiredConstant = HttpMethod.parseResponseContent(response).getLong("energy_used"); logger.info("energyRequired: " + energyRequired); logger.info("energyRequiredConstant: " + energyRequiredConstant); logger.info("deployEnergyCost: " + deployContractEnergy); Assert.assertTrue(energyRequired >= energyRequiredConstant); Assert.assertTrue((energyRequired - energyRequiredConstant) * energyFee <= 1000000L); Assert.assertTrue((energyRequired - deployContractEnergy) * energyFee <= 1000000L); - } - /** - * constructor. - */ - @Test(enabled = true, description = "Estimate function out_of_time by estimateEnergy and triggerConstant", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Estimate function out_of_time by estimateEnergy and triggerConstant", + groups = {"daily", "serial"}) public void test04EstimateWithCallvalueAndCommandAfterCall() { String method = "testUseCpu(int256)"; - String args = "00000000000000000000000000000000000000000000000000000000001324b0"; - response = HttpMethod - .getEstimateEnergy(httpnode, foundationAddress, contractAddress, method, args, null,true, 0, 0, 0); + String args = "00000000000000000000000000000000000000000000000000000000001324b0"; + response = + HttpMethod.getEstimateEnergy( + httpnode, foundationAddress, contractAddress, method, args, null, true, 0, 0, 0); responseContent = HttpMethod.parseResponseContent(response); logger.info("EstimateEnergy result: " + responseContent.toJSONString()); - Assert.assertTrue( responseContent.containsKey("result")); + Assert.assertTrue(responseContent.containsKey("result")); JSONObject res = responseContent.getJSONObject("result"); Assert.assertEquals(2, res.keySet().size()); Assert.assertEquals("OTHER_ERROR".toLowerCase(), res.getString("code").toLowerCase()); - Assert.assertTrue( res.getString("message").contains("CPU timeout")); + Assert.assertTrue(res.getString("message").contains("CPU timeout")); - response = HttpMethod - .triggerConstantContractWithData( - httpnode, foundationAddress, ByteArray.toHexString(contractAddress), method, args,null,0,0,0); + response = + HttpMethod.triggerConstantContractWithData( + httpnode, + foundationAddress, + ByteArray.toHexString(contractAddress), + method, + args, + null, + 0, + 0, + 0); responseContent = HttpMethod.parseResponseContent(response); logger.info("triggerconstant result: " + responseContent); - Assert.assertTrue( responseContent.containsKey("result")); + Assert.assertTrue(responseContent.containsKey("result")); res = responseContent.getJSONObject("result"); Assert.assertEquals(2, res.keySet().size()); Assert.assertEquals("OTHER_ERROR".toLowerCase(), res.getString("code").toLowerCase()); - Assert.assertTrue(ByteString.copyFrom(ByteArray.fromHexString(res.getString("message"))).toStringUtf8().contains("CPU timeout")); + Assert.assertTrue( + ByteString.copyFrom(ByteArray.fromHexString(res.getString("message"))) + .toStringUtf8() + .contains("CPU timeout")); } - /** - * constructor. - */ - @Test(enabled = true, description = "estimateEnergy and triggerconstantcontract " - + "without function_selector but with contract address and data ", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = + "estimateEnergy and triggerconstantcontract " + + "without function_selector but with contract address and data ", + groups = {"daily", "serial"}) public void test05EstimateOnlyHasCalldata() { // function is writeNumber(uint256); - String data = "5637a79c0000000000000000000000000000000000000000000000000000000000000006"; - response = HttpMethod - .getEstimateEnergy(httpnode, foundationAddress, contractAddress, null, null, data,true, 0, 0, 0); - Long energyRequired = HttpMethod.parseResponseContent(response).getLong("energy_required"); + String data = "5637a79c0000000000000000000000000000000000000000000000000000000000000006"; + response = + HttpMethod.getEstimateEnergy( + httpnode, foundationAddress, contractAddress, null, null, data, true, 0, 0, 0); + Long energyRequired = HttpMethod.parseResponseContent(response).getLong("energy_required"); Assert.assertTrue(energyRequired >= 0); - response = HttpMethod - .triggerConstantContractWithData( - httpnode, foundationAddress, ByteArray.toHexString(contractAddress), null, null,data,0,0,0); - Long energyRequiredConstant = - HttpMethod.parseResponseContent(response).getLong("energy_used"); + response = + HttpMethod.triggerConstantContractWithData( + httpnode, + foundationAddress, + ByteArray.toHexString(contractAddress), + null, + null, + data, + 0, + 0, + 0); + Long energyRequiredConstant = HttpMethod.parseResponseContent(response).getLong("energy_used"); logger.info("energyRequired: " + energyRequired); logger.info("energyRequiredConstant" + energyRequiredConstant); Assert.assertTrue(energyRequired >= energyRequiredConstant); Assert.assertTrue((energyRequired - energyRequiredConstant) * energyFee <= 1000000L); } - - /** - * constructor. - */ - @Test(enabled = true, description = "estimateEnergy and triggerconstantcontract " - + "only with contract address. and it will trigger fallback function ", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = + "estimateEnergy and triggerconstantcontract " + + "only with contract address. and it will trigger fallback function ", + groups = {"daily", "serial"}) public void test06EstimateOnlyContractAddress() { - response = HttpMethod - .getEstimateEnergy(httpnode, foundationAddress, contractAddress, null, null, null,true, 0, 0, 0); - Long energyRequired = HttpMethod.parseResponseContent(response).getLong("energy_required"); + response = + HttpMethod.getEstimateEnergy( + httpnode, foundationAddress, contractAddress, null, null, null, true, 0, 0, 0); + Long energyRequired = HttpMethod.parseResponseContent(response).getLong("energy_required"); Assert.assertTrue(energyRequired >= 0); - response = HttpMethod - .triggerConstantContractWithData( - httpnode, foundationAddress, ByteArray.toHexString(contractAddress), null, null,null,0,0,0); + response = + HttpMethod.triggerConstantContractWithData( + httpnode, + foundationAddress, + ByteArray.toHexString(contractAddress), + null, + null, + null, + 0, + 0, + 0); responseContent = HttpMethod.parseResponseContent(response); logger.info(responseContent.toJSONString()); Assert.assertTrue(responseContent.getJSONObject("result").getBoolean("result")); Assert.assertEquals(1, responseContent.getJSONArray("logs").size()); - Long energyRequiredConstant = responseContent.getLong("energy_used"); + Long energyRequiredConstant = responseContent.getLong("energy_used"); logger.info("energyRequired: " + energyRequired); logger.info("energyRequiredConstant" + energyRequiredConstant); Assert.assertTrue(energyRequired >= energyRequiredConstant); Assert.assertTrue((energyRequired - energyRequiredConstant) * energyFee <= 1000000L); } - - /** - * constructor. - */ - @Test(enabled = true, description = "estimateEnergy and triggerconstantcontract " - + "with contract address, function_selector and data. and it will triggerContract use function_selector ", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = + "estimateEnergy and triggerconstantcontract " + + "with contract address, function_selector and data. and it will triggerContract use" + + " function_selector ", + groups = {"daily", "serial"}) public void test07EstimatePreferFunctionSelector() { String method = "writeNumber(uint256)"; - String param = "0000000000000000000000000000000000000000000000000000000000000006"; - //testUseCpu(int256) + String param = "0000000000000000000000000000000000000000000000000000000000000006"; + // testUseCpu(int256) String data = "56d14afe00000000000000000000000000000000000000000000000000000000001324b0"; - response = HttpMethod - .getEstimateEnergy(httpnode, foundationAddress, contractAddress, method, param, data,true, 0, 0, 0); - Long energyRequired = HttpMethod.parseResponseContent(response).getLong("energy_required"); + response = + HttpMethod.getEstimateEnergy( + httpnode, foundationAddress, contractAddress, method, param, data, true, 0, 0, 0); + Long energyRequired = HttpMethod.parseResponseContent(response).getLong("energy_required"); Assert.assertTrue(energyRequired >= 0); - response = HttpMethod - .triggerConstantContractWithData( - httpnode, foundationAddress, ByteArray.toHexString(contractAddress), method, param, data,0,0,0); + response = + HttpMethod.triggerConstantContractWithData( + httpnode, + foundationAddress, + ByteArray.toHexString(contractAddress), + method, + param, + data, + 0, + 0, + 0); responseContent = HttpMethod.parseResponseContent(response); logger.info(responseContent.toJSONString()); - Long energyRequiredConstant = responseContent.getLong("energy_used"); + Long energyRequiredConstant = responseContent.getLong("energy_used"); logger.info("energyRequired: " + energyRequired); logger.info("energyRequiredConstant" + energyRequiredConstant); Assert.assertTrue(energyRequired >= energyRequiredConstant); Assert.assertTrue((energyRequired - energyRequiredConstant) * energyFee <= 1000000L); } - /** - * constructor. - */ - @Test(enabled = true, description = "triggerSmartContract using data", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "triggerSmartContract using data", + groups = {"daily", "serial"}) public void test08triggerSmartContractWithData() { - //testUseCpu(int256) + // testUseCpu(int256) String data = "56d14afe00000000000000000000000000000000000000000000000000000000001324b0"; - String contractHex = ByteArray.toHexString(contractAddress); - String txid = + String contractHex = ByteArray.toHexString(contractAddress); + String txid = HttpMethod.triggerContractGetTxid( httpnode, triggerAddress, @@ -275,11 +332,9 @@ public void test08triggerSmartContractWithData() { Assert.assertEquals("OUT_OF_TIME".toLowerCase(), res.getString("contractRet").toLowerCase()); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - HttpMethod.disConnect(); } - + HttpMethod.disConnect(); + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestExchange001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestExchange001.java index 8d3dd57d..b9f7f89f 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestExchange001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestExchange001.java @@ -29,8 +29,8 @@ public class HttpTestExchange001 { private static Long afterWithdrawBalance; private static Long beforeTransactionBalance; private static Long afterTransactionBalance; - private final String testKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); + private final String testKey002 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key1"); private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] exchangeOwnerAddress = ecKey1.getAddress(); @@ -39,41 +39,71 @@ public class HttpTestExchange001 { byte[] asset2Address = ecKey2.getAddress(); String asset2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); Long amount = 2048000000L; - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private JSONObject responseContent; private HttpResponse response; - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(1); - private String httpSoliditynode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); - private String httpPbftNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(4); - - - /** - * constructor. - */ - @Test(enabled = false, description = "Create asset issue by http", groups = {"daily", "serial"}) + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(1); + private String httpSoliditynode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); + private String httpPbftNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(4); + + /** constructor. */ + @Test( + enabled = false, + description = "Create asset issue by http", + groups = {"daily", "serial"}) public void test01CreateExchange() { - response = HttpMethod - .sendCoin(httpnode, fromAddress, exchangeOwnerAddress, 2048000000L, testKey002); + response = + HttpMethod.sendCoin(httpnode, fromAddress, exchangeOwnerAddress, 2048000000L, testKey002); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.sendCoin(httpnode, fromAddress, asset2Address, amount, testKey002); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - //Create an asset issue - response = HttpMethod.assetIssue(httpnode, exchangeOwnerAddress, name, name, totalSupply, 1, 1, - System.currentTimeMillis() + 5000, System.currentTimeMillis() + 50000000, 2, 3, description, - url, 1000L, 1000L, exchangeOwnerKey); + // Create an asset issue + response = + HttpMethod.assetIssue( + httpnode, + exchangeOwnerAddress, + name, + name, + totalSupply, + 1, + 1, + System.currentTimeMillis() + 5000, + System.currentTimeMillis() + 50000000, + 2, + 3, + description, + url, + 1000L, + 1000L, + exchangeOwnerKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - response = HttpMethod.assetIssue(httpnode, asset2Address, name, name, totalSupply, 1, 1, - System.currentTimeMillis() + 5000, System.currentTimeMillis() + 50000000, 2, 3, description, - url, 1000L, 1000L, asset2Key); + response = + HttpMethod.assetIssue( + httpnode, + asset2Address, + name, + name, + totalSupply, + 1, + 1, + System.currentTimeMillis() + 5000, + System.currentTimeMillis() + 50000000, + 2, + 3, + description, + url, + 1000L, + 1000L, + asset2Key); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); @@ -87,24 +117,31 @@ public void test01CreateExchange() { assetIssueId2 = responseContent.getString("asset_issued_ID"); Assert.assertTrue(Integer.parseInt(assetIssueId2) > 1000000); - response = HttpMethod - .transferAsset(httpnode, asset2Address, exchangeOwnerAddress, assetIssueId2, 10000000000L, - asset2Key); + response = + HttpMethod.transferAsset( + httpnode, asset2Address, exchangeOwnerAddress, assetIssueId2, 10000000000L, asset2Key); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - //Create exchange. - response = HttpMethod - .exchangeCreate(httpnode, exchangeOwnerAddress, assetIssueId1, 1000000L, assetIssueId2, - 1000000L, exchangeOwnerKey); + // Create exchange. + response = + HttpMethod.exchangeCreate( + httpnode, + exchangeOwnerAddress, + assetIssueId1, + 1000000L, + assetIssueId2, + 1000000L, + exchangeOwnerKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); } - /** - * constructor. - */ - @Test(enabled = false, description = "List exchanges by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "List exchanges by http", + groups = {"daily", "serial"}) public void test02ListExchange() { response = HttpMethod.listExchanges(httpnode); responseContent = HttpMethod.parseResponseContent(response); @@ -114,10 +151,11 @@ public void test02ListExchange() { exchangeId = jsonArray.size(); } - /** - * constructor. - */ - @Test(enabled = false, description = "List exchanges from solidity by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "List exchanges from solidity by http", + groups = {"daily", "serial"}) public void test03ListExchangeFromSolidity() { HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); response = HttpMethod.listExchangesFromSolidity(httpSoliditynode); @@ -128,10 +166,11 @@ public void test03ListExchangeFromSolidity() { exchangeId = jsonArray.size(); } - /** - * constructor. - */ - @Test(enabled = false, description = "List exchanges from PBFT by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "List exchanges from PBFT by http", + groups = {"daily", "serial"}) public void test04ListExchangeFromPbft() { HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); response = HttpMethod.listExchangesFromPbft(httpPbftNode); @@ -142,65 +181,67 @@ public void test04ListExchangeFromPbft() { exchangeId = jsonArray.size(); } - - /** - * constructor. - */ - @Test(enabled = false, description = "GetExchangeById by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetExchangeById by http", + groups = {"daily", "serial"}) public void test05GetExchangeById() { response = HttpMethod.getExchangeById(httpnode, exchangeId); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); Assert.assertTrue(responseContent.getInteger("exchange_id").equals(exchangeId)); - Assert.assertEquals(responseContent.getString("creator_address"), - ByteArray.toHexString(exchangeOwnerAddress)); + Assert.assertEquals( + responseContent.getString("creator_address"), ByteArray.toHexString(exchangeOwnerAddress)); beforeInjectBalance = responseContent.getLong("first_token_balance"); logger.info("beforeInjectBalance" + beforeInjectBalance); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetExchangeById from solidity by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetExchangeById from solidity by http", + groups = {"daily", "serial"}) public void test06GetExchangeByIdFromSolidity() { response = HttpMethod.getExchangeByIdFromSolidity(httpSoliditynode, exchangeId); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); Assert.assertTrue(responseContent.getInteger("exchange_id").equals(exchangeId)); - Assert.assertEquals(responseContent.getString("creator_address"), - ByteArray.toHexString(exchangeOwnerAddress)); + Assert.assertEquals( + responseContent.getString("creator_address"), ByteArray.toHexString(exchangeOwnerAddress)); beforeInjectBalance = responseContent.getLong("first_token_balance"); logger.info("beforeInjectBalance" + beforeInjectBalance); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetExchangeById from Pbft by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetExchangeById from Pbft by http", + groups = {"daily", "serial"}) public void test07GetExchangeByIdFromPbft() { response = HttpMethod.getExchangeByIdFromPbft(httpPbftNode, exchangeId); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); Assert.assertTrue(responseContent.getInteger("exchange_id").equals(exchangeId)); - Assert.assertEquals(responseContent.getString("creator_address"), - ByteArray.toHexString(exchangeOwnerAddress)); + Assert.assertEquals( + responseContent.getString("creator_address"), ByteArray.toHexString(exchangeOwnerAddress)); beforeInjectBalance = responseContent.getLong("first_token_balance"); logger.info("beforeInjectBalance" + beforeInjectBalance); } - - /** - * constructor. - */ - @Test(enabled = false, description = "Inject exchange by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "Inject exchange by http", + groups = {"daily", "serial"}) public void test08InjectExchange() { - //Inject exchange. - response = HttpMethod - .exchangeInject(httpnode, exchangeOwnerAddress, exchangeId, assetIssueId1, 300L, - exchangeOwnerKey); + // Inject exchange. + response = + HttpMethod.exchangeInject( + httpnode, exchangeOwnerAddress, exchangeId, assetIssueId1, 300L, exchangeOwnerKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getExchangeById(httpnode, exchangeId); @@ -214,15 +255,16 @@ public void test08InjectExchange() { beforeWithdrawBalance = afterInjectBalance; } - /** - * constructor. - */ - @Test(enabled = false, description = "Withdraw exchange by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "Withdraw exchange by http", + groups = {"daily", "serial"}) public void test09WithdrawExchange() { - //Withdraw exchange. - response = HttpMethod - .exchangeWithdraw(httpnode, exchangeOwnerAddress, exchangeId, assetIssueId1, 170L, - exchangeOwnerKey); + // Withdraw exchange. + response = + HttpMethod.exchangeWithdraw( + httpnode, exchangeOwnerAddress, exchangeId, assetIssueId1, 170L, exchangeOwnerKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getExchangeById(httpnode, exchangeId); @@ -235,15 +277,16 @@ public void test09WithdrawExchange() { beforeTransactionBalance = afterWithdrawBalance; } - /** - * constructor. - */ - @Test(enabled = false, description = "Transaction exchange by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "Transaction exchange by http", + groups = {"daily", "serial"}) public void test10TransactionExchange() { - //Transaction exchange. - response = HttpMethod - .exchangeTransaction(httpnode, exchangeOwnerAddress, exchangeId, assetIssueId1, 100L, 1L, - exchangeOwnerKey); + // Transaction exchange. + response = + HttpMethod.exchangeTransaction( + httpnode, exchangeOwnerAddress, exchangeId, assetIssueId1, 100L, 1L, exchangeOwnerKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getExchangeById(httpnode, exchangeId); @@ -255,11 +298,11 @@ public void test10TransactionExchange() { Assert.assertTrue(afterTransactionBalance - beforeTransactionBalance >= 1); } - - /** - * constructor. - */ - @Test(enabled = false, description = "Get asset issue list by name by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "Get asset issue list by name by http", + groups = {"daily", "serial"}) public void test11GetAssetIssueListByName() { response = HttpMethod.getAssetIssueListByName(httpnode, name); responseContent = HttpMethod.parseResponseContent(response); @@ -268,10 +311,11 @@ public void test11GetAssetIssueListByName() { Assert.assertTrue(jsonArray.size() >= 2); } - /** - * constructor. - */ - @Test(enabled = false, description = "Get asset issue list by name from solidity and pbft by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "Get asset issue list by name from solidity and pbft by http", + groups = {"daily", "serial"}) public void test12GetAssetIssueListByNameFromSolidityAndPbft() { HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); response = HttpMethod.getAssetIssueListByNameFromSolidity(httpSoliditynode, name); @@ -287,10 +331,11 @@ public void test12GetAssetIssueListByNameFromSolidityAndPbft() { Assert.assertTrue(jsonArray.size() >= 2); } - /** - * * constructor. * - */ - @Test(enabled = false, description = "Get paginated exchange list by http", groups = {"daily", "serial"}) + /** * constructor. * */ + @Test( + enabled = false, + description = "Get paginated exchange list by http", + groups = {"daily", "serial"}) public void test13GetPaginatedExchangeList() { response = HttpMethod.getPaginatedExchangeList(httpnode, 0, 1); @@ -302,13 +347,10 @@ public void test13GetPaginatedExchangeList() { Assert.assertTrue(jsonArray.size() == 1); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { HttpMethod.freeResource(httpnode, asset2Address, fromAddress, asset2Key); HttpMethod.disConnect(); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestFreezeV2001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestFreezeV2001.java index 115c1b24..ab3d7a9e 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestFreezeV2001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestFreezeV2001.java @@ -4,26 +4,27 @@ import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; -import org.bouncycastle.math.ec.ScaleYNegateXPointMap; import org.junit.Assert; import org.testng.SkipException; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; - - -/** - * - */ +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.Flaky; +import stest.tron.wallet.common.client.utils.HttpMethod; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.Utils; + +/** */ @Slf4j -@Flaky(reason = "HTTP API timing-sensitive: freeze/unfreeze operations", - since = "2026-04-03") +@Flaky(reason = "HTTP API timing-sensitive: freeze/unfreeze operations", since = "2026-04-03") public class HttpTestFreezeV2001 { - private final String testKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); + private final String testKey002 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key1"); private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] freezeBandwidthAddress = ecKey1.getAddress(); @@ -32,7 +33,6 @@ public class HttpTestFreezeV2001 { byte[] receiverResourceAddress = ecKey2.getAddress(); String receiverResourceKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - ECKey ecKey3 = new ECKey(Utils.getRandom()); byte[] freezeEnergyAddress = ecKey3.getAddress(); String freezeEnergyKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); @@ -40,10 +40,10 @@ public class HttpTestFreezeV2001 { ECKey ecKey4 = new ECKey(Utils.getRandom()); byte[] freezeForQuery = ecKey4.getAddress(); String freezeForQueryKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); - + Long beforeBalance; Long afterBalance; - + Long beforeFreezeBalance; Long afterFreezeBalance; Long amount = 40000000L; @@ -54,17 +54,14 @@ public class HttpTestFreezeV2001 { Long delegateAmount = 1000000L; private JSONObject responseContent; private HttpResponse response; - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(1); - private String httpSoliditynode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); - private String httpPbftNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(4); - - - /** - * constructor. - */ + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(1); + private String httpSoliditynode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); + private String httpPbftNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(4); + + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { if (!HttpMethod.proposalFreezeV2IsOpen(httpnode)) { @@ -72,67 +69,51 @@ public void beforeClass() { } PublicMethod.printAddress(freezeBandwidthKey); PublicMethod.printAddress(receiverResourceKey); - //Send trx to test account - response = HttpMethod - .sendCoin(httpnode, fromAddress, freezeBandwidthAddress, amount, testKey002); - response = HttpMethod - .sendCoin(httpnode, fromAddress, freezeEnergyAddress, amount, testKey002); - response = HttpMethod - .sendCoin(httpnode, fromAddress, receiverResourceAddress, 1L, testKey002); + // Send trx to test account + response = + HttpMethod.sendCoin(httpnode, fromAddress, freezeBandwidthAddress, amount, testKey002); + response = HttpMethod.sendCoin(httpnode, fromAddress, freezeEnergyAddress, amount, testKey002); + response = HttpMethod.sendCoin(httpnode, fromAddress, receiverResourceAddress, 1L, testKey002); response = HttpMethod.sendCoin(httpnode, fromAddress, freezeForQuery, amount * 100, testKey002); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - - } - - - /** - * constructor. - */ - @Test(enabled = true, description = "FreezeBalanceV2 for bandwidth by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "FreezeBalanceV2 for bandwidth by http", + groups = {"daily", "serial"}) public void test001FreezeBalanceV2ForBandwidth() { beforeBalance = HttpMethod.getBalance(httpnode, freezeBandwidthAddress); - //FreezeBalanceV2 balance - response = HttpMethod - .freezeBalanceV2( - httpnode, - freezeBandwidthAddress, - frozenBalance, - 0, - null, - freezeBandwidthKey - ); + // FreezeBalanceV2 balance + response = + HttpMethod.freezeBalanceV2( + httpnode, freezeBandwidthAddress, frozenBalance, 0, null, freezeBandwidthKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); afterBalance = HttpMethod.getBalance(httpnode, freezeBandwidthAddress); Assert.assertTrue(beforeBalance - afterBalance == frozenBalance); } - /** - * constructor. - */ - @Test(enabled = true, description = "UnFreezeBalanceV2 for bandwidth by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "UnFreezeBalanceV2 for bandwidth by http", + groups = {"daily", "serial"}) public void test002UnFreezeBalanceV2ForBandwidth() { beforeBalance = HttpMethod.getBalance(httpnode, freezeBandwidthAddress); - //UnFreezeBalanceV2 for bandwidth - response = HttpMethod - .unFreezeBalanceV2( - httpnode, - freezeBandwidthAddress, - unfrozenBalance, - 0, - freezeBandwidthKey - ); + // UnFreezeBalanceV2 for bandwidth + response = + HttpMethod.unFreezeBalanceV2( + httpnode, freezeBandwidthAddress, unfrozenBalance, 0, freezeBandwidthKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); afterBalance = HttpMethod.getBalance(httpnode, freezeBandwidthAddress); Assert.assertEquals(afterBalance, beforeBalance); - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getAccount(httpnode, freezeBandwidthAddress) - ); + responseContent = + HttpMethod.parseResponseContent(HttpMethod.getAccount(httpnode, freezeBandwidthAddress)); JSONArray unfrozenV2 = responseContent.getJSONArray("unfrozenV2"); Assert.assertTrue(unfrozenV2.size() == 1); @@ -149,56 +130,46 @@ public void test002UnFreezeBalanceV2ForBandwidth() { while (System.currentTimeMillis() < unfreezeExpireTime && retryTimes++ <= 100) { HttpMethod.waitToProduceOneBlock(httpnode); } - } - /** - * constructor. - */ - @Test(enabled = true, description = "FreezeBalanceV2 for energy by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "FreezeBalanceV2 for energy by http", + groups = {"daily", "serial"}) public void test003FreezeBalanceForEnergy() { beforeBalance = HttpMethod.getBalance(httpnode, freezeEnergyAddress); - //Freeze balance for energy - response = HttpMethod - .freezeBalanceV2( - httpnode, - freezeEnergyAddress, - frozenEnergyBalance, - 1, - null, - freezeEnergyKey - ); + // Freeze balance for energy + response = + HttpMethod.freezeBalanceV2( + httpnode, freezeEnergyAddress, frozenEnergyBalance, 1, null, freezeEnergyKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); afterBalance = HttpMethod.getBalance(httpnode, freezeEnergyAddress); Assert.assertTrue(beforeBalance - afterBalance == frozenEnergyBalance); } - /** - * constructor. - */ - @Test(enabled = true, description = "UnFreezeBalanceV2 for energy by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "UnFreezeBalanceV2 for energy by http", + groups = {"daily", "serial"}) public void test004UnFreezeBalanceForEnergy() { beforeBalance = HttpMethod.getBalance(httpnode, freezeEnergyAddress); HttpMethod.waitToProduceOneBlock(httpnode); - //UnFreeze balance for energy - response = HttpMethod.unFreezeBalanceV2( - httpnode, - freezeEnergyAddress, - unfrozenEnergyBalance, - 1, - freezeEnergyKey - ); + // UnFreeze balance for energy + response = + HttpMethod.unFreezeBalanceV2( + httpnode, freezeEnergyAddress, unfrozenEnergyBalance, 1, freezeEnergyKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); afterBalance = HttpMethod.getBalance(httpnode, freezeEnergyAddress); Assert.assertEquals(afterBalance, beforeBalance); - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getAccount(httpnode, freezeEnergyAddress) - ); + responseContent = + HttpMethod.parseResponseContent(HttpMethod.getAccount(httpnode, freezeEnergyAddress)); JSONArray unfrozenV2 = responseContent.getJSONArray("unfrozenV2"); Assert.assertTrue(unfrozenV2.size() == 1); @@ -209,193 +180,175 @@ public void test004UnFreezeBalanceForEnergy() { Assert.assertEquals(unfreezeAmount, unfrozenEnergyBalance); Assert.assertTrue(System.currentTimeMillis() < unfreezeExpireTime); Assert.assertEquals(unfrozenV2.getJSONObject(0).getString("type"), "ENERGY"); - - } - /** - * constructor. - */ - @Test(enabled = true, description = "DelegateResource of bandwidth for others by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "DelegateResource of bandwidth for others by http", + groups = {"daily", "serial"}) public void test005DelegateResourceOfBandwidthForOthers() { - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getAccount(httpnode, freezeBandwidthAddress) - ); + responseContent = + HttpMethod.parseResponseContent(HttpMethod.getAccount(httpnode, freezeBandwidthAddress)); JSONArray frozenV2 = responseContent.getJSONArray("frozenV2"); beforeFreezeBalance = frozenV2.getJSONObject(0).getLong("amount"); - //Freeze balance with bandwidth for others - response = HttpMethod.delegateresource( - httpnode, - freezeBandwidthAddress, - delegateAmount, - 0, - null, - null, - receiverResourceAddress, - freezeBandwidthKey - ); + // Freeze balance with bandwidth for others + response = + HttpMethod.delegateresource( + httpnode, + freezeBandwidthAddress, + delegateAmount, + 0, + null, + null, + receiverResourceAddress, + freezeBandwidthKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getAccount(httpnode, freezeBandwidthAddress) - ); + responseContent = + HttpMethod.parseResponseContent(HttpMethod.getAccount(httpnode, freezeBandwidthAddress)); frozenV2 = responseContent.getJSONArray("frozenV2"); - afterFreezeBalance = - frozenV2.getJSONObject(0).getLong("amount"); + afterFreezeBalance = frozenV2.getJSONObject(0).getLong("amount"); Assert.assertTrue(beforeFreezeBalance - afterFreezeBalance == delegateAmount); Long delegatedFrozenBalanceForBandwidth = responseContent.getLong("delegated_frozenV2_balance_for_bandwidth"); Assert.assertEquals(delegatedFrozenBalanceForBandwidth, delegateAmount); - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getAccount(httpnode, receiverResourceAddress) - ); + responseContent = + HttpMethod.parseResponseContent(HttpMethod.getAccount(httpnode, receiverResourceAddress)); Long acquiredDelegatedFrozenBalanceForBandwidth = responseContent.getLong("acquired_delegated_frozenV2_balance_for_bandwidth"); Assert.assertEquals(acquiredDelegatedFrozenBalanceForBandwidth, delegateAmount); - - } - - /** - * constructor. - */ - @Test(enabled = true, description = "UndelegateResource of bandwidth for others by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "UndelegateResource of bandwidth for others by http", + groups = {"daily", "serial"}) public void test006UndelegateResourceOfBandwidthForOthers() { - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getAccount(httpnode, freezeBandwidthAddress) - ); + responseContent = + HttpMethod.parseResponseContent(HttpMethod.getAccount(httpnode, freezeBandwidthAddress)); JSONArray frozenV2 = responseContent.getJSONArray("frozenV2"); beforeFreezeBalance = frozenV2.getJSONObject(0).getLong("amount"); - //Freeze balance with bandwidth for others - response = HttpMethod.unDelegateresource( - httpnode, - freezeBandwidthAddress, - delegateAmount, - 0, - receiverResourceAddress, - freezeBandwidthKey - ); + // Freeze balance with bandwidth for others + response = + HttpMethod.unDelegateresource( + httpnode, + freezeBandwidthAddress, + delegateAmount, + 0, + receiverResourceAddress, + freezeBandwidthKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getAccount(httpnode, freezeBandwidthAddress) - ); + responseContent = + HttpMethod.parseResponseContent(HttpMethod.getAccount(httpnode, freezeBandwidthAddress)); frozenV2 = responseContent.getJSONArray("frozenV2"); afterFreezeBalance = frozenV2.getJSONObject(0).getLong("amount"); Assert.assertTrue(beforeFreezeBalance - afterFreezeBalance == -delegateAmount); Long delegatedFrozenBalanceForBandwidth = responseContent.getLong("delegated_frozenV2_balance_for_bandwidth"); Assert.assertNull(delegatedFrozenBalanceForBandwidth); - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getAccount(httpnode, receiverResourceAddress) - ); + responseContent = + HttpMethod.parseResponseContent(HttpMethod.getAccount(httpnode, receiverResourceAddress)); Long acquiredDelegatedFrozenBalanceForBandwidth = responseContent.getLong("acquired_delegated_frozenV2_balance_for_bandwidth"); Assert.assertNull(acquiredDelegatedFrozenBalanceForBandwidth); } - - /** - * constructor. - */ - @Test(enabled = true, description = "DelegateResource of energy for others by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "DelegateResource of energy for others by http", + groups = {"daily", "serial"}) public void test007DelegateResourceOfEnergyForOthers() { - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getAccount(httpnode, freezeEnergyAddress) - ); + responseContent = + HttpMethod.parseResponseContent(HttpMethod.getAccount(httpnode, freezeEnergyAddress)); JSONArray frozenV2 = responseContent.getJSONArray("frozenV2"); beforeFreezeBalance = frozenV2.getJSONObject(1).getLong("amount"); - //Freeze balance with bandwidth for others - response = HttpMethod.delegateresource( - httpnode, - freezeEnergyAddress, - delegateAmount, - 1, - null, - null, - receiverResourceAddress, - freezeEnergyKey - ); + // Freeze balance with bandwidth for others + response = + HttpMethod.delegateresource( + httpnode, + freezeEnergyAddress, + delegateAmount, + 1, + null, + null, + receiverResourceAddress, + freezeEnergyKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getAccount(httpnode, freezeEnergyAddress) - ); + responseContent = + HttpMethod.parseResponseContent(HttpMethod.getAccount(httpnode, freezeEnergyAddress)); frozenV2 = responseContent.getJSONArray("frozenV2"); afterFreezeBalance = frozenV2.getJSONObject(1).getLong("amount"); Assert.assertTrue(beforeFreezeBalance - afterFreezeBalance == delegateAmount); Long delegatedFrozenBalanceForBandwidth = - responseContent.getJSONObject("account_resource") + responseContent + .getJSONObject("account_resource") .getLong("delegated_frozenV2_balance_for_energy"); Assert.assertEquals(delegatedFrozenBalanceForBandwidth, delegateAmount); - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getAccount(httpnode, receiverResourceAddress) - ); + responseContent = + HttpMethod.parseResponseContent(HttpMethod.getAccount(httpnode, receiverResourceAddress)); Long acquiredDelegatedFrozenBalanceForBandwidth = - responseContent.getJSONObject("account_resource") + responseContent + .getJSONObject("account_resource") .getLong("acquired_delegated_frozenV2_balance_for_energy"); Assert.assertEquals(acquiredDelegatedFrozenBalanceForBandwidth, delegateAmount); - - } - - /** - * constructor. - */ - @Test(enabled = true, description = "UndelegateResource of energy for others by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "UndelegateResource of energy for others by http", + groups = {"daily", "serial"}) public void test008UndelegateResourceOfEnergyForOthers() { - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getAccount(httpnode, freezeEnergyAddress) - ); + responseContent = + HttpMethod.parseResponseContent(HttpMethod.getAccount(httpnode, freezeEnergyAddress)); JSONArray frozenV2 = responseContent.getJSONArray("frozenV2"); beforeFreezeBalance = frozenV2.getJSONObject(1).getLong("amount"); - //Freeze balance with bandwidth for others - response = HttpMethod.unDelegateresource( - httpnode, - freezeEnergyAddress, - delegateAmount, - 1, - receiverResourceAddress, - freezeEnergyKey - ); + // Freeze balance with bandwidth for others + response = + HttpMethod.unDelegateresource( + httpnode, + freezeEnergyAddress, + delegateAmount, + 1, + receiverResourceAddress, + freezeEnergyKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getAccount(httpnode, freezeEnergyAddress) - ); + responseContent = + HttpMethod.parseResponseContent(HttpMethod.getAccount(httpnode, freezeEnergyAddress)); frozenV2 = responseContent.getJSONArray("frozenV2"); afterFreezeBalance = frozenV2.getJSONObject(1).getLong("amount"); Assert.assertTrue(beforeFreezeBalance - afterFreezeBalance == -delegateAmount); Long delegatedFrozenBalanceForEnergy = - responseContent.getJSONObject("account_resource") + responseContent + .getJSONObject("account_resource") .getLong("delegated_frozenV2_balance_for_energy"); Assert.assertNull(delegatedFrozenBalanceForEnergy); - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getAccount(httpnode, receiverResourceAddress) - ); + responseContent = + HttpMethod.parseResponseContent(HttpMethod.getAccount(httpnode, receiverResourceAddress)); Long acquiredDelegatedFrozenBalanceForEnergy = - responseContent.getJSONObject("account_resource") + responseContent + .getJSONObject("account_resource") .getLong("acquired_delegated_frozenV2_balance_for_energy"); Assert.assertNull(acquiredDelegatedFrozenBalanceForEnergy); - - } - - - /** - * constructor. - */ - @Test(enabled = true, description = "WithdrawExpireUnfreeze by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "WithdrawExpireUnfreeze by http", + groups = {"daily", "serial"}) public void test009WithdrawExpireUnfreeze() { - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getAccount(httpnode, freezeBandwidthAddress) - ); + responseContent = + HttpMethod.parseResponseContent(HttpMethod.getAccount(httpnode, freezeBandwidthAddress)); JSONArray unfrozenV2 = responseContent.getJSONArray("unfrozenV2"); Long unfreezeExpireTime = unfrozenV2.getJSONObject(0).getLong("unfreeze_expire_time"); int retryTimes = 0; @@ -403,154 +356,115 @@ public void test009WithdrawExpireUnfreeze() { HttpMethod.waitToProduceOneBlock(httpnode); } - - - - - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getAccount(httpnode, freezeBandwidthAddress) - ); + responseContent = + HttpMethod.parseResponseContent(HttpMethod.getAccount(httpnode, freezeBandwidthAddress)); unfrozenV2 = responseContent.getJSONArray("unfrozenV2"); final Long unfreezeAmount = unfrozenV2.getJSONObject(0).getLong("unfreeze_amount"); final Long beforeBalance = responseContent.getLong("balance"); - response = HttpMethod.withdrawExpireUnfreeze( - httpnode, - freezeBandwidthAddress, - freezeBandwidthKey - ); + response = + HttpMethod.withdrawExpireUnfreeze(httpnode, freezeBandwidthAddress, freezeBandwidthKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getAccount(httpnode, freezeBandwidthAddress) - ); + responseContent = + HttpMethod.parseResponseContent(HttpMethod.getAccount(httpnode, freezeBandwidthAddress)); Assert.assertNull(responseContent.getJSONArray("unfrozenV2")); afterBalance = responseContent.getLong("balance"); Assert.assertTrue(afterBalance - beforeBalance == unfreezeAmount); - - - } - /** - * constructor. - */ - @Test(enabled = true, description = "GetCanDelegateMaxSize by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "GetCanDelegateMaxSize by http", + groups = {"daily", "serial"}) public void test010GetCanDelegateMaxSize() { long frozenBalance = 100000000L; - //without freeze, Assert null - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getCanDelegatedMaxSize(httpnode, freezeForQuery, 0L, false) - ); + // without freeze, Assert null + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getCanDelegatedMaxSize(httpnode, freezeForQuery, 0L, false)); Assert.assertNull(responseContent.getJSONObject("max_size")); - //freeze bandwidth - response = HttpMethod.freezeBalanceV2( - httpnode, - freezeForQuery, - frozenBalance, - 0, - null, - freezeForQueryKey - ); + // freeze bandwidth + response = + HttpMethod.freezeBalanceV2( + httpnode, freezeForQuery, frozenBalance, 0, null, freezeForQueryKey); Assert.assertTrue(HttpMethod.verificationResult(response)); - //freeze energy - response = HttpMethod.freezeBalanceV2( - httpnode, - freezeForQuery, - frozenBalance, - 1, - null, - freezeForQueryKey - ); + // freeze energy + response = + HttpMethod.freezeBalanceV2( + httpnode, freezeForQuery, frozenBalance, 1, null, freezeForQueryKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); - //query fullNode - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getCanDelegatedMaxSize(httpnode, freezeForQuery, 0L, false) - ); + // query fullNode + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getCanDelegatedMaxSize(httpnode, freezeForQuery, 0L, false)); logger.info("bandwidth max_size:" + responseContent.getInteger("max_size").toString()); Assert.assertTrue(responseContent.getInteger("max_size") <= frozenBalance); - //query solidity node - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getCanDelegatedMaxSizeSolidity(httpSoliditynode, freezeForQuery, 0L, false) - ); + // query solidity node + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getCanDelegatedMaxSizeSolidity(httpSoliditynode, freezeForQuery, 0L, false)); logger.info("bandwidth max_size:" + responseContent.getInteger("max_size").toString()); Assert.assertTrue(responseContent.getInteger("max_size") <= frozenBalance); - //query pbft node - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getCanDelegatedMaxSizePbft(httpPbftNode, freezeForQuery, 0L, false) - ); + // query pbft node + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getCanDelegatedMaxSizePbft(httpPbftNode, freezeForQuery, 0L, false)); logger.info("bandwidth max_size:" + responseContent.getInteger("max_size").toString()); Assert.assertTrue(responseContent.getInteger("max_size") <= frozenBalance); - - //query fullNode - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getCanDelegatedMaxSize(httpnode, freezeForQuery, 1L, false) - ); + // query fullNode + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getCanDelegatedMaxSize(httpnode, freezeForQuery, 1L, false)); logger.info("energy max_size:" + responseContent.getInteger("max_size").toString()); Assert.assertTrue(responseContent.getInteger("max_size") == frozenBalance); - //query solidity node - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getCanDelegatedMaxSizeSolidity(httpSoliditynode, freezeForQuery, 1L, false) - ); + // query solidity node + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getCanDelegatedMaxSizeSolidity(httpSoliditynode, freezeForQuery, 1L, false)); logger.info("energy max_size:" + responseContent.getInteger("max_size").toString()); Assert.assertTrue(responseContent.getInteger("max_size") == frozenBalance); - //query pbft node - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getCanDelegatedMaxSizePbft(httpPbftNode, freezeForQuery, 1L, false) - ); + // query pbft node + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getCanDelegatedMaxSizePbft(httpPbftNode, freezeForQuery, 1L, false)); logger.info("energy max_size:" + responseContent.getInteger("max_size").toString()); Assert.assertTrue(responseContent.getInteger("max_size") == frozenBalance); - - } - - - @Test(enabled = true, description = "getCanWithdrawUnfreezeAmount by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "getCanWithdrawUnfreezeAmount by http", + groups = {"daily", "serial"}) public void test012GetCanWithdrawUnfreezeAmount() { final long fronzenBalance = 9000000L; final long unfronzenBalance = fronzenBalance; HttpMethod.freezeBalanceV2( - httpnode, - freezeForQuery, - fronzenBalance, - 0, - null, - freezeForQueryKey - ); - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getCanWithdrawUnfreezeAmount( - httpnode, - freezeForQuery, - System.currentTimeMillis(), - false - ) - ); + httpnode, freezeForQuery, fronzenBalance, 0, null, freezeForQueryKey); + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getCanWithdrawUnfreezeAmount( + httpnode, freezeForQuery, System.currentTimeMillis(), false)); Assert.assertNull(responseContent.getJSONObject("amount")); HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); - response = HttpMethod.unFreezeBalanceV2( - httpnode, - freezeForQuery, - unfronzenBalance, - 0, - freezeForQueryKey - ); + response = + HttpMethod.unFreezeBalanceV2( + httpnode, freezeForQuery, unfronzenBalance, 0, freezeForQueryKey); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getAccount(httpnode, freezeForQuery) - ); + responseContent = + HttpMethod.parseResponseContent(HttpMethod.getAccount(httpnode, freezeForQuery)); JSONArray unfreezeList = responseContent.getJSONArray("unfrozenV2"); long unfreezeExpireTime = 0L; for (int i = 0; i < unfreezeList.size(); i++) { @@ -559,155 +473,119 @@ public void test012GetCanWithdrawUnfreezeAmount() { unfreezeExpireTime = item.getLongValue("unfreeze_expire_time"); } } - //query expire time - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getCanWithdrawUnfreezeAmount(httpnode, freezeForQuery, unfreezeExpireTime, false) - ); + // query expire time + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getCanWithdrawUnfreezeAmount( + httpnode, freezeForQuery, unfreezeExpireTime, false)); Assert.assertEquals(unfronzenBalance, responseContent.getLongValue("amount")); - //query solidity - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getCanWithdrawUnfreezeAmountSolidity( - httpSoliditynode, - freezeForQuery, - unfreezeExpireTime, - false - ) - ); + // query solidity + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getCanWithdrawUnfreezeAmountSolidity( + httpSoliditynode, freezeForQuery, unfreezeExpireTime, false)); Assert.assertEquals(unfronzenBalance, responseContent.getLongValue("amount")); - //query pbft node - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getCanWithdrawUnfreezeAmountPbft( - httpPbftNode, - freezeForQuery, - unfreezeExpireTime, - false - ) - ); + // query pbft node + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getCanWithdrawUnfreezeAmountPbft( + httpPbftNode, freezeForQuery, unfreezeExpireTime, false)); Assert.assertEquals(unfronzenBalance, responseContent.getLongValue("amount")); - //query expire time-1 - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getCanWithdrawUnfreezeAmount( - httpnode, - freezeForQuery, - unfreezeExpireTime - 1L, - false - ) - ); + // query expire time-1 + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getCanWithdrawUnfreezeAmount( + httpnode, freezeForQuery, unfreezeExpireTime - 1L, false)); Assert.assertNull(responseContent.getJSONObject("amount")); - //query solidity expire time-1 - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getCanWithdrawUnfreezeAmountSolidity( - httpSoliditynode, - freezeForQuery, - unfreezeExpireTime - 1L, - false) - ); + // query solidity expire time-1 + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getCanWithdrawUnfreezeAmountSolidity( + httpSoliditynode, freezeForQuery, unfreezeExpireTime - 1L, false)); Assert.assertNull(responseContent.getJSONObject("amount")); - //query expire time+1 - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getCanWithdrawUnfreezeAmount( - httpnode, - freezeForQuery, - unfreezeExpireTime + 1L, - true - ) - ); + // query expire time+1 + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getCanWithdrawUnfreezeAmount( + httpnode, freezeForQuery, unfreezeExpireTime + 1L, true)); Assert.assertEquals(unfronzenBalance, responseContent.getLongValue("amount")); - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getCanWithdrawUnfreezeAmountSolidity( - httpSoliditynode, - freezeForQuery, - unfreezeExpireTime + 1L, - true - ) - ); + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getCanWithdrawUnfreezeAmountSolidity( + httpSoliditynode, freezeForQuery, unfreezeExpireTime + 1L, true)); Assert.assertEquals(unfronzenBalance, responseContent.getLongValue("amount")); } - @Test(enabled = true, description = "GetDelegatedResourceV2 by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "GetDelegatedResourceV2 by http", + groups = {"daily", "serial"}) public void test013GetDelegatedResourceV2() { final long freezeAmount = 100000000L; final long delegateAmount = 50000000L; - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getDelegatedResourceV2( - httpnode, - freezeForQuery, - receiverResourceAddress, - true - ) - ); + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getDelegatedResourceV2( + httpnode, freezeForQuery, receiverResourceAddress, true)); Assert.assertNull(responseContent.getJSONArray("delegatedResource")); - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getDelegatedResourceV2Solidity( - httpSoliditynode, - freezeForQuery, - receiverResourceAddress, - true - ) - ); + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getDelegatedResourceV2Solidity( + httpSoliditynode, freezeForQuery, receiverResourceAddress, true)); Assert.assertNull(responseContent.getJSONArray("delegatedResource")); - response = HttpMethod.freezeBalanceV2( - httpnode, - freezeForQuery, - freezeAmount, - 0, - null, - freezeForQueryKey - ); + response = + HttpMethod.freezeBalanceV2( + httpnode, freezeForQuery, freezeAmount, 0, null, freezeForQueryKey); Assert.assertTrue(HttpMethod.verificationResult(response)); - response = HttpMethod.freezeBalanceV2( - httpnode, - freezeForQuery, - freezeAmount, - 1, - null, - freezeForQueryKey - ); + response = + HttpMethod.freezeBalanceV2( + httpnode, freezeForQuery, freezeAmount, 1, null, freezeForQueryKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); - response = HttpMethod.delegateresource( - httpnode, - freezeForQuery, - delegateAmount, - 0, - null, - null, - receiverResourceAddress, - freezeForQueryKey - ); - Assert.assertTrue(HttpMethod.verificationResult(response)); - response = HttpMethod.delegateresource( - httpnode, - freezeForQuery, - delegateAmount, - 1, - null, - null, - receiverResourceAddress, - freezeForQueryKey - ); + response = + HttpMethod.delegateresource( + httpnode, + freezeForQuery, + delegateAmount, + 0, + null, + null, + receiverResourceAddress, + freezeForQueryKey); Assert.assertTrue(HttpMethod.verificationResult(response)); - HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); - - //query fullNode - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getDelegatedResourceV2( + response = + HttpMethod.delegateresource( httpnode, freezeForQuery, + delegateAmount, + 1, + null, + null, receiverResourceAddress, - true) - ); + freezeForQueryKey); + Assert.assertTrue(HttpMethod.verificationResult(response)); + HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); + + // query fullNode + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getDelegatedResourceV2( + httpnode, freezeForQuery, receiverResourceAddress, true)); JSONArray delegateList = responseContent.getJSONArray("delegatedResource"); JSONObject delegateItem = null; for (int i = 0; i < delegateList.size(); i++) { - if (delegateList.getJSONObject(i).getString("from") - .equals(Base58.encode58Check(freezeForQuery)) - && delegateList.getJSONObject(i).getString("to") - .equals(Base58.encode58Check(receiverResourceAddress))) { + if (delegateList + .getJSONObject(i) + .getString("from") + .equals(Base58.encode58Check(freezeForQuery)) + && delegateList + .getJSONObject(i) + .getString("to") + .equals(Base58.encode58Check(receiverResourceAddress))) { delegateItem = delegateList.getJSONObject(i); } } @@ -715,22 +593,22 @@ public void test013GetDelegatedResourceV2() { Assert.assertEquals(delegateAmount, delegateItem.getLongValue("frozen_balance_for_bandwidth")); Assert.assertEquals(delegateAmount, delegateItem.getLongValue("frozen_balance_for_energy")); - //query solidity - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getDelegatedResourceV2Solidity( - httpSoliditynode, - freezeForQuery, - receiverResourceAddress, - true - ) - ); + // query solidity + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getDelegatedResourceV2Solidity( + httpSoliditynode, freezeForQuery, receiverResourceAddress, true)); delegateList = responseContent.getJSONArray("delegatedResource"); delegateItem = null; for (int i = 0; i < delegateList.size(); i++) { - if (delegateList.getJSONObject(i).getString("from") - .equals(Base58.encode58Check(freezeForQuery)) - && delegateList.getJSONObject(i).getString("to") - .equals(Base58.encode58Check(receiverResourceAddress))) { + if (delegateList + .getJSONObject(i) + .getString("from") + .equals(Base58.encode58Check(freezeForQuery)) + && delegateList + .getJSONObject(i) + .getString("to") + .equals(Base58.encode58Check(receiverResourceAddress))) { delegateItem = delegateList.getJSONObject(i); } } @@ -738,171 +616,143 @@ public void test013GetDelegatedResourceV2() { Assert.assertEquals(delegateAmount, delegateItem.getLongValue("frozen_balance_for_bandwidth")); Assert.assertEquals(delegateAmount, delegateItem.getLongValue("frozen_balance_for_energy")); - //query pbft - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getDelegatedResourceV2Pbft( - httpPbftNode, - freezeForQuery, - receiverResourceAddress, - true - ) - ); + // query pbft + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getDelegatedResourceV2Pbft( + httpPbftNode, freezeForQuery, receiverResourceAddress, true)); delegateList = responseContent.getJSONArray("delegatedResource"); delegateItem = null; for (int i = 0; i < delegateList.size(); i++) { - if (delegateList.getJSONObject(i).getString("from") - .equals(Base58.encode58Check(freezeForQuery)) - && delegateList.getJSONObject(i).getString("to") - .equals(Base58.encode58Check(receiverResourceAddress))) { + if (delegateList + .getJSONObject(i) + .getString("from") + .equals(Base58.encode58Check(freezeForQuery)) + && delegateList + .getJSONObject(i) + .getString("to") + .equals(Base58.encode58Check(receiverResourceAddress))) { delegateItem = delegateList.getJSONObject(i); } } Assert.assertNotNull(delegateItem); Assert.assertEquals(delegateAmount, delegateItem.getLongValue("frozen_balance_for_bandwidth")); Assert.assertEquals(delegateAmount, delegateItem.getLongValue("frozen_balance_for_energy")); - - } - @Test(enabled = true, description = "GetDelegatedResourceAccountIndexV2 by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "GetDelegatedResourceAccountIndexV2 by http", + groups = {"daily", "serial"}) public void test014GetDelegatedResourceAccountIndexV2() { final long freezeAmount = 100000000L; final long delegateAmount = 50000000L; - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getDelegatedResourceAccountIndexV2( - httpnode, - freezeForQuery, - true - ) - ); + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getDelegatedResourceAccountIndexV2(httpnode, freezeForQuery, true)); logger.info(responseContent.toJSONString()); - response = HttpMethod.freezeBalanceV2( - httpnode, - freezeForQuery, - freezeAmount, - 0, - null, - freezeForQueryKey - ); + response = + HttpMethod.freezeBalanceV2( + httpnode, freezeForQuery, freezeAmount, 0, null, freezeForQueryKey); Assert.assertTrue(HttpMethod.verificationResult(response)); - response = HttpMethod.freezeBalanceV2( - httpnode, - freezeForQuery, - freezeAmount, - 1, - null, - freezeForQueryKey - ); + response = + HttpMethod.freezeBalanceV2( + httpnode, freezeForQuery, freezeAmount, 1, null, freezeForQueryKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); - response = HttpMethod.delegateresource( - httpnode, - freezeForQuery, - delegateAmount, - 0, - null, - null, - receiverResourceAddress, - freezeForQueryKey - ); + response = + HttpMethod.delegateresource( + httpnode, + freezeForQuery, + delegateAmount, + 0, + null, + null, + receiverResourceAddress, + freezeForQueryKey); Assert.assertTrue(HttpMethod.verificationResult(response)); - response = HttpMethod.delegateresource( - httpnode, - freezeForQuery, - delegateAmount, - 1, - null, - null, - receiverResourceAddress, - freezeForQueryKey - ); + response = + HttpMethod.delegateresource( + httpnode, + freezeForQuery, + delegateAmount, + 1, + null, + null, + receiverResourceAddress, + freezeForQueryKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); - //query fullNode - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getDelegatedResourceAccountIndexV2(httpnode, freezeForQuery, true) - ); + // query fullNode + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getDelegatedResourceAccountIndexV2(httpnode, freezeForQuery, true)); Assert.assertTrue( - responseContent.getString("account").equals(Base58.encode58Check(freezeForQuery)) - ); + responseContent.getString("account").equals(Base58.encode58Check(freezeForQuery))); Assert.assertTrue( - responseContent.getJSONArray("toAccounts") - .contains(Base58.encode58Check(receiverResourceAddress)) - ); - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getDelegatedResourceAccountIndexV2(httpnode, receiverResourceAddress, true) - ); + responseContent + .getJSONArray("toAccounts") + .contains(Base58.encode58Check(receiverResourceAddress))); + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getDelegatedResourceAccountIndexV2(httpnode, receiverResourceAddress, true)); Assert.assertTrue( - responseContent.getString("account").equals(Base58.encode58Check(receiverResourceAddress)) - ); + responseContent.getString("account").equals(Base58.encode58Check(receiverResourceAddress))); Assert.assertTrue( - responseContent.getJSONArray("fromAccounts").contains(Base58.encode58Check(freezeForQuery)) - ); - //query solidity - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getDelegatedResourceAccountIndexV2Solidity( - httpSoliditynode, - freezeForQuery, - true - ) - ); + responseContent + .getJSONArray("fromAccounts") + .contains(Base58.encode58Check(freezeForQuery))); + // query solidity + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getDelegatedResourceAccountIndexV2Solidity( + httpSoliditynode, freezeForQuery, true)); Assert.assertTrue( - responseContent.getString("account").equals(Base58.encode58Check(freezeForQuery)) - ); + responseContent.getString("account").equals(Base58.encode58Check(freezeForQuery))); Assert.assertTrue( - responseContent.getJSONArray("toAccounts") - .contains(Base58.encode58Check(receiverResourceAddress)) - ); - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getDelegatedResourceAccountIndexV2Solidity( - httpSoliditynode, - receiverResourceAddress, - true - ) - ); + responseContent + .getJSONArray("toAccounts") + .contains(Base58.encode58Check(receiverResourceAddress))); + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getDelegatedResourceAccountIndexV2Solidity( + httpSoliditynode, receiverResourceAddress, true)); Assert.assertTrue( - responseContent.getString("account").equals(Base58.encode58Check(receiverResourceAddress)) - ); + responseContent.getString("account").equals(Base58.encode58Check(receiverResourceAddress))); Assert.assertTrue( - responseContent.getJSONArray("fromAccounts").contains(Base58.encode58Check(freezeForQuery)) - ); - //query pbft - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getDelegatedResourceAccountIndexV2Pbft( - httpPbftNode, - freezeForQuery, - true - ) - ); + responseContent + .getJSONArray("fromAccounts") + .contains(Base58.encode58Check(freezeForQuery))); + // query pbft + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getDelegatedResourceAccountIndexV2Pbft(httpPbftNode, freezeForQuery, true)); Assert.assertTrue( - responseContent.getString("account").equals(Base58.encode58Check(freezeForQuery)) - ); + responseContent.getString("account").equals(Base58.encode58Check(freezeForQuery))); Assert.assertTrue( - responseContent.getJSONArray("toAccounts") - .contains(Base58.encode58Check(receiverResourceAddress)) - ); - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getDelegatedResourceAccountIndexV2Pbft( - httpPbftNode, - receiverResourceAddress, - true - ) - ); + responseContent + .getJSONArray("toAccounts") + .contains(Base58.encode58Check(receiverResourceAddress))); + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getDelegatedResourceAccountIndexV2Pbft( + httpPbftNode, receiverResourceAddress, true)); Assert.assertTrue( - responseContent.getString("account").equals(Base58.encode58Check(receiverResourceAddress)) - ); + responseContent.getString("account").equals(Base58.encode58Check(receiverResourceAddress))); Assert.assertTrue( - responseContent.getJSONArray("fromAccounts").contains(Base58.encode58Check(freezeForQuery)) - ); - - + responseContent + .getJSONArray("fromAccounts") + .contains(Base58.encode58Check(freezeForQuery))); } - @Test(enabled = true, description = "GetAvailableUnfreezeCount by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "GetAvailableUnfreezeCount by http", + groups = {"daily", "serial"}) public void test011GetAvailableUnfreezeCount() { - //use another account for case independence + // use another account for case independence ECKey ecKey = new ECKey(Utils.getRandom()); byte[] unfreezeAccount = ecKey.getAddress(); final String unfreezeAccountKey = ByteArray.toHexString(ecKey.getPrivKeyBytes()); @@ -910,46 +760,43 @@ public void test011GetAvailableUnfreezeCount() { Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); long freezeAmount = 1000000L; - //without unfreeze, Assert 32 - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getAvailableUnfreezeCount(httpnode, unfreezeAccount, true) - ); + // without unfreeze, Assert 32 + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getAvailableUnfreezeCount(httpnode, unfreezeAccount, true)); Assert.assertEquals(32L, responseContent.getLongValue("count")); - response = HttpMethod.freezeBalanceV2( - httpnode, - unfreezeAccount, - freezeAmount, - 0, - null, - unfreezeAccountKey - ); + response = + HttpMethod.freezeBalanceV2( + httpnode, unfreezeAccount, freezeAmount, 0, null, unfreezeAccountKey); HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); // unfreezeBalance 1 SUN bandwidth Assert 31 - responseContent = HttpMethod.parseResponseContent( - HttpMethod.unFreezeBalanceV2(httpnode, unfreezeAccount, 1L, 0, unfreezeAccountKey) - ); + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.unFreezeBalanceV2(httpnode, unfreezeAccount, 1L, 0, unfreezeAccountKey)); HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); - //query fullNode - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getAvailableUnfreezeCount(httpnode, unfreezeAccount, true) - ); + // query fullNode + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getAvailableUnfreezeCount(httpnode, unfreezeAccount, true)); Assert.assertEquals(31L, responseContent.getLongValue("count")); - //query solidity - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getAvailableUnfreezeCountSolidity(httpSoliditynode, unfreezeAccount, true) - ); + // query solidity + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getAvailableUnfreezeCountSolidity(httpSoliditynode, unfreezeAccount, true)); Assert.assertEquals(31L, responseContent.getLongValue("count")); - //query pbft - responseContent = HttpMethod.parseResponseContent( - HttpMethod.getAvailableUnfreezeCountPbft(httpPbftNode, unfreezeAccount, true) - ); + // query pbft + responseContent = + HttpMethod.parseResponseContent( + HttpMethod.getAvailableUnfreezeCountPbft(httpPbftNode, unfreezeAccount, true)); Assert.assertEquals(31L, responseContent.getLongValue("count")); - } - @Test(enabled = true, description = "Test lockPeriod = 1000L", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Test lockPeriod = 1000L", + groups = {"daily", "serial"}) public void test015lockPeriodTest() { final long lockPeriod = 1000L; ECKey ecKey = new ECKey(Utils.getRandom()); @@ -960,14 +807,23 @@ public void test015lockPeriodTest() { HttpMethod.freezeBalanceV2(httpnode, fromDelegateAddress, amount, 1, null, fromDelegateKey); HttpMethod.waitToProduceOneBlock(httpnode); final long delegateTime = System.currentTimeMillis(); - response = HttpMethod.delegateresource(httpnode, fromDelegateAddress, delegateAmount, - 1, true, lockPeriod, receiverResourceAddress, fromDelegateKey); + response = + HttpMethod.delegateresource( + httpnode, + fromDelegateAddress, + delegateAmount, + 1, + true, + lockPeriod, + receiverResourceAddress, + fromDelegateKey); responseContent = HttpMethod.parseResponseContent(response); logger.info("delegateResource:" + responseContent.toJSONString()); Assert.assertEquals(responseContent.getBoolean("result"), true); HttpMethod.waitToProduceOneBlock(httpnode); - response = HttpMethod.getDelegatedResourceV2( - httpnode, fromDelegateAddress, receiverResourceAddress, true); + response = + HttpMethod.getDelegatedResourceV2( + httpnode, fromDelegateAddress, receiverResourceAddress, true); responseContent = HttpMethod.parseResponseContent(response); logger.info(responseContent.toJSONString()); Long expireTime = @@ -979,30 +835,25 @@ public void test015lockPeriodTest() { Assert.assertEquals( responseContent .getJSONArray("delegatedResource") - .getJSONObject(0).getLong("frozen_balance_for_energy") + .getJSONObject(0) + .getLong("frozen_balance_for_energy") .longValue(), delegateAmount.longValue()); Assert.assertEquals( - responseContent - .getJSONArray("delegatedResource") - .getJSONObject(0).getString("from"), + responseContent.getJSONArray("delegatedResource").getJSONObject(0).getString("from"), Base58.encode58Check(fromDelegateAddress)); Assert.assertEquals( - responseContent - .getJSONArray("delegatedResource") - .getJSONObject(0).getString("to"), + responseContent.getJSONArray("delegatedResource").getJSONObject(0).getString("to"), Base58.encode58Check(receiverResourceAddress)); } - /** - * constructor. - * */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - response = HttpMethod - .unFreezeBalance(httpnode, fromAddress, frozenBalance, 0, freezeBandwidthAddress, - testKey002); + response = + HttpMethod.unFreezeBalance( + httpnode, fromAddress, frozenBalance, 0, freezeBandwidthAddress, testKey002); HttpMethod.freeResource(httpnode, freezeBandwidthAddress, fromAddress, freezeBandwidthKey); HttpMethod.disConnect(); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestFreezeV2002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestFreezeV2002.java index aa79a093..d3a29a27 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestFreezeV2002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestFreezeV2002.java @@ -12,22 +12,21 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.HttpMethod; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.Utils; -import java.util.HashMap; - - -/** - * - */ +/** */ @Slf4j public class HttpTestFreezeV2002 { - private final String testKeyFrom = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); + private final String testKeyFrom = + Configuration.getByPath("testng.conf").getString("foundationAccount.key1"); private final byte[] fromAddress = PublicMethod.getFinalAddress(testKeyFrom); - private final String testWitnessKey = Configuration.getByPath("testng.conf") - .getString("witness.key1"); + private final String testWitnessKey = + Configuration.getByPath("testng.conf").getString("witness.key1"); private final byte[] testWitnessAddress = PublicMethod.getFinalAddress(testWitnessKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -36,41 +35,36 @@ public class HttpTestFreezeV2002 { private JSONObject responseContent; private HttpResponse response; - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(0); - private String httpSoliditynode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); - private String httpPbftNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(4); - + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); + private String httpSoliditynode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); + private String httpPbftNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(4); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { if (!HttpMethod.proposalFreezeV2IsOpen(httpnode)) { throw new SkipException("Skipping this freezeV2 test case"); } PublicMethod.printAddress(testKey001); - response = HttpMethod - .sendCoin(httpnode, fromAddress, testAddress001, 1000000000L, testKeyFrom); + response = HttpMethod.sendCoin(httpnode, fromAddress, testAddress001, 1000000000L, testKeyFrom); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - response = HttpMethod.freezeBalance(httpnode, testAddress001,20000000L, 0, 0, testKey001); + response = HttpMethod.freezeBalance(httpnode, testAddress001, 20000000L, 0, 0, testKey001); Assert.assertTrue(HttpMethod.verificationResult(response)); - response = HttpMethod.freezeBalance(httpnode, testAddress001,20000000L, 0, 1, testKey001); + response = HttpMethod.freezeBalance(httpnode, testAddress001, 20000000L, 0, 1, testKey001); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - } - - /** - * constructor. - */ - @Test(enabled = true, description = "cancel all unfrozen net", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "cancel all unfrozen net", + groups = {"daily", "serial"}) public void test001CancelAllUnfreezeNet() { response = HttpMethod.unFreezeBalanceV2(httpnode, testAddress001, 1000000L, 0, testKey001); Assert.assertTrue(HttpMethod.verificationResult(response)); @@ -79,7 +73,8 @@ public void test001CancelAllUnfreezeNet() { responseContent = HttpMethod.parseResponseContent(response); long beforeBalance = responseContent.getLongValue("balance"); Assert.assertEquals(responseContent.getJSONArray("unfrozenV2").size(), 1); - long beforeUnfreezeNet = responseContent.getJSONArray("unfrozenV2").getJSONObject(0).getLongValue("unfreeze_amount"); + long beforeUnfreezeNet = + responseContent.getJSONArray("unfrozenV2").getJSONObject(0).getLongValue("unfreeze_amount"); Assert.assertEquals(beforeUnfreezeNet, 1000000); response = HttpMethod.getAccountReource(httpnode, testAddress001); responseContent = HttpMethod.parseResponseContent(response); @@ -92,15 +87,16 @@ public void test001CancelAllUnfreezeNet() { Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); String txid = responseContent.getString("txid"); - responseContent = HttpMethod.parseResponseContent(HttpMethod.getTransactionInfoById(httpnode, txid)); + responseContent = + HttpMethod.parseResponseContent(HttpMethod.getTransactionInfoById(httpnode, txid)); logger.info("test001 cancelAllUnfreeze info: " + responseContent.toJSONString()); JSONArray cancelArray = responseContent.getJSONArray("cancel_unfreezeV2_amount"); Assert.assertEquals(cancelArray.size(), 3); - for(int i=0;i<3;i++){ + for (int i = 0; i < 3; i++) { JSONObject tem = cancelArray.getJSONObject(i); - if(tem.getString("key").equals("BANDWIDTH")){ + if (tem.getString("key").equals("BANDWIDTH")) { Assert.assertEquals(tem.getLongValue("value"), 1000000); - }else { + } else { Assert.assertEquals(tem.getLongValue("value"), 0); } } @@ -111,8 +107,10 @@ public void test001CancelAllUnfreezeNet() { System.out.println(responseContent.toJSONString()); long afterBalance = responseContent.getLongValue("balance"); Assert.assertFalse(responseContent.containsKey("unfrozenV2")); - long afterUnfreezeNet = responseContent.getJSONArray("frozenV2").getJSONObject(0).getLongValue("amount"); - long afterUnfreezeEnergy = responseContent.getJSONArray("frozenV2").getJSONObject(1).getLongValue("amount"); + long afterUnfreezeNet = + responseContent.getJSONArray("frozenV2").getJSONObject(0).getLongValue("amount"); + long afterUnfreezeEnergy = + responseContent.getJSONArray("frozenV2").getJSONObject(1).getLongValue("amount"); Assert.assertEquals(afterUnfreezeNet, 20000000); Assert.assertEquals(afterUnfreezeEnergy, 20000000); response = HttpMethod.getAccountReource(httpnode, testAddress001); @@ -122,10 +120,11 @@ public void test001CancelAllUnfreezeNet() { Assert.assertEquals(powerLimit2, 40); } - /** - * constructor. - */ - @Test(enabled = true, description = "cancel all unfrozen energy", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "cancel all unfrozen energy", + groups = {"daily", "serial"}) public void test002CancelAllUnfreezeEnergy() { response = HttpMethod.unFreezeBalanceV2(httpnode, testAddress001, 2000000L, 1, testKey001); Assert.assertTrue(HttpMethod.verificationResult(response)); @@ -135,7 +134,8 @@ public void test002CancelAllUnfreezeEnergy() { responseContent = HttpMethod.parseResponseContent(response); long beforeBalance = responseContent.getLongValue("balance"); Assert.assertEquals(responseContent.getJSONArray("unfrozenV2").size(), 1); - long beforeUnfreezeNet = responseContent.getJSONArray("unfrozenV2").getJSONObject(0).getLongValue("unfreeze_amount"); + long beforeUnfreezeNet = + responseContent.getJSONArray("unfrozenV2").getJSONObject(0).getLongValue("unfreeze_amount"); Assert.assertEquals(beforeUnfreezeNet, 2000000); response = HttpMethod.getAccountReource(httpnode, testAddress001); responseContent = HttpMethod.parseResponseContent(response); @@ -148,15 +148,16 @@ public void test002CancelAllUnfreezeEnergy() { logger.info("test002 cancel res: " + responseContent.toJSONString()); HttpMethod.waitToProduceOneBlock(httpnode); String txid = responseContent.getString("txid"); - responseContent = HttpMethod.parseResponseContent(HttpMethod.getTransactionInfoById(httpnode, txid)); + responseContent = + HttpMethod.parseResponseContent(HttpMethod.getTransactionInfoById(httpnode, txid)); logger.info("test002 cancelAllUnfreeze info: " + responseContent.toJSONString()); JSONArray cancelArray = responseContent.getJSONArray("cancel_unfreezeV2_amount"); Assert.assertEquals(cancelArray.size(), 3); - for(int i=0;i<3;i++){ + for (int i = 0; i < 3; i++) { JSONObject tem = cancelArray.getJSONObject(i); - if(tem.getString("key").equals("ENERGY")){ + if (tem.getString("key").equals("ENERGY")) { Assert.assertEquals(tem.getLongValue("value"), 2000000); - }else { + } else { Assert.assertEquals(tem.getLongValue("value"), 0); } } @@ -167,8 +168,10 @@ public void test002CancelAllUnfreezeEnergy() { logger.info(responseContent.toJSONString()); long afterBalance = responseContent.getLongValue("balance"); Assert.assertFalse(responseContent.containsKey("unfrozenV2")); - long afterUnfreezeNet = responseContent.getJSONArray("frozenV2").getJSONObject(0).getLongValue("amount"); - long afterUnfreezeEnergy = responseContent.getJSONArray("frozenV2").getJSONObject(1).getLongValue("amount"); + long afterUnfreezeNet = + responseContent.getJSONArray("frozenV2").getJSONObject(0).getLongValue("amount"); + long afterUnfreezeEnergy = + responseContent.getJSONArray("frozenV2").getJSONObject(1).getLongValue("amount"); Assert.assertEquals(afterUnfreezeNet, 20000000); Assert.assertEquals(afterUnfreezeEnergy, 20000000); response = HttpMethod.getAccountReource(httpnode, testAddress001); @@ -178,10 +181,11 @@ public void test002CancelAllUnfreezeEnergy() { Assert.assertEquals(powerLimit2, 40); } - /** - * constructor. - */ - @Test(enabled = true, description = "cancel all unexpired unfreeze net and energy", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "cancel all unexpired unfreeze net and energy", + groups = {"daily", "serial"}) public void test03CancelAllUnfreezeNetAndEnergy() { response = HttpMethod.unFreezeBalanceV2(httpnode, testAddress001, 2000000L, 0, testKey001); Assert.assertTrue(HttpMethod.verificationResult(response)); @@ -193,8 +197,10 @@ public void test03CancelAllUnfreezeNetAndEnergy() { responseContent = HttpMethod.parseResponseContent(response); long beforeBalance = responseContent.getLongValue("balance"); Assert.assertEquals(responseContent.getJSONArray("unfrozenV2").size(), 2); - long beforeUnfreezeNet = responseContent.getJSONArray("unfrozenV2").getJSONObject(0).getLongValue("unfreeze_amount"); - long beforeUnfreezeEnergy = responseContent.getJSONArray("unfrozenV2").getJSONObject(1).getLongValue("unfreeze_amount"); + long beforeUnfreezeNet = + responseContent.getJSONArray("unfrozenV2").getJSONObject(0).getLongValue("unfreeze_amount"); + long beforeUnfreezeEnergy = + responseContent.getJSONArray("unfrozenV2").getJSONObject(1).getLongValue("unfreeze_amount"); Assert.assertEquals(beforeUnfreezeNet, 2000000); Assert.assertEquals(beforeUnfreezeEnergy, 2000000); response = HttpMethod.getAccountReource(httpnode, testAddress001); @@ -207,7 +213,8 @@ public void test03CancelAllUnfreezeNetAndEnergy() { logger.info("test003 cancel res: " + responseContent.toJSONString()); HttpMethod.waitToProduceOneBlock(httpnode); String txid = responseContent.getString("txid"); - responseContent = HttpMethod.parseResponseContent(HttpMethod.getTransactionInfoById(httpnode, txid)); + responseContent = + HttpMethod.parseResponseContent(HttpMethod.getTransactionInfoById(httpnode, txid)); logger.info("test003 cancelAllUnfreeze info: " + responseContent.toJSONString()); JSONArray cancelArray = responseContent.getJSONArray("cancel_unfreezeV2_amount"); Assert.assertEquals(cancelArray.size(), 3); @@ -226,8 +233,10 @@ public void test03CancelAllUnfreezeNetAndEnergy() { logger.info(responseContent.toJSONString()); long afterBalance = responseContent.getLongValue("balance"); Assert.assertFalse(responseContent.containsKey("unfrozenV2")); - long afterUnfreezeNet = responseContent.getJSONArray("frozenV2").getJSONObject(0).getLongValue("amount"); - long afterUnfreezeEnergy = responseContent.getJSONArray("frozenV2").getJSONObject(1).getLongValue("amount"); + long afterUnfreezeNet = + responseContent.getJSONArray("frozenV2").getJSONObject(0).getLongValue("amount"); + long afterUnfreezeEnergy = + responseContent.getJSONArray("frozenV2").getJSONObject(1).getLongValue("amount"); Assert.assertEquals(afterUnfreezeNet, 20000000); Assert.assertEquals(afterUnfreezeEnergy, 20000000); response = HttpMethod.getAccountReource(httpnode, testAddress001); @@ -237,12 +246,13 @@ public void test03CancelAllUnfreezeNetAndEnergy() { Assert.assertEquals(powerLimit2, 40); } - /** - * constructor. - */ - @Test(enabled = true, description = "cancel 32 unexpired unfreeze", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "cancel 32 unexpired unfreeze", + groups = {"daily", "serial"}) public void test04CancelAll32Unfreeze() { - for(int i=0;i<32;i++){ + for (int i = 0; i < 32; i++) { response = HttpMethod.unFreezeBalanceV2(httpnode, testAddress001, i + 1L, i % 2, testKey001); Assert.assertTrue(HttpMethod.verificationResult(response)); } @@ -264,7 +274,8 @@ public void test04CancelAll32Unfreeze() { logger.info("test004 cancel res: " + responseContent.toJSONString()); HttpMethod.waitToProduceOneBlock(httpnode); String txid = responseContent.getString("txid"); - responseContent = HttpMethod.parseResponseContent(HttpMethod.getTransactionInfoById(httpnode, txid)); + responseContent = + HttpMethod.parseResponseContent(HttpMethod.getTransactionInfoById(httpnode, txid)); logger.info("test004 cancelAllUnfreeze info: " + responseContent.toJSONString()); JSONArray cancelArray = responseContent.getJSONArray("cancel_unfreezeV2_amount"); Assert.assertEquals(cancelArray.size(), 3); @@ -272,7 +283,7 @@ public void test04CancelAll32Unfreeze() { JSONObject tem = cancelArray.getJSONObject(i); if (tem.getString("key").equals("BANDWIDTH")) { Assert.assertEquals(tem.getLongValue("value"), 256); - }else if (tem.getString("key").equals("ENERGY")) { + } else if (tem.getString("key").equals("ENERGY")) { Assert.assertEquals(tem.getLongValue("value"), 272); } else { Assert.assertEquals(tem.getLongValue("value"), 0); @@ -284,8 +295,10 @@ public void test04CancelAll32Unfreeze() { responseContent = HttpMethod.parseResponseContent(response); long afterBalance = responseContent.getLongValue("balance"); Assert.assertFalse(responseContent.containsKey("unfrozenV2")); - long afterUnfreezeNet = responseContent.getJSONArray("frozenV2").getJSONObject(0).getLongValue("amount"); - long afterUnfreezeEnergy = responseContent.getJSONArray("frozenV2").getJSONObject(1).getLongValue("amount"); + long afterUnfreezeNet = + responseContent.getJSONArray("frozenV2").getJSONObject(0).getLongValue("amount"); + long afterUnfreezeEnergy = + responseContent.getJSONArray("frozenV2").getJSONObject(1).getLongValue("amount"); Assert.assertEquals(afterUnfreezeNet, 20000000); Assert.assertEquals(afterUnfreezeEnergy, 20000000); response = HttpMethod.getAccountReource(httpnode, testAddress001); @@ -295,10 +308,11 @@ public void test04CancelAll32Unfreeze() { Assert.assertEquals(powerLimit2, 40); } - /** - * constructor. - */ - @Test(enabled = true, description = "vote after cancel all unfreeze", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "vote after cancel all unfreeze", + groups = {"daily", "serial"}) public void test05VoteAfterCancelAllUnfreeze() { JsonArray voteKeys = new JsonArray(); JsonObject voteElement = new JsonObject(); @@ -310,31 +324,32 @@ public void test05VoteAfterCancelAllUnfreeze() { HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getAccount(httpnode, testAddress001); responseContent = HttpMethod.parseResponseContent(response); - long afterUnfreezeNet = responseContent.getJSONArray("frozenV2").getJSONObject(0).getLongValue("amount"); - long afterUnfreezeEnergy = responseContent.getJSONArray("frozenV2").getJSONObject(1).getLongValue("amount"); + long afterUnfreezeNet = + responseContent.getJSONArray("frozenV2").getJSONObject(0).getLongValue("amount"); + long afterUnfreezeEnergy = + responseContent.getJSONArray("frozenV2").getJSONObject(1).getLongValue("amount"); Assert.assertEquals(afterUnfreezeNet, 20000000); Assert.assertEquals(afterUnfreezeEnergy, 20000000); Assert.assertEquals(responseContent.getJSONArray("votes").size(), 1); String srAdd = responseContent.getJSONArray("votes").getJSONObject(0).getString("vote_address"); - int voteCount = responseContent.getJSONArray("votes").getJSONObject(0).getIntValue("vote_count"); - Assert.assertEquals(srAdd.toLowerCase(), ByteArray.toHexString(testWitnessAddress).toLowerCase()); + int voteCount = + responseContent.getJSONArray("votes").getJSONObject(0).getIntValue("vote_count"); + Assert.assertEquals( + srAdd.toLowerCase(), ByteArray.toHexString(testWitnessAddress).toLowerCase()); Assert.assertEquals(voteCount, 40); } - - - /** - * constructor. - * */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { response = HttpMethod.getAccount(httpnode, testAddress001); responseContent = HttpMethod.parseResponseContent(response); for (int i = 0; i < responseContent.getJSONArray("frozenV2").size(); i++) { - long amount = responseContent.getJSONArray("frozenV2").getJSONObject(i).getLongValue("amount"); + long amount = + responseContent.getJSONArray("frozenV2").getJSONObject(i).getLongValue("amount"); HttpMethod.unFreezeBalanceV2(httpnode, testAddress001, amount, i, testKey001); } HttpMethod.freeResource(httpnode, testAddress001, fromAddress, testKey001); HttpMethod.disConnect(); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestMarket001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestMarket001.java index 8a247efd..b47b9e3d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestMarket001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestMarket001.java @@ -22,8 +22,8 @@ public class HttpTestMarket001 { private static String name = "testAssetIssue002_" + now; private static String assetIssueId1; private static String assetIssueId2; - private final String testKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); + private final String testKey002 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key1"); private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] sellAddress = ecKey1.getAddress(); @@ -40,8 +40,8 @@ public class HttpTestMarket001 { Long amount = 2048000000L; - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private JSONObject responseContent; private JSONObject getMarketOrderByIdContent; @@ -60,18 +60,18 @@ public class HttpTestMarket001 { private JSONObject getMarketPriceByPairContentFromSolidity; private JSONObject getMarketPriceByPairContentFromPbft; private HttpResponse response; - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(1); - private String httpSolidityNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); - private String httpPbftNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(4); - - - /** - * constructor. - */ - @Test(enabled = false, description = "MarketSellAsset trx with trc10 by http", groups = {"daily", "serial"}) + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(1); + private String httpSolidityNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); + private String httpPbftNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(4); + + /** constructor. */ + @Test( + enabled = false, + description = "MarketSellAsset trx with trc10 by http", + groups = {"daily", "serial"}) public void test01MarketSellAsset() { PublicMethod.printAddress(sellKey); PublicMethod.printAddress(dev002Key); @@ -81,10 +81,25 @@ public void test01MarketSellAsset() { Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - //Create an asset issue - response = HttpMethod.assetIssue(httpnode, sellAddress, name, name, totalSupply, 1, 1, - System.currentTimeMillis() + 5000, System.currentTimeMillis() + 50000000, 2, 3, description, - url, 1000L, 1000L, sellKey); + // Create an asset issue + response = + HttpMethod.assetIssue( + httpnode, + sellAddress, + name, + name, + totalSupply, + 1, + 1, + System.currentTimeMillis() + 5000, + System.currentTimeMillis() + 50000000, + 2, + 3, + description, + url, + 1000L, + 1000L, + sellKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getAccount(httpnode, sellAddress); @@ -94,9 +109,24 @@ public void test01MarketSellAsset() { logger.info(assetIssueId1); Assert.assertTrue(Integer.parseInt(assetIssueId1) > 1000000); - response = HttpMethod.assetIssue(httpnode, dev002Address, name, name, totalSupply, 1, 1, - System.currentTimeMillis() + 5000, System.currentTimeMillis() + 50000000, 2, 3, description, - url, 1000L, 1000L, dev002Key); + response = + HttpMethod.assetIssue( + httpnode, + dev002Address, + name, + name, + totalSupply, + 1, + 1, + System.currentTimeMillis() + 5000, + System.currentTimeMillis() + 50000000, + 2, + 3, + description, + url, + 1000L, + 1000L, + dev002Key); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getAccount(httpnode, dev002Address); @@ -107,8 +137,9 @@ public void test01MarketSellAsset() { Assert.assertTrue(Integer.parseInt(assetIssueId2) > 1000000); // transferAsset - response = HttpMethod - .transferAsset(httpnode, dev002Address, sellAddress, assetIssueId2, 10000L, dev002Key); + response = + HttpMethod.transferAsset( + httpnode, dev002Address, sellAddress, assetIssueId2, 10000L, dev002Key); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getAccount(httpnode, sellAddress); @@ -116,9 +147,9 @@ public void test01MarketSellAsset() { HttpMethod.printJsonContent(responseContent); // marketsellasset trc10-trc10 - txId2 = HttpMethod - .marketSellAssetGetTxId(httpnode, sellAddress, assetIssueId1, 10L, assetIssueId2, 500L, - sellKey, "true"); + txId2 = + HttpMethod.marketSellAssetGetTxId( + httpnode, sellAddress, assetIssueId1, 10L, assetIssueId2, 500L, sellKey, "true"); HttpMethod.waitToProduceOneBlock(httpnode); logger.info(txId2); response = HttpMethod.getTransactionInfoById(httpnode, txId2); @@ -129,9 +160,9 @@ public void test01MarketSellAsset() { logger.info("orderId:" + orderId); // marketsellasset trx-trc10 - txId1 = HttpMethod - .marketSellAssetGetTxId(httpnode, sellAddress, "_", 1000L, assetIssueId1, 20L, sellKey, - "false"); + txId1 = + HttpMethod.marketSellAssetGetTxId( + httpnode, sellAddress, "_", 1000L, assetIssueId1, 20L, sellKey, "false"); HttpMethod.waitToProduceOneBlock(httpnode); logger.info(txId1); response = HttpMethod.getTransactionInfoById(httpnode, txId1); @@ -142,9 +173,9 @@ public void test01MarketSellAsset() { logger.info("orderId1:" + orderId1); // marketsellasset trc10-trx - txId2 = HttpMethod - .marketSellAssetGetTxId(httpnode, sellAddress, assetIssueId1, 10L, "_", 500L, sellKey, - "true"); + txId2 = + HttpMethod.marketSellAssetGetTxId( + httpnode, sellAddress, assetIssueId1, 10L, "_", 500L, sellKey, "true"); HttpMethod.waitToProduceOneBlock(httpnode); logger.info(txId2); response = HttpMethod.getTransactionInfoById(httpnode, txId2); @@ -154,27 +185,26 @@ public void test01MarketSellAsset() { Assert.assertTrue(!responseContent.getString("orderId").isEmpty()); Assert.assertTrue(500L == orderDetails.getLong("fillBuyQuantity")); Assert.assertTrue(10L == orderDetails.getLong("fillSellQuantity")); - Assert - .assertEquals(responseContent.getString("orderId"), orderDetails.getString("takerOrderId")); + Assert.assertEquals( + responseContent.getString("orderId"), orderDetails.getString("takerOrderId")); Assert.assertEquals(orderId1, orderDetails.getString("makerOrderId")); orderId2 = responseContent.getString("orderId"); logger.info("orderId2:" + orderId2); - - } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketOrderById by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketOrderById by http", + groups = {"daily", "serial"}) public void test02GetMarketOrderById() { // getMarketOrderById orderId1 HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getMarketOrderById(httpnode, orderId1, "true"); getMarketOrderByIdContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(getMarketOrderByIdContent); - Assert.assertEquals(Base58.encode58Check(sellAddress), - getMarketOrderByIdContent.getString("owner_address")); + Assert.assertEquals( + Base58.encode58Check(sellAddress), getMarketOrderByIdContent.getString("owner_address")); Assert.assertEquals("_", getMarketOrderByIdContent.getString("sell_token_id")); Assert.assertTrue(1000L == getMarketOrderByIdContent.getLong("sell_token_quantity")); Assert.assertEquals(assetIssueId1, getMarketOrderByIdContent.getString("buy_token_id")); @@ -187,54 +217,57 @@ public void test02GetMarketOrderById() { HttpMethod.printJsonContent(getMarketOrderByIdContent2); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketOrderById by http from solidity", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketOrderById by http from solidity", + groups = {"daily", "serial"}) public void test03GetMarketOrderByIdFromSolidity() { HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSolidityNode); response = HttpMethod.getMarketOrderByIdFromSolidity(httpSolidityNode, orderId1, "true"); getMarketOrderByIdContentFromSolidity = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(getMarketOrderByIdContentFromSolidity); - Assert.assertEquals(Base58.encode58Check(sellAddress), + Assert.assertEquals( + Base58.encode58Check(sellAddress), getMarketOrderByIdContentFromSolidity.getString("owner_address")); Assert.assertEquals("_", getMarketOrderByIdContentFromSolidity.getString("sell_token_id")); - Assert - .assertTrue(1000L == getMarketOrderByIdContentFromSolidity.getLong("sell_token_quantity")); - Assert.assertEquals(assetIssueId1, - getMarketOrderByIdContentFromSolidity.getString("buy_token_id")); + Assert.assertTrue( + 1000L == getMarketOrderByIdContentFromSolidity.getLong("sell_token_quantity")); + Assert.assertEquals( + assetIssueId1, getMarketOrderByIdContentFromSolidity.getString("buy_token_id")); Assert.assertTrue(20L == getMarketOrderByIdContentFromSolidity.getLong("buy_token_quantity")); Assert.assertTrue( 500L == getMarketOrderByIdContentFromSolidity.getLong("sell_token_quantity_remain")); Assert.assertEquals(getMarketOrderByIdContent, getMarketOrderByIdContentFromSolidity); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketOrderById by http from pbft", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketOrderById by http from pbft", + groups = {"daily", "serial"}) public void test04GetMarketOrderByIdFromPbft() { HttpMethod.waitToProduceOneBlockFromPbft(httpnode, httpPbftNode); response = HttpMethod.getMarketOrderByIdFromPbft(httpPbftNode, orderId1, "true"); getMarketOrderByIdContentFromPbft = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(getMarketOrderByIdContentFromPbft); - Assert.assertEquals(Base58.encode58Check(sellAddress), + Assert.assertEquals( + Base58.encode58Check(sellAddress), getMarketOrderByIdContentFromPbft.getString("owner_address")); Assert.assertEquals("_", getMarketOrderByIdContentFromPbft.getString("sell_token_id")); - Assert - .assertTrue(1000L == getMarketOrderByIdContentFromPbft.getLong("sell_token_quantity")); - Assert.assertEquals(assetIssueId1, - getMarketOrderByIdContentFromPbft.getString("buy_token_id")); + Assert.assertTrue(1000L == getMarketOrderByIdContentFromPbft.getLong("sell_token_quantity")); + Assert.assertEquals(assetIssueId1, getMarketOrderByIdContentFromPbft.getString("buy_token_id")); Assert.assertTrue(20L == getMarketOrderByIdContentFromPbft.getLong("buy_token_quantity")); Assert.assertTrue( 500L == getMarketOrderByIdContentFromPbft.getLong("sell_token_quantity_remain")); Assert.assertEquals(getMarketOrderByIdContent, getMarketOrderByIdContentFromPbft); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketOrderByAccount by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketOrderByAccount by http", + groups = {"daily", "serial"}) public void test05GetMarketOrderByAccount() { HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getMarketOrderByAccount(httpnode, sellAddress, "true"); @@ -250,18 +283,19 @@ public void test05GetMarketOrderByAccount() { Assert.assertTrue(500L == orders.getLong("sell_token_quantity_remain")); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketOrderByAccount by http from solidity", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketOrderByAccount by http from solidity", + groups = {"daily", "serial"}) public void test06GetMarketOrderByAccountFromSolidity() { - response = HttpMethod - .getMarketOrderByAccountFromSolidity(httpSolidityNode, sellAddress, "true"); + response = + HttpMethod.getMarketOrderByAccountFromSolidity(httpSolidityNode, sellAddress, "true"); getMarketOrderByAccountContentFromSolidity = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(getMarketOrderByAccountContentFromSolidity); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); - JSONObject orders = getMarketOrderByAccountContentFromSolidity.getJSONArray("orders") - .getJSONObject(1); + JSONObject orders = + getMarketOrderByAccountContentFromSolidity.getJSONArray("orders").getJSONObject(1); Assert.assertEquals(Base58.encode58Check(sellAddress), orders.getString("owner_address")); Assert.assertEquals("_", orders.getString("sell_token_id")); Assert.assertTrue(1000L == orders.getLong("sell_token_quantity")); @@ -271,17 +305,18 @@ public void test06GetMarketOrderByAccountFromSolidity() { Assert.assertEquals(getMarketOrderByAccountContent, getMarketOrderByAccountContentFromSolidity); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketOrderByAccount by http from pbft", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketOrderByAccount by http from pbft", + groups = {"daily", "serial"}) public void test07GetMarketOrderByAccountFromPbft() { response = HttpMethod.getMarketOrderByAccountFromPbft(httpPbftNode, sellAddress, "true"); getMarketOrderByAccountContentFromPbft = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(getMarketOrderByAccountContentFromPbft); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); - JSONObject orders = getMarketOrderByAccountContentFromPbft.getJSONArray("orders") - .getJSONObject(1); + JSONObject orders = + getMarketOrderByAccountContentFromPbft.getJSONArray("orders").getJSONObject(1); Assert.assertEquals(Base58.encode58Check(sellAddress), orders.getString("owner_address")); Assert.assertEquals("_", orders.getString("sell_token_id")); Assert.assertTrue(1000L == orders.getLong("sell_token_quantity")); @@ -291,10 +326,11 @@ public void test07GetMarketOrderByAccountFromPbft() { Assert.assertEquals(getMarketOrderByAccountContent, getMarketOrderByAccountContentFromPbft); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketPairList by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketPairList by http", + groups = {"daily", "serial"}) public void test08GetMarketPairList() { response = HttpMethod.getMarketPairList(httpnode, "true"); getMarketPairListContent = HttpMethod.parseResponseContent(response); @@ -302,18 +338,25 @@ public void test08GetMarketPairList() { Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); int orderPairSize = getMarketPairListContent.getJSONArray("orderPair").size(); Assert.assertTrue(orderPairSize > 0); - Assert.assertEquals("_", - getMarketPairListContent.getJSONArray("orderPair").getJSONObject(orderPairSize - 1) + Assert.assertEquals( + "_", + getMarketPairListContent + .getJSONArray("orderPair") + .getJSONObject(orderPairSize - 1) .getString("sell_token_id")); - Assert.assertEquals(assetIssueId1, - getMarketPairListContent.getJSONArray("orderPair").getJSONObject(orderPairSize - 1) + Assert.assertEquals( + assetIssueId1, + getMarketPairListContent + .getJSONArray("orderPair") + .getJSONObject(orderPairSize - 1) .getString("buy_token_id")); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketPairList by http from solidity", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketPairList by http from solidity", + groups = {"daily", "serial"}) public void test09GetMarketPairListFromSolidity() { response = HttpMethod.getMarketPairListFromSolidity(httpSolidityNode, "true"); getMarketPairListContentFromSolidity = HttpMethod.parseResponseContent(response); @@ -321,22 +364,26 @@ public void test09GetMarketPairListFromSolidity() { Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); int orderPairSize = getMarketPairListContentFromSolidity.getJSONArray("orderPair").size(); Assert.assertTrue(orderPairSize > 0); - Assert.assertEquals("_", - getMarketPairListContentFromSolidity.getJSONArray("orderPair") + Assert.assertEquals( + "_", + getMarketPairListContentFromSolidity + .getJSONArray("orderPair") .getJSONObject(orderPairSize - 1) .getString("sell_token_id")); - Assert.assertEquals(assetIssueId1, - getMarketPairListContentFromSolidity.getJSONArray("orderPair") + Assert.assertEquals( + assetIssueId1, + getMarketPairListContentFromSolidity + .getJSONArray("orderPair") .getJSONObject(orderPairSize - 1) .getString("buy_token_id")); Assert.assertEquals(getMarketPairListContent, getMarketPairListContentFromSolidity); - } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketPairList by http from pbft", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketPairList by http from pbft", + groups = {"daily", "serial"}) public void test10GetMarketPairListFromPbft() { response = HttpMethod.getMarketPairListFromPbft(httpPbftNode, "true"); getMarketPairListContentFromPbft = HttpMethod.parseResponseContent(response); @@ -344,100 +391,113 @@ public void test10GetMarketPairListFromPbft() { Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); int orderPairSize = getMarketPairListContentFromPbft.getJSONArray("orderPair").size(); Assert.assertTrue(orderPairSize > 0); - Assert.assertEquals("_", - getMarketPairListContentFromPbft.getJSONArray("orderPair") + Assert.assertEquals( + "_", + getMarketPairListContentFromPbft + .getJSONArray("orderPair") .getJSONObject(orderPairSize - 1) .getString("sell_token_id")); - Assert.assertEquals(assetIssueId1, - getMarketPairListContentFromPbft.getJSONArray("orderPair") + Assert.assertEquals( + assetIssueId1, + getMarketPairListContentFromPbft + .getJSONArray("orderPair") .getJSONObject(orderPairSize - 1) .getString("buy_token_id")); Assert.assertEquals(getMarketPairListContent, getMarketPairListContentFromPbft); - } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketOrderListByPair by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketOrderListByPair by http", + groups = {"daily", "serial"}) public void test11GetMarketOrderListByPair() { response = HttpMethod.getMarketOrderListByPair(httpnode, "_", assetIssueId1, "true"); getMarketOrderListByPairContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(getMarketOrderListByPairContent); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); - JSONObject orders = getMarketOrderListByPairContent.getJSONArray("orders") - .getJSONObject(getMarketOrderListByPairContent.getJSONArray("orders").size() - 1); + JSONObject orders = + getMarketOrderListByPairContent + .getJSONArray("orders") + .getJSONObject(getMarketOrderListByPairContent.getJSONArray("orders").size() - 1); Assert.assertEquals(Base58.encode58Check(sellAddress), orders.getString("owner_address")); Assert.assertEquals("_", orders.getString("sell_token_id")); Assert.assertTrue(1000L == orders.getLong("sell_token_quantity")); Assert.assertEquals(assetIssueId1, orders.getString("buy_token_id")); Assert.assertTrue(20L == orders.getLong("buy_token_quantity")); - Assert.assertEquals(getMarketOrderListByPairContent.getLong("sell_token_quantity"), + Assert.assertEquals( + getMarketOrderListByPairContent.getLong("sell_token_quantity"), getMarketOrderListByPairContent.getLong("sell_token_quantity_remain")); Assert.assertTrue(getMarketOrderListByPairContent.getJSONArray("orders").size() > 0); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketOrderListByPair by http from solidity", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketOrderListByPair by http from solidity", + groups = {"daily", "serial"}) public void test12GetMarketOrderListByPairFromSolidity() { - response = HttpMethod - .getMarketOrderListByPairFromSolidity(httpSolidityNode, "_", assetIssueId1, "true"); + response = + HttpMethod.getMarketOrderListByPairFromSolidity( + httpSolidityNode, "_", assetIssueId1, "true"); getMarketOrderListByPairContentFromSolidity = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(getMarketOrderListByPairContentFromSolidity); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); - JSONObject orders = getMarketOrderListByPairContentFromSolidity.getJSONArray("orders") - .getJSONObject( - getMarketOrderListByPairContentFromSolidity.getJSONArray("orders").size() - 1); + JSONObject orders = + getMarketOrderListByPairContentFromSolidity + .getJSONArray("orders") + .getJSONObject( + getMarketOrderListByPairContentFromSolidity.getJSONArray("orders").size() - 1); Assert.assertEquals(Base58.encode58Check(sellAddress), orders.getString("owner_address")); Assert.assertEquals("_", orders.getString("sell_token_id")); Assert.assertTrue(1000L == orders.getLong("sell_token_quantity")); Assert.assertEquals(assetIssueId1, orders.getString("buy_token_id")); Assert.assertTrue(20L == orders.getLong("buy_token_quantity")); - Assert.assertEquals(getMarketOrderListByPairContentFromSolidity.getLong("sell_token_quantity"), + Assert.assertEquals( + getMarketOrderListByPairContentFromSolidity.getLong("sell_token_quantity"), getMarketOrderListByPairContentFromSolidity.getLong("sell_token_quantity_remain")); - Assert - .assertTrue(getMarketOrderListByPairContentFromSolidity.getJSONArray("orders").size() > 0); - Assert - .assertEquals(getMarketOrderListByPairContent, getMarketOrderListByPairContentFromSolidity); - + Assert.assertTrue( + getMarketOrderListByPairContentFromSolidity.getJSONArray("orders").size() > 0); + Assert.assertEquals( + getMarketOrderListByPairContent, getMarketOrderListByPairContentFromSolidity); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketOrderListByPair by http from pbft", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketOrderListByPair by http from pbft", + groups = {"daily", "serial"}) public void test13GetMarketOrderListByPairFromPbft() { - response = HttpMethod - .getMarketOrderListByPairFromPbft(httpPbftNode, "_", assetIssueId1, "true"); + response = + HttpMethod.getMarketOrderListByPairFromPbft(httpPbftNode, "_", assetIssueId1, "true"); getMarketOrderListByPairContentFromPbft = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(getMarketOrderListByPairContentFromPbft); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); - JSONObject orders = getMarketOrderListByPairContentFromPbft.getJSONArray("orders") - .getJSONObject( - getMarketOrderListByPairContentFromPbft.getJSONArray("orders").size() - 1); + JSONObject orders = + getMarketOrderListByPairContentFromPbft + .getJSONArray("orders") + .getJSONObject( + getMarketOrderListByPairContentFromPbft.getJSONArray("orders").size() - 1); Assert.assertEquals(Base58.encode58Check(sellAddress), orders.getString("owner_address")); Assert.assertEquals("_", orders.getString("sell_token_id")); Assert.assertTrue(1000L == orders.getLong("sell_token_quantity")); Assert.assertEquals(assetIssueId1, orders.getString("buy_token_id")); Assert.assertTrue(20L == orders.getLong("buy_token_quantity")); - Assert.assertEquals(getMarketOrderListByPairContentFromPbft.getLong("sell_token_quantity"), + Assert.assertEquals( + getMarketOrderListByPairContentFromPbft.getLong("sell_token_quantity"), getMarketOrderListByPairContentFromPbft.getLong("sell_token_quantity_remain")); - Assert - .assertTrue(getMarketOrderListByPairContentFromPbft.getJSONArray("orders").size() > 0); - Assert - .assertEquals(getMarketOrderListByPairContent, getMarketOrderListByPairContentFromPbft); - + Assert.assertTrue(getMarketOrderListByPairContentFromPbft.getJSONArray("orders").size() > 0); + Assert.assertEquals(getMarketOrderListByPairContent, getMarketOrderListByPairContentFromPbft); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketPriceByPair from by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketPriceByPair from by http", + groups = {"daily", "serial"}) public void test14GetMarketPriceByPair() { response = HttpMethod.getMarketPriceByPair(httpnode, "_", assetIssueId1, "true"); getMarketPriceByPairContent = HttpMethod.parseResponseContent(response); @@ -451,54 +511,53 @@ public void test14GetMarketPriceByPair() { Assert.assertTrue(getMarketPriceByPairContent.getJSONArray("prices").size() > 0); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketPriceByPair from by http from solidity", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketPriceByPair from by http from solidity", + groups = {"daily", "serial"}) public void test15GetMarketPriceByPairFromSolidity() { - response = HttpMethod - .getMarketPriceByPairFromSolidity(httpSolidityNode, "_", assetIssueId1, "true"); + response = + HttpMethod.getMarketPriceByPairFromSolidity(httpSolidityNode, "_", assetIssueId1, "true"); getMarketPriceByPairContentFromSolidity = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(getMarketPriceByPairContentFromSolidity); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); Assert.assertEquals("_", getMarketPriceByPairContentFromSolidity.getString("sell_token_id")); - Assert - .assertEquals(assetIssueId1, - getMarketPriceByPairContentFromSolidity.getString("buy_token_id")); - JSONObject prices = getMarketPriceByPairContentFromSolidity.getJSONArray("prices") - .getJSONObject(0); + Assert.assertEquals( + assetIssueId1, getMarketPriceByPairContentFromSolidity.getString("buy_token_id")); + JSONObject prices = + getMarketPriceByPairContentFromSolidity.getJSONArray("prices").getJSONObject(0); Assert.assertEquals("50", prices.getString("sell_token_quantity")); Assert.assertEquals("1", prices.getString("buy_token_quantity")); Assert.assertTrue(getMarketPriceByPairContentFromSolidity.getJSONArray("prices").size() > 0); Assert.assertEquals(getMarketPriceByPairContent, getMarketPriceByPairContentFromSolidity); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketPriceByPair from by http from pbft", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketPriceByPair from by http from pbft", + groups = {"daily", "serial"}) public void test16GetMarketPriceByPairFromPbft() { - response = HttpMethod - .getMarketPriceByPairFromPbft(httpPbftNode, "_", assetIssueId1, "true"); + response = HttpMethod.getMarketPriceByPairFromPbft(httpPbftNode, "_", assetIssueId1, "true"); getMarketPriceByPairContentFromPbft = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(getMarketPriceByPairContentFromPbft); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); Assert.assertEquals("_", getMarketPriceByPairContentFromPbft.getString("sell_token_id")); - Assert - .assertEquals(assetIssueId1, - getMarketPriceByPairContentFromPbft.getString("buy_token_id")); - JSONObject prices = getMarketPriceByPairContentFromPbft.getJSONArray("prices") - .getJSONObject(0); + Assert.assertEquals( + assetIssueId1, getMarketPriceByPairContentFromPbft.getString("buy_token_id")); + JSONObject prices = getMarketPriceByPairContentFromPbft.getJSONArray("prices").getJSONObject(0); Assert.assertEquals("50", prices.getString("sell_token_quantity")); Assert.assertEquals("1", prices.getString("buy_token_quantity")); Assert.assertTrue(getMarketPriceByPairContentFromPbft.getJSONArray("prices").size() > 0); Assert.assertEquals(getMarketPriceByPairContent, getMarketPriceByPairContentFromPbft); } - /** - * constructor. - */ - @Test(enabled = false, description = "MarketCancelOrder trx with trc10 by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "MarketCancelOrder trx with trc10 by http", + groups = {"daily", "serial"}) public void test17MarketCancelOrder() { response = HttpMethod.getMarketOrderByAccount(httpnode, sellAddress, "true"); getMarketOrderByAccountContent = HttpMethod.parseResponseContent(response); @@ -522,12 +581,10 @@ public void test17MarketCancelOrder() { Assert.assertEquals(1, getMarketOrderByAccountContent.getJSONArray("orders").size()); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { HttpMethod.freeResource(httpnode, sellAddress, fromAddress, sellKey); HttpMethod.disConnect(); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestMarket002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestMarket002.java index 575a0769..2c9be26b 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestMarket002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestMarket002.java @@ -21,8 +21,8 @@ public class HttpTestMarket002 { private static String name = "testAssetIssue002_" + now; private static String assetIssueId1; private static String assetIssueId2; - private final String testKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); + private final String testKey002 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key1"); private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] sellAddress = ecKey1.getAddress(); @@ -39,8 +39,8 @@ public class HttpTestMarket002 { Long amount = 2048000000L; - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private JSONObject responseContent; private JSONObject getMarketOrderByIdContent; @@ -59,18 +59,18 @@ public class HttpTestMarket002 { private JSONObject getMarketPriceByPairContentFromSolidity; private JSONObject getMarketPriceByPairContentFromPbft; private HttpResponse response; - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(1); - private String httpSolidityNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); - private String httpPbftNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(4); - - - /** - * constructor. - */ - @Test(enabled = false, description = "MarketSellAsset trx with trc10 by http", groups = {"daily", "serial"}) + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(1); + private String httpSolidityNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); + private String httpPbftNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(4); + + /** constructor. */ + @Test( + enabled = false, + description = "MarketSellAsset trx with trc10 by http", + groups = {"daily", "serial"}) public void test01MarketSellAsset() { PublicMethod.printAddress(sellKey); PublicMethod.printAddress(dev002Key); @@ -80,10 +80,25 @@ public void test01MarketSellAsset() { Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - //Create an asset issue - response = HttpMethod.assetIssue(httpnode, sellAddress, name, name, totalSupply, 1, 1, - System.currentTimeMillis() + 5000, System.currentTimeMillis() + 50000000, 2, 3, description, - url, 1000L, 1000L, sellKey); + // Create an asset issue + response = + HttpMethod.assetIssue( + httpnode, + sellAddress, + name, + name, + totalSupply, + 1, + 1, + System.currentTimeMillis() + 5000, + System.currentTimeMillis() + 50000000, + 2, + 3, + description, + url, + 1000L, + 1000L, + sellKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getAccount(httpnode, sellAddress); @@ -93,9 +108,24 @@ public void test01MarketSellAsset() { logger.info(assetIssueId1); Assert.assertTrue(Integer.parseInt(assetIssueId1) > 1000000); - response = HttpMethod.assetIssue(httpnode, dev002Address, name, name, totalSupply, 1, 1, - System.currentTimeMillis() + 5000, System.currentTimeMillis() + 50000000, 2, 3, description, - url, 1000L, 1000L, dev002Key); + response = + HttpMethod.assetIssue( + httpnode, + dev002Address, + name, + name, + totalSupply, + 1, + 1, + System.currentTimeMillis() + 5000, + System.currentTimeMillis() + 50000000, + 2, + 3, + description, + url, + 1000L, + 1000L, + dev002Key); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getAccount(httpnode, dev002Address); @@ -106,8 +136,9 @@ public void test01MarketSellAsset() { Assert.assertTrue(Integer.parseInt(assetIssueId2) > 1000000); // transferAsset - response = HttpMethod - .transferAsset(httpnode, dev002Address, sellAddress, assetIssueId2, 10000L, dev002Key); + response = + HttpMethod.transferAsset( + httpnode, dev002Address, sellAddress, assetIssueId2, 10000L, dev002Key); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getAccount(httpnode, sellAddress); @@ -115,9 +146,9 @@ public void test01MarketSellAsset() { HttpMethod.printJsonContent(responseContent); // marketsellasset trc10-trc10 - txId2 = HttpMethod - .marketSellAssetGetTxId(httpnode, sellAddress, assetIssueId1, 10L, assetIssueId2, 500L, - sellKey, "false"); + txId2 = + HttpMethod.marketSellAssetGetTxId( + httpnode, sellAddress, assetIssueId1, 10L, assetIssueId2, 500L, sellKey, "false"); HttpMethod.waitToProduceOneBlock(httpnode); logger.info(txId2); response = HttpMethod.getTransactionInfoById(httpnode, txId2); @@ -128,9 +159,9 @@ public void test01MarketSellAsset() { logger.info("orderId:" + orderId); // marketsellasset trx-trc10 - txId1 = HttpMethod - .marketSellAssetGetTxId(httpnode, sellAddress, "_", 1000L, assetIssueId1, 20L, sellKey, - "false"); + txId1 = + HttpMethod.marketSellAssetGetTxId( + httpnode, sellAddress, "_", 1000L, assetIssueId1, 20L, sellKey, "false"); HttpMethod.waitToProduceOneBlock(httpnode); logger.info(txId1); response = HttpMethod.getTransactionInfoById(httpnode, txId1); @@ -141,9 +172,9 @@ public void test01MarketSellAsset() { logger.info("orderId1:" + orderId1); // marketsellasset trc10-trx - txId2 = HttpMethod - .marketSellAssetGetTxId(httpnode, sellAddress, assetIssueId1, 10L, "_", 500L, sellKey, - "false"); + txId2 = + HttpMethod.marketSellAssetGetTxId( + httpnode, sellAddress, assetIssueId1, 10L, "_", 500L, sellKey, "false"); HttpMethod.waitToProduceOneBlock(httpnode); logger.info(txId2); response = HttpMethod.getTransactionInfoById(httpnode, txId2); @@ -153,31 +184,30 @@ public void test01MarketSellAsset() { Assert.assertTrue(!responseContent.getString("orderId").isEmpty()); Assert.assertTrue(500L == orderDetails.getLong("fillBuyQuantity")); Assert.assertTrue(10L == orderDetails.getLong("fillSellQuantity")); - Assert - .assertEquals(responseContent.getString("orderId"), orderDetails.getString("takerOrderId")); + Assert.assertEquals( + responseContent.getString("orderId"), orderDetails.getString("takerOrderId")); Assert.assertEquals(orderId1, orderDetails.getString("makerOrderId")); orderId2 = responseContent.getString("orderId"); logger.info("orderId2:" + orderId2); - - } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketOrderById by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketOrderById by http", + groups = {"daily", "serial"}) public void test02GetMarketOrderById() { // getMarketOrderById orderId1 HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getMarketOrderById(httpnode, orderId1, "false"); getMarketOrderByIdContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(getMarketOrderByIdContent); - Assert.assertEquals(ByteArray.toHexString(sellAddress), - getMarketOrderByIdContent.getString("owner_address")); + Assert.assertEquals( + ByteArray.toHexString(sellAddress), getMarketOrderByIdContent.getString("owner_address")); Assert.assertEquals("5f", getMarketOrderByIdContent.getString("sell_token_id")); Assert.assertTrue(1000L == getMarketOrderByIdContent.getLong("sell_token_quantity")); - Assert.assertEquals(HttpMethod.str2hex(assetIssueId1), - getMarketOrderByIdContent.getString("buy_token_id")); + Assert.assertEquals( + HttpMethod.str2hex(assetIssueId1), getMarketOrderByIdContent.getString("buy_token_id")); Assert.assertTrue(20L == getMarketOrderByIdContent.getLong("buy_token_quantity")); Assert.assertTrue(500L == getMarketOrderByIdContent.getLong("sell_token_quantity_remain")); @@ -187,21 +217,24 @@ public void test02GetMarketOrderById() { HttpMethod.printJsonContent(getMarketOrderByIdContent2); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketOrderById by http from solidity", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketOrderById by http from solidity", + groups = {"daily", "serial"}) public void test03GetMarketOrderByIdFromSolidity() { HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSolidityNode); response = HttpMethod.getMarketOrderByIdFromSolidity(httpSolidityNode, orderId1, "false"); getMarketOrderByIdContentFromSolidity = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(getMarketOrderByIdContentFromSolidity); - Assert.assertEquals(ByteArray.toHexString(sellAddress), + Assert.assertEquals( + ByteArray.toHexString(sellAddress), getMarketOrderByIdContentFromSolidity.getString("owner_address")); Assert.assertEquals("5f", getMarketOrderByIdContentFromSolidity.getString("sell_token_id")); - Assert - .assertTrue(1000L == getMarketOrderByIdContentFromSolidity.getLong("sell_token_quantity")); - Assert.assertEquals(HttpMethod.str2hex(assetIssueId1), + Assert.assertTrue( + 1000L == getMarketOrderByIdContentFromSolidity.getLong("sell_token_quantity")); + Assert.assertEquals( + HttpMethod.str2hex(assetIssueId1), getMarketOrderByIdContentFromSolidity.getString("buy_token_id")); Assert.assertTrue(20L == getMarketOrderByIdContentFromSolidity.getLong("buy_token_quantity")); Assert.assertTrue( @@ -209,21 +242,23 @@ public void test03GetMarketOrderByIdFromSolidity() { Assert.assertEquals(getMarketOrderByIdContent, getMarketOrderByIdContentFromSolidity); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketOrderById by http from pbft", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketOrderById by http from pbft", + groups = {"daily", "serial"}) public void test04GetMarketOrderByIdFromPbft() { HttpMethod.waitToProduceOneBlockFromPbft(httpnode, httpPbftNode); response = HttpMethod.getMarketOrderByIdFromPbft(httpPbftNode, orderId1, "false"); getMarketOrderByIdContentFromPbft = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(getMarketOrderByIdContentFromPbft); - Assert.assertEquals(ByteArray.toHexString(sellAddress), + Assert.assertEquals( + ByteArray.toHexString(sellAddress), getMarketOrderByIdContentFromPbft.getString("owner_address")); Assert.assertEquals("5f", getMarketOrderByIdContentFromPbft.getString("sell_token_id")); - Assert - .assertTrue(1000L == getMarketOrderByIdContentFromPbft.getLong("sell_token_quantity")); - Assert.assertEquals(HttpMethod.str2hex(assetIssueId1), + Assert.assertTrue(1000L == getMarketOrderByIdContentFromPbft.getLong("sell_token_quantity")); + Assert.assertEquals( + HttpMethod.str2hex(assetIssueId1), getMarketOrderByIdContentFromPbft.getString("buy_token_id")); Assert.assertTrue(20L == getMarketOrderByIdContentFromPbft.getLong("buy_token_quantity")); Assert.assertTrue( @@ -231,10 +266,11 @@ public void test04GetMarketOrderByIdFromPbft() { Assert.assertEquals(getMarketOrderByIdContent, getMarketOrderByIdContentFromPbft); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketOrderByAccount by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketOrderByAccount by http", + groups = {"daily", "serial"}) public void test05GetMarketOrderByAccount() { HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getMarketOrderByAccount(httpnode, sellAddress, "false"); @@ -250,18 +286,19 @@ public void test05GetMarketOrderByAccount() { Assert.assertTrue(500L == orders.getLong("sell_token_quantity_remain")); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketOrderByAccount by http from solidity", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketOrderByAccount by http from solidity", + groups = {"daily", "serial"}) public void test06GetMarketOrderByAccountFromSolidity() { - response = HttpMethod - .getMarketOrderByAccountFromSolidity(httpSolidityNode, sellAddress, "false"); + response = + HttpMethod.getMarketOrderByAccountFromSolidity(httpSolidityNode, sellAddress, "false"); getMarketOrderByAccountContentFromSolidity = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(getMarketOrderByAccountContentFromSolidity); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); - JSONObject orders = getMarketOrderByAccountContentFromSolidity.getJSONArray("orders") - .getJSONObject(1); + JSONObject orders = + getMarketOrderByAccountContentFromSolidity.getJSONArray("orders").getJSONObject(1); Assert.assertEquals(ByteArray.toHexString(sellAddress), orders.getString("owner_address")); Assert.assertEquals("5f", orders.getString("sell_token_id")); Assert.assertTrue(1000L == orders.getLong("sell_token_quantity")); @@ -271,17 +308,18 @@ public void test06GetMarketOrderByAccountFromSolidity() { Assert.assertEquals(getMarketOrderByAccountContent, getMarketOrderByAccountContentFromSolidity); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketOrderByAccount by http from pbft", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketOrderByAccount by http from pbft", + groups = {"daily", "serial"}) public void test07GetMarketOrderByAccountFromPbft() { response = HttpMethod.getMarketOrderByAccountFromPbft(httpPbftNode, sellAddress, "false"); getMarketOrderByAccountContentFromPbft = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(getMarketOrderByAccountContentFromPbft); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); - JSONObject orders = getMarketOrderByAccountContentFromPbft.getJSONArray("orders") - .getJSONObject(1); + JSONObject orders = + getMarketOrderByAccountContentFromPbft.getJSONArray("orders").getJSONObject(1); Assert.assertEquals(ByteArray.toHexString(sellAddress), orders.getString("owner_address")); Assert.assertEquals("5f", orders.getString("sell_token_id")); Assert.assertTrue(1000L == orders.getLong("sell_token_quantity")); @@ -291,10 +329,11 @@ public void test07GetMarketOrderByAccountFromPbft() { Assert.assertEquals(getMarketOrderByAccountContent, getMarketOrderByAccountContentFromPbft); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketPairList by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketPairList by http", + groups = {"daily", "serial"}) public void test08GetMarketPairList() { response = HttpMethod.getMarketPairList(httpnode, "false"); getMarketPairListContent = HttpMethod.parseResponseContent(response); @@ -302,18 +341,25 @@ public void test08GetMarketPairList() { Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); int orderPairSize = getMarketPairListContent.getJSONArray("orderPair").size(); Assert.assertTrue(orderPairSize > 0); - Assert.assertEquals("5f", - getMarketPairListContent.getJSONArray("orderPair").getJSONObject(orderPairSize - 1) + Assert.assertEquals( + "5f", + getMarketPairListContent + .getJSONArray("orderPair") + .getJSONObject(orderPairSize - 1) .getString("sell_token_id")); - Assert.assertEquals(HttpMethod.str2hex(assetIssueId1), - getMarketPairListContent.getJSONArray("orderPair").getJSONObject(orderPairSize - 1) + Assert.assertEquals( + HttpMethod.str2hex(assetIssueId1), + getMarketPairListContent + .getJSONArray("orderPair") + .getJSONObject(orderPairSize - 1) .getString("buy_token_id")); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketPairList by http from solidity", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketPairList by http from solidity", + groups = {"daily", "serial"}) public void test09GetMarketPairListFromSolidity() { response = HttpMethod.getMarketPairListFromSolidity(httpSolidityNode, "false"); getMarketPairListContentFromSolidity = HttpMethod.parseResponseContent(response); @@ -321,22 +367,26 @@ public void test09GetMarketPairListFromSolidity() { Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); int orderPairSize = getMarketPairListContentFromSolidity.getJSONArray("orderPair").size(); Assert.assertTrue(orderPairSize > 0); - Assert.assertEquals("5f", - getMarketPairListContentFromSolidity.getJSONArray("orderPair") + Assert.assertEquals( + "5f", + getMarketPairListContentFromSolidity + .getJSONArray("orderPair") .getJSONObject(orderPairSize - 1) .getString("sell_token_id")); - Assert.assertEquals(HttpMethod.str2hex(assetIssueId1), - getMarketPairListContentFromSolidity.getJSONArray("orderPair") + Assert.assertEquals( + HttpMethod.str2hex(assetIssueId1), + getMarketPairListContentFromSolidity + .getJSONArray("orderPair") .getJSONObject(orderPairSize - 1) .getString("buy_token_id")); Assert.assertEquals(getMarketPairListContent, getMarketPairListContentFromSolidity); - } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketPairList by http from pbft", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketPairList by http from pbft", + groups = {"daily", "serial"}) public void test10GetMarketPairListFromPbft() { response = HttpMethod.getMarketPairListFromPbft(httpPbftNode, "false"); getMarketPairListContentFromPbft = HttpMethod.parseResponseContent(response); @@ -344,162 +394,176 @@ public void test10GetMarketPairListFromPbft() { Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); int orderPairSize = getMarketPairListContentFromPbft.getJSONArray("orderPair").size(); Assert.assertTrue(orderPairSize > 0); - Assert.assertEquals("5f", - getMarketPairListContentFromPbft.getJSONArray("orderPair") + Assert.assertEquals( + "5f", + getMarketPairListContentFromPbft + .getJSONArray("orderPair") .getJSONObject(orderPairSize - 1) .getString("sell_token_id")); - Assert.assertEquals(HttpMethod.str2hex(assetIssueId1), - getMarketPairListContentFromPbft.getJSONArray("orderPair") + Assert.assertEquals( + HttpMethod.str2hex(assetIssueId1), + getMarketPairListContentFromPbft + .getJSONArray("orderPair") .getJSONObject(orderPairSize - 1) .getString("buy_token_id")); Assert.assertEquals(getMarketPairListContent, getMarketPairListContentFromPbft); - } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketOrderListByPair by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketOrderListByPair by http", + groups = {"daily", "serial"}) public void test11GetMarketOrderListByPair() { response = HttpMethod.getMarketOrderListByPair(httpnode, "_", assetIssueId1, "false"); getMarketOrderListByPairContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(getMarketOrderListByPairContent); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); - JSONObject orders = getMarketOrderListByPairContent.getJSONArray("orders") - .getJSONObject(getMarketOrderListByPairContent.getJSONArray("orders").size() - 1); + JSONObject orders = + getMarketOrderListByPairContent + .getJSONArray("orders") + .getJSONObject(getMarketOrderListByPairContent.getJSONArray("orders").size() - 1); Assert.assertEquals(ByteArray.toHexString(sellAddress), orders.getString("owner_address")); Assert.assertEquals("5f", orders.getString("sell_token_id")); Assert.assertTrue(1000L == orders.getLong("sell_token_quantity")); Assert.assertEquals(HttpMethod.str2hex(assetIssueId1), orders.getString("buy_token_id")); Assert.assertTrue(20L == orders.getLong("buy_token_quantity")); - Assert.assertEquals(getMarketOrderListByPairContent.getLong("sell_token_quantity"), + Assert.assertEquals( + getMarketOrderListByPairContent.getLong("sell_token_quantity"), getMarketOrderListByPairContent.getLong("sell_token_quantity_remain")); Assert.assertTrue(getMarketOrderListByPairContent.getJSONArray("orders").size() > 0); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketOrderListByPair by http from solidity", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketOrderListByPair by http from solidity", + groups = {"daily", "serial"}) public void test12GetMarketOrderListByPairFromSolidity() { - response = HttpMethod - .getMarketOrderListByPairFromSolidity(httpSolidityNode, "_", assetIssueId1, "false"); + response = + HttpMethod.getMarketOrderListByPairFromSolidity( + httpSolidityNode, "_", assetIssueId1, "false"); getMarketOrderListByPairContentFromSolidity = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(getMarketOrderListByPairContentFromSolidity); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); - JSONObject orders = getMarketOrderListByPairContentFromSolidity.getJSONArray("orders") - .getJSONObject( - getMarketOrderListByPairContentFromSolidity.getJSONArray("orders").size() - 1); + JSONObject orders = + getMarketOrderListByPairContentFromSolidity + .getJSONArray("orders") + .getJSONObject( + getMarketOrderListByPairContentFromSolidity.getJSONArray("orders").size() - 1); Assert.assertEquals(ByteArray.toHexString(sellAddress), orders.getString("owner_address")); Assert.assertEquals("5f", orders.getString("sell_token_id")); Assert.assertTrue(1000L == orders.getLong("sell_token_quantity")); Assert.assertEquals(HttpMethod.str2hex(assetIssueId1), orders.getString("buy_token_id")); Assert.assertTrue(20L == orders.getLong("buy_token_quantity")); - Assert.assertEquals(getMarketOrderListByPairContentFromSolidity.getLong("sell_token_quantity"), + Assert.assertEquals( + getMarketOrderListByPairContentFromSolidity.getLong("sell_token_quantity"), getMarketOrderListByPairContentFromSolidity.getLong("sell_token_quantity_remain")); - Assert - .assertTrue(getMarketOrderListByPairContentFromSolidity.getJSONArray("orders").size() > 0); - Assert - .assertEquals(getMarketOrderListByPairContent, getMarketOrderListByPairContentFromSolidity); - + Assert.assertTrue( + getMarketOrderListByPairContentFromSolidity.getJSONArray("orders").size() > 0); + Assert.assertEquals( + getMarketOrderListByPairContent, getMarketOrderListByPairContentFromSolidity); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketOrderListByPair by http from pbft", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketOrderListByPair by http from pbft", + groups = {"daily", "serial"}) public void test13GetMarketOrderListByPairFromPbft() { - response = HttpMethod - .getMarketOrderListByPairFromPbft(httpPbftNode, "_", assetIssueId1, "false"); + response = + HttpMethod.getMarketOrderListByPairFromPbft(httpPbftNode, "_", assetIssueId1, "false"); getMarketOrderListByPairContentFromPbft = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(getMarketOrderListByPairContentFromPbft); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); - JSONObject orders = getMarketOrderListByPairContentFromPbft.getJSONArray("orders") - .getJSONObject( - getMarketOrderListByPairContentFromPbft.getJSONArray("orders").size() - 1); + JSONObject orders = + getMarketOrderListByPairContentFromPbft + .getJSONArray("orders") + .getJSONObject( + getMarketOrderListByPairContentFromPbft.getJSONArray("orders").size() - 1); Assert.assertEquals(ByteArray.toHexString(sellAddress), orders.getString("owner_address")); Assert.assertEquals("5f", orders.getString("sell_token_id")); Assert.assertTrue(1000L == orders.getLong("sell_token_quantity")); Assert.assertEquals(HttpMethod.str2hex(assetIssueId1), orders.getString("buy_token_id")); Assert.assertTrue(20L == orders.getLong("buy_token_quantity")); - Assert.assertEquals(getMarketOrderListByPairContentFromPbft.getLong("sell_token_quantity"), + Assert.assertEquals( + getMarketOrderListByPairContentFromPbft.getLong("sell_token_quantity"), getMarketOrderListByPairContentFromPbft.getLong("sell_token_quantity_remain")); - Assert - .assertTrue(getMarketOrderListByPairContentFromPbft.getJSONArray("orders").size() > 0); - Assert - .assertEquals(getMarketOrderListByPairContent, getMarketOrderListByPairContentFromPbft); - + Assert.assertTrue(getMarketOrderListByPairContentFromPbft.getJSONArray("orders").size() > 0); + Assert.assertEquals(getMarketOrderListByPairContent, getMarketOrderListByPairContentFromPbft); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketPriceByPair from by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketPriceByPair from by http", + groups = {"daily", "serial"}) public void test14GetMarketPriceByPair() { response = HttpMethod.getMarketPriceByPair(httpnode, "_", assetIssueId1, "false"); getMarketPriceByPairContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(getMarketPriceByPairContent); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); Assert.assertEquals("5f", getMarketPriceByPairContent.getString("sell_token_id")); - Assert.assertEquals(HttpMethod.str2hex(assetIssueId1), - getMarketPriceByPairContent.getString("buy_token_id")); + Assert.assertEquals( + HttpMethod.str2hex(assetIssueId1), getMarketPriceByPairContent.getString("buy_token_id")); JSONObject prices = getMarketPriceByPairContent.getJSONArray("prices").getJSONObject(0); Assert.assertEquals("50", prices.getString("sell_token_quantity")); Assert.assertEquals("1", prices.getString("buy_token_quantity")); Assert.assertTrue(getMarketPriceByPairContent.getJSONArray("prices").size() > 0); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketPriceByPair from by http from solidity", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketPriceByPair from by http from solidity", + groups = {"daily", "serial"}) public void test15GetMarketPriceByPairFromSolidity() { - response = HttpMethod - .getMarketPriceByPairFromSolidity(httpSolidityNode, "_", assetIssueId1, "false"); + response = + HttpMethod.getMarketPriceByPairFromSolidity(httpSolidityNode, "_", assetIssueId1, "false"); getMarketPriceByPairContentFromSolidity = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(getMarketPriceByPairContentFromSolidity); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); Assert.assertEquals("5f", getMarketPriceByPairContentFromSolidity.getString("sell_token_id")); - Assert - .assertEquals(HttpMethod.str2hex(assetIssueId1), - getMarketPriceByPairContentFromSolidity.getString("buy_token_id")); - JSONObject prices = getMarketPriceByPairContentFromSolidity.getJSONArray("prices") - .getJSONObject(0); + Assert.assertEquals( + HttpMethod.str2hex(assetIssueId1), + getMarketPriceByPairContentFromSolidity.getString("buy_token_id")); + JSONObject prices = + getMarketPriceByPairContentFromSolidity.getJSONArray("prices").getJSONObject(0); Assert.assertEquals("50", prices.getString("sell_token_quantity")); Assert.assertEquals("1", prices.getString("buy_token_quantity")); Assert.assertTrue(getMarketPriceByPairContentFromSolidity.getJSONArray("prices").size() > 0); Assert.assertEquals(getMarketPriceByPairContent, getMarketPriceByPairContentFromSolidity); } - /** - * constructor. - */ - @Test(enabled = false, description = "GetMarketPriceByPair from by http from pbft", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "GetMarketPriceByPair from by http from pbft", + groups = {"daily", "serial"}) public void test16GetMarketPriceByPairFromPbft() { - response = HttpMethod - .getMarketPriceByPairFromPbft(httpPbftNode, "_", assetIssueId1, "false"); + response = HttpMethod.getMarketPriceByPairFromPbft(httpPbftNode, "_", assetIssueId1, "false"); getMarketPriceByPairContentFromPbft = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(getMarketPriceByPairContentFromPbft); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); Assert.assertEquals("5f", getMarketPriceByPairContentFromPbft.getString("sell_token_id")); - Assert - .assertEquals(HttpMethod.str2hex(assetIssueId1), - getMarketPriceByPairContentFromPbft.getString("buy_token_id")); - JSONObject prices = getMarketPriceByPairContentFromPbft.getJSONArray("prices") - .getJSONObject(0); + Assert.assertEquals( + HttpMethod.str2hex(assetIssueId1), + getMarketPriceByPairContentFromPbft.getString("buy_token_id")); + JSONObject prices = getMarketPriceByPairContentFromPbft.getJSONArray("prices").getJSONObject(0); Assert.assertEquals("50", prices.getString("sell_token_quantity")); Assert.assertEquals("1", prices.getString("buy_token_quantity")); Assert.assertTrue(getMarketPriceByPairContentFromPbft.getJSONArray("prices").size() > 0); Assert.assertEquals(getMarketPriceByPairContent, getMarketPriceByPairContentFromPbft); } - /** - * constructor. - */ - @Test(enabled = false, description = "MarketCancelOrder trx with trc10 by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "MarketCancelOrder trx with trc10 by http", + groups = {"daily", "serial"}) public void test17MarketCancelOrder() { response = HttpMethod.getMarketOrderByAccount(httpnode, sellAddress, "false"); getMarketOrderByAccountContent = HttpMethod.parseResponseContent(response); @@ -523,12 +587,10 @@ public void test17MarketCancelOrder() { Assert.assertEquals(1, getMarketOrderByAccountContent.getJSONArray("orders").size()); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { HttpMethod.freeResource(httpnode, sellAddress, fromAddress, sellKey); HttpMethod.disConnect(); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestMortgageMechanism01.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestMortgageMechanism01.java index c65fd2ac..3ac34496 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestMortgageMechanism01.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestMortgageMechanism01.java @@ -44,7 +44,10 @@ public class HttpTestMortgageMechanism01 { private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); /** constructor. */ - @Test(enabled = true, description = "GetBrokerage by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "GetBrokerage by http", + groups = {"daily", "serial"}) public void test01GetBrokerage() { response = HttpMethod.getBrokerage(httpnode, witnessAddress); responseContent = HttpMethod.parseResponseContent(response); @@ -65,7 +68,10 @@ public void test01GetBrokerage() { Assert.assertTrue(Integer.parseInt(responseContent.getString("brokerage")) < 100); } - @Test(enabled = true, description = "GetBrokerage from solidity by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "GetBrokerage from solidity by http", + groups = {"daily", "serial"}) public void test02GetBrokerageFromSolidity() { response = HttpMethod.getBrokerageFromSolidity(httpSoliditynode, witnessAddress); responseContent = HttpMethod.parseResponseContent(response); @@ -73,7 +79,6 @@ public void test02GetBrokerageFromSolidity() { Assert.assertTrue(Integer.parseInt(responseContent.getString("brokerage")) > 0); Assert.assertTrue(Integer.parseInt(responseContent.getString("brokerage")) < 100); - response = HttpMethod.getBrokerageFromSolidityOnVisible(httpSoliditynode, witnessAddress2, "true"); responseContent = HttpMethod.parseResponseContent(response); @@ -89,7 +94,10 @@ public void test02GetBrokerageFromSolidity() { } /** constructor. */ - @Test(enabled = true, description = "GetBrokerage from PBFT by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "GetBrokerage from PBFT by http", + groups = {"daily", "serial"}) public void test03GetBrokerageFromPbft() { response = HttpMethod.getBrokerageFromPbft(httpPbftNode, witnessAddress); responseContent = HttpMethod.parseResponseContent(response); @@ -99,7 +107,10 @@ public void test03GetBrokerageFromPbft() { } /** constructor. */ - @Test(enabled = true, description = "UpdateBrokerage by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "UpdateBrokerage by http", + groups = {"daily", "serial"}) public void test04UpdateBrokerage() { response = HttpMethod.sendCoin(httpnode, fromAddress, witnessAddress, amount, testKey002); Assert.assertTrue(HttpMethod.verificationResult(response)); @@ -137,7 +148,10 @@ public void test04UpdateBrokerage() { } /** constructor. */ - @Test(enabled = true, description = "GetReward by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "GetReward by http", + groups = {"daily", "serial"}) public void test05GetReward() { response = HttpMethod.getReward(httpnode, witnessAddress); responseContent = HttpMethod.parseResponseContent(response); @@ -159,7 +173,10 @@ public void test05GetReward() { } /** constructor. */ - @Test(enabled = true, description = "GetReward from solidity by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "GetReward from solidity by http", + groups = {"daily", "serial"}) public void test06GetRewardFromSolidity() { response = HttpMethod.getRewardFromSolidity(httpSoliditynode, witnessAddress); responseContent = HttpMethod.parseResponseContent(response); @@ -181,7 +198,10 @@ public void test06GetRewardFromSolidity() { } /** constructor. */ - @Test(enabled = true, description = "GetReward from PBFT by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "GetReward from PBFT by http", + groups = {"daily", "serial"}) public void test07GetRewardFromPbft() { response = HttpMethod.getRewardFromPbft(httpPbftNode, witnessAddress); responseContent = HttpMethod.parseResponseContent(response); diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestMultiSign001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestMultiSign001.java index 8546afbb..2d6e0d10 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestMultiSign001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestMultiSign001.java @@ -3,7 +3,6 @@ import com.alibaba.fastjson.JSONObject; import com.google.gson.JsonArray; import com.google.gson.JsonObject; - import java.util.List; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; @@ -17,8 +16,8 @@ import stest.tron.wallet.common.client.utils.HttpMethod; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class HttpTestMultiSign001 extends TronBaseTest { @@ -53,13 +52,17 @@ public class HttpTestMultiSign001 extends TronBaseTest { /** constructor. */ @BeforeClass - public void beforeClass() { } + public void beforeClass() {} /** constructor. */ - @Test(enabled = true, description = "Account Permission Up Date by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Account Permission Up Date by http", + groups = {"daily", "serial"}) public void test1AccountPermissionUpDate() { PublicMethod.printAddress(ownerKey); - response = HttpMethod.sendCoin(httpnode, foundationAddress, ownerAddress, amount, foundationKey); + response = + HttpMethod.sendCoin(httpnode, foundationAddress, ownerAddress, amount, foundationKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); manager1Wight.addProperty("address", ByteArray.toHexString(foundationAddress)); @@ -105,7 +108,10 @@ public void test1AccountPermissionUpDate() { } /** constructor. */ - @Test(enabled = true, description = "Add transaction sign by http with permission id", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Add transaction sign by http with permission id", + groups = {"daily", "serial"}) public void test2AddTransactionSign() { HttpMethod.waitToProduceOneBlock(httpnode); @@ -146,44 +152,55 @@ public void test2AddTransactionSign() { /** constructor. */ @Test( enabled = true, - description = "Add broadcasthex http interface to " + "broadcast hex transaction string", groups = {"daily", "serial"}) + description = "Add broadcasthex http interface to " + "broadcast hex transaction string", + groups = {"daily", "serial"}) public void test3Broadcasthex() { PublicMethod.printAddress(hexTestKey); - String transactionHex = + String transactionHex = PublicMethod.sendcoinGetTransactionHex( hexTestAddress, 1000L, foundationAddress, foundationKey, blockingStubFull); - // Wrong type of hex + // Wrong type of hex response = HttpMethod.broadcasthex(httpnode, transactionHex); Assert.assertTrue(HttpMethod.verificationResult(response)); - String wrongTransactionHex = transactionHex + "wrong"; + String wrongTransactionHex = transactionHex + "wrong"; response = HttpMethod.broadcasthex(httpnode, wrongTransactionHex); logger.info("transaction wrong:"); Assert.assertFalse(HttpMethod.verificationResult(response)); - // SingleSign for broadcastHex + // SingleSign for broadcastHex response = HttpMethod.broadcasthex(httpnode, transactionHex); Assert.assertFalse(HttpMethod.verificationResult(response)); - // Multisign for broadcastHex + // Multisign for broadcastHex String multiSignTransactionHex = PublicMethodForMultiSign.sendcoinGetTransactionHex( hexTestAddress, 999L, ownerAddress, ownerKey, blockingStubFull, permissionKeyString); response = HttpMethod.broadcasthex(httpnode, multiSignTransactionHex); Assert.assertTrue(HttpMethod.verificationResult(response)); - // Hex is null + // Hex is null response = HttpMethod.broadcasthex(httpnode, ""); Assert.assertFalse(HttpMethod.verificationResult(response)); } - @Test(enabled = true, description = "GetApprovedList type is wrong by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "GetApprovedList type is wrong by http", + groups = {"daily", "serial"}) public void test4getApprovedListTypeWrong() { permissionKeyString = new String[2]; permissionKeyString[0] = foundationKey; permissionKeyString[1] = manager2Key; - String originType = "\"type\":\"TransferContract\""; - String type = "\"type\": \"TransferContract1111111\""; + String originType = "\"type\":\"TransferContract\""; + String type = "\"type\": \"TransferContract1111111\""; response = HttpMethod.sendCoinReplaceTransactionType( - httpnode, foundationAddress, receiverAddress, 10L, 0, permissionKeyString, originType, type); + httpnode, + foundationAddress, + receiverAddress, + 10L, + 0, + permissionKeyString, + originType, + type); Assert.assertTrue(!HttpMethod.verificationResult(response)); responseContent = HttpMethod.parseResponseContent(response); Assert.assertEquals(responseContent.getJSONObject("result").getString("code"), "OTHER_ERROR"); @@ -193,16 +210,26 @@ public void test4getApprovedListTypeWrong() { } /** constructor. */ - @Test(enabled = true, description = "GetApprovedList without type by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "GetApprovedList without type by http", + groups = {"daily", "serial"}) public void test5getApprovedListWithoutType() { permissionKeyString = new String[2]; permissionKeyString[0] = foundationKey; permissionKeyString[1] = manager2Key; - String originType = "," + "\"type\":\"TransferContract\""; - String type = " "; + String originType = "," + "\"type\":\"TransferContract\""; + String type = " "; response = HttpMethod.sendCoinReplaceTransactionType( - httpnode, foundationAddress, receiverAddress, 10L, 0, permissionKeyString, originType, type); + httpnode, + foundationAddress, + receiverAddress, + 10L, + 0, + permissionKeyString, + originType, + type); Assert.assertTrue(!HttpMethod.verificationResult(response)); responseContent = HttpMethod.parseResponseContent(response); Assert.assertEquals("OTHER_ERROR", responseContent.getJSONObject("result").getString("code")); @@ -214,5 +241,6 @@ public void test5getApprovedListWithoutType() { /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - HttpMethod.disConnect(); } + HttpMethod.disConnect(); + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestProposal001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestProposal001.java index aa4f1035..23f645ab 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestProposal001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestProposal001.java @@ -13,7 +13,6 @@ import stest.tron.wallet.common.client.utils.HttpMethod; import stest.tron.wallet.common.client.utils.PublicMethod; - @Slf4j public class HttpTestProposal001 { @@ -35,7 +34,10 @@ public class HttpTestProposal001 { private int bandFee = 0; /** constructor. */ - @Test(enabled = true, description = "Create proposal by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Create proposal by http", + groups = {"daily", "serial"}) public void test1CreateProposal() { response = HttpMethod.createProposal(httpnode, witness1Address, 20L, 1L, witnessKey001); Assert.assertTrue(HttpMethod.verificationResult(response)); @@ -43,7 +45,10 @@ public void test1CreateProposal() { } /** * constructor. * */ - @Test(enabled = true, description = "List proposals by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "List proposals by http", + groups = {"daily", "serial"}) public void test2ListProposals() { response = HttpMethod.listProposals(httpnode); responseContent = HttpMethod.parseResponseContent(response); @@ -54,7 +59,10 @@ public void test2ListProposals() { } /** constructor. */ - @Test(enabled = true, description = "GetProposalById by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "GetProposalById by http", + groups = {"daily", "serial"}) public void test3GetExchangeById() { response = HttpMethod.getProposalById(httpnode, proposalId); responseContent = HttpMethod.parseResponseContent(response); @@ -65,7 +73,10 @@ public void test3GetExchangeById() { } /** constructor. */ - @Test(enabled = true, description = "Approval proposal by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Approval proposal by http", + groups = {"daily", "serial"}) public void test4ApprovalProposal() { response = HttpMethod.approvalProposal(httpnode, witness1Address, proposalId, true, witnessKey001); @@ -83,7 +94,10 @@ public void test4ApprovalProposal() { } /** * constructor. * */ - @Test(enabled = true, description = "Get paginated proposal list by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get paginated proposal list by http", + groups = {"daily", "serial"}) public void test5GetPaginatedProposalList() { response = HttpMethod.getPaginatedProposalList(httpnode, 0, 1); @@ -96,7 +110,10 @@ public void test5GetPaginatedProposalList() { } /** constructor. */ - @Test(enabled = true, description = "Delete proposal by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Delete proposal by http", + groups = {"daily", "serial"}) public void test6DeleteProposal() { response = HttpMethod.deleteProposal(httpnode, witness1Address, proposalId, witnessKey001); Assert.assertTrue(HttpMethod.verificationResult(response)); @@ -108,7 +125,10 @@ public void test6DeleteProposal() { } /** constructor. */ - @Test(enabled = true, description = "Get chain parameters by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get chain parameters by http", + groups = {"daily", "serial"}) public void test7GetChainParameters() { response = HttpMethod.getChainParameters(httpnode); responseContent = HttpMethod.parseResponseContent(response); @@ -136,7 +156,10 @@ public void test7GetChainParameters() { } /** constructor. */ - @Test(enabled = true, description = "Get energy price by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get energy price by http", + groups = {"daily", "serial"}) public void test8GetEnergyPrice() { response = HttpMethod.getEnergyPric(httpnode); responseContent = HttpMethod.parseResponseContent(response); @@ -148,8 +171,10 @@ public void test8GetEnergyPrice() { } /** constructor. */ - - @Test(enabled = true, description = "Get band price by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get band price by http", + groups = {"daily", "serial"}) public void test8GetBandPrice() { response = HttpMethod.getBandPric(httpnode); responseContent = HttpMethod.parseResponseContent(response); diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestResourcePrices.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestResourcePrices.java index bbb2e505..1ac5a480 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestResourcePrices.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestResourcePrices.java @@ -11,85 +11,100 @@ public class HttpTestResourcePrices { private JSONObject responseContent; private HttpResponse response; - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(0); - private String httpSoliditynode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); - private String httpPbftNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(4); - private String httpnodeSolidityPort = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(3); - - - @Test(enabled = true, description = "get MemoFee from http interface", groups = {"daily", "serial"}) + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); + private String httpSoliditynode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); + private String httpPbftNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(4); + private String httpnodeSolidityPort = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(3); + + @Test( + enabled = true, + description = "get MemoFee from http interface", + groups = {"daily", "serial"}) public void test01GetMemoFee() { - //get MemoFee from chainParameters - Long memoFeeChainParameter = HttpMethod.getProposalValue(httpnode, ProposalEnum.GetMemoFee.getProposalName()); + // get MemoFee from chainParameters + Long memoFeeChainParameter = + HttpMethod.getProposalValue(httpnode, ProposalEnum.GetMemoFee.getProposalName()); - //get MemoFee from http - HttpResponse res = HttpMethod.getMemoFee(httpnode); - String prices = HttpMethod.parseResponseContent(res).getString("prices"); + // get MemoFee from http + HttpResponse res = HttpMethod.getMemoFee(httpnode); + String prices = HttpMethod.parseResponseContent(res).getString("prices"); Long memoNow = Long.parseLong(prices.split(":")[2]); Assert.assertEquals(memoFeeChainParameter.longValue(), memoNow.longValue()); } - @Test(enabled = true, description = "get Energy prices from http interface", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "get Energy prices from http interface", + groups = {"daily", "serial"}) public void test02GetEnergyPrices() { - //get EnergyPrice from chainParameters - Long energyPriceChainParameter = HttpMethod.getProposalValue(httpnode, ProposalEnum.GetEnergyFee.getProposalName()); + // get EnergyPrice from chainParameters + Long energyPriceChainParameter = + HttpMethod.getProposalValue(httpnode, ProposalEnum.GetEnergyFee.getProposalName()); - //get EnergyPrice from http + // get EnergyPrice from http HttpResponse res = HttpMethod.getEnergyPric(httpnode); String prices = HttpMethod.parseResponseContent(res).getString("prices"); Long energyPriceNow = Long.parseLong(prices.split(":")[2]); Assert.assertEquals(energyPriceChainParameter.longValue(), energyPriceNow.longValue()); - //get EnergyPrice from http solidityNode + // get EnergyPrice from http solidityNode HttpResponse resSolidity = HttpMethod.getEnergyPricSolidity(httpSoliditynode); String pricesSolidity = HttpMethod.parseResponseContent(resSolidity).getString("prices"); Long energyPriceSolidity = Long.parseLong(pricesSolidity.split(":")[2]); Assert.assertEquals(energyPriceChainParameter.longValue(), energyPriceSolidity.longValue()); - //get EnergyPrice from FullNode Solidity port + // get EnergyPrice from FullNode Solidity port HttpResponse resSolidityport = HttpMethod.getEnergyPricSolidity(httpnodeSolidityPort); - String pricesSolidityPort = HttpMethod.parseResponseContent(resSolidityport).getString("prices"); + String pricesSolidityPort = + HttpMethod.parseResponseContent(resSolidityport).getString("prices"); Long energyPriceSolidityPort = Long.parseLong(pricesSolidityPort.split(":")[2]); Assert.assertEquals(energyPriceChainParameter.longValue(), energyPriceSolidityPort.longValue()); - //get EnergyPrice from http pbft + // get EnergyPrice from http pbft HttpResponse resPbft = HttpMethod.getEnergyPricPbft(httpPbftNode); String pricesPbft = HttpMethod.parseResponseContent(resPbft).getString("prices"); Long energyPricePbft = Long.parseLong(pricesPbft.split(":")[2]); Assert.assertEquals(energyPriceChainParameter.longValue(), energyPricePbft.longValue()); } - @Test(enabled = true, description = "get Bandwidth prices from http interface", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "get Bandwidth prices from http interface", + groups = {"daily", "serial"}) public void test02GetBandwidthPrices() { - //get Bandwidth prices from chainParameters - Long BandwidthPriceChainParameter = HttpMethod.getProposalValue(httpnode, ProposalEnum.getTransactionFee.getProposalName()); + // get Bandwidth prices from chainParameters + Long BandwidthPriceChainParameter = + HttpMethod.getProposalValue(httpnode, ProposalEnum.getTransactionFee.getProposalName()); - //get BandwidthPrice from http + // get BandwidthPrice from http HttpResponse res = HttpMethod.getBandPric(httpnode); String prices = HttpMethod.parseResponseContent(res).getString("prices"); Long BandwidthPriceNow = Long.parseLong(prices.split(":")[2]); Assert.assertEquals(BandwidthPriceChainParameter.longValue(), BandwidthPriceNow.longValue()); - //get BandwidthPrice from http solidity + // get BandwidthPrice from http solidity HttpResponse resSolidity = HttpMethod.getBandPricSolidity(httpSoliditynode); String pricesSolidity = HttpMethod.parseResponseContent(resSolidity).getString("prices"); Long bandwidthPriceSolidity = Long.parseLong(pricesSolidity.split(":")[2]); - Assert.assertEquals(BandwidthPriceChainParameter.longValue(), bandwidthPriceSolidity.longValue()); + Assert.assertEquals( + BandwidthPriceChainParameter.longValue(), bandwidthPriceSolidity.longValue()); - //get BandwidthPrice from FullNode solidity port + // get BandwidthPrice from FullNode solidity port HttpResponse resSolidityPort = HttpMethod.getBandPricSolidity(httpnodeSolidityPort); - String pricesSolidityPort = HttpMethod.parseResponseContent(resSolidityPort).getString("prices"); + String pricesSolidityPort = + HttpMethod.parseResponseContent(resSolidityPort).getString("prices"); Long bandwidthPriceSolidityPort = Long.parseLong(pricesSolidityPort.split(":")[2]); - Assert.assertEquals(BandwidthPriceChainParameter.longValue(), bandwidthPriceSolidityPort.longValue()); + Assert.assertEquals( + BandwidthPriceChainParameter.longValue(), bandwidthPriceSolidityPort.longValue()); - //get BandwidthPrice from http pbft + // get BandwidthPrice from http pbft HttpResponse resPbft = HttpMethod.getBandPricPbft(httpPbftNode); String pricesPbft = HttpMethod.parseResponseContent(resPbft).getString("prices"); Long bandwidthPricePbft = Long.parseLong(pricesPbft.split(":")[2]); diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestSendCoin001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestSendCoin001.java index f9c0a0ab..5db33694 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestSendCoin001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestSendCoin001.java @@ -17,26 +17,28 @@ @Slf4j public class HttpTestSendCoin001 { - private final String testKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); + private final String testKey002 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key1"); private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] receiverAddress = ecKey1.getAddress(); String receiverKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); Long amount = 1000L; - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(1); - private String httpSoliditynode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); - private String httpPbftNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(4); + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(1); + private String httpSoliditynode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); + private String httpPbftNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(4); private JSONObject responseContent; private HttpResponse response; String txid; - /** - * constructor. - */ - @Test(enabled = true, description = "SendCoin by http", groups = {"daily", "serial"}) + /** constructor. */ + + @Test( + enabled = true, + description = "SendCoin by http", + groups = {"daily", "serial"}) public void test1SendCoin() { response = HttpMethod.sendCoin(httpnode, fromAddress, receiverAddress, amount, testKey002); Assert.assertTrue(HttpMethod.verificationResult(response)); @@ -44,13 +46,13 @@ public void test1SendCoin() { Assert.assertEquals(HttpMethod.getBalance(httpnode, receiverAddress), amount); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get transaction by id from solidity by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get transaction by id from solidity by http", + groups = {"daily", "serial"}) public void test2GetTransactionByIdFromSolidity() { - txid = HttpMethod - .sendCoinGetTxid(httpnode, fromAddress, receiverAddress, amount, testKey002); + txid = HttpMethod.sendCoinGetTxid(httpnode, fromAddress, receiverAddress, amount, testKey002); HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSoliditynode); response = HttpMethod.getTransactionByIdFromSolidity(httpSoliditynode, txid); @@ -63,10 +65,11 @@ public void test2GetTransactionByIdFromSolidity() { Assert.assertTrue(responseContent.size() > 4); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get transaction by id from PBFT by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get transaction by id from PBFT by http", + groups = {"daily", "serial"}) public void test3GetTransactionByIdFromPbft() { response = HttpMethod.getTransactionByIdFromPbft(httpPbftNode, txid); responseContent = HttpMethod.parseResponseContent(response); @@ -78,11 +81,11 @@ public void test3GetTransactionByIdFromPbft() { Assert.assertTrue(responseContent.size() > 4); } - - /** - * constructor. - */ - @Test(enabled = true, description = "Get transaction info by id from solidity by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get transaction info by id from solidity by http", + groups = {"daily", "serial"}) public void test4GetTransactionInfoByIdFromSolidity() { response = HttpMethod.getTransactionInfoByIdFromSolidity(httpSoliditynode, txid); responseContent = HttpMethod.parseResponseContent(response); @@ -90,10 +93,11 @@ public void test4GetTransactionInfoByIdFromSolidity() { Assert.assertTrue(responseContent.size() > 4); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get transaction info by id from PBFT by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get transaction info by id from PBFT by http", + groups = {"daily", "serial"}) public void test5GetTransactionInfoByIdFromPbft() { response = HttpMethod.getTransactionInfoByIdFromPbft(httpPbftNode, txid); responseContent = HttpMethod.parseResponseContent(response); @@ -101,19 +105,20 @@ public void test5GetTransactionInfoByIdFromPbft() { Assert.assertTrue(responseContent.size() > 4); } - - /** - * constructor. - */ - @Test(enabled = false, description = "Get transactions from this from solidity by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "Get transactions from this from solidity by http", + groups = {"daily", "serial"}) public void test4GetTransactionsFromThisFromSolidity() { - response = HttpMethod - .getTransactionsFromThisFromSolidity(httpSoliditynode, fromAddress, 0, 100); + response = + HttpMethod.getTransactionsFromThisFromSolidity(httpSoliditynode, fromAddress, 0, 100); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - JSONObject transactionObject = HttpMethod.parseStringContent( - JSONArray.parseArray(responseContent.getString("transaction")).get(0).toString()); + JSONObject transactionObject = + HttpMethod.parseStringContent( + JSONArray.parseArray(responseContent.getString("transaction")).get(0).toString()); String retString = transactionObject.getString("ret"); JSONArray array = JSONArray.parseArray(retString); Assert.assertEquals( @@ -121,18 +126,20 @@ public void test4GetTransactionsFromThisFromSolidity() { Assert.assertTrue(responseContent.size() == 1); } - /** - * constructor. - */ - @Test(enabled = false, description = "Get transactions to this from solidity by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "Get transactions to this from solidity by http", + groups = {"daily", "serial"}) public void test5GetTransactionsToThisFromSolidity() { - response = HttpMethod - .getTransactionsFromThisFromSolidity(httpSoliditynode, fromAddress, 0, 100); + response = + HttpMethod.getTransactionsFromThisFromSolidity(httpSoliditynode, fromAddress, 0, 100); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - JSONObject transactionObject = HttpMethod.parseStringContent( - JSONArray.parseArray(responseContent.getString("transaction")).get(0).toString()); + JSONObject transactionObject = + HttpMethod.parseStringContent( + JSONArray.parseArray(responseContent.getString("transaction")).get(0).toString()); String retString = transactionObject.getString("ret"); JSONArray array = JSONArray.parseArray(retString); Assert.assertEquals( @@ -140,13 +147,10 @@ public void test5GetTransactionsToThisFromSolidity() { Assert.assertTrue(responseContent.size() == 1); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { HttpMethod.freeResource(httpnode, receiverAddress, fromAddress, receiverKey); HttpMethod.disConnect(); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestSmartContract001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestSmartContract001.java index 3bb31d9d..5948ab11 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestSmartContract001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestSmartContract001.java @@ -50,7 +50,10 @@ public class HttpTestSmartContract001 { JSONObject responseCon2; /** constructor. */ - @Test(enabled = true, description = "Deploy smart contract by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Deploy smart contract by http", + groups = {"daily", "serial"}) public void test1DeployContract() { PublicMethod.printAddress(assetOwnerKey); response = HttpMethod.sendCoin(httpnode, fromAddress, assetOwnerAddress, amount, testKey002); @@ -139,7 +142,10 @@ public void test1DeployContract() { } /** constructor. */ - @Test(enabled = true, description = "Get contract by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get contract by http", + groups = {"daily", "serial"}) public void test2GetContract() { response = HttpMethod.getContract(httpnode, contractAddress); responseContent = HttpMethod.parseResponseContent(response); @@ -154,7 +160,10 @@ public void test2GetContract() { } /** constructor. */ - @Test(enabled = true, description = "Trigger contract by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Trigger contract by http", + groups = {"daily", "serial"}) public void test3TriggerContract() { String hexReceiverAddress = ByteArray.toHexString(assetReceiverAddress); @@ -196,7 +205,9 @@ public void test3TriggerContract() { Long afterBalance = HttpMethod.getBalance(httpnode, assetOwnerAddress); logger.info("beforeBalance: " + beforeBalance); logger.info("afterBalance: " + afterBalance); - Assert.assertTrue(beforeBalance - afterBalance == callValue + Long.valueOf(responseContent.getOrDefault("fee",0L).toString())); + Assert.assertTrue( + beforeBalance - afterBalance + == callValue + Long.valueOf(responseContent.getOrDefault("fee", 0L).toString())); JSONObject receiptString = responseContent.getJSONObject("receipt"); Assert.assertEquals(receiptString.getString("result"), "SUCCESS"); @@ -210,7 +221,10 @@ public void test3TriggerContract() { } /** constructor. */ - @Test(enabled = true, description = "Get transaction info by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get transaction info by http", + groups = {"daily", "serial"}) public void test4GetTransactionInfoByBlocknum() throws InterruptedException { String hexReceiverAddress = ByteArray.toHexString(assetReceiverAddress); String addressParam = "000000000000000000000000" + hexReceiverAddress.substring(2); // [0,3) @@ -258,8 +272,7 @@ public void test4GetTransactionInfoByBlocknum() throws InterruptedException { HttpMethod.printJsonContent(responseCon2); if (responseCon1.getLong("blockNumber").equals(responseCon2.getLong("blockNumber"))) { HttpResponse responseByBlocknum = - HttpMethod.getTransactionInfoByBlocknum( - httpnode, responseCon1.getLong("blockNumber")); + HttpMethod.getTransactionInfoByBlocknum(httpnode, responseCon1.getLong("blockNumber")); List responseContentByBlocknum = HttpMethod.parseResponseContentArray(responseByBlocknum); boolean flag1 = false; @@ -282,9 +295,13 @@ public void test4GetTransactionInfoByBlocknum() throws InterruptedException { } /** constructor. */ - @Test(enabled = true, description = "Get transaction info by http from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get transaction info by http from solidity", + groups = {"daily", "serial"}) public void test5GetTransactionInfoByBlocknumFromSolidity() { - HttpMethod.waitUntilFixedBlockFromSolidity(responseCon1.getIntValue("blockNumber"), httpSolidityNode); + HttpMethod.waitUntilFixedBlockFromSolidity( + responseCon1.getIntValue("blockNumber"), httpSolidityNode); HttpResponse responseByBlocknum = HttpMethod.getTransactionInfoByBlocknumFromSolidity( httpSolidityNode, responseCon1.getLong("blockNumber")); @@ -305,9 +322,13 @@ public void test5GetTransactionInfoByBlocknumFromSolidity() { } /** constructor. */ - @Test(enabled = true, description = "Get transaction info by http from real solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Get transaction info by http from real solidity", + groups = {"daily", "serial"}) public void test6GetTransactionInfoByBlocknumFromRealSolidity() { - HttpMethod.waitUntilFixedBlockFromSolidity(responseCon1.getIntValue("blockNumber"), httpRealSolidityNode); + HttpMethod.waitUntilFixedBlockFromSolidity( + responseCon1.getIntValue("blockNumber"), httpRealSolidityNode); HttpResponse responseByBlocknum = HttpMethod.getTransactionInfoByBlocknumFromSolidity( httpRealSolidityNode, responseCon1.getLong("blockNumber")); @@ -328,7 +349,10 @@ public void test6GetTransactionInfoByBlocknumFromRealSolidity() { } /** constructor. */ - @Test(enabled = true, description = "UpdateSetting contract by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "UpdateSetting contract by http", + groups = {"daily", "serial"}) public void test7UpdateSetting() { // assetOwnerAddress, assetOwnerKey @@ -349,7 +373,10 @@ public void test7UpdateSetting() { } /** constructor. */ - @Test(enabled = true, description = "UpdateEnergyLimit contract by http", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "UpdateEnergyLimit contract by http", + groups = {"daily", "serial"}) public void test8UpdateEnergyLimit() { // assetOwnerAddress, assetOwnerKey diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestTransactionPending001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestTransactionPending001.java index f33efd72..d4ed66d7 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestTransactionPending001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestTransactionPending001.java @@ -16,86 +16,82 @@ @Slf4j public class HttpTestTransactionPending001 { - private final String testKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); + private final String testKey002 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key1"); private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); private JSONObject responseContent; private HttpResponse response; - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(0); - private String httpSoliditynode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); - private String httpPbftNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(4); + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); + private String httpSoliditynode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); + private String httpPbftNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(4); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] receiverAddress = ecKey1.getAddress(); String receiverKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); String txid; JSONObject transaction; - /** - * constructor. - */ - @Test(enabled = true, description = "Get transaction pending size by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get transaction pending size by http", + groups = {"daily", "serial"}) public void test01GetTransactionPendingSize() { int pendingSize = 0; int retryTimes = 50; while (pendingSize == 0 && retryTimes-- > 0) { - HttpMethod.sendCoin(httpnode,fromAddress,receiverAddress,1L,testKey002); + HttpMethod.sendCoin(httpnode, fromAddress, receiverAddress, 1L, testKey002); if (retryTimes % 5 == 0) { pendingSize = HttpMethod.getTransactionPendingSize(httpnode); } } - Assert.assertNotEquals(pendingSize,0); + Assert.assertNotEquals(pendingSize, 0); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get pending transaction list by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get pending transaction list by http", + groups = {"daily", "serial"}) public void test02GetPendingTransactionList() { int transactionSize = 0; int retryTimes = 50; while (transactionSize == 0 && retryTimes-- > 0) { - HttpMethod.sendCoin(httpnode,fromAddress,receiverAddress,1L,testKey002); + HttpMethod.sendCoin(httpnode, fromAddress, receiverAddress, 1L, testKey002); if (retryTimes % 5 == 0) { response = HttpMethod.getTransactionListFromPending(httpnode); responseContent = HttpMethod.parseResponseContent(response); transactionSize = responseContent.getJSONArray("txId").size(); } } - Assert.assertNotEquals(transactionSize,0); + Assert.assertNotEquals(transactionSize, 0); txid = responseContent.getJSONArray("txId").getString(0); } - - /** - * constructor. - */ - @Test(enabled = true, description = "Get transaction from pending by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get transaction from pending by http", + groups = {"daily", "serial"}) public void test03GetPendingTransactionList() { - response = HttpMethod.getTransactionFromPending(httpnode,txid); + response = HttpMethod.getTransactionFromPending(httpnode, txid); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - Assert.assertEquals(txid,responseContent.getString("txID")); - Assert.assertNotEquals(null,responseContent); + Assert.assertEquals(txid, responseContent.getString("txID")); + Assert.assertNotEquals(null, responseContent); Assert.assertTrue(responseContent.containsKey("ret")); } - - - - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { HttpMethod.disConnect(); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken001.java index 91ae36be..e796d9ce 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken001.java @@ -56,46 +56,49 @@ public class HttpTestZenToken001 { ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] zenTokenOwnerAddress = ecKey1.getAddress(); String zenTokenOwnerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(0); - private String httpSolidityNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); - private String httpPbftNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(4); - private String foundationZenTokenKey = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenOwnerKey"); + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); + private String httpSolidityNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); + private String httpPbftNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(4); + private String foundationZenTokenKey = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenOwnerKey"); byte[] foundationZenTokenAddress = PublicMethod.getFinalAddress(foundationZenTokenKey); - private String zenTokenId = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenId"); + private String zenTokenId = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenId"); private String tokenId = zenTokenId; - private Long zenTokenFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.zenTokenFee"); + private Long zenTokenFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.zenTokenFee"); private Long costTokenAmount = 20 * zenTokenFee; private Long sendTokenAmount = 8 * zenTokenFee; private JSONObject responseContent; private HttpResponse response; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = false) public void beforeClass() { - //Args.setFullNodeAllowShieldedTransaction(true); + // Args.setFullNodeAllowShieldedTransaction(true); PublicMethod.printAddress(foundationZenTokenKey); PublicMethod.printAddress(zenTokenOwnerKey); } - @Test(enabled = false, description = "Get spending key by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Get spending key by http", + groups = {"daily", "serial"}) public void test01GetSpendingKey() { response = HttpMethod.getSpendingKey(httpnode); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); sk = responseContent.getString("value"); logger.info("sk: " + sk); - } - @Test(enabled = false, description = "Get diversifier by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Get diversifier by http", + groups = {"daily", "serial"}) public void test02GetDiversifier() { response = HttpMethod.getDiversifier(httpnode); responseContent = HttpMethod.parseResponseContent(response); @@ -116,7 +119,10 @@ public void test02GetDiversifier() { logger.info("d3: " + d3); } - @Test(enabled = false, description = "Get expanded spending key by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Get expanded spending key by http", + groups = {"daily", "serial"}) public void test03GetExpandedSpendingKey() { response = HttpMethod.getExpandedSpendingKey(httpnode, sk); responseContent = HttpMethod.parseResponseContent(response); @@ -129,7 +135,10 @@ public void test03GetExpandedSpendingKey() { logger.info("ovk: " + ovk); } - @Test(enabled = false, description = "Get AK from ASK by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Get AK from ASK by http", + groups = {"daily", "serial"}) public void test04GetAkFromAsk() { response = HttpMethod.getAkFromAsk(httpnode, ask); responseContent = HttpMethod.parseResponseContent(response); @@ -138,7 +147,10 @@ public void test04GetAkFromAsk() { logger.info("ak: " + ak); } - @Test(enabled = false, description = "Get Nk from Nsk by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Get Nk from Nsk by http", + groups = {"daily", "serial"}) public void test05GetNkFromNsk() { response = HttpMethod.getNkFromNsk(httpnode, nsk); responseContent = HttpMethod.parseResponseContent(response); @@ -147,7 +159,10 @@ public void test05GetNkFromNsk() { logger.info("nk: " + nk); } - @Test(enabled = false, description = "Get incoming viewing Key by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Get incoming viewing Key by http", + groups = {"daily", "serial"}) public void test06GetIncomingViewingKey() { response = HttpMethod.getIncomingViewingKey(httpnode, ak, nk); responseContent = HttpMethod.parseResponseContent(response); @@ -156,7 +171,10 @@ public void test06GetIncomingViewingKey() { logger.info("ivk: " + ivk); } - @Test(enabled = false, description = "Get Zen Payment Address by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Get Zen Payment Address by http", + groups = {"daily", "serial"}) public void test07GetZenPaymentAddress() { response = HttpMethod.getZenPaymentAddress(httpnode, ivk, d1); responseContent = HttpMethod.parseResponseContent(response); @@ -201,7 +219,10 @@ public void test07GetZenPaymentAddress() { shieldAddressOptionalInfo3 = Optional.of(shieldAddressInfo3); } - @Test(enabled = false, description = "Get rcm by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Get rcm by http", + groups = {"daily", "serial"}) public void test08GetRcm() { response = HttpMethod.getRcm(httpnode); responseContent = HttpMethod.parseResponseContent(response); @@ -210,11 +231,19 @@ public void test08GetRcm() { logger.info("rcm: " + rcm); } - @Test(enabled = false, description = "Public to shield transaction withoutask by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Public to shield transaction withoutask by http", + groups = {"daily", "serial"}) public void test09PublicToShieldTransactionWithoutAsk() { - response = HttpMethod - .transferAsset(httpnode, foundationZenTokenAddress, zenTokenOwnerAddress, tokenId, - costTokenAmount, foundationZenTokenKey); + response = + HttpMethod.transferAsset( + httpnode, + foundationZenTokenAddress, + zenTokenOwnerAddress, + tokenId, + costTokenAmount, + foundationZenTokenKey); org.junit.Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); @@ -222,8 +251,8 @@ public void test09PublicToShieldTransactionWithoutAsk() { responseContent = HttpMethod.parseResponseContent(response); assetIssueId = responseContent.getString("asset_issued_ID"); - final Long beforeAssetBalance = HttpMethod - .getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); + final Long beforeAssetBalance = + HttpMethod.getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); response = HttpMethod.getAccountReource(httpnode, zenTokenOwnerAddress); responseContent = HttpMethod.parseResponseContent(response); final Long beforeNetUsed = responseContent.getLong("freeNetUsed"); @@ -234,22 +263,40 @@ public void test09PublicToShieldTransactionWithoutAsk() { Long sendSheldAddressAmount2 = zenTokenFee * 3; Long sendAmount = sendSheldAddressAmount1 + sendSheldAddressAmount2 + zenTokenFee; shieldOutList.clear(); - shieldOutList = HttpMethod - .addShieldOutputList(httpnode, shieldOutList, shieldAddressOptionalInfo1.get().getAddress(), - "" + sendSheldAddressAmount1, memo1); - shieldOutList = HttpMethod - .addShieldOutputList(httpnode, shieldOutList, shieldAddressOptionalInfo2.get().getAddress(), - "" + sendSheldAddressAmount2, memo2); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, + shieldOutList, + shieldAddressOptionalInfo1.get().getAddress(), + "" + sendSheldAddressAmount1, + memo1); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, + shieldOutList, + shieldAddressOptionalInfo2.get().getAddress(), + "" + sendSheldAddressAmount2, + memo2); HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSolidityNode); - response = HttpMethod - .sendShieldCoinWithoutAsk(httpnode, httpSolidityNode, httpPbftNode, zenTokenOwnerAddress, - sendAmount, null, null, shieldOutList, null, 0, zenTokenOwnerKey); + response = + HttpMethod.sendShieldCoinWithoutAsk( + httpnode, + httpSolidityNode, + httpPbftNode, + zenTokenOwnerAddress, + sendAmount, + null, + null, + shieldOutList, + null, + 0, + zenTokenOwnerKey); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); HttpMethod.waitToProduceOneBlock(httpnode); - Long afterAssetBalance = HttpMethod - .getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); + Long afterAssetBalance = + HttpMethod.getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); response = HttpMethod.getAccountReource(httpnode, zenTokenOwnerAddress); responseContent = HttpMethod.parseResponseContent(response); @@ -261,26 +308,39 @@ public void test09PublicToShieldTransactionWithoutAsk() { String memo3 = "Shield memo33 in " + System.currentTimeMillis(); Long sendSheldAddressAmount3 = costTokenAmount - sendAmount - zenTokenFee; shieldOutList.clear(); - shieldOutList = HttpMethod - .addShieldOutputList(httpnode, shieldOutList, shieldAddressOptionalInfo3.get().getAddress(), - "" + sendSheldAddressAmount3, memo3); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, + shieldOutList, + shieldAddressOptionalInfo3.get().getAddress(), + "" + sendSheldAddressAmount3, + memo3); HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSolidityNode); - response = HttpMethod - .sendShieldCoinWithoutAsk(httpnode, httpSolidityNode, httpPbftNode, zenTokenOwnerAddress, - sendSheldAddressAmount3 + zenTokenFee, null, null, shieldOutList, null, 0, + response = + HttpMethod.sendShieldCoinWithoutAsk( + httpnode, + httpSolidityNode, + httpPbftNode, + zenTokenOwnerAddress, + sendSheldAddressAmount3 + zenTokenFee, + null, + null, + shieldOutList, + null, + 0, zenTokenOwnerKey); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); - List shieldNoteInfoByIvkList = HttpMethod - .scanNoteByIvk(httpnode, shieldAddressOptionalInfo1.get()); + List shieldNoteInfoByIvkList = + HttpMethod.scanNoteByIvk(httpnode, shieldAddressOptionalInfo1.get()); logger.info("size are:" + shieldNoteInfoByIvkList.size()); Assert.assertTrue(shieldNoteInfoByIvkList.size() == 3); - List shieldNoteInfoByMarkList = HttpMethod - .scanAndMarkNoteByIvk(httpnode, shieldAddressOptionalInfo2.get()); + List shieldNoteInfoByMarkList = + HttpMethod.scanAndMarkNoteByIvk(httpnode, shieldAddressOptionalInfo2.get()); Assert.assertTrue(shieldNoteInfoByMarkList.size() == 3); shieldNote1 = shieldNoteInfoByIvkList.get(0); @@ -297,29 +357,47 @@ public void test09PublicToShieldTransactionWithoutAsk() { Assert.assertFalse(shieldNoteInfoByMarkList.get(2).getIsSpend()); } - @Test(enabled = false, description = "Shield to shield transaction withoutask by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Shield to shield transaction withoutask by http", + groups = {"daily", "serial"}) public void test10ShieldToShieldTransactionWithoutAsk() { - Optional receiverShieldAddressInfo1 = HttpMethod - .generateShieldAddress(httpnode); + Optional receiverShieldAddressInfo1 = + HttpMethod.generateShieldAddress(httpnode); String receiverShieldAddress1 = receiverShieldAddressInfo1.get().getAddress(); logger.info("receiverShieldAddress1:" + receiverShieldAddress1); - Optional receiverShieldAddressInfo2 = HttpMethod - .generateShieldAddress(httpnode); + Optional receiverShieldAddressInfo2 = + HttpMethod.generateShieldAddress(httpnode); String receiverShieldAddress2 = receiverShieldAddressInfo2.get().getAddress(); logger.info("receiverShieldAddress2:" + receiverShieldAddress2); - Optional receiverShieldAddressInfo3 = HttpMethod - .generateShieldAddress(httpnode); + Optional receiverShieldAddressInfo3 = + HttpMethod.generateShieldAddress(httpnode); String receiverShieldAddress3 = receiverShieldAddressInfo3.get().getAddress(); logger.info("receiverShieldAddress3:" + receiverShieldAddress3); shieldOutList.clear(); String receiverMemo1 = "Shield memo1 in " + System.currentTimeMillis(); - shieldOutList = HttpMethod.addShieldOutputList(httpnode, shieldOutList, receiverShieldAddress1, - "" + (shieldNote1.getValue() - zenTokenFee), receiverMemo1); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, + shieldOutList, + receiverShieldAddress1, + "" + (shieldNote1.getValue() - zenTokenFee), + receiverMemo1); HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSolidityNode); - response = HttpMethod - .sendShieldCoinWithoutAsk(httpnode, httpSolidityNode, httpPbftNode, null, 0, - shieldAddressOptionalInfo1.get(), shieldNote1, shieldOutList, null, 0, null); + response = + HttpMethod.sendShieldCoinWithoutAsk( + httpnode, + httpSolidityNode, + httpPbftNode, + null, + 0, + shieldAddressOptionalInfo1.get(), + shieldNote1, + shieldOutList, + null, + 0, + null); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); /*shieldOutList.clear(); @@ -335,22 +413,37 @@ public void test10ShieldToShieldTransactionWithoutAsk() { HttpMethod.printJsonContent(responseContent);*/ shieldOutList.clear(); String receiverMemo3 = "Shield memo3 in " + System.currentTimeMillis(); - shieldOutList = HttpMethod.addShieldOutputList(httpnode, shieldOutList, receiverShieldAddress3, - "" + (shieldNote3.getValue() - zenTokenFee), receiverMemo3); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, + shieldOutList, + receiverShieldAddress3, + "" + (shieldNote3.getValue() - zenTokenFee), + receiverMemo3); HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSolidityNode); - response = HttpMethod - .sendShieldCoinWithoutAsk(httpnode, httpSolidityNode, httpPbftNode, null, 0, - shieldAddressOptionalInfo3.get(), shieldNote3, shieldOutList, null, 0, null); + response = + HttpMethod.sendShieldCoinWithoutAsk( + httpnode, + httpSolidityNode, + httpPbftNode, + null, + 0, + shieldAddressOptionalInfo3.get(), + shieldNote3, + shieldOutList, + null, + 0, + null); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); + // HttpMethod.waitToProduceOneBlock(httpnode); - List shieldNoteInfoByOvkList = HttpMethod - .scanNoteByOvk(httpnode, shieldAddressOptionalInfo3.get()); + List shieldNoteInfoByOvkList = + HttpMethod.scanNoteByOvk(httpnode, shieldAddressOptionalInfo3.get()); Assert.assertTrue(shieldNoteInfoByOvkList.size() == 2); - List shieldNoteInfoByMarkList = HttpMethod - .scanAndMarkNoteByIvk(httpnode, shieldAddressOptionalInfo2.get()); + List shieldNoteInfoByMarkList = + HttpMethod.scanAndMarkNoteByIvk(httpnode, shieldAddressOptionalInfo2.get()); Assert.assertTrue(shieldNoteInfoByMarkList.size() == 3); Assert.assertTrue( @@ -367,15 +460,17 @@ public void test10ShieldToShieldTransactionWithoutAsk() { Assert.assertTrue(shieldNoteInfoByMarkList.get(2).getIsSpend()); } - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - final Long assetBalance = HttpMethod - .getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); - HttpMethod - .transferAsset(httpnode, zenTokenOwnerAddress, foundationZenTokenAddress, assetIssueId, - assetBalance, zenTokenOwnerKey); + final Long assetBalance = + HttpMethod.getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); + HttpMethod.transferAsset( + httpnode, + zenTokenOwnerAddress, + foundationZenTokenAddress, + assetIssueId, + assetBalance, + zenTokenOwnerKey); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken002.java index 765d56d4..0e3ee789 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken002.java @@ -38,48 +38,54 @@ public class HttpTestZenToken002 { ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] zenTokenOwnerAddress = ecKey1.getAddress(); String zenTokenOwnerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(0); - private String httpSolidityNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); - private String httpPbftNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(4); - private String foundationZenTokenKey = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenOwnerKey"); + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); + private String httpSolidityNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); + private String httpPbftNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(4); + private String foundationZenTokenKey = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenOwnerKey"); byte[] foundationZenTokenAddress = PublicMethod.getFinalAddress(foundationZenTokenKey); - private String zenTokenId = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenId"); - private Long zenTokenFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.zenTokenFee"); + private String zenTokenId = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenId"); + private Long zenTokenFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.zenTokenFee"); private Long sendTokenAmount = 7 * zenTokenFee; private JSONObject responseContent; private HttpResponse response; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = false) public void beforeClass() { PublicMethod.printAddress(foundationZenTokenKey); PublicMethod.printAddress(zenTokenOwnerKey); - response = HttpMethod - .transferAsset(httpnode, foundationZenTokenAddress, zenTokenOwnerAddress, zenTokenId, - sendTokenAmount, foundationZenTokenKey); + response = + HttpMethod.transferAsset( + httpnode, + foundationZenTokenAddress, + zenTokenOwnerAddress, + zenTokenId, + sendTokenAmount, + foundationZenTokenKey); org.junit.Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - //Args.setFullNodeAllowShieldedTransaction(true); + // Args.setFullNodeAllowShieldedTransaction(true); } - @Test(enabled = false, description = "Public to shield transaction by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Public to shield transaction by http", + groups = {"daily", "serial"}) public void test01PublicToShieldTransaction() { response = HttpMethod.getAccount(httpnode, foundationZenTokenAddress); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); assetIssueId = responseContent.getString("asset_issued_ID"); - final Long beforeAssetBalance = HttpMethod - .getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); + final Long beforeAssetBalance = + HttpMethod.getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); response = HttpMethod.getAccountReource(httpnode, zenTokenOwnerAddress); responseContent = HttpMethod.parseResponseContent(response); final Long beforeNetUsed = responseContent.getLong("freeNetUsed"); @@ -88,18 +94,31 @@ public void test01PublicToShieldTransaction() { sendShieldAddress = sendShieldAddressInfo.get().getAddress(); logger.info("sendShieldAddress:" + sendShieldAddress); memo1 = "Shield memo1 in " + System.currentTimeMillis(); - shieldOutList = HttpMethod.addShieldOutputList(httpnode, shieldOutList, sendShieldAddress, - "" + (sendTokenAmount - zenTokenFee), memo1); - - response = HttpMethod - .sendShieldCoin(httpnode, zenTokenOwnerAddress, sendTokenAmount, null, null, shieldOutList, - null, 0, zenTokenOwnerKey); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, + shieldOutList, + sendShieldAddress, + "" + (sendTokenAmount - zenTokenFee), + memo1); + + response = + HttpMethod.sendShieldCoin( + httpnode, + zenTokenOwnerAddress, + sendTokenAmount, + null, + null, + shieldOutList, + null, + 0, + zenTokenOwnerKey); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); HttpMethod.waitToProduceOneBlock(httpnode); - Long afterAssetBalance = HttpMethod - .getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); + Long afterAssetBalance = + HttpMethod.getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); response = HttpMethod.getAccountReource(httpnode, zenTokenOwnerAddress); responseContent = HttpMethod.parseResponseContent(response); Long afterNetUsed = responseContent.getLong("freeNetUsed"); @@ -111,47 +130,58 @@ public void test01PublicToShieldTransaction() { Assert.assertTrue(sendNote.getValue() == sendTokenAmount - zenTokenFee); Assert.assertEquals(memo1.getBytes(), sendNote.getMemo()); - ShieldNoteInfo scanAndMarkNoteSendNote = HttpMethod - .scanAndMarkNoteByIvk(httpnode, sendShieldAddressInfo.get()).get(0); + ShieldNoteInfo scanAndMarkNoteSendNote = + HttpMethod.scanAndMarkNoteByIvk(httpnode, sendShieldAddressInfo.get()).get(0); Assert.assertFalse(scanAndMarkNoteSendNote.getIsSpend()); } - @Test(enabled = false, description = "Shield to shield transaction by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Shield to shield transaction by http", + groups = {"daily", "serial"}) public void test02ShieldToShieldTransaction() { receiverShieldAddressInfo = HttpMethod.generateShieldAddress(httpnode); receiverShieldAddress = receiverShieldAddressInfo.get().getAddress(); shieldOutList.clear(); memo2 = "Send shield to receiver shield memo in" + System.currentTimeMillis(); - shieldOutList = HttpMethod.addShieldOutputList(httpnode, shieldOutList, receiverShieldAddress, - "" + (sendNote.getValue() - zenTokenFee), memo2); - - response = HttpMethod - .sendShieldCoin(httpnode, null, 0, sendShieldAddressInfo.get(), sendNote, shieldOutList, - null, 0, null); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, + shieldOutList, + receiverShieldAddress, + "" + (sendNote.getValue() - zenTokenFee), + memo2); + + response = + HttpMethod.sendShieldCoin( + httpnode, null, 0, sendShieldAddressInfo.get(), sendNote, shieldOutList, null, 0, null); org.junit.Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); HttpMethod.waitToProduceOneBlock(httpnode); -// HttpMethod.waitToProduceOneBlock(httpnode); - Long afterAssetBalance = HttpMethod - .getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); + // HttpMethod.waitToProduceOneBlock(httpnode); + Long afterAssetBalance = + HttpMethod.getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); receiverNote = HttpMethod.scanNoteByIvk(httpnode, receiverShieldAddressInfo.get()).get(0); Assert.assertTrue(receiverNote.getValue() == sendNote.getValue() - zenTokenFee); - Assert.assertEquals(ByteArray.toHexString(memo2.getBytes()), - ByteArray.toHexString(receiverNote.getMemo())); + Assert.assertEquals( + ByteArray.toHexString(memo2.getBytes()), ByteArray.toHexString(receiverNote.getMemo())); Assert.assertTrue(HttpMethod.getSpendResult(httpnode, sendShieldAddressInfo.get(), sendNote)); Assert.assertFalse( HttpMethod.getSpendResult(httpnode, receiverShieldAddressInfo.get(), receiverNote)); } - @Test(enabled = false, description = "Scan note by ivk and scan not by ivk on FullNode by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Scan note by ivk and scan not by ivk on FullNode by http", + groups = {"daily", "serial"}) public void test03ScanNoteByIvkAndOvk() { - //Scan sender note by ovk equals scan receiver note by ivk on FullNode + // Scan sender note by ovk equals scan receiver note by ivk on FullNode noteByOvk = HttpMethod.scanNoteByOvk(httpnode, sendShieldAddressInfo.get()).get(0); noteByIvk = HttpMethod.scanNoteByIvk(httpnode, receiverShieldAddressInfo.get()).get(0); Assert.assertEquals(noteByIvk.getValue(), noteByOvk.getValue()); @@ -160,149 +190,176 @@ public void test03ScanNoteByIvkAndOvk() { Assert.assertEquals(noteByIvk.getPaymentAddress(), noteByOvk.getPaymentAddress()); } - @Test(enabled = false, description = "Scan note by ivk and scan not by ivk on Solidity by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Scan note by ivk and scan not by ivk on Solidity by http", + groups = {"daily", "serial"}) public void test04ScanNoteByIvkAndOvkFromSolidity() { HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSolidityNode); - //Scan sender note by ovk equals scan receiver note by ivk on Solidity - noteByOvk = HttpMethod.scanNoteByOvkFromSolidity(httpSolidityNode, sendShieldAddressInfo.get()) - .get(0); - noteByIvk = HttpMethod - .scanNoteByIvkFromSolidity(httpSolidityNode, receiverShieldAddressInfo.get()).get(0); + // Scan sender note by ovk equals scan receiver note by ivk on Solidity + noteByOvk = + HttpMethod.scanNoteByOvkFromSolidity(httpSolidityNode, sendShieldAddressInfo.get()).get(0); + noteByIvk = + HttpMethod.scanNoteByIvkFromSolidity(httpSolidityNode, receiverShieldAddressInfo.get()) + .get(0); Assert.assertEquals(noteByIvk.getValue(), noteByOvk.getValue()); Assert.assertEquals(noteByIvk.getMemo(), noteByOvk.getMemo()); Assert.assertEquals(noteByIvk.getR(), noteByOvk.getR()); Assert.assertEquals(noteByIvk.getPaymentAddress(), noteByOvk.getPaymentAddress()); } - @Test(enabled = false, description = "Scan note by ivk and scan not by ivk on PBFT by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Scan note by ivk and scan not by ivk on PBFT by http", + groups = {"daily", "serial"}) public void test05ScanNoteByIvkAndOvkFromPbft() { HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSolidityNode); - //Scan sender note by ovk equals scan receiver note by ivk on Solidity + // Scan sender note by ovk equals scan receiver note by ivk on Solidity noteByOvk = HttpMethod.scanNoteByOvkFromPbft(httpPbftNode, sendShieldAddressInfo.get()).get(0); - noteByIvk = HttpMethod.scanNoteByIvkFromPbft(httpPbftNode, receiverShieldAddressInfo.get()) - .get(0); + noteByIvk = + HttpMethod.scanNoteByIvkFromPbft(httpPbftNode, receiverShieldAddressInfo.get()).get(0); Assert.assertEquals(noteByIvk.getValue(), noteByOvk.getValue()); Assert.assertEquals(noteByIvk.getMemo(), noteByOvk.getMemo()); Assert.assertEquals(noteByIvk.getR(), noteByOvk.getR()); Assert.assertEquals(noteByIvk.getPaymentAddress(), noteByOvk.getPaymentAddress()); } - - /** - * constructor. - */ - @Test(enabled = false, description = "Query whether note is spend on solidity by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "Query whether note is spend on solidity by http", + groups = {"daily", "serial"}) public void test06QueryNoteIsSpendOnSolidity() { HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSolidityNode); - Assert.assertTrue(HttpMethod - .getSpendResultFromSolidity(httpnode, httpSolidityNode, sendShieldAddressInfo.get(), - sendNote)); - Assert.assertFalse(HttpMethod - .getSpendResultFromSolidity(httpnode, httpSolidityNode, receiverShieldAddressInfo.get(), - receiverNote)); + Assert.assertTrue( + HttpMethod.getSpendResultFromSolidity( + httpnode, httpSolidityNode, sendShieldAddressInfo.get(), sendNote)); + Assert.assertFalse( + HttpMethod.getSpendResultFromSolidity( + httpnode, httpSolidityNode, receiverShieldAddressInfo.get(), receiverNote)); } - /** - * constructor. - */ - @Test(enabled = false, description = "Query whether note is spend on PBFT by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "Query whether note is spend on PBFT by http", + groups = {"daily", "serial"}) public void test07QueryNoteIsSpendOnSolidity() { HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSolidityNode); - Assert.assertTrue(HttpMethod - .getSpendResultFromPbft(httpnode, httpPbftNode, sendShieldAddressInfo.get(), sendNote)); - Assert.assertFalse(HttpMethod - .getSpendResultFromPbft(httpnode, httpPbftNode, receiverShieldAddressInfo.get(), - receiverNote)); + Assert.assertTrue( + HttpMethod.getSpendResultFromPbft( + httpnode, httpPbftNode, sendShieldAddressInfo.get(), sendNote)); + Assert.assertFalse( + HttpMethod.getSpendResultFromPbft( + httpnode, httpPbftNode, receiverShieldAddressInfo.get(), receiverNote)); } - - /** - * constructor. - */ - @Test(enabled = false, description = "Query note and spend status on fullnode", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + description = "Query note and spend status on fullnode", + groups = {"daily", "serial"}) public void test08QueryNoteAndSpendStatusOnFullnode() { - ShieldNoteInfo scanAndMarkNoteSendNote = HttpMethod - .scanAndMarkNoteByIvk(httpnode, sendShieldAddressInfo.get()).get(0); + ShieldNoteInfo scanAndMarkNoteSendNote = + HttpMethod.scanAndMarkNoteByIvk(httpnode, sendShieldAddressInfo.get()).get(0); Assert.assertTrue(scanAndMarkNoteSendNote.isSpend); Assert.assertEquals(scanAndMarkNoteSendNote.getValue(), sendNote.getValue()); Assert.assertEquals(scanAndMarkNoteSendNote.getMemo(), sendNote.getMemo()); Assert.assertEquals(scanAndMarkNoteSendNote.getR(), sendNote.getR()); Assert.assertEquals(scanAndMarkNoteSendNote.getPaymentAddress(), sendNote.getPaymentAddress()); - ShieldNoteInfo scanAndMarkNoteReceiverNote = HttpMethod - .scanAndMarkNoteByIvk(httpnode, receiverShieldAddressInfo.get()).get(0); + ShieldNoteInfo scanAndMarkNoteReceiverNote = + HttpMethod.scanAndMarkNoteByIvk(httpnode, receiverShieldAddressInfo.get()).get(0); Assert.assertFalse(scanAndMarkNoteReceiverNote.getIsSpend()); Assert.assertEquals(scanAndMarkNoteReceiverNote.getValue(), receiverNote.getValue()); Assert.assertEquals(scanAndMarkNoteReceiverNote.getMemo(), receiverNote.getMemo()); Assert.assertEquals(scanAndMarkNoteReceiverNote.getR(), receiverNote.getR()); - Assert.assertEquals(scanAndMarkNoteReceiverNote.getPaymentAddress(), - receiverNote.getPaymentAddress()); + Assert.assertEquals( + scanAndMarkNoteReceiverNote.getPaymentAddress(), receiverNote.getPaymentAddress()); } - @Test(enabled = false, description = "Query note and spend status on solidity", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Query note and spend status on solidity", + groups = {"daily", "serial"}) public void test09QueryNoteAndSpendStatusOnSolidity() { - ShieldNoteInfo scanAndMarkNoteSendNote = HttpMethod - .scanAndMarkNoteByIvkFromSolidity(httpnode, httpSolidityNode, sendShieldAddressInfo.get()) - .get(0); + ShieldNoteInfo scanAndMarkNoteSendNote = + HttpMethod.scanAndMarkNoteByIvkFromSolidity( + httpnode, httpSolidityNode, sendShieldAddressInfo.get()) + .get(0); Assert.assertTrue(scanAndMarkNoteSendNote.isSpend); Assert.assertEquals(scanAndMarkNoteSendNote.getValue(), sendNote.getValue()); Assert.assertEquals(scanAndMarkNoteSendNote.getMemo(), sendNote.getMemo()); Assert.assertEquals(scanAndMarkNoteSendNote.getR(), sendNote.getR()); Assert.assertEquals(scanAndMarkNoteSendNote.getPaymentAddress(), sendNote.getPaymentAddress()); - ShieldNoteInfo scanAndMarkNoteReceiverNote = HttpMethod - .scanAndMarkNoteByIvkFromSolidity(httpnode, httpSolidityNode, - receiverShieldAddressInfo.get()).get(0); + ShieldNoteInfo scanAndMarkNoteReceiverNote = + HttpMethod.scanAndMarkNoteByIvkFromSolidity( + httpnode, httpSolidityNode, receiverShieldAddressInfo.get()) + .get(0); Assert.assertFalse(scanAndMarkNoteReceiverNote.getIsSpend()); Assert.assertEquals(scanAndMarkNoteReceiverNote.getValue(), receiverNote.getValue()); Assert.assertEquals(scanAndMarkNoteReceiverNote.getMemo(), receiverNote.getMemo()); Assert.assertEquals(scanAndMarkNoteReceiverNote.getR(), receiverNote.getR()); - Assert.assertEquals(scanAndMarkNoteReceiverNote.getPaymentAddress(), - receiverNote.getPaymentAddress()); - + Assert.assertEquals( + scanAndMarkNoteReceiverNote.getPaymentAddress(), receiverNote.getPaymentAddress()); } - @Test(enabled = false, description = "Query note and spend status on PBFT", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Query note and spend status on PBFT", + groups = {"daily", "serial"}) public void test10QueryNoteAndSpendStatusOnPbft() { - ShieldNoteInfo scanAndMarkNoteSendNote = HttpMethod - .scanAndMarkNoteByIvkFromPbft(httpnode, httpPbftNode, sendShieldAddressInfo.get()).get(0); + ShieldNoteInfo scanAndMarkNoteSendNote = + HttpMethod.scanAndMarkNoteByIvkFromPbft(httpnode, httpPbftNode, sendShieldAddressInfo.get()) + .get(0); Assert.assertTrue(scanAndMarkNoteSendNote.isSpend); Assert.assertEquals(scanAndMarkNoteSendNote.getValue(), sendNote.getValue()); Assert.assertEquals(scanAndMarkNoteSendNote.getMemo(), sendNote.getMemo()); Assert.assertEquals(scanAndMarkNoteSendNote.getR(), sendNote.getR()); Assert.assertEquals(scanAndMarkNoteSendNote.getPaymentAddress(), sendNote.getPaymentAddress()); - ShieldNoteInfo scanAndMarkNoteReceiverNote = HttpMethod - .scanAndMarkNoteByIvkFromPbft(httpnode, httpPbftNode, receiverShieldAddressInfo.get()) - .get(0); + ShieldNoteInfo scanAndMarkNoteReceiverNote = + HttpMethod.scanAndMarkNoteByIvkFromPbft( + httpnode, httpPbftNode, receiverShieldAddressInfo.get()) + .get(0); Assert.assertFalse(scanAndMarkNoteReceiverNote.getIsSpend()); Assert.assertEquals(scanAndMarkNoteReceiverNote.getValue(), receiverNote.getValue()); Assert.assertEquals(scanAndMarkNoteReceiverNote.getMemo(), receiverNote.getMemo()); Assert.assertEquals(scanAndMarkNoteReceiverNote.getR(), receiverNote.getR()); - Assert.assertEquals(scanAndMarkNoteReceiverNote.getPaymentAddress(), - receiverNote.getPaymentAddress()); - + Assert.assertEquals( + scanAndMarkNoteReceiverNote.getPaymentAddress(), receiverNote.getPaymentAddress()); } - - @Test(enabled = false, description = "Shield to public transaction by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Shield to public transaction by http", + groups = {"daily", "serial"}) public void test11ShieldToPublicTransaction() { - final Long beforeAssetBalance = HttpMethod - .getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); + final Long beforeAssetBalance = + HttpMethod.getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); response = HttpMethod.getAccountReource(httpnode, zenTokenOwnerAddress); responseContent = HttpMethod.parseResponseContent(response); final Long beforeNetUsed = responseContent.getLong("freeNetUsed"); shieldOutList.clear(); - response = HttpMethod - .sendShieldCoin(httpnode, null, 0, receiverShieldAddressInfo.get(), receiverNote, - shieldOutList, zenTokenOwnerAddress, receiverNote.getValue() - zenTokenFee, null); + response = + HttpMethod.sendShieldCoin( + httpnode, + null, + 0, + receiverShieldAddressInfo.get(), + receiverNote, + shieldOutList, + zenTokenOwnerAddress, + receiverNote.getValue() - zenTokenFee, + null); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); HttpMethod.waitToProduceOneBlock(httpnode); - Long afterAssetBalance = HttpMethod - .getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); + Long afterAssetBalance = + HttpMethod.getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); response = HttpMethod.getAccountReource(httpnode, zenTokenOwnerAddress); responseContent = HttpMethod.parseResponseContent(response); Long afterNetUsed = responseContent.getLong("freeNetUsed"); @@ -317,15 +374,17 @@ public void test11ShieldToPublicTransaction() { HttpMethod.getSpendResult(httpnode, receiverShieldAddressInfo.get(), receiverNote)); } - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - final Long assetBalance = HttpMethod - .getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); - HttpMethod - .transferAsset(httpnode, zenTokenOwnerAddress, foundationZenTokenAddress, assetIssueId, - assetBalance, zenTokenOwnerKey); + final Long assetBalance = + HttpMethod.getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); + HttpMethod.transferAsset( + httpnode, + zenTokenOwnerAddress, + foundationZenTokenAddress, + assetIssueId, + assetBalance, + zenTokenOwnerKey); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken003.java index fc15b7b3..c17d991b 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken003.java @@ -51,37 +51,44 @@ public class HttpTestZenToken003 { ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] receiverPublicAddress = ecKey2.getAddress(); String receiverPublicKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(0); - private String foundationZenTokenKey = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenOwnerKey"); + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); + private String foundationZenTokenKey = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenOwnerKey"); byte[] foundationZenTokenAddress = PublicMethod.getFinalAddress(foundationZenTokenKey); - private String zenTokenId = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenId"); - private Long zenTokenFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.zenTokenFee"); - private Long zenTokenWhenCreateNewAddress = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.zenTokenWhenCreateNewAddress"); + private String zenTokenId = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenId"); + private Long zenTokenFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.zenTokenFee"); + private Long zenTokenWhenCreateNewAddress = + Configuration.getByPath("testng.conf") + .getLong("defaultParameter.zenTokenWhenCreateNewAddress"); private Long sendTokenAmount = 18 * zenTokenFee; private JSONObject responseContent; private HttpResponse response; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(foundationZenTokenKey); PublicMethod.printAddress(zenTokenOwnerKey); - //Args.setFullNodeAllowShieldedTransaction(true); + // Args.setFullNodeAllowShieldedTransaction(true); } - @Test(enabled = false, description = "Public to two shield transaction by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Public to two shield transaction by http", + groups = {"daily", "serial"}) public void test01PublicToTwoShieldTransaction() { - response = HttpMethod - .transferAsset(httpnode, foundationZenTokenAddress, zenTokenOwnerAddress, zenTokenId, - sendTokenAmount, foundationZenTokenKey); + response = + HttpMethod.transferAsset( + httpnode, + foundationZenTokenAddress, + zenTokenOwnerAddress, + zenTokenId, + sendTokenAmount, + foundationZenTokenKey); HttpMethod.waitToProduceOneBlock(httpnode); receiverShieldAddressInfo1 = HttpMethod.generateShieldAddress(httpnode); @@ -94,32 +101,50 @@ public void test01PublicToTwoShieldTransaction() { memo2 = "Shield memo2 in " + System.currentTimeMillis(); Long sendToShiledAddress1Amount = 1 * zenTokenFee; Long sendToShiledAddress2Amount = sendTokenAmount - sendToShiledAddress1Amount - zenTokenFee; - shieldOutList = HttpMethod.addShieldOutputList(httpnode, shieldOutList, receiverShieldAddress1, - "" + sendToShiledAddress1Amount, memo1); - shieldOutList = HttpMethod.addShieldOutputList(httpnode, shieldOutList, receiverShieldAddress2, - "" + sendToShiledAddress2Amount, memo2); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, + shieldOutList, + receiverShieldAddress1, + "" + sendToShiledAddress1Amount, + memo1); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, + shieldOutList, + receiverShieldAddress2, + "" + sendToShiledAddress2Amount, + memo2); response = HttpMethod.getAccount(httpnode, foundationZenTokenAddress); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); assetIssueId = responseContent.getString("asset_issued_ID"); - final Long beforeAssetBalance = HttpMethod - .getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); + final Long beforeAssetBalance = + HttpMethod.getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); response = HttpMethod.getAccountReource(httpnode, zenTokenOwnerAddress); responseContent = HttpMethod.parseResponseContent(response); final Long beforeNetUsed = responseContent.getLong("freeNetUsed"); - response = HttpMethod - .sendShieldCoin(httpnode, zenTokenOwnerAddress, sendTokenAmount, null, null, shieldOutList, - null, 0, zenTokenOwnerKey); + response = + HttpMethod.sendShieldCoin( + httpnode, + zenTokenOwnerAddress, + sendTokenAmount, + null, + null, + shieldOutList, + null, + 0, + zenTokenOwnerKey); org.junit.Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); HttpMethod.waitToProduceOneBlock(httpnode); - Long afterAssetBalance = HttpMethod - .getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); + Long afterAssetBalance = + HttpMethod.getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); response = HttpMethod.getAccountReource(httpnode, zenTokenOwnerAddress); responseContent = HttpMethod.parseResponseContent(response); Long afterNetUsed = responseContent.getLong("freeNetUsed"); @@ -134,18 +159,26 @@ public void test01PublicToTwoShieldTransaction() { Assert.assertEquals(memo2.getBytes(), receiverNote2.getMemo()); } - @Test(enabled = false, description = "Public to one public and one shield transaction by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Public to one public and one shield transaction by http", + groups = {"daily", "serial"}) public void test02ShieldToOneShieldAndOnePublicTransaction() { - response = HttpMethod - .transferAsset(httpnode, foundationZenTokenAddress, zenTokenOwnerAddress, zenTokenId, - sendTokenAmount, foundationZenTokenKey); + response = + HttpMethod.transferAsset( + httpnode, + foundationZenTokenAddress, + zenTokenOwnerAddress, + zenTokenId, + sendTokenAmount, + foundationZenTokenKey); HttpMethod.waitToProduceOneBlock(httpnode); receiverShieldAddressInfo3 = HttpMethod.generateShieldAddress(httpnode); receiverShieldAddress3 = receiverShieldAddressInfo3.get().getAddress(); - final Long beforeAssetBalanceSendAddress = HttpMethod - .getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); + final Long beforeAssetBalanceSendAddress = + HttpMethod.getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); response = HttpMethod.getAccountReource(httpnode, zenTokenOwnerAddress); responseContent = HttpMethod.parseResponseContent(response); final Long beforeNetUsedSendAddress = responseContent.getLong("freeNetUsed"); @@ -153,8 +186,8 @@ public void test02ShieldToOneShieldAndOnePublicTransaction() { responseContent = HttpMethod.parseResponseContent(response); Long beforeBalanceSendAddress = responseContent.getLong("balance"); - final Long beforeAssetBalanceReceiverAddress = HttpMethod - .getAssetIssueValue(httpnode, receiverPublicAddress, assetIssueId); + final Long beforeAssetBalanceReceiverAddress = + HttpMethod.getAssetIssueValue(httpnode, receiverPublicAddress, assetIssueId); response = HttpMethod.getAccountReource(httpnode, receiverPublicAddress); responseContent = HttpMethod.parseResponseContent(response); final Long beforeNetUsedReceiverAddress = responseContent.getLong("freeNetUsed"); @@ -164,20 +197,29 @@ public void test02ShieldToOneShieldAndOnePublicTransaction() { Long sendToShiledAddressAmount = sendTokenAmount - sendToPublicAddressAmount - zenTokenWhenCreateNewAddress; memo3 = "Send shield to receiver shield memo in" + System.currentTimeMillis(); - shieldOutList = HttpMethod.addShieldOutputList(httpnode, shieldOutList, receiverShieldAddress3, - "" + sendToShiledAddressAmount, memo3); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, shieldOutList, receiverShieldAddress3, "" + sendToShiledAddressAmount, memo3); PublicMethod.printAddress(receiverPublicKey); - response = HttpMethod - .sendShieldCoin(httpnode, zenTokenOwnerAddress, sendTokenAmount, null, null, shieldOutList, - receiverPublicAddress, sendToPublicAddressAmount, zenTokenOwnerKey); + response = + HttpMethod.sendShieldCoin( + httpnode, + zenTokenOwnerAddress, + sendTokenAmount, + null, + null, + shieldOutList, + receiverPublicAddress, + sendToPublicAddressAmount, + zenTokenOwnerKey); org.junit.Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); HttpMethod.waitToProduceOneBlock(httpnode); - Long afterAssetBalanceSendAddress = HttpMethod - .getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); + Long afterAssetBalanceSendAddress = + HttpMethod.getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); response = HttpMethod.getAccountReource(httpnode, zenTokenOwnerAddress); responseContent = HttpMethod.parseResponseContent(response); Long afterNetUsedSendAddress = responseContent.getLong("freeNetUsed"); @@ -185,8 +227,8 @@ public void test02ShieldToOneShieldAndOnePublicTransaction() { responseContent = HttpMethod.parseResponseContent(response); Long afterBalanceSendAddress = responseContent.getLong("balance"); - final Long afterAssetBalanceReceiverAddress = HttpMethod - .getAssetIssueValue(httpnode, receiverPublicAddress, assetIssueId); + final Long afterAssetBalanceReceiverAddress = + HttpMethod.getAssetIssueValue(httpnode, receiverPublicAddress, assetIssueId); response = HttpMethod.getAccountReource(httpnode, receiverPublicAddress); responseContent = HttpMethod.parseResponseContent(response); final Long afterNetUsedReceiverAddress = responseContent.getLong("freeNetUsed"); @@ -196,8 +238,9 @@ public void test02ShieldToOneShieldAndOnePublicTransaction() { Assert.assertTrue(beforeNetUsedSendAddress == afterNetUsedSendAddress); Assert.assertTrue(beforeBalanceSendAddress == afterBalanceSendAddress); - Assert.assertTrue(afterAssetBalanceReceiverAddress - beforeAssetBalanceReceiverAddress - == sendToPublicAddressAmount); + Assert.assertTrue( + afterAssetBalanceReceiverAddress - beforeAssetBalanceReceiverAddress + == sendToPublicAddressAmount); Assert.assertTrue(beforeNetUsedReceiverAddress == afterNetUsedReceiverAddress); receiverNote3 = HttpMethod.scanNoteByIvk(httpnode, receiverShieldAddressInfo3.get()).get(0); @@ -206,11 +249,19 @@ public void test02ShieldToOneShieldAndOnePublicTransaction() { Assert.assertEquals(memo3.getBytes(), receiverNote3.getMemo()); } - @Test(enabled = false, description = "Public to one public and two shield transaction by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Public to one public and two shield transaction by http", + groups = {"daily", "serial"}) public void test03ShieldToOneShieldAndTwoPublicTransaction() { - response = HttpMethod - .transferAsset(httpnode, foundationZenTokenAddress, zenTokenOwnerAddress, zenTokenId, - sendTokenAmount, foundationZenTokenKey); + response = + HttpMethod.transferAsset( + httpnode, + foundationZenTokenAddress, + zenTokenOwnerAddress, + zenTokenId, + sendTokenAmount, + foundationZenTokenKey); HttpMethod.waitToProduceOneBlock(httpnode); receiverShieldAddressInfo4 = HttpMethod.generateShieldAddress(httpnode); @@ -218,8 +269,8 @@ public void test03ShieldToOneShieldAndTwoPublicTransaction() { receiverShieldAddressInfo5 = HttpMethod.generateShieldAddress(httpnode); receiverShieldAddress5 = receiverShieldAddressInfo5.get().getAddress(); - final Long beforeAssetBalanceSendAddress = HttpMethod - .getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); + final Long beforeAssetBalanceSendAddress = + HttpMethod.getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); response = HttpMethod.getAccountReource(httpnode, zenTokenOwnerAddress); responseContent = HttpMethod.parseResponseContent(response); final Long beforeNetUsedSendAddress = responseContent.getLong("freeNetUsed"); @@ -227,8 +278,8 @@ public void test03ShieldToOneShieldAndTwoPublicTransaction() { responseContent = HttpMethod.parseResponseContent(response); Long beforeBalanceSendAddress = responseContent.getLong("balance"); - final Long beforeAssetBalanceReceiverAddress = HttpMethod - .getAssetIssueValue(httpnode, receiverPublicAddress, assetIssueId); + final Long beforeAssetBalanceReceiverAddress = + HttpMethod.getAssetIssueValue(httpnode, receiverPublicAddress, assetIssueId); response = HttpMethod.getAccountReource(httpnode, receiverPublicAddress); responseContent = HttpMethod.parseResponseContent(response); final Long beforeNetUsedReceiverAddress = responseContent.getLong("freeNetUsed"); @@ -240,22 +291,40 @@ public void test03ShieldToOneShieldAndTwoPublicTransaction() { sendTokenAmount - sendToPublicAddressAmount - sendToShiledAddress1Amount - zenTokenFee; memo4 = "Send shield to receiver shield memo in" + System.currentTimeMillis(); memo5 = "Send shield to receiver shield memo in" + System.currentTimeMillis(); - shieldOutList = HttpMethod.addShieldOutputList(httpnode, shieldOutList, receiverShieldAddress4, - "" + sendToShiledAddress1Amount, memo4); - shieldOutList = HttpMethod.addShieldOutputList(httpnode, shieldOutList, receiverShieldAddress5, - "" + sendToShiledAddress2Amount, memo5); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, + shieldOutList, + receiverShieldAddress4, + "" + sendToShiledAddress1Amount, + memo4); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, + shieldOutList, + receiverShieldAddress5, + "" + sendToShiledAddress2Amount, + memo5); PublicMethod.printAddress(receiverPublicKey); - response = HttpMethod - .sendShieldCoin(httpnode, zenTokenOwnerAddress, sendTokenAmount, null, null, shieldOutList, - receiverPublicAddress, sendToPublicAddressAmount, zenTokenOwnerKey); + response = + HttpMethod.sendShieldCoin( + httpnode, + zenTokenOwnerAddress, + sendTokenAmount, + null, + null, + shieldOutList, + receiverPublicAddress, + sendToPublicAddressAmount, + zenTokenOwnerKey); org.junit.Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); HttpMethod.waitToProduceOneBlock(httpnode); - Long afterAssetBalanceSendAddress = HttpMethod - .getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); + Long afterAssetBalanceSendAddress = + HttpMethod.getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); response = HttpMethod.getAccountReource(httpnode, zenTokenOwnerAddress); responseContent = HttpMethod.parseResponseContent(response); Long afterNetUsedSendAddress = responseContent.getLong("freeNetUsed"); @@ -263,8 +332,8 @@ public void test03ShieldToOneShieldAndTwoPublicTransaction() { responseContent = HttpMethod.parseResponseContent(response); Long afterBalanceSendAddress = responseContent.getLong("balance"); - final Long afterAssetBalanceReceiverAddress = HttpMethod - .getAssetIssueValue(httpnode, receiverPublicAddress, assetIssueId); + final Long afterAssetBalanceReceiverAddress = + HttpMethod.getAssetIssueValue(httpnode, receiverPublicAddress, assetIssueId); response = HttpMethod.getAccountReource(httpnode, receiverPublicAddress); responseContent = HttpMethod.parseResponseContent(response); final Long afterNetUsedReceiverAddress = responseContent.getLong("freeNetUsed"); @@ -274,8 +343,9 @@ public void test03ShieldToOneShieldAndTwoPublicTransaction() { Assert.assertTrue(beforeNetUsedSendAddress == afterNetUsedSendAddress); Assert.assertTrue(beforeBalanceSendAddress == afterBalanceSendAddress); - Assert.assertTrue(afterAssetBalanceReceiverAddress - beforeAssetBalanceReceiverAddress - == sendToPublicAddressAmount); + Assert.assertTrue( + afterAssetBalanceReceiverAddress - beforeAssetBalanceReceiverAddress + == sendToPublicAddressAmount); Assert.assertTrue(beforeNetUsedReceiverAddress == afterNetUsedReceiverAddress); receiverNote4 = HttpMethod.scanNoteByIvk(httpnode, receiverShieldAddressInfo4.get()).get(0); @@ -287,21 +357,27 @@ public void test03ShieldToOneShieldAndTwoPublicTransaction() { Assert.assertEquals(memo5.getBytes(), receiverNote5.getMemo()); } - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - final Long assetBalance1 = HttpMethod - .getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); - HttpMethod - .transferAsset(httpnode, zenTokenOwnerAddress, foundationZenTokenAddress, assetIssueId, - assetBalance1, zenTokenOwnerKey); - - final Long assetBalance2 = HttpMethod - .getAssetIssueValue(httpnode, receiverPublicAddress, assetIssueId); - HttpMethod - .transferAsset(httpnode, receiverPublicAddress, foundationZenTokenAddress, assetIssueId, - assetBalance2, receiverPublicKey); + final Long assetBalance1 = + HttpMethod.getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); + HttpMethod.transferAsset( + httpnode, + zenTokenOwnerAddress, + foundationZenTokenAddress, + assetIssueId, + assetBalance1, + zenTokenOwnerKey); + + final Long assetBalance2 = + HttpMethod.getAssetIssueValue(httpnode, receiverPublicAddress, assetIssueId); + HttpMethod.transferAsset( + httpnode, + receiverPublicAddress, + foundationZenTokenAddress, + assetIssueId, + assetBalance2, + receiverPublicKey); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken004.java index 9e8b8f46..4c0bfa58 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken004.java @@ -51,42 +51,52 @@ public class HttpTestZenToken004 { ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] receiverPublicAddress = ecKey1.getAddress(); String receiverPublicKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(0); - private String httpSolidityNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); - private String foundationZenTokenKey = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenOwnerKey"); + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); + private String httpSolidityNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); + private String foundationZenTokenKey = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenOwnerKey"); byte[] foundationZenTokenAddress = PublicMethod.getFinalAddress(foundationZenTokenKey); - private Long zenTokenFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.zenTokenFee"); - private Long zenTokenWhenCreateNewAddress = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.zenTokenWhenCreateNewAddress"); + private Long zenTokenFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.zenTokenFee"); + private Long zenTokenWhenCreateNewAddress = + Configuration.getByPath("testng.conf") + .getLong("defaultParameter.zenTokenWhenCreateNewAddress"); private Long sendTokenAmount = 18 * zenTokenFee; private JSONObject responseContent; private HttpResponse response; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(foundationZenTokenKey); - //Args.setFullNodeAllowShieldedTransaction(true); + // Args.setFullNodeAllowShieldedTransaction(true); } - @Test(enabled = false, description = "Shield to two shield transaction by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Shield to two shield transaction by http", + groups = {"daily", "serial"}) public void test01ShieldToTwoShieldTransaction() { sendShieldAddressInfo = HttpMethod.generateShieldAddress(httpnode); sendShieldAddress = sendShieldAddressInfo.get().getAddress(); logger.info("sendShieldAddress:" + sendShieldAddress); String memo = "Shield memo in " + System.currentTimeMillis(); - shieldOutList = HttpMethod - .addShieldOutputList(httpnode, shieldOutList, sendShieldAddress, "" + sendTokenAmount, - memo); - response = HttpMethod - .sendShieldCoin(httpnode, foundationZenTokenAddress, sendTokenAmount + zenTokenFee, null, - null, shieldOutList, null, 0, foundationZenTokenKey); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, shieldOutList, sendShieldAddress, "" + sendTokenAmount, memo); + response = + HttpMethod.sendShieldCoin( + httpnode, + foundationZenTokenAddress, + sendTokenAmount + zenTokenFee, + null, + null, + shieldOutList, + null, + 0, + foundationZenTokenKey); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); HttpMethod.waitToProduceOneBlock(httpnode); @@ -103,14 +113,24 @@ public void test01ShieldToTwoShieldTransaction() { Long sendToShiledAddress1Amount = 1 * zenTokenFee; Long sendToShiledAddress2Amount = sendTokenAmount - sendToShiledAddress1Amount - zenTokenFee; shieldOutList.clear(); - shieldOutList = HttpMethod.addShieldOutputList(httpnode, shieldOutList, receiverShieldAddress1, - "" + sendToShiledAddress1Amount, memo1); - shieldOutList = HttpMethod.addShieldOutputList(httpnode, shieldOutList, receiverShieldAddress2, - "" + sendToShiledAddress2Amount, memo2); - - response = HttpMethod - .sendShieldCoin(httpnode, null, 0, sendShieldAddressInfo.get(), sendNote, shieldOutList, - null, 0, null); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, + shieldOutList, + receiverShieldAddress1, + "" + sendToShiledAddress1Amount, + memo1); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, + shieldOutList, + receiverShieldAddress2, + "" + sendToShiledAddress2Amount, + memo2); + + response = + HttpMethod.sendShieldCoin( + httpnode, null, 0, sendShieldAddressInfo.get(), sendNote, shieldOutList, null, 0, null); org.junit.Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); @@ -127,19 +147,30 @@ public void test01ShieldToTwoShieldTransaction() { Assert.assertTrue(HttpMethod.getSpendResult(httpnode, sendShieldAddressInfo.get(), sendNote)); } - @Test(enabled = false, description = "Shield to one public and one shield transaction by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Shield to one public and one shield transaction by http", + groups = {"daily", "serial"}) public void test02ShieldToOnePublicAndOneShieldTransaction() { sendShieldAddressInfo = HttpMethod.generateShieldAddress(httpnode); sendShieldAddress = sendShieldAddressInfo.get().getAddress(); logger.info("sendShieldAddress:" + sendShieldAddress); String memo = "Shield memo in " + System.currentTimeMillis(); shieldOutList.clear(); - shieldOutList = HttpMethod - .addShieldOutputList(httpnode, shieldOutList, sendShieldAddress, "" + sendTokenAmount, - memo); - response = HttpMethod - .sendShieldCoin(httpnode, foundationZenTokenAddress, sendTokenAmount + zenTokenFee, null, - null, shieldOutList, null, 0, foundationZenTokenKey); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, shieldOutList, sendShieldAddress, "" + sendTokenAmount, memo); + response = + HttpMethod.sendShieldCoin( + httpnode, + foundationZenTokenAddress, + sendTokenAmount + zenTokenFee, + null, + null, + shieldOutList, + null, + 0, + foundationZenTokenKey); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); HttpMethod.waitToProduceOneBlock(httpnode); @@ -153,8 +184,8 @@ public void test02ShieldToOnePublicAndOneShieldTransaction() { HttpMethod.printJsonContent(responseContent); assetIssueId = responseContent.getString("asset_issued_ID"); - final Long beforeAssetBalance = HttpMethod - .getAssetIssueValue(httpnode, receiverPublicAddress, assetIssueId); + final Long beforeAssetBalance = + HttpMethod.getAssetIssueValue(httpnode, receiverPublicAddress, assetIssueId); response = HttpMethod.getAccountReource(httpnode, receiverPublicAddress); responseContent = HttpMethod.parseResponseContent(response); final Long beforeNetUsed = responseContent.getLong("freeNetUsed"); @@ -164,19 +195,28 @@ public void test02ShieldToOnePublicAndOneShieldTransaction() { Long sendToShiledAddressAmount = sendTokenAmount - sendToPublicAddressAmount - zenTokenWhenCreateNewAddress; memo3 = "Send shield to receiver shield memo in" + System.currentTimeMillis(); - shieldOutList = HttpMethod.addShieldOutputList(httpnode, shieldOutList, receiverShieldAddress3, - "" + sendToShiledAddressAmount, memo3); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, shieldOutList, receiverShieldAddress3, "" + sendToShiledAddressAmount, memo3); PublicMethod.printAddress(receiverPublicKey); - response = HttpMethod - .sendShieldCoin(httpnode, null, 0, sendShieldAddressInfo.get(), sendNote, shieldOutList, - receiverPublicAddress, sendToPublicAddressAmount, null); + response = + HttpMethod.sendShieldCoin( + httpnode, + null, + 0, + sendShieldAddressInfo.get(), + sendNote, + shieldOutList, + receiverPublicAddress, + sendToPublicAddressAmount, + null); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); HttpMethod.waitToProduceOneBlock(httpnode); - final Long afterAssetBalance = HttpMethod - .getAssetIssueValue(httpnode, receiverPublicAddress, assetIssueId); + final Long afterAssetBalance = + HttpMethod.getAssetIssueValue(httpnode, receiverPublicAddress, assetIssueId); response = HttpMethod.getAccountReource(httpnode, receiverPublicAddress); responseContent = HttpMethod.parseResponseContent(response); final Long afterNetUsed = responseContent.getLong("freeNetUsed"); @@ -191,33 +231,45 @@ public void test02ShieldToOnePublicAndOneShieldTransaction() { Assert.assertTrue(HttpMethod.getSpendResult(httpnode, sendShieldAddressInfo.get(), sendNote)); HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSolidityNode); - Assert.assertTrue(HttpMethod - .getSpendResultFromSolidity(httpnode, httpSolidityNode, sendShieldAddressInfo.get(), - sendNote)); - Assert.assertFalse(HttpMethod - .getSpendResultFromSolidity(httpnode, httpSolidityNode, receiverShieldAddressInfo3.get(), - receiverNote3)); + Assert.assertTrue( + HttpMethod.getSpendResultFromSolidity( + httpnode, httpSolidityNode, sendShieldAddressInfo.get(), sendNote)); + Assert.assertFalse( + HttpMethod.getSpendResultFromSolidity( + httpnode, httpSolidityNode, receiverShieldAddressInfo3.get(), receiverNote3)); Assert.assertTrue( HttpMethod.scanAndMarkNoteByIvk(httpnode, sendShieldAddressInfo.get()).get(0).getIsSpend()); Assert.assertFalse( - HttpMethod.scanAndMarkNoteByIvk(httpnode, receiverShieldAddressInfo3.get()).get(0) + HttpMethod.scanAndMarkNoteByIvk(httpnode, receiverShieldAddressInfo3.get()) + .get(0) .getIsSpend()); } - @Test(enabled = false, description = "Shield to one public and two shield transaction by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Shield to one public and two shield transaction by http", + groups = {"daily", "serial"}) public void test03ShieldToOnePublicAndTwoShieldTransaction() { sendShieldAddressInfo = HttpMethod.generateShieldAddress(httpnode); sendShieldAddress = sendShieldAddressInfo.get().getAddress(); logger.info("sendShieldAddress:" + sendShieldAddress); String memo = "Shield memo in " + System.currentTimeMillis(); shieldOutList.clear(); - shieldOutList = HttpMethod - .addShieldOutputList(httpnode, shieldOutList, sendShieldAddress, "" + sendTokenAmount, - memo); - response = HttpMethod - .sendShieldCoin(httpnode, foundationZenTokenAddress, sendTokenAmount + zenTokenFee, null, - null, shieldOutList, null, 0, foundationZenTokenKey); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, shieldOutList, sendShieldAddress, "" + sendTokenAmount, memo); + response = + HttpMethod.sendShieldCoin( + httpnode, + foundationZenTokenAddress, + sendTokenAmount + zenTokenFee, + null, + null, + shieldOutList, + null, + 0, + foundationZenTokenKey); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); HttpMethod.waitToProduceOneBlock(httpnode); @@ -228,8 +280,8 @@ public void test03ShieldToOnePublicAndTwoShieldTransaction() { receiverShieldAddressInfo5 = HttpMethod.generateShieldAddress(httpnode); receiverShieldAddress5 = receiverShieldAddressInfo5.get().getAddress(); - final Long beforeAssetBalance = HttpMethod - .getAssetIssueValue(httpnode, receiverPublicAddress, assetIssueId); + final Long beforeAssetBalance = + HttpMethod.getAssetIssueValue(httpnode, receiverPublicAddress, assetIssueId); response = HttpMethod.getAccountReource(httpnode, receiverPublicAddress); responseContent = HttpMethod.parseResponseContent(response); final Long beforeNetUsed = responseContent.getLong("freeNetUsed"); @@ -241,21 +293,39 @@ public void test03ShieldToOnePublicAndTwoShieldTransaction() { sendTokenAmount - sendToPublicAddressAmount - sendToShiledAddress1Amount - zenTokenFee; memo4 = "Send shield to receiver shield memo in" + System.currentTimeMillis(); memo5 = "Send shield to receiver shield memo in" + System.currentTimeMillis(); - shieldOutList = HttpMethod.addShieldOutputList(httpnode, shieldOutList, receiverShieldAddress4, - "" + sendToShiledAddress1Amount, memo4); - shieldOutList = HttpMethod.addShieldOutputList(httpnode, shieldOutList, receiverShieldAddress5, - "" + sendToShiledAddress2Amount, memo5); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, + shieldOutList, + receiverShieldAddress4, + "" + sendToShiledAddress1Amount, + memo4); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, + shieldOutList, + receiverShieldAddress5, + "" + sendToShiledAddress2Amount, + memo5); PublicMethod.printAddress(receiverPublicKey); - response = HttpMethod - .sendShieldCoin(httpnode, null, 0, sendShieldAddressInfo.get(), sendNote, shieldOutList, - receiverPublicAddress, sendToPublicAddressAmount, null); + response = + HttpMethod.sendShieldCoin( + httpnode, + null, + 0, + sendShieldAddressInfo.get(), + sendNote, + shieldOutList, + receiverPublicAddress, + sendToPublicAddressAmount, + null); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); HttpMethod.waitToProduceOneBlock(httpnode); - final Long afterAssetBalance = HttpMethod - .getAssetIssueValue(httpnode, receiverPublicAddress, assetIssueId); + final Long afterAssetBalance = + HttpMethod.getAssetIssueValue(httpnode, receiverPublicAddress, assetIssueId); response = HttpMethod.getAccountReource(httpnode, receiverPublicAddress); responseContent = HttpMethod.parseResponseContent(response); final Long afterNetUsed = responseContent.getLong("freeNetUsed"); @@ -274,15 +344,17 @@ public void test03ShieldToOnePublicAndTwoShieldTransaction() { Assert.assertTrue(HttpMethod.getSpendResult(httpnode, sendShieldAddressInfo.get(), sendNote)); } - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - final Long assetBalance = HttpMethod - .getAssetIssueValue(httpnode, receiverPublicAddress, assetIssueId); - HttpMethod - .transferAsset(httpnode, receiverPublicAddress, foundationZenTokenAddress, assetIssueId, - assetBalance, receiverPublicKey); + final Long assetBalance = + HttpMethod.getAssetIssueValue(httpnode, receiverPublicAddress, assetIssueId); + HttpMethod.transferAsset( + httpnode, + receiverPublicAddress, + foundationZenTokenAddress, + assetIssueId, + assetBalance, + receiverPublicKey); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken005.java index bf57647f..4de36416 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken005.java @@ -37,46 +37,62 @@ public class HttpTestZenToken005 { ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] zenTokenOwnerAddress = ecKey1.getAddress(); String zenTokenOwnerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(0); - private String httpSolidityNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); - private String httpPbftNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(4); - private String foundationZenTokenKey = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenOwnerKey"); + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); + private String httpSolidityNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); + private String httpPbftNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(4); + private String foundationZenTokenKey = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenOwnerKey"); byte[] foundationZenTokenAddress = PublicMethod.getFinalAddress(foundationZenTokenKey); - private String zenTokenId = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenId"); - private Long zenTokenFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.zenTokenFee"); + private String zenTokenId = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenId"); + private Long zenTokenFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.zenTokenFee"); private Long sendTokenAmount = 7 * zenTokenFee; private JSONObject responseContent; private HttpResponse response; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(foundationZenTokenKey); PublicMethod.printAddress(zenTokenOwnerKey); - response = HttpMethod - .transferAsset(httpnode, foundationZenTokenAddress, zenTokenOwnerAddress, zenTokenId, - sendTokenAmount, foundationZenTokenKey); + response = + HttpMethod.transferAsset( + httpnode, + foundationZenTokenAddress, + zenTokenOwnerAddress, + zenTokenId, + sendTokenAmount, + foundationZenTokenKey); org.junit.Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - //Args.setFullNodeAllowShieldedTransaction(true); + // Args.setFullNodeAllowShieldedTransaction(true); sendShieldAddressInfo = HttpMethod.generateShieldAddress(httpnode); sendShieldAddress = sendShieldAddressInfo.get().getAddress(); logger.info("sendShieldAddress:" + sendShieldAddress); memo1 = "Shield memo1 in " + System.currentTimeMillis(); - shieldOutList = HttpMethod.addShieldOutputList(httpnode, shieldOutList, sendShieldAddress, - "" + (sendTokenAmount - zenTokenFee), memo1); - - response = HttpMethod - .sendShieldCoin(httpnode, zenTokenOwnerAddress, sendTokenAmount, null, null, shieldOutList, - null, 0, zenTokenOwnerKey); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, + shieldOutList, + sendShieldAddress, + "" + (sendTokenAmount - zenTokenFee), + memo1); + + response = + HttpMethod.sendShieldCoin( + httpnode, + zenTokenOwnerAddress, + sendTokenAmount, + null, + null, + shieldOutList, + null, + 0, + zenTokenOwnerKey); org.junit.Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); @@ -86,20 +102,38 @@ public void beforeClass() { sendNote = HttpMethod.scanNoteByIvk(httpnode, sendShieldAddressInfo.get()).get(0); } - @Test(enabled = false, description = "Shield to shield transaction without ask by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Shield to shield transaction without ask by http", + groups = {"daily", "serial"}) public void test01ShieldToShieldWithoutAskTransaction() { receiverShieldAddressInfo = HttpMethod.generateShieldAddress(httpnode); receiverShieldAddress = receiverShieldAddressInfo.get().getAddress(); shieldOutList.clear(); memo2 = "Send shield to receiver shield memo in" + System.currentTimeMillis(); - shieldOutList = HttpMethod.addShieldOutputList(httpnode, shieldOutList, receiverShieldAddress, - "" + (sendNote.getValue() - zenTokenFee), memo2); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, + shieldOutList, + receiverShieldAddress, + "" + (sendNote.getValue() - zenTokenFee), + memo2); HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSolidityNode); - response = HttpMethod - .sendShieldCoinWithoutAsk(httpnode, httpSolidityNode, httpPbftNode, null, 0, - sendShieldAddressInfo.get(), sendNote, shieldOutList, null, 0, null); + response = + HttpMethod.sendShieldCoinWithoutAsk( + httpnode, + httpSolidityNode, + httpPbftNode, + null, + 0, + sendShieldAddressInfo.get(), + sendNote, + shieldOutList, + null, + 0, + null); org.junit.Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); logger.info("response:" + response); responseContent = HttpMethod.parseResponseContent(response); @@ -110,65 +144,82 @@ public void test01ShieldToShieldWithoutAskTransaction() { receiveNote = HttpMethod.scanNoteByIvk(httpnode, receiverShieldAddressInfo.get()).get(0); Assert.assertTrue(receiveNote.getValue() == sendNote.getValue() - zenTokenFee); - Assert.assertEquals(ByteArray.toHexString(memo2.getBytes()), - ByteArray.toHexString(receiveNote.getMemo())); + Assert.assertEquals( + ByteArray.toHexString(memo2.getBytes()), ByteArray.toHexString(receiveNote.getMemo())); Assert.assertTrue(HttpMethod.getSpendResult(httpnode, sendShieldAddressInfo.get(), sendNote)); } - @Test(enabled = false, description = "Get merkle tree voucher info by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Get merkle tree voucher info by http", + groups = {"daily", "serial"}) public void test02GetMerkleTreeVoucherInfo() { HttpMethod.waitToProduceOneBlock(httpnode); - response = HttpMethod - .getMerkleTreeVoucherInfo(httpnode, sendNote.getTrxId(), sendNote.getIndex(), 1); + response = + HttpMethod.getMerkleTreeVoucherInfo(httpnode, sendNote.getTrxId(), sendNote.getIndex(), 1); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); Assert.assertTrue(responseContent.toJSONString().contains("tree")); Assert.assertTrue(responseContent.toJSONString().contains("rt")); Assert.assertTrue(responseContent.toJSONString().contains("paths")); - response = HttpMethod - .getMerkleTreeVoucherInfo(httpnode, receiveNote.getTrxId(), receiveNote.getIndex(), 1000); + response = + HttpMethod.getMerkleTreeVoucherInfo( + httpnode, receiveNote.getTrxId(), receiveNote.getIndex(), 1000); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - Assert.assertTrue(responseContent.toJSONString().contains( - "synBlockNum is too large, cmBlockNum plus synBlockNum must be <= latestBlockNumber")); + Assert.assertTrue( + responseContent + .toJSONString() + .contains( + "synBlockNum is too large, cmBlockNum plus synBlockNum" + + " must be <= latestBlockNumber")); } - @Test(enabled = false, description = "Get merkle tree voucher info by http from solidity", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Get merkle tree voucher info by http from solidity", + groups = {"daily", "serial"}) public void test03GetMerkleTreeVoucherInfoFromSolidity() { HttpMethod.waitToProduceOneBlock(httpnode); - response = HttpMethod - .getMerkleTreeVoucherInfoFromSolidity(httpSolidityNode, sendNote.getTrxId(), - sendNote.getIndex(), 1); + response = + HttpMethod.getMerkleTreeVoucherInfoFromSolidity( + httpSolidityNode, sendNote.getTrxId(), sendNote.getIndex(), 1); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); Assert.assertTrue(responseContent.toJSONString().contains("tree")); Assert.assertTrue(responseContent.toJSONString().contains("rt")); Assert.assertTrue(responseContent.toJSONString().contains("paths")); - response = HttpMethod - .getMerkleTreeVoucherInfoFromSolidity(httpSolidityNode, receiveNote.getTrxId(), - receiveNote.getIndex(), 1000); + response = + HttpMethod.getMerkleTreeVoucherInfoFromSolidity( + httpSolidityNode, receiveNote.getTrxId(), receiveNote.getIndex(), 1000); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - Assert.assertTrue(responseContent.toJSONString().contains( - "synBlockNum is too large, cmBlockNum plus synBlockNum must be <= latestBlockNumber")); + Assert.assertTrue( + responseContent + .toJSONString() + .contains( + "synBlockNum is too large, cmBlockNum plus synBlockNum" + + " must be <= latestBlockNumber")); } - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { response = HttpMethod.getAccount(httpnode, foundationZenTokenAddress); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); assetIssueId = responseContent.getString("asset_issued_ID"); - final Long assetBalance = HttpMethod - .getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); - HttpMethod - .transferAsset(httpnode, zenTokenOwnerAddress, foundationZenTokenAddress, assetIssueId, - assetBalance, zenTokenOwnerKey); + final Long assetBalance = + HttpMethod.getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); + HttpMethod.transferAsset( + httpnode, + zenTokenOwnerAddress, + foundationZenTokenAddress, + assetIssueId, + assetBalance, + zenTokenOwnerKey); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken006.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken006.java index 3581b90f..abc51003 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken006.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestZenToken006.java @@ -36,34 +36,35 @@ public class HttpTestZenToken006 { ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] zenTokenOwnerAddress = ecKey1.getAddress(); String zenTokenOwnerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(0); - private String httpSolidityNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); - private String foundationZenTokenKey = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenOwnerKey"); + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); + private String httpSolidityNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); + private String foundationZenTokenKey = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenOwnerKey"); byte[] foundationZenTokenAddress = PublicMethod.getFinalAddress(foundationZenTokenKey); - private String zenTokenId = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenId"); + private String zenTokenId = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenId"); private String tokenId = zenTokenId; - private Long zenTokenFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.zenTokenFee"); + private Long zenTokenFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.zenTokenFee"); private Long costTokenAmount = 20 * zenTokenFee; private Long sendTokenAmount = 8 * zenTokenFee; private JSONObject responseContent; private HttpResponse response; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - //Args.setFullNodeAllowShieldedTransaction(true); + // Args.setFullNodeAllowShieldedTransaction(true); PublicMethod.printAddress(foundationZenTokenKey); PublicMethod.printAddress(zenTokenOwnerKey); } - @Test(enabled = false, description = "Get new shielded address by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Get new shielded address by http", + groups = {"daily", "serial"}) public void test01GetNewShieldedAddress() { response = HttpMethod.getNewShieldedAddress(httpnode); responseContent = HttpMethod.parseResponseContent(response); @@ -92,7 +93,10 @@ public void test01GetNewShieldedAddress() { paymentAddress1 = responseContent.getString("payment_address"); } - @Test(enabled = false, description = "Get expanded spending key by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Get expanded spending key by http", + groups = {"daily", "serial"}) public void test02GetExpandedSpendingKey() { response = HttpMethod.getExpandedSpendingKey(httpnode, sk); responseContent = HttpMethod.parseResponseContent(response); @@ -103,11 +107,12 @@ public void test02GetExpandedSpendingKey() { Assert.assertEquals(ask, askFromSk); Assert.assertEquals(nsk, nskFromSk); Assert.assertEquals(ovk, ovkFromSk); - } - - @Test(enabled = false, description = "Get rcm by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Get rcm by http", + groups = {"daily", "serial"}) public void test03GetRcm() { response = HttpMethod.getRcm(httpnode); responseContent = HttpMethod.parseResponseContent(response); @@ -116,11 +121,19 @@ public void test03GetRcm() { logger.info("rcm: " + rcm); } - @Test(enabled = false, description = "Public to shield transaction withoutask by http", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Public to shield transaction withoutask by http", + groups = {"daily", "serial"}) public void test04PublicToShieldTransactionWithoutAsk() { - response = HttpMethod - .transferAsset(httpnode, foundationZenTokenAddress, zenTokenOwnerAddress, tokenId, - costTokenAmount, foundationZenTokenKey); + response = + HttpMethod.transferAsset( + httpnode, + foundationZenTokenAddress, + zenTokenOwnerAddress, + tokenId, + costTokenAmount, + foundationZenTokenKey); org.junit.Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); @@ -128,8 +141,8 @@ public void test04PublicToShieldTransactionWithoutAsk() { responseContent = HttpMethod.parseResponseContent(response); assetIssueId = responseContent.getString("asset_issued_ID"); - final Long beforeAssetBalance = HttpMethod - .getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); + final Long beforeAssetBalance = + HttpMethod.getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); response = HttpMethod.getAccountReource(httpnode, zenTokenOwnerAddress); responseContent = HttpMethod.parseResponseContent(response); final Long beforeNetUsed = responseContent.getLong("freeNetUsed"); @@ -138,19 +151,29 @@ public void test04PublicToShieldTransactionWithoutAsk() { Long sendSheldAddressAmount1 = zenTokenFee * 2; Long sendAmount = sendSheldAddressAmount1 + zenTokenFee; shieldOutList.clear(); - shieldOutList = HttpMethod - .addShieldOutputList(httpnode, shieldOutList, paymentAddress1, "" + sendSheldAddressAmount1, - memo1); + shieldOutList = + HttpMethod.addShieldOutputList( + httpnode, shieldOutList, paymentAddress1, "" + sendSheldAddressAmount1, memo1); HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSolidityNode); - response = HttpMethod - .sendShieldCoinWithoutAsk(httpnode, httpSolidityNode, httpnode, zenTokenOwnerAddress, - sendAmount, null, null, shieldOutList, null, 0, zenTokenOwnerKey); + response = + HttpMethod.sendShieldCoinWithoutAsk( + httpnode, + httpSolidityNode, + httpnode, + zenTokenOwnerAddress, + sendAmount, + null, + null, + shieldOutList, + null, + 0, + zenTokenOwnerKey); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); HttpMethod.waitToProduceOneBlock(httpnode); - Long afterAssetBalance = HttpMethod - .getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); + Long afterAssetBalance = + HttpMethod.getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); response = HttpMethod.getAccountReource(httpnode, zenTokenOwnerAddress); responseContent = HttpMethod.parseResponseContent(response); @@ -158,18 +181,19 @@ public void test04PublicToShieldTransactionWithoutAsk() { Assert.assertTrue(beforeAssetBalance - afterAssetBalance == sendAmount); Assert.assertTrue(beforeNetUsed == afterNetUsed); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - final Long assetBalance = HttpMethod - .getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); - HttpMethod - .transferAsset(httpnode, zenTokenOwnerAddress, foundationZenTokenAddress, assetIssueId, - assetBalance, zenTokenOwnerKey); + final Long assetBalance = + HttpMethod.getAssetIssueValue(httpnode, zenTokenOwnerAddress, assetIssueId); + HttpMethod.transferAsset( + httpnode, + zenTokenOwnerAddress, + foundationZenTokenAddress, + assetIssueId, + assetBalance, + zenTokenOwnerKey); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/internaltransaction/ContractInternalTransaction001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/internaltransaction/ContractInternalTransaction001.java index 857e6877..ce739f50 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/internaltransaction/ContractInternalTransaction001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/internaltransaction/ContractInternalTransaction001.java @@ -20,18 +20,17 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j - @MultiNode public class ContractInternalTransaction001 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -39,79 +38,118 @@ public class ContractInternalTransaction001 extends TronBaseTest { String testKeyForinternalTxsAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(testKeyForinternalTxsAddress); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(testKeyForinternalTxsAddress); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - logger.info(Long.toString(PublicMethod.queryAccount(testNetAccountKey, blockingStubFull) - .getBalance())); + logger.info( + Long.toString(PublicMethod.queryAccount(testNetAccountKey, blockingStubFull).getBalance())); } - @Test(enabled = true, description = "Create->call.Two-level nesting", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Create->call.Two-level nesting", + groups = {"contract", "daily"}) public void testInternalTransaction001() { PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod - .sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + internalTxsAddress, + 100000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/" - + "contractInternalTransaction001testInternalTransaction001.sol"; - String contractName = "A"; + String filePath = + "src/test/resources/soliditycode/" + + "contractInternalTransaction001testInternalTransaction001.sol"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName1 = "C"; + String contractName1 = "C"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - byte[] contractAddress1 = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + byte[] contractAddress1 = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = ""; - String initParmes = "\"" + Base58.encode58Check(contractAddress1) + "\""; - txid = PublicMethod.triggerContract(contractAddress, - "test1(address)", initParmes, false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String txid = ""; + String initParmes = "\"" + Base58.encode58Check(contractAddress1) + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "test1(address)", + initParmes, + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - int transactionsCount = infoById.get().getInternalTransactionsCount(); + int transactionsCount = infoById.get().getInternalTransactionsCount(); Assert.assertEquals(7, transactionsCount); dupInternalTrsansactionHash(infoById.get().getInternalTransactionsList()); for (int i = 0; i < transactionsCount; i++) { Assert.assertFalse(infoById.get().getInternalTransactions(i).getRejected()); } String initParmes2 = "\"" + Base58.encode58Check(contractAddress1) + "\",\"1\""; - String txid1 = PublicMethod.triggerContract(contractAddress, - "test2(address,uint256)", initParmes2, false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + contractAddress, + "test2(address,uint256)", + initParmes2, + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); Assert.assertTrue(infoById1.get().getResultValue() == 0); - int transactionsCount1 = infoById1.get().getInternalTransactionsCount(); + int transactionsCount1 = infoById1.get().getInternalTransactionsCount(); Assert.assertEquals(10, transactionsCount1); dupInternalTrsansactionHash(infoById1.get().getInternalTransactionsList()); for (int i = 0; i < transactionsCount1; i++) { @@ -119,280 +157,443 @@ public void testInternalTransaction001() { } } - @Test(enabled = true, description = "There is one internalTransaction.Only call", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "There is one internalTransaction.Only call", + groups = {"contract", "daily"}) public void testInternalTransaction002() { - Assert.assertTrue(PublicMethod - .sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + internalTxsAddress, + 100000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/" - + "contractInternalTransaction001testInternalTransaction002.sol"; - String contractName = "A"; + String filePath = + "src/test/resources/soliditycode/" + + "contractInternalTransaction001testInternalTransaction002.sol"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName1 = "C"; + String contractName1 = "C"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - byte[] contractAddress1 = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + byte[] contractAddress1 = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String initParmes2 = "\"" + Base58.encode58Check(contractAddress1) + "\",\"1\""; - String txid1 = PublicMethod.triggerContract(contractAddress, - "test2(address,uint256)", initParmes2, false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String initParmes2 = "\"" + Base58.encode58Check(contractAddress1) + "\",\"1\""; + String txid1 = + PublicMethod.triggerContract( + contractAddress, + "test2(address,uint256)", + initParmes2, + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); Assert.assertTrue(infoById1.get().getResultValue() == 0); - int transactionsCount1 = infoById1.get().getInternalTransactionsCount(); + int transactionsCount1 = infoById1.get().getInternalTransactionsCount(); Assert.assertEquals(1, transactionsCount1); dupInternalTrsansactionHash(infoById1.get().getInternalTransactionsList()); Assert.assertFalse(infoById1.get().getInternalTransactions(0).getRejected()); - String note = ByteArray - .toStr(infoById1.get().getInternalTransactions(0).getNote().toByteArray()); + String note = + ByteArray.toStr(infoById1.get().getInternalTransactions(0).getNote().toByteArray()); Assert.assertEquals("call", note); - Assert.assertEquals(1, - infoById1.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue()); - + Assert.assertEquals( + 1, infoById1.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue()); } - @Test(enabled = true, description = "There is one internalTransaction.Only create", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "There is one internalTransaction.Only create", + groups = {"contract", "daily"}) public void testInternalTransaction003() { - Assert.assertTrue(PublicMethod - .sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + internalTxsAddress, + 100000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/" - + "contractInternalTransaction001testInternalTransaction003.sol"; - String contractName = "A"; + String filePath = + "src/test/resources/soliditycode/" + + "contractInternalTransaction001testInternalTransaction003.sol"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid1 = PublicMethod.triggerContract(contractAddress, - "transfer()", "#", false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + contractAddress, + "transfer()", + "#", + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); Assert.assertTrue(infoById1.get().getResultValue() == 0); - int transactionsCount1 = infoById1.get().getInternalTransactionsCount(); + int transactionsCount1 = infoById1.get().getInternalTransactionsCount(); Assert.assertEquals(1, transactionsCount1); dupInternalTrsansactionHash(infoById1.get().getInternalTransactionsList()); Assert.assertFalse(infoById1.get().getInternalTransactions(0).getRejected()); - String note = ByteArray - .toStr(infoById1.get().getInternalTransactions(0).getNote().toByteArray()); + String note = + ByteArray.toStr(infoById1.get().getInternalTransactions(0).getNote().toByteArray()); Assert.assertEquals("create", note); - Assert.assertEquals(10, - infoById1.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue()); - + Assert.assertEquals( + 10, infoById1.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue()); } - @Test(enabled = true, description = "Test suicide type in internalTransaction", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Test suicide type in internalTransaction", + groups = {"contract", "daily"}) public void testInternalTransaction004() { - Assert.assertTrue(PublicMethod - .sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + internalTxsAddress, + 100000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/" - + "contractInternalTransaction001testInternalTransaction004.sol"; - String contractName = "A"; + String filePath = + "src/test/resources/soliditycode/" + + "contractInternalTransaction001testInternalTransaction004.sol"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName1 = "B"; + String contractName1 = "B"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - byte[] contractAddress1 = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, - 0, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + byte[] contractAddress1 = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 0, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = ""; - String initParmes = "\"" + Base58.encode58Check(contractAddress) - + "\",\"" + Base58.encode58Check(contractAddress1) + "\""; - txid = PublicMethod.triggerContract(contractAddress1, - "kill(address,address)", initParmes, false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String txid = ""; + String initParmes = + "\"" + + Base58.encode58Check(contractAddress) + + "\",\"" + + Base58.encode58Check(contractAddress1) + + "\""; + txid = + PublicMethod.triggerContract( + contractAddress1, + "kill(address,address)", + initParmes, + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - int transactionsCount = infoById.get().getInternalTransactionsCount(); + int transactionsCount = infoById.get().getInternalTransactionsCount(); Assert.assertEquals(2, transactionsCount); dupInternalTrsansactionHash(infoById.get().getInternalTransactionsList()); for (int i = 0; i < transactionsCount; i++) { Assert.assertFalse(infoById.get().getInternalTransactions(i).getRejected()); } - String note = ByteArray - .toStr(infoById.get().getInternalTransactions(0).getNote().toByteArray()); - String note1 = ByteArray - .toStr(infoById.get().getInternalTransactions(1).getNote().toByteArray()); - Long vaule1 = infoById.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); - Long vaule2 = infoById.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); + String note = + ByteArray.toStr(infoById.get().getInternalTransactions(0).getNote().toByteArray()); + String note1 = + ByteArray.toStr(infoById.get().getInternalTransactions(1).getNote().toByteArray()); + Long vaule1 = infoById.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); + Long vaule2 = infoById.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); Assert.assertEquals("call", note); Assert.assertEquals("suicide", note1); Assert.assertTrue(0 == vaule1); Assert.assertTrue(1000000L == vaule2); - String txid1 = PublicMethod.triggerContract(contractAddress1, - "kill2()", "#", false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + contractAddress1, + "kill2()", + "#", + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); Assert.assertTrue(infoById1.get().getResultValue() == 0); - int transactionsCount1 = infoById1.get().getInternalTransactionsCount(); + int transactionsCount1 = infoById1.get().getInternalTransactionsCount(); Assert.assertEquals(3, transactionsCount1); dupInternalTrsansactionHash(infoById1.get().getInternalTransactionsList()); - String note3 = ByteArray - .toStr(infoById1.get().getInternalTransactions(0).getNote().toByteArray()); - String note4 = ByteArray - .toStr(infoById1.get().getInternalTransactions(1).getNote().toByteArray()); - String note5 = ByteArray - .toStr(infoById1.get().getInternalTransactions(2).getNote().toByteArray()); + String note3 = + ByteArray.toStr(infoById1.get().getInternalTransactions(0).getNote().toByteArray()); + String note4 = + ByteArray.toStr(infoById1.get().getInternalTransactions(1).getNote().toByteArray()); + String note5 = + ByteArray.toStr(infoById1.get().getInternalTransactions(2).getNote().toByteArray()); Assert.assertEquals("create", note3); Assert.assertEquals("call", note4); Assert.assertEquals("suicide", note5); for (int i = 0; i < transactionsCount1; i++) { Assert.assertFalse(infoById1.get().getInternalTransactions(i).getRejected()); - Assert.assertEquals(0, - infoById1.get().getInternalTransactions(i).getCallValueInfo(0).getCallValue()); - + Assert.assertEquals( + 0, infoById1.get().getInternalTransactions(i).getCallValueInfo(0).getCallValue()); } } - @Test(enabled = true, description = "Type is create call", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Type is create call", + groups = {"contract", "daily"}) public void testInternalTransaction005() { - Assert.assertTrue(PublicMethod - .sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + internalTxsAddress, + 100000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/" - + "contractInternalTransaction001testInternalTransaction005.sol"; - String contractName = "A"; + String filePath = + "src/test/resources/soliditycode/" + + "contractInternalTransaction001testInternalTransaction005.sol"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = ""; - - txid = PublicMethod.triggerContract(contractAddress, - "test1()", "#", false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String txid = ""; + + txid = + PublicMethod.triggerContract( + contractAddress, + "test1()", + "#", + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 1); - int transactionsCount = infoById.get().getInternalTransactionsCount(); + int transactionsCount = infoById.get().getInternalTransactionsCount(); Assert.assertEquals(2, transactionsCount); dupInternalTrsansactionHash(infoById.get().getInternalTransactionsList()); for (int i = 0; i < transactionsCount; i++) { Assert.assertTrue(infoById.get().getInternalTransactions(i).getRejected()); } - String note = ByteArray - .toStr(infoById.get().getInternalTransactions(0).getNote().toByteArray()); - String note1 = ByteArray - .toStr(infoById.get().getInternalTransactions(1).getNote().toByteArray()); - Long vaule1 = infoById.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); - Long vaule2 = infoById.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); + String note = + ByteArray.toStr(infoById.get().getInternalTransactions(0).getNote().toByteArray()); + String note1 = + ByteArray.toStr(infoById.get().getInternalTransactions(1).getNote().toByteArray()); + Long vaule1 = infoById.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); + Long vaule2 = infoById.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); Assert.assertEquals("create", note); Assert.assertEquals("call", note1); Assert.assertTrue(10 == vaule1); Assert.assertTrue(0 == vaule2); - String txid1 = PublicMethod.triggerContract(contractAddress, - "test2()", "#", false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + contractAddress, + "test2()", + "#", + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); Assert.assertTrue(infoById1.get().getResultValue() == 1); - int transactionsCount1 = infoById1.get().getInternalTransactionsCount(); + int transactionsCount1 = infoById1.get().getInternalTransactionsCount(); Assert.assertEquals(2, transactionsCount1); dupInternalTrsansactionHash(infoById1.get().getInternalTransactionsList()); - String note3 = ByteArray - .toStr(infoById1.get().getInternalTransactions(0).getNote().toByteArray()); - String note4 = ByteArray - .toStr(infoById1.get().getInternalTransactions(1).getNote().toByteArray()); - Long vaule3 = infoById1.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); - Long vaule4 = infoById1.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); + String note3 = + ByteArray.toStr(infoById1.get().getInternalTransactions(0).getNote().toByteArray()); + String note4 = + ByteArray.toStr(infoById1.get().getInternalTransactions(1).getNote().toByteArray()); + Long vaule3 = infoById1.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); + Long vaule4 = infoById1.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); Assert.assertTrue(10 == vaule3); Assert.assertTrue(0 == vaule4); Assert.assertEquals("create", note3); Assert.assertEquals("call", note4); for (int i = 0; i < transactionsCount1; i++) { Assert.assertTrue(infoById1.get().getInternalTransactions(i).getRejected()); - - } } - @Test(enabled = true, description = "Type is create call call", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Type is create call call", + groups = {"contract", "daily"}) public void testInternalTransaction006() { - Assert.assertTrue(PublicMethod - .sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + internalTxsAddress, + 100000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/" - + "contractInternalTransaction001testInternalTransaction006.sol"; - String contractName = "A"; + String filePath = + "src/test/resources/soliditycode/" + + "contractInternalTransaction001testInternalTransaction006.sol"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = ""; - - txid = PublicMethod.triggerContract(contractAddress, - "test1()", "#", false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String txid = ""; + + txid = + PublicMethod.triggerContract( + contractAddress, + "test1()", + "#", + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 1); - int transactionsCount = infoById.get().getInternalTransactionsCount(); + int transactionsCount = infoById.get().getInternalTransactionsCount(); Assert.assertEquals(3, transactionsCount); dupInternalTrsansactionHash(infoById.get().getInternalTransactionsList()); for (int i = 0; i < transactionsCount; i++) { Assert.assertTrue(infoById.get().getInternalTransactions(i).getRejected()); } - String note = ByteArray - .toStr(infoById.get().getInternalTransactions(0).getNote().toByteArray()); - String note1 = ByteArray - .toStr(infoById.get().getInternalTransactions(1).getNote().toByteArray()); - String note2 = ByteArray - .toStr(infoById.get().getInternalTransactions(1).getNote().toByteArray()); - Long vaule1 = infoById.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); - Long vaule2 = infoById.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); - Long vaule3 = infoById.get().getInternalTransactions(2).getCallValueInfo(0).getCallValue(); + String note = + ByteArray.toStr(infoById.get().getInternalTransactions(0).getNote().toByteArray()); + String note1 = + ByteArray.toStr(infoById.get().getInternalTransactions(1).getNote().toByteArray()); + String note2 = + ByteArray.toStr(infoById.get().getInternalTransactions(1).getNote().toByteArray()); + Long vaule1 = infoById.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); + Long vaule2 = infoById.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); + Long vaule3 = infoById.get().getInternalTransactions(2).getCallValueInfo(0).getCallValue(); Assert.assertEquals("create", note); Assert.assertEquals("call", note1); @@ -400,26 +601,34 @@ public void testInternalTransaction006() { Assert.assertTrue(10 == vaule1); Assert.assertTrue(0 == vaule2); Assert.assertTrue(0 == vaule3); - String txid1 = PublicMethod.triggerContract(contractAddress, - "test2()", "#", false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + contractAddress, + "test2()", + "#", + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); Assert.assertTrue(infoById1.get().getResultValue() == 1); - int transactionsCount1 = infoById1.get().getInternalTransactionsCount(); + int transactionsCount1 = infoById1.get().getInternalTransactionsCount(); Assert.assertEquals(3, transactionsCount1); dupInternalTrsansactionHash(infoById1.get().getInternalTransactionsList()); - String note4 = ByteArray - .toStr(infoById1.get().getInternalTransactions(0).getNote().toByteArray()); - String note5 = ByteArray - .toStr(infoById1.get().getInternalTransactions(1).getNote().toByteArray()); - String note6 = ByteArray - .toStr(infoById1.get().getInternalTransactions(2).getNote().toByteArray()); - Long vaule4 = infoById1.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); - Long vaule5 = infoById1.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); - Long vaule6 = infoById1.get().getInternalTransactions(2).getCallValueInfo(0).getCallValue(); + String note4 = + ByteArray.toStr(infoById1.get().getInternalTransactions(0).getNote().toByteArray()); + String note5 = + ByteArray.toStr(infoById1.get().getInternalTransactions(1).getNote().toByteArray()); + String note6 = + ByteArray.toStr(infoById1.get().getInternalTransactions(2).getNote().toByteArray()); + Long vaule4 = infoById1.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); + Long vaule5 = infoById1.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); + Long vaule6 = infoById1.get().getInternalTransactions(2).getCallValueInfo(0).getCallValue(); Assert.assertTrue(10 == vaule4); Assert.assertTrue(0 == vaule5); @@ -433,32 +642,31 @@ public void testInternalTransaction006() { } } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(internalTxsAddress, testKeyForinternalTxsAddress, testNetAccountAddress, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + internalTxsAddress, testKeyForinternalTxsAddress, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - + } + } - /** - * constructor. - */ + /** constructor. */ public void dupInternalTrsansactionHash( List internalTransactionList) { List hashList = new ArrayList<>(); internalTransactionList.forEach( - internalTransaction -> hashList - .add(Hex.toHexString(internalTransaction.getHash().toByteArray()))); - List dupHash = hashList.stream() - .collect(Collectors.toMap(e -> e, e -> 1, (a, b) -> a + b)) - .entrySet().stream().filter(entry -> entry.getValue() > 1).map(entry -> entry.getKey()) - .collect(Collectors.toList()); + internalTransaction -> + hashList.add(Hex.toHexString(internalTransaction.getHash().toByteArray()))); + List dupHash = + hashList.stream() + .collect(Collectors.toMap(e -> e, e -> 1, (a, b) -> a + b)) + .entrySet() + .stream() + .filter(entry -> entry.getValue() > 1) + .map(entry -> entry.getKey()) + .collect(Collectors.toList()); Assert.assertEquals(dupHash.size(), 0); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/internaltransaction/ContractInternalTransaction002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/internaltransaction/ContractInternalTransaction002.java index c4077f53..f9cca863 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/internaltransaction/ContractInternalTransaction002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/internaltransaction/ContractInternalTransaction002.java @@ -20,20 +20,17 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; -import stest.tron.wallet.common.client.utils.ProposalEnum; -import stest.tron.wallet.common.client.utils.Flaky; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j - @MultiNode public class ContractInternalTransaction002 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -41,81 +38,111 @@ public class ContractInternalTransaction002 extends TronBaseTest { String testKeyForinternalTxsAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(testKeyForinternalTxsAddress); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(testKeyForinternalTxsAddress); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - logger.info(Long.toString(PublicMethod.queryAccount(testNetAccountKey, blockingStubFull) - .getBalance())); + logger.info( + Long.toString(PublicMethod.queryAccount(testNetAccountKey, blockingStubFull).getBalance())); } - - @Test(enabled = true, description = "Type is create create call call", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Type is create create call call", + groups = {"contract", "daily"}) public void test1InternalTransaction007() { - Assert.assertTrue(PublicMethod - .sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + internalTxsAddress, + 100000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/" - + "contractInternalTransaction002test1InternalTransaction007.sol"; - String contractName = "A"; + String filePath = + "src/test/resources/soliditycode/" + + "contractInternalTransaction002test1InternalTransaction007.sol"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName1 = "C"; + String contractName1 = "C"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - byte[] contractAddress1 = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + byte[] contractAddress1 = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String initParmes = "\"" + Base58.encode58Check(contractAddress1) + "\""; - String txid = ""; - - txid = PublicMethod.triggerContract(contractAddress, - "test1(address)", initParmes, false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String initParmes = "\"" + Base58.encode58Check(contractAddress1) + "\""; + String txid = ""; + + txid = + PublicMethod.triggerContract( + contractAddress, + "test1(address)", + initParmes, + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertNotNull(infoById); Assert.assertTrue(infoById.get().getResultValue() == 1); - int transactionsCount = infoById.get().getInternalTransactionsCount(); + int transactionsCount = infoById.get().getInternalTransactionsCount(); Assert.assertEquals(4, transactionsCount); dupInternalTrsansactionHash(infoById.get().getInternalTransactionsList()); for (int i = 0; i < transactionsCount; i++) { Assert.assertTrue(infoById.get().getInternalTransactions(i).getRejected()); } - String note = ByteArray - .toStr(infoById.get().getInternalTransactions(0).getNote().toByteArray()); - String note1 = ByteArray - .toStr(infoById.get().getInternalTransactions(1).getNote().toByteArray()); - String note2 = ByteArray - .toStr(infoById.get().getInternalTransactions(2).getNote().toByteArray()); - String note3 = ByteArray - .toStr(infoById.get().getInternalTransactions(3).getNote().toByteArray()); - Long vaule1 = infoById.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); - Long vaule2 = infoById.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); - Long vaule3 = infoById.get().getInternalTransactions(2).getCallValueInfo(0).getCallValue(); - Long vaule4 = infoById.get().getInternalTransactions(3).getCallValueInfo(0).getCallValue(); + String note = + ByteArray.toStr(infoById.get().getInternalTransactions(0).getNote().toByteArray()); + String note1 = + ByteArray.toStr(infoById.get().getInternalTransactions(1).getNote().toByteArray()); + String note2 = + ByteArray.toStr(infoById.get().getInternalTransactions(2).getNote().toByteArray()); + String note3 = + ByteArray.toStr(infoById.get().getInternalTransactions(3).getNote().toByteArray()); + Long vaule1 = infoById.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); + Long vaule2 = infoById.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); + Long vaule3 = infoById.get().getInternalTransactions(2).getCallValueInfo(0).getCallValue(); + Long vaule4 = infoById.get().getInternalTransactions(3).getCallValueInfo(0).getCallValue(); Assert.assertEquals("create", note); Assert.assertEquals("create", note1); Assert.assertEquals("call", note2); @@ -124,246 +151,385 @@ public void test1InternalTransaction007() { Assert.assertTrue(0 == vaule2); Assert.assertTrue(5 == vaule3); Assert.assertTrue(0 == vaule4); - String initParmes1 = "\"" + Base58.encode58Check(contractAddress1) + "\",\"1\""; - String txid1 = PublicMethod.triggerContract(contractAddress, - "test2(address,uint256)", initParmes1, false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String initParmes1 = "\"" + Base58.encode58Check(contractAddress1) + "\",\"1\""; + String txid1 = + PublicMethod.triggerContract( + contractAddress, + "test2(address,uint256)", + initParmes1, + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); Assert.assertTrue(infoById1.get().getResultValue() == 0); - int transactionsCount1 = infoById1.get().getInternalTransactionsCount(); + int transactionsCount1 = infoById1.get().getInternalTransactionsCount(); Assert.assertEquals(1, transactionsCount1); dupInternalTrsansactionHash(infoById1.get().getInternalTransactionsList()); - String note5 = ByteArray - .toStr(infoById1.get().getInternalTransactions(0).getNote().toByteArray()); - Long vaule5 = infoById1.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); + String note5 = + ByteArray.toStr(infoById1.get().getInternalTransactions(0).getNote().toByteArray()); + Long vaule5 = infoById1.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); Assert.assertTrue(1 == vaule5); Assert.assertEquals("call", note5); Assert.assertTrue(infoById1.get().getInternalTransactions(0).getRejected()); - - } - @Test(enabled = true, description = "Type is call call", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Type is call call", + groups = {"contract", "daily"}) public void test2InternalTransaction008() { - Assert.assertTrue(PublicMethod - .sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + internalTxsAddress, + 100000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull1)); PublicMethod.waitProduceNextBlock(blockingStubFull1); - String filePath = "src/test/resources/soliditycode/" - + "contractInternalTransaction002test2InternalTransaction008.sol"; - String contractName = "A"; + String filePath = + "src/test/resources/soliditycode/" + + "contractInternalTransaction002test2InternalTransaction008.sol"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull1); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull1); - String contractName1 = "B"; + String contractName1 = "B"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - byte[] contractAddress1 = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull1); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + byte[] contractAddress1 = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull1); - String initParmes = "\"" + Base58.encode58Check(contractAddress1) + "\",\"1\""; - String txid = ""; - txid = PublicMethod.triggerContract(contractAddress, - "testAssert(address,uint256)", initParmes, false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull1); + String initParmes = "\"" + Base58.encode58Check(contractAddress1) + "\",\"1\""; + String txid = ""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testAssert(address,uint256)", + initParmes, + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull1); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull1); Assert.assertTrue(infoById.get().getResultValue() == 0); - int transactionsCount = infoById.get().getInternalTransactionsCount(); + int transactionsCount = infoById.get().getInternalTransactionsCount(); Assert.assertEquals(2, transactionsCount); dupInternalTrsansactionHash(infoById.get().getInternalTransactionsList()); Assert.assertTrue(infoById.get().getInternalTransactions(0).getRejected()); Assert.assertFalse(infoById.get().getInternalTransactions(1).getRejected()); - String note = ByteArray - .toStr(infoById.get().getInternalTransactions(0).getNote().toByteArray()); - String note1 = ByteArray - .toStr(infoById.get().getInternalTransactions(1).getNote().toByteArray()); - Long vaule1 = infoById.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); - Long vaule2 = infoById.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); + String note = + ByteArray.toStr(infoById.get().getInternalTransactions(0).getNote().toByteArray()); + String note1 = + ByteArray.toStr(infoById.get().getInternalTransactions(1).getNote().toByteArray()); + Long vaule1 = infoById.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); + Long vaule2 = infoById.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); Assert.assertEquals("call", note); Assert.assertEquals("call", note1); Assert.assertTrue(1 == vaule1); Assert.assertTrue(1 == vaule2); - String contractName2 = "C"; + String contractName2 = "C"; HashMap retMap2 = PublicMethod.getBycodeAbi(filePath, contractName2); - String code2 = retMap2.get("byteCode").toString(); - String abi2 = retMap2.get("abI").toString(); - byte[] contractAddress2 = PublicMethod - .deployContract(contractName2, abi2, code2, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull1); + String code2 = retMap2.get("byteCode").toString(); + String abi2 = retMap2.get("abI").toString(); + byte[] contractAddress2 = + PublicMethod.deployContract( + contractName2, + abi2, + code2, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull1); - String initParmes1 = "\"" + Base58.encode58Check(contractAddress2) + "\",\"1\""; - String txid1 = PublicMethod.triggerContract(contractAddress, - "testRequire(address,uint256)", initParmes1, false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull1); + String initParmes1 = "\"" + Base58.encode58Check(contractAddress2) + "\",\"1\""; + String txid1 = + PublicMethod.triggerContract( + contractAddress, + "testRequire(address,uint256)", + initParmes1, + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull1); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull1); Assert.assertTrue(infoById1.get().getResultValue() == 0); - int transactionsCount1 = infoById1.get().getInternalTransactionsCount(); + int transactionsCount1 = infoById1.get().getInternalTransactionsCount(); Assert.assertEquals(2, transactionsCount1); dupInternalTrsansactionHash(infoById1.get().getInternalTransactionsList()); Assert.assertTrue(infoById1.get().getInternalTransactions(0).getRejected()); Assert.assertFalse(infoById1.get().getInternalTransactions(1).getRejected()); - String note2 = ByteArray - .toStr(infoById1.get().getInternalTransactions(0).getNote().toByteArray()); - String note3 = ByteArray - .toStr(infoById1.get().getInternalTransactions(1).getNote().toByteArray()); - Long vaule3 = infoById1.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); - Long vaule4 = infoById1.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); + String note2 = + ByteArray.toStr(infoById1.get().getInternalTransactions(0).getNote().toByteArray()); + String note3 = + ByteArray.toStr(infoById1.get().getInternalTransactions(1).getNote().toByteArray()); + Long vaule3 = infoById1.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); + Long vaule4 = infoById1.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); Assert.assertEquals("call", note2); Assert.assertEquals("call", note3); Assert.assertTrue(1 == vaule3); Assert.assertTrue(1 == vaule4); - String txid2 = PublicMethod.triggerContract(contractAddress, - "testAssert1(address,uint256)", initParmes, false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull1); + String txid2 = + PublicMethod.triggerContract( + contractAddress, + "testAssert1(address,uint256)", + initParmes, + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull1); Optional infoById2 = null; infoById2 = PublicMethod.getTransactionInfoById(txid2, blockingStubFull1); Assert.assertTrue(infoById2.get().getResultValue() == 0); - int transactionsCount2 = infoById2.get().getInternalTransactionsCount(); + int transactionsCount2 = infoById2.get().getInternalTransactionsCount(); Assert.assertEquals(2, transactionsCount2); dupInternalTrsansactionHash(infoById2.get().getInternalTransactionsList()); Assert.assertFalse(infoById2.get().getInternalTransactions(0).getRejected()); Assert.assertTrue(infoById2.get().getInternalTransactions(1).getRejected()); - String note5 = ByteArray - .toStr(infoById2.get().getInternalTransactions(0).getNote().toByteArray()); - String note6 = ByteArray - .toStr(infoById2.get().getInternalTransactions(1).getNote().toByteArray()); - Long vaule5 = infoById2.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); - Long vaule6 = infoById2.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); + String note5 = + ByteArray.toStr(infoById2.get().getInternalTransactions(0).getNote().toByteArray()); + String note6 = + ByteArray.toStr(infoById2.get().getInternalTransactions(1).getNote().toByteArray()); + Long vaule5 = infoById2.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); + Long vaule6 = infoById2.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); Assert.assertEquals("call", note5); Assert.assertEquals("call", note6); Assert.assertTrue(1 == vaule5); Assert.assertTrue(1 == vaule6); - String txid3 = PublicMethod.triggerContract(contractAddress, - "testtRequire2(address,uint256)", initParmes1, false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull1); + String txid3 = + PublicMethod.triggerContract( + contractAddress, + "testtRequire2(address,uint256)", + initParmes1, + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull1); Optional infoById3 = null; infoById3 = PublicMethod.getTransactionInfoById(txid3, blockingStubFull1); Assert.assertTrue(infoById3.get().getResultValue() == 0); - int transactionsCount3 = infoById3.get().getInternalTransactionsCount(); + int transactionsCount3 = infoById3.get().getInternalTransactionsCount(); Assert.assertEquals(2, transactionsCount3); dupInternalTrsansactionHash(infoById3.get().getInternalTransactionsList()); Assert.assertFalse(infoById3.get().getInternalTransactions(0).getRejected()); Assert.assertTrue(infoById3.get().getInternalTransactions(1).getRejected()); - String note7 = ByteArray - .toStr(infoById3.get().getInternalTransactions(0).getNote().toByteArray()); - String note8 = ByteArray - .toStr(infoById3.get().getInternalTransactions(1).getNote().toByteArray()); - Long vaule7 = infoById3.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); - Long vaule8 = infoById3.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); + String note7 = + ByteArray.toStr(infoById3.get().getInternalTransactions(0).getNote().toByteArray()); + String note8 = + ByteArray.toStr(infoById3.get().getInternalTransactions(1).getNote().toByteArray()); + Long vaule7 = infoById3.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); + Long vaule8 = infoById3.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); Assert.assertEquals("call", note7); Assert.assertEquals("call", note8); Assert.assertTrue(1 == vaule7); Assert.assertTrue(1 == vaule8); - } - @Test(enabled = true, description = "Test suicide type in internalTransaction after call", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Test suicide type in internalTransaction after call", + groups = {"contract", "daily"}) public void test3InternalTransaction009() { - Assert.assertTrue(PublicMethod - .sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + internalTxsAddress, + 100000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/" - + "contractInternalTransaction002test3InternalTransaction009.sol"; - String contractName = "A"; + String filePath = + "src/test/resources/soliditycode/" + + "contractInternalTransaction002test3InternalTransaction009.sol"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName1 = "B"; + String contractName1 = "B"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - byte[] contractAddress1 = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + byte[] contractAddress1 = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName2 = "C"; + String contractName2 = "C"; HashMap retMap2 = PublicMethod.getBycodeAbi(filePath, contractName2); - String code2 = retMap2.get("byteCode").toString(); - String abi2 = retMap2.get("abI").toString(); - byte[] contractAddress2 = PublicMethod - .deployContract(contractName2, abi2, code2, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code2 = retMap2.get("byteCode").toString(); + String abi2 = retMap2.get("abI").toString(); + byte[] contractAddress2 = + PublicMethod.deployContract( + contractName2, + abi2, + code2, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName3 = "D"; + String contractName3 = "D"; HashMap retMap3 = PublicMethod.getBycodeAbi(filePath, contractName3); - String code3 = retMap3.get("byteCode").toString(); - String abi3 = retMap3.get("abI").toString(); - byte[] contractAddress3 = PublicMethod - .deployContract(contractName3, abi3, code3, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code3 = retMap3.get("byteCode").toString(); + String abi3 = retMap3.get("abI").toString(); + byte[] contractAddress3 = + PublicMethod.deployContract( + contractName3, + abi3, + code3, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String initParmes = "\"" + Base58.encode58Check(contractAddress2) - + "\",\"" + Base58.encode58Check(contractAddress3) + "\",\"" + Base58 - .encode58Check(contractAddress1) + "\""; - String txid = ""; - txid = PublicMethod.triggerContract(contractAddress, - "test1(address,address,address)", initParmes, false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String initParmes = + "\"" + + Base58.encode58Check(contractAddress2) + + "\",\"" + + Base58.encode58Check(contractAddress3) + + "\",\"" + + Base58.encode58Check(contractAddress1) + + "\""; + String txid = ""; + txid = + PublicMethod.triggerContract( + contractAddress, + "test1(address,address,address)", + initParmes, + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - int transactionsCount = infoById.get().getInternalTransactionsCount(); + int transactionsCount = infoById.get().getInternalTransactionsCount(); Assert.assertEquals(7, transactionsCount); dupInternalTrsansactionHash(infoById.get().getInternalTransactionsList()); for (int i = 0; i < transactionsCount; i++) { Assert.assertFalse(infoById.get().getInternalTransactions(i).getRejected()); } - String note = ByteArray - .toStr(infoById.get().getInternalTransactions(0).getNote().toByteArray()); - String note1 = ByteArray - .toStr(infoById.get().getInternalTransactions(1).getNote().toByteArray()); - String note2 = ByteArray - .toStr(infoById.get().getInternalTransactions(6).getNote().toByteArray()); - Long vaule1 = infoById.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); - Long vaule2 = infoById.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); + String note = + ByteArray.toStr(infoById.get().getInternalTransactions(0).getNote().toByteArray()); + String note1 = + ByteArray.toStr(infoById.get().getInternalTransactions(1).getNote().toByteArray()); + String note2 = + ByteArray.toStr(infoById.get().getInternalTransactions(6).getNote().toByteArray()); + Long vaule1 = infoById.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); + Long vaule2 = infoById.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); Assert.assertEquals("create", note); Assert.assertEquals("call", note1); Assert.assertEquals("suicide", note2); Assert.assertTrue(10 == vaule1); Assert.assertTrue(5 == vaule2); - String txid1 = ""; - txid1 = PublicMethod.triggerContract(contractAddress, - "test1(address,address,address)", initParmes, false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String txid1 = ""; + txid1 = + PublicMethod.triggerContract( + contractAddress, + "test1(address,address,address)", + initParmes, + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); Assert.assertTrue(infoById1.get().getResultValue() == 0); - int transactionsCount1 = infoById1.get().getInternalTransactionsCount(); + int transactionsCount1 = infoById1.get().getInternalTransactionsCount(); Assert.assertEquals(7, transactionsCount1); dupInternalTrsansactionHash(infoById1.get().getInternalTransactionsList()); @@ -372,109 +538,154 @@ public void test3InternalTransaction009() { } } - - @Test(enabled = true, description = "Type is call create->call->call.Three-level nesting", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Type is call create->call->call.Three-level nesting", + groups = {"contract", "daily"}) public void test4InternalTransaction012() { - Assert.assertTrue(PublicMethod - .sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + internalTxsAddress, + 100000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/" - + "contractInternalTransaction002test5InternalTransaction012.sol"; - String contractName = "A"; + String filePath = + "src/test/resources/soliditycode/" + + "contractInternalTransaction002test5InternalTransaction012.sol"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName1 = "B"; + String contractName1 = "B"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - byte[] contractAddress1 = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + byte[] contractAddress1 = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName2 = "E"; + String contractName2 = "E"; HashMap retMap2 = PublicMethod.getBycodeAbi(filePath, contractName2); - String code2 = retMap1.get("byteCode").toString(); - String abi2 = retMap1.get("abI").toString(); - byte[] contractAddress2 = PublicMethod - .deployContract(contractName2, abi2, code2, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code2 = retMap1.get("byteCode").toString(); + String abi2 = retMap1.get("abI").toString(); + byte[] contractAddress2 = + PublicMethod.deployContract( + contractName2, + abi2, + code2, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String initParmes = "\"" + Base58.encode58Check(contractAddress1) - + "\",\"" + Base58.encode58Check(contractAddress2) + "\""; - String txid = ""; - txid = PublicMethod.triggerContract(contractAddress, - "test1(address,address)", initParmes, false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String initParmes = + "\"" + + Base58.encode58Check(contractAddress1) + + "\",\"" + + Base58.encode58Check(contractAddress2) + + "\""; + String txid = ""; + txid = + PublicMethod.triggerContract( + contractAddress, + "test1(address,address)", + initParmes, + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - int transactionsCount = infoById.get().getInternalTransactionsCount(); + int transactionsCount = infoById.get().getInternalTransactionsCount(); Assert.assertEquals(4, transactionsCount); dupInternalTrsansactionHash(infoById.get().getInternalTransactionsList()); for (int i = 0; i < transactionsCount; i++) { Assert.assertFalse(infoById.get().getInternalTransactions(i).getRejected()); } - String note = ByteArray - .toStr(infoById.get().getInternalTransactions(0).getNote().toByteArray()); - String note1 = ByteArray - .toStr(infoById.get().getInternalTransactions(1).getNote().toByteArray()); - String note2 = ByteArray - .toStr(infoById.get().getInternalTransactions(2).getNote().toByteArray()); - String note3 = ByteArray - .toStr(infoById.get().getInternalTransactions(3).getNote().toByteArray()); + String note = + ByteArray.toStr(infoById.get().getInternalTransactions(0).getNote().toByteArray()); + String note1 = + ByteArray.toStr(infoById.get().getInternalTransactions(1).getNote().toByteArray()); + String note2 = + ByteArray.toStr(infoById.get().getInternalTransactions(2).getNote().toByteArray()); + String note3 = + ByteArray.toStr(infoById.get().getInternalTransactions(3).getNote().toByteArray()); Assert.assertEquals("call", note); Assert.assertEquals("create", note1); Assert.assertEquals("call", note2); Assert.assertEquals("call", note3); - Long vaule1 = infoById.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); - Long vaule2 = infoById.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); - Long vaule3 = infoById.get().getInternalTransactions(2).getCallValueInfo(0).getCallValue(); - Long vaule4 = infoById.get().getInternalTransactions(3).getCallValueInfo(0).getCallValue(); + Long vaule1 = infoById.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); + Long vaule2 = infoById.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); + Long vaule3 = infoById.get().getInternalTransactions(2).getCallValueInfo(0).getCallValue(); + Long vaule4 = infoById.get().getInternalTransactions(3).getCallValueInfo(0).getCallValue(); Assert.assertTrue(1 == vaule1); Assert.assertTrue(1000 == vaule2); Assert.assertTrue(0 == vaule3); Assert.assertTrue(1 == vaule4); - - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(internalTxsAddress, testKeyForinternalTxsAddress, testNetAccountAddress, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + internalTxsAddress, testKeyForinternalTxsAddress, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - + } + } - /** - * constructor. - */ + /** constructor. */ public void dupInternalTrsansactionHash( List internalTransactionList) { List hashList = new ArrayList<>(); internalTransactionList.forEach( - internalTransaction -> hashList - .add(Hex.toHexString(internalTransaction.getHash().toByteArray()))); - List dupHash = hashList.stream() - .collect(Collectors.toMap(e -> e, e -> 1, (a, b) -> a + b)) - .entrySet().stream().filter(entry -> entry.getValue() > 1).map(entry -> entry.getKey()) - .collect(Collectors.toList()); + internalTransaction -> + hashList.add(Hex.toHexString(internalTransaction.getHash().toByteArray()))); + List dupHash = + hashList.stream() + .collect(Collectors.toMap(e -> e, e -> 1, (a, b) -> a + b)) + .entrySet() + .stream() + .filter(entry -> entry.getValue() > 1) + .map(entry -> entry.getKey()) + .collect(Collectors.toList()); Assert.assertEquals(dupHash.size(), 0); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/internaltransaction/ContractInternalTransaction003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/internaltransaction/ContractInternalTransaction003.java index 6cad007a..4e2e2b6d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/internaltransaction/ContractInternalTransaction003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/internaltransaction/ContractInternalTransaction003.java @@ -20,14 +20,13 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.Retry; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j - @MultiNode public class ContractInternalTransaction003 extends TronBaseTest { @@ -37,468 +36,698 @@ public class ContractInternalTransaction003 extends TronBaseTest { String testKeyForinternalTxsAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(testKeyForinternalTxsAddress); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(testKeyForinternalTxsAddress); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - logger.info(Long.toString(PublicMethod.queryAccount(foundationKey, blockingStubFull) - .getBalance())); + logger.info( + Long.toString(PublicMethod.queryAccount(foundationKey, blockingStubFull).getBalance())); } - - @Test(enabled = true, description = "Three-level nesting.Type is Create call->call->create", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Three-level nesting.Type is Create call->call->create", + groups = {"contract", "daily"}) public void testInternalTransaction013() { - Assert.assertTrue(PublicMethod - .sendcoin(internalTxsAddress, 100000000000L, foundationAddress, foundationKey, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + internalTxsAddress, 100000000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/" - + "contractInternalTransaction003testInternalTransaction013.sol"; - String contractName = "A"; + String filePath = + "src/test/resources/soliditycode/" + + "contractInternalTransaction003testInternalTransaction013.sol"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); - String contractName1 = "D"; + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); + String contractName1 = "D"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - byte[] contractAddress1 = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + byte[] contractAddress1 = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String initParmes = "\"" + Base58.encode58Check(contractAddress1) + "\""; - String txid = ""; - txid = PublicMethod.triggerContract(contractAddress, - "test1(address)", initParmes, false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String initParmes = "\"" + Base58.encode58Check(contractAddress1) + "\""; + String txid = ""; + txid = + PublicMethod.triggerContract( + contractAddress, + "test1(address)", + initParmes, + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - int transactionsCount = infoById.get().getInternalTransactionsCount(); + int transactionsCount = infoById.get().getInternalTransactionsCount(); Assert.assertEquals(4, transactionsCount); for (int i = 0; i < transactionsCount; i++) { Assert.assertFalse(infoById.get().getInternalTransactions(i).getRejected()); } dupInternalTrsansactionHash(infoById.get().getInternalTransactionsList()); - String note = ByteArray - .toStr(infoById.get().getInternalTransactions(0).getNote().toByteArray()); - String note1 = ByteArray - .toStr(infoById.get().getInternalTransactions(1).getNote().toByteArray()); - String note2 = ByteArray - .toStr(infoById.get().getInternalTransactions(2).getNote().toByteArray()); - String note3 = ByteArray - .toStr(infoById.get().getInternalTransactions(3).getNote().toByteArray()); + String note = + ByteArray.toStr(infoById.get().getInternalTransactions(0).getNote().toByteArray()); + String note1 = + ByteArray.toStr(infoById.get().getInternalTransactions(1).getNote().toByteArray()); + String note2 = + ByteArray.toStr(infoById.get().getInternalTransactions(2).getNote().toByteArray()); + String note3 = + ByteArray.toStr(infoById.get().getInternalTransactions(3).getNote().toByteArray()); Assert.assertEquals("create", note); Assert.assertEquals("call", note1); Assert.assertEquals("call", note2); Assert.assertEquals("create", note3); - Long vaule1 = infoById.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); - Long vaule2 = infoById.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); - Long vaule3 = infoById.get().getInternalTransactions(2).getCallValueInfo(0).getCallValue(); - Long vaule4 = infoById.get().getInternalTransactions(3).getCallValueInfo(0).getCallValue(); + Long vaule1 = infoById.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); + Long vaule2 = infoById.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); + Long vaule3 = infoById.get().getInternalTransactions(2).getCallValueInfo(0).getCallValue(); + Long vaule4 = infoById.get().getInternalTransactions(3).getCallValueInfo(0).getCallValue(); Assert.assertTrue(10 == vaule1); Assert.assertTrue(0 == vaule2); Assert.assertTrue(2 == vaule3); Assert.assertTrue(5 == vaule4); - - } - - @Test(enabled = true, description = "Test delegatecall and callcode.", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Test delegatecall and callcode.", + groups = {"contract", "daily"}) public void testInternalTransaction014() { - Assert.assertTrue(PublicMethod - .sendcoin(internalTxsAddress, 100000000000L, foundationAddress, foundationKey, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + internalTxsAddress, 100000000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/" - + "contractInternalTransaction003testInternalTransaction014.sol"; - String contractName = "callerContract"; + String filePath = + "src/test/resources/soliditycode/" + + "contractInternalTransaction003testInternalTransaction014.sol"; + String contractName = "callerContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); - String contractName1 = "calledContract"; + String contractName1 = "calledContract"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - byte[] contractAddress1 = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); - - String contractName2 = "c"; + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + byte[] contractAddress1 = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); + + String contractName2 = "c"; HashMap retMap2 = PublicMethod.getBycodeAbi(filePath, contractName2); - String code2 = retMap2.get("byteCode").toString(); - String abi2 = retMap2.get("abI").toString(); - byte[] contractAddress2 = PublicMethod - .deployContract(contractName2, abi2, code2, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code2 = retMap2.get("byteCode").toString(); + String abi2 = retMap2.get("abI").toString(); + byte[] contractAddress2 = + PublicMethod.deployContract( + contractName2, + abi2, + code2, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String initParmes = "\"" + Base58.encode58Check(contractAddress1) - + "\",\"" + Base58.encode58Check(contractAddress2) + "\""; - String txid = ""; - txid = PublicMethod.triggerContract(contractAddress, - "sendToB(address,address)", initParmes, false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); - + String initParmes = + "\"" + + Base58.encode58Check(contractAddress1) + + "\",\"" + + Base58.encode58Check(contractAddress2) + + "\""; + String txid = ""; + txid = + PublicMethod.triggerContract( + contractAddress, + "sendToB(address,address)", + initParmes, + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); - String txid2 = ""; - txid2 = PublicMethod.triggerContract(contractAddress, - "sendToB2(address,address)", initParmes, false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String txid2 = ""; + txid2 = + PublicMethod.triggerContract( + contractAddress, + "sendToB2(address,address)", + initParmes, + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); - String txid3 = ""; - txid3 = PublicMethod.triggerContract(contractAddress, - "sendToB3(address,address)", initParmes, false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String txid3 = ""; + txid3 = + PublicMethod.triggerContract( + contractAddress, + "sendToB3(address,address)", + initParmes, + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - int transactionsCount = infoById.get().getInternalTransactionsCount(); + int transactionsCount = infoById.get().getInternalTransactionsCount(); Assert.assertEquals(2, transactionsCount); for (int i = 0; i < transactionsCount; i++) { Assert.assertFalse(infoById.get().getInternalTransactions(i).getRejected()); - Assert.assertEquals("call", ByteArray - .toStr(infoById.get().getInternalTransactions(i).getNote().toByteArray())); + Assert.assertEquals( + "call", + ByteArray.toStr(infoById.get().getInternalTransactions(i).getNote().toByteArray())); } - Assert.assertEquals(ByteArray - .toHexString(infoById.get().getInternalTransactions(0).getCallerAddress() - .toByteArray()), + Assert.assertEquals( + ByteArray.toHexString( + infoById.get().getInternalTransactions(0).getCallerAddress().toByteArray()), ByteArray.toHexString( infoById.get().getInternalTransactions(0).getTransferToAddress().toByteArray())); - Assert.assertEquals(ByteArray - .toHexString(contractAddress2), + Assert.assertEquals( + ByteArray.toHexString(contractAddress2), ByteArray.toHexString( infoById.get().getInternalTransactions(1).getTransferToAddress().toByteArray())); - Optional infoById2 = null; infoById2 = PublicMethod.getTransactionInfoById(txid2, blockingStubFull); Assert.assertTrue(infoById2.get().getResultValue() == 0); - int transactionsCount2 = infoById2.get().getInternalTransactionsCount(); + int transactionsCount2 = infoById2.get().getInternalTransactionsCount(); Assert.assertEquals(2, transactionsCount2); for (int i = 0; i < transactionsCount2; i++) { Assert.assertFalse(infoById2.get().getInternalTransactions(i).getRejected()); - Assert.assertEquals("call", ByteArray - .toStr(infoById2.get().getInternalTransactions(i).getNote().toByteArray())); + Assert.assertEquals( + "call", + ByteArray.toStr(infoById2.get().getInternalTransactions(i).getNote().toByteArray())); } - Assert.assertEquals(ByteArray - .toHexString(contractAddress), + Assert.assertEquals( + ByteArray.toHexString(contractAddress), ByteArray.toHexString( infoById2.get().getInternalTransactions(0).getCallerAddress().toByteArray())); - Assert.assertEquals(ByteArray - .toHexString(contractAddress1), + Assert.assertEquals( + ByteArray.toHexString(contractAddress1), ByteArray.toHexString( infoById2.get().getInternalTransactions(0).getTransferToAddress().toByteArray())); - Assert.assertEquals(ByteArray - .toHexString(contractAddress1), + Assert.assertEquals( + ByteArray.toHexString(contractAddress1), ByteArray.toHexString( infoById2.get().getInternalTransactions(1).getCallerAddress().toByteArray())); - Assert.assertEquals(ByteArray - .toHexString(contractAddress2), + Assert.assertEquals( + ByteArray.toHexString(contractAddress2), ByteArray.toHexString( infoById2.get().getInternalTransactions(1).getTransferToAddress().toByteArray())); Optional infoById3 = null; infoById3 = PublicMethod.getTransactionInfoById(txid3, blockingStubFull); Assert.assertTrue(infoById3.get().getResultValue() == 0); - int transactionsCount3 = infoById3.get().getInternalTransactionsCount(); + int transactionsCount3 = infoById3.get().getInternalTransactionsCount(); Assert.assertEquals(2, transactionsCount3); for (int i = 0; i < transactionsCount3; i++) { Assert.assertFalse(infoById3.get().getInternalTransactions(i).getRejected()); - Assert.assertEquals("call", ByteArray - .toStr(infoById3.get().getInternalTransactions(i).getNote().toByteArray())); + Assert.assertEquals( + "call", + ByteArray.toStr(infoById3.get().getInternalTransactions(i).getNote().toByteArray())); } - Assert.assertEquals(ByteArray - .toHexString(infoById3.get().getInternalTransactions(0).getCallerAddress() - .toByteArray()), + Assert.assertEquals( + ByteArray.toHexString( + infoById3.get().getInternalTransactions(0).getCallerAddress().toByteArray()), ByteArray.toHexString( infoById3.get().getInternalTransactions(0).getTransferToAddress().toByteArray())); - Assert.assertEquals(ByteArray - .toHexString(contractAddress2), + Assert.assertEquals( + ByteArray.toHexString(contractAddress2), ByteArray.toHexString( infoById3.get().getInternalTransactions(1).getTransferToAddress().toByteArray())); dupInternalTrsansactionHash(infoById.get().getInternalTransactionsList()); dupInternalTrsansactionHash(infoById2.get().getInternalTransactionsList()); dupInternalTrsansactionHash(infoById3.get().getInternalTransactionsList()); - } - @Test(enabled = true, description = "Three-level nesting.Type " - + "is create call->call->create call->suicide", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Three-level nesting.Type " + "is create call->call->create call->suicide", + groups = {"contract", "daily"}) public void testInternalTransaction015() { - Assert.assertTrue(PublicMethod - .sendcoin(internalTxsAddress, 100000000000L, foundationAddress, foundationKey, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + internalTxsAddress, 100000000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/" - + "contractInternalTransaction003testInternalTransaction015.sol"; - String contractName = "A"; + String filePath = + "src/test/resources/soliditycode/" + + "contractInternalTransaction003testInternalTransaction015.sol"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); - String contractName1 = "D"; + String contractName1 = "D"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - byte[] contractAddress1 = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); - - String contractName2 = "E"; + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + byte[] contractAddress1 = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); + + String contractName2 = "E"; HashMap retMap2 = PublicMethod.getBycodeAbi(filePath, contractName2); - String code2 = retMap2.get("byteCode").toString(); - String abi2 = retMap2.get("abI").toString(); - byte[] contractAddress2 = PublicMethod - .deployContract(contractName2, abi2, code2, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code2 = retMap2.get("byteCode").toString(); + String abi2 = retMap2.get("abI").toString(); + byte[] contractAddress2 = + PublicMethod.deployContract( + contractName2, + abi2, + code2, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String initParmes = "\"" + Base58.encode58Check(contractAddress1) - + "\",\"" + Base58.encode58Check(contractAddress2) + "\""; - String txid = ""; - txid = PublicMethod.triggerContract(contractAddress, - "test1(address,address)", initParmes, false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String initParmes = + "\"" + + Base58.encode58Check(contractAddress1) + + "\",\"" + + Base58.encode58Check(contractAddress2) + + "\""; + String txid = ""; + txid = + PublicMethod.triggerContract( + contractAddress, + "test1(address,address)", + initParmes, + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - int transactionsCount = infoById.get().getInternalTransactionsCount(); + int transactionsCount = infoById.get().getInternalTransactionsCount(); Assert.assertEquals(6, transactionsCount); dupInternalTrsansactionHash(infoById.get().getInternalTransactionsList()); - - } - - @Test(enabled = false, description = "After create 80 times,then suicide", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "After create 80 times,then suicide", + groups = {"contract", "daily"}) public void testInternalTransaction016() { - Assert.assertTrue(PublicMethod - .sendcoin(internalTxsAddress, 100000000000L, foundationAddress, foundationKey, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + internalTxsAddress, 100000000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/" - + "contractInternalTransaction003testInternalTransaction016.sol"; - String contractName = "A"; + String filePath = + "src/test/resources/soliditycode/" + + "contractInternalTransaction003testInternalTransaction016.sol"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = ""; - txid = PublicMethod.triggerContract(contractAddress, - "transfer()", "#", false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String txid = ""; + txid = + PublicMethod.triggerContract( + contractAddress, + "transfer()", + "#", + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); String txid1 = ""; - txid1 = PublicMethod.triggerContract(contractAddress, - "transfer2()", "#", false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + txid1 = + PublicMethod.triggerContract( + contractAddress, + "transfer2()", + "#", + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - int transactionsCount = infoById.get().getInternalTransactionsCount(); + int transactionsCount = infoById.get().getInternalTransactionsCount(); Assert.assertEquals(69, transactionsCount); for (int i = 0; i < transactionsCount; i++) { Assert.assertFalse(infoById.get().getInternalTransactions(i).getRejected()); } - Assert.assertEquals("suicide", ByteArray - .toStr(infoById.get().getInternalTransactions(68).getNote().toByteArray())); - Assert.assertEquals("call", ByteArray - .toStr(infoById.get().getInternalTransactions(67).getNote().toByteArray())); - Assert.assertEquals(0, - infoById.get().getInternalTransactions(67).getCallValueInfo(0).getCallValue()); - Assert.assertEquals(1, - infoById.get().getInternalTransactions(68).getCallValueInfo(0).getCallValue()); + Assert.assertEquals( + "suicide", + ByteArray.toStr(infoById.get().getInternalTransactions(68).getNote().toByteArray())); + Assert.assertEquals( + "call", + ByteArray.toStr(infoById.get().getInternalTransactions(67).getNote().toByteArray())); + Assert.assertEquals( + 0, infoById.get().getInternalTransactions(67).getCallValueInfo(0).getCallValue()); + Assert.assertEquals( + 1, infoById.get().getInternalTransactions(68).getCallValueInfo(0).getCallValue()); for (int i = 0; i < transactionsCount - 2; i++) { - Assert.assertEquals("create", ByteArray - .toStr(infoById.get().getInternalTransactions(i).getNote().toByteArray())); - Assert.assertEquals(1, - infoById.get().getInternalTransactions(i).getCallValueInfo(0).getCallValue()); + Assert.assertEquals( + "create", + ByteArray.toStr(infoById.get().getInternalTransactions(i).getNote().toByteArray())); + Assert.assertEquals( + 1, infoById.get().getInternalTransactions(i).getCallValueInfo(0).getCallValue()); } Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); - int transactionsCount1 = infoById1.get().getInternalTransactionsCount(); + int transactionsCount1 = infoById1.get().getInternalTransactionsCount(); Assert.assertEquals(68, transactionsCount1); for (int i = 0; i < transactionsCount1; i++) { Assert.assertTrue(infoById1.get().getInternalTransactions(i).getRejected()); - Assert.assertEquals("create", ByteArray - .toStr(infoById1.get().getInternalTransactions(i).getNote().toByteArray())); - + Assert.assertEquals( + "create", + ByteArray.toStr(infoById1.get().getInternalTransactions(i).getNote().toByteArray())); } dupInternalTrsansactionHash(infoById.get().getInternalTransactionsList()); dupInternalTrsansactionHash(infoById1.get().getInternalTransactionsList()); - } - @Test(enabled = false, description = "After create 88 times,then suicide", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "After create 88 times,then suicide", + groups = {"contract", "daily"}) public void testInternalTransaction017() { - Assert.assertTrue(PublicMethod - .sendcoin(internalTxsAddress, 100000000000L, foundationAddress, foundationKey, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + internalTxsAddress, 100000000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/" - + "contractInternalTransaction003testInternalTransaction017.sol"; - String contractName = "A"; + String filePath = + "src/test/resources/soliditycode/" + + "contractInternalTransaction003testInternalTransaction017.sol"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String initParmes = "\"" + Base58.encode58Check(contractAddress) + "\""; - String txid = ""; - txid = PublicMethod.triggerContract(contractAddress, - "transfer(address)", initParmes, false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String initParmes = "\"" + Base58.encode58Check(contractAddress) + "\""; + String txid = ""; + txid = + PublicMethod.triggerContract( + contractAddress, + "transfer(address)", + initParmes, + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - int transactionsCount = infoById.get().getInternalTransactionsCount(); + int transactionsCount = infoById.get().getInternalTransactionsCount(); Assert.assertEquals(77, transactionsCount); for (int i = 0; i < transactionsCount; i++) { Assert.assertFalse(infoById.get().getInternalTransactions(i).getRejected()); } - Assert.assertEquals("suicide", ByteArray - .toStr(infoById.get().getInternalTransactions(76).getNote().toByteArray())); - Assert.assertEquals(1000000 - 76, + Assert.assertEquals( + "suicide", + ByteArray.toStr(infoById.get().getInternalTransactions(76).getNote().toByteArray())); + Assert.assertEquals( + 1000000 - 76, infoById.get().getInternalTransactions(76).getCallValueInfo(0).getCallValue()); for (int i = 0; i < transactionsCount - 1; i++) { - Assert.assertEquals("create", ByteArray - .toStr(infoById.get().getInternalTransactions(i).getNote().toByteArray())); - Assert.assertEquals(1, - infoById.get().getInternalTransactions(i).getCallValueInfo(0).getCallValue()); + Assert.assertEquals( + "create", + ByteArray.toStr(infoById.get().getInternalTransactions(i).getNote().toByteArray())); + Assert.assertEquals( + 1, infoById.get().getInternalTransactions(i).getCallValueInfo(0).getCallValue()); } dupInternalTrsansactionHash(infoById.get().getInternalTransactionsList()); } - @Test(enabled = true, retryAnalyzer = Retry.class, - description = "Test maxfeelimit can trigger call create call max time", groups = {"contract", "daily"}) + @Test( + enabled = true, + retryAnalyzer = Retry.class, + description = "Test maxfeelimit can trigger call create call max time", + groups = {"contract", "daily"}) public void testInternalTransaction018() { - Assert.assertTrue(PublicMethod - .sendcoin(internalTxsAddress, 100000000000L, foundationAddress, foundationKey, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + internalTxsAddress, 100000000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/" - + "contractInternalTransaction003testInternalTransaction018.sol"; - String contractName = "A"; + String filePath = + "src/test/resources/soliditycode/" + + "contractInternalTransaction003testInternalTransaction018.sol"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); - String contractName1 = "B"; + String contractName1 = "B"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - byte[] contractAddress1 = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); - - String contractName2 = "E"; + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + byte[] contractAddress1 = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); + + String contractName2 = "E"; HashMap retMap2 = PublicMethod.getBycodeAbi(filePath, contractName2); - String code2 = retMap2.get("byteCode").toString(); - String abi2 = retMap2.get("abI").toString(); - byte[] contractAddress2 = PublicMethod - .deployContract(contractName2, abi2, code2, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); - PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod - .sendcoin(internalTxsAddress, 500000000000L, foundationAddress, foundationKey, + String code2 = retMap2.get("byteCode").toString(); + String abi2 = retMap2.get("abI").toString(); + byte[] contractAddress2 = + PublicMethod.deployContract( + contractName2, + abi2, + code2, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); + PublicMethod.sendcoin( + internalTxsAddress, 500000000000L, foundationAddress, foundationKey, blockingStubFull); + PublicMethod.waitProduceNextBlock(blockingStubFull); - String initParmes = "\"" + Base58.encode58Check(contractAddress1) - + "\",\"" + Base58.encode58Check(contractAddress2) + "\""; - String txid = ""; - txid = PublicMethod.triggerContract(contractAddress, - "test1(address,address)", initParmes, false, - 100000, 2 * maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String initParmes = + "\"" + + Base58.encode58Check(contractAddress1) + + "\",\"" + + Base58.encode58Check(contractAddress2) + + "\""; + String txid = ""; + txid = + PublicMethod.triggerContract( + contractAddress, + "test1(address,address)", + initParmes, + false, + 100000, + 2 * maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("InfoById:" + infoById); - int retryTimes = 1; + int retryTimes = 1; while (retryTimes++ < 5 && infoById.get().getResultValue() != 0) { // retry 5 times - txid = PublicMethod.triggerContract(contractAddress, - "test1(address,address)", initParmes, false, - 100000, 2 * maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "test1(address,address)", + initParmes, + false, + 100000, + 2 * maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - logger.info("InfoById retry " + retryTimes + " : " + infoById); + logger.info("InfoById retry " + retryTimes + " : " + infoById); } - Assert.assertEquals(0, infoById.get().getResultValue()); - int transactionsCount = infoById.get().getInternalTransactionsCount(); + int transactionsCount = infoById.get().getInternalTransactionsCount(); Assert.assertEquals(184, transactionsCount); for (int i = 0; i < transactionsCount; i++) { Assert.assertFalse(infoById.get().getInternalTransactions(i).getRejected()); } dupInternalTrsansactionHash(infoById.get().getInternalTransactionsList()); - String note = ByteArray - .toStr(infoById.get().getInternalTransactions(0).getNote().toByteArray()); - String note1 = ByteArray - .toStr(infoById.get().getInternalTransactions(1).getNote().toByteArray()); - String note2 = ByteArray - .toStr(infoById.get().getInternalTransactions(2).getNote().toByteArray()); - String note3 = ByteArray - .toStr(infoById.get().getInternalTransactions(3).getNote().toByteArray()); - Long vaule1 = infoById.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); - Long vaule2 = infoById.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); - Long vaule3 = infoById.get().getInternalTransactions(2).getCallValueInfo(0).getCallValue(); - Long vaule4 = infoById.get().getInternalTransactions(3).getCallValueInfo(0).getCallValue(); + String note = + ByteArray.toStr(infoById.get().getInternalTransactions(0).getNote().toByteArray()); + String note1 = + ByteArray.toStr(infoById.get().getInternalTransactions(1).getNote().toByteArray()); + String note2 = + ByteArray.toStr(infoById.get().getInternalTransactions(2).getNote().toByteArray()); + String note3 = + ByteArray.toStr(infoById.get().getInternalTransactions(3).getNote().toByteArray()); + Long vaule1 = infoById.get().getInternalTransactions(0).getCallValueInfo(0).getCallValue(); + Long vaule2 = infoById.get().getInternalTransactions(1).getCallValueInfo(0).getCallValue(); + Long vaule3 = infoById.get().getInternalTransactions(2).getCallValueInfo(0).getCallValue(); + Long vaule4 = infoById.get().getInternalTransactions(3).getCallValueInfo(0).getCallValue(); Assert.assertEquals("call", note); Assert.assertEquals("create", note1); @@ -510,31 +739,31 @@ public void testInternalTransaction018() { Assert.assertTrue(1 == vaule4); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(internalTxsAddress, testKeyForinternalTxsAddress, foundationAddress, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + internalTxsAddress, testKeyForinternalTxsAddress, foundationAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - + } + } - /** - * constructor. - */ + /** constructor. */ public void dupInternalTrsansactionHash( List internalTransactionList) { List hashList = new ArrayList<>(); internalTransactionList.forEach( - internalTransaction -> hashList - .add(Hex.toHexString(internalTransaction.getHash().toByteArray()))); - List dupHash = hashList.stream() - .collect(Collectors.toMap(e -> e, e -> 1, (a, b) -> a + b)) - .entrySet().stream().filter(entry -> entry.getValue() > 1).map(entry -> entry.getKey()) - .collect(Collectors.toList()); + internalTransaction -> + hashList.add(Hex.toHexString(internalTransaction.getHash().toByteArray()))); + List dupHash = + hashList.stream() + .collect(Collectors.toMap(e -> e, e -> 1, (a, b) -> a + b)) + .entrySet() + .stream() + .filter(entry -> entry.getValue() > 1) + .map(entry -> entry.getKey()) + .collect(Collectors.toList()); Assert.assertEquals(dupHash.size(), 0); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/Accounts001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/Accounts001.java index 4bcfe9da..ad3d5294 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/Accounts001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/Accounts001.java @@ -5,7 +5,11 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import io.grpc.ManagedChannelBuilder; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; @@ -54,7 +58,10 @@ public void beforeClass() { blockingStubFull = WalletGrpc.newBlockingStub(channelFull); } - @Test(enabled = true, description = "Json rpc api of eth_accounts", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_accounts", + groups = {"daily", "serial"}) public void test01JsonRpcApiTestForEthAccounts() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("eth_accounts", params); @@ -65,7 +72,10 @@ public void test01JsonRpcApiTestForEthAccounts() throws Exception { Assert.assertEquals(responseContent.get("result"), result); } - @Test(enabled = true, description = "Json rpc api of eth_blockNumber", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_blockNumber", + groups = {"daily", "serial"}) public void test02JsonRpcApiTestForEthBlockNumber() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("eth_blockNumber", params); @@ -83,7 +93,10 @@ public void test02JsonRpcApiTestForEthBlockNumber() throws Exception { Assert.assertTrue(Math.abs(blockNumFromJsonRpcNode - blockNumFromHttp) <= 3); } - @Test(enabled = true, description = "Json rpc api of eth_call", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_call", + groups = {"daily", "serial"}) public void test03JsonRpcApiTestForEthCall() throws Exception { JsonObject param = new JsonObject(); HttpMethod.waitToProduceOneBlock(httpFullNode); @@ -109,10 +122,7 @@ public void test03JsonRpcApiTestForEthCall() throws Exception { + "00000000000000000000000000000000000", dataResult); - - - - //release_4.5.2 to latest version, revert will return instead of failed gas value. + // release_4.5.2 to latest version, revert will return instead of failed gas value. JsonObject wrongParam = new JsonObject(); params.remove(param); HttpMethod.waitToProduceOneBlock(httpFullNode); @@ -121,8 +131,11 @@ public void test03JsonRpcApiTestForEthCall() throws Exception { wrongParam.addProperty("gas", "0x0"); wrongParam.addProperty("gasPrice", "0x0"); wrongParam.addProperty("value", "0x0"); - paramString = "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000010000000000000000000000000000000"; - wrongParam.addProperty("data", "0x" + Util.parseMethod("transfer(address,uint256)", paramString)); + paramString = + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000010000000000000000000000000000000"; + wrongParam.addProperty( + "data", "0x" + Util.parseMethod("transfer(address,uint256)", paramString)); params.add(wrongParam); params.add("latest"); @@ -133,12 +146,14 @@ public void test03JsonRpcApiTestForEthCall() throws Exception { responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); JSONObject errorResult = responseContent.getJSONObject("error"); - Assert.assertEquals(errorResult.getString("code"),"-32602"); - Assert.assertEquals(errorResult.getString("message"),"method parameters invalid"); - + Assert.assertEquals(errorResult.getString("code"), "-32602"); + Assert.assertEquals(errorResult.getString("message"), "method parameters invalid"); } - @Test(enabled = true, description = "Json rpc api of eth_chainId", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_chainId", + groups = {"daily", "serial"}) public void test04JsonRpcApiTestForEthChainId() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("eth_chainId", params); @@ -154,7 +169,10 @@ public void test04JsonRpcApiTestForEthChainId() throws Exception { Assert.assertEquals(blockIdFromJsonRpcNode, blockIdFromHttp); } - @Test(enabled = true, description = "Json rpc api of eth_coinbase", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_coinbase", + groups = {"daily", "serial"}) public void test05JsonRpcApiTestForEthCoinbase() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("eth_coinbase", params); @@ -165,7 +183,10 @@ public void test05JsonRpcApiTestForEthCoinbase() throws Exception { "0x410be88a918d74d0dfd71dc84bd4abf036d0562991", responseContent.getString("result")); } - @Test(enabled = true, description = "Json rpc api of eth_estimateGas", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_estimateGas", + groups = {"daily", "serial"}) public void test06JsonRpcApiTestForEthEstimateGas() throws Exception { JsonObject param = new JsonObject(); param.addProperty("from", ByteArray.toHexString(jsonRpcOwnerAddress)); @@ -173,7 +194,9 @@ public void test06JsonRpcApiTestForEthEstimateGas() throws Exception { param.addProperty("gas", "0x0"); param.addProperty("gasPrice", "0x0"); param.addProperty("value", "0x0"); - paramString = "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000010000000000000000000000000000000"; + paramString = + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000010000000000000000000000000000000"; param.addProperty("data", "0x" + Util.parseMethod("approve(address,uint256)", paramString)); JsonArray params = new JsonArray(); params.add(param); @@ -185,7 +208,7 @@ public void test06JsonRpcApiTestForEthEstimateGas() throws Exception { String dataResult = responseContent.getString("result"); Assert.assertEquals("0x4fd1", dataResult); - //release_4.5.2 to latest version, revert will return instead of failed gas value. + // release_4.5.2 to latest version, revert will return instead of failed gas value. JsonObject wrongParam = new JsonObject(); params.remove(param); wrongParam.addProperty("from", ByteArray.toHexString(jsonRpcOwnerAddress)); @@ -193,18 +216,22 @@ public void test06JsonRpcApiTestForEthEstimateGas() throws Exception { wrongParam.addProperty("gas", "0x0"); wrongParam.addProperty("gasPrice", "0x0"); wrongParam.addProperty("value", "0x0"); - wrongParam.addProperty("data", "0x" + Util.parseMethod("transfer(address,uint256)", paramString)); + wrongParam.addProperty( + "data", "0x" + Util.parseMethod("transfer(address,uint256)", paramString)); params.add(wrongParam); requestBody = getJsonRpcBody("eth_estimateGas", params); response = getJsonRpc(jsonRpcNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); JSONObject errorResult = responseContent.getJSONObject("error"); - Assert.assertEquals(errorResult.getString("code"),"-32000"); - Assert.assertEquals(errorResult.getString("message"),"REVERT opcode executed"); + Assert.assertEquals(errorResult.getString("code"), "-32000"); + Assert.assertEquals(errorResult.getString("message"), "REVERT opcode executed"); } - @Test(enabled = true, description = "Json rpc api of eth_estimateGasHasPayable", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_estimateGasHasPayable", + groups = {"daily", "serial"}) public void test07JsonRpcApiTestForEthEstimateGasHasPayable() throws Exception { response = HttpMethod.getTransactionInfoById(httpFullNode, txid); responseContent = HttpMethod.parseResponseContent(response); @@ -227,7 +254,10 @@ public void test07JsonRpcApiTestForEthEstimateGasHasPayable() throws Exception { Assert.assertEquals((long) realEnergyUsed, Long.parseLong(dataResult.substring(2), 16)); } - @Test(enabled = true, description = "Json rpc api of eth_estimateGasWithoutTo", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_estimateGasWithoutTo", + groups = {"daily", "serial"}) public void test08JsonRpcApiTestForEthEstimateGasWithoutTo() throws Exception { JsonObject param = new JsonObject(); param.addProperty("from", "0x6C0214C9995C6F3A61AB23F0EB84B0CDE7FD9C7C"); @@ -258,7 +288,10 @@ public void test08JsonRpcApiTestForEthEstimateGasWithoutTo() throws Exception { Assert.assertEquals(energyUsed, dataResult); } - @Test(enabled = true, description = "Json rpc api of eth_estimateGasSendTrx", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_estimateGasSendTrx", + groups = {"daily", "serial"}) public void test09JsonRpcApiTestForEthEstimateGasSendTrx() throws Exception { JsonObject param = new JsonObject(); param.addProperty("from", ByteArray.toHexString(jsonRpcOwnerAddress)); @@ -277,7 +310,10 @@ public void test09JsonRpcApiTestForEthEstimateGasSendTrx() throws Exception { Assert.assertEquals("0x0", dataResult); } - @Test(enabled = true, description = "Json rpc api of eth_gasPrice", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_gasPrice", + groups = {"daily", "serial"}) public void test10JsonRpcApiTestForEthGasPrice() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("eth_gasPrice", params); @@ -300,7 +336,10 @@ public void test10JsonRpcApiTestForEthGasPrice() throws Exception { Assert.assertEquals(gasPriceFromJsonrpc, gasPriceFromHttp); } - @Test(enabled = true, description = "Json rpc api of eth_getBalance", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getBalance", + groups = {"daily", "serial"}) public void test11JsonRpcApiTestForEthGetBalance() throws Exception { JsonArray params = new JsonArray(); params.add("0x" + ByteArray.toHexString(foundationAddress).substring(2)); @@ -316,7 +355,10 @@ public void test11JsonRpcApiTestForEthGetBalance() throws Exception { Assert.assertEquals(balance1, balance2); } - @Test(enabled = true, description = "Json rpc api of eth_getBlockTransactionCountByNumber", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getBlockTransactionCountByNumber", + groups = {"daily", "serial"}) public void test12JsonRpcApiTestForEthGetBlockTransactionCountByNum() throws Exception { response = HttpMethod.getNowBlock(httpFullNode); responseContent = HttpMethod.parseResponseContent(response); @@ -335,7 +377,10 @@ public void test12JsonRpcApiTestForEthGetBlockTransactionCountByNum() throws Exc Assert.assertEquals(transactionNum1, transactionNum2); } - @Test(enabled = true, description = "Json rpc api of eth_getCode", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getCode", + groups = {"daily", "serial"}) public void test13JsonRpcApiTestForEthGetCode() throws Exception { JsonArray params = new JsonArray(); @@ -354,7 +399,10 @@ public void test13JsonRpcApiTestForEthGetCode() throws Exception { Assert.assertEquals(codeFromJsonRpc, codeFromHttp); } - @Test(enabled = true, description = "Json rpc api of eth_getStorageAt", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getStorageAt", + groups = {"daily", "serial"}) public void test14JsonRpcApiTestForEthGetStorageAt01() throws Exception { JsonArray params = new JsonArray(); @@ -372,7 +420,10 @@ public void test14JsonRpcApiTestForEthGetStorageAt01() throws Exception { Assert.assertEquals("1234", String.valueOf(resultExpect)); } - @Test(enabled = true, description = "Json rpc api of eth_getStorageAt", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getStorageAt", + groups = {"daily", "serial"}) public void test15JsonRpcApiTestForEthGetStorageAt02() throws Exception { String address = @@ -403,7 +454,10 @@ public void test15JsonRpcApiTestForEthGetStorageAt02() throws Exception { Assert.assertEquals("5678", String.valueOf(Integer.parseInt(result, 16))); } - @Test(enabled = true, description = "Json rpc api of eth_getTransactionByBlockNumberAndIndex", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getTransactionByBlockNumberAndIndex", + groups = {"daily", "serial"}) public void test16JsonRpcApiTestForEthGetTransactionByBlockNumberAndIndex() throws Exception { logger.info("16blockNum:" + blockNum); blockNumHex = "0x" + Long.toHexString(blockNum); @@ -518,12 +572,25 @@ public void test16JsonRpcApiTestForEthGetTransactionByBlockNumberAndIndex() thro Assert.assertEquals(jsonrpcResult.get("value").toString(), "0x1389"); String data; - if (getBlockByNumResult.getJSONObject("raw_data").getJSONArray("contract").getJSONObject(0) - .getJSONObject("parameter").getJSONObject("value").getString("data") == null) { + if (getBlockByNumResult + .getJSONObject("raw_data") + .getJSONArray("contract") + .getJSONObject(0) + .getJSONObject("parameter") + .getJSONObject("value") + .getString("data") + == null) { data = "0x"; } else { - data = "0x" + getBlockByNumResult.getJSONObject("raw_data").getJSONArray("contract") - .getJSONObject(0).getJSONObject("parameter").getJSONObject("value").getString("data"); + data = + "0x" + + getBlockByNumResult + .getJSONObject("raw_data") + .getJSONArray("contract") + .getJSONObject(0) + .getJSONObject("parameter") + .getJSONObject("value") + .getString("data"); } Assert.assertEquals(jsonrpcResult.get("input").toString(), data); @@ -541,7 +608,10 @@ public void test16JsonRpcApiTestForEthGetTransactionByBlockNumberAndIndex() thro getBlockByNumResult.getString("signature").substring(66, 130)); } - @Test(enabled = true, description = "Json rpc api of eth_getBlockTransactionCountByHash", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getBlockTransactionCountByHash", + groups = {"daily", "serial"}) public void test17JsonRpcApiTestForEthGetBlockTransactionCountByHash() throws Exception { logger.info("17blockNum:" + blockNum); JsonArray params = new JsonArray(); @@ -563,7 +633,10 @@ public void test17JsonRpcApiTestForEthGetBlockTransactionCountByHash() throws Ex Assert.assertEquals(transactionNumFromHttp, transactionNumFromJsonRpcNode); } - @Test(enabled = true, description = "Json rpc api of eth_getBlockTransactionCountByNumber", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getBlockTransactionCountByNumber", + groups = {"daily", "serial"}) public void test18JsonRpcApiTestForEthGetBlockTransactionCountByNum() throws Exception { JsonArray params = new JsonArray(); params.add(blockNum); @@ -585,7 +658,10 @@ public void test18JsonRpcApiTestForEthGetBlockTransactionCountByNum() throws Exc Assert.assertEquals(transactionNum1, transactionNum2); } - @Test(enabled = true, description = "Json rpc api of eth_getTransactionByBlockHashAndIndex", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getTransactionByBlockHashAndIndex", + groups = {"daily", "serial"}) public void test19JsonRpcApiTestForEthGetTransactionByBlockHashAndIndex() throws Exception { JsonArray params = new JsonArray(); params.add("0x" + bid); @@ -598,7 +674,10 @@ public void test19JsonRpcApiTestForEthGetTransactionByBlockHashAndIndex() throws Assert.assertEquals(result, resultForGetTransactionByBlockHashAndIndex); } - @Test(enabled = true, description = "Json rpc api of eth_getTransactionByHash", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getTransactionByHash", + groups = {"daily", "serial"}) public void test20JsonRpcApiTestForEthGetTransactionByHash() throws Exception { logger.info("20transacionHash:" + transacionHash); JsonArray params = new JsonArray(); @@ -611,7 +690,10 @@ public void test20JsonRpcApiTestForEthGetTransactionByHash() throws Exception { Assert.assertEquals(result, result1); } - @Test(enabled = true, description = "Json rpc api of eth_getTransactionReceipt", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getTransactionReceipt", + groups = {"daily", "serial"}) public void test21JsonRpcApiTestForEthGetTransactionReceipt() throws Exception { logger.info("trc20Txid:" + trc20Txid); JsonArray params = new JsonArray(); @@ -728,7 +810,10 @@ public void test21JsonRpcApiTestForEthGetTransactionReceipt() throws Exception { responseContent1.get(index).getJSONArray("log").getJSONObject(0).getString("topics")); } - @Test(enabled = true, description = "Json rpc api of eth_getUncleByBlockHashAndIndex", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getUncleByBlockHashAndIndex", + groups = {"daily", "serial"}) public void test22JsonRpcApiTestForEthGetUncleByBlockHashAndIndex() throws Exception { JsonArray params = new JsonArray(); params.add("0x0000000000f9cc56243898cbe88685678855e07f51c5af91322c225ce3693868"); @@ -741,7 +826,10 @@ public void test22JsonRpcApiTestForEthGetUncleByBlockHashAndIndex() throws Excep Assert.assertNull(result); } - @Test(enabled = true, description = "Json rpc api of eth_getUncleByBlockNumberAndIndex", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getUncleByBlockNumberAndIndex", + groups = {"daily", "serial"}) public void test23JsonRpcApiTestForEthGetUncleByBlockNumberAndIndex() throws Exception { JsonArray params = new JsonArray(); params.add("0xeb82f0"); @@ -754,7 +842,10 @@ public void test23JsonRpcApiTestForEthGetUncleByBlockNumberAndIndex() throws Exc Assert.assertNull(result); } - @Test(enabled = true, description = "Json rpc api of eth_getUncleCountByBlockHash", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getUncleCountByBlockHash", + groups = {"daily", "serial"}) public void test24JsonRpcApiTestForEthGetUncleCountByBlockHash() throws Exception { JsonArray params = new JsonArray(); params.add("0x0000000000f9cc56243898cbe88685678855e07f51c5af91322c225ce3693868"); @@ -766,7 +857,10 @@ public void test24JsonRpcApiTestForEthGetUncleCountByBlockHash() throws Exceptio Assert.assertEquals(result, "0x0"); } - @Test(enabled = true, description = "Json rpc api of eth_getUncleCountByBlockNumber", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getUncleCountByBlockNumber", + groups = {"daily", "serial"}) public void test25JsonRpcApiTestForEthGetUncleCountByBlockNumber() throws Exception { JsonArray params = new JsonArray(); params.add("eth_getUncleCountByBlockNumber"); @@ -778,7 +872,10 @@ public void test25JsonRpcApiTestForEthGetUncleCountByBlockNumber() throws Except Assert.assertEquals(result, "0x0"); } - @Test(enabled = true, description = "Json rpc api of eth_getWork", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getWork", + groups = {"daily", "serial"}) public void test26JsonRpcApiTestForEthGetWork() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("eth_getWork", params); @@ -795,7 +892,10 @@ public void test26JsonRpcApiTestForEthGetWork() throws Exception { Assert.assertEquals(resultFromJsonRpcNode, resultFromHttp); } - @Test(enabled = true, description = "Json rpc api of eth_hashrate", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_hashrate", + groups = {"daily", "serial"}) public void test27JsonRpcApiTestForEthHashRate() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("eth_hashrate", params); @@ -806,7 +906,10 @@ public void test27JsonRpcApiTestForEthHashRate() throws Exception { Assert.assertEquals("0x0", result); } - @Test(enabled = true, description = "Json rpc api of eth_mining", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_mining", + groups = {"daily", "serial"}) public void test28JsonRpcApiTestForEthMining() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("eth_mining", params); @@ -817,7 +920,10 @@ public void test28JsonRpcApiTestForEthMining() throws Exception { Assert.assertEquals(result, "true"); } - @Test(enabled = true, description = "Json rpc api of eth_protocolVersion", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_protocolVersion", + groups = {"daily", "serial"}) public void test29JsonRpcApiTestForEthProtocolVersion() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("eth_protocolVersion", params); @@ -834,7 +940,10 @@ public void test29JsonRpcApiTestForEthProtocolVersion() throws Exception { Assert.assertEquals(protocolVersion1, protocolVersion2); } - @Test(enabled = true, description = "Json rpc api of eth_syncing", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_syncing", + groups = {"daily", "serial"}) public void test30JsonRpcApiTestForEthSyncing() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("eth_syncing", params); @@ -856,7 +965,10 @@ public void test30JsonRpcApiTestForEthSyncing() throws Exception { Assert.assertTrue(temp.containsKey("highestBlock")); } - @Test(enabled = true, description = "Json rpc api of net_listening", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of net_listening", + groups = {"daily", "serial"}) public void test31JsonRpcApiTestForNetListening() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("net_listening", params); @@ -874,7 +986,10 @@ public void test31JsonRpcApiTestForNetListening() throws Exception { Assert.assertEquals(temp, expect); } - @Test(enabled = true, description = "Json rpc api of net_peerCount", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of net_peerCount", + groups = {"daily", "serial"}) public void test32JsonRpcApiTestForNetPeerCount() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("net_peerCount", params); @@ -885,7 +1000,10 @@ public void test32JsonRpcApiTestForNetPeerCount() throws Exception { Assert.assertNotNull(result); } - @Test(enabled = true, description = "Json rpc api of net_version", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of net_version", + groups = {"daily", "serial"}) public void test33JsonRpcApiTestForEthVersion() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("net_version", params); @@ -900,7 +1018,10 @@ public void test33JsonRpcApiTestForEthVersion() throws Exception { Assert.assertEquals(firstBlockHashFromJsonRpc, firstBlockHashFromHttp); } - @Test(enabled = true, description = "Json rpc api of web3_clientVersion", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of web3_clientVersion", + groups = {"daily", "serial"}) public void test34JsonRpcApiTestForWeb3ClientVersion() throws Exception { String javaFullVersion = System.getProperty("java.version"); logger.info("javaFullVersion:" + javaFullVersion); @@ -929,25 +1050,32 @@ public void test34JsonRpcApiTestForWeb3ClientVersion() throws Exception { Assert.assertEquals(resultList.get(3), "Java" + javaVersion); } - @Test(enabled = true, description = "Json rpc api of web3_sha3", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of web3_sha3", + groups = {"daily", "serial"}) public void test35JsonRpcApiTestForWeb3Sha3() throws Exception { JsonArray params = new JsonArray(); params.add("0x08"); - //JsonObject requestBody1 = getJsonRpcBody("web3_sha3", params); - //response = getEthHttps(ethHttpsNode, requestBody1); - //responseContent = HttpMethod.parseResponseContent(response); - //HttpMethod.printJsonContent(responseContent); - //String result1 = responseContent.getString("result"); + // JsonObject requestBody1 = getJsonRpcBody("web3_sha3", params); + // response = getEthHttps(ethHttpsNode, requestBody1); + // responseContent = HttpMethod.parseResponseContent(response); + // HttpMethod.printJsonContent(responseContent); + // String result1 = responseContent.getString("result"); JsonObject requestBody2 = getJsonRpcBody("web3_sha3", params); response = getJsonRpc(jsonRpcNode, requestBody2); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); String result2 = responseContent.getString("result"); - Assert.assertEquals("0xd33e25809fcaa2b6900567812852539da8559dc8b76a7ce3fc5ddd77e8d19a69", result2); + Assert.assertEquals( + "0xd33e25809fcaa2b6900567812852539da8559dc8b76a7ce3fc5ddd77e8d19a69", result2); } - @Test(enabled = true, description = "Json rpc api of eth_compileLLL", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_compileLLL", + groups = {"daily", "serial"}) public void test36JsonRpcApiTestForEthCompileLll() throws Exception { JsonArray params = new JsonArray(); params.add("(returnlll (suicide (caller)))"); @@ -958,7 +1086,10 @@ public void test36JsonRpcApiTestForEthCompileLll() throws Exception { Assert.assertEquals(errorMessage, "the method eth_compileLLL does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of eth_compileSerpent", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_compileSerpent", + groups = {"daily", "serial"}) public void test37JsonRpcApiTestForEthCompileSerpent() throws Exception { JsonArray params = new JsonArray(); params.add("/* some serpent */"); @@ -970,7 +1101,10 @@ public void test37JsonRpcApiTestForEthCompileSerpent() throws Exception { errorMessage, "the method eth_compileSerpent does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of eth_compileSolidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_compileSolidity", + groups = {"daily", "serial"}) public void test38JsonRpcApiTestForEthCompileSolidity() throws Exception { JsonArray params = new JsonArray(); params.add("contract test { function multiply(uint a) returns(uint d) { return a * 7; } }"); @@ -982,7 +1116,10 @@ public void test38JsonRpcApiTestForEthCompileSolidity() throws Exception { errorMessage, "the method eth_compileSolidity does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of eth_getCompilers", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getCompilers", + groups = {"daily", "serial"}) public void test39JsonRpcApiTestForEthCompileSolidity() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("eth_getCompilers", params); @@ -993,7 +1130,10 @@ public void test39JsonRpcApiTestForEthCompileSolidity() throws Exception { errorMessage, "the method eth_getCompilers does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of eth_getTransactionCount", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getTransactionCount", + groups = {"daily", "serial"}) public void test40JsonRpcApiTestForEthGetTransactionCount() throws Exception { JsonArray params = new JsonArray(); params.add("0x407d73d8a49eeb85d32cf465507dd71d507100c1"); @@ -1006,7 +1146,10 @@ public void test40JsonRpcApiTestForEthGetTransactionCount() throws Exception { errorMessage, "the method eth_getTransactionCount does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of eth_sendRawTransaction", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_sendRawTransaction", + groups = {"daily", "serial"}) public void test41JsonRpcApiTestForEthSendRawTransaction() throws Exception { JsonArray params = new JsonArray(); params.add("0x234"); @@ -1018,7 +1161,10 @@ public void test41JsonRpcApiTestForEthSendRawTransaction() throws Exception { errorMessage, "the method eth_sendRawTransaction does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of eth_sendTransaction", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_sendTransaction", + groups = {"daily", "serial"}) public void test42JsonRpcApiTestForEthSendTransaction() throws Exception { JsonArray params = new JsonArray(); JsonObject temp = new JsonObject(); @@ -1040,7 +1186,10 @@ public void test42JsonRpcApiTestForEthSendTransaction() throws Exception { errorMessage, "the method eth_sendTransaction does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of eth_sign", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_sign", + groups = {"daily", "serial"}) public void test43JsonRpcApiTestForEthSign() throws Exception { JsonArray params = new JsonArray(); params.add("0x9b2055d370f73ec7d8a03e965129118dc8f5bf83"); @@ -1052,7 +1201,10 @@ public void test43JsonRpcApiTestForEthSign() throws Exception { Assert.assertEquals(errorMessage, "the method eth_sign does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of eth_signTransaction", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_signTransaction", + groups = {"daily", "serial"}) public void test44JsonRpcApiTestForEthSignTransaction() throws Exception { JsonArray params = new JsonArray(); JsonObject temp = new JsonObject(); @@ -1074,7 +1226,10 @@ public void test44JsonRpcApiTestForEthSignTransaction() throws Exception { errorMessage, "the method eth_signTransaction does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of eth_submitWork", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_submitWork", + groups = {"daily", "serial"}) public void test45JsonRpcApiTestForEthSubmitWork() throws Exception { JsonArray params = new JsonArray(); params.add("0x0000000000000001"); @@ -1087,7 +1242,10 @@ public void test45JsonRpcApiTestForEthSubmitWork() throws Exception { Assert.assertEquals(errorMessage, "the method eth_submitWork does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of parity_nextNonce", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of parity_nextNonce", + groups = {"daily", "serial"}) public void test46JsonRpcApiTestForParityNextNonce() throws Exception { JsonArray params = new JsonArray(); params.add("0x9b2055d370f73ec7d8a03e965129118dc8f5bf83"); @@ -1099,7 +1257,10 @@ public void test46JsonRpcApiTestForParityNextNonce() throws Exception { errorMessage, "the method parity_nextNonce does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of eth_submitHashrate", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_submitHashrate", + groups = {"daily", "serial"}) public void test47JsonRpcApiTestForEthSubmitHashrate() throws Exception { JsonArray params = new JsonArray(); params.add("0x0000000000000000000000000000000000000000000000000000000000500000"); @@ -1112,7 +1273,10 @@ public void test47JsonRpcApiTestForEthSubmitHashrate() throws Exception { errorMessage, "the method eth_submitHashrate does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of eth_getBlockByHash params is false", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getBlockByHash params is false", + groups = {"daily", "serial"}) public void test48JsonRpcApiTestForEthGetBlockByHash() throws Exception { response = HttpMethod.getBlockByNum(httpFullNode, blockNum); responseContent = HttpMethod.parseResponseContent(response); @@ -1190,7 +1354,10 @@ public void test48JsonRpcApiTestForEthGetBlockByHash() throws Exception { Assert.assertEquals(transactionIdListFromGetBlockByHash, transactionIdList); } - @Test(enabled = true, description = "Json rpc api of eth_getBlockByNumber params is true", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getBlockByNumber params is true", + groups = {"daily", "serial"}) public void test49JsonRpcApiTestForEthGetBlockByNumber() throws Exception { JsonArray params = new JsonArray(); @@ -1278,7 +1445,8 @@ public void test49JsonRpcApiTestForEthGetBlockByNumber() throws Exception { @Test( enabled = true, description = - "Json rpc api of eth_call,eth_estimateGas and eth_getTransactionByBlockHashAndIndex.", groups = {"daily", "serial"}) + "Json rpc api of eth_call,eth_estimateGas and eth_getTransactionByBlockHashAndIndex.", + groups = {"daily", "serial"}) public void test50JsonRpcApiTestForInterfaceCombination() throws Exception { final JsonArray jsonArrayParams = new JsonArray(); JsonObject param = new JsonObject(); @@ -1342,7 +1510,9 @@ public void test50JsonRpcApiTestForInterfaceCombination() throws Exception { } @Test( - enabled = true, description = "Json rpc api of eth_call with blockNumber", groups = {"daily", "serial"}) + enabled = true, + description = "Json rpc api of eth_call with blockNumber", + groups = {"daily", "serial"}) public void test51JsonRpcApiTestForEthCallWithBlockNumber() throws Exception { final JsonArray jsonArrayParams = new JsonArray(); JsonObject param = new JsonObject(); @@ -1356,7 +1526,7 @@ public void test51JsonRpcApiTestForEthCallWithBlockNumber() throws Exception { JsonArray params = new JsonArray(); params.add(param); JsonObject blockNumAndHash = new JsonObject(); - blockNumAndHash.addProperty("blockNumber",String.valueOf(blockNum)); + blockNumAndHash.addProperty("blockNumber", String.valueOf(blockNum)); params.add(blockNumAndHash); final JsonObject requestBody = getJsonRpcBody("eth_call", params); JsonObject param1 = new JsonObject(); @@ -1407,9 +1577,10 @@ public void test51JsonRpcApiTestForEthCallWithBlockNumber() throws Exception { Assert.assertEquals(result, resultForGetTransactionByBlockHashAndIndex); } - @Test( - enabled = true, description = "Json rpc api of eth_call with blockHash", groups = {"daily", "serial"}) + enabled = true, + description = "Json rpc api of eth_call with blockHash", + groups = {"daily", "serial"}) public void test52JsonRpcApiTestForEthCallWithBlockHash() throws Exception { final JsonArray jsonArrayParams = new JsonArray(); JsonObject param = new JsonObject(); @@ -1423,7 +1594,7 @@ public void test52JsonRpcApiTestForEthCallWithBlockHash() throws Exception { JsonArray params = new JsonArray(); params.add(param); JsonObject blockNumAndHash = new JsonObject(); - blockNumAndHash.addProperty("blockHash",blockHash); + blockNumAndHash.addProperty("blockHash", blockHash); params.add(blockNumAndHash); final JsonObject requestBody = getJsonRpcBody("eth_call", params); JsonObject param1 = new JsonObject(); @@ -1474,7 +1645,10 @@ public void test52JsonRpcApiTestForEthCallWithBlockHash() throws Exception { Assert.assertEquals(result, resultForGetTransactionByBlockHashAndIndex); } - @Test(enabled = true, description = "eth_getStorageAt with create2 address", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "eth_getStorageAt with create2 address", + groups = {"daily", "serial"}) public void test53StateTreeWithEthGetStorageAt() { JsonArray params = new JsonArray(); params.add(create2AddressFrom41); @@ -1489,7 +1663,10 @@ public void test53StateTreeWithEthGetStorageAt() { Assert.assertEquals(1, beforePos2); } - @Test(enabled = true, description = "Json rpc api of eth_getBlockByNumber params are finalized and true", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getBlockByNumber params are finalized and true", + groups = {"daily", "serial"}) public void test54JsonRpcApiTestForEthGetBlockByNumber() throws Exception { JsonArray params = new JsonArray(); @@ -1507,14 +1684,18 @@ public void test54JsonRpcApiTestForEthGetBlockByNumber() throws Exception { response = getJsonRpc(jsonRpcNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); JSONObject getBlockByNumberResult1 = responseContent.getJSONObject("result"); - Assert.assertEquals(getBlockByNumberResult.toJSONString(),getBlockByNumberResult1.toJSONString()); + Assert.assertEquals( + getBlockByNumberResult.toJSONString(), getBlockByNumberResult1.toJSONString()); } - @Test(enabled = false, description = "Json rpc api of eth_getBlockTransactionCountByNumber params are finalized ", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Json rpc api of eth_getBlockTransactionCountByNumber params are finalized ", + groups = {"daily", "serial"}) public void test55JsonRpcApiTestForEthGetBlockTransactionCountByNum() { response = HttpMethod.getNowBlockFromSolidity(httpsolidityNode); responseContent = HttpMethod.parseResponseContent(response); - if (!responseContent.containsKey("transactions")){ + if (!responseContent.containsKey("transactions")) { return; } int transactionNum1 = responseContent.getJSONArray("transactions").size(); @@ -1527,12 +1708,15 @@ public void test55JsonRpcApiTestForEthGetBlockTransactionCountByNum() { String transactionNum = responseContent.getString("result").substring(2); int transactionNum2 = Integer.parseInt(transactionNum, 16); logger.info(String.valueOf(transactionNum1)); - System.out.println("transactionNum1: " +transactionNum1); - System.out.println("transactionNum2: " +transactionNum2); + System.out.println("transactionNum1: " + transactionNum1); + System.out.println("transactionNum2: " + transactionNum2); Assert.assertEquals(transactionNum1, transactionNum2); } - @Test(enabled = false, description = "Json rpc api of eth_getTransactionByBlockNumberAndIndex params are finalized", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = "Json rpc api of eth_getTransactionByBlockNumberAndIndex params are finalized", + groups = {"daily", "serial"}) public void test56JsonRpcApiTestForEthGetTransactionByBlockNumberAndIndex() throws Exception { response = HttpMethod.getNowBlockFromSolidity(httpsolidityNode); responseContent = HttpMethod.parseResponseContent(response); @@ -1549,23 +1733,25 @@ public void test56JsonRpcApiTestForEthGetTransactionByBlockNumberAndIndex() thro responseContent = HttpMethod.parseResponseContent(response); String trans2 = responseContent.getJSONObject("result").toJSONString(); System.out.println(responseContent.toJSONString()); -// Assert.assertEquals(trans1, trans2); + // Assert.assertEquals(trans1, trans2); } - @Test(enabled = true, description = "Json rpc api of eth_getBlockReceipts test") public void test57JsonRpcApiTestForEthGetBlockReceipts() throws Exception { String selector = "transfer(address,uint256)"; String addressParam = - "000000000000000000000000" - + ByteArray.toHexString(foundationAddress).substring(2); // [0,3) + "000000000000000000000000" + ByteArray.toHexString(foundationAddress).substring(2); // [0,3) String transferValueParam = "0000000000000000000000000000000000000000000000000000000000000001"; String paramString = addressParam + transferValueParam; - long startBlockNum = blockingStubFull.getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + long startBlockNum = + blockingStubFull + .getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); int count = 10; - while (count-->0){ + while (count-- > 0) { Random r = new Random(); int randomValue = r.nextInt(9); transferValueParam.replace("1", String.valueOf(randomValue)); @@ -1586,11 +1772,11 @@ public void test57JsonRpcApiTestForEthGetBlockReceipts() throws Exception { PublicMethod.waitProduceNextBlock(blockingStubFull); long endBlockNum = startBlockNum + 10L; long targetBlockNum = 0L; - while (startBlockNum++ < endBlockNum){ + while (startBlockNum++ < endBlockNum) { int trxCount = PublicMethod.getBlock(startBlockNum, blockingStubFull).getTransactionsCount(); logger.info("trxCount: " + trxCount); logger.info("BlockNum: " + startBlockNum); - if(trxCount>=2){ + if (trxCount >= 2) { targetBlockNum = startBlockNum; break; } @@ -1609,7 +1795,7 @@ public void test57JsonRpcApiTestForEthGetBlockReceipts() throws Exception { logger.info("targetBlockNum: " + targetBlockNum); Assert.assertTrue(trxCount > 1); Assert.assertEquals(trxCount, trxArray.size()); - for(int i = 0; i < trxCount; i++){ + for (int i = 0; i < trxCount; i++) { JSONObject receipt = trxArray.getJSONObject(i); String txId = receipt.getString("transactionHash"); JsonArray param = new JsonArray(); diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/Accounts002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/Accounts002.java index e921ac10..f37c3c30 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/Accounts002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/Accounts002.java @@ -56,7 +56,10 @@ public void beforeClass() { blockingStubFull = WalletGrpc.newBlockingStub(channelFull); } - @Test(enabled = true, description = "Json rpc api of eth_accounts from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_accounts from solidity", + groups = {"daily", "serial"}) public void test01JsonRpcApiTestForEthAccounts() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("eth_accounts", params); @@ -67,7 +70,10 @@ public void test01JsonRpcApiTestForEthAccounts() throws Exception { Assert.assertEquals(responseContent.get("result"), result); } - @Test(enabled = true, description = "Json rpc api of eth_blockNumber from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_blockNumber from solidity", + groups = {"daily", "serial"}) public void test02JsonRpcApiTestForEthBlockNumber() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("eth_blockNumber", params); @@ -85,7 +91,10 @@ public void test02JsonRpcApiTestForEthBlockNumber() throws Exception { Assert.assertTrue(Math.abs(blockNumFromjsonRpcNodeForSolidity - blockNumFromHttp) <= 3); } - @Test(enabled = true, description = "Json rpc api of eth_call from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_call from solidity", + groups = {"daily", "serial"}) public void test03JsonRpcApiTestForEthCall() throws Exception { JsonObject param = new JsonObject(); HttpMethod.waitToProduceOneBlock(httpFullNode); @@ -112,7 +121,10 @@ public void test03JsonRpcApiTestForEthCall() throws Exception { dataResult); } - @Test(enabled = true, description = "Json rpc api of eth_chainId from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_chainId from solidity", + groups = {"daily", "serial"}) public void test04JsonRpcApiTestForEthChainId() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("eth_chainId", params); @@ -129,7 +141,10 @@ public void test04JsonRpcApiTestForEthChainId() throws Exception { Assert.assertEquals(blockIdFromjsonRpcNodeForSolidity, blockIdFromHttp); } - @Test(enabled = true, description = "Json rpc api of eth_coinbase from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_coinbase from solidity", + groups = {"daily", "serial"}) public void test05JsonRpcApiTestForEthCoinbase() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("eth_coinbase", params); @@ -140,7 +155,10 @@ public void test05JsonRpcApiTestForEthCoinbase() throws Exception { "0x410be88a918d74d0dfd71dc84bd4abf036d0562991", responseContent.getString("result")); } - @Test(enabled = true, description = "Json rpc api of eth_estimateGas from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_estimateGas from solidity", + groups = {"daily", "serial"}) public void test06JsonRpcApiTestForEthEstimateGas() throws Exception { JsonObject param = new JsonObject(); param.addProperty("from", ByteArray.toHexString(jsonRpcOwnerAddress)); @@ -148,7 +166,9 @@ public void test06JsonRpcApiTestForEthEstimateGas() throws Exception { param.addProperty("gas", "0x0"); param.addProperty("gasPrice", "0x0"); param.addProperty("value", "0x0"); - paramString = "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000010000000000000000000000000000000"; + paramString = + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000010000000000000000000000000000000"; param.addProperty("data", "0x" + Util.parseMethod("approve(address,uint256)", paramString)); JsonArray params = new JsonArray(); params.add(param); @@ -160,7 +180,7 @@ public void test06JsonRpcApiTestForEthEstimateGas() throws Exception { String dataResult = responseContent.getString("result"); Assert.assertEquals("0x4fd1", dataResult); - //release_4.5.2 to latest version, revert will return instead of failed gas value. + // release_4.5.2 to latest version, revert will return instead of failed gas value. JsonObject wrongParam = new JsonObject(); params.remove(param); wrongParam.addProperty("from", ByteArray.toHexString(jsonRpcOwnerAddress)); @@ -168,18 +188,22 @@ public void test06JsonRpcApiTestForEthEstimateGas() throws Exception { wrongParam.addProperty("gas", "0x0"); wrongParam.addProperty("gasPrice", "0x0"); wrongParam.addProperty("value", "0x0"); - wrongParam.addProperty("data", "0x" + Util.parseMethod("transfer(address,uint256)", paramString)); + wrongParam.addProperty( + "data", "0x" + Util.parseMethod("transfer(address,uint256)", paramString)); params.add(wrongParam); requestBody = getJsonRpcBody("eth_estimateGas", params); response = getJsonRpc(jsonRpcNodeForSolidity, requestBody); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); JSONObject errorResult = responseContent.getJSONObject("error"); - Assert.assertEquals(errorResult.getString("code"),"-32000"); - Assert.assertEquals(errorResult.getString("message"),"REVERT opcode executed"); + Assert.assertEquals(errorResult.getString("code"), "-32000"); + Assert.assertEquals(errorResult.getString("message"), "REVERT opcode executed"); } - @Test(enabled = true, description = "Json rpc api of eth_estimateGasHasPayable", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_estimateGasHasPayable", + groups = {"daily", "serial"}) public void test07JsonRpcApiTestForEthEstimateGasHasPayable() throws Exception { response = HttpMethod.getTransactionInfoByIdFromSolidity(httpsolidityNode, txid); responseContent = HttpMethod.parseResponseContent(response); @@ -202,7 +226,10 @@ public void test07JsonRpcApiTestForEthEstimateGasHasPayable() throws Exception { Assert.assertEquals((long) realEnergyUsed, Long.parseLong(dataResult.substring(2), 16)); } - @Test(enabled = true, description = "Json rpc api of eth_estimateGasWithoutTo from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_estimateGasWithoutTo from solidity", + groups = {"daily", "serial"}) public void test08JsonRpcApiTestForEthEstimateGasWithoutTo() throws Exception { JsonObject param = new JsonObject(); param.addProperty("from", "0x6C0214C9995C6F3A61AB23F0EB84B0CDE7FD9C7C"); @@ -233,7 +260,10 @@ public void test08JsonRpcApiTestForEthEstimateGasWithoutTo() throws Exception { Assert.assertEquals(energyUsed, dataResult); } - @Test(enabled = true, description = "Json rpc api of eth_estimateGasSendTrx from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_estimateGasSendTrx from solidity", + groups = {"daily", "serial"}) public void test09JsonRpcApiTestForEthEstimateGasSendTrx() throws Exception { JsonObject param = new JsonObject(); param.addProperty("from", ByteArray.toHexString(jsonRpcOwnerAddress)); @@ -252,7 +282,10 @@ public void test09JsonRpcApiTestForEthEstimateGasSendTrx() throws Exception { Assert.assertEquals("0x0", dataResult); } - @Test(enabled = true, description = "Json rpc api of eth_gasPrice from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_gasPrice from solidity", + groups = {"daily", "serial"}) public void test10JsonRpcApiTestForEthGasPrice() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("eth_gasPrice", params); @@ -275,7 +308,10 @@ public void test10JsonRpcApiTestForEthGasPrice() throws Exception { Assert.assertEquals(gasPriceFromJsonrpc, gasPriceFromHttp); } - @Test(enabled = true, description = "Json rpc api of eth_getBalance from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getBalance from solidity", + groups = {"daily", "serial"}) public void test11JsonRpcApiTestForEthGetBalance() throws Exception { JsonArray params = new JsonArray(); params.add("0x" + ByteArray.toHexString(foundationAddress).substring(2)); @@ -296,7 +332,8 @@ public void test11JsonRpcApiTestForEthGetBalance() throws Exception { @Test( enabled = true, - description = "Json rpc api of eth_getBlockTransactionCountByNumber from solidity", groups = {"daily", "serial"}) + description = "Json rpc api of eth_getBlockTransactionCountByNumber from solidity", + groups = {"daily", "serial"}) public void test12JsonRpcApiTestForEthGetBlockTransactionCountByNum() throws Exception { response = HttpMethod.getNowBlockFromSolidity(httpsolidityNode); responseContent = HttpMethod.parseResponseContent(response); @@ -315,7 +352,10 @@ public void test12JsonRpcApiTestForEthGetBlockTransactionCountByNum() throws Exc Assert.assertEquals(transactionNum1, transactionNum2); } - @Test(enabled = true, description = "Json rpc api of eth_getCode from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getCode from solidity", + groups = {"daily", "serial"}) public void test13JsonRpcApiTestForEthGetCode() throws Exception { JsonArray params = new JsonArray(); @@ -334,7 +374,10 @@ public void test13JsonRpcApiTestForEthGetCode() throws Exception { Assert.assertEquals(codeFromJsonRpc, codeFromHttp); } - @Test(enabled = true, description = "Json rpc api of eth_getStorageAt from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getStorageAt from solidity", + groups = {"daily", "serial"}) public void test14JsonRpcApiTestForEthGetStorageAt01() throws Exception { JsonArray params = new JsonArray(); @@ -352,7 +395,10 @@ public void test14JsonRpcApiTestForEthGetStorageAt01() throws Exception { Assert.assertEquals("1234", String.valueOf(resultExpect)); } - @Test(enabled = true, description = "Json rpc api of eth_getStorageAt from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getStorageAt from solidity", + groups = {"daily", "serial"}) public void test15JsonRpcApiTestForEthGetStorageAt02() throws Exception { String address = @@ -385,7 +431,8 @@ public void test15JsonRpcApiTestForEthGetStorageAt02() throws Exception { @Test( enabled = true, - description = "Json rpc api of eth_getTransactionByBlockNumberAndIndex from solidity", groups = {"daily", "serial"}) + description = "Json rpc api of eth_getTransactionByBlockNumberAndIndex from solidity", + groups = {"daily", "serial"}) public void test16JsonRpcApiTestForEthGetTransactionByBlockNumberAndIndex() throws Exception { logger.info("16blockNum:" + blockNum); blockNumHex = "0x" + Long.toHexString(blockNum); @@ -502,14 +549,25 @@ public void test16JsonRpcApiTestForEthGetTransactionByBlockNumberAndIndex() thro Assert.assertEquals(jsonrpcResult.get("value").toString(), "0x1389"); String data; - if (getBlockByNumFromSolidityResult.getJSONObject("raw_data").getJSONArray("contract") - .getJSONObject(0).getJSONObject("parameter") - .getJSONObject("value").getString("data") == null) { + if (getBlockByNumFromSolidityResult + .getJSONObject("raw_data") + .getJSONArray("contract") + .getJSONObject(0) + .getJSONObject("parameter") + .getJSONObject("value") + .getString("data") + == null) { data = "0x"; } else { data = - "0x" + getBlockByNumFromSolidityResult.getJSONObject("raw_data").getJSONArray("contract") - .getJSONObject(0).getJSONObject("parameter").getJSONObject("value").getString("data"); + "0x" + + getBlockByNumFromSolidityResult + .getJSONObject("raw_data") + .getJSONArray("contract") + .getJSONObject(0) + .getJSONObject("parameter") + .getJSONObject("value") + .getString("data"); } Assert.assertEquals(jsonrpcResult.get("input").toString(), data); @@ -533,7 +591,8 @@ public void test16JsonRpcApiTestForEthGetTransactionByBlockNumberAndIndex() thro @Test( enabled = true, - description = "Json rpc api of eth_getBlockTransactionCountByHash from solidity", groups = {"daily", "serial"}) + description = "Json rpc api of eth_getBlockTransactionCountByHash from solidity", + groups = {"daily", "serial"}) public void test17JsonRpcApiTestForEthGetBlockTransactionCountByHash() throws Exception { logger.info("blockNum:" + blockNum); JsonArray params = new JsonArray(); @@ -558,7 +617,8 @@ public void test17JsonRpcApiTestForEthGetBlockTransactionCountByHash() throws Ex @Test( enabled = true, - description = "Json rpc api of eth_getBlockTransactionCountByNumber from solidity", groups = {"daily", "serial"}) + description = "Json rpc api of eth_getBlockTransactionCountByNumber from solidity", + groups = {"daily", "serial"}) public void test18JsonRpcApiTestForEthGetBlockTransactionCountByNum() throws Exception { JsonArray params = new JsonArray(); params.add(blockNum); @@ -582,7 +642,8 @@ public void test18JsonRpcApiTestForEthGetBlockTransactionCountByNum() throws Exc @Test( enabled = true, - description = "Json rpc api of eth_getTransactionByBlockHashAndIndex from solidity", groups = {"daily", "serial"}) + description = "Json rpc api of eth_getTransactionByBlockHashAndIndex from solidity", + groups = {"daily", "serial"}) public void test19JsonRpcApiTestForEthGetTransactionByBlockHashAndIndex() throws Exception { JsonArray params = new JsonArray(); params.add("0x" + bid); @@ -595,7 +656,10 @@ public void test19JsonRpcApiTestForEthGetTransactionByBlockHashAndIndex() throws Assert.assertEquals(result, resultForGetTransactionByBlockHashAndIndex); } - @Test(enabled = true, description = "Json rpc api of eth_getTransactionByHash from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getTransactionByHash from solidity", + groups = {"daily", "serial"}) public void test20JsonRpcApiTestForEthGetTransactionByHash() throws Exception { JsonArray params = new JsonArray(); params.add(transacionHash); @@ -606,7 +670,10 @@ public void test20JsonRpcApiTestForEthGetTransactionByHash() throws Exception { Assert.assertEquals(result, result1); } - @Test(enabled = true, description = "Json rpc api of eth_getTransactionReceipt from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getTransactionReceipt from solidity", + groups = {"daily", "serial"}) public void test21JsonRpcApiTestForEthGetTransactionReceipt() throws Exception { JsonArray params = new JsonArray(); Thread.sleep(6000); @@ -725,7 +792,8 @@ public void test21JsonRpcApiTestForEthGetTransactionReceipt() throws Exception { @Test( enabled = true, - description = "Json rpc api of eth_getUncleByBlockHashAndIndex from solidity", groups = {"daily", "serial"}) + description = "Json rpc api of eth_getUncleByBlockHashAndIndex from solidity", + groups = {"daily", "serial"}) public void test22JsonRpcApiTestForEthGetUncleByBlockHashAndIndex() throws Exception { JsonArray params = new JsonArray(); params.add("0x0000000000f9cc56243898cbe88685678855e07f51c5af91322c225ce3693868"); @@ -740,7 +808,8 @@ public void test22JsonRpcApiTestForEthGetUncleByBlockHashAndIndex() throws Excep @Test( enabled = true, - description = "Json rpc api of eth_getUncleByBlockNumberAndIndex from solidity", groups = {"daily", "serial"}) + description = "Json rpc api of eth_getUncleByBlockNumberAndIndex from solidity", + groups = {"daily", "serial"}) public void test23JsonRpcApiTestForEthGetUncleByBlockNumberAndIndex() throws Exception { JsonArray params = new JsonArray(); params.add("0xeb82f0"); @@ -753,7 +822,10 @@ public void test23JsonRpcApiTestForEthGetUncleByBlockNumberAndIndex() throws Exc Assert.assertNull(result); } - @Test(enabled = true, description = "Json rpc api of eth_getUncleCountByBlockHash from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getUncleCountByBlockHash from solidity", + groups = {"daily", "serial"}) public void test24JsonRpcApiTestForEthGetUncleCountByBlockHash() throws Exception { JsonArray params = new JsonArray(); params.add("0x0000000000f9cc56243898cbe88685678855e07f51c5af91322c225ce3693868"); @@ -767,7 +839,8 @@ public void test24JsonRpcApiTestForEthGetUncleCountByBlockHash() throws Exceptio @Test( enabled = true, - description = "Json rpc api of eth_getUncleCountByBlockNumber from solidity", groups = {"daily", "serial"}) + description = "Json rpc api of eth_getUncleCountByBlockNumber from solidity", + groups = {"daily", "serial"}) public void test25JsonRpcApiTestForEthGetUncleCountByBlockNumber() throws Exception { JsonArray params = new JsonArray(); params.add("eth_getUncleCountByBlockNumber"); @@ -779,7 +852,10 @@ public void test25JsonRpcApiTestForEthGetUncleCountByBlockNumber() throws Except Assert.assertEquals(result, "0x0"); } - @Test(enabled = true, description = "Json rpc api of eth_getWork from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getWork from solidity", + groups = {"daily", "serial"}) public void test26JsonRpcApiTestForEthGetWork() throws Exception { String resultFromjsonRpcNodeForSolidity = ""; String resultFromHttp = ""; @@ -804,7 +880,10 @@ public void test26JsonRpcApiTestForEthGetWork() throws Exception { Assert.assertEquals(resultFromjsonRpcNodeForSolidity, resultFromHttp); } - @Test(enabled = true, description = "Json rpc api of eth_hashrate from solidity ", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_hashrate from solidity ", + groups = {"daily", "serial"}) public void test27JsonRpcApiTestForEthHashRate() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("eth_hashrate", params); @@ -815,7 +894,10 @@ public void test27JsonRpcApiTestForEthHashRate() throws Exception { Assert.assertEquals("0x0", result); } - @Test(enabled = true, description = "Json rpc api of eth_mining from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_mining from solidity", + groups = {"daily", "serial"}) public void test28JsonRpcApiTestForEthMining() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("eth_mining", params); @@ -826,7 +908,10 @@ public void test28JsonRpcApiTestForEthMining() throws Exception { Assert.assertEquals(result, "true"); } - @Test(enabled = true, description = "Json rpc api of eth_protocolVersion from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_protocolVersion from solidity", + groups = {"daily", "serial"}) public void test29JsonRpcApiTestForEthProtocolVersion() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("eth_protocolVersion", params); @@ -843,7 +928,10 @@ public void test29JsonRpcApiTestForEthProtocolVersion() throws Exception { Assert.assertEquals(protocolVersion1, protocolVersion2); } - @Test(enabled = true, description = "Json rpc api of eth_syncing from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_syncing from solidity", + groups = {"daily", "serial"}) public void test30JsonRpcApiTestForEthSyncing() throws Exception { long currentNumFromHttp = 0; long currentNumFromJsonRpc = 0; @@ -875,7 +963,10 @@ public void test30JsonRpcApiTestForEthSyncing() throws Exception { Assert.assertTrue(temp.containsKey("highestBlock")); } - @Test(enabled = true, description = "Json rpc api of net_listening from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of net_listening from solidity", + groups = {"daily", "serial"}) public void test31JsonRpcApiTestForNetListening() throws Exception { boolean temp = false; boolean expect = false; @@ -902,7 +993,10 @@ public void test31JsonRpcApiTestForNetListening() throws Exception { Assert.assertEquals(expect, temp); } - @Test(enabled = true, description = "Json rpc api of net_peerCount from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of net_peerCount from solidity", + groups = {"daily", "serial"}) public void test32JsonRpcApiTestForNetPeerCount() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("net_peerCount", params); @@ -913,7 +1007,10 @@ public void test32JsonRpcApiTestForNetPeerCount() throws Exception { Assert.assertNotNull(result); } - @Test(enabled = true, description = "Json rpc api of net_version from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of net_version from solidity", + groups = {"daily", "serial"}) public void test33JsonRpcApiTestForEthVersion() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("net_version", params); @@ -928,7 +1025,10 @@ public void test33JsonRpcApiTestForEthVersion() throws Exception { Assert.assertEquals(firstBlockHashFromJsonRpc, firstBlockHashFromHttp); } - @Test(enabled = true, description = "Json rpc api of web3_clientVersion from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of web3_clientVersion from solidity", + groups = {"daily", "serial"}) public void test34JsonRpcApiTestForWeb3ClientVersion() throws Exception { String javaFullVersion = System.getProperty("java.version"); logger.info("javaFullVersion:" + javaFullVersion); @@ -956,22 +1056,29 @@ public void test34JsonRpcApiTestForWeb3ClientVersion() throws Exception { Assert.assertEquals(resultList.get(3), "Java" + javaVersion); } - @Test(enabled = true, description = "Json rpc api of web3_sha3 from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of web3_sha3 from solidity", + groups = {"daily", "serial"}) public void test35JsonRpcApiTestForWeb3Sha3() throws Exception { JsonArray params = new JsonArray(); params.add("0x08"); - //JsonObject requestBody1 = getJsonRpcBody("web3_sha3", params); - //response = getEthHttps(ethHttpsNode, requestBody1); - //responseContent = HttpMethod.parseResponseContent(response); - //String result1 = responseContent.getString("result"); + // JsonObject requestBody1 = getJsonRpcBody("web3_sha3", params); + // response = getEthHttps(ethHttpsNode, requestBody1); + // responseContent = HttpMethod.parseResponseContent(response); + // String result1 = responseContent.getString("result"); JsonObject requestBody2 = getJsonRpcBody("web3_sha3", params); response = getJsonRpc(jsonRpcNodeForSolidity, requestBody2); responseContent = HttpMethod.parseResponseContent(response); String result2 = responseContent.getString("result"); - Assert.assertEquals("0xd33e25809fcaa2b6900567812852539da8559dc8b76a7ce3fc5ddd77e8d19a69", result2); + Assert.assertEquals( + "0xd33e25809fcaa2b6900567812852539da8559dc8b76a7ce3fc5ddd77e8d19a69", result2); } - @Test(enabled = true, description = "Json rpc api of eth_compileLLL from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_compileLLL from solidity", + groups = {"daily", "serial"}) public void test36JsonRpcApiTestForEthCompileLll() throws Exception { JsonArray params = new JsonArray(); params.add("(returnlll (suicide (caller)))"); @@ -982,7 +1089,10 @@ public void test36JsonRpcApiTestForEthCompileLll() throws Exception { Assert.assertEquals(errorMessage, "the method eth_compileLLL does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of eth_compileSerpent from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_compileSerpent from solidity", + groups = {"daily", "serial"}) public void test37JsonRpcApiTestForEthCompileSerpent() throws Exception { JsonArray params = new JsonArray(); params.add("/* some serpent */"); @@ -994,7 +1104,10 @@ public void test37JsonRpcApiTestForEthCompileSerpent() throws Exception { errorMessage, "the method eth_compileSerpent does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of eth_compileSolidity from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_compileSolidity from solidity", + groups = {"daily", "serial"}) public void test38JsonRpcApiTestForEthCompileSolidity() throws Exception { JsonArray params = new JsonArray(); params.add("contract test { function multiply(uint a) returns(uint d) { return a * 7; } }"); @@ -1006,7 +1119,10 @@ public void test38JsonRpcApiTestForEthCompileSolidity() throws Exception { errorMessage, "the method eth_compileSolidity does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of eth_getCompilers from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getCompilers from solidity", + groups = {"daily", "serial"}) public void test39JsonRpcApiTestForEthCompileSolidity() throws Exception { JsonArray params = new JsonArray(); JsonObject requestBody = getJsonRpcBody("eth_getCompilers", params); @@ -1017,7 +1133,10 @@ public void test39JsonRpcApiTestForEthCompileSolidity() throws Exception { errorMessage, "the method eth_getCompilers does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of eth_getTransactionCount from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getTransactionCount from solidity", + groups = {"daily", "serial"}) public void test40JsonRpcApiTestForEthGetTransactionCount() throws Exception { JsonArray params = new JsonArray(); params.add("0x407d73d8a49eeb85d32cf465507dd71d507100c1"); @@ -1030,7 +1149,10 @@ public void test40JsonRpcApiTestForEthGetTransactionCount() throws Exception { errorMessage, "the method eth_getTransactionCount does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of eth_sendRawTransaction from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_sendRawTransaction from solidity", + groups = {"daily", "serial"}) public void test41JsonRpcApiTestForEthSendRawTransaction() throws Exception { JsonArray params = new JsonArray(); params.add("0x234"); @@ -1042,7 +1164,10 @@ public void test41JsonRpcApiTestForEthSendRawTransaction() throws Exception { errorMessage, "the method eth_sendRawTransaction does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of eth_sendTransaction", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_sendTransaction", + groups = {"daily", "serial"}) public void test42JsonRpcApiTestForEthSendTransaction() throws Exception { JsonArray params = new JsonArray(); JsonObject temp = new JsonObject(); @@ -1064,7 +1189,10 @@ public void test42JsonRpcApiTestForEthSendTransaction() throws Exception { errorMessage, "the method eth_sendTransaction does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of eth_sign from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_sign from solidity", + groups = {"daily", "serial"}) public void test43JsonRpcApiTestForEthSign() throws Exception { JsonArray params = new JsonArray(); params.add("0x9b2055d370f73ec7d8a03e965129118dc8f5bf83"); @@ -1076,7 +1204,10 @@ public void test43JsonRpcApiTestForEthSign() throws Exception { Assert.assertEquals(errorMessage, "the method eth_sign does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of eth_signTransaction from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_signTransaction from solidity", + groups = {"daily", "serial"}) public void test44JsonRpcApiTestForEthSignTransaction() throws Exception { JsonArray params = new JsonArray(); JsonObject temp = new JsonObject(); @@ -1098,7 +1229,10 @@ public void test44JsonRpcApiTestForEthSignTransaction() throws Exception { errorMessage, "the method eth_signTransaction does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of eth_submitWork from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_submitWork from solidity", + groups = {"daily", "serial"}) public void test45JsonRpcApiTestForEthSubmitWork() throws Exception { JsonArray params = new JsonArray(); params.add("0x0000000000000001"); @@ -1111,7 +1245,10 @@ public void test45JsonRpcApiTestForEthSubmitWork() throws Exception { Assert.assertEquals(errorMessage, "the method eth_submitWork does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of parity_nextNonce from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of parity_nextNonce from solidity", + groups = {"daily", "serial"}) public void test46JsonRpcApiTestForParityNextNonce() throws Exception { JsonArray params = new JsonArray(); params.add("0x9b2055d370f73ec7d8a03e965129118dc8f5bf83"); @@ -1123,7 +1260,10 @@ public void test46JsonRpcApiTestForParityNextNonce() throws Exception { errorMessage, "the method parity_nextNonce does not exist/is not available"); } - @Test(enabled = true, description = "Json rpc api of eth_submitHashrate from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_submitHashrate from solidity", + groups = {"daily", "serial"}) public void test47JsonRpcApiTestForEthSubmitHashrate() throws Exception { JsonArray params = new JsonArray(); params.add("0x0000000000000000000000000000000000000000000000000000000000500000"); @@ -1138,7 +1278,8 @@ public void test47JsonRpcApiTestForEthSubmitHashrate() throws Exception { @Test( enabled = true, - description = "Json rpc api of eth_getBlockByHash params is false from solidity", groups = {"daily", "serial"}) + description = "Json rpc api of eth_getBlockByHash params is false from solidity", + groups = {"daily", "serial"}) public void test48JsonRpcApiTestForEthGetBlockByHash() throws Exception { response = HttpMethod.getBlockByNumFromSolidity(httpsolidityNode, blockNum); responseContent = HttpMethod.parseResponseContent(response); @@ -1215,7 +1356,8 @@ public void test48JsonRpcApiTestForEthGetBlockByHash() throws Exception { @Test( enabled = true, - description = "Json rpc api of eth_getBlockByNumFromSolidityber params is true from solidity", groups = {"daily", "serial"}) + description = "Json rpc api of eth_getBlockByNumFromSolidityber params is true from solidity", + groups = {"daily", "serial"}) public void test49JsonRpcApiTestForEthgetBlockByNumFromSolidityber() throws Exception { JsonArray params = new JsonArray(); @@ -1312,7 +1454,8 @@ public void test49JsonRpcApiTestForEthgetBlockByNumFromSolidityber() throws Exce @Test( enabled = true, description = - "Json rpc api of eth_call,eth_estimateGas and eth_getTransactionByBlockHashAndIndex.", groups = {"daily", "serial"}) + "Json rpc api of eth_call,eth_estimateGas and eth_getTransactionByBlockHashAndIndex.", + groups = {"daily", "serial"}) public void test50JsonRpcApiTestForInterfaceCombination() throws Exception { final JsonArray jsonArrayParams = new JsonArray(); JsonObject param = new JsonObject(); @@ -1376,7 +1519,9 @@ public void test50JsonRpcApiTestForInterfaceCombination() throws Exception { } @Test( - enabled = true, description = "Json rpc api of eth_call with blockNumber", groups = {"daily", "serial"}) + enabled = true, + description = "Json rpc api of eth_call with blockNumber", + groups = {"daily", "serial"}) public void test51JsonRpcApiTestForEthCallWithBlockNumber() throws Exception { final JsonArray jsonArrayParams = new JsonArray(); JsonObject param = new JsonObject(); @@ -1390,7 +1535,7 @@ public void test51JsonRpcApiTestForEthCallWithBlockNumber() throws Exception { JsonArray params = new JsonArray(); params.add(param); JsonObject blockNumAndHash = new JsonObject(); - blockNumAndHash.addProperty("blockNumber",String.valueOf(blockNum)); + blockNumAndHash.addProperty("blockNumber", String.valueOf(blockNum)); params.add(blockNumAndHash); final JsonObject requestBody = getJsonRpcBody("eth_call", params); JsonObject param1 = new JsonObject(); @@ -1441,9 +1586,10 @@ public void test51JsonRpcApiTestForEthCallWithBlockNumber() throws Exception { Assert.assertEquals(result, resultForGetTransactionByBlockHashAndIndex); } - @Test( - enabled = true, description = "Json rpc api of eth_call with blockHash", groups = {"daily", "serial"}) + enabled = true, + description = "Json rpc api of eth_call with blockHash", + groups = {"daily", "serial"}) public void test52JsonRpcApiTestForEthCallWithBlockHash() throws Exception { final JsonArray jsonArrayParams = new JsonArray(); JsonObject param = new JsonObject(); @@ -1457,7 +1603,7 @@ public void test52JsonRpcApiTestForEthCallWithBlockHash() throws Exception { JsonArray params = new JsonArray(); params.add(param); JsonObject blockNumAndHash = new JsonObject(); - blockNumAndHash.addProperty("blockHash",blockHash); + blockNumAndHash.addProperty("blockHash", blockHash); params.add(blockNumAndHash); final JsonObject requestBody = getJsonRpcBody("eth_call", params); JsonObject param1 = new JsonObject(); diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/Accounts003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/Accounts003.java index 447f1c6b..b7d4010d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/Accounts003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/Accounts003.java @@ -22,7 +22,10 @@ public class Accounts003 extends JsonRpcBase { String newFilterResultIdfrom02 = null; String blockHash = null; - @Test(enabled = true, description = "Eth api of eth_newFilter contains nothing.", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Eth api of eth_newFilter contains nothing.", + groups = {"daily", "serial"}) public void test01GetNewFilterContainNothing() { JsonObject paramBody = new JsonObject(); JsonArray params = new JsonArray(); @@ -38,7 +41,8 @@ public void test01GetNewFilterContainNothing() { @Test( enabled = true, - description = "Eth api of eth_newFilter contains address,fromBlock and toBlock.", groups = {"daily", "serial"}) + description = "Eth api of eth_newFilter contains address,fromBlock and toBlock.", + groups = {"daily", "serial"}) public void test02GetNewFilterContainAddress() { if (blockNumForTrc20 - 10 < 0) { fromBlock = "0"; @@ -65,7 +69,8 @@ public void test02GetNewFilterContainAddress() { @Test( enabled = true, - description = "Eth api of eth_newFilter contains topic fromBlock and toBlock.", groups = {"daily", "serial"}) + description = "Eth api of eth_newFilter contains topic fromBlock and toBlock.", + groups = {"daily", "serial"}) public void test03GetNewFilterContainTopic() { response = HttpMethod.getBlockByNum(httpFullNode, blockNumForTrc20); responseContent = HttpMethod.parseResponseContent(response); @@ -91,7 +96,10 @@ public void test03GetNewFilterContainTopic() { logger.info("test03GetNewFilterContainTopic_id:" + newFilterResultIdfrom02); } - @Test(enabled = true, description = "Eth api of eth_newFilter contains topic and address.", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Eth api of eth_newFilter contains topic and address.", + groups = {"daily", "serial"}) public void test04GetNewFilterContainsTopicAndAddress() { JsonArray addressArray = new JsonArray(); @@ -113,7 +121,10 @@ public void test04GetNewFilterContainsTopicAndAddress() { Assert.assertNotNull(responseContent.getString("result")); } - @Test(enabled = true, description = "Eth api of eth_newFilter only contain topic and blockHash.", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Eth api of eth_newFilter only contain topic and blockHash.", + groups = {"daily", "serial"}) public void test05GetNewFilterOnlyContainTopic() { JsonObject paramBody = new JsonObject(); paramBody.addProperty("blockHash", blockHash); @@ -130,7 +141,10 @@ public void test05GetNewFilterOnlyContainTopic() { Assert.assertNotNull(responseContent.getString("result")); } - @Test(enabled = true, description = "Eth api of eth_newFilter which only contains blockHash.", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Eth api of eth_newFilter which only contains blockHash.", + groups = {"daily", "serial"}) public void test06GetNewFilterHasOnlyBlockHash() { response = HttpMethod.getNowBlock(httpFullNode); @@ -148,7 +162,10 @@ public void test06GetNewFilterHasOnlyBlockHash() { Assert.assertNotNull(responseContent.getString("result")); } - @Test(enabled = true, description = "Eth api of eth_newFilter check new and after block.", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Eth api of eth_newFilter check new and after block.", + groups = {"daily", "serial"}) public void test07GetNewFilterCheckNewBlock() { JsonObject paramBody = new JsonObject(); JsonArray topicArray = new JsonArray(); @@ -164,7 +181,10 @@ public void test07GetNewFilterCheckNewBlock() { Assert.assertNotNull(responseContent.getString("result")); } - @Test(enabled = true, description = "Eth api of eth_newBlockFilter", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Eth api of eth_newBlockFilter", + groups = {"daily", "serial"}) public void test08GetEthNewBlockFilter() { JsonArray params = new JsonArray(); @@ -176,7 +196,10 @@ public void test08GetEthNewBlockFilter() { Assert.assertNotNull(responseContent.getString("result")); } - @Test(enabled = true, description = "Eth api of eth_getFilterChanges has less 20 elements.", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Eth api of eth_getFilterChanges has less 20 elements.", + groups = {"daily", "serial"}) public void test09GetFilterChanges() { JsonArray params = new JsonArray(); @@ -201,7 +224,8 @@ public void test09GetFilterChanges() { @Test( enabled = true, - description = "Eth api of eth_getLogs contains address ,fromBlock and toBlock.", groups = {"daily", "serial"}) + description = "Eth api of eth_getLogs contains address ,fromBlock and toBlock.", + groups = {"daily", "serial"}) public void test10GetLogsOnlyContainAddress() { JsonArray addressArray = new JsonArray(); logger.info("contractTrc20AddressFrom58:" + contractTrc20AddressFrom58); @@ -225,7 +249,10 @@ public void test10GetLogsOnlyContainAddress() { topic0 = responseContent.getJSONArray("result").getJSONObject(0).getString("topic"); } - @Test(enabled = true, description = "Eth api of eth_getLogs both contains topic and address.", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Eth api of eth_getLogs both contains topic and address.", + groups = {"daily", "serial"}) public void test11GetLogsContainsTopicAndAddress() { JsonArray topicArray = new JsonArray(); topicArray.add(topic0); @@ -246,7 +273,10 @@ public void test11GetLogsContainsTopicAndAddress() { Assert.assertEquals(topicFromResult, topic0); } - @Test(enabled = true, description = "Eth api of eth_getFilterLogs .", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Eth api of eth_getFilterLogs .", + groups = {"daily", "serial"}) public void test12GetFilterLogsContainsAddress() { JsonArray params = new JsonArray(); @@ -259,7 +289,10 @@ public void test12GetFilterLogsContainsAddress() { Assert.assertNotNull(responseContent.getString("result")); } - @Test(enabled = true, description = "Eth api of eth_getFilterLogs .", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Eth api of eth_getFilterLogs .", + groups = {"daily", "serial"}) public void test13GetFilterLogsContainsTopic() { JsonArray params = new JsonArray(); @@ -276,7 +309,8 @@ public void test13GetFilterLogsContainsTopic() { enabled = true, description = "Eth api of eth_uninstallFilter which method is eth_newFilter" - + " and params has one element ", groups = {"daily", "serial"}) + + " and params has one element ", + groups = {"daily", "serial"}) public void test14EthUninstallFilter() { // create ID JsonArray addressArray = new JsonArray(); @@ -330,7 +364,8 @@ public void test14EthUninstallFilter() { enabled = true, description = "Eth api of eth_uninstallFilter which method is eth_newBlockFilter" - + " and params has one element ", groups = {"daily", "serial"}) + + " and params has one element ", + groups = {"daily", "serial"}) public void test15EthUninstallFilter() { // create ID diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/Accounts004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/Accounts004.java index c09c2f4e..bdcd8a48 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/Accounts004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/Accounts004.java @@ -22,7 +22,10 @@ public class Accounts004 extends JsonRpcBase { String newFilterResultIdfrom02 = null; String blockHash = null; - @Test(enabled = true, description = "Eth api of eth_newFilter contains nothing from solidity.", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Eth api of eth_newFilter contains nothing from solidity.", + groups = {"daily", "serial"}) public void test01GetNewFilterContainNothing() { JsonObject paramBody = new JsonObject(); JsonArray params = new JsonArray(); @@ -39,7 +42,8 @@ public void test01GetNewFilterContainNothing() { @Test( enabled = true, description = - "Eth api of eth_newFilter contains address,fromBlock and toBlock from solidity.", groups = {"daily", "serial"}) + "Eth api of eth_newFilter contains address,fromBlock and toBlock from solidity.", + groups = {"daily", "serial"}) public void test02GetNewFilterContainAddress() { if (blockNumForTrc20 - 10 < 0) { fromBlock = "0"; @@ -66,7 +70,8 @@ public void test02GetNewFilterContainAddress() { @Test( enabled = true, - description = "Eth api of eth_newFilter contains topic fromBlock and toBlock from solidity.", groups = {"daily", "serial"}) + description = "Eth api of eth_newFilter contains topic fromBlock and toBlock from solidity.", + groups = {"daily", "serial"}) public void test03GetNewFilterContainTopic() { response = HttpMethod.getBlockByNumFromSolidity(httpsolidityNode, blockNumForTrc20); responseContent = HttpMethod.parseResponseContent(response); @@ -93,7 +98,8 @@ public void test03GetNewFilterContainTopic() { @Test( enabled = true, - description = "Eth api of eth_newFilter contains topic and address from solidity.", groups = {"daily", "serial"}) + description = "Eth api of eth_newFilter contains topic and address from solidity.", + groups = {"daily", "serial"}) public void test04GetNewFilterContainsTopicAndAddress() { JsonArray addressArray = new JsonArray(); @@ -117,7 +123,8 @@ public void test04GetNewFilterContainsTopicAndAddress() { @Test( enabled = true, - description = "Eth api of eth_newFilter only contain topic and blockHash from solidity.", groups = {"daily", "serial"}) + description = "Eth api of eth_newFilter only contain topic and blockHash from solidity.", + groups = {"daily", "serial"}) public void test05GetNewFilterOnlyContainTopic() throws InterruptedException { JsonObject paramBody = new JsonObject(); paramBody.addProperty("blockHash", blockHash); @@ -136,7 +143,8 @@ public void test05GetNewFilterOnlyContainTopic() throws InterruptedException { @Test( enabled = true, - description = "Eth api of eth_newFilter which only contains blockHash from solidity.", groups = {"daily", "serial"}) + description = "Eth api of eth_newFilter which only contains blockHash from solidity.", + groups = {"daily", "serial"}) public void test06GetNewFilterHasOnlyBlockHash() throws InterruptedException { response = HttpMethod.getNowBlockFromSolidity(httpsolidityNode); responseContent = HttpMethod.parseResponseContent(response); @@ -156,7 +164,8 @@ public void test06GetNewFilterHasOnlyBlockHash() throws InterruptedException { @Test( enabled = true, - description = "Eth api of eth_newFilter check new and after block from solidity.", groups = {"daily", "serial"}) + description = "Eth api of eth_newFilter check new and after block from solidity.", + groups = {"daily", "serial"}) public void test07GetNewFilterCheckNewBlock() { JsonObject paramBody = new JsonObject(); JsonArray topicArray = new JsonArray(); @@ -172,7 +181,10 @@ public void test07GetNewFilterCheckNewBlock() { Assert.assertNotNull(responseContent.getString("result")); } - @Test(enabled = true, description = "Eth api of eth_newBlockFilter from solidity", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Eth api of eth_newBlockFilter from solidity", + groups = {"daily", "serial"}) public void test08GetEthNewBlockFilter() { JsonArray params = new JsonArray(); @@ -186,7 +198,8 @@ public void test08GetEthNewBlockFilter() { @Test( enabled = true, - description = "Eth api of eth_getFilterChanges has less 20 elements from solidity.", groups = {"daily", "serial"}) + description = "Eth api of eth_getFilterChanges has less 20 elements from solidity.", + groups = {"daily", "serial"}) public void test09GetFilterChanges() { JsonArray params = new JsonArray(); @@ -212,7 +225,8 @@ public void test09GetFilterChanges() { @Test( enabled = true, description = - "Eth api of eth_getLogs contains address ,fromBlock and toBlock from solidity.", groups = {"daily", "serial"}) + "Eth api of eth_getLogs contains address ,fromBlock and toBlock from solidity.", + groups = {"daily", "serial"}) public void test10GetLogsOnlyContainAddress() { JsonArray addressArray = new JsonArray(); logger.info("contractTrc20AddressFrom58:" + contractTrc20AddressFrom58); @@ -239,7 +253,8 @@ public void test10GetLogsOnlyContainAddress() { @Test( enabled = true, - description = "Eth api of eth_getLogs both contains topic and address from solidity.", groups = {"daily", "serial"}) + description = "Eth api of eth_getLogs both contains topic and address from solidity.", + groups = {"daily", "serial"}) public void test11GetLogsContainsTopicAndAddress() { JsonArray topicArray = new JsonArray(); topicArray.add(topic0); @@ -261,7 +276,10 @@ public void test11GetLogsContainsTopicAndAddress() { Assert.assertEquals(topicFromResult, topic0); } - @Test(enabled = true, description = "Eth api of eth_getFilterLogs from solidity.", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Eth api of eth_getFilterLogs from solidity.", + groups = {"daily", "serial"}) public void test12GetFilterLogsContainsAddress() { JsonArray params = new JsonArray(); @@ -274,7 +292,10 @@ public void test12GetFilterLogsContainsAddress() { Assert.assertNotNull(responseContent.getString("result")); } - @Test(enabled = true, description = "Eth api of eth_getFilterLogs from solidity.", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Eth api of eth_getFilterLogs from solidity.", + groups = {"daily", "serial"}) public void test13GetFilterLogsContainsTopic() { JsonArray params = new JsonArray(); @@ -291,7 +312,8 @@ public void test13GetFilterLogsContainsTopic() { enabled = true, description = "Eth api of eth_uninstallFilter which method is eth_newFilter from solidity" - + " and params has one element ", groups = {"daily", "serial"}) + + " and params has one element ", + groups = {"daily", "serial"}) public void test14EthUninstallFilter() { // create ID JsonArray addressArray = new JsonArray(); @@ -345,7 +367,8 @@ public void test14EthUninstallFilter() { enabled = true, description = "Eth api of eth_uninstallFilter which method is eth_newBlockFilter" - + " and params has one element from solidity", groups = {"daily", "serial"}) + + " and params has one element from solidity", + groups = {"daily", "serial"}) public void test15EthUninstallFilter() { // create ID diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/BuildTransaction001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/BuildTransaction001.java index 5c8b43a5..630e8852 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/BuildTransaction001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/BuildTransaction001.java @@ -21,13 +21,11 @@ import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.Utils; - @Slf4j - public class BuildTransaction001 extends JsonRpcBase { JSONArray jsonRpcReceives = new JSONArray(); - //String txid; + // String txid; private JSONObject responseContent; private HttpResponse response; String transactionString; @@ -37,51 +35,50 @@ public class BuildTransaction001 extends JsonRpcBase { byte[] receiverAddress = ecKey1.getAddress(); final String receiverKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext() - .build(); + channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); blockingStubFull = WalletGrpc.newBlockingStub(channelFull); } - - - @Test(enabled = true, description = "Json rpc api of buildTransaction for transfer trx", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of buildTransaction for transfer trx", + groups = {"daily", "serial"}) public void test01JsonRpcApiTestOfBuildTransactionForTransferTrx() throws Exception { final Long beforeRecevierBalance = HttpMethod.getBalance(httpFullNode, receiverAddress); - JsonObject param = new JsonObject(); param.addProperty("from", ByteArray.toHexString(jsonRpcOwnerAddress)); param.addProperty("to", ByteArray.toHexString(receiverAddress)); param.addProperty("value", "0x1"); JsonArray params = new JsonArray(); params.add(param); - JsonObject requestBody = getJsonRpcBody("buildTransaction",params); + JsonObject requestBody = getJsonRpcBody("buildTransaction", params); response = getJsonRpc(jsonRpcNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); transactionString = responseContent.getJSONObject("result").getString("transaction"); - transactionSignString = HttpMethod.gettransactionsign(httpFullNode, transactionString, - jsonRpcOwnerKey); + transactionSignString = + HttpMethod.gettransactionsign(httpFullNode, transactionString, jsonRpcOwnerKey); response = HttpMethod.broadcastTransaction(httpFullNode, transactionSignString); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpFullNode); Long afterRecevierBalance = HttpMethod.getBalance(httpFullNode, receiverAddress); - Assert.assertEquals(afterRecevierBalance - beforeRecevierBalance,1L); - + Assert.assertEquals(afterRecevierBalance - beforeRecevierBalance, 1L); } - @Test(enabled = true, description = "Json rpc api of buildTransaction for transfer trc10", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of buildTransaction for transfer trc10", + groups = {"daily", "serial"}) public void test02JsonRpcApiTestOfBuildTransactionForTransferTrc10() throws Exception { PublicMethod.waitProduceNextBlock(blockingStubFull); - final Long beforeTokenBalance = PublicMethod.getAssetBalanceByAssetId(ByteString - .copyFromUtf8(jsonRpcAssetId), receiverKey, blockingStubFull); + final Long beforeTokenBalance = + PublicMethod.getAssetBalanceByAssetId( + ByteString.copyFromUtf8(jsonRpcAssetId), receiverKey, blockingStubFull); JsonObject param = new JsonObject(); param.addProperty("from", ByteArray.toHexString(jsonRpcOwnerAddress)); param.addProperty("to", ByteArray.toHexString(receiverAddress)); @@ -89,32 +86,28 @@ public void test02JsonRpcApiTestOfBuildTransactionForTransferTrc10() throws Exce param.addProperty("tokenValue", 1); JsonArray params = new JsonArray(); params.add(param); - JsonObject requestBody = getJsonRpcBody("buildTransaction",params); + JsonObject requestBody = getJsonRpcBody("buildTransaction", params); response = getJsonRpc(jsonRpcNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); transactionString = responseContent.getJSONObject("result").getString("transaction"); - transactionSignString = HttpMethod.gettransactionsign(httpFullNode, transactionString, - jsonRpcOwnerKey); + transactionSignString = + HttpMethod.gettransactionsign(httpFullNode, transactionString, jsonRpcOwnerKey); response = HttpMethod.broadcastTransaction(httpFullNode, transactionSignString); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpFullNode); - Long afterTokenBalance = PublicMethod.getAssetBalanceByAssetId(ByteString - .copyFromUtf8(jsonRpcAssetId), receiverKey, blockingStubFull); - - Assert.assertEquals(afterTokenBalance - beforeTokenBalance,1L); + Long afterTokenBalance = + PublicMethod.getAssetBalanceByAssetId( + ByteString.copyFromUtf8(jsonRpcAssetId), receiverKey, blockingStubFull); + Assert.assertEquals(afterTokenBalance - beforeTokenBalance, 1L); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { if (channelFull != null) { channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/EthSmartContract001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/EthSmartContract001.java index 729e2d63..00fce0a8 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/EthSmartContract001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/EthSmartContract001.java @@ -11,14 +11,15 @@ import stest.tron.wallet.common.client.utils.HttpMethod; import stest.tron.wallet.common.client.utils.JsonRpcBase; - @Slf4j - public class EthSmartContract001 extends JsonRpcBase { private JSONObject responseContent; private HttpResponse response; - @Test(enabled = true, description = "Json rpc api of eth_call", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_call", + groups = {"daily", "serial"}) public void test01JsonRpcApiTestForEthCall() throws Exception { JsonObject param = new JsonObject(); param.addProperty("from", ByteArray.toHexString(jsonRpcOwnerAddress)); @@ -30,26 +31,30 @@ public void test01JsonRpcApiTestForEthCall() throws Exception { JsonArray params = new JsonArray(); params.add(param); params.add("latest"); - JsonObject requestBody = getJsonRpcBody("eth_call",params); + JsonObject requestBody = getJsonRpcBody("eth_call", params); response = getJsonRpc(jsonRpcNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); String dataResult = responseContent.getString("result"); - Assert.assertEquals(dataResult,"0x000000000000000000000000000000000000000000000000000" - + "0000000000020000000000000000000000000000000000000000000000000000000000000000a546f6b65" - + "6e545243323000000000000000000000000000000000000000000000"); + Assert.assertEquals( + dataResult, + "0x000000000000000000000000000000000000000000000000000" + + "0000000000020000000000000000000000000000000000000000000000000000000000000000a546f6b6" + + "5" + + "6e545243323000000000000000000000000000000000000000000000"); } - - @Test(enabled = true, description = "Json rpc api of eth_getCode", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getCode", + groups = {"daily", "serial"}) public void test02JsonRpcApiTestForEthGetCode() throws Exception { JsonArray params = new JsonArray(); params.add(trc20AddressHex); params.add("latest"); - JsonObject requestBody = getJsonRpcBody("eth_getCode",params); + JsonObject requestBody = getJsonRpcBody("eth_getCode", params); response = getJsonRpc(jsonRpcNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); String dataResult = responseContent.getString("result"); Assert.assertTrue(dataResult.length() > 1000L); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/GetBlock001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/GetBlock001.java index d807affc..fdd1db7f 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/GetBlock001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/GetBlock001.java @@ -12,58 +12,47 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.WalletGrpc; - import stest.tron.wallet.common.client.utils.HttpMethod; import stest.tron.wallet.common.client.utils.JsonRpcBase; - @Slf4j - public class GetBlock001 extends JsonRpcBase { private JSONObject responseContent; private HttpResponse response; - - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext() - .build(); + channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); blockingStubFull = WalletGrpc.newBlockingStub(channelFull); } - - - - @Test(enabled = true, description = "Json rpc api of eth_getBlockByHash", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Json rpc api of eth_getBlockByHash", + groups = {"daily", "serial"}) public void test01JsonRpcApiTestForEthGetBlockByHash() throws Exception { JsonArray params = new JsonArray(); params.add(blockId); params.add("true"); - JsonObject requestBody = getJsonRpcBody("eth_getBlockByHash",params); + JsonObject requestBody = getJsonRpcBody("eth_getBlockByHash", params); response = getJsonRpc(jsonRpcNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); - Assert.assertEquals(Long.toHexString(blockNum), responseContent.getJSONObject("result") - .getString("number").substring(2)); - Assert.assertEquals(blockId, responseContent.getJSONObject("result").getString("hash") - .substring(2)); - Assert.assertTrue(responseContent.getJSONObject("result") - .getJSONArray("transactions").size() >= 1); + Assert.assertEquals( + Long.toHexString(blockNum), + responseContent.getJSONObject("result").getString("number").substring(2)); + Assert.assertEquals( + blockId, responseContent.getJSONObject("result").getString("hash").substring(2)); + Assert.assertTrue( + responseContent.getJSONObject("result").getJSONArray("transactions").size() >= 1); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { if (channelFull != null) { channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/MultiGetFilterChange.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/MultiGetFilterChange.java index f73c8099..edb4a05b 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/MultiGetFilterChange.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/MultiGetFilterChange.java @@ -5,7 +5,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import java.nio.charset.Charset; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; @@ -15,7 +14,6 @@ import org.apache.http.impl.conn.PoolingClientConnectionManager; import org.apache.http.params.CoreConnectionPNames; import org.eclipse.jetty.util.ConcurrentHashSet; -import org.junit.Assert; import org.testng.annotations.Test; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.HttpMethod; @@ -25,29 +23,33 @@ public class MultiGetFilterChange { AtomicInteger atomicInteger = new AtomicInteger(0); ConcurrentHashSet concurrentHashSet = new ConcurrentHashSet(); String[] topicsArray = { - "0x21f80ad16517f8cc77e4eada2d83f2b2", - "0x21800cfb29623d7a93d03eec6bd38036", - "0xca52b1edad238bf6e0efcc017e82698c", - "0xc4e9b7615e37a055d8c033921a2a875b", - "0x6c86e7a89f0fde45c330133fa5d6057c" + "0x21f80ad16517f8cc77e4eada2d83f2b2", + "0x21800cfb29623d7a93d03eec6bd38036", + "0xca52b1edad238bf6e0efcc017e82698c", + "0xc4e9b7615e37a055d8c033921a2a875b", + "0x6c86e7a89f0fde45c330133fa5d6057c" }; - @Test(enabled = false, threadPoolSize = 7, invocationCount = 7, groups = {"daily", "serial"}) + @Test( + enabled = false, + threadPoolSize = 7, + invocationCount = 7, + groups = {"daily", "serial"}) public void test01MutiForEthGetFilterChange() throws Exception { - System.out.println(Thread.currentThread().getName().substring(Thread.currentThread().getName().length()-1)); - + System.out.println( + Thread.currentThread().getName().substring(Thread.currentThread().getName().length() - 1)); JsonArray param = new JsonArray(); - //param.add(topicsArray[Integer.valueOf(Thread.currentThread().getName().substring(Thread.currentThread().getName().length()-1))-1]); + // param.add(topicsArray[Integer.valueOf( + // Thread.currentThread().getName().substring( + // Thread.currentThread().getName().length()-1))-1]); param.add("0x609785f327ea981fa6e3c8cb1f8472f2"); System.out.println(param.toString()); JsonArray params = new JsonArray(); params.addAll(param); JsonObject requestBody = JsonRpcBase.getJsonRpcBody("eth_getFilterChanges", params); - - Integer total = 0; while (true) { HttpResponse response = getJsonRpc("39.106.110.245:50545", requestBody); @@ -55,15 +57,16 @@ public void test01MutiForEthGetFilterChange() throws Exception { try { JSONArray jsonArray = responseContent.getJSONArray("result"); - if(jsonArray.size() != 0 ) { - for(int i = 0; i < jsonArray.size();i++) { - if(concurrentHashSet.contains(jsonArray.getJSONObject(i).getString("transactionHash"))) { - System.out.println(jsonArray.getJSONObject(i).getString("transactionHash") + " is wrong"); + if (jsonArray.size() != 0) { + for (int i = 0; i < jsonArray.size(); i++) { + if (concurrentHashSet.contains( + jsonArray.getJSONObject(i).getString("transactionHash"))) { + System.out.println( + jsonArray.getJSONObject(i).getString("transactionHash") + " is wrong"); System.exit(1); } concurrentHashSet.add(jsonArray.getJSONObject(i).getString("transactionHash")); - } System.out.println(atomicInteger.addAndGet(jsonArray.size())); } @@ -72,14 +75,12 @@ public void test01MutiForEthGetFilterChange() throws Exception { HttpMethod.printJsonContent(responseContent); System.out.println("query failed"); } - } - - } - - @Test(enabled = false, groups = {"daily", "serial"}) + @Test( + enabled = false, + groups = {"daily", "serial"}) public void test02MutiForCreateTopic() throws Exception { MyThread event1 = new MyThread("0xc1212face8030981dba8c87177346bcc"); MyThread event2 = new MyThread("0xf82da7256633956a39e9e83bab6409b0"); @@ -100,34 +101,35 @@ public void test02MutiForCreateTopic() throws Exception { t5.start(); } - class MyThread implements Runnable{ - private String topics ; - public MyThread(String topics){ - this.topics = topics ; - } - public void run(){ - - JsonArray param = new JsonArray(); - param.add(this.topics); - System.out.println("topics:" + topics); - - JsonArray params = new JsonArray(); - params.addAll(param); - JsonObject requestBody = JsonRpcBase.getJsonRpcBody("eth_getFilterChanges", params); - - while (true) { - HttpResponse response = getJsonRpc("39.106.110.245:50545", requestBody); - JSONObject responseContent = HttpMethod.parseResponseContent(response); - try { - Integer current = responseContent.getJSONArray("result").size(); - System.out.println("current total Query Num :" + atomicInteger.addAndGet(current)); - } catch (Exception e) { - System.out.println("query failed"); - } + class MyThread implements Runnable { + private String topics; + + public MyThread(String topics) { + this.topics = topics; + } + + public void run() { + JsonArray param = new JsonArray(); + param.add(this.topics); + System.out.println("topics:" + topics); + + JsonArray params = new JsonArray(); + params.addAll(param); + JsonObject requestBody = JsonRpcBase.getJsonRpcBody("eth_getFilterChanges", params); + + while (true) { + HttpResponse response = getJsonRpc("39.106.110.245:50545", requestBody); + JSONObject responseContent = HttpMethod.parseResponseContent(response); + try { + Integer current = responseContent.getJSONArray("result").size(); + System.out.println("current total Query Num :" + atomicInteger.addAndGet(current)); + } catch (Exception e) { + System.out.println("query failed"); } - } - }; + } + } + } public static HttpResponse getJsonRpc(String jsonRpcNode, JsonObject jsonRpcObject) { try { @@ -136,18 +138,15 @@ public static HttpResponse getJsonRpc(String jsonRpcNode, JsonObject jsonRpcObje return response; } catch (Exception e) { e.printStackTrace(); - //httppost.releaseConnection(); + // httppost.releaseConnection(); return null; } - } - - static Integer connectionTimeout = Configuration.getByPath("testng.conf") - .getInt("defaultParameter.httpConnectionTimeout"); - static Integer soTimeout = Configuration.getByPath("testng.conf") - .getInt("defaultParameter.httpSoTimeout"); - + static Integer connectionTimeout = + Configuration.getByPath("testng.conf").getInt("defaultParameter.httpConnectionTimeout"); + static Integer soTimeout = + Configuration.getByPath("testng.conf").getInt("defaultParameter.httpSoTimeout"); public static HttpResponse createConnect(String url, JsonObject requestBody) { HttpClient httpClient; @@ -160,7 +159,8 @@ public static HttpResponse createConnect(String url, JsonObject requestBody) { try { HttpPost httppost; - httpClient.getParams() + httpClient + .getParams() .setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, soTimeout); httppost = new HttpPost(url); @@ -177,12 +177,8 @@ public static HttpResponse createConnect(String url, JsonObject requestBody) { return response; } catch (Exception e) { e.printStackTrace(); - //httppost.releaseConnection(); + // httppost.releaseConnection(); return null; } - } - - - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/StateTree001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/StateTree001.java index 67ed76f3..65eed00e 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/StateTree001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/StateTree001.java @@ -4,9 +4,7 @@ import com.alibaba.fastjson.JSONObject; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import com.google.protobuf.ByteString; import io.grpc.ManagedChannelBuilder; -import java.nio.charset.StandardCharsets; import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; @@ -14,13 +12,11 @@ import org.testng.SkipException; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; -import org.testng.annotations.Ignore; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.EmptyMessage; import org.tron.api.WalletGrpc; import org.tron.protos.Protocol.Transaction.Result.contractResult; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.HttpMethod; @@ -28,7 +24,6 @@ import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.Utils; - @Slf4j public class StateTree001 extends JsonRpcBase { private JSONObject responseContent; @@ -38,53 +33,62 @@ public class StateTree001 extends JsonRpcBase { byte[] getBalanceTestAddress = getBalanceECKey.getAddress(); String getBalanceTestKey = ByteArray.toHexString(getBalanceECKey.getPrivKeyBytes()); - private final String foundationKey001 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); + private final String foundationKey001 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key1"); private final Long sendAmount = 20000000L; private final Long transferAmount = 2L; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - if(!stateRootIsOpen()) { + if (!stateRootIsOpen()) { throw new SkipException("Skipping this state root test case"); } - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext() - .build(); + channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); blockingStubFull = WalletGrpc.newBlockingStub(channelFull); PublicMethod.printAddress(getBalanceTestKey); } - - - - @Test(enabled = true, description = "State tree with eth_getBalance", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "State tree with eth_getBalance", + groups = {"daily", "serial"}) public void test01StateTreeWithEthGetBalance() throws Exception { - PublicMethod.sendcoin(getBalanceTestAddress,sendAmount, - PublicMethod.getFinalAddress(foundationKey001),foundationKey001, blockingStubFull); + PublicMethod.sendcoin( + getBalanceTestAddress, + sendAmount, + PublicMethod.getFinalAddress(foundationKey001), + foundationKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); final Long beforeBalance = sendAmount; - final Long beforeBlockNumber = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + final Long beforeBlockNumber = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.sendcoin(PublicMethod.getFinalAddress(foundationKey001),transferAmount, - getBalanceTestAddress,getBalanceTestKey, blockingStubFull); + PublicMethod.sendcoin( + PublicMethod.getFinalAddress(foundationKey001), + transferAmount, + getBalanceTestAddress, + getBalanceTestKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - final Long afterBalance = PublicMethod.queryAccount(getBalanceTestAddress,blockingStubFull) - .getBalance(); - Assert.assertEquals((long)(beforeBalance - afterBalance),(long)transferAmount); - final Long afterBlockNumber = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); - - - - - //Assert before balance + final Long afterBalance = + PublicMethod.queryAccount(getBalanceTestAddress, blockingStubFull).getBalance(); + Assert.assertEquals((long) (beforeBalance - afterBalance), (long) transferAmount); + final Long afterBlockNumber = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); + + // Assert before balance JsonArray params = new JsonArray(); params.add("0x" + ByteArray.toHexString(getBalanceTestAddress).substring(2)); params.add("0x" + Long.toHexString(beforeBlockNumber)); @@ -93,13 +97,9 @@ public void test01StateTreeWithEthGetBalance() throws Exception { responseContent = HttpMethod.parseResponseContent(response); String balance = responseContent.getString("result").substring(2); Long assertBalance = Long.parseLong(balance, 16); - Assert.assertEquals(assertBalance,beforeBalance); - - - + Assert.assertEquals(assertBalance, beforeBalance); - - //Assert after balance + // Assert after balance params = new JsonArray(); params.add("0x" + ByteArray.toHexString(getBalanceTestAddress).substring(2)); params.add("0x" + Long.toHexString(afterBlockNumber)); @@ -108,11 +108,9 @@ public void test01StateTreeWithEthGetBalance() throws Exception { responseContent = HttpMethod.parseResponseContent(response); balance = responseContent.getString("result").substring(2); assertBalance = Long.parseLong(balance, 16); - Assert.assertEquals(assertBalance,afterBalance); - - + Assert.assertEquals(assertBalance, afterBalance); - //State tree not open didn't support block number + // State tree not open didn't support block number params = new JsonArray(); params.add("0x" + ByteArray.toHexString(getBalanceTestAddress).substring(2)); params.add("0x" + Long.toHexString(afterBlockNumber)); @@ -120,31 +118,52 @@ public void test01StateTreeWithEthGetBalance() throws Exception { response = getJsonRpc(jsonRpcNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); String wrongMessage = responseContent.getJSONObject("error").getString("message"); - Assert.assertEquals(wrongMessage,"QUANTITY not supported, just support TAG as latest"); + Assert.assertEquals(wrongMessage, "QUANTITY not supported, just support TAG as latest"); } - - @Test(enabled = true, description = "State tree with tron_getAssets", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "State tree with tron_getAssets", + groups = {"daily", "serial"}) public void test02StateTreeWithTronGetAssets() throws Exception { - Assert.assertTrue(PublicMethod.transferAsset(getBalanceTestAddress, jsonRpcAssetId.getBytes(),sendAmount, - jsonRpcOwnerAddress,jsonRpcOwnerKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + getBalanceTestAddress, + jsonRpcAssetId.getBytes(), + sendAmount, + jsonRpcOwnerAddress, + jsonRpcOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); final Long beforeBalance = sendAmount; - final Long beforeBlockNumber = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + final Long beforeBlockNumber = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.transferAsset(getBalanceTestAddress, jsonRpcAssetId.getBytes(),transferAmount, - jsonRpcOwnerAddress,jsonRpcOwnerKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + getBalanceTestAddress, + jsonRpcAssetId.getBytes(), + transferAmount, + jsonRpcOwnerAddress, + jsonRpcOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); final Long afterBalance = sendAmount + transferAmount; - final Long afterBlockNumber = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); - - - //Assert before trc10 balance + final Long afterBlockNumber = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); + + // Assert before trc10 balance JsonArray params = new JsonArray(); params.add("0x" + ByteArray.toHexString(getBalanceTestAddress).substring(2)); params.add("0x" + Long.toHexString(beforeBlockNumber)); @@ -152,14 +171,14 @@ public void test02StateTreeWithTronGetAssets() throws Exception { response = getJsonRpc(stateTreeNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); JSONArray jsonArray = responseContent.getJSONArray("result"); - Assert.assertEquals(jsonArray.size(),1); - Long tokenId = Long.parseLong(jsonArray.getJSONObject(0).getString("key").substring(2),16); - Long assertBalance = Long.parseLong(jsonArray.getJSONObject(0).getString("value").substring(2),16); - Assert.assertEquals(assertBalance,beforeBalance); - Assert.assertEquals(String.valueOf(tokenId),jsonRpcAssetId); - - - //Assert after balance + Assert.assertEquals(jsonArray.size(), 1); + Long tokenId = Long.parseLong(jsonArray.getJSONObject(0).getString("key").substring(2), 16); + Long assertBalance = + Long.parseLong(jsonArray.getJSONObject(0).getString("value").substring(2), 16); + Assert.assertEquals(assertBalance, beforeBalance); + Assert.assertEquals(String.valueOf(tokenId), jsonRpcAssetId); + + // Assert after balance params = new JsonArray(); params.add("0x" + ByteArray.toHexString(getBalanceTestAddress).substring(2)); params.add("0x" + Long.toHexString(afterBlockNumber)); @@ -167,14 +186,13 @@ public void test02StateTreeWithTronGetAssets() throws Exception { response = getJsonRpc(stateTreeNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); jsonArray = responseContent.getJSONArray("result"); - Assert.assertEquals(jsonArray.size(),1); - tokenId = Long.parseLong(jsonArray.getJSONObject(0).getString("key").substring(2),16); - assertBalance = Long.parseLong(jsonArray.getJSONObject(0).getString("value").substring(2),16); - Assert.assertEquals(assertBalance,afterBalance); - Assert.assertEquals(String.valueOf(tokenId),jsonRpcAssetId); - + Assert.assertEquals(jsonArray.size(), 1); + tokenId = Long.parseLong(jsonArray.getJSONObject(0).getString("key").substring(2), 16); + assertBalance = Long.parseLong(jsonArray.getJSONObject(0).getString("value").substring(2), 16); + Assert.assertEquals(assertBalance, afterBalance); + Assert.assertEquals(String.valueOf(tokenId), jsonRpcAssetId); - //State tree not open didn't support block number + // State tree not open didn't support block number params = new JsonArray(); params.add("0x" + ByteArray.toHexString(getBalanceTestAddress).substring(2)); params.add("0x" + Long.toHexString(afterBlockNumber)); @@ -182,41 +200,56 @@ public void test02StateTreeWithTronGetAssets() throws Exception { response = getJsonRpc(jsonRpcNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); String wrongMessage = responseContent.getJSONObject("error").getString("message"); - Assert.assertEquals(wrongMessage,"QUANTITY not supported, just support TAG as latest"); - - - - - - + Assert.assertEquals(wrongMessage, "QUANTITY not supported, just support TAG as latest"); } - - @Test(enabled = true, description = "State tree with tron_getAssetById", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "State tree with tron_getAssetById", + groups = {"daily", "serial"}) public void test03StateTreeWithTronGetAssetById() throws Exception { ECKey getBalanceECKey = new ECKey(Utils.getRandom()); byte[] getBalanceTestAddress = getBalanceECKey.getAddress(); String getBalanceTestKey = ByteArray.toHexString(getBalanceECKey.getPrivKeyBytes()); PublicMethod.printAddress(getBalanceTestKey); - Assert.assertTrue(PublicMethod.transferAsset(getBalanceTestAddress, jsonRpcAssetId.getBytes(),sendAmount, - jsonRpcOwnerAddress,jsonRpcOwnerKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + getBalanceTestAddress, + jsonRpcAssetId.getBytes(), + sendAmount, + jsonRpcOwnerAddress, + jsonRpcOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); final Long beforeBalance = sendAmount; - final Long beforeBlockNumber = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + final Long beforeBlockNumber = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.transferAsset(getBalanceTestAddress, jsonRpcAssetId.getBytes(),transferAmount, - jsonRpcOwnerAddress,jsonRpcOwnerKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + getBalanceTestAddress, + jsonRpcAssetId.getBytes(), + transferAmount, + jsonRpcOwnerAddress, + jsonRpcOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); final Long afterBalance = sendAmount + transferAmount; - final Long afterBlockNumber = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); - - - //Assert before trc10 balance + final Long afterBlockNumber = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); + + // Assert before trc10 balance JsonArray params = new JsonArray(); params.add("0x" + ByteArray.toHexString(getBalanceTestAddress).substring(2)); params.add("0x" + Long.toHexString(Long.valueOf(jsonRpcAssetId))); @@ -224,13 +257,14 @@ public void test03StateTreeWithTronGetAssetById() throws Exception { JsonObject requestBody = getJsonRpcBody("tron_getAssetById", params); response = getJsonRpc(stateTreeNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); - Long tokenId = Long.parseLong(responseContent.getJSONObject("result").getString("key").substring(2),16); - Long assertBalance = Long.parseLong(responseContent.getJSONObject("result").getString("value").substring(2),16); - Assert.assertEquals(assertBalance,beforeBalance); - Assert.assertEquals(String.valueOf(tokenId),jsonRpcAssetId); - - - //Assert after balance + Long tokenId = + Long.parseLong(responseContent.getJSONObject("result").getString("key").substring(2), 16); + Long assertBalance = + Long.parseLong(responseContent.getJSONObject("result").getString("value").substring(2), 16); + Assert.assertEquals(assertBalance, beforeBalance); + Assert.assertEquals(String.valueOf(tokenId), jsonRpcAssetId); + + // Assert after balance params = new JsonArray(); params.add("0x" + ByteArray.toHexString(getBalanceTestAddress).substring(2)); params.add("0x" + Long.toHexString(Long.valueOf(jsonRpcAssetId))); @@ -238,14 +272,15 @@ public void test03StateTreeWithTronGetAssetById() throws Exception { requestBody = getJsonRpcBody("tron_getAssetById", params); response = getJsonRpc(stateTreeNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); - tokenId = Long.parseLong(responseContent.getJSONObject("result").getString("key").substring(2),16); - assertBalance = Long.parseLong(responseContent.getJSONObject("result").getString("value").substring(2),16); + tokenId = + Long.parseLong(responseContent.getJSONObject("result").getString("key").substring(2), 16); + assertBalance = + Long.parseLong(responseContent.getJSONObject("result").getString("value").substring(2), 16); - Assert.assertEquals(assertBalance,afterBalance); - Assert.assertEquals(String.valueOf(tokenId),jsonRpcAssetId); + Assert.assertEquals(assertBalance, afterBalance); + Assert.assertEquals(String.valueOf(tokenId), jsonRpcAssetId); - - //State tree not open didn't support block number + // State tree not open didn't support block number params = new JsonArray(); params.add("0x" + ByteArray.toHexString(getBalanceTestAddress).substring(2)); params.add("0x" + Long.toHexString(Long.valueOf(jsonRpcAssetId))); @@ -254,17 +289,13 @@ public void test03StateTreeWithTronGetAssetById() throws Exception { response = getJsonRpc(jsonRpcNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); String wrongMessage = responseContent.getJSONObject("error").getString("message"); - Assert.assertEquals(wrongMessage,"QUANTITY not supported, just support TAG as latest"); - - - - - - + Assert.assertEquals(wrongMessage, "QUANTITY not supported, just support TAG as latest"); } - - @Test(enabled = true, description = "State tree with eth_call", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "State tree with eth_call", + groups = {"daily", "serial"}) public void test04StateTreeWithEthCall() throws Exception { String selector = "transfer(address,uint256)"; String addressParam = @@ -287,13 +318,17 @@ public void test04StateTreeWithEthCall() throws Exception { jsonRpcOwnerKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.getTransactionInfoById(trc20Txid01,blockingStubFull).get() - .getLogCount() == 1); - - - final Long beforeBalance = Long.parseLong("100",16); - final Long beforeBlockNumber = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + Assert.assertTrue( + PublicMethod.getTransactionInfoById(trc20Txid01, blockingStubFull).get().getLogCount() + == 1); + + final Long beforeBalance = Long.parseLong("100", 16); + final Long beforeBlockNumber = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); PublicMethod.waitProduceNextBlock(blockingStubFull); trc20Txid01 = @@ -311,15 +346,19 @@ public void test04StateTreeWithEthCall() throws Exception { blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.getTransactionInfoById(trc20Txid01,blockingStubFull).get() - .getLogCount() == 1); + Assert.assertTrue( + PublicMethod.getTransactionInfoById(trc20Txid01, blockingStubFull).get().getLogCount() + == 1); final Long afterBalance = beforeBalance + beforeBalance; - final Long afterBlockNumber = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); - - - //Assert before trc20 balance + final Long afterBlockNumber = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); + + // Assert before trc20 balance JsonObject param = new JsonObject(); HttpMethod.waitToProduceOneBlock(httpFullNode); param.addProperty("from", ByteArray.toHexString(getBalanceTestAddress)); @@ -327,10 +366,9 @@ public void test04StateTreeWithEthCall() throws Exception { param.addProperty("gas", "0x0"); param.addProperty("gasPrice", "0x0"); param.addProperty("value", "0x0"); - //balanceOf(address) keccak encode + // balanceOf(address) keccak encode param.addProperty("data", "0x70a08231" + addressParam); - JsonArray params = new JsonArray(); params.add(param); params.add("0x" + Long.toHexString(beforeBlockNumber)); @@ -340,10 +378,9 @@ public void test04StateTreeWithEthCall() throws Exception { responseContent = HttpMethod.parseResponseContent(response); String balance = responseContent.getString("result").substring(2); Long assertBalance = Long.parseLong(balance, 16); - Assert.assertEquals(assertBalance,beforeBalance); - + Assert.assertEquals(assertBalance, beforeBalance); - //Assert after balance + // Assert after balance params = new JsonArray(); params.add(param); params.add("0x" + Long.toHexString(afterBlockNumber)); @@ -352,11 +389,9 @@ public void test04StateTreeWithEthCall() throws Exception { responseContent = HttpMethod.parseResponseContent(response); balance = responseContent.getString("result").substring(2); assertBalance = Long.parseLong(balance, 16); - Assert.assertEquals(assertBalance,afterBalance); - + Assert.assertEquals(assertBalance, afterBalance); - - //State tree not open didn't support block number + // State tree not open didn't support block number params = new JsonArray(); params.add(param); params.add("0x" + Long.toHexString(afterBlockNumber)); @@ -364,15 +399,19 @@ public void test04StateTreeWithEthCall() throws Exception { response = getJsonRpc(jsonRpcNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); String wrongMessage = responseContent.getJSONObject("error").getString("message"); - Assert.assertEquals(wrongMessage,"QUANTITY not supported, just support TAG as latest"); + Assert.assertEquals(wrongMessage, "QUANTITY not supported, just support TAG as latest"); } - - @Test(enabled = true, description = "State tree with eth_getCode", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "State tree with eth_getCode", + groups = {"daily", "serial"}) public void test05StateTreeWithEthGetCode() throws Exception { - String getCodeFromGetContract = ByteArray - .toHexString(PublicMethod.getContract(selfDestructAddressByte,blockingStubFull) - .getBytecode().toByteArray()); + String getCodeFromGetContract = + ByteArray.toHexString( + PublicMethod.getContract(selfDestructAddressByte, blockingStubFull) + .getBytecode() + .toByteArray()); logger.info("Get contract bytecode: " + getCodeFromGetContract); @@ -383,15 +422,17 @@ public void test05StateTreeWithEthGetCode() throws Exception { JsonObject requestBody = getJsonRpcBody("eth_getCode", params); response = getJsonRpc(stateTreeNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); - String getCodeFromLatest= responseContent.getString("result").substring(2); + String getCodeFromLatest = responseContent.getString("result").substring(2); logger.info("Latest getCode:" + getCodeFromLatest); - //Assert.assertEquals(getCodeFromJsonRpc,getCodeFromGetContract); + // Assert.assertEquals(getCodeFromJsonRpc,getCodeFromGetContract); - - - final Long beforeBlockNumber = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + final Long beforeBlockNumber = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); PublicMethod.waitProduceNextBlock(blockingStubFull); String txid02 = @@ -409,13 +450,20 @@ public void test05StateTreeWithEthGetCode() throws Exception { blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(PublicMethod.getTransactionInfoById(txid02,blockingStubFull).get() - .getReceipt().getResult(), contractResult.SUCCESS); - final Long afterBlockNumber = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); - - - //Assert before selfDestruct eth_getCode + Assert.assertEquals( + PublicMethod.getTransactionInfoById(txid02, blockingStubFull) + .get() + .getReceipt() + .getResult(), + contractResult.SUCCESS); + final Long afterBlockNumber = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); + + // Assert before selfDestruct eth_getCode params = new JsonArray(); params.add(ByteArray.toHexString(selfDestructAddressByte)); params.add("0x" + Long.toHexString(beforeBlockNumber)); @@ -426,10 +474,9 @@ public void test05StateTreeWithEthGetCode() throws Exception { String getCodeFromBeforeKill = responseContent.getString("result").substring(2); logger.info("Before kill : " + getCodeFromBeforeKill); - Assert.assertEquals(getCodeFromBeforeKill,getCodeFromLatest); - + Assert.assertEquals(getCodeFromBeforeKill, getCodeFromLatest); - //Assert after self destruct + // Assert after self destruct params = new JsonArray(); params.add(ByteArray.toHexString(selfDestructAddressByte)); params.add("0x" + Long.toHexString(afterBlockNumber)); @@ -438,11 +485,9 @@ public void test05StateTreeWithEthGetCode() throws Exception { responseContent = HttpMethod.parseResponseContent(response); String getCodeFromAfterKill = responseContent.getString("result"); logger.info("After kill : " + getCodeFromAfterKill); - Assert.assertEquals(getCodeFromAfterKill,"0x"); + Assert.assertEquals(getCodeFromAfterKill, "0x"); - - - //State tree not open didn't support block number + // State tree not open didn't support block number params = new JsonArray(); params.add(ByteArray.toHexString(selfDestructAddressByte)); params.add("0x" + Long.toHexString(beforeBlockNumber)); @@ -450,10 +495,13 @@ public void test05StateTreeWithEthGetCode() throws Exception { response = getJsonRpc(jsonRpcNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); String wrongMessage = responseContent.getJSONObject("error").getString("message"); - Assert.assertEquals(wrongMessage,"QUANTITY not supported, just support TAG as latest"); + Assert.assertEquals(wrongMessage, "QUANTITY not supported, just support TAG as latest"); } - @Test(enabled = true, description = "State tree with eth_getStorageAt", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "State tree with eth_getStorageAt", + groups = {"daily", "serial"}) public void test06StateTreeWithEthGetStorageAt() throws Exception { JsonArray params = new JsonArray(); params.add(contractAddressFrom58); @@ -465,8 +513,12 @@ public void test06StateTreeWithEthGetStorageAt() throws Exception { String result = responseContent.getString("result").substring(2); long beforePos2 = Long.parseLong(result, 16); logger.info("beforePos2:" + beforePos2); - final Long beforeBlockNumber = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + final Long beforeBlockNumber = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); String txid00 = PublicMethod.triggerContract( @@ -483,14 +535,21 @@ public void test06StateTreeWithEthGetStorageAt() throws Exception { blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(PublicMethod.getTransactionInfoById(txid00,blockingStubFull).get() - .getReceipt().getResult(), contractResult.SUCCESS); - - final Long afterBlockNumber = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); - - - //Assert before pos2 eth_getStorageAt + Assert.assertEquals( + PublicMethod.getTransactionInfoById(txid00, blockingStubFull) + .get() + .getReceipt() + .getResult(), + contractResult.SUCCESS); + + final Long afterBlockNumber = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); + + // Assert before pos2 eth_getStorageAt params = new JsonArray(); params.add(contractAddressFrom58); params.add("0x2"); @@ -499,13 +558,13 @@ public void test06StateTreeWithEthGetStorageAt() throws Exception { requestBody = getJsonRpcBody("eth_getStorageAt", params); response = getJsonRpc(stateTreeNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); - Long beforeNumberEthGetStorageAt = Long.parseLong(responseContent.getString("result").substring(2),16); + Long beforeNumberEthGetStorageAt = + Long.parseLong(responseContent.getString("result").substring(2), 16); logger.info("Before change pos2 : " + beforeNumberEthGetStorageAt); - Assert.assertEquals((long)beforeNumberEthGetStorageAt,beforePos2); + Assert.assertEquals((long) beforeNumberEthGetStorageAt, beforePos2); - - //Assert after change pos2 + // Assert after change pos2 params = new JsonArray(); params.add(contractAddressFrom58); params.add("0x2"); @@ -513,13 +572,12 @@ public void test06StateTreeWithEthGetStorageAt() throws Exception { requestBody = getJsonRpcBody("eth_getStorageAt", params); response = getJsonRpc(stateTreeNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); - Long afterNumberEthGetStorageAt = Long.parseLong(responseContent.getString("result").substring(2),16); - - Assert.assertEquals((long)afterNumberEthGetStorageAt,2); - + Long afterNumberEthGetStorageAt = + Long.parseLong(responseContent.getString("result").substring(2), 16); + Assert.assertEquals((long) afterNumberEthGetStorageAt, 2); - //State tree not open didn't support block number + // State tree not open didn't support block number params = new JsonArray(); params.add(contractAddressFrom58); params.add("0x2"); @@ -528,12 +586,14 @@ public void test06StateTreeWithEthGetStorageAt() throws Exception { response = getJsonRpc(jsonRpcNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); String wrongMessage = responseContent.getJSONObject("error").getString("message"); - Assert.assertEquals(wrongMessage,"QUANTITY not supported, just support TAG as latest"); + Assert.assertEquals(wrongMessage, "QUANTITY not supported, just support TAG as latest"); } - - @Test(enabled = false, description = "eth_getStorageAt with create2 address." - + "this case has been moved to Accounts001.java", groups = {"daily", "serial"}) + @Test( + enabled = false, + description = + "eth_getStorageAt with create2 address." + "this case has been moved to Accounts001.java", + groups = {"daily", "serial"}) public void test07StateTreeWithEthGetStorageAt() { JsonArray params = new JsonArray(); params.add(create2AddressFrom41); @@ -545,8 +605,12 @@ public void test07StateTreeWithEthGetStorageAt() { String result = responseContent.getString("result").substring(2); long beforePos2 = Long.parseLong(result, 16); logger.info("beforePos2:" + beforePos2); - final Long beforeBlockNumber = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + final Long beforeBlockNumber = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); String txid01 = PublicMethod.triggerContract( @@ -563,14 +627,21 @@ public void test07StateTreeWithEthGetStorageAt() { blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(PublicMethod.getTransactionInfoById(txid01,blockingStubFull).get() - .getReceipt().getResult(), contractResult.SUCCESS); - - final Long afterBlockNumber = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); - - - //Assert before pos2 eth_getStorageAt + Assert.assertEquals( + PublicMethod.getTransactionInfoById(txid01, blockingStubFull) + .get() + .getReceipt() + .getResult(), + contractResult.SUCCESS); + + final Long afterBlockNumber = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); + + // Assert before pos2 eth_getStorageAt params = new JsonArray(); params.add(create2AddressFrom41); params.add("0x2"); @@ -579,13 +650,13 @@ public void test07StateTreeWithEthGetStorageAt() { requestBody = getJsonRpcBody("eth_getStorageAt", params); response = getJsonRpc(stateTreeNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); - Long beforeNumberEthGetStorageAt = Long.parseLong(responseContent.getString("result").substring(2),16); + Long beforeNumberEthGetStorageAt = + Long.parseLong(responseContent.getString("result").substring(2), 16); logger.info("Before change pos2 : " + beforeNumberEthGetStorageAt); - Assert.assertEquals((long)beforeNumberEthGetStorageAt,beforePos2); - + Assert.assertEquals((long) beforeNumberEthGetStorageAt, beforePos2); - //Assert after change pos2 + // Assert after change pos2 params = new JsonArray(); params.add(create2AddressFrom41); params.add("0x2"); @@ -593,13 +664,12 @@ public void test07StateTreeWithEthGetStorageAt() { requestBody = getJsonRpcBody("eth_getStorageAt", params); response = getJsonRpc(stateTreeNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); - Long afterNumberEthGetStorageAt = Long.parseLong(responseContent.getString("result").substring(2),16); - - Assert.assertEquals((long)afterNumberEthGetStorageAt,2); - + Long afterNumberEthGetStorageAt = + Long.parseLong(responseContent.getString("result").substring(2), 16); + Assert.assertEquals((long) afterNumberEthGetStorageAt, 2); - //State tree not open didn't support block number + // State tree not open didn't support block number params = new JsonArray(); params.add(create2AddressFrom41); params.add("0x2"); @@ -608,21 +678,14 @@ public void test07StateTreeWithEthGetStorageAt() { response = getJsonRpc(jsonRpcNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); String wrongMessage = responseContent.getJSONObject("error").getString("message"); - Assert.assertEquals(wrongMessage,"QUANTITY not supported, just support TAG as latest"); + Assert.assertEquals(wrongMessage, "QUANTITY not supported, just support TAG as latest"); } - - - - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { if (channelFull != null) { channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/StateTree002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/StateTree002.java index 0c82dc8f..be0f3f0b 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/StateTree002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/StateTree002.java @@ -4,24 +4,27 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; import org.junit.Assert; import org.testng.SkipException; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; -import org.testng.annotations.Ignore; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.EmptyMessage; import org.tron.api.WalletGrpc; import org.tron.protos.Protocol; import org.tron.protos.Protocol.Transaction.Result.contractResult; import org.tron.protos.contract.SmartContractOuterClass; -import stest.tron.wallet.common.client.utils.*; - -import java.util.HashMap; -import java.util.concurrent.TimeUnit; - +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.HttpMethod; +import stest.tron.wallet.common.client.utils.JsonRpcBase; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class StateTree002 extends JsonRpcBase { @@ -43,25 +46,27 @@ public class StateTree002 extends JsonRpcBase { Long afterBlockNumber051; Long afterBlockNumber052; - - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - if(!stateRootIsOpen()) { + if (!stateRootIsOpen()) { throw new SkipException("Skipping this state root test case"); } - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext() - .build(); + channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); blockingStubFull = WalletGrpc.newBlockingStub(channelFull); PublicMethod.printAddress(callerPrivKey); - Assert.assertTrue(PublicMethod.sendcoin(callerAddress, 10000000000L, foundationAddress, - foundationKey, blockingStubFull)); -// jsonRpcAssetId = "1000001"; - Assert.assertTrue(PublicMethod.transferAsset(callerAddress, jsonRpcAssetId.getBytes(), 300L, - jsonRpcOwnerAddress,jsonRpcOwnerKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + callerAddress, 10000000000L, foundationAddress, foundationKey, blockingStubFull)); + // jsonRpcAssetId = "1000001"; + Assert.assertTrue( + PublicMethod.transferAsset( + callerAddress, + jsonRpcAssetId.getBytes(), + 300L, + jsonRpcOwnerAddress, + jsonRpcOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -71,28 +76,67 @@ public void beforeClass() { String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - callerContract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 100L, 100, 1000L, jsonRpcAssetId, - 100,null, callerPrivKey, callerAddress, blockingStubFull); + callerContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 100L, + 100, + 1000L, + jsonRpcAssetId, + 100, + null, + callerPrivKey, + callerAddress, + blockingStubFull); contractName = "calledContract"; retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - calledContract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 100L, 100, 1000L, jsonRpcAssetId, - 100, null, callerPrivKey, callerAddress, blockingStubFull); + calledContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 100L, + 100, + 1000L, + jsonRpcAssetId, + 100, + null, + callerPrivKey, + callerAddress, + blockingStubFull); contractName = "c"; retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - cContract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, 1000L, jsonRpcAssetId, - 100, null, callerPrivKey, callerAddress, blockingStubFull); + cContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + 1000L, + jsonRpcAssetId, + 100, + null, + callerPrivKey, + callerAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(callerContract, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(callerContract, blockingStubFull); Assert.assertTrue(smartContract.hasAbi()); smartContract = PublicMethod.getContract(calledContract, blockingStubFull); @@ -102,15 +146,30 @@ public void beforeClass() { Assert.assertTrue(smartContract.hasAbi()); } - - @Test(enabled = true, description = "eth_call get trx balance after contract delegate call ", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "eth_call get trx balance after contract delegate call ", + groups = {"daily", "serial"}) public void test01StateTreeWithEthCall() { - String parmes = "\"" + Base58.encode58Check(calledContract) - + "\",\"" + Base58.encode58Check(cContract) + "\""; + String parmes = + "\"" + + Base58.encode58Check(calledContract) + + "\",\"" + + Base58.encode58Check(cContract) + + "\""; String method = "sendToB(address,address)"; - String txid = PublicMethod.triggerContract(callerContract, method, parmes, false, - 0, maxFeeLimit, callerAddress, callerPrivKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + callerContract, + method, + parmes, + false, + 0, + maxFeeLimit, + callerAddress, + callerPrivKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Protocol.TransactionInfo infoById = @@ -119,20 +178,39 @@ public void test01StateTreeWithEthCall() { Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, infoById.getResult()); Assert.assertEquals(contractResult.SUCCESS, infoById.getReceipt().getResult()); - afterBlockNumber01 = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + afterBlockNumber01 = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); checkResult01(); } - - @Test(enabled = true, description = "eth_call get trx balance after contract call ", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "eth_call get trx balance after contract call ", + groups = {"daily", "serial"}) public void test02tateTreeWithEthCall() { - String parmes = "\"" + Base58.encode58Check(calledContract) - + "\",\"" + Base58.encode58Check(cContract) + "\""; + String parmes = + "\"" + + Base58.encode58Check(calledContract) + + "\",\"" + + Base58.encode58Check(cContract) + + "\""; String method = "sendToB2(address,address)"; - String txid = PublicMethod.triggerContract(callerContract, method, parmes, false, - 0, maxFeeLimit, callerAddress, callerPrivKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + callerContract, + method, + parmes, + false, + 0, + maxFeeLimit, + callerAddress, + callerPrivKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Protocol.TransactionInfo infoById = @@ -141,23 +219,46 @@ public void test02tateTreeWithEthCall() { Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, infoById.getResult()); Assert.assertEquals(contractResult.SUCCESS, infoById.getReceipt().getResult()); - afterBlockNumber02 = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + afterBlockNumber02 = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); checkResult02(); checkResult01(); } - @Test(enabled = true, description = "eth_call get trc10 balance after contract delegate call ", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "eth_call get trc10 balance after contract delegate call ", + groups = {"daily", "serial"}) public void test03StateTreeWithEthCall() { String method = "transferAssetIndelegateCall(address,address,address,uint256,trcToken)"; String param = - "\"" + Base58.encode58Check(calledContract) + "\",\"" + Base58.encode58Check(cContract) - + "\",\"" + Base58.encode58Check(callerContract) - + "\",1,\"" + jsonRpcAssetId + "\""; - - String txid = PublicMethod.triggerContract(callerContract, method, - param, false, 0, 1000000000L, "0", - 0, callerAddress, callerPrivKey, blockingStubFull); + "\"" + + Base58.encode58Check(calledContract) + + "\",\"" + + Base58.encode58Check(cContract) + + "\",\"" + + Base58.encode58Check(callerContract) + + "\",1,\"" + + jsonRpcAssetId + + "\""; + + String txid = + PublicMethod.triggerContract( + callerContract, + method, + param, + false, + 0, + 1000000000L, + "0", + 0, + callerAddress, + callerPrivKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Protocol.TransactionInfo infoById = @@ -166,23 +267,46 @@ public void test03StateTreeWithEthCall() { Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, infoById.getResult()); Assert.assertEquals(contractResult.SUCCESS, infoById.getReceipt().getResult()); - afterBlockNumber03 = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + afterBlockNumber03 = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); checkResult03(); checkResult02(); } - @Test(enabled = true, description = "eth_call get trc10 balance after contract call ", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "eth_call get trc10 balance after contract call ", + groups = {"daily", "serial"}) public void test04StateTreeWithEthCall() { String method = "transferAssetInCall(address,address,address,uint256,trcToken)"; String param = - "\"" + Base58.encode58Check(calledContract) + "\",\"" + Base58.encode58Check(cContract) - + "\",\"" + Base58.encode58Check(callerContract) - + "\",1,\"" + jsonRpcAssetId + "\""; - - String txid = PublicMethod.triggerContract(callerContract, method, - param, false, 0, 1000000000L, "0", - 0, callerAddress, callerPrivKey, blockingStubFull); + "\"" + + Base58.encode58Check(calledContract) + + "\",\"" + + Base58.encode58Check(cContract) + + "\",\"" + + Base58.encode58Check(callerContract) + + "\",1,\"" + + jsonRpcAssetId + + "\""; + + String txid = + PublicMethod.triggerContract( + callerContract, + method, + param, + false, + 0, + 1000000000L, + "0", + 0, + callerAddress, + callerPrivKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Protocol.TransactionInfo infoById = @@ -191,20 +315,37 @@ public void test04StateTreeWithEthCall() { Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, infoById.getResult()); Assert.assertEquals(contractResult.SUCCESS, infoById.getReceipt().getResult()); - afterBlockNumber04 = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + afterBlockNumber04 = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); checkResult04(); checkResult03(); } - @Test(enabled = true, description = "eth_call get trx and trc10 balance around create2 contract kill", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "eth_call get trx and trc10 balance around create2 contract kill", + groups = {"daily", "serial"}) public void test05StateTreeWithEthCall() { - //generate create2 contract + // generate create2 contract String method = "createWithSalted(bytes32)"; String param = "1232"; - String txid = PublicMethod.triggerContract(cContract, method, - param, false, 0, 1000000000L, "0", - 0, callerAddress, callerPrivKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + cContract, + method, + param, + false, + 0, + 1000000000L, + "0", + 0, + callerAddress, + callerPrivKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Protocol.TransactionInfo infoById = @@ -212,58 +353,87 @@ public void test05StateTreeWithEthCall() { logger.info("Trigger InfobyId: " + infoById); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, infoById.getResult()); Assert.assertEquals(contractResult.SUCCESS, infoById.getReceipt().getResult()); - String create241 = "41" + ByteArray.toHexString(infoById.getContractResult(0).toByteArray()).substring(24); + String create241 = + "41" + ByteArray.toHexString(infoById.getContractResult(0).toByteArray()).substring(24); create2Contract = ByteArray.fromHexString(create241); - //trans 1 trc10 to create2 contract + // trans 1 trc10 to create2 contract method = "trans(address,uint256,trcToken)"; param = "\"" + Base58.encode58Check(create2Contract) + "\",1,\"" + jsonRpcAssetId + "\""; - PublicMethod.triggerContract(cContract, method, - param, false, 0, 1000000000L, "0", - 0, callerAddress, callerPrivKey, blockingStubFull); + PublicMethod.triggerContract( + cContract, + method, + param, + false, + 0, + 1000000000L, + "0", + 0, + callerAddress, + callerPrivKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - afterBlockNumber051 = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); - //check create2 add 1 jsonRpcAssetId - Long create2ContractTokenBalance01 = getAssetById(create2Contract, jsonRpcAssetId, afterBlockNumber051, stateTreeNode); + afterBlockNumber051 = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); + // check create2 add 1 jsonRpcAssetId + Long create2ContractTokenBalance01 = + getAssetById(create2Contract, jsonRpcAssetId, afterBlockNumber051, stateTreeNode); Assert.assertEquals(1, create2ContractTokenBalance01.longValue()); - //check cContract decrease 1 jsonRpcAssetId - Long cContractTokenBalance01 = getAssetById(cContract, jsonRpcAssetId, afterBlockNumber051, stateTreeNode); + // check cContract decrease 1 jsonRpcAssetId + Long cContractTokenBalance01 = + getAssetById(cContract, jsonRpcAssetId, afterBlockNumber051, stateTreeNode); Assert.assertEquals(97, cContractTokenBalance01.longValue()); - //kill create2 contract and set cContract as receiver + // kill create2 contract and set cContract as receiver method = "destroy(address)"; param = "\"" + Base58.encode58Check(cContract) + "\""; - PublicMethod.triggerContract(create2Contract, method, - param, false, 0, 1000000000L, "0", - 0, callerAddress, callerPrivKey, blockingStubFull); + PublicMethod.triggerContract( + create2Contract, + method, + param, + false, + 0, + 1000000000L, + "0", + 0, + callerAddress, + callerPrivKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - afterBlockNumber052 = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); - - //check create2 has no jsonRpcAssetId - Long create2ContractTokenBalance02 = getAssetById(create2Contract, jsonRpcAssetId, afterBlockNumber052, stateTreeNode); + afterBlockNumber052 = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); + + // check create2 has no jsonRpcAssetId + Long create2ContractTokenBalance02 = + getAssetById(create2Contract, jsonRpcAssetId, afterBlockNumber052, stateTreeNode); Assert.assertEquals(0, create2ContractTokenBalance02.longValue()); - //check cContract add 1 jsonRpcAssetId - Long cContractTokenBalance02 = getAssetById(cContract, jsonRpcAssetId, afterBlockNumber052, stateTreeNode); + // check cContract add 1 jsonRpcAssetId + Long cContractTokenBalance02 = + getAssetById(cContract, jsonRpcAssetId, afterBlockNumber052, stateTreeNode); Assert.assertEquals(98, cContractTokenBalance02.longValue()); - } - void checkResult01() { - //eth_call get callerContract balance - String addressParam = "000000000000000000000000" - + ByteArray.toHexString(callerContract).substring(2); + // eth_call get callerContract balance + String addressParam = + "000000000000000000000000" + ByteArray.toHexString(callerContract).substring(2); JsonObject param = new JsonObject(); param.addProperty("from", ByteArray.toHexString(callerAddress)); param.addProperty("to", ByteArray.toHexString(callerContract)); param.addProperty("gas", "0x0"); param.addProperty("gasPrice", "0x0"); param.addProperty("value", "0x0"); - //getBalance(address)keccak encode + // getBalance(address)keccak encode param.addProperty("data", "0xf8b2cb4f" + addressParam); JsonArray params = new JsonArray(); params.add(param); @@ -276,9 +446,8 @@ void checkResult01() { Long callerContractBalance1 = Long.parseLong(balance, 16); Assert.assertEquals(95, callerContractBalance1.longValue()); - //eth_call get calledContract balance - addressParam = "000000000000000000000000" - + ByteArray.toHexString(cContract).substring(2); + // eth_call get calledContract balance + addressParam = "000000000000000000000000" + ByteArray.toHexString(cContract).substring(2); param.addProperty("data", "0xf8b2cb4f" + addressParam); requestBody = getJsonRpcBody("eth_call", params); response = getJsonRpc(stateTreeNode, requestBody); @@ -287,13 +456,12 @@ void checkResult01() { Long cContractBalance1 = Long.parseLong(balance, 16); Assert.assertEquals(5, cContractBalance1.longValue()); - //eth_call get callerContract balance with jsonObject blockNumber - addressParam = "000000000000000000000000" - + ByteArray.toHexString(callerContract).substring(2); + // eth_call get callerContract balance with jsonObject blockNumber + addressParam = "000000000000000000000000" + ByteArray.toHexString(callerContract).substring(2); param.addProperty("data", "0xf8b2cb4f" + addressParam); params.remove(1); JsonObject blockNumAndHash = new JsonObject(); - blockNumAndHash.addProperty("blockNumber",String.valueOf(afterBlockNumber01)); + blockNumAndHash.addProperty("blockNumber", String.valueOf(afterBlockNumber01)); params.add(blockNumAndHash); requestBody = getJsonRpcBody("eth_call", params); response = getJsonRpc(stateTreeNode, requestBody); @@ -302,9 +470,8 @@ void checkResult01() { callerContractBalance1 = Long.parseLong(balance, 16); Assert.assertEquals(95, callerContractBalance1.longValue()); - //eth_call get cContract balance with jsonObject blockNumber - addressParam = "000000000000000000000000" - + ByteArray.toHexString(cContract).substring(2); + // eth_call get cContract balance with jsonObject blockNumber + addressParam = "000000000000000000000000" + ByteArray.toHexString(cContract).substring(2); param.addProperty("data", "0xf8b2cb4f" + addressParam); requestBody = getJsonRpcBody("eth_call", params); response = getJsonRpc(stateTreeNode, requestBody); @@ -313,42 +480,40 @@ void checkResult01() { cContractBalance1 = Long.parseLong(balance, 16); Assert.assertEquals(5, cContractBalance1.longValue()); - - //eth_getBalance callerContract + // eth_getBalance callerContract params = new JsonArray(); params.add("0x" + ByteArray.toHexString(callerContract).substring(2)); params.add("0x" + Long.toHexString(afterBlockNumber01)); - requestBody = getJsonRpcBody("eth_getBalance", params); + requestBody = getJsonRpcBody("eth_getBalance", params); response = getJsonRpc(stateTreeNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); balance = responseContent.getString("result").substring(2); Long callerContractBalance2 = Long.parseLong(balance, 16); - Assert.assertEquals(callerContractBalance1,callerContractBalance2); + Assert.assertEquals(callerContractBalance1, callerContractBalance2); - //eth_getBalance crContract + // eth_getBalance crContract params = new JsonArray(); params.add("0x" + ByteArray.toHexString(cContract).substring(2)); params.add("0x" + Long.toHexString(afterBlockNumber01)); - requestBody = getJsonRpcBody("eth_getBalance", params); + requestBody = getJsonRpcBody("eth_getBalance", params); response = getJsonRpc(stateTreeNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); balance = responseContent.getString("result").substring(2); Long cContractBalance2 = Long.parseLong(balance, 16); - Assert.assertEquals(cContractBalance1,cContractBalance2); + Assert.assertEquals(cContractBalance1, cContractBalance2); } void checkResult02() { - //eth_call get calledContract balance + // eth_call get calledContract balance String addressParam = - "000000000000000000000000" - + ByteArray.toHexString(calledContract).substring(2); + "000000000000000000000000" + ByteArray.toHexString(calledContract).substring(2); JsonObject param = new JsonObject(); param.addProperty("from", ByteArray.toHexString(callerAddress)); param.addProperty("to", ByteArray.toHexString(callerContract)); param.addProperty("gas", "0x0"); param.addProperty("gasPrice", "0x0"); param.addProperty("value", "0x0"); - //balanceOf(address) keccak encode + // balanceOf(address) keccak encode param.addProperty("data", "0xf8b2cb4f" + addressParam); JsonArray params = new JsonArray(); params.add(param); @@ -357,15 +522,13 @@ void checkResult02() { JsonObject requestBody = getJsonRpcBody("eth_call", params); response = getJsonRpc(stateTreeNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); - System.out.println("-------: "+responseContent.toJSONString()); + System.out.println("-------: " + responseContent.toJSONString()); String balance = responseContent.getString("result").substring(2); Long calledContractBalance1 = Long.parseLong(balance, 16); Assert.assertEquals(95, calledContractBalance1.longValue()); - //eth_call get cContract balance - addressParam = - "000000000000000000000000" - + ByteArray.toHexString(cContract).substring(2); + // eth_call get cContract balance + addressParam = "000000000000000000000000" + ByteArray.toHexString(cContract).substring(2); param.addProperty("data", "0xf8b2cb4f" + addressParam); requestBody = getJsonRpcBody("eth_call", params); response = getJsonRpc(stateTreeNode, requestBody); @@ -374,31 +537,31 @@ void checkResult02() { Long cContractBalance1 = Long.parseLong(balance, 16); Assert.assertEquals(10, cContractBalance1.longValue()); - //eth_getBalance calledContract + // eth_getBalance calledContract params = new JsonArray(); params.add("0x" + ByteArray.toHexString(calledContract).substring(2)); params.add("0x" + Long.toHexString(afterBlockNumber02)); - requestBody = getJsonRpcBody("eth_getBalance", params); + requestBody = getJsonRpcBody("eth_getBalance", params); response = getJsonRpc(stateTreeNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); balance = responseContent.getString("result").substring(2); Long calledContractBalance2 = Long.parseLong(balance, 16); - Assert.assertEquals(calledContractBalance1,calledContractBalance2); + Assert.assertEquals(calledContractBalance1, calledContractBalance2); - //eth_getBalance cContract + // eth_getBalance cContract params = new JsonArray(); params.add("0x" + ByteArray.toHexString(cContract).substring(2)); params.add("0x" + Long.toHexString(afterBlockNumber02)); - requestBody = getJsonRpcBody("eth_getBalance", params); + requestBody = getJsonRpcBody("eth_getBalance", params); response = getJsonRpc(stateTreeNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); balance = responseContent.getString("result").substring(2); Long cContractBalance2 = Long.parseLong(balance, 16); - Assert.assertEquals(cContractBalance1,cContractBalance2); + Assert.assertEquals(cContractBalance1, cContractBalance2); } void checkResult03() { - //get callerContract token balance by tron_getAssetById + // get callerContract token balance by tron_getAssetById JsonArray params = new JsonArray(); params.add("0x" + ByteArray.toHexString(callerContract).substring(2)); params.add("0x" + Long.toHexString(Long.valueOf(jsonRpcAssetId))); @@ -406,12 +569,14 @@ void checkResult03() { JsonObject requestBody = getJsonRpcBody("tron_getAssetById", params); response = getJsonRpc(stateTreeNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); - Long tokenId = Long.parseLong(responseContent.getJSONObject("result").getString("key").substring(2),16); - Long callerContractTokenBalance01 = Long.parseLong(responseContent.getJSONObject("result").getString("value").substring(2),16); + Long tokenId = + Long.parseLong(responseContent.getJSONObject("result").getString("key").substring(2), 16); + Long callerContractTokenBalance01 = + Long.parseLong(responseContent.getJSONObject("result").getString("value").substring(2), 16); Assert.assertEquals(101, callerContractTokenBalance01.longValue()); - Assert.assertEquals(String.valueOf(tokenId),jsonRpcAssetId); + Assert.assertEquals(String.valueOf(tokenId), jsonRpcAssetId); - //get cContract token balance by tron_getAssetById + // get cContract token balance by tron_getAssetById params = new JsonArray(); params.add("0x" + ByteArray.toHexString(cContract).substring(2)); params.add("0x" + Long.toHexString(Long.valueOf(jsonRpcAssetId))); @@ -419,23 +584,26 @@ void checkResult03() { requestBody = getJsonRpcBody("tron_getAssetById", params); response = getJsonRpc(stateTreeNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); - tokenId = Long.parseLong(responseContent.getJSONObject("result").getString("key").substring(2),16); - Long cTokenBalance01 = Long.parseLong(responseContent.getJSONObject("result").getString("value").substring(2),16); + tokenId = + Long.parseLong(responseContent.getJSONObject("result").getString("key").substring(2), 16); + Long cTokenBalance01 = + Long.parseLong(responseContent.getJSONObject("result").getString("value").substring(2), 16); Assert.assertEquals(99, cTokenBalance01.longValue()); - Assert.assertEquals(String.valueOf(tokenId),jsonRpcAssetId); + Assert.assertEquals(String.valueOf(tokenId), jsonRpcAssetId); - //get callerContract token balance by eth_call - String addressParam = "000000000000000000000000" - + ByteArray.toHexString(callerContract).substring(2) - + "00000000000000000000000000000000000000000000000000000000000" - + Long.toHexString(Long.valueOf(jsonRpcAssetId)); + // get callerContract token balance by eth_call + String addressParam = + "000000000000000000000000" + + ByteArray.toHexString(callerContract).substring(2) + + "00000000000000000000000000000000000000000000000000000000000" + + Long.toHexString(Long.valueOf(jsonRpcAssetId)); JsonObject param = new JsonObject(); param.addProperty("from", ByteArray.toHexString(callerAddress)); param.addProperty("to", ByteArray.toHexString(callerContract)); param.addProperty("gas", "0x0"); param.addProperty("gasPrice", "0x0"); param.addProperty("value", "0x0"); - //getTokenBalance(address,trcToken) keccak encode + // getTokenBalance(address,trcToken) keccak encode param.addProperty("data", "0x5cae14a7" + addressParam); params = new JsonArray(); params.add(param); @@ -446,13 +614,15 @@ void checkResult03() { responseContent = HttpMethod.parseResponseContent(response); String balance = responseContent.getString("result").substring(2); Long callerContractTokenBalance02 = Long.parseLong(balance, 16); - Assert.assertEquals(callerContractTokenBalance01.longValue(), callerContractTokenBalance02.longValue()); + Assert.assertEquals( + callerContractTokenBalance01.longValue(), callerContractTokenBalance02.longValue()); - //get cContract token balance by eth_call - addressParam = "000000000000000000000000" - + ByteArray.toHexString(cContract).substring(2) - + "00000000000000000000000000000000000000000000000000000000000" - + Long.toHexString(Long.valueOf(jsonRpcAssetId)); + // get cContract token balance by eth_call + addressParam = + "000000000000000000000000" + + ByteArray.toHexString(cContract).substring(2) + + "00000000000000000000000000000000000000000000000000000000000" + + Long.toHexString(Long.valueOf(jsonRpcAssetId)); param.addProperty("data", "0x5cae14a7" + addressParam); requestBody = getJsonRpcBody("eth_call", params); response = getJsonRpc(stateTreeNode, requestBody); @@ -461,15 +631,16 @@ void checkResult03() { Long cTokenBalance02 = Long.parseLong(balance, 16); Assert.assertEquals(cTokenBalance01.longValue(), cTokenBalance02.longValue()); - //eth_call get callerContract token balance with jsonObject blockNumber - addressParam = "000000000000000000000000" - + ByteArray.toHexString(callerContract).substring(2) - + "00000000000000000000000000000000000000000000000000000000000" - + Long.toHexString(Long.valueOf(jsonRpcAssetId)); + // eth_call get callerContract token balance with jsonObject blockNumber + addressParam = + "000000000000000000000000" + + ByteArray.toHexString(callerContract).substring(2) + + "00000000000000000000000000000000000000000000000000000000000" + + Long.toHexString(Long.valueOf(jsonRpcAssetId)); param.addProperty("data", "0x5cae14a7" + addressParam); params.remove(1); JsonObject blockNumAndHash = new JsonObject(); - blockNumAndHash.addProperty("blockNumber",String.valueOf(afterBlockNumber03)); + blockNumAndHash.addProperty("blockNumber", String.valueOf(afterBlockNumber03)); params.add(blockNumAndHash); requestBody = getJsonRpcBody("eth_call", params); response = getJsonRpc(stateTreeNode, requestBody); @@ -478,11 +649,12 @@ void checkResult03() { Long callerContractTokenBalance03 = Long.parseLong(balance, 16); Assert.assertEquals(callerContractTokenBalance01, callerContractTokenBalance03); - //eth_call get cContract balance with jsonObject blockNumber - addressParam = "000000000000000000000000" - + ByteArray.toHexString(cContract).substring(2) - + "00000000000000000000000000000000000000000000000000000000000" - + Long.toHexString(Long.valueOf(jsonRpcAssetId)); + // eth_call get cContract balance with jsonObject blockNumber + addressParam = + "000000000000000000000000" + + ByteArray.toHexString(cContract).substring(2) + + "00000000000000000000000000000000000000000000000000000000000" + + Long.toHexString(Long.valueOf(jsonRpcAssetId)); param.addProperty("data", "0x5cae14a7" + addressParam); requestBody = getJsonRpcBody("eth_call", params); response = getJsonRpc(stateTreeNode, requestBody); @@ -493,7 +665,7 @@ void checkResult03() { } void checkResult04() { - //get callerContract token balance by tron_getAssetById + // get callerContract token balance by tron_getAssetById JsonArray params = new JsonArray(); params.add("0x" + ByteArray.toHexString(callerContract).substring(2)); params.add("0x" + Long.toHexString(Long.valueOf(jsonRpcAssetId))); @@ -501,12 +673,14 @@ void checkResult04() { JsonObject requestBody = getJsonRpcBody("tron_getAssetById", params); response = getJsonRpc(stateTreeNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); - Long tokenId = Long.parseLong(responseContent.getJSONObject("result").getString("key").substring(2),16); - Long callerContractTokenBalance01 = Long.parseLong(responseContent.getJSONObject("result").getString("value").substring(2),16); + Long tokenId = + Long.parseLong(responseContent.getJSONObject("result").getString("key").substring(2), 16); + Long callerContractTokenBalance01 = + Long.parseLong(responseContent.getJSONObject("result").getString("value").substring(2), 16); Assert.assertEquals(102, callerContractTokenBalance01.longValue()); - Assert.assertEquals(String.valueOf(tokenId),jsonRpcAssetId); + Assert.assertEquals(String.valueOf(tokenId), jsonRpcAssetId); - //get cContract token balance by tron_getAssetById + // get cContract token balance by tron_getAssetById params = new JsonArray(); params.add("0x" + ByteArray.toHexString(cContract).substring(2)); params.add("0x" + Long.toHexString(Long.valueOf(jsonRpcAssetId))); @@ -514,23 +688,26 @@ void checkResult04() { requestBody = getJsonRpcBody("tron_getAssetById", params); response = getJsonRpc(stateTreeNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); - tokenId = Long.parseLong(responseContent.getJSONObject("result").getString("key").substring(2),16); - Long cTokenBalance01 = Long.parseLong(responseContent.getJSONObject("result").getString("value").substring(2),16); + tokenId = + Long.parseLong(responseContent.getJSONObject("result").getString("key").substring(2), 16); + Long cTokenBalance01 = + Long.parseLong(responseContent.getJSONObject("result").getString("value").substring(2), 16); Assert.assertEquals(98, cTokenBalance01.longValue()); - Assert.assertEquals(String.valueOf(tokenId),jsonRpcAssetId); + Assert.assertEquals(String.valueOf(tokenId), jsonRpcAssetId); - //get callerContract token balance by eth_call - String addressParam = "000000000000000000000000" - + ByteArray.toHexString(callerContract).substring(2) - + "00000000000000000000000000000000000000000000000000000000000" - + Long.toHexString(Long.valueOf(jsonRpcAssetId)); + // get callerContract token balance by eth_call + String addressParam = + "000000000000000000000000" + + ByteArray.toHexString(callerContract).substring(2) + + "00000000000000000000000000000000000000000000000000000000000" + + Long.toHexString(Long.valueOf(jsonRpcAssetId)); JsonObject param = new JsonObject(); param.addProperty("from", ByteArray.toHexString(callerAddress)); param.addProperty("to", ByteArray.toHexString(callerContract)); param.addProperty("gas", "0x0"); param.addProperty("gasPrice", "0x0"); param.addProperty("value", "0x0"); - //getTokenBalance(address,trcToken) keccak encode + // getTokenBalance(address,trcToken) keccak encode param.addProperty("data", "0x5cae14a7" + addressParam); params = new JsonArray(); params.add(param); @@ -541,13 +718,15 @@ void checkResult04() { responseContent = HttpMethod.parseResponseContent(response); String balance = responseContent.getString("result").substring(2); Long callerContractTokenBalance02 = Long.parseLong(balance, 16); - Assert.assertEquals(callerContractTokenBalance01.longValue(), callerContractTokenBalance02.longValue()); + Assert.assertEquals( + callerContractTokenBalance01.longValue(), callerContractTokenBalance02.longValue()); - //get cContract token balance by eth_call - addressParam = "000000000000000000000000" - + ByteArray.toHexString(cContract).substring(2) - + "00000000000000000000000000000000000000000000000000000000000" - + Long.toHexString(Long.valueOf(jsonRpcAssetId)); + // get cContract token balance by eth_call + addressParam = + "000000000000000000000000" + + ByteArray.toHexString(cContract).substring(2) + + "00000000000000000000000000000000000000000000000000000000000" + + Long.toHexString(Long.valueOf(jsonRpcAssetId)); param.addProperty("data", "0x5cae14a7" + addressParam); requestBody = getJsonRpcBody("eth_call", params); response = getJsonRpc(stateTreeNode, requestBody); @@ -556,15 +735,16 @@ void checkResult04() { Long cTokenBalance02 = Long.parseLong(balance, 16); Assert.assertEquals(cTokenBalance01.longValue(), cTokenBalance02.longValue()); - //eth_call get callerContract token balance with jsonObject blockNumber - addressParam = "000000000000000000000000" - + ByteArray.toHexString(callerContract).substring(2) - + "00000000000000000000000000000000000000000000000000000000000" - + Long.toHexString(Long.valueOf(jsonRpcAssetId)); + // eth_call get callerContract token balance with jsonObject blockNumber + addressParam = + "000000000000000000000000" + + ByteArray.toHexString(callerContract).substring(2) + + "00000000000000000000000000000000000000000000000000000000000" + + Long.toHexString(Long.valueOf(jsonRpcAssetId)); param.addProperty("data", "0x5cae14a7" + addressParam); params.remove(1); JsonObject blockNumAndHash = new JsonObject(); - blockNumAndHash.addProperty("blockNumber",String.valueOf(afterBlockNumber04)); + blockNumAndHash.addProperty("blockNumber", String.valueOf(afterBlockNumber04)); params.add(blockNumAndHash); requestBody = getJsonRpcBody("eth_call", params); response = getJsonRpc(stateTreeNode, requestBody); @@ -573,11 +753,12 @@ void checkResult04() { Long callerContractTokenBalance03 = Long.parseLong(balance, 16); Assert.assertEquals(callerContractTokenBalance01, callerContractTokenBalance03); - //eth_call get cContract balance with jsonObject blockNumber - addressParam = "000000000000000000000000" - + ByteArray.toHexString(cContract).substring(2) - + "00000000000000000000000000000000000000000000000000000000000" - + Long.toHexString(Long.valueOf(jsonRpcAssetId)); + // eth_call get cContract balance with jsonObject blockNumber + addressParam = + "000000000000000000000000" + + ByteArray.toHexString(cContract).substring(2) + + "00000000000000000000000000000000000000000000000000000000000" + + Long.toHexString(Long.valueOf(jsonRpcAssetId)); param.addProperty("data", "0x5cae14a7" + addressParam); requestBody = getJsonRpcBody("eth_call", params); response = getJsonRpc(stateTreeNode, requestBody); @@ -595,22 +776,20 @@ long getAssetById(byte[] address, String assetId, long blockNum, String node) { JsonObject requestBody = getJsonRpcBody("tron_getAssetById", params); response = getJsonRpc(node, requestBody); responseContent = HttpMethod.parseResponseContent(response); - long tokenId = Long.parseLong(responseContent.getJSONObject("result").getString("key").substring(2),16); + long tokenId = + Long.parseLong(responseContent.getJSONObject("result").getString("key").substring(2), 16); Assert.assertEquals(assetId, String.valueOf(tokenId)); - Long cContractTokenBalance01 = Long.parseLong(responseContent.getJSONObject("result").getString("value").substring(2),16); + Long cContractTokenBalance01 = + Long.parseLong(responseContent.getJSONObject("result").getString("value").substring(2), 16); return cContractTokenBalance01; } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(callerAddress, callerPrivKey, foundationAddress, blockingStubFull); if (channelFull != null) { channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); } - } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/longexecutiontime/DynamicEnergyTest001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/longexecutiontime/DynamicEnergyTest001.java index 98e80e73..469b71e8 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/longexecutiontime/DynamicEnergyTest001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/longexecutiontime/DynamicEnergyTest001.java @@ -1,10 +1,6 @@ package stest.tron.wallet.dailybuild.longexecutiontime; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; -import java.util.Optional; -import java.util.Random; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.testng.SkipException; @@ -12,22 +8,18 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.EmptyMessage; -import org.tron.api.GrpcAPI.NumberMessage; -import org.tron.protos.Protocol.Block; -import org.tron.protos.Protocol.ChainParameters; -import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.TransactionInfo; import org.tron.protos.contract.SmartContractOuterClass.ContractState; -import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.ProposalEnum; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class DynamicEnergyTest001 extends TronBaseTest { Long sendAmount = 100000000000000L; +public class DynamicEnergyTest001 extends TronBaseTest { + Long sendAmount = 100000000000000L; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAccountAddress = ecKey1.getAddress(); String testAccountKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -36,87 +28,144 @@ public class DynamicEnergyTest001 extends TronBaseTest { Long sendAmount = 1000 byte[] contractAddress; private Long chainMaxFeeLimit = 0L; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() throws Exception { - PublicMethod.printAddress(testAccountKey); if(!PublicMethod.getAllowDynamicEnergyProposalIsOpen(blockingStubFull)) { throw new SkipException("Skipping getAllowDynamicEnergy test case"); + PublicMethod.printAddress(testAccountKey); + if (!PublicMethod.getAllowDynamicEnergyProposalIsOpen(blockingStubFull)) { + throw new SkipException("Skipping getAllowDynamicEnergy test case"); } - chainMaxFeeLimit = PublicMethod.getChainParametersValue(ProposalEnum.getMaxFeeLimit.getProposalName(), blockingStubFull); - energyFee = PublicMethod.getChainParametersValue(ProposalEnum.GetEnergyFee.getProposalName(), blockingStubFull); + chainMaxFeeLimit = + PublicMethod.getChainParametersValue( + ProposalEnum.getMaxFeeLimit.getProposalName(), blockingStubFull); + energyFee = + PublicMethod.getChainParametersValue( + ProposalEnum.GetEnergyFee.getProposalName(), blockingStubFull); maxFeeLimit = Math.min((long) (maxFeeLimit * (energyFee / 280.0)), chainMaxFeeLimit); - PublicMethod.sendcoin(testAccountAddress,sendAmount,foundationAddress,foundationKey,blockingStubFull); + PublicMethod.sendcoin( + testAccountAddress, sendAmount, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/contractLinkage005.sol"; - String contractName = "timeoutTest"; + String filePath = "./src/test/resources/soliditycode/contractLinkage005.sol"; + String contractName = "timeoutTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod.deployContractAndGetTransactionInfoById(contractName, abi, code, - "", maxFeeLimit, 0L, 100, null, testAccountKey, - testAccountAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testAccountKey, + testAccountAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - contractAddress = PublicMethod.getTransactionInfoById(txid,blockingStubFull).get().getContractAddress().toByteArray(); - Long nextMaintainTime = blockingStubFull.getNextMaintenanceTime(EmptyMessage.newBuilder().build()).getNum(); + contractAddress = + PublicMethod.getTransactionInfoById(txid, blockingStubFull) + .get() + .getContractAddress() + .toByteArray(); + Long nextMaintainTime = + blockingStubFull.getNextMaintenanceTime(EmptyMessage.newBuilder().build()).getNum(); while (System.currentTimeMillis() < nextMaintainTime + 9000) { PublicMethod.waitProduceNextBlock(blockingStubFull); } - } - - @Test(enabled = true,description = "Test get contract state", groups = {"daily"}) + @Test( + enabled = true, + description = "Test get contract state", + groups = {"daily"}) public void test01GetContractStatus() throws Exception { - ContractState contractState = PublicMethod.getContractInfo(contractAddress,blockingStubFull).getContractState(); + ContractState contractState = + PublicMethod.getContractInfo(contractAddress, blockingStubFull).getContractState(); Assert.assertTrue(contractState.getEnergyUsage() == 0); Assert.assertTrue(contractState.getEnergyFactor() == 0); - Long currentCycle = contractState.getUpdateCycle(); - Long getDynamicEnergyThreshold = PublicMethod.getChainParametersValue(ProposalEnum.GetDynamicEnergyThreshold - .getProposalName(), blockingStubFull); - Long getDynamicEnergyIncreaseFactor = PublicMethod.getChainParametersValue(ProposalEnum.GetDynamicEnergyIncreaseFactor - .getProposalName(), blockingStubFull); - String argsStr = "500"; - String txid = PublicMethod.triggerContract(contractAddress, - "testUseStorage(uint256)", argsStr, false, - 0, maxFeeLimit, testAccountAddress, testAccountKey, blockingStubFull); + Long currentCycle = contractState.getUpdateCycle(); + Long getDynamicEnergyThreshold = + PublicMethod.getChainParametersValue( + ProposalEnum.GetDynamicEnergyThreshold.getProposalName(), blockingStubFull); + Long getDynamicEnergyIncreaseFactor = + PublicMethod.getChainParametersValue( + ProposalEnum.GetDynamicEnergyIncreaseFactor.getProposalName(), blockingStubFull); + String argsStr = "500"; + String txid = + PublicMethod.triggerContract( + contractAddress, + "testUseStorage(uint256)", + argsStr, + false, + 0, + maxFeeLimit, + testAccountAddress, + testAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); - Long energyUsageTotal = PublicMethod.getTransactionInfoById(txid,blockingStubFull).get().getReceipt().getEnergyUsageTotal(); - - contractState = PublicMethod.getContractInfo(contractAddress,blockingStubFull).getContractState(); - Long currentContractUsed = contractState.getEnergyUsage(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + Long energyUsageTotal = + PublicMethod.getTransactionInfoById(txid, blockingStubFull) + .get() + .getReceipt() + .getEnergyUsageTotal(); + + contractState = + PublicMethod.getContractInfo(contractAddress, blockingStubFull).getContractState(); + Long currentContractUsed = contractState.getEnergyUsage(); Assert.assertEquals(energyUsageTotal, currentContractUsed); - //Failed trigger didn't increase contract energy used - txid = PublicMethod.triggerContract(contractAddress, - "testUseStorage(uint256)", "5000", false, - 0, maxFeeLimit, testAccountAddress, testAccountKey, blockingStubFull); + // Failed trigger didn't increase contract energy used + txid = + PublicMethod.triggerContract( + contractAddress, + "testUseStorage(uint256)", + "5000", + false, + 0, + maxFeeLimit, + testAccountAddress, + testAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - energyUsageTotal = PublicMethod.getTransactionInfoById(txid,blockingStubFull).get().getReceipt().getEnergyUsageTotal(); + energyUsageTotal = + PublicMethod.getTransactionInfoById(txid, blockingStubFull) + .get() + .getReceipt() + .getEnergyUsageTotal(); - contractState = PublicMethod.getContractInfo(contractAddress,blockingStubFull).getContractState(); - Long newCurrentContractUsed = contractState.getEnergyUsage(); + contractState = + PublicMethod.getContractInfo(contractAddress, blockingStubFull).getContractState(); + Long newCurrentContractUsed = contractState.getEnergyUsage(); Assert.assertEquals(currentContractUsed, newCurrentContractUsed); Assert.assertTrue(energyUsageTotal > 0); - Long nextMaintainTime = blockingStubFull.getNextMaintenanceTime(EmptyMessage.newBuilder().build()).getNum(); - + Long nextMaintainTime = + blockingStubFull.getNextMaintenanceTime(EmptyMessage.newBuilder().build()).getNum(); argsStr = "1200"; - int repeatTimes = 0; + int repeatTimes = 0; while (currentContractUsed < getDynamicEnergyThreshold) { - //if repeat too many times , set case to fail + // if repeat too many times , set case to fail Assert.assertTrue(repeatTimes < 25); - PublicMethod.triggerContract(contractAddress, - "testUseStorage(uint256)", argsStr, false, - 0, maxFeeLimit, testAccountAddress, testAccountKey, blockingStubFull); + PublicMethod.triggerContract( + contractAddress, + "testUseStorage(uint256)", + argsStr, + false, + 0, + maxFeeLimit, + testAccountAddress, + testAccountKey, + blockingStubFull); Thread.sleep(500); - contractState = PublicMethod.getContractInfo(contractAddress,blockingStubFull).getContractState(); + contractState = + PublicMethod.getContractInfo(contractAddress, blockingStubFull).getContractState(); currentContractUsed = contractState.getEnergyUsage(); - logger.info("currentContractUsed : " + currentContractUsed); - logger.info("getDynamicEnergyThreshold : " + getDynamicEnergyThreshold); + logger.info("currentContractUsed : " + currentContractUsed); + logger.info("getDynamicEnergyThreshold : " + getDynamicEnergyThreshold); repeatTimes += 1; } @@ -124,30 +173,43 @@ public void test01GetContractStatus() throws Exception { PublicMethod.waitProduceNextBlock(blockingStubFull); } - - contractState = PublicMethod.getContractInfo(contractAddress,blockingStubFull).getContractState(); + contractState = + PublicMethod.getContractInfo(contractAddress, blockingStubFull).getContractState(); Assert.assertTrue(contractState.getEnergyFactor() == getDynamicEnergyIncreaseFactor); Assert.assertTrue(currentCycle + 1 == contractState.getUpdateCycle()); - String transactionId = PublicMethod.triggerContract(contractAddress, - "testUseStorage(uint256)", "500", false, - 0, maxFeeLimit, testAccountAddress, testAccountKey, blockingStubFull); + String transactionId = + PublicMethod.triggerContract( + contractAddress, + "testUseStorage(uint256)", + "500", + false, + 0, + maxFeeLimit, + testAccountAddress, + testAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo transactionInfo = PublicMethod.getTransactionInfoById(transactionId,blockingStubFull).get(); - Long penaltyEnergyTotal = transactionInfo.getReceipt().getEnergyUsageTotal(); - Long penaltyEnergy = transactionInfo.getReceipt().getEnergyPenaltyTotal(); - //Assert.assertEquals((Long)(notPenaltyEnergyTotal + penaltyEnergy),penaltyEnergyTotal); - Assert.assertTrue(penaltyEnergy <= (Long)((penaltyEnergyTotal - penaltyEnergy) * contractState.getEnergyFactor() / 10000)); - Assert.assertTrue(penaltyEnergy >= (Long)((penaltyEnergyTotal - penaltyEnergy) * contractState.getEnergyFactor() / 10000) - 30000); - - + TransactionInfo transactionInfo = + PublicMethod.getTransactionInfoById(transactionId, blockingStubFull).get(); + Long penaltyEnergyTotal = transactionInfo.getReceipt().getEnergyUsageTotal(); + Long penaltyEnergy = transactionInfo.getReceipt().getEnergyPenaltyTotal(); + // Assert.assertEquals((Long)(notPenaltyEnergyTotal + penaltyEnergy),penaltyEnergyTotal); + Assert.assertTrue( + penaltyEnergy + <= (Long) + ((penaltyEnergyTotal - penaltyEnergy) * contractState.getEnergyFactor() / 10000)); + Assert.assertTrue( + penaltyEnergy + >= (Long) + ((penaltyEnergyTotal - penaltyEnergy) * contractState.getEnergyFactor() / 10000) + - 30000); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(testAccountAddress, testAccountKey, foundationAddress, blockingStubFull); } -} \ No newline at end of file + PublicMethod.freeResource( + testAccountAddress, testAccountKey, foundationAddress, blockingStubFull); + } +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/longexecutiontime/FreezeBalanceV2Test007.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/longexecutiontime/FreezeBalanceV2Test007.java index 9432486a..72c4e6b8 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/longexecutiontime/FreezeBalanceV2Test007.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/longexecutiontime/FreezeBalanceV2Test007.java @@ -10,13 +10,11 @@ import org.tron.api.GrpcAPI.AccountResourceMessage; import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.AccountType; -import org.tron.protos.Protocol.Transaction.Result.contractResult; -import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class FreezeBalanceV2Test007 extends TronBaseTest { @@ -37,72 +35,117 @@ public class FreezeBalanceV2Test007 extends TronBaseTest { Integer maxUnfreezeListCount = 32; byte[] contractAddress; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() throws Exception{ - PublicMethod.printAddress(frozenBandwidthKey); if(!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { throw new SkipException("Skipping freezeV2 test case"); + public void beforeClass() throws Exception { + PublicMethod.printAddress(frozenBandwidthKey); + if (!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + throw new SkipException("Skipping freezeV2 test case"); } - Assert.assertTrue(PublicMethod.sendcoin(frozenBandwidthAddress, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(frozenEnergyAddress, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(frozenEnergyRevertAddress, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + frozenBandwidthAddress, + sendAmount, + foundationAddress, + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + frozenEnergyAddress, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + frozenEnergyRevertAddress, + sendAmount, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/contractLinkage005.sol"; - String contractName = "timeoutTest"; + String filePath = "./src/test/resources/soliditycode/contractLinkage005.sol"; + String contractName = "timeoutTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod.deployContractAndGetTransactionInfoById(contractName, abi, code, - "", maxFeeLimit, 0L, 100, null, frozenEnergyKey, - frozenEnergyAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + frozenEnergyKey, + frozenEnergyAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - contractAddress = PublicMethod.getTransactionInfoById(txid,blockingStubFull).get().getContractAddress().toByteArray(); - Assert.assertEquals(PublicMethod.queryAccount(contractAddress,blockingStubFull).getType(),AccountType.Contract); + contractAddress = + PublicMethod.getTransactionInfoById(txid, blockingStubFull) + .get() + .getContractAddress() + .toByteArray(); + Assert.assertEquals( + PublicMethod.queryAccount(contractAddress, blockingStubFull).getType(), + AccountType.Contract); - Assert.assertTrue(PublicMethod.freezeBalanceV2(frozenBandwidthAddress, - freezeBandwidthBalance,0,frozenBandwidthKey,blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceV2(frozenEnergyAddress, - freezeEnergyBalance,1,frozenEnergyKey,blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceV2(frozenEnergyRevertAddress, - freezeEnergyBalance,1,frozenEnergyRevertKey,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + frozenBandwidthAddress, + freezeBandwidthBalance, + 0, + frozenBandwidthKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + frozenEnergyAddress, freezeEnergyBalance, 1, frozenEnergyKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + frozenEnergyRevertAddress, + freezeEnergyBalance, + 1, + frozenEnergyRevertKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - } - /** - * constructor. - */ - @Test(enabled = true, description = "Bandwidth NetUsage change net_window_size", groups = {"daily"}) - public void test01BandwidthNetUsageChangeNetWindowSIze() throws Exception{ - Account account = PublicMethod.queryAccount(frozenBandwidthAddress,blockingStubFull); - AccountResourceMessage accountResourceMessage = PublicMethod.getAccountResource(frozenBandwidthAddress,blockingStubFull); - Long beforeNetUsage = account.getNetUsage(); - Long beforeNetUsageFromAccountResource = accountResourceMessage.getNetUsed(); - Long beforeNetWindowSize = account.getNetWindowSize(); + /** constructor. */ + @Test( + enabled = true, + description = "Bandwidth NetUsage change net_window_size", + groups = {"daily"}) + public void test01BandwidthNetUsageChangeNetWindowSIze() throws Exception { + Account account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); + AccountResourceMessage accountResourceMessage = + PublicMethod.getAccountResource(frozenBandwidthAddress, blockingStubFull); + Long beforeNetUsage = account.getNetUsage(); + Long beforeNetUsageFromAccountResource = accountResourceMessage.getNetUsed(); + Long beforeNetWindowSize = account.getNetWindowSize(); System.out.println("beforeNetWindowSize: " + beforeNetWindowSize); Assert.assertTrue(beforeNetWindowSize == 28800 * 1000); - Assert.assertEquals(beforeNetUsage,beforeNetUsageFromAccountResource); + Assert.assertEquals(beforeNetUsage, beforeNetUsageFromAccountResource); Assert.assertTrue(beforeNetUsage == 0); - String txid = PublicMethod.sendcoinGetTransactionId(foundationAddress,1L, - frozenBandwidthAddress,frozenBandwidthKey,blockingStubFull); + String txid = + PublicMethod.sendcoinGetTransactionId( + foundationAddress, 1L, frozenBandwidthAddress, frozenBandwidthKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - account = PublicMethod.queryAccount(frozenBandwidthAddress,blockingStubFull); - accountResourceMessage = PublicMethod.getAccountResource(frozenBandwidthAddress,blockingStubFull); - Long afterNetUsage = account.getNetUsage(); - Long afterNetUsageFromAccountResource = accountResourceMessage.getNetUsed(); - Assert.assertEquals(afterNetUsage,afterNetUsageFromAccountResource); - Long transactionNetUsage = PublicMethod.getTransactionInfoById(txid,blockingStubFull) - .get().getReceipt().getNetUsage(); - Assert.assertTrue(afterNetUsage <= transactionNetUsage - && afterNetUsage + 2 >= transactionNetUsage - && transactionNetUsage > 200); - Long beforeLatestConsumeTime = account.getLatestConsumeTime(); + account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); + accountResourceMessage = + PublicMethod.getAccountResource(frozenBandwidthAddress, blockingStubFull); + Long afterNetUsage = account.getNetUsage(); + Long afterNetUsageFromAccountResource = accountResourceMessage.getNetUsed(); + Assert.assertEquals(afterNetUsage, afterNetUsageFromAccountResource); + Long transactionNetUsage = + PublicMethod.getTransactionInfoById(txid, blockingStubFull) + .get() + .getReceipt() + .getNetUsage(); + Assert.assertTrue( + afterNetUsage <= transactionNetUsage + && afterNetUsage + 2 >= transactionNetUsage + && transactionNetUsage > 200); + Long beforeLatestConsumeTime = account.getLatestConsumeTime(); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -110,74 +153,85 @@ public void test01BandwidthNetUsageChangeNetWindowSIze() throws Exception{ PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - account = PublicMethod.queryAccount(frozenBandwidthAddress,blockingStubFull); - Long afterLatestConsumeTime = account.getLatestConsumeTime(); - //getLatestConsumeTime means this user latest use consume net Time,not current timestamp - Assert.assertEquals(beforeLatestConsumeTime,afterLatestConsumeTime); + account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); + Long afterLatestConsumeTime = account.getLatestConsumeTime(); + // getLatestConsumeTime means this user latest use consume net Time,not current timestamp + Assert.assertEquals(beforeLatestConsumeTime, afterLatestConsumeTime); beforeNetWindowSize = account.getNetWindowSize(); logger.info("beforeNetWindowSize:" + beforeNetWindowSize); Assert.assertTrue(beforeNetWindowSize < 28800 * 1000); beforeNetUsage = account.getNetUsage(); Assert.assertTrue(beforeNetUsage > 200); - txid = PublicMethod.sendcoinGetTransactionId(foundationAddress,1L, - frozenBandwidthAddress,frozenBandwidthKey,blockingStubFull); + txid = + PublicMethod.sendcoinGetTransactionId( + foundationAddress, 1L, frozenBandwidthAddress, frozenBandwidthKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - account = PublicMethod.queryAccount(frozenBandwidthAddress,blockingStubFull); - Long afterNetWindowSize = account.getNetWindowSize(); + account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); + Long afterNetWindowSize = account.getNetWindowSize(); logger.info("afterNetWindowSize:" + afterNetWindowSize); Assert.assertTrue( - afterNetWindowSize > beforeNetWindowSize - && afterNetWindowSize <= 28795 * 1000); + afterNetWindowSize > beforeNetWindowSize && afterNetWindowSize <= 28795 * 1000); afterNetUsage = account.getNetUsage(); - transactionNetUsage = PublicMethod.getTransactionInfoById(txid,blockingStubFull) - .get().getReceipt().getNetUsage(); - Assert.assertTrue(afterNetUsage - beforeNetUsage <= transactionNetUsage - && afterNetUsage - beforeNetUsage + 2 >= transactionNetUsage - && transactionNetUsage > 200 && afterNetUsage > 400); - + transactionNetUsage = + PublicMethod.getTransactionInfoById(txid, blockingStubFull) + .get() + .getReceipt() + .getNetUsage(); + Assert.assertTrue( + afterNetUsage - beforeNetUsage <= transactionNetUsage + && afterNetUsage - beforeNetUsage + 2 >= transactionNetUsage + && transactionNetUsage > 200 + && afterNetUsage > 400); } - /** - * constructor. - */ - @Test(enabled = true, description = "Free net can not make netWindowSize change", groups = {"daily"}) - public void test02FreeNetCanNotMakeNetWindowSizeChange() throws Exception{ - AccountResourceMessage accountResourceMessage = PublicMethod.getAccountResource(frozenBandwidthAddress,blockingStubFull); - Long currentNetPrice = (1000000L * accountResourceMessage.getTotalNetWeight()) / accountResourceMessage.getTotalNetLimit(); - currentNetPrice = Math.max(1L,currentNetPrice); - Long needUnfreezeBalance = PublicMethod.getFrozenV2Amount(frozenBandwidthAddress,0,blockingStubFull) - 275 * currentNetPrice - currentNetPrice * 100 - - accountResourceMessage.getNetUsed() * currentNetPrice; - needUnfreezeBalance = Math.max(1L,needUnfreezeBalance); + /** constructor. */ + @Test( + enabled = true, + description = "Free net can not make netWindowSize change", + groups = {"daily"}) + public void test02FreeNetCanNotMakeNetWindowSizeChange() throws Exception { + AccountResourceMessage accountResourceMessage = + PublicMethod.getAccountResource(frozenBandwidthAddress, blockingStubFull); + Long currentNetPrice = + (1000000L * accountResourceMessage.getTotalNetWeight()) + / accountResourceMessage.getTotalNetLimit(); + currentNetPrice = Math.max(1L, currentNetPrice); + Long needUnfreezeBalance = + PublicMethod.getFrozenV2Amount(frozenBandwidthAddress, 0, blockingStubFull) + - 275 * currentNetPrice + - currentNetPrice * 100 + - accountResourceMessage.getNetUsed() * currentNetPrice; + needUnfreezeBalance = Math.max(1L, needUnfreezeBalance); logger.info("needUnfreezeBalance:" + needUnfreezeBalance); - Assert.assertTrue(PublicMethod.unFreezeBalanceV2(frozenBandwidthAddress,frozenBandwidthKey,needUnfreezeBalance, - 0,blockingStubFull)); + Assert.assertTrue( + PublicMethod.unFreezeBalanceV2( + frozenBandwidthAddress, frozenBandwidthKey, needUnfreezeBalance, 0, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Thread.sleep(600000); - Account account = PublicMethod.queryAccount(frozenBandwidthAddress,blockingStubFull); - Long beforeUseFreeNetWindowSize = account.getNetWindowSize(); - Long beforeNetUsed = account.getFreeNetUsage(); + Account account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); + Long beforeUseFreeNetWindowSize = account.getNetWindowSize(); + Long beforeNetUsed = account.getFreeNetUsage(); logger.info("beforeUseFreeNetWindowSize:" + beforeUseFreeNetWindowSize); - PublicMethod.sendcoinGetTransactionId(foundationAddress,1L,frozenBandwidthAddress,frozenBandwidthKey, - blockingStubFull); + PublicMethod.sendcoinGetTransactionId( + foundationAddress, 1L, frozenBandwidthAddress, frozenBandwidthKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - account = PublicMethod.queryAccount(frozenBandwidthAddress,blockingStubFull); - Long afterUseFreeNetWindowSize = account.getNetWindowSize(); - Long afterNetUsed = account.getFreeNetUsage(); + account = PublicMethod.queryAccount(frozenBandwidthAddress, blockingStubFull); + Long afterUseFreeNetWindowSize = account.getNetWindowSize(); + Long afterNetUsed = account.getFreeNetUsage(); logger.info("afterUseFreeNetWindowSize:" + afterUseFreeNetWindowSize); Assert.assertTrue(afterNetUsed - beforeNetUsed > 200); Assert.assertTrue(beforeUseFreeNetWindowSize - afterUseFreeNetWindowSize <= 50 * 1000); } - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - PublicMethod.freeResource(frozenBandwidthAddress, frozenBandwidthKey, foundationAddress, blockingStubFull); } + PublicMethod.freeResource( + frozenBandwidthAddress, frozenBandwidthKey, foundationAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractLinkage001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractLinkage001.java index 882a4c82..5c0b92ff 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractLinkage001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractLinkage001.java @@ -16,53 +16,53 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode -public class ContractLinkage001 extends TronBaseTest { ECKey ecKey1 = new ECKey(Utils.getRandom()); +public class ContractLinkage001 extends TronBaseTest { + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] linkage001Address = ecKey1.getAddress(); String linkage001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(linkage001Key); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(linkage001Key); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - } - @Test(enabled = true, description = "Deploy contract with valid or invalid value", groups = {"daily"}) + @Test( + enabled = true, + description = "Deploy contract with valid or invalid value", + groups = {"daily"}) public void deployContentValue() { - Assert.assertTrue(PublicMethod.sendcoin(linkage001Address, 30000000000L, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + linkage001Address, 30000000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(linkage001Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(linkage001Address, blockingStubFull); info = PublicMethod.queryAccount(linkage001Address, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeNetLimit = resourceInfo.getNetLimit(); - Long beforeFreeNetLimit = resourceInfo.getFreeNetLimit(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeEnergyLimit = resourceInfo.getEnergyLimit(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeBalance = info.getBalance(); + Long beforeNetLimit = resourceInfo.getNetLimit(); + Long beforeFreeNetLimit = resourceInfo.getFreeNetLimit(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeEnergyLimit = resourceInfo.getEnergyLimit(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyLimit:" + beforeEnergyLimit); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); @@ -70,28 +70,38 @@ public void deployContentValue() { logger.info("beforeNetLimit:" + beforeNetLimit); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - //Value is equal balance,this will be failed.Only use FreeNet,Other not change. + // Value is equal balance,this will be failed.Only use FreeNet,Other not change. String filePath = "./src/test/resources/soliditycode/contractLinkage001.sol"; - String contractName = "divideIHaveArgsReturnStorage"; + String contractName = "divideIHaveArgsReturnStorage"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String payableCode = retMap.get("byteCode").toString(); - String payableAbi = retMap.get("abI").toString(); + String payableCode = retMap.get("byteCode").toString(); + String payableAbi = retMap.get("abI").toString(); PublicMethod.waitProduceNextBlock(blockingStubFull); Account accountGet = PublicMethod.queryAccount(linkage001Key, blockingStubFull); - Long accountBalance = accountGet.getBalance(); - String txid = PublicMethod.deployContractAndGetTransactionInfoById(contractName, payableAbi, - payableCode, "", maxFeeLimit, accountBalance, 100, null, - linkage001Key, linkage001Address, blockingStubFull); + Long accountBalance = accountGet.getBalance(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + payableAbi, + payableCode, + "", + maxFeeLimit, + accountBalance, + 100, + null, + linkage001Key, + linkage001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); - Long fee = infoById.get().getFee(); - Long energyFee = infoById.get().getReceipt().getEnergyFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + Long fee = infoById.get().getFee(); + Long energyFee = infoById.get().getReceipt().getEnergyFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); logger.info("energyUsageTotal:" + energyUsageTotal); logger.info("fee:" + fee); logger.info("energyFee:" + energyFee); @@ -100,15 +110,15 @@ public void deployContentValue() { logger.info("netFee:" + netFee); Account infoafter = PublicMethod.queryAccount(linkage001Address, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(linkage001Address, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyLimit = resourceInfoafter.getEnergyLimit(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterFreeNetLimit = resourceInfoafter.getFreeNetLimit(); - Long afterNetLimit = resourceInfoafter.getNetLimit(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(linkage001Address, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyLimit = resourceInfoafter.getEnergyLimit(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterFreeNetLimit = resourceInfoafter.getFreeNetLimit(); + Long afterNetLimit = resourceInfoafter.getNetLimit(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyLimit:" + afterEnergyLimit); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -123,22 +133,23 @@ public void deployContentValue() { Assert.assertTrue(afterNetUsed == 0); Assert.assertTrue(afterEnergyUsed == 0); Assert.assertTrue(afterFreeNetUsed > 0); - Long freezeBalance = 2000000000L; - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(linkage001Address, freezeBalance, - 0, 1, linkage001Key, blockingStubFull)); + Long freezeBalance = 2000000000L; + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + linkage001Address, freezeBalance, 0, 1, linkage001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //maxFeeLimit = maxFeeLimit - freezeBalance; + // maxFeeLimit = maxFeeLimit - freezeBalance; PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage resourceInfo1 = PublicMethod.getAccountResource(linkage001Address, - blockingStubFull); + AccountResourceMessage resourceInfo1 = + PublicMethod.getAccountResource(linkage001Address, blockingStubFull); Account info1 = PublicMethod.queryAccount(linkage001Address, blockingStubFull); - Long beforeBalance1 = info1.getBalance(); - Long beforeEnergyLimit1 = resourceInfo1.getEnergyLimit(); - Long beforeEnergyUsed1 = resourceInfo1.getEnergyUsed(); - Long beforeFreeNetLimit1 = resourceInfo1.getFreeNetLimit(); - Long beforeNetLimit1 = resourceInfo1.getNetLimit(); - Long beforeNetUsed1 = resourceInfo1.getNetUsed(); - Long beforeFreeNetUsed1 = resourceInfo1.getFreeNetUsed(); + Long beforeBalance1 = info1.getBalance(); + Long beforeEnergyLimit1 = resourceInfo1.getEnergyLimit(); + Long beforeEnergyUsed1 = resourceInfo1.getEnergyUsed(); + Long beforeFreeNetLimit1 = resourceInfo1.getFreeNetLimit(); + Long beforeNetLimit1 = resourceInfo1.getNetLimit(); + Long beforeNetUsed1 = resourceInfo1.getNetUsed(); + Long beforeFreeNetUsed1 = resourceInfo1.getFreeNetUsed(); logger.info("beforeBalance1:" + beforeBalance1); logger.info("beforeEnergyLimit1:" + beforeEnergyLimit1); logger.info("beforeEnergyUsed1:" + beforeEnergyUsed1); @@ -146,20 +157,29 @@ public void deployContentValue() { logger.info("beforeNetLimit1:" + beforeNetLimit1); logger.info("beforeNetUsed1:" + beforeNetUsed1); logger.info("beforeFreeNetUsed1:" + beforeFreeNetUsed1); - //Value is 1,use BalanceGetEnergy,use FreeNet,fee==0. - txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, payableAbi, payableCode, - "", maxFeeLimit, 1L, 100, null, linkage001Key, - linkage001Address, blockingStubFull); + // Value is 1,use BalanceGetEnergy,use FreeNet,fee==0. + txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + payableAbi, + payableCode, + "", + maxFeeLimit, + 1L, + 100, + null, + linkage001Key, + linkage001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById1 = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - Long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); - Long fee1 = infoById1.get().getFee(); - Long energyFee1 = infoById1.get().getReceipt().getEnergyFee(); - Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); - Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); - Long netFee1 = infoById1.get().getReceipt().getNetFee(); + Optional infoById1 = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); + Long fee1 = infoById1.get().getFee(); + Long energyFee1 = infoById1.get().getReceipt().getEnergyFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); logger.info("energyUsageTotal1:" + energyUsageTotal1); logger.info("fee1:" + fee1); logger.info("energyFee1:" + energyFee1); @@ -169,15 +189,15 @@ public void deployContentValue() { Assert.assertTrue(infoById1.get().getResultValue() == 0); Account infoafter1 = PublicMethod.queryAccount(linkage001Address, blockingStubFull1); - AccountResourceMessage resourceInfoafter1 = PublicMethod.getAccountResource(linkage001Address, - blockingStubFull1); - Long afterBalance1 = infoafter1.getBalance(); - Long afterEnergyLimit1 = resourceInfoafter1.getEnergyLimit(); - Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); - Long afterFreeNetLimit1 = resourceInfoafter1.getFreeNetLimit(); - Long afterNetLimit1 = resourceInfoafter1.getNetLimit(); - Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); - Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter1 = + PublicMethod.getAccountResource(linkage001Address, blockingStubFull1); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyLimit1 = resourceInfoafter1.getEnergyLimit(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterFreeNetLimit1 = resourceInfoafter1.getFreeNetLimit(); + Long afterNetLimit1 = resourceInfoafter1.getNetLimit(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); logger.info("afterBalance1:" + afterBalance1); logger.info("afterEnergyLimit1:" + afterEnergyLimit1); logger.info("afterEnergyUsed1:" + afterEnergyUsed1); @@ -187,23 +207,23 @@ public void deployContentValue() { logger.info("afterFreeNetUsed1:" + afterFreeNetUsed1); Assert.assertTrue(beforeBalance1 - fee1 - 1L == afterBalance1); - byte[] contractAddress = infoById1.get().getContractAddress().toByteArray(); + byte[] contractAddress = infoById1.get().getContractAddress().toByteArray(); Account account = PublicMethod.queryAccount(contractAddress, blockingStubFull); Assert.assertTrue(account.getBalance() == 1L); Assert.assertTrue(afterNetUsed1 == 0); Assert.assertTrue(afterEnergyUsed1 > 0); Assert.assertTrue(afterFreeNetUsed1 > 0); - //Value is account all balance plus 1. balance is not sufficient,Nothing changde. - AccountResourceMessage resourceInfo2 = PublicMethod.getAccountResource(linkage001Address, - blockingStubFull); + // Value is account all balance plus 1. balance is not sufficient,Nothing changde. + AccountResourceMessage resourceInfo2 = + PublicMethod.getAccountResource(linkage001Address, blockingStubFull); Account info2 = PublicMethod.queryAccount(linkage001Address, blockingStubFull); - Long beforeBalance2 = info2.getBalance(); - Long beforeEnergyLimit2 = resourceInfo2.getEnergyLimit(); - Long beforeEnergyUsed2 = resourceInfo2.getEnergyUsed(); - Long beforeFreeNetLimit2 = resourceInfo2.getFreeNetLimit(); - Long beforeNetLimit2 = resourceInfo2.getNetLimit(); - Long beforeNetUsed2 = resourceInfo2.getNetUsed(); - Long beforeFreeNetUsed2 = resourceInfo2.getFreeNetUsed(); + Long beforeBalance2 = info2.getBalance(); + Long beforeEnergyLimit2 = resourceInfo2.getEnergyLimit(); + Long beforeEnergyUsed2 = resourceInfo2.getEnergyUsed(); + Long beforeFreeNetLimit2 = resourceInfo2.getFreeNetLimit(); + Long beforeNetLimit2 = resourceInfo2.getNetLimit(); + Long beforeNetUsed2 = resourceInfo2.getNetUsed(); + Long beforeFreeNetUsed2 = resourceInfo2.getFreeNetUsed(); logger.info("beforeBalance2:" + beforeBalance2); logger.info("beforeEnergyLimit2:" + beforeEnergyLimit2); logger.info("beforeEnergyUsed2:" + beforeEnergyUsed2); @@ -213,23 +233,33 @@ public void deployContentValue() { logger.info("beforeFreeNetUsed2:" + beforeFreeNetUsed2); account = PublicMethod.queryAccount(linkage001Key, blockingStubFull); - Long valueBalance = account.getBalance(); - contractAddress = PublicMethod.deployContract(contractName, payableAbi, payableCode, "", - maxFeeLimit, valueBalance + 1, 100, null, linkage001Key, - linkage001Address, blockingStubFull); + Long valueBalance = account.getBalance(); + contractAddress = + PublicMethod.deployContract( + contractName, + payableAbi, + payableCode, + "", + maxFeeLimit, + valueBalance + 1, + 100, + null, + linkage001Key, + linkage001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(contractAddress == null); Account infoafter2 = PublicMethod.queryAccount(linkage001Address, blockingStubFull1); - AccountResourceMessage resourceInfoafter2 = PublicMethod.getAccountResource(linkage001Address, - blockingStubFull1); - Long afterBalance2 = infoafter2.getBalance(); - Long afterEnergyLimit2 = resourceInfoafter2.getEnergyLimit(); - Long afterEnergyUsed2 = resourceInfoafter2.getEnergyUsed(); - Long afterFreeNetLimit2 = resourceInfoafter2.getFreeNetLimit(); - Long afterNetLimit2 = resourceInfoafter2.getNetLimit(); - Long afterNetUsed2 = resourceInfoafter2.getNetUsed(); - Long afterFreeNetUsed2 = resourceInfoafter2.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter2 = + PublicMethod.getAccountResource(linkage001Address, blockingStubFull1); + Long afterBalance2 = infoafter2.getBalance(); + Long afterEnergyLimit2 = resourceInfoafter2.getEnergyLimit(); + Long afterEnergyUsed2 = resourceInfoafter2.getEnergyUsed(); + Long afterFreeNetLimit2 = resourceInfoafter2.getFreeNetLimit(); + Long afterNetLimit2 = resourceInfoafter2.getNetLimit(); + Long afterNetUsed2 = resourceInfoafter2.getNetUsed(); + Long afterFreeNetUsed2 = resourceInfoafter2.getFreeNetUsed(); logger.info("afterBalance2:" + afterBalance2); logger.info("afterEnergyLimit2:" + afterEnergyLimit2); logger.info("afterEnergyUsed2:" + afterEnergyUsed2); @@ -241,20 +271,21 @@ public void deployContentValue() { Assert.assertTrue(afterEnergyUsed2 > 0); Assert.assertTrue(afterFreeNetUsed2 > 0); Assert.assertEquals(beforeBalance2, afterBalance2); - //Value is account all balance.use freezeBalanceGetEnergy ,freezeBalanceGetNet .Balance ==0 - Assert.assertTrue(PublicMethod.freezeBalance(linkage001Address, freezeBalance, - 0, linkage001Key, blockingStubFull)); + // Value is account all balance.use freezeBalanceGetEnergy ,freezeBalanceGetNet .Balance ==0 + Assert.assertTrue( + PublicMethod.freezeBalance( + linkage001Address, freezeBalance, 0, linkage001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage resourceInfo3 = PublicMethod.getAccountResource(linkage001Address, - blockingStubFull); + AccountResourceMessage resourceInfo3 = + PublicMethod.getAccountResource(linkage001Address, blockingStubFull); Account info3 = PublicMethod.queryAccount(linkage001Address, blockingStubFull); - Long beforeBalance3 = info3.getBalance(); - Long beforeEnergyLimit3 = resourceInfo3.getEnergyLimit(); - Long beforeEnergyUsed3 = resourceInfo3.getEnergyUsed(); - Long beforeFreeNetLimit3 = resourceInfo3.getFreeNetLimit(); - Long beforeNetLimit3 = resourceInfo3.getNetLimit(); - Long beforeNetUsed3 = resourceInfo3.getNetUsed(); - Long beforeFreeNetUsed3 = resourceInfo3.getFreeNetUsed(); + Long beforeBalance3 = info3.getBalance(); + Long beforeEnergyLimit3 = resourceInfo3.getEnergyLimit(); + Long beforeEnergyUsed3 = resourceInfo3.getEnergyUsed(); + Long beforeFreeNetLimit3 = resourceInfo3.getFreeNetLimit(); + Long beforeNetLimit3 = resourceInfo3.getNetLimit(); + Long beforeNetUsed3 = resourceInfo3.getNetUsed(); + Long beforeFreeNetUsed3 = resourceInfo3.getFreeNetUsed(); logger.info("beforeBalance3:" + beforeBalance3); logger.info("beforeEnergyLimit3:" + beforeEnergyLimit3); logger.info("beforeEnergyUsed3:" + beforeEnergyUsed3); @@ -264,25 +295,34 @@ public void deployContentValue() { logger.info("beforeFreeNetUsed3:" + beforeFreeNetUsed3); account = PublicMethod.queryAccount(linkage001Key, blockingStubFull); valueBalance = account.getBalance(); - txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, payableAbi, payableCode, - "", maxFeeLimit, valueBalance, 100, null, linkage001Key, - linkage001Address, blockingStubFull); + txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + payableAbi, + payableCode, + "", + maxFeeLimit, + valueBalance, + 100, + null, + linkage001Key, + linkage001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); fee = infoById.get().getFee(); Assert.assertTrue(infoById.get().getResultValue() == 0); contractAddress = infoById.get().getContractAddress().toByteArray(); Account infoafter3 = PublicMethod.queryAccount(linkage001Address, blockingStubFull1); - AccountResourceMessage resourceInfoafter3 = PublicMethod.getAccountResource(linkage001Address, - blockingStubFull1); - Long afterBalance3 = infoafter3.getBalance(); - Long afterEnergyLimit3 = resourceInfoafter3.getEnergyLimit(); - Long afterEnergyUsed3 = resourceInfoafter3.getEnergyUsed(); - Long afterFreeNetLimit3 = resourceInfoafter3.getFreeNetLimit(); - Long afterNetLimit3 = resourceInfoafter3.getNetLimit(); - Long afterNetUsed3 = resourceInfoafter3.getNetUsed(); - Long afterFreeNetUsed3 = resourceInfoafter3.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter3 = + PublicMethod.getAccountResource(linkage001Address, blockingStubFull1); + Long afterBalance3 = infoafter3.getBalance(); + Long afterEnergyLimit3 = resourceInfoafter3.getEnergyLimit(); + Long afterEnergyUsed3 = resourceInfoafter3.getEnergyUsed(); + Long afterFreeNetLimit3 = resourceInfoafter3.getFreeNetLimit(); + Long afterNetLimit3 = resourceInfoafter3.getNetLimit(); + Long afterNetUsed3 = resourceInfoafter3.getNetUsed(); + Long afterFreeNetUsed3 = resourceInfoafter3.getFreeNetUsed(); logger.info("afterBalance3:" + afterBalance3); logger.info("afterEnergyLimit3:" + afterEnergyLimit3); logger.info("afterEnergyUsed3:" + afterEnergyUsed3); @@ -296,20 +336,16 @@ public void deployContentValue() { Assert.assertTrue(afterFreeNetUsed3 > 0); Assert.assertTrue(beforeBalance2 - fee == afterBalance2); Assert.assertTrue(afterBalance3 == 0); - Assert.assertTrue(PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance() == valueBalance); - PublicMethod - .unFreezeBalance(linkage001Address, linkage001Key, 1, - linkage001Address, blockingStubFull); + Assert.assertTrue( + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance() == valueBalance); + PublicMethod.unFreezeBalance( + linkage001Address, linkage001Key, 1, linkage001Address, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(linkage001Address, linkage001Key, foundationAddress, blockingStubFull); } + PublicMethod.freeResource( + linkage001Address, linkage001Key, foundationAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractLinkage005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractLinkage005.java index f104d4e6..b772f18f 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractLinkage005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractLinkage005.java @@ -17,10 +17,10 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode @@ -47,44 +47,46 @@ public class ContractLinkage005 extends TronBaseTest { String linkage005Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(linkage005Key); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(linkage005Key); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } - @Test(enabled = true, description = "Every same trigger use same energy and net", groups = {"daily"}) + @Test( + enabled = true, + description = "Every same trigger use same energy and net", + groups = {"daily"}) public void testEnergyCostDetail() { PublicMethod.waitProduceNextBlock(blockingStubFull1); - Assert.assertTrue(PublicMethod.sendcoin(linkage005Address, 5000000000000L, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + linkage005Address, 5000000000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalance(linkage005Address, 250000000000L, - 0, linkage005Key, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(linkage005Address, 250000000000L, - 0, 1, linkage005Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance( + linkage005Address, 250000000000L, 0, linkage005Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + linkage005Address, 250000000000L, 0, 1, linkage005Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(linkage005Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(linkage005Address, blockingStubFull); Account info; info = PublicMethod.queryAccount(linkage005Address, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyLimit = resourceInfo.getEnergyLimit(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeFreeNetLimit = resourceInfo.getFreeNetLimit(); - Long beforeNetLimit = resourceInfo.getNetLimit(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyLimit = resourceInfo.getEnergyLimit(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeFreeNetLimit = resourceInfo.getFreeNetLimit(); + Long beforeNetLimit = resourceInfo.getNetLimit(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyLimit:" + beforeEnergyLimit); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); @@ -92,14 +94,24 @@ public void testEnergyCostDetail() { logger.info("beforeNetLimit:" + beforeNetLimit); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String filePath = "./src/test/resources/soliditycode/contractLinkage005.sol"; - String contractName = "timeoutTest"; + String filePath = "./src/test/resources/soliditycode/contractLinkage005.sol"; + String contractName = "timeoutTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod.deployContractAndGetTransactionInfoById(contractName, abi, code, - "", maxFeeLimit, 0L, 100, null, linkage005Key, - linkage005Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + linkage005Key, + linkage005Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -108,15 +120,15 @@ public void testEnergyCostDetail() { logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); Account infoafter = PublicMethod.queryAccount(linkage005Address, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(linkage005Address, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyLimit = resourceInfoafter.getEnergyLimit(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterFreeNetLimit = resourceInfoafter.getFreeNetLimit(); - Long afterNetLimit = resourceInfoafter.getNetLimit(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(linkage005Address, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyLimit = resourceInfoafter.getEnergyLimit(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterFreeNetLimit = resourceInfoafter.getFreeNetLimit(); + Long afterNetLimit = resourceInfoafter.getNetLimit(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyLimit:" + afterEnergyLimit); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -128,22 +140,22 @@ public void testEnergyCostDetail() { long fee = infoById.get().getFee(); Assert.assertTrue(beforeBalance - fee == afterBalance); - //Assert.assertTrue(afterEnergyUsed > 0); - //Assert.assertTrue(afterFreeNetUsed > 0); + // Assert.assertTrue(afterEnergyUsed > 0); + // Assert.assertTrue(afterFreeNetUsed > 0); firstForCycleTimes = 1000L; secondForCycleTimes = 1002L; thirdForCycleTimes = 1004L; - AccountResourceMessage resourceInfo1 = PublicMethod.getAccountResource(linkage005Address, - blockingStubFull); + AccountResourceMessage resourceInfo1 = + PublicMethod.getAccountResource(linkage005Address, blockingStubFull); Account info1 = PublicMethod.queryAccount(linkage005Address, blockingStubFull); - Long beforeBalance1 = info1.getBalance(); - Long beforeEnergyLimit1 = resourceInfo1.getEnergyLimit(); - Long beforeEnergyUsed1 = resourceInfo1.getEnergyUsed(); - Long beforeFreeNetLimit1 = resourceInfo1.getFreeNetLimit(); - Long beforeNetLimit1 = resourceInfo1.getNetLimit(); - Long beforeNetUsed1 = resourceInfo1.getNetUsed(); - Long beforeFreeNetUsed1 = resourceInfo1.getFreeNetUsed(); + Long beforeBalance1 = info1.getBalance(); + Long beforeEnergyLimit1 = resourceInfo1.getEnergyLimit(); + Long beforeEnergyUsed1 = resourceInfo1.getEnergyUsed(); + Long beforeFreeNetLimit1 = resourceInfo1.getFreeNetLimit(); + Long beforeNetLimit1 = resourceInfo1.getNetLimit(); + Long beforeNetUsed1 = resourceInfo1.getNetUsed(); + Long beforeFreeNetUsed1 = resourceInfo1.getFreeNetUsed(); logger.info("beforeBalance1:" + beforeBalance1); logger.info("beforeEnergyLimit1:" + beforeEnergyLimit1); logger.info("beforeEnergyUsed1:" + beforeEnergyUsed1); @@ -151,22 +163,30 @@ public void testEnergyCostDetail() { logger.info("beforeNetLimit1:" + beforeNetLimit1); logger.info("beforeNetUsed1:" + beforeNetUsed1); logger.info("beforeFreeNetUsed1:" + beforeFreeNetUsed1); - byte[] contractAddress = infoById.get().getContractAddress().toByteArray(); - txid = PublicMethod.triggerContract(contractAddress, - "testUseCpu(uint256)", firstForCycleTimes.toString(), false, - 0, 100000000L, linkage005Address, linkage005Key, blockingStubFull); + byte[] contractAddress = infoById.get().getContractAddress().toByteArray(); + txid = + PublicMethod.triggerContract( + contractAddress, + "testUseCpu(uint256)", + firstForCycleTimes.toString(), + false, + 0, + 100000000L, + linkage005Address, + linkage005Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull1); Account infoafter1 = PublicMethod.queryAccount(linkage005Address, blockingStubFull1); - AccountResourceMessage resourceInfoafter1 = PublicMethod.getAccountResource(linkage005Address, - blockingStubFull1); - Long afterBalance1 = infoafter1.getBalance(); - Long afterEnergyLimit1 = resourceInfoafter1.getEnergyLimit(); - Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); - Long afterFreeNetLimit1 = resourceInfoafter1.getFreeNetLimit(); - Long afterNetLimit1 = resourceInfoafter1.getNetLimit(); - Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); - Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter1 = + PublicMethod.getAccountResource(linkage005Address, blockingStubFull1); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyLimit1 = resourceInfoafter1.getEnergyLimit(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterFreeNetLimit1 = resourceInfoafter1.getFreeNetLimit(); + Long afterNetLimit1 = resourceInfoafter1.getNetLimit(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); logger.info("afterBalance1:" + afterBalance1); logger.info("afterEnergyLimit1:" + afterEnergyLimit1); logger.info("afterEnergyUsed1:" + afterEnergyUsed1); @@ -181,14 +201,30 @@ public void testEnergyCostDetail() { Assert.assertTrue((beforeBalance1 - fee) == afterBalance1); Assert.assertTrue(afterEnergyUsed1 > beforeEnergyUsed1); Assert.assertTrue(afterNetUsed1 > beforeNetUsed1); - //use EnergyUsed and NetUsed.balance not change - - String txid6 = PublicMethod.triggerContract(contractAddress, - "testUseCpu(uint256)", secondForCycleTimes.toString(), false, - 0, 100000000L, linkage005Address, linkage005Key, blockingStubFull); - final String txid7 = PublicMethod.triggerContract(contractAddress, - "testUseCpu(uint256)", thirdForCycleTimes.toString(), false, - 0, 100000000L, linkage005Address, linkage005Key, blockingStubFull); + // use EnergyUsed and NetUsed.balance not change + + String txid6 = + PublicMethod.triggerContract( + contractAddress, + "testUseCpu(uint256)", + secondForCycleTimes.toString(), + false, + 0, + 100000000L, + linkage005Address, + linkage005Key, + blockingStubFull); + final String txid7 = + PublicMethod.triggerContract( + contractAddress, + "testUseCpu(uint256)", + thirdForCycleTimes.toString(), + false, + 0, + 100000000L, + linkage005Address, + linkage005Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -198,8 +234,8 @@ public void testEnergyCostDetail() { infoById = PublicMethod.getTransactionInfoById(txid7, blockingStubFull); thirdForCycleCost = infoById.get().getReceipt().getEnergyUsageTotal(); - Assert.assertTrue(thirdForCycleCost - secondForCycleCost - == secondForCycleCost - firstForCycleCost); + Assert.assertTrue( + thirdForCycleCost - secondForCycleCost == secondForCycleCost - firstForCycleCost); zeroForCycleTimes = 498L; firstForCycleTimes = 500L; @@ -207,16 +243,16 @@ public void testEnergyCostDetail() { thirdForCycleTimes = 504L; forthForCycleTimes = 506L; fifthForCycleTimes = 508L; - AccountResourceMessage resourceInfo4 = PublicMethod.getAccountResource(linkage005Address, - blockingStubFull); + AccountResourceMessage resourceInfo4 = + PublicMethod.getAccountResource(linkage005Address, blockingStubFull); Account info4 = PublicMethod.queryAccount(linkage005Address, blockingStubFull); - Long beforeBalance4 = info4.getBalance(); - Long beforeEnergyLimit4 = resourceInfo4.getEnergyLimit(); - Long beforeEnergyUsed4 = resourceInfo4.getEnergyUsed(); - Long beforeFreeNetLimit4 = resourceInfo4.getFreeNetLimit(); - Long beforeNetLimit4 = resourceInfo4.getNetLimit(); - Long beforeNetUsed4 = resourceInfo4.getNetUsed(); - Long beforeFreeNetUsed4 = resourceInfo4.getFreeNetUsed(); + Long beforeBalance4 = info4.getBalance(); + Long beforeEnergyLimit4 = resourceInfo4.getEnergyLimit(); + Long beforeEnergyUsed4 = resourceInfo4.getEnergyUsed(); + Long beforeFreeNetLimit4 = resourceInfo4.getFreeNetLimit(); + Long beforeNetLimit4 = resourceInfo4.getNetLimit(); + Long beforeNetUsed4 = resourceInfo4.getNetUsed(); + Long beforeFreeNetUsed4 = resourceInfo4.getFreeNetUsed(); logger.info("beforeBalance4:" + beforeBalance4); logger.info("beforeEnergyLimit4:" + beforeEnergyLimit4); logger.info("beforeEnergyUsed4:" + beforeEnergyUsed4); @@ -224,24 +260,32 @@ public void testEnergyCostDetail() { logger.info("beforeNetLimit4:" + beforeNetLimit4); logger.info("beforeNetUsed4:" + beforeNetUsed4); logger.info("beforeFreeNetUsed4:" + beforeFreeNetUsed4); - txid = PublicMethod.triggerContract(contractAddress, - "testUseStorage(uint256)", zeroForCycleTimes.toString(), false, - 0, 1000000000L, linkage005Address, linkage005Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "testUseStorage(uint256)", + zeroForCycleTimes.toString(), + false, + 0, + 1000000000L, + linkage005Address, + linkage005Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); fee = infoById.get().getFee(); Account infoAfter4 = PublicMethod.queryAccount(linkage005Address, blockingStubFull1); - AccountResourceMessage resourceInfoAfter4 = PublicMethod.getAccountResource(linkage005Address, - blockingStubFull1); - Long afterBalance4 = infoAfter4.getBalance(); - Long afterEnergyLimit4 = resourceInfoAfter4.getEnergyLimit(); - Long afterEnergyUsed4 = resourceInfoAfter4.getEnergyUsed(); - Long afterFreeNetLimit4 = resourceInfoAfter4.getFreeNetLimit(); - Long afterNetLimit4 = resourceInfoAfter4.getNetLimit(); - Long afterNetUsed4 = resourceInfoAfter4.getNetUsed(); - Long afterFreeNetUsed4 = resourceInfoAfter4.getFreeNetUsed(); + AccountResourceMessage resourceInfoAfter4 = + PublicMethod.getAccountResource(linkage005Address, blockingStubFull1); + Long afterBalance4 = infoAfter4.getBalance(); + Long afterEnergyLimit4 = resourceInfoAfter4.getEnergyLimit(); + Long afterEnergyUsed4 = resourceInfoAfter4.getEnergyUsed(); + Long afterFreeNetLimit4 = resourceInfoAfter4.getFreeNetLimit(); + Long afterNetLimit4 = resourceInfoAfter4.getNetLimit(); + Long afterNetUsed4 = resourceInfoAfter4.getNetUsed(); + Long afterFreeNetUsed4 = resourceInfoAfter4.getFreeNetUsed(); logger.info("afterBalance4:" + afterBalance4); logger.info("afterEnergyLimit4:" + afterEnergyLimit4); logger.info("afterEnergyUsed4:" + afterEnergyUsed4); @@ -256,21 +300,61 @@ public void testEnergyCostDetail() { infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); zeroForCycleCost = infoById.get().getReceipt().getEnergyUsageTotal(); - String txid1 = PublicMethod.triggerContract(contractAddress, - "testUseStorage(uint256)", firstForCycleTimes.toString(), false, - 0, 100000000L, linkage005Address, linkage005Key, blockingStubFull); - final String txid2 = PublicMethod.triggerContract(contractAddress, - "testUseStorage(uint256)", secondForCycleTimes.toString(), false, - 0, 100000000L, linkage005Address, linkage005Key, blockingStubFull); - final String txid3 = PublicMethod.triggerContract(contractAddress, - "testUseStorage(uint256)", thirdForCycleTimes.toString(), false, - 0, 100000000L, linkage005Address, linkage005Key, blockingStubFull); - final String txid4 = PublicMethod.triggerContract(contractAddress, - "testUseStorage(uint256)", forthForCycleTimes.toString(), false, - 0, 100000000L, linkage005Address, linkage005Key, blockingStubFull); - final String txid5 = PublicMethod.triggerContract(contractAddress, - "testUseStorage(uint256)", fifthForCycleTimes.toString(), false, - 0, 100000000L, linkage005Address, linkage005Key, blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + contractAddress, + "testUseStorage(uint256)", + firstForCycleTimes.toString(), + false, + 0, + 100000000L, + linkage005Address, + linkage005Key, + blockingStubFull); + final String txid2 = + PublicMethod.triggerContract( + contractAddress, + "testUseStorage(uint256)", + secondForCycleTimes.toString(), + false, + 0, + 100000000L, + linkage005Address, + linkage005Key, + blockingStubFull); + final String txid3 = + PublicMethod.triggerContract( + contractAddress, + "testUseStorage(uint256)", + thirdForCycleTimes.toString(), + false, + 0, + 100000000L, + linkage005Address, + linkage005Key, + blockingStubFull); + final String txid4 = + PublicMethod.triggerContract( + contractAddress, + "testUseStorage(uint256)", + forthForCycleTimes.toString(), + false, + 0, + 100000000L, + linkage005Address, + linkage005Key, + blockingStubFull); + final String txid5 = + PublicMethod.triggerContract( + contractAddress, + "testUseStorage(uint256)", + fifthForCycleTimes.toString(), + false, + 0, + 100000000L, + linkage005Address, + linkage005Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -289,30 +373,23 @@ public void testEnergyCostDetail() { infoById = PublicMethod.getTransactionInfoById(txid5, blockingStubFull); fifthForCycleCost = infoById.get().getReceipt().getEnergyUsageTotal(); - Assert.assertTrue(thirdForCycleCost - secondForCycleCost - == secondForCycleCost - firstForCycleCost); - Assert.assertTrue(fifthForCycleCost - forthForCycleCost - == forthForCycleCost - thirdForCycleCost); - - + Assert.assertTrue( + thirdForCycleCost - secondForCycleCost == secondForCycleCost - firstForCycleCost); + Assert.assertTrue( + fifthForCycleCost - forthForCycleCost == forthForCycleCost - thirdForCycleCost); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.unFreezeBalance(linkage005Address, linkage005Key, 1, - linkage005Address, blockingStubFull); - PublicMethod.unFreezeBalance(linkage005Address, linkage005Key, 0, - linkage005Address, blockingStubFull); - PublicMethod.freeResource(linkage005Address, linkage005Key, foundationAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.unFreezeBalance( + linkage005Address, linkage005Key, 1, linkage005Address, blockingStubFull); + PublicMethod.unFreezeBalance( + linkage005Address, linkage005Key, 0, linkage005Address, blockingStubFull); + PublicMethod.freeResource( + linkage005Address, linkage005Key, foundationAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - - } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractLinkage006.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractLinkage006.java index b8323137..f32f8c4e 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractLinkage006.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractLinkage006.java @@ -17,17 +17,17 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class ContractLinkage006 extends TronBaseTest { - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey003); String contractName; String code; @@ -42,48 +42,50 @@ public class ContractLinkage006 extends TronBaseTest { ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] linkage006Address2 = ecKey2.getAddress(); String linkage006Key2 = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(linkage006Key); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(linkage006Key); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } - @Test(enabled = true, description = "Deploy contract with stack function", groups = {"daily"}) + @Test( + enabled = true, + description = "Deploy contract with stack function", + groups = {"daily"}) public void teststackOutByContract() { - Assert.assertTrue(PublicMethod.sendcoin(linkage006Address, 20000000000L, fromAddress, - testKey003, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + linkage006Address, 20000000000L, fromAddress, testKey003, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalance(linkage006Address, 1000000L, - 0, linkage006Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance( + linkage006Address, 1000000L, 0, linkage006Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(linkage006Address, 1000000L, - 0, 1, linkage006Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + linkage006Address, 1000000L, 0, 1, linkage006Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(linkage006Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(linkage006Address, blockingStubFull); Account info; info = PublicMethod.queryAccount(linkage006Address, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyLimit = resourceInfo.getEnergyLimit(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeFreeNetLimit = resourceInfo.getFreeNetLimit(); - Long beforeNetLimit = resourceInfo.getNetLimit(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyLimit = resourceInfo.getEnergyLimit(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeFreeNetLimit = resourceInfo.getFreeNetLimit(); + Long beforeNetLimit = resourceInfo.getNetLimit(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyLimit:" + beforeEnergyLimit); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); @@ -91,26 +93,35 @@ public void teststackOutByContract() { logger.info("beforeNetLimit:" + beforeNetLimit); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String filePath = "./src/test/resources/soliditycode/contractLinkage006.sol"; - String contractName = "AA"; + String filePath = "./src/test/resources/soliditycode/contractLinkage006.sol"; + String contractName = "AA"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - //success ,balnace change.use EnergyUsed and NetUsed - txid = PublicMethod.deployContractAndGetTransactionInfoById(contractName, abi, code, - "", maxFeeLimit, 1000L, 100, null, linkage006Key, - linkage006Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + // success ,balnace change.use EnergyUsed and NetUsed + txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000L, + 100, + null, + linkage006Key, + linkage006Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("txid is " + txid); contractAddress = infoById.get().getContractAddress().toByteArray(); - Long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); - Long fee = infoById.get().getFee(); - Long energyFee = infoById.get().getReceipt().getEnergyFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + Long fee = infoById.get().getFee(); + Long energyFee = infoById.get().getReceipt().getEnergyFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); logger.info("energyUsageTotal:" + energyUsageTotal); logger.info("fee:" + fee); logger.info("energyFee:" + energyFee); @@ -118,15 +129,15 @@ public void teststackOutByContract() { logger.info("energyUsed:" + energyUsed); logger.info("netFee:" + netFee); Account infoafter = PublicMethod.queryAccount(linkage006Address, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(linkage006Address, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyLimit = resourceInfoafter.getEnergyLimit(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterFreeNetLimit = resourceInfoafter.getFreeNetLimit(); - Long afterNetLimit = resourceInfoafter.getNetLimit(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(linkage006Address, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyLimit = resourceInfoafter.getEnergyLimit(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterFreeNetLimit = resourceInfoafter.getFreeNetLimit(); + Long afterNetLimit = resourceInfoafter.getNetLimit(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyLimit:" + afterEnergyLimit); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -139,31 +150,36 @@ public void teststackOutByContract() { Assert.assertTrue((beforeBalance - fee - 1000L) == afterBalance); Assert.assertTrue((beforeNetUsed + netUsed) >= afterNetUsed); Assert.assertTrue((beforeEnergyUsed + energyUsed) >= afterEnergyUsed); - PublicMethod.unFreezeBalance(linkage006Address, linkage006Key, 1, - null, blockingStubFull); + PublicMethod.unFreezeBalance(linkage006Address, linkage006Key, 1, null, blockingStubFull); } - @Test(enabled = true, description = "Boundary value for contract stack(63 is the largest level)", groups = {"daily"}) + @Test( + enabled = true, + description = "Boundary value for contract stack(63 is the largest level)", + groups = {"daily"}) public void teststackOutByContract1() { - Assert.assertTrue(PublicMethod.sendcoin(linkage006Address2, 20000000000L, fromAddress, - testKey003, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + linkage006Address2, 20000000000L, fromAddress, testKey003, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalance(linkage006Address2, 1000000L, - 0, linkage006Key2, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance( + linkage006Address2, 1000000L, 0, linkage006Key2, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(linkage006Address2, 1000000L, - 0, 1, linkage006Key2, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + linkage006Address2, 1000000L, 0, 1, linkage006Key2, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage resourceInfo1 = PublicMethod.getAccountResource(linkage006Address2, - blockingStubFull); + AccountResourceMessage resourceInfo1 = + PublicMethod.getAccountResource(linkage006Address2, blockingStubFull); Account info1 = PublicMethod.queryAccount(linkage006Address2, blockingStubFull); - Long beforeBalance1 = info1.getBalance(); - Long beforeEnergyLimit1 = resourceInfo1.getEnergyLimit(); - Long beforeEnergyUsed1 = resourceInfo1.getEnergyUsed(); - Long beforeFreeNetLimit1 = resourceInfo1.getFreeNetLimit(); - Long beforeNetLimit1 = resourceInfo1.getNetLimit(); - Long beforeNetUsed1 = resourceInfo1.getNetUsed(); - Long beforeFreeNetUsed1 = resourceInfo1.getFreeNetUsed(); + Long beforeBalance1 = info1.getBalance(); + Long beforeEnergyLimit1 = resourceInfo1.getEnergyLimit(); + Long beforeEnergyUsed1 = resourceInfo1.getEnergyUsed(); + Long beforeFreeNetLimit1 = resourceInfo1.getFreeNetLimit(); + Long beforeNetLimit1 = resourceInfo1.getNetLimit(); + Long beforeNetUsed1 = resourceInfo1.getNetUsed(); + Long beforeFreeNetUsed1 = resourceInfo1.getFreeNetUsed(); logger.info("beforeBalance1:" + beforeBalance1); logger.info("beforeEnergyLimit1:" + beforeEnergyLimit1); logger.info("beforeEnergyUsed1:" + beforeEnergyUsed1); @@ -171,21 +187,29 @@ public void teststackOutByContract1() { logger.info("beforeNetLimit1:" + beforeNetLimit1); logger.info("beforeNetUsed1:" + beforeNetUsed1); logger.info("beforeFreeNetUsed1:" + beforeFreeNetUsed1); - //success ,balance change.use EnergyUsed and NetUsed + // success ,balance change.use EnergyUsed and NetUsed initParmes = "\"" + Base58.encode58Check(fromAddress) + "\",\"63\""; - txid = PublicMethod.triggerContract(contractAddress, - "init(address,uint256)", initParmes, false, - 0, 2000000000L, linkage006Address2, linkage006Key2, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "init(address,uint256)", + initParmes, + false, + 0, + 2000000000L, + linkage006Address2, + linkage006Key2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById1 = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - Long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); - Long fee1 = infoById1.get().getFee(); - Long energyFee1 = infoById1.get().getReceipt().getEnergyFee(); - Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); - Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); - Long netFee1 = infoById1.get().getReceipt().getNetFee(); + Optional infoById1 = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); + Long fee1 = infoById1.get().getFee(); + Long energyFee1 = infoById1.get().getReceipt().getEnergyFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); logger.info("energyUsageTotal1:" + energyUsageTotal1); logger.info("fee1:" + fee1); logger.info("energyFee1:" + energyFee1); @@ -193,16 +217,15 @@ public void teststackOutByContract1() { logger.info("energyUsed1:" + energyUsed1); logger.info("netFee1:" + netFee1); Account infoafter1 = PublicMethod.queryAccount(linkage006Address2, blockingStubFull1); - AccountResourceMessage resourceInfoafter1 = PublicMethod - .getAccountResource(linkage006Address2, - blockingStubFull1); - Long afterBalance1 = infoafter1.getBalance(); - Long afterEnergyLimit1 = resourceInfoafter1.getEnergyLimit(); - Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); - Long afterFreeNetLimit1 = resourceInfoafter1.getFreeNetLimit(); - Long afterNetLimit1 = resourceInfoafter1.getNetLimit(); - Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); - Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter1 = + PublicMethod.getAccountResource(linkage006Address2, blockingStubFull1); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyLimit1 = resourceInfoafter1.getEnergyLimit(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterFreeNetLimit1 = resourceInfoafter1.getFreeNetLimit(); + Long afterNetLimit1 = resourceInfoafter1.getNetLimit(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); logger.info("afterBalance1:" + afterBalance1); logger.info("afterEnergyLimit1:" + afterEnergyLimit1); logger.info("afterEnergyUsed1:" + afterEnergyUsed1); @@ -219,21 +242,23 @@ public void teststackOutByContract1() { Assert.assertTrue(infoById.get().getResultValue() == 0); } - @Test(enabled = true, description = "Boundary value for contract stack" - + "(Trigger 64 level can't success)", groups = {"daily"}) + @Test( + enabled = true, + description = "Boundary value for contract stack" + "(Trigger 64 level can't success)", + groups = {"daily"}) public void teststackOutByContract2() { PublicMethod.waitProduceNextBlock(blockingStubFull); initParmes = "\"" + Base58.encode58Check(fromAddress) + "\",\"64\""; - AccountResourceMessage resourceInfo2 = PublicMethod.getAccountResource(linkage006Address2, - blockingStubFull); + AccountResourceMessage resourceInfo2 = + PublicMethod.getAccountResource(linkage006Address2, blockingStubFull); Account info2 = PublicMethod.queryAccount(linkage006Address2, blockingStubFull); - Long beforeBalance2 = info2.getBalance(); - Long beforeEnergyLimit2 = resourceInfo2.getEnergyLimit(); - Long beforeEnergyUsed2 = resourceInfo2.getEnergyUsed(); - Long beforeFreeNetLimit2 = resourceInfo2.getFreeNetLimit(); - Long beforeNetLimit2 = resourceInfo2.getNetLimit(); - Long beforeNetUsed2 = resourceInfo2.getNetUsed(); - Long beforeFreeNetUsed2 = resourceInfo2.getFreeNetUsed(); + Long beforeBalance2 = info2.getBalance(); + Long beforeEnergyLimit2 = resourceInfo2.getEnergyLimit(); + Long beforeEnergyUsed2 = resourceInfo2.getEnergyUsed(); + Long beforeFreeNetLimit2 = resourceInfo2.getFreeNetLimit(); + Long beforeNetLimit2 = resourceInfo2.getNetLimit(); + Long beforeNetUsed2 = resourceInfo2.getNetUsed(); + Long beforeFreeNetUsed2 = resourceInfo2.getFreeNetUsed(); logger.info("beforeBalance2:" + beforeBalance2); logger.info("beforeEnergyLimit2:" + beforeEnergyLimit2); logger.info("beforeEnergyUsed2:" + beforeEnergyUsed2); @@ -241,20 +266,28 @@ public void teststackOutByContract2() { logger.info("beforeNetLimit2:" + beforeNetLimit2); logger.info("beforeNetUsed2:" + beforeNetUsed2); logger.info("beforeFreeNetUsed2:" + beforeFreeNetUsed2); - //failed ,use EnergyUsed and NetUsed - txid = PublicMethod.triggerContract(contractAddress, - "init(address,uint256)", initParmes, false, - 1000, 100000000L, linkage006Address2, linkage006Key2, blockingStubFull); + // failed ,use EnergyUsed and NetUsed + txid = + PublicMethod.triggerContract( + contractAddress, + "init(address,uint256)", + initParmes, + false, + 1000, + 100000000L, + linkage006Address2, + linkage006Key2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById2 = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - Long energyUsageTotal2 = infoById2.get().getReceipt().getEnergyUsageTotal(); - Long fee2 = infoById2.get().getFee(); - Long energyFee2 = infoById2.get().getReceipt().getEnergyFee(); - Long netUsed2 = infoById2.get().getReceipt().getNetUsage(); - Long energyUsed2 = infoById2.get().getReceipt().getEnergyUsage(); - Long netFee2 = infoById2.get().getReceipt().getNetFee(); + Optional infoById2 = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Long energyUsageTotal2 = infoById2.get().getReceipt().getEnergyUsageTotal(); + Long fee2 = infoById2.get().getFee(); + Long energyFee2 = infoById2.get().getReceipt().getEnergyFee(); + Long netUsed2 = infoById2.get().getReceipt().getNetUsage(); + Long energyUsed2 = infoById2.get().getReceipt().getEnergyUsage(); + Long netFee2 = infoById2.get().getReceipt().getNetFee(); logger.info("energyUsageTotal2:" + energyUsageTotal2); logger.info("fee2:" + fee2); logger.info("energyFee2:" + energyFee2); @@ -263,15 +296,15 @@ public void teststackOutByContract2() { logger.info("netFee2:" + netFee2); Account infoafter2 = PublicMethod.queryAccount(linkage006Address2, blockingStubFull1); - AccountResourceMessage resourceInfoafter2 = PublicMethod.getAccountResource(linkage006Address2, - blockingStubFull1); - Long afterBalance2 = infoafter2.getBalance(); - Long afterEnergyLimit2 = resourceInfoafter2.getEnergyLimit(); - Long afterEnergyUsed2 = resourceInfoafter2.getEnergyUsed(); - Long afterFreeNetLimit2 = resourceInfoafter2.getFreeNetLimit(); - Long afterNetLimit2 = resourceInfoafter2.getNetLimit(); - Long afterNetUsed2 = resourceInfoafter2.getNetUsed(); - Long afterFreeNetUsed2 = resourceInfoafter2.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter2 = + PublicMethod.getAccountResource(linkage006Address2, blockingStubFull1); + Long afterBalance2 = infoafter2.getBalance(); + Long afterEnergyLimit2 = resourceInfoafter2.getEnergyLimit(); + Long afterEnergyUsed2 = resourceInfoafter2.getEnergyUsed(); + Long afterFreeNetLimit2 = resourceInfoafter2.getFreeNetLimit(); + Long afterNetLimit2 = resourceInfoafter2.getNetLimit(); + Long afterNetUsed2 = resourceInfoafter2.getNetUsed(); + Long afterFreeNetUsed2 = resourceInfoafter2.getFreeNetUsed(); logger.info("afterBalance2:" + afterBalance2); logger.info("afterEnergyLimit2:" + afterEnergyLimit2); logger.info("afterEnergyUsed2:" + afterEnergyUsed2); @@ -284,28 +317,22 @@ public void teststackOutByContract2() { Assert.assertTrue((beforeEnergyUsed2 + energyUsed2) >= afterEnergyUsed2); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 1); - PublicMethod.unFreezeBalance(linkage006Address2, linkage006Key2, 1, - linkage006Address2, blockingStubFull); + PublicMethod.unFreezeBalance( + linkage006Address2, linkage006Key2, 1, linkage006Address2, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.unFreezeBalance(linkage006Address, linkage006Key, 1, - linkage006Address, blockingStubFull); - PublicMethod.unFreezeBalance(linkage006Address, linkage006Key, 0, - linkage006Address, blockingStubFull); - PublicMethod.unFreezeBalance(linkage006Address2, linkage006Key2, 1, - linkage006Address2, blockingStubFull); - PublicMethod.unFreezeBalance(linkage006Address2, linkage006Key2, 0, - linkage006Address2, blockingStubFull); + PublicMethod.unFreezeBalance( + linkage006Address, linkage006Key, 1, linkage006Address, blockingStubFull); + PublicMethod.unFreezeBalance( + linkage006Address, linkage006Key, 0, linkage006Address, blockingStubFull); + PublicMethod.unFreezeBalance( + linkage006Address2, linkage006Key2, 1, linkage006Address2, blockingStubFull); + PublicMethod.unFreezeBalance( + linkage006Address2, linkage006Key2, 0, linkage006Address2, blockingStubFull); PublicMethod.freeResource(linkage006Address, linkage006Key, fromAddress, blockingStubFull); - PublicMethod.freeResource(linkage006Address2, linkage006Key2, fromAddress, blockingStubFull); } - - + PublicMethod.freeResource(linkage006Address2, linkage006Key2, fromAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario002.java index a86ccec5..3c04aec3 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario002.java @@ -18,14 +18,15 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode -public class ContractScenario002 extends TronBaseTest { ECKey ecKey1 = new ECKey(Utils.getRandom()); +public class ContractScenario002 extends TronBaseTest { + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contract002Address = ecKey1.getAddress(); String contract002Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private String txid; @@ -33,86 +34,91 @@ public class ContractScenario002 extends TronBaseTest { ECKey ecKey1 = new ECKe private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSoliInFull = null; private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - private String soliInFullnode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1); - private String soliInPbft = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(2); - - /** - * constructor. - */ - + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + private String soliInFullnode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); + private String soliInPbft = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(2); + + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initPbftChannel(); initSolidityChannel(); - PublicMethod.printAddress(contract002Key); channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - channelSoliInFull = ManagedChannelBuilder.forTarget(soliInFullnode) - .usePlaintext() - .build(); + PublicMethod.printAddress(contract002Key); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + channelSoliInFull = ManagedChannelBuilder.forTarget(soliInFullnode).usePlaintext().build(); blockingStubSoliInFull = WalletSolidityGrpc.newBlockingStub(channelSoliInFull); - channelPbft = ManagedChannelBuilder.forTarget(soliInPbft) - .usePlaintext() - .build(); - channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + channelPbft = ManagedChannelBuilder.forTarget(soliInPbft).usePlaintext().build(); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - } - @Test(enabled = true, description = "Deploy contract with java-tron support interface", groups = {"daily"}) + @Test( + enabled = true, + description = "Deploy contract with java-tron support interface", + groups = {"daily"}) public void test01DeployTronNative() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] contract002Address = ecKey1.getAddress(); - String contract002Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + byte[] contract002Address = ecKey1.getAddress(); + String contract002Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(contract002Address, 500000000L, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + contract002Address, 500000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(contract002Address, 1000000L, - 0, 1, contract002Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + contract002Address, 1000000L, 0, 1, contract002Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(contract002Address, - blockingStubFull); - Long energyLimit = accountResource.getEnergyLimit(); - Long energyUsage = accountResource.getEnergyUsed(); - Long balanceBefore = PublicMethod.queryAccount(contract002Key, blockingStubFull).getBalance(); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(contract002Address, blockingStubFull); + Long energyLimit = accountResource.getEnergyLimit(); + Long energyUsage = accountResource.getEnergyUsed(); + Long balanceBefore = PublicMethod.queryAccount(contract002Key, blockingStubFull).getBalance(); logger.info("before energy limit is " + Long.toString(energyLimit)); logger.info("before energy usage is " + Long.toString(energyUsage)); logger.info("before balance is " + Long.toString(balanceBefore)); - String contractName = "TronNative"; - String filePath = "./src/test/resources/soliditycode/contractScenario002.sol"; + String contractName = "TronNative"; + String filePath = "./src/test/resources/soliditycode/contractScenario002.sol"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - txid = PublicMethod.deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 100, null, contract002Key, contract002Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contract002Key, + contract002Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull1); logger.info(txid); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); com.google.protobuf.ByteString contractAddress = infoById.get().getContractAddress(); - SmartContract smartContract = PublicMethod - .getContract(contractAddress.toByteArray(), blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(contractAddress.toByteArray(), blockingStubFull); Assert.assertTrue(smartContract.getAbi() != null); PublicMethod.waitProduceNextBlock(blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(contract002Address, blockingStubFull1); energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); - Long balanceAfter = PublicMethod.queryAccount(contract002Address, blockingStubFull1) - .getBalance(); + Long balanceAfter = + PublicMethod.queryAccount(contract002Address, blockingStubFull1).getBalance(); logger.info("after energy limit is " + Long.toString(energyLimit)); logger.info("after energy usage is " + Long.toString(energyUsage)); @@ -121,15 +127,15 @@ public void test01DeployTronNative() { Assert.assertTrue(energyUsage > 0); Assert.assertTrue(balanceBefore == balanceAfter + infoById.get().getFee()); - PublicMethod.unFreezeBalance(contract002Address, contract002Key, 1, - contract002Address, blockingStubFull); - + PublicMethod.unFreezeBalance( + contract002Address, contract002Key, 1, contract002Address, blockingStubFull); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get smart contract with invalid address", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get smart contract with invalid address", + groups = {"daily"}) public void test02GetContractWithInvalidAddress() { byte[] contractAddress = contract002Address; SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); @@ -137,65 +143,88 @@ public void test02GetContractWithInvalidAddress() { Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get transaction by id from solidity", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get transaction by id from solidity", + groups = {"daily"}) public void test03GetTransactionByIdFromSolidity() { - Assert.assertFalse(PublicMethod.getTransactionById(txid, blockingStubSolidity) - .get().getSignature(0).isEmpty()); - Assert.assertEquals(PublicMethod.getTransactionById(txid, blockingStubFull), + Assert.assertFalse( + PublicMethod.getTransactionById(txid, blockingStubSolidity) + .get() + .getSignature(0) + .isEmpty()); + Assert.assertEquals( + PublicMethod.getTransactionById(txid, blockingStubFull), PublicMethod.getTransactionById(txid, blockingStubSolidity)); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get transaction by id from PBFT", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get transaction by id from PBFT", + groups = {"daily"}) public void test04GetTransactionByIdFromPbft() { - Assert.assertFalse(PublicMethod.getTransactionById(txid, blockingStubPbft) - .get().getSignature(0).isEmpty()); - Assert.assertEquals(PublicMethod.getTransactionById(txid, blockingStubSoliInFull), + Assert.assertFalse( + PublicMethod.getTransactionById(txid, blockingStubPbft).get().getSignature(0).isEmpty()); + Assert.assertEquals( + PublicMethod.getTransactionById(txid, blockingStubSoliInFull), PublicMethod.getTransactionById(txid, blockingStubPbft)); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get transaction by id from Solidity", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get transaction by id from Solidity", + groups = {"daily"}) public void test05GetTransactionInfoByIdFromSolidity() throws Exception { - long netUsage = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get().getReceipt() - .getNetUsage(); - - Assert.assertEquals(PublicMethod.getTransactionInfoByIdFromSolidity(txid, blockingStubSolidity) - .get().getReceipt().getNetUsage(), netUsage); - - Assert - .assertEquals(PublicMethod.getTransactionInfoByIdFromSolidity(txid, blockingStubSoliInFull) - .get().getReceipt().getNetUsage(), netUsage); + long netUsage = + PublicMethod.getTransactionInfoById(txid, blockingStubFull) + .get() + .getReceipt() + .getNetUsage(); + + Assert.assertEquals( + PublicMethod.getTransactionInfoByIdFromSolidity(txid, blockingStubSolidity) + .get() + .getReceipt() + .getNetUsage(), + netUsage); + + Assert.assertEquals( + PublicMethod.getTransactionInfoByIdFromSolidity(txid, blockingStubSoliInFull) + .get() + .getReceipt() + .getNetUsage(), + netUsage); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get transaction by id from PBFT", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get transaction by id from PBFT", + groups = {"daily"}) public void test06GetTransactionInfoByIdFromPbft() { - long energyUsage = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get() - .getReceipt() - .getEnergyUsage(); - - Assert.assertEquals(PublicMethod.getTransactionInfoByIdFromSolidity(txid, blockingStubPbft) - .get().getReceipt().getEnergyUsage(), energyUsage); + long energyUsage = + PublicMethod.getTransactionInfoById(txid, blockingStubFull) + .get() + .getReceipt() + .getEnergyUsage(); + + Assert.assertEquals( + PublicMethod.getTransactionInfoByIdFromSolidity(txid, blockingStubPbft) + .get() + .getReceipt() + .getEnergyUsage(), + energyUsage); } - - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contract002Address, contract002Key, foundationAddress, blockingStubFull); if (channelSoliInFull != null) { + PublicMethod.freeResource( + contract002Address, contract002Key, foundationAddress, blockingStubFull); + if (channelSoliInFull != null) { channelSoliInFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario011.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario011.java index 78b83827..1237355f 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario011.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario011.java @@ -16,13 +16,19 @@ import org.tron.protos.Protocol.TransactionInfo; import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; -import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.ProposalEnum; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode -public class ContractScenario011 extends TronBaseTest { String kittyCoreAddressAndCut = ""; +public class ContractScenario011 extends TronBaseTest { + String kittyCoreAddressAndCut = ""; byte[] kittyCoreContractAddress = null; byte[] saleClockAuctionContractAddress = null; byte[] siringClockAuctionContractAddress = null; @@ -38,66 +44,80 @@ public class ContractScenario011 extends TronBaseTest { String kittyCoreAddress String triggerKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private Long energyFee = 0L; private double feeLimitRate = 1.0; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(deployKey); - PublicMethod.printAddress(triggerKey); Assert.assertTrue(PublicMethod.sendcoin(deployAddress, 50000000000L, foundationAddress, - foundationKey, blockingStubFull)); + PublicMethod.printAddress(triggerKey); + Assert.assertTrue( + PublicMethod.sendcoin( + deployAddress, 50000000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.sendcoin(triggerAddress, 50000000000L, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + triggerAddress, 50000000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - energyFee = PublicMethod.getChainParametersValue(ProposalEnum.GetEnergyFee.getProposalName(), blockingStubFull); + energyFee = + PublicMethod.getChainParametersValue( + ProposalEnum.GetEnergyFee.getProposalName(), blockingStubFull); feeLimitRate = energyFee / 280.0; } - @Test(enabled = true, description = "Deploy Erc721 contract \"Kitty Core\"", groups = {"daily"}) + @Test( + enabled = true, + description = "Deploy Erc721 contract \"Kitty Core\"", + groups = {"daily"}) public void deployErc721KittyCore() { - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(deployAddress, 3000000000L, - 0, 1, deployKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + deployAddress, 3000000000L, 0, 1, deployKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull1); - Assert.assertTrue(PublicMethod.freezeBalance(deployAddress, 6000000000L, 0, - deployKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance(deployAddress, 6000000000L, 0, deployKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull1); - Assert.assertTrue(PublicMethod.freezeBalance(triggerAddress, 6000000000L, 0, - triggerKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance(triggerAddress, 6000000000L, 0, triggerKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull1); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(deployAddress, - blockingStubFull); - Long cpuLimit = accountResource.getEnergyLimit(); - Long cpuUsage = accountResource.getEnergyUsed(); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(deployAddress, blockingStubFull); + Long cpuLimit = accountResource.getEnergyLimit(); + Long cpuUsage = accountResource.getEnergyUsed(); Account account = PublicMethod.queryAccount(deployAddress, blockingStubFull); logger.info("before balance is " + Long.toString(account.getBalance())); logger.info("before cpu limit is " + Long.toString(cpuLimit)); logger.info("before cpu usage is " + Long.toString(cpuUsage)); - String contractName = "KittyCore"; - String filePath = "./src/test/resources/soliditycode/contractScenario011.sol"; + String contractName = "KittyCore"; + String filePath = "./src/test/resources/soliditycode/contractScenario011.sol"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); logger.info("Kitty Core"); - kittyCoreContractAddress = PublicMethod.deployContract(contractName, abi, code, "", - maxFeeLimit, 0L, consumeUserResourcePercent, null, deployKey, - deployAddress, blockingStubFull); + kittyCoreContractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + consumeUserResourcePercent, + null, + deployKey, + deployAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethod.getContract(kittyCoreContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(kittyCoreContractAddress, blockingStubFull); Assert.assertFalse(StringUtils.isEmpty(smartContract.getBytecode())); Assert.assertTrue(smartContract.getAbi() != null); @@ -111,43 +131,59 @@ public void deployErc721KittyCore() { logger.info(ByteArray.toHexString(kittyCoreContractAddress)); logger.info(ByteArray.toHexString(kittyCoreContractAddress).substring(2)); - kittyCoreAddressAndCut = "000000000000000000000000" + ByteArray - .toHexString(kittyCoreContractAddress).substring(2); - kittyCoreAddressAndCut = kittyCoreAddressAndCut + "0000000000000000000000000000000000000000000" - + "000000000000000000100"; + kittyCoreAddressAndCut = + "000000000000000000000000" + ByteArray.toHexString(kittyCoreContractAddress).substring(2); + kittyCoreAddressAndCut = + kittyCoreAddressAndCut + + "0000000000000000000000000000000000000000000" + + "000000000000000000100"; } - @Test(enabled = true, description = "Deploy Erc721 contract \"Sale Clock Auction\"", groups = {"daily"}) + @Test( + enabled = true, + description = "Deploy Erc721 contract \"Sale Clock Auction\"", + groups = {"daily"}) public void deploySaleClockAuction() { - AccountResourceMessage accountResource = PublicMethod.getAccountResource(deployAddress, - blockingStubFull); - Long cpuLimit = accountResource.getEnergyLimit(); - Long cpuUsage = accountResource.getEnergyUsed(); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(deployAddress, blockingStubFull); + Long cpuLimit = accountResource.getEnergyLimit(); + Long cpuUsage = accountResource.getEnergyUsed(); Account account = PublicMethod.queryAccount(deployKey, blockingStubFull); logger.info("before balance is " + Long.toString(account.getBalance())); logger.info("before cpu limit is " + Long.toString(cpuLimit)); logger.info("before cpu usage is " + Long.toString(cpuUsage)); - String contractName = "SaleClockAuction"; - String filePath = "./src/test/resources/soliditycode/contractScenario011.sol"; + String contractName = "SaleClockAuction"; + String filePath = "./src/test/resources/soliditycode/contractScenario011.sol"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); logger.info("Sale Clock Auction"); - //saleClockAuctionContractAddress; - String data = "\"" + Base58.encode58Check(kittyCoreContractAddress) + "\"," + 100; - String deplTxid = PublicMethod - .deployContractWithConstantParame(contractName, abi, code, "constructor(address,uint256)", - data, "", maxFeeLimit, 0L, consumeUserResourcePercent, null, deployKey, deployAddress, + // saleClockAuctionContractAddress; + String data = "\"" + Base58.encode58Check(kittyCoreContractAddress) + "\"," + 100; + String deplTxid = + PublicMethod.deployContractWithConstantParame( + contractName, + abi, + code, + "constructor(address,uint256)", + data, + "", + maxFeeLimit, + 0L, + consumeUserResourcePercent, + null, + deployKey, + deployAddress, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = PublicMethod - .getTransactionInfoById(deplTxid, blockingStubFull); + Optional info = + PublicMethod.getTransactionInfoById(deplTxid, blockingStubFull); Assert.assertTrue(info.get().getResultValue() == 0); saleClockAuctionContractAddress = info.get().getContractAddress().toByteArray(); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethod.getContract(saleClockAuctionContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(saleClockAuctionContractAddress, blockingStubFull); Assert.assertFalse(StringUtils.isEmpty(smartContract.getBytecode())); Assert.assertTrue(smartContract.getAbi() != null); accountResource = PublicMethod.getAccountResource(deployAddress, blockingStubFull); @@ -157,43 +193,65 @@ public void deploySaleClockAuction() { logger.info("after balance is " + Long.toString(account.getBalance())); logger.info("after cpu limit is " + Long.toString(cpuLimit)); logger.info("after cpu usage is " + Long.toString(cpuUsage)); - String triggerTxid = PublicMethod - .triggerContract(saleClockAuctionContractAddress, "isSaleClockAuction()", "#", false, 0, - maxFeeLimit, deployAddress, deployKey, blockingStubFull); - Optional inFoByid = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + saleClockAuctionContractAddress, + "isSaleClockAuction()", + "#", + false, + 0, + maxFeeLimit, + deployAddress, + deployKey, + blockingStubFull); + Optional inFoByid = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Ttttt " + triggerTxid); Assert.assertTrue(inFoByid.get().getResultValue() == 0); } - @Test(enabled = true, description = "Deploy Erc721 contract \"Siring Clock Auction\"", groups = {"daily"}) + @Test( + enabled = true, + description = "Deploy Erc721 contract \"Siring Clock Auction\"", + groups = {"daily"}) public void deploySiringClockAuction() { - AccountResourceMessage accountResource = PublicMethod.getAccountResource(deployAddress, - blockingStubFull); - Long cpuLimit = accountResource.getEnergyLimit(); - Long cpuUsage = accountResource.getEnergyUsed(); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(deployAddress, blockingStubFull); + Long cpuLimit = accountResource.getEnergyLimit(); + Long cpuUsage = accountResource.getEnergyUsed(); Account account = PublicMethod.queryAccount(deployKey, blockingStubFull); logger.info("before balance is " + Long.toString(account.getBalance())); logger.info("before cpu limit is " + Long.toString(cpuLimit)); logger.info("before cpu usage is " + Long.toString(cpuUsage)); - String contractName = "SiringClockAuction"; - String filePath = "./src/test/resources/soliditycode/contractScenario011.sol"; + String contractName = "SiringClockAuction"; + String filePath = "./src/test/resources/soliditycode/contractScenario011.sol"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String data = "\"" + Base58.encode58Check(kittyCoreContractAddress) + "\"," + 100; - String siringClockAuctionContractAddressTxid = PublicMethod - .deployContractWithConstantParame(contractName, abi, code, "constructor(address,uint256)", + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String data = "\"" + Base58.encode58Check(kittyCoreContractAddress) + "\"," + 100; + String siringClockAuctionContractAddressTxid = + PublicMethod.deployContractWithConstantParame( + contractName, + abi, + code, + "constructor(address,uint256)", data, - "", maxFeeLimit, 0L, consumeUserResourcePercent, null, deployKey, - deployAddress, blockingStubFull); + "", + maxFeeLimit, + 0L, + consumeUserResourcePercent, + null, + deployKey, + deployAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info2 = PublicMethod - .getTransactionInfoById(siringClockAuctionContractAddressTxid, blockingStubFull); + Optional info2 = + PublicMethod.getTransactionInfoById( + siringClockAuctionContractAddressTxid, blockingStubFull); siringClockAuctionContractAddress = info2.get().getContractAddress().toByteArray(); Assert.assertTrue(info2.get().getResultValue() == 0); - SmartContract smartContract = PublicMethod.getContract(siringClockAuctionContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(siringClockAuctionContractAddress, blockingStubFull); Assert.assertFalse(StringUtils.isEmpty(smartContract.getBytecode())); Assert.assertTrue(smartContract.getAbi() != null); accountResource = PublicMethod.getAccountResource(deployAddress, blockingStubFull); @@ -205,32 +263,44 @@ public void deploySiringClockAuction() { logger.info("after cpu usage is " + Long.toString(cpuUsage)); } - @Test(enabled = true, description = "Deploy Erc721 contract \"Gene Science Interface\"", groups = {"daily"}) + @Test( + enabled = true, + description = "Deploy Erc721 contract \"Gene Science Interface\"", + groups = {"daily"}) public void deployGeneScienceInterface() { - AccountResourceMessage accountResource = PublicMethod.getAccountResource(deployAddress, - blockingStubFull); - Long cpuLimit = accountResource.getEnergyLimit(); - Long cpuUsage = accountResource.getEnergyUsed(); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(deployAddress, blockingStubFull); + Long cpuLimit = accountResource.getEnergyLimit(); + Long cpuUsage = accountResource.getEnergyUsed(); Account account = PublicMethod.queryAccount(deployKey, blockingStubFull); logger.info("before balance is " + Long.toString(account.getBalance())); logger.info("before cpu limit is " + Long.toString(cpuLimit)); logger.info("before cpu usage is " + Long.toString(cpuUsage)); - String contractName = "GeneScienceInterface"; - String filePath = "./src/test/resources/soliditycode/contractScenario011.sol"; + String contractName = "GeneScienceInterface"; + String filePath = "./src/test/resources/soliditycode/contractScenario011.sol"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod.deployContractAndGetTransactionInfoById(contractName, abi, code, - "", maxFeeLimit, - 0L, consumeUserResourcePercent, null, deployKey, deployAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + consumeUserResourcePercent, + null, + deployKey, + deployAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info2 = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional info2 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); geneScienceInterfaceContractAddress = info2.get().getContractAddress().toByteArray(); Assert.assertTrue(info2.get().getResultValue() == 0); - SmartContract smartContract = PublicMethod.getContract(geneScienceInterfaceContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(geneScienceInterfaceContractAddress, blockingStubFull); Assert.assertFalse(StringUtils.isEmpty(smartContract.getBytecode())); Assert.assertTrue(smartContract.getAbi() != null); accountResource = PublicMethod.getAccountResource(deployAddress, blockingStubFull); @@ -242,40 +312,76 @@ public void deployGeneScienceInterface() { logger.info("after cpu usage is " + Long.toString(cpuUsage)); } - @Test(enabled = true, description = "Set three contract address for Kitty Core, " - + "set three CXO roles", groups = {"daily"}) + @Test( + enabled = true, + description = "Set three contract address for Kitty Core, " + "set three CXO roles", + groups = {"daily"}) public void triggerToSetThreeContractAddressToKittyCore() { - //Set SaleAuctionAddress to kitty core. + // Set SaleAuctionAddress to kitty core. String saleContractString = "\"" + Base58.encode58Check(saleClockAuctionContractAddress) + "\""; - txid = PublicMethod.triggerContract(kittyCoreContractAddress, "setSaleAuctionAddress(address)", - saleContractString, false, 0, 10000000L, deployAddress, deployKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "setSaleAuctionAddress(address)", + saleContractString, + false, + 0, + 10000000L, + deployAddress, + deployKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info(txid); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - //Set SiringAuctionAddress to kitty core. - String siringContractString = "\"" + Base58.encode58Check(siringClockAuctionContractAddress) - + "\""; - txid = PublicMethod - .triggerContract(kittyCoreContractAddress, "setSiringAuctionAddress(address)", - siringContractString, false, 0, 10000000L, deployAddress, deployKey, blockingStubFull); + // Set SiringAuctionAddress to kitty core. + String siringContractString = + "\"" + Base58.encode58Check(siringClockAuctionContractAddress) + "\""; + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "setSiringAuctionAddress(address)", + siringContractString, + false, + 0, + 10000000L, + deployAddress, + deployKey, + blockingStubFull); logger.info(txid); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - //Set gen contract to kitty core - String genContractString = "\"" + Base58.encode58Check(geneScienceInterfaceContractAddress) - + "\""; - txid = PublicMethod.triggerContract(kittyCoreContractAddress, - "setGeneScienceAddress(address)", genContractString, - false, 0, 10000000L, deployAddress, deployKey, blockingStubFull); + // Set gen contract to kitty core + String genContractString = + "\"" + Base58.encode58Check(geneScienceInterfaceContractAddress) + "\""; + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "setGeneScienceAddress(address)", + genContractString, + false, + 0, + 10000000L, + deployAddress, + deployKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info(txid); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - //Start the game. + // Start the game. Integer result = 1; Integer times = 0; while (result == 1) { - txid = PublicMethod.triggerContract(kittyCoreContractAddress, "unpause()", "", false, 0, - 10000000L, deployAddress, deployKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "unpause()", + "", + false, + 0, + 10000000L, + deployAddress, + deployKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); result = infoById.get().getResultValue(); @@ -286,85 +392,162 @@ public void triggerToSetThreeContractAddressToKittyCore() { Assert.assertTrue(result == 0); logger.info("start the game " + txid); - //Create one gen0 cat. - txid = PublicMethod.triggerContract(kittyCoreContractAddress, - "createGen0Auction(uint256)", "-1000000000000000", false, - 0, (long)(100000000L * feeLimitRate), deployAddress, deployKey, blockingStubFull); + // Create one gen0 cat. + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "createGen0Auction(uint256)", + "-1000000000000000", + false, + 0, + (long) (100000000L * feeLimitRate), + deployAddress, + deployKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - txid = PublicMethod.triggerContract(kittyCoreContractAddress, - "gen0CreatedCount()", "#", false, - 0, (long)(100000000L * feeLimitRate), deployAddress, deployKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "gen0CreatedCount()", + "#", + false, + 0, + (long) (100000000L * feeLimitRate), + deployAddress, + deployKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - txid = PublicMethod.triggerContract(kittyCoreContractAddress, - "getKitty(uint256)", "1", false, 0, (long) (10000000L * feeLimitRate), triggerAddress, - triggerKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "getKitty(uint256)", + "1", + false, + 0, + (long) (10000000L * feeLimitRate), + triggerAddress, + triggerKey, + blockingStubFull); logger.info("getKitty " + txid); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - String newCxoAddress = "\"" + Base58.encode58Check(triggerAddress) - + "\""; - - txid = PublicMethod.triggerContract(kittyCoreContractAddress, - "setCOO(address)", newCxoAddress, false, 0, (long) (10000000L * feeLimitRate), deployAddress, - deployKey, blockingStubFull); + String newCxoAddress = "\"" + Base58.encode58Check(triggerAddress) + "\""; + + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "setCOO(address)", + newCxoAddress, + false, + 0, + (long) (10000000L * feeLimitRate), + deployAddress, + deployKey, + blockingStubFull); logger.info("COO " + txid); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - txid = PublicMethod.triggerContract(kittyCoreContractAddress, - "setCFO(address)", newCxoAddress, false, 0, (long) (10000000L * feeLimitRate), deployAddress, - deployKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "setCFO(address)", + newCxoAddress, + false, + 0, + (long) (10000000L * feeLimitRate), + deployAddress, + deployKey, + blockingStubFull); logger.info("CFO " + txid); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - txid = PublicMethod.triggerContract(kittyCoreContractAddress, - "setCEO(address)", newCxoAddress, false, 0, (long) (1000000000L * feeLimitRate), deployAddress, - deployKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "setCEO(address)", + newCxoAddress, + false, + 0, + (long) (1000000000L * feeLimitRate), + deployAddress, + deployKey, + blockingStubFull); logger.info("CEO " + txid); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); } - @Test(enabled = true, description = "Create Gen0 cat", groups = {"daily"}) + @Test( + enabled = true, + description = "Create Gen0 cat", + groups = {"daily"}) public void triggerUseTriggerEnergyUsage() { ECKey ecKey3 = new ECKey(Utils.getRandom()); - byte[] triggerUseTriggerEnergyUsageAddress = ecKey3.getAddress(); - final String triggerUseTriggerEnergyUsageKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); + byte[] triggerUseTriggerEnergyUsageAddress = ecKey3.getAddress(); + final String triggerUseTriggerEnergyUsageKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); Assert.assertTrue( - PublicMethod.sendcoin(triggerUseTriggerEnergyUsageAddress, 100000000000L, - foundationAddress, foundationKey, blockingStubFull)); - String newCxoAddress = "\"" + Base58.encode58Check(triggerUseTriggerEnergyUsageAddress) - + "\""; + PublicMethod.sendcoin( + triggerUseTriggerEnergyUsageAddress, + 100000000000L, + foundationAddress, + foundationKey, + blockingStubFull)); + String newCxoAddress = "\"" + Base58.encode58Check(triggerUseTriggerEnergyUsageAddress) + "\""; PublicMethod.waitProduceNextBlock(blockingStubFull); - final String txid1; - final String txid2; - final String txid3; - txid1 = PublicMethod.triggerContract(kittyCoreContractAddress, - "setCOO(address)", newCxoAddress, false, 0, maxFeeLimit, triggerAddress, - triggerKey, blockingStubFull); + final String txid1; + final String txid2; + final String txid3; + txid1 = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "setCOO(address)", + newCxoAddress, + false, + 0, + maxFeeLimit, + triggerAddress, + triggerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("COO " + txid); - txid2 = PublicMethod.triggerContract(kittyCoreContractAddress, - "setCFO(address)", newCxoAddress, false, 0, maxFeeLimit, triggerAddress, - triggerKey, blockingStubFull); + txid2 = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "setCFO(address)", + newCxoAddress, + false, + 0, + maxFeeLimit, + triggerAddress, + triggerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("CFO " + txid); - txid3 = PublicMethod.triggerContract(kittyCoreContractAddress, - "setCEO(address)", newCxoAddress, false, 0, maxFeeLimit, triggerAddress, - triggerKey, blockingStubFull); + txid3 = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "setCEO(address)", + newCxoAddress, + false, + 0, + maxFeeLimit, + triggerAddress, + triggerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("CEO " + txid); @@ -376,54 +559,73 @@ public void triggerUseTriggerEnergyUsage() { Assert.assertTrue(infoById.get().getResultValue() == 0); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long beforeBalance = PublicMethod - .queryAccount(triggerUseTriggerEnergyUsageKey, blockingStubFull).getBalance(); + Long beforeBalance = + PublicMethod.queryAccount(triggerUseTriggerEnergyUsageKey, blockingStubFull).getBalance(); logger.info("before balance is " + Long.toString(beforeBalance)); - txid = PublicMethod.triggerContract(kittyCoreContractAddress, - "createGen0Auction(uint256)", "0", false, - 0, 100000000L, triggerUseTriggerEnergyUsageAddress, triggerUseTriggerEnergyUsageKey, - blockingStubFull); + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "createGen0Auction(uint256)", + "0", + false, + 0, + 100000000L, + triggerUseTriggerEnergyUsageAddress, + triggerUseTriggerEnergyUsageKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull1); - logger.info("Q " + Long - .toString(infoById.get().getReceipt().getEnergyFee())); + logger.info("Q " + Long.toString(infoById.get().getReceipt().getEnergyFee())); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsage() == 0); Assert.assertTrue(infoById.get().getReceipt().getEnergyFee() > 10000); - // Assert.assertTrue(infoById.get().getReceipt().getOriginEnergyUsage() > 10000); - Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() - == infoById.get().getReceipt().getEnergyFee() / energyFee + infoById.get().getReceipt() - .getOriginEnergyUsage()); - Long fee = infoById.get().getFee(); - Long afterBalance = PublicMethod - .queryAccount(triggerUseTriggerEnergyUsageKey, blockingStubFull1).getBalance(); + // Assert.assertTrue(infoById.get().getReceipt().getOriginEnergyUsage() > 10000); + Assert.assertTrue( + infoById.get().getReceipt().getEnergyUsageTotal() + == infoById.get().getReceipt().getEnergyFee() / energyFee + + infoById.get().getReceipt().getOriginEnergyUsage()); + Long fee = infoById.get().getFee(); + Long afterBalance = + PublicMethod.queryAccount(triggerUseTriggerEnergyUsageKey, blockingStubFull1).getBalance(); logger.info("after balance is " + Long.toString(afterBalance)); logger.info("fee is " + Long.toString(fee)); Assert.assertTrue(beforeBalance == afterBalance + fee); logger.info("before EnergyUsage is " + infoById.get().getReceipt().getEnergyUsage()); logger.info("before EnergyFee is " + infoById.get().getReceipt().getEnergyFee()); - logger.info("before OriginEnergyUsage is " + infoById.get().getReceipt() - .getOriginEnergyUsage()); + logger.info( + "before OriginEnergyUsage is " + infoById.get().getReceipt().getOriginEnergyUsage()); logger.info("before EnergyTotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); Assert.assertTrue( - PublicMethod.freezeBalanceGetEnergy(triggerUseTriggerEnergyUsageAddress, 6000000000L, - 0, 1, triggerUseTriggerEnergyUsageKey, blockingStubFull)); + PublicMethod.freezeBalanceGetEnergy( + triggerUseTriggerEnergyUsageAddress, + 6000000000L, + 0, + 1, + triggerUseTriggerEnergyUsageKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - beforeBalance = PublicMethod.queryAccount(triggerUseTriggerEnergyUsageKey, blockingStubFull) - .getBalance(); + beforeBalance = + PublicMethod.queryAccount(triggerUseTriggerEnergyUsageKey, blockingStubFull).getBalance(); logger.info("before balance is " + Long.toString(beforeBalance)); - AccountResourceMessage accountResource = PublicMethod - .getAccountResource(triggerUseTriggerEnergyUsageAddress, blockingStubFull); - Long energyLimit = accountResource.getEnergyLimit(); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(triggerUseTriggerEnergyUsageAddress, blockingStubFull); + Long energyLimit = accountResource.getEnergyLimit(); logger.info("before EnergyLimit is " + Long.toString(energyLimit)); - txid = PublicMethod.triggerContract(kittyCoreContractAddress, - "createGen0Auction(uint256)", "0", false, - 0, (long) (100000000L * feeLimitRate), triggerUseTriggerEnergyUsageAddress, triggerUseTriggerEnergyUsageKey, - blockingStubFull); + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "createGen0Auction(uint256)", + "0", + false, + 0, + (long) (100000000L * feeLimitRate), + triggerUseTriggerEnergyUsageAddress, + triggerUseTriggerEnergyUsageKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull1); @@ -432,45 +634,45 @@ public void triggerUseTriggerEnergyUsage() { logger.info("after OriginEnergyUsage is " + infoById.get().getReceipt().getOriginEnergyUsage()); logger.info("after EnergyTotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); fee = infoById.get().getFee(); - afterBalance = PublicMethod.queryAccount(triggerUseTriggerEnergyUsageKey, blockingStubFull1) - .getBalance(); + afterBalance = + PublicMethod.queryAccount(triggerUseTriggerEnergyUsageKey, blockingStubFull1).getBalance(); logger.info("after balance is " + Long.toString(afterBalance)); logger.info("fee is " + Long.toString(fee)); - accountResource = PublicMethod - .getAccountResource(triggerUseTriggerEnergyUsageAddress, blockingStubFull1); + accountResource = + PublicMethod.getAccountResource(triggerUseTriggerEnergyUsageAddress, blockingStubFull1); energyLimit = accountResource.getEnergyLimit(); logger.info("after EnergyLimit is " + Long.toString(energyLimit)); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsage() > 10000); Assert.assertTrue(infoById.get().getReceipt().getEnergyFee() == 0); - //Assert.assertTrue(infoById.get().getReceipt().getOriginEnergyUsage() > 10000); - Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() == infoById.get() - .getReceipt().getEnergyUsage() + infoById.get().getReceipt().getOriginEnergyUsage()); - // Assert.assertTrue(infoById.get().getReceipt().getEnergyUsage() == infoById.get() + // Assert.assertTrue(infoById.get().getReceipt().getOriginEnergyUsage() > 10000); + Assert.assertTrue( + infoById.get().getReceipt().getEnergyUsageTotal() + == infoById.get().getReceipt().getEnergyUsage() + + infoById.get().getReceipt().getOriginEnergyUsage()); + // Assert.assertTrue(infoById.get().getReceipt().getEnergyUsage() == infoById.get() // .getReceipt().getOriginEnergyUsage()); Assert.assertTrue(beforeBalance == afterBalance + fee); - PublicMethod.unFreezeBalance(deployAddress, deployKey, 1, - deployAddress, blockingStubFull); - PublicMethod.unFreezeBalance(triggerAddress, triggerKey, 1, - triggerAddress, blockingStubFull); - - PublicMethod - .unFreezeBalance(triggerUseTriggerEnergyUsageAddress, triggerUseTriggerEnergyUsageKey, 1, - triggerUseTriggerEnergyUsageAddress, blockingStubFull); - PublicMethod.freeResource(triggerUseTriggerEnergyUsageAddress, triggerUseTriggerEnergyUsageKey, - foundationAddress, blockingStubFull); - + PublicMethod.unFreezeBalance(deployAddress, deployKey, 1, deployAddress, blockingStubFull); + PublicMethod.unFreezeBalance(triggerAddress, triggerKey, 1, triggerAddress, blockingStubFull); + + PublicMethod.unFreezeBalance( + triggerUseTriggerEnergyUsageAddress, + triggerUseTriggerEnergyUsageKey, + 1, + triggerUseTriggerEnergyUsageAddress, + blockingStubFull); + PublicMethod.freeResource( + triggerUseTriggerEnergyUsageAddress, + triggerUseTriggerEnergyUsageKey, + foundationAddress, + blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario014.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario014.java index 25109c00..718a6232 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario014.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario014.java @@ -13,11 +13,12 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class ContractScenario014 extends TronBaseTest { byte[] contractAddress1 = null; +public class ContractScenario014 extends TronBaseTest { + byte[] contractAddress1 = null; byte[] contractAddress2 = null; byte[] contractAddress3 = null; String txid = ""; @@ -29,14 +30,16 @@ public class ContractScenario014 extends TronBaseTest { byte[] contractAddress1 String priKey014 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] receiverAddress = ecKey2.getAddress(); - String receiverKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); /** - * constructor. - */ + String receiverKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Triple trigger in smart contract", groups = {"daily"}) + @Test( + enabled = true, + description = "Triple trigger in smart contract", + groups = {"daily"}) public void testTripleTrigger() { ecKey2 = new ECKey(Utils.getRandom()); @@ -45,97 +48,154 @@ public void testTripleTrigger() { PublicMethod.printAddress(contract014Key); PublicMethod.printAddress(receiverKey); - Assert.assertTrue(PublicMethod.sendcoin(contract014Address, 50_000_000_000L, foundationAddress, - foundationKey, blockingStubFull)); - PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceGetEnergy(contract014Address, 10_000_000_000L, 0, 1, priKey014, + Assert.assertTrue( + PublicMethod.sendcoin( + contract014Address, + 50_000_000_000L, + foundationAddress, + foundationKey, blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + contract014Address, 10_000_000_000L, 0, 1, priKey014, blockingStubFull)); logger.info("contract014Address : == " + contract014Key); - //Deploy contract1, contract1 has a function to transaction 5 sun to target account + // Deploy contract1, contract1 has a function to transaction 5 sun to target account String contractName = "Contract1"; - String filePath = "./src/test/resources/soliditycode/contractScenario014.sol"; + String filePath = "./src/test/resources/soliditycode/contractScenario014.sol"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - txid = PublicMethod.deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 1000000L, 100, null, contract014Key, contract014Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + null, + contract014Key, + contract014Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); contractAddress1 = infoById.get().getContractAddress().toByteArray(); - //Deploy contract2, contract2 has a function to call contract1 transaction sun function. + // Deploy contract2, contract2 has a function to call contract1 transaction sun function. // and has a revert function. contractName = "contract2"; - String filePath1 = "./src/test/resources/soliditycode/contractScenario014.sol"; + String filePath1 = "./src/test/resources/soliditycode/contractScenario014.sol"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath1, contractName); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - String parame = "\"" + Base58.encode58Check(contractAddress1) + "\""; - - txid = PublicMethod.deployContractWithConstantParame(contractName, abi1, code1, - "constructor(address)", parame, "", maxFeeLimit, 1000000L, 100, null, - contract014Key, contract014Address, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String parame = "\"" + Base58.encode58Check(contractAddress1) + "\""; + + txid = + PublicMethod.deployContractWithConstantParame( + contractName, + abi1, + code1, + "constructor(address)", + parame, + "", + maxFeeLimit, + 1000000L, + 100, + null, + contract014Key, + contract014Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); contractAddress2 = infoById.get().getContractAddress().toByteArray(); - //Deploy contract3, trigger contrct2 function. + // Deploy contract3, trigger contrct2 function. contractName = "contract3"; - String filePath2 = "./src/test/resources/soliditycode/contractScenario014.sol"; + String filePath2 = "./src/test/resources/soliditycode/contractScenario014.sol"; HashMap retMap2 = PublicMethod.getBycodeAbi(filePath2, contractName); - String code2 = retMap2.get("byteCode").toString(); - String abi2 = retMap2.get("abI").toString(); + String code2 = retMap2.get("byteCode").toString(); + String abi2 = retMap2.get("abI").toString(); parame = "\"" + Base58.encode58Check(contractAddress2) + "\""; - txid = PublicMethod.deployContractWithConstantParame(contractName, abi2, code2, - "constructor(address)", parame, "", maxFeeLimit, 1000000L, 100, null, - contract014Key, contract014Address, blockingStubFull); + txid = + PublicMethod.deployContractWithConstantParame( + contractName, + abi2, + code2, + "constructor(address)", + parame, + "", + maxFeeLimit, + 1000000L, + 100, + null, + contract014Key, + contract014Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); contractAddress3 = infoById.get().getContractAddress().toByteArray(); - Assert.assertTrue(PublicMethod.sendcoin(receiverAddress, 1000000L, foundationAddress, foundationKey, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + receiverAddress, 1000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Test contract2 trigger contract1 to test call function + // Test contract2 trigger contract1 to test call function Account contract2AccountInfo = PublicMethod.queryAccount(contractAddress2, blockingStubFull); - final Long contract2BeforeBalance = contract2AccountInfo.getBalance(); + final Long contract2BeforeBalance = contract2AccountInfo.getBalance(); Account receiverAccountInfo = PublicMethod.queryAccount(receiverAddress, blockingStubFull); - Long receiverBeforeBalance = receiverAccountInfo.getBalance(); + Long receiverBeforeBalance = receiverAccountInfo.getBalance(); Account contract1AccountInfo = PublicMethod.queryAccount(contractAddress1, blockingStubFull); - Long contract1BeforeBalance = contract1AccountInfo.getBalance(); + Long contract1BeforeBalance = contract1AccountInfo.getBalance(); logger.info("before contract1 balance is " + Long.toString(contract1BeforeBalance)); logger.info("before receiver balance is " + Long.toString(receiverBeforeBalance)); - String receiveAddress = "\"" + Base58.encode58Check(receiverAddress) + "\""; - txid = PublicMethod.triggerContract(contractAddress2, - "triggerContract1(address)", receiveAddress, false, - 0, maxFeeLimit, contract014Address, contract014Key, blockingStubFull); + String receiveAddress = "\"" + Base58.encode58Check(receiverAddress) + "\""; + txid = + PublicMethod.triggerContract( + contractAddress2, + "triggerContract1(address)", + receiveAddress, + false, + 0, + maxFeeLimit, + contract014Address, + contract014Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); contract2AccountInfo = PublicMethod.queryAccount(contractAddress2, blockingStubFull); - final Long contract2AfterBalance = contract2AccountInfo.getBalance(); - //contract2AccountInfo.getAccountResource().getFrozenBalanceForEnergy(); + final Long contract2AfterBalance = contract2AccountInfo.getBalance(); + // contract2AccountInfo.getAccountResource().getFrozenBalanceForEnergy(); receiverAccountInfo = PublicMethod.queryAccount(receiverAddress, blockingStubFull); - Long receiverAfterBalance = receiverAccountInfo.getBalance(); + Long receiverAfterBalance = receiverAccountInfo.getBalance(); contract1AccountInfo = PublicMethod.queryAccount(contractAddress1, blockingStubFull); - Long contract1AfterBalance = contract1AccountInfo.getBalance(); + Long contract1AfterBalance = contract1AccountInfo.getBalance(); logger.info("after contract1 balance is " + Long.toString(contract1AfterBalance)); Assert.assertTrue(receiverAfterBalance - receiverBeforeBalance == 5); Assert.assertTrue(contract2BeforeBalance - contract2AfterBalance == 0); Assert.assertTrue(contract1BeforeBalance - contract1AfterBalance == 5); - //Test contract2 trigger contract1 but revert + // Test contract2 trigger contract1 but revert contract1AccountInfo = PublicMethod.queryAccount(contractAddress1, blockingStubFull); contract1BeforeBalance = contract1AccountInfo.getBalance(); receiverAccountInfo = PublicMethod.queryAccount(receiverAddress, blockingStubFull); receiverBeforeBalance = receiverAccountInfo.getBalance(); receiveAddress = "\"" + Base58.encode58Check(receiverAddress) + "\""; - txid = PublicMethod.triggerContract(contractAddress2, - "triggerContract1ButRevert(address)", receiveAddress, false, - 0, 10000000L, contract014Address, contract014Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress2, + "triggerContract1ButRevert(address)", + receiveAddress, + false, + 0, + 10000000L, + contract014Address, + contract014Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 1); @@ -146,24 +206,32 @@ public void testTripleTrigger() { logger.info("after receiver balance is " + Long.toString(receiverAfterBalance)); Assert.assertTrue(receiverAfterBalance - receiverBeforeBalance == 0); Assert.assertTrue(contract1BeforeBalance - contract1AfterBalance == 0); - //Test contract3 trigger contract2 to call contract1 + // Test contract3 trigger contract2 to call contract1 contract1AccountInfo = PublicMethod.queryAccount(contractAddress1, blockingStubFull); contract1BeforeBalance = contract1AccountInfo.getBalance(); Account contract3AccountInfo = PublicMethod.queryAccount(contractAddress3, blockingStubFull); - final Long contract3BeforeBalance = contract3AccountInfo.getBalance(); + final Long contract3BeforeBalance = contract3AccountInfo.getBalance(); receiverAccountInfo = PublicMethod.queryAccount(receiverAddress, blockingStubFull); receiverBeforeBalance = receiverAccountInfo.getBalance(); logger.info("before receiver balance is " + Long.toString(receiverBeforeBalance)); logger.info("before contract3 balance is " + Long.toString(contract3BeforeBalance)); receiveAddress = "\"" + Base58.encode58Check(receiverAddress) + "\""; - txid = PublicMethod.triggerContract(contractAddress3, - "triggerContract2(address)", receiveAddress, false, - 0, 10000000L, contract014Address, contract014Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress3, + "triggerContract2(address)", + receiveAddress, + false, + 0, + 10000000L, + contract014Address, + contract014Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); contract3AccountInfo = PublicMethod.queryAccount(contractAddress3, blockingStubFull); - final Long contract3AfterBalance = contract3AccountInfo.getBalance(); + final Long contract3AfterBalance = contract3AccountInfo.getBalance(); receiverAccountInfo = PublicMethod.queryAccount(receiverAddress, blockingStubFull); receiverAfterBalance = receiverAccountInfo.getBalance(); logger.info("after receiver balance is " + Long.toString(receiverAfterBalance)); @@ -174,20 +242,14 @@ public void testTripleTrigger() { Assert.assertTrue(receiverAfterBalance - receiverBeforeBalance == 5); Assert.assertTrue(contract3BeforeBalance - contract3AfterBalance == 0); Assert.assertTrue(contract1BeforeBalance - contract1AfterBalance == 5); - - } - - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.unFreezeBalance(contract014Address, contract014Key, 1, contract014Address, - blockingStubFull); - PublicMethod.freeResource(contract014Address, contract014Key, foundationAddress, blockingStubFull); } + PublicMethod.unFreezeBalance( + contract014Address, contract014Key, 1, contract014Address, blockingStubFull); + PublicMethod.freeResource( + contract014Address, contract014Key, foundationAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario015.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario015.java index 1ed88b76..4f3463ab 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario015.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario015.java @@ -12,11 +12,12 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class ContractScenario015 extends TronBaseTest { byte[] contractAddress1 = null; +public class ContractScenario015 extends TronBaseTest { + byte[] contractAddress1 = null; byte[] contractAddress2 = null; byte[] contractAddress3 = null; String txid = ""; @@ -27,14 +28,16 @@ public class ContractScenario015 extends TronBaseTest { byte[] contractAddress1 String contract014Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] receiverAddress = ecKey2.getAddress(); - String receiverKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); /** - * constructor. - */ + String receiverKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "TRON TRC20 transfer token", groups = {"daily"}) + @Test( + enabled = true, + description = "TRON TRC20 transfer token", + groups = {"daily"}) public void trc20Tron() { ecKey1 = new ECKey(Utils.getRandom()); contract014Address = ecKey1.getAddress(); @@ -46,34 +49,61 @@ public void trc20Tron() { PublicMethod.printAddress(contract014Key); PublicMethod.printAddress(receiverKey); - Assert.assertTrue(PublicMethod.sendcoin(contract014Address, 1000000000L, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + contract014Address, 1000000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Deploy contract1, contract1 has a function to transaction 5 sun to target account + // Deploy contract1, contract1 has a function to transaction 5 sun to target account String contractName = "TRON TRC20"; - String code = Configuration.getByPath("testng.conf") - .getString("code.code_Scenario015_TRC20_TRON"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_Scenario015_TRC20_TRON"); - txid = PublicMethod.deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 100, null, contract014Key, contract014Address, blockingStubFull); + String code = + Configuration.getByPath("testng.conf").getString("code.code_Scenario015_TRC20_TRON"); + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_Scenario015_TRC20_TRON"); + txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contract014Key, + contract014Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info(txid); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); contractAddress1 = infoById.get().getContractAddress().toByteArray(); - //Set SiringAuctionAddress to kitty core. + // Set SiringAuctionAddress to kitty core. String siringContractString = "\"" + Base58.encode58Check(foundationAddress) + "\""; - txid = PublicMethod - .triggerContract(contractAddress1, "balanceOf(address)", siringContractString, - false, 0, 30000000L, contract014Address, contract014Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress1, + "balanceOf(address)", + siringContractString, + false, + 0, + 30000000L, + contract014Address, + contract014Key, + blockingStubFull); logger.info(txid); siringContractString = "\"" + Base58.encode58Check(foundationAddress) + "\",\"" + 17 + "\""; - txid = PublicMethod.triggerContract(contractAddress1, "transfer(address,uint256)", - siringContractString, false, 0, 30000000L, contract014Address, - contract014Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress1, + "transfer(address,uint256)", + siringContractString, + false, + 0, + 30000000L, + contract014Address, + contract014Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -82,21 +112,24 @@ public void trc20Tron() { Assert.assertTrue(infoById.get().getResultValue() == 0); siringContractString = "\"" + Base58.encode58Check(foundationAddress) + "\""; - txid = PublicMethod - .triggerContract(contractAddress1, "balanceOf(address)", - siringContractString, false, 0, 30000000L, contract014Address, - contract014Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress1, + "balanceOf(address)", + siringContractString, + false, + 0, + 30000000L, + contract014Address, + contract014Key, + blockingStubFull); logger.info(txid); } - - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contract014Address, contract014Key, foundationAddress, blockingStubFull); } + PublicMethod.freeResource( + contract014Address, contract014Key, foundationAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractTrc1155.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractTrc1155.java index 0cc5e158..28b4d51f 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractTrc1155.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractTrc1155.java @@ -20,15 +20,17 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode -public class ContractTrc1155 extends TronBaseTest { private final String fullnode = - Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); Optional infoById = null; +public class ContractTrc1155 extends TronBaseTest { + private final String fullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + Optional infoById = null; ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] ownerAddressByte = ecKey2.getAddress(); String ownerKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); @@ -39,25 +41,27 @@ public class ContractTrc1155 extends TronBaseTest { private final String fullno byte[] trc1155AddressByte = null; /** constructor. */ - @BeforeSuite - public void beforeSuite() { } + public void beforeSuite() {} /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() throws Exception { - //Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + // Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); deployTrc1155(); deployHolder(); deployNoHolder(); } - @Test(enabled = true, description = "Trigger Trc1155 balanceOf method", groups = {"daily"}) + @Test( + enabled = true, + description = "Trigger Trc1155 balanceOf method", + groups = {"daily"}) public void test01triggerTrc1155BalanceOfMethod() { int coinType = 3; List parameters = Arrays.asList(ownerAddressString, coinType); - String data = PublicMethod.parametersString(parameters); + String data = PublicMethod.parametersString(parameters); logger.info("data:" + data); GrpcAPI.TransactionExtention transactionExtention = @@ -73,12 +77,15 @@ public void test01triggerTrc1155BalanceOfMethod() { ownerAddressByte, ownerKey, blockingStubFull); - String hexBalance = Hex.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + String hexBalance = Hex.toHexString(transactionExtention.getConstantResult(0).toByteArray()); long result = Long.parseLong(hexBalance, 16); Assert.assertEquals((long) Math.pow(10, 4), result); } - @Test(enabled = true, description = "Trigger Trc1155 balanceOfBatch method", groups = {"daily"}) + @Test( + enabled = true, + description = "Trigger Trc1155 balanceOfBatch method", + groups = {"daily"}) public void test02triggerTrc1155BalanceOfBatchMethod() { List address = Stream.of( @@ -91,7 +98,7 @@ public void test02triggerTrc1155BalanceOfBatchMethod() { .collect(Collectors.toList()); List coinType = Stream.of(0, 1, 2, 3, 4, 5).collect(Collectors.toList()); List parameters = Arrays.asList(address, coinType); - String data = PublicMethod.parametersString(parameters); + String data = PublicMethod.parametersString(parameters); logger.info("data:" + data); GrpcAPI.TransactionExtention transactionExtention1 = PublicMethod.triggerConstantContractForExtention( @@ -106,14 +113,14 @@ public void test02triggerTrc1155BalanceOfBatchMethod() { ownerAddressByte, ownerKey, blockingStubFull); - String hexBalance = Hex.toHexString(transactionExtention1.getConstantResult(0).toByteArray()); + String hexBalance = Hex.toHexString(transactionExtention1.getConstantResult(0).toByteArray()); logger.info("hexBalance:" + hexBalance); - final long trxAmount = (long) Math.pow(10, 3); - final long bttAmount = (long) Math.pow(10, 2); - final long winAmount = (long) Math.pow(10, 5); - final long sunAmount = (long) Math.pow(10, 4); - final long apenftAmount = 1L; - final long apenft1Amount = 1L; + final long trxAmount = (long) Math.pow(10, 3); + final long bttAmount = (long) Math.pow(10, 2); + final long winAmount = (long) Math.pow(10, 5); + final long sunAmount = (long) Math.pow(10, 4); + final long apenftAmount = 1L; + final long apenft1Amount = 1L; Assert.assertEquals(trxAmount, Long.parseLong(hexBalance.substring(128, 192), 16)); Assert.assertEquals(bttAmount, Long.parseLong(hexBalance.substring(192, 256), 16)); Assert.assertEquals(winAmount, Long.parseLong(hexBalance.substring(256, 320), 16)); @@ -122,16 +129,19 @@ public void test02triggerTrc1155BalanceOfBatchMethod() { Assert.assertEquals(apenft1Amount, Long.parseLong(hexBalance.substring(448, 512), 16)); } - @Test(enabled = true, description = "Trigger Trc1155 safeTransferFrom function", groups = {"daily"}) + @Test( + enabled = true, + description = "Trigger Trc1155 safeTransferFrom function", + groups = {"daily"}) public void test03triggerTrc1155SafeTransferFromFunction() { ECKey ecKey3 = new ECKey(Utils.getRandom()); - byte[] contract003Address = ecKey3.getAddress(); - String sendAddress = WalletClient.encode58Check(contract003Address); + byte[] contract003Address = ecKey3.getAddress(); + String sendAddress = WalletClient.encode58Check(contract003Address); logger.info(sendAddress); - int coinType = 3; - final int coinAmount = 2; + int coinType = 3; + final int coinAmount = 2; List parameters1 = Arrays.asList(ownerAddressString, coinType); - String data = PublicMethod.parametersString(parameters1); + String data = PublicMethod.parametersString(parameters1); logger.info("data1:" + data); GrpcAPI.TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtention( @@ -146,15 +156,15 @@ public void test03triggerTrc1155SafeTransferFromFunction() { ownerAddressByte, ownerKey, blockingStubFull); - String hexBalance = Hex.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + String hexBalance = Hex.toHexString(transactionExtention.getConstantResult(0).toByteArray()); long result = Long.parseLong(hexBalance, 16); Assert.assertEquals((long) Math.pow(10, 4), result); - String bytes = "0000000000000000000000000000000000e6b58be8af95e5ad97e7aca6e4b8b2"; + String bytes = "0000000000000000000000000000000000e6b58be8af95e5ad97e7aca6e4b8b2"; List parameters = Arrays.asList(ownerAddressString, sendAddress, coinType, coinAmount, bytes); data = PublicMethod.parametersString(parameters); logger.info("data2:" + data); - String txid = + String txid = PublicMethod.triggerContract( trc1155AddressByte, "safeTransferFrom(address,address,uint256,uint256,bytes)", @@ -170,7 +180,7 @@ public void test03triggerTrc1155SafeTransferFromFunction() { infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); Optional byId = PublicMethod.getTransactionById(txid, blockingStubFull); - String s = ByteArray.toHexString(byId.get().getRawData().getContract(0).toByteArray()); + String s = ByteArray.toHexString(byId.get().getRawData().getContract(0).toByteArray()); Assert.assertTrue(s.contains(bytes)); List parameters3 = Arrays.asList(ownerAddressString, coinType); @@ -215,20 +225,23 @@ public void test03triggerTrc1155SafeTransferFromFunction() { Assert.assertEquals(coinAmount, result); } - @Test(enabled = true, description = "trigger Trc1155 SafeBatchTransferFrom function", groups = {"daily"}) + @Test( + enabled = true, + description = "trigger Trc1155 SafeBatchTransferFrom function", + groups = {"daily"}) public void test04triggerTrc1155SafeBatchTransferFromFunction() { ECKey ecKey4 = new ECKey(Utils.getRandom()); - byte[] receiverAddress = ecKey4.getAddress(); - String sendAddress = WalletClient.encode58Check(receiverAddress); + byte[] receiverAddress = ecKey4.getAddress(); + String sendAddress = WalletClient.encode58Check(receiverAddress); List coinType = Stream.of(0, 1, 5).collect(Collectors.toList()); List coinAccount = Stream.of(50, 10, 1).collect(Collectors.toList()); - String bytes = "0000000000000000000000000000000000e6b58be8af95e5ad97e7aca6e4b8b2"; + String bytes = "0000000000000000000000000000000000e6b58be8af95e5ad97e7aca6e4b8b2"; List parameters = Arrays.asList(ownerAddressString, sendAddress, coinType, coinAccount, bytes); - String input = PublicMethod.parametersString(parameters); + String input = PublicMethod.parametersString(parameters); logger.info("input:" + input); - String txid = + String txid = PublicMethod.triggerContract( trc1155AddressByte, "safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)", @@ -244,7 +257,7 @@ public void test04triggerTrc1155SafeBatchTransferFromFunction() { infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); Optional byId = PublicMethod.getTransactionById(txid, blockingStubFull); - String s = ByteArray.toHexString(byId.get().getRawData().getContract(0).toByteArray()); + String s = ByteArray.toHexString(byId.get().getRawData().getContract(0).toByteArray()); Assert.assertTrue(s.contains(bytes)); List address = Stream.of( @@ -257,7 +270,7 @@ public void test04triggerTrc1155SafeBatchTransferFromFunction() { .collect(Collectors.toList()); List coinType1 = Stream.of(0, 1, 2, 3, 4, 5).collect(Collectors.toList()); List parameters1 = Arrays.asList(address, coinType1); - String data = PublicMethod.parametersString(parameters1); + String data = PublicMethod.parametersString(parameters1); logger.info("data2:" + data); GrpcAPI.TransactionExtention transactionExtention = @@ -273,7 +286,7 @@ public void test04triggerTrc1155SafeBatchTransferFromFunction() { ownerAddressByte, ownerKey, blockingStubFull); - String hexBalance = Hex.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + String hexBalance = Hex.toHexString(transactionExtention.getConstantResult(0).toByteArray()); logger.info("hexBalance:" + hexBalance); Assert.assertEquals( (long) Math.pow(10, 3) - 50, Long.parseLong(hexBalance.substring(128, 192), 16)); @@ -322,10 +335,13 @@ public void test04triggerTrc1155SafeBatchTransferFromFunction() { Assert.assertEquals(1, Long.parseLong(hexBalance.substring(448, 512), 16)); } - @Test(enabled = true, description = "Trc1155Holder can receive trc1155", groups = {"daily"}) + @Test( + enabled = true, + description = "Trc1155Holder can receive trc1155", + groups = {"daily"}) public void test05Trc1155HolderCanReceiveTrc1155() { List parameters = Arrays.asList(holderAddressString, true); - String data = PublicMethod.parametersString(parameters); + String data = PublicMethod.parametersString(parameters); logger.info("data:" + data); txid = PublicMethod.triggerContract( @@ -343,9 +359,9 @@ public void test05Trc1155HolderCanReceiveTrc1155() { logger.info("setApprovalForAll_txid:" + txid); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); - int coinType = 0; - int coinAmount = 10; - String bytes = "0000000000000000000000000000000000e6b58be8af95e5ad97e7aca6e4b8b2"; + int coinType = 0; + int coinAmount = 10; + String bytes = "0000000000000000000000000000000000e6b58be8af95e5ad97e7aca6e4b8b2"; parameters = Arrays.asList(ownerAddressString, holderAddressString, coinType, coinAmount, bytes); data = PublicMethod.parametersString(parameters); @@ -365,7 +381,7 @@ public void test05Trc1155HolderCanReceiveTrc1155() { logger.info("safeTransferFrom_txid:" + txid); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Optional byId = PublicMethod.getTransactionById(txid, blockingStubFull); - String s = ByteArray.toHexString(byId.get().getRawData().getContract(0).toByteArray()); + String s = ByteArray.toHexString(byId.get().getRawData().getContract(0).toByteArray()); Assert.assertTrue(s.contains(bytes)); logger.info("infobyid1 : --- " + byId); @@ -387,16 +403,19 @@ public void test05Trc1155HolderCanReceiveTrc1155() { ownerAddressByte, ownerKey, blockingStubFull); - String hexBalance = Hex.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + String hexBalance = Hex.toHexString(transactionExtention.getConstantResult(0).toByteArray()); long result = Long.parseLong(hexBalance, 16); Assert.assertEquals(coinAmount, result); } - @Test(enabled = true, description = "Trc1155Holder can receive trc1155[]", groups = {"daily"}) + @Test( + enabled = true, + description = "Trc1155Holder can receive trc1155[]", + groups = {"daily"}) public void test06Trc1155HolderCanReceiveTrc1155_01() { List parameters = Arrays.asList(holderAddressString, true); - String data = PublicMethod.parametersString(parameters); + String data = PublicMethod.parametersString(parameters); logger.info("data:" + data); txid = PublicMethod.triggerContract( @@ -414,16 +433,16 @@ public void test06Trc1155HolderCanReceiveTrc1155_01() { logger.info("setApprovalForAll_txid:" + txid); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); - int trxAmount = 50; - int bttAmount = 30; - int winAmount = 25; - int sunAmount = 10; - int apenftAmount = 1; + int trxAmount = 50; + int bttAmount = 30; + int winAmount = 25; + int sunAmount = 10; + int apenftAmount = 1; List coinType = Stream.of(0, 1, 2, 3, 4).collect(Collectors.toList()); List coinAmount = Stream.of(trxAmount, bttAmount, winAmount, sunAmount, apenftAmount) .collect(Collectors.toList()); - String bytes = "0000000000000000000000000000000000e6b58be8af95e5ad97e7aca6e4b8b2"; + String bytes = "0000000000000000000000000000000000e6b58be8af95e5ad97e7aca6e4b8b2"; parameters = Arrays.asList(ownerAddressString, holderAddressString, coinType, coinAmount, bytes); data = PublicMethod.parametersString(parameters); @@ -444,7 +463,7 @@ public void test06Trc1155HolderCanReceiveTrc1155_01() { infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid1 : --- " + infoById); Optional byId = PublicMethod.getTransactionById(txid, blockingStubFull); - String s = ByteArray.toHexString(byId.get().getRawData().getContract(0).toByteArray()); + String s = ByteArray.toHexString(byId.get().getRawData().getContract(0).toByteArray()); Assert.assertTrue(s.contains(bytes)); List address = Stream.of( @@ -472,7 +491,7 @@ public void test06Trc1155HolderCanReceiveTrc1155_01() { ownerAddressByte, ownerKey, blockingStubFull); - String hexBalance = Hex.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + String hexBalance = Hex.toHexString(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(trxAmount + 10, Long.parseLong(hexBalance.substring(128, 192), 16)); Assert.assertEquals(bttAmount, Long.parseLong(hexBalance.substring(192, 256), 16)); Assert.assertEquals(winAmount, Long.parseLong(hexBalance.substring(256, 320), 16)); @@ -481,10 +500,13 @@ public void test06Trc1155HolderCanReceiveTrc1155_01() { Assert.assertEquals(0, Long.parseLong(hexBalance.substring(448, 512), 16)); } - @Test(enabled = true, description = "Non-trc1155Holder can not receive trc1155", groups = {"daily"}) + @Test( + enabled = true, + description = "Non-trc1155Holder can not receive trc1155", + groups = {"daily"}) public void test07NonTrc1155HolderCanNotReceiveTrc1155() { List parameters = Arrays.asList(noHolderAddress, true); - String data = PublicMethod.parametersString(parameters); + String data = PublicMethod.parametersString(parameters); logger.info("data:" + data); txid = PublicMethod.triggerContract( @@ -502,9 +524,9 @@ public void test07NonTrc1155HolderCanNotReceiveTrc1155() { logger.info("setApprovalForAll_txid:" + txid); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); - String bytes = "0000000000000000000000000000000000e6b58be8af95e5ad97e7aca6e4b8b2"; + String bytes = "0000000000000000000000000000000000e6b58be8af95e5ad97e7aca6e4b8b2"; List parameters1 = Arrays.asList(ownerAddressString, noHolderAddress, 1, 1, bytes); - String data1 = PublicMethod.parametersString(parameters1); + String data1 = PublicMethod.parametersString(parameters1); logger.info("data:" + data1); txid = PublicMethod.triggerContract( @@ -537,7 +559,7 @@ public void test07NonTrc1155HolderCanNotReceiveTrc1155() { ownerAddressByte, ownerKey, blockingStubFull); - String hexBalance = Hex.toHexString(transactionExtention1.getConstantResult(0).toByteArray()); + String hexBalance = Hex.toHexString(transactionExtention1.getConstantResult(0).toByteArray()); long result = Long.parseLong(hexBalance, 16); Assert.assertEquals(0, result); } @@ -548,12 +570,12 @@ public void deployTrc1155() throws Exception { PublicMethod.sendcoin( ownerAddressByte, 500000000000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName = "TronCoins"; - String filePath = "./src/test/resources/soliditycode/contractTrc1155.sol"; + String contractName = "TronCoins"; + String filePath = "./src/test/resources/soliditycode/contractTrc1155.sol"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - int deploySuccessFlag = 1; + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + int deploySuccessFlag = 1; Integer retryTimes = 5; while (retryTimes-- > 0 && deploySuccessFlag != 0) { @@ -593,11 +615,11 @@ public void deployTrc1155() throws Exception { /** constructor. */ public void deployHolder() throws Exception { String contractName = "MyContractCanReceiver"; - String filePath = "./src/test/resources/soliditycode/contractTrc1155.sol"; + String filePath = "./src/test/resources/soliditycode/contractTrc1155.sol"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = PublicMethod.deployContractAndGetTransactionInfoById( contractName, abi, @@ -629,11 +651,11 @@ public void deployHolder() throws Exception { /** constructor. */ public void deployNoHolder() throws Exception { String contractName = "MyContractCanNotReceiver"; - String filePath = "./src/test/resources/soliditycode/contractTrc1155.sol"; + String filePath = "./src/test/resources/soliditycode/contractTrc1155.sol"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = PublicMethod.deployContractAndGetTransactionInfoById( contractName, abi, @@ -664,5 +686,6 @@ public void deployNoHolder() throws Exception { /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(fromAddress, ownerKey, ownerAddressByte, blockingStubFull); } + PublicMethod.freeResource(fromAddress, ownerKey, ownerAddressByte, blockingStubFull); + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractUnknownException.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractUnknownException.java index bece10bb..cbb335a4 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractUnknownException.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ContractUnknownException.java @@ -12,12 +12,11 @@ import org.tron.api.GrpcAPI.AccountResourceMessage; import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.TransactionInfo; -import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class ContractUnknownException extends TronBaseTest { @@ -35,33 +34,35 @@ public class ContractUnknownException extends TronBaseTest { byte[] grammarAddress4 = ecKey4.getAddress(); String testKeyForGrammarAddress4 = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(testKeyForGrammarAddress); logger.info(Long.toString(PublicMethod.queryAccount(foundationKey, blockingStubFull) - .getBalance())); + PublicMethod.printAddress(testKeyForGrammarAddress); + logger.info( + Long.toString(PublicMethod.queryAccount(foundationKey, blockingStubFull).getBalance())); } - @Test(enabled = true, description = "trigger selfdestruct method", groups = {"daily"}) + @Test( + enabled = true, + description = "trigger selfdestruct method", + groups = {"daily"}) public void testGrammar001() { - Assert.assertTrue(PublicMethod - .sendcoin(grammarAddress, 1000000000L, foundationAddress, foundationKey, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + grammarAddress, 1000000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(grammarAddress, 204800000, - 0, 1, testKeyForGrammarAddress, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + grammarAddress, 204800000, 0, 1, testKeyForGrammarAddress, blockingStubFull)); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(grammarAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(grammarAddress, blockingStubFull); info = PublicMethod.queryAccount(grammarAddress, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); long beforeenergyLimit = resourceInfo.getEnergyLimit(); logger.info("beforeBalance:" + beforeBalance); @@ -69,30 +70,39 @@ public void testGrammar001() { logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("beforeenergyLimit:" + beforeenergyLimit); - String filePath = "src/test/resources/soliditycode/contractUnknownException.sol"; - String contractName = "testA"; + String filePath = "src/test/resources/soliditycode/contractUnknownException.sol"; + String contractName = "testA"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 20L, 100, null, testKeyForGrammarAddress, - grammarAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 20L, + 100, + null, + testKeyForGrammarAddress, + grammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - final String s = infoById.get().getResMessage().toStringUtf8(); + final String s = infoById.get().getResMessage().toStringUtf8(); long fee = infoById.get().getFee(); long energyUsage = infoById.get().getReceipt().getEnergyUsage(); long energyFee = infoById.get().getReceipt().getEnergyFee(); Account infoafter = PublicMethod.queryAccount(grammarAddress, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(grammarAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfo.getNetUsed(); - Long afterFreeNetUsed = resourceInfo.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(grammarAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfo.getNetUsed(); + Long afterFreeNetUsed = resourceInfo.getFreeNetUsed(); long aftereenergyLimit = resourceInfo.getEnergyLimit(); logger.info("afterBalance:" + afterBalance); @@ -101,28 +111,32 @@ public void testGrammar001() { logger.info("afterFreeNetUsed:" + afterFreeNetUsed); logger.info("afterenergyLimit:" + aftereenergyLimit); Assert.assertThat(s, containsString("REVERT opcode executed")); - PublicMethod.unFreezeBalance(grammarAddress, testKeyForGrammarAddress, 1, grammarAddress, - blockingStubFull); - PublicMethod.freeResource(grammarAddress, testKeyForGrammarAddress, foundationAddress, - blockingStubFull); + PublicMethod.unFreezeBalance( + grammarAddress, testKeyForGrammarAddress, 1, grammarAddress, blockingStubFull); + PublicMethod.freeResource( + grammarAddress, testKeyForGrammarAddress, foundationAddress, blockingStubFull); } - @Test(enabled = true, description = "trigger revert method", groups = {"daily"}) + @Test( + enabled = true, + description = "trigger revert method", + groups = {"daily"}) public void testGrammar002() { - Assert.assertTrue(PublicMethod - .sendcoin(grammarAddress2, 100000000L, foundationAddress, foundationKey, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + grammarAddress2, 100000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(grammarAddress2, 10000000L, - 0, 1, testKeyForGrammarAddress2, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + grammarAddress2, 10000000L, 0, 1, testKeyForGrammarAddress2, blockingStubFull)); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(grammarAddress2, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(grammarAddress2, blockingStubFull); info = PublicMethod.queryAccount(grammarAddress2, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); long beforeenergyLimit = resourceInfo.getEnergyLimit(); logger.info("beforeBalance:" + beforeBalance); @@ -130,31 +144,40 @@ public void testGrammar002() { logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("beforeenergyLimit:" + beforeenergyLimit); - String filePath = "src/test/resources/soliditycode/contractUnknownException.sol"; - String contractName = "testB"; + String filePath = "src/test/resources/soliditycode/contractUnknownException.sol"; + String contractName = "testB"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 20L, 100, null, testKeyForGrammarAddress2, - grammarAddress2, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 20L, + 100, + null, + testKeyForGrammarAddress2, + grammarAddress2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - final long fee = infoById.get().getFee(); - final long energyUsage = infoById.get().getReceipt().getEnergyUsage(); - final long energyFee = infoById.get().getReceipt().getEnergyFee(); - final String s = infoById.get().getResMessage().toStringUtf8(); + final long fee = infoById.get().getFee(); + final long energyUsage = infoById.get().getReceipt().getEnergyUsage(); + final long energyFee = infoById.get().getReceipt().getEnergyFee(); + final String s = infoById.get().getResMessage().toStringUtf8(); Account infoafter = PublicMethod.queryAccount(grammarAddress2, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(grammarAddress2, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfo.getNetUsed(); - Long afterFreeNetUsed = resourceInfo.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(grammarAddress2, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfo.getNetUsed(); + Long afterFreeNetUsed = resourceInfo.getFreeNetUsed(); long aftereenergyLimit = resourceInfo.getEnergyLimit(); logger.info("afterBalance:" + afterBalance); @@ -166,29 +189,32 @@ public void testGrammar002() { Assert.assertFalse(energyFee == 1000000000); Assert.assertTrue(beforeBalance - fee == afterBalance); - PublicMethod.unFreezeBalance(grammarAddress2, testKeyForGrammarAddress2, 1, grammarAddress2, - blockingStubFull); - PublicMethod.freeResource(grammarAddress2, testKeyForGrammarAddress2, foundationAddress, - blockingStubFull); - + PublicMethod.unFreezeBalance( + grammarAddress2, testKeyForGrammarAddress2, 1, grammarAddress2, blockingStubFull); + PublicMethod.freeResource( + grammarAddress2, testKeyForGrammarAddress2, foundationAddress, blockingStubFull); } - @Test(enabled = true, description = "trigger assert method", groups = {"daily"}) + @Test( + enabled = true, + description = "trigger assert method", + groups = {"daily"}) public void testGrammar003() { - Assert.assertTrue(PublicMethod - .sendcoin(grammarAddress3, 100000000000L, foundationAddress, foundationKey, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + grammarAddress3, 100000000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(grammarAddress3, 1000000000L, - 0, 1, testKeyForGrammarAddress3, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + grammarAddress3, 1000000000L, 0, 1, testKeyForGrammarAddress3, blockingStubFull)); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(grammarAddress3, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(grammarAddress3, blockingStubFull); info = PublicMethod.queryAccount(grammarAddress3, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); long beforeenergyLimit = resourceInfo.getEnergyLimit(); logger.info("beforeBalance:" + beforeBalance); @@ -196,30 +222,39 @@ public void testGrammar003() { logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("beforeenergyLimit:" + beforeenergyLimit); - String filePath = "src/test/resources/soliditycode/contractUnknownException.sol"; - String contractName = "testC"; + String filePath = "src/test/resources/soliditycode/contractUnknownException.sol"; + String contractName = "testC"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 20L, 100, null, testKeyForGrammarAddress3, - grammarAddress3, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 20L, + 100, + null, + testKeyForGrammarAddress3, + grammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - final long fee = infoById.get().getFee(); - final long energyUsage = infoById.get().getReceipt().getEnergyUsage(); - final long energyFee = infoById.get().getReceipt().getEnergyFee(); - String s = infoById.get().getResMessage().toStringUtf8(); + final long fee = infoById.get().getFee(); + final long energyUsage = infoById.get().getReceipt().getEnergyUsage(); + final long energyFee = infoById.get().getReceipt().getEnergyFee(); + String s = infoById.get().getResMessage().toStringUtf8(); Account infoafter = PublicMethod.queryAccount(grammarAddress3, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(grammarAddress3, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfo.getNetUsed(); - Long afterFreeNetUsed = resourceInfo.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(grammarAddress3, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfo.getNetUsed(); + Long afterFreeNetUsed = resourceInfo.getFreeNetUsed(); long aftereenergyLimit = resourceInfo.getEnergyLimit(); logger.info("afterBalance:" + afterBalance); @@ -230,30 +265,32 @@ public void testGrammar003() { logger.info("s:" + s); Assert.assertThat(s, containsString("REVERT opcode executed")); Assert.assertTrue(beforeBalance - fee == afterBalance); - PublicMethod.unFreezeBalance(grammarAddress3, testKeyForGrammarAddress3, 1, grammarAddress3, - blockingStubFull); - PublicMethod.freeResource(grammarAddress3, testKeyForGrammarAddress3, foundationAddress, - blockingStubFull); - + PublicMethod.unFreezeBalance( + grammarAddress3, testKeyForGrammarAddress3, 1, grammarAddress3, blockingStubFull); + PublicMethod.freeResource( + grammarAddress3, testKeyForGrammarAddress3, foundationAddress, blockingStubFull); } - - @Test(enabled = true, description = "trigger require method", groups = {"daily"}) + @Test( + enabled = true, + description = "trigger require method", + groups = {"daily"}) public void testGrammar004() { - Assert.assertTrue(PublicMethod - .sendcoin(grammarAddress4, 100000000000L, foundationAddress, foundationKey, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + grammarAddress4, 100000000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(grammarAddress4, 100000000L, - 0, 1, testKeyForGrammarAddress4, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + grammarAddress4, 100000000L, 0, 1, testKeyForGrammarAddress4, blockingStubFull)); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(grammarAddress4, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(grammarAddress4, blockingStubFull); info = PublicMethod.queryAccount(grammarAddress4, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); long beforeenergyLimit = resourceInfo.getEnergyLimit(); logger.info("beforeBalance:" + beforeBalance); @@ -261,31 +298,40 @@ public void testGrammar004() { logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("beforeenergyLimit:" + beforeenergyLimit); - String filePath = "src/test/resources/soliditycode/contractUnknownException.sol"; - String contractName = "testD"; + String filePath = "src/test/resources/soliditycode/contractUnknownException.sol"; + String contractName = "testD"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 20L, 100, null, testKeyForGrammarAddress4, - grammarAddress4, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 20L, + 100, + null, + testKeyForGrammarAddress4, + grammarAddress4, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - final String s = infoById.get().getResMessage().toStringUtf8(); - final long fee = infoById.get().getFee(); + final String s = infoById.get().getResMessage().toStringUtf8(); + final long fee = infoById.get().getFee(); long energyUsage = infoById.get().getReceipt().getEnergyUsage(); - final long energyFee = infoById.get().getReceipt().getEnergyFee(); + final long energyFee = infoById.get().getReceipt().getEnergyFee(); Account infoafter = PublicMethod.queryAccount(grammarAddress4, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(grammarAddress4, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfo.getNetUsed(); - Long afterFreeNetUsed = resourceInfo.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(grammarAddress4, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfo.getNetUsed(); + Long afterFreeNetUsed = resourceInfo.getFreeNetUsed(); long aftereenergyLimit = resourceInfo.getEnergyLimit(); logger.info("afterBalance:" + afterBalance); @@ -296,16 +342,13 @@ public void testGrammar004() { Assert.assertThat(s, containsString("REVERT opcode executed")); Assert.assertTrue(beforeBalance - fee == afterBalance); Assert.assertFalse(energyFee == 1000000000); - PublicMethod.unFreezeBalance(grammarAddress4, testKeyForGrammarAddress4, 1, grammarAddress4, - blockingStubFull); - PublicMethod.freeResource(grammarAddress4, testKeyForGrammarAddress4, foundationAddress, - blockingStubFull); + PublicMethod.unFreezeBalance( + grammarAddress4, testKeyForGrammarAddress4, 1, grammarAddress4, blockingStubFull); + PublicMethod.freeResource( + grammarAddress4, testKeyForGrammarAddress4, foundationAddress, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/EstimateEnergyTest001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/EstimateEnergyTest001.java index 42da1ad6..8826b62a 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/EstimateEnergyTest001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/EstimateEnergyTest001.java @@ -5,11 +5,11 @@ import com.google.gson.JsonObject; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpPost; import org.junit.Assert; -import org.testng.SkipException; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -18,34 +18,32 @@ import org.tron.api.WalletSolidityGrpc; import org.tron.protos.Protocol; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; -import zmq.socket.pubsub.Pub; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.HttpMethod; +import stest.tron.wallet.common.client.utils.JsonRpcBase; import stest.tron.wallet.common.client.utils.ProposalEnum; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; - -import java.util.HashMap; -import java.util.Optional; -import stest.tron.wallet.common.client.utils.JsonRpcBase.*; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class EstimateEnergyTest001 extends TronBaseTest { - //FullNode1 estimateEnergy = False + // FullNode1 estimateEnergy = False private String soliditynode = - Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list") - .get(1); + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFullSolidity = null; private String pbftnode = - Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list") - .get(3); + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(3); private byte[] contractAddress = null; private byte[] contractAddressTrc721 = null; private byte[] contractAddressTrc20 = null; - //FullNode2 estimateEnergy = True + // FullNode2 estimateEnergy = True private ManagedChannel channelFull2 = null; private WalletGrpc.WalletBlockingStub blockingStubFull2 = null; private String fullnode2 = - Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list") - .get(1); + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); static HttpResponse response; static JSONObject responseContent; public static String jsonRpcNode = @@ -54,52 +52,58 @@ public class EstimateEnergyTest001 extends TronBaseTest { Configuration.getByPath("testng.conf").getStringList("jsonRpcNode.ip.list").get(2); private Long energyFee = 0L; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() throws Exception { channelFull2 = ManagedChannelBuilder.forTarget(fullnode2) - .usePlaintext() - .build(); + public void beforeClass() throws Exception { + channelFull2 = ManagedChannelBuilder.forTarget(fullnode2).usePlaintext().build(); blockingStubFull2 = WalletGrpc.newBlockingStub(channelFull2); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubFullSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - channelPbft = ManagedChannelBuilder.forTarget(pbftnode) - .usePlaintext() - .build(); + channelPbft = ManagedChannelBuilder.forTarget(pbftnode).usePlaintext().build(); blockingStubPbft = WalletSolidityGrpc.newBlockingStub(channelPbft); - String filePath = "src/test/resources/soliditycode/estimateenergy.sol"; - String contractName = "TCtoken"; + String filePath = "src/test/resources/soliditycode/estimateenergy.sol"; + String contractName = "TCtoken"; HashMap retMap = PublicMethod.getBycodeAbiNoOptimize(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 0, 100, 10000, "0", 0, null, foundationKey, foundationAddress, + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0, + 100, + 10000, + "0", + 0, + null, + foundationKey, + foundationAddress, blockingStubFull2); PublicMethod.waitProduceNextBlock(blockingStubFull2); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull2); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull2); if (txid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } contractAddress = infoById.get().getContractAddress().toByteArray(); - //deploy TRC20 + // deploy TRC20 String contractNameTrc20 = "shieldTrc20Token"; - String abiTrc20 = Configuration.getByPath("testng.conf").getString("abi.abi_shieldTrc20Token"); - String codeTrc20 = + String abiTrc20 = Configuration.getByPath("testng.conf").getString("abi.abi_shieldTrc20Token"); + String codeTrc20 = Configuration.getByPath("testng.conf").getString("code.code_shieldTrc20Token"); - String constructorStr = "constructor(uint256,string,string)"; - Long totalSupply = 10000000000L; - String data = totalSupply.toString() + "," + "\"TokenTRC20\"" + "," + "\"zen20\""; + String constructorStr = "constructor(uint256,string,string)"; + Long totalSupply = 10000000000L; + String data = totalSupply.toString() + "," + "\"TokenTRC20\"" + "," + "\"zen20\""; logger.info("data:" + data); - String deployTrc20Txid = + String deployTrc20Txid = PublicMethod.deployContractWithConstantParame( contractNameTrc20, abiTrc20, @@ -121,79 +125,115 @@ public void beforeClass() throws Exception { channelFull2 = ManagedChannelBui Assert.assertTrue(info.get().getReceipt().getResult().toString() == "SUCCESS"); contractAddressTrc20 = info.get().getContractAddress().toByteArray(); - //deploy TRC721 + // deploy TRC721 String filePathTrc721 = "./src/test/resources/soliditycode/trontrc721.sol"; - String contractNameTrc721 = "TRC721Token"; + String contractNameTrc721 = "TRC721Token"; retMap = PublicMethod.getBycodeAbi(filePathTrc721, contractNameTrc721); - String codeTrc721 = retMap.get("byteCode").toString(); - String abiTrc721 = retMap.get("abI").toString(); + String codeTrc721 = retMap.get("byteCode").toString(); + String abiTrc721 = retMap.get("abI").toString(); - contractAddressTrc721 = PublicMethod.deployContract( - contractNameTrc721, abiTrc721, codeTrc721, "", maxFeeLimit, - 0L, 100, null, foundationKey, foundationAddress, blockingStubFull2); + contractAddressTrc721 = + PublicMethod.deployContract( + contractNameTrc721, + abiTrc721, + codeTrc721, + "", + maxFeeLimit, + 0L, + 100, + null, + foundationKey, + foundationAddress, + blockingStubFull2); PublicMethod.waitProduceNextBlock(blockingStubFull2); - energyFee = PublicMethod - .getChainParametersValue(ProposalEnum.GetEnergyFee.getProposalName(), blockingStubFull2); + energyFee = + PublicMethod.getChainParametersValue( + ProposalEnum.GetEnergyFee.getProposalName(), blockingStubFull2); Assert.assertNotEquals(0L, energyFee.longValue()); - } - /** - * constructor. - */ - @Test(enabled = true, description = "EstimateEnergy request fullnode solidity pbft", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "EstimateEnergy request fullnode solidity pbft", + groups = {"daily"}) public void test01TriggerFunctionFullnodeSolidityPbft() { String method = "writeNumber(uint256)"; - String args = "5"; + String args = "5"; boolean isHex = false; Optional estimateEnergyMessage = PublicMethod.estimateEnergy( blockingStubFull2, foundationAddress, contractAddress, 0, method, args, isHex, 0, null); Assert.assertEquals(estimateEnergyMessage.get().getResult().getCode().toString(), "SUCCESS"); - Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); + Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); GrpcAPI.TransactionExtention te = PublicMethod.triggerConstantContractForExtention( - contractAddress, method, args, false, 0, - maxFeeLimit, "#", 0L, foundationAddress, foundationKey, blockingStubFull2); + contractAddress, + method, + args, + false, + 0, + maxFeeLimit, + "#", + 0L, + foundationAddress, + foundationKey, + blockingStubFull2); Assert.assertEquals(te.getResult().getCode().toString(), "SUCCESS"); - Long energyUsedConstant = te.getEnergyUsed(); - //energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. + Long energyUsedConstant = te.getEnergyUsed(); + // energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. Assert.assertTrue((energyEstimateRequired - energyUsedConstant) * energyFee <= 1000000L); - //if do not wait, contact can be null + // if do not wait, contact can be null PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull2, blockingStubFullSolidity); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull2, blockingStubPbft); - //query solidity , query pbft + // query solidity , query pbft Optional estimateEnergyMessageSolidity = PublicMethod.estimateEnergySolidity( - blockingStubFullSolidity, foundationAddress, - contractAddress, 0, method, args, isHex, 0, null); + blockingStubFullSolidity, + foundationAddress, + contractAddress, + 0, + method, + args, + isHex, + 0, + null); logger.info("energyEstimateRequired:" + energyEstimateRequired); - logger.info("estimateEnergyMessageSolidity:" - + estimateEnergyMessageSolidity.get().getEnergyRequired()); + logger.info( + "estimateEnergyMessageSolidity:" + estimateEnergyMessageSolidity.get().getEnergyRequired()); logger.info(estimateEnergyMessage.get().toString()); logger.info(estimateEnergyMessageSolidity.get().toString()); Assert.assertTrue( energyEstimateRequired == estimateEnergyMessageSolidity.get().getEnergyRequired()); Optional estimateEnergyMessagePbft = - PublicMethod.estimateEnergySolidity(blockingStubPbft, - foundationAddress, contractAddress, 0, method, args, isHex, 0, null); + PublicMethod.estimateEnergySolidity( + blockingStubPbft, foundationAddress, contractAddress, 0, method, args, isHex, 0, null); Assert.assertEquals( energyEstimateRequired.longValue(), estimateEnergyMessagePbft.get().getEnergyRequired()); } - /** - * constructor. - */ - @Test(enabled = true, description = "EstimateEnergy to a Revert Function", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "EstimateEnergy to a Revert Function", + groups = {"daily"}) public void test02TriggerFunctionRevert() { String method = "writeNumber(uint256)"; - String args = "5"; + String args = "5"; long callValue = 1; - //give a non payable function a callValue to make REVERT opcode executed + // give a non payable function a callValue to make REVERT opcode executed Optional estimateEnergyMessage = - PublicMethod.estimateEnergy(blockingStubFull2, foundationAddress, - contractAddress, callValue, method, args, false, 0, null); + PublicMethod.estimateEnergy( + blockingStubFull2, + foundationAddress, + contractAddress, + callValue, + method, + args, + false, + 0, + null); Assert.assertEquals( estimateEnergyMessage.get().getResult().getCode().toString(), "CONTRACT_EXE_ERROR"); Assert.assertEquals( @@ -201,162 +241,238 @@ public void test02TriggerFunctionRevert() { "REVERT opcode executed"); } - /** - * constructor. - */ - @Test(enabled = true, description = "EstimateEnergy use to calculate feelimit can be triggered success", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "EstimateEnergy use to calculate feelimit can be triggered success", + groups = {"daily"}) public void test03EstimateEnergyUseToCalculateFeeLimit() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - final byte[] ownerAddress = ecKey1.getAddress(); - final String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + final byte[] ownerAddress = ecKey1.getAddress(); + final String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, 100000000L, - foundationAddress, foundationKey, blockingStubFull2)); + PublicMethod.sendcoin( + ownerAddress, 100000000L, foundationAddress, foundationKey, blockingStubFull2)); PublicMethod.waitProduceNextBlock(blockingStubFull2); - String method = "writeNumber(uint256)"; - String args = "6"; + String method = "writeNumber(uint256)"; + String args = "6"; boolean isHex = false; Optional estimateEnergyMessage = - PublicMethod.estimateEnergy(blockingStubFull2, ownerAddress, - contractAddress, 0, method, args, isHex, 0, null); + PublicMethod.estimateEnergy( + blockingStubFull2, ownerAddress, contractAddress, 0, method, args, isHex, 0, null); Assert.assertEquals(estimateEnergyMessage.get().getResult().getCode().toString(), "SUCCESS"); - Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); + Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); GrpcAPI.TransactionExtention te = PublicMethod.triggerConstantContractForExtention( - contractAddress, method, args, false, 0, - maxFeeLimit, "#", 0L, ownerAddress, ownerKey, blockingStubFull2); + contractAddress, + method, + args, + false, + 0, + maxFeeLimit, + "#", + 0L, + ownerAddress, + ownerKey, + blockingStubFull2); Assert.assertEquals(te.getResult().getCode().toString(), "SUCCESS"); - Long energyUsedConstant = te.getEnergyUsed(); - //energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. + Long energyUsedConstant = te.getEnergyUsed(); + // energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. logger.info("energyUsedConstant:" + energyUsedConstant); logger.info("energyEstimateRequired:" + energyEstimateRequired); Assert.assertNotEquals(energyEstimateRequired.longValue(), energyUsedConstant.longValue()); Assert.assertTrue((energyEstimateRequired - energyUsedConstant) * energyFee <= 1000000L); - Long feeLimit = energyEstimateRequired * energyFee; + Long feeLimit = energyEstimateRequired * energyFee; logger.info("FeeLimit:" + feeLimit); - String triggerTxidSuccess = + String triggerTxidSuccess = PublicMethod.triggerContract( - contractAddress, method, args, isHex, - 0L, feeLimit, ownerAddress, ownerKey, blockingStubFull2); + contractAddress, + method, + args, + isHex, + 0L, + feeLimit, + ownerAddress, + ownerKey, + blockingStubFull2); PublicMethod.waitProduceNextBlock(blockingStubFull2); Optional info = PublicMethod.getTransactionInfoById(triggerTxidSuccess, blockingStubFull2); logger.info(info.get().getReceipt().toString()); Assert.assertEquals(info.get().getReceipt().getResult().toString(), "SUCCESS"); - //if feelimit is low , OUT_OF_ENERGY + // if feelimit is low , OUT_OF_ENERGY args = "8"; - te = PublicMethod.triggerConstantContractForExtention( - contractAddress, method, args, false, 0, - maxFeeLimit, "#", 0L, ownerAddress, ownerKey, blockingStubFull2); + te = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + method, + args, + false, + 0, + maxFeeLimit, + "#", + 0L, + ownerAddress, + ownerKey, + blockingStubFull2); energyUsedConstant = te.getEnergyUsed(); feeLimit = energyUsedConstant - energyFee; - String triggerTxidFail = + String triggerTxidFail = PublicMethod.triggerContract( - contractAddress, method, args, isHex, 0L, - feeLimit, ownerAddress, ownerKey, blockingStubFull2); + contractAddress, + method, + args, + isHex, + 0L, + feeLimit, + ownerAddress, + ownerKey, + blockingStubFull2); PublicMethod.waitProduceNextBlock(blockingStubFull2); info = PublicMethod.getTransactionInfoById(triggerTxidFail, blockingStubFull2); logger.info(info.get().getReceipt().toString()); Assert.assertEquals(info.get().getReceipt().getResult().toString(), "OUT_OF_ENERGY"); } - - /** - * constructor. - */ - @Test(enabled = true, description = "TriggerConstantContract use to calculate feelimit boundary value test", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "TriggerConstantContract use to calculate feelimit boundary value test", + groups = {"daily"}) public void test04FeeLimitBoundary() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - final byte[] ownerAddress = ecKey1.getAddress(); - final String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + final byte[] ownerAddress = ecKey1.getAddress(); + final String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); logger.info("bse58:" + Base58.encode58Check(ownerAddress)); Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, 10000000000L, - foundationAddress, foundationKey, blockingStubFull2)); + PublicMethod.sendcoin( + ownerAddress, 10000000000L, foundationAddress, foundationKey, blockingStubFull2)); PublicMethod.waitProduceNextBlock(blockingStubFull2); - Assert.assertTrue(PublicMethod - .freezeBalanceGetEnergy(ownerAddress, 1000000000L, 3L, 1, ownerKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + ownerAddress, 1000000000L, 3L, 1, ownerKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull2); - String method = "writeNumber(uint256)"; - String args = "6"; + String method = "writeNumber(uint256)"; + String args = "6"; boolean isHex = false; Optional estimateEnergyMessage = - PublicMethod.estimateEnergy(blockingStubFull2, ownerAddress, - contractAddress, 0, method, args, isHex, 0, null); + PublicMethod.estimateEnergy( + blockingStubFull2, ownerAddress, contractAddress, 0, method, args, isHex, 0, null); Assert.assertEquals(estimateEnergyMessage.get().getResult().getCode().toString(), "SUCCESS"); - Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); + Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); GrpcAPI.TransactionExtention te = PublicMethod.triggerConstantContractForExtention( - contractAddress, method, args, false, 0, - maxFeeLimit, "#", 0L, ownerAddress, ownerKey, blockingStubFull2); + contractAddress, + method, + args, + false, + 0, + maxFeeLimit, + "#", + 0L, + ownerAddress, + ownerKey, + blockingStubFull2); Assert.assertEquals(te.getResult().getCode().toString(), "SUCCESS"); - Long energyUsedConstant = te.getEnergyUsed(); - //energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. + Long energyUsedConstant = te.getEnergyUsed(); + // energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. logger.info("energyUsedConstant:" + energyUsedConstant); logger.info("energyEstimateRequired:" + energyEstimateRequired); Assert.assertNotEquals(energyEstimateRequired.longValue(), energyUsedConstant.longValue()); Assert.assertTrue((energyEstimateRequired - energyUsedConstant) * energyFee <= 1000000L); - Long feeLimit = energyEstimateRequired * energyFee; + Long feeLimit = energyEstimateRequired * energyFee; logger.info("FeeLimit:" + feeLimit); - Long feeLimitConstant = energyUsedConstant * energyFee; + Long feeLimitConstant = energyUsedConstant * energyFee; logger.info("feeLimitConstant:" + feeLimitConstant); Assert.assertTrue(feeLimitConstant <= feeLimit); - String failTxid = + String failTxid = PublicMethod.triggerContract( - contractAddress, method, args, isHex, - 0L, feeLimitConstant - 1L, ownerAddress, ownerKey, blockingStubFull2); + contractAddress, + method, + args, + isHex, + 0L, + feeLimitConstant - 1L, + ownerAddress, + ownerKey, + blockingStubFull2); PublicMethod.waitProduceNextBlock(blockingStubFull2); Optional infofail = PublicMethod.getTransactionInfoById(failTxid, blockingStubFull2); logger.info(infofail.get().getReceipt().toString()); Assert.assertEquals(infofail.get().getReceipt().getResult().toString(), "OUT_OF_ENERGY"); PublicMethod.waitProduceNextBlock(blockingStubFull2); - String triggerTxidSuccess = + String triggerTxidSuccess = PublicMethod.triggerContract( - contractAddress, method, args, isHex, - 0L, feeLimitConstant, ownerAddress, ownerKey, blockingStubFull2); + contractAddress, + method, + args, + isHex, + 0L, + feeLimitConstant, + ownerAddress, + ownerKey, + blockingStubFull2); PublicMethod.waitProduceNextBlock(blockingStubFull2); Optional info = PublicMethod.getTransactionInfoById(triggerTxidSuccess, blockingStubFull2); logger.info(info.get().getReceipt().toString()); Assert.assertEquals(info.get().getReceipt().getResult().toString(), "SUCCESS"); - } - /** - * constructor. - */ - @Test(enabled = true, description = "Estimate a function which has emit a event", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Estimate a function which has emit a event", + groups = {"daily"}) public void test05TriggerEventFunction() { String method = "clockOut(address,string,uint256,bool,uint256)"; - String args = "\"TB4B1RMhoPeivkj4Hebm6tttHjRY9yQFes\",\"beijing\",5,true,256"; + String args = "\"TB4B1RMhoPeivkj4Hebm6tttHjRY9yQFes\",\"beijing\",5,true,256"; boolean isHex = false; Optional estimateEnergyMessage = - PublicMethod.estimateEnergy(blockingStubFull2, foundationAddress, - contractAddress, 0, method, args, isHex, 0, null); - Assert.assertEquals(estimateEnergyMessage.get().getResult().getCode().toString(), "SUCCESS"); - Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); + PublicMethod.estimateEnergy( + blockingStubFull2, foundationAddress, contractAddress, 0, method, args, isHex, 0, null); + Assert.assertEquals(estimateEnergyMessage.get().getResult().getCode().toString(), "SUCCESS"); + Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); GrpcAPI.TransactionExtention te = PublicMethod.triggerConstantContractForExtention( - contractAddress, method, args, false, 0, - maxFeeLimit, "#", 0L, foundationAddress, foundationKey, blockingStubFull2); + contractAddress, + method, + args, + false, + 0, + maxFeeLimit, + "#", + 0L, + foundationAddress, + foundationKey, + blockingStubFull2); Assert.assertEquals(te.getResult().getCode().toString(), "SUCCESS"); - Long energyUsedConstant = te.getEnergyUsed(); - //energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. + Long energyUsedConstant = te.getEnergyUsed(); + // energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. Assert.assertTrue((energyEstimateRequired - energyUsedConstant) * energyFee <= 1000000L); } - /** - * constructor. - */ - @Test(enabled = true, description = "Estimate nonexistent function", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Estimate nonexistent function", + groups = {"daily"}) public void test06NotExistFunction() { String method = "aaa(address,string,uint256,bool,uint256)"; - String args = "\"TB4B1RMhoPeivkj4Hebm6tttHjRY9yQFes\",\"beijing\",5,true,256"; + String args = "\"TB4B1RMhoPeivkj4Hebm6tttHjRY9yQFes\",\"beijing\",5,true,256"; boolean isHex = false; Optional estimateEnergyMessage = PublicMethod.estimateEnergy( - blockingStubFull2, foundationAddress, contractAddressTrc721, 0, method, args, isHex, 0, null); + blockingStubFull2, + foundationAddress, + contractAddressTrc721, + 0, + method, + args, + isHex, + 0, + null); Assert.assertEquals( estimateEnergyMessage.get().getResult().getCode().toString(), "CONTRACT_EXE_ERROR"); Assert.assertEquals( @@ -364,163 +480,245 @@ public void test06NotExistFunction() { "REVERT opcode executed"); } - - /** - * constructor. - */ - @Test(enabled = true, description = "Estimate payable function", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Estimate payable function", + groups = {"daily"}) public void test07PayableFunction() { String method = "payMeTRX()"; - String args = ""; + String args = ""; boolean isHex = false; Optional estimateEnergyMessage = - PublicMethod.estimateEnergy(blockingStubFull2, foundationAddress, - contractAddress, 0, method, args, isHex, 0, null); + PublicMethod.estimateEnergy( + blockingStubFull2, foundationAddress, contractAddress, 0, method, args, isHex, 0, null); Assert.assertEquals(estimateEnergyMessage.get().getResult().getCode().toString(), "SUCCESS"); - Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); - GrpcAPI.TransactionExtention te = PublicMethod.triggerConstantContractForExtention( - contractAddress, method, args, false, 10000000L, - maxFeeLimit, "#", 0L, foundationAddress, foundationKey, blockingStubFull2); + Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); + GrpcAPI.TransactionExtention te = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + method, + args, + false, + 10000000L, + maxFeeLimit, + "#", + 0L, + foundationAddress, + foundationKey, + blockingStubFull2); Assert.assertEquals(te.getResult().getCode().toString(), "SUCCESS"); - Long energyUsedConstant = te.getEnergyUsed(); - //energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. + Long energyUsedConstant = te.getEnergyUsed(); + // energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. Assert.assertTrue((energyEstimateRequired - energyUsedConstant) * energyFee <= 1000000L); - } - /** - * constructor. - */ - @Test(enabled = true, description = "Estimate TRC20 important function", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Estimate TRC20 important function", + groups = {"daily"}) public void test08Trc20TransferFunction() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] coinReceiverAddress = ecKey1.getAddress(); - String coinReceiverBase58 = Base58.encode58Check(coinReceiverAddress); - //transfer + byte[] coinReceiverAddress = ecKey1.getAddress(); + String coinReceiverBase58 = Base58.encode58Check(coinReceiverAddress); + // transfer String method = "transfer(address,uint256)"; - String args = "\"" + coinReceiverBase58 + "\",256"; + String args = "\"" + coinReceiverBase58 + "\",256"; boolean isHex = false; Optional estimateEnergyMessage = PublicMethod.estimateEnergy( - blockingStubFull2, foundationAddress, - contractAddressTrc20, 0, method, args, isHex, 0, null); + blockingStubFull2, + foundationAddress, + contractAddressTrc20, + 0, + method, + args, + isHex, + 0, + null); Assert.assertEquals(estimateEnergyMessage.get().getResult().getCode().toString(), "SUCCESS"); - Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); + Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); GrpcAPI.TransactionExtention te = PublicMethod.triggerConstantContractForExtention( - contractAddressTrc20, method, args, false, 0L, - maxFeeLimit, "#", 0L, foundationAddress, foundationKey, blockingStubFull2); + contractAddressTrc20, + method, + args, + false, + 0L, + maxFeeLimit, + "#", + 0L, + foundationAddress, + foundationKey, + blockingStubFull2); Assert.assertEquals(te.getResult().getCode().toString(), "SUCCESS"); - Long energyUsedConstant = te.getEnergyUsed(); - //energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. + Long energyUsedConstant = te.getEnergyUsed(); + // energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. Assert.assertTrue((energyEstimateRequired - energyUsedConstant) * energyFee <= 1000000L); } - /** - * constructor. - */ - @Test(enabled = true, description = "Estimate TRC20 important function", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Estimate TRC20 important function", + groups = {"daily"}) public void test09Trc20BalanceOfFunction() { String method = "balanceOf(address)"; - String args = "\"" + Base58.encode58Check(foundationAddress) + "\""; + String args = "\"" + Base58.encode58Check(foundationAddress) + "\""; boolean isHex = false; Optional estimateEnergyMessage = - PublicMethod.estimateEnergy(blockingStubFull2, foundationAddress, - contractAddressTrc20, 0, method, args, isHex, 0, null); + PublicMethod.estimateEnergy( + blockingStubFull2, + foundationAddress, + contractAddressTrc20, + 0, + method, + args, + isHex, + 0, + null); Assert.assertEquals(estimateEnergyMessage.get().getResult().getCode().toString(), "SUCCESS"); - Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); + Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); GrpcAPI.TransactionExtention te = PublicMethod.triggerConstantContractForExtention( - contractAddressTrc20, method, args, false, 0L, - maxFeeLimit, "#", 0L, foundationAddress, foundationKey, blockingStubFull2); + contractAddressTrc20, + method, + args, + false, + 0L, + maxFeeLimit, + "#", + 0L, + foundationAddress, + foundationKey, + blockingStubFull2); Assert.assertEquals(te.getResult().getCode().toString(), "SUCCESS"); - Long energyUsedConstant = te.getEnergyUsed(); - //energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. + Long energyUsedConstant = te.getEnergyUsed(); + // energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. Assert.assertTrue((energyEstimateRequired - energyUsedConstant) * energyFee <= 1000000L); } - /** - * constructor. - */ - @Test(enabled = true, description = "Estimate TRC20 important function", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Estimate TRC20 important function", + groups = {"daily"}) public void test10Trc20ApproveFunction() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] coinReceiverAddress = ecKey1.getAddress(); - String coinReceiverBase58 = Base58.encode58Check(coinReceiverAddress); - //transfer + byte[] coinReceiverAddress = ecKey1.getAddress(); + String coinReceiverBase58 = Base58.encode58Check(coinReceiverAddress); + // transfer String method = "approve(address,uint256)"; - String args = "\"" + coinReceiverBase58 + "\",256"; + String args = "\"" + coinReceiverBase58 + "\",256"; boolean isHex = false; Optional estimateEnergyMessage = - PublicMethod.estimateEnergy(blockingStubFull2, foundationAddress, - contractAddressTrc20, 0, method, args, isHex, 0, null); + PublicMethod.estimateEnergy( + blockingStubFull2, + foundationAddress, + contractAddressTrc20, + 0, + method, + args, + isHex, + 0, + null); Assert.assertEquals(estimateEnergyMessage.get().getResult().getCode().toString(), "SUCCESS"); - Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); + Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); GrpcAPI.TransactionExtention te = PublicMethod.triggerConstantContractForExtention( - contractAddressTrc20, method, args, false, 0L, - maxFeeLimit, "#", 0L, foundationAddress, foundationKey, blockingStubFull2); + contractAddressTrc20, + method, + args, + false, + 0L, + maxFeeLimit, + "#", + 0L, + foundationAddress, + foundationKey, + blockingStubFull2); Assert.assertEquals(te.getResult().getCode().toString(), "SUCCESS"); - Long energyUsedConstant = te.getEnergyUsed(); - //energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. + Long energyUsedConstant = te.getEnergyUsed(); + // energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. Assert.assertTrue((energyEstimateRequired - energyUsedConstant) * energyFee <= 1000000L); } - /** - * constructor. - */ - @Test(enabled = true, description = "Estimate TRC20 important function", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Estimate TRC20 important function", + groups = {"daily"}) public void test11Trc20AllowanceFunction() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] coinReceiverAddress = ecKey1.getAddress(); - String coinReceiverBase58 = Base58.encode58Check(coinReceiverAddress); - //transfer + byte[] coinReceiverAddress = ecKey1.getAddress(); + String coinReceiverBase58 = Base58.encode58Check(coinReceiverAddress); + // transfer String method = "allowance(address,address)"; - String args = "\"" + Base58.encode58Check(foundationAddress) + "\",\"" - + coinReceiverBase58 + "\""; + String args = + "\"" + Base58.encode58Check(foundationAddress) + "\",\"" + coinReceiverBase58 + "\""; boolean isHex = false; Optional estimateEnergyMessage = - PublicMethod.estimateEnergy(blockingStubFull2, foundationAddress, - contractAddressTrc20, 0, method, args, isHex, 0, null); - Assert.assertEquals(estimateEnergyMessage.get().getResult().getCode().toString(), "SUCCESS"); - Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); + PublicMethod.estimateEnergy( + blockingStubFull2, + foundationAddress, + contractAddressTrc20, + 0, + method, + args, + isHex, + 0, + null); + Assert.assertEquals(estimateEnergyMessage.get().getResult().getCode().toString(), "SUCCESS"); + Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); GrpcAPI.TransactionExtention te = PublicMethod.triggerConstantContractForExtention( - contractAddressTrc20, method, args, false, 0L, - maxFeeLimit, "#", 0L, foundationAddress, foundationKey, blockingStubFull2); + contractAddressTrc20, + method, + args, + false, + 0L, + maxFeeLimit, + "#", + 0L, + foundationAddress, + foundationKey, + blockingStubFull2); Assert.assertEquals(te.getResult().getCode().toString(), "SUCCESS"); - Long energyUsedConstant = te.getEnergyUsed(); - //energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. + Long energyUsedConstant = te.getEnergyUsed(); + // energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. Assert.assertTrue((energyEstimateRequired - energyUsedConstant) * energyFee <= 1000000L); } - /** - * constructor. - */ - @Test(enabled = true, description = "Estimate compare to eth_estimateEnergy", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Estimate compare to eth_estimateEnergy", + groups = {"daily"}) public void test12EthJsonRpcFunction() { String method = "writeNumber(uint256)"; - String args = "5"; + String args = "5"; boolean isHex = false; - //fullnode1 vm.estimateEnergy = false fullnode2 vm.estimateEnergy = true - //query fullnode1 failed and eth_estimateEnergy == triggerConstantContract + // fullnode1 vm.estimateEnergy = false fullnode2 vm.estimateEnergy = true + // query fullnode1 failed and eth_estimateEnergy == triggerConstantContract Optional estimateEnergyMessage = - PublicMethod.estimateEnergy(blockingStubFull, foundationAddress, - contractAddress, 0, method, args, isHex, 0, null); + PublicMethod.estimateEnergy( + blockingStubFull, foundationAddress, contractAddress, 0, method, args, isHex, 0, null); logger.info(estimateEnergyMessage.get().toString()); Assert.assertEquals( estimateEnergyMessage.get().getResult().getCode().toString(), "CONTRACT_VALIDATE_ERROR"); - Assert.assertEquals(estimateEnergyMessage.get().getResult().getMessage().toStringUtf8(), "Contract validate error : this node does not support estimate energy"); - //query json rpc + Assert.assertEquals( + estimateEnergyMessage.get().getResult().getMessage().toStringUtf8(), + "Contract validate error : this node does not support estimate energy"); + // query json rpc JsonObject param = new JsonObject(); param.addProperty("from", ByteArray.toHexString(foundationAddress)); param.addProperty("to", ByteArray.toHexString(contractAddress)); param.addProperty("gas", "0x0"); param.addProperty("gasPrice", "0x0"); param.addProperty("value", "0x0"); - param.addProperty("data", - "0x5637a79c" - + "0000000000000000000000000000000000000000000000000000000000000005"); + param.addProperty( + "data", "0x5637a79c" + "0000000000000000000000000000000000000000000000000000000000000005"); JsonArray params = new JsonArray(); params.add(param); JsonRpcBase jrpc = new JsonRpcBase(); @@ -529,32 +727,50 @@ public void test12EthJsonRpcFunction() { responseContent = HttpMethod.parseResponseContent(response); logger.info(responseContent.toJSONString()); Assert.assertNotNull(responseContent.getString("result")); - Long energyEstimateFromjrpc = + Long energyEstimateFromjrpc = Long.valueOf(responseContent.getString("result").replace("0x", ""), 16); GrpcAPI.TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtention( - contractAddress, method, args, false, 0, - maxFeeLimit, "", 0L, foundationAddress, foundationKey, blockingStubFull); + contractAddress, + method, + args, + false, + 0, + maxFeeLimit, + "", + 0L, + foundationAddress, + foundationKey, + blockingStubFull); logger.info("triggerConstantContract" + transactionExtention.getResult().toString()); logger.info("triggerConstantContract energyUsed:" + transactionExtention.getEnergyUsed()); Assert.assertEquals(transactionExtention.getResult().getCode().toString(), "SUCCESS"); - Assert.assertTrue( - transactionExtention.getEnergyUsed() == energyEstimateFromjrpc.longValue()); - //query fullnode2 - //eth_estimateEnergy == estimateEnergy - //eth_estimateEnergy >= triggerConstantContract energyUsed - estimateEnergyMessage = PublicMethod.estimateEnergy( - blockingStubFull2, foundationAddress, contractAddress, 0, method, args, isHex, 0, null); + Assert.assertTrue(transactionExtention.getEnergyUsed() == energyEstimateFromjrpc.longValue()); + // query fullnode2 + // eth_estimateEnergy == estimateEnergy + // eth_estimateEnergy >= triggerConstantContract energyUsed + estimateEnergyMessage = + PublicMethod.estimateEnergy( + blockingStubFull2, foundationAddress, contractAddress, 0, method, args, isHex, 0, null); Assert.assertEquals(estimateEnergyMessage.get().getResult().getCode().toString(), "SUCCESS"); - Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); + Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); GrpcAPI.TransactionExtention te = PublicMethod.triggerConstantContractForExtention( - contractAddress, method, args, false, 0, - maxFeeLimit, "#", 0L, foundationAddress, foundationKey, blockingStubFull2); + contractAddress, + method, + args, + false, + 0, + maxFeeLimit, + "#", + 0L, + foundationAddress, + foundationKey, + blockingStubFull2); Assert.assertEquals(te.getResult().getCode().toString(), "SUCCESS"); - Long energyUsedConstant = te.getEnergyUsed(); - //energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. + Long energyUsedConstant = te.getEnergyUsed(); + // energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. Assert.assertTrue((energyEstimateRequired - energyUsedConstant) * energyFee <= 1000000L); response = jrpc.getJsonRpc(jsonRpcNode2, requestBody); @@ -569,63 +785,105 @@ public void test12EthJsonRpcFunction() { Assert.assertTrue(energyEstimateFromjrpc.longValue() == energyEstimateRequired.longValue()); } - - /** - * constructor. - */ - @Test(enabled = true, description = "Estimate TRC721 important function", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Estimate TRC721 important function", + groups = {"daily"}) public void test13Trc721BalanceOfFunction() { String method = "balanceOf(address)"; - String args = "\"" + Base58.encode58Check(foundationAddress) + "\""; + String args = "\"" + Base58.encode58Check(foundationAddress) + "\""; boolean isHex = false; Optional estimateEnergyMessage = - PublicMethod.estimateEnergy(blockingStubFull2, foundationAddress, - contractAddressTrc721, 0, method, args, isHex, 0, null); + PublicMethod.estimateEnergy( + blockingStubFull2, + foundationAddress, + contractAddressTrc721, + 0, + method, + args, + isHex, + 0, + null); Assert.assertEquals(estimateEnergyMessage.get().getResult().getCode().toString(), "SUCCESS"); - Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); + Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); GrpcAPI.TransactionExtention te = PublicMethod.triggerConstantContractForExtention( - contractAddressTrc721, method, args, false, 0, - maxFeeLimit, "#", 0L, foundationAddress, foundationKey, blockingStubFull2); + contractAddressTrc721, + method, + args, + false, + 0, + maxFeeLimit, + "#", + 0L, + foundationAddress, + foundationKey, + blockingStubFull2); Assert.assertEquals(te.getResult().getCode().toString(), "SUCCESS"); - Long energyUsedConstant = te.getEnergyUsed(); + Long energyUsedConstant = te.getEnergyUsed(); logger.info("energyUsedConstant:" + energyUsedConstant); logger.info("energyEstimateRequired:" + energyEstimateRequired); - //energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. + // energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. Assert.assertTrue((energyEstimateRequired - energyUsedConstant) * energyFee <= 1000000L); } - /** - * constructor. - */ - @Test(enabled = true, description = "Estimate TRC721 important function", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Estimate TRC721 important function", + groups = {"daily"}) public void test14Trc721MintFunction() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] coinReceiverAddress = ecKey1.getAddress(); - String coinReceiverBase58 = Base58.encode58Check(coinReceiverAddress); - String method = "mintWithTokenURI(address,uint256,string)"; - String args = "\"" + Base58.encode58Check(foundationAddress) + "\",1,\"sdd\""; + byte[] coinReceiverAddress = ecKey1.getAddress(); + String coinReceiverBase58 = Base58.encode58Check(coinReceiverAddress); + String method = "mintWithTokenURI(address,uint256,string)"; + String args = "\"" + Base58.encode58Check(foundationAddress) + "\",1,\"sdd\""; boolean isHex = false; Optional estimateEnergyMessage = - PublicMethod.estimateEnergy(blockingStubFull2, foundationAddress, - contractAddressTrc721, 0, method, args, isHex, 0, null); - Assert.assertEquals(estimateEnergyMessage.get().getResult().getCode().toString(),"SUCCESS"); - Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); + PublicMethod.estimateEnergy( + blockingStubFull2, + foundationAddress, + contractAddressTrc721, + 0, + method, + args, + isHex, + 0, + null); + Assert.assertEquals(estimateEnergyMessage.get().getResult().getCode().toString(), "SUCCESS"); + Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); GrpcAPI.TransactionExtention te = PublicMethod.triggerConstantContractForExtention( - contractAddressTrc721, method, args, false, 0, - maxFeeLimit, "#", 0L, foundationAddress, foundationKey, blockingStubFull2); + contractAddressTrc721, + method, + args, + false, + 0, + maxFeeLimit, + "#", + 0L, + foundationAddress, + foundationKey, + blockingStubFull2); logger.info(te.getResult().toString()); Assert.assertEquals(te.getResult().getCode().toString(), "SUCCESS"); - Long energyUsedConstant = te.getEnergyUsed(); + Long energyUsedConstant = te.getEnergyUsed(); logger.info("energyUsedConstant:" + energyUsedConstant); logger.info("energyEstimateRequired:" + energyEstimateRequired); - //energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. + // energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. Assert.assertTrue((energyEstimateRequired - energyUsedConstant) * energyFee <= 1000000L); - String triggerTxidSuccess = + String triggerTxidSuccess = PublicMethod.triggerContract( - contractAddressTrc721, method, args, isHex, 0L, - maxFeeLimit, foundationAddress, foundationKey, blockingStubFull2); + contractAddressTrc721, + method, + args, + isHex, + 0L, + maxFeeLimit, + foundationAddress, + foundationKey, + blockingStubFull2); PublicMethod.waitProduceNextBlock(blockingStubFull2); Optional info = PublicMethod.getTransactionInfoById(triggerTxidSuccess, blockingStubFull2); @@ -633,173 +891,271 @@ public void test14Trc721MintFunction() { Assert.assertEquals(info.get().getReceipt().getResult().toString(), "SUCCESS"); } - - /** - * constructor. - */ - @Test(enabled = true, - description = "Estimate TRC721 important function", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Estimate TRC721 important function", + groups = {"daily"}) public void test15Trc721TransferFromFunction() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] coinReceiverAddress = ecKey1.getAddress(); - String coinReceiverBase58 = Base58.encode58Check(coinReceiverAddress); - String method = "transferFrom(address,address,uint256)"; - String args = "\"" + Base58.encode58Check(foundationAddress) + "\"," + "\"" - + coinReceiverBase58 + "\",1"; + byte[] coinReceiverAddress = ecKey1.getAddress(); + String coinReceiverBase58 = Base58.encode58Check(coinReceiverAddress); + String method = "transferFrom(address,address,uint256)"; + String args = + "\"" + Base58.encode58Check(foundationAddress) + "\"," + "\"" + coinReceiverBase58 + "\",1"; boolean isHex = false; Optional estimateEnergyMessage = - PublicMethod.estimateEnergy(blockingStubFull2, foundationAddress, - contractAddressTrc721, 0, method, args, isHex, 0, null); + PublicMethod.estimateEnergy( + blockingStubFull2, + foundationAddress, + contractAddressTrc721, + 0, + method, + args, + isHex, + 0, + null); Assert.assertEquals(estimateEnergyMessage.get().getResult().getCode().toString(), "SUCCESS"); - Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); + Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); GrpcAPI.TransactionExtention te = PublicMethod.triggerConstantContractForExtention( - contractAddressTrc721, method, args, false, 0, - maxFeeLimit, "#", 0L, foundationAddress, foundationKey, blockingStubFull2); + contractAddressTrc721, + method, + args, + false, + 0, + maxFeeLimit, + "#", + 0L, + foundationAddress, + foundationKey, + blockingStubFull2); Assert.assertEquals(te.getResult().getCode().toString(), "SUCCESS"); - Long energyUsedConstant = te.getEnergyUsed(); + Long energyUsedConstant = te.getEnergyUsed(); logger.info("energyUsedConstant:" + energyUsedConstant); logger.info("energyEstimateRequired:" + energyEstimateRequired); - //energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. + // energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. Assert.assertTrue((energyEstimateRequired - energyUsedConstant) * energyFee <= 1000000L); } - /** - * constructor. - */ - @Test(enabled = true, - description = "Estimate TRC721 important function", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Estimate TRC721 important function", + groups = {"daily"}) public void test16Trc721SafeTransferFromFunction() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] coinReceiverAddress = ecKey1.getAddress(); - String coinReceiverBase58 = Base58.encode58Check(coinReceiverAddress); - String method = "safeTransferFrom(address,address,uint256)"; - String args = "\"" + Base58.encode58Check(foundationAddress) + "\"," + "\"" - + coinReceiverBase58 + "\",1"; + byte[] coinReceiverAddress = ecKey1.getAddress(); + String coinReceiverBase58 = Base58.encode58Check(coinReceiverAddress); + String method = "safeTransferFrom(address,address,uint256)"; + String args = + "\"" + Base58.encode58Check(foundationAddress) + "\"," + "\"" + coinReceiverBase58 + "\",1"; boolean isHex = false; Optional estimateEnergyMessage = - PublicMethod.estimateEnergy(blockingStubFull2, foundationAddress, - contractAddressTrc721, 0, method, args, isHex, 0, null); + PublicMethod.estimateEnergy( + blockingStubFull2, + foundationAddress, + contractAddressTrc721, + 0, + method, + args, + isHex, + 0, + null); logger.info(estimateEnergyMessage.get().toString()); Assert.assertEquals(estimateEnergyMessage.get().getResult().getCode().toString(), "SUCCESS"); - Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); + Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); GrpcAPI.TransactionExtention te = PublicMethod.triggerConstantContractForExtention( - contractAddressTrc721, method, args, false, 0, - maxFeeLimit, "#", 0L, foundationAddress, foundationKey, blockingStubFull2); + contractAddressTrc721, + method, + args, + false, + 0, + maxFeeLimit, + "#", + 0L, + foundationAddress, + foundationKey, + blockingStubFull2); logger.info(te.toString()); Assert.assertEquals(te.getResult().getCode().toString(), "SUCCESS"); - Long energyUsedConstant = te.getEnergyUsed(); + Long energyUsedConstant = te.getEnergyUsed(); logger.info("energyUsedConstant:" + energyUsedConstant); logger.info("energyEstimateRequired:" + energyEstimateRequired); - //energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. + // energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. Assert.assertTrue((energyEstimateRequired - energyUsedConstant) * energyFee <= 1000000L); } - /** - * constructor. - */ - @Test(enabled = true, - description = "Estimate TRC721 important function", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Estimate TRC721 important function", + groups = {"daily"}) public void test17Trc721MintFunctionApprove() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] coinReceiverAddress = ecKey1.getAddress(); - String coinReceiverBase58 = Base58.encode58Check(coinReceiverAddress); - String method = "approve(address,uint256)"; - String args = "\"" + coinReceiverBase58 + "\",1"; + byte[] coinReceiverAddress = ecKey1.getAddress(); + String coinReceiverBase58 = Base58.encode58Check(coinReceiverAddress); + String method = "approve(address,uint256)"; + String args = "\"" + coinReceiverBase58 + "\",1"; boolean isHex = false; Optional estimateEnergyMessage = - PublicMethod.estimateEnergy(blockingStubFull2, foundationAddress, - contractAddressTrc721, 0, method, args, isHex, 0, null); + PublicMethod.estimateEnergy( + blockingStubFull2, + foundationAddress, + contractAddressTrc721, + 0, + method, + args, + isHex, + 0, + null); logger.info(estimateEnergyMessage.get().toString()); Assert.assertEquals(estimateEnergyMessage.get().getResult().getCode().toString(), "SUCCESS"); - Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); + Long energyEstimateRequired = estimateEnergyMessage.get().getEnergyRequired(); GrpcAPI.TransactionExtention te = PublicMethod.triggerConstantContractForExtention( - contractAddressTrc721, method, args, false, 0, - maxFeeLimit, "#", 0L, foundationAddress, foundationKey, blockingStubFull2); + contractAddressTrc721, + method, + args, + false, + 0, + maxFeeLimit, + "#", + 0L, + foundationAddress, + foundationKey, + blockingStubFull2); logger.info(te.toString()); Assert.assertEquals(te.getResult().getCode().toString(), "SUCCESS"); - Long energyUsedConstant = te.getEnergyUsed(); + Long energyUsedConstant = te.getEnergyUsed(); logger.info("energyUsedConstant:" + energyUsedConstant); logger.info("energyEstimateRequired:" + energyEstimateRequired); - //energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. + // energyEstimateRequired is bigger than energyUsedConstant but not more than 1 TRX. Assert.assertTrue((energyEstimateRequired - energyUsedConstant) * energyFee <= 1000000L); } - /** - * constructor. - */ - @Test(enabled = true, description = "Estimate function with call_value bug-fix call refund", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Estimate function with call_value bug-fix call refund", + groups = {"daily"}) public void test18EstimateWithCallvalue() { - String method = "test()"; - String args = ""; + String args = ""; boolean isHex = false; Optional estimateEnergyMessage = PublicMethod.estimateEnergy( - blockingStubFull2, foundationAddress, contractAddress, 10, method, args, isHex, 0, null); + blockingStubFull2, + foundationAddress, + contractAddress, + 10, + method, + args, + isHex, + 0, + null); Assert.assertEquals(true, estimateEnergyMessage.get().getResult().getResult()); Assert.assertEquals(10563, estimateEnergyMessage.get().getEnergyRequired()); - String txid = PublicMethod.triggerContract(contractAddress, method, args, - false, 10, maxFeeLimit, foundationAddress, foundationKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + method, + args, + false, + 10, + maxFeeLimit, + foundationAddress, + foundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("1 infoById: " + infoById.get().toString()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, + infoById.get().getReceipt().getResult()); long actualEnergyTotal = infoById.get().getReceipt().getEnergyUsageTotal(); long feeLimit = (actualEnergyTotal + 2300) * energyFee; - txid = PublicMethod.triggerContract(contractAddress, method, args, - false, 10, feeLimit, foundationAddress, foundationKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + method, + args, + false, + 10, + feeLimit, + foundationAddress, + foundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("2 infoById: " + infoById.get().toString()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, + infoById.get().getReceipt().getResult()); - txid = PublicMethod.triggerContract(contractAddress, method, args, - false, 10, feeLimit - 1, foundationAddress, foundationKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + method, + args, + false, + 10, + feeLimit - 1, + foundationAddress, + foundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("3 infoById: " + infoById.get().toString()); - //expect out of energy, but success -// Assert.assertEquals(Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY, infoById.get().getReceipt().getResult()); + // expect out of energy, but success + // Assert.assertEquals(Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY, + // infoById.get().getReceipt().getResult()); } - /** - * constructor. - */ - @Test(enabled = true, description = "Estimate function with call_value and command after call", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Estimate function with call_value and command after call", + groups = {"daily"}) public void test19EstimateWithCallvalueAndCommandAfterCall() { String method = "test1()"; - String args = ""; + String args = ""; boolean isHex = false; Optional estimateEnergyMessage = PublicMethod.estimateEnergy( - blockingStubFull2, foundationAddress, contractAddress, 10, method, args, isHex, 0, null); + blockingStubFull2, + foundationAddress, + contractAddress, + 10, + method, + args, + isHex, + 0, + null); Assert.assertEquals(true, estimateEnergyMessage.get().getResult().getResult()); Assert.assertEquals(28700, estimateEnergyMessage.get().getEnergyRequired()); } - /** - * constructor. - */ - @Test(enabled = true, description = "Estimate function out_of_time", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Estimate function out_of_time", + groups = {"daily"}) public void test20EstimateWithCallvalueAndCommandAfterCall() { String method = "testUseCpu(int256)"; - String args = "206000"; + String args = "206000"; boolean isHex = false; Optional estimateEnergyMessage = PublicMethod.estimateEnergy( blockingStubFull2, foundationAddress, contractAddress, 0, method, args, isHex, 0, null); System.out.println(estimateEnergyMessage.get().toString()); - Assert.assertTrue( estimateEnergyMessage.get().toString().contains("CPU timeout")); + Assert.assertTrue(estimateEnergyMessage.get().toString().contains("CPU timeout")); } - @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } - - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/GetTransactionInfoByBlockNumFromSolidity.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/GetTransactionInfoByBlockNumFromSolidity.java index c9ae1e10..c93d1c8d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/GetTransactionInfoByBlockNumFromSolidity.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/GetTransactionInfoByBlockNumFromSolidity.java @@ -1,6 +1,5 @@ package stest.tron.wallet.dailybuild.manual; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import org.junit.Assert; import org.testng.annotations.Test; @@ -10,13 +9,19 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; - public class GetTransactionInfoByBlockNumFromSolidity extends TronBaseTest { public String fullNode = + +public class GetTransactionInfoByBlockNumFromSolidity extends TronBaseTest { + public String fullNode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0); public String solidityNode = Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); - @Test(enabled = true, description = "test getTransactionInfoByBlockNumFromSolidity", groups = {"daily"}) - public void test01GetTransactionInfoByBlockNumFromSolidity() { channelSolidity = ManagedChannelBuilder.forTarget(solidityNode).usePlaintext().build(); + @Test( + enabled = true, + description = "test getTransactionInfoByBlockNumFromSolidity", + groups = {"daily"}) + public void test01GetTransactionInfoByBlockNumFromSolidity() { + channelSolidity = ManagedChannelBuilder.forTarget(solidityNode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); Protocol.Block solidityCurrentBlock = diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/RequireException.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/RequireException.java index 78769726..3c89698a 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/RequireException.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/RequireException.java @@ -16,10 +16,10 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode @@ -33,85 +33,100 @@ public class RequireException extends TronBaseTest { private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; private ManagedChannel channelFull2 = null; private WalletGrpc.WalletBlockingStub blockingStubFull2 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(testKeyForAssetIssue016); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(testKeyForAssetIssue016); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = true, description = "Require Exception", groups = {"daily"}) + @Test( + enabled = true, + description = "Require Exception", + groups = {"daily"}) public void test1TestRequireContract() { ecKey1 = new ECKey(Utils.getRandom()); asset016Address = ecKey1.getAddress(); testKeyForAssetIssue016 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - logger.info(Long.toString(PublicMethod.queryAccount(foundationKey, blockingStubFull) - .getBalance())); + logger.info( + Long.toString(PublicMethod.queryAccount(foundationKey, blockingStubFull).getBalance())); - Assert.assertTrue(PublicMethod - .sendcoin(asset016Address, 1000000000L, foundationAddress, foundationKey, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + asset016Address, 1000000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = + String filePath = "src/test/resources/soliditycode/requireExceptiontest1TestRequireContract.sol"; - String contractName = "TestThrowsContract"; + String contractName = "TestThrowsContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForAssetIssue016, - asset016Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForAssetIssue016, + asset016Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(asset016Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(asset016Address, blockingStubFull); info = PublicMethod.queryAccount(testKeyForAssetIssue016, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - final String txid = PublicMethod.triggerContract(contractAddress, - "testRequire()", "#", false, - 0, maxFeeLimit, asset016Address, testKeyForAssetIssue016, blockingStubFull); + final String txid = + PublicMethod.triggerContract( + contractAddress, + "testRequire()", + "#", + false, + 0, + maxFeeLimit, + asset016Address, + testKeyForAssetIssue016, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("energyUsed:" + energyUsed); Account infoafter = PublicMethod.queryAccount(testKeyForAssetIssue016, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(asset016Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(asset016Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -123,55 +138,74 @@ public void test1TestRequireContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - } - @Test(enabled = true, description = "Throw Exception", groups = {"daily"}) + @Test( + enabled = true, + description = "Throw Exception", + groups = {"daily"}) public void test2TestThrowsContract() { - String filePath = - "src/test/resources/soliditycode/requireExceptiontest2TestThrowsContract.sol"; - String contractName = "TestThrowsContract"; + String filePath = "src/test/resources/soliditycode/requireExceptiontest2TestThrowsContract.sol"; + String contractName = "TestThrowsContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForAssetIssue016, - asset016Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForAssetIssue016, + asset016Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(asset016Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(asset016Address, blockingStubFull); info = PublicMethod.queryAccount(testKeyForAssetIssue016, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - final String txid = PublicMethod.triggerContract(contractAddress, - "testThrow()", "#", false, - 0, maxFeeLimit, asset016Address, testKeyForAssetIssue016, blockingStubFull); + final String txid = + PublicMethod.triggerContract( + contractAddress, + "testThrow()", + "#", + false, + 0, + maxFeeLimit, + asset016Address, + testKeyForAssetIssue016, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("energyUsed:" + energyUsed); Account infoafter = PublicMethod.queryAccount(testKeyForAssetIssue016, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(asset016Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(asset016Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -186,54 +220,73 @@ public void test2TestThrowsContract() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - - @Test(enabled = true, description = "Call Revert ", groups = {"daily"}) + @Test( + enabled = true, + description = "Call Revert ", + groups = {"daily"}) public void test3TestRevertContract() { - String filePath = - "src/test/resources/soliditycode/requireExceptiontest3TestRevertContract.sol"; - String contractName = "TestThrowsContract"; + String filePath = "src/test/resources/soliditycode/requireExceptiontest3TestRevertContract.sol"; + String contractName = "TestThrowsContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForAssetIssue016, - asset016Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForAssetIssue016, + asset016Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(asset016Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(asset016Address, blockingStubFull); info = PublicMethod.queryAccount(testKeyForAssetIssue016, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - final String txid = PublicMethod.triggerContract(contractAddress, - "testRevert()", "#", false, - 0, maxFeeLimit, asset016Address, testKeyForAssetIssue016, blockingStubFull); + final String txid = + PublicMethod.triggerContract( + contractAddress, + "testRevert()", + "#", + false, + 0, + maxFeeLimit, + asset016Address, + testKeyForAssetIssue016, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("energyUsed:" + energyUsed); Account infoafter = PublicMethod.queryAccount(testKeyForAssetIssue016, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(asset016Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(asset016Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -245,55 +298,75 @@ public void test3TestRevertContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - } - @Test(enabled = false, description = "No payable function call value", groups = {"daily"}) + @Test( + enabled = false, + description = "No payable function call value", + groups = {"daily"}) public void test4noPayableContract() { String filePath = "src/test/resources/soliditycode/requireExceptiontest4noPayableContract_1.sol"; - String contractName = "noPayableContract"; + String contractName = "noPayableContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForAssetIssue016, - asset016Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForAssetIssue016, + asset016Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(asset016Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(asset016Address, blockingStubFull); info = PublicMethod.queryAccount(testKeyForAssetIssue016, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - final String txid = PublicMethod.triggerContract(contractAddress, - "noPayable()", "#", false, - 22, maxFeeLimit, asset016Address, testKeyForAssetIssue016, blockingStubFull); + final String txid = + PublicMethod.triggerContract( + contractAddress, + "noPayable()", + "#", + false, + 22, + maxFeeLimit, + asset016Address, + testKeyForAssetIssue016, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("energyUsed:" + energyUsed); Account infoafter = PublicMethod.queryAccount(testKeyForAssetIssue016, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(asset016Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(asset016Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -305,53 +378,64 @@ public void test4noPayableContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - } - @Test(enabled = false, description = "No payable Constructor", groups = {"daily"}) + @Test( + enabled = false, + description = "No payable Constructor", + groups = {"daily"}) public void test5noPayableConstructor() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(asset016Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(asset016Address, blockingStubFull); info = PublicMethod.queryAccount(testKeyForAssetIssue016, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String filePath = + String filePath = "src/test/resources/soliditycode/requireExceptiontest5noPayableConstructor_1.sol"; - String contractName = "MyContract"; + String contractName = "MyContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 22L, 100, null, - testKeyForAssetIssue016, asset016Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 22L, + 100, + null, + testKeyForAssetIssue016, + asset016Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("energyUsed:" + energyUsed); Account infoafter = PublicMethod.queryAccount(testKeyForAssetIssue016, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(asset016Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(asset016Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -363,59 +447,77 @@ public void test5noPayableConstructor() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - - } - @Test(enabled = true, description = "Transfer failed", groups = {"daily"}) + @Test( + enabled = true, + description = "Transfer failed", + groups = {"daily"}) public void test6transferTestContract() { String filePath = "src/test/resources/soliditycode/requireExceptiontest6transferTestContract.sol"; - String contractName = "transferTestContract"; + String contractName = "transferTestContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForAssetIssue016, - asset016Address, blockingStubFull); - final Account info; + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForAssetIssue016, + asset016Address, + blockingStubFull); + final Account info; PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(asset016Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(asset016Address, blockingStubFull); info = PublicMethod.queryAccount(testKeyForAssetIssue016, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String newCxoAddress = "\"" + Base58.encode58Check(foundationAddress) - + "\""; - final String txid = PublicMethod.triggerContract(contractAddress, - "tranferTest(address) ", newCxoAddress, false, - 5, maxFeeLimit, asset016Address, testKeyForAssetIssue016, blockingStubFull); + String newCxoAddress = "\"" + Base58.encode58Check(foundationAddress) + "\""; + final String txid = + PublicMethod.triggerContract( + contractAddress, + "tranferTest(address) ", + newCxoAddress, + false, + 5, + maxFeeLimit, + asset016Address, + testKeyForAssetIssue016, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("energyUsed:" + energyUsed); Account infoafter = PublicMethod.queryAccount(testKeyForAssetIssue016, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(asset016Address, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(asset016Address, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -428,67 +530,96 @@ public void test6transferTestContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - } - @Test(enabled = true, description = "No payable fallback call value", groups = {"daily"}) + @Test( + enabled = true, + description = "No payable fallback call value", + groups = {"daily"}) public void test7payableFallbakContract() { String filePath = "src/test/resources/soliditycode/requireExceptiontest7payableFallbakContract.sol"; - String contractName = "Caller"; + String contractName = "Caller"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForAssetIssue016, - asset016Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForAssetIssue016, + asset016Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Integer times = 0; - String contractName1 = "Test"; + String contractName1 = "Test"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - byte[] contractAddress1; - contractAddress1 = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, 0L, - 100, null, testKeyForAssetIssue016, - asset016Address, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + byte[] contractAddress1; + contractAddress1 = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForAssetIssue016, + asset016Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(asset016Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(asset016Address, blockingStubFull); Account info; info = PublicMethod.queryAccount(testKeyForAssetIssue016, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String saleContractString = "\"" + Base58.encode58Check(contractAddress) + "\""; - final String txid = PublicMethod.triggerContract(contractAddress1, - "callTest(address)", saleContractString, false, - 5, maxFeeLimit, asset016Address, testKeyForAssetIssue016, blockingStubFull); + String saleContractString = "\"" + Base58.encode58Check(contractAddress) + "\""; + final String txid = + PublicMethod.triggerContract( + contractAddress1, + "callTest(address)", + saleContractString, + false, + 5, + maxFeeLimit, + asset016Address, + testKeyForAssetIssue016, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("energyUsed:" + energyUsed); Account infoafter = PublicMethod.queryAccount(testKeyForAssetIssue016, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(asset016Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(asset016Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -500,64 +631,93 @@ public void test7payableFallbakContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - } - @Test(enabled = true, description = "New contract gas not enough", groups = {"daily"}) + @Test( + enabled = true, + description = "New contract gas not enough", + groups = {"daily"}) public void test8newContractGasNoenough() { String filePath = "src/test/resources/soliditycode/requireExceptiontest8newContractGasNoenough.sol"; - String contractName = "Account"; + String contractName = "Account"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForAssetIssue016, - asset016Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForAssetIssue016, + asset016Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName1 = "Initialize"; + String contractName1 = "Initialize"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - final byte[] contractAddress1 = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, - 0L, 100, null, - testKeyForAssetIssue016, asset016Address, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + final byte[] contractAddress1 = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForAssetIssue016, + asset016Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(asset016Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(asset016Address, blockingStubFull); info = PublicMethod.queryAccount(testKeyForAssetIssue016, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - final String txid = PublicMethod.triggerContract(contractAddress1, - "newAccount()", "#", false, - 0, 5226000, asset016Address, testKeyForAssetIssue016, blockingStubFull); + final String txid = + PublicMethod.triggerContract( + contractAddress1, + "newAccount()", + "#", + false, + 0, + 5226000, + asset016Address, + testKeyForAssetIssue016, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("energyUsed:" + energyUsed); Account infoafter = PublicMethod.queryAccount(testKeyForAssetIssue016, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(asset016Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(asset016Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -568,66 +728,94 @@ public void test8newContractGasNoenough() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - - } - @Test(enabled = true, description = "Message used error", groups = {"daily"}) + @Test( + enabled = true, + description = "Message used error", + groups = {"daily"}) public void test9MessageUsedErrorFeed() { String filePath = "src/test/resources/soliditycode/requireExceptiontest9MessageUsedErrorFeed.sol"; - String contractName = "MathedFeed"; + String contractName = "MathedFeed"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForAssetIssue016, - asset016Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForAssetIssue016, + asset016Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - final String saleContractString = "\"" + Base58.encode58Check(contractAddress) + "\""; - String contractName1 = "MathedUseContract"; + final String saleContractString = "\"" + Base58.encode58Check(contractAddress) + "\""; + String contractName1 = "MathedUseContract"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - final byte[] contractAddress1 = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, - 0L, 100, null, - testKeyForAssetIssue016, asset016Address, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + final byte[] contractAddress1 = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForAssetIssue016, + asset016Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(asset016Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(asset016Address, blockingStubFull); info = PublicMethod.queryAccount(testKeyForAssetIssue016, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - final String txid = PublicMethod.triggerContract(contractAddress1, - "messageUse(address)", saleContractString, false, - 0, maxFeeLimit, asset016Address, testKeyForAssetIssue016, blockingStubFull); + final String txid = + PublicMethod.triggerContract( + contractAddress1, + "messageUse(address)", + saleContractString, + false, + 0, + maxFeeLimit, + asset016Address, + testKeyForAssetIssue016, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("energyUsed:" + energyUsed); Account infoafter = PublicMethod.queryAccount(testKeyForAssetIssue016, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(asset016Address, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(asset016Address, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -638,66 +826,95 @@ public void test9MessageUsedErrorFeed() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - } - @Test(enabled = true, description = "Function used error", groups = {"daily"}) + @Test( + enabled = true, + description = "Function used error", + groups = {"daily"}) public void testFunctionUsedErrorFeed() { String filePath = "src/test/resources/soliditycode/requireExceptiontestFunctionUsedErrorFeed.sol"; - String contractName = "MessageFeed"; + String contractName = "MessageFeed"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForAssetIssue016, - asset016Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForAssetIssue016, + asset016Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - final String saleContractString = "\"" + Base58.encode58Check(contractAddress) + "\""; - String contractName1 = "MessageUseContract"; + final String saleContractString = "\"" + Base58.encode58Check(contractAddress) + "\""; + String contractName1 = "MessageUseContract"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - final byte[] contractAddress1 = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, 0L, - 100, null, testKeyForAssetIssue016, - asset016Address, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + final byte[] contractAddress1 = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForAssetIssue016, + asset016Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(asset016Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(asset016Address, blockingStubFull); info = PublicMethod.queryAccount(testKeyForAssetIssue016, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - final String txid = PublicMethod.triggerContract(contractAddress1, - "messageUse(address)", saleContractString, false, - 0, maxFeeLimit, asset016Address, testKeyForAssetIssue016, blockingStubFull); + final String txid = + PublicMethod.triggerContract( + contractAddress1, + "messageUse(address)", + saleContractString, + false, + 0, + maxFeeLimit, + asset016Address, + testKeyForAssetIssue016, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("energyUsed:" + energyUsed); Account infoafter = PublicMethod.queryAccount(testKeyForAssetIssue016, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(asset016Address, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(asset016Address, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -709,7 +926,7 @@ public void testFunctionUsedErrorFeed() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - PublicMethod.freeResource(asset016Address, testKeyForAssetIssue016, foundationAddress, - blockingStubFull); + PublicMethod.freeResource( + asset016Address, testKeyForAssetIssue016, foundationAddress, blockingStubFull); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ResourcePriceTest001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ResourcePriceTest001.java index a3f4dc2c..22f9ff11 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ResourcePriceTest001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/ResourcePriceTest001.java @@ -1,119 +1,109 @@ package stest.tron.wallet.dailybuild.manual; -import com.google.protobuf.ByteString; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; -import java.math.BigInteger; -import java.util.Comparator; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.bouncycastle.util.encoders.Hex; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.tron.api.GrpcAPI; -import org.tron.api.GrpcAPI.NumberMessage; import org.tron.api.WalletGrpc; import org.tron.api.WalletSolidityGrpc; -import org.tron.protos.Protocol.Account; -import org.tron.protos.Protocol.Block; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.ProposalEnum; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; - @Slf4j -public class ResourcePriceTest001 extends TronBaseTest { private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; +public class ResourcePriceTest001 extends TronBaseTest { + private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; private String soliditynode = - Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list") - .get(0); + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFullSolidity = null; private String fullNodeSolidityPort = - Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list") - .get(1); + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); private ManagedChannel channelSolidityPort = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubFullSolidityPort = null; private String pbftnode = - Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list") - .get(2); + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(2); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubFullSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - channelSolidityPort = ManagedChannelBuilder.forTarget(fullNodeSolidityPort) - .usePlaintext() - .build(); + channelSolidityPort = + ManagedChannelBuilder.forTarget(fullNodeSolidityPort).usePlaintext().build(); blockingStubFullSolidityPort = WalletSolidityGrpc.newBlockingStub(channelSolidityPort); - channelPbft = ManagedChannelBuilder.forTarget(pbftnode) - .usePlaintext() - .build(); + channelPbft = ManagedChannelBuilder.forTarget(pbftnode).usePlaintext().build(); blockingStubPbft = WalletSolidityGrpc.newBlockingStub(channelPbft); } - - @Test(enabled = true, description = "get memoFee grpc", groups = {"daily"}) + @Test( + enabled = true, + description = "get memoFee grpc", + groups = {"daily"}) public void test01GetMemoFee() { - //get memoFee from chainParameters + // get memoFee from chainParameters Long memoFeeChainParameters = PublicMethod.getProposalMemoFee(blockingStubFull); - String memoFee = PublicMethod.getMemoFee(blockingStubFull); + String memoFee = PublicMethod.getMemoFee(blockingStubFull); Assert.assertNotNull(memoFee); logger.info("memoFee is " + memoFee); long memoNow = Long.parseLong(memoFee.split(":")[2]); Assert.assertEquals(memoNow, memoFeeChainParameters.longValue()); } - @Test(enabled = true, description = "get energyPrice grpc", groups = {"daily"}) + @Test( + enabled = true, + description = "get energyPrice grpc", + groups = {"daily"}) public void test02GetEnergyPrices() { - //get energyPrice from chainParameters - Long energyPriceChainParameters = PublicMethod.getChainParametersValue( - ProposalEnum.GetEnergyFee.getProposalName(), blockingStubFull - ); - //get energyPrice from grpc interface + // get energyPrice from chainParameters + Long energyPriceChainParameters = + PublicMethod.getChainParametersValue( + ProposalEnum.GetEnergyFee.getProposalName(), blockingStubFull); + // get energyPrice from grpc interface String energyPrice = PublicMethod.getEnergyPrice(blockingStubFull); Assert.assertNotNull(energyPrice); logger.info(energyPrice); logger.info("energyPrice is " + energyPrice); long energyPricesNow = Long.parseLong(energyPrice.split(":")[2]); Assert.assertEquals(energyPricesNow, energyPriceChainParameters.longValue()); - //request solidity and pbft interface and fullNode solidity port + // request solidity and pbft interface and fullNode solidity port String energyPricesSolidity = PublicMethod.getEnergyPriceSolidity(blockingStubFullSolidity); - String energyPricesSolidityPort = PublicMethod.getEnergyPriceSolidity(blockingStubFullSolidityPort); - String energyPricesPbft = PublicMethod.getEnergyPriceSolidity(blockingStubPbft); + String energyPricesSolidityPort = + PublicMethod.getEnergyPriceSolidity(blockingStubFullSolidityPort); + String energyPricesPbft = PublicMethod.getEnergyPriceSolidity(blockingStubPbft); Assert.assertEquals(energyPrice, energyPricesSolidity); Assert.assertEquals(energyPrice, energyPricesPbft); Assert.assertEquals(energyPrice, energyPricesSolidityPort); } - @Test(enabled = true, description = "get bandwidthPrices grpc", groups = {"daily"}) + @Test( + enabled = true, + description = "get bandwidthPrices grpc", + groups = {"daily"}) public void test02GetBandwidthPrices() { - //get BandwidthPrices from chainParameters - Long bandwidthPriceChainParameters = PublicMethod.getChainParametersValue( - ProposalEnum.getTransactionFee.getProposalName(), blockingStubFull - ); - //get BandwidthPrices from grpc interface + // get BandwidthPrices from chainParameters + Long bandwidthPriceChainParameters = + PublicMethod.getChainParametersValue( + ProposalEnum.getTransactionFee.getProposalName(), blockingStubFull); + // get BandwidthPrices from grpc interface String bandwidthPrices = PublicMethod.getBandwidthPrices(blockingStubFull); Assert.assertNotNull(bandwidthPrices); logger.info(bandwidthPrices); logger.info("bandwidthPrices is " + bandwidthPrices); long bandwidthPricesNow = Long.parseLong(bandwidthPrices.split(":")[2]); Assert.assertEquals(bandwidthPricesNow, bandwidthPriceChainParameters.longValue()); - //request solidity and pbft and fullNode solidity port - String bandwidthPricesSolidity = PublicMethod.getBandwidthPricesSolidity(blockingStubFullSolidity); - String bandwidthPricesSolidityPort = PublicMethod.getBandwidthPricesSolidity(blockingStubFullSolidityPort); - String bandwidthPricesPbft = PublicMethod.getBandwidthPricesSolidity(blockingStubPbft); + // request solidity and pbft and fullNode solidity port + String bandwidthPricesSolidity = + PublicMethod.getBandwidthPricesSolidity(blockingStubFullSolidity); + String bandwidthPricesSolidityPort = + PublicMethod.getBandwidthPricesSolidity(blockingStubFullSolidityPort); + String bandwidthPricesPbft = PublicMethod.getBandwidthPricesSolidity(blockingStubPbft); Assert.assertEquals(bandwidthPrices, bandwidthPricesSolidity); Assert.assertEquals(bandwidthPrices, bandwidthPricesPbft); Assert.assertEquals(bandwidthPrices, bandwidthPricesSolidityPort); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount002.java index 34b530bc..5843e530 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount002.java @@ -17,74 +17,65 @@ import org.tron.protos.Protocol.Block; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.TronBaseTest; @Slf4j @MultiNode -public class WalletTestAccount002 extends TronBaseTest { private ManagedChannel searchChannelFull = null; +public class WalletTestAccount002 extends TronBaseTest { + private ManagedChannel searchChannelFull = null; private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; - private String searchFullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String searchFullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - /* @Test(enabled = true, groups = {"daily"}) - public void TestGetAllAccount(){ - GrpcAPI.AccountList accountlist = - blockingStubFull.listAccounts(GrpcAPI.EmptyMessage.newBuilder().build()); - Optional result = Optional.ofNullable(accountlist); - if (result.isPresent()) { - GrpcAPI.AccountList accountList = result.get(); - List list = accountList.getAccountsList(); - List newList = new ArrayList(); - newList.addAll(list); - newList.sort(new AccountComparator()); - GrpcAPI.AccountList.Builder builder = GrpcAPI.AccountList.newBuilder(); - newList.forEach(account -> builder.addAccounts(account)); - result = Optional.of(builder.build()); - } - Assert.assertTrue(result.get().getAccountsCount() > 0); - logger.info(Integer.toString(result.get().getAccountsCount())); - for (int j = 0; j < result.get().getAccountsCount(); j++){ - Assert.assertFalse(result.get().getAccounts(j).getAddress().isEmpty()); - } - + public void TestGetAllAccount(){ + GrpcAPI.AccountList accountlist = + blockingStubFull.listAccounts(GrpcAPI.EmptyMessage.newBuilder().build()); + Optional result = Optional.ofNullable(accountlist); + if (result.isPresent()) { + GrpcAPI.AccountList accountList = result.get(); + List list = accountList.getAccountsList(); + List newList = new ArrayList(); + newList.addAll(list); + newList.sort(new AccountComparator()); + GrpcAPI.AccountList.Builder builder = GrpcAPI.AccountList.newBuilder(); + newList.forEach(account -> builder.addAccounts(account)); + result = Optional.of(builder.build()); + } + Assert.assertTrue(result.get().getAccountsCount() > 0); + logger.info(Integer.toString(result.get().getAccountsCount())); + for (int j = 0; j < result.get().getAccountsCount(); j++){ + Assert.assertFalse(result.get().getAccounts(j).getAddress().isEmpty()); + } - }*/ - /** - * constructor. - */ + }*/ + /** constructor. */ @BeforeClass - public void beforeClass() { searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode) - .usePlaintext() - .build(); + public void beforeClass() { + searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode).usePlaintext().build(); searchBlockingStubFull = WalletGrpc.newBlockingStub(searchChannelFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { if (searchChannelFull != null) { + public void shutdown() throws InterruptedException { + if (searchChannelFull != null) { searchChannelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -93,13 +84,13 @@ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockin } ECKey ecKey = temKey; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -109,23 +100,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } class AccountComparator implements Comparator { @@ -135,5 +121,3 @@ public int compare(Object o1, Object o2) { } } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount010.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount010.java index 6435eeb6..04e4c8d9 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount010.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount010.java @@ -11,15 +11,15 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestAccount010 extends TronBaseTest { private static final long now = System.currentTimeMillis(); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] account010Address = ecKey1.getAddress(); @@ -31,72 +31,77 @@ public class WalletTestAccount010 extends TronBaseTest { byte[] account010InvalidAddress = ecKey3.getAddress(); String account010InvalidKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = false) public void beforeClass() { PublicMethod.printAddress(account010Key); - PublicMethod.printAddress(account010SecondKey); } + PublicMethod.printAddress(account010SecondKey); + } - @Test(enabled = false, groups = {"daily"}) + @Test( + enabled = false, + groups = {"daily"}) public void testGetStorage() { - Assert.assertTrue(PublicMethod.sendcoin(account010Address, 100000000, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(account010SecondAddress, 100000000, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(account010InvalidAddress, 100000000, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + account010Address, 100000000, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + account010SecondAddress, + 100000000, + foundationAddress, + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + account010InvalidAddress, + 100000000, + foundationAddress, + foundationKey, + blockingStubFull)); Account account010Info = PublicMethod.queryAccount(account010Key, blockingStubFull); Assert.assertTrue(account010Info.getAccountResource().getStorageLimit() == 0); Assert.assertTrue(account010Info.getAccountResource().getLatestExchangeStorageTime() == 0); - Assert.assertTrue(PublicMethod.buyStorage(100000000L, account010Address, account010Key, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.buyStorage(100000000L, account010Address, account010Key, blockingStubFull)); account010Info = PublicMethod.queryAccount(account010Key, blockingStubFull); Assert.assertTrue(account010Info.getAccountResource().getStorageLimit() > 0); Assert.assertTrue(account010Info.getAccountResource().getLatestExchangeStorageTime() > 0); - AccountResourceMessage account010Resource = PublicMethod.getAccountResource(account010Address, - blockingStubFull); + AccountResourceMessage account010Resource = + PublicMethod.getAccountResource(account010Address, blockingStubFull); Assert.assertTrue(account010Resource.getStorageLimit() > 0); } - @Test(enabled = false, groups = {"daily"}) + @Test( + enabled = false, + groups = {"daily"}) public void testSellStorage() { - AccountResourceMessage account010Resource = PublicMethod.getAccountResource(account010Address, - blockingStubFull); - Long storageLimit = account010Resource.getStorageLimit(); + AccountResourceMessage account010Resource = + PublicMethod.getAccountResource(account010Address, blockingStubFull); + Long storageLimit = account010Resource.getStorageLimit(); Account account001Info = PublicMethod.queryAccount(account010Key, blockingStubFull); Assert.assertTrue(account001Info.getBalance() == 0); - //When there is no enough storage,sell failed. - Assert.assertFalse(PublicMethod.sellStorage(storageLimit + 1, account010Address, account010Key, - blockingStubFull)); - //Can not sell 0 storage - Assert.assertFalse(PublicMethod.sellStorage(0, account010Address, account010Key, - blockingStubFull)); - //Sell all storage. - Assert.assertTrue(PublicMethod.sellStorage(storageLimit, account010Address, account010Key, - blockingStubFull)); - account010Resource = PublicMethod.getAccountResource(account010Address, - blockingStubFull); + // When there is no enough storage,sell failed. + Assert.assertFalse( + PublicMethod.sellStorage( + storageLimit + 1, account010Address, account010Key, blockingStubFull)); + // Can not sell 0 storage + Assert.assertFalse( + PublicMethod.sellStorage(0, account010Address, account010Key, blockingStubFull)); + // Sell all storage. + Assert.assertTrue( + PublicMethod.sellStorage(storageLimit, account010Address, account010Key, blockingStubFull)); + account010Resource = PublicMethod.getAccountResource(account010Address, blockingStubFull); storageLimit = account010Resource.getStorageLimit(); Assert.assertTrue(storageLimit == 0); account001Info = PublicMethod.queryAccount(account010Key, blockingStubFull); Assert.assertTrue(account001Info.getBalance() > 0); - - } - - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount012.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount012.java index d8f5fa58..5197aef7 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount012.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount012.java @@ -21,22 +21,22 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class WalletTestAccount012 extends TronBaseTest { - private final String testKey002 = Configuration.getByPath("testng.conf") - .getString("mainWitness.key25"); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("mainWitness.key2"); + private final String testKey002 = + Configuration.getByPath("testng.conf").getString("mainWitness.key25"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("mainWitness.key2"); private final byte[] testAddress003 = PublicMethod.getFinalAddress(testKey003); - private final String testKey004 = Configuration.getByPath("testng.conf") - .getString("mainWitness.key3"); + private final String testKey004 = + Configuration.getByPath("testng.conf").getString("mainWitness.key3"); private final byte[] testAddress004 = PublicMethod.getFinalAddress(testKey004); ArrayList txidList = new ArrayList(); Optional infoById = null; @@ -48,122 +48,140 @@ public class WalletTestAccount012 extends TronBaseTest { Long currentBlockNum; private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - //get account + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + // get account - /** - * constructor. - */ - - - /** - * constructor. - */ + /** constructor. */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(testKey002); - PublicMethod.printAddress(testKey003); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(testKey003); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); currentBlock = blockingStubFull1.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); beforeBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); beforeTime = System.currentTimeMillis(); } - @Test(enabled = false, threadPoolSize = 20, invocationCount = 20, groups = {"daily"}) + @Test( + enabled = false, + threadPoolSize = 20, + invocationCount = 20, + groups = {"daily"}) public void storageAndCpu() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] asset011Address = ecKey1.getAddress(); - String testKeyForAssetIssue011 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + byte[] asset011Address = ecKey1.getAddress(); + String testKeyForAssetIssue011 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); PublicMethod.printAddress(testKeyForAssetIssue011); - PublicMethod - .sendcoin(asset011Address, 100000000000000L, foundationAddress, testKey002, blockingStubFull); + PublicMethod.sendcoin( + asset011Address, 100000000000000L, foundationAddress, testKey002, blockingStubFull); Random rand = new Random(); Integer randNum = rand.nextInt(30) + 1; randNum = rand.nextInt(4000); - Long maxFeeLimit = 1000000000L; - String contractName = "StorageAndCpu" + Integer.toString(randNum); - String code = Configuration.getByPath("testng.conf") - .getString("code.code_WalletTestAccount012_storageAndCpu"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_WalletTestAccount012_storageAndCpu"); - byte[] contractAddress = PublicMethod.deployContract(contractName, abi, code, - "", maxFeeLimit, - 0L, 100, null, testKeyForAssetIssue011, asset011Address, blockingStubFull); + Long maxFeeLimit = 1000000000L; + String contractName = "StorageAndCpu" + Integer.toString(randNum); + String code = + Configuration.getByPath("testng.conf") + .getString("code.code_WalletTestAccount012_storageAndCpu"); + String abi = + Configuration.getByPath("testng.conf") + .getString("abi.abi_WalletTestAccount012_storageAndCpu"); + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForAssetIssue011, + asset011Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); - String txid; + String txid; Integer i = 1; - AccountResourceMessage accountResource = PublicMethod.getAccountResource(asset011Address, - blockingStubFull); - accountResource = PublicMethod.getAccountResource(asset011Address, - blockingStubFull); - Long beforeEnergyLimit = accountResource.getEnergyLimit(); - Long afterEnergyLimit; - Long beforeTotalEnergyLimit = accountResource.getTotalEnergyLimit(); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(asset011Address, blockingStubFull); + accountResource = PublicMethod.getAccountResource(asset011Address, blockingStubFull); + Long beforeEnergyLimit = accountResource.getEnergyLimit(); + Long afterEnergyLimit; + Long beforeTotalEnergyLimit = accountResource.getTotalEnergyLimit(); Account account = PublicMethod.queryAccount(testKeyForAssetIssue011, blockingStubFull); - Long afterTotalEnergyLimit; + Long afterTotalEnergyLimit; while (i++ < 20000) { - accountResource = PublicMethod.getAccountResource(asset011Address, - blockingStubFull); + accountResource = PublicMethod.getAccountResource(asset011Address, blockingStubFull); beforeEnergyLimit = accountResource.getEnergyLimit(); beforeTotalEnergyLimit = accountResource.getTotalEnergyLimit(); - String initParmes = "\"" + "21" + "\""; + String initParmes = "\"" + "21" + "\""; /* txid = PublicMethod.triggerContract(contractAddress, - "storage8Char()", "", false, - 0, maxFeeLimit, asset011Address, testKeyForAssetIssue011, blockingStubFull);*/ + "storage8Char()", "", false, + 0, maxFeeLimit, asset011Address, testKeyForAssetIssue011, blockingStubFull);*/ PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull1); - txid = PublicMethod.triggerContract(contractAddress, - "add2(uint256)", initParmes, false, - 0, maxFeeLimit, asset011Address, testKeyForAssetIssue011, blockingStubFull); - accountResource = PublicMethod.getAccountResource(asset011Address, - blockingStubFull); - //logger.info("Current limit is " + accountResource.getTotalEnergyLimit()); - //PublicMethod.freezeBalanceGetEnergy(asset011Address,1000000L,3, + txid = + PublicMethod.triggerContract( + contractAddress, + "add2(uint256)", + initParmes, + false, + 0, + maxFeeLimit, + asset011Address, + testKeyForAssetIssue011, + blockingStubFull); + accountResource = PublicMethod.getAccountResource(asset011Address, blockingStubFull); + // logger.info("Current limit is " + accountResource.getTotalEnergyLimit()); + // PublicMethod.freezeBalanceGetEnergy(asset011Address,1000000L,3, // 1,testKeyForAssetIssue011,blockingStubFull); - accountResource = PublicMethod.getAccountResource(asset011Address, - blockingStubFull); + accountResource = PublicMethod.getAccountResource(asset011Address, blockingStubFull); afterEnergyLimit = accountResource.getEnergyLimit(); afterTotalEnergyLimit = accountResource.getTotalEnergyLimit(); logger.info("Total energy limit is " + (float) afterTotalEnergyLimit / 50000000000L); Float rate = (float) (afterTotalEnergyLimit - beforeTotalEnergyLimit) / beforeTotalEnergyLimit; - //logger.info("rate is " + rate); - //Assert.assertTrue(rate >= 0.001001000 && rate <= 0.001001002); - //txidList.add(txid); + // logger.info("rate is " + rate); + // Assert.assertTrue(rate >= 0.001001000 && rate <= 0.001001002); + // txidList.add(txid); try { Thread.sleep(30); } catch (InterruptedException e) { e.printStackTrace(); } account = PublicMethod.queryAccount(testKeyForAssetIssue011, blockingStubFull); - Float energyrate = (float) (beforeEnergyLimit) / account.getAccountResource() - .getFrozenBalanceForEnergy().getFrozenBalance(); - //logger.info("energy rate is " + energyrate); + Float energyrate = + (float) (beforeEnergyLimit) + / account.getAccountResource().getFrozenBalanceForEnergy().getFrozenBalance(); + // logger.info("energy rate is " + energyrate); if (i % 20 == 0) { - PublicMethod.freezeBalanceForReceiver(foundationAddress, 1000000L, 3, 1, - ByteString.copyFrom(asset011Address), testKey002, blockingStubFull); + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000L, + 3, + 1, + ByteString.copyFrom(asset011Address), + testKey002, + blockingStubFull); } } } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { if (channelFull1 != null) { + public void shutdown() throws InterruptedException { + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount013.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount013.java index 9ec8229a..017b3a1a 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount013.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount013.java @@ -20,12 +20,13 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class WalletTestAccount013 extends TronBaseTest { private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); +public class WalletTestAccount013 extends TronBaseTest { + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); Optional infoById = null; long account013BeforeBalance; @@ -47,144 +48,166 @@ public class WalletTestAccount013 extends TronBaseTest { private final String t String accountForAssetIssueKey; private ManagedChannel channelSoliInFull = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSoliInFull = null; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - private String soliInFullnode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1); - private String soliInPbft = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(2); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + private String soliInFullnode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); + private String soliInPbft = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(2); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - channelSoliInFull = ManagedChannelBuilder.forTarget(soliInFullnode) - .usePlaintext() - .build(); + channelSoliInFull = ManagedChannelBuilder.forTarget(soliInFullnode).usePlaintext().build(); blockingStubSoliInFull = WalletSolidityGrpc.newBlockingStub(channelSoliInFull); - channelPbft = ManagedChannelBuilder.forTarget(soliInPbft) - .usePlaintext() - .build(); + channelPbft = ManagedChannelBuilder.forTarget(soliInPbft).usePlaintext().build(); blockingStubPbft = WalletSolidityGrpc.newBlockingStub(channelPbft); - if(PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + if (PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { throw new SkipException("Skipping delegate resource v1 test case"); } } - @Test(enabled = true, description = "Delegate resource for bandwidth and energy", groups = {"daily"}) + @Test( + enabled = true, + description = "Delegate resource for bandwidth and energy", + groups = {"daily"}) public void test1DelegateResourceForBandwidthAndEnergy() { - //Create account013 + // Create account013 ECKey ecKey1 = new ECKey(Utils.getRandom()); account013Address = ecKey1.getAddress(); testKeyForAccount013 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); PublicMethod.printAddress(testKeyForAccount013); - //Create receiver + // Create receiver ECKey ecKey2 = new ECKey(Utils.getRandom()); receiverDelegateAddress = ecKey2.getAddress(); receiverDelegateKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); PublicMethod.printAddress(receiverDelegateKey); - //Create Empty account + // Create Empty account ECKey ecKey3 = new ECKey(Utils.getRandom()); emptyAddress = ecKey3.getAddress(); emptyKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - //sendcoin to Account013 - Assert.assertTrue(PublicMethod - .sendcoin(account013Address, 10000000000L, foundationAddress, foundationKey, blockingStubFull)); - //sendcoin to receiver - Assert.assertTrue(PublicMethod - .sendcoin(receiverDelegateAddress, 10000000000L, toAddress, testKey003, blockingStubFull)); - //getAccountResource account013 + // sendcoin to Account013 + Assert.assertTrue( + PublicMethod.sendcoin( + account013Address, 10000000000L, foundationAddress, foundationKey, blockingStubFull)); + // sendcoin to receiver + Assert.assertTrue( + PublicMethod.sendcoin( + receiverDelegateAddress, 10000000000L, toAddress, testKey003, blockingStubFull)); + // getAccountResource account013 PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage account013Resource = PublicMethod - .getAccountResource(account013Address, blockingStubFull); + AccountResourceMessage account013Resource = + PublicMethod.getAccountResource(account013Address, blockingStubFull); logger.info("013 energy limit is " + account013Resource.getEnergyLimit()); logger.info("013 net limit is " + account013Resource.getNetLimit()); - //getAccountResource receiver - AccountResourceMessage receiverResource = PublicMethod - .getAccountResource(receiverDelegateAddress, blockingStubFull); + // getAccountResource receiver + AccountResourceMessage receiverResource = + PublicMethod.getAccountResource(receiverDelegateAddress, blockingStubFull); logger.info("receiver energy limit is " + receiverResource.getEnergyLimit()); logger.info("receiver net limit is " + receiverResource.getNetLimit()); - Protocol.Account account013infoBefore = PublicMethod - .queryAccount(account013Address, blockingStubFull); - //get resources of account013 before DelegateResource + Protocol.Account account013infoBefore = + PublicMethod.queryAccount(account013Address, blockingStubFull); + // get resources of account013 before DelegateResource account013BeforeBalance = account013infoBefore.getBalance(); - AccountResourceMessage account013ResBefore = PublicMethod - .getAccountResource(account013Address, blockingStubFull); - final long account013BeforeBandWidth = account013ResBefore.getNetLimit(); - AccountResourceMessage receiverResourceBefore = PublicMethod - .getAccountResource(receiverDelegateAddress, blockingStubFull); + AccountResourceMessage account013ResBefore = + PublicMethod.getAccountResource(account013Address, blockingStubFull); + final long account013BeforeBandWidth = account013ResBefore.getNetLimit(); + AccountResourceMessage receiverResourceBefore = + PublicMethod.getAccountResource(receiverDelegateAddress, blockingStubFull); long receiverBeforeBandWidth = receiverResourceBefore.getNetLimit(); - //Account013 DelegateResource for BandWidth to receiver - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(account013Address, freezeAmount, freezeDuration, 0, - ByteString.copyFrom(receiverDelegateAddress), testKeyForAccount013, blockingStubFull)); - Protocol.Account account013infoAfter = PublicMethod - .queryAccount(account013Address, blockingStubFull); - //get balance of account013 after DelegateResource + // Account013 DelegateResource for BandWidth to receiver + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + account013Address, + freezeAmount, + freezeDuration, + 0, + ByteString.copyFrom(receiverDelegateAddress), + testKeyForAccount013, + blockingStubFull)); + Protocol.Account account013infoAfter = + PublicMethod.queryAccount(account013Address, blockingStubFull); + // get balance of account013 after DelegateResource long account013AfterBalance = account013infoAfter.getBalance(); - AccountResourceMessage account013ResAfter = PublicMethod - .getAccountResource(account013Address, blockingStubFull); - //get BandWidth of account013 after DelegateResource + AccountResourceMessage account013ResAfter = + PublicMethod.getAccountResource(account013Address, blockingStubFull); + // get BandWidth of account013 after DelegateResource long account013AfterBandWidth = account013ResAfter.getNetLimit(); - AccountResourceMessage receiverResourceAfter = PublicMethod - .getAccountResource(receiverDelegateAddress, blockingStubFull); - //Bandwidth of receiver after DelegateResource + AccountResourceMessage receiverResourceAfter = + PublicMethod.getAccountResource(receiverDelegateAddress, blockingStubFull); + // Bandwidth of receiver after DelegateResource long receiverAfterBandWidth = receiverResourceAfter.getNetLimit(); - //Balance of Account013 reduced amount same as DelegateResource + // Balance of Account013 reduced amount same as DelegateResource Assert.assertTrue(account013BeforeBalance == account013AfterBalance + freezeAmount); - //Bandwidth of account013 is equally before and after DelegateResource + // Bandwidth of account013 is equally before and after DelegateResource Assert.assertTrue(account013AfterBandWidth == account013BeforeBandWidth); - //Bandwidth of receiver after DelegateResource is greater than before + // Bandwidth of receiver after DelegateResource is greater than before Assert.assertTrue(receiverAfterBandWidth > receiverBeforeBandWidth); - Protocol.Account account013Before1 = PublicMethod - .queryAccount(account013Address, blockingStubFull); - //balance of account013 before DelegateResource + Protocol.Account account013Before1 = + PublicMethod.queryAccount(account013Address, blockingStubFull); + // balance of account013 before DelegateResource long account013BeforeBalance1 = account013Before1.getBalance(); - AccountResourceMessage account013ResBefore1 = PublicMethod - .getAccountResource(account013Address, blockingStubFull); - //Energy of account013 before DelegateResource + AccountResourceMessage account013ResBefore1 = + PublicMethod.getAccountResource(account013Address, blockingStubFull); + // Energy of account013 before DelegateResource long account013BeforeEnergy = account013ResBefore1.getEnergyLimit(); - AccountResourceMessage receiverResourceBefore1 = PublicMethod - .getAccountResource(receiverDelegateAddress, blockingStubFull); - //Energy of receiver before DelegateResource + AccountResourceMessage receiverResourceBefore1 = + PublicMethod.getAccountResource(receiverDelegateAddress, blockingStubFull); + // Energy of receiver before DelegateResource long receiverBeforeEnergy = receiverResourceBefore1.getEnergyLimit(); - //Account013 DelegateResource Energy to receiver - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(account013Address, freezeAmount, freezeDuration, 1, - ByteString.copyFrom(receiverDelegateAddress), testKeyForAccount013, blockingStubFull)); - Protocol.Account account013infoAfter1 = PublicMethod - .queryAccount(account013Address, blockingStubFull); - //balance of account013 after DelegateResource + // Account013 DelegateResource Energy to receiver + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + account013Address, + freezeAmount, + freezeDuration, + 1, + ByteString.copyFrom(receiverDelegateAddress), + testKeyForAccount013, + blockingStubFull)); + Protocol.Account account013infoAfter1 = + PublicMethod.queryAccount(account013Address, blockingStubFull); + // balance of account013 after DelegateResource long account013AfterBalance1 = account013infoAfter1.getBalance(); - AccountResourceMessage account013ResAfter1 = PublicMethod - .getAccountResource(account013Address, blockingStubFull); + AccountResourceMessage account013ResAfter1 = + PublicMethod.getAccountResource(account013Address, blockingStubFull); long account013AfterEnergy = account013ResAfter1.getEnergyLimit(); - //Energy of account013 after DelegateResource - AccountResourceMessage receiverResourceAfter1 = PublicMethod - .getAccountResource(receiverDelegateAddress, blockingStubFull); - //Energy of receiver after DelegateResource + // Energy of account013 after DelegateResource + AccountResourceMessage receiverResourceAfter1 = + PublicMethod.getAccountResource(receiverDelegateAddress, blockingStubFull); + // Energy of receiver after DelegateResource long receiverAfterEnergy = receiverResourceAfter1.getEnergyLimit(); - //Balance of Account013 reduced amount same as DelegateResource + // Balance of Account013 reduced amount same as DelegateResource Assert.assertTrue(account013BeforeBalance1 == account013AfterBalance1 + freezeAmount); - //Bandwidth of account013 is equally before and after DelegateResource + // Bandwidth of account013 is equally before and after DelegateResource Assert.assertTrue(account013AfterEnergy == account013BeforeEnergy); - //Bandwidth of receiver after DelegateResource is greater than before + // Bandwidth of receiver after DelegateResource is greater than before Assert.assertTrue(receiverAfterEnergy > receiverBeforeEnergy); - //account013 DelegateResource to Empty failed - Assert.assertFalse(PublicMethod - .freezeBalanceForReceiver(account013Address, freezeAmount, freezeDuration, 0, - ByteString.copyFrom(emptyAddress), testKeyForAccount013, blockingStubFull)); - //account013 DelegateResource to account013 failed - Assert.assertFalse(PublicMethod - .freezeBalanceForReceiver(account013Address, freezeAmount, freezeDuration, 0, - ByteString.copyFrom(account013Address), testKeyForAccount013, blockingStubFull)); + // account013 DelegateResource to Empty failed + Assert.assertFalse( + PublicMethod.freezeBalanceForReceiver( + account013Address, + freezeAmount, + freezeDuration, + 0, + ByteString.copyFrom(emptyAddress), + testKeyForAccount013, + blockingStubFull)); + // account013 DelegateResource to account013 failed + Assert.assertFalse( + PublicMethod.freezeBalanceForReceiver( + account013Address, + freezeAmount, + freezeDuration, + 0, + ByteString.copyFrom(account013Address), + testKeyForAccount013, + blockingStubFull)); account013Resource = PublicMethod.getAccountResource(account013Address, blockingStubFull); logger.info("After 013 energy limit is " + account013Resource.getEnergyLimit()); logger.info("After 013 net limit is " + account013Resource.getNetLimit()); @@ -194,278 +217,394 @@ public void test1DelegateResourceForBandwidthAndEnergy() { logger.info("After receiver net limit is " + receiverResource.getNetLimit()); } - @Test(enabled = true, description = "Get delegate resource", groups = {"daily"}) + @Test( + enabled = true, + description = "Get delegate resource", + groups = {"daily"}) public void test2getDelegatedResource() { - //Create Account4 + // Create Account4 ECKey ecKey4 = new ECKey(Utils.getRandom()); account4DelegatedResourceAddress = ecKey4.getAddress(); account4DelegatedResourceKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); - //Create Account5 + // Create Account5 ECKey ecKey5 = new ECKey(Utils.getRandom()); account5DelegatedResourceAddress = ecKey5.getAddress(); account5DelegatedResourceKey = ByteArray.toHexString(ecKey5.getPrivKeyBytes()); - //sendcoin to Account4 - Assert.assertTrue(PublicMethod - .sendcoin(account4DelegatedResourceAddress, 10000000000L, foundationAddress, foundationKey, + // sendcoin to Account4 + Assert.assertTrue( + PublicMethod.sendcoin( + account4DelegatedResourceAddress, + 10000000000L, + foundationAddress, + foundationKey, blockingStubFull)); - //sendcoin to Account5 - Assert.assertTrue(PublicMethod - .sendcoin(account5DelegatedResourceAddress, 20000000000L, toAddress, testKey003, + // sendcoin to Account5 + Assert.assertTrue( + PublicMethod.sendcoin( + account5DelegatedResourceAddress, + 20000000000L, + toAddress, + testKey003, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.Account account4infoBefore = PublicMethod - .queryAccount(account4DelegatedResourceAddress, blockingStubFull); - //Balance of Account4 before DelegateResource + Protocol.Account account4infoBefore = + PublicMethod.queryAccount(account4DelegatedResourceAddress, blockingStubFull); + // Balance of Account4 before DelegateResource final long account4BeforeBalance = account4infoBefore.getBalance(); - //account013 DelegateResource of bandwidth to Account4 - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(account013Address, freezeAmount, freezeDuration, 0, - ByteString.copyFrom(account4DelegatedResourceAddress), testKeyForAccount013, + // account013 DelegateResource of bandwidth to Account4 + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + account013Address, + freezeAmount, + freezeDuration, + 0, + ByteString.copyFrom(account4DelegatedResourceAddress), + testKeyForAccount013, blockingStubFull)); - //Account4 DelegateResource of energy to Account5 - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(account4DelegatedResourceAddress, freezeAmount, freezeDuration, 1, - ByteString.copyFrom(account5DelegatedResourceAddress), account4DelegatedResourceKey, + // Account4 DelegateResource of energy to Account5 + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + account4DelegatedResourceAddress, + freezeAmount, + freezeDuration, + 1, + ByteString.copyFrom(account5DelegatedResourceAddress), + account4DelegatedResourceKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //check DelegatedResourceList,from:account013 to:Account4 - Optional delegatedResourceResult1 = PublicMethod - .getDelegatedResource(account013Address, account4DelegatedResourceAddress, - blockingStubFull); - long afterFreezeBandwidth = delegatedResourceResult1.get().getDelegatedResource(0) - .getFrozenBalanceForBandwidth(); - //check DelegatedResourceList,from:Account4 to:Account5 - Optional delegatedResourceResult2 = PublicMethod - .getDelegatedResource(account4DelegatedResourceAddress, account5DelegatedResourceAddress, - blockingStubFull); - long afterFreezeEnergy = delegatedResourceResult2.get().getDelegatedResource(0) - .getFrozenBalanceForEnergy(); - //FrozenBalanceForBandwidth > 0 + // check DelegatedResourceList,from:account013 to:Account4 + Optional delegatedResourceResult1 = + PublicMethod.getDelegatedResource( + account013Address, account4DelegatedResourceAddress, blockingStubFull); + long afterFreezeBandwidth = + delegatedResourceResult1.get().getDelegatedResource(0).getFrozenBalanceForBandwidth(); + // check DelegatedResourceList,from:Account4 to:Account5 + Optional delegatedResourceResult2 = + PublicMethod.getDelegatedResource( + account4DelegatedResourceAddress, account5DelegatedResourceAddress, blockingStubFull); + long afterFreezeEnergy = + delegatedResourceResult2.get().getDelegatedResource(0).getFrozenBalanceForEnergy(); + // FrozenBalanceForBandwidth > 0 Assert.assertTrue(afterFreezeBandwidth > 0); - //FrozenBalanceForEnergy > 0 + // FrozenBalanceForEnergy > 0 Assert.assertTrue(afterFreezeEnergy > 0); - //check DelegatedResourceAccountIndex for Account4 - Optional delegatedResourceIndexResult1 = PublicMethod - .getDelegatedResourceAccountIndex(account4DelegatedResourceAddress, blockingStubFull); - //result of From list, first Address is same as account013 address - Assert.assertTrue(new String(account013Address) - .equals(new String(delegatedResourceIndexResult1.get().getFromAccounts(0).toByteArray()))); - //result of To list, first Address is same as Account5 address - Assert.assertTrue(new String(account5DelegatedResourceAddress) - .equals(new String(delegatedResourceIndexResult1.get().getToAccounts(0).toByteArray()))); - //unfreezebalance of bandwidth from Account013 to Account4 - Assert.assertTrue(PublicMethod.unFreezeBalance(account013Address, testKeyForAccount013, 0, - account4DelegatedResourceAddress, blockingStubFull)); + // check DelegatedResourceAccountIndex for Account4 + Optional delegatedResourceIndexResult1 = + PublicMethod.getDelegatedResourceAccountIndex( + account4DelegatedResourceAddress, blockingStubFull); + // result of From list, first Address is same as account013 address + Assert.assertTrue( + new String(account013Address) + .equals( + new String(delegatedResourceIndexResult1.get().getFromAccounts(0).toByteArray()))); + // result of To list, first Address is same as Account5 address + Assert.assertTrue( + new String(account5DelegatedResourceAddress) + .equals( + new String(delegatedResourceIndexResult1.get().getToAccounts(0).toByteArray()))); + // unfreezebalance of bandwidth from Account013 to Account4 + Assert.assertTrue( + PublicMethod.unFreezeBalance( + account013Address, + testKeyForAccount013, + 0, + account4DelegatedResourceAddress, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //check DelegatedResourceAccountIndex of Account4 + // check DelegatedResourceAccountIndex of Account4 Optional delegatedResourceIndexResult1AfterUnfreeze = - PublicMethod - .getDelegatedResourceAccountIndex(account4DelegatedResourceAddress, blockingStubFull); - //result of From list is empty + PublicMethod.getDelegatedResourceAccountIndex( + account4DelegatedResourceAddress, blockingStubFull); + // result of From list is empty Assert.assertTrue( delegatedResourceIndexResult1AfterUnfreeze.get().getFromAccountsList().isEmpty()); Assert.assertFalse( delegatedResourceIndexResult1AfterUnfreeze.get().getToAccountsList().isEmpty()); - //Balance of Account013 after unfreezeBalance + // Balance of Account013 after unfreezeBalance // (013 -> receiver(bandwidth), 013 -> receiver(Energy), 013 -> Account4(bandwidth)) - Assert.assertTrue(PublicMethod.queryAccount(account013Address, blockingStubFull).getBalance() - == account013BeforeBalance - 2 * freezeAmount); - //bandwidth from Account013 to Account4 gone + Assert.assertTrue( + PublicMethod.queryAccount(account013Address, blockingStubFull).getBalance() + == account013BeforeBalance - 2 * freezeAmount); + // bandwidth from Account013 to Account4 gone Assert.assertTrue( PublicMethod.getAccountResource(account4DelegatedResourceAddress, blockingStubFull) - .getNetLimit() == 0); - //unfreezebalance of Energy from Account4 to Account5 - Assert.assertTrue(PublicMethod - .unFreezeBalance(account4DelegatedResourceAddress, account4DelegatedResourceKey, 1, - account5DelegatedResourceAddress, blockingStubFull)); + .getNetLimit() + == 0); + // unfreezebalance of Energy from Account4 to Account5 + Assert.assertTrue( + PublicMethod.unFreezeBalance( + account4DelegatedResourceAddress, + account4DelegatedResourceKey, + 1, + account5DelegatedResourceAddress, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.Account account4infoAfterUnfreezeEnergy = PublicMethod - .queryAccount(account4DelegatedResourceAddress, blockingStubFull); - //balance of Account4 after unfreezebalance + Protocol.Account account4infoAfterUnfreezeEnergy = + PublicMethod.queryAccount(account4DelegatedResourceAddress, blockingStubFull); + // balance of Account4 after unfreezebalance long account4BalanceAfterUnfreezeEnergy = account4infoAfterUnfreezeEnergy.getBalance(); - //balance of Account4 is same as before + // balance of Account4 is same as before Assert.assertTrue(account4BeforeBalance == account4BalanceAfterUnfreezeEnergy); - //Energy from Account4 to Account5 gone + // Energy from Account4 to Account5 gone Assert.assertTrue( PublicMethod.getAccountResource(account5DelegatedResourceAddress, blockingStubFull) - .getEnergyLimit() == 0); - //Unfreezebalance of Bandwidth from Account4 to Account5 fail - Assert.assertFalse(PublicMethod - .unFreezeBalance(account4DelegatedResourceAddress, account4DelegatedResourceKey, 0, - account5DelegatedResourceAddress, blockingStubFull)); + .getEnergyLimit() + == 0); + // Unfreezebalance of Bandwidth from Account4 to Account5 fail + Assert.assertFalse( + PublicMethod.unFreezeBalance( + account4DelegatedResourceAddress, + account4DelegatedResourceKey, + 0, + account5DelegatedResourceAddress, + blockingStubFull)); } - @Test(enabled = true, description = "Prepare delegate resource token", groups = {"daily"}) + @Test( + enabled = true, + description = "Prepare delegate resource token", + groups = {"daily"}) public void test3PrepareToken() { - //Create Account7 + // Create Account7 ECKey ecKey7 = new ECKey(Utils.getRandom()); accountForAssetIssueAddress = ecKey7.getAddress(); accountForAssetIssueKey = ByteArray.toHexString(ecKey7.getPrivKeyBytes()); - //sendcoin to Account7 - Assert.assertTrue(PublicMethod - .sendcoin(accountForAssetIssueAddress, 10000000000L, toAddress, testKey003, - blockingStubFull)); - //account013 DelegateResource of bandwidth to accountForAssetIssue - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(account013Address, 1000000000L, freezeDuration, 0, - ByteString.copyFrom(accountForAssetIssueAddress), testKeyForAccount013, + // sendcoin to Account7 + Assert.assertTrue( + PublicMethod.sendcoin( + accountForAssetIssueAddress, 10000000000L, toAddress, testKey003, blockingStubFull)); + // account013 DelegateResource of bandwidth to accountForAssetIssue + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + account013Address, + 1000000000L, + freezeDuration, + 0, + ByteString.copyFrom(accountForAssetIssueAddress), + testKeyForAccount013, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //accountForAssetIssue AssetIssue + // accountForAssetIssue AssetIssue long now = System.currentTimeMillis(); - String name = "testAccount013_" + Long.toString(now); + String name = "testAccount013_" + Long.toString(now); long totalSupply = 100000000000L; - String description = "zfbnb"; - String url = "aaa.com"; - Assert.assertTrue(PublicMethod - .createAssetIssue(accountForAssetIssueAddress, name, totalSupply, 1, 1, - System.currentTimeMillis() + 2000, System.currentTimeMillis() + 1000000000, 1, - description, url, 2000L, 2000L, 500L, 1L, accountForAssetIssueKey, blockingStubFull)); - + String description = "zfbnb"; + String url = "aaa.com"; + Assert.assertTrue( + PublicMethod.createAssetIssue( + accountForAssetIssueAddress, + name, + totalSupply, + 1, + 1, + System.currentTimeMillis() + 2000, + System.currentTimeMillis() + 1000000000, + 1, + description, + url, + 2000L, + 2000L, + 500L, + 1L, + accountForAssetIssueKey, + blockingStubFull)); } - @Test(enabled = true, description = "Delegate resource about transfer asset", groups = {"daily"}) + @Test( + enabled = true, + description = "Delegate resource about transfer asset", + groups = {"daily"}) public void test4DelegateResourceAboutTransferAsset() { - //Wait for 3s + // Wait for 3s PublicMethod.waitProduceNextBlock(blockingStubFull); - //get AssetIssue Id + // get AssetIssue Id Protocol.Account getAssetIdFromThisAccount; - getAssetIdFromThisAccount = PublicMethod - .queryAccount(accountForAssetIssueAddress, blockingStubFull); + getAssetIdFromThisAccount = + PublicMethod.queryAccount(accountForAssetIssueAddress, blockingStubFull); ByteString assetAccountId = getAssetIdFromThisAccount.getAssetIssuedID(); - //Account5 Participate AssetIssue - Assert.assertTrue(PublicMethod - .participateAssetIssue(accountForAssetIssueAddress, assetAccountId.toByteArray(), 1000000, - account5DelegatedResourceAddress, account5DelegatedResourceKey, blockingStubFull)); + // Account5 Participate AssetIssue + Assert.assertTrue( + PublicMethod.participateAssetIssue( + accountForAssetIssueAddress, + assetAccountId.toByteArray(), + 1000000, + account5DelegatedResourceAddress, + account5DelegatedResourceKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //get account013,accountForAssetIssue,Account5 account resources before transferAssets - final long account013CurrentBandwidth = PublicMethod - .getAccountResource(account013Address, blockingStubFull).getNetUsed(); - long accountForAssetIssueCurrentBandwidth = PublicMethod - .getAccountResource(accountForAssetIssueAddress, blockingStubFull).getNetUsed(); - final long account5CurrentBandwidth = PublicMethod - .getAccountResource(account5DelegatedResourceAddress, blockingStubFull).getNetUsed(); - //Account5 transfer Assets receiver - Assert.assertTrue(PublicMethod - .transferAsset(receiverDelegateAddress, assetAccountId.toByteArray(), 100000, - account5DelegatedResourceAddress, account5DelegatedResourceKey, blockingStubFull)); + // get account013,accountForAssetIssue,Account5 account resources before transferAssets + final long account013CurrentBandwidth = + PublicMethod.getAccountResource(account013Address, blockingStubFull).getNetUsed(); + long accountForAssetIssueCurrentBandwidth = + PublicMethod.getAccountResource(accountForAssetIssueAddress, blockingStubFull).getNetUsed(); + final long account5CurrentBandwidth = + PublicMethod.getAccountResource(account5DelegatedResourceAddress, blockingStubFull) + .getNetUsed(); + // Account5 transfer Assets receiver + Assert.assertTrue( + PublicMethod.transferAsset( + receiverDelegateAddress, + assetAccountId.toByteArray(), + 100000, + account5DelegatedResourceAddress, + account5DelegatedResourceKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.printAddress(accountForAssetIssueKey); PublicMethod.printAddress(account5DelegatedResourceKey); - //get account013,accountForAssetIssue,Account5 resource after transferAsset - final long account013CurrentBandwidthAfterTrans = PublicMethod - .getAccountResource(account013Address, blockingStubFull).getNetUsed(); - final long accountForAssetIssueCurrentBandwidthAfterTrans = PublicMethod - .getAccountResource(accountForAssetIssueAddress, blockingStubFull).getFreeNetUsed(); - final long account5CurrentBandwidthAfterTrans = PublicMethod - .getAccountResource(account5DelegatedResourceAddress, blockingStubFull).getNetUsed(); - AccountResourceMessage account5ResourceAfterTrans = PublicMethod - .getAccountResource(account5DelegatedResourceAddress, blockingStubFull); - String result = ""; + // get account013,accountForAssetIssue,Account5 resource after transferAsset + final long account013CurrentBandwidthAfterTrans = + PublicMethod.getAccountResource(account013Address, blockingStubFull).getNetUsed(); + final long accountForAssetIssueCurrentBandwidthAfterTrans = + PublicMethod.getAccountResource(accountForAssetIssueAddress, blockingStubFull) + .getFreeNetUsed(); + final long account5CurrentBandwidthAfterTrans = + PublicMethod.getAccountResource(account5DelegatedResourceAddress, blockingStubFull) + .getNetUsed(); + AccountResourceMessage account5ResourceAfterTrans = + PublicMethod.getAccountResource(account5DelegatedResourceAddress, blockingStubFull); + String result = ""; if (account5ResourceAfterTrans.getAssetNetLimitCount() > 0) { logger.info("getAssetNetLimitCount > 0 "); for (String name1 : account5ResourceAfterTrans.getAssetNetLimitMap().keySet()) { logger.info(name1); result += account5ResourceAfterTrans.getAssetNetUsedMap().get(name1); - } } logger.info(result); PublicMethod.printAddress(receiverDelegateKey); PublicMethod.printAddress(account5DelegatedResourceKey); long account5FreeAssetNetUsed = accountForAssetIssueCurrentBandwidthAfterTrans; - //check resource diff + // check resource diff Assert.assertTrue(Long.parseLong(result) > 0); Assert.assertTrue(account013CurrentBandwidth == account013CurrentBandwidthAfterTrans); Assert.assertTrue(account5CurrentBandwidth == account5CurrentBandwidthAfterTrans); } - @Test(enabled = true, description = "Can't delegate resource for contract", groups = {"daily"}) + @Test( + enabled = true, + description = "Can't delegate resource for contract", + groups = {"daily"}) public void test5CanNotDelegateResourceToContract() { - //Create Account6 + // Create Account6 ECKey ecKey6 = new ECKey(Utils.getRandom()); accountForDeployAddress = ecKey6.getAddress(); accountForDeployKey = ByteArray.toHexString(ecKey6.getPrivKeyBytes()); - //PublicMethod.printAddress(accountForDeployKey); - //sendcoin to Account6 - Assert.assertTrue(PublicMethod - .sendcoin(accountForDeployAddress, 10000000000L, foundationAddress, foundationKey, + // PublicMethod.printAddress(accountForDeployKey); + // sendcoin to Account6 + Assert.assertTrue( + PublicMethod.sendcoin( + accountForDeployAddress, + 10000000000L, + foundationAddress, + foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //deploy contract under Account6 + // deploy contract under Account6 Integer consumeUserResourcePercent = 0; - String contractName = "TestSStore"; - String code = Configuration.getByPath("testng.conf") - .getString("code.code_WalletTestAccount013"); - String abi = Configuration.getByPath("testng.conf").getString("abi.abi_WalletTestAccount013"); + String contractName = "TestSStore"; + String code = + Configuration.getByPath("testng.conf").getString("code.code_WalletTestAccount013"); + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_WalletTestAccount013"); logger.info("TestSStore"); - final byte[] contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, consumeUserResourcePercent, - null, accountForDeployKey, accountForDeployAddress, blockingStubFull); + final byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + consumeUserResourcePercent, + null, + accountForDeployKey, + accountForDeployAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Account4 DelegatedResource of Energy to Contract - //After 3.6 can not delegate resource to contract - Assert.assertFalse(PublicMethod - .freezeBalanceForReceiver(account4DelegatedResourceAddress, freezeAmount, freezeDuration, 1, - ByteString.copyFrom(contractAddress), account4DelegatedResourceKey, blockingStubFull)); + // Account4 DelegatedResource of Energy to Contract + // After 3.6 can not delegate resource to contract + Assert.assertFalse( + PublicMethod.freezeBalanceForReceiver( + account4DelegatedResourceAddress, + freezeAmount, + freezeDuration, + 1, + ByteString.copyFrom(contractAddress), + account4DelegatedResourceKey, + blockingStubFull)); } - - @Test(enabled = true, description = "Get delegate resource from solidity", groups = {"daily"}) + @Test( + enabled = true, + description = "Get delegate resource from solidity", + groups = {"daily"}) public void test6GetDelegateResourceFromSolidity() { - Optional delegateResource = PublicMethod - .getDelegatedResourceFromSolidity(account013Address, receiverDelegateAddress, - blockingStubSolidity); - Assert.assertTrue(delegateResource.get().getDelegatedResource(0) - .getFrozenBalanceForEnergy() == 10000000); - Assert.assertTrue(delegateResource.get().getDelegatedResource(0) - .getFrozenBalanceForBandwidth() == 10000000); + Optional delegateResource = + PublicMethod.getDelegatedResourceFromSolidity( + account013Address, receiverDelegateAddress, blockingStubSolidity); + Assert.assertTrue( + delegateResource.get().getDelegatedResource(0).getFrozenBalanceForEnergy() == 10000000); + Assert.assertTrue( + delegateResource.get().getDelegatedResource(0).getFrozenBalanceForBandwidth() == 10000000); } - @Test(enabled = true, description = "Get delegate resource from PBFT", groups = {"daily"}) + @Test( + enabled = true, + description = "Get delegate resource from PBFT", + groups = {"daily"}) public void test7GetDelegateResourceFromPbft() { - Optional delegateResource = PublicMethod - .getDelegatedResourceFromSolidity(account013Address, receiverDelegateAddress, - blockingStubPbft); - Assert.assertTrue(delegateResource.get().getDelegatedResource(0) - .getFrozenBalanceForEnergy() == 10000000); - Assert.assertTrue(delegateResource.get().getDelegatedResource(0) - .getFrozenBalanceForBandwidth() == 10000000); + Optional delegateResource = + PublicMethod.getDelegatedResourceFromSolidity( + account013Address, receiverDelegateAddress, blockingStubPbft); + Assert.assertTrue( + delegateResource.get().getDelegatedResource(0).getFrozenBalanceForEnergy() == 10000000); + Assert.assertTrue( + delegateResource.get().getDelegatedResource(0).getFrozenBalanceForBandwidth() == 10000000); } - @Test(enabled = true, description = "Get delegate resource index from solidity", groups = {"daily"}) + @Test( + enabled = true, + description = "Get delegate resource index from solidity", + groups = {"daily"}) public void test8GetDelegateResourceIndexFromSolidity() { - Optional delegateResourceIndex = PublicMethod - .getDelegatedResourceAccountIndexFromSolidity(account013Address, - blockingStubSolidity); + Optional delegateResourceIndex = + PublicMethod.getDelegatedResourceAccountIndexFromSolidity( + account013Address, blockingStubSolidity); Assert.assertTrue(delegateResourceIndex.get().getToAccountsCount() == 2); } - @Test(enabled = true, description = "Get delegate resource index from PBFT", groups = {"daily"}) + @Test( + enabled = true, + description = "Get delegate resource index from PBFT", + groups = {"daily"}) public void test9GetDelegateResourceIndexFromPbft() { - Optional delegateResourceIndex = PublicMethod - .getDelegatedResourceAccountIndexFromSolidity(account013Address, - blockingStubSolidity); + Optional delegateResourceIndex = + PublicMethod.getDelegatedResourceAccountIndexFromSolidity( + account013Address, blockingStubSolidity); Assert.assertTrue(delegateResourceIndex.get().getToAccountsCount() == 2); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(account013Address, testKeyForAccount013, - foundationAddress, blockingStubFull); - PublicMethod.freeResource(receiverDelegateAddress, receiverDelegateKey, foundationAddress, + PublicMethod.freeResource( + account013Address, testKeyForAccount013, foundationAddress, blockingStubFull); + PublicMethod.freeResource( + receiverDelegateAddress, receiverDelegateKey, foundationAddress, blockingStubFull); + PublicMethod.freeResource( + account4DelegatedResourceAddress, + account4DelegatedResourceKey, + foundationAddress, + blockingStubFull); + PublicMethod.freeResource( + account5DelegatedResourceAddress, + account5DelegatedResourceKey, + foundationAddress, blockingStubFull); - PublicMethod.freeResource(account4DelegatedResourceAddress, account4DelegatedResourceKey, - foundationAddress, blockingStubFull); - PublicMethod.freeResource(account5DelegatedResourceAddress, account5DelegatedResourceKey, - foundationAddress, blockingStubFull); if (channelSoliInFull != null) { + if (channelSoliInFull != null) { channelSoliInFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount014.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount014.java index 91561288..b1611b4f 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount014.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount014.java @@ -12,8 +12,12 @@ import org.tron.api.WalletSolidityGrpc; import org.tron.protos.Protocol.Account; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.JsonFormat; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestAccount014 extends TronBaseTest { @@ -26,37 +30,34 @@ public class WalletTestAccount014 extends TronBaseTest { String account014SecondKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); private ManagedChannel channelSoliInFull = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSoliInFull = null; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - private String soliInFullnode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + private String soliInFullnode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(testKey002); channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - channelSoliInFull = ManagedChannelBuilder.forTarget(soliInFullnode) - .usePlaintext() - .build(); + PublicMethod.printAddress(testKey002); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + channelSoliInFull = ManagedChannelBuilder.forTarget(soliInFullnode).usePlaintext().build(); blockingStubSoliInFull = WalletSolidityGrpc.newBlockingStub(channelSoliInFull); - if(PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + if (PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { throw new SkipException("Skipping delegate resource v1 test case"); } - } - @Test(enabled = true, description = "Query freeNetUsage in 50061", groups = {"daily"}) + @Test( + enabled = true, + description = "Query freeNetUsage in 50061", + groups = {"daily"}) public void fullAndSoliMerged1ForFreeNetUsage() { - if(PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + if (PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { throw new SkipException("Skipping delegate resource v1 test case"); } - //Create account014 + // Create account014 ecKey1 = new ECKey(Utils.getRandom()); account014Address = ecKey1.getAddress(); account014Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -65,147 +66,190 @@ public void fullAndSoliMerged1ForFreeNetUsage() { account014SecondKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); PublicMethod.printAddress(account014Key); PublicMethod.printAddress(account014SecondKey); - Assert.assertTrue(PublicMethod.sendcoin(account014Address, 1000000000L, foundationAddress, - testKey002, blockingStubFull)); - //Test freeNetUsage in fullnode and soliditynode. - Assert.assertTrue(PublicMethod.sendcoin(account014SecondAddress, 5000000L, - account014Address, account014Key, - blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(account014SecondAddress, 5000000L, - account014Address, account014Key, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + account014Address, 1000000000L, foundationAddress, testKey002, blockingStubFull)); + // Test freeNetUsage in fullnode and soliditynode. + Assert.assertTrue( + PublicMethod.sendcoin( + account014SecondAddress, 5000000L, account014Address, account014Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + account014SecondAddress, 5000000L, account014Address, account014Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account account014 = PublicMethod.queryAccount(account014Address, blockingStubFull); - final long freeNetUsageInFullnode = account014.getFreeNetUsage(); - final long createTimeInFullnode = account014.getCreateTime(); - final long lastOperationTimeInFullnode = account014.getLatestOprationTime(); - final long lastCustomeFreeTimeInFullnode = account014.getLatestConsumeFreeTime(); + final long freeNetUsageInFullnode = account014.getFreeNetUsage(); + final long createTimeInFullnode = account014.getCreateTime(); + final long lastOperationTimeInFullnode = account014.getLatestOprationTime(); + final long lastCustomeFreeTimeInFullnode = account014.getLatestConsumeFreeTime(); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSoliInFull); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSoliInFull); account014 = PublicMethod.queryAccount(account014Address, blockingStubSoliInFull); - final long freeNetUsageInSoliInFull = account014.getFreeNetUsage(); - final long createTimeInSoliInFull = account014.getCreateTime(); - final long lastOperationTimeInSoliInFull = account014.getLatestOprationTime(); - final long lastCustomeFreeTimeInSoliInFull = account014.getLatestConsumeFreeTime(); + final long freeNetUsageInSoliInFull = account014.getFreeNetUsage(); + final long createTimeInSoliInFull = account014.getCreateTime(); + final long lastOperationTimeInSoliInFull = account014.getLatestOprationTime(); + final long lastCustomeFreeTimeInSoliInFull = account014.getLatestConsumeFreeTime(); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); account014 = PublicMethod.queryAccount(account014Address, blockingStubSolidity); - final long freeNetUsageInSolidity = account014.getFreeNetUsage(); - final long createTimeInSolidity = account014.getCreateTime(); - final long lastOperationTimeInSolidity = account014.getLatestOprationTime(); - final long lastCustomeFreeTimeInSolidity = account014.getLatestConsumeFreeTime(); - Assert.assertTrue(freeNetUsageInSoliInFull > 0 && freeNetUsageInSolidity > 0 - && freeNetUsageInFullnode > 0); - Assert.assertTrue(freeNetUsageInFullnode <= freeNetUsageInSoliInFull + 5 - && freeNetUsageInFullnode >= freeNetUsageInSoliInFull - 5); - Assert.assertTrue(freeNetUsageInFullnode <= freeNetUsageInSolidity + 5 - && freeNetUsageInFullnode >= freeNetUsageInSolidity - 5); - Assert.assertTrue(createTimeInFullnode == createTimeInSolidity && createTimeInFullnode - == createTimeInSoliInFull); + final long freeNetUsageInSolidity = account014.getFreeNetUsage(); + final long createTimeInSolidity = account014.getCreateTime(); + final long lastOperationTimeInSolidity = account014.getLatestOprationTime(); + final long lastCustomeFreeTimeInSolidity = account014.getLatestConsumeFreeTime(); + Assert.assertTrue( + freeNetUsageInSoliInFull > 0 && freeNetUsageInSolidity > 0 && freeNetUsageInFullnode > 0); + Assert.assertTrue( + freeNetUsageInFullnode <= freeNetUsageInSoliInFull + 5 + && freeNetUsageInFullnode >= freeNetUsageInSoliInFull - 5); + Assert.assertTrue( + freeNetUsageInFullnode <= freeNetUsageInSolidity + 5 + && freeNetUsageInFullnode >= freeNetUsageInSolidity - 5); + Assert.assertTrue( + createTimeInFullnode == createTimeInSolidity + && createTimeInFullnode == createTimeInSoliInFull); Assert.assertTrue(createTimeInSoliInFull != 0); - Assert.assertTrue(lastOperationTimeInFullnode == lastOperationTimeInSolidity - && lastOperationTimeInFullnode == lastOperationTimeInSoliInFull); + Assert.assertTrue( + lastOperationTimeInFullnode == lastOperationTimeInSolidity + && lastOperationTimeInFullnode == lastOperationTimeInSoliInFull); Assert.assertTrue(lastOperationTimeInSoliInFull != 0); - Assert.assertTrue(lastCustomeFreeTimeInFullnode == lastCustomeFreeTimeInSolidity - && lastCustomeFreeTimeInFullnode == lastCustomeFreeTimeInSoliInFull); + Assert.assertTrue( + lastCustomeFreeTimeInFullnode == lastCustomeFreeTimeInSolidity + && lastCustomeFreeTimeInFullnode == lastCustomeFreeTimeInSoliInFull); Assert.assertTrue(lastCustomeFreeTimeInSoliInFull != 0); } - @Test(enabled = true, description = "Query net usage in 50061", groups = {"daily"}) + @Test( + enabled = true, + description = "Query net usage in 50061", + groups = {"daily"}) public void fullAndSoliMerged2ForNetUsage() { - if(PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + if (PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { throw new SkipException("Skipping delegate resource v1 test case"); } - Assert.assertTrue(PublicMethod.freezeBalance(account014Address, 1000000L, 3, - account014Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance( + account014Address, 1000000L, 3, account014Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.sendcoin(account014SecondAddress, 1000000L, - account014Address, account014Key, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(account014Address, 1000000, - 3, 1, account014Key, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(account014Address, 1000000, - 3, 0, ByteString.copyFrom( - account014SecondAddress), account014Key, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(account014Address, 1000000, - 3, 1, ByteString.copyFrom( - account014SecondAddress), account014Key, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(account014SecondAddress, 1000000, - 3, 0, ByteString.copyFrom( - account014Address), account014SecondKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(account014SecondAddress, 1000000, - 3, 1, ByteString.copyFrom( - account014Address), account014SecondKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + account014SecondAddress, 1000000L, account014Address, account014Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + account014Address, 1000000, 3, 1, account014Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + account014Address, + 1000000, + 3, + 0, + ByteString.copyFrom(account014SecondAddress), + account014Key, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + account014Address, + 1000000, + 3, + 1, + ByteString.copyFrom(account014SecondAddress), + account014Key, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + account014SecondAddress, + 1000000, + 3, + 0, + ByteString.copyFrom(account014Address), + account014SecondKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + account014SecondAddress, + 1000000, + 3, + 1, + ByteString.copyFrom(account014Address), + account014SecondKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSoliInFull); Account account014 = PublicMethod.queryAccount(account014Address, blockingStubFull); logger.info("account014: " + JsonFormat.printToString(account014)); - final long lastCustomeTimeInFullnode = account014.getLatestConsumeTime(); - final long netUsageInFullnode = account014.getNetUsage(); - final long acquiredForBandwidthInFullnode = account014 - .getAcquiredDelegatedFrozenBalanceForBandwidth(); - final long delegatedBandwidthInFullnode = account014.getDelegatedFrozenBalanceForBandwidth(); - final long acquiredForEnergyInFullnode = account014 - .getAccountResource().getAcquiredDelegatedFrozenBalanceForEnergy(); - final long delegatedForEnergyInFullnode = account014 - .getAccountResource().getDelegatedFrozenBalanceForEnergy(); + final long lastCustomeTimeInFullnode = account014.getLatestConsumeTime(); + final long netUsageInFullnode = account014.getNetUsage(); + final long acquiredForBandwidthInFullnode = + account014.getAcquiredDelegatedFrozenBalanceForBandwidth(); + final long delegatedBandwidthInFullnode = account014.getDelegatedFrozenBalanceForBandwidth(); + final long acquiredForEnergyInFullnode = + account014.getAccountResource().getAcquiredDelegatedFrozenBalanceForEnergy(); + final long delegatedForEnergyInFullnode = + account014.getAccountResource().getDelegatedFrozenBalanceForEnergy(); logger.info("delegatedForEnergyInFullnode " + delegatedForEnergyInFullnode); account014 = PublicMethod.queryAccount(account014Address, blockingStubSoliInFull); - final long lastCustomeTimeInSoliInFull = account014.getLatestConsumeTime(); + final long lastCustomeTimeInSoliInFull = account014.getLatestConsumeTime(); logger.info("freeNetUsageInSoliInFull " + lastCustomeTimeInSoliInFull); - final long netUsageInSoliInFull = account014.getNetUsage(); - final long acquiredForBandwidthInSoliInFull = account014 - .getAcquiredDelegatedFrozenBalanceForBandwidth(); - final long delegatedBandwidthInSoliInFull = account014.getDelegatedFrozenBalanceForBandwidth(); - final long acquiredForEnergyInSoliInFull = account014 - .getAccountResource().getAcquiredDelegatedFrozenBalanceForEnergy(); - final long delegatedForEnergyInSoliInFull = account014 - .getAccountResource().getDelegatedFrozenBalanceForEnergy(); + final long netUsageInSoliInFull = account014.getNetUsage(); + final long acquiredForBandwidthInSoliInFull = + account014.getAcquiredDelegatedFrozenBalanceForBandwidth(); + final long delegatedBandwidthInSoliInFull = account014.getDelegatedFrozenBalanceForBandwidth(); + final long acquiredForEnergyInSoliInFull = + account014.getAccountResource().getAcquiredDelegatedFrozenBalanceForEnergy(); + final long delegatedForEnergyInSoliInFull = + account014.getAccountResource().getDelegatedFrozenBalanceForEnergy(); logger.info("delegatedForEnergyInSoliInFull " + delegatedForEnergyInSoliInFull); account014 = PublicMethod.queryAccount(account014Address, blockingStubSolidity); - final long netUsageInSolidity = account014.getNetUsage(); - final long lastCustomeTimeInSolidity = account014.getLatestConsumeTime(); - final long acquiredForBandwidthInSolidity = account014 - .getAcquiredDelegatedFrozenBalanceForBandwidth(); - final long delegatedBandwidthInSolidity = account014.getDelegatedFrozenBalanceForBandwidth(); - final long acquiredForEnergyInSolidity = account014.getAccountResource() - .getAcquiredDelegatedFrozenBalanceForEnergy(); - final long delegatedForEnergyInSolidity = account014.getAccountResource() - .getDelegatedFrozenBalanceForEnergy(); + final long netUsageInSolidity = account014.getNetUsage(); + final long lastCustomeTimeInSolidity = account014.getLatestConsumeTime(); + final long acquiredForBandwidthInSolidity = + account014.getAcquiredDelegatedFrozenBalanceForBandwidth(); + final long delegatedBandwidthInSolidity = account014.getDelegatedFrozenBalanceForBandwidth(); + final long acquiredForEnergyInSolidity = + account014.getAccountResource().getAcquiredDelegatedFrozenBalanceForEnergy(); + final long delegatedForEnergyInSolidity = + account014.getAccountResource().getDelegatedFrozenBalanceForEnergy(); logger.info("delegatedForEnergyInSolidity " + delegatedForEnergyInSolidity); - Assert.assertTrue(netUsageInSoliInFull > 0 && netUsageInSolidity > 0 - && netUsageInFullnode > 0); - Assert.assertTrue(netUsageInFullnode <= netUsageInSoliInFull + 5 - && netUsageInFullnode >= netUsageInSoliInFull - 5); - Assert.assertTrue(netUsageInFullnode <= netUsageInSolidity + 5 - && netUsageInFullnode >= netUsageInSolidity - 5); - Assert.assertTrue(acquiredForBandwidthInFullnode == acquiredForBandwidthInSoliInFull - && acquiredForBandwidthInFullnode == acquiredForBandwidthInSolidity); - Assert.assertTrue(delegatedBandwidthInFullnode == delegatedBandwidthInSoliInFull - && delegatedBandwidthInFullnode == delegatedBandwidthInSolidity); - Assert.assertTrue(acquiredForEnergyInFullnode == acquiredForEnergyInSoliInFull - && acquiredForEnergyInFullnode == acquiredForEnergyInSolidity); - Assert.assertTrue(delegatedForEnergyInFullnode == delegatedForEnergyInSoliInFull - && delegatedForEnergyInFullnode == delegatedForEnergyInSolidity); - Assert.assertTrue(acquiredForBandwidthInSoliInFull == 1000000 - && delegatedBandwidthInSoliInFull == 1000000 && acquiredForEnergyInSoliInFull == 1000000 - && delegatedForEnergyInSoliInFull == 1000000); + Assert.assertTrue(netUsageInSoliInFull > 0 && netUsageInSolidity > 0 && netUsageInFullnode > 0); + Assert.assertTrue( + netUsageInFullnode <= netUsageInSoliInFull + 5 + && netUsageInFullnode >= netUsageInSoliInFull - 5); + Assert.assertTrue( + netUsageInFullnode <= netUsageInSolidity + 5 + && netUsageInFullnode >= netUsageInSolidity - 5); + Assert.assertTrue( + acquiredForBandwidthInFullnode == acquiredForBandwidthInSoliInFull + && acquiredForBandwidthInFullnode == acquiredForBandwidthInSolidity); + Assert.assertTrue( + delegatedBandwidthInFullnode == delegatedBandwidthInSoliInFull + && delegatedBandwidthInFullnode == delegatedBandwidthInSolidity); + Assert.assertTrue( + acquiredForEnergyInFullnode == acquiredForEnergyInSoliInFull + && acquiredForEnergyInFullnode == acquiredForEnergyInSolidity); + Assert.assertTrue( + delegatedForEnergyInFullnode == delegatedForEnergyInSoliInFull + && delegatedForEnergyInFullnode == delegatedForEnergyInSolidity); + Assert.assertTrue( + acquiredForBandwidthInSoliInFull == 1000000 + && delegatedBandwidthInSoliInFull == 1000000 + && acquiredForEnergyInSoliInFull == 1000000 + && delegatedForEnergyInSoliInFull == 1000000); logger.info("lastCustomeTimeInSoliInFull " + lastCustomeTimeInSoliInFull); - Assert.assertTrue(lastCustomeTimeInFullnode == lastCustomeTimeInSolidity - && lastCustomeTimeInFullnode == lastCustomeTimeInSoliInFull); + Assert.assertTrue( + lastCustomeTimeInFullnode == lastCustomeTimeInSolidity + && lastCustomeTimeInFullnode == lastCustomeTimeInSoliInFull); logger.info("lastCustomeTimeInSoliInFull " + lastCustomeTimeInSoliInFull); Assert.assertTrue(lastCustomeTimeInSoliInFull != 0); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(account014Address, account014Key, foundationAddress, blockingStubFull); - PublicMethod - .freeResource(account014SecondAddress, account014SecondKey, foundationAddress, blockingStubFull); } -} \ No newline at end of file + PublicMethod.freeResource( + account014Address, account014Key, foundationAddress, blockingStubFull); + PublicMethod.freeResource( + account014SecondAddress, account014SecondKey, foundationAddress, blockingStubFull); + } +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount015.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount015.java index 5a712eb9..9ea667fe 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount015.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestAccount015.java @@ -1,10 +1,7 @@ package stest.tron.wallet.dailybuild.manual; -import com.google.protobuf.ByteString; - import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; -import java.util.HashMap; import java.util.Random; import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; @@ -12,11 +9,13 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.tron.api.GrpcAPI; import org.tron.api.WalletSolidityGrpc; -import org.tron.protos.Protocol; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*;; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestAccount015 extends TronBaseTest { @@ -29,113 +28,129 @@ public class WalletTestAccount015 extends TronBaseTest { String account015Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelSoliInFull = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSoliInFull = null; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - private String soliInFullnode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1); - private String soliInPbft = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(2); - - /** - * constructor. - */ + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + private String soliInFullnode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); + private String soliInPbft = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(2); + + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initPbftChannel(); initSolidityChannel(); - PublicMethod.printAddress(testKey002); channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - channelSoliInFull = ManagedChannelBuilder.forTarget(soliInFullnode) - .usePlaintext() - .build(); + PublicMethod.printAddress(testKey002); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + channelSoliInFull = ManagedChannelBuilder.forTarget(soliInFullnode).usePlaintext().build(); blockingStubSoliInFull = WalletSolidityGrpc.newBlockingStub(channelSoliInFull); - channelPbft = ManagedChannelBuilder.forTarget(soliInPbft) - .usePlaintext() - .build(); + channelPbft = ManagedChannelBuilder.forTarget(soliInPbft).usePlaintext().build(); Random rand = new Random(); amount = amount + rand.nextInt(10000); } - @Test(enabled = true, description = "Set account id", groups = {"daily"}) + @Test( + enabled = true, + description = "Set account id", + groups = {"daily"}) public void test01SetAccountId() { - //Create account014 + // Create account014 ecKey1 = new ECKey(Utils.getRandom()); account015Address = ecKey1.getAddress(); account015Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); PublicMethod.printAddress(account015Key); - Assert.assertTrue(PublicMethod.sendcoin(account015Address, amount, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + account015Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.setAccountId(accountId.getBytes(), - account015Address, account015Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.setAccountId( + accountId.getBytes(), account015Address, account015Key, blockingStubFull)); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSoliInFull); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSoliInFull); } - @Test(enabled = true, description = "Get account by id", groups = {"daily"}) + @Test( + enabled = true, + description = "Get account by id", + groups = {"daily"}) public void test02GetAccountById() { - Assert.assertEquals(amount, PublicMethod.getAccountById( - accountId, blockingStubFull).getBalance()); + Assert.assertEquals( + amount, PublicMethod.getAccountById(accountId, blockingStubFull).getBalance()); } - - @Test(enabled = true, description = "Get account by id from solidity", groups = {"daily"}) + @Test( + enabled = true, + description = "Get account by id from solidity", + groups = {"daily"}) public void test03GetAccountByIdFromSolidity() { - Assert.assertEquals(amount, PublicMethod.getAccountByIdFromSolidity( - accountId, blockingStubSoliInFull).getBalance()); + Assert.assertEquals( + amount, + PublicMethod.getAccountByIdFromSolidity(accountId, blockingStubSoliInFull).getBalance()); } - @Test(enabled = true, description = "Get account by id from PBFT", groups = {"daily"}) + @Test( + enabled = true, + description = "Get account by id from PBFT", + groups = {"daily"}) public void test04GetAccountByIdFromPbft() { - Assert.assertEquals(amount, PublicMethod.getAccountByIdFromSolidity( - accountId, blockingStubPbft).getBalance()); + Assert.assertEquals( + amount, PublicMethod.getAccountByIdFromSolidity(accountId, blockingStubPbft).getBalance()); } - - @Test(enabled = true, description = "Get account from PBFT", groups = {"daily"}) + @Test( + enabled = true, + description = "Get account from PBFT", + groups = {"daily"}) public void test05GetAccountFromPbft() { - Assert.assertEquals(amount, PublicMethod.queryAccount( - account015Address, blockingStubPbft).getBalance()); + Assert.assertEquals( + amount, PublicMethod.queryAccount(account015Address, blockingStubPbft).getBalance()); } - - @Test(enabled = true, description = "List witnesses", groups = {"daily"}) + @Test( + enabled = true, + description = "List witnesses", + groups = {"daily"}) public void test06ListWitness() { - Assert.assertTrue(PublicMethod.listWitnesses(blockingStubFull) - .get().getWitnessesCount() >= 2); + Assert.assertTrue(PublicMethod.listWitnesses(blockingStubFull).get().getWitnessesCount() >= 2); } - @Test(enabled = true, description = "List witnesses from solidity node", groups = {"daily"}) + @Test( + enabled = true, + description = "List witnesses from solidity node", + groups = {"daily"}) public void test07ListWitnessFromSolidity() { - Assert.assertTrue(PublicMethod.listWitnessesFromSolidity(blockingStubSolidity) - .get().getWitnessesCount() >= 2); - Assert.assertTrue(PublicMethod.listWitnessesFromSolidity(blockingStubSoliInFull) - .get().getWitnessesCount() >= 2); + Assert.assertTrue( + PublicMethod.listWitnessesFromSolidity(blockingStubSolidity).get().getWitnessesCount() + >= 2); + Assert.assertTrue( + PublicMethod.listWitnessesFromSolidity(blockingStubSoliInFull).get().getWitnessesCount() + >= 2); } - @Test(enabled = true, description = "List witnesses from PBFT node", groups = {"daily"}) + @Test( + enabled = true, + description = "List witnesses from PBFT node", + groups = {"daily"}) public void test08ListWitnessFromPbft() { - Assert.assertTrue(PublicMethod.listWitnessesFromSolidity(blockingStubPbft) - .get().getWitnessesCount() >= 2); + Assert.assertTrue( + PublicMethod.listWitnessesFromSolidity(blockingStubPbft).get().getWitnessesCount() >= 2); } - // TODO: Enable when proto supports getPaginatedNowWitnessList (v4.8.1+ API) // @Test(enabled = false, description = "List witness realTime vote data") // public void test09CheckVoteChangesRealtimeAfterVote(){ ... } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(account015Address, account015Key, foundationAddress, blockingStubFull); if (channelSoliInFull != null) { + PublicMethod.freeResource( + account015Address, account015Key, foundationAddress, blockingStubFull); + if (channelSoliInFull != null) { channelSoliInFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestBlock001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestBlock001.java index 8464482e..7873dac4 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestBlock001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestBlock001.java @@ -1,12 +1,9 @@ package stest.tron.wallet.dailybuild.manual; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; -import io.grpc.ManagedChannelBuilder; -import java.math.BigInteger; - import io.grpc.Metadata; import io.grpc.stub.MetadataUtils; +import java.math.BigInteger; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.bouncycastle.util.encoders.Hex; @@ -17,66 +14,57 @@ import org.tron.api.GrpcAPI; import org.tron.api.GrpcAPI.NumberMessage; import org.tron.api.WalletGrpc; -import org.tron.api.WalletSolidityGrpc; import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.Block; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestBlock001 extends TronBaseTest { - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - /** - * constructor. - */ - - - /** - * constructor. - */ + /** constructor. */ + /** constructor. */ @BeforeClass public void beforeClass() { initSolidityChannel(); - // Add metadata as grpc headers + // Add metadata as grpc headers Metadata headers = new Metadata(); headers.put(Metadata.Key.of("content-length", Metadata.ASCII_STRING_MARSHALLER), "5"); - headers - .put(Metadata.Key.of("Content-Type", Metadata.ASCII_STRING_MARSHALLER), "application/grpc"); - headers - .put(Metadata.Key.of("Host", Metadata.ASCII_STRING_MARSHALLER), "grpc.demo.com"); - headers - .put(Metadata.Key.of("x-trace-id", Metadata.ASCII_STRING_MARSHALLER), "testGroupAutoTest"); - headers - .put(Metadata.Key.of("x-trace-path", Metadata.ASCII_STRING_MARSHALLER), "123 23123"); - headers - .put(Metadata.Key.of("x-trace-name", Metadata.ASCII_STRING_MARSHALLER), "!@^&$!* ()^&%"); - ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] randomAddress = ecKey1.getAddress(); - headers - .put(Metadata.Key.of("address-bin", Metadata.BINARY_BYTE_MARSHALLER), randomAddress); - blockingStubFull = WalletGrpc.newBlockingStub(channelFull) - .withInterceptors(MetadataUtils.newAttachHeadersInterceptor(headers)); - // channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - // .usePlaintext() - // .build(); - // blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity) - // .withInterceptors(MetadataUtils.newAttachHeadersInterceptor(headers)); + headers.put( + Metadata.Key.of("Content-Type", Metadata.ASCII_STRING_MARSHALLER), "application/grpc"); + headers.put(Metadata.Key.of("Host", Metadata.ASCII_STRING_MARSHALLER), "grpc.demo.com"); + headers.put( + Metadata.Key.of("x-trace-id", Metadata.ASCII_STRING_MARSHALLER), "testGroupAutoTest"); + headers.put(Metadata.Key.of("x-trace-path", Metadata.ASCII_STRING_MARSHALLER), "123 23123"); + headers.put(Metadata.Key.of("x-trace-name", Metadata.ASCII_STRING_MARSHALLER), "!@^&$!* ()^&%"); + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] randomAddress = ecKey1.getAddress(); + headers.put(Metadata.Key.of("address-bin", Metadata.BINARY_BYTE_MARSHALLER), randomAddress); + blockingStubFull = + WalletGrpc.newBlockingStub(channelFull) + .withInterceptors(MetadataUtils.newAttachHeadersInterceptor(headers)); + // channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + // .usePlaintext() + // .build(); + // blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity) + // .withInterceptors(MetadataUtils.newAttachHeadersInterceptor(headers)); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get now block from fullnode", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get now block from fullnode", + groups = {"daily"}) public void testCurrentBlock() { Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); Assert.assertTrue(currentBlock.hasBlockHeader()); @@ -86,9 +74,10 @@ public void testCurrentBlock() { Assert.assertTrue(currentBlock.getBlockHeader().getRawData().getNumber() > 0); Assert.assertFalse(currentBlock.getBlockHeader().getRawData().getParentHash().isEmpty()); Assert.assertTrue(currentBlock.getBlockHeader().getRawData().getWitnessId() >= 0); - logger.info("test getcurrentblock is " + Long.toString(currentBlock.getBlockHeader() - .getRawData().getNumber())); - //Improve coverage. + logger.info( + "test getcurrentblock is " + + Long.toString(currentBlock.getBlockHeader().getRawData().getNumber())); + // Improve coverage. currentBlock.equals(currentBlock); Block newBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); newBlock.equals(currentBlock); @@ -98,13 +87,14 @@ public void testCurrentBlock() { newBlock.getTransactionsList(); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get now block from solidity", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get now block from solidity", + groups = {"daily"}) public void testCurrentBlockFromSolidity() { - Block currentBlock = blockingStubSolidity - .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); + Block currentBlock = + blockingStubSolidity.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); Assert.assertTrue(currentBlock.hasBlockHeader()); Assert.assertFalse(currentBlock.getBlockHeader().getWitnessSignature().isEmpty()); Assert.assertTrue(currentBlock.getBlockHeader().getRawData().getTimestamp() > 0); @@ -112,23 +102,19 @@ public void testCurrentBlockFromSolidity() { Assert.assertTrue(currentBlock.getBlockHeader().getRawData().getNumber() > 0); Assert.assertFalse(currentBlock.getBlockHeader().getRawData().getParentHash().isEmpty()); Assert.assertTrue(currentBlock.getBlockHeader().getRawData().getWitnessId() >= 0); - logger.info("test getcurrentblock in soliditynode is " + Long.toString(currentBlock - .getBlockHeader().getRawData().getNumber())); + logger.info( + "test getcurrentblock in soliditynode is " + + Long.toString(currentBlock.getBlockHeader().getRawData().getNumber())); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -137,13 +123,13 @@ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockin } ECKey ecKey = temKey; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -153,24 +139,17 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestBlock002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestBlock002.java index ab22b414..10c816c6 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestBlock002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestBlock002.java @@ -24,62 +24,55 @@ import stest.tron.wallet.common.client.utils.TronBaseTest; @Slf4j -public class WalletTestBlock002 extends TronBaseTest { private ManagedChannel channelSoliInFull = null; +public class WalletTestBlock002 extends TronBaseTest { + private ManagedChannel channelSoliInFull = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSoliInFull = null; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - private String soliInFullnode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1); - private String soliInPbft = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(2); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + private String soliInFullnode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); + private String soliInPbft = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(2); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - channelSoliInFull = ManagedChannelBuilder.forTarget(soliInFullnode) - .usePlaintext() - .build(); + channelSoliInFull = ManagedChannelBuilder.forTarget(soliInFullnode).usePlaintext().build(); blockingStubSoliInFull = WalletSolidityGrpc.newBlockingStub(channelSoliInFull); - channelPbft = ManagedChannelBuilder.forTarget(soliInPbft) - .usePlaintext() - .build(); + channelPbft = ManagedChannelBuilder.forTarget(soliInPbft).usePlaintext().build(); blockingStubPbft = WalletSolidityGrpc.newBlockingStub(channelPbft); } - /** - * constructor. - */ - @Test(enabled = true, description = "GetBlockByNum from fullnode", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "GetBlockByNum from fullnode", + groups = {"daily"}) public void test01GetBlockByNum() { Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); + Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Assert.assertFalse(currentBlockNum < 0); if (currentBlockNum == 1) { logger.info("Now has very little block, Please test this case by manual"); Assert.assertTrue(currentBlockNum == 1); } - //The number is large than the currently number, there is no exception when query this number. + // The number is large than the currently number, there is no exception when query this number. Long outOfCurrentBlockNum = currentBlockNum + 10000L; NumberMessage.Builder builder1 = NumberMessage.newBuilder(); builder1.setNum(outOfCurrentBlockNum); Block outOfCurrentBlock = blockingStubFull.getBlockByNum(builder1.build()); Assert.assertFalse(outOfCurrentBlock.hasBlockHeader()); - //Query the first block. + // Query the first block. NumberMessage.Builder builder2 = NumberMessage.newBuilder(); builder2.setNum(1); Block firstBlock = blockingStubFull.getBlockByNum(builder2.build()); @@ -90,7 +83,7 @@ public void test01GetBlockByNum() { Assert.assertTrue(firstBlock.getBlockHeader().getRawData().getNumber() == 1); Assert.assertFalse(firstBlock.getBlockHeader().getRawData().getParentHash().isEmpty()); Assert.assertTrue(firstBlock.getBlockHeader().getRawData().getWitnessId() >= 0); - //Query the second latest block. + // Query the second latest block. NumberMessage.Builder builder3 = NumberMessage.newBuilder(); builder3.setNum(currentBlockNum - 1); Block lastSecondBlock = blockingStubFull.getBlockByNum(builder3.build()); @@ -104,24 +97,27 @@ public void test01GetBlockByNum() { Assert.assertTrue(lastSecondBlock.getBlockHeader().getRawData().getWitnessId() >= 0); } - @Test(enabled = true, description = "GetBlockByNum from solidity", groups = {"daily"}) + @Test( + enabled = true, + description = "GetBlockByNum from solidity", + groups = {"daily"}) public void test02GetBlockByNumFromSolidity() { - Block currentBlock = blockingStubSolidity - .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); + Block currentBlock = + blockingStubSolidity.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); + Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Assert.assertFalse(currentBlockNum < 0); if (currentBlockNum == 1) { logger.info("Now has very little block, Please test this case by manual"); Assert.assertTrue(currentBlockNum == 1); } - //The number is large than the currently number, there is no exception when query this number. + // The number is large than the currently number, there is no exception when query this number. Long outOfCurrentBlockNum = currentBlockNum + 10000L; NumberMessage.Builder builder1 = NumberMessage.newBuilder(); builder1.setNum(outOfCurrentBlockNum); Block outOfCurrentBlock = blockingStubSolidity.getBlockByNum(builder1.build()); Assert.assertFalse(outOfCurrentBlock.hasBlockHeader()); - //Query the first block. + // Query the first block. NumberMessage.Builder builder2 = NumberMessage.newBuilder(); builder2.setNum(1); Block firstBlock = blockingStubSolidity.getBlockByNum(builder2.build()); @@ -133,7 +129,7 @@ public void test02GetBlockByNumFromSolidity() { Assert.assertFalse(firstBlock.getBlockHeader().getRawData().getParentHash().isEmpty()); Assert.assertTrue(firstBlock.getBlockHeader().getRawData().getWitnessId() >= 0); logger.info("firstblock test from solidity succesfully"); - //Query the second latest block. + // Query the second latest block. NumberMessage.Builder builder3 = NumberMessage.newBuilder(); builder3.setNum(currentBlockNum - 1); Block lastSecondBlock = blockingStubSolidity.getBlockByNum(builder3.build()); @@ -148,7 +144,10 @@ public void test02GetBlockByNumFromSolidity() { logger.info("Last second test from solidity succesfully"); } - @Test(enabled = true, description = "Get block by id", groups = {"daily"}) + @Test( + enabled = true, + description = "Get block by id", + groups = {"daily"}) public void test03GetBlockById() { Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); @@ -162,80 +161,90 @@ public void test03GetBlockById() { logger.info(Long.toString(setIdOfBlock.getBlockHeader().getRawData().getNumber())); logger.info(Long.toString(currentBlock.getBlockHeader().getRawData().getNumber())); Assert.assertTrue( - setIdOfBlock.getBlockHeader().getRawData().getNumber() + 1 == currentBlock.getBlockHeader() - .getRawData().getNumber()); + setIdOfBlock.getBlockHeader().getRawData().getNumber() + 1 + == currentBlock.getBlockHeader().getRawData().getNumber()); Assert.assertFalse(setIdOfBlock.getBlockHeader().getRawData().getParentHash().isEmpty()); Assert.assertTrue(setIdOfBlock.getBlockHeader().getRawData().getWitnessId() >= 0); logger.info("By ID test succesfully"); } - - @Test(enabled = true, description = "Get transaction count by block num", groups = {"daily"}) + @Test( + enabled = true, + description = "Get transaction count by block num", + groups = {"daily"}) public void test04GetTransactionCountByBlockNum() { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(0); - Assert.assertTrue(blockingStubFull.getTransactionCountByBlockNum(builder.build()) - .getNum() > 3); + Assert.assertTrue(blockingStubFull.getTransactionCountByBlockNum(builder.build()).getNum() > 3); } - @Test(enabled = true, description = "Get transaction count by block num from solidity", groups = {"daily"}) + @Test( + enabled = true, + description = "Get transaction count by block num from solidity", + groups = {"daily"}) public void test05GetTransactionCountByBlockNumFromSolidity() { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(0); - Assert.assertTrue(blockingStubSolidity.getTransactionCountByBlockNum(builder.build()) - .getNum() > 3); - Assert.assertTrue(blockingStubSoliInFull.getTransactionCountByBlockNum(builder.build()) - .getNum() > 3); + Assert.assertTrue( + blockingStubSolidity.getTransactionCountByBlockNum(builder.build()).getNum() > 3); + Assert.assertTrue( + blockingStubSoliInFull.getTransactionCountByBlockNum(builder.build()).getNum() > 3); } - @Test(enabled = true, description = "Get transaction count by block num from PBFT", groups = {"daily"}) + @Test( + enabled = true, + description = "Get transaction count by block num from PBFT", + groups = {"daily"}) public void test06GetTransactionCountByBlockNumFromPbft() { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(0); - Assert.assertTrue(blockingStubPbft.getTransactionCountByBlockNum(builder.build()) - .getNum() > 3); + Assert.assertTrue(blockingStubPbft.getTransactionCountByBlockNum(builder.build()).getNum() > 3); } - @Test(enabled = true, description = "Get now block from PBFT", groups = {"daily"}) + @Test( + enabled = true, + description = "Get now block from PBFT", + groups = {"daily"}) public void test07GetNowBlockFromPbft() { Block nowBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - Long nowBlockNum = nowBlock.getBlockHeader().getRawData().getNumber(); + Long nowBlockNum = nowBlock.getBlockHeader().getRawData().getNumber(); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubPbft); Block pbftNowBlock = blockingStubPbft.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - Long nowPbftBlockNum = pbftNowBlock.getBlockHeader().getRawData().getNumber(); + Long nowPbftBlockNum = pbftNowBlock.getBlockHeader().getRawData().getNumber(); logger.info("nowBlockNum:" + nowBlockNum + " , nowPbftBlockNum:" + nowPbftBlockNum); Assert.assertTrue(nowPbftBlockNum >= nowBlockNum); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubPbft); - GrpcAPI.BlockExtention pbftNowBlock2 = blockingStubPbft.getNowBlock2(GrpcAPI.EmptyMessage - .newBuilder().build()); - Long nowPbftBlockNum2 = pbftNowBlock2.getBlockHeader().getRawData().getNumber(); + GrpcAPI.BlockExtention pbftNowBlock2 = + blockingStubPbft.getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); + Long nowPbftBlockNum2 = pbftNowBlock2.getBlockHeader().getRawData().getNumber(); logger.info("nowBlockNum:" + nowBlockNum + " , nowPbftBlockNum2:" + nowPbftBlockNum2); Assert.assertTrue(nowPbftBlockNum2 >= nowBlockNum); } - - @Test(enabled = true, description = "Get block by num from PBFT", groups = {"daily"}) + @Test( + enabled = true, + description = "Get block by num from PBFT", + groups = {"daily"}) public void test08GetBlockByNumFromPbft() { - Block currentBlock = blockingStubPbft - .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); + Block currentBlock = blockingStubPbft.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); + Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Assert.assertFalse(currentBlockNum < 0); if (currentBlockNum == 1) { logger.info("Now has very little block, Please test this case by manual"); Assert.assertTrue(currentBlockNum == 1); } - //The number is large than the currently number, there is no exception when query this number. + // The number is large than the currently number, there is no exception when query this number. Long outOfCurrentBlockNum = currentBlockNum + 10000L; NumberMessage.Builder builder1 = NumberMessage.newBuilder(); builder1.setNum(outOfCurrentBlockNum); Block outOfCurrentBlock = blockingStubPbft.getBlockByNum(builder1.build()); Assert.assertFalse(outOfCurrentBlock.hasBlockHeader()); - //Query the first block. + // Query the first block. NumberMessage.Builder builder2 = NumberMessage.newBuilder(); builder2.setNum(1); Block firstBlock = blockingStubPbft.getBlockByNum(builder2.build()); @@ -247,7 +256,7 @@ public void test08GetBlockByNumFromPbft() { Assert.assertFalse(firstBlock.getBlockHeader().getRawData().getParentHash().isEmpty()); Assert.assertTrue(firstBlock.getBlockHeader().getRawData().getWitnessId() >= 0); logger.info("firstblock test from solidity succesfully"); - //Query the second latest block. + // Query the second latest block. NumberMessage.Builder builder3 = NumberMessage.newBuilder(); builder3.setNum(currentBlockNum - 1); Block lastSecondBlock = blockingStubPbft.getBlockByNum(builder3.build()); @@ -260,41 +269,34 @@ public void test08GetBlockByNumFromPbft() { Assert.assertFalse(lastSecondBlock.getBlockHeader().getRawData().getParentHash().isEmpty()); Assert.assertTrue(lastSecondBlock.getBlockHeader().getRawData().getWitnessId() >= 0); logger.info("Last second test from solidity succesfully"); - //Query the second latest block getBlockByNum2. + // Query the second latest block getBlockByNum2. NumberMessage.Builder builder4 = NumberMessage.newBuilder(); builder4.setNum(currentBlockNum - 1); GrpcAPI.BlockExtention lastSecondBlock1 = blockingStubPbft.getBlockByNum2(builder4.build()); Assert.assertTrue(lastSecondBlock1.hasBlockHeader()); Assert.assertFalse(lastSecondBlock1.getBlockHeader().getWitnessSignature().isEmpty()); Assert.assertTrue(lastSecondBlock1.getBlockHeader().getRawData().getTimestamp() > 0); - Assert.assertFalse(lastSecondBlock1.getBlockHeader().getRawData().getWitnessAddress() - .isEmpty()); + Assert.assertFalse( + lastSecondBlock1.getBlockHeader().getRawData().getWitnessAddress().isEmpty()); Assert.assertTrue( - lastSecondBlock1.getBlockHeader().getRawData().getNumber() + 1 == currentBlockNum); + lastSecondBlock1.getBlockHeader().getRawData().getNumber() + 1 == currentBlockNum); Assert.assertFalse(lastSecondBlock1.getBlockHeader().getRawData().getParentHash().isEmpty()); Assert.assertTrue(lastSecondBlock1.getBlockHeader().getRawData().getWitnessId() >= 0); logger.info("Last second test from getBlockByNum2 succesfully"); - } - - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { if (channelSoliInFull != null) { + public void shutdown() throws InterruptedException { + if (channelSoliInFull != null) { channelSoliInFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); } - } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -303,13 +305,13 @@ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockin } ECKey ecKey = temKey; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -319,22 +321,17 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestBlock003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestBlock003.java index 4c8d05d2..3ec90aba 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestBlock003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestBlock003.java @@ -1,12 +1,8 @@ package stest.tron.wallet.dailybuild.manual; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; -import java.math.BigInteger; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.bouncycastle.util.encoders.Hex; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; @@ -16,42 +12,45 @@ import org.tron.api.GrpcAPI.BlockReq; import org.tron.api.GrpcAPI.NumberMessage; import org.tron.api.WalletSolidityGrpc; -import org.tron.protos.Protocol.Account; -import org.tron.protos.Protocol.Block; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class WalletTestBlock003 extends TronBaseTest { private final byte[] foundationAddress = PublicMethod.getFinalAddress(foundationKey); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); +public class WalletTestBlock003 extends TronBaseTest { + private final byte[] foundationAddress = PublicMethod.getFinalAddress(foundationKey); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); String txid; Long blockNum; ByteString blockHash; - @BeforeClass - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] receiverAddress = ecKey1.getAddress(); - txid = PublicMethod.sendcoinGetTransactionId(receiverAddress,1L,foundationAddress,foundationKey,blockingStubFull); + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] receiverAddress = ecKey1.getAddress(); + txid = + PublicMethod.sendcoinGetTransactionId( + receiverAddress, 1L, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - blockNum = PublicMethod.getTransactionInfoById(txid,blockingStubFull).get().getBlockNumber(); - blockHash = PublicMethod.getBlock(blockNum+1,blockingStubFull).getBlockHeader().getRawData().getParentHash(); - + blockNum = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get().getBlockNumber(); + blockHash = + PublicMethod.getBlock(blockNum + 1, blockingStubFull) + .getBlockHeader() + .getRawData() + .getParentHash(); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get block from fullnode", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get block from fullnode", + groups = {"daily"}) public void test01GetBlock() { Boolean getBlockEqualGetNowBlock = false; Integer retryTimes = 5; @@ -60,11 +59,17 @@ public void test01GetBlock() { BlockReq.Builder builder = BlockReq.newBuilder(); BlockExtention currentBlockFromGetBlock = blockingStubFull.getBlock(builder.build()); - BlockExtention currentBlockFromGetNowBlock = blockingStubFull.getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); - logger.info("currentBlockFromGetBlock: " + currentBlockFromGetBlock.getBlockHeader().toString()); - logger.info("currentBlockFromGetNowBlock: " + currentBlockFromGetNowBlock.getBlockHeader().toString()); - - if(currentBlockFromGetBlock.getBlockHeader().equals(currentBlockFromGetNowBlock.getBlockHeader())) { + BlockExtention currentBlockFromGetNowBlock = + blockingStubFull.getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); + logger.info( + "currentBlockFromGetBlock: " + currentBlockFromGetBlock.getBlockHeader().toString()); + logger.info( + "currentBlockFromGetNowBlock: " + + currentBlockFromGetNowBlock.getBlockHeader().toString()); + + if (currentBlockFromGetBlock + .getBlockHeader() + .equals(currentBlockFromGetNowBlock.getBlockHeader())) { getBlockEqualGetNowBlock = true; } else { PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -74,10 +79,11 @@ public void test01GetBlock() { Assert.assertTrue(getBlockEqualGetNowBlock); } - /** - * constructor. - */ - @Test(enabled = true, description = "Get block from solidity", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get block from solidity", + groups = {"daily"}) public void test02GetBlockFromSolidity() { Boolean getBlockEqualGetNowBlock = false; Integer retryTimes = 5; @@ -86,11 +92,18 @@ public void test02GetBlockFromSolidity() { BlockReq.Builder builder = BlockReq.newBuilder(); BlockExtention currentBlockFromGetBlock = blockingStubSolidity.getBlock(builder.build()); - BlockExtention currentBlockFromGetNowBlock = blockingStubSolidity.getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); - - logger.info("test02GetBlockFromSolidity: currentBlockFromGetBlock"+currentBlockFromGetBlock.toString()); - logger.info("test02GetBlockFromSolidity: currentBlockFromGetNowBlock"+currentBlockFromGetNowBlock.getBlockHeader().toString()); - if(currentBlockFromGetBlock.getBlockHeader().equals(currentBlockFromGetNowBlock.getBlockHeader())) { + BlockExtention currentBlockFromGetNowBlock = + blockingStubSolidity.getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); + + logger.info( + "test02GetBlockFromSolidity: currentBlockFromGetBlock" + + currentBlockFromGetBlock.toString()); + logger.info( + "test02GetBlockFromSolidity: currentBlockFromGetNowBlock" + + currentBlockFromGetNowBlock.getBlockHeader().toString()); + if (currentBlockFromGetBlock + .getBlockHeader() + .equals(currentBlockFromGetNowBlock.getBlockHeader())) { getBlockEqualGetNowBlock = true; } else { PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -100,11 +113,11 @@ public void test02GetBlockFromSolidity() { Assert.assertTrue(getBlockEqualGetNowBlock); } - - /** - * constructor. - */ - @Test(enabled = true, description = "Get block by block num with detail true", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get block by block num with detail true", + groups = {"daily"}) public void test03GetBlockByBlockNumWithDetailTrue() { BlockReq.Builder builder = BlockReq.newBuilder(); @@ -120,16 +133,16 @@ public void test03GetBlockByBlockNumWithDetailTrue() { builder1.setNum(blockNum); BlockExtention blockByGetBlockByNum = blockingStubFull.getBlockByNum2(builder1.build()); - Assert.assertEquals(blockByGetBlockByNum,lastBlockByNumWithDetailTrue); - Assert.assertEquals(lastBlockByNumWithDetailTrue,lastBlockByIdWithDetailTrue); + Assert.assertEquals(blockByGetBlockByNum, lastBlockByNumWithDetailTrue); + Assert.assertEquals(lastBlockByNumWithDetailTrue, lastBlockByIdWithDetailTrue); Assert.assertTrue(lastBlockByNumWithDetailTrue.getTransactionsCount() >= 1); } - - /** - * constructor. - */ - @Test(enabled = true, description = "Get block by block num with detail default false", groups = {"daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Get block by block num with detail default false", + groups = {"daily"}) public void test03GetBlockByBlockNumWithDetailDefaultFalse() { BlockReq.Builder builder = BlockReq.newBuilder(); @@ -143,16 +156,12 @@ public void test03GetBlockByBlockNumWithDetailDefaultFalse() { builder1.setNum(blockNum); BlockExtention blockByGetBlockByNum = blockingStubFull.getBlockByNum2(builder1.build()); - Assert.assertNotEquals(blockByGetBlockByNum,lastBlockByNumWithDetailFalse); - Assert.assertEquals(lastBlockByNumWithDetailFalse,lastBlockByIdWithDetailFalse); + Assert.assertNotEquals(blockByGetBlockByNum, lastBlockByNumWithDetailFalse); + Assert.assertEquals(lastBlockByNumWithDetailFalse, lastBlockByIdWithDetailFalse); Assert.assertTrue(blockByGetBlockByNum.getTransactionsCount() >= 1); - Assert.assertEquals(lastBlockByIdWithDetailFalse.getTransactionsCount(),0); + Assert.assertEquals(lastBlockByIdWithDetailFalse.getTransactionsCount(), 0); } - @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestMultiSign002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestMultiSign002.java index 7756a1df..6d394d1a 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestMultiSign002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestMultiSign002.java @@ -1,7 +1,6 @@ package stest.tron.wallet.dailybuild.manual; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.Optional; import lombok.extern.slf4j.Slf4j; @@ -19,8 +18,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestMultiSign002 extends TronBaseTest { @@ -56,25 +55,24 @@ public class WalletTestMultiSign002 extends TronBaseTest { Integer exchangeRate = 10; Long firstTokenInitialBalance = 10000L; Long secondTokenInitialBalance = firstTokenInitialBalance * exchangeRate; - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1); - - /** - * constructor. - */ - + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "MultiSign for create token", groups = {"daily"}) + @Test( + enabled = true, + description = "MultiSign for create token", + groups = {"daily"}) public void test1CreateUsedAsset() { ecKey1 = new ECKey(Utils.getRandom()); exchange001Address = ecKey1.getAddress(); @@ -87,28 +85,72 @@ public void test1CreateUsedAsset() { PublicMethod.printAddress(exchange001Key); PublicMethod.printAddress(secondExchange001Key); - Assert.assertTrue(PublicMethod.sendcoin(exchange001Address, 10240000000L, foundationAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(secondExchange001Address, 10240000000L, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + exchange001Address, 10240000000L, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + secondExchange001Address, + 10240000000L, + foundationAddress, + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, ByteString.copyFrom(exchange001Address), - testKey002, blockingStubFull)); + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long start = System.currentTimeMillis() + 5000L; - Long end = System.currentTimeMillis() + 5000000L; - Assert.assertTrue(PublicMethod.createAssetIssue(exchange001Address, name1, totalSupply, 1, - 1, start, end, 1, description, url, 10000L, 10000L, - 1L, 1L, exchange001Key, blockingStubFull)); - Assert.assertTrue(PublicMethod.createAssetIssue(secondExchange001Address, name2, totalSupply, 1, - 1, start, end, 1, description, url, 10000L, 10000L, - 1L, 1L, secondExchange001Key, blockingStubFull)); + Long start = System.currentTimeMillis() + 5000L; + Long end = System.currentTimeMillis() + 5000000L; + Assert.assertTrue( + PublicMethod.createAssetIssue( + exchange001Address, + name1, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + exchange001Key, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.createAssetIssue( + secondExchange001Address, + name2, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + secondExchange001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "MultiSign for create exchange", groups = {"daily"}) + @Test( + enabled = true, + description = "MultiSign for create exchange", + groups = {"daily"}) public void test2CreateExchange() { ecKey3 = new ECKey(Utils.getRandom()); manager1Address = ecKey3.getAddress(); @@ -117,8 +159,8 @@ public void test2CreateExchange() { ecKey4 = new ECKey(Utils.getRandom()); manager2Address = ecKey4.getAddress(); manager2Key = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); - Long balanceBefore = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + Long balanceBefore = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -129,89 +171,119 @@ public void test2CreateExchange() { ownerKeyString[2] = manager2Key; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":3,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(exchange001Key) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(exchange001Key) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); PublicMethodForMultiSign.accountPermissionUpdate( - accountPermissionJson, exchange001Address, exchange001Key, - blockingStubFull, ownerKeyString); + accountPermissionJson, + exchange001Address, + exchange001Key, + blockingStubFull, + ownerKeyString); listExchange = PublicMethod.getExchangeList(blockingStubFull); - final Integer beforeCreateExchangeNum = listExchange.get().getExchangesCount(); + final Integer beforeCreateExchangeNum = listExchange.get().getExchangesCount(); exchangeId = listExchange.get().getExchangesCount(); Account getAssetIdFromThisAccount; getAssetIdFromThisAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); assetAccountId1 = getAssetIdFromThisAccount.getAssetIssuedID(); - getAssetIdFromThisAccount = PublicMethod - .queryAccount(secondExchange001Address, blockingStubFull); + getAssetIdFromThisAccount = + PublicMethod.queryAccount(secondExchange001Address, blockingStubFull); assetAccountId2 = getAssetIdFromThisAccount.getAssetIssuedID(); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long token1BeforeBalance = 0L; + Long token1BeforeBalance = 0L; for (String name : firstAccount.getAssetMap().keySet()) { token1BeforeBalance = firstAccount.getAssetMap().get(name); } - Assert.assertTrue(PublicMethod.transferAsset(exchange001Address, assetAccountId2.toByteArray(), - secondTransferAssetToFirstAccountNum, secondExchange001Address, - secondExchange001Key, blockingStubFull)); - Long token2BeforeBalance = secondTransferAssetToFirstAccountNum; + Assert.assertTrue( + PublicMethod.transferAsset( + exchange001Address, + assetAccountId2.toByteArray(), + secondTransferAssetToFirstAccountNum, + secondExchange001Address, + secondExchange001Key, + blockingStubFull)); + Long token2BeforeBalance = secondTransferAssetToFirstAccountNum; PublicMethod.waitProduceNextBlock(blockingStubFull); - //logger.info("name1 is " + name1); - //logger.info("name2 is " + name2); - //logger.info("first balance is " + Long.toString(token1BeforeBalance)); - //logger.info("second balance is " + token2BeforeBalance.toString()); - //CreateExchange + // logger.info("name1 is " + name1); + // logger.info("name2 is " + name2); + // logger.info("first balance is " + Long.toString(token1BeforeBalance)); + // logger.info("second balance is " + token2BeforeBalance.toString()); + // CreateExchange Assert.assertTrue( PublicMethodForMultiSign.exchangeCreate( - assetAccountId1.toByteArray(), firstTokenInitialBalance, - assetAccountId2.toByteArray(), secondTokenInitialBalance, exchange001Address, - exchange001Key, blockingStubFull, ownerKeyString)); + assetAccountId1.toByteArray(), + firstTokenInitialBalance, + assetAccountId2.toByteArray(), + secondTokenInitialBalance, + exchange001Address, + exchange001Key, + blockingStubFull, + ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); listExchange = PublicMethod.getExchangeList(blockingStubFull); exchangeId = listExchange.get().getExchangesCount(); - Long balanceAfter = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + Long balanceAfter = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); long needCoin = updateAccountPermissionFee + multiSignFee; Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1024_000_000L); - } - @Test(enabled = true, description = "List exchange after create exchange by MultiSign", groups = {"daily"}) + @Test( + enabled = true, + description = "List exchange after create exchange by MultiSign", + groups = {"daily"}) public void test3ListExchange() { PublicMethod.waitProduceNextBlock(blockingStubFull); listExchange = PublicMethod.getExchangeList(blockingStubFull); for (Integer i = 0; i < listExchange.get().getExchangesCount(); i++) { - Assert.assertFalse(ByteArray.toHexString(listExchange.get().getExchanges(i) - .getCreatorAddress().toByteArray()).isEmpty()); + Assert.assertFalse( + ByteArray.toHexString( + listExchange.get().getExchanges(i).getCreatorAddress().toByteArray()) + .isEmpty()); Assert.assertTrue(listExchange.get().getExchanges(i).getExchangeId() > 0); - Assert.assertFalse(ByteArray.toStr(listExchange.get().getExchanges(i).getFirstTokenId() - .toByteArray()).isEmpty()); + Assert.assertFalse( + ByteArray.toStr(listExchange.get().getExchanges(i).getFirstTokenId().toByteArray()) + .isEmpty()); Assert.assertTrue(listExchange.get().getExchanges(i).getFirstTokenBalance() > 0); } } - @Test(enabled = true, description = "Multisign for inject exchange", groups = {"daily"}) + @Test( + enabled = true, + description = "Multisign for inject exchange", + groups = {"daily"}) public void test4InjectExchange() { exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); - Long balanceBefore = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + Long balanceBefore = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long beforeToken1Balance = 0L; - Long beforeToken2Balance = 0L; + Long beforeToken1Balance = 0L; + Long beforeToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { beforeToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -225,12 +297,17 @@ public void test4InjectExchange() { Integer injectBalance = 100; Assert.assertTrue( PublicMethodForMultiSign.injectExchange( - exchangeId, assetAccountId1.toByteArray(), injectBalance, - exchange001Address, exchange001Key, blockingStubFull, ownerKeyString)); + exchangeId, + assetAccountId1.toByteArray(), + injectBalance, + exchange001Address, + exchange001Key, + blockingStubFull, + ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long afterToken1Balance = 0L; - Long afterToken2Balance = 0L; + Long afterToken1Balance = 0L; + Long afterToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { afterToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -243,36 +320,37 @@ public void test4InjectExchange() { logger.info("before token 2 balance is " + Long.toString(afterToken2Balance)); Assert.assertTrue(beforeToken1Balance - afterToken1Balance == injectBalance); - Assert.assertTrue(beforeToken2Balance - afterToken2Balance == injectBalance - * exchangeRate); + Assert.assertTrue(beforeToken2Balance - afterToken2Balance == injectBalance * exchangeRate); exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); - Assert.assertTrue(afterExchangeToken1Balance - beforeExchangeToken1Balance - == injectBalance); - Assert.assertTrue(afterExchangeToken2Balance - beforeExchangeToken2Balance - == injectBalance * exchangeRate); - Long balanceAfter = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + Assert.assertTrue(afterExchangeToken1Balance - beforeExchangeToken1Balance == injectBalance); + Assert.assertTrue( + afterExchangeToken2Balance - beforeExchangeToken2Balance == injectBalance * exchangeRate); + Long balanceAfter = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); long needCoin = multiSignFee; Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - @Test(enabled = true, description = "MultiSign for withdraw exchange", groups = {"daily"}) + @Test( + enabled = true, + description = "MultiSign for withdraw exchange", + groups = {"daily"}) public void test5WithdrawExchange() { - Long balanceBefore = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + Long balanceBefore = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long beforeToken1Balance = 0L; - Long beforeToken2Balance = 0L; + Long beforeToken1Balance = 0L; + Long beforeToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { beforeToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -287,12 +365,17 @@ public void test5WithdrawExchange() { Integer withdrawNum = 200; Assert.assertTrue( PublicMethodForMultiSign.exchangeWithdraw( - exchangeId, assetAccountId1.toByteArray(), withdrawNum, - exchange001Address, exchange001Key, blockingStubFull, ownerKeyString)); + exchangeId, + assetAccountId1.toByteArray(), + withdrawNum, + exchange001Address, + exchange001Key, + blockingStubFull, + ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long afterToken1Balance = 0L; - Long afterToken2Balance = 0L; + Long afterToken1Balance = 0L; + Long afterToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { afterToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -306,37 +389,37 @@ public void test5WithdrawExchange() { logger.info("before token 2 balance is " + Long.toString(afterToken2Balance)); Assert.assertTrue(afterToken1Balance - beforeToken1Balance == withdrawNum); - Assert.assertTrue(afterToken2Balance - beforeToken2Balance == withdrawNum - * exchangeRate); + Assert.assertTrue(afterToken2Balance - beforeToken2Balance == withdrawNum * exchangeRate); exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); - Assert.assertTrue(afterExchangeToken1Balance - beforeExchangeToken1Balance - == -withdrawNum); - Assert.assertTrue(afterExchangeToken2Balance - beforeExchangeToken2Balance - == -withdrawNum * exchangeRate); - Long balanceAfter = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + Assert.assertTrue(afterExchangeToken1Balance - beforeExchangeToken1Balance == -withdrawNum); + Assert.assertTrue( + afterExchangeToken2Balance - beforeExchangeToken2Balance == -withdrawNum * exchangeRate); + Long balanceAfter = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); long needCoin = multiSignFee; Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - } - @Test(enabled = false, description = "MultiSign for transaction exchange", groups = {"daily"}) + @Test( + enabled = false, + description = "MultiSign for transaction exchange", + groups = {"daily"}) public void test6TransactionExchange() { - Long balanceBefore = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + Long balanceBefore = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); logger.info("beforeExchangeToken1Balance" + beforeExchangeToken1Balance); logger.info("beforeExchangeToken2Balance" + beforeExchangeToken2Balance); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long beforeToken1Balance = 0L; - Long beforeToken2Balance = 0L; + Long beforeToken1Balance = 0L; + Long beforeToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { beforeToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -350,13 +433,19 @@ public void test6TransactionExchange() { logger.info("before token 2 balance is " + Long.toString(beforeToken2Balance)); Integer transactionNum = 50; Assert.assertTrue( - PublicMethodForMultiSign - .exchangeTransaction(exchangeId, assetAccountId1.toByteArray(), transactionNum, 1, - exchange001Address, exchange001Key, blockingStubFull, ownerKeyString)); + PublicMethodForMultiSign.exchangeTransaction( + exchangeId, + assetAccountId1.toByteArray(), + transactionNum, + 1, + exchange001Address, + exchange001Key, + blockingStubFull, + ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long afterToken1Balance = 0L; - Long afterToken2Balance = 0L; + Long afterToken1Balance = 0L; + Long afterToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { afterToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -369,55 +458,54 @@ public void test6TransactionExchange() { logger.info("before token 2 balance is " + Long.toString(afterToken2Balance)); exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); logger.info("afterExchangeToken1Balance" + afterExchangeToken1Balance); logger.info("afterExchangeToken2Balance" + afterExchangeToken2Balance); - Assert.assertTrue(afterExchangeToken1Balance - beforeExchangeToken1Balance - == beforeToken1Balance - afterToken1Balance); - Assert.assertTrue(afterExchangeToken2Balance - beforeExchangeToken2Balance - == beforeToken2Balance - afterToken2Balance); - Long balanceAfter = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + Assert.assertTrue( + afterExchangeToken1Balance - beforeExchangeToken1Balance + == beforeToken1Balance - afterToken1Balance); + Assert.assertTrue( + afterExchangeToken2Balance - beforeExchangeToken2Balance + == beforeToken2Balance - afterToken2Balance); + Long balanceAfter = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); long needCoin = multiSignFee; Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - - @Test(enabled = true, description = "GetExchangeListPaginated after " - + "MultiSign exchange kind of transaction", groups = {"daily"}) - + @Test( + enabled = true, + description = "GetExchangeListPaginated after " + "MultiSign exchange kind of transaction", + groups = {"daily"}) public void test7GetExchangeListPaginated() { PaginatedMessage.Builder pageMessageBuilder = PaginatedMessage.newBuilder(); pageMessageBuilder.setOffset(0); pageMessageBuilder.setLimit(100); - ExchangeList exchangeList = blockingStubFull - .getPaginatedExchangeList(pageMessageBuilder.build()); + ExchangeList exchangeList = + blockingStubFull.getPaginatedExchangeList(pageMessageBuilder.build()); Assert.assertTrue(exchangeList.getExchangesCount() >= 1); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); - //Solidity support getExchangeId + // Solidity support getExchangeId exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubSolidity); logger.info("createtime is" + exchangeIdInfo.get().getCreateTime()); Assert.assertTrue(exchangeIdInfo.get().getCreateTime() > 0); - //Solidity support listexchange + // Solidity support listexchange listExchange = PublicMethod.getExchangeList(blockingStubSolidity); Assert.assertTrue(listExchange.get().getExchangesCount() > 0); - PublicMethod - .unFreezeBalance(foundationAddress, testKey002, 0, exchange001Address, blockingStubFull); + PublicMethod.unFreezeBalance( + foundationAddress, testKey002, 0, exchange001Address, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .unFreezeBalance(exchange001Address, exchange001Key, 0, foundationAddress, blockingStubFull); - PublicMethod.freeResource(exchange001Address, exchange001Key, foundationAddress, blockingStubFull); - PublicMethod.freeResource(secondExchange001Address, secondExchange001Key, foundationAddress, - blockingStubFull); } + PublicMethod.unFreezeBalance( + exchange001Address, exchange001Key, 0, foundationAddress, blockingStubFull); + PublicMethod.freeResource( + exchange001Address, exchange001Key, foundationAddress, blockingStubFull); + PublicMethod.freeResource( + secondExchange001Address, secondExchange001Key, foundationAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestNode001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestNode001.java index ac473ded..dd7e1732 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestNode001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestNode001.java @@ -10,76 +10,67 @@ import org.tron.api.GrpcAPI; import org.tron.api.WalletGrpc; import stest.tron.wallet.common.client.Configuration; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; @Slf4j @MultiNode -public class WalletTestNode001 extends TronBaseTest { private ManagedChannel channelFull1 = null; +public class WalletTestNode001 extends TronBaseTest { + private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass - public void beforeClass() { channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + public void beforeClass() { + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - } - - @Test(enabled = true, description = "List all nodes", groups = {"daily"}) + @Test( + enabled = true, + description = "List all nodes", + groups = {"daily"}) public void testGetAllNode() { - GrpcAPI.NodeList nodeList = blockingStubFull - .listNodes(GrpcAPI.EmptyMessage.newBuilder().build()); - GrpcAPI.NodeList nodeList1 = blockingStubFull1 - .listNodes(GrpcAPI.EmptyMessage.newBuilder().build()); + GrpcAPI.NodeList nodeList = + blockingStubFull.listNodes(GrpcAPI.EmptyMessage.newBuilder().build()); + GrpcAPI.NodeList nodeList1 = + blockingStubFull1.listNodes(GrpcAPI.EmptyMessage.newBuilder().build()); Integer times = 0; while (nodeList.getNodesCount() == 0 && times++ < 5) { - nodeList = blockingStubFull - .listNodes(GrpcAPI.EmptyMessage.newBuilder().build()); - nodeList1 = blockingStubFull1 - .listNodes(GrpcAPI.EmptyMessage.newBuilder().build()); + nodeList = blockingStubFull.listNodes(GrpcAPI.EmptyMessage.newBuilder().build()); + nodeList1 = blockingStubFull1.listNodes(GrpcAPI.EmptyMessage.newBuilder().build()); if (nodeList.getNodesCount() != 0 || nodeList1.getNodesCount() != 0) { break; } PublicMethod.waitProduceNextBlock(blockingStubFull); } - //Assert.assertTrue(nodeList.getNodesCount() != 0 || nodeList1.getNodesCount() != 0); + // Assert.assertTrue(nodeList.getNodesCount() != 0 || nodeList1.getNodesCount() != 0); for (Integer j = 0; j < nodeList.getNodesCount(); j++) { - //Assert.assertTrue(nodeList.getNodes(j).hasAddress()); - //Assert.assertFalse(nodeList.getNodes(j).getAddress().getHost().isEmpty()); - //Assert.assertTrue(nodeList.getNodes(j).getAddress().getPort() < 65535); - //logger.info(ByteArray.toStr(nodeList.getNodes(j).getAddress().getHost().toByteArray())); + // Assert.assertTrue(nodeList.getNodes(j).hasAddress()); + // Assert.assertFalse(nodeList.getNodes(j).getAddress().getHost().isEmpty()); + // Assert.assertTrue(nodeList.getNodes(j).getAddress().getPort() < 65535); + // logger.info(ByteArray.toStr(nodeList.getNodes(j).getAddress().getHost().toByteArray())); } logger.info("get listnode succesuflly"); - //Improve coverage. - GrpcAPI.NodeList newNodeList = blockingStubFull - .listNodes(GrpcAPI.EmptyMessage.newBuilder().build()); + // Improve coverage. + GrpcAPI.NodeList newNodeList = + blockingStubFull.listNodes(GrpcAPI.EmptyMessage.newBuilder().build()); nodeList.equals(nodeList); nodeList.equals(newNodeList); nodeList.getNodesList(); nodeList.hashCode(); nodeList.isInitialized(); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { if (channelFull1 != null) { + public void shutdown() throws InterruptedException { + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestTransfer002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestTransfer002.java index d9b9fa80..3a455ea2 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestTransfer002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestTransfer002.java @@ -1,7 +1,6 @@ package stest.tron.wallet.dailybuild.manual; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.math.BigInteger; import lombok.extern.slf4j.Slf4j; @@ -28,44 +27,44 @@ import stest.tron.wallet.common.client.utils.TronBaseTest; @Slf4j -public class WalletTestTransfer002 extends TronBaseTest { private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); +public class WalletTestTransfer002 extends TronBaseTest { + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); private WalletExtensionGrpc.WalletExtensionBlockingStub blockingStubExtension = null; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); blockingStubExtension = WalletExtensionGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = false, groups = {"daily"}) + @Test( + enabled = false, + groups = {"daily"}) public void testGetTotalTransaction() { - NumberMessage beforeGetTotalTransaction = blockingStubFull - .totalTransaction(GrpcAPI.EmptyMessage.newBuilder().build()); + NumberMessage beforeGetTotalTransaction = + blockingStubFull.totalTransaction(GrpcAPI.EmptyMessage.newBuilder().build()); logger.info(Long.toString(beforeGetTotalTransaction.getNum())); - Long beforeTotalTransaction = beforeGetTotalTransaction.getNum(); - Assert.assertTrue(PublicMethod.sendcoin(toAddress, 1000000, foundationAddress, - foundationKey, blockingStubFull)); - NumberMessage afterGetTotalTransaction = blockingStubFull - .totalTransaction(GrpcAPI.EmptyMessage.newBuilder().build()); + Long beforeTotalTransaction = beforeGetTotalTransaction.getNum(); + Assert.assertTrue( + PublicMethod.sendcoin( + toAddress, 1000000, foundationAddress, foundationKey, blockingStubFull)); + NumberMessage afterGetTotalTransaction = + blockingStubFull.totalTransaction(GrpcAPI.EmptyMessage.newBuilder().build()); logger.info(Long.toString(afterGetTotalTransaction.getNum())); - Long afterTotalTransaction = afterGetTotalTransaction.getNum(); + Long afterTotalTransaction = afterGetTotalTransaction.getNum(); Assert.assertTrue(afterTotalTransaction - beforeTotalTransaction > 0); - //Improve coverage. + // Improve coverage. afterGetTotalTransaction.equals(beforeGetTotalTransaction); afterGetTotalTransaction.equals(afterGetTotalTransaction); afterGetTotalTransaction.hashCode(); @@ -74,25 +73,19 @@ public void testGetTotalTransaction() { afterGetTotalTransaction.getDefaultInstanceForType(); afterGetTotalTransaction.getParserForType(); afterGetTotalTransaction.getUnknownFields(); - - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(toAddress, testKey003, foundationAddress, blockingStubFull); } + PublicMethod.freeResource(toAddress, testKey003, foundationAddress, blockingStubFull); + } - /** - * constructor. - */ + /** constructor. */ public Boolean sendcoin(byte[] to, long amount, byte[] owner, String priKey) { - //String priKey = foundationKey; - ECKey temKey = null; + // String priKey = foundationKey; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -119,19 +112,17 @@ public Boolean sendcoin(byte[] to, long amount, byte[] owner, String priKey) { return response.getResult(); } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -141,23 +132,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -169,5 +155,3 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestTransfer005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestTransfer005.java index 6aaa175b..ff788b3a 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestTransfer005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestTransfer005.java @@ -1,7 +1,6 @@ package stest.tron.wallet.dailybuild.manual; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.Optional; import lombok.extern.slf4j.Slf4j; @@ -27,43 +26,37 @@ import stest.tron.wallet.common.client.utils.TransactionUtils; import stest.tron.wallet.common.client.utils.TronBaseTest; - @Slf4j public class WalletTestTransfer005 extends TronBaseTest { private static final byte[] INVAILD_ADDRESS = Base58.decodeFromBase58Check("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48"); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); private WalletExtensionGrpc.WalletExtensionBlockingStub blockingStubExtension = null; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); blockingStubExtension = WalletExtensionGrpc.newBlockingStub(channelSolidity); - - } - @Test(enabled = false, groups = {"daily"}) + @Test( + enabled = false, + groups = {"daily"}) public void testgetTransactionsFromThis() { - //Create a transfer. - //Assert.assertTrue(PublicMethod.sendcoin(toAddress,1000000,foundationAddress, + // Create a transfer. + // Assert.assertTrue(PublicMethod.sendcoin(toAddress,1000000,foundationAddress, // foundationKey,blockingStubFull)); ByteString addressBs = ByteString.copyFrom(foundationAddress); @@ -71,89 +64,83 @@ public void testgetTransactionsFromThis() { AccountPaginated.Builder accountPaginated = AccountPaginated.newBuilder().setAccount(account); accountPaginated.setOffset(1000); accountPaginated.setLimit(0); - GrpcAPI.TransactionList transactionList = blockingStubExtension - .getTransactionsFromThis(accountPaginated.build()); - Optional gettransactionsfromthis = Optional - .ofNullable(transactionList); + GrpcAPI.TransactionList transactionList = + blockingStubExtension.getTransactionsFromThis(accountPaginated.build()); + Optional gettransactionsfromthis = + Optional.ofNullable(transactionList); if (gettransactionsfromthis.get().getTransactionCount() == 0) { - Assert.assertTrue(PublicMethod.sendcoin(toAddress, 1000000L, foundationAddress, - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, - blockingStubSolidity)); + Assert.assertTrue( + PublicMethod.sendcoin( + toAddress, 1000000L, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity)); } Assert.assertTrue(gettransactionsfromthis.isPresent()); Integer beforecount = gettransactionsfromthis.get().getTransactionCount(); logger.info(Integer.toString(beforecount)); for (Integer j = 0; j < beforecount; j++) { - Assert.assertFalse(gettransactionsfromthis.get().getTransaction(j) - .getRawData().getContractList().isEmpty()); + Assert.assertFalse( + gettransactionsfromthis.get().getTransaction(j).getRawData().getContractList().isEmpty()); } } - @Test(enabled = false, groups = {"daily"}) + @Test( + enabled = false, + groups = {"daily"}) public void testgetTransactionsFromThisByInvaildAddress() { - //Invaild address. + // Invaild address. ByteString addressBs = ByteString.copyFrom(INVAILD_ADDRESS); Account account = Account.newBuilder().setAddress(addressBs).build(); AccountPaginated.Builder accountPaginated = AccountPaginated.newBuilder().setAccount(account); accountPaginated.setOffset(1000); accountPaginated.setLimit(0); - GrpcAPI.TransactionList transactionList = blockingStubExtension - .getTransactionsFromThis(accountPaginated.build()); - Optional gettransactionsfromthisByInvaildAddress = Optional - .ofNullable(transactionList); + GrpcAPI.TransactionList transactionList = + blockingStubExtension.getTransactionsFromThis(accountPaginated.build()); + Optional gettransactionsfromthisByInvaildAddress = + Optional.ofNullable(transactionList); Assert.assertTrue(gettransactionsfromthisByInvaildAddress.get().getTransactionCount() == 0); - //Limit is -1 + // Limit is -1 addressBs = ByteString.copyFrom(INVAILD_ADDRESS); account = Account.newBuilder().setAddress(addressBs).build(); accountPaginated = AccountPaginated.newBuilder().setAccount(account); accountPaginated.setOffset(1000); accountPaginated.setLimit(-1); - transactionList = blockingStubExtension - .getTransactionsFromThis(accountPaginated.build()); - gettransactionsfromthisByInvaildAddress = Optional - .ofNullable(transactionList); + transactionList = blockingStubExtension.getTransactionsFromThis(accountPaginated.build()); + gettransactionsfromthisByInvaildAddress = Optional.ofNullable(transactionList); Assert.assertTrue(gettransactionsfromthisByInvaildAddress.get().getTransactionCount() == 0); - //offset is -1 + // offset is -1 addressBs = ByteString.copyFrom(INVAILD_ADDRESS); account = Account.newBuilder().setAddress(addressBs).build(); accountPaginated = AccountPaginated.newBuilder().setAccount(account); accountPaginated.setOffset(-1); accountPaginated.setLimit(100); - transactionList = blockingStubExtension - .getTransactionsFromThis(accountPaginated.build()); - gettransactionsfromthisByInvaildAddress = Optional - .ofNullable(transactionList); + transactionList = blockingStubExtension.getTransactionsFromThis(accountPaginated.build()); + gettransactionsfromthisByInvaildAddress = Optional.ofNullable(transactionList); Assert.assertTrue(gettransactionsfromthisByInvaildAddress.get().getTransactionCount() == 0); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(toAddress, testKey003, foundationAddress, blockingStubFull); } + PublicMethod.freeResource(toAddress, testKey003, foundationAddress, blockingStubFull); + } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -163,18 +150,14 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); @@ -190,5 +173,3 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestTransfer006.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestTransfer006.java index 327dad09..f68b76c4 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestTransfer006.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestTransfer006.java @@ -1,7 +1,6 @@ package stest.tron.wallet.dailybuild.manual; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.Optional; import lombok.extern.slf4j.Slf4j; @@ -27,134 +26,123 @@ import stest.tron.wallet.common.client.utils.TransactionUtils; import stest.tron.wallet.common.client.utils.TronBaseTest; - @Slf4j public class WalletTestTransfer006 extends TronBaseTest { private static final byte[] INVAILD_ADDRESS = Base58.decodeFromBase58Check("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48"); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); private WalletExtensionGrpc.WalletExtensionBlockingStub blockingStubExtension = null; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); blockingStubExtension = WalletExtensionGrpc.newBlockingStub(channelSolidity); - - } - @Test(enabled = false, groups = {"daily"}) + @Test( + enabled = false, + groups = {"daily"}) public void testgetTransactionsToThis() { - //Create a transfer. - Assert.assertTrue(PublicMethod.sendcoin(toAddress, 1000000, foundationAddress, - foundationKey, blockingStubFull)); + // Create a transfer. + Assert.assertTrue( + PublicMethod.sendcoin( + toAddress, 1000000, foundationAddress, foundationKey, blockingStubFull)); ByteString addressBs = ByteString.copyFrom(toAddress); Account account = Account.newBuilder().setAddress(addressBs).build(); AccountPaginated.Builder accountPaginated = AccountPaginated.newBuilder().setAccount(account); accountPaginated.setOffset(1000); accountPaginated.setLimit(0); - GrpcAPI.TransactionList transactionList = blockingStubExtension - .getTransactionsToThis(accountPaginated.build()); + GrpcAPI.TransactionList transactionList = + blockingStubExtension.getTransactionsToThis(accountPaginated.build()); - Optional gettransactionstothis = Optional - .ofNullable(transactionList); + Optional gettransactionstothis = Optional.ofNullable(transactionList); if (gettransactionstothis.get().getTransactionCount() == 0) { - Assert.assertTrue(PublicMethod.sendcoin(toAddress, 1000000L, foundationAddress, foundationKey, - blockingStubFull)); - Assert.assertTrue(PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, - blockingStubSolidity)); - //logger.info("This account didn't transfation any coin to other"); + Assert.assertTrue( + PublicMethod.sendcoin( + toAddress, 1000000L, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity)); + // logger.info("This account didn't transfation any coin to other"); } Assert.assertTrue(gettransactionstothis.isPresent()); Integer beforecount = gettransactionstothis.get().getTransactionCount(); logger.info(Integer.toString(beforecount)); for (Integer j = 0; j < beforecount; j++) { - Assert.assertFalse(gettransactionstothis.get().getTransaction(j) - .getRawData().getContractList().isEmpty()); + Assert.assertFalse( + gettransactionstothis.get().getTransaction(j).getRawData().getContractList().isEmpty()); } } - @Test(enabled = false, groups = {"daily"}) + @Test( + enabled = false, + groups = {"daily"}) public void testgetTransactionsToThisByInvaildAddress() { - //Invaild address. + // Invaild address. ByteString addressBs = ByteString.copyFrom(INVAILD_ADDRESS); Account account = Account.newBuilder().setAddress(addressBs).build(); AccountPaginated.Builder accountPaginated = AccountPaginated.newBuilder().setAccount(account); accountPaginated.setOffset(1000); accountPaginated.setLimit(0); - GrpcAPI.TransactionList transactionList = blockingStubExtension - .getTransactionsToThis(accountPaginated.build()); - Optional gettransactionstothisByInvaildAddress = Optional - .ofNullable(transactionList); + GrpcAPI.TransactionList transactionList = + blockingStubExtension.getTransactionsToThis(accountPaginated.build()); + Optional gettransactionstothisByInvaildAddress = + Optional.ofNullable(transactionList); Assert.assertTrue(gettransactionstothisByInvaildAddress.get().getTransactionCount() == 0); - //Limit is -1 + // Limit is -1 addressBs = ByteString.copyFrom(INVAILD_ADDRESS); account = Account.newBuilder().setAddress(addressBs).build(); accountPaginated = AccountPaginated.newBuilder().setAccount(account); accountPaginated.setOffset(1000); accountPaginated.setLimit(-1); - transactionList = blockingStubExtension - .getTransactionsToThis(accountPaginated.build()); - gettransactionstothisByInvaildAddress = Optional - .ofNullable(transactionList); + transactionList = blockingStubExtension.getTransactionsToThis(accountPaginated.build()); + gettransactionstothisByInvaildAddress = Optional.ofNullable(transactionList); Assert.assertTrue(gettransactionstothisByInvaildAddress.get().getTransactionCount() == 0); - //offset is -1 + // offset is -1 addressBs = ByteString.copyFrom(INVAILD_ADDRESS); account = Account.newBuilder().setAddress(addressBs).build(); accountPaginated = AccountPaginated.newBuilder().setAccount(account); accountPaginated.setOffset(-1); accountPaginated.setLimit(100); - transactionList = blockingStubExtension - .getTransactionsToThis(accountPaginated.build()); - gettransactionstothisByInvaildAddress = Optional - .ofNullable(transactionList); + transactionList = blockingStubExtension.getTransactionsToThis(accountPaginated.build()); + gettransactionstothisByInvaildAddress = Optional.ofNullable(transactionList); Assert.assertTrue(gettransactionstothisByInvaildAddress.get().getTransactionCount() == 0); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(toAddress, testKey003, foundationAddress, blockingStubFull); } + PublicMethod.freeResource(toAddress, testKey003, foundationAddress, blockingStubFull); + } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -164,18 +152,14 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); @@ -191,5 +175,3 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestWitness003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestWitness003.java index a1fc2efc..4bf7619c 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestWitness003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/manual/WalletTestWitness003.java @@ -26,22 +26,24 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - //import stest.tron.wallet.common.client.AccountComparator; +import stest.tron.wallet.common.client.utils.Utils; + +// import stest.tron.wallet.common.client.AccountComparator; @Slf4j public class WalletTestWitness003 extends TronBaseTest { - private static final byte[] INVAILD_ADDRESS = Base58 - .decodeFromBase58Check("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48"); + private static final byte[] INVAILD_ADDRESS = + Base58.decodeFromBase58Check("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48"); private static final Long costForCreateWitness = 9999000000L; - private static final String tooLongUrl = "qagwqaswqaswqaswqaswqaswqaswqaswqaswqaswqaswqas" - + "wqaswqasw1qazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazx" - + "swedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedc" - + "vqazxswedcvqazxswedcvqazxswedcvqazxswedcv"; - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private static final String tooLongUrl = + "qagwqaswqaswqaswqaswqaswqaswqaswqaswqaswqaswqas" + + "wqaswqasw1qazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazx" + + "swedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedc" + + "vqazxswedcvqazxswedcvqazxswedcvqazxswedcv"; + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); String createWitnessUrl = "http://www.createwitnessurl.com"; String updateWitnessUrl = "http://www.updatewitnessurl.com"; @@ -51,90 +53,93 @@ public class WalletTestWitness003 extends TronBaseTest { byte[] updateUrl = updateWitnessUrl.getBytes(); byte[] wrongUrl = nullUrl.getBytes(); byte[] updateSpaceUrl = spaceUrl.getBytes(); - //get account + // get account ECKey ecKey = new ECKey(Utils.getRandom()); byte[] lowBalAddress = ecKey.getAddress(); String lowBalTest = ByteArray.toHexString(ecKey.getPrivKeyBytes()); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass public void beforeClass() { logger.info(lowBalTest); logger.info(ByteArray.toHexString(PublicMethod.getFinalAddress(lowBalTest))); - logger.info(Base58.encode58Check(PublicMethod.getFinalAddress(lowBalTest))); } + logger.info(Base58.encode58Check(PublicMethod.getFinalAddress(lowBalTest))); + } - @Test(enabled = true, description = "Invaild account to apply create witness", groups = {"daily"}) + @Test( + enabled = true, + description = "Invaild account to apply create witness", + groups = {"daily"}) public void testInvaildToApplyBecomeWitness() { Assert.assertFalse(createWitnessNotBroadcast(INVAILD_ADDRESS, createUrl, foundationKey)); } - @Test(enabled = true, description = "Create witness", groups = {"daily"}) + @Test( + enabled = true, + description = "Create witness", + groups = {"daily"}) public void testCreateWitness() { - //If you are already is witness, apply failed - //createWitness(foundationAddress, createUrl, foundationKey); - //Assert.assertFalse(createWitness(foundationAddress, createUrl, foundationKey)); - //No balance,try to create witness. + // If you are already is witness, apply failed + // createWitness(foundationAddress, createUrl, foundationKey); + // Assert.assertFalse(createWitness(foundationAddress, createUrl, foundationKey)); + // No balance,try to create witness. Assert.assertFalse(createWitnessNotBroadcast(lowBalAddress, createUrl, lowBalTest)); - //Send enough coin to the apply account to make that account + // Send enough coin to the apply account to make that account // has ability to apply become witness. - GrpcAPI.WitnessList witnesslist = blockingStubFull - .listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build()); + GrpcAPI.WitnessList witnesslist = + blockingStubFull.listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build()); Optional result = Optional.ofNullable(witnesslist); GrpcAPI.WitnessList witnessList = result.get(); if (result.get().getWitnessesCount() < 6) { - Assert.assertTrue(PublicMethod - .sendcoin(lowBalAddress, costForCreateWitness, foundationAddress, foundationKey, + Assert.assertTrue( + PublicMethod.sendcoin( + lowBalAddress, + costForCreateWitness, + foundationAddress, + foundationKey, blockingStubFull)); - //null url, update failed + // null url, update failed Assert.assertFalse(createWitnessNotBroadcast(lowBalAddress, wrongUrl, witnessKey)); - //too long url, update failed - Assert.assertFalse(createWitnessNotBroadcast(lowBalAddress, - tooLongUrl.getBytes(), witnessKey)); + // too long url, update failed + Assert.assertFalse( + createWitnessNotBroadcast(lowBalAddress, tooLongUrl.getBytes(), witnessKey)); Assert.assertTrue(createWitnessNotBroadcast(lowBalAddress, createUrl, lowBalTest)); - } } - @Test(enabled = true, description = "Update witness", groups = {"daily"}) + @Test( + enabled = true, + description = "Update witness", + groups = {"daily"}) public void testUpdateWitness() { - GrpcAPI.WitnessList witnesslist = blockingStubFull - .listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build()); + GrpcAPI.WitnessList witnesslist = + blockingStubFull.listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build()); Optional result = Optional.ofNullable(witnesslist); GrpcAPI.WitnessList witnessList = result.get(); if (result.get().getWitnessesCount() < 6) { - //null url, update failed + // null url, update failed Assert.assertFalse(updateWitness(witnessAddress, wrongUrl, witnessKey)); - //too long url, update failed + // too long url, update failed Assert.assertFalse(updateWitness(witnessAddress, tooLongUrl.getBytes(), witnessKey)); - //Content space and special char, update success + // Content space and special char, update success Assert.assertTrue(updateWitness(witnessAddress, updateSpaceUrl, witnessKey)); - //update success + // update success Assert.assertTrue(updateWitness(witnessAddress, updateUrl, witnessKey)); } else { logger.info("Update witness case had been test.This time skip it."); } - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ + /** constructor. */ public Boolean createWitnessNotBroadcast(byte[] owner, byte[] url, String priKey) { ECKey temKey = null; try { @@ -157,9 +162,7 @@ public Boolean createWitnessNotBroadcast(byte[] owner, byte[] url, String priKey return true; } - /** - * constructor. - */ + /** constructor. */ public Boolean updateWitness(byte[] owner, byte[] url, String priKey) { ECKey temKey = null; try { @@ -188,16 +191,13 @@ public Boolean updateWitness(byte[] owner, byte[] url, String priKey) { } else { return true; } - } - /** - * constructor. - */ + /** constructor. */ public Boolean sendcoin(byte[] to, long amount, byte[] owner, String priKey) { - //String priKey = foundationKey; - ECKey temKey = null; + // String priKey = foundationKey; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -228,12 +228,10 @@ public Boolean sendcoin(byte[] to, long amount, byte[] owner, String priKey) { } } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -242,13 +240,13 @@ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockin } ECKey ecKey = temKey; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -258,23 +256,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Protocol.Transaction signTransaction(ECKey ecKey, Protocol.Transaction transaction) { @@ -286,4 +279,3 @@ private Protocol.Transaction signTransaction(ECKey ecKey, Protocol.Transaction t return TransactionUtils.sign(transaction, ecKey); } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign01.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign01.java index ab913e23..19cb3a6d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign01.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign01.java @@ -14,19 +14,20 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode -public class MultiSign01 extends TronBaseTest { private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); +public class MultiSign01 extends TronBaseTest { + private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -36,30 +37,31 @@ public class MultiSign01 extends TronBaseTest { private final byte[] witnessAdd private ECKey tmpEcKey02 = new ECKey(Utils.getRandom()); private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Owner permission_name is owner", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner permission_name is owner", + groups = {"daily", "multisig"}) public void testOwnerName01() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2 + multiSignFee; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); @@ -70,21 +72,32 @@ public void testOwnerName01() { ownerPermissionKeys.add(ownerKey); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -92,51 +105,64 @@ public void testOwnerName01() { ownerPermissionKeys.add(tmpKey02); ownerPermissionKeys.add(witnessKey); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - @Test(enabled = true, description = "Owner permission_name is owner1", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner permission_name is owner1", + groups = {"daily", "multisig"}) public void testOwnerName02() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - final byte[] ownerAddress = ecKey1.getAddress(); - final String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + final byte[] ownerAddress = ecKey1.getAddress(); + final String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -147,62 +173,85 @@ public void testOwnerName02() { ownerPermissionKeys.add(ownerKey); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = "{\"owner_permission\":{\"type\":0," - + "\"permission_name\":\"owner1\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" - + "]}]}"; - - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + String accountPermissionJson = + "{\"owner_permission\":{\"type\":0," + + "\"permission_name\":\"owner1\",\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - } - @Test(enabled = true, description = "Owner permission_name is string \"123\"", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner permission_name is string \"123\"", + groups = {"daily", "multisig"}) public void testOwnerName03() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); @@ -210,11 +259,11 @@ public void testOwnerName03() { long needCoin = updateAccountPermissionFee * 2; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -225,73 +274,95 @@ public void testOwnerName03() { ownerPermissionKeys.add(ownerKey); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"123\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - } - @Test(enabled = true, description = "Owner permission_name is string \"\"", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner permission_name is string \"\"", + groups = {"daily", "multisig"}) public void testOwnerName04() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -302,70 +373,93 @@ public void testOwnerName04() { ownerPermissionKeys.add(ownerKey); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - @Test(enabled = true, description = "Owner permission_name is null", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner permission_name is null", + groups = {"daily", "multisig"}) public void testOwnerName05() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, 1_000000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, 1_000000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -373,50 +467,58 @@ public void testOwnerName05() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - // null - String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":" + null - + ",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}]}," - + "\"witness_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"" - + "keys\":[{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" - + "]}]}"; + // null + String accountPermissionJson = + "{\"owner_permission\":{\"type\":0,\"permission_name\":" + + null + + ",\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + + "\"witness_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"" + + "keys\":[{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; boolean ret = false; try { - PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NullPointerException e) { logger.info("Expected NullPointerException!"); ret = true; } Assert.assertTrue(ret); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); - } - @Test(enabled = true, description = "Owner without permission_name", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner without permission_name", + groups = {"daily", "multisig"}) public void testOwnerName06() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -426,70 +528,93 @@ public void testOwnerName06() { ownerPermissionKeys.add(ownerKey); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - @Test(enabled = true, description = "Owner permission_name is numbers", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner permission_name is numbers", + groups = {"daily", "multisig"}) public void testOwnerName07() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -498,62 +623,84 @@ public void testOwnerName07() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":123,\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - } - @Test(enabled = true, description = "Owner permission_name is 0.1", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner permission_name is 0.1", + groups = {"daily", "multisig"}) public void testOwnerName08() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); @@ -561,11 +708,11 @@ public void testOwnerName08() { long needCoin = updateAccountPermissionFee * 2; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin + 1000000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1000000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -574,62 +721,84 @@ public void testOwnerName08() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"0.1\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - } - @Test(enabled = true, description = "Owner permission_name length is 32", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner permission_name length is 32", + groups = {"daily", "multisig"}) public void testOwnerName09() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); @@ -637,12 +806,12 @@ public void testOwnerName09() { long needCoin = updateAccountPermissionFee * 2; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin + 1000000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1000000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -651,110 +820,139 @@ public void testOwnerName09() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0," + "\"permission_name\":\"abcdefghijklmnopqrstuvwxyzabcdef\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - } - - @Test(enabled = true, description = "Owner permission_name length is 33", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner permission_name length is 33", + groups = {"daily", "multisig"}) public void testOwnerName10() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, 1000000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, 1000000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0," + "\"permission_name\":\"abcdefghijklmnopqrstuvwxyzabcdefg\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's name is too long", + Assert.assertEquals( + "Contract validate error : permission's name is too long", response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); - } - @Test(enabled = true, description = "Owner permission_name contains special char", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner permission_name contains special char", + groups = {"daily", "multisig"}) public void testOwnerName11() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); @@ -762,11 +960,11 @@ public void testOwnerName11() { long needCoin = updateAccountPermissionFee * 2; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin + 1000000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1000000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -775,61 +973,86 @@ public void testOwnerName11() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"0&^%\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0&^%%09\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); - - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); - logger.info("1111___" + PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getOwnerPermission().toString()); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); + + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); + logger.info( + "1111___" + + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .toString()); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - logger.info("22222___" + PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getOwnerPermission().toString()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + logger.info( + "22222___" + + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .toString()); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - } @AfterMethod @@ -837,10 +1060,7 @@ public void aftertest() { PublicMethod.freeResource(ownerAddress, ownerKey, foundationAddress, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign02.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign02.java index c6458019..dcbb5b60 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign02.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign02.java @@ -14,19 +14,20 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode -public class MultiSign02 extends TronBaseTest { private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); +public class MultiSign02 extends TronBaseTest { + private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -39,131 +40,161 @@ public class MultiSign02 extends TronBaseTest { private final byte[] witnessAdd private ECKey tmpEcKey02 = new ECKey(Utils.getRandom()); private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Owner threshold in exception condition", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner threshold in exception condition", + groups = {"daily", "multisig"}) public void testOwnerThreshold01() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); PublicMethod.printAddress(ownerKey); ownerPermissionKeys.add(ownerKey); - // threshold = Integer.MIN_VALUE + // threshold = Integer.MIN_VALUE String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":-2147483648," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's" - + " threshold should be greater than 0", + Assert.assertEquals( + "Contract validate error : permission's" + " threshold should be greater than 0", response.getMessage().toStringUtf8()); - // threshold = 0 + // threshold = 0 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":0," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's" - + " threshold should be greater than 0", + Assert.assertEquals( + "Contract validate error : permission's" + " threshold should be greater than 0", response.getMessage().toStringUtf8()); - // threshold = -1 + // threshold = -1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":-1," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's" - + " threshold should be greater than 0", + Assert.assertEquals( + "Contract validate error : permission's" + " threshold should be greater than 0", response.getMessage().toStringUtf8()); - // threshold = long.min + // threshold = long.min logger.info("** update owner and active permission to two address"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\"," + "\"threshold\":-9223372036854775808,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's" - + " threshold should be greater than 0", + Assert.assertEquals( + "Contract validate error : permission's" + " threshold should be greater than 0", response.getMessage().toStringUtf8()); - // threshold = long.min - 1000020 + // threshold = long.min - 1000020 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\"," + "\"threshold\":-9223372036855775828,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; boolean ret = false; @@ -175,16 +206,19 @@ public void testOwnerThreshold01() { ret = true; } Assert.assertTrue(ret); - // threshold = long.min - 1 + // threshold = long.min - 1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\"," + "\"threshold\":-9223372036854775809,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":2}" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}" + "]}]}"; ret = false; @@ -196,17 +230,22 @@ public void testOwnerThreshold01() { ret = true; } Assert.assertTrue(ret); - // threshold = "12a" + // threshold = "12a" accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\"," + "\"threshold\":\"12a\",\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; @@ -218,17 +257,22 @@ public void testOwnerThreshold01() { ret = true; } Assert.assertTrue(ret); - // threshold = "" + // threshold = "" accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\"," + "\"threshold\":\"\",\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; @@ -240,17 +284,22 @@ public void testOwnerThreshold01() { ret = true; } Assert.assertTrue(ret); - // theshold = + // theshold = accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\"," + "\"threshold\":,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; @@ -262,17 +311,24 @@ public void testOwnerThreshold01() { ret = true; } Assert.assertTrue(ret); - // theshold = null + // theshold = null accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\"," - + "\"threshold\":" + null + ",\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "\"threshold\":" + + null + + ",\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; @@ -284,17 +340,26 @@ public void testOwnerThreshold01() { ret = true; } Assert.assertTrue(ret); - // theshold = 1.1 - accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\"," - + "\"threshold\": 1.1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" - + "]}]}"; + // theshold = 1.1 + accountPermissionJson = + "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\"," + + "\"threshold\": 1.1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; ret = false; try { @@ -305,44 +370,57 @@ public void testOwnerThreshold01() { ret = true; } Assert.assertTrue(ret); - // theshold = Long.MAX_VALUE < sum(weight) - accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\"," - + "\"threshold\": 9223372036854775807,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2147483647}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":9223372036854775807}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" - + "]}]}"; - - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + // theshold = Long.MAX_VALUE < sum(weight) + accountPermissionJson = + "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\"," + + "\"threshold\": 9223372036854775807,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2147483647}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":9223372036854775807}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; + + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : long overflow", - response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertEquals( + "Contract validate error : long overflow", response.getMessage().toStringUtf8()); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); } - @Test(enabled = true, description = "Owner threshold is 1", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner threshold is 1", + groups = {"daily", "multisig"}) public void testOwnerThreshold02() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -350,71 +428,93 @@ public void testOwnerThreshold02() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\"," + "\"threshold\": 1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - @Test(enabled = true, description = "Owner threshold is more than sum of keys' weight", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner threshold is more than sum of keys' weight", + groups = {"daily", "multisig"}) public void testOwnerThreshold03() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -423,62 +523,94 @@ public void testOwnerThreshold03() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - // theshold = Long.MAX_VALUE > sum(weight) - String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\"," - + "\"threshold\": 9223372036854775807,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":214748364}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":214748364}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" - + "]}]}"; - - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + // theshold = Long.MAX_VALUE > sum(weight) + String accountPermissionJson = + "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\"," + + "\"threshold\": 9223372036854775807,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":214748364}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":214748364}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; + + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : sum of all key's weight should not" + Assert.assertEquals( + "Contract validate error : sum of all key's weight should not" + " be less than threshold in permission Owner", response.getMessage().toStringUtf8()); - // theshold = Integer.MAX_VALUE > sum(weight) - accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\"," - + "\"threshold\": 2147483647,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":214748364}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":214748364}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" - + "]}]}"; - - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + // theshold = Integer.MAX_VALUE > sum(weight) + accountPermissionJson = + "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\"," + + "\"threshold\": 2147483647,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":214748364}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":214748364}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; + + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : sum of all key's weight " + Assert.assertEquals( + "Contract validate error : sum of all key's weight " + "should not be less than threshold in permission Owner", response.getMessage().toStringUtf8()); - // theshold = Long.MAX_VALUE + 1 > sum(weight) - accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\"," - + "\"threshold\": 9223372036854775808,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":9223372036854775806}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" - + "]}]}"; + // theshold = Long.MAX_VALUE + 1 > sum(weight) + accountPermissionJson = + "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\"," + + "\"threshold\": 9223372036854775808,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":9223372036854775806}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; boolean ret = false; try { @@ -489,24 +621,26 @@ public void testOwnerThreshold03() { ret = true; } Assert.assertTrue(ret); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); } - @Test(enabled = true, description = "Owner threshold is Long.MAX_VALUE and equal sum(weight)", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner threshold is Long.MAX_VALUE and equal sum(weight)", + groups = {"daily", "multisig"}) public void testOwnerThreshold04() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2 + multiSignFee; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -514,72 +648,97 @@ public void testOwnerThreshold04() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\"," - + "\"threshold\": 9223372036854775807,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":9223372036854775806}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" - + "]}]}"; - - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + String accountPermissionJson = + "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\"," + + "\"threshold\": 9223372036854775807,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":9223372036854775806}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - @Test(enabled = true, description = "Owner threshold is Integer.MAX_VALUE", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner threshold is Integer.MAX_VALUE", + groups = {"daily", "multisig"}) public void testOwnerThreshold05() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -588,59 +747,82 @@ public void testOwnerThreshold05() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\"," - + "\"threshold\": 2147483647,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2147483647}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2147483647}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2147483647}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" - + "]}]}"; - - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + String accountPermissionJson = + "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\"," + + "\"threshold\": 2147483647,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2147483647}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2147483647}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2147483647}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.add(tmpKey02); ownerPermissionKeys.add(witnessKey); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(3, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 3, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); @@ -651,10 +833,7 @@ public void aftertest() { PublicMethod.freeResource(ownerAddress, ownerKey, foundationAddress, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign03.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign03.java index 6b27de2f..952f7de9 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign03.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign03.java @@ -14,19 +14,20 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode -public class MultiSign03 extends TronBaseTest { private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); +public class MultiSign03 extends TronBaseTest { + private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -37,32 +38,35 @@ public class MultiSign03 extends TronBaseTest { private final byte[] witnessAdd private ECKey tmpEcKey02 = new ECKey(Utils.getRandom()); private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull); + public void beforeClass() { + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull); } - @Test(enabled = true, description = "Owner doesn't have parent_id", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner doesn't have parent_id", + groups = {"daily", "multisig"}) public void testOwnerParent01() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -70,71 +74,93 @@ public void testOwnerParent01() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - @Test(enabled = true, description = "Owner parent_id in exception condition", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner parent_id in exception condition", + groups = {"daily", "multisig"}) public void testOwnerParent02() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -142,276 +168,355 @@ public void testOwnerParent02() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - // parent_id = "123" + // parent_id = "123" String accountPermissionJson = "{\"owner_permission\":{\"parent_id\":\"123\",\"type\":0," + "\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = "abc" + // parent_id = "abc" accountPermissionJson = "{\"owner_permission\":{\"parent_id\":\"abc\",\"type\":0," + "\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; boolean ret = false; try { - PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NumberFormatException e) { logger.info("Expected NumberFormatException!"); ret = true; } Assert.assertTrue(ret); - // parent_id = "" + // parent_id = "" accountPermissionJson = "{\"owner_permission\":{\"parent_id\":\"\",\"type\":0," + "\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; try { - PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NullPointerException e) { logger.info("Expected NullPointerException!"); ret = true; } Assert.assertTrue(ret); - // parent_id = null + // parent_id = null accountPermissionJson = - "{\"owner_permission\":{\"parent_id\":" + null + ",\"type\":0," + "{\"owner_permission\":{\"parent_id\":" + + null + + ",\"type\":0," + "\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; try { - PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NullPointerException e) { logger.info("Expected NullPointerException!"); ret = true; } Assert.assertTrue(ret); - // parent_id = 1 + // parent_id = 1 accountPermissionJson = "{\"owner_permission\":{\"parent_id\":1,\"type\":0," + "\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = 2 + // parent_id = 2 accountPermissionJson = "{\"owner_permission\":{\"parent_id\":2,\"type\":0," + "\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = 3 + // parent_id = 3 accountPermissionJson = "{\"owner_permission\":{\"parent_id\":3,\"type\":0," + "\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = -1 + // parent_id = -1 accountPermissionJson = "{\"owner_permission\":{\"parent_id\":3,\"type\":0," + "\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = Integer.MAX_VALUE + // parent_id = Integer.MAX_VALUE accountPermissionJson = "{\"owner_permission\":{\"parent_id\":2147483647,\"type\":0," + "\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = Integer.MAX_VALUE +1 + // parent_id = Integer.MAX_VALUE +1 accountPermissionJson = "{\"owner_permission\":{\"parent_id\":2147483648,\"type\":0," + "\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = Integer.MIN_VALUE + // parent_id = Integer.MIN_VALUE accountPermissionJson = "{\"owner_permission\":{\"parent_id\":-2147483648,\"type\":0," + "\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = Integer.MIN_VALUE -1 + // parent_id = Integer.MIN_VALUE -1 accountPermissionJson = "{\"owner_permission\":{\"parent_id\":-2147483649,\"type\":0," + "\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); } - @Test(enabled = true, description = "Owner parent_id is 0", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner parent_id is 0", + groups = {"daily", "multisig"}) public void testOwnerParent03() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -419,59 +524,78 @@ public void testOwnerParent03() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"parent_id\":0,\"type\":0," + "\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); @@ -482,10 +606,7 @@ public void aftertest() { PublicMethod.freeResource(ownerAddress, ownerKey, foundationAddress, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign04.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign04.java index ffa52f4a..0d898d63 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign04.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign04.java @@ -14,19 +14,20 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode -public class MultiSign04 extends TronBaseTest { private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); +public class MultiSign04 extends TronBaseTest { + private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -39,144 +40,191 @@ public class MultiSign04 extends TronBaseTest { private final byte[] witnessAdd private ECKey tmpEcKey02 = new ECKey(Utils.getRandom()); private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull); + public void beforeClass() { + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull); } - @Test(enabled = true, description = "Owner weight in exception condition", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner weight in exception condition", + groups = {"daily", "multisig"}) public void testOwnerWeight01() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); List ownerPermissionKeys = new ArrayList<>(); ownerPermissionKeys.add(ownerKey); - // weight = Integer.MIN_VALUE - String accountPermissionJson = "{\"owner_permission\":{\"type\":0," - + ",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":-2147483647}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2147483647}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" - + "]}]}"; - - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + // weight = Integer.MIN_VALUE + String accountPermissionJson = + "{\"owner_permission\":{\"type\":0," + + ",\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":-2147483647}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2147483647}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : key's weight" - + " should be greater than 0", + Assert.assertEquals( + "Contract validate error : key's weight" + " should be greater than 0", response.getMessage().toStringUtf8()); - // weight = 0 - accountPermissionJson = "{\"owner_permission\":{\"type\":0," - + ",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":0}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":0}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" - + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + // weight = 0 + accountPermissionJson = + "{\"owner_permission\":{\"type\":0," + + ",\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":0}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":0}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : key's weight" - + " should be greater than 0", + Assert.assertEquals( + "Contract validate error : key's weight" + " should be greater than 0", response.getMessage().toStringUtf8()); - // weight = -1 - accountPermissionJson = "{\"owner_permission\":{\"type\":0," - + ",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":-1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" - + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + // weight = -1 + accountPermissionJson = + "{\"owner_permission\":{\"type\":0," + + ",\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":-1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : key's weight" - + " should be greater than 0", + Assert.assertEquals( + "Contract validate error : key's weight" + " should be greater than 0", response.getMessage().toStringUtf8()); - // weight = long.min - accountPermissionJson = "{\"owner_permission\":{\"type\":0," - + ",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":-9223372036854775808}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" - + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + // weight = long.min + accountPermissionJson = + "{\"owner_permission\":{\"type\":0," + + ",\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":-9223372036854775808}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : key's weight" - + " should be greater than 0", + Assert.assertEquals( + "Contract validate error : key's weight" + " should be greater than 0", response.getMessage().toStringUtf8()); - // weight = long.min - 1000020 - accountPermissionJson = "{\"owner_permission\":{\"type\":0," - + ",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":-9223372036855775828}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" - + "]}]}"; + // weight = long.min - 1000020 + accountPermissionJson = + "{\"owner_permission\":{\"type\":0," + + ",\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":-9223372036855775828}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; boolean ret = false; try { PublicMethod.accountPermissionUpdateForResponse( @@ -186,21 +234,29 @@ public void testOwnerWeight01() { ret = true; } Assert.assertTrue(ret); - // weight = "12a" - accountPermissionJson = "{\"owner_permission\":{\"type\":0," - + ",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":\"12a\"}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" - + "]}]}"; + // weight = "12a" + accountPermissionJson = + "{\"owner_permission\":{\"type\":0," + + ",\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":\"12a\"}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; ret = false; try { PublicMethod.accountPermissionUpdateForResponse( @@ -210,21 +266,29 @@ public void testOwnerWeight01() { ret = true; } Assert.assertTrue(ret); - // weight = "" - accountPermissionJson = "{\"owner_permission\":{\"type\":0," - + ",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":\"\"}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" - + "]}]}"; + // weight = "" + accountPermissionJson = + "{\"owner_permission\":{\"type\":0," + + ",\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":\"\"}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; ret = false; try { PublicMethod.accountPermissionUpdateForResponse( @@ -234,21 +298,29 @@ public void testOwnerWeight01() { ret = true; } Assert.assertTrue(ret); - // weight = - accountPermissionJson = "{\"owner_permission\":{\"type\":0," - + ",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" - + "]}]}"; + // weight = + accountPermissionJson = + "{\"owner_permission\":{\"type\":0," + + ",\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; ret = false; try { @@ -259,21 +331,31 @@ public void testOwnerWeight01() { ret = true; } Assert.assertTrue(ret); - // weight = null - accountPermissionJson = "{\"owner_permission\":{\"type\":0," - + ",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":" + null + "}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" - + "]}]}"; + // weight = null + accountPermissionJson = + "{\"owner_permission\":{\"type\":0," + + ",\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":" + + null + + "}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; ret = false; try { PublicMethod.accountPermissionUpdateForResponse( @@ -283,37 +365,51 @@ public void testOwnerWeight01() { ret = true; } Assert.assertTrue(ret); - // sum(weight) > Long.MAX_VALUE - accountPermissionJson = "{\"owner_permission\":{\"type\":0," - + ",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":9223372036854775807}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" - + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + // sum(weight) > Long.MAX_VALUE + accountPermissionJson = + "{\"owner_permission\":{\"type\":0," + + ",\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":9223372036854775807}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : long overflow", - response.getMessage().toStringUtf8()); - // weight = 1.1 - accountPermissionJson = "{\"owner_permission\":{\"type\":0," - + ",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1.1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" - + "]}]}"; + Assert.assertEquals( + "Contract validate error : long overflow", response.getMessage().toStringUtf8()); + // weight = 1.1 + accountPermissionJson = + "{\"owner_permission\":{\"type\":0," + + ",\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1.1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; ret = false; try { @@ -324,26 +420,27 @@ public void testOwnerWeight01() { ret = true; } Assert.assertTrue(ret); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); - } - @Test(enabled = true, description = "Owner weight is 1", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner weight is 1", + groups = {"daily", "multisig"}) public void testOwnerWeight02() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -351,76 +448,99 @@ public void testOwnerWeight02() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = "{\"owner_permission\":{\"type\":0," - + ",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" - + "]}]}"; - - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + String accountPermissionJson = + "{\"owner_permission\":{\"type\":0," + + ",\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - - @Test(enabled = true, description = "Owner weight is Long.MAX_VALUE", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner weight is Long.MAX_VALUE", + groups = {"daily", "multisig"}) public void testOwnerWeight04() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -428,57 +548,77 @@ public void testOwnerWeight04() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = "{\"owner_permission\":{\"type\":0," - + ",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":9223372036854775807}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" - + "]}]}"; - - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + String accountPermissionJson = + "{\"owner_permission\":{\"type\":0," + + ",\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":9223372036854775807}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); @@ -489,11 +629,7 @@ public void aftertest() { PublicMethod.freeResource(ownerAddress, ownerKey, foundationAddress, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign05.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign05.java index db7e8b61..56a9cd48 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign05.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign05.java @@ -16,17 +16,17 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSign05 extends TronBaseTest { private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); private final String contractTronDiceAddr = "TMYcx6eoRXnePKT1jVn25ZNeMNJ6828HWk"; - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -39,30 +39,32 @@ public class MultiSign05 extends TronBaseTest { private ECKey tmpEcKey02 = new ECKey(Utils.getRandom()); private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull); + public void beforeClass() { + PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull); } - @Test(enabled = true, description = "Owner key-address is witness account", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner key-address is witness account", + groups = {"daily", "multisig"}) public void testOwnerKeyAddress01() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2 + multiSignFee; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -70,73 +72,97 @@ public void testOwnerKeyAddress01() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.add(witnessKey); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - - @Test(enabled = true, description = "Owner key-address is contract address", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner key-address is contract address", + groups = {"daily", "multisig"}) public void testOwnerKeyAddress02() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -144,74 +170,98 @@ public void testOwnerKeyAddress02() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + contractTronDiceAddr + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + contractTronDiceAddr + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":2}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(testKey002); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - @Test(enabled = true, description = "Owner key-address is inactive address", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner key-address is inactive address", + groups = {"daily", "multisig"}) public void testOwnerKeyAddress03() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2 + multiSignFee; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -219,62 +269,86 @@ public void testOwnerKeyAddress03() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.add(tmpKey01); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - @Test(enabled = true, description = "Owner key-address is owner address", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner key-address is owner address", + groups = {"daily", "multisig"}) public void testOwnerKeyAddress04() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); @@ -282,11 +356,11 @@ public void testOwnerKeyAddress04() { long needCoin = updateAccountPermissionFee * 2; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -294,69 +368,90 @@ public void testOwnerKeyAddress04() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - } - @Test(enabled = true, description = "Owner key-address in exception condition", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner key-address in exception condition", + groups = {"daily", "multisig"}) public void testOwnerKeyAddress05() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -364,40 +459,57 @@ public void testOwnerKeyAddress05() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - // address = owner_address more than once + // address = owner_address more than once String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : address should be distinct " - + "in permission Owner", + Assert.assertEquals( + "Contract validate error : address should be distinct " + "in permission Owner", response.getMessage().toStringUtf8()); - // address = not exist + // address = not exist String fakeAddress = "THph9K2M2nLvkianrMGswRhz5hjSA9fuH1"; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + fakeAddress + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + fakeAddress + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; boolean ret = false; try { @@ -408,19 +520,26 @@ public void testOwnerKeyAddress05() { ret = true; } Assert.assertTrue(ret); - // address = long address + // address = long address fakeAddress = "TR3FAbhiSeP7kSh39RjGYpwCqfMDHPMhX4d121"; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + fakeAddress + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + fakeAddress + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; try { @@ -431,19 +550,26 @@ public void testOwnerKeyAddress05() { ret = true; } Assert.assertTrue(ret); - // address = short address + // address = short address fakeAddress = "THph9K2M2nLvkianrMGswRhz5hj"; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + fakeAddress + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + fakeAddress + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; try { @@ -454,17 +580,23 @@ public void testOwnerKeyAddress05() { ret = true; } Assert.assertTrue(ret); - // address = + // address = fakeAddress = ""; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":5,\"keys\":[" - + "{\"address\":\"" + fakeAddress + "\",\"weight\":5}]}," + + "{\"address\":\"" + + fakeAddress + + "\",\"weight\":5}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; try { @@ -476,19 +608,24 @@ public void testOwnerKeyAddress05() { } Assert.assertTrue(ret); - // address = null + // address = null fakeAddress = null; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":5,\"keys\":[" - + "{\"address\":\"" + fakeAddress + + "{\"address\":\"" + + fakeAddress + "\",\"weight\":5}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; @@ -501,18 +638,23 @@ public void testOwnerKeyAddress05() { } Assert.assertTrue(ret); - // address = "1.1" + // address = "1.1" fakeAddress = "1.1"; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":5,\"keys\":[" - + "{\"address\":\"" + fakeAddress + + "{\"address\":\"" + + fakeAddress + "\",\"weight\":5}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; @@ -525,26 +667,27 @@ public void testOwnerKeyAddress05() { } Assert.assertTrue(ret); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); - } - @Test(enabled = true, description = "Owner key-address count is 5", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner key-address count is 5", + groups = {"daily", "multisig"}) public void testOwnerKeyAddress06() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2 + multiSignFee; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -552,38 +695,60 @@ public void testOwnerKeyAddress06() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":5,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(5, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 5, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); ownerPermissionKeys.add(testKey002); ownerPermissionKeys.add(witnessKey); @@ -593,35 +758,44 @@ public void testOwnerKeyAddress06() { logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - @Test(enabled = true, description = "Owner key-address count in exception condition", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner key-address count in exception condition", + groups = {"daily", "multisig"}) public void testOwnerKeyAddress07() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -629,63 +803,80 @@ public void testOwnerKeyAddress07() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - // address count = 6 + // address count = 6 String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":5,\"keys\":[" - + "{\"address\":\"" + contractTronDiceAddr + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + + "{\"address\":\"" + + contractTronDiceAddr + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : number of keys in permission should" - + " not be greater than 5", + Assert.assertEquals( + "Contract validate error : number of keys in permission should" + " not be greater than 5", response.getMessage().toStringUtf8()); - // address count = 0 + // address count = 0 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":5," + "\"keys\":[]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : key's count should be greater than 0", + Assert.assertEquals( + "Contract validate error : key's count should be greater than 0", response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); } - @AfterMethod public void aftertest() { PublicMethod.freeResource(ownerAddress, ownerKey, foundationAddress, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign06.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign06.java index 5ffdc723..4e027be4 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign06.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign06.java @@ -16,16 +16,16 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSign06 extends TronBaseTest { private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -38,118 +38,152 @@ public class MultiSign06 extends TronBaseTest { private ECKey tmpEcKey02 = new ECKey(Utils.getRandom()); private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Owner type in exception condition", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner type in exception condition", + groups = {"daily", "multisig"}) public void testOwnerType01() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - final byte[] ownerAddress = ecKey1.getAddress(); - final String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, - testKey002, blockingStubFull)); + final byte[] ownerAddress = ecKey1.getAddress(); + final String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); - // type = 1 + // type = 1 String accountPermissionJson = "{\"owner_permission\":{\"type\":1,\"permission_name\":\"owner\",\"threshold\":1," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : owner permission type is error", + Assert.assertEquals( + "Contract validate error : owner permission type is error", response.getMessage().toStringUtf8()); - // type = 2 + // type = 2 accountPermissionJson = "{\"owner_permission\":{\"type\":2,\"permission_name\":\"owner\",\"threshold\":1," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : owner permission type is error", + Assert.assertEquals( + "Contract validate error : owner permission type is error", response.getMessage().toStringUtf8()); - // type = -1 + // type = -1 accountPermissionJson = "{\"owner_permission\":{\"type\":-1,\"permission_name\":\"owner\",\"threshold\":1," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : owner permission type is error", + Assert.assertEquals( + "Contract validate error : owner permission type is error", response.getMessage().toStringUtf8()); - // type = long.min - 1000020 + // type = long.min - 1000020 accountPermissionJson = "{\"owner_permission\":{\"type\":-9223372036855775828,\"permission_name\":\"\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : owner permission type is error", + Assert.assertEquals( + "Contract validate error : owner permission type is error", response.getMessage().toStringUtf8()); - // type = "12a" + // type = "12a" accountPermissionJson = "{\"owner_permission\":{\"type\":\"12a\",\"permission_name\":\"\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; boolean ret = false; @@ -161,17 +195,22 @@ public void testOwnerType01() { ret = true; } Assert.assertTrue(ret); - // type = "" + // type = "" accountPermissionJson = "{\"owner_permission\":{\"type\":\"\",\"permission_name\":\"\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; try { @@ -182,17 +221,22 @@ public void testOwnerType01() { ret = true; } Assert.assertTrue(ret); - // type = + // type = accountPermissionJson = "{\"owner_permission\":{\"type\":,\"permission_name\":\"\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; @@ -204,17 +248,24 @@ public void testOwnerType01() { ret = true; } Assert.assertTrue(ret); - // type = null + // type = null accountPermissionJson = - "{\"owner_permission\":{\"type\":" + null + ",\"permission_name\":\"\"," + "{\"owner_permission\":{\"type\":" + + null + + ",\"permission_name\":\"\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; @@ -226,104 +277,137 @@ public void testOwnerType01() { ret = true; } Assert.assertTrue(ret); - // type = Integer.MAX_VALUE + // type = Integer.MAX_VALUE accountPermissionJson = "{\"owner_permission\":{\"type\":2147483647,\"permission_name\":\"\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : owner permission type is error", + Assert.assertEquals( + "Contract validate error : owner permission type is error", response.getMessage().toStringUtf8()); - // type = Long.MAX_VALUE + // type = Long.MAX_VALUE accountPermissionJson = "{\"owner_permission\":{\"type\":9223372036854775807,\"permission_name\":\"\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : owner permission type is error", + Assert.assertEquals( + "Contract validate error : owner permission type is error", response.getMessage().toStringUtf8()); - // type = long.min - 1 + // type = long.min - 1 accountPermissionJson = "{\"owner_permission\":{\"type\":-9223372036854775809,\"permission_name\":\"owner\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : owner permission type is error", + Assert.assertEquals( + "Contract validate error : owner permission type is error", response.getMessage().toStringUtf8()); - // type = Long.MAX_VALUE + 10 - accountPermissionJson = "{\"owner_permission\":{\"type\":9223372036854775817," - + "\"permission_name\":\"owner\",\"threshold\": 1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":9223372036854775806}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" - + "]}]}"; - - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + // type = Long.MAX_VALUE + 10 + accountPermissionJson = + "{\"owner_permission\":{\"type\":9223372036854775817," + + "\"permission_name\":\"owner\",\"threshold\": 1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":9223372036854775806}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; + + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : owner permission type is error", + Assert.assertEquals( + "Contract validate error : owner permission type is error", response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); } - @Test(enabled = true, description = "Owner type is 0", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner type is 0", + groups = {"daily", "multisig"}) public void testOwnerType02() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - final byte[] ownerAddress = ecKey1.getAddress(); - final String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + final byte[] ownerAddress = ecKey1.getAddress(); + final String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -333,74 +417,95 @@ public void testOwnerType02() { ownerPermissionKeys.add(ownerKey); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - - @Test(enabled = true, description = "Owner type is Long.Min", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner type is Long.Min", + groups = {"daily", "multisig"}) public void testOwnerType03() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - final byte[] ownerAddress = ecKey1.getAddress(); - final String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + final byte[] ownerAddress = ecKey1.getAddress(); + final String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -410,75 +515,97 @@ public void testOwnerType03() { ownerPermissionKeys.add(ownerKey); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":-9223372036854775808,\"permission_name\":\"\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - @Test(enabled = true, description = "Owner type is Long.MAX_VALUE + 1", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner type is Long.MAX_VALUE + 1", + groups = {"daily", "multisig"}) public void testOwnerType04() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - final byte[] ownerAddress = ecKey1.getAddress(); - final String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + final byte[] ownerAddress = ecKey1.getAddress(); + final String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -488,77 +615,97 @@ public void testOwnerType04() { ownerPermissionKeys.add(ownerKey); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":9223372036854775808,\"permission_name\":\"Owner\"," + "\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":2}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":9223372036854775806}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - - @Test(enabled = true, description = "Owner type is 0.1", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner type is 0.1", + groups = {"daily", "multisig"}) public void testOwnerType05() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - final byte[] ownerAddress = ecKey1.getAddress(); - final String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + final byte[] ownerAddress = ecKey1.getAddress(); + final String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -566,57 +713,79 @@ public void testOwnerType05() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = "{\"owner_permission\":{\"type\":0.1," - + "\"permission_name\":\"owner\",\"threshold\": 1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":9223372036854775806}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" - + "]}]}"; - - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + String accountPermissionJson = + "{\"owner_permission\":{\"type\":0.1," + + "\"permission_name\":\"owner\",\"threshold\": 1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":9223372036854775806}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); @@ -627,10 +796,7 @@ public void aftertest() { PublicMethod.freeResource(ownerAddress, ownerKey, foundationAddress, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign07.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign07.java index a5c3d132..6a7996ab 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign07.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign07.java @@ -17,8 +17,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSign07 extends TronBaseTest { @@ -27,10 +27,10 @@ public class MultiSign07 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -44,18 +44,19 @@ public class MultiSign07 extends TronBaseTest { private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); private byte[] transferTokenContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Owner permission_name is owner", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner permission_name is owner", + groups = {"daily", "multisig"}) public void testActiveName01() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); @@ -63,10 +64,11 @@ public void testActiveName01() { long needCoin = updateAccountPermissionFee + multiSignFee; - Assert.assertTrue(PublicMethod - .sendcoin(ownerAddress, needCoin + 1000000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1000000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); @@ -77,17 +79,28 @@ public void testActiveName01() { ownerPermissionKeys.add(ownerKey); activePermissionKeys.add(witnessKey); activePermissionKeys.add(tmpKey02); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"owner\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -95,22 +108,32 @@ public void testActiveName01() { ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a normal transaction"); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -118,20 +141,23 @@ public void testActiveName01() { logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); - } - @Test(enabled = true, description = "Owner permission_name is active", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner permission_name is active", + groups = {"daily", "multisig"}) public void testActiveName02() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee + multiSignFee; - Assert.assertTrue(PublicMethod - .sendcoin(ownerAddress, needCoin + 1_000000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1_000000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -141,16 +167,27 @@ public void testActiveName02() { ownerPermissionKeys.add(ownerKey); activePermissionKeys.add(witnessKey); activePermissionKeys.add(tmpKey02); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -158,41 +195,54 @@ public void testActiveName02() { ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a normal transaction"); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); - } - @Test(enabled = true, description = "Owner permission_name is activea", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner permission_name is activea", + groups = {"daily", "multisig"}) public void testActiveName03() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee + multiSignFee; - Assert.assertTrue(PublicMethod - .sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -202,16 +252,27 @@ public void testActiveName03() { ownerPermissionKeys.add(ownerKey); activePermissionKeys.add(witnessKey); activePermissionKeys.add(tmpKey02); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"activea\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -219,40 +280,54 @@ public void testActiveName03() { ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a normal transaction"); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); } - @Test(enabled = true, description = "Owner permission_name is \"123\"", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner permission_name is \"123\"", + groups = {"daily", "multisig"}) public void testActiveName04() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee + multiSignFee; - Assert.assertTrue(PublicMethod - .sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -262,16 +337,27 @@ public void testActiveName04() { ownerPermissionKeys.add(ownerKey); activePermissionKeys.add(witnessKey); activePermissionKeys.add(tmpKey02); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"123\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -279,40 +365,54 @@ public void testActiveName04() { ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a normal transaction"); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); } - @Test(enabled = true, description = "Owner permission_name is \"\"", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner permission_name is \"\"", + groups = {"daily", "multisig"}) public void testActiveName05() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee + multiSignFee; - Assert.assertTrue(PublicMethod - .sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -322,17 +422,28 @@ public void testActiveName05() { ownerPermissionKeys.add(ownerKey); activePermissionKeys.add(witnessKey); activePermissionKeys.add(tmpKey02); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -340,38 +451,52 @@ public void testActiveName05() { ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a normal transaction"); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); } - @Test(enabled = true, description = "Owner permission_name in exception condition", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner permission_name in exception condition", + groups = {"daily", "multisig"}) public void testActiveName06() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -379,62 +504,81 @@ public void testActiveName06() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + null + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + null + ",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; boolean ret = false; try { - GrpcAPI.Return response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NullPointerException e) { logger.info("Expected NullPointerException!"); ret = true; } Assert.assertTrue(ret); - // name = + // name = accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":,\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (com.alibaba.fastjson.JSONException e) { logger.info("Expected com.alibaba.fastjson.JSONException!"); ret = true; } Assert.assertTrue(ret); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); } - @Test(enabled = true, description = "Owner permission_name is 1.1", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner permission_name is 1.1", + groups = {"daily", "multisig"}) public void testActiveName07() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee + multiSignFee; - Assert.assertTrue(PublicMethod - .sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -444,16 +588,27 @@ public void testActiveName07() { ownerPermissionKeys.add(ownerKey); activePermissionKeys.add(witnessKey); activePermissionKeys.add(tmpKey02); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":1.1,\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -461,31 +616,44 @@ public void testActiveName07() { ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a normal transaction"); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); } - @Test(enabled = true, description = "Active permission_name length is 32", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active permission_name length is 32", + groups = {"daily", "multisig"}) public void testActiveName08() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); @@ -493,11 +661,12 @@ public void testActiveName08() { long needCoin = updateAccountPermissionFee * 2; - Assert.assertTrue(PublicMethod - .sendcoin(ownerAddress, needCoin + 1000000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1000000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -506,18 +675,29 @@ public void testActiveName08() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2," + "\"permission_name\":\"abcdefghijklmnopqrstuvwxyzabcdef\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -525,80 +705,104 @@ public void testActiveName08() { ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - } - - @Test(enabled = true, description = "Active permission_name length is 33", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active permission_name length is 33", + groups = {"daily", "multisig"}) public void testActiveName09() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, 1000000, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, 1000000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); - String accountPermissionJson = "{\"owner_permission\":{\"type\":0," - + "\"permission_name\":\"owner001\",\"threshold\":1,\"keys\":[" + "{\"address\":\"" - + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2," - + "\"permission_name\":\"abcdefghijklmnopqrstuvwxyzabcdefg\",\"threshold\":1," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - - GrpcAPI.Return response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + String accountPermissionJson = + "{\"owner_permission\":{\"type\":0," + + "\"permission_name\":\"owner001\",\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2," + + "\"permission_name\":\"abcdefghijklmnopqrstuvwxyzabcdefg\",\"threshold\":1," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's name is too long", + Assert.assertEquals( + "Contract validate error : permission's name is too long", response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); - } @AfterMethod @@ -606,10 +810,7 @@ public void aftertest() { PublicMethod.freeResource(ownerAddress, ownerKey, foundationAddress, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign08.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign08.java index 25c9727a..91dab9ba 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign08.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign08.java @@ -16,16 +16,16 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSign08 extends TronBaseTest { private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -38,26 +38,28 @@ public class MultiSign08 extends TronBaseTest { private ECKey tmpEcKey02 = new ECKey(Utils.getRandom()); private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Active threshold is exception condition", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active threshold is exception condition", + groups = {"daily", "multisig"}) public void testActiveTheshold01() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -65,266 +67,354 @@ public void testActiveTheshold01() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - // threshold = Integer.Min_Value + // threshold = Integer.Min_Value String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":-2147483648," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - - GrpcAPI.Return response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); Assert.assertEquals( "Contract validate error : permission's" + " threshold should be greater than 0", response.getMessage().toStringUtf8()); - // threshold = 0 + // threshold = 0 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":0," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); Assert.assertEquals( "Contract validate error : permission's" + " threshold should be greater than 0", response.getMessage().toStringUtf8()); - // threshold = -1 + // threshold = -1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":-1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); Assert.assertEquals( "Contract validate error : permission's" + " threshold should be greater than 0", response.getMessage().toStringUtf8()); - // threshold = long.min + // threshold = long.min accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":-9223372036854775808," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); Assert.assertEquals( "Contract validate error : permission's" + " threshold should be greater than 0", response.getMessage().toStringUtf8()); - // threshold = long.min - 1000020 + // threshold = long.min - 1000020 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":-9223372036855775828," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; boolean ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NumberFormatException e) { logger.info("NumberFormatException !"); ret = true; } Assert.assertTrue(ret); - // threshold = long.min - 1 + // threshold = long.min - 1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":-9223372036854775809," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NumberFormatException e) { logger.info("NumberFormatException !"); ret = true; } Assert.assertTrue(ret); - // threshold = "12a" + // threshold = "12a" accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":\"-12a\"," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NumberFormatException e) { logger.info("NumberFormatException : -12a !"); ret = true; } Assert.assertTrue(ret); - // threshold = "" + // threshold = "" accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":\"\"," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NumberFormatException e) { logger.info("NumberFormatException !"); ret = true; } Assert.assertTrue(ret); - // threshold = + // threshold = accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (com.alibaba.fastjson.JSONException e) { logger.info("JSONException !"); ret = true; } Assert.assertTrue(ret); - // threshold = null + // threshold = null accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," - + "\"threshold\":" + null + "," + + "\"threshold\":" + + null + + "," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NumberFormatException e) { logger.info("NumberFormatException !"); ret = true; } Assert.assertTrue(ret); - // threshold = 1.9 + // threshold = 1.9 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1.9," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":21}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":21}" + + "]}]}"; ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NumberFormatException e) { logger.info("NumberFormatException !"); ret = true; } Assert.assertTrue(ret); - // threshold = Long.MAX_VALUE + // threshold = Long.MAX_VALUE accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":9223372036854775807," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":9223372036854775807}," + "{\"address\":\"" + PublicMethod - .getAddressString(ownerKey) + "\",\"weight\":1}" + "]}]}"; - - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":9223372036854775807}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; + + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : long overflow", - response.getMessage().toStringUtf8()); - // theshold = 1.1 > sum(weight) + Assert.assertEquals( + "Contract validate error : long overflow", response.getMessage().toStringUtf8()); + // theshold = 1.1 > sum(weight) accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1.1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":9223372036854775806}," + "{\"address\":\"" + PublicMethod - .getAddressString(ownerKey) + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":9223372036854775806}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NumberFormatException e) { logger.info("NumberFormatException !"); ret = true; } Assert.assertTrue(ret); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); } - @Test(enabled = true, description = "Active threshold is 1", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active threshold is 1", + groups = {"daily", "multisig"}) public void testActiveTheshold02() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); @@ -332,10 +422,11 @@ public void testActiveTheshold02() { long needCoin = updateAccountPermissionFee; - Assert.assertTrue(PublicMethod - .sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -344,56 +435,79 @@ public void testActiveTheshold02() { List activePermissionKeys = new ArrayList<>(); ownerPermissionKeys.add(ownerKey); activePermissionKeys.add(tmpKey02); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(1, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 1, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a normal transaction"); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); } - @Test(enabled = true, description = "Active threshold is more than sum of weight", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active threshold is more than sum of weight", + groups = {"daily", "multisig"}) public void testActiveTheshold03() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -401,41 +515,56 @@ public void testActiveTheshold03() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - // threshold = Integer.MAX_VALUE *2 + 5 > sum(weight) + // threshold = Integer.MAX_VALUE *2 + 5 > sum(weight) String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":4294967299," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2147483647}," + "{\"address\":\"" + PublicMethod - .getAddressString(witnessKey) + "\",\"weight\":3}," + "{\"address\":\"" - + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":2147483647}" + "]}]}"; - GrpcAPI.Return response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2147483647}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":2147483647}" + + "]}]}"; + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : sum of all key's weight should not" - + " be less than threshold in permission Active", response.getMessage().toStringUtf8()); - + Assert.assertEquals( + "Contract validate error : sum of all key's weight should not" + + " be less than threshold in permission Active", + response.getMessage().toStringUtf8()); } - @Test(enabled = true, description = "Active threshold is Long.MAX_VALUE", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active threshold is Long.MAX_VALUE", + groups = {"daily", "multisig"}) public void testActiveTheshold04() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee + multiSignFee; - Assert.assertTrue(PublicMethod - .sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); @@ -448,58 +577,85 @@ public void testActiveTheshold04() { activePermissionKeys.add(ownerKey); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":9223372036854775807," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":9223372036854775806}," + "{\"address\":\"" + PublicMethod - .getAddressString(ownerKey) + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":9223372036854775806}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a normal transaction"); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); } - @Test(enabled = true, description = "Active threshold is Integer.MAX_VALUE", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active threshold is Integer.MAX_VALUE", + groups = {"daily", "multisig"}) public void testActiveTheshold05() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee + multiSignFee; - Assert.assertTrue(PublicMethod - .sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); @@ -513,43 +669,66 @@ public void testActiveTheshold05() { activePermissionKeys.add(tmpKey01); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":2147483647," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2147483646}," + "{\"address\":\"" + PublicMethod - .getAddressString(ownerKey) + "\",\"weight\":2147483647}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2147483646}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2147483647}" + + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a normal transaction"); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); } @@ -559,10 +738,7 @@ public void aftertest() { PublicMethod.freeResource(ownerAddress, ownerKey, foundationAddress, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign09.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign09.java index 4b6bf2bd..a2dca2e2 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign09.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign09.java @@ -16,16 +16,16 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSign09 extends TronBaseTest { private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -38,18 +38,19 @@ public class MultiSign09 extends TronBaseTest { private ECKey tmpEcKey02 = new ECKey(Utils.getRandom()); private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Active doesn't have parent_id", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active doesn't have parent_id", + groups = {"daily", "multisig"}) public void testActiveParent01() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); @@ -58,9 +59,10 @@ public void testActiveParent01() { long needCoin = updateAccountPermissionFee * 2; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -68,17 +70,28 @@ public void testActiveParent01() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":4," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -86,46 +99,64 @@ public void testActiveParent01() { ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - @Test(enabled = true, description = "Active parent_id is exception condition", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active parent_id is exception condition", + groups = {"daily", "multisig"}) public void testActiveParent02() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -133,229 +164,331 @@ public void testActiveParent02() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - // parent_id = "123" + // parent_id = "123" String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + "\"active_permissions\":[" + "{\"parent_id\":\"123\",\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - GrpcAPI.Return response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = "abc" + // parent_id = "abc" accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + "\"active_permissions\":[" + "{\"parent_id\":\"abc\",\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; boolean ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NumberFormatException e) { logger.info("Expected NumberFormatException!"); ret = true; } Assert.assertTrue(ret); - // parent_id = "" + // parent_id = "" accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + "\"active_permissions\":[" + "{\"parent_id\":\"\",\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NullPointerException e) { logger.info("Expected NullPointerException!"); ret = true; } Assert.assertTrue(ret); - // parent_id = null + // parent_id = null accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," - + "\"active_permissions\":[" + "{\"parent_id\":" + null + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + + "\"active_permissions\":[" + + "{\"parent_id\":" + + null + ",\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NullPointerException e) { logger.info("Expected NullPointerException!"); ret = true; } Assert.assertTrue(ret); - // parent_id = 1 + // parent_id = 1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + "\"active_permissions\":[" + "{\"parent_id\":1,\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = 2 + // parent_id = 2 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + "\"active_permissions\":[" + "{\"parent_id\":2,\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = 3 + // parent_id = 3 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + "\"active_permissions\":[" + "{\"parent_id\":3,\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = -1 + // parent_id = -1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + "\"active_permissions\":[" + "{\"parent_id\":-1,\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = Integer.MAX_VALUE + // parent_id = Integer.MAX_VALUE accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," - + "\"active_permissions\":[" + "{\"parent_id\":2147483647,\"type\":2," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + + "\"active_permissions\":[" + + "{\"parent_id\":2147483647,\"type\":2," + "\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = Integer.MAX_VALUE +1 + // parent_id = Integer.MAX_VALUE +1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," - + "\"active_permissions\":[" + "{\"parent_id\":2147483648,\"type\":2," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + + "\"active_permissions\":[" + + "{\"parent_id\":2147483648,\"type\":2," + "\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = Integer.MIN_VALUE + // parent_id = Integer.MIN_VALUE accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," - + "\"active_permissions\":[" + "{\"parent_id\":-2147483648,\"type\":2," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + + "\"active_permissions\":[" + + "{\"parent_id\":-2147483648,\"type\":2," + "\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = Integer.MIN_VALUE -1 + // parent_id = Integer.MIN_VALUE -1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," - + "\"active_permissions\":[" + "{\"parent_id\":-2147483649,\"type\":2," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + + "\"active_permissions\":[" + + "{\"parent_id\":-2147483649,\"type\":2," + "\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); } - @Test(enabled = true, description = "Active parent_id is 0", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active parent_id is 0", + groups = {"daily", "multisig"}) public void testActiveParent03() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); @@ -363,9 +496,10 @@ public void testActiveParent03() { long needCoin = updateAccountPermissionFee * 2; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -373,17 +507,28 @@ public void testActiveParent03() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}]}," + "\"active_permissions\":[" + "{\"parent_id\":0,\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -391,33 +536,47 @@ public void testActiveParent03() { ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } @@ -427,11 +586,7 @@ public void aftertest() { PublicMethod.freeResource(ownerAddress, ownerKey, foundationAddress, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign10.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign10.java index c8ff890b..70a36778 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign10.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign10.java @@ -17,8 +17,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSign10 extends TronBaseTest { @@ -27,10 +27,10 @@ public class MultiSign10 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -44,27 +44,28 @@ public class MultiSign10 extends TronBaseTest { private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); private byte[] transferTokenContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Active weight is exception condition", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active weight is exception condition", + groups = {"daily", "multisig"}) public void testActiveWeight01() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -72,113 +73,169 @@ public void testActiveWeight01() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - // weight = Integer.MIN_VALUE + // weight = Integer.MIN_VALUE String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":-2147483648}" + "]}]}"; - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : key's weight" - + " should be greater than 0", + Assert.assertEquals( + "Contract validate error : key's weight" + " should be greater than 0", response.getMessage().toStringUtf8()); - // weight = 0 + // weight = 0 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":0}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":0}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : key's weight" - + " should be greater than 0", + Assert.assertEquals( + "Contract validate error : key's weight" + " should be greater than 0", response.getMessage().toStringUtf8()); - // weight = -1 + // weight = -1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":-1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":-1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : key's weight" - + " should be greater than 0", + Assert.assertEquals( + "Contract validate error : key's weight" + " should be greater than 0", response.getMessage().toStringUtf8()); - // weight = long.min + // weight = long.min accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":-9223372036854775808}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : key's weight" - + " should be greater than 0", + Assert.assertEquals( + "Contract validate error : key's weight" + " should be greater than 0", response.getMessage().toStringUtf8()); - // weight = long.min - 1000020 + // weight = long.min - 1000020 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":-9223372036855775828}" + "]}]}"; @@ -191,19 +248,30 @@ public void testActiveWeight01() { ret = true; } Assert.assertTrue(ret); - // weight = "12a" + // weight = "12a" accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":\"12a\"}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":\"12a\"}" + "]}]}"; ret = false; try { @@ -214,20 +282,29 @@ public void testActiveWeight01() { ret = true; } Assert.assertTrue(ret); - // weight = "" + // weight = "" accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":\"\"}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":-9223372036855775828}" + "]}]}"; ret = false; @@ -239,19 +316,30 @@ public void testActiveWeight01() { ret = true; } Assert.assertTrue(ret); - // weight = + // weight = accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; try { @@ -262,20 +350,32 @@ public void testActiveWeight01() { ret = true; } Assert.assertTrue(ret); - // weight = null + // weight = null accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":" - + null + "}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":" + + null + + "}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; @@ -287,15 +387,17 @@ public void testActiveWeight01() { ret = true; } Assert.assertTrue(ret); - // weight = Long.MIN -1 + // weight = Long.MIN -1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":-9223372036854775809}" + "]}]}"; @@ -308,15 +410,17 @@ public void testActiveWeight01() { ret = true; } Assert.assertTrue(ret); - // weight = 1.1 + // weight = 1.1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1.1}" + "]}]}"; @@ -329,24 +433,26 @@ public void testActiveWeight01() { ret = true; } Assert.assertTrue(ret); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); } - @Test(enabled = true, description = "Active weight is 1", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active weight is 1", + groups = {"daily", "multisig"}) public void testActiveWeight02() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee + multiSignFee; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -357,66 +463,92 @@ public void testActiveWeight02() { activePermissionKeys.add(witnessKey); activePermissionKeys.add(ownerKey); activePermissionKeys.add(tmpKey02); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(3, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 3, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(3, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 3, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a normal transaction"); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); } - @Test(enabled = true, description = "Active weight is Integer.MAX_VALUE", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active weight is Integer.MAX_VALUE", + groups = {"daily", "multisig"}) public void testActiveWeight03() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -426,66 +558,86 @@ public void testActiveWeight03() { ownerPermissionKeys.add(ownerKey); activePermissionKeys.add(witnessKey); activePermissionKeys.add(tmpKey02); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2147483647}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":2147483647}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":21474836471}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":21474836471}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.add(tmpKey02); ownerPermissionKeys.add(witnessKey); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(3, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 3, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a normal transaction"); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); } - @Test(enabled = true, description = "Active sum of weight is more than Long.MAX_VALUE", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active sum of weight is more than Long.MAX_VALUE", + groups = {"daily", "multisig"}) public void testActiveWeight04() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -495,46 +647,55 @@ public void testActiveWeight04() { ownerPermissionKeys.add(ownerKey); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2147483647}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":2147483647}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":9223372036854775807}" + "]}]}"; - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : long overflow", - response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertEquals( + "Contract validate error : long overflow", response.getMessage().toStringUtf8()); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); } - @Test(enabled = true, description = "Active weight is Long.MAX_VALUE", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active weight is Long.MAX_VALUE", + groups = {"daily", "multisig"}) public void testActiveWeight05() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -543,46 +704,60 @@ public void testActiveWeight05() { List activePermissionKeys = new ArrayList<>(); ownerPermissionKeys.add(ownerKey); activePermissionKeys.add(witnessKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":9223372036854775807}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(1, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 1, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a normal transaction"); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); } @@ -592,10 +767,7 @@ public void aftertest() { PublicMethod.freeResource(ownerAddress, ownerKey, foundationAddress, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign11.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign11.java index d329fdcc..958d679b 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign11.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign11.java @@ -17,8 +17,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSign11 extends TronBaseTest { @@ -28,10 +28,10 @@ public class MultiSign11 extends TronBaseTest { private static ByteString assetAccountId = null; private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); private final String contractTronDiceAddr = "TMYcx6eoRXnePKT1jVn25ZNeMNJ6828HWk"; - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -45,28 +45,30 @@ public class MultiSign11 extends TronBaseTest { private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); private byte[] transferTokenContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Active address is witness", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active address is witness", + groups = {"daily", "multisig"}) public void testActiveAddress01() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee + multiSignFee; - Assert.assertTrue(PublicMethod - .sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -76,58 +78,84 @@ public void testActiveAddress01() { ownerPermissionKeys.add(ownerKey); activePermissionKeys.add(witnessKey); activePermissionKeys.add(tmpKey02); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":4," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.add(witnessKey); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a normal transaction"); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); } - @Test(enabled = true, description = "Active address is contract address", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active address is contract address", + groups = {"daily", "multisig"}) public void testActiveAddress02() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee; - Assert.assertTrue(PublicMethod - .sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -136,58 +164,87 @@ public void testActiveAddress02() { List activePermissionKeys = new ArrayList<>(); ownerPermissionKeys.add(ownerKey); activePermissionKeys.add(tmpKey02); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + contractTronDiceAddr + "\",\"weight\":1}," + "{\"address\":\"" - + PublicMethod.getAddressString(testKey002) + "\",\"weight\":2147483647}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + contractTronDiceAddr + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + contractTronDiceAddr + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}" + + "\"keys\":[" + + "{\"address\":\"" + + contractTronDiceAddr + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.add(testKey002); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(3, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 3, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a normal transaction"); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); } - @Test(enabled = true, description = "Active address is inactive address", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active address is inactive address", + groups = {"daily", "multisig"}) public void testActiveAddress03() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee + multiSignFee; - Assert.assertTrue(PublicMethod - .sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -197,60 +254,86 @@ public void testActiveAddress03() { ownerPermissionKeys.add(ownerKey); activePermissionKeys.add(witnessKey); activePermissionKeys.add(tmpKey02); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":5," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":3}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":3}" + + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.add(tmpKey01); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a normal transaction"); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); } - @Test(enabled = true, description = "Active address is owner address", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active address is owner address", + groups = {"daily", "multisig"}) public void testActiveAddress04() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee; - Assert.assertTrue(PublicMethod - .sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -259,54 +342,78 @@ public void testActiveAddress04() { List activePermissionKeys = new ArrayList<>(); ownerPermissionKeys.add(ownerKey); activePermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":3}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}" + + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(1, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 1, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a normal transaction"); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); } - @Test(enabled = true, description = "Active address is exception condition", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active address is exception condition", + groups = {"daily", "multisig"}) public void testActiveAddress05() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -314,181 +421,245 @@ public void testActiveAddress05() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - // address = same address more than once + // address = same address more than once String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":3}," + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":3}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}" + + "]}]}"; - GrpcAPI.Return response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); Assert.assertEquals( "Contract validate error : address should be distinct" + " in permission Active", response.getMessage().toStringUtf8()); - // address = not exist + // address = not exist String fakeAddress = "THph9K2M2nLvkianrMGswRhz5hjSA9fuH1"; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + fakeAddress + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}" + + "\"keys\":[" + + "{\"address\":\"" + + fakeAddress + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}" + "]}]}"; boolean ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NullPointerException e) { logger.info("NullPointerException !"); ret = true; } Assert.assertTrue(ret); - // address = long address + // address = long address fakeAddress = "TR3FAbhiSeP7kSh39RjGYpwCqfMDHPMhX4d121"; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + fakeAddress + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}" + + "\"keys\":[" + + "{\"address\":\"" + + fakeAddress + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}" + "]}]}"; ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NullPointerException e) { logger.info("NullPointerException !"); ret = true; } Assert.assertTrue(ret); - // address = short address + // address = short address fakeAddress = "THph9K2M2nLvkianrMGswRhz5hj"; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + fakeAddress + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}" + + "\"keys\":[" + + "{\"address\":\"" + + fakeAddress + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}" + "]}]}"; ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NullPointerException e) { logger.info("NullPointerException !"); ret = true; } Assert.assertTrue(ret); - // address = + // address = fakeAddress = ""; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + fakeAddress + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":3}" + + "\"keys\":[" + + "{\"address\":\"" + + fakeAddress + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + "]}]}"; ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, fakeAddress.getBytes(), - ownerKey, blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, fakeAddress.getBytes(), ownerKey, blockingStubFull); } catch (NullPointerException e) { logger.info("NullPointerException!"); ret = true; } Assert.assertTrue(ret); - // address = null + // address = null fakeAddress = null; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + fakeAddress + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":3}" + + "\"keys\":[" + + "{\"address\":\"" + + fakeAddress + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + "]}]}"; ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, fakeAddress.getBytes(), - ownerKey, blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, fakeAddress.getBytes(), ownerKey, blockingStubFull); } catch (NullPointerException e) { logger.info("NullPointerException!"); ret = true; } Assert.assertTrue(ret); - // address = 1.1 + // address = 1.1 fakeAddress = "1.1"; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + fakeAddress + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":3}" + + "\"keys\":[" + + "{\"address\":\"" + + fakeAddress + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + "]}]}"; ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, fakeAddress.getBytes(), - ownerKey, blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, fakeAddress.getBytes(), ownerKey, blockingStubFull); } catch (IllegalArgumentException e) { logger.info("IllegalArgumentException!"); ret = true; } Assert.assertTrue(ret); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); - - } - @Test(enabled = true, description = "Active address count is 5", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active address count is 5", + groups = {"daily", "multisig"}) public void testActiveAddress06() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee + multiSignFee; - Assert.assertTrue(PublicMethod - .sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -501,63 +672,93 @@ public void testActiveAddress06() { activePermissionKeys.add(tmpKey01); activePermissionKeys.add(tmpKey02); activePermissionKeys.add(testKey002); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"" + ",\"threshold\":10," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}]}"; - - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}]}"; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(5, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 5, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); ownerPermissionKeys.add(tmpKey01); logger.info("** trigger a normal transaction"); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); - - } - @Test(enabled = true, description = "Active address count is more than 5", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active address count is more than 5", + groups = {"daily", "multisig"}) public void testActiveAddress07() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -566,43 +767,63 @@ public void testActiveAddress07() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + contractTronDiceAddr + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":3}" + + "\"keys\":[" + + "{\"address\":\"" + + contractTronDiceAddr + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + "]}]}"; - GrpcAPI.Return response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); Assert.assertEquals( "Contract validate error : number of keys in permission should" + " not be greater than 5", response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); } - @Test(enabled = true, description = "Active address count is 0", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active address count is 0", + groups = {"daily", "multisig"}) public void testActiveAddress08() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -610,38 +831,46 @@ public void testActiveAddress08() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[]}]}"; - GrpcAPI.Return response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : key's count should be greater than 0", + Assert.assertEquals( + "Contract validate error : key's count should be greater than 0", response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); } - @Test(enabled = true, description = "Active address count is 1", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active address count is 1", + groups = {"daily", "multisig"}) public void testActiveAddress09() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee; - Assert.assertTrue(PublicMethod - .sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); @@ -651,58 +880,82 @@ public void testActiveAddress09() { List activePermissionKeys = new ArrayList<>(); ownerPermissionKeys.add(ownerKey); activePermissionKeys.add(tmpKey01); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(1, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 1, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); ownerPermissionKeys.add(witnessKey); logger.info("** trigger a normal transaction"); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); } - @Test(enabled = true, description = "Active permission count is 8", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active permission count is 8", + groups = {"daily", "multisig"}) public void testActiveAddress10() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee + multiSignFee; - Assert.assertTrue(PublicMethod - .sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -715,117 +968,227 @@ public void testActiveAddress10() { activePermissionKeys.add(tmpKey01); activePermissionKeys.add(tmpKey02); activePermissionKeys.add(testKey002); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":2147483647}]}," + + "\"active_permissions\":[" + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}," + "{\"type\":2,\"permission_name\":\"active1\",\"threshold\":5," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}," + "{\"type\":2,\"permission_name\":\"active2\",\"threshold\":7," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}," + "{\"type\":2,\"permission_name\":\"active3\",\"threshold\":9," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}," + "{\"type\":2,\"permission_name\":\"active4\",\"threshold\":10," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}," + "{\"type\":2,\"permission_name\":\"active5\",\"threshold\":11," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}," + "{\"type\":2,\"permission_name\":\"active6\",\"threshold\":10," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}," + "{\"type\":2,\"permission_name\":\"active7\",\"threshold\":11," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}]}"; PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(40, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 40, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); ownerPermissionKeys.add(tmpKey01); logger.info("** trigger a normal transaction"); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 9, ownerKey, + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 9, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); } - @Test(enabled = true, description = "Active permission count is 9", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active permission count is 9", + groups = {"daily", "multisig"}) public void testActiveAddress11() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -833,108 +1196,215 @@ public void testActiveAddress11() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":2147483647}]}," + + "\"active_permissions\":[" + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}," + "{\"type\":2,\"permission_name\":\"active1\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}," + "{\"type\":2,\"permission_name\":\"active2\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}," + "{\"type\":2,\"permission_name\":\"active3\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}," + "{\"type\":2,\"permission_name\":\"active4\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}," + "{\"type\":2,\"permission_name\":\"active5\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}," + "{\"type\":2,\"permission_name\":\"active6\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}," + "{\"type\":2,\"permission_name\":\"active7\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}," + "{\"type\":2,\"permission_name\":\"active8\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}]}"; - GrpcAPI.Return response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : active permission is too many", + Assert.assertEquals( + "Contract validate error : active permission is too many", response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); } - @Test(enabled = true, description = "Active permission count is 8, " - + "sum of weight is less than threshold", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active permission count is 8, " + "sum of weight is less than threshold", + groups = {"daily", "multisig"}) public void testActiveAddress12() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -942,85 +1412,179 @@ public void testActiveAddress12() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":2147483647}]}," + + "\"active_permissions\":[" + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}," + "{\"type\":2,\"permission_name\":\"active1\",\"threshold\":9223372036854775807," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}," + "{\"type\":2,\"permission_name\":\"active2\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}," + "{\"type\":2,\"permission_name\":\"active3\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}," + "{\"type\":2,\"permission_name\":\"active4\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}," + "{\"type\":2,\"permission_name\":\"active5\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}," + "{\"type\":2,\"permission_name\":\"active6\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}," + "{\"type\":2,\"permission_name\":\"active7\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":2}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) - + "\",\"weight\":3}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":3}" + + "]}]}"; - GrpcAPI.Return response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : sum of all key's weight should" - + " not be less than threshold in permission Active", response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Assert.assertEquals( + "Contract validate error : sum of all key's weight should" + + " not be less than threshold in permission Active", + response.getMessage().toStringUtf8()); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); } @@ -1030,11 +1594,7 @@ public void aftertest() { PublicMethod.freeResource(ownerAddress, ownerKey, foundationAddress, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign12.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign12.java index bb7da6e4..8fef6046 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign12.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign12.java @@ -17,8 +17,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSign12 extends TronBaseTest { @@ -26,10 +26,10 @@ public class MultiSign12 extends TronBaseTest { private static final long TotalSupply = 1000L; private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -43,27 +43,28 @@ public class MultiSign12 extends TronBaseTest { private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); private byte[] transferTokenContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Active type is exception condition", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active type is exception condition", + groups = {"daily", "multisig"}) public void testActiveType01() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull); + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -71,139 +72,182 @@ public void testActiveType01() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - // type = Integer.MIN_VALUE + // type = Integer.MIN_VALUE String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":-2147483648,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey2) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey2) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : active permission type is error", + Assert.assertEquals( + "Contract validate error : active permission type is error", response.getMessage().toStringUtf8()); - // type = 0 + // type = 0 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":0,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey2) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey2) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : active permission type is error", + Assert.assertEquals( + "Contract validate error : active permission type is error", response.getMessage().toStringUtf8()); - // type = -1 + // type = -1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":-1,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey2) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey2) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : active permission type is error", + Assert.assertEquals( + "Contract validate error : active permission type is error", response.getMessage().toStringUtf8()); - // type = long.min + // type = long.min accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":-9223372036854775808," + "\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey2) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey2) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : active permission type is error", + Assert.assertEquals( + "Contract validate error : active permission type is error", response.getMessage().toStringUtf8()); - // type = long.min - 1000020 + // type = long.min - 1000020 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":-9223372036855775828," + "\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey2) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey2) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : active permission type is error", + Assert.assertEquals( + "Contract validate error : active permission type is error", response.getMessage().toStringUtf8()); - // type = long.min - 1 + // type = long.min - 1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":-9223372036854775809," + "\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : active permission type is error", + Assert.assertEquals( + "Contract validate error : active permission type is error", response.getMessage().toStringUtf8()); - // type = "12a" + // type = "12a" accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":\"12a\",\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; boolean ret = false; @@ -215,16 +259,19 @@ public void testActiveType01() { ret = true; } Assert.assertTrue(ret); - // type = "" + // type = "" accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":\"\",\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; try { @@ -235,37 +282,46 @@ public void testActiveType01() { ret = true; } Assert.assertTrue(ret); - // type = + // type = accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; try { - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (com.alibaba.fastjson.JSONException e) { logger.info("JSONException !"); ret = true; } Assert.assertTrue(ret); - // type = null + // type = null accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," - + "\"active_permissions\":[{\"type\":" + null + ",\"permission_name\":\"active0\"," + + "\"active_permissions\":[{\"type\":" + + null + + ",\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; @@ -277,112 +333,141 @@ public void testActiveType01() { ret = true; } Assert.assertTrue(ret); - // type = 1 + // type = 1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":1,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : active permission type is error", + Assert.assertEquals( + "Contract validate error : active permission type is error", response.getMessage().toStringUtf8()); - // type = Long.MAX_VALUE + // type = Long.MAX_VALUE accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":9223372036854775807," + "\"permission_name\":\"active0\"," + "\"threshold\":9223372036854775807," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey2) + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey2) + "\",\"weight\":9223372036854775806}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : active permission type is error", + Assert.assertEquals( + "Contract validate error : active permission type is error", response.getMessage().toStringUtf8()); - // type = Long.MAX_VALUE + 1 + // type = Long.MAX_VALUE + 1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":9223372036854775808," + "\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey2) + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey2) + "\",\"weight\":9223372036854775806}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : active permission type is error", + Assert.assertEquals( + "Contract validate error : active permission type is error", response.getMessage().toStringUtf8()); - // type = 1.1 + // type = 1.1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":1.1,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey2) + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey2) + "\",\"weight\":9223372036854775806}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : active permission type is error", + Assert.assertEquals( + "Contract validate error : active permission type is error", response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); - } - @Test(enabled = true, description = "Active type is 2.9", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active type is 2.9", + groups = {"daily", "multisig"}) public void testActiveType02() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] ownerAddress = ecKey1.getAddress(); + byte[] ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); PublicMethod.waitProduceNextBlock(blockingStubFull); long needCoin = updateAccountPermissionFee; - PublicMethod - .sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, foundationKey, blockingStubFull); + PublicMethod.sendcoin( + ownerAddress, needCoin + 1_000_000, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -393,47 +478,62 @@ public void testActiveType02() { activePermissionKeys.add(tmpKey02); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2.9,\"permission_name\":\"active0\"," + "\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":21}" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":21}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(1, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 1, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a normal transaction"); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); } @@ -443,10 +543,7 @@ public void aftertest() { PublicMethod.freeResource(ownerAddress, ownerKey, foundationAddress, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign13.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign13.java index f406271c..a246e2e2 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign13.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign13.java @@ -16,11 +16,11 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode @@ -30,10 +30,10 @@ public class MultiSign13 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -46,36 +46,42 @@ public class MultiSign13 extends TronBaseTest { private ECKey tmpEcKey02 = new ECKey(Utils.getRandom()); private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] transferTokenContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Witness permission_name is witness", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness permission_name is witness", + groups = {"daily", "multisig"}) public void testWitnessName01() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); long needCoin = updateAccountPermissionFee * 2; - PublicMethod - .sendcoin(ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 1000000000, 0, 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000000, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -85,76 +91,101 @@ public void testWitnessName01() { ownerPermissionKeys.add(ownerKey); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(foundationKey); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); - PublicMethodForMultiSign - .recoverWitnessPermission(ownerKey, ownerPermissionKeys, blockingStubFull); + PublicMethodForMultiSign.recoverWitnessPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - PublicMethod - .unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Witness permission_name is witness12", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness permission_name is witness12", + groups = {"daily", "multisig"}) public void testWitnessName02() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); long needCoin = updateAccountPermissionFee * 2; - PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 1000000000L, 0, 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000000L, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -164,77 +195,102 @@ public void testWitnessName02() { ownerPermissionKeys.add(ownerKey); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness12\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(foundationKey); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission().getKeysCount()); - - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission())); - - PublicMethodForMultiSign - .recoverWitnessPermission(ownerKey, ownerPermissionKeys, blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() + .getKeysCount()); + + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); + + PublicMethodForMultiSign.recoverWitnessPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - PublicMethod - .unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Witness permission_name is \"123\"", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness permission_name is \"123\"", + groups = {"daily", "multisig"}) public void testWitnessName03() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); long needCoin = updateAccountPermissionFee * 2; - PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 1000000000, 0, 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000000, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -244,77 +300,102 @@ public void testWitnessName03() { ownerPermissionKeys.add(ownerKey); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"123\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(foundationKey); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission().getKeysCount()); - - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission())); - - PublicMethodForMultiSign - .recoverWitnessPermission(ownerKey, ownerPermissionKeys, blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() + .getKeysCount()); + + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); + + PublicMethodForMultiSign.recoverWitnessPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - PublicMethod - .unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Witness permission_name is \"\"", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness permission_name is \"\"", + groups = {"daily", "multisig"}) public void testWitnessName04() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); long needCoin = updateAccountPermissionFee * 2; - PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 1000000000, 0, 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000000, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -324,74 +405,99 @@ public void testWitnessName04() { ownerPermissionKeys.add(ownerKey); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(foundationKey); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission().getKeysCount()); - - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission())); - - PublicMethodForMultiSign - .recoverWitnessPermission(ownerKey, ownerPermissionKeys, blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() + .getKeysCount()); + + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); + + PublicMethodForMultiSign.recoverWitnessPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - PublicMethod - .unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); - + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Witness permission_name is null", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness permission_name is null", + groups = {"daily", "multisig"}) public void testWitnessName05() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); - PublicMethod.sendcoin(ownerAddress, 1_000000, foundationAddress, foundationKey, blockingStubFull); - - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 1000000000, 0, 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, 1_000000, foundationAddress, foundationKey, blockingStubFull); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000000, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -399,54 +505,68 @@ public void testWitnessName05() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," - + "\"witness_permission\":{\"type\":1,\"permission_name\":" + null + + "\"witness_permission\":{\"type\":1,\"permission_name\":" + + null + ",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; boolean ret = false; try { - GrpcAPI.Return response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NullPointerException e) { logger.info("Expected NullPointerException!"); ret = true; } Assert.assertTrue(ret); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); - PublicMethod - .unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); - + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Witness doesn't have permission_name", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness doesn't have permission_name", + groups = {"daily", "multisig"}) public void testWitnessName06() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); long needCoin = updateAccountPermissionFee * 2; - PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 1000000000, 0, 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000000, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -454,75 +574,100 @@ public void testWitnessName06() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(foundationKey); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); - PublicMethodForMultiSign - .recoverWitnessPermission(ownerKey, ownerPermissionKeys, blockingStubFull); + PublicMethodForMultiSign.recoverWitnessPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - PublicMethod - .unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); - + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Witness permission_name is 123", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness permission_name is 123", + groups = {"daily", "multisig"}) public void testWitnessName07() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); long needCoin = updateAccountPermissionFee * 2; - PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 1000000000, 0, 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000000, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -530,75 +675,101 @@ public void testWitnessName07() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"permission_name\":123,\"type\":1," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(foundationKey); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); - PublicMethodForMultiSign - .recoverWitnessPermission(ownerKey, ownerPermissionKeys, blockingStubFull); + PublicMethodForMultiSign.recoverWitnessPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - PublicMethod - .unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Witness permission_name is 0.1", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness permission_name is 0.1", + groups = {"daily", "multisig"}) public void testWitnessName08() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); long needCoin = updateAccountPermissionFee * 2; - PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 1000000000, 0, 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000000, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -606,77 +777,102 @@ public void testWitnessName08() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"permission_name\":\"0.1\",\"type\":1," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(foundationKey); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission().getKeysCount()); - - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission())); - - PublicMethodForMultiSign - .recoverWitnessPermission(ownerKey, ownerPermissionKeys, blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() + .getKeysCount()); + + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); + + PublicMethodForMultiSign.recoverWitnessPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - PublicMethod - .unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Witness permission_name length is 32", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness permission_name length is 32", + groups = {"daily", "multisig"}) public void testWitnessName09() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); long needCoin = updateAccountPermissionFee * 2; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin + 1000000, foundationAddress, - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 100000000L, 0, 0, + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1000000, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000L, + 0, + 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -685,118 +881,137 @@ public void testWitnessName09() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":" + "{\"permission_name\":\"abcdefghijklmnopqrstuvwxyzabcdef\",\"type\":1," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(foundationKey); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); - PublicMethodForMultiSign - .recoverWitnessPermission(ownerKey, ownerPermissionKeys, blockingStubFull); + PublicMethodForMultiSign.recoverWitnessPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - PublicMethod - .unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); - + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); } - - @Test(enabled = true, description = "Witness permission_name length is 33", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness permission_name length is 33", + groups = {"daily", "multisig"}) public void testWitnessName10() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, 1000000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, 1000000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":" + "{\"permission_name\":\"abcdefghijklmnopqrstuvwxyzabcdefg\",\"type\":1," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's name is too long", + Assert.assertEquals( + "Contract validate error : permission's name is too long", response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); - } @AfterMethod public void aftertest() { PublicMethod.freeResource(ownerAddress, ownerKey, foundationAddress, blockingStubFull); - PublicMethod.unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign14.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign14.java index cf96b22b..fabff172 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign14.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign14.java @@ -16,19 +16,20 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode -public class MultiSign14 extends TronBaseTest { private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); +public class MultiSign14 extends TronBaseTest { + private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -41,30 +42,37 @@ public class MultiSign14 extends TronBaseTest { private final byte[] witnessAdd private ECKey tmpEcKey02 = new ECKey(Utils.getRandom()); private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Witness threshold is exception condition", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness threshold is exception condition", + groups = {"daily", "multisig"}) public void testWitnessThreshold01() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); - PublicMethod.sendcoin(ownerAddress, 1_000000, foundationAddress, foundationKey, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 1000000000, 0, 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, 1_000000, foundationAddress, foundationKey, blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000000, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -72,115 +80,149 @@ public void testWitnessThreshold01() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - // theshold = Integer.MIN_VALUE + // theshold = Integer.MIN_VALUE String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," + "\"threshold\":-2147483648,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's" - + " threshold should be greater than 0", + Assert.assertEquals( + "Contract validate error : permission's" + " threshold should be greater than 0", response.getMessage().toStringUtf8()); - // theshold = 0 + // theshold = 0 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," + "\"threshold\":0,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's" - + " threshold should be greater than 0", + Assert.assertEquals( + "Contract validate error : permission's" + " threshold should be greater than 0", response.getMessage().toStringUtf8()); - // theshold = -1 + // theshold = -1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," + "\"threshold\":-1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's" - + " threshold should be greater than 0", + Assert.assertEquals( + "Contract validate error : permission's" + " threshold should be greater than 0", response.getMessage().toStringUtf8()); - // theshold = long.min + // theshold = long.min accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," + "\"threshold\":-9223372036854775808,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's" - + " threshold should be greater than 0", + Assert.assertEquals( + "Contract validate error : permission's" + " threshold should be greater than 0", response.getMessage().toStringUtf8()); - // theshold = long.min - 1000020 + // theshold = long.min - 1000020 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," + "\"threshold\":-9223372036855775828,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; boolean ret = false; try { @@ -191,20 +233,26 @@ public void testWitnessThreshold01() { ret = true; } Assert.assertTrue(ret); - // theshold = long.min - 1 + // theshold = long.min - 1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," + "\"threshold\":-9223372036854775809,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; try { @@ -215,21 +263,27 @@ public void testWitnessThreshold01() { ret = true; } Assert.assertTrue(ret); - // theshold = "12a" + // theshold = "12a" accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," + "\"threshold\":\"12a\",\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; @@ -241,20 +295,26 @@ public void testWitnessThreshold01() { ret = true; } Assert.assertTrue(ret); - // theshold = "" + // theshold = "" accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," + "\"threshold\":\"\",\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; @@ -266,20 +326,26 @@ public void testWitnessThreshold01() { ret = true; } Assert.assertTrue(ret); - // theshold = + // theshold = accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," + "\"threshold\":,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; try { @@ -290,20 +356,28 @@ public void testWitnessThreshold01() { ret = true; } Assert.assertTrue(ret); - // theshold = null + // theshold = null accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," - + "\"threshold\":" + null + ",\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "\"threshold\":" + + null + + ",\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; @@ -315,43 +389,57 @@ public void testWitnessThreshold01() { ret = true; } Assert.assertTrue(ret); - // theshold = Long.MAX_VALUE < sum(weight) + // theshold = Long.MAX_VALUE < sum(weight) accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," + "\"threshold\":9223372036854775807,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":9223372036854775806}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : sum of all key's weight should not be" + Assert.assertEquals( + "Contract validate error : sum of all key's weight should not be" + " less than threshold in permission Witness", response.getMessage().toStringUtf8()); - // theshold = Long.MAX_VALUE + 1 > sum(weight) + // theshold = Long.MAX_VALUE + 1 > sum(weight) accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," + "\"threshold\":9223372036854775808,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":9223372036854775806}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; @@ -363,20 +451,26 @@ public void testWitnessThreshold01() { ret = true; } Assert.assertTrue(ret); - // theshold = 1.1 + // theshold = 1.1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," + "\"threshold\":1.1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":9223372036854775806}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; @@ -388,30 +482,37 @@ public void testWitnessThreshold01() { ret = true; } Assert.assertTrue(ret); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); - Assert.assertTrue(PublicMethod - .unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull)); - + Assert.assertTrue( + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull)); } - @Test(enabled = true, description = "Witness threshold is 1", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness threshold is 1", + groups = {"daily", "multisig"}) public void testWitnessThreshold02() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); long needCoin = updateAccountPermissionFee * 2; - PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -419,74 +520,98 @@ public void testWitnessThreshold02() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(foundationKey); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission().getKeysCount()); - - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission())); - - PublicMethodForMultiSign - .recoverWitnessPermission(ownerKey, ownerPermissionKeys, blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() + .getKeysCount()); + + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); + + PublicMethodForMultiSign.recoverWitnessPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - PublicMethod - .unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); - + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Witness threshold is more than sum of weight", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness threshold is more than sum of weight", + groups = {"daily", "multisig"}) public void testWitnessThreshold03() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); - PublicMethod.sendcoin(ownerAddress, 1_000000, foundationAddress, foundationKey, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 1000000000, 0, 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, 1_000000, foundationAddress, foundationKey, blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000000, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -494,75 +619,98 @@ public void testWitnessThreshold03() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - // threshold > sum(weight) + // threshold > sum(weight) String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," + "\"threshold\":4294967299,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":214748364}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : sum of all key's weight should not be" + Assert.assertEquals( + "Contract validate error : sum of all key's weight should not be" + " less than threshold in permission Witness", response.getMessage().toStringUtf8()); - // threshold = Integer.MAX_VALUE > sum(weight) + // threshold = Integer.MAX_VALUE > sum(weight) accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," + "\"threshold\":2147483647,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":214748364}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : sum of all key's weight " + Assert.assertEquals( + "Contract validate error : sum of all key's weight " + "should not be less than threshold in permission Witness", response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); - PublicMethod - .unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Witness threshold is Long.MAX_VALUE", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness threshold is Long.MAX_VALUE", + groups = {"daily", "multisig"}) public void testWitnessThreshold04() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); long needCoin = updateAccountPermissionFee * 2; - PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -571,72 +719,85 @@ public void testWitnessThreshold04() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," + "\"threshold\":9223372036854775807,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":9223372036854775807}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(foundationKey); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission().getKeysCount()); - - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission())); - - PublicMethodForMultiSign - .recoverWitnessPermission(ownerKey, ownerPermissionKeys, blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() + .getKeysCount()); + + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); + + PublicMethodForMultiSign.recoverWitnessPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - PublicMethod - .unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); - + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); } @AfterMethod public void aftertest() { PublicMethod.freeResource(ownerAddress, ownerKey, foundationAddress, blockingStubFull); - PublicMethod.unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign15.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign15.java index 7e80afd2..aedac4c2 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign15.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign15.java @@ -16,11 +16,11 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode @@ -30,10 +30,10 @@ public class MultiSign15 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -46,35 +46,41 @@ public class MultiSign15 extends TronBaseTest { private ECKey tmpEcKey02 = new ECKey(Utils.getRandom()); private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] transferTokenContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull); + public void beforeClass() { + PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, testKey002, blockingStubFull); } - @Test(enabled = true, description = "Witness doesn't have parent_id", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness doesn't have parent_id", + groups = {"daily", "multisig"}) public void testWitnessParent01() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); long needCoin = updateAccountPermissionFee * 2; PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, testKey002, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, ByteString.copyFrom(ownerAddress), - testKey002, blockingStubFull)); + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -84,72 +90,94 @@ public void testWitnessParent01() { ownerPermissionKeys.add(ownerKey); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(testKey002); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission().getKeysCount()); - - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission())); - - PublicMethodForMultiSign - .recoverWitnessPermission(ownerKey, ownerPermissionKeys, blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() + .getKeysCount()); + + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); + + PublicMethodForMultiSign.recoverWitnessPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - PublicMethod - .unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); + PublicMethod.unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Witness parent_id is exception condition", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness parent_id is exception condition", + groups = {"daily", "multisig"}) public void testWitnessParent02() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, ByteString.copyFrom(ownerAddress), - testKey002, blockingStubFull)); + testKey002, + blockingStubFull)); PublicMethod.sendcoin(ownerAddress, 1_000000, foundationAddress, testKey002, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -157,322 +185,423 @@ public void testWitnessParent02() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - // parent_id = "123" + // parent_id = "123" String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"parent_id\":\"123\",\"type\":1," + "\"permission_name\":\"witness\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = 123 + // parent_id = 123 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"parent_id\":123,\"type\":1," + "\"permission_name\":\"witness\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = "abc" + // parent_id = "abc" accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"parent_id\":\"abc\",\"type\":1," + "\"permission_name\":\"witness\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; boolean ret = false; try { - PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NumberFormatException e) { logger.info("Expected NumberFormatException!"); ret = true; } Assert.assertTrue(ret); - // parent_id = "" + // parent_id = "" accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"parent_id\":\"\",\"type\":1," + "\"permission_name\":\"witness\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; try { - PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NullPointerException e) { logger.info("Expected NullPointerException!"); ret = true; } Assert.assertTrue(ret); - // parent_id = null + // parent_id = null accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," - + "\"witness_permission\":{\"parent_id\":" + null + ",\"type\":1," + + "\"witness_permission\":{\"parent_id\":" + + null + + ",\"type\":1," + "\"permission_name\":\"witness\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; try { - PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NullPointerException e) { logger.info("Expected NullPointerException!"); ret = true; } Assert.assertTrue(ret); - // parent_id = 1 + // parent_id = 1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"parent_id\":1,\"type\":1," + "\"permission_name\":\"witness\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = 2 + // parent_id = 2 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"parent_id\":2,\"type\":1," + "\"permission_name\":\"witness\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = 3 + // parent_id = 3 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"parent_id\":3,\"type\":1," + "\"permission_name\":\"witness\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = -1 + // parent_id = -1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"parent_id\":-1,\"type\":1," + "\"permission_name\":\"witness\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = Integer.MAX_VALUE + // parent_id = Integer.MAX_VALUE accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"parent_id\":2147483647,\"type\":1," + "\"permission_name\":\"witness\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = Integer.MAX_VALUE +1 + // parent_id = Integer.MAX_VALUE +1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"parent_id\":2147483648,\"type\":1," + "\"permission_name\":\"witness\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = Integer.MIN_VALUE + // parent_id = Integer.MIN_VALUE accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"parent_id\":-2147483648,\"type\":1," + "\"permission_name\":\"witness\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - // parent_id = Integer.MIN_VALUE -1 + // parent_id = Integer.MIN_VALUE -1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"parent_id\":-2147483649,\"type\":1," + "\"permission_name\":\"witness\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : permission's parent should be owner", + Assert.assertEquals( + "Contract validate error : permission's parent should be owner", response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); - PublicMethod - .unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); - + PublicMethod.unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Witness parent_id is 0", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness parent_id is 0", + groups = {"daily", "multisig"}) public void testWitnessParent03() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); long needCoin = updateAccountPermissionFee * 2; PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, testKey002, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, ByteString.copyFrom(ownerAddress), - testKey002, blockingStubFull)); + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -482,62 +611,76 @@ public void testWitnessParent03() { ownerPermissionKeys.add(ownerKey); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"parent_id\":0,\"type\":1," + "\"permission_name\":\"witness\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(testKey002); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); - PublicMethodForMultiSign - .recoverWitnessPermission(ownerKey, ownerPermissionKeys, blockingStubFull); + PublicMethodForMultiSign.recoverWitnessPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - PublicMethod - .unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); - + PublicMethod.unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); } @AfterMethod @@ -546,10 +689,7 @@ public void aftertest() { PublicMethod.unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign16.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign16.java index 8713faf1..86bd7790 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign16.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign16.java @@ -18,15 +18,16 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class MultiSign16 extends TronBaseTest { private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); +public class MultiSign16 extends TronBaseTest { + private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -39,26 +40,35 @@ public class MultiSign16 extends TronBaseTest { private final byte[] witnessAdd private ECKey tmpEcKey02 = new ECKey(Utils.getRandom()); private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Witness weight is exception condition", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness weight is exception condition", + groups = {"daily", "multisig"}) public void testWitnessWeight01() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); - PublicMethod.sendcoin(ownerAddress, 1_000000, foundationAddress, foundationKey, blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, - ByteString.copyFrom(ownerAddress), foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, 1_000000, foundationAddress, foundationKey, blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -66,255 +76,393 @@ public void testWitnessWeight01() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - // weight = Integer.MIN_VALUE + // weight = Integer.MIN_VALUE String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," - + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + "{\"address\":\"" - + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":-2147483647}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}]}," + + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":-2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - - GrpcAPI.Return response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : key's weight" + " should be greater than 0", + Assert.assertEquals( + "Contract validate error : key's weight" + " should be greater than 0", response.getMessage().toStringUtf8()); - // weight = 0 + // weight = 0 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," - + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + "{\"address\":\"" - + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":0}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}]}," + + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":0}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : key's weight" + " should be greater than 0", + Assert.assertEquals( + "Contract validate error : key's weight" + " should be greater than 0", response.getMessage().toStringUtf8()); - // weight = -1 + // weight = -1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," - + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + "{\"address\":\"" - + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":-1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}]}," + + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":-1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : key's weight" + " should be greater than 0", + Assert.assertEquals( + "Contract validate error : key's weight" + " should be greater than 0", response.getMessage().toStringUtf8()); - // weight = long.min + // weight = long.min accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," - + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + "{\"address\":\"" - + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":-9223372036854775808}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}]}," + + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":-9223372036854775808}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : key's weight" + " should be greater than 0", + Assert.assertEquals( + "Contract validate error : key's weight" + " should be greater than 0", response.getMessage().toStringUtf8()); - // weight = long.min - 1000020 + // weight = long.min - 1000020 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," - + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + "{\"address\":\"" - + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":-9223372036855775828}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}]}," + + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":-9223372036855775828}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; boolean ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NumberFormatException e) { logger.info("NumberFormatException !"); ret = true; } Assert.assertTrue(ret); - // weight = "12a" + // weight = "12a" accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," - + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + "{\"address\":\"" - + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":\"12a\"}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}]}," + + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":\"12a\"}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NumberFormatException e) { logger.info("NumberFormatException !"); ret = true; } Assert.assertTrue(ret); - // weight = "" + // weight = "" accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," - + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + "{\"address\":\"" - + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":\"\"}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}]}," + + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":\"\"}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NumberFormatException e) { logger.info("NumberFormatException !"); ret = true; } Assert.assertTrue(ret); - // weight = + // weight = accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," - + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + "{\"address\":\"" - + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}]}," + + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (com.alibaba.fastjson.JSONException e) { logger.info("JSONException !"); ret = true; } Assert.assertTrue(ret); - // weight = null + // weight = null accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," - + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + "{\"address\":\"" - + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":" + null + "}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}]}," + + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":" + + null + + "}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NumberFormatException e) { logger.info("NumberFormatException !"); ret = true; } Assert.assertTrue(ret); - // Long.MAX_VALUE + 1 + // Long.MAX_VALUE + 1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," - + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + "{\"address\":\"" - + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":9223372036854775808}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}]}," + + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":9223372036854775808}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NumberFormatException e) { logger.info("NumberFormatException !"); ret = true; } Assert.assertTrue(ret); - // weight = 1.1 + // weight = 1.1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," - + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + "{\"address\":\"" - + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1.1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}]}," + + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1.1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NumberFormatException e) { logger.info("NumberFormatException !"); ret = true; } Assert.assertTrue(ret); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); Assert.assertTrue( - PublicMethod.unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull)); - + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull)); } - @Test(enabled = true, description = "Witness weight is 1", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness weight is 1", + groups = {"daily", "multisig"}) public void testWitnessWeight02() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); long needCoin = updateAccountPermissionFee * 2; - PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, - ByteString.copyFrom(ownerAddress), foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -322,66 +470,101 @@ public void testWitnessWeight02() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," - + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + "{\"address\":\"" - + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}]}," + + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.add(foundationKey); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethodForMultiSign - .recoverWitnessPermission(ownerKey, ownerPermissionKeys, blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + PublicMethodForMultiSign.recoverWitnessPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - PublicMethod.unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Witness weight is Integer.MAX_VALUE", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness weight is Integer.MAX_VALUE", + groups = {"daily", "multisig"}) public void testWitnessWeight03() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); long needCoin = updateAccountPermissionFee * 2; - PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, - ByteString.copyFrom(ownerAddress), foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -389,65 +572,99 @@ public void testWitnessWeight03() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," - + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + "{\"address\":\"" - + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":2147483647}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}]}," + + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2147483647}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.add(foundationKey); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); - PublicMethodForMultiSign - .recoverWitnessPermission(ownerKey, ownerPermissionKeys, blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + PublicMethodForMultiSign.recoverWitnessPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - PublicMethod.unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); - + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Witness weight is Long.MAX_VALUE", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness weight is Long.MAX_VALUE", + groups = {"daily", "multisig"}) public void testWitnessWeight04() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); long needCoin = updateAccountPermissionFee * 2; - PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, - ByteString.copyFrom(ownerAddress), foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -455,65 +672,85 @@ public void testWitnessWeight04() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"threshold\":9223372036854775807,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":9223372036854775807}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.add(foundationKey); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); - PublicMethodForMultiSign - .recoverWitnessPermission(ownerKey, ownerPermissionKeys, blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + PublicMethodForMultiSign.recoverWitnessPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - PublicMethod.unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); } @AfterMethod public void aftertest() { PublicMethod.freeResource(ownerAddress, ownerKey, foundationAddress, blockingStubFull); - PublicMethod.unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign17.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign17.java index 516b31d8..7f54b34a 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign17.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign17.java @@ -18,17 +18,17 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSign17 extends TronBaseTest { private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); private final String contractTronDiceAddr = "TMYcx6eoRXnePKT1jVn25ZNeMNJ6828HWk"; - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -41,31 +41,36 @@ public class MultiSign17 extends TronBaseTest { private ECKey tmpEcKey02 = new ECKey(Utils.getRandom()); private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Witness address is witness", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness address is witness", + groups = {"daily", "multisig"}) public void testWitnessAddress01() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); long needCoin = updateAccountPermissionFee * 2; PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, testKey002, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, ByteString.copyFrom(ownerAddress), - testKey002, blockingStubFull)); + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -73,75 +78,97 @@ public void testWitnessAddress01() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness12\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(testKey002); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission().getKeysCount()); - - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission())); - - PublicMethodForMultiSign - .recoverWitnessPermission(ownerKey, ownerPermissionKeys, blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() + .getKeysCount()); + + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); + + PublicMethodForMultiSign.recoverWitnessPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - PublicMethod - .unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); - + PublicMethod.unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Witness address is contract", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness address is contract", + groups = {"daily", "multisig"}) public void testWitnessAddress02() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); long needCoin = updateAccountPermissionFee * 2; PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, testKey002, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, ByteString.copyFrom(ownerAddress), - testKey002, blockingStubFull)); + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -149,75 +176,98 @@ public void testWitnessAddress02() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness12\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + contractTronDiceAddr + "\",\"weight\":1}]}," + + "{\"address\":\"" + + contractTronDiceAddr + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(testKey002); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission().getKeysCount()); - - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() + .getKeysCount()); + + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethodForMultiSign - .recoverWitnessPermission(ownerKey, ownerPermissionKeys, blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + PublicMethodForMultiSign.recoverWitnessPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - PublicMethod - .unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); - + PublicMethod.unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Witness address is inactive address", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness address is inactive address", + groups = {"daily", "multisig"}) public void testWitnessAddress03() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); long needCoin = updateAccountPermissionFee * 2; PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, testKey002, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, ByteString.copyFrom(ownerAddress), - testKey002, blockingStubFull)); + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -225,75 +275,98 @@ public void testWitnessAddress03() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness12\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(testKey002); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission().getKeysCount()); - - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission())); - - PublicMethodForMultiSign - .recoverWitnessPermission(ownerKey, ownerPermissionKeys, blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() + .getKeysCount()); + + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); + + PublicMethodForMultiSign.recoverWitnessPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - PublicMethod - .unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); - + PublicMethod.unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Witness address is owner_address", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness address is owner_address", + groups = {"daily", "multisig"}) public void testWitnessAddress04() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); long needCoin = updateAccountPermissionFee * 2; PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, testKey002, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, ByteString.copyFrom(ownerAddress), - testKey002, blockingStubFull)); + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -303,74 +376,97 @@ public void testWitnessAddress04() { ownerPermissionKeys.add(ownerKey); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness12\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(testKey002); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); - PublicMethodForMultiSign - .recoverWitnessPermission(ownerKey, ownerPermissionKeys, blockingStubFull); + PublicMethodForMultiSign.recoverWitnessPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - PublicMethod - .unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); - + PublicMethod.unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Witness address is exception condition", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness address is exception condition", + groups = {"daily", "multisig"}) public void testWitnessAddress05() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); PublicMethod.sendcoin(ownerAddress, 1_000000, foundationAddress, testKey002, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, ByteString.copyFrom(ownerAddress), - testKey002, blockingStubFull)); + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -378,121 +474,157 @@ public void testWitnessAddress05() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - // address = owner_address more than once + // address = owner_address more than once String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness12\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : Witness permission's key count should be 1", + Assert.assertEquals( + "Contract validate error : Witness permission's key count should be 1", response.getMessage().toStringUtf8()); - // address = not exist + // address = not exist String fakeAddress = "THph9K2M2nLvkianrMGswRhz5hjSA9fuH1"; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness12\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + fakeAddress + "\",\"weight\":1}]}," + + "{\"address\":\"" + + fakeAddress + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; boolean ret = false; try { - PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NullPointerException e) { logger.info("Expected NullPointerException!"); ret = true; } Assert.assertTrue(ret); - // address = long address + // address = long address fakeAddress = "TR3FAbhiSeP7kSh39RjGYpwCqfMDHPMhX4d121"; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness12\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + fakeAddress + "\",\"weight\":1}]}," + + "{\"address\":\"" + + fakeAddress + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; try { - PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NullPointerException e) { logger.info("Expected NullPointerException!"); ret = true; } Assert.assertTrue(ret); - // address = short address + // address = short address fakeAddress = "THph9K2M2nLvkianrMGswRhz5hj"; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness12\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + fakeAddress + "\",\"weight\":1}]}," + + "{\"address\":\"" + + fakeAddress + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; try { - PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); } catch (NullPointerException e) { logger.info("Expected NullPointerException!"); ret = true; } Assert.assertTrue(ret); - // address = + // address = fakeAddress = ""; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness12\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + fakeAddress + "\",\"weight\":1}]}," + + "{\"address\":\"" + + fakeAddress + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; try { @@ -504,21 +636,28 @@ public void testWitnessAddress05() { } Assert.assertTrue(ret); - // address = null + // address = null fakeAddress = null; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness12\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + fakeAddress + "\",\"weight\":1}]}," + + "{\"address\":\"" + + fakeAddress + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; @@ -531,21 +670,28 @@ public void testWitnessAddress05() { } Assert.assertTrue(ret); - // address = "1.1" + // address = "1.1" fakeAddress = "1.1"; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness12\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + fakeAddress + "\",\"weight\":1}]}," + + "{\"address\":\"" + + fakeAddress + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; @@ -558,27 +704,32 @@ public void testWitnessAddress05() { } Assert.assertTrue(ret); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); - PublicMethod - .unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); + PublicMethod.unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Witness address account is 5", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness address account is 5", + groups = {"daily", "multisig"}) public void testWitnessAddress06() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); PublicMethod.sendcoin(ownerAddress, 1_000000, foundationAddress, testKey002, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, ByteString.copyFrom(ownerAddress), - testKey002, blockingStubFull)); + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -586,52 +737,73 @@ public void testWitnessAddress06() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness12\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : Witness permission's key count should be 1", + Assert.assertEquals( + "Contract validate error : Witness permission's key count should be 1", response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); - PublicMethod - .unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); - + PublicMethod.unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Witness address account is 0", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness address account is 0", + groups = {"daily", "multisig"}) public void testWitnessAddress07() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); PublicMethod.sendcoin(ownerAddress, 1_000000, foundationAddress, testKey002, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, ByteString.copyFrom(ownerAddress), - testKey002, blockingStubFull)); + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -639,31 +811,36 @@ public void testWitnessAddress07() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness12\"," + "\"threshold\":1,\"keys\":[]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : key's count should be greater than 0", + Assert.assertEquals( + "Contract validate error : key's count should be greater than 0", response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); - PublicMethod - .unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); + PublicMethod.unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); } @AfterMethod @@ -672,10 +849,7 @@ public void aftertest() { PublicMethod.unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign18.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign18.java index d5039698..b1354145 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign18.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign18.java @@ -18,8 +18,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSign18 extends TronBaseTest { @@ -28,10 +28,10 @@ public class MultiSign18 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -45,18 +45,19 @@ public class MultiSign18 extends TronBaseTest { private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); private byte[] transferTokenContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Witness type is 1", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness type is 1", + groups = {"daily", "multisig"}) public void testWitnessType01() { // type = 1 ownerKey = witnessKey; @@ -64,13 +65,17 @@ public void testWitnessType01() { long needCoin = updateAccountPermissionFee * 2; PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, testKey002, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, ByteString.copyFrom(ownerAddress), - testKey002, blockingStubFull)); + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -78,73 +83,96 @@ public void testWitnessType01() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(testKey002); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); - PublicMethodForMultiSign - .recoverWitnessPermission(ownerKey, ownerPermissionKeys, blockingStubFull); + PublicMethodForMultiSign.recoverWitnessPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - PublicMethod - .unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); + PublicMethod.unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Witness type is exception condition", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness type is exception condition", + groups = {"daily", "multisig"}) public void testWitnessType02() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); PublicMethod.sendcoin(ownerAddress, 1_000000, foundationAddress, testKey002, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, ByteString.copyFrom(ownerAddress), - testKey002, blockingStubFull)); + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -152,124 +180,170 @@ public void testWitnessType02() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - // type = 2 + // type = 2 String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":2,\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : witness permission type is error", + Assert.assertEquals( + "Contract validate error : witness permission type is error", response.getMessage().toStringUtf8()); - // type = 0 + // type = 0 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":0,\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : witness permission type is error", + Assert.assertEquals( + "Contract validate error : witness permission type is error", response.getMessage().toStringUtf8()); - // type = -1 + // type = -1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":-1,\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : witness permission type is error", + Assert.assertEquals( + "Contract validate error : witness permission type is error", response.getMessage().toStringUtf8()); - // type = long.min + // type = long.min accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":-9223372036854775808,\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : witness permission type is error", + Assert.assertEquals( + "Contract validate error : witness permission type is error", response.getMessage().toStringUtf8()); - // type = long.min - 1000020 + // type = long.min - 1000020 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":-9223372036855775828,\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : witness permission type is error", + Assert.assertEquals( + "Contract validate error : witness permission type is error", response.getMessage().toStringUtf8()); - // type = "12a" + // type = "12a" accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":\"12a\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; boolean ret = false; @@ -281,19 +355,25 @@ public void testWitnessType02() { ret = true; } Assert.assertTrue(ret); - // type = "" + // type = "" accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":\"\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; try { @@ -304,19 +384,25 @@ public void testWitnessType02() { ret = true; } Assert.assertTrue(ret); - // type = + // type = accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":,\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; @@ -328,19 +414,27 @@ public void testWitnessType02() { ret = true; } Assert.assertTrue(ret); - // type = null + // type = null accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," - + "\"witness_permission\":{\"type\":" + null + ",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "\"witness_permission\":{\"type\":" + + null + + ",\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; @@ -352,137 +446,182 @@ public void testWitnessType02() { ret = true; } Assert.assertTrue(ret); - // type = Integer.MAX_VALUE + // type = Integer.MAX_VALUE accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":2147483647,\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : witness permission type is error", + Assert.assertEquals( + "Contract validate error : witness permission type is error", response.getMessage().toStringUtf8()); - // type = Long.MAX_VALUE + // type = Long.MAX_VALUE accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":9223372036854775807,\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : witness permission type is error", + Assert.assertEquals( + "Contract validate error : witness permission type is error", response.getMessage().toStringUtf8()); - // type = long.MAX_VALUE + 1 + // type = long.MAX_VALUE + 1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":9223372036854775808,\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : witness permission type is error", + Assert.assertEquals( + "Contract validate error : witness permission type is error", response.getMessage().toStringUtf8()); - // type = long.min - 1 + // type = long.min - 1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":-9223372036854775809,\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : witness permission type is error", + Assert.assertEquals( + "Contract validate error : witness permission type is error", response.getMessage().toStringUtf8()); - // type = Long.MAX_VALUE + 1 + // type = Long.MAX_VALUE + 1 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":9223372036854775808,\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : witness permission type is error", + Assert.assertEquals( + "Contract validate error : witness permission type is error", response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); - PublicMethod - .unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); + PublicMethod.unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Witness type is 1.5", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness type is 1.5", + groups = {"daily", "multisig"}) public void testWitnessType03() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); long needCoin = updateAccountPermissionFee * 2; PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, testKey002, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, ByteString.copyFrom(ownerAddress), - testKey002, blockingStubFull)); + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -491,60 +630,75 @@ public void testWitnessType03() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey002) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey002) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1.5,\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(testKey002); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); - PublicMethodForMultiSign - .recoverWitnessPermission(ownerKey, ownerPermissionKeys, blockingStubFull); + PublicMethodForMultiSign.recoverWitnessPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - PublicMethod - .unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); - + PublicMethod.unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); } @AfterMethod @@ -553,10 +707,7 @@ public void aftertest() { PublicMethod.unFreezeBalance(foundationAddress, testKey002, 0, ownerAddress, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign19.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign19.java index 07c226be..94c89d0d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign19.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign19.java @@ -18,18 +18,18 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSign19 extends TronBaseTest { public static final String DEFAULT_OPERATION = "7fff1fc0033e0000000000000000000000000000000000000000000000000000"; private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -42,29 +42,34 @@ public class MultiSign19 extends TronBaseTest { private ECKey tmpEcKey02 = new ECKey(Utils.getRandom()); private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Active operation is ContractType.TransferContract_VALUE", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active operation is ContractType.TransferContract_VALUE", + groups = {"daily", "multisig"}) public void testActiveOperations01() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, + needCoin + 1_000_000, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); @@ -78,26 +83,39 @@ public void testActiveOperations01() { activePermissionKeys2.add(witnessKey); Integer[] ints = {ContractType.TransferContract_VALUE}; - String operationsTransfer = PublicMethodForMultiSign.getOperations(ints); + String operationsTransfer = PublicMethodForMultiSign.getOperations(ints); Integer[] ints2 = {ContractType.TransferAssetContract_VALUE}; - String operationsTransferAsset = PublicMethodForMultiSign.getOperations(ints2); - String accountPermissionJson = + String operationsTransferAsset = PublicMethodForMultiSign.getOperations(ints2); + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"" + operationsTransfer + "\"," + + "\"operations\":\"" + + operationsTransfer + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"" + operationsTransferAsset + "\"," + + "\"operations\":\"" + + operationsTransferAsset + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + "]}]}"; Assert.assertTrue( - PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, 0, + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + 0, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -105,47 +123,67 @@ public void testActiveOperations01() { ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign - .getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a normal transaction"); - Assert.assertFalse(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 3, ownerKey, + Assert.assertFalse( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 3, + ownerKey, blockingStubFull, activePermissionKeys2.toArray(new String[activePermissionKeys2.size()]))); - Assert.assertFalse(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertFalse( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys2.toArray(new String[activePermissionKeys2.size()]))); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); - - } - @Test(enabled = true, description = "Active operation is" - + " 0000000000000000000000000000000000000000000000000000000000000000", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Active operation is" + + " 0000000000000000000000000000000000000000000000000000000000000000", + groups = {"daily", "multisig"}) public void testActiveOperations02() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); @@ -153,11 +191,11 @@ public void testActiveOperations02() { long needCoin = updateAccountPermissionFee; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin + 1000000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1000000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -166,19 +204,26 @@ public void testActiveOperations02() { List activePermissionKeys = new ArrayList<>(); ownerPermissionKeys.add(ownerKey); activePermissionKeys.add(foundationKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"0000000000000000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}" + "]}]}"; Assert.assertTrue( - PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, 0, + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + 0, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -186,43 +231,53 @@ public void testActiveOperations02() { ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(1, PublicMethodForMultiSign - .getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); - - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); - - Assert.assertFalse(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertEquals( + 1, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); + + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + + Assert.assertFalse( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - } - @Test(enabled = true, description = "Active operation include invalid contract", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active operation include invalid contract", + groups = {"daily", "multisig"}) public void testActiveOperations03() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -230,200 +285,306 @@ public void testActiveOperations03() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - // operation include invalid 99 contract - Integer[] ints = {0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 30, 31, - 32, 33, 41, 42, 43, 44, 45, 99}; - String operations = PublicMethodForMultiSign.getOperations(ints); - String accountPermissionJson = + // operation include invalid 99 contract + Integer[] ints = { + 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 30, 31, 32, 33, 41, 42, + 43, 44, 45, 99 + }; + String operations = PublicMethodForMultiSign.getOperations(ints); + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : 99 isn't a validate ContractType", + Assert.assertEquals( + "Contract validate error : 99 isn't a validate ContractType", response.getMessage().toStringUtf8()); - // operation's length is less then 64, + // operation's length is less then 64, // 63: 7fff1fc0033e000000000000000000000000000000000000000000000000000 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : 21 isn't a validate ContractType", + Assert.assertEquals( + "Contract validate error : 21 isn't a validate ContractType", response.getMessage().toStringUtf8()); - // operation's length is less then 64, + // operation's length is less then 64, // 62: 7fff1fc0033e00000000000000000000000000000000000000000000000000 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e00000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : operations size must 32", - response.getMessage().toStringUtf8()); - // operation's length is more then 64, + Assert.assertEquals( + "Contract validate error : operations size must 32", response.getMessage().toStringUtf8()); + // operation's length is more then 64, // 65: 7fff1fc0033e00000000000000000000000000000000000000000000000000000 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":" + "\"7fff1fc0033e00000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : operations size must 32", - response.getMessage().toStringUtf8()); - // operation's length is more then 64, + Assert.assertEquals( + "Contract validate error : operations size must 32", response.getMessage().toStringUtf8()); + // operation's length is more then 64, // 66: 7fff1fc0033e00000000000000000000000000000000000000000000000000000 accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":" + "\"7fff1fc0033e000000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : operations size must 32", - response.getMessage().toStringUtf8()); - // oprations = "12aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + Assert.assertEquals( + "Contract validate error : operations size must 32", response.getMessage().toStringUtf8()); + // oprations = "12aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" // same result 12eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee operations = "12aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : 21 isn't a validate ContractType", + Assert.assertEquals( + "Contract validate error : 21 isn't a validate ContractType", response.getMessage().toStringUtf8()); - // operation = "" + // operation = "" operations = ""; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : operations size must 32", - response.getMessage().toStringUtf8()); - // Operation = + Assert.assertEquals( + "Contract validate error : operations size must 32", response.getMessage().toStringUtf8()); + // Operation = accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; boolean ret = false; try { @@ -434,20 +595,33 @@ public void testActiveOperations03() { ret = true; } Assert.assertTrue(ret); - // Operation = null + // Operation = null operations = null; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; ret = false; @@ -459,45 +633,58 @@ public void testActiveOperations03() { ret = true; } Assert.assertTrue(ret); - // no Operation + // no Operation accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : operations size must 32", - response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertEquals( + "Contract validate error : operations size must 32", response.getMessage().toStringUtf8()); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); - } - @Test(enabled = true, description = "Owner sets operation", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner sets operation", + groups = {"daily", "multisig"}) public void testActiveOperations04() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -505,44 +692,63 @@ public void testActiveOperations04() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1," - + "\"operations\":\"" + DEFAULT_OPERATION + "\"," + + "\"operations\":\"" + + DEFAULT_OPERATION + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"" + DEFAULT_OPERATION + "\"," + + "\"operations\":\"" + + DEFAULT_OPERATION + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : Owner permission needn't operations", + Assert.assertEquals( + "Contract validate error : Owner permission needn't operations", response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); } - @Test(enabled = true, description = "Witness sets operation", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Witness sets operation", + groups = {"daily", "multisig"}) public void testActiveOperations05() { String ownerKey = witnessKey; - byte[] ownerAddress = new WalletClient(ownerKey).getAddress(); - PublicMethod.sendcoin(ownerAddress, 1_000000, foundationAddress, foundationKey, blockingStubFull); + byte[] ownerAddress = new WalletClient(ownerKey).getAddress(); + PublicMethod.sendcoin( + ownerAddress, 1_000000, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -550,38 +756,52 @@ public void testActiveOperations05() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"owner\",\"threshold\":1," - + "\"operations\":\"" + DEFAULT_OPERATION + "\"," + + "\"operations\":\"" + + DEFAULT_OPERATION + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"" + DEFAULT_OPERATION + "\"," + + "\"operations\":\"" + + DEFAULT_OPERATION + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : Witness permission needn't operations", + Assert.assertEquals( + "Contract validate error : Witness permission needn't operations", response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); - } @AfterMethod @@ -589,10 +809,7 @@ public void aftertest() { PublicMethod.freeResource(ownerAddress, ownerKey, foundationAddress, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign20.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign20.java index d2a83626..e528ec73 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign20.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign20.java @@ -18,16 +18,17 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class MultiSign20 extends TronBaseTest { private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); +public class MultiSign20 extends TronBaseTest { + private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); private final String contractTronDiceAddr = "TMYcx6eoRXnePKT1jVn25ZNeMNJ6828HWk"; - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -40,33 +41,45 @@ public class MultiSign20 extends TronBaseTest { private final byte[] witnessAdd private ECKey tmpEcKey02 = new ECKey(Utils.getRandom()); private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Owner address is witness", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner address is witness", + groups = {"daily", "multisig"}) public void testOwnerAddress01() { // address = witness ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); long needCoin = updateAccountPermissionFee * 2; - PublicMethod - .freezeBalanceForReceiver(foundationAddress, 50000000L, 0, 1, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull); - PublicMethod - .freezeBalanceForReceiver(foundationAddress, 50000000L, 0, 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull); - PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 50000000L, + 0, + 1, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull); + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 50000000L, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull); + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -74,19 +87,30 @@ public void testOwnerAddress01() { ownerPermissionKeys.add(ownerKey); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"owner\"," - + "\"threshold\":1,\"keys\":[" + "{\"address\":\"" + PublicMethod - .getAddressString(foundationKey) + "\",\"weight\":1}]}," + + "\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -94,127 +118,179 @@ public void testOwnerAddress01() { ownerPermissionKeys.clear(); ownerPermissionKeys.add(foundationKey); - Assert.assertEquals(1, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 1, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," - + "\"threshold\":1,\"keys\":[" + "{\"address\":\"" + PublicMethod - .getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - } - @Test(enabled = true, description = "Owner address is witness with exception condition", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner address is witness with exception condition", + groups = {"daily", "multisig"}) public void testOwnerAddress02() { // address = witness, without witness permission ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); - PublicMethod.sendcoin(ownerAddress, 1_000000, foundationAddress, foundationKey, blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, - ByteString.copyFrom(ownerAddress), foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, 1_000000, foundationAddress, foundationKey, blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); PublicMethod.printAddress(ownerKey); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; - GrpcAPI.Return response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : witness permission is missed", + Assert.assertEquals( + "Contract validate error : witness permission is missed", response.getMessage().toStringUtf8()); - // address = witness, without active permission + // address = witness, without active permission accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," - + "\"threshold\":1,\"keys\":[" + "{\"address\":\"" + PublicMethod - .getAddressString(ownerKey) + "\",\"weight\":1}]}}"; - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + + "\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}}"; + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : active permission is missed", + Assert.assertEquals( + "Contract validate error : active permission is missed", response.getMessage().toStringUtf8()); - // address = witness, without owner permission - accountPermissionJson = "{\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," - + "\"threshold\":1,\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + // address = witness, without owner permission + accountPermissionJson = + "{\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," + + "\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : owner permission is missed", + Assert.assertEquals( + "Contract validate error : owner permission is missed", response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); - PublicMethod.unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Owner address is normal address with exception condition", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Owner address is normal address with exception condition", + groups = {"daily", "multisig"}) public void testOwnerAddress03() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -223,78 +299,101 @@ public void testOwnerAddress03() { PublicMethod.printAddress(ownerKey); ownerPermissionKeys.add(ownerKey); - // address = normal address, with witness permission + // address = normal address, with witness permission String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"witness\"," - + "\"threshold\":1,\"keys\":[" + "{\"address\":\"" + PublicMethod - .getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "\"threshold\":1,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; - GrpcAPI.Return response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); Assert.assertEquals( "Contract validate error : account isn't witness can't set" + " witness permission", response.getMessage().toStringUtf8()); - // address = normal address, without owner permission + // address = normal address, without owner permission accountPermissionJson = "{\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : owner permission is missed", + Assert.assertEquals( + "Contract validate error : owner permission is missed", response.getMessage().toStringUtf8()); - // address = normal address, without active permission + // address = normal address, without active permission accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}}"; + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}}"; - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull); + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : active permission is missed", + Assert.assertEquals( + "Contract validate error : active permission is missed", response.getMessage().toStringUtf8()); - // address = contract address + // address = contract address byte[] ownerAddress02 = contractTronDiceAddr.getBytes(); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress02, ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress02, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : invalidate ownerAddress", - response.getMessage().toStringUtf8()); - // address = not active address + Assert.assertEquals( + "Contract validate error : invalidate ownerAddress", response.getMessage().toStringUtf8()); + // address = not active address ECKey ecKeyTmp = new ECKey(Utils.getRandom()); - final byte[] ownerAddressTmp = ecKeyTmp.getAddress(); - final String ownerKeyTmp = ByteArray.toHexString(ecKeyTmp.getPrivKeyBytes()); + final byte[] ownerAddressTmp = ecKeyTmp.getAddress(); + final String ownerKeyTmp = ByteArray.toHexString(ecKeyTmp.getPrivKeyBytes()); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.printAddress(ownerKey); @@ -304,163 +403,225 @@ public void testOwnerAddress03() { accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddressTmp, ownerKeyTmp, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddressTmp, ownerKeyTmp, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : ownerAddress account does not exist", + Assert.assertEquals( + "Contract validate error : ownerAddress account does not exist", response.getMessage().toStringUtf8()); - // address = not exist + // address = not exist String fakeAddress = "THph9K2M2nLvkianrMGswRhz5hjSA9fuH1"; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, fakeAddress.getBytes(), ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, fakeAddress.getBytes(), ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : invalidate ownerAddress", - response.getMessage().toStringUtf8()); - // address = long address + Assert.assertEquals( + "Contract validate error : invalidate ownerAddress", response.getMessage().toStringUtf8()); + // address = long address fakeAddress = "TR3FAbhiSeP7kSh39RjGYpwCqfMDHPMhX4d121"; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, fakeAddress.getBytes(), ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, fakeAddress.getBytes(), ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : invalidate ownerAddress", - response.getMessage().toStringUtf8()); - // address = short address + Assert.assertEquals( + "Contract validate error : invalidate ownerAddress", response.getMessage().toStringUtf8()); + // address = short address fakeAddress = "THph9K2M2nLvkianrMGswRhz5hj"; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, fakeAddress.getBytes(), ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, fakeAddress.getBytes(), ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : invalidate ownerAddress", - response.getMessage().toStringUtf8()); - // address = + Assert.assertEquals( + "Contract validate error : invalidate ownerAddress", response.getMessage().toStringUtf8()); + // address = fakeAddress = ""; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, fakeAddress.getBytes(), ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, fakeAddress.getBytes(), ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : invalidate ownerAddress", - response.getMessage().toStringUtf8()); - // address = null + Assert.assertEquals( + "Contract validate error : invalidate ownerAddress", response.getMessage().toStringUtf8()); + // address = null fakeAddress = null; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; boolean ret = false; try { - PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, fakeAddress.getBytes(), - ownerKey, blockingStubFull); + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, fakeAddress.getBytes(), ownerKey, blockingStubFull); } catch (NullPointerException e) { logger.info("NullPointerException !"); ret = true; } Assert.assertTrue(ret); - // address = "1ab(*c" + // address = "1ab(*c" fakeAddress = "1ab(*c"; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) - + "\",\"weight\":1}" + "]}]}"; - - response = PublicMethod - .accountPermissionUpdateForResponse(accountPermissionJson, fakeAddress.getBytes(), ownerKey, - blockingStubFull); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + + response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, fakeAddress.getBytes(), ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : invalidate ownerAddress", - response.getMessage().toStringUtf8()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Assert.assertEquals( + "Contract validate error : invalidate ownerAddress", response.getMessage().toStringUtf8()); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); } @AfterMethod public void aftertest() { - PublicMethod.unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); - PublicMethod.unFreezeBalance(foundationAddress, foundationKey, 1, ownerAddress, blockingStubFull); + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 1, ownerAddress, blockingStubFull); PublicMethod.freeResource(ownerAddress, ownerKey, foundationAddress, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign21.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign21.java index fe70214c..04af74fe 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign21.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign21.java @@ -18,15 +18,16 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class MultiSign21 extends TronBaseTest { private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); +public class MultiSign21 extends TronBaseTest { + private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -39,45 +40,50 @@ public class MultiSign21 extends TronBaseTest { private final byte[] witnessAdd private ECKey tmpEcKey02 = new ECKey(Utils.getRandom()); private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Permission Count is in exception condition", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Permission Count is in exception condition", + groups = {"daily", "multisig"}) public void testPermissionCount01() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); PublicMethod.printAddress(ownerKey); ownerPermissionKeys.add(ownerKey); - // count = 1 + // count = 1 String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}}"; + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}]}}"; - GrpcAPI.Return response = PublicMethod.accountPermissionUpdateForResponse(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("Contract validate error : active permission is missed", + Assert.assertEquals( + "Contract validate error : active permission is missed", response.getMessage().toStringUtf8()); - // count = 0 + // count = 0 accountPermissionJson = "[]"; boolean ret = false; @@ -89,86 +95,110 @@ public void testPermissionCount01() { ret = true; } Assert.assertTrue(ret); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); - } - @Test(enabled = true, description = "Permission Count is 4", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Permission Count is 4", + groups = {"daily", "multisig"}) public void testPermissionCount02() { ownerKey = witnessKey; ownerAddress = new WalletClient(ownerKey).getAddress(); long needCoin = updateAccountPermissionFee * 2; - PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); PublicMethod.printAddress(ownerKey); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"owner\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"owner\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey01) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey01) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(foundationKey); - Assert.assertEquals(1, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); - - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission().getKeysCount()); - - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); - - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getWitnessPermission())); - - PublicMethodForMultiSign - .recoverWitnessPermission(ownerKey, ownerPermissionKeys, blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertEquals( + 1, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getWitnessPermission() + .getKeysCount()); + + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getWitnessPermission())); + + PublicMethodForMultiSign.recoverWitnessPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - PublicMethod - .unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); } @AfterMethod @@ -176,10 +206,7 @@ public void aftertest() { PublicMethod.freeResource(ownerAddress, ownerKey, foundationAddress, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign22.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign22.java index e52797cf..b82e36b7 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign22.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign22.java @@ -18,33 +18,35 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class MultiSign22 extends TronBaseTest { private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); +public class MultiSign22 extends TronBaseTest { + private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ECKey ecKey2 = new ECKey(Utils.getRandom()); private byte[] normalAddr001 = ecKey2.getAddress(); private String normalKey001 = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Sign permission transaction by owner permission", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Sign permission transaction by owner permission", + groups = {"daily", "multisig"}) public void test01SignByOwnerKey() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); @@ -52,142 +54,203 @@ public void test01SignByOwnerKey() { long needCoin = updateAccountPermissionFee * 2 + multiSignFee; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); List ownerPermissionKeys = new ArrayList<>(); PublicMethod.printAddress(ownerKey); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; ownerPermissionKeys.add(ownerKey); - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(1, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 1, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; ownerPermissionKeys.add(foundationKey); - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, 0, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + 0, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(1, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 1, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - } - - @Test(enabled = true, description = "Sign normal transaction by owner permission", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Sign normal transaction by owner permission", + groups = {"daily", "multisig"}) public void test02SignByOwnerKeyForNormal() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee + multiSignFee; - Assert.assertTrue(PublicMethod - .sendcoin(ownerAddress, needCoin + 1_000000, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1_000000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); PublicMethod.printAddress(ownerKey); logger.info("** update owner permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; ownerPermissionKeys.add(ownerKey); - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(1, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 1, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); ownerPermissionKeys.add(foundationKey); logger.info("** trigger a normal permission"); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 0, ownerKey, - blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 0, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1_000000); } - - @Test(enabled = true, description = "Sign normal transaction by active permission", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Sign normal transaction by active permission", + groups = {"daily", "multisig"}) public void test03SignByActiveKey() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee + multiSignFee; - Assert.assertTrue(PublicMethod - .sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, + needCoin + 1_000_000, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); @@ -198,54 +261,81 @@ public void test03SignByActiveKey() { activePermissionKeys.add(normalKey001); logger.info("** update active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(normalKey001) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(normalKey001) + + "\",\"weight\":1}" + + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** update owner permission to two address"); logger.info("** trigger a normal permission"); - Assert.assertFalse(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 0, ownerKey, + Assert.assertFalse( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 0, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); - Assert.assertTrue(PublicMethodForMultiSign - .sendcoinWithPermissionId(foundationAddress, 1_000000, ownerAddress, 2, ownerKey, + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + foundationAddress, + 1_000000, + ownerAddress, + 2, + ownerKey, blockingStubFull, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); - } - - @Test(enabled = true, description = "Sign permission transaction by active permission", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Sign permission transaction by active permission", + groups = {"daily", "multisig"}) public void test04SignByActiveKeyForPermission() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); @@ -253,12 +343,13 @@ public void test04SignByActiveKeyForPermission() { long needCoin = updateAccountPermissionFee * 2 + multiSignFee; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); Integer[] ints = {ContractType.AccountPermissionUpdateContract_VALUE}; - final String operations = PublicMethodForMultiSign.getOperations(ints); + final String operations = PublicMethodForMultiSign.getOperations(ints); PublicMethod.printAddress(ownerKey); @@ -269,202 +360,285 @@ public void test04SignByActiveKeyForPermission() { activePermissionKeys.add(normalKey001); logger.info("** update active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"" + operations + "\"," + "\"keys\":[" + "{\"address\":\"" - + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}," + "{\"address\":\"" - + PublicMethod.getAddressString(normalKey001) + "\",\"weight\":1}" + "]}]}"; + + "\"operations\":\"" + + operations + + "\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(normalKey001) + + "\",\"weight\":1}" + + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, 2, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + 2, activePermissionKeys.toArray(new String[activePermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(1, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 1, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - @Test(enabled = true, description = "Sign permission transaction" - + " by address which is out of permission list", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Sign permission transaction" + " by address which is out of permission list", + groups = {"daily", "multisig"}) public void test06SignByOtherKey() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, 1000000, foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, 1000000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); PublicMethod.printAddress(ownerKey); logger.info("** update active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; ownerPermissionKeys.add(normalKey001); - GrpcAPI.Return response = PublicMethodForMultiSign - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()])); + GrpcAPI.Return response = + PublicMethodForMultiSign.accountPermissionUpdateForResponse( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()])); Assert.assertFalse(response.getResult()); Assert.assertEquals(SIGERROR, response.getCode()); - Assert.assertThat(response.getMessage().toStringUtf8(), - containsString("it is not contained of permission")); + Assert.assertThat( + response.getMessage().toStringUtf8(), containsString("it is not contained of permission")); - Assert.assertEquals(1, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 1, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); - } - @Test(enabled = true, description = "Sign permission transaction " + "by empty permission list", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Sign permission transaction " + "by empty permission list", + groups = {"daily", "multisig"}) public void test07SignByEmptyObjectKey() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); String[] ownerPermissionKeys = new String[0]; PublicMethod.printAddress(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}" + "]}]}"; - - GrpcAPI.Return response = PublicMethodForMultiSign - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerPermissionKeys); + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; + + GrpcAPI.Return response = + PublicMethodForMultiSign.accountPermissionUpdateForResponse( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerPermissionKeys); Assert.assertFalse(response.getResult()); Assert.assertEquals(SIGERROR, response.getCode()); - Assert.assertEquals("Validate signature error: miss sig or contract", - response.getMessage().toStringUtf8()); + Assert.assertEquals( + "Validate signature error: miss sig or contract", response.getMessage().toStringUtf8()); - Assert.assertEquals(1, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 1, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); } - @Test(enabled = true, description = "Sign permission transaction by empty address", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Sign permission transaction by empty address", + groups = {"daily", "multisig"}) public void test08SignByEmptyKey() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); String[] ownerPermissionKeys = new String[1]; PublicMethod.printAddress(ownerKey); ownerPermissionKeys[0] = ""; logger.info("** update active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; boolean ret = false; try { - PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys); + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerPermissionKeys); } catch (NumberFormatException e) { logger.info("NumberFormatException !"); ret = true; @@ -474,57 +648,77 @@ public void test08SignByEmptyKey() { } Assert.assertTrue(ret); - Assert.assertEquals(1, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 1, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); - } - @Test(enabled = true, description = "Sign permission transaction by invalid address", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Sign permission transaction by invalid address", + groups = {"daily", "multisig"}) public void test07SignByStringKey() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); PublicMethod.printAddress(ownerKey); - String emptyKey = "abc1222"; + String emptyKey = "abc1222"; logger.info("** update active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + emptyKey + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod - .getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + emptyKey + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; ownerPermissionKeys.add(emptyKey); boolean ret = false; try { - GrpcAPI.Return response = PublicMethodForMultiSign - .accountPermissionUpdateForResponse(accountPermissionJson, ownerKey.getBytes(), ownerKey, + GrpcAPI.Return response = + PublicMethodForMultiSign.accountPermissionUpdateForResponse( + accountPermissionJson, + ownerKey.getBytes(), + ownerKey, blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()])); } catch (NullPointerException e) { @@ -532,12 +726,15 @@ public void test07SignByStringKey() { ret = true; } Assert.assertTrue(ret); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); } - @Test(enabled = true, description = "Set same permission", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Set same permission", + groups = {"daily", "multisig"}) public void test08RepeatUpdateSamePermission() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); @@ -545,83 +742,109 @@ public void test08RepeatUpdateSamePermission() { long needCoin = updateAccountPermissionFee * 2; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); ownerPermissionKeys.add(ownerKey); - PublicMethodForMultiSign - .recoverAccountPermission(ownerKey, ownerPermissionKeys, blockingStubFull); - PublicMethodForMultiSign - .recoverAccountPermission(ownerKey, ownerPermissionKeys, blockingStubFull); - Assert.assertEquals(1, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + PublicMethodForMultiSign.recoverAccountPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); + PublicMethodForMultiSign.recoverAccountPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); + Assert.assertEquals( + 1, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - @Test(enabled = true, description = "Sign permission transaction " - + "by active address and default permissionId", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Sign permission transaction " + "by active address and default permissionId", + groups = {"daily", "multisig"}) public void test09SignListMoreThanPermissionKeys() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); PublicMethod.printAddress(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":1}" + "]}]}"; + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + + "]}]}"; ownerPermissionKeys.add(foundationKey); ownerPermissionKeys.add(ownerKey); - GrpcAPI.Return response = PublicMethodForMultiSign - .accountPermissionUpdateForResponse(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()])); + GrpcAPI.Return response = + PublicMethodForMultiSign.accountPermissionUpdateForResponse( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()])); Assert.assertFalse(response.getResult()); Assert.assertEquals(SIGERROR, response.getCode()); Assert.assertEquals( - "Validate signature error: Signature count " + "is 2 more than key counts of permission : 1", + "Validate signature error: Signature count " + + "is 2 more than key counts of permission : 1", response.getMessage().toStringUtf8()); - Assert.assertEquals(1, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 1, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission() + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() .getKeysCount()); PublicMethodForMultiSign.printPermissionList( PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out.printf(PublicMethodForMultiSign.printPermission( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); } @@ -631,12 +854,7 @@ public void aftertest() { PublicMethod.freeResource(ownerAddress, ownerKey, foundationAddress, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign23.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign23.java index e66bc984..1af85d61 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign23.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign23.java @@ -23,11 +23,11 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode @@ -37,10 +37,10 @@ public class MultiSign23 extends TronBaseTest { private static final String DEFAULT_OPERATION = "7fff1fc0033e0000000000000000000000000000000000000000000000000000"; private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -53,32 +53,37 @@ public class MultiSign23 extends TronBaseTest { private ECKey tmpEcKey02 = new ECKey(Utils.getRandom()); private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Add sign for multi sign normal transaction", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Add sign for multi sign normal transaction", + groups = {"daily", "multisig"}) public void test01MultiSignNormalTransaction() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2 + multiSignFee; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, + needCoin + 1_000_000, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -90,92 +95,115 @@ public void test01MultiSignNormalTransaction() { activePermissionKeys.add(tmpKey02); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner1\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.clear(); ownerPermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(1, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 1, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a normal transaction"); - Transaction transaction = PublicMethodForMultiSign - .sendcoin2(foundationAddress, 1000_000, ownerAddress, ownerKey, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoin2( + foundationAddress, 1000_000, ownerAddress, ownerKey, blockingStubFull); - Transaction transaction1 = PublicMethodForMultiSign.addTransactionSignWithPermissionId( - transaction, tmpKey02, 2, blockingStubFull); + Transaction transaction1 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction, tmpKey02, 2, blockingStubFull); - Transaction transaction2 = PublicMethodForMultiSign.addTransactionSignWithPermissionId( - transaction1, witnessKey, 2, blockingStubFull); + Transaction transaction2 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction1, witnessKey, 2, blockingStubFull); logger.info("transaction hex string is " + ByteArray.toHexString(transaction2.toByteArray())); - TransactionSignWeight txWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + TransactionSignWeight txWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("TransactionSignWeight info : " + txWeight); - Assert.assertTrue(PublicMethodForMultiSign.broadcastTransaction(transaction2, blockingStubFull)); + Assert.assertTrue( + PublicMethodForMultiSign.broadcastTransaction(transaction2, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethodForMultiSign - .recoverAccountPermission(ownerKey, ownerPermissionKeys, blockingStubFull); + PublicMethodForMultiSign.recoverAccountPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); txWeight = PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("TransactionSignWeight info : " + txWeight); - Transaction transaction3 = PublicMethodForMultiSign - .sendcoin2(foundationAddress, 1000_000, ownerAddress, ownerKey, blockingStubFull); - - Transaction transaction4 = PublicMethodForMultiSign.addTransactionSignWithPermissionId( - transaction, tmpKey02, 2, blockingStubFull); - Assert.assertFalse(PublicMethodForMultiSign.broadcastTransaction(transaction3,blockingStubFull)); - Assert.assertFalse(PublicMethodForMultiSign.broadcastTransaction(transaction4,blockingStubFull)); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Transaction transaction3 = + PublicMethodForMultiSign.sendcoin2( + foundationAddress, 1000_000, ownerAddress, ownerKey, blockingStubFull); + + Transaction transaction4 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction, tmpKey02, 2, blockingStubFull); + Assert.assertFalse( + PublicMethodForMultiSign.broadcastTransaction(transaction3, blockingStubFull)); + Assert.assertFalse( + PublicMethodForMultiSign.broadcastTransaction(transaction4, blockingStubFull)); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); - } - - @Test(enabled = true, description = "Add sign for multi sign permission transaction", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Add sign for multi sign permission transaction", + groups = {"daily", "multisig"}) public void test02MultiSignPermissionTransaction() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); - String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2 + multiSignFee; - PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -187,89 +215,122 @@ public void test02MultiSignPermissionTransaction() { activePermissionKeys.add(ownerKey); Integer[] ints = {ContractType.AccountPermissionUpdateContract_VALUE}; - String operations = PublicMethodForMultiSign.getOperations(ints); + String operations = PublicMethodForMultiSign.getOperations(ints); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner1\"," + "\"threshold\":5,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," - + "\"operations\":\"" + operations + "\",\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "\"operations\":\"" + + operations + + "\",\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.add(foundationKey); activePermissionKeys.add(tmpKey02); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a permission transaction"); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - Transaction transaction = PublicMethodForMultiSign.accountPermissionUpdateWithoutSign( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()])); + Transaction transaction = + PublicMethodForMultiSign.accountPermissionUpdateWithoutSign( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()])); - Transaction transaction1 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction, tmpKey02, 2, blockingStubFull); + Transaction transaction1 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction, tmpKey02, 2, blockingStubFull); - Transaction transaction2 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction1, ownerKey, 2, blockingStubFull); + Transaction transaction2 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction1, ownerKey, 2, blockingStubFull); - TransactionSignWeight txWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + TransactionSignWeight txWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("TransactionSignWeight info : " + txWeight); - Assert.assertTrue(PublicMethodForMultiSign.broadcastTransaction(transaction2, blockingStubFull)); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertTrue( + PublicMethodForMultiSign.broadcastTransaction(transaction2, blockingStubFull)); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - @Test(enabled = true, description = "" - + "Add sign for single sign normal transaction,get approve list", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "" + "Add sign for single sign normal transaction,get approve list", + groups = {"daily", "multisig"}) public void test03SingleSignNormalTransaction() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, + needCoin + 1_000_000, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); List activePermissionKeys = new ArrayList<>(); @@ -280,69 +341,96 @@ public void test03SingleSignNormalTransaction() { activePermissionKeys.add(ownerKey); Integer[] ints = {ContractType.TransferContract_VALUE}; - String operations = PublicMethodForMultiSign.getOperations(ints); - String accountPermissionJson = + String operations = PublicMethodForMultiSign.getOperations(ints); + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner1\"," + "\"threshold\":5,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"" + operations + "\",\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "\"operations\":\"" + + operations + + "\",\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission()); + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission()); logger.info("** trigger a normal transaction"); - Transaction transaction = PublicMethodForMultiSign - .sendcoin2(foundationAddress, 1000_000, ownerAddress, ownerKey, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoin2( + foundationAddress, 1000_000, ownerAddress, ownerKey, blockingStubFull); - Transaction transaction1 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction, tmpKey02, 2, blockingStubFull); + Transaction transaction1 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction, tmpKey02, 2, blockingStubFull); - TransactionSignWeight txWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + TransactionSignWeight txWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("TransactionSignWeight info : " + txWeight); - Assert.assertTrue(PublicMethodForMultiSign.broadcastTransaction(transaction1, blockingStubFull)); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertTrue( + PublicMethodForMultiSign.broadcastTransaction(transaction1, blockingStubFull)); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); - GrpcAPI.TransactionApprovedList transactionApprovedList = PublicMethod - .getTransactionApprovedList(transaction1, blockingStubFull); + GrpcAPI.TransactionApprovedList transactionApprovedList = + PublicMethod.getTransactionApprovedList(transaction1, blockingStubFull); logger.info("transactionApprovedList:" + transactionApprovedList); - Assert.assertEquals(Base58.encode58Check(tmpAddr02), Base58 - .encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); - Assert.assertEquals(2, - transactionApprovedList.getTransaction().getTransaction().getRawData().getContract(0) + Assert.assertEquals( + Base58.encode58Check(tmpAddr02), + Base58.encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); + Assert.assertEquals( + 2, + transactionApprovedList + .getTransaction() + .getTransaction() + .getRawData() + .getContract(0) .getPermissionId()); Assert.assertEquals(1, transactionApprovedList.getApprovedListCount()); - } - @Test(enabled = true, description = "Add sign for normal transaction " - + "with address not in permission list", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Add sign for normal transaction " + "with address not in permission list", + groups = {"daily", "multisig"}) public void test06SignFailedTransaction() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); @@ -350,12 +438,12 @@ public void test06SignFailedTransaction() { long needCoin = updateAccountPermissionFee; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin + 1000_000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, needCoin + 1000_000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -365,72 +453,97 @@ public void test06SignFailedTransaction() { ownerPermissionKeys.add(ownerKey); activePermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner1\"," + "\"threshold\":5,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"" + AVAILABLE_OPERATION + "\",\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "\"operations\":\"" + + AVAILABLE_OPERATION + + "\",\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission()); + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission()); ownerPermissionKeys.add(foundationKey); activePermissionKeys.add(tmpKey02); logger.info("** trigger a normal transaction"); - Transaction transaction = PublicMethodForMultiSign - .sendcoin2(foundationAddress, 1000_000, ownerAddress, ownerKey, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoin2( + foundationAddress, 1000_000, ownerAddress, ownerKey, blockingStubFull); - Transaction transaction1 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction, foundationKey, 2, blockingStubFull); + Transaction transaction1 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction, foundationKey, 2, blockingStubFull); - TransactionSignWeight txWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + TransactionSignWeight txWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("TransactionSignWeight info : " + txWeight); - Assert - .assertFalse(PublicMethodForMultiSign.broadcastTransaction(transaction1, blockingStubFull)); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertFalse( + PublicMethodForMultiSign.broadcastTransaction(transaction1, blockingStubFull)); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - } - @Test(enabled = true, description = "Add sign for timeout normal transaction,get approve list", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Add sign for timeout normal transaction,get approve list", + groups = {"daily", "multisig"}) public void test07TimeoutTransaction() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, + needCoin + 1_000_000, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); @@ -439,42 +552,61 @@ public void test07TimeoutTransaction() { ownerPermissionKeys.add(ownerKey); ownerPermissionKeys.add(foundationKey); activePermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner1\"," + "\"threshold\":5,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"" + AVAILABLE_OPERATION + "\",\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "\"operations\":\"" + + AVAILABLE_OPERATION + + "\",\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission()); + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission()); ownerPermissionKeys.add(foundationKey); activePermissionKeys.add(tmpKey02); logger.info("** trigger a normal transaction"); - Transaction transaction = PublicMethodForMultiSign - .sendcoin2(foundationAddress, 1000_000, ownerAddress, ownerKey, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoin2( + foundationAddress, 1000_000, ownerAddress, ownerKey, blockingStubFull); try { Thread.sleep(70000); @@ -482,100 +614,113 @@ public void test07TimeoutTransaction() { e.printStackTrace(); } - Transaction transaction1 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction, tmpKey02, 2, blockingStubFull); + Transaction transaction1 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction, tmpKey02, 2, blockingStubFull); - TransactionSignWeight txWeight = PublicMethodForMultiSign.getTransactionSignWeight( - transaction1, blockingStubFull); + TransactionSignWeight txWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("TransactionSignWeight info : " + txWeight); - Assert - .assertFalse(PublicMethodForMultiSign.broadcastTransaction(transaction1, blockingStubFull)); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertFalse( + PublicMethodForMultiSign.broadcastTransaction(transaction1, blockingStubFull)); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - GrpcAPI.TransactionApprovedList transactionApprovedList = PublicMethod - .getTransactionApprovedList(transaction1, blockingStubFull); + GrpcAPI.TransactionApprovedList transactionApprovedList = + PublicMethod.getTransactionApprovedList(transaction1, blockingStubFull); logger.info("transactionApprovedList:" + transactionApprovedList); - logger.info("Base58.encode58Check(test001Address)1:" + Base58 - .encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); + logger.info( + "Base58.encode58Check(test001Address)1:" + + Base58.encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); Assert.assertEquals(1, transactionApprovedList.getApprovedListCount()); - Assert.assertEquals(Base58.encode58Check(tmpAddr02), Base58 - .encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); - Assert.assertEquals(2, - transactionApprovedList.getTransaction().getTransaction().getRawData().getContract(0) + Assert.assertEquals( + Base58.encode58Check(tmpAddr02), + Base58.encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); + Assert.assertEquals( + 2, + transactionApprovedList + .getTransaction() + .getTransaction() + .getRawData() + .getContract(0) .getPermissionId()); - } - @Test(enabled = true, description = "Add sign for empty transaction,get approve list", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Add sign for empty transaction,get approve list", + groups = {"daily", "multisig"}) public void test08EmptyTransaction() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, 1_000_000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, 1_000_000, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); logger.info("** created an empty transaction"); - AccountPermissionUpdateContract.Builder builder = - AccountPermissionUpdateContract.newBuilder(); + AccountPermissionUpdateContract.Builder builder = AccountPermissionUpdateContract.newBuilder(); AccountPermissionUpdateContract contract = builder.build(); - TransactionExtention transactionExtention = - blockingStubFull.accountPermissionUpdate(contract); + TransactionExtention transactionExtention = blockingStubFull.accountPermissionUpdate(contract); Transaction transaction = transactionExtention.getTransaction(); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, ownerKey, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, ownerKey, blockingStubFull); - TransactionSignWeight txWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + TransactionSignWeight txWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("TransactionSignWeight info : " + txWeight); - Assert - .assertFalse(PublicMethodForMultiSign.broadcastTransaction(transaction1, blockingStubFull)); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertFalse( + PublicMethodForMultiSign.broadcastTransaction(transaction1, blockingStubFull)); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore, balanceAfter); logger.info("transaction hex string is " + ByteArray.toHexString(transaction.toByteArray())); - GrpcAPI.TransactionApprovedList transactionApprovedList = PublicMethod - .getTransactionApprovedList(transaction, blockingStubFull); + GrpcAPI.TransactionApprovedList transactionApprovedList = + PublicMethod.getTransactionApprovedList(transaction, blockingStubFull); logger.info("Before broadcast transactionApprovedList info :\n" + transactionApprovedList); - Assert.assertEquals("Invalid transaction: no valid contract", - transactionApprovedList.getResult().getMessage()); - Assert.assertFalse(PublicMethodForMultiSign - .broadcastTransaction(transaction1, blockingStubFull)); + Assert.assertEquals( + "Invalid transaction: no valid contract", transactionApprovedList.getResult().getMessage()); + Assert.assertFalse( + PublicMethodForMultiSign.broadcastTransaction(transaction1, blockingStubFull)); logger.info("transaction hex string is " + ByteArray.toHexString(transaction1.toByteArray())); - transactionApprovedList = PublicMethod - .getTransactionApprovedList(transaction1, blockingStubFull); - Assert.assertEquals("Invalid transaction: no valid contract", - transactionApprovedList.getResult().getMessage()); + transactionApprovedList = + PublicMethod.getTransactionApprovedList(transaction1, blockingStubFull); + Assert.assertEquals( + "Invalid transaction: no valid contract", transactionApprovedList.getResult().getMessage()); } - @Test(enabled = true, description = "Add sign for fake transaction,get approve list", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Add sign for fake transaction,get approve list", + groups = {"daily", "multisig"}) public void test09ErrorTransaction() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, + needCoin + 1_000_000, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); List activePermissionKeys = new ArrayList<>(); @@ -584,81 +729,112 @@ public void test09ErrorTransaction() { ownerPermissionKeys.add(ownerKey); activePermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner1\"," + "\"threshold\":5,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"" + AVAILABLE_OPERATION + "\",\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":2}" + + "\"operations\":\"" + + AVAILABLE_OPERATION + + "\",\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":2}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(2, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission()); + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission()); ownerPermissionKeys.add(foundationKey); activePermissionKeys.add(tmpKey02); logger.info("** trigger a fake transaction"); - Transaction transaction = PublicMethodForMultiSign - .createFakeTransaction(ownerAddress, 1_000_000L, ownerAddress); - Transaction transaction1 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction, tmpKey02, 2, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.createFakeTransaction(ownerAddress, 1_000_000L, ownerAddress); + Transaction transaction1 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction, tmpKey02, 2, blockingStubFull); logger.info("transaction hex string is " + ByteArray.toHexString(transaction1.toByteArray())); - TransactionSignWeight txWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + TransactionSignWeight txWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("Before broadcast permission TransactionSignWeight info :\n" + txWeight); Assert.assertEquals(ENOUGH_PERMISSION, txWeight.getResult().getCode()); Assert.assertEquals(2, txWeight.getCurrentWeight()); - Assert - .assertFalse(PublicMethodForMultiSign.broadcastTransaction(transaction1, blockingStubFull)); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertFalse( + PublicMethodForMultiSign.broadcastTransaction(transaction1, blockingStubFull)); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - GrpcAPI.TransactionApprovedList transactionApprovedList = PublicMethod - .getTransactionApprovedList(transaction1, blockingStubFull); + GrpcAPI.TransactionApprovedList transactionApprovedList = + PublicMethod.getTransactionApprovedList(transaction1, blockingStubFull); Assert.assertEquals(1, transactionApprovedList.getApprovedListCount()); - Assert.assertEquals(Base58.encode58Check(tmpAddr02), Base58 - .encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); - Assert.assertEquals(2, - transactionApprovedList.getTransaction().getTransaction().getRawData().getContract(0) + Assert.assertEquals( + Base58.encode58Check(tmpAddr02), + Base58.encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); + Assert.assertEquals( + 2, + transactionApprovedList + .getTransaction() + .getTransaction() + .getRawData() + .getContract(0) .getPermissionId()); } - @Test(enabled = true, description = "Add sign transaction with mix order", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Add sign transaction with mix order", + groups = {"daily", "multisig"}) public void test10MultiSignNormalTransactionWithMixOrder() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee + multiSignFee; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, + needCoin + 1_000_000, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -666,62 +842,84 @@ public void test10MultiSignNormalTransactionWithMixOrder() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner1\"," + "\"threshold\":5,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," - + "\"operations\":\"" + DEFAULT_OPERATION + "\",\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "\"operations\":\"" + + DEFAULT_OPERATION + + "\",\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.add(foundationKey); - Assert.assertEquals(3, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 3, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission()); + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission()); logger.info("** trigger a normal transaction"); - Transaction transaction = PublicMethodForMultiSign - .sendcoin2(foundationAddress, 1000_000, ownerAddress, ownerKey, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoin2( + foundationAddress, 1000_000, ownerAddress, ownerKey, blockingStubFull); logger.info("transaction hex string is " + ByteArray.toHexString(transaction.toByteArray())); - TransactionSignWeight txWeight = PublicMethodForMultiSign.getTransactionSignWeight( - transaction, blockingStubFull); + TransactionSignWeight txWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction, blockingStubFull); logger.info("Before Sign TransactionSignWeight info :\n" + txWeight); Assert.assertEquals(NOT_ENOUGH_PERMISSION, txWeight.getResult().getCode()); Assert.assertEquals(0, txWeight.getCurrentWeight()); - Transaction transaction1 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction, tmpKey02, 2, blockingStubFull); + Transaction transaction1 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction, tmpKey02, 2, blockingStubFull); - logger.info("transaction hex string is " + ByteArray.toHexString( - transaction1.toByteArray())); + logger.info("transaction hex string is " + ByteArray.toHexString(transaction1.toByteArray())); txWeight = PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("Before broadcast1 TransactionSignWeight info :\n" + txWeight); Assert.assertEquals(NOT_ENOUGH_PERMISSION, txWeight.getResult().getCode()); Assert.assertEquals(1, txWeight.getCurrentWeight()); - Transaction transaction2 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction1, ownerKey, 2, blockingStubFull); + Transaction transaction2 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction1, ownerKey, 2, blockingStubFull); logger.info("transaction hex string is " + ByteArray.toHexString(transaction2.toByteArray())); txWeight = PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); @@ -729,8 +927,9 @@ public void test10MultiSignNormalTransactionWithMixOrder() { Assert.assertEquals(NOT_ENOUGH_PERMISSION, txWeight.getResult().getCode()); Assert.assertEquals(2, txWeight.getCurrentWeight()); - Transaction transaction3 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction2, witnessKey, 2, blockingStubFull); + Transaction transaction3 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction2, witnessKey, 2, blockingStubFull); logger.info("transaction hex string is " + ByteArray.toHexString(transaction3.toByteArray())); txWeight = PublicMethodForMultiSign.getTransactionSignWeight(transaction3, blockingStubFull); @@ -738,26 +937,33 @@ public void test10MultiSignNormalTransactionWithMixOrder() { Assert.assertEquals(ENOUGH_PERMISSION, txWeight.getResult().getCode()); Assert.assertEquals(3, txWeight.getCurrentWeight()); - Assert.assertTrue(PublicMethodForMultiSign.broadcastTransaction(transaction3, blockingStubFull)); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertTrue( + PublicMethodForMultiSign.broadcastTransaction(transaction3, blockingStubFull)); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); } - @Test(enabled = true, description = "Add sign transaction with same address", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Add sign transaction with same address", + groups = {"daily", "multisig"}) public void test11MultiSignNormalTransactionBySameAccount() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, + needCoin + 1_000_000, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -767,42 +973,63 @@ public void test11MultiSignNormalTransactionBySameAccount() { ownerPermissionKeys.add(ownerKey); logger.info("** update owner and active permission to two address"); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner1\"," + "\"threshold\":5,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," - + "\"operations\":\"" + DEFAULT_OPERATION + "\",\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "\"operations\":\"" + + DEFAULT_OPERATION + + "\",\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.add(foundationKey); - Assert.assertEquals(3, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 3, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission()); + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission()); logger.info("** trigger a normal transaction"); - Transaction transaction = PublicMethodForMultiSign - .sendcoin2(foundationAddress, 1000_000, ownerAddress, ownerKey, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoin2( + foundationAddress, 1000_000, ownerAddress, ownerKey, blockingStubFull); logger.info("transaction hex string is " + ByteArray.toHexString(transaction.toByteArray())); TransactionSignWeight txWeight = @@ -811,8 +1038,9 @@ public void test11MultiSignNormalTransactionBySameAccount() { Assert.assertEquals(NOT_ENOUGH_PERMISSION, txWeight.getResult().getCode()); Assert.assertEquals(0, txWeight.getCurrentWeight()); - Transaction transaction1 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction, tmpKey02, 2, blockingStubFull); + Transaction transaction1 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction, tmpKey02, 2, blockingStubFull); logger.info("transaction hex string is " + ByteArray.toHexString(transaction1.toByteArray())); txWeight = PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); @@ -820,8 +1048,9 @@ public void test11MultiSignNormalTransactionBySameAccount() { Assert.assertEquals(NOT_ENOUGH_PERMISSION, txWeight.getResult().getCode()); Assert.assertEquals(1, txWeight.getCurrentWeight()); - Transaction transaction2 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction1, ownerKey, 2, blockingStubFull); + Transaction transaction2 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction1, ownerKey, 2, blockingStubFull); logger.info("transaction hex string is " + ByteArray.toHexString(transaction2.toByteArray())); txWeight = PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); @@ -829,26 +1058,28 @@ public void test11MultiSignNormalTransactionBySameAccount() { Assert.assertEquals(NOT_ENOUGH_PERMISSION, txWeight.getResult().getCode()); Assert.assertEquals(2, txWeight.getCurrentWeight()); - Transaction transaction3 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction2, ownerKey, 2, blockingStubFull); + Transaction transaction3 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction2, ownerKey, 2, blockingStubFull); logger.info("transaction hex string is " + ByteArray.toHexString(transaction3.toByteArray())); txWeight = PublicMethodForMultiSign.getTransactionSignWeight(transaction3, blockingStubFull); logger.info("Before broadcast2 TransactionSignWeight info :\n" + txWeight); Assert.assertEquals(PERMISSION_ERROR, txWeight.getResult().getCode()); Assert.assertEquals(0, txWeight.getCurrentWeight()); - Assert.assertThat(txWeight.getResult().getMessage(), - containsString("has signed twice!")); + Assert.assertThat(txWeight.getResult().getMessage(), containsString("has signed twice!")); - Assert.assertFalse(PublicMethodForMultiSign.broadcastTransaction( - transaction3, blockingStubFull)); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertFalse( + PublicMethodForMultiSign.broadcastTransaction(transaction3, blockingStubFull)); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - @Test(enabled = true, description = "Add sign transaction with null address", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Add sign transaction with null address", + groups = {"daily", "multisig"}) public void test12MultiSignNormalTransactionByNullKey() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); @@ -856,12 +1087,16 @@ public void test12MultiSignNormalTransactionByNullKey() { long needCoin = updateAccountPermissionFee; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, + needCoin + 1_000_000, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); @@ -869,42 +1104,63 @@ public void test12MultiSignNormalTransactionByNullKey() { PublicMethod.printAddress(tmpKey02); ownerPermissionKeys.add(ownerKey); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner1\"," + "\"threshold\":5,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," - + "\"operations\":\"" + DEFAULT_OPERATION + "\",\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "\"operations\":\"" + + DEFAULT_OPERATION + + "\",\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.add(foundationKey); - Assert.assertEquals(3, - PublicMethodForMultiSign.getActivePermissionKeyCount(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 3, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission()); + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission()); logger.info("** trigger a normal transaction"); - Transaction transaction = PublicMethodForMultiSign - .sendcoin2(foundationAddress, 1000_000, ownerAddress, ownerKey, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoin2( + foundationAddress, 1000_000, ownerAddress, ownerKey, blockingStubFull); logger.info("transaction hex string is " + ByteArray.toHexString(transaction.toByteArray())); TransactionSignWeight txWeight = @@ -916,8 +1172,9 @@ public void test12MultiSignNormalTransactionByNullKey() { Transaction transaction1 = null; boolean ret = false; try { - transaction1 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction, null, 2, blockingStubFull); + transaction1 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction, null, 2, blockingStubFull); } catch (NullPointerException e) { logger.info("java.lang.NullPointerException"); ret = true; @@ -926,8 +1183,9 @@ public void test12MultiSignNormalTransactionByNullKey() { ret = false; try { - transaction1 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction, "", 2, blockingStubFull); + transaction1 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction, "", 2, blockingStubFull); } catch (NumberFormatException e) { logger.info("NumberFormatException: Zero length BigInteger"); ret = true; @@ -939,8 +1197,9 @@ public void test12MultiSignNormalTransactionByNullKey() { ret = false; try { - transaction1 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction, "abcd1234", 2, blockingStubFull); + transaction1 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction, "abcd1234", 2, blockingStubFull); } catch (Exception e) { logger.info("Exception!!"); ret = true; @@ -952,13 +1211,11 @@ public void test12MultiSignNormalTransactionByNullKey() { logger.info("Before broadcast TransactionSignWeight info :\n" + txWeight); Assert.assertEquals(PERMISSION_ERROR, txWeight.getResult().getCode()); Assert.assertEquals(0, txWeight.getCurrentWeight()); - Assert.assertThat(txWeight.getResult().getMessage(), - containsString("but it is not contained of permission")); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Assert.assertThat( + txWeight.getResult().getMessage(), containsString("but it is not contained of permission")); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - } @AfterMethod @@ -966,10 +1223,7 @@ public void aftertest() { PublicMethod.freeResource(ownerAddress, ownerKey, foundationAddress, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign24.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign24.java index 35fb8f62..f0b683aa 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign24.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign24.java @@ -15,24 +15,24 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class MultiSign24 extends TronBaseTest { - private static final String AVAILABLE_OPERATION - = "7fff1fc0037e0000000000000000000000000000000000000000000000000000"; - private static final String DEFAULT_OPERATION - = "7fff1fc0033e0000000000000000000000000000000000000000000000000000"; + private static final String AVAILABLE_OPERATION = + "7fff1fc0037e0000000000000000000000000000000000000000000000000000"; + private static final String DEFAULT_OPERATION = + "7fff1fc0033e0000000000000000000000000000000000000000000000000000"; private final byte[] witnessAddress001 = PublicMethod.getFinalAddress(witnessKey); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] ownerAddress = ecKey1.getAddress(); private String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -45,36 +45,46 @@ public class MultiSign24 extends TronBaseTest { private ECKey tmpEcKey02 = new ECKey(Utils.getRandom()); private byte[] tmpAddr02 = tmpEcKey02.getAddress(); private String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Broadcast multi sign normal transaction", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Broadcast multi sign normal transaction", + groups = {"daily", "multisig"}) public void test01BroadcastMultiSignNormalTransaction() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2 + multiSignFee * 2; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 100000000000L, 0, 0, + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, + needCoin + 1_000_000, + foundationAddress, + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L, + 0, + 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -84,20 +94,33 @@ public void test01BroadcastMultiSignNormalTransaction() { ownerPermissionKeys.add(ownerKey); ownerPermissionKeys.add(foundationKey); activePermissionKeys.add(ownerKey); - String accountPermissionJson = "{\"owner_permission\":{\"type\":0," - + "\"permission_name\":\"owner1\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" - + "]}]}"; - - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + String accountPermissionJson = + "{\"owner_permission\":{\"type\":0," + + "\"permission_name\":\"owner1\",\"threshold\":2,\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + + "]}]}"; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -107,65 +130,79 @@ public void test01BroadcastMultiSignNormalTransaction() { activePermissionKeys.add(witnessKey); activePermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a normal transaction"); - Transaction transaction = PublicMethodForMultiSign - .sendcoin2(foundationAddress, 1000_000, ownerAddress, ownerKey, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoin2( + foundationAddress, 1000_000, ownerAddress, ownerKey, blockingStubFull); - Transaction transaction1 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction, tmpKey02, 0, blockingStubFull); + Transaction transaction1 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction, tmpKey02, 0, blockingStubFull); - Transaction transaction2 = PublicMethodForMultiSign.addTransactionSignWithPermissionId( - transaction1, foundationKey, 0, blockingStubFull); + Transaction transaction2 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction1, foundationKey, 0, blockingStubFull); logger.info("transaction hex string is " + ByteArray.toHexString(transaction2.toByteArray())); - TransactionSignWeight txWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + TransactionSignWeight txWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("TransactionSignWeight info : " + txWeight); - Assert.assertTrue(PublicMethodForMultiSign.broadcastTransaction(transaction2, blockingStubFull)); + Assert.assertTrue( + PublicMethodForMultiSign.broadcastTransaction(transaction2, blockingStubFull)); - PublicMethodForMultiSign - .recoverAccountPermission(ownerKey, ownerPermissionKeys, blockingStubFull); + PublicMethodForMultiSign.recoverAccountPermission( + ownerKey, ownerPermissionKeys, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); txWeight = PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("TransactionSignWeight info : " + txWeight); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); - PublicMethod - .unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); - + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); } - @Test(enabled = true, description = "Broadcast single owner sign normal transaction", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Broadcast single owner sign normal transaction", + groups = {"daily", "multisig"}) public void test03BroadcastSingleSignNormalTransaction() { ECKey ecKey1 = new ECKey(Utils.getRandom()); ownerAddress = ecKey1.getAddress(); ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, needCoin + 1_000_000, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, + needCoin + 1_000_000, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); List ownerPermissionKeys = new ArrayList<>(); List activePermissionKeys = new ArrayList<>(); @@ -176,72 +213,88 @@ public void test03BroadcastSingleSignNormalTransaction() { activePermissionKeys.add(ownerKey); Integer[] ints = {ContractType.TransferContract_VALUE}; - String operations = PublicMethodForMultiSign.getOperations(ints); - String accountPermissionJson = + String operations = PublicMethodForMultiSign.getOperations(ints); + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner1\"," + "\"threshold\":1,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":3}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":3}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"" + operations + "\",\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(tmpKey02) + "\",\"weight\":1}" + + "\"operations\":\"" + + operations + + "\",\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(tmpKey02) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, - ownerAddress, ownerKey, blockingStubFull, - ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + ownerAddress, + ownerKey, + blockingStubFull, + ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]))); PublicMethod.waitProduceNextBlock(blockingStubFull); ownerPermissionKeys.add(foundationKey); activePermissionKeys.add(tmpKey02); - Assert.assertEquals(2, PublicMethodForMultiSign.getActivePermissionKeyCount( - PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList())); + Assert.assertEquals( + 2, + PublicMethodForMultiSign.getActivePermissionKeyCount( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList())); - Assert.assertEquals(2, PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission().getKeysCount()); + Assert.assertEquals( + 2, + PublicMethod.queryAccount(ownerAddress, blockingStubFull) + .getOwnerPermission() + .getKeysCount()); - PublicMethodForMultiSign.printPermissionList(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getActivePermissionList()); + PublicMethodForMultiSign.printPermissionList( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getActivePermissionList()); - System.out - .printf(PublicMethodForMultiSign.printPermission(PublicMethod.queryAccount(ownerAddress, - blockingStubFull).getOwnerPermission())); + System.out.printf( + PublicMethodForMultiSign.printPermission( + PublicMethod.queryAccount(ownerAddress, blockingStubFull).getOwnerPermission())); logger.info("** trigger a normal transaction"); - Transaction transaction = PublicMethodForMultiSign - .sendcoin2(foundationAddress, 1000_000, ownerAddress, ownerKey, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoin2( + foundationAddress, 1000_000, ownerAddress, ownerKey, blockingStubFull); - Transaction transaction1 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction, foundationKey, 0, blockingStubFull); + Transaction transaction1 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction, foundationKey, 0, blockingStubFull); - TransactionSignWeight txWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + TransactionSignWeight txWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("TransactionSignWeight info : " + txWeight); - Assert.assertTrue(PublicMethodForMultiSign.broadcastTransaction(transaction1, blockingStubFull)); + Assert.assertTrue( + PublicMethodForMultiSign.broadcastTransaction(transaction1, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1000000); - } - @AfterMethod public void aftertest() { PublicMethod.freeResource(ownerAddress, ownerKey, foundationAddress, blockingStubFull); - PublicMethod.unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign26.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign26.java index ccccf087..e1f7716c 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign26.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign26.java @@ -23,8 +23,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSign26 extends TronBaseTest { @@ -46,28 +46,29 @@ public class MultiSign26 extends TronBaseTest { private ECKey ecKey5 = new ECKey(Utils.getRandom()); byte[] test005Address = ecKey5.getAddress(); String sendAccountKey5 = ByteArray.toHexString(ecKey5.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - - /** - * constructor. - */ + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + /** constructor. */ @BeforeClass - public void beforeClass() { } - - @Test(enabled = true, description = "Sendcoin,use acticve address to sign," - + "not meet the requirements.Delete the address,broadcastTransaction.", groups = {"daily", "multisig"}) + public void beforeClass() {} + + @Test( + enabled = true, + description = + "Sendcoin,use acticve address to sign," + + "not meet the requirements.Delete the address,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_BeforeSign() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = 2 * updateAccountPermissionFee + 1; - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, amount, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -78,25 +79,33 @@ public void testMultiUpdatepermissions_BeforeSign() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); dev001Key = ByteArray.toHexString(ecKey.getPrivKeyBytes()); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = + String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" - + ":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + "\"active0\",\"threshold\":1,\"operations\"" + ":\"0100000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -109,37 +118,43 @@ public void testMultiUpdatepermissions_BeforeSign() { logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); long balance1 = test001AddressAccount1.getBalance(); Assert.assertEquals(balance - balance1, updateAccountPermissionFee); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1, test001Address, 2, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey2, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); - Assert - .assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert - .assertThat(transactionSignWeight.getResult().getMessage(), - containsString("Permission denied")); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1, test001Address, 2, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey2, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), containsString("Permission denied")); logger.info("transactionSignWeight:" + transactionSignWeight); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1, balance2); - String accountPermissionJson2 = + String accountPermissionJson2 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" - + ":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + "\"active0\",\"threshold\":1,\"operations\"" + ":\"0100000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey4) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey4) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson2, test001Address, dev001Key, - blockingStubFull, 0, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson2, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); Account test001AddressAccount3 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -149,30 +164,31 @@ public void testMultiUpdatepermissions_BeforeSign() { PublicMethodForMultiSign.printPermissionList(permissionsList3); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission3)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission3)); - final Return returnResult = PublicMethodForMultiSign - .broadcastTransaction1(transaction1, blockingStubFull); + final Return returnResult = + PublicMethodForMultiSign.broadcastTransaction1(transaction1, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); long balance3 = test001AddressAccount3.getBalance(); Assert.assertEquals(balance2 - balance3, updateAccountPermissionFee); logger.info("returnResult:"); - Assert - .assertThat(returnResult.getCode().toString(), containsString("SIGERROR")); - Assert - .assertThat(returnResult.getMessage().toStringUtf8(), - containsString("Permission denied")); - + Assert.assertThat(returnResult.getCode().toString(), containsString("SIGERROR")); + Assert.assertThat( + returnResult.getMessage().toStringUtf8(), containsString("Permission denied")); } - @Test(enabled = true, description = "Sendcoin,use acticve address to sign," - + "meet the all requirements.Delete the address,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use acticve address to sign," + + "meet the all requirements.Delete the address,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_BeforeSign_1() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = 2 * updateAccountPermissionFee + 1; - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, amount, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -183,25 +199,33 @@ public void testMultiUpdatepermissions_BeforeSign_1() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); dev001Key = ByteArray.toHexString(ecKey.getPrivKeyBytes()); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = + String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" - + ":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + "\"active0\",\"threshold\":1,\"operations\"" + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -214,47 +238,59 @@ public void testMultiUpdatepermissions_BeforeSign_1() { logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); long balance1 = test001AddressAccount1.getBalance(); Assert.assertEquals(balance - balance1, updateAccountPermissionFee); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1, test001Address, 2, dev001Key, - blockingStubFull); - final Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey2, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1, test001Address, 2, dev001Key, blockingStubFull); + final Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey2, blockingStubFull); - GrpcAPI.TransactionApprovedList transactionApprovedList = PublicMethod - .getTransactionApprovedList(transaction, blockingStubFull); + GrpcAPI.TransactionApprovedList transactionApprovedList = + PublicMethod.getTransactionApprovedList(transaction, blockingStubFull); logger.info("transactionApprovedList:" + transactionApprovedList); Assert.assertEquals(0, transactionApprovedList.getApprovedListCount()); - Assert.assertEquals(2, - transactionApprovedList.getTransaction().getTransaction().getRawData().getContract(0) - .getPermissionId()); - String accountPermissionJson2 = + Assert.assertEquals( + 2, + transactionApprovedList + .getTransaction() + .getTransaction() + .getRawData() + .getContract(0) + .getPermissionId()); + String accountPermissionJson2 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" - + ":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + "\"active0\",\"threshold\":1,\"operations\"" + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey4) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey4) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson2, test001Address, dev001Key, - blockingStubFull, 0, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson2, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); - Assert - .assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert - .assertThat(transactionSignWeight.getResult().getMessage(), - containsString("but it is not contained of permission")); - final Return returnResult = PublicMethodForMultiSign - .broadcastTransaction1(transaction1, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), + containsString("but it is not contained of permission")); + final Return returnResult = + PublicMethodForMultiSign.broadcastTransaction1(transaction1, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList2 = test001AddressAccount2.getActivePermissionList(); @@ -263,26 +299,28 @@ public void testMultiUpdatepermissions_BeforeSign_1() { PublicMethodForMultiSign.printPermissionList(permissionsList2); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission2)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission2)); - Assert - .assertThat(returnResult.getCode().toString(), containsString("SIGERROR")); - Assert - .assertThat(returnResult.getMessage().toStringUtf8(), - containsString("but it is not contained of permission")); + Assert.assertThat(returnResult.getCode().toString(), containsString("SIGERROR")); + Assert.assertThat( + returnResult.getMessage().toStringUtf8(), + containsString("but it is not contained of permission")); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1 - balance2, updateAccountPermissionFee); } - @Test(enabled = true, description = "Sendcoin,use owner address to sign," - + "Delete the address,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use owner address to sign," + "Delete the address,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_BeforeSign_2() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = 2 * updateAccountPermissionFee + 1; - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, amount, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -293,26 +331,34 @@ public void testMultiUpdatepermissions_BeforeSign_2() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); dev001Key = ByteArray.toHexString(ecKey.getPrivKeyBytes()); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); String[] permissionKeyString = new String[2]; permissionKeyString[0] = dev001Key; permissionKeyString[1] = sendAccountKey2; - String accountPermissionJson1 = + String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name" + "\":\"owner\",\"threshold\":1,\"keys\":[{" - + "\"address\":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + + "\"address\":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1,\"operations\"" + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -325,70 +371,79 @@ public void testMultiUpdatepermissions_BeforeSign_2() { logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); long balance1 = test001AddressAccount1.getBalance(); Assert.assertEquals(balance - balance1, updateAccountPermissionFee); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1, test001Address, 0, dev001Key, - blockingStubFull); - final Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey2, blockingStubFull); - String accountPermissionJson2 = + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1, test001Address, 0, dev001Key, blockingStubFull); + final Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey2, blockingStubFull); + String accountPermissionJson2 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" + ":\"owner\",\"threshold\":1,\"keys\":[{\"address" - + "\":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," + + "\":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"" + "active0\",\"threshold\":1,\"operations\":" + "\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + "\",\"weight\":1}]}]} "; String[] permissionKeyString1 = new String[1]; permissionKeyString1[0] = dev001Key; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson2, test001Address, dev001Key, - blockingStubFull, 0, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson2, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString1)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList2 = test001AddressAccount2.getActivePermissionList(); Permission ownerPermission2 = test001AddressAccount2.getOwnerPermission(); - final Permission witnessPermission2 = test001AddressAccount2.getWitnessPermission(); + final Permission witnessPermission2 = test001AddressAccount2.getWitnessPermission(); PublicMethodForMultiSign.printPermissionList(permissionsList2); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1 - balance2, updateAccountPermissionFee); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission2)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission2)); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transactionSignWeight:" + transactionSignWeight); - Assert - .assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert - .assertThat(transactionSignWeight.getResult().getMessage(), - containsString("but it is not contained of permission")); - Return returnResult = PublicMethodForMultiSign - .broadcastTransaction1(transaction1, blockingStubFull); + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), + containsString("but it is not contained of permission")); + Return returnResult = + PublicMethodForMultiSign.broadcastTransaction1(transaction1, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert - .assertThat(returnResult.getCode().toString(), containsString("SIGERROR")); - Assert - .assertThat(returnResult.getMessage().toStringUtf8(), - containsString("but it is not contained of permission")); + Assert.assertThat(returnResult.getCode().toString(), containsString("SIGERROR")); + Assert.assertThat( + returnResult.getMessage().toStringUtf8(), + containsString("but it is not contained of permission")); Account test001AddressAccount3 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance3 = test001AddressAccount3.getBalance(); Assert.assertEquals(balance2 - balance3, 0); } - @Test(enabled = true, description = "AccountPermissionUpdate transaction," - + "use owner address to sign,Delete the address,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "AccountPermissionUpdate transaction," + + "use owner address to sign,Delete the address,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_BeforeSign_3() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = 2 * updateAccountPermissionFee + 1; - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, amount, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -399,26 +454,34 @@ public void testMultiUpdatepermissions_BeforeSign_3() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); dev001Key = ByteArray.toHexString(ecKey.getPrivKeyBytes()); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); String[] permissionKeyString = new String[2]; permissionKeyString[0] = dev001Key; permissionKeyString[1] = sendAccountKey2; - String accountPermissionJson1 = + String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name" + "\":\"owner\",\"threshold\":1,\"keys\":[{" - + "\"address\":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + + "\"address\":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1,\"operations\"" + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -431,38 +494,53 @@ public void testMultiUpdatepermissions_BeforeSign_3() { logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); long balance1 = test001AddressAccount1.getBalance(); Assert.assertEquals(balance - balance1, updateAccountPermissionFee); - String accountPermissionJson3 = + String accountPermissionJson3 = "{\"owner_permission\":{\"type\":0,\"permission_name" + "\":\"owner\",\"threshold\":1,\"keys\":[{" - + "\"address\":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + + "\"address\":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1,\"operations\"" + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey4) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey4) + "\",\"weight\":1}]}]} "; - Transaction transaction = PublicMethodForMultiSign - .accountPermissionUpdateWithoutSign(accountPermissionJson3, test001Address, dev001Key, + Transaction transaction = + PublicMethodForMultiSign.accountPermissionUpdateWithoutSign( + accountPermissionJson3, + test001Address, + dev001Key, blockingStubFull, permissionKeyString); - final Transaction transaction1 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction, sendAccountKey2, 0, blockingStubFull); - String accountPermissionJson2 = + final Transaction transaction1 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction, sendAccountKey2, 0, blockingStubFull); + String accountPermissionJson2 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" + ":\"owner\",\"threshold\":1,\"keys\":[{\"address" - + "\":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," + + "\":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"" + "active0\",\"threshold\":1,\"operations\":" + "\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + "\",\"weight\":1}]}]} "; String[] permissionKeyString1 = new String[1]; permissionKeyString1[0] = dev001Key; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson2, test001Address, dev001Key, - blockingStubFull, 0, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson2, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString1)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -475,40 +553,41 @@ public void testMultiUpdatepermissions_BeforeSign_3() { logger.info(PublicMethodForMultiSign.printPermission(witnessPermission2)); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1 - balance2, updateAccountPermissionFee); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transactionSignWeight:" + transactionSignWeight); - Assert - .assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert - .assertThat(transactionSignWeight.getResult().getMessage(), - containsString("but it is not contained of permission")); - Return returnResult = PublicMethodForMultiSign - .broadcastTransaction1(transaction1, blockingStubFull); + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), + containsString("but it is not contained of permission")); + Return returnResult = + PublicMethodForMultiSign.broadcastTransaction1(transaction1, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert - .assertThat(returnResult.getCode().toString(), containsString("SIGERROR")); - Assert - .assertThat(returnResult.getMessage().toStringUtf8(), - containsString("but it is not contained of permission")); + Assert.assertThat(returnResult.getCode().toString(), containsString("SIGERROR")); + Assert.assertThat( + returnResult.getMessage().toStringUtf8(), + containsString("but it is not contained of permission")); Account test001AddressAccount3 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance3 = test001AddressAccount3.getBalance(); Assert.assertEquals(balance2 - balance3, 0); } - @Test(enabled = true, description = "Sendcoin,Delete the owner address," - + "use the address to sign,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,Delete the owner address," + "use the address to sign,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_AfterSign() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = 2 * updateAccountPermissionFee + 1; - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, amount, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -519,25 +598,33 @@ public void testMultiUpdatepermissions_AfterSign() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); dev001Key = ByteArray.toHexString(ecKey.getPrivKeyBytes()); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = + String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" - + ":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + "\"active0\",\"threshold\":1,\"operations\"" + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -551,23 +638,31 @@ public void testMultiUpdatepermissions_AfterSign() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); logger.info("1-----------------------"); - final Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1, test001Address, 0, dev001Key, - blockingStubFull); - String accountPermissionJson2 = + final Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1, test001Address, 0, dev001Key, blockingStubFull); + String accountPermissionJson2 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" - + ":\"" + PublicMethod.getAddressString(sendAccountKey2) + "\",\"weight\":1}]}," + + ":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + "\"active0\",\"threshold\":1,\"operations\"" + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey4) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey4) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson2, test001Address, dev001Key, - blockingStubFull, 0, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson2, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -581,34 +676,36 @@ public void testMultiUpdatepermissions_AfterSign() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission2)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission2)); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, dev001Key, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); - Assert - .assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert - .assertThat(transactionSignWeight.getResult().getMessage(), - containsString("but it is not contained of permission")); - Assert - .assertFalse(PublicMethodForMultiSign.broadcastTransaction(transaction1, blockingStubFull)); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, dev001Key, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), + containsString("but it is not contained of permission")); + Assert.assertFalse( + PublicMethodForMultiSign.broadcastTransaction(transaction1, blockingStubFull)); Account test001AddressAccount3 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance3 = test001AddressAccount3.getBalance(); Assert.assertEquals(balance2 - balance3, 0); - } - @Test(enabled = true, description = "AccountPermissionUpdate transaction," - + "Delete the owner address,use the address to sign,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "AccountPermissionUpdate transaction," + + "Delete the owner address,use the address to sign,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_AfterSign_4() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = 3 * updateAccountPermissionFee + 1; - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, amount, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -619,25 +716,33 @@ public void testMultiUpdatepermissions_AfterSign_4() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); dev001Key = ByteArray.toHexString(ecKey.getPrivKeyBytes()); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = + String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" - + ":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + "\"active0\",\"threshold\":1,\"operations\"" + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -650,35 +755,50 @@ public void testMultiUpdatepermissions_AfterSign_4() { Permission witnessPermission1 = test001AddressAccount1.getWitnessPermission(); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - String accountPermissionJson3 = + String accountPermissionJson3 = "{\"owner_permission\":{\"type\":0,\"permission_name" + "\":\"owner\",\"threshold\":1,\"keys\":[{" - + "\"address\":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + + "\"address\":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1,\"operations\"" + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey4) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey4) + "\",\"weight\":1}]}]} "; - final Transaction transaction = PublicMethodForMultiSign - .accountPermissionUpdateWithoutSign(accountPermissionJson3, test001Address, dev001Key, + final Transaction transaction = + PublicMethodForMultiSign.accountPermissionUpdateWithoutSign( + accountPermissionJson3, + test001Address, + dev001Key, blockingStubFull, permissionKeyString); - String accountPermissionJson2 = + String accountPermissionJson2 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" - + ":\"" + PublicMethod.getAddressString(sendAccountKey2) + "\",\"weight\":1}]}," + + ":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + "\"active0\",\"threshold\":1,\"operations\"" + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey4) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey4) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson2, test001Address, dev001Key, - blockingStubFull, 0, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson2, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -691,18 +811,18 @@ public void testMultiUpdatepermissions_AfterSign_4() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission2)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission2)); - Transaction transaction1 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction, dev001Key, 0, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); - Assert - .assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert - .assertThat(transactionSignWeight.getResult().getMessage(), - containsString("but it is not contained of permission")); - Assert - .assertFalse(PublicMethodForMultiSign.broadcastTransaction(transaction1, blockingStubFull)); + Transaction transaction1 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction, dev001Key, 0, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), + containsString("but it is not contained of permission")); + Assert.assertFalse( + PublicMethodForMultiSign.broadcastTransaction(transaction1, blockingStubFull)); Account test001AddressAccount3 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance3 = test001AddressAccount3.getBalance(); @@ -714,11 +834,7 @@ public void aftertest() { PublicMethod.freeResource(test001Address, dev001Key, foundationAddress, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign27.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign27.java index 81d35947..a0931b0e 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign27.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign27.java @@ -19,8 +19,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSign27 extends TronBaseTest { @@ -39,21 +39,22 @@ public class MultiSign27 extends TronBaseTest { private ECKey ecKey5 = new ECKey(Utils.getRandom()); byte[] test005Address = ecKey5.getAddress(); String sendAccountKey5 = ByteArray.toHexString(ecKey5.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - - /** - * constructor. - */ + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + /** constructor. */ @BeforeClass - public void beforeClass() { } - - @Test(enabled = true, description = "Sendcoin,use active address sign, meet all requirements." - + "Then use permissionID not same in activelist address to sign," - + "not meet the requirements,broadcastTransaction.", groups = {"daily", "multisig"}) + public void beforeClass() {} + + @Test( + enabled = true, + description = + "Sendcoin,use active address sign, meet all requirements." + + "Then use permissionID not same in activelist address to sign," + + "not meet the requirements,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_3() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); @@ -61,7 +62,8 @@ public void testMultiUpdatepermissions_3() { long amount = updateAccountPermissionFee + 1; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -69,29 +71,39 @@ public void testMultiUpdatepermissions_3() { Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); PublicMethodForMultiSign.printPermissionList(permissionsList); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":" - + "\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + ":\"" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations" - + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}]}," - + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations" - + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]}"; - - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":" + + "\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations" + + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}]}," + + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations" + + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]}"; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList1 = test001AddressAccount1.getActivePermissionList(); @@ -103,42 +115,49 @@ public void testMultiUpdatepermissions_3() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 2, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey2, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 2, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey2, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, sendAccountKey3, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, sendAccountKey3, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("Signature count is 2 more than key counts of permission : 1")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert.assertThat(returnResult1.getMessage().toStringUtf8(), + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("Signature count is 2 more than key counts of permission : 1")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1, balance2); } - @Test(enabled = true, description = "Sendcoin,use active address sign, not meet the requirements." - + "Then use permissionID not same in activelist address to sign," - + "not meet the requirements,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use active address sign, not meet the requirements." + + "Then use permissionID not same in activelist address to sign," + + "not meet the requirements,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_4() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); @@ -146,36 +165,47 @@ public void testMultiUpdatepermissions_4() { long amount = updateAccountPermissionFee + 1; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); PublicMethodForMultiSign.printPermissionList(permissionsList); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":" - + "\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + ":\"" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations" - + "\":\"0100000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}]}," - + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations" - + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]}"; - - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":" + + "\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations" + + "\":\"0100000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}]}," + + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations" + + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]}"; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -187,44 +217,49 @@ public void testMultiUpdatepermissions_4() { logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); long balance1 = test001AddressAccount1.getBalance(); Assert.assertEquals(balance - balance1, updateAccountPermissionFee); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1, test001Address, 2, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey2, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1, test001Address, 2, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey2, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Assert.assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight.getResult().getMessage(), - containsString("Permission denied")); - - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, sendAccountKey3, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), containsString("Permission denied")); + + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, sendAccountKey3, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), - containsString("Permission denied")); + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("Permission denied")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert - .assertThat(returnResult1.getMessage().toStringUtf8(), containsString("Permission denied")); + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("Permission denied")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1, balance2); } - @Test(enabled = true, description = "Sendcoin,use active address sign, meet all requirements." - + "Then use permissionID not same in activelist address to sign," - + "meet all requirements,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use active address sign, meet all requirements." + + "Then use permissionID not same in activelist address to sign," + + "meet all requirements,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_6() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); @@ -232,7 +267,8 @@ public void testMultiUpdatepermissions_6() { long amount = updateAccountPermissionFee + 1; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -242,26 +278,36 @@ public void testMultiUpdatepermissions_6() { PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":" - + "\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + ":\"" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations" - + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}]}," - + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations" - + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]}"; - - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":" + + "\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations" + + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}]}," + + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations" + + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]}"; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -273,41 +319,49 @@ public void testMultiUpdatepermissions_6() { logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); long balance1 = test001AddressAccount1.getBalance(); Assert.assertEquals(balance - balance1, updateAccountPermissionFee); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1, test001Address, 3, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey3, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1, test001Address, 3, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey3, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Transaction transaction2 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction1, sendAccountKey2, 2, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Transaction transaction2 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction1, sendAccountKey2, 2, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("Signature count is 2 more than key counts of permission : 1")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert.assertThat(returnResult1.getMessage().toStringUtf8(), + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("Signature count is 2 more than key counts of permission : 1")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1, balance2); } - @Test(enabled = true, description = "Sendcoin,use owner address sign, meet all requirements." - + "Then use not in permissionlist address to sign," - + "not meet the requirements,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use owner address sign, meet all requirements." + + "Then use not in permissionlist address to sign," + + "not meet the requirements,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_7() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); @@ -315,7 +369,8 @@ public void testMultiUpdatepermissions_7() { long amount = updateAccountPermissionFee + 1; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -325,23 +380,34 @@ public void testMultiUpdatepermissions_7() { PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" - + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + ":\"" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations\"" - + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\"" + + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations\"" + + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -353,41 +419,49 @@ public void testMultiUpdatepermissions_7() { logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); long balance1 = test001AddressAccount1.getBalance(); Assert.assertEquals(balance - balance1, updateAccountPermissionFee); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 0, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, dev001Key, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 0, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, dev001Key, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, sendAccountKey4, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, sendAccountKey4, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("Signature count is 2 more than key counts of permission : 1")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert.assertThat(returnResult1.getMessage().toStringUtf8(), + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("Signature count is 2 more than key counts of permission : 1")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1, balance2); } - @Test(enabled = true, description = "Sendcoin,use owner address sign, meet all requirements." - + "Then use in active address to sign,not meet the requirements,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use owner address sign, meet all requirements." + + "Then use in active address to sign," + + "not meet the requirements,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_8() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); @@ -395,7 +469,8 @@ public void testMultiUpdatepermissions_8() { long amount = updateAccountPermissionFee + 1; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -405,23 +480,34 @@ public void testMultiUpdatepermissions_8() { PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" - + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + ":\"" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations\"" - + ":\"0100000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\"" + + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations\"" + + ":\"0100000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -433,41 +519,47 @@ public void testMultiUpdatepermissions_8() { logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); long balance1 = test001AddressAccount1.getBalance(); Assert.assertEquals(balance - balance1, updateAccountPermissionFee); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 0, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, dev001Key, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 0, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, dev001Key, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Transaction transaction2 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction1, sendAccountKey2, 2, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Transaction transaction2 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction1, sendAccountKey2, 2, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), - containsString("Permission denied")); + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("Permission denied")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert - .assertThat(returnResult1.getMessage().toStringUtf8(), containsString("Permission denied")); + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("Permission denied")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1, balance2); } - @Test(enabled = true, description = "Sendcoin,use owner address sign, meet all requirements." - + "Then use in active address to sign, meet all requirements,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use owner address sign, meet all requirements." + + "Then use in active address to sign, meet all requirements,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_9() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); @@ -475,7 +567,8 @@ public void testMultiUpdatepermissions_9() { long amount = updateAccountPermissionFee + 1; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -485,23 +578,34 @@ public void testMultiUpdatepermissions_9() { PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" - + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + ":\"" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations\"" - + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\"" + + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations\"" + + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList1 = test001AddressAccount1.getActivePermissionList(); @@ -512,33 +616,37 @@ public void testMultiUpdatepermissions_9() { logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); long balance1 = test001AddressAccount1.getBalance(); Assert.assertEquals(balance - balance1, updateAccountPermissionFee); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1, test001Address, 0, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, dev001Key, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1, test001Address, 0, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, dev001Key, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Transaction transaction2 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction1, sendAccountKey2, 2, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Transaction transaction2 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction1, sendAccountKey2, 2, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("but it is not contained of permission")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert.assertThat(returnResult1.getMessage().toStringUtf8(), + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("but it is not contained of permission")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); @@ -550,11 +658,7 @@ public void aftertest() { PublicMethod.freeResource(test001Address, dev001Key, foundationAddress, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign28.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign28.java index 1ca1f2d9..621b85da 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign28.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign28.java @@ -19,8 +19,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSign28 extends TronBaseTest { @@ -39,29 +39,29 @@ public class MultiSign28 extends TronBaseTest { private ECKey ecKey5 = new ECKey(Utils.getRandom()); byte[] test005Address = ecKey5.getAddress(); String sendAccountKey5 = ByteArray.toHexString(ecKey5.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - - /** - * constructor. - */ + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + /** constructor. */ @BeforeClass - public void beforeClass() { } - - - @Test(enabled = true, description = - "Sendcoin permission id 2,use not in permissionlist address sign." - + "Then use in active address permission id 2 to sign ,broadcastTransaction.", groups = {"daily", "multisig"}) + public void beforeClass() {} + + @Test( + enabled = true, + description = + "Sendcoin permission id 2,use not in permissionlist address sign." + + "Then use in active address permission id 2 to sign ,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_10() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -69,26 +69,37 @@ public void testMultiUpdatepermissions_10() { Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); PublicMethodForMultiSign.printPermissionList(permissionsList); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); dev001Key = ByteArray.toHexString(ecKey.getPrivKeyBytes()); String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" - + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + ":\"" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations\"" - + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\"" + + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations\"" + + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -102,56 +113,63 @@ public void testMultiUpdatepermissions_10() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 2, dev001Key, - blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 2, dev001Key, blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey4, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey4, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Assert.assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight.getResult().getMessage(), + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), containsString("but it is not contained of permission")); - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, sendAccountKey2, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, sendAccountKey2, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("but it is not contained of permission")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert.assertThat(returnResult1.getMessage().toStringUtf8(), + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("but it is not contained of permission")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1, balance2); - } - @Test(enabled = true, description = - "Sendcoin permission id 2,use not in permissionlist address sign." - + "Then use in active address to sign,no right to sendcoin,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin permission id 2,use not in permissionlist address sign." + + "Then use in active address to sign,no right to sendcoin,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_11() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -159,7 +177,7 @@ public void testMultiUpdatepermissions_11() { Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); PublicMethodForMultiSign.printPermissionList(permissionsList); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -167,19 +185,30 @@ public void testMultiUpdatepermissions_11() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" - + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + ":\"" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations\"" - + ":\"0100000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\"" + + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations\"" + + ":\"0100000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -192,59 +221,64 @@ public void testMultiUpdatepermissions_11() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 2, dev001Key, - blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 2, dev001Key, blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey4, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey4, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Assert.assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight.getResult().getMessage(), - containsString("Permission denied")); - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, sendAccountKey2, blockingStubFull); - - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), containsString("Permission denied")); + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, sendAccountKey2, blockingStubFull); + + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), - containsString("Permission denied")); + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("Permission denied")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert - .assertThat(returnResult1.getMessage().toStringUtf8(), containsString("Permission denied")); + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("Permission denied")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); logger.info("balance2:" + balance2); Assert.assertEquals(balance1, balance2); - } - @Test(enabled = true, description = "Sendcoin permission id 2" - + ",use active address in permission id 3 sign." - + "Then use active address in permission id 2to sign.broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin permission id 2" + + ",use active address in permission id 3 sign." + + "Then use active address in permission id 2to sign.broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_12() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -252,29 +286,39 @@ public void testMultiUpdatepermissions_12() { Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); PublicMethodForMultiSign.printPermissionList(permissionsList); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); dev001Key = ByteArray.toHexString(ecKey.getPrivKeyBytes()); String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":" - + "\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + ":\"" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations" - + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}]}," - + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations" - + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]}"; - - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":" + + "\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations" + + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}]}," + + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations" + + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]}"; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList1 = test001AddressAccount1.getActivePermissionList(); @@ -286,52 +330,60 @@ public void testMultiUpdatepermissions_12() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 2, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey3, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 2, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey3, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Assert.assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight.getResult().getMessage(), + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), containsString("but it is not contained of permission")); - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, sendAccountKey2, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, sendAccountKey2, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("Signature count is 2 more than key counts of permission : 1")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert.assertThat(returnResult1.getMessage().toStringUtf8(), + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("Signature count is 2 more than key counts of permission : 1")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1, balance2); } - @Test(enabled = true, description = "Sendcoin,use active address sign, meet all requirements." - + "sum weight > threshold", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use active address sign, meet all requirements." + "sum weight > threshold", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_13() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + multiSignFee + 1; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -347,48 +399,59 @@ public void testMultiUpdatepermissions_13() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" - + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + ":\"" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations\"" - + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\"" + + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations\"" + + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList1 = test001AddressAccount1.getActivePermissionList(); Permission ownerPermission1 = test001AddressAccount1.getOwnerPermission(); Permission witnessPermission1 = test001AddressAccount1.getWitnessPermission(); PublicMethodForMultiSign.printPermissionList(permissionsList1); - final long balance1 = test001AddressAccount1.getBalance(); + final long balance1 = test001AddressAccount1.getBalance(); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 2, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey3, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 2, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey3, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, sendAccountKey2, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, sendAccountKey2, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("returnResult1:" + returnResult1); @@ -396,19 +459,22 @@ public void testMultiUpdatepermissions_13() { Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1 - balance2, multiSignFee + 1); - - } - @Test(enabled = true, description = "Sendcoin,use active address sign, meet all requirements." - + "Then use permissionId not same in active address to sign,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use active address sign, meet all requirements." + + "Then use permissionId not same in active address to sign,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_14() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -416,7 +482,7 @@ public void testMultiUpdatepermissions_14() { Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); PublicMethodForMultiSign.printPermissionList(permissionsList); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -424,21 +490,31 @@ public void testMultiUpdatepermissions_14() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":" - + "\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + ":\"" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations" - + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}]}," - + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations" - + "\":\"0100000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":" + + "\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations" + + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}]}," + + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations" + + "\":\"0100000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]}"; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -451,51 +527,60 @@ public void testMultiUpdatepermissions_14() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 2, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey2, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 2, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey2, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Assert.assertThat(transactionSignWeight.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("ENOUGH_PERMISSION")); - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, sendAccountKey3, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, sendAccountKey3, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("Signature count is 2 more than key counts of permission : 1")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert.assertThat(returnResult1.getMessage().toStringUtf8(), + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("Signature count is 2 more than key counts of permission : 1")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1, balance2); } - @Test(enabled = true, description = "Sendcoin,use active address sign, not meet the requirements." - + "Then use permissionId not same active address to sign,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use active address sign, not meet the requirements." + + "Then use permissionId not same active address to sign,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_15() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -503,28 +588,38 @@ public void testMultiUpdatepermissions_15() { Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); PublicMethodForMultiSign.printPermissionList(permissionsList); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); dev001Key = ByteArray.toHexString(ecKey.getPrivKeyBytes()); String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":" - + "\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + ":\"" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations" - + "\":\"0100000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}]}," - + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations" - + "\":\"0100000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":" + + "\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations" + + "\":\"0100000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}]}," + + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations" + + "\":\"0100000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]}"; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -536,60 +631,65 @@ public void testMultiUpdatepermissions_15() { logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); long balance1 = test001AddressAccount1.getBalance(); Assert.assertEquals(balance - balance1, updateAccountPermissionFee); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 2, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey3, blockingStubFull); - - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 2, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey3, blockingStubFull); + + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Assert.assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight.getResult().getMessage(), - containsString("Permission denied")); - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, sendAccountKey2, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), containsString("Permission denied")); + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, sendAccountKey2, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), - containsString("Permission denied")); + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("Permission denied")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert - .assertThat(returnResult1.getMessage().toStringUtf8(), containsString("Permission denied")); + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("Permission denied")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1, balance2); } - @Test(enabled = true, description = - "Sendcoin,use not in permissionlist address sign," - + "Then use owner address to sign,meet all requirements,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use not in permissionlist address sign," + + "Then use owner address to sign,meet all requirements,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_16() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -597,19 +697,30 @@ public void testMultiUpdatepermissions_16() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" - + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + ":\"" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations\"" - + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\"" + + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations\"" + + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -622,60 +733,68 @@ public void testMultiUpdatepermissions_16() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 0, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey4, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 0, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey4, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Assert.assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight.getResult().getMessage(), + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), containsString("but it is not contained of permission")); - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, dev001Key, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, dev001Key, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("Signature count is 2 more than key counts of permission : 1")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert.assertThat(returnResult1.getMessage().toStringUtf8(), + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("Signature count is 2 more than key counts of permission : 1")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1, balance2); } - @Test(enabled = true, description = - "Sendcoin,use not in permissionlist address sign, meet all requirements." - + "Then use owner address to sign,,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use not in permissionlist address sign, meet all requirements." + + "Then use owner address to sign,,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_17() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -683,19 +802,30 @@ public void testMultiUpdatepermissions_17() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" - + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + ":\"" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations\"" - + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\"" + + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations\"" + + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -708,58 +838,67 @@ public void testMultiUpdatepermissions_17() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1, test001Address, 2, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey4, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1, test001Address, 2, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey4, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Assert.assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight.getResult().getMessage(), + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), containsString("but it is not contained of permission")); - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, dev001Key, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, dev001Key, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("but it is not contained of permission")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert.assertThat(returnResult1.getMessage().toStringUtf8(), + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("but it is not contained of permission")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1, balance2); } - @Test(enabled = true, description = "Sendcoin permission id 2" - + ",use active address sign, meet all requirements." - + "Then use owner address to sign,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin permission id 2" + + ",use active address sign, meet all requirements." + + "Then use owner address to sign,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_18() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -767,19 +906,30 @@ public void testMultiUpdatepermissions_18() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" - + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + ":\"" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations\"" - + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\"" + + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations\"" + + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -792,50 +942,58 @@ public void testMultiUpdatepermissions_18() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 2, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey2, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 2, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey2, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, dev001Key, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, dev001Key, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("but it is not contained of permission")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert.assertThat(returnResult1.getMessage().toStringUtf8(), + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("but it is not contained of permission")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1, balance2); } - @Test(enabled = true, description = "Sendcoin permission id 2" - + ",use active address sign, meet all requirements." - + "Then use owner address to sign with permission id 0,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin permission id 2" + + ",use active address sign, meet all requirements." + + "Then use owner address to sign with permission id 0,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_19() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -843,7 +1001,7 @@ public void testMultiUpdatepermissions_19() { Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); PublicMethodForMultiSign.printPermissionList(permissionsList); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -851,19 +1009,30 @@ public void testMultiUpdatepermissions_19() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" - + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + ":\"" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations\"" - + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\"" + + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations\"" + + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -876,49 +1045,58 @@ public void testMultiUpdatepermissions_19() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 2, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey2, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 2, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey2, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Transaction transaction2 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction1, dev001Key, 0, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Transaction transaction2 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction1, dev001Key, 0, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("Signature count is 2 more than key counts of permission : 1")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert.assertThat(returnResult1.getMessage().toStringUtf8(), + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("Signature count is 2 more than key counts of permission : 1")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1, balance2); } - @Test(enabled = true, description = "Sendcoin permission id 2,use owner address sign." - + "Then use active address to sign, meet permission id.broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin permission id 2,use owner address sign." + + "Then use active address to sign, meet permission id.broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_20() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -934,19 +1112,30 @@ public void testMultiUpdatepermissions_20() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" - + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + ":\"" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations\"" - + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\"" + + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations\"" + + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -954,55 +1143,64 @@ public void testMultiUpdatepermissions_20() { Permission ownerPermission1 = test001AddressAccount1.getOwnerPermission(); Permission witnessPermission1 = test001AddressAccount1.getWitnessPermission(); PublicMethodForMultiSign.printPermissionList(permissionsList1); - final long balance1 = test001AddressAccount1.getBalance(); + final long balance1 = test001AddressAccount1.getBalance(); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 2, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, dev001Key, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 2, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, dev001Key, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Transaction transaction2 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction1, sendAccountKey2, 2, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Transaction transaction2 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction1, sendAccountKey2, 2, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("but it is not contained of permission")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert.assertThat(returnResult1.getMessage().toStringUtf8(), + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("but it is not contained of permission")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1, balance2); } - @Test(enabled = true, description = "Sendcoin permission id 2" - + ",use not in permissionlist address sign." - + "Then use owner address to sign,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin permission id 2" + + ",use not in permissionlist address sign." + + "Then use owner address to sign,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_21() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -1010,7 +1208,7 @@ public void testMultiUpdatepermissions_21() { Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); PublicMethodForMultiSign.printPermissionList(permissionsList); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -1018,19 +1216,30 @@ public void testMultiUpdatepermissions_21() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" - + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + ":\"" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations\"" - + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\"" + + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations\"" + + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -1043,34 +1252,38 @@ public void testMultiUpdatepermissions_21() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 2, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey4, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 2, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey4, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Transaction transaction2 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction1, dev001Key, 2, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Transaction transaction2 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction1, dev001Key, 2, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("but it is not contained of permission")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert.assertThat(returnResult1.getMessage().toStringUtf8(), + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("but it is not contained of permission")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); @@ -1082,12 +1295,7 @@ public void aftertest() { PublicMethod.freeResource(test001Address, dev001Key, foundationAddress, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign29.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign29.java index 7197a190..d653ccb9 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign29.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign29.java @@ -19,12 +19,13 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class MultiSign29 extends TronBaseTest { private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); +public class MultiSign29 extends TronBaseTest { + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); private ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] test001Address = ecKey1.getAddress(); @@ -41,35 +42,36 @@ public class MultiSign29 extends TronBaseTest { private final String testKey003 private ECKey ecKey5 = new ECKey(Utils.getRandom()); byte[] test005Address = ecKey5.getAddress(); String sendAccountKey5 = ByteArray.toHexString(ecKey5.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - - /** - * constructor. - */ + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + /** constructor. */ @BeforeClass - public void beforeClass() { } - - - @Test(enabled = true, description = "Sendcoin,use active address sign, not meet the requirements." - + "Then use permissionID same in active address to sign,broadcastTransaction.", groups = {"daily", "multisig"}) + public void beforeClass() {} + + @Test( + enabled = true, + description = + "Sendcoin,use active address sign, not meet the requirements." + + "Then use permissionID same in active address to sign,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_23() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 2000000; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -77,18 +79,29 @@ public void testMultiUpdatepermissions_23() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"" - + "owner\",\"threshold\":1,\"keys\":[{\"address\":\"" + "" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name" - + "\":\"active0\",\"threshold\":1,\"operations\":\"" - + "0100000000000000000000000000000000000000000000000000000000000000\"" - + ",\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + "\"," - + "\"weight\":1},{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":\"" + + "owner\",\"threshold\":1,\"keys\":[{\"address\":\"" + + "" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name" + + "\":\"active0\",\"threshold\":1,\"operations\":\"" + + "0100000000000000000000000000000000000000000000000000000000000000\"" + + ",\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\"," + + "\"weight\":1},{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList1 = test001AddressAccount1.getActivePermissionList(); @@ -100,57 +113,63 @@ public void testMultiUpdatepermissions_23() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 2, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey2, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 2, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey2, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Assert.assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight.getResult().getMessage(), - containsString("Permission denied")); - - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, sendAccountKey3, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), containsString("Permission denied")); + + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, sendAccountKey3, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); logger.info("transaction:" + transactionSignWeight); - Assert.assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight.getResult().getMessage(), - containsString("Permission denied")); + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), containsString("Permission denied")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert.assertThat(returnResult1.getMessage().toStringUtf8(), + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("Validate signature error: Permission denied")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1, balance2); } - @Test(enabled = true, description = "Sendcoin with permission id 0,use owner address sign," - + "Then use owner address to sign, sum weight > threshold,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin with permission id 0,use owner address sign," + + "Then use owner address to sign, sum weight > threshold,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_24() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 2000000; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -158,18 +177,29 @@ public void testMultiUpdatepermissions_24() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":" - + "\"owner\",\"threshold\":1,\"keys\":[{\"address\":" + "\"" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod - .getAddressString(sendAccountKey2) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," - + "\"threshold\":1,\"operations\":" - + "\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":" + + "\"owner\",\"threshold\":1,\"keys\":[{\"address\":" + + "\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + + "\"threshold\":1,\"operations\":" + + "\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -182,48 +212,51 @@ public void testMultiUpdatepermissions_24() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 0, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey2, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 0, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey2, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, dev001Key, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, dev001Key, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertTrue(returnResult1.getResult()); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1 - balance2, multiSignFee + 1); - } - - @Test(enabled = true, description = "Sendcoin,use active address sign, not meet the requirements." - + "Then use owner address to sign, not meet the requirements,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use active address sign, not meet the requirements." + + "Then use owner address to sign, not meet the requirements,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_25() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1000000; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -231,18 +264,29 @@ public void testMultiUpdatepermissions_25() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"" - + "owner\",\"threshold\":1,\"keys\":[{\"address\":\"" + "" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name" - + "\":\"active0\",\"threshold\":1,\"operations\":\"" - + "0100000000000000000000000000000000000000000000000000000000000000\"" - + ",\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + "\"," - + "\"weight\":1},{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":\"" + + "owner\",\"threshold\":1,\"keys\":[{\"address\":\"" + + "" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name" + + "\":\"active0\",\"threshold\":1,\"operations\":\"" + + "0100000000000000000000000000000000000000000000000000000000000000\"" + + ",\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\"," + + "\"weight\":1},{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -255,35 +299,37 @@ public void testMultiUpdatepermissions_25() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 2, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey2, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 2, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey2, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Assert.assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight.getResult().getMessage(), - containsString("Permission denied")); - - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, dev001Key, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), containsString("Permission denied")); + + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, dev001Key, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), - containsString("Permission denied")); + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("Permission denied")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert.assertThat(returnResult1.getMessage().toStringUtf8(), + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("Validate signature error: Permission denied")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -291,23 +337,27 @@ public void testMultiUpdatepermissions_25() { Assert.assertEquals(balance1, balance2); } - - @Test(enabled = true, description = "Sendcoin,use active address sign, not meet the requirements." - + "Then use owner address to sign with permission id 0,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use active address sign, not meet the requirements." + + "Then use owner address to sign with permission id 0,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_27() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1000000; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -315,18 +365,29 @@ public void testMultiUpdatepermissions_27() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"" - + "owner\",\"threshold\":1,\"keys\":[{\"address\":\"" + "" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name" - + "\":\"active0\",\"threshold\":1,\"operations\":\"" - + "0100000000000000000000000000000000000000000000000000000000000000\"" - + ",\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + "\"," - + "\"weight\":1},{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":\"" + + "owner\",\"threshold\":1,\"keys\":[{\"address\":\"" + + "" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name" + + "\":\"active0\",\"threshold\":1,\"operations\":\"" + + "0100000000000000000000000000000000000000000000000000000000000000\"" + + ",\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\"," + + "\"weight\":1},{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -339,57 +400,65 @@ public void testMultiUpdatepermissions_27() { Permission witnessPermission1 = test001AddressAccount1.getWitnessPermission(); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 2, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey2, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 2, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey2, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Assert.assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight.getResult().getMessage(), - containsString("Permission denied")); - - Transaction transaction2 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction1, dev001Key, 0, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), containsString("Permission denied")); + + Transaction transaction2 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction1, dev001Key, 0, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("Signature count is 2 more than key counts of permission : 1")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert.assertThat(returnResult1.getMessage().toStringUtf8(), + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("Signature count is 2 more than key counts of permission : 1")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1, balance2); } - - @Test(enabled = true, description = "Sendcoin,use active address sign,meet all requirements." - + "Then use owner address to sign with permission id 0,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use active address sign,meet all requirements." + + "Then use owner address to sign with permission id 0,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_28() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1000000; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -397,18 +466,29 @@ public void testMultiUpdatepermissions_28() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"" - + "owner\",\"threshold\":1,\"keys\":[{\"address\":\"" + "" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name" - + "\":\"active0\",\"threshold\":1,\"operations\":\"" - + "0200000000000000000000000000000000000000000000000000000000000000\"" - + ",\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + "\"," - + "\"weight\":1},{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":\"" + + "owner\",\"threshold\":1,\"keys\":[{\"address\":\"" + + "" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name" + + "\":\"active0\",\"threshold\":1,\"operations\":\"" + + "0200000000000000000000000000000000000000000000000000000000000000\"" + + ",\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\"," + + "\"weight\":1},{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -421,51 +501,60 @@ public void testMultiUpdatepermissions_28() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 2, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey2, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 2, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey2, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Transaction transaction2 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction1, dev001Key, 0, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Transaction transaction2 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction1, dev001Key, 0, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("Signature count is 2 more than key counts of permission : 1")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert.assertThat(returnResult1.getMessage().toStringUtf8(), + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("Signature count is 2 more than key counts of permission : 1")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1, balance2); } - @Test(enabled = true, description = "Sendcoin,use owner address sign, meet all requirements." - + "Then use active address to sign no permission id,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use owner address sign, meet all requirements." + + "Then use active address to sign no permission id,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_29() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1000000; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -473,18 +562,29 @@ public void testMultiUpdatepermissions_29() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"" - + "owner\",\"threshold\":1,\"keys\":[{\"address\":\"" + "" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name" - + "\":\"active0\",\"threshold\":1,\"operations\":\"" - + "0200000000000000000000000000000000000000000000000000000000000000\"" - + ",\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + "\"," - + "\"weight\":1},{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":\"" + + "owner\",\"threshold\":1,\"keys\":[{\"address\":\"" + + "" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name" + + "\":\"active0\",\"threshold\":1,\"operations\":\"" + + "0200000000000000000000000000000000000000000000000000000000000000\"" + + ",\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\"," + + "\"weight\":1},{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -497,52 +597,60 @@ public void testMultiUpdatepermissions_29() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 0, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, dev001Key, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 0, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, dev001Key, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, sendAccountKey2, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, sendAccountKey2, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("Signature count is 2 more than key counts of permission : 1")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert.assertThat(returnResult1.getMessage().toStringUtf8(), + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("Signature count is 2 more than key counts of permission : 1")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1, balance2); } - @Test(enabled = true, description = "Sendcoin,use owner address sign, meet all requirements." - + "Then use active address to sign with permission id 2,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use owner address sign, meet all requirements." + + "Then use active address to sign with permission id 2,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_30() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1000000; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -550,18 +658,29 @@ public void testMultiUpdatepermissions_30() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"" - + "owner\",\"threshold\":1,\"keys\":[{\"address\":\"" + "" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name" - + "\":\"active0\",\"threshold\":1,\"operations\":\"" - + "0200000000000000000000000000000000000000000000000000000000000000\"" - + ",\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + "\"," - + "\"weight\":1},{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":\"" + + "owner\",\"threshold\":1,\"keys\":[{\"address\":\"" + + "" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name" + + "\":\"active0\",\"threshold\":1,\"operations\":\"" + + "0200000000000000000000000000000000000000000000000000000000000000\"" + + ",\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\"," + + "\"weight\":1},{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -574,30 +693,34 @@ public void testMultiUpdatepermissions_30() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 0, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, dev001Key, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 0, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, dev001Key, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Transaction transaction2 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction1, sendAccountKey3, 2, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Transaction transaction2 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction1, sendAccountKey3, 2, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("but it is not contained of permission")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert.assertThat(returnResult1.getMessage().toStringUtf8(), + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("but it is not contained of permission")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -605,17 +728,12 @@ public void testMultiUpdatepermissions_30() { Assert.assertEquals(balance1, balance2); } - /** - * constructor. - */ - + /** constructor. */ @AfterMethod public void aftertest() { PublicMethod.freeResource(test001Address, dev001Key, foundationAddress, blockingStubFull); } @AfterClass - public void shutdown() throws InterruptedException { } - - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign30.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign30.java index 31c7dfbd..5f542c37 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign30.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign30.java @@ -19,8 +19,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSign30 extends TronBaseTest { @@ -39,36 +39,36 @@ public class MultiSign30 extends TronBaseTest { private ECKey ecKey5 = new ECKey(Utils.getRandom()); byte[] test005Address = ecKey5.getAddress(); String sendAccountKey5 = ByteArray.toHexString(ecKey5.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - - /** - * constructor. - */ + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + /** constructor. */ @BeforeClass - public void beforeClass() { } - - @Test(enabled = true, description = - "Sendcoin,use active address no right to sendcoin sign(weight< threshold)." - + "Then use the same address to sign(weight>=threshold),broadcastTransaction.", groups = {"daily", "multisig"}) + public void beforeClass() {} + + @Test( + enabled = true, + description = + "Sendcoin,use active address no right to sendcoin sign(weight< threshold)." + + "Then use the same address to sign(weight>=threshold),broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_32() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1000000; - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, amount, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -76,21 +76,29 @@ public void testMultiUpdatepermissions_32() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = + String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\":" - + "\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," + + "\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + "\"active0\",\"threshold\":2,\"operations\":\"" + "0100000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey4) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey4) + "\",\"weight\":1}" - + ",{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) + + ",{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -104,62 +112,52 @@ public void testMultiUpdatepermissions_32() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1, test001Address, 2, dev001Key, - blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1, test001Address, 2, dev001Key, blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey4, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey4, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Assert - .assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert - .assertThat(transactionSignWeight.getResult().getMessage(), - containsString("Permission denied")); - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, sendAccountKey4, blockingStubFull); - - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), containsString("Permission denied")); + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, sendAccountKey4, blockingStubFull); + + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert - .assertThat(transactionSignWeight1.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert - .assertThat(transactionSignWeight1.getResult().getMessage(), - containsString("Permission denied")); + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), + containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("Permission denied")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); logger.info("returnResult1:" + returnResult1); - Assert - .assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert - .assertThat(returnResult1.getMessage().toStringUtf8(), - containsString("Validate signature error: Permission denied")); + Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), + containsString("Validate signature error: Permission denied")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1, balance2); } - @AfterMethod public void aftertest() { PublicMethod.freeResource(test001Address, dev001Key, foundationAddress, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign31.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign31.java index 8153a159..88a0aa4b 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign31.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign31.java @@ -18,20 +18,20 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class MultiSign31 extends TronBaseTest { private ManagedChannel searchChannelFull = null; - private String searchFullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String searchFullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); private ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] test001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -47,28 +47,28 @@ public class MultiSign31 extends TronBaseTest { private ECKey ecKey5 = new ECKey(Utils.getRandom()); byte[] test005Address = ecKey5.getAddress(); String sendAccountKey5 = ByteArray.toHexString(ecKey5.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - - /** - * constructor. - */ + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + /** constructor. */ @BeforeClass - public void beforeClass() { } - - @Test(enabled = true, description = - "Sendcoin,use active address sign, meet all requirements,broadcast,Then use the same" - + " permissionID active address to sign, meet all requirements,broadcast.", groups = {"daily", "multisig"}) + public void beforeClass() {} + + @Test( + enabled = true, + description = + "Sendcoin,use active address sign, meet all requirements,broadcast,Then use the same" + + " permissionID active address to sign, meet all requirements,broadcast.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_34() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1000000; - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, amount, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -84,18 +84,28 @@ public void testMultiUpdatepermissions_34() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"" - + "owner\",\"threshold\":1,\"keys\":[{\"address\":\"" - + "" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name" - + "\":\"active0\",\"threshold\":1,\"operations\":\"" - + "0200000000000000000000000000000000000000000000000000000000000000\"" - + ",\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + "\"," - + "\"weight\":1},{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":\"" + + "owner\",\"threshold\":1,\"keys\":[{\"address\":\"" + + "" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name" + + "\":\"active0\",\"threshold\":1,\"operations\":\"" + + "0200000000000000000000000000000000000000000000000000000000000000\"" + + ",\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\"," + + "\"weight\":1},{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -110,17 +120,17 @@ public void testMultiUpdatepermissions_34() { logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); Assert.assertEquals(balance - balance1, updateAccountPermissionFee); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 2, dev001Key, - blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 2, dev001Key, blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey2, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey2, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transactionSignWeight:" + transactionSignWeight); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction1, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction1, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertTrue(returnResult1.getResult()); @@ -129,43 +139,44 @@ public void testMultiUpdatepermissions_34() { logger.info("balance2:" + balance2); Assert.assertEquals(balance1 - balance2, 1L); - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, sendAccountKey3, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, sendAccountKey3, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Return returnResult2 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult2 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("returnResult2:" + returnResult2); - Assert - .assertThat(returnResult2.getCode().toString(), containsString("DUP_TRANSACTION_ERROR")); + Assert.assertThat(returnResult2.getCode().toString(), containsString("DUP_TRANSACTION_ERROR")); Account test001AddressAccount3 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance3 = test001AddressAccount3.getBalance(); Assert.assertEquals(balance3, balance2); - } - @Test(enabled = true, description = - "Sendcoin,use active address sign," - + "not meet the requirements broadcastTransaction.Then use the same" - + " permissionID active address to sign,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use active address sign," + + "not meet the requirements broadcastTransaction.Then use the same" + + " permissionID active address to sign,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_35() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1; - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, amount, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -173,18 +184,28 @@ public void testMultiUpdatepermissions_35() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"" - + "owner\",\"threshold\":1,\"keys\":[{\"address\":\"" - + "" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name" - + "\":\"active0\",\"threshold\":1,\"operations\":\"" - + "0100000000000000000000000000000000000000000000000000000000000000\"" - + ",\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + "\"," - + "\"weight\":1},{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":\"" + + "owner\",\"threshold\":1,\"keys\":[{\"address\":\"" + + "" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name" + + "\":\"active0\",\"threshold\":1,\"operations\":\"" + + "0100000000000000000000000000000000000000000000000000000000000000\"" + + ",\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\"," + + "\"weight\":1},{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -197,76 +218,74 @@ public void testMultiUpdatepermissions_35() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 2, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey2, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 2, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey2, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Assert - .assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert - .assertThat(transactionSignWeight.getResult().getMessage(), - containsString("Permission denied")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction1, blockingStubFull); + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), containsString("Permission denied")); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction1, blockingStubFull); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); logger.info("balance2:" + balance2); Assert.assertEquals(balance1, balance2); logger.info("returnResult1:" + returnResult1); - Assert - .assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert - .assertThat(returnResult1.getMessage().toStringUtf8().toLowerCase(), - containsString("Validate signature error: permission denied".toLowerCase())); - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, sendAccountKey3, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); + Assert.assertThat( + returnResult1.getMessage().toStringUtf8().toLowerCase(), + containsString("Validate signature error: permission denied".toLowerCase())); + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, sendAccountKey3, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert - .assertThat(transactionSignWeight1.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert - .assertThat(transactionSignWeight1.getResult().getMessage(), - containsString("Permission denied")); + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), + containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("Permission denied")); - Return returnResult2 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult2 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); logger.info("returnResult2:" + returnResult2); - Assert - .assertThat(returnResult2.getCode().toString(), containsString("SIGERROR")); + Assert.assertThat(returnResult2.getCode().toString(), containsString("SIGERROR")); Account test001AddressAccount3 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance3 = test001AddressAccount3.getBalance(); logger.info("balance3:" + balance3); Assert.assertEquals(balance3, balance2); - } - @Test(enabled = true, description = - "Sendcoin,use owner address sign, broadcast,Then use other owner address to sign,broadcast.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use owner address sign, broadcast,Then use other owner address to sign,broadcas" + + "t.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_36() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1; - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, amount, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -274,18 +293,28 @@ public void testMultiUpdatepermissions_36() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":" - + "\"owner\",\"threshold\":1,\"keys\":[{\"address\":" - + "\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," - + "\"threshold\":1,\"operations\":" - + "\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":" + + "\"owner\",\"threshold\":1,\"keys\":[{\"address\":" + + "\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + + "\"threshold\":1,\"operations\":" + + "\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -299,17 +328,17 @@ public void testMultiUpdatepermissions_36() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1, test001Address, 0, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey2, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1, test001Address, 0, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey2, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction1, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction1, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(returnResult1.getResult()); @@ -317,41 +346,43 @@ public void testMultiUpdatepermissions_36() { Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1 - balance2, 1); - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, dev001Key, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, dev001Key, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Return returnResult2 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult2 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); logger.info("returnResult1:" + returnResult2); - Assert - .assertThat(returnResult2.getCode().toString(), containsString("DUP_TRANSACTION_ERROR")); + Assert.assertThat(returnResult2.getCode().toString(), containsString("DUP_TRANSACTION_ERROR")); Account test001AddressAccount3 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance3 = test001AddressAccount3.getBalance(); Assert.assertEquals(balance2, balance3); } - @Test(enabled = true, description = - "Sendcoin permission id 3,use active address in permission id 2 sign," - + "Then use active address" - + " in permission id 3 to sign, meet all requirements.broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin permission id 3,use active address in permission id 2 sign," + + "Then use active address" + + " in permission id 3 to sign, meet all requirements.broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_37() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1; - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, amount, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -359,21 +390,30 @@ public void testMultiUpdatepermissions_37() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":" - + "\"owner\",\"threshold\":1,\"keys\":[{\"address\"" - + ":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations" - + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}]}," - + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations" - + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":" + + "\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations" + + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}]}," + + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations" + + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]}"; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -387,74 +427,74 @@ public void testMultiUpdatepermissions_37() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 3, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey2, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 3, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey2, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Assert - .assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert - .assertThat(transactionSignWeight.getResult().getMessage(), - containsString("but it is not contained of permission")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction1, blockingStubFull); + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), + containsString("but it is not contained of permission")); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction1, blockingStubFull); logger.info("returnResult1:" + returnResult1); - Assert - .assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert - .assertThat(returnResult1.getMessage().toStringUtf8(), - containsString("but it is not contained of permission")); + Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), + containsString("but it is not contained of permission")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1, balance2); - //Assert.assertTrue(returnResult1.getResult()); - Transaction transaction2 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction1, sendAccountKey3, 3, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + // Assert.assertTrue(returnResult1.getResult()); + Transaction transaction2 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction1, sendAccountKey3, 3, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert - .assertThat(transactionSignWeight1.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert - .assertThat(transactionSignWeight1.getResult().getMessage(), - containsString("Signature count is 2 more than key counts of permission : 1")); - - Return returnResult2 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), + containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), + containsString("Signature count is 2 more than key counts of permission : 1")); + + Return returnResult2 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); logger.info("returnResult2:" + returnResult2); - Assert - .assertThat(returnResult2.getCode().toString(), containsString("SIGERROR")); + Assert.assertThat(returnResult2.getCode().toString(), containsString("SIGERROR")); Account test001AddressAccount3 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance3 = test001AddressAccount3.getBalance(); Assert.assertEquals(balance2, balance3); - } - @Test(enabled = true, description = - "Sendcoin,use active address sign meet all requirements,broadcast,Then use active address" - + "in wrong permission id to sign,not meet the requirements.broadcast.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use active address sign meet all requirements,broadcast,Then use active address" + + "in wrong permission id to sign,not meet the requirements.broadcast.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_38() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 2; - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, amount, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -462,21 +502,30 @@ public void testMultiUpdatepermissions_38() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":" - + "\"owner\",\"threshold\":1,\"keys\":[{\"address\"" - + ":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations" - + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}]}," - + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations" - + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":" + + "\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations" + + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}]}," + + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations" + + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]}"; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -490,62 +539,63 @@ public void testMultiUpdatepermissions_38() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1, test001Address, 3, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey3, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1, test001Address, 3, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey3, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction1, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction1, blockingStubFull); logger.info("returnResult1:" + returnResult1); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1 - balance2, 1); - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, sendAccountKey2, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, sendAccountKey2, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert - .assertThat(transactionSignWeight1.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert - .assertThat(transactionSignWeight1.getResult().getMessage(), - containsString("Signature count is 2 more than key counts of permission : 1")); - - Return returnResult2 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), + containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), + containsString("Signature count is 2 more than key counts of permission : 1")); + + Return returnResult2 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); logger.info("returnResult2:" + returnResult2); - Assert - .assertThat(returnResult2.getCode().toString(), containsString("SIGERROR")); + Assert.assertThat(returnResult2.getCode().toString(), containsString("SIGERROR")); Account test001AddressAccount3 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance3 = test001AddressAccount3.getBalance(); Assert.assertEquals(balance3, balance2); - } - @Test(enabled = true, description = - "Sendcoin,use active address sign, meet all requirements,Then use the other permissionID " - + "in active address to sign, meet all requirements.broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use active address sign, meet all requirements,Then use the other permissionID " + + "in active address to sign, meet all requirements.broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_39() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 2; - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, amount, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -553,21 +603,30 @@ public void testMultiUpdatepermissions_39() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":" - + "\"owner\",\"threshold\":1,\"keys\":[{\"address\"" - + ":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations" - + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}]}," - + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations" - + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":" + + "\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations" + + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}]}," + + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations" + + "\":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]}"; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -581,44 +640,43 @@ public void testMultiUpdatepermissions_39() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 3, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey3, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 3, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey3, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction1, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction1, blockingStubFull); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance2 = test001AddressAccount2.getBalance(); Assert.assertEquals(balance1 - balance2, 1L); logger.info("returnResult1:" + returnResult1); Assert.assertTrue(returnResult1.getResult()); - Transaction transaction2 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction1, sendAccountKey2, 2, blockingStubFull); - - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); - Assert - .assertThat(transactionSignWeight1.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert - .assertThat(transactionSignWeight1.getResult().getMessage(), - containsString("Signature count is 2 more than key counts of permission : 1")); + Transaction transaction2 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction1, sendAccountKey2, 2, blockingStubFull); + + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), + containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), + containsString("Signature count is 2 more than key counts of permission : 1")); logger.info("transaction1:" + transactionSignWeight1); - Return returnResult2 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Return returnResult2 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); logger.info("returnResult2:" + returnResult2); - Assert - .assertThat(returnResult2.getCode().toString(), containsString("SIGERROR")); + Assert.assertThat(returnResult2.getCode().toString(), containsString("SIGERROR")); Account test001AddressAccount3 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance3 = test001AddressAccount3.getBalance(); Assert.assertEquals(balance3, balance2); - } @AfterMethod @@ -626,11 +684,7 @@ public void aftertest() { PublicMethod.freeResource(test001Address, dev001Key, foundationAddress, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign33.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign33.java index fb320fa1..a2225765 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign33.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign33.java @@ -14,8 +14,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSign33 extends TronBaseTest { @@ -34,33 +34,34 @@ public class MultiSign33 extends TronBaseTest { private ECKey ecKey5 = new ECKey(Utils.getRandom()); byte[] test005Address = ecKey5.getAddress(); String sendAccountKey5 = ByteArray.toHexString(ecKey5.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - - /** - * constructor. - */ + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + /** constructor. */ @BeforeClass - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Active address fall back into only myself", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Active address fall back into only myself", + groups = {"daily", "multisig"}) public void testMultiSignActiveAddress() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = 2 * updateAccountPermissionFee; Assert.assertTrue( - PublicMethod.sendcoin(test001Address, amount, foundationAddress, testKey002, blockingStubFull)); + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -68,43 +69,63 @@ public void testMultiSignActiveAddress() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":" - + "\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + ":\"" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations" - + "\":\"0100000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(dev001Key) - + "\",\"weight\":1}]}," - + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations" - + "\":\"0100000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]}"; + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":" + + "\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations" + + "\":\"0100000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations" + + "\":\"0100000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]}"; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList1 = test001AddressAccount1.getActivePermissionList(); Permission ownerPermission1 = test001AddressAccount1.getOwnerPermission(); Permission witnessPermission1 = test001AddressAccount1.getWitnessPermission(); - final long balance1 = test001AddressAccount1.getBalance(); + final long balance1 = test001AddressAccount1.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList1); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); Assert.assertEquals(balance - balance1, updateAccountPermissionFee); - String accountPermissionJson2 = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"" - + "owner\",\"threshold\":1,\"keys\":[{\"address\":\"" + "" + PublicMethod - .getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name" - + "\":\"active0\",\"threshold\":1,\"operations\":\"" - + "0200000000000000000000000000000000000000000000000000000000000000\"" - + ",\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(dev001Key) + "\"," - + "\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson2, test001Address, dev001Key, - blockingStubFull, 0, permissionKeyString)); + String accountPermissionJson2 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":\"" + + "owner\",\"threshold\":1,\"keys\":[{\"address\":\"" + + "" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name" + + "\":\"active0\",\"threshold\":1,\"operations\":\"" + + "0200000000000000000000000000000000000000000000000000000000000000\"" + + ",\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(dev001Key) + + "\"," + + "\"weight\":1}]}]} "; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson2, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList2 = test001AddressAccount2.getActivePermissionList(); @@ -115,8 +136,6 @@ public void testMultiSignActiveAddress() { PublicMethodForMultiSign.printPermissionList(permissionsList2); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission2)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission2)); - - } @AfterMethod @@ -124,13 +143,7 @@ public void aftertest() { PublicMethod.freeResource(test001Address, dev001Key, foundationAddress, blockingStubFull); } - - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign34.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign34.java index 802900a8..5705ea1b 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign34.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign34.java @@ -18,8 +18,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSign34 extends TronBaseTest { @@ -35,136 +35,134 @@ public class MultiSign34 extends TronBaseTest { private ECKey ecKey5 = new ECKey(Utils.getRandom()); byte[] test005Address = ecKey5.getAddress(); String sendAccountKey5 = ByteArray.toHexString(ecKey5.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - - /** - * constructor. - */ + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + /** constructor. */ @BeforeClass - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "SR witness,sendcoin, use witnessPermission address sign.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "SR witness,sendcoin, use witnessPermission address sign.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_42() { - Assert.assertTrue(PublicMethod - .sendcoin(witnessAddress2, 1000000000, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + witnessAddress2, 1000000000, foundationAddress, testKey002, blockingStubFull)); Account test001AddressAccount = PublicMethod.queryAccount(witnessAddress2, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, witnessAddress2, 1, witnessKey2, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, witnessKey2, blockingStubFull); - final TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, witnessAddress2, 1, witnessKey2, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, witnessKey2, blockingStubFull); + final TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); Account test001AddressAccount1 = PublicMethod.queryAccount(witnessAddress2, blockingStubFull); List permissionsList1 = test001AddressAccount1.getActivePermissionList(); Permission ownerPermission1 = test001AddressAccount1.getOwnerPermission(); Permission witnessPermission1 = test001AddressAccount1.getWitnessPermission(); - final long balance1 = test001AddressAccount1.getBalance(); + final long balance1 = test001AddressAccount1.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList1); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); Assert.assertEquals(balance, balance1); logger.info("transaction:" + transactionSignWeight); - Assert - .assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert - .assertThat(transactionSignWeight.getResult().getMessage(), - containsString("Permission for this, does not exist!")); - - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction1, blockingStubFull); + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), + containsString("Permission for this, does not exist!")); + + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction1, blockingStubFull); logger.info("returnResult1:" + returnResult1); - Assert - .assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert - .assertThat(returnResult1.getMessage().toStringUtf8(), - containsString("permission isn't exit")); - + Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("permission isn't exit")); } - @Test(enabled = true, description = "SR witness,sendcoin, use active address sign.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "SR witness,sendcoin, use active address sign.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_43() { - Assert.assertTrue(PublicMethod - .sendcoin(witnessAddress2, 1000000000, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + witnessAddress2, 1000000000, foundationAddress, testKey002, blockingStubFull)); Account test001AddressAccount = PublicMethod.queryAccount(witnessAddress2, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, witnessAddress2, 2, witnessKey2, - blockingStubFull); - final Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, witnessKey2, blockingStubFull); - final TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, witnessAddress2, 2, witnessKey2, blockingStubFull); + final Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, witnessKey2, blockingStubFull); + final TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transaction:" + transactionSignWeight); - Assert - .assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert - .assertThat(transactionSignWeight.getResult().getMessage(), - containsString("Permission for this, does not exist!")); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction1, blockingStubFull); + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), + containsString("Permission for this, does not exist!")); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction1, blockingStubFull); logger.info("returnResult1:" + returnResult1); Account test001AddressAccount1 = PublicMethod.queryAccount(witnessAddress2, blockingStubFull); List permissionsList1 = test001AddressAccount1.getActivePermissionList(); Permission ownerPermission1 = test001AddressAccount1.getOwnerPermission(); Permission witnessPermission1 = test001AddressAccount1.getWitnessPermission(); - final long balance1 = test001AddressAccount1.getBalance(); + final long balance1 = test001AddressAccount1.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList1); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); Assert.assertEquals(balance, balance1); - Assert - .assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); - Assert - .assertThat(returnResult1.getMessage().toStringUtf8(), - containsString("permission isn't exit")); - + Assert.assertThat(returnResult1.getCode().toString(), containsString("SIGERROR")); + Assert.assertThat( + returnResult1.getMessage().toStringUtf8(), containsString("permission isn't exit")); } - @Test(enabled = true, description = "SR witness,sendcoin, use owner address sign.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "SR witness,sendcoin, use owner address sign.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_44() { - Assert.assertTrue(PublicMethod - .sendcoin(witnessAddress2, 1000000000, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + witnessAddress2, 1000000000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(witnessAddress2, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info("balance: " + balance); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, witnessAddress2, 0, witnessKey2, - blockingStubFull); - final Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, witnessKey2, blockingStubFull); - Return returnResult1 = PublicMethodForMultiSign - .broadcastTransaction1(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, witnessAddress2, 0, witnessKey2, blockingStubFull); + final Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, witnessKey2, blockingStubFull); + Return returnResult1 = + PublicMethodForMultiSign.broadcastTransaction1(transaction1, blockingStubFull); logger.info("returnResult1:" + returnResult1); Assert.assertTrue(returnResult1.getResult()); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -172,20 +170,15 @@ public void testMultiUpdatepermissions_44() { List permissionsList1 = test001AddressAccount1.getActivePermissionList(); Permission ownerPermission1 = test001AddressAccount1.getOwnerPermission(); Permission witnessPermission1 = test001AddressAccount1.getWitnessPermission(); - final long balance1 = test001AddressAccount1.getBalance(); + final long balance1 = test001AddressAccount1.getBalance(); logger.info("balance1: " + balance1); PublicMethodForMultiSign.printPermissionList(permissionsList1); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); Assert.assertEquals(balance - balance1, 1); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign35.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign35.java index e4156131..4b3423c9 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign35.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign35.java @@ -19,8 +19,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSign35 extends TronBaseTest { @@ -39,35 +39,34 @@ public class MultiSign35 extends TronBaseTest { private ECKey ecKey5 = new ECKey(Utils.getRandom()); byte[] test005Address = ecKey5.getAddress(); String sendAccountKey5 = ByteArray.toHexString(ecKey5.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - - /** - * constructor. - */ + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + /** constructor. */ @BeforeClass - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "update active operation," - + " use active address meet all requirement", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "update active operation," + " use active address meet all requirement", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_45() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = 2 * updateAccountPermissionFee; - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, amount, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -75,23 +74,31 @@ public void testMultiUpdatepermissions_45() { String[] permissionKeyString = new String[5]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = + String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"" - + "keys\":[{\"address\":\"" + PublicMethod.getAddressString(dev001Key) + + "keys\":[{\"address\":\"" + + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey5) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey5) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1,\"operations\":\"" + "7fff1fc0037e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey4) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey4) + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -99,68 +106,77 @@ public void testMultiUpdatepermissions_45() { List permissionsList1 = test001AddressAccount1.getActivePermissionList(); Permission ownerPermission1 = test001AddressAccount1.getOwnerPermission(); Permission witnessPermission1 = test001AddressAccount1.getWitnessPermission(); - final long balance1 = test001AddressAccount1.getBalance(); + final long balance1 = test001AddressAccount1.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList1); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); Assert.assertEquals(balance - balance1, updateAccountPermissionFee); - String accountPermissionJson2 = + String accountPermissionJson2 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" - + ":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + "\"active0\",\"threshold\":1,\"operations\"" + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey4) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey4) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + "\",\"weight\":1}]}]} "; String[] permissionKeyString1 = new String[5]; permissionKeyString1[0] = sendAccountKey4; - Transaction transaction = PublicMethodForMultiSign - .accountPermissionUpdateWithoutSign(accountPermissionJson2, test001Address, dev001Key, + Transaction transaction = + PublicMethodForMultiSign.accountPermissionUpdateWithoutSign( + accountPermissionJson2, + test001Address, + dev001Key, blockingStubFull, permissionKeyString); - Transaction transaction1 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction, sendAccountKey4, 2, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction1 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction, sendAccountKey4, 2, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transactionSignWeight:" + transactionSignWeight); - Return returnResult = PublicMethodForMultiSign - .broadcastTransaction1(transaction1, blockingStubFull); + Return returnResult = + PublicMethodForMultiSign.broadcastTransaction1(transaction1, blockingStubFull); logger.info("returnResult:" + returnResult); Assert.assertTrue(returnResult.getResult()); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList2 = test001AddressAccount2.getActivePermissionList(); Permission ownerPermission2 = test001AddressAccount2.getOwnerPermission(); Permission witnessPermission2 = test001AddressAccount2.getWitnessPermission(); - final long balance2 = test001AddressAccount2.getBalance(); + final long balance2 = test001AddressAccount2.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList2); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission2)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission2)); Assert.assertEquals(balance1 - balance2, updateAccountPermissionFee); - - } - @Test(enabled = true, description = "update active operation," - + " use active address no right update sign, broadcast", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "update active operation," + " use active address no right update sign, broadcast", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_46() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee; - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, amount, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); Permission witnessPermission = test001AddressAccount.getWitnessPermission(); - final long balance = test001AddressAccount.getBalance(); + final long balance = test001AddressAccount.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission)); @@ -168,82 +184,92 @@ public void testMultiUpdatepermissions_46() { String[] permissionKeyString = new String[5]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = + String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"" - + "keys\":[{\"address\":\"" + PublicMethod.getAddressString(dev001Key) + + "keys\":[{\"address\":\"" + + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey5) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey5) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1,\"operations\":\"" + "7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey4) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey4) + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList1 = test001AddressAccount1.getActivePermissionList(); Permission ownerPermission1 = test001AddressAccount1.getOwnerPermission(); Permission witnessPermission1 = test001AddressAccount1.getWitnessPermission(); - final long balance1 = test001AddressAccount1.getBalance(); + final long balance1 = test001AddressAccount1.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList1); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); Assert.assertEquals(balance - balance1, updateAccountPermissionFee); - String accountPermissionJson2 = + String accountPermissionJson2 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" - + ":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + "\"active0\",\"threshold\":1,\"operations\"" + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey4) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey4) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + "\",\"weight\":1}]}]} "; String[] permissionKeyString1 = new String[5]; permissionKeyString1[0] = sendAccountKey4; - Transaction transaction = PublicMethodForMultiSign - .accountPermissionUpdateWithoutSign(accountPermissionJson2, test001Address, dev001Key, + Transaction transaction = + PublicMethodForMultiSign.accountPermissionUpdateWithoutSign( + accountPermissionJson2, + test001Address, + dev001Key, blockingStubFull, permissionKeyString); - Transaction transaction1 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction, sendAccountKey4, 2, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction1 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction, sendAccountKey4, 2, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transactionSignWeight:" + transactionSignWeight); - Assert - .assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert - .assertThat(transactionSignWeight.getResult().getMessage(), - containsString("Permission denied")); - Return returnResult = PublicMethodForMultiSign - .broadcastTransaction1(transaction1, blockingStubFull); + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight.getResult().getMessage(), containsString("Permission denied")); + Return returnResult = + PublicMethodForMultiSign.broadcastTransaction1(transaction1, blockingStubFull); logger.info("returnResult:" + returnResult); - Assert - .assertThat(returnResult.getCode().toString(), containsString("SIGERROR")); - Assert - .assertThat(returnResult.getMessage().toStringUtf8(), - containsString("Permission denied")); + Assert.assertThat(returnResult.getCode().toString(), containsString("SIGERROR")); + Assert.assertThat( + returnResult.getMessage().toStringUtf8(), containsString("Permission denied")); Account test001AddressAccount2 = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList2 = test001AddressAccount2.getActivePermissionList(); Permission ownerPermission2 = test001AddressAccount2.getOwnerPermission(); Permission witnessPermission2 = test001AddressAccount2.getWitnessPermission(); - final long balance2 = test001AddressAccount2.getBalance(); + final long balance2 = test001AddressAccount2.getBalance(); PublicMethodForMultiSign.printPermissionList(permissionsList2); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission2)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission2)); Assert.assertEquals(balance1, balance2); - - } @AfterMethod @@ -251,12 +277,7 @@ public void aftertest() { PublicMethod.freeResource(test001Address, dev001Key, foundationAddress, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign36.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign36.java index 3d9cce8c..7473720c 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign36.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign36.java @@ -24,8 +24,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSign36 extends TronBaseTest { @@ -45,28 +45,29 @@ public class MultiSign36 extends TronBaseTest { private ECKey ecKey5 = new ECKey(Utils.getRandom()); byte[] test005Address = ecKey5.getAddress(); String sendAccountKey5 = ByteArray.toHexString(ecKey5.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - - /** - * constructor. - */ + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + /** constructor. */ @BeforeClass - public void beforeClass() { } - - @Test(enabled = true, description = "two owner address sign update permission transaction " - + "sum(weight)==threshold,get approve list", groups = {"daily", "multisig"}) + public void beforeClass() {} + + @Test( + enabled = true, + description = + "two owner address sign update permission transaction " + + "sum(weight)==threshold,get approve list", + groups = {"daily", "multisig"}) public void getTransactionApprovedList_01() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee; - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, amount, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -81,62 +82,80 @@ public void getTransactionApprovedList_01() { String[] permissionKeyString = new String[2]; permissionKeyString[0] = dev001Key; permissionKeyString[1] = sendAccountKey2; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":" - + "\"owner\",\"threshold\":2,\"keys\":[{\"address\":" - + "\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," - + "\"threshold\":1,\"operations\":" - + "\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - - Transaction transaction = PublicMethodForMultiSign - .accountPermissionUpdateWithoutSign(accountPermissionJson1, test001Address, dev001Key, + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":" + + "\"owner\",\"threshold\":2,\"keys\":[{\"address\":" + + "\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + + "\"threshold\":1,\"operations\":" + + "\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + + Transaction transaction = + PublicMethodForMultiSign.accountPermissionUpdateWithoutSign( + accountPermissionJson1, + test001Address, + dev001Key, blockingStubFull, permissionKeyString); - Transaction transaction1 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction, dev001Key, 0, blockingStubFull); - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, sendAccountKey2, blockingStubFull); - TransactionApprovedList transactionApprovedList = PublicMethod - .getTransactionApprovedList(transaction2, blockingStubFull); + Transaction transaction1 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction, dev001Key, 0, blockingStubFull); + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, sendAccountKey2, blockingStubFull); + TransactionApprovedList transactionApprovedList = + PublicMethod.getTransactionApprovedList(transaction2, blockingStubFull); logger.info("test001Address:" + Base58.encode58Check(test001Address)); logger.info( - "transactionApprovedList:" + Base58 - .encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); - Assert.assertEquals(Base58.encode58Check(test001Address), Base58 - .encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); - Assert.assertEquals(Base58.encode58Check(test002Address), Base58 - .encode58Check(transactionApprovedList.getApprovedList(1).toByteArray())); + "transactionApprovedList:" + + Base58.encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); + Assert.assertEquals( + Base58.encode58Check(test001Address), + Base58.encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); + Assert.assertEquals( + Base58.encode58Check(test002Address), + Base58.encode58Check(transactionApprovedList.getApprovedList(1).toByteArray())); Assert.assertEquals(2, transactionApprovedList.getApprovedListCount()); - Assert.assertEquals(0, - transactionApprovedList.getTransaction().getTransaction().getRawData().getContract(0) + Assert.assertEquals( + 0, + transactionApprovedList + .getTransaction() + .getTransaction() + .getRawData() + .getContract(0) .getPermissionId()); - Account test001AddressAccount1 = PublicMethod - .queryAccount(test001Address, blockingStubFull); + Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList1 = test001AddressAccount1.getActivePermissionList(); Permission ownerPermission1 = test001AddressAccount1.getOwnerPermission(); Permission witnessPermission1 = test001AddressAccount1.getWitnessPermission(); PublicMethodForMultiSign.printPermissionList(permissionsList1); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - } - @Test(enabled = true, description = - "sendcoin,use active address sign meet all requirement,delete " - + "the used active address," - + "and change active no right to sendcoin. get first transaction approve list", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "sendcoin,use active address sign meet all requirement,delete " + + "the used active address," + + "and change active no right to sendcoin. get first transaction approve list", + groups = {"daily", "multisig"}) public void getTransactionApprovedList_02() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = 2 * updateAccountPermissionFee + 1; - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, amount, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -150,21 +169,29 @@ public void getTransactionApprovedList_02() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = + String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" - + ":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + "\"active0\",\"threshold\":1,\"operations\"" + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -176,40 +203,55 @@ public void getTransactionApprovedList_02() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 2, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction, sendAccountKey2, 2, blockingStubFull); - String accountPermissionJson2 = + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 2, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction, sendAccountKey2, 2, blockingStubFull); + String accountPermissionJson2 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" - + ":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + "\"active0\",\"threshold\":1,\"operations\"" + ":\"0100000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey4) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey4) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson2, test001Address, dev001Key, - blockingStubFull, 0, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson2, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); - TransactionApprovedList transactionApprovedList = PublicMethod - .getTransactionApprovedList(transaction1, blockingStubFull); + TransactionApprovedList transactionApprovedList = + PublicMethod.getTransactionApprovedList(transaction1, blockingStubFull); logger.info("transactionSignWeight:" + transactionApprovedList); logger.info("transactionSignWeight:" + transactionApprovedList); logger.info("test001Address:" + Base58.encode58Check(test001Address)); logger.info( - "transactionApprovedList:" + Base58 - .encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); - Assert.assertEquals(Base58.encode58Check(test002Address), Base58 - .encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); + "transactionApprovedList:" + + Base58.encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); + Assert.assertEquals( + Base58.encode58Check(test002Address), + Base58.encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); Assert.assertEquals(1, transactionApprovedList.getApprovedListCount()); - Assert.assertEquals(2, - transactionApprovedList.getTransaction().getTransaction().getRawData().getContract(0) + Assert.assertEquals( + 2, + transactionApprovedList + .getTransaction() + .getTransaction() + .getRawData() + .getContract(0) .getPermissionId()); Account test001AddressAccount2 = PublicMethod.queryAccount(sendAccountKey2, blockingStubFull); List permissionsList2 = test001AddressAccount2.getActivePermissionList(); @@ -218,19 +260,20 @@ public void getTransactionApprovedList_02() { PublicMethodForMultiSign.printPermissionList(permissionsList2); logger.info(PublicMethodForMultiSign.printPermission(ownerPermission2)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission2)); - } - @Test(enabled = true, description = "sendcoin,use active address sign," - + "sum(weight)==threshold,get approve list", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "sendcoin,use active address sign," + "sum(weight)==threshold,get approve list", + groups = {"daily", "multisig"}) public void getTransactionApprovedList_03() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1 + 1100000; - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, amount, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -244,21 +287,29 @@ public void getTransactionApprovedList_03() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = + String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" - + ":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + "\"active0\",\"threshold\":2,\"operations\"" + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -269,39 +320,49 @@ public void getTransactionApprovedList_03() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(test005Address, 1L, test001Address, 2, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey2, blockingStubFull); - Transaction transaction2 = PublicMethod - .addTransactionSign(transaction1, sendAccountKey3, blockingStubFull); - TransactionApprovedList transactionApprovedList = PublicMethod - .getTransactionApprovedList(transaction2, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + test005Address, 1L, test001Address, 2, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey2, blockingStubFull); + Transaction transaction2 = + PublicMethod.addTransactionSign(transaction1, sendAccountKey3, blockingStubFull); + TransactionApprovedList transactionApprovedList = + PublicMethod.getTransactionApprovedList(transaction2, blockingStubFull); logger.info("transactionSignWeight:" + transactionApprovedList); logger.info("test001Address:" + Base58.encode58Check(test001Address)); logger.info( - "transactionApprovedList:" + Base58 - .encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); - Assert.assertEquals(Base58.encode58Check(test002Address), Base58 - .encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); - Assert.assertEquals(Base58.encode58Check(test003Address), Base58 - .encode58Check(transactionApprovedList.getApprovedList(1).toByteArray())); + "transactionApprovedList:" + + Base58.encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); + Assert.assertEquals( + Base58.encode58Check(test002Address), + Base58.encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); + Assert.assertEquals( + Base58.encode58Check(test003Address), + Base58.encode58Check(transactionApprovedList.getApprovedList(1).toByteArray())); Assert.assertEquals(2, transactionApprovedList.getApprovedListCount()); - Assert.assertEquals(2, - transactionApprovedList.getTransaction().getTransaction().getRawData().getContract(0) + Assert.assertEquals( + 2, + transactionApprovedList + .getTransaction() + .getTransaction() + .getRawData() + .getContract(0) .getPermissionId()); } - @Test(enabled = true, description = "Multi-signature unfinished transaction,get approve list", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = "Multi-signature unfinished transaction,get approve list", + groups = {"daily", "multisig"}) public void getTransactionApprovedList_06() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1 + 1100000; - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, amount, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -315,21 +376,29 @@ public void getTransactionApprovedList_06() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = + String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" - + ":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + "\"active0\",\"threshold\":2,\"operations\"" + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -340,36 +409,46 @@ public void getTransactionApprovedList_06() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(test005Address, 1L, test001Address, 2, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey2, blockingStubFull); - TransactionApprovedList transactionApprovedList = PublicMethod - .getTransactionApprovedList(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + test005Address, 1L, test001Address, 2, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey2, blockingStubFull); + TransactionApprovedList transactionApprovedList = + PublicMethod.getTransactionApprovedList(transaction1, blockingStubFull); logger.info("transactionSignWeight:" + transactionApprovedList); logger.info("test001Address:" + Base58.encode58Check(test001Address)); Assert.assertEquals(1, transactionApprovedList.getApprovedListCount()); - Assert.assertEquals(Base58.encode58Check(test002Address), Base58 - .encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); - Assert.assertEquals(2, - transactionApprovedList.getTransaction().getTransaction().getRawData().getContract(0) + Assert.assertEquals( + Base58.encode58Check(test002Address), + Base58.encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); + Assert.assertEquals( + 2, + transactionApprovedList + .getTransaction() + .getTransaction() + .getRawData() + .getContract(0) .getPermissionId()); } - @Test(enabled = true, description = "sendcoin transaction in owner permission," - + "but sign use active address," - + "get approve list", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "sendcoin transaction in owner permission," + + "but sign use active address," + + "get approve list", + groups = {"daily", "multisig"}) public void getTransactionApprovedList_07() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1100000; - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, amount, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -383,21 +462,29 @@ public void getTransactionApprovedList_07() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = + String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" - + ":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + "\"active0\",\"threshold\":2,\"operations\"" + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -408,74 +495,82 @@ public void getTransactionApprovedList_07() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(test005Address, 1L, test001Address, 0, dev001Key, - blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, sendAccountKey2, blockingStubFull); - TransactionApprovedList transactionApprovedList = PublicMethod - .getTransactionApprovedList(transaction1, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + test005Address, 1L, test001Address, 0, dev001Key, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, sendAccountKey2, blockingStubFull); + TransactionApprovedList transactionApprovedList = + PublicMethod.getTransactionApprovedList(transaction1, blockingStubFull); logger.info("transactionSignWeight:" + transactionApprovedList); Assert.assertEquals(1, transactionApprovedList.getApprovedListCount()); - Assert.assertEquals(Base58.encode58Check(test002Address), Base58 - .encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); - Assert.assertEquals(0, - transactionApprovedList.getTransaction().getTransaction().getRawData().getContract(0) + Assert.assertEquals( + Base58.encode58Check(test002Address), + Base58.encode58Check(transactionApprovedList.getApprovedList(0).toByteArray())); + Assert.assertEquals( + 0, + transactionApprovedList + .getTransaction() + .getTransaction() + .getRawData() + .getContract(0) .getPermissionId()); } - /** - * constructor. - */ - public Protocol.Transaction createFakeTransaction(byte[] toAddrss, Long amount, - byte[] foundationAddress) { - - BalanceContract.TransferContract contract = BalanceContract.TransferContract.newBuilder() - .setOwnerAddress(ByteString.copyFrom(foundationAddress)) - .setToAddress(ByteString.copyFrom(toAddrss)) - .setAmount(amount) - .build(); + /** constructor. */ + public Protocol.Transaction createFakeTransaction( + byte[] toAddrss, Long amount, byte[] foundationAddress) { + + BalanceContract.TransferContract contract = + BalanceContract.TransferContract.newBuilder() + .setOwnerAddress(ByteString.copyFrom(foundationAddress)) + .setToAddress(ByteString.copyFrom(toAddrss)) + .setAmount(amount) + .build(); Protocol.Transaction transaction = createTransaction(contract, ContractType.TransferContract); return transaction; } - private Transaction setReference(Transaction transaction, long blockNum, - byte[] blockHash) { + private Transaction setReference(Transaction transaction, long blockNum, byte[] blockHash) { byte[] refBlockNum = ByteArray.fromLong(blockNum); - Transaction.raw rawData = transaction.getRawData().toBuilder() - .setRefBlockHash(ByteString.copyFrom(blockHash)) - .setRefBlockBytes(ByteString.copyFrom(refBlockNum)) - .build(); + Transaction.raw rawData = + transaction + .getRawData() + .toBuilder() + .setRefBlockHash(ByteString.copyFrom(blockHash)) + .setRefBlockBytes(ByteString.copyFrom(refBlockNum)) + .build(); return transaction.toBuilder().setRawData(rawData).build(); - } + } - /** - * constructor. - */ + /** constructor. */ public Transaction setExpiration(Transaction transaction, long expiration) { - Transaction.raw rawData = transaction.getRawData().toBuilder().setExpiration(expiration) - .build(); + Transaction.raw rawData = + transaction.getRawData().toBuilder().setExpiration(expiration).build(); return transaction.toBuilder().setRawData(rawData).build(); - } - - /** - * constructor. - */ - public Transaction createTransaction(com.google.protobuf.Message message, - ContractType contractType) { - Transaction.raw.Builder transactionBuilder = Transaction.raw.newBuilder().addContract( - Transaction.Contract.newBuilder().setType(contractType).setParameter( - Any.pack(message)).build()); - - Transaction transaction = Transaction.newBuilder().setRawData(transactionBuilder.build()) - .build(); + } + + /** constructor. */ + public Transaction createTransaction( + com.google.protobuf.Message message, ContractType contractType) { + Transaction.raw.Builder transactionBuilder = + Transaction.raw + .newBuilder() + .addContract( + Transaction.Contract.newBuilder() + .setType(contractType) + .setParameter(Any.pack(message)) + .build()); + + Transaction transaction = + Transaction.newBuilder().setRawData(transactionBuilder.build()).build(); long time = System.currentTimeMillis(); AtomicLong count = new AtomicLong(); long gtime = count.incrementAndGet() + time; - String ref = "" + gtime; + String ref = "" + gtime; transaction = setReference(transaction, gtime, ByteArray.fromString(ref)); @@ -489,11 +584,7 @@ public void aftertest() { PublicMethod.freeResource(test001Address, dev001Key, foundationAddress, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign37.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign37.java index 43fa173d..b6d6e2fb 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign37.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/multisign/MultiSign37.java @@ -24,8 +24,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSign37 extends TronBaseTest { @@ -45,34 +45,34 @@ public class MultiSign37 extends TronBaseTest { private ECKey ecKey5 = new ECKey(Utils.getRandom()); byte[] test005Address = ecKey5.getAddress(); String sendAccountKey5 = ByteArray.toHexString(ecKey5.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - - /** - * constructor. - */ + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + /** constructor. */ @BeforeClass - public void beforeClass() { } - - @Test(enabled = true, description = - "Sendcoin with permission id 0,use owner address sign, weight permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); - final Permission witnessPermission = test001AddressAccount.getWitnessPermission(); + final Permission witnessPermission = test001AddressAccount.getWitnessPermission(); long balance = test001AddressAccount.getBalance(); logger.info("balance:" + balance); PublicMethodForMultiSign.printPermissionList(permissionsList); @@ -82,24 +82,34 @@ public void testMultiUpdatepermissions_47() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":" - + "\"owner\",\"threshold\":2,\"keys\":[{\"address\":" - + "\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," - + "\"threshold\":1,\"operations\":" - + "\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":" + + "\"owner\",\"threshold\":2,\"keys\":[{\"address\":" + + "\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + + "\"threshold\":1,\"operations\":" + + "\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList1 = test001AddressAccount1.getActivePermissionList(); Permission ownerPermission1 = test001AddressAccount1.getOwnerPermission(); - final Permission witnessPermission1 = test001AddressAccount1.getWitnessPermission(); + final Permission witnessPermission1 = test001AddressAccount1.getWitnessPermission(); long balance1 = test001AddressAccount1.getBalance(); logger.info("balance1:" + balance1); @@ -108,59 +118,61 @@ public void testMultiUpdatepermissions_47() { logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); Assert.assertEquals(balance - balance1, updateAccountPermissionFee); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 0, dev001Key, - blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 0, dev001Key, blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, dev001Key, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, dev001Key, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transactionSignWeight:" + transactionSignWeight); - Assert - .assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("NOT_ENOUGH_PERMISSION")); - Transaction transaction2 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction1, sendAccountKey3, 2, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), + containsString("NOT_ENOUGH_PERMISSION")); + Transaction transaction2 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction1, sendAccountKey3, 2, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert - .assertThat(transactionSignWeight1.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert - .assertThat(transactionSignWeight1.getResult().getMessage(), - containsString("Signature count is 2 more than key counts of permission : 1")); - Return returnResult2 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), + containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), + containsString("Signature count is 2 more than key counts of permission : 1")); + Return returnResult2 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); logger.info("returnResult2:" + returnResult2); - Assert - .assertThat(returnResult2.getCode().toString(), containsString("SIGERROR")); + Assert.assertThat(returnResult2.getCode().toString(), containsString("SIGERROR")); Account test001AddressAccount3 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance3 = test001AddressAccount3.getBalance(); - Assert - .assertThat(returnResult2.getMessage().toStringUtf8(), - containsString( - "Signature count is 2 more than key counts of permission : 1")); + Assert.assertThat( + returnResult2.getMessage().toStringUtf8(), + containsString("Signature count is 2 more than key counts of permission : 1")); Assert.assertEquals(balance1, balance3); } - @Test(enabled = true, description = - "Sendcoin,use owner address sign, not meet all requirements.Then use " - + " active address to sign, not meet all requirements,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use owner address sign, not meet all requirements.Then use " + + " active address to sign, not meet all requirements,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_48() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + 1000000; - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, amount, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); - final Permission witnessPermission = test001AddressAccount.getWitnessPermission(); + final Permission witnessPermission = test001AddressAccount.getWitnessPermission(); long balance = test001AddressAccount.getBalance(); logger.info("balance:" + balance); PublicMethodForMultiSign.printPermissionList(permissionsList); @@ -170,24 +182,34 @@ public void testMultiUpdatepermissions_48() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":" - + "\"owner\",\"threshold\":2,\"keys\":[{\"address\":" - + "\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," - + "\"threshold\":1,\"operations\":" - + "\"0100000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":" + + "\"owner\",\"threshold\":2,\"keys\":[{\"address\":" + + "\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + + "\"threshold\":1,\"operations\":" + + "\"0100000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList1 = test001AddressAccount1.getActivePermissionList(); Permission ownerPermission1 = test001AddressAccount1.getOwnerPermission(); - final Permission witnessPermission1 = test001AddressAccount1.getWitnessPermission(); + final Permission witnessPermission1 = test001AddressAccount1.getWitnessPermission(); long balance1 = test001AddressAccount1.getBalance(); logger.info("balance1:" + balance1); @@ -196,53 +218,58 @@ public void testMultiUpdatepermissions_48() { logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); Assert.assertEquals(balance - balance1, updateAccountPermissionFee); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 0, dev001Key, - blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 0, dev001Key, blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, dev001Key, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, dev001Key, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transactionSignWeight:" + transactionSignWeight); - Assert.assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("NOT_ENOUGH_PERMISSION")); - Transaction transaction2 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction1, sendAccountKey3, 2, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), + containsString("NOT_ENOUGH_PERMISSION")); + Transaction transaction2 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction1, sendAccountKey3, 2, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert.assertThat(transactionSignWeight1.getResult().getCode().toString(), - containsString("PERMISSION_ERROR")); - Assert.assertThat(transactionSignWeight1.getResult().getMessage(), - containsString("Permission denied")); - Return returnResult2 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), + containsString("PERMISSION_ERROR")); + Assert.assertThat( + transactionSignWeight1.getResult().getMessage(), containsString("Permission denied")); + Return returnResult2 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); logger.info("returnResult2:" + returnResult2); - Assert - .assertThat(returnResult2.getCode().toString(), containsString("SIGERROR")); + Assert.assertThat(returnResult2.getCode().toString(), containsString("SIGERROR")); Account test001AddressAccount3 = PublicMethod.queryAccount(test001Address, blockingStubFull); long balance3 = test001AddressAccount3.getBalance(); - Assert.assertThat(returnResult2.getMessage().toStringUtf8(), - containsString("Permission denied")); + Assert.assertThat( + returnResult2.getMessage().toStringUtf8(), containsString("Permission denied")); Assert.assertEquals(balance1, balance3); } - @Test(enabled = true, description = - "Sendcoin,use two owner address sign,sum(weight)==threshold,broadcastTransaction.", groups = {"daily", "multisig"}) + @Test( + enabled = true, + description = + "Sendcoin,use two owner address sign,sum(weight)==threshold,broadcastTransaction.", + groups = {"daily", "multisig"}) public void testMultiUpdatepermissions_49() { ECKey ecKey = new ECKey(Utils.getRandom()); test001Address = ecKey.getAddress(); long amount = updateAccountPermissionFee + multiSignFee + 1000000; - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, amount, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, amount, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); Permission ownerPermission = test001AddressAccount.getOwnerPermission(); - final Permission witnessPermission = test001AddressAccount.getWitnessPermission(); + final Permission witnessPermission = test001AddressAccount.getWitnessPermission(); long balance = test001AddressAccount.getBalance(); logger.info("balance:" + balance); PublicMethodForMultiSign.printPermissionList(permissionsList); @@ -252,24 +279,34 @@ public void testMultiUpdatepermissions_49() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":" - + "\"owner\",\"threshold\":2,\"keys\":[{\"address\":" - + "\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," - + "\"threshold\":1,\"operations\":" - + "\"0100000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]} "; - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, dev001Key, - blockingStubFull, 0, + String accountPermissionJson1 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":" + + "\"owner\",\"threshold\":2,\"keys\":[{\"address\":" + + "\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + + "\"threshold\":1,\"operations\":" + + "\"0100000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]} "; + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList1 = test001AddressAccount1.getActivePermissionList(); Permission ownerPermission1 = test001AddressAccount1.getOwnerPermission(); - final Permission witnessPermission1 = test001AddressAccount1.getWitnessPermission(); + final Permission witnessPermission1 = test001AddressAccount1.getWitnessPermission(); long balance1 = test001AddressAccount1.getBalance(); logger.info("balance1:" + balance1); @@ -278,28 +315,29 @@ public void testMultiUpdatepermissions_49() { logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); Assert.assertEquals(balance - balance1, updateAccountPermissionFee); - Transaction transaction = PublicMethodForMultiSign - .sendcoinWithPermissionIdNotSign(foundationAddress, 1L, test001Address, 0, dev001Key, - blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, test001Address, 0, dev001Key, blockingStubFull); - Transaction transaction1 = PublicMethod - .addTransactionSign(transaction, dev001Key, blockingStubFull); - TransactionSignWeight transactionSignWeight = PublicMethodForMultiSign - .getTransactionSignWeight(transaction1, blockingStubFull); + Transaction transaction1 = + PublicMethod.addTransactionSign(transaction, dev001Key, blockingStubFull); + TransactionSignWeight transactionSignWeight = + PublicMethodForMultiSign.getTransactionSignWeight(transaction1, blockingStubFull); logger.info("transactionSignWeight:" + transactionSignWeight); - Assert - .assertThat(transactionSignWeight.getResult().getCode().toString(), - containsString("NOT_ENOUGH_PERMISSION")); - Transaction transaction2 = PublicMethodForMultiSign - .addTransactionSignWithPermissionId(transaction1, sendAccountKey2, 0, blockingStubFull); - TransactionSignWeight transactionSignWeight1 = PublicMethodForMultiSign - .getTransactionSignWeight(transaction2, blockingStubFull); + Assert.assertThat( + transactionSignWeight.getResult().getCode().toString(), + containsString("NOT_ENOUGH_PERMISSION")); + Transaction transaction2 = + PublicMethodForMultiSign.addTransactionSignWithPermissionId( + transaction1, sendAccountKey2, 0, blockingStubFull); + TransactionSignWeight transactionSignWeight1 = + PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("transaction1:" + transactionSignWeight1); - Assert - .assertThat(transactionSignWeight1.getResult().getCode().toString(), - containsString("ENOUGH_PERMISSION")); - Return returnResult2 = PublicMethodForMultiSign - .broadcastTransaction1(transaction2, blockingStubFull); + Assert.assertThat( + transactionSignWeight1.getResult().getCode().toString(), + containsString("ENOUGH_PERMISSION")); + Return returnResult2 = + PublicMethodForMultiSign.broadcastTransaction1(transaction2, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("returnResult2:" + returnResult2); Account test001AddressAccount3 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -308,43 +346,44 @@ public void testMultiUpdatepermissions_49() { Assert.assertTrue(returnResult2.getResult()); } - /** - * constructor. - */ - private Transaction setReference(Transaction transaction, long blockNum, - byte[] blockHash) { + /** constructor. */ + private Transaction setReference(Transaction transaction, long blockNum, byte[] blockHash) { byte[] refBlockNum = ByteArray.fromLong(blockNum); - Transaction.raw rawData = transaction.getRawData().toBuilder() - .setRefBlockHash(ByteString.copyFrom(blockHash)) - .setRefBlockBytes(ByteString.copyFrom(refBlockNum)) - .build(); + Transaction.raw rawData = + transaction + .getRawData() + .toBuilder() + .setRefBlockHash(ByteString.copyFrom(blockHash)) + .setRefBlockBytes(ByteString.copyFrom(refBlockNum)) + .build(); return transaction.toBuilder().setRawData(rawData).build(); - } + } - /** - * constructor. - */ + /** constructor. */ public Transaction setExpiration(Transaction transaction, long expiration) { - Transaction.raw rawData = transaction.getRawData().toBuilder().setExpiration(expiration) - .build(); + Transaction.raw rawData = + transaction.getRawData().toBuilder().setExpiration(expiration).build(); return transaction.toBuilder().setRawData(rawData).build(); - } - - /** - * constructor. - */ - public Transaction createTransaction(com.google.protobuf.Message message, - ContractType contractType) { - Transaction.raw.Builder transactionBuilder = Transaction.raw.newBuilder().addContract( - Transaction.Contract.newBuilder().setType(contractType).setParameter( - Any.pack(message)).build()); - - Transaction transaction = Transaction.newBuilder().setRawData(transactionBuilder.build()) - .build(); + } + + /** constructor. */ + public Transaction createTransaction( + com.google.protobuf.Message message, ContractType contractType) { + Transaction.raw.Builder transactionBuilder = + Transaction.raw + .newBuilder() + .addContract( + Transaction.Contract.newBuilder() + .setType(contractType) + .setParameter(Any.pack(message)) + .build()); + + Transaction transaction = + Transaction.newBuilder().setRawData(transactionBuilder.build()).build(); long time = System.currentTimeMillis(); AtomicLong count = new AtomicLong(); long gtime = count.incrementAndGet() + time; - String ref = "" + gtime; + String ref = "" + gtime; transaction = setReference(transaction, gtime, ByteArray.fromString(ref)); @@ -358,11 +397,7 @@ public void aftertest() { PublicMethod.freeResource(test001Address, dev001Key, foundationAddress, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/network/BlockSyncTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/network/BlockSyncTest.java index 72332836..0838bdb4 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/network/BlockSyncTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/network/BlockSyncTest.java @@ -17,8 +17,8 @@ /** * Block synchronization tests. * - *

Verifies that two nodes stay in sync: block heights should converge - * and the same block number should have the same block hash on both nodes. + *

Verifies that two nodes stay in sync: block heights should converge and the same block number + * should have the same block hash on both nodes. */ @Slf4j @MultiNode(reason = "Block sync verification requires two independent nodes") @@ -35,7 +35,9 @@ public void beforeClass() { blockingStubFull2 = WalletGrpc.newBlockingStub(channelFull2); } - @Test(enabled = true, description = "Block heights on two nodes should be close", + @Test( + enabled = true, + description = "Block heights on two nodes should be close", groups = {"daily"}) public void test01BlockHeightConvergence() { // Wait for a fresh block to ensure both nodes are up-to-date @@ -50,11 +52,13 @@ public void test01BlockHeightConvergence() { logger.info("Node1 height: {}, Node2 height: {}, diff: {}", height1, height2, diff); // Allow up to 3 blocks difference (sync lag) - Assert.assertTrue(diff <= 3, - "Block height difference between nodes should be <= 3, got " + diff); + Assert.assertTrue( + diff <= 3, "Block height difference between nodes should be <= 3, got " + diff); } - @Test(enabled = true, description = "Same block number should have same content on both nodes", + @Test( + enabled = true, + description = "Same block number should have same content on both nodes", groups = {"daily"}) public void test02SameBlockSameContent() { PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -71,45 +75,58 @@ public void test02SameBlockSameContent() { // Compare block hash (witness_address + timestamp + number should match) long ts1 = blockOnNode1.getBlockHeader().getRawData().getTimestamp(); long ts2 = blockOnNode2.getBlockHeader().getRawData().getTimestamp(); - Assert.assertEquals(ts1, ts2, - "Block " + targetNum + " timestamp should match on both nodes"); + Assert.assertEquals(ts1, ts2, "Block " + targetNum + " timestamp should match on both nodes"); long num1 = blockOnNode1.getBlockHeader().getRawData().getNumber(); long num2 = blockOnNode2.getBlockHeader().getRawData().getNumber(); - Assert.assertEquals(num1, num2, - "Block number should match on both nodes"); + Assert.assertEquals(num1, num2, "Block number should match on both nodes"); - String witness1 = blockOnNode1.getBlockHeader().getRawData() - .getWitnessAddress().toStringUtf8(); - String witness2 = blockOnNode2.getBlockHeader().getRawData() - .getWitnessAddress().toStringUtf8(); - Assert.assertEquals(witness1, witness2, - "Block witness should match on both nodes"); + String witness1 = blockOnNode1.getBlockHeader().getRawData().getWitnessAddress().toStringUtf8(); + String witness2 = blockOnNode2.getBlockHeader().getRawData().getWitnessAddress().toStringUtf8(); + Assert.assertEquals(witness1, witness2, "Block witness should match on both nodes"); logger.info("Block {} verified consistent across both nodes", targetNum); } - @Test(enabled = true, description = "New blocks appear on both nodes after waiting", + @Test( + enabled = true, + description = "New blocks appear on both nodes after waiting", groups = {"daily"}) public void test03ContinuousSyncVerification() { - long startHeight1 = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder() - .build()).getBlockHeader().getRawData().getNumber(); - long startHeight2 = blockingStubFull2.getNowBlock(GrpcAPI.EmptyMessage.newBuilder() - .build()).getBlockHeader().getRawData().getNumber(); + long startHeight1 = + blockingStubFull + .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); + long startHeight2 = + blockingStubFull2 + .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); // Wait for 2 blocks PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull2); - long endHeight1 = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder() - .build()).getBlockHeader().getRawData().getNumber(); - long endHeight2 = blockingStubFull2.getNowBlock(GrpcAPI.EmptyMessage.newBuilder() - .build()).getBlockHeader().getRawData().getNumber(); + long endHeight1 = + blockingStubFull + .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); + long endHeight2 = + blockingStubFull2 + .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); Assert.assertTrue(endHeight1 > startHeight1, "Node1 should have new blocks"); Assert.assertTrue(endHeight2 > startHeight2, "Node2 should have new blocks"); - logger.info("Node1: {} -> {}, Node2: {} -> {}", - startHeight1, endHeight1, startHeight2, endHeight2); + logger.info( + "Node1: {} -> {}, Node2: {} -> {}", startHeight1, endHeight1, startHeight2, endHeight2); } @AfterClass(enabled = true) diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/network/CrossNodeConsistencyTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/network/CrossNodeConsistencyTest.java index f401750b..52df9e0c 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/network/CrossNodeConsistencyTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/network/CrossNodeConsistencyTest.java @@ -20,8 +20,8 @@ /** * Cross-node state consistency tests. * - *

Verifies that account balance and contract state are consistent - * when queried from different nodes after transactions are confirmed. + *

Verifies that account balance and contract state are consistent when queried from different + * nodes after transactions are confirmed. */ @Slf4j @MultiNode(reason = "Cross-node state consistency requires two nodes") @@ -46,13 +46,20 @@ public void beforeClass() { testKeyStr = ByteArray.toHexString(testEcKey.getPrivKeyBytes()); // Fund the test account - Assert.assertTrue(PublicMethod.sendcoin(testAddress, TronConstants.TEN_THOUSAND_TRX, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress, + TronConstants.TEN_THOUSAND_TRX, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Account balance should be consistent across nodes", + @Test( + enabled = true, + description = "Account balance should be consistent across nodes", groups = {"daily"}) public void test01BalanceConsistency() { Account accOnNode1 = PublicMethod.queryAccount(testAddress, blockingStubFull); @@ -61,11 +68,12 @@ public void test01BalanceConsistency() { long balance1 = accOnNode1.getBalance(); long balance2 = accOnNode2.getBalance(); logger.info("Balance on node1: {}, node2: {}", balance1, balance2); - Assert.assertEquals(balance1, balance2, - "Account balance should be identical on both nodes"); + Assert.assertEquals(balance1, balance2, "Account balance should be identical on both nodes"); } - @Test(enabled = true, dependsOnMethods = "test01BalanceConsistency", + @Test( + enabled = true, + dependsOnMethods = "test01BalanceConsistency", description = "Balance update via node1 should be reflected on node2", groups = {"daily"}) public void test02BalanceUpdatePropagation() { @@ -75,39 +83,48 @@ public void test02BalanceUpdatePropagation() { byte[] receiverAddr = receiverKey.getAddress(); // Transfer via node1 - Assert.assertTrue(PublicMethod.sendcoin(receiverAddr, sendAmount, - testAddress, testKeyStr, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin(receiverAddr, sendAmount, testAddress, testKeyStr, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); // Check sender balance consistency Account senderOnNode1 = PublicMethod.queryAccount(testAddress, blockingStubFull); Account senderOnNode2 = PublicMethod.queryAccount(testAddress, blockingStubFull2); - Assert.assertEquals(senderOnNode1.getBalance(), senderOnNode2.getBalance(), + Assert.assertEquals( + senderOnNode1.getBalance(), + senderOnNode2.getBalance(), "Sender balance should be consistent after transfer"); // Check receiver balance consistency Account receiverOnNode1 = PublicMethod.queryAccount(receiverAddr, blockingStubFull); Account receiverOnNode2 = PublicMethod.queryAccount(receiverAddr, blockingStubFull2); - Assert.assertEquals(receiverOnNode1.getBalance(), receiverOnNode2.getBalance(), + Assert.assertEquals( + receiverOnNode1.getBalance(), + receiverOnNode2.getBalance(), "Receiver balance should be consistent after transfer"); - Assert.assertEquals(receiverOnNode1.getBalance(), sendAmount, - "Receiver should have received the exact amount"); + Assert.assertEquals( + receiverOnNode1.getBalance(), sendAmount, "Receiver should have received the exact amount"); logger.info("Balance update propagated correctly to both nodes"); } - @Test(enabled = true, description = "Foundation account should be consistent on both nodes", + @Test( + enabled = true, + description = "Foundation account should be consistent on both nodes", groups = {"daily"}) public void test03FoundationAccountConsistency() { Account foundOnNode1 = PublicMethod.queryAccount(foundationAddress, blockingStubFull); Account foundOnNode2 = PublicMethod.queryAccount(foundationAddress, blockingStubFull2); - Assert.assertEquals(foundOnNode1.getBalance(), foundOnNode2.getBalance(), + Assert.assertEquals( + foundOnNode1.getBalance(), + foundOnNode2.getBalance(), "Foundation balance should be identical on both nodes"); - Assert.assertEquals(foundOnNode1.getAccountName(), foundOnNode2.getAccountName(), + Assert.assertEquals( + foundOnNode1.getAccountName(), + foundOnNode2.getAccountName(), "Foundation account name should match"); - logger.info("Foundation account consistent: balance={}", - foundOnNode1.getBalance()); + logger.info("Foundation account consistent: balance={}", foundOnNode1.getBalance()); } @AfterClass(enabled = true) diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/network/TransactionBroadcastTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/network/TransactionBroadcastTest.java index 28972cb7..8a03c43d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/network/TransactionBroadcastTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/network/TransactionBroadcastTest.java @@ -14,14 +14,13 @@ import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.TronConstants; import stest.tron.wallet.common.client.utils.Utils; /** * Cross-node transaction broadcast tests. * - *

Sends a transaction via node1 and verifies it is visible on node2, - * confirming P2P transaction propagation. + *

Sends a transaction via node1 and verifies it is visible on node2, confirming P2P transaction + * propagation. */ @Slf4j @MultiNode(reason = "Cross-node transaction broadcast verification") @@ -47,14 +46,17 @@ public void beforeClass() { PublicMethod.printAddress(receiverKeyStr); } - @Test(enabled = true, description = "Transaction sent via node1 should be visible on node2", + @Test( + enabled = true, + description = "Transaction sent via node1 should be visible on node2", groups = {"daily"}) public void test01TransactionPropagation() { long sendAmount = 1_000_000L; // 1 TRX // Send via node1 - String txId = PublicMethod.sendcoinGetTransactionId(receiverAddress, sendAmount, - foundationAddress, foundationKey, blockingStubFull); + String txId = + PublicMethod.sendcoinGetTransactionId( + receiverAddress, sendAmount, foundationAddress, foundationKey, blockingStubFull); Assert.assertNotNull(txId, "Transaction should be created on node1"); logger.info("Transaction sent via node1, txId: {}", txId); @@ -66,11 +68,13 @@ public void test01TransactionPropagation() { Account receiverAccount = PublicMethod.queryAccount(receiverAddress, blockingStubFull2); long balanceOnNode2 = receiverAccount.getBalance(); logger.info("Receiver balance on node2: {}", balanceOnNode2); - Assert.assertEquals(balanceOnNode2, sendAmount, - "Receiver balance on node2 should match sent amount"); + Assert.assertEquals( + balanceOnNode2, sendAmount, "Receiver balance on node2 should match sent amount"); } - @Test(enabled = true, dependsOnMethods = "test01TransactionPropagation", + @Test( + enabled = true, + dependsOnMethods = "test01TransactionPropagation", description = "Multiple transactions propagate correctly", groups = {"daily"}) public void test02MultipleTxPropagation() { @@ -81,8 +85,9 @@ public void test02MultipleTxPropagation() { // Send 3 transactions via node1 for (int i = 0; i < 3; i++) { - Assert.assertTrue(PublicMethod.sendcoin(receiverAddress, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + receiverAddress, sendAmount, foundationAddress, foundationKey, blockingStubFull)); } PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -91,7 +96,9 @@ public void test02MultipleTxPropagation() { Account afterAccount = PublicMethod.queryAccount(receiverAddress, blockingStubFull2); long balanceAfter = afterAccount.getBalance(); logger.info("Balance before: {}, after: {}", balanceBefore, balanceAfter); - Assert.assertEquals(balanceAfter - balanceBefore, sendAmount * 3, + Assert.assertEquals( + balanceAfter - balanceBefore, + sendAmount * 3, "All 3 transactions should propagate to node2"); } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAccountPermissionUpdateTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAccountPermissionUpdateTest.java index db9a61ec..f2c93674 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAccountPermissionUpdateTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAccountPermissionUpdateTest.java @@ -13,8 +13,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSignAccountPermissionUpdateTest extends TronBaseTest { @@ -22,15 +22,14 @@ public class MultiSignAccountPermissionUpdateTest extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final long totalSupply = now; private static String name = "MultiSign001_" + Long.toString(now); - private final String testKey001 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey001 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] fromAddress01 = PublicMethod.getFinalAddress(testKey001); - private final String operations = Configuration.getByPath("testng.conf") - .getString("defaultParameter.operations"); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private final String operations = + Configuration.getByPath("testng.conf").getString("defaultParameter.operations"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ByteString assetAccountId1; String[] permissionKeyString = new String[2]; String[] ownerKeyString = new String[2]; @@ -47,19 +46,18 @@ public class MultiSignAccountPermissionUpdateTest extends TronBaseTest { ECKey ecKey4 = new ECKey(Utils.getRandom()); byte[] participateAddress = ecKey4.getAddress(); String participateKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - - /** - * constructor. - */ + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, groups = {"contract", "daily"}) + @Test( + enabled = true, + groups = {"contract", "daily"}) public void testMultiSign1UpdatePermission() { ecKey1 = new ECKey(Utils.getRandom()); manager1Address = ecKey1.getAddress(); @@ -77,10 +75,10 @@ public void testMultiSign1UpdatePermission() { long needCoin = updateAccountPermissionFee * 2 + multiSignFee * 3; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, foundationKey, - blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -91,24 +89,33 @@ public void testMultiSign1UpdatePermission() { permissionKeyString1[0] = ownerKey; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - String txid = PublicMethodForMultiSign - .accountPermissionUpdateForTransactionId(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerKeyString); + String txid = + PublicMethodForMultiSign.accountPermissionUpdateForTransactionId( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); long energyFee = infoById.get().getReceipt().getEnergyFee(); @@ -124,26 +131,34 @@ public void testMultiSign1UpdatePermission() { Assert.assertEquals(fee, energyFee + netFee + updateAccountPermissionFee); balanceBefore = balanceAfter; - String accountPermissionJson1 = + String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - txid = PublicMethodForMultiSign - .accountPermissionUpdateForTransactionId1(accountPermissionJson1, ownerAddress, ownerKey, - blockingStubFull, 0, ownerKeyString); + txid = + PublicMethodForMultiSign.accountPermissionUpdateForTransactionId1( + accountPermissionJson1, ownerAddress, ownerKey, blockingStubFull, 0, ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); energyFee = infoById.get().getReceipt().getEnergyFee(); netFee = infoById.get().getReceipt().getNetFee(); @@ -153,16 +168,9 @@ public void testMultiSign1UpdatePermission() { logger.info("energyFee: " + energyFee); logger.info("netFee: " + netFee); logger.info("fee: " + fee); - - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAccountPermissionUpdateTest002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAccountPermissionUpdateTest002.java index 493ce681..306ce8f5 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAccountPermissionUpdateTest002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAccountPermissionUpdateTest002.java @@ -13,23 +13,22 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSignAccountPermissionUpdateTest002 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final long totalSupply = now; private static String name = "MultiSign001_" + Long.toString(now); - private final String testKey001 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey001 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] fromAddress01 = PublicMethod.getFinalAddress(testKey001); - private final String operations = Configuration.getByPath("testng.conf") - .getString("defaultParameter.operations"); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private final String operations = + Configuration.getByPath("testng.conf").getString("defaultParameter.operations"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ByteString assetAccountId1; String[] permissionKeyString = new String[2]; String[] ownerKeyString = new String[2]; @@ -46,19 +45,18 @@ public class MultiSignAccountPermissionUpdateTest002 extends TronBaseTest { ECKey ecKey4 = new ECKey(Utils.getRandom()); byte[] participateAddress = ecKey4.getAddress(); String participateKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - - /** - * constructor. - */ + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, groups = {"contract", "daily"}) + @Test( + enabled = true, + groups = {"contract", "daily"}) public void testMultiSign1UpdatePermission() { ecKey1 = new ECKey(Utils.getRandom()); manager1Address = ecKey1.getAddress(); @@ -76,10 +74,10 @@ public void testMultiSign1UpdatePermission() { long needCoin = updateAccountPermissionFee * 2 + multiSignFee * 3; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, needCoin, foundationAddress, foundationKey, - blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, needCoin, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -90,24 +88,33 @@ public void testMultiSign1UpdatePermission() { permissionKeyString1[0] = ownerKey; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - String txid = PublicMethodForMultiSign - .accountPermissionUpdateForTransactionId(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerKeyString); + String txid = + PublicMethodForMultiSign.accountPermissionUpdateForTransactionId( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); long energyFee = infoById.get().getReceipt().getEnergyFee(); @@ -123,26 +130,39 @@ public void testMultiSign1UpdatePermission() { Assert.assertEquals(fee, energyFee + netFee + updateAccountPermissionFee); balanceBefore = balanceAfter; - String accountPermissionJson1 = + String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - txid = PublicMethodForMultiSign - .accountPermissionUpdateForTransactionId1(accountPermissionJson1, ownerAddress, ownerKey, - blockingStubFull, 2, permissionKeyString); + txid = + PublicMethodForMultiSign.accountPermissionUpdateForTransactionId1( + accountPermissionJson1, + ownerAddress, + ownerKey, + blockingStubFull, + 2, + permissionKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); energyFee = infoById.get().getReceipt().getEnergyFee(); netFee = infoById.get().getReceipt().getNetFee(); @@ -152,16 +172,9 @@ public void testMultiSign1UpdatePermission() { logger.info("energyFee: " + energyFee); logger.info("netFee: " + netFee); logger.info("fee: " + fee); - - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAccountTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAccountTest.java index cf3a29fe..dd388d57 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAccountTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAccountTest.java @@ -15,12 +15,13 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class MultiSignAccountTest extends TronBaseTest { private String operations = Configuration.getByPath("testng.conf") - .getString("defaultParameter.operations"); +public class MultiSignAccountTest extends TronBaseTest { + private String operations = + Configuration.getByPath("testng.conf").getString("defaultParameter.operations"); ByteString assetAccountId1; String[] permissionKeyString = new String[2]; String[] ownerKeyString = new String[3]; @@ -37,21 +38,20 @@ public class MultiSignAccountTest extends TronBaseTest { private String operati ECKey ecKey4 = new ECKey(Utils.getRandom()); byte[] newAddress = ecKey4.getAddress(); String newKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - - /** - * constructor. - */ + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - //operations = "77ff1fc0037e0100000000000000000000000000000000000000000000000000"; + // operations = "77ff1fc0037e0100000000000000000000000000000000000000000000000000"; } - @Test(enabled = true, groups = {"contract", "daily"}) + @Test( + enabled = true, + groups = {"contract", "daily"}) public void testMultiSignForAccount() { ecKey1 = new ECKey(Utils.getRandom()); manager1Address = ecKey1.getAddress(); @@ -73,16 +73,25 @@ public void testMultiSignForAccount() { long needCoin = updateAccountPermissionFee * 1 + multiSignFee * 10; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, needCoin + 200000000L, foundationAddress, foundationKey, + PublicMethod.sendcoin( + ownerAddress, + needCoin + 200000000L, + foundationAddress, + foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 2000000000, 0, 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 2000000000, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -92,26 +101,37 @@ public void testMultiSignForAccount() { ownerKeyString[2] = manager2Key; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":3,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - String txid = PublicMethodForMultiSign - .accountPermissionUpdateForTransactionId(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerKeyString); - final String updateName = Long.toString(System.currentTimeMillis()); + String txid = + PublicMethodForMultiSign.accountPermissionUpdateForTransactionId( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); + final String updateName = Long.toString(System.currentTimeMillis()); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); long energyFee = infoById.get().getReceipt().getEnergyFee(); long netFee = infoById.get().getReceipt().getNetFee(); @@ -126,49 +146,66 @@ public void testMultiSignForAccount() { Assert.assertEquals(fee, energyFee + netFee + updateAccountPermissionFee); balanceBefore = balanceAfter; - byte[] accountName = String.valueOf(System.currentTimeMillis()).getBytes(); - Assert.assertTrue(PublicMethodForMultiSign.createAccount1( - ownerAddress, newAddress, ownerKey, blockingStubFull, 0, ownerKeyString)); + byte[] accountName = String.valueOf(System.currentTimeMillis()).getBytes(); + Assert.assertTrue( + PublicMethodForMultiSign.createAccount1( + ownerAddress, newAddress, ownerKey, blockingStubFull, 0, ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertTrue( - PublicMethodForMultiSign.setAccountId1(accountName, - ownerAddress, ownerKey, 0, blockingStubFull, ownerKeyString)); + PublicMethodForMultiSign.setAccountId1( + accountName, ownerAddress, ownerKey, 0, blockingStubFull, ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethodForMultiSign.sendcoinWithPermissionId( - newAddress, 100L, ownerAddress, 0, ownerKey, blockingStubFull, ownerKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + newAddress, 100L, ownerAddress, 0, ownerKey, blockingStubFull, ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethodForMultiSign.freezeBalanceWithPermissionId( - ownerAddress, 1000000L, 0, 0, ownerKey, blockingStubFull, ownerKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.freezeBalanceWithPermissionId( + ownerAddress, 1000000L, 0, 0, ownerKey, blockingStubFull, ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethodForMultiSign.freezeBalanceGetEnergyWithPermissionId( - ownerAddress, 1000000L, 0, 1, ownerKey, blockingStubFull, 0, ownerKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.freezeBalanceGetEnergyWithPermissionId( + ownerAddress, 1000000L, 0, 1, ownerKey, blockingStubFull, 0, ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - if(PublicMethod.tronPowerProposalIsOpen(blockingStubFull)) { - Assert.assertTrue(PublicMethodForMultiSign.freezeBalanceGetEnergyWithPermissionId( - ownerAddress, 1000000L, 0, 2, ownerKey, blockingStubFull, 0, ownerKeyString)); + if (PublicMethod.tronPowerProposalIsOpen(blockingStubFull)) { + Assert.assertTrue( + PublicMethodForMultiSign.freezeBalanceGetEnergyWithPermissionId( + ownerAddress, 1000000L, 0, 2, ownerKey, blockingStubFull, 0, ownerKeyString)); } else { - Assert.assertTrue(PublicMethodForMultiSign.freezeBalanceGetEnergyWithPermissionId( - ownerAddress, 1000000L, 0, 1, ownerKey, blockingStubFull, 0, ownerKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.freezeBalanceGetEnergyWithPermissionId( + ownerAddress, 1000000L, 0, 1, ownerKey, blockingStubFull, 0, ownerKeyString)); } - - if(!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + if (!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethodForMultiSign.freezeBalanceForReceiverWithPermissionId( - ownerAddress, 2000000L, 0, 0, ByteString.copyFrom(newAddress), - ownerKey, blockingStubFull, 0, ownerKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.freezeBalanceForReceiverWithPermissionId( + ownerAddress, + 2000000L, + 0, + 0, + ByteString.copyFrom(newAddress), + ownerKey, + blockingStubFull, + 0, + ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethodForMultiSign.unFreezeBalanceWithPermissionId( - ownerAddress, ownerKey, 0, null, 0, blockingStubFull, ownerKeyString)); - Assert.assertTrue(PublicMethodForMultiSign.unFreezeBalanceWithPermissionId( - ownerAddress, ownerKey, 0, newAddress, 0, blockingStubFull, ownerKeyString)); - Assert.assertTrue(PublicMethodForMultiSign.updateAccountWithPermissionId( - ownerAddress, updateName.getBytes(), ownerKey, blockingStubFull, 0, ownerKeyString)); - String voteStr = Base58.encode58Check(witnessAddress); + Assert.assertTrue( + PublicMethodForMultiSign.unFreezeBalanceWithPermissionId( + ownerAddress, ownerKey, 0, null, 0, blockingStubFull, ownerKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.unFreezeBalanceWithPermissionId( + ownerAddress, ownerKey, 0, newAddress, 0, blockingStubFull, ownerKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.updateAccountWithPermissionId( + ownerAddress, updateName.getBytes(), ownerKey, blockingStubFull, 0, ownerKeyString)); + String voteStr = Base58.encode58Check(witnessAddress); HashMap smallVoteMap = new HashMap(); smallVoteMap.put(voteStr, "1"); - Assert.assertTrue(PublicMethodForMultiSign.voteWitnessWithPermissionId( - smallVoteMap, ownerAddress, ownerKey, blockingStubFull, 0, ownerKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.voteWitnessWithPermissionId( + smallVoteMap, ownerAddress, ownerKey, blockingStubFull, 0, ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -177,17 +214,12 @@ public void testMultiSignForAccount() { Assert.assertEquals(balanceBefore - balanceAfter, multiSignFee * 11 + 3000000 + 100); Assert.assertTrue( - PublicMethod.unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull)); + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull)); } - - } - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAccountTest002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAccountTest002.java index cf4bafcf..19cec153 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAccountTest002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAccountTest002.java @@ -15,12 +15,13 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class MultiSignAccountTest002 extends TronBaseTest { private final String operations = Configuration.getByPath("testng.conf") - .getString("defaultParameter.operations"); +public class MultiSignAccountTest002 extends TronBaseTest { + private final String operations = + Configuration.getByPath("testng.conf").getString("defaultParameter.operations"); ByteString assetAccountId1; String[] permissionKeyString = new String[2]; String[] ownerKeyString = new String[3]; @@ -37,19 +38,18 @@ public class MultiSignAccountTest002 extends TronBaseTest { private final Strin ECKey ecKey4 = new ECKey(Utils.getRandom()); byte[] newAddress = ecKey4.getAddress(); String newKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - - /** - * constructor. - */ + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, groups = {"contract", "daily"}) + @Test( + enabled = true, + groups = {"contract", "daily"}) public void testMultiSignForAccount() { ecKey1 = new ECKey(Utils.getRandom()); manager1Address = ecKey1.getAddress(); @@ -71,16 +71,25 @@ public void testMultiSignForAccount() { long needCoin = updateAccountPermissionFee * 1 + multiSignFee * 10; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, needCoin + 100000000L, foundationAddress, foundationKey, + PublicMethod.sendcoin( + ownerAddress, + needCoin + 100000000L, + foundationAddress, + foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 1000000000, 0, 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000000, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -90,27 +99,38 @@ public void testMultiSignForAccount() { ownerKeyString[2] = manager2Key; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":3,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - String txid = PublicMethodForMultiSign - .accountPermissionUpdateForTransactionId(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerKeyString); + String txid = + PublicMethodForMultiSign.accountPermissionUpdateForTransactionId( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); - final String updateName = Long.toString(System.currentTimeMillis()); + final String updateName = Long.toString(System.currentTimeMillis()); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); long energyFee = infoById.get().getReceipt().getEnergyFee(); long netFee = infoById.get().getReceipt().getNetFee(); @@ -126,36 +146,63 @@ public void testMultiSignForAccount() { balanceBefore = balanceAfter; - - if(!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + if (!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { byte[] accountName = String.valueOf(System.currentTimeMillis()).getBytes(); - Assert.assertTrue(PublicMethodForMultiSign.createAccount1( - ownerAddress, newAddress, ownerKey, blockingStubFull, 2, permissionKeyString)); Assert.assertTrue( - PublicMethodForMultiSign.setAccountId1(accountName, - ownerAddress, ownerKey, 2, blockingStubFull, permissionKeyString)); - Assert.assertTrue(PublicMethodForMultiSign.sendcoinWithPermissionId( - newAddress, 100L, ownerAddress, 2, ownerKey, blockingStubFull, permissionKeyString)); - Assert.assertTrue(PublicMethodForMultiSign.freezeBalanceWithPermissionId( - ownerAddress, 1000000L, 0, 2, ownerKey, blockingStubFull, permissionKeyString)); - Assert.assertTrue(PublicMethodForMultiSign.freezeBalanceGetEnergyWithPermissionId( - ownerAddress, 1000000L, 0, PublicMethod.tronPowerProposalIsOpen(blockingStubFull) ? 2 : 1, ownerKey, blockingStubFull, 2, permissionKeyString)); - - Assert.assertTrue(PublicMethodForMultiSign.freezeBalanceForReceiverWithPermissionId( - ownerAddress, 1000000L, 0, 0, ByteString.copyFrom(newAddress), - ownerKey, blockingStubFull, 2, permissionKeyString)); - Assert.assertTrue(PublicMethodForMultiSign.unFreezeBalanceWithPermissionId( - ownerAddress, ownerKey, 0, null, 2, blockingStubFull, permissionKeyString)); - Assert.assertTrue(PublicMethodForMultiSign.unFreezeBalanceWithPermissionId( - ownerAddress, ownerKey, 0, newAddress, 2, blockingStubFull, permissionKeyString)); - Assert.assertTrue(PublicMethodForMultiSign.updateAccountWithPermissionId( - ownerAddress, updateName.getBytes(), ownerKey, blockingStubFull, 2, permissionKeyString)); - String voteStr = Base58.encode58Check(witnessAddress); + PublicMethodForMultiSign.createAccount1( + ownerAddress, newAddress, ownerKey, blockingStubFull, 2, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.setAccountId1( + accountName, ownerAddress, ownerKey, 2, blockingStubFull, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + newAddress, 100L, ownerAddress, 2, ownerKey, blockingStubFull, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.freezeBalanceWithPermissionId( + ownerAddress, 1000000L, 0, 2, ownerKey, blockingStubFull, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.freezeBalanceGetEnergyWithPermissionId( + ownerAddress, + 1000000L, + 0, + PublicMethod.tronPowerProposalIsOpen(blockingStubFull) ? 2 : 1, + ownerKey, + blockingStubFull, + 2, + permissionKeyString)); + + Assert.assertTrue( + PublicMethodForMultiSign.freezeBalanceForReceiverWithPermissionId( + ownerAddress, + 1000000L, + 0, + 0, + ByteString.copyFrom(newAddress), + ownerKey, + blockingStubFull, + 2, + permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.unFreezeBalanceWithPermissionId( + ownerAddress, ownerKey, 0, null, 2, blockingStubFull, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.unFreezeBalanceWithPermissionId( + ownerAddress, ownerKey, 0, newAddress, 2, blockingStubFull, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.updateAccountWithPermissionId( + ownerAddress, + updateName.getBytes(), + ownerKey, + blockingStubFull, + 2, + permissionKeyString)); + String voteStr = Base58.encode58Check(witnessAddress); HashMap smallVoteMap = new HashMap(); smallVoteMap.put(voteStr, "1"); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethodForMultiSign.voteWitnessWithPermissionId( - smallVoteMap, ownerAddress, ownerKey, blockingStubFull, 2, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.voteWitnessWithPermissionId( + smallVoteMap, ownerAddress, ownerKey, blockingStubFull, 2, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -164,17 +211,12 @@ public void testMultiSignForAccount() { Assert.assertEquals(balanceBefore - balanceAfter, multiSignFee * 10 + 2000000 + 100); Assert.assertTrue( - PublicMethod.unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull)); + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull)); } - - } - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAssetTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAssetTest.java index 79e4f5c3..fca3029e 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAssetTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAssetTest.java @@ -14,23 +14,22 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSignAssetTest extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final long totalSupply = now; private static String name = "MultiSign001_" + Long.toString(now); - private final String testKey001 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey001 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] fromAddress01 = PublicMethod.getFinalAddress(testKey001); - private final String operations = Configuration.getByPath("testng.conf") - .getString("defaultParameter.operations"); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private final String operations = + Configuration.getByPath("testng.conf").getString("defaultParameter.operations"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ByteString assetAccountId1; String[] permissionKeyString = new String[2]; String[] ownerKeyString = new String[2]; @@ -47,19 +46,18 @@ public class MultiSignAssetTest extends TronBaseTest { ECKey ecKey4 = new ECKey(Utils.getRandom()); byte[] participateAddress = ecKey4.getAddress(); String participateKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - - /** - * constructor. - */ + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, groups = {"contract", "daily"}) + @Test( + enabled = true, + groups = {"contract", "daily"}) public void testMultiSign1CreateAssetissue() { ecKey1 = new ECKey(Utils.getRandom()); manager1Address = ecKey1.getAddress(); @@ -77,10 +75,14 @@ public void testMultiSign1CreateAssetissue() { long needCoin = updateAccountPermissionFee * 1 + multiSignFee * 3; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, needCoin + 2048000000L, foundationAddress, foundationKey, + PublicMethod.sendcoin( + ownerAddress, + needCoin + 2048000000L, + foundationAddress, + foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -91,24 +93,33 @@ public void testMultiSign1CreateAssetissue() { permissionKeyString1[0] = ownerKey; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - String txid = PublicMethodForMultiSign - .accountPermissionUpdateForTransactionId(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerKeyString); + String txid = + PublicMethodForMultiSign.accountPermissionUpdateForTransactionId( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); long energyFee = infoById.get().getReceipt().getEnergyFee(); @@ -124,20 +135,35 @@ public void testMultiSign1CreateAssetissue() { Assert.assertEquals(fee, energyFee + netFee + updateAccountPermissionFee); balanceBefore = balanceAfter; - Long start = System.currentTimeMillis() + 5000; - Long end = System.currentTimeMillis() + 1000000000; + Long start = System.currentTimeMillis() + 5000; + Long end = System.currentTimeMillis() + 1000000000; logger.info("try create asset issue"); - txid = PublicMethodForMultiSign - .createAssetIssueForTransactionId1(ownerAddress, name, totalSupply, 1, - 1, start, end, 1, description, url, 2000L, 2000L, - 1L, 1L, ownerKey, blockingStubFull, 0, ownerKeyString); + txid = + PublicMethodForMultiSign.createAssetIssueForTransactionId1( + ownerAddress, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + ownerKey, + blockingStubFull, + 0, + ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); energyFee = infoById.get().getReceipt().getEnergyFee(); netFee = infoById.get().getReceipt().getNetFee(); @@ -154,29 +180,35 @@ public void testMultiSign1CreateAssetissue() { logger.info(" create asset end"); } - /** - * constructor. - */ - - @Test(enabled = true, groups = {"contract", "daily"}) + /** constructor. */ + @Test( + enabled = true, + groups = {"contract", "daily"}) public void testMultiSign2TransferAssetissue() { PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.printAddress(manager1Key); Account getAssetIdFromOwnerAccount; getAssetIdFromOwnerAccount = PublicMethod.queryAccount(ownerAddress, blockingStubFull); assetAccountId1 = getAssetIdFromOwnerAccount.getAssetIssuedID(); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); - String txid = PublicMethodForMultiSign.transferAssetForTransactionId1(manager1Address, - assetAccountId1.toByteArray(), 10, ownerAddress, ownerKey, blockingStubFull, - 0, ownerKeyString); + String txid = + PublicMethodForMultiSign.transferAssetForTransactionId1( + manager1Address, + assetAccountId1.toByteArray(), + 10, + ownerAddress, + ownerKey, + blockingStubFull, + 0, + ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); long energyFee = infoById.get().getReceipt().getEnergyFee(); long netFee = infoById.get().getReceipt().getNetFee(); @@ -191,11 +223,10 @@ public void testMultiSign2TransferAssetissue() { Assert.assertEquals(fee, energyFee + netFee + multiSignFee + 1000000L); } - /** - * constructor. - */ - - @Test(enabled = true, groups = {"contract", "daily"}) + /** constructor. */ + @Test( + enabled = true, + groups = {"contract", "daily"}) public void testMultiSign3ParticipateAssetissue() { ecKey4 = new ECKey(Utils.getRandom()); participateAddress = ecKey4.getAddress(); @@ -204,38 +235,55 @@ public void testMultiSign3ParticipateAssetissue() { long needCoin = updateAccountPermissionFee * 1 + multiSignFee * 2; Assert.assertTrue( - PublicMethod.sendcoin(participateAddress, needCoin + 2048000000L, foundationAddress, foundationKey, + PublicMethod.sendcoin( + participateAddress, + needCoin + 2048000000L, + foundationAddress, + foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(participateAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = + PublicMethod.queryAccount(participateAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); ownerKeyString[0] = participateKey; ownerKeyString[1] = manager1Key; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(participateKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(participateKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - String txid = PublicMethodForMultiSign - .accountPermissionUpdateForTransactionId(accountPermissionJson, participateAddress, - participateKey, blockingStubFull, ownerKeyString); + String txid = + PublicMethodForMultiSign.accountPermissionUpdateForTransactionId( + accountPermissionJson, + participateAddress, + participateKey, + blockingStubFull, + ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - long balanceAfter = PublicMethod.queryAccount(participateAddress, blockingStubFull) - .getBalance(); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + long balanceAfter = + PublicMethod.queryAccount(participateAddress, blockingStubFull).getBalance(); long energyFee = infoById.get().getReceipt().getEnergyFee(); long netFee = infoById.get().getReceipt().getNetFee(); long fee = infoById.get().getFee(); @@ -250,15 +298,20 @@ public void testMultiSign3ParticipateAssetissue() { balanceBefore = balanceAfter; - txid = PublicMethodForMultiSign.participateAssetIssueForTransactionId(ownerAddress, - assetAccountId1.toByteArray(), 10, participateAddress, participateKey, 0, - blockingStubFull, ownerKeyString); + txid = + PublicMethodForMultiSign.participateAssetIssueForTransactionId( + ownerAddress, + assetAccountId1.toByteArray(), + 10, + participateAddress, + participateKey, + 0, + blockingStubFull, + ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - balanceAfter = PublicMethod.queryAccount(participateAddress, blockingStubFull) - .getBalance(); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); + balanceAfter = PublicMethod.queryAccount(participateAddress, blockingStubFull).getBalance(); energyFee = infoById.get().getReceipt().getEnergyFee(); netFee = infoById.get().getReceipt().getNetFee(); fee = infoById.get().getFee(); @@ -271,26 +324,33 @@ public void testMultiSign3ParticipateAssetissue() { Assert.assertEquals(fee, energyFee + netFee + multiSignFee); } - /** - * constructor. - */ - - @Test(enabled = true, groups = {"contract", "daily"}) + /** constructor. */ + @Test( + enabled = true, + groups = {"contract", "daily"}) public void testMultiSign4updateAssetissue() { url = "MultiSign001_update_url" + Long.toString(now); ownerKeyString[0] = ownerKey; description = "MultiSign001_update_description" + Long.toString(now); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); - String txid = PublicMethodForMultiSign - .updateAssetForTransactionId(ownerAddress, description.getBytes(), url.getBytes(), 100L, - 100L, ownerKey, 0, blockingStubFull, ownerKeyString); + String txid = + PublicMethodForMultiSign.updateAssetForTransactionId( + ownerAddress, + description.getBytes(), + url.getBytes(), + 100L, + 100L, + ownerKey, + 0, + blockingStubFull, + ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); long energyFee = infoById.get().getReceipt().getEnergyFee(); long netFee = infoById.get().getReceipt().getNetFee(); @@ -305,12 +365,7 @@ public void testMultiSign4updateAssetissue() { Assert.assertEquals(fee, energyFee + netFee + multiSignFee); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAssetTest002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAssetTest002.java index bfcfabf9..f015bc95 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAssetTest002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignAssetTest002.java @@ -14,23 +14,22 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSignAssetTest002 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final long totalSupply = now; private static String name = "MultiSign001_" + Long.toString(now); - private final String testKey001 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey001 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] fromAddress01 = PublicMethod.getFinalAddress(testKey001); - private final String operations = Configuration.getByPath("testng.conf") - .getString("defaultParameter.operations"); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private final String operations = + Configuration.getByPath("testng.conf").getString("defaultParameter.operations"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ByteString assetAccountId1; String[] permissionKeyString = new String[2]; String[] ownerKeyString = new String[2]; @@ -47,19 +46,18 @@ public class MultiSignAssetTest002 extends TronBaseTest { ECKey ecKey4 = new ECKey(Utils.getRandom()); byte[] participateAddress = ecKey4.getAddress(); String participateKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - - /** - * constructor. - */ + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, groups = {"contract", "daily"}) + @Test( + enabled = true, + groups = {"contract", "daily"}) public void testMultiSign1CreateAssetissue() { ecKey1 = new ECKey(Utils.getRandom()); manager1Address = ecKey1.getAddress(); @@ -77,10 +75,14 @@ public void testMultiSign1CreateAssetissue() { long needCoin = updateAccountPermissionFee * 1 + multiSignFee * 3; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, needCoin + 2048000000L, foundationAddress, foundationKey, + PublicMethod.sendcoin( + ownerAddress, + needCoin + 2048000000L, + foundationAddress, + foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -91,24 +93,33 @@ public void testMultiSign1CreateAssetissue() { permissionKeyString1[0] = ownerKey; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - String txid = PublicMethodForMultiSign - .accountPermissionUpdateForTransactionId(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerKeyString); + String txid = + PublicMethodForMultiSign.accountPermissionUpdateForTransactionId( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); long energyFee = infoById.get().getReceipt().getEnergyFee(); @@ -124,20 +135,35 @@ public void testMultiSign1CreateAssetissue() { Assert.assertEquals(fee, energyFee + netFee + updateAccountPermissionFee); balanceBefore = balanceAfter; - Long start = System.currentTimeMillis() + 5000; - Long end = System.currentTimeMillis() + 1000000000; + Long start = System.currentTimeMillis() + 5000; + Long end = System.currentTimeMillis() + 1000000000; logger.info("try create asset issue"); - txid = PublicMethodForMultiSign - .createAssetIssueForTransactionId1(ownerAddress, name, totalSupply, 1, - 1, start, end, 1, description, url, 2000L, 2000L, - 1L, 1L, ownerKey, blockingStubFull, 2, permissionKeyString); + txid = + PublicMethodForMultiSign.createAssetIssueForTransactionId1( + ownerAddress, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + ownerKey, + blockingStubFull, + 2, + permissionKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); energyFee = infoById.get().getReceipt().getEnergyFee(); netFee = infoById.get().getReceipt().getNetFee(); @@ -154,29 +180,35 @@ public void testMultiSign1CreateAssetissue() { logger.info(" create asset end"); } - /** - * constructor. - */ - - @Test(enabled = true, groups = {"contract", "daily"}) + /** constructor. */ + @Test( + enabled = true, + groups = {"contract", "daily"}) public void testMultiSign2TransferAssetissue() { PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.printAddress(manager1Key); Account getAssetIdFromOwnerAccount; getAssetIdFromOwnerAccount = PublicMethod.queryAccount(ownerAddress, blockingStubFull); assetAccountId1 = getAssetIdFromOwnerAccount.getAssetIssuedID(); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); - String txid = PublicMethodForMultiSign.transferAssetForTransactionId1(manager1Address, - assetAccountId1.toByteArray(), 10, ownerAddress, ownerKey, blockingStubFull, - 2, permissionKeyString); + String txid = + PublicMethodForMultiSign.transferAssetForTransactionId1( + manager1Address, + assetAccountId1.toByteArray(), + 10, + ownerAddress, + ownerKey, + blockingStubFull, + 2, + permissionKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); long energyFee = infoById.get().getReceipt().getEnergyFee(); long netFee = infoById.get().getReceipt().getNetFee(); @@ -191,11 +223,10 @@ public void testMultiSign2TransferAssetissue() { Assert.assertEquals(fee, energyFee + netFee + multiSignFee + 1000000L); } - /** - * constructor. - */ - - @Test(enabled = true, groups = {"contract", "daily"}) + /** constructor. */ + @Test( + enabled = true, + groups = {"contract", "daily"}) public void testMultiSign3ParticipateAssetissue() { ecKey4 = new ECKey(Utils.getRandom()); participateAddress = ecKey4.getAddress(); @@ -204,39 +235,56 @@ public void testMultiSign3ParticipateAssetissue() { long needCoin = updateAccountPermissionFee * 1 + multiSignFee * 2; Assert.assertTrue( - PublicMethod.sendcoin(participateAddress, needCoin + 2048000000L, foundationAddress, foundationKey, + PublicMethod.sendcoin( + participateAddress, + needCoin + 2048000000L, + foundationAddress, + foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(participateAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = + PublicMethod.queryAccount(participateAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); ownerKeyString[0] = participateKey; ownerKeyString[1] = manager1Key; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(participateKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(participateKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - String txid = PublicMethodForMultiSign - .accountPermissionUpdateForTransactionId(accountPermissionJson, participateAddress, - participateKey, blockingStubFull, ownerKeyString); + String txid = + PublicMethodForMultiSign.accountPermissionUpdateForTransactionId( + accountPermissionJson, + participateAddress, + participateKey, + blockingStubFull, + ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - long balanceAfter = PublicMethod.queryAccount(participateAddress, blockingStubFull) - .getBalance(); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + long balanceAfter = + PublicMethod.queryAccount(participateAddress, blockingStubFull).getBalance(); long energyFee = infoById.get().getReceipt().getEnergyFee(); long netFee = infoById.get().getReceipt().getNetFee(); long fee = infoById.get().getFee(); @@ -251,16 +299,21 @@ public void testMultiSign3ParticipateAssetissue() { balanceBefore = balanceAfter; - txid = PublicMethodForMultiSign.participateAssetIssueForTransactionId(ownerAddress, - assetAccountId1.toByteArray(), 10, participateAddress, participateKey, 2, - blockingStubFull, permissionKeyString); + txid = + PublicMethodForMultiSign.participateAssetIssueForTransactionId( + ownerAddress, + assetAccountId1.toByteArray(), + 10, + participateAddress, + participateKey, + 2, + blockingStubFull, + permissionKeyString); Assert.assertNotNull(txid); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - balanceAfter = PublicMethod.queryAccount(participateAddress, blockingStubFull) - .getBalance(); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); + balanceAfter = PublicMethod.queryAccount(participateAddress, blockingStubFull).getBalance(); energyFee = infoById.get().getReceipt().getEnergyFee(); netFee = infoById.get().getReceipt().getNetFee(); fee = infoById.get().getFee(); @@ -270,31 +323,37 @@ public void testMultiSign3ParticipateAssetissue() { logger.info("netFee: " + netFee); logger.info("fee: " + fee); - Assert.assertEquals(balanceBefore - balanceAfter, fee + 10); Assert.assertEquals(fee, energyFee + netFee + multiSignFee); } - /** - * constructor. - */ - - @Test(enabled = true, groups = {"contract", "daily"}) + /** constructor. */ + @Test( + enabled = true, + groups = {"contract", "daily"}) public void testMultiSign4updateAssetissue() { url = "MultiSign001_update_url" + Long.toString(now); ownerKeyString[0] = ownerKey; description = "MultiSign001_update_description" + Long.toString(now); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); - String txid = PublicMethodForMultiSign - .updateAssetForTransactionId(ownerAddress, description.getBytes(), url.getBytes(), 100L, - 100L, ownerKey, 2, blockingStubFull, permissionKeyString); + String txid = + PublicMethodForMultiSign.updateAssetForTransactionId( + ownerAddress, + description.getBytes(), + url.getBytes(), + 100L, + 100L, + ownerKey, + 2, + blockingStubFull, + permissionKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); long energyFee = infoById.get().getReceipt().getEnergyFee(); long netFee = infoById.get().getReceipt().getNetFee(); @@ -309,12 +368,7 @@ public void testMultiSign4updateAssetissue() { Assert.assertEquals(fee, energyFee + netFee + multiSignFee); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignClearContractAbiTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignClearContractAbiTest.java index 26c2acc7..6889b58c 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignClearContractAbiTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignClearContractAbiTest.java @@ -20,16 +20,17 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode -public class MultiSignClearContractAbiTest extends TronBaseTest { private final String operations = Configuration.getByPath("testng.conf") - .getString("defaultParameter.operations"); +public class MultiSignClearContractAbiTest extends TronBaseTest { + private final String operations = + Configuration.getByPath("testng.conf").getString("defaultParameter.operations"); ArrayList txidList = new ArrayList(); Optional infoById = null; Long beforeTime; @@ -50,27 +51,27 @@ public class MultiSignClearContractAbiTest extends TronBaseTest { private final ECKey ecKey3 = new ECKey(Utils.getRandom()); byte[] ownerAddress = ecKey3.getAddress(); String ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + public void beforeClass() { + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } - @Test(enabled = true, threadPoolSize = 1, invocationCount = 1, groups = {"contract", "daily"}) + @Test( + enabled = true, + threadPoolSize = 1, + invocationCount = 1, + groups = {"contract", "daily"}) public void test1MultiSignForClearContractAbi() { ecKey1 = new ECKey(Utils.getRandom()); manager1Address = ecKey1.getAddress(); @@ -88,18 +89,33 @@ public void test1MultiSignForClearContractAbi() { long needcoin = updateAccountPermissionFee + multiSignFee * 4; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, needcoin + 100000000L, foundationAddress, foundationKey, + PublicMethod.sendcoin( + ownerAddress, + needcoin + 100000000L, + foundationAddress, + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000000 + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000000 + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 1, + ByteString.copyFrom(ownerAddress), + foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 1000000000 + PublicMethod.randomFreezeAmount.getAndAdd(1), 0, 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 1000000000 + PublicMethod.randomFreezeAmount.getAndAdd(1), 0, 1, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -109,41 +125,64 @@ public void test1MultiSignForClearContractAbi() { ownerKeyString[1] = manager1Key; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerKeyString); + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long maxFeeLimit = 1000000000L; - String filePath = "./src/test/resources/soliditycode/TriggerConstant004.sol"; - String contractName = "testConstantContract"; + Long maxFeeLimit = 1000000000L; + String filePath = "./src/test/resources/soliditycode/TriggerConstant004.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] contractAddress = PublicMethodForMultiSign.deployContract1(contractName, abi, code, - "", maxFeeLimit, - 0L, 100, null, ownerKey, ownerAddress, blockingStubFull, 2, permissionKeyString); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress = + PublicMethodForMultiSign.deployContract1( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + ownerKey, + ownerAddress, + blockingStubFull, + 2, + permissionKeyString); logger.info("address:" + Base58.encode58Check(contractAddress)); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotEquals(smartContract.getAbi().toString(), ""); - Assert.assertTrue(PublicMethodForMultiSign - .clearContractAbi(contractAddress, ownerAddress, ownerKey, - blockingStubFull, 2, permissionKeyString)); - - + Assert.assertTrue( + PublicMethodForMultiSign.clearContractAbi( + contractAddress, ownerAddress, ownerKey, blockingStubFull, 2, permissionKeyString)); } - @Test(enabled = true, threadPoolSize = 1, invocationCount = 1, groups = {"contract", "daily"}) + @Test( + enabled = true, + threadPoolSize = 1, + invocationCount = 1, + groups = {"contract", "daily"}) public void test2MultiSignForClearContractAbiForDefault() { ecKey1 = new ECKey(Utils.getRandom()); manager1Address = ecKey1.getAddress(); @@ -161,18 +200,33 @@ public void test2MultiSignForClearContractAbiForDefault() { long needcoin = updateAccountPermissionFee + multiSignFee * 4; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, needcoin + 100000000L, foundationAddress, foundationKey, + PublicMethod.sendcoin( + ownerAddress, + needcoin + 100000000L, + foundationAddress, + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000000, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000000, + 0, + 1, + ByteString.copyFrom(ownerAddress), + foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 1000000000, 0, 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 1000000000, 0, 1, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -182,42 +236,66 @@ public void test2MultiSignForClearContractAbiForDefault() { ownerKeyString[1] = manager1Key; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerKeyString); + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long maxFeeLimit = 1000000000L; - String filePath = "./src/test/resources/soliditycode/TriggerConstant004.sol"; - String contractName = "testConstantContract"; + Long maxFeeLimit = 1000000000L; + String filePath = "./src/test/resources/soliditycode/TriggerConstant004.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] contractAddress = PublicMethodForMultiSign.deployContract1(contractName, abi, code, - "", maxFeeLimit, - 0L, 100, null, ownerKey, ownerAddress, blockingStubFull, 2, permissionKeyString); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress = + PublicMethodForMultiSign.deployContract1( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + ownerKey, + ownerAddress, + blockingStubFull, + 2, + permissionKeyString); logger.info("address:" + Base58.encode58Check(contractAddress)); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); - Assert.assertTrue(smartContract.getAbi().toString() != null && - !("".equalsIgnoreCase(smartContract.getAbi().toString()))); - Assert.assertTrue(PublicMethodForMultiSign - .clearContractAbi(contractAddress, ownerAddress, ownerKey, - blockingStubFull, 2, permissionKeyString)); - + Assert.assertTrue( + smartContract.getAbi().toString() != null + && !("".equalsIgnoreCase(smartContract.getAbi().toString()))); + Assert.assertTrue( + PublicMethodForMultiSign.clearContractAbi( + contractAddress, ownerAddress, ownerKey, blockingStubFull, 2, permissionKeyString)); } - - @Test(enabled = true, threadPoolSize = 1, invocationCount = 1, groups = {"contract", "daily"}) + @Test( + enabled = true, + threadPoolSize = 1, + invocationCount = 1, + groups = {"contract", "daily"}) public void test3MultiSignForClearContractAbiForDefault() { ecKey3 = new ECKey(Utils.getRandom()); ownerAddress = ecKey3.getAddress(); @@ -227,51 +305,76 @@ public void test3MultiSignForClearContractAbiForDefault() { long needcoin = updateAccountPermissionFee + multiSignFee * 4; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, needcoin + 100000000L, foundationAddress, foundationKey, + PublicMethod.sendcoin( + ownerAddress, + needcoin + 100000000L, + foundationAddress, + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000000, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000000, + 0, + 1, + ByteString.copyFrom(ownerAddress), + foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 1000000000, 0, 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 1000000000, 0, 1, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); String[] activeDefaultKeyString = new String[1]; activeDefaultKeyString[0] = ownerKey; PublicMethod.waitProduceNextBlock(blockingStubFull); - Long maxFeeLimit = 1000000000L; - String filePath = "./src/test/resources/soliditycode/TriggerConstant004.sol"; - String contractName = "testConstantContract"; + Long maxFeeLimit = 1000000000L; + String filePath = "./src/test/resources/soliditycode/TriggerConstant004.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] contractAddress = PublicMethodForMultiSign.deployContract1(contractName, abi, code, - "", maxFeeLimit, - 0L, 100, null, ownerKey, ownerAddress, blockingStubFull, 2, activeDefaultKeyString); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress = + PublicMethodForMultiSign.deployContract1( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + ownerKey, + ownerAddress, + blockingStubFull, + 2, + activeDefaultKeyString); logger.info("address:" + Base58.encode58Check(contractAddress)); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString() != null); - Assert.assertTrue(PublicMethodForMultiSign - .clearContractAbi(contractAddress, ownerAddress, ownerKey, - blockingStubFull, 2, activeDefaultKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.clearContractAbi( + contractAddress, ownerAddress, ownerKey, blockingStubFull, 2, activeDefaultKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { if (channelFull1 != null) { + public void shutdown() throws InterruptedException { + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignExchangeContractTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignExchangeContractTest.java index 905936a5..84b76c11 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignExchangeContractTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignExchangeContractTest.java @@ -1,7 +1,6 @@ package stest.tron.wallet.dailybuild.operationupdate; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.Optional; import lombok.extern.slf4j.Slf4j; @@ -9,7 +8,6 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.tron.api.GrpcAPI.ExchangeList; import org.tron.api.WalletSolidityGrpc; import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.Exchange; @@ -18,8 +16,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSignExchangeContractTest extends TronBaseTest { @@ -27,8 +25,8 @@ public class MultiSignExchangeContractTest extends TronBaseTest { private static final long totalSupply = 1000000001L; private static String name1 = "exchange001_1_" + Long.toString(now); private static String name2 = "exchange001_2_" + Long.toString(now); - private final String operations = Configuration.getByPath("testng.conf") - .getString("defaultParameter.operations"); + private final String operations = + Configuration.getByPath("testng.conf").getString("defaultParameter.operations"); String description = "just-test"; String url = "https://github.com/tronprotocol/wallet-cli/"; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -56,25 +54,24 @@ public class MultiSignExchangeContractTest extends TronBaseTest { Integer exchangeRate = 10; Long firstTokenInitialBalance = 10000L; Long secondTokenInitialBalance = firstTokenInitialBalance * exchangeRate; - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1); - - /** - * constructor. - */ - + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = false, description = "MultiSign for create token", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "MultiSign for create token", + groups = {"contract", "daily"}) public void test1CreateUsedAsset() { ecKey1 = new ECKey(Utils.getRandom()); exchange001Address = ecKey1.getAddress(); @@ -87,27 +84,71 @@ public void test1CreateUsedAsset() { PublicMethod.printAddress(exchange001Key); PublicMethod.printAddress(secondExchange001Key); - Assert.assertTrue(PublicMethod.sendcoin(exchange001Address, 10240000000L, foundationAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(secondExchange001Address, 10240000000L, foundationAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 100000000000L + PublicMethod.randomFreezeAmount.addAndGet(1), 0, 0, + Assert.assertTrue( + PublicMethod.sendcoin( + exchange001Address, 10240000000L, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + secondExchange001Address, + 10240000000L, + foundationAddress, + testKey002, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L + PublicMethod.randomFreezeAmount.addAndGet(1), + 0, + 0, ByteString.copyFrom(exchange001Address), - testKey002, blockingStubFull)); + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long start = System.currentTimeMillis() + 5000L; - Long end = System.currentTimeMillis() + 5000000L; - Assert.assertTrue(PublicMethod.createAssetIssue(exchange001Address, name1, totalSupply, 1, - 1, start, end, 1, description, url, 10000L, 10000L, - 1L, 1L, exchange001Key, blockingStubFull)); - Assert.assertTrue(PublicMethod.createAssetIssue(secondExchange001Address, name2, totalSupply, 1, - 1, start, end, 1, description, url, 10000L, 10000L, - 1L, 1L, secondExchange001Key, blockingStubFull)); + Long start = System.currentTimeMillis() + 5000L; + Long end = System.currentTimeMillis() + 5000000L; + Assert.assertTrue( + PublicMethod.createAssetIssue( + exchange001Address, + name1, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + exchange001Key, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.createAssetIssue( + secondExchange001Address, + name2, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + secondExchange001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = false, description = "MultiSign for create exchange", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "MultiSign for create exchange", + groups = {"contract", "daily"}) public void test2CreateExchange() { ecKey3 = new ECKey(Utils.getRandom()); manager1Address = ecKey3.getAddress(); @@ -116,9 +157,9 @@ public void test2CreateExchange() { ecKey4 = new ECKey(Utils.getRandom()); manager2Address = ecKey4.getAddress(); manager2Key = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); - final long needCoin = updateAccountPermissionFee + multiSignFee; - Long balanceBefore = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + final long needCoin = updateAccountPermissionFee + multiSignFee; + Long balanceBefore = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -129,73 +170,99 @@ public void test2CreateExchange() { ownerKeyString[2] = manager2Key; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":3,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(exchange001Key) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(exchange001Key) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); PublicMethodForMultiSign.accountPermissionUpdate( - accountPermissionJson, exchange001Address, exchange001Key, - blockingStubFull, ownerKeyString); - + accountPermissionJson, + exchange001Address, + exchange001Key, + blockingStubFull, + ownerKeyString); Account getAssetIdFromThisAccount; getAssetIdFromThisAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); assetAccountId1 = getAssetIdFromThisAccount.getAssetIssuedID(); - getAssetIdFromThisAccount = PublicMethod - .queryAccount(secondExchange001Address, blockingStubFull); + getAssetIdFromThisAccount = + PublicMethod.queryAccount(secondExchange001Address, blockingStubFull); assetAccountId2 = getAssetIdFromThisAccount.getAssetIssuedID(); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long token1BeforeBalance = 0L; + Long token1BeforeBalance = 0L; for (String name : firstAccount.getAssetMap().keySet()) { token1BeforeBalance = firstAccount.getAssetMap().get(name); } - Assert.assertTrue(PublicMethod.transferAsset(exchange001Address, assetAccountId2.toByteArray(), - secondTransferAssetToFirstAccountNum, secondExchange001Address, - secondExchange001Key, blockingStubFull)); - Long token2BeforeBalance = secondTransferAssetToFirstAccountNum; + Assert.assertTrue( + PublicMethod.transferAsset( + exchange001Address, + assetAccountId2.toByteArray(), + secondTransferAssetToFirstAccountNum, + secondExchange001Address, + secondExchange001Key, + blockingStubFull)); + Long token2BeforeBalance = secondTransferAssetToFirstAccountNum; PublicMethod.waitProduceNextBlock(blockingStubFull); - //logger.info("name1 is " + name1); - //logger.info("name2 is " + name2); - //logger.info("first balance is " + Long.toString(token1BeforeBalance)); - //logger.info("second balance is " + token2BeforeBalance.toString()); - //CreateExchange + // logger.info("name1 is " + name1); + // logger.info("name2 is " + name2); + // logger.info("first balance is " + Long.toString(token1BeforeBalance)); + // logger.info("second balance is " + token2BeforeBalance.toString()); + // CreateExchange Assert.assertTrue( PublicMethodForMultiSign.exchangeCreate1( - assetAccountId1.toByteArray(), firstTokenInitialBalance, - assetAccountId2.toByteArray(), secondTokenInitialBalance, exchange001Address, - exchange001Key, blockingStubFull, 0, ownerKeyString)); + assetAccountId1.toByteArray(), + firstTokenInitialBalance, + assetAccountId2.toByteArray(), + secondTokenInitialBalance, + exchange001Address, + exchange001Key, + blockingStubFull, + 0, + ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - exchangeId = PublicMethod.getExchangeIdByCreatorAddress(exchange001Address, blockingStubFull).intValue(); - Long balanceAfter = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + exchangeId = + PublicMethod.getExchangeIdByCreatorAddress(exchange001Address, blockingStubFull).intValue(); + Long balanceAfter = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1024_000_000L); - } - - @Test(enabled = false, description = "Multisign for inject exchange", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Multisign for inject exchange", + groups = {"contract", "daily"}) public void test4InjectExchange() { exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); - final long needCoin = multiSignFee; - Long balanceBefore = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + final long needCoin = multiSignFee; + Long balanceBefore = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long beforeToken1Balance = 0L; - Long beforeToken2Balance = 0L; + Long beforeToken1Balance = 0L; + Long beforeToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { beforeToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -209,12 +276,18 @@ public void test4InjectExchange() { Integer injectBalance = 100; Assert.assertTrue( PublicMethodForMultiSign.injectExchange1( - exchangeId, assetAccountId1.toByteArray(), injectBalance, - exchange001Address, exchange001Key, blockingStubFull, 0, ownerKeyString)); + exchangeId, + assetAccountId1.toByteArray(), + injectBalance, + exchange001Address, + exchange001Key, + blockingStubFull, + 0, + ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long afterToken1Balance = 0L; - Long afterToken2Balance = 0L; + Long afterToken1Balance = 0L; + Long afterToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { afterToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -227,35 +300,36 @@ public void test4InjectExchange() { logger.info("before token 2 balance is " + Long.toString(afterToken2Balance)); Assert.assertTrue(beforeToken1Balance - afterToken1Balance == injectBalance); - Assert.assertTrue(beforeToken2Balance - afterToken2Balance == injectBalance - * exchangeRate); + Assert.assertTrue(beforeToken2Balance - afterToken2Balance == injectBalance * exchangeRate); exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); - Assert.assertTrue(afterExchangeToken1Balance - beforeExchangeToken1Balance - == injectBalance); - Assert.assertTrue(afterExchangeToken2Balance - beforeExchangeToken2Balance - == injectBalance * exchangeRate); - Long balanceAfter = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + Assert.assertTrue(afterExchangeToken1Balance - beforeExchangeToken1Balance == injectBalance); + Assert.assertTrue( + afterExchangeToken2Balance - beforeExchangeToken2Balance == injectBalance * exchangeRate); + Long balanceAfter = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - @Test(enabled = false, description = "MultiSign for withdraw exchange", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "MultiSign for withdraw exchange", + groups = {"contract", "daily"}) public void test5WithdrawExchange() { final long needCoin = multiSignFee; - Long balanceBefore = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + Long balanceBefore = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long beforeToken1Balance = 0L; - Long beforeToken2Balance = 0L; + Long beforeToken1Balance = 0L; + Long beforeToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { beforeToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -270,12 +344,18 @@ public void test5WithdrawExchange() { Integer withdrawNum = 200; Assert.assertTrue( PublicMethodForMultiSign.exchangeWithdraw1( - exchangeId, assetAccountId1.toByteArray(), withdrawNum, - exchange001Address, exchange001Key, blockingStubFull, 0, ownerKeyString)); + exchangeId, + assetAccountId1.toByteArray(), + withdrawNum, + exchange001Address, + exchange001Key, + blockingStubFull, + 0, + ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long afterToken1Balance = 0L; - Long afterToken2Balance = 0L; + Long afterToken1Balance = 0L; + Long afterToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { afterToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -289,37 +369,37 @@ public void test5WithdrawExchange() { logger.info("before token 2 balance is " + Long.toString(afterToken2Balance)); Assert.assertTrue(afterToken1Balance - beforeToken1Balance == withdrawNum); - Assert.assertTrue(afterToken2Balance - beforeToken2Balance == withdrawNum - * exchangeRate); + Assert.assertTrue(afterToken2Balance - beforeToken2Balance == withdrawNum * exchangeRate); exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); - Assert.assertTrue(afterExchangeToken1Balance - beforeExchangeToken1Balance - == -withdrawNum); - Assert.assertTrue(afterExchangeToken2Balance - beforeExchangeToken2Balance - == -withdrawNum * exchangeRate); - Long balanceAfter = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + Assert.assertTrue(afterExchangeToken1Balance - beforeExchangeToken1Balance == -withdrawNum); + Assert.assertTrue( + afterExchangeToken2Balance - beforeExchangeToken2Balance == -withdrawNum * exchangeRate); + Long balanceAfter = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - } - @Test(enabled = false, description = "MultiSign for transaction exchange", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "MultiSign for transaction exchange", + groups = {"contract", "daily"}) public void test6TransactionExchange() { final long needCoin = multiSignFee; - Long balanceBefore = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + Long balanceBefore = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); logger.info("beforeExchangeToken1Balance" + beforeExchangeToken1Balance); logger.info("beforeExchangeToken2Balance" + beforeExchangeToken2Balance); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long beforeToken1Balance = 0L; - Long beforeToken2Balance = 0L; + Long beforeToken1Balance = 0L; + Long beforeToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { beforeToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -333,13 +413,20 @@ public void test6TransactionExchange() { logger.info("before token 2 balance is " + Long.toString(beforeToken2Balance)); Integer transactionNum = 50; Assert.assertTrue( - PublicMethodForMultiSign - .exchangeTransaction1(exchangeId, assetAccountId1.toByteArray(), transactionNum, 1, - exchange001Address, exchange001Key, blockingStubFull, 0, ownerKeyString)); + PublicMethodForMultiSign.exchangeTransaction1( + exchangeId, + assetAccountId1.toByteArray(), + transactionNum, + 1, + exchange001Address, + exchange001Key, + blockingStubFull, + 0, + ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long afterToken1Balance = 0L; - Long afterToken2Balance = 0L; + Long afterToken1Balance = 0L; + Long afterToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { afterToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -352,26 +439,23 @@ public void test6TransactionExchange() { logger.info("before token 2 balance is " + Long.toString(afterToken2Balance)); exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); logger.info("afterExchangeToken1Balance" + afterExchangeToken1Balance); logger.info("afterExchangeToken2Balance" + afterExchangeToken2Balance); - Assert.assertTrue(afterExchangeToken1Balance - beforeExchangeToken1Balance - == beforeToken1Balance - afterToken1Balance); - Assert.assertTrue(afterExchangeToken2Balance - beforeExchangeToken2Balance - == beforeToken2Balance - afterToken2Balance); - Long balanceAfter = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + Assert.assertTrue( + afterExchangeToken1Balance - beforeExchangeToken1Balance + == beforeToken1Balance - afterToken1Balance); + Assert.assertTrue( + afterExchangeToken2Balance - beforeExchangeToken2Balance + == beforeToken2Balance - afterToken2Balance); + Long balanceAfter = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignExchangeContractTest002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignExchangeContractTest002.java index fb7fdfe7..15d04962 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignExchangeContractTest002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignExchangeContractTest002.java @@ -1,7 +1,6 @@ package stest.tron.wallet.dailybuild.operationupdate; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.Optional; import lombok.extern.slf4j.Slf4j; @@ -9,7 +8,6 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.tron.api.GrpcAPI.ExchangeList; import org.tron.api.WalletSolidityGrpc; import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.Exchange; @@ -18,8 +16,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSignExchangeContractTest002 extends TronBaseTest { @@ -27,8 +25,8 @@ public class MultiSignExchangeContractTest002 extends TronBaseTest { private static final long totalSupply = 1000000001L; private static String name1 = "exchange001_1_" + Long.toString(now); private static String name2 = "exchange001_2_" + Long.toString(now); - private final String operations = Configuration.getByPath("testng.conf") - .getString("defaultParameter.operations"); + private final String operations = + Configuration.getByPath("testng.conf").getString("defaultParameter.operations"); String description = "just-test"; String url = "https://github.com/tronprotocol/wallet-cli/"; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -55,25 +53,24 @@ public class MultiSignExchangeContractTest002 extends TronBaseTest { Integer exchangeRate = 10; Long firstTokenInitialBalance = 10000L; Long secondTokenInitialBalance = firstTokenInitialBalance * exchangeRate; - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1); - - /** - * constructor. - */ - + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = false, description = "MultiSign for create token", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "MultiSign for create token", + groups = {"contract", "daily"}) public void test1CreateUsedAsset() { ecKey1 = new ECKey(Utils.getRandom()); exchange001Address = ecKey1.getAddress(); @@ -86,27 +83,71 @@ public void test1CreateUsedAsset() { PublicMethod.printAddress(exchange001Key); PublicMethod.printAddress(secondExchange001Key); - Assert.assertTrue(PublicMethod.sendcoin(exchange001Address, 10240000000L, foundationAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(secondExchange001Address, 10240000000L, foundationAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 100000000000L + PublicMethod.randomFreezeAmount.addAndGet(1), 0, 0, + Assert.assertTrue( + PublicMethod.sendcoin( + exchange001Address, 10240000000L, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + secondExchange001Address, + 10240000000L, + foundationAddress, + testKey002, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100000000000L + PublicMethod.randomFreezeAmount.addAndGet(1), + 0, + 0, ByteString.copyFrom(exchange001Address), - testKey002, blockingStubFull)); + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long start = System.currentTimeMillis() + 5000L; - Long end = System.currentTimeMillis() + 5000000L; - Assert.assertTrue(PublicMethod.createAssetIssue(exchange001Address, name1, totalSupply, 1, - 1, start, end, 1, description, url, 10000L, 10000L, - 1L, 1L, exchange001Key, blockingStubFull)); - Assert.assertTrue(PublicMethod.createAssetIssue(secondExchange001Address, name2, totalSupply, 1, - 1, start, end, 1, description, url, 10000L, 10000L, - 1L, 1L, secondExchange001Key, blockingStubFull)); + Long start = System.currentTimeMillis() + 5000L; + Long end = System.currentTimeMillis() + 5000000L; + Assert.assertTrue( + PublicMethod.createAssetIssue( + exchange001Address, + name1, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + exchange001Key, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.createAssetIssue( + secondExchange001Address, + name2, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + secondExchange001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = false, description = "MultiSign for create exchange", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "MultiSign for create exchange", + groups = {"contract", "daily"}) public void test2CreateExchange() { ecKey3 = new ECKey(Utils.getRandom()); manager1Address = ecKey3.getAddress(); @@ -115,9 +156,9 @@ public void test2CreateExchange() { ecKey4 = new ECKey(Utils.getRandom()); manager2Address = ecKey4.getAddress(); manager2Key = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); - final long needCoin = updateAccountPermissionFee + multiSignFee; - Long balanceBefore = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + final long needCoin = updateAccountPermissionFee + multiSignFee; + Long balanceBefore = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -128,72 +169,98 @@ public void test2CreateExchange() { ownerKeyString[2] = manager2Key; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":3,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(exchange001Key) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(exchange001Key) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); PublicMethodForMultiSign.accountPermissionUpdate( - accountPermissionJson, exchange001Address, exchange001Key, - blockingStubFull, ownerKeyString); - + accountPermissionJson, + exchange001Address, + exchange001Key, + blockingStubFull, + ownerKeyString); Account getAssetIdFromThisAccount; getAssetIdFromThisAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); assetAccountId1 = getAssetIdFromThisAccount.getAssetIssuedID(); - getAssetIdFromThisAccount = PublicMethod - .queryAccount(secondExchange001Address, blockingStubFull); + getAssetIdFromThisAccount = + PublicMethod.queryAccount(secondExchange001Address, blockingStubFull); assetAccountId2 = getAssetIdFromThisAccount.getAssetIssuedID(); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long token1BeforeBalance = 0L; + Long token1BeforeBalance = 0L; for (String name : firstAccount.getAssetMap().keySet()) { token1BeforeBalance = firstAccount.getAssetMap().get(name); } - Assert.assertTrue(PublicMethod.transferAsset(exchange001Address, assetAccountId2.toByteArray(), - secondTransferAssetToFirstAccountNum, secondExchange001Address, - secondExchange001Key, blockingStubFull)); - Long token2BeforeBalance = secondTransferAssetToFirstAccountNum; + Assert.assertTrue( + PublicMethod.transferAsset( + exchange001Address, + assetAccountId2.toByteArray(), + secondTransferAssetToFirstAccountNum, + secondExchange001Address, + secondExchange001Key, + blockingStubFull)); + Long token2BeforeBalance = secondTransferAssetToFirstAccountNum; PublicMethod.waitProduceNextBlock(blockingStubFull); - //logger.info("name1 is " + name1); - //logger.info("name2 is " + name2); - //logger.info("first balance is " + Long.toString(token1BeforeBalance)); - //logger.info("second balance is " + token2BeforeBalance.toString()); - //CreateExchange + // logger.info("name1 is " + name1); + // logger.info("name2 is " + name2); + // logger.info("first balance is " + Long.toString(token1BeforeBalance)); + // logger.info("second balance is " + token2BeforeBalance.toString()); + // CreateExchange Assert.assertTrue( PublicMethodForMultiSign.exchangeCreate1( - assetAccountId1.toByteArray(), firstTokenInitialBalance, - assetAccountId2.toByteArray(), secondTokenInitialBalance, exchange001Address, - exchange001Key, blockingStubFull, 2, permissionKeyString)); + assetAccountId1.toByteArray(), + firstTokenInitialBalance, + assetAccountId2.toByteArray(), + secondTokenInitialBalance, + exchange001Address, + exchange001Key, + blockingStubFull, + 2, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - exchangeId = PublicMethod.getExchangeIdByCreatorAddress(exchange001Address, blockingStubFull).intValue(); - Long balanceAfter = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + exchangeId = + PublicMethod.getExchangeIdByCreatorAddress(exchange001Address, blockingStubFull).intValue(); + Long balanceAfter = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin + 1024_000_000L); - } - - @Test(enabled = false, description = "Multisign for inject exchange", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Multisign for inject exchange", + groups = {"contract", "daily"}) public void test4InjectExchange() { exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); - final long needCoin = multiSignFee; - Long balanceBefore = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + final long needCoin = multiSignFee; + Long balanceBefore = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long beforeToken1Balance = 0L; - Long beforeToken2Balance = 0L; + Long beforeToken1Balance = 0L; + Long beforeToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { beforeToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -207,12 +274,18 @@ public void test4InjectExchange() { Integer injectBalance = 100; Assert.assertTrue( PublicMethodForMultiSign.injectExchange1( - exchangeId, assetAccountId1.toByteArray(), injectBalance, - exchange001Address, exchange001Key, blockingStubFull, 2, permissionKeyString)); + exchangeId, + assetAccountId1.toByteArray(), + injectBalance, + exchange001Address, + exchange001Key, + blockingStubFull, + 2, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long afterToken1Balance = 0L; - Long afterToken2Balance = 0L; + Long afterToken1Balance = 0L; + Long afterToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { afterToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -225,35 +298,36 @@ public void test4InjectExchange() { logger.info("before token 2 balance is " + Long.toString(afterToken2Balance)); Assert.assertTrue(beforeToken1Balance - afterToken1Balance == injectBalance); - Assert.assertTrue(beforeToken2Balance - afterToken2Balance == injectBalance - * exchangeRate); + Assert.assertTrue(beforeToken2Balance - afterToken2Balance == injectBalance * exchangeRate); exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); - Assert.assertTrue(afterExchangeToken1Balance - beforeExchangeToken1Balance - == injectBalance); - Assert.assertTrue(afterExchangeToken2Balance - beforeExchangeToken2Balance - == injectBalance * exchangeRate); - Long balanceAfter = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + Assert.assertTrue(afterExchangeToken1Balance - beforeExchangeToken1Balance == injectBalance); + Assert.assertTrue( + afterExchangeToken2Balance - beforeExchangeToken2Balance == injectBalance * exchangeRate); + Long balanceAfter = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - @Test(enabled = false, description = "MultiSign for withdraw exchange", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "MultiSign for withdraw exchange", + groups = {"contract", "daily"}) public void test5WithdrawExchange() { final long needCoin = multiSignFee; - Long balanceBefore = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + Long balanceBefore = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long beforeToken1Balance = 0L; - Long beforeToken2Balance = 0L; + Long beforeToken1Balance = 0L; + Long beforeToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { beforeToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -268,12 +342,18 @@ public void test5WithdrawExchange() { Integer withdrawNum = 200; Assert.assertTrue( PublicMethodForMultiSign.exchangeWithdraw1( - exchangeId, assetAccountId1.toByteArray(), withdrawNum, - exchange001Address, exchange001Key, blockingStubFull, 2, permissionKeyString)); + exchangeId, + assetAccountId1.toByteArray(), + withdrawNum, + exchange001Address, + exchange001Key, + blockingStubFull, + 2, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long afterToken1Balance = 0L; - Long afterToken2Balance = 0L; + Long afterToken1Balance = 0L; + Long afterToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { afterToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -287,37 +367,37 @@ public void test5WithdrawExchange() { logger.info("before token 2 balance is " + Long.toString(afterToken2Balance)); Assert.assertTrue(afterToken1Balance - beforeToken1Balance == withdrawNum); - Assert.assertTrue(afterToken2Balance - beforeToken2Balance == withdrawNum - * exchangeRate); + Assert.assertTrue(afterToken2Balance - beforeToken2Balance == withdrawNum * exchangeRate); exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); - Assert.assertTrue(afterExchangeToken1Balance - beforeExchangeToken1Balance - == -withdrawNum); - Assert.assertTrue(afterExchangeToken2Balance - beforeExchangeToken2Balance - == -withdrawNum * exchangeRate); - Long balanceAfter = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + Assert.assertTrue(afterExchangeToken1Balance - beforeExchangeToken1Balance == -withdrawNum); + Assert.assertTrue( + afterExchangeToken2Balance - beforeExchangeToken2Balance == -withdrawNum * exchangeRate); + Long balanceAfter = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); - } - @Test(enabled = false, description = "MultiSign for transaction exchange", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "MultiSign for transaction exchange", + groups = {"contract", "daily"}) public void test6TransactionExchange() { final long needCoin = multiSignFee; - Long balanceBefore = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + Long balanceBefore = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + final Long beforeExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + final Long beforeExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); logger.info("beforeExchangeToken1Balance" + beforeExchangeToken1Balance); logger.info("beforeExchangeToken2Balance" + beforeExchangeToken2Balance); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long beforeToken1Balance = 0L; - Long beforeToken2Balance = 0L; + Long beforeToken1Balance = 0L; + Long beforeToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { beforeToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -331,13 +411,20 @@ public void test6TransactionExchange() { logger.info("before token 2 balance is " + Long.toString(beforeToken2Balance)); Integer transactionNum = 50; Assert.assertTrue( - PublicMethodForMultiSign - .exchangeTransaction1(exchangeId, assetAccountId1.toByteArray(), transactionNum, 1, - exchange001Address, exchange001Key, blockingStubFull, 2, permissionKeyString)); + PublicMethodForMultiSign.exchangeTransaction1( + exchangeId, + assetAccountId1.toByteArray(), + transactionNum, + 1, + exchange001Address, + exchange001Key, + blockingStubFull, + 2, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); firstAccount = PublicMethod.queryAccount(exchange001Address, blockingStubFull); - Long afterToken1Balance = 0L; - Long afterToken2Balance = 0L; + Long afterToken1Balance = 0L; + Long afterToken2Balance = 0L; for (String id : firstAccount.getAssetV2Map().keySet()) { if (assetAccountId1.toStringUtf8().equalsIgnoreCase(id)) { afterToken1Balance = firstAccount.getAssetV2Map().get(id); @@ -350,26 +437,23 @@ public void test6TransactionExchange() { logger.info("before token 2 balance is " + Long.toString(afterToken2Balance)); exchangeIdInfo = PublicMethod.getExchange(exchangeId.toString(), blockingStubFull); - Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); - Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); + Long afterExchangeToken1Balance = exchangeIdInfo.get().getFirstTokenBalance(); + Long afterExchangeToken2Balance = exchangeIdInfo.get().getSecondTokenBalance(); logger.info("afterExchangeToken1Balance" + afterExchangeToken1Balance); logger.info("afterExchangeToken2Balance" + afterExchangeToken2Balance); - Assert.assertTrue(afterExchangeToken1Balance - beforeExchangeToken1Balance - == beforeToken1Balance - afterToken1Balance); - Assert.assertTrue(afterExchangeToken2Balance - beforeExchangeToken2Balance - == beforeToken2Balance - afterToken2Balance); - Long balanceAfter = PublicMethod.queryAccount(exchange001Address, blockingStubFull) - .getBalance(); + Assert.assertTrue( + afterExchangeToken1Balance - beforeExchangeToken1Balance + == beforeToken1Balance - afterToken1Balance); + Assert.assertTrue( + afterExchangeToken2Balance - beforeExchangeToken2Balance + == beforeToken2Balance - afterToken2Balance); + Long balanceAfter = + PublicMethod.queryAccount(exchange001Address, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertEquals(balanceBefore - balanceAfter, needCoin); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignMarketAssetTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignMarketAssetTest.java index bd782108..b4dbbfd2 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignMarketAssetTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignMarketAssetTest.java @@ -12,12 +12,12 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class MultiSignMarketAssetTest extends TronBaseTest { ECKey ecKey0 = new ECKey(Utils.getRandom()); +public class MultiSignMarketAssetTest extends TronBaseTest { + ECKey ecKey0 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey0.getAddress(); String testKey001 = ByteArray.toHexString(ecKey0.getPrivKeyBytes()); @@ -32,28 +32,37 @@ public class MultiSignMarketAssetTest extends TronBaseTest { ECKey ecKey0 = new String manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); private ManagedChannel channelSolidity = null; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass public void beforeClass() { - initSolidityChannel(); Assert.assertTrue(PublicMethod - .sendcoin(testAddress001, 20000_000000L, foundationAddress, foundationKey, - blockingStubFull)); + initSolidityChannel(); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress001, 20000_000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod.createAssetIssue(testAddress001, - "MarketAsset" + start, - 100_000000L, - 1,1, - start, end,1,"MarketAsset","MarketAsset.com",10000L,10000L,1L, 1L,testKey001, - blockingStubFull)); - Long balanceBefore = PublicMethod.queryAccount(testAddress001, blockingStubFull) - .getBalance(); + Assert.assertTrue( + PublicMethod.createAssetIssue( + testAddress001, + "MarketAsset" + start, + 100_000000L, + 1, + 1, + start, + end, + 1, + "MarketAsset", + "MarketAsset.com", + 10000L, + 10000L, + 1L, + 1L, + testKey001, + blockingStubFull)); + Long balanceBefore = PublicMethod.queryAccount(testAddress001, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -61,124 +70,169 @@ public void beforeClass() { PublicMethod.waitProduceNextBlock(blockingStubFull); ownerKeyString[0] = testKey001; ownerKeyString[1] = foundationKey; - // operation include MarketSellAssetContract(52) - Integer[] ints = {0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 30, 31, - 32, 33, 41, 42, 43, 44, 45, 48, 49, 52, 53}; - String operations = PublicMethodForMultiSign.getOperations(ints); + // operation include MarketSellAssetContract(52) + Integer[] ints = { + 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 30, 31, 32, 33, 41, 42, + 43, 44, 45, 48, 49, 52, 53 + }; + String operations = PublicMethodForMultiSign.getOperations(ints); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(testKey001) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(foundationKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(testKey001) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, testAddress001, testKey001, - blockingStubFull, ownerKeyString); + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, testAddress001, testKey001, blockingStubFull, ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); - } - @Test(enabled = false, description = "MultiSignForMarketSellAsset with active_permissions", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "MultiSignForMarketSellAsset with active_permissions", + groups = {"contract", "daily"}) public void testMultiSignForMarketSellAsset001() { // MarketSellAsset - ByteString assetAccountId = PublicMethod - .queryAccount(testAddress001, blockingStubFull).getAssetIssuedID(); - int marketOrderCountBefore = PublicMethod - .getMarketOrderByAccount(testAddress001, blockingStubFull).get().getOrdersCount(); - - Assert.assertTrue(PublicMethodForMultiSign - .marketSellAsset(testAddress001,assetAccountId.toByteArray(),10,"_".getBytes(),10,2, - permissionKeyString,blockingStubFull)); + ByteString assetAccountId = + PublicMethod.queryAccount(testAddress001, blockingStubFull).getAssetIssuedID(); + int marketOrderCountBefore = + PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull) + .get() + .getOrdersCount(); + + Assert.assertTrue( + PublicMethodForMultiSign.marketSellAsset( + testAddress001, + assetAccountId.toByteArray(), + 10, + "_".getBytes(), + 10, + 2, + permissionKeyString, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull); - MarketOrderList marketOrder = PublicMethod - .getMarketOrderByAccount(testAddress001, blockingStubFull).get(); + MarketOrderList marketOrder = + PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull).get(); Assert.assertEquals(marketOrderCountBefore + 1, marketOrder.getOrdersCount()); } - @Test(enabled = false, description = "MultiSignForMarketSellAsset with owner_permission", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "MultiSignForMarketSellAsset with owner_permission", + groups = {"contract", "daily"}) public void testMultiSignForMarketSellAsset002() { // MarketSellAsset - ByteString assetAccountId = PublicMethod - .queryAccount(testAddress001, blockingStubFull).getAssetIssuedID(); - int marketOrderCountBefore = PublicMethod - .getMarketOrderByAccount(testAddress001, blockingStubFull).get().getOrdersCount(); - - - Assert.assertTrue(PublicMethodForMultiSign - .marketSellAsset(testAddress001,assetAccountId.toByteArray(),10,"_".getBytes(),10,0, - ownerKeyString,blockingStubFull)); + ByteString assetAccountId = + PublicMethod.queryAccount(testAddress001, blockingStubFull).getAssetIssuedID(); + int marketOrderCountBefore = + PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull) + .get() + .getOrdersCount(); + + Assert.assertTrue( + PublicMethodForMultiSign.marketSellAsset( + testAddress001, + assetAccountId.toByteArray(), + 10, + "_".getBytes(), + 10, + 0, + ownerKeyString, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - MarketOrderList marketOrder = PublicMethod - .getMarketOrderByAccount(testAddress001, blockingStubFull).get(); + MarketOrderList marketOrder = + PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull).get(); Assert.assertEquals(marketOrderCountBefore + 1, marketOrder.getOrdersCount()); } - - @Test(enabled = false, dependsOnMethods = "testMultiSignForMarketSellAsset001", - description = "MultiSignForMarketOrderCancel with active_permissions", groups = {"contract", "daily"}) + @Test( + enabled = false, + dependsOnMethods = "testMultiSignForMarketSellAsset001", + description = "MultiSignForMarketOrderCancel with active_permissions", + groups = {"contract", "daily"}) public void testMultiSignForMarketOrderCancel001() { // MarketOrderCancel - ByteString orderId = PublicMethod - .getMarketOrderByAccount(testAddress001, blockingStubFull).get().getOrders(0).getOrderId(); - int marketOrderCountBefore = PublicMethod - .getMarketOrderByAccount(testAddress001, blockingStubFull).get().getOrdersCount(); - + ByteString orderId = + PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull) + .get() + .getOrders(0) + .getOrderId(); + int marketOrderCountBefore = + PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull) + .get() + .getOrdersCount(); - Assert.assertTrue(PublicMethodForMultiSign.marketCancelOrder(testAddress001, - orderId.toByteArray(),2,permissionKeyString,blockingStubFull)); + Assert.assertTrue( + PublicMethodForMultiSign.marketCancelOrder( + testAddress001, orderId.toByteArray(), 2, permissionKeyString, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(marketOrderCountBefore - 1, PublicMethod - .getMarketOrderByAccount(testAddress001, blockingStubFull).get().getOrdersCount()); - + Assert.assertEquals( + marketOrderCountBefore - 1, + PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull) + .get() + .getOrdersCount()); } - @Test(enabled = false, dependsOnMethods = "testMultiSignForMarketSellAsset002", - description = "MultiSignForMarketOrderCancel with owner_permission", groups = {"contract", "daily"}) + @Test( + enabled = false, + dependsOnMethods = "testMultiSignForMarketSellAsset002", + description = "MultiSignForMarketOrderCancel with owner_permission", + groups = {"contract", "daily"}) public void testMultiSignForMarketOrderCancel002() { // MarketOrderCancel - ByteString orderId = PublicMethod - .getMarketOrderByAccount(testAddress001, blockingStubFull).get().getOrders(0).getOrderId(); - int marketOrderCountBefore = PublicMethod - .getMarketOrderByAccount(testAddress001, blockingStubFull).get().getOrdersCount(); - + ByteString orderId = + PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull) + .get() + .getOrders(0) + .getOrderId(); + int marketOrderCountBefore = + PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull) + .get() + .getOrdersCount(); - Assert.assertTrue(PublicMethodForMultiSign.marketCancelOrder(testAddress001, - orderId.toByteArray(),0,ownerKeyString,blockingStubFull)); + Assert.assertTrue( + PublicMethodForMultiSign.marketCancelOrder( + testAddress001, orderId.toByteArray(), 0, ownerKeyString, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(marketOrderCountBefore - 1, PublicMethod - .getMarketOrderByAccount(testAddress001, blockingStubFull).get().getOrdersCount()); - + Assert.assertEquals( + marketOrderCountBefore - 1, + PublicMethod.getMarketOrderByAccount(testAddress001, blockingStubFull) + .get() + .getOrdersCount()); } - - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignProposalTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignProposalTest.java index d88faee2..ffb491eb 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignProposalTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignProposalTest.java @@ -1,6 +1,5 @@ package stest.tron.wallet.dailybuild.operationupdate; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.HashMap; import java.util.Map; @@ -19,14 +18,14 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSignProposalTest extends TronBaseTest { private static final long now = System.currentTimeMillis(); - private final String operations = Configuration.getByPath("testng.conf") - .getString("defaultParameter.operations"); + private final String operations = + Configuration.getByPath("testng.conf").getString("defaultParameter.operations"); String[] permissionKeyString = new String[2]; String[] ownerKeyString = new String[2]; String accountPermissionJson = ""; @@ -36,29 +35,32 @@ public class MultiSignProposalTest extends TronBaseTest { ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] manager2Address = ecKey2.getAddress(); String manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ - + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + + /** constructor. */ @BeforeClass - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, groups = {"contract", "daily"}) + @Test( + enabled = true, + groups = {"contract", "daily"}) public void testMultiSignForProposal() { long needcoin = updateAccountPermissionFee + multiSignFee * 5; - Assert.assertTrue(PublicMethod.sendcoin(witnessAddress2, needcoin + 10000000L, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + witnessAddress2, + needcoin + 10000000L, + foundationAddress, + foundationKey, + blockingStubFull)); ecKey1 = new ECKey(Utils.getRandom()); manager1Address = ecKey1.getAddress(); @@ -69,8 +71,7 @@ public void testMultiSignForProposal() { manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(witnessAddress2, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(witnessAddress2, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -79,37 +80,43 @@ public void testMultiSignForProposal() { ownerKeyString[0] = witnessKey2; ownerKeyString[1] = foundationKey; - accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\"" - + ",\"threshold\":2,\"keys\":[{\"address\":\"" + PublicMethod - .getAddressString(witnessKey2) + "\"," - + "\"weight\":1},{\"address\":\"" + PublicMethod.getAddressString(foundationKey) - + "\",\"weight\":1}]}," - + "\"witness_permission\":{\"type\":1,\"permission_name\":\"owner\",\"threshold\":1," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(witnessKey2) - + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"7fff1fc0037e0000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(manager1Key) - + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}]}]} "; + accountPermissionJson = + "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\"" + + ",\"threshold\":2,\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(witnessKey2) + + "\"," + + "\"weight\":1},{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}]}," + + "\"witness_permission\":{\"type\":1,\"permission_name\":\"owner\",\"threshold\":1," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(witnessKey2) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + + "\"operations\":\"7fff1fc0037e0000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}]}]} "; logger.info(accountPermissionJson); PublicMethodForMultiSign.accountPermissionUpdate( - accountPermissionJson, witnessAddress2, witnessKey2, - blockingStubFull, ownerKeyString); - //Create a proposal + accountPermissionJson, witnessAddress2, witnessKey2, blockingStubFull, ownerKeyString); + // Create a proposal PublicMethod.waitProduceNextBlock(blockingStubFull); HashMap proposalMap = new HashMap(); Long proposalValue = 819897L; proposalMap.put(0L, proposalValue); Assert.assertTrue( - PublicMethodForMultiSign.createProposalWithPermissionId(witnessAddress2, witnessKey2, - proposalMap, 0, blockingStubFull, ownerKeyString)); + PublicMethodForMultiSign.createProposalWithPermissionId( + witnessAddress2, witnessKey2, proposalMap, 0, blockingStubFull, ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Get proposal list + // Get proposal list ProposalList proposalList = blockingStubFull.listProposals(EmptyMessage.newBuilder().build()); Optional listProposals = Optional.ofNullable(proposalList); - Integer proposalId = listProposals.get().getProposalsCount(); + Integer proposalId = -1; for (Proposal proposal : listProposals.get().getProposalsList()) { for (Map.Entry entry : proposal.getParametersMap().entrySet()) { if (entry.getValue().equals(proposalValue)) { @@ -117,29 +124,33 @@ public void testMultiSignForProposal() { break; } } + if (proposalId != -1) { + break; + } } final Integer finalProposalId = proposalId; logger.info(Integer.toString(finalProposalId)); - Assert.assertTrue(PublicMethodForMultiSign.approveProposalWithPermission( - witnessAddress2, witnessKey2, finalProposalId, - true, 0, blockingStubFull, ownerKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.approveProposalWithPermission( + witnessAddress2, + witnessKey2, + finalProposalId, + true, + 0, + blockingStubFull, + ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Delete proposal list after approve - Assert.assertTrue(PublicMethodForMultiSign.deleteProposalWithPermissionId( - witnessAddress2, witnessKey2, finalProposalId, 0, blockingStubFull, ownerKeyString)); + // Delete proposal list after approve + Assert.assertTrue( + PublicMethodForMultiSign.deleteProposalWithPermissionId( + witnessAddress2, witnessKey2, finalProposalId, 0, blockingStubFull, ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(witnessAddress2, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(witnessAddress2, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignProposalTest002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignProposalTest002.java index feec1d16..00e648b9 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignProposalTest002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignProposalTest002.java @@ -1,7 +1,5 @@ package stest.tron.wallet.dailybuild.operationupdate; -import io.grpc.ManagedChannel; -import io.grpc.ManagedChannelBuilder; import java.util.HashMap; import java.util.Map; import java.util.Optional; @@ -12,23 +10,20 @@ import org.testng.annotations.Test; import org.tron.api.GrpcAPI.EmptyMessage; import org.tron.api.GrpcAPI.ProposalList; -import org.tron.api.WalletSolidityGrpc; import org.tron.protos.Protocol.Proposal; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSignProposalTest002 extends TronBaseTest { - private static final long now = System.currentTimeMillis(); private final byte[] witness001Address = PublicMethod.getFinalAddress(witnessKey); - private final String operations = Configuration.getByPath("testng.conf") - .getString("defaultParameter.operations"); + private final String operations = + Configuration.getByPath("testng.conf").getString("defaultParameter.operations"); String[] permissionKeyString = new String[2]; String[] ownerKeyString = new String[1]; String accountPermissionJson = ""; @@ -38,29 +33,27 @@ public class MultiSignProposalTest002 extends TronBaseTest { ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] manager2Address = ecKey2.getAddress(); String manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + /** constructor. */ @BeforeClass - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - } + public void beforeClass() {} - @Test(enabled = true, groups = {"contract", "daily"}) + @Test( + enabled = true, + groups = {"contract", "daily"}) public void testMultiSignForProposal() { long needcoin = updateAccountPermissionFee + multiSignFee * 3; - Assert.assertTrue(PublicMethod.sendcoin(witness001Address, needcoin + 10000000L, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + witness001Address, + needcoin + 10000000L, + foundationAddress, + foundationKey, + blockingStubFull)); ecKey1 = new ECKey(Utils.getRandom()); manager1Address = ecKey1.getAddress(); @@ -71,8 +64,8 @@ public void testMultiSignForProposal() { manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(witness001Address, blockingStubFull) - .getBalance(); + Long balanceBefore = + PublicMethod.queryAccount(witness001Address, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -81,35 +74,42 @@ public void testMultiSignForProposal() { ownerKeyString[0] = witnessKey; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":2}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"owner\",\"threshold\":1,\"" - + "keys\":[{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + + "keys\":[{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); PublicMethodForMultiSign.accountPermissionUpdate( - accountPermissionJson, witness001Address, witnessKey, - blockingStubFull, ownerKeyString); - //Create a proposal + accountPermissionJson, witness001Address, witnessKey, blockingStubFull, ownerKeyString); + // Create a proposal PublicMethod.waitProduceNextBlock(blockingStubFull); HashMap proposalMap = new HashMap(); Long proposalValue = 819697L; proposalMap.put(0L, proposalValue); Assert.assertTrue( - PublicMethodForMultiSign.createProposalWithPermissionId(witness001Address, witnessKey, - proposalMap, 2, blockingStubFull, permissionKeyString)); + PublicMethodForMultiSign.createProposalWithPermissionId( + witness001Address, witnessKey, proposalMap, 2, blockingStubFull, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Get proposal list + // Get proposal list ProposalList proposalList = blockingStubFull.listProposals(EmptyMessage.newBuilder().build()); Optional listProposals = Optional.ofNullable(proposalList); - Integer proposalId = listProposals.get().getProposalsCount(); + Integer proposalId = -1; for (Proposal proposal : listProposals.get().getProposalsList()) { for (Map.Entry entry : proposal.getParametersMap().entrySet()) { if (entry.getValue().equals(proposalValue)) { @@ -117,35 +117,41 @@ public void testMultiSignForProposal() { break; } } + if (proposalId != -1) { + break; + } } final Integer finalProposalId = proposalId; logger.info(Integer.toString(finalProposalId)); - Assert.assertTrue(PublicMethodForMultiSign.approveProposalWithPermission( - witness001Address, witnessKey, finalProposalId, - true, 2, blockingStubFull, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.approveProposalWithPermission( + witness001Address, + witnessKey, + finalProposalId, + true, + 2, + blockingStubFull, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Delete proposal list after approve - Assert.assertTrue(PublicMethodForMultiSign.deleteProposalWithPermissionId( - witness001Address, witnessKey, finalProposalId, 2, blockingStubFull, permissionKeyString)); + // Delete proposal list after approve + Assert.assertTrue( + PublicMethodForMultiSign.deleteProposalWithPermissionId( + witness001Address, + witnessKey, + finalProposalId, + 2, + blockingStubFull, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(witness001Address, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(witness001Address, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertTrue(balanceBefore - balanceAfter >= needcoin); - - //Temp test, please delete - Assert.assertTrue(balanceBefore - balanceAfter < needcoin); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignSmartContractTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignSmartContractTest.java index 3a056d92..1ff36d3f 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignSmartContractTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignSmartContractTest.java @@ -19,16 +19,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode -public class MultiSignSmartContractTest extends TronBaseTest { private final String operations = Configuration.getByPath("testng.conf") - .getString("defaultParameter.operations"); +public class MultiSignSmartContractTest extends TronBaseTest { + private final String operations = + Configuration.getByPath("testng.conf").getString("defaultParameter.operations"); ArrayList txidList = new ArrayList(); Optional infoById = null; Long beforeTime; @@ -49,27 +50,25 @@ public class MultiSignSmartContractTest extends TronBaseTest { private final St ECKey ecKey3 = new ECKey(Utils.getRandom()); byte[] ownerAddress = ecKey3.getAddress(); String ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + public void beforeClass() { + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } - @Test(enabled = true, groups = {"contract", "daily"}) + @Test( + enabled = true, + groups = {"contract", "daily"}) public void testMultiSignForSmartContract() { ecKey1 = new ECKey(Utils.getRandom()); manager1Address = ecKey1.getAddress(); @@ -87,18 +86,33 @@ public void testMultiSignForSmartContract() { long needcoin = updateAccountPermissionFee + multiSignFee * 4; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, needcoin + 100000000L, foundationAddress, foundationKey, + PublicMethod.sendcoin( + ownerAddress, + needcoin + 100000000L, + foundationAddress, + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000000 + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000000 + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 1, + ByteString.copyFrom(ownerAddress), + foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 1000000000 + PublicMethod.randomFreezeAmount.getAndAdd(1), 0, 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 1000000000 + PublicMethod.randomFreezeAmount.getAndAdd(1), 0, 1, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -108,68 +122,101 @@ public void testMultiSignForSmartContract() { ownerKeyString[1] = manager1Key; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - Assert.assertTrue(PublicMethodForMultiSign.accountPermissionUpdate( - accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); Random rand = new Random(); Integer randNum = rand.nextInt(30) + 1; randNum = rand.nextInt(4000); - Long maxFeeLimit = 1000000000L; - String contractName = "StorageAndCpu" + Integer.toString(randNum); - String code = Configuration.getByPath("testng.conf") - .getString("code.code_TestStorageAndCpu_storageAndCpu"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_TestStorageAndCpu_storageAndCpu"); - String txid = PublicMethodForMultiSign.deployContractAndGetTransactionInfoById(contractName, abi, code, - "", maxFeeLimit, 0L, 100, null, ownerKey, ownerAddress, 0, ownerKeyString, blockingStubFull); + Long maxFeeLimit = 1000000000L; + String contractName = "StorageAndCpu" + Integer.toString(randNum); + String code = + Configuration.getByPath("testng.conf") + .getString("code.code_TestStorageAndCpu_storageAndCpu"); + String abi = + Configuration.getByPath("testng.conf").getString("abi.abi_TestStorageAndCpu_storageAndCpu"); + String txid = + PublicMethodForMultiSign.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + ownerKey, + ownerAddress, + 0, + ownerKeyString, + blockingStubFull); Assert.assertNotEquals(txid, null); PublicMethod.waitUntilTransactionInfoFound(blockingStubFull, txid, 30); - Optional infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getBlockTimeStamp() > 0); - byte[] contractAddress = infoById.get().getContractAddress().toByteArray(); + byte[] contractAddress = infoById.get().getContractAddress().toByteArray(); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); - String abiStr = smartContract.getAbi().toString(); + String abiStr = smartContract.getAbi().toString(); System.out.println("abiStr: " + abiStr); Assert.assertTrue(abiStr != null && abiStr.length() > 0); - String initParmes = "\"" + "930" + "\""; - txid = PublicMethodForMultiSign.triggerContract1(contractAddress, - "testUseCpu(uint256)", initParmes, false, - 0, maxFeeLimit, ownerAddress, ownerKey, blockingStubFull, 0, ownerKeyString); + String initParmes = "\"" + "930" + "\""; + txid = + PublicMethodForMultiSign.triggerContract1( + contractAddress, + "testUseCpu(uint256)", + initParmes, + false, + 0, + maxFeeLimit, + ownerAddress, + ownerKey, + blockingStubFull, + 0, + ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.getTransactionById(txid, blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue( - PublicMethodForMultiSign.updateSettingWithPermissionId(contractAddress, 50, ownerKey, - ownerAddress, 0, blockingStubFull, ownerKeyString)); + PublicMethodForMultiSign.updateSettingWithPermissionId( + contractAddress, 50, ownerKey, ownerAddress, 0, blockingStubFull, ownerKeyString)); Assert.assertTrue( - PublicMethodForMultiSign.updateEnergyLimitWithPermissionId(contractAddress, 50, ownerKey, - ownerAddress, 0, blockingStubFull, ownerKeyString)); + PublicMethodForMultiSign.updateEnergyLimitWithPermissionId( + contractAddress, 50, ownerKey, ownerAddress, 0, blockingStubFull, ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { if (channelFull1 != null) { + public void shutdown() throws InterruptedException { + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignSmartContractTest002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignSmartContractTest002.java index e70d8951..eb45d6d0 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignSmartContractTest002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignSmartContractTest002.java @@ -19,16 +19,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode -public class MultiSignSmartContractTest002 extends TronBaseTest { private final String operations = Configuration.getByPath("testng.conf") - .getString("defaultParameter.operations"); +public class MultiSignSmartContractTest002 extends TronBaseTest { + private final String operations = + Configuration.getByPath("testng.conf").getString("defaultParameter.operations"); ArrayList txidList = new ArrayList(); Optional infoById = null; Long beforeTime; @@ -49,27 +50,27 @@ public class MultiSignSmartContractTest002 extends TronBaseTest { private final ECKey ecKey3 = new ECKey(Utils.getRandom()); byte[] ownerAddress = ecKey3.getAddress(); String ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + public void beforeClass() { + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } - @Test(enabled = true, threadPoolSize = 1, invocationCount = 1, groups = {"contract", "daily"}) + @Test( + enabled = true, + threadPoolSize = 1, + invocationCount = 1, + groups = {"contract", "daily"}) public void testMultiSignForSmartContract() { ecKey1 = new ECKey(Utils.getRandom()); manager1Address = ecKey1.getAddress(); @@ -87,18 +88,33 @@ public void testMultiSignForSmartContract() { long needcoin = updateAccountPermissionFee + multiSignFee * 4; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, needcoin + 100000000L, foundationAddress, foundationKey, + PublicMethod.sendcoin( + ownerAddress, + needcoin + 100000000L, + foundationAddress, + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000000, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000000, + 0, + 1, + ByteString.copyFrom(ownerAddress), + foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 1000000000, 0, 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 1000000000, 0, 1, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -108,62 +124,92 @@ public void testMultiSignForSmartContract() { ownerKeyString[1] = manager1Key; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerKeyString); + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); Random rand = new Random(); Integer randNum = rand.nextInt(30) + 1; randNum = rand.nextInt(4000); - Long maxFeeLimit = 1000000000L; - String contractName = "StorageAndCpu" + Integer.toString(randNum); - String code = Configuration.getByPath("testng.conf") - .getString("code.code_TestStorageAndCpu_storageAndCpu"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_TestStorageAndCpu_storageAndCpu"); - byte[] contractAddress = PublicMethodForMultiSign.deployContract1(contractName, abi, code, - "", maxFeeLimit, - 0L, 100, null, ownerKey, ownerAddress, blockingStubFull, 2, permissionKeyString); + Long maxFeeLimit = 1000000000L; + String contractName = "StorageAndCpu" + Integer.toString(randNum); + String code = + Configuration.getByPath("testng.conf") + .getString("code.code_TestStorageAndCpu_storageAndCpu"); + String abi = + Configuration.getByPath("testng.conf").getString("abi.abi_TestStorageAndCpu_storageAndCpu"); + byte[] contractAddress = + PublicMethodForMultiSign.deployContract1( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + ownerKey, + ownerAddress, + blockingStubFull, + 2, + permissionKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString() != null); - String txid; - String initParmes = "\"" + "930" + "\""; - txid = PublicMethodForMultiSign.triggerContract1(contractAddress, - "testUseCpu(uint256)", initParmes, false, - 0, maxFeeLimit, ownerAddress, ownerKey, blockingStubFull, 2, permissionKeyString); + String txid; + String initParmes = "\"" + "930" + "\""; + txid = + PublicMethodForMultiSign.triggerContract1( + contractAddress, + "testUseCpu(uint256)", + initParmes, + false, + 0, + maxFeeLimit, + ownerAddress, + ownerKey, + blockingStubFull, + 2, + permissionKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.getTransactionById(txid, blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue( - PublicMethodForMultiSign.updateSettingWithPermissionId(contractAddress, 50, ownerKey, - ownerAddress, 2, blockingStubFull, permissionKeyString)); + PublicMethodForMultiSign.updateSettingWithPermissionId( + contractAddress, 50, ownerKey, ownerAddress, 2, blockingStubFull, permissionKeyString)); Assert.assertTrue( - PublicMethodForMultiSign.updateEnergyLimitWithPermissionId(contractAddress, 50, ownerKey, - ownerAddress, 2, blockingStubFull, permissionKeyString)); + PublicMethodForMultiSign.updateEnergyLimitWithPermissionId( + contractAddress, 50, ownerKey, ownerAddress, 2, blockingStubFull, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { if (channelFull1 != null) { + public void shutdown() throws InterruptedException { + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignUpdateBrokerageTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignUpdateBrokerageTest.java index b15a4c55..2f11f568 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignUpdateBrokerageTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/operationupdate/MultiSignUpdateBrokerageTest.java @@ -10,14 +10,14 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MultiSignUpdateBrokerageTest extends TronBaseTest { private static final long now = System.currentTimeMillis(); - private final String operations = Configuration.getByPath("testng.conf") - .getString("defaultParameter.operations"); + private final String operations = + Configuration.getByPath("testng.conf").getString("defaultParameter.operations"); String[] permissionKeyString = new String[2]; String[] ownerKeyString = new String[2]; String accountPermissionJson = ""; @@ -27,26 +27,30 @@ public class MultiSignUpdateBrokerageTest extends TronBaseTest { ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] manager2Address = ecKey2.getAddress(); String manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass public void beforeClass() { - initSolidityChannel(); } + initSolidityChannel(); + } - @Test(enabled = true, groups = {"contract", "daily"}) + @Test( + enabled = true, + groups = {"contract", "daily"}) public void testMultiSignForUpdateBrokerage() { long needcoin = updateAccountPermissionFee * 2 + multiSignFee * 5; - Assert.assertTrue(PublicMethod - .sendcoin(witnessAddress2, needcoin + 1000000L, foundationAddress, foundationKey, + Assert.assertTrue( + PublicMethod.sendcoin( + witnessAddress2, + needcoin + 1000000L, + foundationAddress, + foundationKey, blockingStubFull)); ecKey1 = new ECKey(Utils.getRandom()); @@ -58,8 +62,7 @@ public void testMultiSignForUpdateBrokerage() { manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(witnessAddress2, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(witnessAddress2, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -68,57 +71,64 @@ public void testMultiSignForUpdateBrokerage() { ownerKeyString[0] = witnessKey2; ownerKeyString[1] = foundationKey; - accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\"" - + ",\"threshold\":2,\"keys\":[{\"address\":\"" + PublicMethod - .getAddressString(witnessKey2) + "\"," + "\"weight\":1},{\"address\":\"" + PublicMethod - .getAddressString(foundationKey) + "\",\"weight\":1}]}," - + "\"witness_permission\":{\"type\":1,\"permission_name\":\"owner\",\"threshold\":1," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(witnessKey2) - + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"7fff1fc0033e0300000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(manager1Key) - + "\",\"weight\":1}," + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) - + "\",\"weight\":1}]}]} "; + accountPermissionJson = + "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\"" + + ",\"threshold\":2,\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(witnessKey2) + + "\"," + + "\"weight\":1},{\"address\":\"" + + PublicMethod.getAddressString(foundationKey) + + "\",\"weight\":1}]}," + + "\"witness_permission\":{\"type\":1,\"permission_name\":\"owner\",\"threshold\":1," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(witnessKey2) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + + "\"operations\":\"7fff1fc0033e0300000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}]}]} "; logger.info(accountPermissionJson); - PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, witnessAddress2, witnessKey2, - blockingStubFull, ownerKeyString); - //Update brokerage + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, witnessAddress2, witnessKey2, blockingStubFull, ownerKeyString); + // Update brokerage -// PublicMethod.waitProduceNextBlock(blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertEquals(PublicMethod.getBrokerage(witnessAddress2, blockingStubFull), 20L); - Assert.assertTrue(PublicMethodForMultiSign - .updateBrokerage(witnessAddress2, 70, witnessKey2, 2, permissionKeyString, - blockingStubFull)); + Assert.assertTrue( + PublicMethodForMultiSign.updateBrokerage( + witnessAddress2, 70, witnessKey2, 2, permissionKeyString, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); - // wait a MaintenanceTimeInterval - accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\"" - + ",\"threshold\":1,\"keys\":[{\"address\":\"" + PublicMethod - .getAddressString(witnessKey2) + "\"," + "\"weight\":1}]}," - + "\"witness_permission\":{\"type\":1,\"permission_name\":\"owner\",\"threshold\":1," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(witnessKey2) - + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"7fff1fc0033e0300000000000000000000000000000000000000000000000000\"," - + "\"keys\":[" + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey2) - + "\",\"weight\":1}]}]} "; + // PublicMethod.waitProduceNextBlock(blockingStubFull); + // wait a MaintenanceTimeInterval + accountPermissionJson = + "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\"" + + ",\"threshold\":1,\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(witnessKey2) + + "\"," + + "\"weight\":1}]}," + + "\"witness_permission\":{\"type\":1,\"permission_name\":\"owner\",\"threshold\":1," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(witnessKey2) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + + "\"operations\":\"7fff1fc0033e0300000000000000000000000000000000000000000000000000\"," + + "\"keys\":[" + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey2) + + "\",\"weight\":1}]}]} "; logger.info(accountPermissionJson); - PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, witnessAddress2, witnessKey2, - blockingStubFull, ownerKeyString); - Long balanceAfter = PublicMethod.queryAccount(witnessAddress2, blockingStubFull).getBalance(); + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, witnessAddress2, witnessKey2, blockingStubFull, ownerKeyString); + Long balanceAfter = PublicMethod.queryAccount(witnessAddress2, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/originenergylimit/ContractOriginEnergyLimit001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/originenergylimit/ContractOriginEnergyLimit001.java index 739ffd10..53c56e03 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/originenergylimit/ContractOriginEnergyLimit001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/originenergylimit/ContractOriginEnergyLimit001.java @@ -14,10 +14,10 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode @@ -27,91 +27,130 @@ public class ContractOriginEnergyLimit001 extends TronBaseTest { String testKeyForGrammarAddress3 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(testKeyForGrammarAddress3); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(testKeyForGrammarAddress3); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } - - //Origin_energy_limit001,028,029 - @Test(enabled = true, description = "Boundary value and update test", groups = {"daily"}) + // Origin_energy_limit001,028,029 + @Test( + enabled = true, + description = "Boundary value and update test", + groups = {"daily"}) public void testOrigin_energy_limit001() { - Assert.assertTrue(PublicMethod - .sendcoin(grammarAddress3, 100000000000L, foundationAddress, foundationKey, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + grammarAddress3, 100000000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/contractOriginEnergyLimit001.sol"; - String contractName = "findArgsContractTest"; + String filePath = "src/test/resources/soliditycode/contractOriginEnergyLimit001.sol"; + String contractName = "findArgsContractTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String contractAddress = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 0L, 100, -1, "0", 0, - null, testKeyForGrammarAddress3, - grammarAddress3, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String contractAddress = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + -1, + "0", + 0, + null, + testKeyForGrammarAddress3, + grammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(contractAddress == null); - String contractAddress1 = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 0L, 100, 0, "0", 0, - null, testKeyForGrammarAddress3, - grammarAddress3, blockingStubFull); + String contractAddress1 = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + 0, + "0", + 0, + null, + testKeyForGrammarAddress3, + grammarAddress3, + blockingStubFull); Assert.assertTrue(contractAddress1 == null); - byte[] contractAddress2 = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, 9223372036854775807L, "0", - 0, null, testKeyForGrammarAddress3, - grammarAddress3, blockingStubFull); + byte[] contractAddress2 = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + 9223372036854775807L, + "0", + 0, + null, + testKeyForGrammarAddress3, + grammarAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertFalse(PublicMethod.updateEnergyLimit(contractAddress2, -1L, - testKeyForGrammarAddress3, grammarAddress3, blockingStubFull)); + Assert.assertFalse( + PublicMethod.updateEnergyLimit( + contractAddress2, -1L, testKeyForGrammarAddress3, grammarAddress3, blockingStubFull)); SmartContract smartContract = PublicMethod.getContract(contractAddress2, blockingStubFull); Assert.assertTrue(smartContract.getOriginEnergyLimit() == 9223372036854775807L); - Assert.assertFalse(PublicMethod.updateEnergyLimit(contractAddress2, 0L, - testKeyForGrammarAddress3, grammarAddress3, blockingStubFull)); + Assert.assertFalse( + PublicMethod.updateEnergyLimit( + contractAddress2, 0L, testKeyForGrammarAddress3, grammarAddress3, blockingStubFull)); SmartContract smartContract1 = PublicMethod.getContract(contractAddress2, blockingStubFull); Assert.assertTrue(smartContract1.getOriginEnergyLimit() == 9223372036854775807L); - Assert.assertTrue(PublicMethod.updateEnergyLimit(contractAddress2, - 9223372036854775807L, testKeyForGrammarAddress3, - grammarAddress3, blockingStubFull)); + Assert.assertTrue( + PublicMethod.updateEnergyLimit( + contractAddress2, + 9223372036854775807L, + testKeyForGrammarAddress3, + grammarAddress3, + blockingStubFull)); SmartContract smartContract2 = PublicMethod.getContract(contractAddress2, blockingStubFull); Assert.assertTrue(smartContract2.getOriginEnergyLimit() == 9223372036854775807L); - Assert.assertTrue(PublicMethod.updateEnergyLimit(contractAddress2, 'c', - testKeyForGrammarAddress3, grammarAddress3, blockingStubFull)); + Assert.assertTrue( + PublicMethod.updateEnergyLimit( + contractAddress2, 'c', testKeyForGrammarAddress3, grammarAddress3, blockingStubFull)); SmartContract smartContract3 = PublicMethod.getContract(contractAddress2, blockingStubFull); Assert.assertEquals(smartContract3.getOriginEnergyLimit(), 99); - Assert.assertFalse(PublicMethod.updateEnergyLimit(contractAddress2, 1L, - foundationKey, foundationAddress, blockingStubFull)); + Assert.assertFalse( + PublicMethod.updateEnergyLimit( + contractAddress2, 1L, foundationKey, foundationAddress, blockingStubFull)); SmartContract smartContract4 = PublicMethod.getContract(contractAddress2, blockingStubFull); Assert.assertEquals(smartContract4.getOriginEnergyLimit(), 99); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(grammarAddress3, testKeyForGrammarAddress3, foundationAddress, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + grammarAddress3, testKeyForGrammarAddress3, foundationAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/originenergylimit/ContractOriginEnergyLimit004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/originenergylimit/ContractOriginEnergyLimit004.java index 386f5b49..23668a47 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/originenergylimit/ContractOriginEnergyLimit004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/originenergylimit/ContractOriginEnergyLimit004.java @@ -20,10 +20,10 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode @@ -37,30 +37,27 @@ public class ContractOriginEnergyLimit004 extends TronBaseTest { String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + public void beforeClass() { + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } private long getAvailableFrozenEnergy(byte[] accountAddress) { - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(accountAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(accountAddress, blockingStubFull); long energyLimit = resourceInfo.getEnergyLimit(); long energyUsed = resourceInfo.getEnergyUsed(); return energyLimit - energyUsed; } private long getUserAvailableEnergy(byte[] userAddress) { - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(userAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(userAddress, blockingStubFull); Account info = PublicMethod.queryAccount(userAddress, blockingStubFull); long balance = info.getBalance(); long energyLimit = resourceInfo.getEnergyLimit(); @@ -89,10 +86,10 @@ private long getConsumeUserResourcePercent(byte[] contractAddress) { return smartContract.getConsumeUserResourcePercent(); } - private long getDevMax(byte[] devAddress, byte[] userAddress, long feeLimit, - byte[] contractAddress) { - long devMax = Math.min(getAvailableFrozenEnergy(devAddress), - getOriginalEnergyLimit(contractAddress)); + private long getDevMax( + byte[] devAddress, byte[] userAddress, long feeLimit, byte[] contractAddress) { + long devMax = + Math.min(getAvailableFrozenEnergy(devAddress), getOriginalEnergyLimit(contractAddress)); long p = getConsumeUserResourcePercent(contractAddress); if (p != 0) { logger.info("p: " + p); @@ -104,49 +101,57 @@ private long getDevMax(byte[] devAddress, byte[] userAddress, long feeLimit, return devMax; } - @Test(enabled = true, description = "Contract use Origin_energy_limit", groups = {"daily"}) + @Test( + enabled = true, + description = "Contract use Origin_energy_limit", + groups = {"daily"}) public void testOriginEnergyLimit() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 1000000L, foundationAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 1000000L, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1000000L, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 1000000L, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - // A2B1 + // A2B1 - //dev balance and Energy + // dev balance and Energy long devTargetBalance = 10_000_000; long devTargetEnergy = 70000; - // deploy contract parameters + // deploy contract parameters final long deployFeeLimit = maxFeeLimit; - final long consumeUserResourcePercent = 0; - final long originEnergyLimit = 1000; - //dev balance and Energy + final long consumeUserResourcePercent = 0; + final long originEnergyLimit = 1000; + // dev balance and Energy final long devTriggerTargetBalance = 0; - final long devTriggerTargetEnergy = 592; - // user balance and Energy + final long devTriggerTargetEnergy = 592; + // user balance and Energy final long userTargetBalance = 0; - final long userTargetEnergy = 2000L; - // trigger contract parameter, maxFeeLimit 10000000 + final long userTargetEnergy = 2000L; + // trigger contract parameter, maxFeeLimit 10000000 final long triggerFeeLimit = maxFeeLimit; - final boolean expectRet = true; - // count dev energy, balance - long devFreezeBalanceSun = PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, - devTargetEnergy, blockingStubFull); + final boolean expectRet = true; + // count dev energy, balance + long devFreezeBalanceSun = + PublicMethod.getFreezeBalanceCount( + dev001Address, dev001Key, devTargetEnergy, blockingStubFull); long devNeedBalance = devTargetBalance + devFreezeBalanceSun + 2000000000L; logger.info("need balance:" + devNeedBalance); - // get balance - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, devNeedBalance, foundationAddress, - testKey002, blockingStubFull)); + // get balance + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, devNeedBalance, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - // get energy - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(dev001Address, devFreezeBalanceSun + 2000000000L, - 0, 1, dev001Key, blockingStubFull)); + // get energy + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + dev001Address, devFreezeBalanceSun + 2000000000L, 0, 1, dev001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); @@ -154,15 +159,27 @@ public void testOriginEnergyLimit() { logger.info("before deploy, dev energy limit is " + Long.toString(devEnergyLimitBefore)); logger.info("before deploy, dev energy usage is " + Long.toString(devEnergyUsageBefore)); logger.info("before deploy, dev balance is " + Long.toString(devBalanceBefore)); - String filePath = "src/test/resources/soliditycode/contractOriginEnergyLimit004.sol"; - String contractName = "findArgsContractTest"; + String filePath = "src/test/resources/soliditycode/contractOriginEnergyLimit004.sol"; + String contractName = "findArgsContractTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String deployTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - deployFeeLimit, 0L, consumeUserResourcePercent, originEnergyLimit, "0", - 0, null, dev001Key, dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String deployTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + deployFeeLimit, + 0L, + consumeUserResourcePercent, + originEnergyLimit, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -174,8 +191,8 @@ public void testOriginEnergyLimit() { logger.info("after deploy, dev energy usage is " + Long.toString(devEnergyUsageAfter)); logger.info("after deploy, dev balance is " + Long.toString(devBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(deployTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(deployTxid, blockingStubFull); ByteString contractAddressString = infoById.get().getContractAddress(); contractAddress = contractAddressString.toByteArray(); @@ -186,30 +203,36 @@ public void testOriginEnergyLimit() { Assert.assertTrue(devEnergyLimitAfter > 0); Assert.assertTrue(devEnergyUsageAfter > 0); Assert.assertEquals(devBalanceBefore, devBalanceAfter); - // count dev energy, balance - devFreezeBalanceSun = PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, - devTriggerTargetEnergy, blockingStubFull); + // count dev energy, balance + devFreezeBalanceSun = + PublicMethod.getFreezeBalanceCount( + dev001Address, dev001Key, devTriggerTargetEnergy, blockingStubFull); devNeedBalance = devTriggerTargetBalance + devFreezeBalanceSun; logger.info("dev need balance:" + devNeedBalance); - // count user energy, balance - long userFreezeBalanceSun = PublicMethod.getFreezeBalanceCount(user001Address, user001Key, - userTargetEnergy, blockingStubFull); + // count user energy, balance + long userFreezeBalanceSun = + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, userTargetEnergy, blockingStubFull); long userNeedBalance = userTargetBalance + userFreezeBalanceSun; logger.info("User need balance:" + userNeedBalance); - // get balance - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, devNeedBalance, foundationAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, userNeedBalance, foundationAddress, - testKey002, blockingStubFull)); + // get balance + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, devNeedBalance, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, userNeedBalance, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - // get energy - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(dev001Address, devFreezeBalanceSun, - 0, 1, dev001Key, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(user001Address, userFreezeBalanceSun, - 0, 1, user001Key, blockingStubFull)); + // get energy + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + dev001Address, devFreezeBalanceSun, 0, 1, dev001Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + user001Address, userFreezeBalanceSun, 0, 1, user001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -217,22 +240,22 @@ public void testOriginEnergyLimit() { devEnergyUsageBefore = accountResource.getEnergyUsed(); devBalanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - logger.info("before trigger, dev devEnergyLimitBefore is " - + Long.toString(devEnergyLimitBefore)); - logger.info("before trigger, dev devEnergyUsageBefore is " - + Long.toString(devEnergyUsageBefore)); + logger.info( + "before trigger, dev devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info( + "before trigger, dev devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); logger.info("before trigger, dev devBalanceBefore is " + Long.toString(devBalanceBefore)); accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount( - user001Address, blockingStubFull).getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); - logger.info("before trigger, user userEnergyLimitBefore is " - + Long.toString(userEnergyLimitBefore)); - logger.info("before trigger, user userEnergyUsageBefore is " - + Long.toString(userEnergyUsageBefore)); + logger.info( + "before trigger, user userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info( + "before trigger, user userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, user userBalanceBefore is " + Long.toString(userBalanceBefore)); logger.info("=================================="); @@ -242,11 +265,18 @@ public void testOriginEnergyLimit() { logger.info("userMax: " + userMax); logger.info("devMax: " + devMax); logger.info("=================================="); - String param = "\"" + 0 + "\""; - final String triggerTxid = PublicMethod - .triggerContract(contractAddress, "findArgsByIndexTest(uint256)", - param, false, 0, triggerFeeLimit, - user001Address, user001Key, blockingStubFull); + String param = "\"" + 0 + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + contractAddress, + "findArgsByIndexTest(uint256)", + param, + false, + 0, + triggerFeeLimit, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -261,13 +291,13 @@ public void testOriginEnergyLimit() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, - blockingStubFull).getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); - logger.info("after trigger, user userEnergyLimitAfter is " - + Long.toString(userEnergyLimitAfter)); - logger.info("after trigger, user userEnergyUsageAfter is " - + Long.toString(userEnergyUsageAfter)); + logger.info( + "after trigger, user userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info( + "after trigger, user userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, user userBalanceAfter is " + Long.toString(userBalanceAfter)); infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); @@ -299,19 +329,19 @@ public void testOriginEnergyLimit() { long devExpectCost = energyTotalUsage * (100 - consumeUserPercent) / 100; long userExpectCost = energyTotalUsage - devExpectCost; - final long totalCost = devExpectCost + userExpectCost; + final long totalCost = devExpectCost + userExpectCost; logger.info("devExpectCost: " + devExpectCost); logger.info("userExpectCost: " + userExpectCost); Assert.assertTrue(devEnergyLimitAfter > 0); Assert.assertEquals(devBalanceBefore, devBalanceAfter); - // dev original is the dev max expense A2B1 + // dev original is the dev max expense A2B1 Assert.assertEquals(getOriginalEnergyLimit(contractAddress), devMax); - // DEV is enough to pay + // DEV is enough to pay Assert.assertEquals(originEnergyUsage, devExpectCost); - // Assert.assertEquals(devEnergyUsageAfter,devExpectCost + devEnergyUsageBefore); - // User Energy is enough to pay"); + // Assert.assertEquals(devEnergyUsageAfter,devExpectCost + devEnergyUsageBefore); + // User Energy is enough to pay"); Assert.assertEquals(energyUsage, userExpectCost); Assert.assertEquals(userBalanceBefore, userBalanceAfter); Assert.assertEquals(userEnergyUsageAfter, userEnergyUsageBefore); @@ -325,18 +355,15 @@ public void testOriginEnergyLimit() { } } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull); PublicMethod.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull); PublicMethod.freeResource(user001Address, user001Key, foundationAddress, blockingStubFull); - PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/performance/ApiLatencyTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/performance/ApiLatencyTest.java index fa69f38b..57af0532 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/performance/ApiLatencyTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/performance/ApiLatencyTest.java @@ -14,8 +14,8 @@ /** * API response latency measurement. * - *

Measures gRPC API call latencies for common operations. - * This is a smoke benchmark to ensure API response times are reasonable. + *

Measures gRPC API call latencies for common operations. This is a smoke benchmark to ensure + * API response times are reasonable. */ @Slf4j public class ApiLatencyTest extends TronBaseTest { @@ -23,7 +23,9 @@ public class ApiLatencyTest extends TronBaseTest { private static final int ITERATIONS = 20; private static final long MAX_AVG_LATENCY_MS = 5000; // 5 seconds max avg - @Test(enabled = true, description = "GetNowBlock API latency", + @Test( + enabled = true, + description = "GetNowBlock API latency", groups = {"daily"}) public void test01GetNowBlockLatency() { long totalMs = 0; @@ -36,11 +38,14 @@ public void test01GetNowBlockLatency() { } double avgMs = (double) totalMs / ITERATIONS; logger.info("GetNowBlock avg latency: {:.1f} ms over {} calls", avgMs, ITERATIONS); - Assert.assertTrue(avgMs < MAX_AVG_LATENCY_MS, + Assert.assertTrue( + avgMs < MAX_AVG_LATENCY_MS, "GetNowBlock avg latency should be < " + MAX_AVG_LATENCY_MS + " ms, got " + avgMs); } - @Test(enabled = true, description = "ListWitnesses API latency", + @Test( + enabled = true, + description = "ListWitnesses API latency", groups = {"daily"}) public void test02ListWitnessesLatency() { long totalMs = 0; @@ -53,11 +58,14 @@ public void test02ListWitnessesLatency() { } double avgMs = (double) totalMs / ITERATIONS; logger.info("ListWitnesses avg latency: {:.1f} ms over {} calls", avgMs, ITERATIONS); - Assert.assertTrue(avgMs < MAX_AVG_LATENCY_MS, + Assert.assertTrue( + avgMs < MAX_AVG_LATENCY_MS, "ListWitnesses avg latency should be < " + MAX_AVG_LATENCY_MS + " ms, got " + avgMs); } - @Test(enabled = true, description = "GetBlockByNum API latency", + @Test( + enabled = true, + description = "GetBlockByNum API latency", groups = {"daily"}) public void test03GetBlockByNumLatency() { Block latest = PublicMethod.getBlock(-1, blockingStubFull); @@ -73,11 +81,14 @@ public void test03GetBlockByNumLatency() { } double avgMs = (double) totalMs / ITERATIONS; logger.info("GetBlockByNum avg latency: {:.1f} ms over {} calls", avgMs, ITERATIONS); - Assert.assertTrue(avgMs < MAX_AVG_LATENCY_MS, + Assert.assertTrue( + avgMs < MAX_AVG_LATENCY_MS, "GetBlockByNum avg latency should be < " + MAX_AVG_LATENCY_MS + " ms, got " + avgMs); } - @Test(enabled = true, description = "QueryAccount API latency", + @Test( + enabled = true, + description = "QueryAccount API latency", groups = {"daily"}) public void test04QueryAccountLatency() { long totalMs = 0; @@ -89,25 +100,29 @@ public void test04QueryAccountLatency() { } double avgMs = (double) totalMs / ITERATIONS; logger.info("QueryAccount avg latency: {:.1f} ms over {} calls", avgMs, ITERATIONS); - Assert.assertTrue(avgMs < MAX_AVG_LATENCY_MS, + Assert.assertTrue( + avgMs < MAX_AVG_LATENCY_MS, "QueryAccount avg latency should be < " + MAX_AVG_LATENCY_MS + " ms, got " + avgMs); } - @Test(enabled = true, description = "GetNextMaintenanceTime API latency", + @Test( + enabled = true, + description = "GetNextMaintenanceTime API latency", groups = {"daily"}) public void test05GetNextMaintenanceTimeLatency() { long totalMs = 0; for (int i = 0; i < ITERATIONS; i++) { long start = System.currentTimeMillis(); - NumberMessage result = blockingStubFull.getNextMaintenanceTime( - EmptyMessage.newBuilder().build()); + NumberMessage result = + blockingStubFull.getNextMaintenanceTime(EmptyMessage.newBuilder().build()); long elapsed = System.currentTimeMillis() - start; totalMs += elapsed; Assert.assertTrue(result.getNum() > 0); } double avgMs = (double) totalMs / ITERATIONS; logger.info("GetNextMaintenanceTime avg latency: {:.1f} ms over {} calls", avgMs, ITERATIONS); - Assert.assertTrue(avgMs < MAX_AVG_LATENCY_MS, + Assert.assertTrue( + avgMs < MAX_AVG_LATENCY_MS, "GetNextMaintenanceTime avg latency should be < " + MAX_AVG_LATENCY_MS + " ms"); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/performance/BlockLatencyTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/performance/BlockLatencyTest.java index 49ddf038..2ce490ae 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/performance/BlockLatencyTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/performance/BlockLatencyTest.java @@ -12,25 +12,28 @@ /** * Block latency measurement. * - *

Measures actual block production intervals by observing consecutive - * blocks and computing statistics. TRON targets 3-second block intervals. + *

Measures actual block production intervals by observing consecutive blocks and computing + * statistics. TRON targets 3-second block intervals. */ @Slf4j public class BlockLatencyTest extends TronBaseTest { private static final int SAMPLE_SIZE = 10; - @Test(enabled = true, description = "Measure block production interval statistics", + @Test( + enabled = true, + description = "Measure block production interval statistics", groups = {"daily"}) public void test01BlockIntervalStatistics() { // Wait for enough blocks to exist PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Block latest = blockingStubFull.getNowBlock(org.tron.api.GrpcAPI.EmptyMessage.newBuilder().build()); + Block latest = + blockingStubFull.getNowBlock(org.tron.api.GrpcAPI.EmptyMessage.newBuilder().build()); long currentNum = latest.getBlockHeader().getRawData().getNumber(); - Assert.assertTrue(currentNum > SAMPLE_SIZE, - "Need at least " + SAMPLE_SIZE + " blocks, got " + currentNum); + Assert.assertTrue( + currentNum > SAMPLE_SIZE, "Need at least " + SAMPLE_SIZE + " blocks, got " + currentNum); long startNum = currentNum - SAMPLE_SIZE; List intervals = new ArrayList<>(); @@ -63,14 +66,18 @@ public void test01BlockIntervalStatistics() { logger.info(" Min: {} ms, Max: {} ms", minMs, maxMs); // TRON targets 3000ms blocks; allow 2000-6000ms average - Assert.assertTrue(avgMs >= 2000 && avgMs <= 6000, + Assert.assertTrue( + avgMs >= 2000 && avgMs <= 6000, "Average block interval should be 2-6 seconds, got " + avgMs + " ms"); } - @Test(enabled = true, description = "Block numbers should be strictly sequential", + @Test( + enabled = true, + description = "Block numbers should be strictly sequential", groups = {"daily"}) public void test02BlockNumberSequential() { - Block latest = blockingStubFull.getNowBlock(org.tron.api.GrpcAPI.EmptyMessage.newBuilder().build()); + Block latest = + blockingStubFull.getNowBlock(org.tron.api.GrpcAPI.EmptyMessage.newBuilder().build()); long currentNum = latest.getBlockHeader().getRawData().getNumber(); long startNum = Math.max(1, currentNum - 20); @@ -79,11 +86,13 @@ public void test02BlockNumberSequential() { Block block = PublicMethod.getBlock(i, blockingStubFull); Assert.assertNotNull(block, "Block " + i + " should exist"); long num = block.getBlockHeader().getRawData().getNumber(); - Assert.assertEquals(num, prevNum + 1, - "Block numbers should be sequential"); + Assert.assertEquals(num, prevNum + 1, "Block numbers should be sequential"); prevNum = num; } - logger.info("Verified {} sequential blocks ({} to {})", - currentNum - startNum + 1, startNum, currentNum); + logger.info( + "Verified {} sequential blocks ({} to {})", + currentNum - startNum + 1, + startNum, + currentNum); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/performance/ThroughputBenchmarkTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/performance/ThroughputBenchmarkTest.java index bfd2abe4..264ff7af 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/performance/ThroughputBenchmarkTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/performance/ThroughputBenchmarkTest.java @@ -17,9 +17,8 @@ /** * Transaction throughput benchmark. * - *

Measures how many TRX transfer transactions can be submitted and - * confirmed within a given time window. This is a smoke benchmark, - * not a full stress test. + *

Measures how many TRX transfer transactions can be submitted and confirmed within a given time + * window. This is a smoke benchmark, not a full stress test. */ @Slf4j public class ThroughputBenchmarkTest extends TronBaseTest { @@ -37,9 +36,13 @@ public void beforeClass() { senderKeyStr = ByteArray.toHexString(senderKey.getPrivKeyBytes()); // Fund sender with enough TRX for batch transfers + fees - Assert.assertTrue(PublicMethod.sendcoin(senderAddress, - TronConstants.TEN_THOUSAND_TRX * 10, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + senderAddress, + TronConstants.TEN_THOUSAND_TRX * 10, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); // Pre-generate receiver addresses @@ -49,7 +52,9 @@ public void beforeClass() { } } - @Test(enabled = true, description = "Batch submit TRX transfers and measure throughput", + @Test( + enabled = true, + description = "Batch submit TRX transfers and measure throughput", groups = {"daily"}) public void test01BatchTransferThroughput() { long sendAmount = 100_000L; // 0.1 TRX each @@ -57,20 +62,22 @@ public void test01BatchTransferThroughput() { long startTime = System.currentTimeMillis(); for (int i = 0; i < BATCH_SIZE; i++) { - boolean result = PublicMethod.sendcoin(receiverAddresses.get(i), sendAmount, - senderAddress, senderKeyStr, blockingStubFull); + boolean result = + PublicMethod.sendcoin( + receiverAddresses.get(i), sendAmount, senderAddress, senderKeyStr, blockingStubFull); if (result) { successCount++; } } long elapsed = System.currentTimeMillis() - startTime; - logger.info("Submitted {} transactions in {} ms ({} success)", - BATCH_SIZE, elapsed, successCount); + logger.info( + "Submitted {} transactions in {} ms ({} success)", BATCH_SIZE, elapsed, successCount); double tps = (successCount * 1000.0) / elapsed; logger.info("Submission TPS: {:.2f}", tps); - Assert.assertTrue(successCount > BATCH_SIZE * 0.8, + Assert.assertTrue( + successCount > BATCH_SIZE * 0.8, "At least 80% of transactions should be accepted, got " + successCount); // Wait for confirmation @@ -80,8 +87,8 @@ public void test01BatchTransferThroughput() { // Verify some transactions were confirmed int confirmedCount = 0; for (int i = 0; i < Math.min(10, BATCH_SIZE); i++) { - org.tron.protos.Protocol.Account acc = PublicMethod.queryAccount( - receiverAddresses.get(i), blockingStubFull); + org.tron.protos.Protocol.Account acc = + PublicMethod.queryAccount(receiverAddresses.get(i), blockingStubFull); if (acc.getBalance() == sendAmount) { confirmedCount++; } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/ratelimit/HttpRateLimit001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/ratelimit/HttpRateLimit001.java index 7fa24383..f2d94fe5 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/ratelimit/HttpRateLimit001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/ratelimit/HttpRateLimit001.java @@ -31,52 +31,47 @@ public class HttpRateLimit001 extends JsonRpcBase { private String httpSoliditynode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(3); private String httpSoliditynode2 = - Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(5); + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(5); private String realHttpSoliditynode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); private String httpPbftNode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(4); private String httpPbftNode2 = - Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(6); + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(6); - //FullNode2 only rate.limiter.global.ip.qps=15 + // FullNode2 only rate.limiter.global.ip.qps=15 private ManagedChannel channelFull2 = null; private WalletGrpc.WalletBlockingStub blockingStubFull2 = null; private String fullnode2 = - Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list") - .get(1); + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private ManagedChannel channelFull3 = null; private WalletGrpc.WalletBlockingStub blockingStubFull3 = null; - //just for case 010 + // just for case 010 private String fullnode3 = - Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list") - .get(1); + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); public static String jsonRpcNode2 = - Configuration.getByPath("testng.conf").getStringList("jsonRpcNode.ip.list").get(2); - private String httpnode2 = Configuration - .getByPath("testng.conf") - .getStringList("httpnode.ip.list") - .get(1); + Configuration.getByPath("testng.conf").getStringList("jsonRpcNode.ip.list").get(2); + private String httpnode2 = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(1); /** constructor. */ @BeforeClass public void beforeClass() { - channelFull2 = ManagedChannelBuilder.forTarget(fullnode2) - .usePlaintext() - .build(); + channelFull2 = ManagedChannelBuilder.forTarget(fullnode2).usePlaintext().build(); blockingStubFull2 = WalletGrpc.newBlockingStub(channelFull2); - channelFull3 = ManagedChannelBuilder.forTarget(fullnode3) - .usePlaintext() - .build(); + channelFull3 = ManagedChannelBuilder.forTarget(fullnode3).usePlaintext().build(); blockingStubFull3 = WalletGrpc.newBlockingStub(channelFull3); } /** constructor. */ - @Test(enabled = true, description = "Rate limit QpsStrategy for ListWitness interface", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Rate limit QpsStrategy for ListWitness interface", + groups = {"daily", "serial"}) public void test01QpsStrategyForListWitnessInterface() { Long startTimeStamp = System.currentTimeMillis(); Integer repeatTimes = 0; @@ -89,7 +84,10 @@ public void test01QpsStrategyForListWitnessInterface() { } /** constructor. */ - @Test(enabled = true, description = "Rate limit IpQpsStrategy for ListNodes interface", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Rate limit IpQpsStrategy for ListNodes interface", + groups = {"daily", "serial"}) public void test02IpQpsStrategyForListNodesInterface() { Long startTimeStamp = System.currentTimeMillis(); Integer repeatTimes = 0; @@ -106,7 +104,8 @@ public void test02IpQpsStrategyForListNodesInterface() { enabled = true, description = "Rate limit IpQpsStrategy for GetBlockByLatestNumOnSolidity " - + "interface on fullnode's solidity service", groups = {"daily", "serial"}) + + "interface on fullnode's solidity service", + groups = {"daily", "serial"}) public void test03IpQpsStrategyForGetBlockByLatestNumOnSolidityInterface() { Long startTimeStamp = System.currentTimeMillis(); Integer repeatTimes = 0; @@ -123,7 +122,8 @@ public void test03IpQpsStrategyForGetBlockByLatestNumOnSolidityInterface() { @Test( enabled = true, description = - "Rate limit QpsStrategy for getBlockByNum " + "interface on fullnode's solidity service", groups = {"daily", "serial"}) + "Rate limit QpsStrategy for getBlockByNum " + "interface on fullnode's solidity service", + groups = {"daily", "serial"}) public void test04QpsStrategyForgetBlockByNumResourceInterfaceOnFullnodeSolidityService() { Long startTimeStamp = System.currentTimeMillis(); Integer repeatTimes = 0; @@ -141,7 +141,8 @@ public void test04QpsStrategyForgetBlockByNumResourceInterfaceOnFullnodeSolidity description = "Rate limit QpsStrategy for " + "getTransactionsFromThisFromSolidity " - + "interface on real solidity", groups = {"daily", "serial"}) + + "interface on real solidity", + groups = {"daily", "serial"}) public void test06QpsStrategyForgetTransactionsToThisFromSolidity() { Long startTimeStamp = System.currentTimeMillis(); Integer repeatTimes = 0; @@ -154,7 +155,10 @@ public void test06QpsStrategyForgetTransactionsToThisFromSolidity() { Assert.assertTrue(endTimesStap - startTimeStamp > 4000); } - @Test(enabled = true, description = "Verify getstatsinfo Interface has been disabled", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Verify getstatsinfo Interface has been disabled", + groups = {"daily", "serial"}) public void test07GetStatsInfo() { response = HttpMethod.getStatsInfo(httpnode); responseContent = HttpMethod.parseResponseContent(response); @@ -164,9 +168,11 @@ public void test07GetStatsInfo() { Assert.assertEquals(resultForGetstatsinfo, "this API is unavailable due to config"); } - /** constructor. */ - @Test(enabled = true, description = "Rate limit global qps for all jsonrpc api", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Rate limit global qps for all jsonrpc api", + groups = {"daily", "serial"}) public void test08GlobalQpsRate() { Long startTimeStamp = System.currentTimeMillis(); Integer repeatTimes = 0; @@ -185,33 +191,39 @@ public void test08GlobalQpsRate() { Assert.assertTrue(endTimesStamp - startTimeStamp > 28500); } - /** constructor. */ - @Test(enabled = true, description = "Rate limit global qps for grpc api", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Rate limit global qps for grpc api", + groups = {"daily", "serial"}) public void test09GlobalQpsRateForGrpc() { Long startTimeStamp = System.currentTimeMillis(); Integer repeatTimes = 0; while (repeatTimes++ < 200) { - Assert.assertTrue(PublicMethod.getAccountResource(foundationAddress, blockingStubFull2) - .getTotalEnergyLimit() > 0); + Assert.assertTrue( + PublicMethod.getAccountResource(foundationAddress, blockingStubFull2) + .getTotalEnergyLimit() + > 0); } Long endTimesStamp = System.currentTimeMillis(); logger.info("startTimeStamp - endTimesStap:" + (endTimesStamp - startTimeStamp)); Assert.assertTrue(endTimesStamp - startTimeStamp > 7500); - } /** constructor. */ - @Test(enabled = true, description = "Rate limit global qps for mix api", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Rate limit global qps for mix api", + groups = {"daily", "serial"}) public void test10GlobalQpsRateForMix() { Long startTimeStamp = System.currentTimeMillis(); Integer repeatTimes = 0; while (repeatTimes < 200) { - Assert.assertTrue(PublicMethod.queryAccount(foundationAddress, blockingStubFull2) - .getBalance() > 0); + Assert.assertTrue( + PublicMethod.queryAccount(foundationAddress, blockingStubFull2).getBalance() > 0); response = HttpMethod.getAccount(httpnode2, foundationAddress); responseContent = HttpMethod.parseResponseContent(response); @@ -232,21 +244,26 @@ public void test10GlobalQpsRateForMix() { logger.info("startTimeStamp - endTimesStap:" + (endTimesStamp - startTimeStamp)); logger.info("QPS:" + repeatTimes / ((endTimesStamp - startTimeStamp) / 1000)); Assert.assertTrue(endTimesStamp - startTimeStamp > 7000); - } /** constructor. */ - @Test(enabled = true, description - = "Rate limit global qps with different blockingStubFull instance but same node", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Rate limit global qps with different blockingStubFull instance but same node", + groups = {"daily", "serial"}) public void test11GlobalQpsRateForGrpcDifferentPort() { Long startTimeStamp = System.currentTimeMillis(); Integer repeatTimes = 0; while (repeatTimes < 200) { - Assert.assertTrue(PublicMethod.getAccountResource(foundationAddress, blockingStubFull2) - .getTotalEnergyLimit() > 0); - Assert.assertTrue(PublicMethod.getAccountResource(foundationAddress, blockingStubFull3) - .getTotalEnergyLimit() > 0); + Assert.assertTrue( + PublicMethod.getAccountResource(foundationAddress, blockingStubFull2) + .getTotalEnergyLimit() + > 0); + Assert.assertTrue( + PublicMethod.getAccountResource(foundationAddress, blockingStubFull3) + .getTotalEnergyLimit() + > 0); repeatTimes += 2; } Long endTimesStamp = System.currentTimeMillis(); @@ -255,16 +272,21 @@ public void test11GlobalQpsRateForGrpcDifferentPort() { Assert.assertTrue(endTimesStamp - startTimeStamp > 7000); } - /** constructor. */ - @Test(enabled = true, description = "Rate limit global ip qps for mix api", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "Rate limit global ip qps for mix api", + groups = {"daily", "serial"}) public void test12GlobalIpQpsRateForMix() { Long startTimeStamp = System.currentTimeMillis(); Integer repeatTimes = 0; while (repeatTimes < 200) { - Assert.assertTrue(PublicMethod.getAccountResource(foundationAddress, blockingStubFull2).getTotalEnergyLimit() > 0); + Assert.assertTrue( + PublicMethod.getAccountResource(foundationAddress, blockingStubFull2) + .getTotalEnergyLimit() + > 0); response = HttpMethod.getAccount(httpnode2, foundationAddress); responseContent = HttpMethod.parseResponseContent(response); @@ -283,13 +305,10 @@ public void test12GlobalIpQpsRateForMix() { } Long endTimesStamp = System.currentTimeMillis(); logger.info("startTimeStamp - endTimesStap:" + (endTimesStamp - startTimeStamp)); - logger.info("QPS:" + repeatTimes/((endTimesStamp - startTimeStamp) / 1000)); + logger.info("QPS:" + repeatTimes / ((endTimesStamp - startTimeStamp) / 1000)); Assert.assertTrue(endTimesStamp - startTimeStamp > 7000); - } - - /** constructor. */ @AfterClass public void shutdown() throws InterruptedException {} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/ratelimit/RateLimitEdgeTest001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/ratelimit/RateLimitEdgeTest001.java index 92472c53..4a94b21a 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/ratelimit/RateLimitEdgeTest001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/ratelimit/RateLimitEdgeTest001.java @@ -9,17 +9,15 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.EmptyMessage; -import org.tron.api.GrpcAPI.NumberMessage; import org.tron.api.WalletGrpc; -import org.tron.protos.Protocol.Account; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; /** * TIP-467: Rate limiting boundary tests. * - *

Tests gRPC rate limiting behavior including burst requests, - * different API endpoint limits, and recovery after rate limiting. + *

Tests gRPC rate limiting behavior including burst requests, different API endpoint limits, and + * recovery after rate limiting. */ @Slf4j public class RateLimitEdgeTest001 extends TronBaseTest { @@ -29,15 +27,23 @@ public void beforeClass() { // Base class provides channelFull and blockingStubFull } - @Test(enabled = true, description = "Single request should always succeed", + @Test( + enabled = true, + description = "Single request should always succeed", groups = {"daily", "serial"}) public void test01SingleRequestSucceeds() { - long blockNum = blockingStubFull.getNowBlock2( - EmptyMessage.newBuilder().build()).getBlockHeader().getRawData().getNumber(); + long blockNum = + blockingStubFull + .getNowBlock2(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); logger.info("Current block number: {}", blockNum); } - @Test(enabled = true, description = "Burst of getNowBlock requests", + @Test( + enabled = true, + description = "Burst of getNowBlock requests", groups = {"daily", "serial"}) public void test02BurstGetNowBlock() { int successCount = 0; @@ -54,12 +60,17 @@ public void test02BurstGetNowBlock() { } } - logger.info("Burst test: {} success, {} rate limited out of {}", - successCount, failCount, totalRequests); + logger.info( + "Burst test: {} success, {} rate limited out of {}", + successCount, + failCount, + totalRequests); Assert.assertTrue(successCount > 0, "At least some requests should succeed"); } - @Test(enabled = true, description = "Burst of getAccount requests", + @Test( + enabled = true, + description = "Burst of getAccount requests", groups = {"daily", "serial"}) public void test03BurstGetAccount() { int successCount = 0; @@ -75,12 +86,17 @@ public void test03BurstGetAccount() { } } - logger.info("getAccount burst: {} success, {} limited out of {}", - successCount, failCount, totalRequests); + logger.info( + "getAccount burst: {} success, {} limited out of {}", + successCount, + failCount, + totalRequests); Assert.assertTrue(successCount > 0, "At least some requests should succeed"); } - @Test(enabled = true, description = "Recovery after rate limiting pause", + @Test( + enabled = true, + description = "Recovery after rate limiting pause", groups = {"daily", "serial"}) public void test04RecoveryAfterPause() throws InterruptedException { // Send a burst to potentially trigger rate limiting @@ -104,12 +120,13 @@ public void test04RecoveryAfterPause() throws InterruptedException { } } - @Test(enabled = true, description = "Multiple connections should have independent rate limits", + @Test( + enabled = true, + description = "Multiple connections should have independent rate limits", groups = {"daily", "serial"}) public void test05IndependentConnectionLimits() throws InterruptedException { // Create a second channel - ManagedChannel channel2 = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext().build(); + ManagedChannel channel2 = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); WalletGrpc.WalletBlockingStub stub2 = WalletGrpc.newBlockingStub(channel2); try { diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/ratelimit/RateLimite001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/ratelimit/RateLimite001.java index 206d225a..a3944f5c 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/ratelimit/RateLimite001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/ratelimit/RateLimite001.java @@ -15,43 +15,35 @@ import stest.tron.wallet.common.client.utils.TronBaseTest; @Slf4j -public class RateLimite001 extends TronBaseTest { private ManagedChannel channelRealSolidity = null; +public class RateLimite001 extends TronBaseTest { + private ManagedChannel channelRealSolidity = null; private WalletSolidityGrpc.WalletSolidityBlockingStub realBlockingStubSolidity = null; - //soliditynode is SR-2 RPC solidity port - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1); - private String realSoliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + // soliditynode is SR-2 RPC solidity port + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); + private String realSoliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); private ManagedChannel channelFull2 = null; private WalletGrpc.WalletBlockingStub blockingStubFull2 = null; - private String fullnode2 = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list") - .get(1); - - /** - * constructor. - */ + private String fullnode2 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - channelRealSolidity = ManagedChannelBuilder.forTarget(realSoliditynode) - .usePlaintext() - .build(); + channelRealSolidity = ManagedChannelBuilder.forTarget(realSoliditynode).usePlaintext().build(); realBlockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelRealSolidity); - channelFull2 = ManagedChannelBuilder.forTarget(fullnode2) - .usePlaintext() - .build(); + channelFull2 = ManagedChannelBuilder.forTarget(fullnode2).usePlaintext().build(); blockingStubFull2 = WalletGrpc.newBlockingStub(channelFull2); - - } - /** - * constructor. - */ - @Test(enabled = true, description = "Rate limit IpQpsStrategy for ListWitness interface", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Rate limit IpQpsStrategy for ListWitness interface", + groups = {"daily", "serial"}) public void test1QpsStrategyForListWitnessInterface() { Long startTimeStamp = System.currentTimeMillis(); Integer repeatTimes = 0; @@ -63,10 +55,11 @@ public void test1QpsStrategyForListWitnessInterface() { Assert.assertTrue(endTimesStap - startTimeStamp > 5000); } - /** - * constructor. - */ - @Test(enabled = true, description = "Rate limit IpQpsStrategy for ListNodes interface", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Rate limit IpQpsStrategy for ListNodes interface", + groups = {"daily", "serial"}) public void test2IpQpsStrategyForListNodesInterface() { Long startTimeStamp = System.currentTimeMillis(); Integer repeatTimes = 0; @@ -78,11 +71,13 @@ public void test2IpQpsStrategyForListNodesInterface() { Assert.assertTrue(endTimesStap - startTimeStamp > 5000); } - /** - * constructor. - */ - @Test(enabled = true, description = "Rate limit IpQpsStrategy for getBlockByNum2 " - + "interface on fullnode's solidity service", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = + "Rate limit IpQpsStrategy for getBlockByNum2 " + + "interface on fullnode's solidity service", + groups = {"daily", "serial"}) public void test3IpQpsStrategyForgetBlockByNum2ResourceInterfaceOnFullnodeSolidityService() { Long startTimeStamp = System.currentTimeMillis(); Integer repeatTimes = 0; @@ -97,11 +92,12 @@ public void test3IpQpsStrategyForgetBlockByNum2ResourceInterfaceOnFullnodeSolidi Assert.assertTrue(endTimesStap - startTimeStamp > 5000); } - /** - * constructor. - */ - @Test(enabled = true, description = "Rate limit QpsStrategy for getBlockByNum " - + "interface on fullnode's solidity service", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = + "Rate limit QpsStrategy for getBlockByNum " + "interface on fullnode's solidity service", + groups = {"daily", "serial"}) public void test4QpsStrategyForgetBlockByNumResourceInterfaceOnFullnodeSolidityService() { Long startTimeStamp = System.currentTimeMillis(); Integer repeatTimes = 0; @@ -115,11 +111,11 @@ public void test4QpsStrategyForgetBlockByNumResourceInterfaceOnFullnodeSolidityS Assert.assertTrue(endTimesStap - startTimeStamp > 5000); } - /** - * constructor. - */ - @Test(enabled = true, description = "Rate limit IpQpsStrategy for getBlockByNum2 " - + "interface on real solidity", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Rate limit IpQpsStrategy for getBlockByNum2 " + "interface on real solidity", + groups = {"daily", "serial"}) public void test5IpQpsStrategyForgetBlockByNum2ResourceInterfaceOnFullnodeSolidityService() { Long startTimeStamp = System.currentTimeMillis(); Integer repeatTimes = 0; @@ -134,11 +130,11 @@ public void test5IpQpsStrategyForgetBlockByNum2ResourceInterfaceOnFullnodeSolidi Assert.assertTrue(endTimesStap - startTimeStamp > 5000); } - /** - * constructor. - */ - @Test(enabled = true, description = "Rate limit QpsStrategy for getBlockByNum " - + "interface on real solidity", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + description = "Rate limit QpsStrategy for getBlockByNum " + "interface on real solidity", + groups = {"daily", "serial"}) public void test6QpsStrategyForgetBlockByNumResourceInterfaceOnFullnodeSolidityService() { Long startTimeStamp = System.currentTimeMillis(); Integer repeatTimes = 0; @@ -152,11 +148,7 @@ public void test6QpsStrategyForgetBlockByNumResourceInterfaceOnFullnodeSolidityS Assert.assertTrue(endTimesStap - startTimeStamp > 5000); } - - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } -} \ No newline at end of file + public void shutdown() throws InterruptedException {} +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/security/SecurityEnergyBombTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/security/SecurityEnergyBombTest.java index 1af732c4..06a96cf1 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/security/SecurityEnergyBombTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/security/SecurityEnergyBombTest.java @@ -27,8 +27,9 @@ public class SecurityEnergyBombTest extends TronBaseTest { @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(testKey); - Assert.assertTrue(PublicMethod.sendcoin(testAddress, 200_000_000_000L, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress, 200_000_000_000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/security/SecurityEnergyBomb.sol"; @@ -36,9 +37,19 @@ public void beforeClass() { HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", - maxFeeLimit, 0L, 100, null, testKey, - testAddress, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKey, + testAddress, + blockingStubFull); Assert.assertNotNull("EnergyBomb contract deployment failed", contractAddress); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContractOuterClass.SmartContract contract = @@ -46,13 +57,22 @@ public void beforeClass() { Assert.assertNotNull("Contract ABI should not be null", contract.getAbi()); } - @Test(enabled = true, + @Test( + enabled = true, description = "Infinite loop should exhaust energy and revert (OUT_OF_ENERGY)", groups = {"daily"}) public void test01InfiniteLoopExhaustsEnergy() { - String txid = PublicMethod.triggerContract(contractAddress, - "infiniteLoop()", "#", - false, 0, maxFeeLimit, testAddress, testKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + "infiniteLoop()", + "#", + false, + 0, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -63,46 +83,74 @@ public void test01InfiniteLoopExhaustsEnergy() { // Should be OUT_OF_ENERGY or OUT_OF_TIME Assert.assertTrue( result == Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY - || result == Protocol.Transaction.Result.contractResult.OUT_OF_TIME); + || result == Protocol.Transaction.Result.contractResult.OUT_OF_TIME); logger.info("Infinite loop correctly stopped by energy/time limit"); logger.info("Energy used: " + info.get().getReceipt().getEnergyUsageTotal()); } - @Test(enabled = true, + @Test( + enabled = true, description = "Bounded loop with small iteration count should succeed", groups = {"daily"}) public void test02SmallBoundedLoopSucceeds() { - String txid = PublicMethod.triggerContract(contractAddress, - "boundedLoop(uint256)", "10", - false, 0, maxFeeLimit, testAddress, testKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + "boundedLoop(uint256)", + "10", + false, + 0, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, - info.get().getReceipt().getResult()); - logger.info("Small bounded loop succeeded, energy used: " - + info.get().getReceipt().getEnergyUsageTotal()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.get().getReceipt().getResult()); + logger.info( + "Small bounded loop succeeded, energy used: " + + info.get().getReceipt().getEnergyUsageTotal()); // Verify counter was updated - GrpcAPI.TransactionExtention ext = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "getCounter()", "#", false, - 0, maxFeeLimit, "0", 0, testAddress, testKey, blockingStubFull); + GrpcAPI.TransactionExtention ext = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getCounter()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress, + testKey, + blockingStubFull); Assert.assertTrue(ext.getResult().getResult()); long counter = ByteArray.toLong(ext.getConstantResult(0).toByteArray()); Assert.assertEquals(10L, counter); logger.info("Counter value after 10 iterations: " + counter); } - @Test(enabled = true, + @Test( + enabled = true, description = "Large bounded loop should exhaust energy and revert", groups = {"daily"}) public void test03LargeBoundedLoopExhaustsEnergy() { // Use a very large iteration count to exhaust energy - String txid = PublicMethod.triggerContract(contractAddress, - "boundedLoop(uint256)", "999999999", - false, 0, maxFeeLimit, testAddress, testKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + "boundedLoop(uint256)", + "999999999", + false, + 0, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -112,18 +160,27 @@ public void test03LargeBoundedLoopExhaustsEnergy() { logger.info("Large loop result: " + result); Assert.assertTrue( result == Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY - || result == Protocol.Transaction.Result.contractResult.OUT_OF_TIME); + || result == Protocol.Transaction.Result.contractResult.OUT_OF_TIME); logger.info("Large bounded loop correctly stopped by energy/time limit"); } - @Test(enabled = true, + @Test( + enabled = true, description = "Storage expansion bomb should exhaust energy with large count", groups = {"daily"}) public void test04StorageExpansionBomb() { // Small storage expansion should succeed - String txid = PublicMethod.triggerContract(contractAddress, - "storageExpansion(uint256)", "5", - false, 0, maxFeeLimit, testAddress, testKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + "storageExpansion(uint256)", + "5", + false, + 0, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -132,74 +189,138 @@ public void test04StorageExpansionBomb() { logger.info("Storage expansion (5 items) energy: " + energySmall); // Large storage expansion should exhaust energy - txid = PublicMethod.triggerContract(contractAddress, - "storageExpansion(uint256)", "999999999", - false, 0, maxFeeLimit, testAddress, testKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "storageExpansion(uint256)", + "999999999", + false, + 0, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(1, info.get().getResultValue()); logger.info("Large storage expansion correctly stopped by energy limit"); } - @Test(enabled = true, + @Test( + enabled = true, description = "Expensive O(n^2) computation: small succeeds, large triggers timeout", groups = {"daily"}) public void test05ExpensiveComputation() { // Small input should succeed via constant call - GrpcAPI.TransactionExtention extSmall = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "expensiveComputation(uint256)", "3", false, - 0, maxFeeLimit, "0", 0, testAddress, testKey, blockingStubFull); + GrpcAPI.TransactionExtention extSmall = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "expensiveComputation(uint256)", + "3", + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress, + testKey, + blockingStubFull); Assert.assertTrue("Small computation (n=3) should succeed", extSmall.getResult().getResult()); logger.info("Small computation (n=3) succeeded"); // Medium input should also succeed - GrpcAPI.TransactionExtention extMed = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "expensiveComputation(uint256)", "50", false, - 0, maxFeeLimit, "0", 0, testAddress, testKey, blockingStubFull); + GrpcAPI.TransactionExtention extMed = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "expensiveComputation(uint256)", + "50", + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress, + testKey, + blockingStubFull); Assert.assertTrue("Medium computation (n=50) should succeed", extMed.getResult().getResult()); logger.info("Medium computation (n=50) succeeded"); // Very large input should fail via constant call (CPU timeout) - GrpcAPI.TransactionExtention extLarge = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "expensiveComputation(uint256)", "99999", false, - 0, maxFeeLimit, "0", 0, testAddress, testKey, blockingStubFull); + GrpcAPI.TransactionExtention extLarge = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "expensiveComputation(uint256)", + "99999", + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress, + testKey, + blockingStubFull); // Either the result is false, or the message contains timeout/energy info boolean largeFailed = !extLarge.getResult().getResult(); String msg = ByteArray.toStr(extLarge.getResult().getMessage().toByteArray()); - logger.info("Large computation (n=99999) result: {}, message: {}", - extLarge.getResult().getResult(), msg); - Assert.assertTrue("Very large O(n^2) computation should fail. msg=" + msg, - largeFailed || msg.contains("CPU") || msg.contains("timeout") - || msg.contains("energy") || msg.contains("REVERT") || msg.contains("OUT_OF")); + logger.info( + "Large computation (n=99999) result: {}, message: {}", + extLarge.getResult().getResult(), + msg); + Assert.assertTrue( + "Very large O(n^2) computation should fail. msg=" + msg, + largeFailed + || msg.contains("CPU") + || msg.contains("timeout") + || msg.contains("energy") + || msg.contains("REVERT") + || msg.contains("OUT_OF")); } - @Test(enabled = true, + @Test( + enabled = true, description = "Infinite loop via constant call should return CPU timeout", groups = {"daily"}) public void test06InfiniteLoopConstantCall() { - GrpcAPI.TransactionExtention ext = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "infiniteLoop()", "#", false, - 0, maxFeeLimit, "0", 0, testAddress, testKey, blockingStubFull); + GrpcAPI.TransactionExtention ext = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "infiniteLoop()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress, + testKey, + blockingStubFull); String message = ByteArray.toStr(ext.getResult().getMessage().toByteArray()); logger.info("Infinite loop constant call message: " + message); - Assert.assertTrue(message.contains("CPU timeout") || message.contains("energy") - || !ext.getResult().getResult()); + Assert.assertTrue( + message.contains("CPU timeout") + || message.contains("energy") + || !ext.getResult().getResult()); logger.info("Infinite loop correctly stopped in constant call"); } - @Test(enabled = true, + @Test( + enabled = true, description = "Energy fee is charged even when transaction reverts due to energy exhaustion", groups = {"daily"}) public void test07EnergyFeeChargedOnRevert() { long balanceBefore = PublicMethod.queryAccount(testAddress, blockingStubFull).getBalance(); - String txid = PublicMethod.triggerContract(contractAddress, - "infiniteLoop()", "#", - false, 0, maxFeeLimit, testAddress, testKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + "infiniteLoop()", + "#", + false, + 0, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/security/SecurityOverflowTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/security/SecurityOverflowTest.java index 7522e180..d1211fd1 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/security/SecurityOverflowTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/security/SecurityOverflowTest.java @@ -2,13 +2,11 @@ import java.math.BigInteger; import java.util.HashMap; -import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI; -import org.tron.protos.Protocol; import org.tron.protos.contract.SmartContractOuterClass; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.PublicMethod; @@ -18,8 +16,8 @@ /** * Integer overflow/underflow behavior tests for TVM. * - *

Tests verify both checked (default 0.8+) and unchecked arithmetic behavior. - * Unchecked blocks wrap without reverting. + *

Tests verify both checked (default 0.8+) and unchecked arithmetic behavior. Unchecked blocks + * wrap without reverting. */ @Slf4j public class SecurityOverflowTest extends TronBaseTest { @@ -32,8 +30,9 @@ public class SecurityOverflowTest extends TronBaseTest { @BeforeClass(enabled = true) public void beforeClass() { - testAccount = TestAccountFactory.funded(100_000_000_000L, - foundationAddress, foundationKey, blockingStubFull); + testAccount = + TestAccountFactory.funded( + 100_000_000_000L, foundationAddress, foundationKey, blockingStubFull); testAddress = testAccount.address; testKey = testAccount.privateKey; @@ -42,9 +41,19 @@ public void beforeClass() { HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", - maxFeeLimit, 0L, 100, null, testKey, - testAddress, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKey, + testAddress, + blockingStubFull); Assert.assertNotNull("OverflowTest contract deployment failed", contractAddress); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContractOuterClass.SmartContract contract = @@ -52,15 +61,25 @@ public void beforeClass() { Assert.assertNotNull("Contract ABI should not be null", contract.getAbi()); } - @Test(enabled = true, + @Test( + enabled = true, description = "uint256 addition overflow: checked arithmetic behavior", groups = {"daily"}) public void test01AddOverflowChecked() { // addOverflow() does: uint256.max + 1 — should revert or wrap depending on TVM version - GrpcAPI.TransactionExtention ext = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "addOverflow()", "#", false, - 0, maxFeeLimit, "0", 0, testAddress, testKey, blockingStubFull); + GrpcAPI.TransactionExtention ext = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "addOverflow()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress, + testKey, + blockingStubFull); boolean success = ext.getResult().getResult(); logger.info("addOverflow constant call success: {}", success); if (!success) { @@ -69,48 +88,75 @@ public void test01AddOverflowChecked() { } // Either behavior is valid — test just documents what this TVM version does Assert.assertNotNull("Should get a response from TVM", ext.getResult()); - logger.info("addOverflow: TVM {} overflow", - success ? "wraps on" : "reverts on"); + logger.info("addOverflow: TVM {} overflow", success ? "wraps on" : "reverts on"); } - @Test(enabled = true, + @Test( + enabled = true, description = "uint256 subtraction underflow: checked arithmetic behavior", groups = {"daily"}) public void test02SubUnderflowChecked() { - GrpcAPI.TransactionExtention ext = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "subUnderflow()", "#", false, - 0, maxFeeLimit, "0", 0, testAddress, testKey, blockingStubFull); + GrpcAPI.TransactionExtention ext = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "subUnderflow()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress, + testKey, + blockingStubFull); boolean success = ext.getResult().getResult(); logger.info("subUnderflow constant call success: {}", success); Assert.assertNotNull(ext.getResult()); - logger.info("subUnderflow: TVM {} underflow", - success ? "wraps on" : "reverts on"); + logger.info("subUnderflow: TVM {} underflow", success ? "wraps on" : "reverts on"); } - @Test(enabled = true, + @Test( + enabled = true, description = "uint256 multiplication overflow: checked arithmetic behavior", groups = {"daily"}) public void test03MulOverflowChecked() { - GrpcAPI.TransactionExtention ext = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "mulOverflow()", "#", false, - 0, maxFeeLimit, "0", 0, testAddress, testKey, blockingStubFull); + GrpcAPI.TransactionExtention ext = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "mulOverflow()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress, + testKey, + blockingStubFull); boolean success = ext.getResult().getResult(); logger.info("mulOverflow constant call success: {}", success); Assert.assertNotNull(ext.getResult()); - logger.info("mulOverflow: TVM {} overflow", - success ? "wraps on" : "reverts on"); + logger.info("mulOverflow: TVM {} overflow", success ? "wraps on" : "reverts on"); } - @Test(enabled = true, + @Test( + enabled = true, description = "unchecked addition overflow wraps to 0", groups = {"daily"}) public void test04UncheckedAddOverflow() { - GrpcAPI.TransactionExtention ext = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "uncheckedAddOverflow()", "#", false, - 0, maxFeeLimit, "0", 0, testAddress, testKey, blockingStubFull); + GrpcAPI.TransactionExtention ext = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "uncheckedAddOverflow()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress, + testKey, + blockingStubFull); Assert.assertTrue("Unchecked add should succeed", ext.getResult().getResult()); byte[] resultBytes = ext.getConstantResult(0).toByteArray(); // ABI-encoded uint256 is 32 bytes, take the last 32 @@ -119,14 +165,24 @@ public void test04UncheckedAddOverflow() { logger.info("Unchecked add overflow wraps to: " + result); } - @Test(enabled = true, + @Test( + enabled = true, description = "unchecked subtraction underflow wraps to max uint256", groups = {"daily"}) public void test05UncheckedSubUnderflow() { - GrpcAPI.TransactionExtention ext = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "uncheckedSubUnderflow()", "#", false, - 0, maxFeeLimit, "0", 0, testAddress, testKey, blockingStubFull); + GrpcAPI.TransactionExtention ext = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "uncheckedSubUnderflow()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress, + testKey, + blockingStubFull); Assert.assertTrue("Unchecked sub should succeed", ext.getResult().getResult()); byte[] resultBytes = ext.getConstantResult(0).toByteArray(); BigInteger result = extractUint256(resultBytes); @@ -135,14 +191,24 @@ public void test05UncheckedSubUnderflow() { logger.info("Unchecked sub underflow wraps to max uint256"); } - @Test(enabled = true, + @Test( + enabled = true, description = "unchecked multiplication overflow wraps", groups = {"daily"}) public void test06UncheckedMulOverflow() { - GrpcAPI.TransactionExtention ext = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "uncheckedMulOverflow()", "#", false, - 0, maxFeeLimit, "0", 0, testAddress, testKey, blockingStubFull); + GrpcAPI.TransactionExtention ext = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "uncheckedMulOverflow()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress, + testKey, + blockingStubFull); Assert.assertTrue("Unchecked mul should succeed", ext.getResult().getResult()); byte[] resultBytes = ext.getConstantResult(0).toByteArray(); BigInteger result = extractUint256(resultBytes); @@ -150,39 +216,57 @@ public void test06UncheckedMulOverflow() { Assert.assertNotNull(result); } - @Test(enabled = true, description = "Safe add with normal values succeeds", + @Test( + enabled = true, + description = "Safe add with normal values succeeds", groups = {"daily"}) public void test07SafeAddNormal() { String argsStr = "100,200"; - GrpcAPI.TransactionExtention ext = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "safeAdd(uint256,uint256)", argsStr, false, - 0, maxFeeLimit, "0", 0, testAddress, testKey, blockingStubFull); + GrpcAPI.TransactionExtention ext = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "safeAdd(uint256,uint256)", + argsStr, + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress, + testKey, + blockingStubFull); Assert.assertTrue(ext.getResult().getResult()); BigInteger result = extractUint256(ext.getConstantResult(0).toByteArray()); Assert.assertEquals(BigInteger.valueOf(300L), result); logger.info("Safe add 100 + 200 = " + result); } - @Test(enabled = true, + @Test( + enabled = true, description = "safeSub(100, 200): checked arithmetic behavior", groups = {"daily"}) public void test08SafeSubChecked() { - GrpcAPI.TransactionExtention ext = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "safeSub(uint256,uint256)", "100,200", false, - 0, maxFeeLimit, "0", 0, testAddress, testKey, blockingStubFull); + GrpcAPI.TransactionExtention ext = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "safeSub(uint256,uint256)", + "100,200", + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress, + testKey, + blockingStubFull); boolean success = ext.getResult().getResult(); logger.info("safeSub(100,200) success: {}", success); // Either reverts or wraps — both are valid TVM behaviors Assert.assertNotNull(ext.getResult()); - logger.info("safeSub(100,200): TVM {} underflow", - success ? "wraps on" : "reverts on"); + logger.info("safeSub(100,200): TVM {} underflow", success ? "wraps on" : "reverts on"); } - /** - * Extract a uint256 from ABI-encoded bytes (last 32 bytes). - */ + /** Extract a uint256 from ABI-encoded bytes (last 32 bytes). */ private static BigInteger extractUint256(byte[] data) { if (data.length <= 32) { return new BigInteger(1, data); diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/security/SecurityPermissionTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/security/SecurityPermissionTest.java index 16670f9b..87f6fd16 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/security/SecurityPermissionTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/security/SecurityPermissionTest.java @@ -8,7 +8,6 @@ import org.testng.annotations.Test; import org.tron.api.GrpcAPI; import org.tron.protos.Protocol; -import org.tron.protos.contract.SmartContractOuterClass; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; @@ -34,10 +33,12 @@ public class SecurityPermissionTest extends TronBaseTest { public void beforeClass() { PublicMethod.printAddress(testKey); PublicMethod.printAddress(nonOwnerKey); - Assert.assertTrue(PublicMethod.sendcoin(testAddress, 200_000_000_000L, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(nonOwnerAddress, 200_000_000_000L, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress, 200_000_000_000L, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + nonOwnerAddress, 200_000_000_000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/security/SecurityPermission.sol"; @@ -47,9 +48,19 @@ public void beforeClass() { HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - permissionAddress = PublicMethod.deployContract(contractName, abi, code, "", - maxFeeLimit, 0L, 100, null, testKey, - testAddress, blockingStubFull); + permissionAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKey, + testAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(PublicMethod.getContract(permissionAddress, blockingStubFull).getAbi()); @@ -59,10 +70,21 @@ public void beforeClass() { code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); String permBase58 = Base58.encode58Check(permissionAddress); - String callerTxid = PublicMethod.deployContractWithConstantParame(contractName, abi, code, - "constructor(address)", "\"" + permBase58 + "\"", "", - maxFeeLimit, 0L, 100, null, testKey, - testAddress, blockingStubFull); + String callerTxid = + PublicMethod.deployContractWithConstantParame( + contractName, + abi, + code, + "constructor(address)", + "\"" + permBase58 + "\"", + "", + maxFeeLimit, + 0L, + 100, + null, + testKey, + testAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional callerInfo = PublicMethod.getTransactionInfoById(callerTxid, blockingStubFull); @@ -70,54 +92,90 @@ public void beforeClass() { Assert.assertNotNull(PublicMethod.getContract(callerAddress, blockingStubFull).getAbi()); } - @Test(enabled = true, + @Test( + enabled = true, description = "Owner can call onlyOwner function", groups = {"daily"}) public void test01OwnerCanCallProtected() { - String txid = PublicMethod.triggerContract(permissionAddress, - "setProtectedValue(uint256)", "42", - false, 0, maxFeeLimit, testAddress, testKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + permissionAddress, + "setProtectedValue(uint256)", + "42", + false, + 0, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.get().getReceipt().getResult()); // Verify value was set - GrpcAPI.TransactionExtention ext = PublicMethod - .triggerConstantContractForExtention(permissionAddress, - "protectedValue()", "#", false, - 0, maxFeeLimit, "0", 0, testAddress, testKey, blockingStubFull); + GrpcAPI.TransactionExtention ext = + PublicMethod.triggerConstantContractForExtention( + permissionAddress, + "protectedValue()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress, + testKey, + blockingStubFull); Assert.assertTrue(ext.getResult().getResult()); long value = ByteArray.toLong(ext.getConstantResult(0).toByteArray()); Assert.assertEquals(42L, value); logger.info("Owner set protected value to: " + value); } - @Test(enabled = true, + @Test( + enabled = true, description = "Non-owner cannot call onlyOwner function - should revert", groups = {"daily"}) public void test02NonOwnerCannotCallProtected() { - String txid = PublicMethod.triggerContract(permissionAddress, - "setProtectedValue(uint256)", "999", - false, 0, maxFeeLimit, nonOwnerAddress, nonOwnerKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + permissionAddress, + "setProtectedValue(uint256)", + "999", + false, + 0, + maxFeeLimit, + nonOwnerAddress, + nonOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(1, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.REVERT, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.REVERT, info.get().getReceipt().getResult()); logger.info("Non-owner correctly blocked from calling onlyOwner function"); } - @Test(enabled = true, + @Test( + enabled = true, description = "Anyone can call public function", groups = {"daily"}) public void test03AnyoneCanCallPublic() { - String txid = PublicMethod.triggerContract(permissionAddress, - "setPublicValue(uint256)", "123", - false, 0, maxFeeLimit, nonOwnerAddress, nonOwnerKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + permissionAddress, + "setPublicValue(uint256)", + "123", + false, + 0, + maxFeeLimit, + nonOwnerAddress, + nonOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -125,67 +183,102 @@ public void test03AnyoneCanCallPublic() { logger.info("Non-owner can call public function"); } - @Test(enabled = true, + @Test( + enabled = true, description = "tx.origin vs msg.sender: msg.sender is contract when called through proxy", groups = {"daily"}) public void test04TxOriginVsMsgSender() { // When calling through PermissionCaller, msg.sender should be the caller contract address // but tx.origin should be the EOA - GrpcAPI.TransactionExtention extSender = PublicMethod - .triggerConstantContractForExtention(callerAddress, - "callGetMsgSender()", "#", false, - 0, maxFeeLimit, "0", 0, testAddress, testKey, blockingStubFull); + GrpcAPI.TransactionExtention extSender = + PublicMethod.triggerConstantContractForExtention( + callerAddress, + "callGetMsgSender()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress, + testKey, + blockingStubFull); Assert.assertTrue(extSender.getResult().getResult()); - String msgSenderHex = "41" + ByteArray.toHexString( - extSender.getConstantResult(0).toByteArray()).substring(24); + String msgSenderHex = + "41" + ByteArray.toHexString(extSender.getConstantResult(0).toByteArray()).substring(24); byte[] msgSenderBytes = ByteArray.fromHexString(msgSenderHex); logger.info("msg.sender when called through proxy: " + Base58.encode58Check(msgSenderBytes)); - GrpcAPI.TransactionExtention extOrigin = PublicMethod - .triggerConstantContractForExtention(callerAddress, - "callGetTxOrigin()", "#", false, - 0, maxFeeLimit, "0", 0, testAddress, testKey, blockingStubFull); + GrpcAPI.TransactionExtention extOrigin = + PublicMethod.triggerConstantContractForExtention( + callerAddress, + "callGetTxOrigin()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress, + testKey, + blockingStubFull); Assert.assertTrue(extOrigin.getResult().getResult()); - String txOriginHex = "41" + ByteArray.toHexString( - extOrigin.getConstantResult(0).toByteArray()).substring(24); + String txOriginHex = + "41" + ByteArray.toHexString(extOrigin.getConstantResult(0).toByteArray()).substring(24); byte[] txOriginBytes = ByteArray.fromHexString(txOriginHex); logger.info("tx.origin when called through proxy: " + Base58.encode58Check(txOriginBytes)); // msg.sender should be the caller contract, NOT the EOA - Assert.assertEquals(Base58.encode58Check(callerAddress), - Base58.encode58Check(msgSenderBytes)); + Assert.assertEquals(Base58.encode58Check(callerAddress), Base58.encode58Check(msgSenderBytes)); // tx.origin should be the EOA (testAddress) - Assert.assertEquals(Base58.encode58Check(testAddress), - Base58.encode58Check(txOriginBytes)); + Assert.assertEquals(Base58.encode58Check(testAddress), Base58.encode58Check(txOriginBytes)); logger.info("tx.origin vs msg.sender difference verified correctly"); } - @Test(enabled = true, + @Test( + enabled = true, description = "Proxy contract cannot call onlyOwner function (msg.sender mismatch)", groups = {"daily"}) public void test05ProxyCannotBypassOwnerCheck() { // The caller contract tries to call setProtectedValue on PermissionTest. // Even though tx.origin is the owner (testAddress), msg.sender is the caller contract. // Since the modifier checks msg.sender, this should fail. - String txid = PublicMethod.triggerContract(callerAddress, - "trySetProtectedValue(uint256)", "888", - false, 0, maxFeeLimit, testAddress, testKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + callerAddress, + "trySetProtectedValue(uint256)", + "888", + false, + 0, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(1, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.REVERT, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.REVERT, info.get().getReceipt().getResult()); logger.info("Proxy contract correctly blocked - msg.sender is contract, not owner"); } - @Test(enabled = true, + @Test( + enabled = true, description = "Proxy can call public function through delegation", groups = {"daily"}) public void test06ProxyCanCallPublicFunction() { - String txid = PublicMethod.triggerContract(callerAddress, - "trySetPublicValue(uint256)", "777", - false, 0, maxFeeLimit, testAddress, testKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + callerAddress, + "trySetPublicValue(uint256)", + "777", + false, + 0, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -193,72 +286,130 @@ public void test06ProxyCanCallPublicFunction() { logger.info("Proxy can call public function through delegation"); } - @Test(enabled = true, + @Test( + enabled = true, description = "Admin role can call onlyAdmin function", groups = {"daily"}) public void test07AdminRoleAccess() { // Add nonOwner as admin String argsStr = "\"" + Base58.encode58Check(nonOwnerAddress) + "\""; - String txid = PublicMethod.triggerContract(permissionAddress, - "addAdmin(address)", argsStr, - false, 0, maxFeeLimit, testAddress, testKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + permissionAddress, + "addAdmin(address)", + argsStr, + false, + 0, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, info.get().getResultValue()); // Now nonOwner should be able to call setAdminValue - txid = PublicMethod.triggerContract(permissionAddress, - "setAdminValue(uint256)", "555", - false, 0, maxFeeLimit, nonOwnerAddress, nonOwnerKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + permissionAddress, + "setAdminValue(uint256)", + "555", + false, + 0, + maxFeeLimit, + nonOwnerAddress, + nonOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, info.get().getResultValue()); logger.info("Admin can call admin-restricted function"); // Remove admin - txid = PublicMethod.triggerContract(permissionAddress, - "removeAdmin(address)", argsStr, - false, 0, maxFeeLimit, testAddress, testKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + permissionAddress, + "removeAdmin(address)", + argsStr, + false, + 0, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); // Now nonOwner should NOT be able to call setAdminValue - txid = PublicMethod.triggerContract(permissionAddress, - "setAdminValue(uint256)", "666", - false, 0, maxFeeLimit, nonOwnerAddress, nonOwnerKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + permissionAddress, + "setAdminValue(uint256)", + "666", + false, + 0, + maxFeeLimit, + nonOwnerAddress, + nonOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(1, info.get().getResultValue()); logger.info("Removed admin correctly blocked from admin function"); } - @Test(enabled = true, + @Test( + enabled = true, description = "Ownership transfer changes who can call protected functions", groups = {"daily"}) public void test08OwnershipTransfer() { // Transfer ownership to nonOwnerAddress String argsStr = "\"" + Base58.encode58Check(nonOwnerAddress) + "\""; - String txid = PublicMethod.triggerContract(permissionAddress, - "transferOwnership(address)", argsStr, - false, 0, maxFeeLimit, testAddress, testKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + permissionAddress, + "transferOwnership(address)", + argsStr, + false, + 0, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, info.get().getResultValue()); // Now nonOwner should be the owner and can call protected function - txid = PublicMethod.triggerContract(permissionAddress, - "setProtectedValue(uint256)", "1000", - false, 0, maxFeeLimit, nonOwnerAddress, nonOwnerKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + permissionAddress, + "setProtectedValue(uint256)", + "1000", + false, + 0, + maxFeeLimit, + nonOwnerAddress, + nonOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, info.get().getResultValue()); logger.info("New owner can call protected function after ownership transfer"); // Original owner should now be blocked - txid = PublicMethod.triggerContract(permissionAddress, - "setProtectedValue(uint256)", "2000", - false, 0, maxFeeLimit, testAddress, testKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + permissionAddress, + "setProtectedValue(uint256)", + "2000", + false, + 0, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(1, info.get().getResultValue()); diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/security/SecurityReentrancyTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/security/SecurityReentrancyTest.java index f22a0ddd..16303ac5 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/security/SecurityReentrancyTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/security/SecurityReentrancyTest.java @@ -28,8 +28,9 @@ public class SecurityReentrancyTest extends TronBaseTest { @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(testKey); - Assert.assertTrue(PublicMethod.sendcoin(testAddress, 500_000_000_000L, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress, 500_000_000_000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); // Deploy Victim contract @@ -38,9 +39,19 @@ public void beforeClass() { HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - victimAddress = PublicMethod.deployContract(contractName, abi, code, "", - maxFeeLimit, 0L, 100, null, testKey, - testAddress, blockingStubFull); + victimAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKey, + testAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContractOuterClass.SmartContract victimContract = PublicMethod.getContract(victimAddress, blockingStubFull); @@ -52,10 +63,21 @@ public void beforeClass() { code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); String victimBase58 = Base58.encode58Check(victimAddress); - String attackerTxid = PublicMethod.deployContractWithConstantParame(contractName, abi, code, - "constructor(address)", "\"" + victimBase58 + "\"", "", - maxFeeLimit, 0L, 100, null, testKey, - testAddress, blockingStubFull); + String attackerTxid = + PublicMethod.deployContractWithConstantParame( + contractName, + abi, + code, + "constructor(address)", + "\"" + victimBase58 + "\"", + "", + maxFeeLimit, + 0L, + 100, + null, + testKey, + testAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional attackerInfo = PublicMethod.getTransactionInfoById(attackerTxid, blockingStubFull); @@ -65,11 +87,23 @@ public void beforeClass() { Assert.assertNotNull(attackerContract.getAbi()); } - @Test(enabled = true, description = "Deposit TRX into victim contract", groups = {"daily"}) + @Test( + enabled = true, + description = "Deposit TRX into victim contract", + groups = {"daily"}) public void test01DepositToVictim() { // Deposit 100 TRX from test account - String txid = PublicMethod.triggerContract(victimAddress, "deposit()", "#", - false, 100_000_000L, maxFeeLimit, testAddress, testKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + victimAddress, + "deposit()", + "#", + false, + 100_000_000L, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -77,17 +111,37 @@ public void test01DepositToVictim() { logger.info("Deposit to victim successful, txid: " + txid); } - @Test(enabled = true, description = "Normal withdraw from victim should succeed", + @Test( + enabled = true, + description = "Normal withdraw from victim should succeed", groups = {"daily"}) public void test02NormalWithdraw() { // First deposit - String txid = PublicMethod.triggerContract(victimAddress, "deposit()", "#", - false, 50_000_000L, maxFeeLimit, testAddress, testKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + victimAddress, + "deposit()", + "#", + false, + 50_000_000L, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); // Then withdraw normally - txid = PublicMethod.triggerContract(victimAddress, "withdraw()", "#", - false, 0, maxFeeLimit, testAddress, testKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + victimAddress, + "withdraw()", + "#", + false, + 0, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -95,26 +149,45 @@ public void test02NormalWithdraw() { logger.info("Normal withdraw successful"); } - @Test(enabled = true, + @Test( + enabled = true, description = "Reentrancy attack should be mitigated by TRON energy limits", groups = {"daily"}) public void test03ReentrancyAttack() { // Deposit 200 TRX into victim from test account (to give victim a balance) - String txid = PublicMethod.triggerContract(victimAddress, "deposit()", "#", - false, 200_000_000L, maxFeeLimit, testAddress, testKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + victimAddress, + "deposit()", + "#", + false, + 200_000_000L, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional depositInfo = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, depositInfo.get().getResultValue()); // Get victim balance before attack - long victimBalanceBefore = PublicMethod.queryAccount(victimAddress, blockingStubFull) - .getBalance(); + long victimBalanceBefore = + PublicMethod.queryAccount(victimAddress, blockingStubFull).getBalance(); logger.info("Victim TRX balance before attack: " + victimBalanceBefore); // Execute reentrancy attack with 10 TRX - txid = PublicMethod.triggerContract(attackerAddress, "attack()", "#", - false, 10_000_000L, maxFeeLimit, testAddress, testKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + attackerAddress, + "attack()", + "#", + false, + 10_000_000L, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional attackInfo = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -125,14 +198,15 @@ public void test03ReentrancyAttack() { // The attack may either revert (due to energy limits stopping reentrancy) // or succeed partially. In either case the victim should not lose all funds. - long victimBalanceAfter = PublicMethod.queryAccount(victimAddress, blockingStubFull) - .getBalance(); + long victimBalanceAfter = + PublicMethod.queryAccount(victimAddress, blockingStubFull).getBalance(); logger.info("Victim TRX balance after attack: " + victimBalanceAfter); if (resultValue == 1) { // Attack reverted - energy limit or reentrancy guard stopped it logger.info("Reentrancy attack was stopped by VM (REVERT)"); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.REVERT, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.REVERT, attackInfo.get().getReceipt().getResult()); } else { // Even if the transaction succeeded, verify victim is not drained @@ -144,17 +218,37 @@ public void test03ReentrancyAttack() { logger.info("Energy used: " + attackInfo.get().getReceipt().getEnergyUsageTotal()); } - @Test(enabled = true, description = "Safe withdraw with checks-effects-interactions pattern", + @Test( + enabled = true, + description = "Safe withdraw with checks-effects-interactions pattern", groups = {"daily"}) public void test04SafeWithdraw() { // Deposit - String txid = PublicMethod.triggerContract(victimAddress, "deposit()", "#", - false, 30_000_000L, maxFeeLimit, testAddress, testKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + victimAddress, + "deposit()", + "#", + false, + 30_000_000L, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); // Safe withdraw - txid = PublicMethod.triggerContract(victimAddress, "safeWithdraw()", "#", - false, 0, maxFeeLimit, testAddress, testKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + victimAddress, + "safeWithdraw()", + "#", + false, + 0, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/security/SecuritySelfdestructTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/security/SecuritySelfdestructTest.java index 7c0d9f60..b26c94a4 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/security/SecuritySelfdestructTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/security/SecuritySelfdestructTest.java @@ -18,16 +18,17 @@ /** * Tests for selfdestruct (TIP-481) behavior. * - *

TIP-481 ({@code getAllowTvmSelfdestructRestriction}) is a chain governance proposal - * (proposal #76) that restricts selfdestruct behavior. When active: + *

TIP-481 ({@code getAllowTvmSelfdestructRestriction}) is a chain governance proposal (proposal + * #76) that restricts selfdestruct behavior. When active: + * *

    - *
  • selfdestruct only transfers TRX to the target, does NOT delete code/storage
  • - *
  • Contract remains callable after selfdestruct
  • - *
  • This aligns with Ethereum's EIP-6780 (Cancun hard fork)
  • + *
  • selfdestruct only transfers TRX to the target, does NOT delete code/storage + *
  • Contract remains callable after selfdestruct + *
  • This aligns with Ethereum's EIP-6780 (Cancun hard fork) *
* - *

This proposal is enabled via on-chain transaction (not config file), typically - * opened in {@code @BeforeSuite} by the test framework (see JsonRpcBase). + *

This proposal is enabled via on-chain transaction (not config file), typically opened in + * {@code @BeforeSuite} by the test framework (see JsonRpcBase). */ @Slf4j public class SecuritySelfdestructTest extends TronBaseTest { @@ -47,8 +48,9 @@ public void beforeClass() { logger.info("allowTvmSelfdestructRestriction active: " + restrictionActive); PublicMethod.printAddress(testKey); - Assert.assertTrue(PublicMethod.sendcoin(testAddress, 500_000_000_000L, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress, 500_000_000_000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/security/SecuritySelfdestruct.sol"; @@ -58,9 +60,19 @@ public void beforeClass() { HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - targetAddress = PublicMethod.deployContract(contractName, abi, code, "", - maxFeeLimit, 0L, 100, null, testKey, - testAddress, blockingStubFull); + targetAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKey, + testAddress, + blockingStubFull); Assert.assertNotNull("SelfdestructTarget deployment failed", targetAddress); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -69,9 +81,19 @@ public void beforeClass() { retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - selfdestructAddress = PublicMethod.deployContract(contractName, abi, code, "", - maxFeeLimit, 500_000_000L, 100, null, testKey, - testAddress, blockingStubFull); + selfdestructAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 500_000_000L, + 100, + null, + testKey, + testAddress, + blockingStubFull); Assert.assertNotNull("SelfdestructTest deployment failed", selfdestructAddress); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -80,37 +102,56 @@ public void beforeClass() { retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - factoryAddress = PublicMethod.deployContract(contractName, abi, code, "", - maxFeeLimit, 0L, 100, null, testKey, - testAddress, blockingStubFull); + factoryAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKey, + testAddress, + blockingStubFull); Assert.assertNotNull("SelfdestructFactory deployment failed", factoryAddress); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, + @Test( + enabled = true, description = "Selfdestruct transfers TRX to target", groups = {"daily"}) public void test01SelfdestructTransfersTrx() { - long targetBalanceBefore = PublicMethod.queryAccount(targetAddress, blockingStubFull) - .getBalance(); - long contractBalance = PublicMethod.queryAccount(selfdestructAddress, blockingStubFull) - .getBalance(); + long targetBalanceBefore = + PublicMethod.queryAccount(targetAddress, blockingStubFull).getBalance(); + long contractBalance = + PublicMethod.queryAccount(selfdestructAddress, blockingStubFull).getBalance(); logger.info("Target before: {}, Contract before: {}", targetBalanceBefore, contractBalance); Assert.assertTrue("Contract should have TRX", contractBalance > 0); // Call selfdestruct String argsStr = "\"" + Base58.encode58Check(targetAddress) + "\""; - String txid = PublicMethod.triggerContract(selfdestructAddress, - "destroyAndSend(address)", argsStr, - false, 0, maxFeeLimit, testAddress, testKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + selfdestructAddress, + "destroyAndSend(address)", + argsStr, + false, + 0, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, info.get().getResultValue()); // TRX should be transferred regardless of restriction mode - long targetBalanceAfter = PublicMethod.queryAccount(targetAddress, blockingStubFull) - .getBalance(); + long targetBalanceAfter = + PublicMethod.queryAccount(targetAddress, blockingStubFull).getBalance(); logger.info("Target after: {}", targetBalanceAfter); if (restrictionActive) { @@ -121,7 +162,8 @@ public void test01SelfdestructTransfersTrx() { } } - @Test(enabled = true, + @Test( + enabled = true, description = "Post-selfdestruct state depends on TIP-481 restriction", groups = {"daily"}) public void test02PostSelfdestructState() { @@ -141,7 +183,8 @@ public void test02PostSelfdestructState() { } } - @Test(enabled = true, + @Test( + enabled = true, description = "Non-owner cannot call selfdestruct — onlyOwner modifier", groups = {"daily"}) public void test03NonOwnerCannotSelfdestruct() { @@ -150,43 +193,70 @@ public void test03NonOwnerCannotSelfdestruct() { HashMap retMap = PublicMethod.getBycodeAbi(filePath, "SelfdestructTest"); String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - byte[] newContract = PublicMethod.deployContract("SelfdestructTest", abi, code, "", - maxFeeLimit, 100_000_000L, 100, null, testKey, - testAddress, blockingStubFull); + byte[] newContract = + PublicMethod.deployContract( + "SelfdestructTest", + abi, + code, + "", + maxFeeLimit, + 100_000_000L, + 100, + null, + testKey, + testAddress, + blockingStubFull); Assert.assertNotNull("Fresh contract deployment failed", newContract); PublicMethod.waitProduceNextBlock(blockingStubFull); // Call from non-owner should revert (onlyOwner modifier) String argsStr = "\"" + Base58.encode58Check(targetAddress) + "\""; - String txid = PublicMethod.triggerContract(newContract, - "destroyAndSend(address)", argsStr, - false, 0, maxFeeLimit, foundationAddress, foundationKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + newContract, + "destroyAndSend(address)", + argsStr, + false, + 0, + maxFeeLimit, + foundationAddress, + foundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(1, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.REVERT, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.REVERT, info.get().getReceipt().getResult()); logger.info("Non-owner selfdestruct correctly reverted"); } - @Test(enabled = true, + @Test( + enabled = true, description = "Factory creates child contract with TRX", groups = {"daily"}) public void test04FactoryCreateChild() { - String txid = PublicMethod.triggerContract(factoryAddress, - "createAndFund()", "#", - false, 100_000_000L, maxFeeLimit, testAddress, testKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + factoryAddress, + "createAndFund()", + "#", + false, + 100_000_000L, + maxFeeLimit, + testAddress, + testKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, info.get().getResultValue()); // Extract child address from internal transactions - Assert.assertTrue("Should have internal transactions", - info.get().getInternalTransactionsCount() > 0); - byte[] childAddress = info.get().getInternalTransactions(0) - .getTransferToAddress().toByteArray(); + Assert.assertTrue( + "Should have internal transactions", info.get().getInternalTransactionsCount() > 0); + byte[] childAddress = + info.get().getInternalTransactions(0).getTransferToAddress().toByteArray(); logger.info("Child contract: " + Base58.encode58Check(childAddress)); long childBalance = PublicMethod.queryAccount(childAddress, blockingStubFull).getBalance(); diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/separateExecution/FreezeWeightDeflationV2Test.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/separateExecution/FreezeWeightDeflationV2Test.java index 2fedf646..14d826f9 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/separateExecution/FreezeWeightDeflationV2Test.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/separateExecution/FreezeWeightDeflationV2Test.java @@ -9,8 +9,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class FreezeWeightDeflationV2Test extends TronBaseTest { @@ -29,79 +29,112 @@ public class FreezeWeightDeflationV2Test extends TronBaseTest { byte[] receiver2Address = ecKey3.getAddress(); String receiver2Key = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() throws Exception { PublicMethod.printAddress(frozen1Key); PublicMethod.printAddress(frozen2Key); PublicMethod.printAddress(receiver1Key); - PublicMethod.printAddress(receiver2Key); if (!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { throw new SkipException("Skipping freezeV2 test case"); + PublicMethod.printAddress(receiver2Key); + if (!PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + throw new SkipException("Skipping freezeV2 test case"); } - - Assert.assertTrue(PublicMethod.sendcoin(frozen1Address, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(frozen2Address, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(receiver1Address, 1L, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(receiver2Address, 1L, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + frozen1Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + frozen2Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + receiver1Address, 1L, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + receiver2Address, 1L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceV2(foundationAddress, frozenAmount * 30, 0, - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceV2(foundationAddress, frozenAmount * 30, 1, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + foundationAddress, frozenAmount * 30, 0, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + foundationAddress, frozenAmount * 30, 1, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.delegateResourceV2(foundationAddress, frozenAmount * 8, - 0, receiver1Address, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.delegateResourceV2(foundationAddress, frozenAmount * 8, - 1, receiver1Address, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.delegateResourceV2(foundationAddress, frozenAmount * 8, - 0, receiver2Address, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.delegateResourceV2(foundationAddress, frozenAmount * 8, - 1, receiver2Address, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.delegateResourceV2( + foundationAddress, + frozenAmount * 8, + 0, + receiver1Address, + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.delegateResourceV2( + foundationAddress, + frozenAmount * 8, + 1, + receiver1Address, + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.delegateResourceV2( + foundationAddress, + frozenAmount * 8, + 0, + receiver2Address, + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.delegateResourceV2( + foundationAddress, + frozenAmount * 8, + 1, + receiver2Address, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, priority=3, description = "Freeze net cause weight deflation issue fix test", groups = {"daily", "serial"}) + @Test( + enabled = true, + priority = 3, + description = "Freeze net cause weight deflation issue fix test", + groups = {"daily", "serial"}) public void test01FreezeNetCauseWeightDeflationTest() { - final Long beforeNetWeight = PublicMethod.getAccountResource(frozen1Address, blockingStubFull) - .getTotalNetWeight(); - final Long beforeEnergyWeight = - PublicMethod.getAccountResource(frozen1Address, blockingStubFull) - .getTotalEnergyWeight(); + final Long beforeNetWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalNetWeight(); + final Long beforeEnergyWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalEnergyWeight(); logger.info("before:" + beforeNetWeight); - Assert.assertTrue(PublicMethod.freezeBalance(frozen1Address, - frozenAmount, 0, frozen1Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance(frozen1Address, frozenAmount, 0, frozen1Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long afterNetWeight = PublicMethod.getAccountResource(frozen1Address, blockingStubFull) - .getTotalNetWeight(); + Long afterNetWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalNetWeight(); Assert.assertTrue(afterNetWeight - beforeNetWeight == 1); - - Assert.assertTrue(PublicMethod.freezeBalance(frozen1Address, - frozenAmount, 0, frozen1Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance(frozen1Address, frozenAmount, 0, frozen1Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - afterNetWeight = PublicMethod.getAccountResource(frozen1Address, blockingStubFull) - .getTotalNetWeight(); - Long afterEnergyWeight = PublicMethod.getAccountResource(frozen1Address, blockingStubFull) - .getTotalEnergyWeight(); + afterNetWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalNetWeight(); + Long afterEnergyWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalEnergyWeight(); Assert.assertTrue(afterNetWeight - beforeNetWeight == 3); Assert.assertTrue(afterEnergyWeight - beforeEnergyWeight == 0); - - Assert.assertTrue(PublicMethod.unFreezeBalanceV2(frozen1Address, frozen1Key, - frozenAmount * 2, 0, blockingStubFull)); + Assert.assertTrue( + PublicMethod.unFreezeBalanceV2( + frozen1Address, frozen1Key, frozenAmount * 2, 0, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long unfreezeTimestamp = PublicMethod.queryAccount(frozen1Address, blockingStubFull) - .getUnfrozenV2(0).getUnfreezeExpireTime(); - int retryTime = 0; + Long unfreezeTimestamp = + PublicMethod.queryAccount(frozen1Address, blockingStubFull) + .getUnfrozenV2(0) + .getUnfreezeExpireTime(); + int retryTime = 0; while (System.currentTimeMillis() < unfreezeTimestamp && retryTime++ < 100) { PublicMethod.waitProduceNextBlock(blockingStubFull); } @@ -110,56 +143,57 @@ public void test01FreezeNetCauseWeightDeflationTest() { PublicMethod.withdrawExpireUnfreeze(frozen1Address, frozen1Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - - afterNetWeight = PublicMethod.getAccountResource(frozen1Address, blockingStubFull) - .getTotalNetWeight(); + afterNetWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalNetWeight(); logger.info("afterNetWeight:" + afterNetWeight); - afterEnergyWeight = PublicMethod.getAccountResource(frozen1Address, blockingStubFull) - .getTotalEnergyWeight(); + afterEnergyWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalEnergyWeight(); Assert.assertTrue(afterEnergyWeight - beforeEnergyWeight == 0); Assert.assertTrue(afterNetWeight - beforeNetWeight == 0); - - } - - @Test(enabled = true, priority=3 ,description = "Freeze energy cause weight deflation issue fix test", groups = {"daily", "serial"}) + @Test( + enabled = true, + priority = 3, + description = "Freeze energy cause weight deflation issue fix test", + groups = {"daily", "serial"}) public void test02FreezeEnergyCauseWeightDeflationTest() { final Long beforeEnergyWeight = - PublicMethod.getAccountResource(frozen1Address, blockingStubFull) - .getTotalEnergyWeight(); - final Long beforeNetWeight = PublicMethod.getAccountResource(frozen1Address, blockingStubFull) - .getTotalNetWeight(); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(frozen1Address, - frozenAmount, 0, 1, frozen1Key, blockingStubFull)); + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalEnergyWeight(); + final Long beforeNetWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalNetWeight(); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + frozen1Address, frozenAmount, 0, 1, frozen1Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long afterEnergyWeight = PublicMethod.getAccountResource(frozen1Address, blockingStubFull) - .getTotalEnergyWeight(); + Long afterEnergyWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalEnergyWeight(); Assert.assertTrue(afterEnergyWeight - beforeEnergyWeight == 1); - Long afterNetWeight = PublicMethod.getAccountResource(frozen1Address, blockingStubFull) - .getTotalNetWeight(); + Long afterNetWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalNetWeight(); Assert.assertTrue(afterNetWeight - beforeNetWeight == 0); - - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(frozen1Address, - frozenAmount, 0, 1, frozen1Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + frozen1Address, frozenAmount, 0, 1, frozen1Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - - afterEnergyWeight = PublicMethod.getAccountResource(frozen1Address, blockingStubFull) - .getTotalEnergyWeight(); + afterEnergyWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalEnergyWeight(); Assert.assertTrue(afterEnergyWeight - beforeEnergyWeight == 3); - afterNetWeight = PublicMethod.getAccountResource(frozen1Address, blockingStubFull) - .getTotalNetWeight(); + afterNetWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalNetWeight(); Assert.assertTrue(afterNetWeight - beforeNetWeight == 0); - - Assert.assertTrue(PublicMethod.unFreezeBalanceV2(frozen1Address, - frozen1Key, frozenAmount * 2, 1, blockingStubFull)); + Assert.assertTrue( + PublicMethod.unFreezeBalanceV2( + frozen1Address, frozen1Key, frozenAmount * 2, 1, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long unfreezeTimestamp = PublicMethod.queryAccount(frozen1Address, blockingStubFull) - .getUnfrozenV2(0).getUnfreezeExpireTime(); - int retryTime = 0; + Long unfreezeTimestamp = + PublicMethod.queryAccount(frozen1Address, blockingStubFull) + .getUnfrozenV2(0) + .getUnfreezeExpireTime(); + int retryTime = 0; while (System.currentTimeMillis() < unfreezeTimestamp && retryTime++ < 100) { PublicMethod.waitProduceNextBlock(blockingStubFull); } @@ -168,24 +202,18 @@ public void test02FreezeEnergyCauseWeightDeflationTest() { PublicMethod.withdrawExpireUnfreeze(frozen1Address, frozen1Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - - afterEnergyWeight = PublicMethod.getAccountResource(frozen1Address, blockingStubFull) - .getTotalEnergyWeight(); + afterEnergyWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalEnergyWeight(); Assert.assertTrue(afterEnergyWeight - beforeEnergyWeight == 0); - afterNetWeight = PublicMethod.getAccountResource(frozen1Address, blockingStubFull) - .getTotalNetWeight(); + afterNetWeight = + PublicMethod.getAccountResource(frozen1Address, blockingStubFull).getTotalNetWeight(); Assert.assertTrue(afterNetWeight - beforeNetWeight == 0); } - - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { PublicMethod.freeResource(frozen1Address, frozen1Key, foundationAddress, blockingStubFull); - PublicMethod.freeResource(frozen2Address, frozen2Key, foundationAddress, blockingStubFull); } + PublicMethod.freeResource(frozen2Address, frozen2Key, foundationAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/separateExecution/GetAccountBalance001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/separateExecution/GetAccountBalance001.java index 6625194a..d74fed1a 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/separateExecution/GetAccountBalance001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/separateExecution/GetAccountBalance001.java @@ -14,12 +14,12 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j - -public class GetAccountBalance001 extends TronBaseTest { private final byte[] foundationAddress = PublicMethod.getFinalAddress(foundationKey); +public class GetAccountBalance001 extends TronBaseTest { + private final byte[] foundationAddress = PublicMethod.getFinalAddress(foundationKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress = ecKey1.getAddress(); final String testKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -31,63 +31,68 @@ public class GetAccountBalance001 extends TronBaseTest { private final byte[] f Long beforeToBalance; Long afterFromBalance; Long afterToBalance; - private final String blackHoleAdd = Configuration.getByPath("testng.conf") - .getString("defaultParameter.blackHoleAddress"); - - /** - * constructor. - */ + private final String blackHoleAdd = + Configuration.getByPath("testng.conf").getString("defaultParameter.blackHoleAddress"); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.sendcoin(sendAddress,100000000L,foundationAddress,foundationKey, - blockingStubFull); + public void beforeClass() { + PublicMethod.sendcoin( + sendAddress, 100000000L, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, priority=1,description = "Test get account balance", groups = {"daily", "serial"}) + @Test( + enabled = true, + priority = 1, + description = "Test get account balance", + groups = {"daily", "serial"}) public void test01GetAccountBalance() { - Protocol.Block currentBlock = blockingStubFull - .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); + Protocol.Block currentBlock = + blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); beforeFromBalance = PublicMethod.getAccountBalance(currentBlock, sendAddress, blockingStubFull); beforeToBalance = PublicMethod.getAccountBalance(currentBlock, testAddress, blockingStubFull); - - } - @Test(enabled = true, priority=1,description = "Test get block balance", groups = {"daily", "serial"}) + @Test( + enabled = true, + priority = 1, + description = "Test get block balance", + groups = {"daily", "serial"}) public void test02GetBlockBalance() { - String txid = PublicMethod.sendcoinGetTransactionId(testAddress, sendAmount, sendAddress, - sendKey, blockingStubFull); + String txid = + PublicMethod.sendcoinGetTransactionId( + testAddress, sendAmount, sendAddress, sendKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - Long blockNum = infoById.get().getBlockNumber(); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Long blockNum = infoById.get().getBlockNumber(); Protocol.Block currentBlock = PublicMethod.getBlock(blockNum, blockingStubFull); - BlockBalanceTrace blockBalanceTrace - = PublicMethod.getBlockBalance(currentBlock, blockingStubFull); - + BlockBalanceTrace blockBalanceTrace = + PublicMethod.getBlockBalance(currentBlock, blockingStubFull); - Assert.assertEquals(ByteString.copyFrom(sendAddress), blockBalanceTrace - .getTransactionBalanceTrace(0).getOperation(0).getAddress()); - Assert.assertEquals(-100000L, blockBalanceTrace.getTransactionBalanceTrace(0) - .getOperation(0).getAmount()); + Assert.assertEquals( + ByteString.copyFrom(sendAddress), + blockBalanceTrace.getTransactionBalanceTrace(0).getOperation(0).getAddress()); + Assert.assertEquals( + -100000L, blockBalanceTrace.getTransactionBalanceTrace(0).getOperation(0).getAmount()); + Assert.assertEquals( + ByteString.copyFrom(sendAddress), + blockBalanceTrace.getTransactionBalanceTrace(0).getOperation(1).getAddress()); + Assert.assertEquals( + -sendAmount - 1000000, + blockBalanceTrace.getTransactionBalanceTrace(0).getOperation(1).getAmount()); - Assert.assertEquals(ByteString.copyFrom(sendAddress), blockBalanceTrace - .getTransactionBalanceTrace(0).getOperation(1).getAddress()); - Assert.assertEquals(-sendAmount - 1000000, blockBalanceTrace.getTransactionBalanceTrace(0) - .getOperation(1).getAmount()); - - - Assert.assertEquals(ByteString.copyFrom(testAddress), blockBalanceTrace - .getTransactionBalanceTrace(0).getOperation(2).getAddress()); - Assert.assertEquals(-sendAmount, -blockBalanceTrace.getTransactionBalanceTrace(0) - .getOperation(2).getAmount()); - + Assert.assertEquals( + ByteString.copyFrom(testAddress), + blockBalanceTrace.getTransactionBalanceTrace(0).getOperation(2).getAddress()); + Assert.assertEquals( + -sendAmount, -blockBalanceTrace.getTransactionBalanceTrace(0).getOperation(2).getAmount()); afterFromBalance = PublicMethod.getAccountBalance(currentBlock, sendAddress, blockingStubFull); afterToBalance = PublicMethod.getAccountBalance(currentBlock, testAddress, blockingStubFull); @@ -96,12 +101,9 @@ public void test02GetBlockBalance() { Assert.assertTrue(beforeFromBalance - afterFromBalance >= sendAmount + 100000L); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(testAddress, testKey, sendAddress, blockingStubFull); } - + PublicMethod.freeResource(testAddress, testKey, sendAddress, blockingStubFull); + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/separateExecution/HttpTestGetAccountBalance001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/separateExecution/HttpTestGetAccountBalance001.java index c46ae1cf..0a34081a 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/separateExecution/HttpTestGetAccountBalance001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/separateExecution/HttpTestGetAccountBalance001.java @@ -18,17 +18,17 @@ @Slf4j public class HttpTestGetAccountBalance001 { - private final String testKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); + private final String testKey002 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key1"); private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); private JSONObject responseContent; private HttpResponse response; - private String httpnode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(0); - private String httpPbftNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(4); - private String httpSolidityNode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(2); + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); + private String httpPbftNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(4); + private String httpSolidityNode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(2); ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] assetOwnerAddress = ecKey2.getAddress(); String assetOwnerKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); @@ -42,17 +42,16 @@ public class HttpTestGetAccountBalance001 { String deployContractBlockHash; Long fee; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true, description = "Deploy smart contract by http") public void test01DeployContractForTest() { HttpMethod.waitToProduceOneBlock(httpnode); PublicMethod.printAddress(assetOwnerKey); txid = HttpMethod.sendCoin(httpnode, fromAddress, assetOwnerAddress, amount, "", testKey002); HttpMethod.waitToProduceOneBlock(httpnode); - txid = HttpMethod.sendCoin(httpnode, assetOwnerAddress, randomAddress, - amount / 1000000L, "", assetOwnerKey); + txid = + HttpMethod.sendCoin( + httpnode, assetOwnerAddress, randomAddress, amount / 1000000L, "", assetOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getTransactionInfoById(httpnode, txid); responseContent = HttpMethod.parseResponseContent(response); @@ -66,13 +65,27 @@ public void test01DeployContractForTest() { sendcoinBlockHash = responseContent.getString("blockID"); String contractName = "transferTokenContract"; - String code = Configuration.getByPath("testng.conf") - .getString("code.code_ContractTrcToken001_transferTokenContract"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_ContractTrcToken001_transferTokenContract"); - txid = HttpMethod - .deployContractGetTxid(httpnode, contractName, abi, code, 1000000L, 1000000000L, 100, - 11111111111111L, 0L, 0, 0L, assetOwnerAddress, assetOwnerKey); + String code = + Configuration.getByPath("testng.conf") + .getString("code.code_ContractTrcToken001_transferTokenContract"); + String abi = + Configuration.getByPath("testng.conf") + .getString("abi.abi_ContractTrcToken001_transferTokenContract"); + txid = + HttpMethod.deployContractGetTxid( + httpnode, + contractName, + abi, + code, + 1000000L, + 1000000000L, + 100, + 11111111111111L, + 0L, + 0, + 0L, + assetOwnerAddress, + assetOwnerKey); HttpMethod.waitToProduceOneBlock(httpnode); logger.info(txid); @@ -83,8 +96,8 @@ public void test01DeployContractForTest() { fee = responseContent.getLong("fee"); deployContractBlockNumber = responseContent.getLong("blockNumber"); String receiptString = responseContent.getString("receipt"); - Assert - .assertEquals(HttpMethod.parseStringContent(receiptString).getString("result"), "SUCCESS"); + Assert.assertEquals( + HttpMethod.parseStringContent(receiptString).getString("result"), "SUCCESS"); response = HttpMethod.getBlockByNum(httpnode, deployContractBlockNumber); responseContent = HttpMethod.parseResponseContent(response); @@ -92,21 +105,25 @@ public void test01DeployContractForTest() { deployContractBlockHash = responseContent.getString("blockID"); } - /** - * constructor. - */ - @Test(enabled = true, priority=2, description = "Get account balance by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + priority = 2, + description = "Get account balance by http", + groups = {"daily", "serial"}) public void test01GetAccountBalance() { - response = HttpMethod.getAccountBalance(httpnode, assetOwnerAddress, - sendcoinBlockNumber, sendcoinBlockHash); + response = + HttpMethod.getAccountBalance( + httpnode, assetOwnerAddress, sendcoinBlockNumber, sendcoinBlockHash); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); Assert.assertTrue(responseContent.size() >= 2); final Long beforeBalance = responseContent.getLong("balance"); - response = HttpMethod.getAccountBalance(httpnode, assetOwnerAddress, - deployContractBlockNumber, deployContractBlockHash); + response = + HttpMethod.getAccountBalance( + httpnode, assetOwnerAddress, deployContractBlockNumber, deployContractBlockHash); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); @@ -115,68 +132,74 @@ public void test01GetAccountBalance() { Assert.assertTrue(beforeBalance - afterBalance == fee); - - response = HttpMethod.getAccountBalance(httpnode, assetOwnerAddress, - deployContractBlockNumber, deployContractBlockHash); + response = + HttpMethod.getAccountBalance( + httpnode, assetOwnerAddress, deployContractBlockNumber, deployContractBlockHash); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); Assert.assertTrue(responseContent.size() >= 2); - - } - - /** - * constructor. - */ - @Test(enabled = true, priority=2, description = "Get block balance by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + priority = 2, + description = "Get block balance by http", + groups = {"daily", "serial"}) public void test02GetBlockBalance() { - response = HttpMethod.getBlockBalance(httpnode, - sendcoinBlockNumber, sendcoinBlockHash); + response = HttpMethod.getBlockBalance(httpnode, sendcoinBlockNumber, sendcoinBlockHash); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); Assert.assertTrue(responseContent.size() >= 2); - Assert.assertEquals(sendcoinBlockNumber, responseContent.getJSONObject("block_identifier") - .getLong("number")); - JSONObject transactionObject = responseContent.getJSONArray("transaction_balance_trace") - .getJSONObject(0); + Assert.assertEquals( + sendcoinBlockNumber, responseContent.getJSONObject("block_identifier").getLong("number")); + JSONObject transactionObject = + responseContent.getJSONArray("transaction_balance_trace").getJSONObject(0); Assert.assertEquals(transactionObject.getString("type"), "TransferContract"); - Assert.assertTrue(Math.abs(transactionObject.getJSONArray("operation") - .getJSONObject(0).getLong("amount")) == 100000L); - Assert.assertTrue(Math.abs(transactionObject.getJSONArray("operation") - .getJSONObject(1).getLong("amount")) == (amount / 1000000L + 1000000L)); - Assert.assertTrue(Math.abs(transactionObject.getJSONArray("operation") - .getJSONObject(2).getLong("amount")) == amount / 1000000L); - - response = HttpMethod.getBlockBalance(httpnode, - deployContractBlockNumber, deployContractBlockHash); + Assert.assertTrue( + Math.abs(transactionObject.getJSONArray("operation").getJSONObject(0).getLong("amount")) + == 100000L); + Assert.assertTrue( + Math.abs(transactionObject.getJSONArray("operation").getJSONObject(1).getLong("amount")) + == (amount / 1000000L + 1000000L)); + Assert.assertTrue( + Math.abs(transactionObject.getJSONArray("operation").getJSONObject(2).getLong("amount")) + == amount / 1000000L); + + response = + HttpMethod.getBlockBalance(httpnode, deployContractBlockNumber, deployContractBlockHash); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); Assert.assertTrue(responseContent.size() >= 2); Integer transactionIndex = 0; - for(int i = 0; i < responseContent.getJSONArray("transaction_balance_trace").size();i++) { - transactionObject = responseContent.getJSONArray("transaction_balance_trace").getJSONObject(i); - if(transactionObject.getString("transaction_identifier").equalsIgnoreCase(txid)) { + for (int i = 0; i < responseContent.getJSONArray("transaction_balance_trace").size(); i++) { + transactionObject = + responseContent.getJSONArray("transaction_balance_trace").getJSONObject(i); + if (transactionObject.getString("transaction_identifier").equalsIgnoreCase(txid)) { transactionIndex = i; break; } } - transactionObject = responseContent.getJSONArray("transaction_balance_trace").getJSONObject(transactionIndex); + transactionObject = + responseContent.getJSONArray("transaction_balance_trace").getJSONObject(transactionIndex); Assert.assertEquals(transactionObject.getString("transaction_identifier"), txid); Assert.assertEquals(transactionObject.getString("type"), "CreateSmartContract"); - Assert.assertTrue(transactionObject.getJSONArray("operation") - .getJSONObject(0).getLong("amount") == -fee); + Assert.assertTrue( + transactionObject.getJSONArray("operation").getJSONObject(0).getLong("amount") == -fee); } - /** - * constructor. - */ - @Test(enabled = true, retryAnalyzer = Retry.class, priority=2, description = "Get burn trx by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = true, + retryAnalyzer = Retry.class, + priority = 2, + description = "Get burn trx by http", + groups = {"daily", "serial"}) public void test03GetBurnTrx() { ECKey ecKey2 = new ECKey(Utils.getRandom()); @@ -188,10 +211,11 @@ public void test03GetBurnTrx() { ECKey ecKey3 = new ECKey(Utils.getRandom()); byte[] receiverAddress = ecKey3.getAddress(); - String txid = HttpMethod.sendCoin(httpnode, assetOwnerAddress, receiverAddress, - amount - 2003000L, "", assetOwnerKey); + String txid = + HttpMethod.sendCoin( + httpnode, assetOwnerAddress, receiverAddress, amount - 2003000L, "", assetOwnerKey); HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSolidityNode); - //HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSolidityNode); + // HttpMethod.waitToProduceOneBlockFromSolidity(httpnode, httpSolidityNode); Long afterBurnTrxAmount = HttpMethod.getBurnTrx(httpnode); logger.info(afterBurnTrxAmount + " : " + beforeBurnTrxAmount); Assert.assertTrue(afterBurnTrxAmount - beforeBurnTrxAmount == 1100000L); @@ -200,29 +224,29 @@ public void test03GetBurnTrx() { Assert.assertEquals(afterBurnTrxAmount, HttpMethod.getBurnTrxFromPbft(httpPbftNode)); } - /** - * constructor. - */ - @Test(enabled = false, priority=2, description = "Get receipt root by http", groups = {"daily", "serial"}) + /** constructor. */ + @Test( + enabled = false, + priority = 2, + description = "Get receipt root by http", + groups = {"daily", "serial"}) public void test04GetReceiptRootByHttp() { response = HttpMethod.getBlockByNum(httpnode, sendcoinBlockNumber); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); - String receiptsRoot = responseContent.getJSONObject("block_header").getJSONObject("raw_data") - .getString("receiptsRoot"); - Assert.assertNotEquals(receiptsRoot, - "0000000000000000000000000000000000000000000000000000000000000000"); + String receiptsRoot = + responseContent + .getJSONObject("block_header") + .getJSONObject("raw_data") + .getString("receiptsRoot"); + Assert.assertNotEquals( + receiptsRoot, "0000000000000000000000000000000000000000000000000000000000000000"); Assert.assertFalse(receiptsRoot.isEmpty()); - } - - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { HttpMethod.disConnect(); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/separateExecution/NewFreezeContractTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/separateExecution/NewFreezeContractTest.java index fbd3e202..1446d1ab 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/separateExecution/NewFreezeContractTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/separateExecution/NewFreezeContractTest.java @@ -18,16 +18,20 @@ import org.tron.protos.Protocol.TransactionInfo.code; import org.tron.protos.contract.SmartContractOuterClass; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; - +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class NewFreezeContractTest extends TronBaseTest { - private String testFoundationKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); - private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); + private String testFoundationKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); + private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey1.getAddress(); String testKey001 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private byte[] contractAddress; @@ -40,7 +44,6 @@ public class NewFreezeContractTest extends TronBaseTest { byte[] testAddress002 = ecKey2.getAddress(); String testKey002 = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - long delegatebleNet = 0; long delegatebleEnergy = 0; Long maxNet = Long.valueOf(0); @@ -48,40 +51,66 @@ public class NewFreezeContractTest extends TronBaseTest { private long frozenAmount = 0L; private long frozenAmountCreate2 = 10000000L; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(testKey001); - PublicMethod.printAddress(testKey002); Assert.assertTrue(PublicMethod.sendcoin(testAddress001, 100000_000000L, - testFoundationAddress, testFoundationKey, blockingStubFull)); - - Assert.assertTrue(PublicMethod.sendcoin(testAddress002, 20000_000000L, - testFoundationAddress, testFoundationKey, blockingStubFull)); + PublicMethod.printAddress(testKey002); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress001, + 100000_000000L, + testFoundationAddress, + testFoundationKey, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress002, + 20000_000000L, + testFoundationAddress, + testFoundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/newFreezeContract.sol"; - String contractName = "NewFreezeV2"; + String filePath = "src/test/resources/soliditycode/newFreezeContract.sol"; + String contractName = "NewFreezeV2"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContractFallback(contractName, abi, code, "", maxFeeLimit, 1000000000L, - 100, null, testKey001, - testAddress001, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContractFallback( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000000L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); contractAddress58 = Base58.encode58Check(contractAddress); contractName = "D"; retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - contractAddressD = PublicMethod - .deployContractFallback(contractName, abi, code, "", maxFeeLimit, 0L, - 100, null, testKey001, - testAddress001, blockingStubFull); + contractAddressD = + PublicMethod.deployContractFallback( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod - .getContract(contractAddress, blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); smartContract = PublicMethod.getContract(contractAddressD, blockingStubFull); @@ -89,29 +118,66 @@ public void beforeClass() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); } - - @Test(enabled = true, description = "freezebalancev2 amount cant not be 0,-1," - + " or number bigger than balance", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "freezebalancev2 amount cant not be 0,-1," + " or number bigger than balance", + groups = {"daily", "serial"}) void test01FreezeAmountException() { - AccountResourceMessage contractResourceBefore = PublicMethod - .getAccountResource(contractAddress, blockingStubFull); + AccountResourceMessage contractResourceBefore = + PublicMethod.getAccountResource(contractAddress, blockingStubFull); Account contractAccountBefore = PublicMethod.queryAccount(contractAddress, blockingStubFull); - String methedStr = "freezeBalanceV2(uint256,uint256)"; - String argsStr = "0,0"; - String txid = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String methedStr = "freezeBalanceV2(uint256,uint256)"; + String argsStr = "0,0"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); argsStr = "0,1"; - String txid1 = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); argsStr = "-1,1"; - String txid2 = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String txid2 = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); argsStr = contractAccountBefore.getBalance() + 1 + ",1"; - String txid3 = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String txid3 = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); @@ -123,83 +189,137 @@ void test01FreezeAmountException() { info = PublicMethod.getTransactionInfoById(txid3, blockingStubFull).get(); Assert.assertEquals(info.getReceipt().getResult(), contractResult.REVERT); - AccountResourceMessage contractResourceAfter = PublicMethod - .getAccountResource(contractAddress, blockingStubFull); + AccountResourceMessage contractResourceAfter = + PublicMethod.getAccountResource(contractAddress, blockingStubFull); Account contractAccountAfter = PublicMethod.queryAccount(contractAddress, blockingStubFull); - logger.info("contractResourceBefore.getEnergyLimit : " - + contractResourceBefore.getEnergyLimit()); - logger.info("contractResourceAfter.getEnergyLimit : " - + contractResourceAfter.getEnergyLimit()); - Assert.assertTrue(contractResourceBefore.getEnergyLimit() - == contractResourceAfter.getEnergyLimit()); - - Assert.assertEquals(contractAccountBefore.getBalance(), - contractAccountAfter.getBalance()); + logger.info( + "contractResourceBefore.getEnergyLimit : " + contractResourceBefore.getEnergyLimit()); + logger.info("contractResourceAfter.getEnergyLimit : " + contractResourceAfter.getEnergyLimit()); + Assert.assertTrue( + contractResourceBefore.getEnergyLimit() == contractResourceAfter.getEnergyLimit()); + Assert.assertEquals(contractAccountBefore.getBalance(), contractAccountAfter.getBalance()); } - @Test(enabled = true, description = "freeze 5trx v2 net and 5trx v2 energy", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "freeze 5trx v2 net and 5trx v2 energy", + groups = {"daily", "serial"}) void test02FreezeContract() { frozenAmount = 200000000L; long temAmt = frozenAmount + 1000000; - String methedStr = "freezeBalanceV2(uint256,uint256)"; - String argsStr = temAmt + ",0"; - String txid = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String methedStr = "freezeBalanceV2(uint256,uint256)"; + String argsStr = temAmt + ",0"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); argsStr = frozenAmount + ",1"; - String txid1 = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); Assert.assertEquals(code.SUCESS, info.getResult()); Assert.assertEquals(contractResult.SUCCESS, info.getReceipt().getResult()); - Assert.assertEquals("freezeBalanceV2ForBandwidth", info.getInternalTransactions(0).getNote().toStringUtf8()); + Assert.assertEquals( + "freezeBalanceV2ForBandwidth", info.getInternalTransactions(0).getNote().toStringUtf8()); info = PublicMethod.getTransactionInfoById(txid1, blockingStubFull).get(); logger.info(info.toString()); Assert.assertEquals(code.SUCESS, info.getResult()); Assert.assertEquals(contractResult.SUCCESS, info.getReceipt().getResult()); - Assert.assertEquals("freezeBalanceV2ForEnergy", info.getInternalTransactions(0).getNote().toStringUtf8()); + Assert.assertEquals( + "freezeBalanceV2ForEnergy", info.getInternalTransactions(0).getNote().toStringUtf8()); HashMap map = getResource(contractAddress58, blockingStubFull); Assert.assertEquals(temAmt, map.get("netFrozenBalanceV2").longValue()); Assert.assertEquals(frozenAmount, map.get("energyFrozenBalanceV2").longValue()); } - @Test(enabled = true, description = "unfreeze 1trx to test withdraw expired unfreeze", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "unfreeze 1trx to test withdraw expired unfreeze", + groups = {"daily", "serial"}) void test03UnfreezeToWithdraw() { String methedStr = "unfreezeBalanceV2(uint256,uint256)"; - String argsStr = "1000000,"; + String argsStr = "1000000,"; long size = getAvailableUnfreezeV2Size(contractAddress, contractAddress58); Assert.assertEquals(32, size); long expireUnfreezeBalance = getExpireUnfreezeBalanceV2(contractAddress, contractAddress58); Assert.assertEquals(0, expireUnfreezeBalance); - String txid = PublicMethod.triggerContract(contractAddress, methedStr, argsStr + 0, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr + 0, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("unfreeze 1trx info: " + info.toString()); Assert.assertEquals(code.SUCESS, info.getResult()); Assert.assertEquals(contractResult.SUCCESS, info.getReceipt().getResult()); - Assert.assertEquals("unfreezeBalanceV2ForBandwidth", info.getInternalTransactions(0).getNote().toStringUtf8()); + Assert.assertEquals( + "unfreezeBalanceV2ForBandwidth", info.getInternalTransactions(0).getNote().toStringUtf8()); } - @Test(enabled = true, description = "cannot delegate resource to self", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "cannot delegate resource to self", + groups = {"daily", "serial"}) void test04CannotDelegateToSelf() { String methedStr = "delegateResource(uint256,uint256,address)"; - String argsStr = frozenAmount + ",0,\"" + contractAddress58 + "\""; - //delegate net - String txid = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argsStr = frozenAmount + ",0,\"" + contractAddress58 + "\""; + // delegate net + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); argsStr = frozenAmount + ",1,\"" + contractAddress58 + "\""; - //delegate energy - String txid1 = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + // delegate energy + String txid1 = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("delegate net to self: " + info.toString()); @@ -213,31 +333,59 @@ void test04CannotDelegateToSelf() { HashMap map = getResource(contractAddress58, blockingStubFull); Assert.assertEquals(frozenAmount, map.get("netFrozenBalanceV2").longValue()); Assert.assertEquals(frozenAmount, map.get("energyFrozenBalanceV2").longValue()); - - } - @Test(enabled = true, description = "cannot delegate resource to contract", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "cannot delegate resource to contract", + groups = {"daily", "serial"}) void test05CannotDelegateToContract() { String filePath = "src/test/resources/soliditycode/onlyCreate2Address.sol"; - String contractName = "C"; + String contractName = "C"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] newContract = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, - 100, null, testFoundationKey, - testFoundationAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] newContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testFoundationKey, + testFoundationAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String methedStr = "delegateResource(uint256,uint256,address)"; - String argsStr = frozenAmount + ",0,\"" + contractAddress58 + "\""; - //delegate net - String txid = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String methedStr = "delegateResource(uint256,uint256,address)"; + String argsStr = frozenAmount + ",0,\"" + contractAddress58 + "\""; + // delegate net + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); argsStr = frozenAmount + ",1,\"" + contractAddress58 + "\""; - //delegate energy - String txid1 = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + // delegate energy + String txid1 = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("delegate net to contract: " + info.toString()); @@ -251,38 +399,60 @@ void test05CannotDelegateToContract() { HashMap map = getResource(contractAddress58, blockingStubFull); Assert.assertEquals(frozenAmount, map.get("netFrozenBalanceV2").longValue()); Assert.assertEquals(frozenAmount, map.get("energyFrozenBalanceV2").longValue()); - } - @Test(enabled = true, description = "delegate all net and energy to normal address", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "delegate all net and energy to normal address", + groups = {"daily", "serial"}) void test06DelegateNetAndEnergy() { long delegatebleNet = getDelegatableResource(contractAddress58, contractAddress58, 0); long delegatebleEnergy = getDelegatableResource(contractAddress58, contractAddress58, 1); Assert.assertEquals(frozenAmount, delegatebleNet); Assert.assertEquals(frozenAmount, delegatebleEnergy); - String receiver = Base58.encode58Check(testAddress002); - String methedStr = "delegateResource(uint256,uint256,address)"; - String argsStr = frozenAmount + ",0,\"" + receiver + "\""; - //delegate net + String receiver = Base58.encode58Check(testAddress002); + String methedStr = "delegateResource(uint256,uint256,address)"; + String argsStr = frozenAmount + ",0,\"" + receiver + "\""; + // delegate net logger.info("methedStr: " + methedStr); logger.info("argsStr: " + argsStr); - String txid = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); argsStr = frozenAmount + ",1,\"" + receiver + "\""; - //delegate energy - String txid1 = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + // delegate energy + String txid1 = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("delegate net info: " + info.toString()); Assert.assertEquals(code.SUCESS, info.getResult()); Assert.assertEquals(contractResult.SUCCESS, info.getReceipt().getResult()); - Assert.assertEquals("delegateResourceOfBandwidth", info.getInternalTransactions(0).getNote().toStringUtf8()); + Assert.assertEquals( + "delegateResourceOfBandwidth", info.getInternalTransactions(0).getNote().toStringUtf8()); info = PublicMethod.getTransactionInfoById(txid1, blockingStubFull).get(); logger.info("delegate energy info: " + info.toString()); Assert.assertEquals(code.SUCESS, info.getResult()); Assert.assertEquals(contractResult.SUCCESS, info.getReceipt().getResult()); - Assert.assertEquals("delegateResourceOfEnergy", info.getInternalTransactions(0).getNote().toStringUtf8()); + Assert.assertEquals( + "delegateResourceOfEnergy", info.getInternalTransactions(0).getNote().toStringUtf8()); delegatebleNet = getDelegatableResource(contractAddress58, contractAddress58, 0); delegatebleEnergy = getDelegatableResource(contractAddress58, contractAddress58, 1); Assert.assertEquals(0, delegatebleNet); @@ -298,22 +468,42 @@ void test06DelegateNetAndEnergy() { getTotalResource(contractAddress58, contractAddress58); getTotalResource(receiver, contractAddress58); getTotalAcquiredResource(contractAddress, receiver); - } - @Test(enabled = true, description = "can not unfreeze delegated resource", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "can not unfreeze delegated resource", + groups = {"daily", "serial"}) void test07CannotUnfreeze() { long unfreezableNet = getUnfreezableBalanceV2(contractAddress, contractAddress58, "0"); long unfreezableEnergy = getUnfreezableBalanceV2(contractAddress, contractAddress58, "1"); Assert.assertEquals(0, unfreezableNet); Assert.assertEquals(0, unfreezableEnergy); - String methedStr = "unfreezeBalanceV2(uint256,uint256)"; - String argsStr = frozenAmount + ",0"; - String txid = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); - String argsStr1 = frozenAmount + ",1"; - String txid1 = PublicMethod.triggerContract(contractAddress, methedStr, argsStr1, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String methedStr = "unfreezeBalanceV2(uint256,uint256)"; + String argsStr = frozenAmount + ",0"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); + String argsStr1 = frozenAmount + ",1"; + String txid1 = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr1, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("unfreeze delegated net: " + info.toString()); @@ -325,26 +515,56 @@ void test07CannotUnfreeze() { Assert.assertEquals(contractResult.REVERT, info.getReceipt().getResult()); } - @Test(enabled = true, description = "undelegate with wrong amount or address", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "undelegate with wrong amount or address", + groups = {"daily", "serial"}) void test08UndelegateException() { String methedStr = "unDelegateResource(uint256,uint256,address)"; - String receiver = Base58.encode58Check(testAddress002); + String receiver = Base58.encode58Check(testAddress002); long amount = frozenAmount + 1; - String argsStr = amount + ",1,\"" + receiver + "\""; - String txid0 = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argsStr = amount + ",1,\"" + receiver + "\""; + String txid0 = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); argsStr = amount + ",0,\"" + receiver + "\""; - String txid1 = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); - //undelegate with wrong address + String txid1 = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); + // undelegate with wrong address ECKey ecKey3 = new ECKey(Utils.getRandom()); - byte[] testAddress003 = ecKey3.getAddress(); + byte[] testAddress003 = ecKey3.getAddress(); receiver = Base58.encode58Check(testAddress003); argsStr = frozenAmount + ",1,\"" + receiver + "\""; - String txid2 = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String txid2 = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info0 = PublicMethod.getTransactionInfoById(txid0, blockingStubFull).get(); @@ -361,51 +581,83 @@ void test08UndelegateException() { logger.info("info0: " + info2.toString()); Assert.assertEquals(code.FAILED, info2.getResult()); Assert.assertEquals(contractResult.REVERT, info2.getReceipt().getResult()); - } - @Test(enabled = true, description = "normal account consume energy and bandwidth", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "normal account consume energy and bandwidth", + groups = {"daily", "serial"}) void test09ConsumeResource() { String methedStr = "testConsumeEnergy(int256,int256)"; - String argsStr = "1,1"; - for(int i = 0; i < 1; i++){ - PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress002, testKey002, blockingStubFull); + String argsStr = "1,1"; + for (int i = 0; i < 1; i++) { + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress002, + testKey002, + blockingStubFull); } PublicMethod.waitProduceNextBlock(blockingStubFull); - checkUnDelegateResource(contractAddress, Base58.encode58Check(testAddress002), - "0", frozenAmount); - checkUnDelegateResource(contractAddress, Base58.encode58Check(testAddress002), - "1", frozenAmount); + checkUnDelegateResource( + contractAddress, Base58.encode58Check(testAddress002), "0", frozenAmount); + checkUnDelegateResource( + contractAddress, Base58.encode58Check(testAddress002), "1", frozenAmount); } - @Test(enabled = true, description = "undelegate net and energy success", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "undelegate net and energy success", + groups = {"daily", "serial"}) void test10UndelegateResource() { - //todo : calculate usage (contract and receiver) + // todo : calculate usage (contract and receiver) String methedStr = "unDelegateResource(uint256,uint256,address)"; - String receiver = Base58.encode58Check(testAddress002); - String argsStr = frozenAmount + ",1,\"" + receiver + "\""; - String txid0 = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String receiver = Base58.encode58Check(testAddress002); + String argsStr = frozenAmount + ",1,\"" + receiver + "\""; + String txid0 = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); argsStr = frozenAmount + ",0,\"" + receiver + "\""; - String txid1 = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info0 = PublicMethod.getTransactionInfoById(txid0, blockingStubFull).get(); logger.info("undelegate energy info0: " + info0.toString()); Assert.assertEquals(code.SUCESS, info0.getResult()); Assert.assertEquals(contractResult.SUCCESS, info0.getReceipt().getResult()); - Assert.assertEquals("unDelegateResourceOfEnergy", info0.getInternalTransactions(0).getNote().toStringUtf8()); - + Assert.assertEquals( + "unDelegateResourceOfEnergy", info0.getInternalTransactions(0).getNote().toStringUtf8()); TransactionInfo info1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull).get(); logger.info("undelegate bandwidth info1: " + info1.toString()); Assert.assertEquals(code.SUCESS, info1.getResult()); Assert.assertEquals(contractResult.SUCCESS, info1.getReceipt().getResult()); - Assert.assertEquals("unDelegateResourceOfBandwidth", info1.getInternalTransactions(0).getNote().toStringUtf8()); + Assert.assertEquals( + "unDelegateResourceOfBandwidth", info1.getInternalTransactions(0).getNote().toStringUtf8()); long resourceV2Net = getResourceV2(contractAddress58, receiver, "0", contractAddress); long resourceV2Energy = getResourceV2(contractAddress58, receiver, "1", contractAddress); @@ -414,32 +666,64 @@ void test10UndelegateResource() { Assert.assertEquals(0, resourceV2Net); Assert.assertEquals(0, resourceV2Energy); resourceUsage(contractAddress58, contractAddress); - //todo : calculate usage (contract and receiver) + // todo : calculate usage (contract and receiver) } - @Test(enabled = true, description = "delegate resource when usage>0", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "delegate resource when usage>0", + groups = {"daily", "serial"}) void test11DelegateWithUsage() { delegatebleNet = getDelegatableResource(contractAddress58, contractAddress58, 0); - maxNet = PublicMethod.getCanDelegatedMaxSize(contractAddress, 0, blockingStubFull) - .get().getMaxSize(); + maxNet = + PublicMethod.getCanDelegatedMaxSize(contractAddress, 0, blockingStubFull) + .get() + .getMaxSize(); delegatebleEnergy = getDelegatableResource(contractAddress58, contractAddress58, 1); - maxEnergy = PublicMethod.getCanDelegatedMaxSize(contractAddress, 1, blockingStubFull) - .get().getMaxSize(); - logger.info("delegatebleNet: " + delegatebleNet + " maxNet: " + maxNet - + "\n delegatebleEnergy: " + delegatebleEnergy + " maxEnergy: " + maxEnergy); - logger.info(PublicMethod.queryAccount(contractAddress,blockingStubFull).toString()); - logger.info(PublicMethod.getAccountResource(contractAddress,blockingStubFull).toString()); - String receiver = Base58.encode58Check(testAddress002); - String methedStr = "delegateResource(uint256,uint256,address)"; - String argsStr = delegatebleNet + ",0,\"" + receiver + "\""; - //delegate net - - String txid = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + maxEnergy = + PublicMethod.getCanDelegatedMaxSize(contractAddress, 1, blockingStubFull) + .get() + .getMaxSize(); + logger.info( + "delegatebleNet: " + + delegatebleNet + + " maxNet: " + + maxNet + + "\n delegatebleEnergy: " + + delegatebleEnergy + + " maxEnergy: " + + maxEnergy); + logger.info(PublicMethod.queryAccount(contractAddress, blockingStubFull).toString()); + logger.info(PublicMethod.getAccountResource(contractAddress, blockingStubFull).toString()); + String receiver = Base58.encode58Check(testAddress002); + String methedStr = "delegateResource(uint256,uint256,address)"; + String argsStr = delegatebleNet + ",0,\"" + receiver + "\""; + // delegate net + + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); argsStr = delegatebleEnergy + ",1,\"" + receiver + "\""; - //delegate energy - String txid1 = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + // delegate energy + String txid1 = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("delegate with usage net info: " + info.toString()); @@ -464,56 +748,97 @@ void test11DelegateWithUsage() { getTotalResource(contractAddress58, contractAddress58); getTotalResource(receiver, contractAddress58); getTotalAcquiredResource(contractAddress, receiver); - } - @Test(enabled = true, description = "normal account consume energy and bandwidth again", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "normal account consume energy and bandwidth again", + groups = {"daily", "serial"}) void test12ConsumeResourceAgain() { String methedStr = "testConsumeEnergy(int256,int256)"; - String argsStr = "1,1"; - for(int i = 0; i < 1; i++){ - PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress002, testKey002, blockingStubFull); + String argsStr = "1,1"; + for (int i = 0; i < 1; i++) { + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress002, + testKey002, + blockingStubFull); } PublicMethod.waitProduceNextBlock(blockingStubFull); - checkUnDelegateResource(contractAddress, Base58.encode58Check(testAddress002), "0", - delegatebleNet / 2); - checkUnDelegateResource(contractAddress, Base58.encode58Check(testAddress002), "1", - delegatebleEnergy / 2); + checkUnDelegateResource( + contractAddress, Base58.encode58Check(testAddress002), "0", delegatebleNet / 2); + checkUnDelegateResource( + contractAddress, Base58.encode58Check(testAddress002), "1", delegatebleEnergy / 2); } - @Test(enabled = true, description = "", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "", + groups = {"daily", "serial"}) void test13CannotKillWithDelegate() { String methedStr = "killme(address)"; - String argsStr = "\"" + Base58.encode58Check(testAddress002) + "\""; - String txid = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testFoundationAddress, testFoundationKey, blockingStubFull); + String argsStr = "\"" + Base58.encode58Check(testAddress002) + "\""; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); logger.info("kill me revert WithDelegate txid: " + txid); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); Assert.assertEquals(code.FAILED, info.getResult()); Assert.assertEquals(contractResult.REVERT, info.getReceipt().getResult()); - } - @Test(enabled = true, description = "undelegate net and energy success again", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "undelegate net and energy success again", + groups = {"daily", "serial"}) void test14UndelegateResourceAgain() { - //todo : calculate usage (contract and receiver) + // todo : calculate usage (contract and receiver) String methedStr = "unDelegateResource(uint256,uint256,address)"; - String receiver = Base58.encode58Check(testAddress002); + String receiver = Base58.encode58Check(testAddress002); PublicMethod.freezeBalanceV2(testAddress002, maxNet, 0, testKey002, blockingStubFull); - PublicMethod.freezeBalanceV2(testAddress002, maxEnergy, - 1, testKey002, blockingStubFull); + PublicMethod.freezeBalanceV2(testAddress002, maxEnergy, 1, testKey002, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String argsStr = delegatebleEnergy + ",1,\"" + receiver + "\""; - String txid0 = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argsStr = delegatebleEnergy + ",1,\"" + receiver + "\""; + String txid0 = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); argsStr = delegatebleNet + ",0,\"" + receiver + "\""; - String txid1 = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info0 = PublicMethod.getTransactionInfoById(txid0, blockingStubFull).get(); @@ -533,10 +858,12 @@ void test14UndelegateResourceAgain() { Assert.assertEquals(0, resourceV2Net); Assert.assertEquals(0, resourceV2Energy); resourceUsage(contractAddress58, contractAddress); - //todo : calculate usage (contract and receiver) + // todo : calculate usage (contract and receiver) } - @Test(description = "", groups = {"daily", "serial"}) + @Test( + description = "", + groups = {"daily", "serial"}) void test15Create2ContractFreezeDelegate() { create2NewFreezeContract(); onlyFreeze(create2AddBytes, frozenAmountCreate2 * 2); @@ -547,21 +874,23 @@ void test15Create2ContractFreezeDelegate() { onlyUndelegate(create2AddBytes, testAddress002, 1, frozenAmountCreate2); } - @Test(description = "vote and resource transfer to receiver if contract destroy", groups = {"daily", "serial"}) + @Test( + description = "vote and resource transfer to receiver if contract destroy", + groups = {"daily", "serial"}) void test16KillCreate2Add() { String witnessTT1 = "TT1smsmhxype64boboU8xTuNZVCKP1w6qT"; - String witnessTB4 = "TB4B1RMhoPeivkj4Hebm6tttHjRY9yQFes"; - String args = "[\"" + witnessTT1 + "\",\"" + witnessTB4 + "\"],[2,2]"; + String witnessTB4 = "TB4B1RMhoPeivkj4Hebm6tttHjRY9yQFes"; + String args = "[\"" + witnessTT1 + "\",\"" + witnessTB4 + "\"],[2,2]"; voteWitness(create2AddBytes, args); - ECKey ecKey = new ECKey(Utils.getRandom()); - byte[] testAddress = ecKey.getAddress(); - String testKey = ByteArray.toHexString(ecKey.getPrivKeyBytes()); + ECKey ecKey = new ECKey(Utils.getRandom()); + byte[] testAddress = ecKey.getAddress(); + String testKey = ByteArray.toHexString(ecKey.getPrivKeyBytes()); long balanceCon = PublicMethod.queryAccount(create2AddBytes, blockingStubFull).getBalance(); - AccountResourceMessage resource = + AccountResourceMessage resource = PublicMethod.getAccountResource(create2AddBytes, blockingStubFull); long netUsedCon = resource.getNetUsed(); long energyUsedCon = resource.getEnergyUsed(); - String txid = killCon(create2AddBytes, testAddress); + String txid = killCon(create2AddBytes, testAddress); TransactionInfo info0 = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("kill info0: " + info0.toString()); Assert.assertEquals(code.SUCESS, info0.getResult()); @@ -571,20 +900,27 @@ void test16KillCreate2Add() { long netUsedReceiver = resource.getNetUsed(); long energyUsedReceiver = resource.getEnergyUsed(); - logger.info("netUsedCon: " + netUsedCon + " energyUsedCon: " + energyUsedCon - + "\nnetUsedReceiver: " + netUsedReceiver + " energyUsedReceiver: " + energyUsedReceiver); + logger.info( + "netUsedCon: " + + netUsedCon + + " energyUsedCon: " + + energyUsedCon + + "\nnetUsedReceiver: " + + netUsedReceiver + + " energyUsedReceiver: " + + energyUsedReceiver); Account receiverAccount = PublicMethod.queryAccount(testAddress, blockingStubFull); long balanceReceiver = receiverAccount.getBalance(); Assert.assertEquals(balanceCon, balanceReceiver); List li = receiverAccount.getVotesList(); Assert.assertEquals(0, li.size()); Account killCreate2 = PublicMethod.queryAccount(create2AddBytes, blockingStubFull); - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { Assert.assertEquals(0L, killCreate2.getBalance()); Assert.assertEquals(0L, killCreate2.getFrozenV2(0).getAmount()); Assert.assertEquals(0L, killCreate2.getFrozenV2(1).getAmount()); Assert.assertEquals(0L, killCreate2.getFrozenV2(2).getAmount()); - }else { + } else { String str = killCreate2.toString(); Assert.assertEquals("", str); } @@ -594,21 +930,32 @@ void test16KillCreate2Add() { Assert.assertTrue(receiverAccount.getAccountResource().getEnergyUsage() > 0); } - @Test(enabled = true, description = "", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "", + groups = {"daily", "serial"}) void test17withdrawExpireUnfreeze() { long expireUnfreezeBalance = getExpireUnfreezeBalanceV2(contractAddress, contractAddress58); Assert.assertEquals(1000000, expireUnfreezeBalance); long balanceBefore = PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); - String methedStr = "withdrawExpireUnfreeze()"; - String argsStr = "#"; - String txid = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String methedStr = "withdrawExpireUnfreeze()"; + String argsStr = "#"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); Assert.assertEquals(code.SUCESS, info.getResult()); Assert.assertEquals(contractResult.SUCCESS, info.getReceipt().getResult()); - long withdrawAmount = - ByteArray.toLong(info.getContractResult(0).toByteArray()); + long withdrawAmount = ByteArray.toLong(info.getContractResult(0).toByteArray()); logger.info("withdrawAmount: " + withdrawAmount); Assert.assertEquals(expireUnfreezeBalance, withdrawAmount); @@ -617,17 +964,28 @@ void test17withdrawExpireUnfreeze() { Assert.assertEquals(balanceAfter, balanceBefore + withdrawAmount); } - @Test(description = "Unfreeze Trigger Portial Unvote", groups = {"daily", "serial"}) + @Test( + description = "Unfreeze Trigger Portial Unvote", + groups = {"daily", "serial"}) void test18UnfreezeTriggerPortialUnvote() { String witnessTT1 = "TT1smsmhxype64boboU8xTuNZVCKP1w6qT"; - String witnessTB4 = "TB4B1RMhoPeivkj4Hebm6tttHjRY9yQFes"; - String args = "[\"" + witnessTT1 + "\",\"" + witnessTB4 + "\"],[200,200]"; + String witnessTB4 = "TB4B1RMhoPeivkj4Hebm6tttHjRY9yQFes"; + String args = "[\"" + witnessTT1 + "\",\"" + witnessTB4 + "\"],[200,200]"; voteWitness(contractAddress, args); withdrawReward(contractAddress); - String methedStr = "unfreezeBalanceV2(uint256,uint256)"; - String argsStr = "10000000,0"; - String txid = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String methedStr = "unfreezeBalanceV2(uint256,uint256)"; + String argsStr = "10000000,0"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("unfreeze 10trx to unvote info: " + info.toString()); @@ -640,22 +998,42 @@ void test18UnfreezeTriggerPortialUnvote() { Assert.assertEquals(195, li.get(1).getVoteCount()); } - @Test(enabled = true, description = "unfreeze list's max size is 32", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "unfreeze list's max size is 32", + groups = {"daily", "serial"}) void test19UnfreezeToMaxSize() { String methedStr = "unfreezeBalanceV2(uint256,uint256)"; - String argsStr = ",1"; + String argsStr = ",1"; for (int i = 0; i < 33; i++) { String argsStr1 = i + argsStr; - PublicMethod.triggerContract(contractAddress, methedStr, argsStr1, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr1, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); } PublicMethod.waitProduceNextBlock(blockingStubFull); long size = getAvailableUnfreezeV2Size(contractAddress, contractAddress58); Assert.assertEquals(0, size); long expireUnfreezeBalance = getExpireUnfreezeBalanceV2(contractAddress, contractAddress58); Assert.assertEquals(0, expireUnfreezeBalance); - String txid = PublicMethod.triggerContract(contractAddress, methedStr, 1 + argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + 1 + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); @@ -664,28 +1042,51 @@ void test19UnfreezeToMaxSize() { Assert.assertEquals(contractResult.REVERT, info.getReceipt().getResult()); } - @Test(enabled = true, description = "", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "", + groups = {"daily", "serial"}) void test20CannotKillWithUnfreeze() { String methedStr = "killme(address)"; - String argsStr = "\"" + Base58.encode58Check(testAddress002) + "\""; - String txid = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testFoundationAddress, testFoundationKey, blockingStubFull); + String argsStr = "\"" + Base58.encode58Check(testAddress002) + "\""; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); logger.info("kill me revert WithUnfreeze txid: " + txid); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); Assert.assertEquals(code.FAILED, info.getResult()); Assert.assertEquals(contractResult.REVERT, info.getReceipt().getResult()); - } - @Test(enabled = true, description = "cancel all unfreeze", groups = {"daily", "serial"}) + @Test( + enabled = true, + description = "cancel all unfreeze", + groups = {"daily", "serial"}) void test21CancelUnfreeze() { long size = getAvailableUnfreezeV2Size(contractAddress, contractAddress58); Assert.assertEquals(0, size); - String methedStr = "cancelAllUnfreezeV2()"; - String argsStr = "#"; - String txid = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String methedStr = "cancelAllUnfreezeV2()"; + String argsStr = "#"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); @@ -693,41 +1094,56 @@ void test21CancelUnfreeze() { Assert.assertEquals(code.SUCESS, info.getResult()); Assert.assertEquals(contractResult.SUCCESS, info.getReceipt().getResult()); Assert.assertTrue(info.getInternalTransactions(0).toString().contains("extra")); - Assert.assertEquals("cancelAllUnfreezeV2", info.getInternalTransactions(0).getNote().toStringUtf8()); + Assert.assertEquals( + "cancelAllUnfreezeV2", info.getInternalTransactions(0).getNote().toStringUtf8()); size = getAvailableUnfreezeV2Size(contractAddress, contractAddress58); Assert.assertEquals(32, size); } - @Test(description = "", groups = {"daily", "serial"}) + @Test( + description = "", + groups = {"daily", "serial"}) void test22GetChainParameters() { HashMap map = getResource(contractAddress58, blockingStubFull); long netTotalLimit = map.get("netTotalLimit"); long netTotalWeight = map.get("netTotalWeight"); long energyTotalLimit = map.get("energyTotalLimit"); long energyTotalWeight = map.get("energyTotalWeight"); - String methedStr = "getChainParameters()"; - String argsStr = "#"; - - TransactionExtention exten = PublicMethod.triggerConstantContractForExtention( - contractAddress, methedStr, argsStr, false, 0, maxFeeLimit, - "#", 0, testFoundationAddress, testFoundationKey, blockingStubFull); - byte[] res = exten.getConstantResult(0).toByteArray(); - - long totalNetLimit = - ByteArray.toLong(ByteArray.subArray(res, 0, 32)); - long totalNetWeight = - ByteArray.toLong(ByteArray.subArray(res, 32, 64)); - long totalEnergyCurrentLimit = - ByteArray.toLong(ByteArray.subArray(res, 64, 96)); - long totalEnergyWeight = - ByteArray.toLong(ByteArray.subArray(res, 96, 128)); - long unfreezeDelayDays = - ByteArray.toLong(ByteArray.subArray(res, 128, 160)); - logger.info("totalNetLimit: " + totalNetLimit + " \ntotalNetWeight: " + totalNetWeight - + " \ntotalEnergyCurrentLimit: " + totalEnergyCurrentLimit - + " \ntotalEnergyWeight: " + totalEnergyWeight - + " \nunfreezeDelayDays: " + unfreezeDelayDays); + String methedStr = "getChainParameters()"; + String argsStr = "#"; + + TransactionExtention exten = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testFoundationAddress, + testFoundationKey, + blockingStubFull); + byte[] res = exten.getConstantResult(0).toByteArray(); + + long totalNetLimit = ByteArray.toLong(ByteArray.subArray(res, 0, 32)); + long totalNetWeight = ByteArray.toLong(ByteArray.subArray(res, 32, 64)); + long totalEnergyCurrentLimit = ByteArray.toLong(ByteArray.subArray(res, 64, 96)); + long totalEnergyWeight = ByteArray.toLong(ByteArray.subArray(res, 96, 128)); + long unfreezeDelayDays = ByteArray.toLong(ByteArray.subArray(res, 128, 160)); + logger.info( + "totalNetLimit: " + + totalNetLimit + + " \ntotalNetWeight: " + + totalNetWeight + + " \ntotalEnergyCurrentLimit: " + + totalEnergyCurrentLimit + + " \ntotalEnergyWeight: " + + totalEnergyWeight + + " \nunfreezeDelayDays: " + + unfreezeDelayDays); Assert.assertEquals(netTotalLimit, totalNetLimit); Assert.assertEquals(netTotalWeight, totalNetWeight); @@ -736,17 +1152,37 @@ void test22GetChainParameters() { Assert.assertEquals(1, unfreezeDelayDays); } - @Test(description = "", groups = {"daily", "serial"}) - void test23UnfreezeAll(){ + @Test( + description = "", + groups = {"daily", "serial"}) + void test23UnfreezeAll() { long net = getDelegatableResource(contractAddress58, contractAddress58, 0); long energy = getDelegatableResource(contractAddress58, contractAddress58, 1); - String methedStr = "unfreezeBalanceV2(uint256,uint256)"; - String argsStr = net + ",0"; - String txid = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String methedStr = "unfreezeBalanceV2(uint256,uint256)"; + String argsStr = net + ",0"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); argsStr = energy + ",1"; - String txid1 = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("unfreeze all net info: " + info.toString()); @@ -759,84 +1195,145 @@ void test23UnfreezeAll(){ Assert.assertEquals(contractResult.SUCCESS, info.getReceipt().getResult()); } - String killCon(byte[] con, byte[] receiverAdd) { String receiver = Base58.encode58Check(receiverAdd); - String methedStr = "killme(address)"; - String argsStr = "\"" + receiver + "\""; - String txid = PublicMethod.triggerContract(con, methedStr, argsStr, - false, 0, maxFeeLimit, testFoundationAddress, testFoundationKey, blockingStubFull); + String methedStr = "killme(address)"; + String argsStr = "\"" + receiver + "\""; + String txid = + PublicMethod.triggerContract( + con, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); return txid; - } - public void voteWitness(byte[] con, String args) { logger.info("vote args: " + args); - String methodStr = "voteWitness(address[],uint256[])"; - String triggerTxid = PublicMethod.triggerContract(con, methodStr, args, false, - 0, maxFeeLimit, testFoundationAddress, testFoundationKey, blockingStubFull); + String methodStr = "voteWitness(address[],uint256[])"; + String triggerTxid = + PublicMethod.triggerContract( + con, + methodStr, + args, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull).get(); + TransactionInfo transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull).get(); Assert.assertEquals(0, transactionInfo.getResultValue()); - Assert.assertEquals(contractResult.SUCCESS, - transactionInfo.getReceipt().getResult()); - Assert.assertEquals("voteWitness", transactionInfo.getInternalTransactions(0).getNote().toStringUtf8()); + Assert.assertEquals(contractResult.SUCCESS, transactionInfo.getReceipt().getResult()); + Assert.assertEquals( + "voteWitness", transactionInfo.getInternalTransactions(0).getNote().toStringUtf8()); logger.info("transactionInfo: " + transactionInfo.toString()); } public void withdrawReward(byte[] con) { String methodStr = "withdrawReward()"; - String triggerTxid = PublicMethod.triggerContract(con, methodStr, "#", false, - 0, maxFeeLimit, testFoundationAddress, testFoundationKey, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + con, + methodStr, + "#", + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull).get(); + TransactionInfo transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull).get(); Assert.assertEquals(0, transactionInfo.getResultValue()); - Assert.assertEquals(contractResult.SUCCESS, - transactionInfo.getReceipt().getResult()); - + Assert.assertEquals(contractResult.SUCCESS, transactionInfo.getReceipt().getResult()); } - void create2NewFreezeContract() { String methedStr = "getPredictedAddress(bytes32)"; - String argsStr = "1232"; - GrpcAPI.TransactionExtention transactionExtention = - PublicMethod.triggerConstantContractForExtention(contractAddressD, methedStr, argsStr, - false, 0, maxFeeLimit, "0", 0, testFoundationAddress, testFoundationKey, blockingStubFull); + String argsStr = "1232"; + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddressD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "0", + 0, + testFoundationAddress, + testFoundationKey, + blockingStubFull); logger.info("getPredictedAddress transactionExtention: " + transactionExtention.toString()); - create2Add41 = "41" + ByteArray.toHexString(transactionExtention.getConstantResult(0) - .toByteArray()).substring(24); + create2Add41 = + "41" + + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()) + .substring(24); create2AddBytes = ByteArray.fromHexString(create2Add41); create2Add58 = Base58.encode58Check(create2AddBytes); - PublicMethod.sendcoin(create2AddBytes, 100000000, testFoundationAddress, testFoundationKey, blockingStubFull); + PublicMethod.sendcoin( + create2AddBytes, 100000000, testFoundationAddress, testFoundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); methedStr = "createDSalted(bytes32)"; - PublicMethod.triggerContract(contractAddressD, methedStr, argsStr, - false, 0, maxFeeLimit, testFoundationAddress, testFoundationKey, blockingStubFull); + PublicMethod.triggerContract( + contractAddressD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(create2AddBytes, blockingStubFull); -// Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(create2AddBytes, blockingStubFull); + // Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); } void onlyFreeze(byte[] con, long amount) { - logger.info("onlyFreeze con: " + PublicMethod.queryAccount(con, blockingStubFull).toString()); - String methedStr = "freezeBalanceV2(uint256,uint256)"; - String argsStr = amount + ",0"; - String txid = PublicMethod.triggerContract(con, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + logger.info("onlyFreeze con: " + PublicMethod.queryAccount(con, blockingStubFull).toString()); + String methedStr = "freezeBalanceV2(uint256,uint256)"; + String argsStr = amount + ",0"; + String txid = + PublicMethod.triggerContract( + con, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); argsStr = amount + ",1"; - String txid1 = PublicMethod.triggerContract(con, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + con, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); @@ -851,13 +1348,22 @@ void onlyFreeze(byte[] con, long amount) { void onlyDelegate(byte[] con, byte[] receiverAdd, int type, long amount) { String receiver = Base58.encode58Check(receiverAdd); - String methedStr = "delegateResource(uint256,uint256,address)"; - String argsStr = amount + "," + type + ",\"" + receiver + "\""; - //delegate net + String methedStr = "delegateResource(uint256,uint256,address)"; + String argsStr = amount + "," + type + ",\"" + receiver + "\""; + // delegate net logger.info("methedStr: " + methedStr); logger.info("argsStr: " + argsStr); - String txid = PublicMethod.triggerContract(con, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String txid = + PublicMethod.triggerContract( + con, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("delegate net info: " + info.toString()); @@ -867,10 +1373,19 @@ void onlyDelegate(byte[] con, byte[] receiverAdd, int type, long amount) { void onlyUndelegate(byte[] con, byte[] receiverAdd, int type, long amount) { String methedStr = "unDelegateResource(uint256,uint256,address)"; - String receiver = Base58.encode58Check(receiverAdd); - String argsStr = amount + "," + type + ",\"" + receiver + "\""; - String txid0 = PublicMethod.triggerContract(con, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String receiver = Base58.encode58Check(receiverAdd); + String argsStr = amount + "," + type + ",\"" + receiver + "\""; + String txid0 = + PublicMethod.triggerContract( + con, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info0 = PublicMethod.getTransactionInfoById(txid0, blockingStubFull).get(); @@ -879,18 +1394,27 @@ void onlyUndelegate(byte[] con, byte[] receiverAdd, int type, long amount) { Assert.assertEquals(contractResult.SUCCESS, info0.getReceipt().getResult()); } - // @Test(description = "test Available UnfreezeV2 Size", groups = {"daily", "serial"}) long getAvailableUnfreezeV2Size(byte[] con, String queryAdd) { String methedStr = "getAvailableUnfreezeV2Size(address)"; - String argsStr = "\"" + queryAdd + "\""; - - TransactionExtention exten = PublicMethod.triggerConstantContractForExtention( - con, methedStr, argsStr, false, 0, maxFeeLimit, - "#", 0, testFoundationAddress, testFoundationKey, blockingStubFull); + String argsStr = "\"" + queryAdd + "\""; + + TransactionExtention exten = + PublicMethod.triggerConstantContractForExtention( + con, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testFoundationAddress, + testFoundationKey, + blockingStubFull); long unfreezeSize = ByteArray.toLong(exten.getConstantResult(0).toByteArray()); -// logger.info("unfreezeSize: " + unfreezeSize); + // logger.info("unfreezeSize: " + unfreezeSize); return unfreezeSize; } @@ -898,13 +1422,22 @@ long getAvailableUnfreezeV2Size(byte[] con, String queryAdd) { public long getUnfreezableBalanceV2(byte[] con, String queryAdd, String type) { String methedStr = "getUnfreezableBalanceV2(address,uint256)"; - String argsStr = "\"" + queryAdd + "\"," + type; - - TransactionExtention exten = PublicMethod.triggerConstantContractForExtention( - con, methedStr, argsStr, false, 0, maxFeeLimit, - "#", 0, testFoundationAddress, testFoundationKey, blockingStubFull); - long unfreezableBalance = - ByteArray.toLong(exten.getConstantResult(0).toByteArray()); + String argsStr = "\"" + queryAdd + "\"," + type; + + TransactionExtention exten = + PublicMethod.triggerConstantContractForExtention( + con, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testFoundationAddress, + testFoundationKey, + blockingStubFull); + long unfreezableBalance = ByteArray.toLong(exten.getConstantResult(0).toByteArray()); logger.info("unfreezableBalanceNet: " + unfreezableBalance); return unfreezableBalance; } @@ -912,14 +1445,23 @@ public long getUnfreezableBalanceV2(byte[] con, String queryAdd, String type) { // @Test(description = "", groups = {"daily", "serial"}) long getExpireUnfreezeBalanceV2(byte[] con, String queryAdd) { String methedStr = "getExpireUnfreezeBalanceV2(address,uint256)"; - String argsStr = "\"" + queryAdd + "\"," + System.currentTimeMillis() / 1000; + String argsStr = "\"" + queryAdd + "\"," + System.currentTimeMillis() / 1000; logger.info("argsStr: " + argsStr); - TransactionExtention exten = PublicMethod.triggerConstantContractForExtention( - con, methedStr, argsStr, false, 0, maxFeeLimit, - "#", 0, testFoundationAddress, testFoundationKey, blockingStubFull); - - long ExpireUnfreezeBalance = - ByteArray.toLong(exten.getConstantResult(0).toByteArray()); + TransactionExtention exten = + PublicMethod.triggerConstantContractForExtention( + con, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testFoundationAddress, + testFoundationKey, + blockingStubFull); + + long ExpireUnfreezeBalance = ByteArray.toLong(exten.getConstantResult(0).toByteArray()); logger.info("ExpireUnfreezeBalance: " + ExpireUnfreezeBalance); return ExpireUnfreezeBalance; } @@ -927,31 +1469,49 @@ long getExpireUnfreezeBalanceV2(byte[] con, String queryAdd) { // @Test(description = "(limit-use)/limit*freezeAmount", groups = {"daily", "serial"}) public long getDelegatableResource(String con, String queryAdd, int type) { String methedStr = "getDelegatableResource(address,uint256)"; - String argsStr = "\"" + queryAdd + "\"," + type; - byte[] contract = PublicMethod.decode58Check(con); - TransactionExtention exten = PublicMethod.triggerConstantContractForExtention( - contract, methedStr, argsStr, false, 0, maxFeeLimit, - "#", 0, testFoundationAddress, testFoundationKey, blockingStubFull); - byte[] res = exten.getConstantResult(0).toByteArray(); - long delegatableResource = - ByteArray.toLong(ByteArray.subArray(res, 0, 32)); + String argsStr = "\"" + queryAdd + "\"," + type; + byte[] contract = PublicMethod.decode58Check(con); + TransactionExtention exten = + PublicMethod.triggerConstantContractForExtention( + contract, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testFoundationAddress, + testFoundationKey, + blockingStubFull); + byte[] res = exten.getConstantResult(0).toByteArray(); + long delegatableResource = ByteArray.toLong(ByteArray.subArray(res, 0, 32)); logger.info("delegatable " + type + " : " + delegatableResource); return delegatableResource; - } - // @Test(description = "equal with api wallet/getdelegatedresourcev2", groups = {"daily", "serial"}) + // @Test(description = "equal with api wallet/getdelegatedresourcev2", groups = {"daily", + // "serial"}) long getResourceV2(String fromAdd, String receiveAdd, String type, byte[] con) { String methedStr = "getResourceV2(address,address,uint256)"; - String argsStr = "\"" + receiveAdd + "\",\"" + fromAdd + "\"," + type; - - TransactionExtention exten = PublicMethod.triggerConstantContractForExtention( - con, methedStr, argsStr, false, 0, maxFeeLimit, - "#", 0, testFoundationAddress, testFoundationKey, blockingStubFull); - byte[] res = exten.getConstantResult(0).toByteArray(); - long delegatedResource = - ByteArray.toLong(ByteArray.subArray(res, 0, 32)); + String argsStr = "\"" + receiveAdd + "\",\"" + fromAdd + "\"," + type; + + TransactionExtention exten = + PublicMethod.triggerConstantContractForExtention( + con, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testFoundationAddress, + testFoundationKey, + blockingStubFull); + byte[] res = exten.getConstantResult(0).toByteArray(); + long delegatedResource = ByteArray.toLong(ByteArray.subArray(res, 0, 32)); logger.info("getResourceV2 delegatedResource: " + delegatedResource); return delegatedResource; @@ -959,22 +1519,29 @@ long getResourceV2(String fromAdd, String receiveAdd, String type, byte[] con) { // @Test(description = "how much can be undelegate", groups = {"daily", "serial"}) void checkUnDelegateResource(byte[] con, String receiveAdd, String type, long amount) { -// String amount = "1"; - String methedStr = "checkUnDelegateResource(address,uint256,uint256)"; - String argsStr = "\"" + receiveAdd + "\"," + amount + "," + type; - - TransactionExtention exten = PublicMethod.triggerConstantContractForExtention( - con, methedStr, argsStr, false, 0, maxFeeLimit, - "#", 0, testFoundationAddress, testFoundationKey, blockingStubFull); + // String amount = "1"; + String methedStr = "checkUnDelegateResource(address,uint256,uint256)"; + String argsStr = "\"" + receiveAdd + "\"," + amount + "," + type; + + TransactionExtention exten = + PublicMethod.triggerConstantContractForExtention( + con, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testFoundationAddress, + testFoundationKey, + blockingStubFull); HashMap map = getResource(receiveAdd, blockingStubFull); - byte[] res = exten.getConstantResult(0).toByteArray(); - long cleanAmount = - ByteArray.toLong(ByteArray.subArray(res, 0, 32)); - long dirtyAmount = - ByteArray.toLong(ByteArray.subArray(res, 32, 64)); - long storeTime = - ByteArray.toLong(ByteArray.subArray(res, 64, 96)); + byte[] res = exten.getConstantResult(0).toByteArray(); + long cleanAmount = ByteArray.toLong(ByteArray.subArray(res, 0, 32)); + long dirtyAmount = ByteArray.toLong(ByteArray.subArray(res, 32, 64)); + long storeTime = ByteArray.toLong(ByteArray.subArray(res, 64, 96)); long returnAmount = cleanAmount + dirtyAmount; long frozenBalanceV1 = 0; @@ -1006,30 +1573,47 @@ void checkUnDelegateResource(byte[] con, String receiveAdd, String type, long am } long sumNetFrozen = frozenBalanceV1 + frozenBalanceV2 + acquiredBalanceV1 + acquiredBalanceV2; - long recycleNet = (long)((double)used * totalWeight * 1000000 / totalLimit ); - long cleanSun = (long) ( amount* ((double)(sumNetFrozen-recycleNet) / sumNetFrozen )); + long recycleNet = (long) ((double) used * totalWeight * 1000000 / totalLimit); + long cleanSun = (long) (amount * ((double) (sumNetFrozen - recycleNet) / sumNetFrozen)); long dirtySun = amount - cleanSun; - logger.info("storeTime: " + storeTime/3 + " windowSize: " + windowSize); - logger.info("clean amount net: " + cleanAmount + " dirty amount net: " + dirtyAmount + ": sum: " - + returnAmount + " compute cleanSun: " + cleanSun + " compute dirtySun: " + dirtySun); + logger.info("storeTime: " + storeTime / 3 + " windowSize: " + windowSize); + logger.info( + "clean amount net: " + + cleanAmount + + " dirty amount net: " + + dirtyAmount + + ": sum: " + + returnAmount + + " compute cleanSun: " + + cleanSun + + " compute dirtySun: " + + dirtySun); Assert.assertEquals(amount, returnAmount); -// Assert.assertEquals(cleanAmount, cleanSun); -// Assert.assertEquals(dirtyAmount, dirtySun); - + // Assert.assertEquals(cleanAmount, cleanSun); + // Assert.assertEquals(dirtyAmount, dirtySun); } // @Test(description = "", groups = {"daily", "serial"}) void resourceUsage(String queryAdd, byte[] con) { String methedStr = "getResourceUsage(address,uint256)"; - String argsStr = "\"" + queryAdd + "\",0"; - - TransactionExtention exten = PublicMethod.triggerConstantContractForExtention( - con, methedStr, argsStr, false, 0, maxFeeLimit, - "#", 0, testFoundationAddress, testFoundationKey, blockingStubFull); - byte[] res = exten.getConstantResult(0).toByteArray(); - long usageAmount = - ByteArray.toLong(ByteArray.subArray(res, 0, 32)); + String argsStr = "\"" + queryAdd + "\",0"; + + TransactionExtention exten = + PublicMethod.triggerConstantContractForExtention( + con, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testFoundationAddress, + testFoundationKey, + blockingStubFull); + byte[] res = exten.getConstantResult(0).toByteArray(); + long usageAmount = ByteArray.toLong(ByteArray.subArray(res, 0, 32)); HashMap map = getResource(queryAdd, blockingStubFull); long netTotalWeight = map.get("netTotalWeight"); @@ -1038,21 +1622,46 @@ void resourceUsage(String queryAdd, byte[] con) { long energyTotalWeight = map.get("energyTotalWeight"); long energyTotalLimit = map.get("energyTotalLimit"); long energyUsed = map.get("energyUsed"); - logger.info(netTotalWeight + " : " + netTotalLimit + " : " + netUsed + " : " + energyTotalWeight - + " : " + energyTotalLimit + " : " + energyUsed); - logger.info("ResourceUsage net: " + usageAmount + " : " - + netUsed * netTotalWeight / netTotalLimit * 1000000); + logger.info( + netTotalWeight + + " : " + + netTotalLimit + + " : " + + netUsed + + " : " + + energyTotalWeight + + " : " + + energyTotalLimit + + " : " + + energyUsed); + logger.info( + "ResourceUsage net: " + + usageAmount + + " : " + + netUsed * netTotalWeight / netTotalLimit * 1000000); argsStr = "\"" + queryAdd + "\",1"; - exten = PublicMethod.triggerConstantContractForExtention( - con, methedStr, argsStr, false, 0, maxFeeLimit, - "#", 0, testFoundationAddress, testFoundationKey, blockingStubFull); + exten = + PublicMethod.triggerConstantContractForExtention( + con, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testFoundationAddress, + testFoundationKey, + blockingStubFull); res = exten.getConstantResult(0).toByteArray(); - usageAmount = - ByteArray.toLong(ByteArray.subArray(res, 0, 32)); - - logger.info("ResourceUsage energy: " + usageAmount + " : " + energyUsed * energyTotalWeight / energyTotalLimit * 1000000); + usageAmount = ByteArray.toLong(ByteArray.subArray(res, 0, 32)); + logger.info( + "ResourceUsage energy: " + + usageAmount + + " : " + + energyUsed * energyTotalWeight / energyTotalLimit * 1000000); } // @Test(description = "return freeze plus acquired", groups = {"daily", "serial"}) @@ -1066,116 +1675,220 @@ void getTotalResource(String queryAdd, String con) { long energyFrozenBalanceV2 = map.get("energyFrozenBalanceV2"); long energyAcquiredBalanceV1 = map.get("energyAcquiredBalanceV1"); long energyAcquiredBalanceV2 = map.get("energyAcquiredBalanceV2"); - String methedStr = "getTotalResource(address,uint256)"; - String argsStr = "\"" + queryAdd + "\",0"; - byte[] contract = PublicMethod.decode58Check(con); - - TransactionExtention exten = PublicMethod.triggerConstantContractForExtention( - contract, methedStr, argsStr, false, 0, maxFeeLimit, - "#", 0, testFoundationAddress, testFoundationKey, blockingStubFull); - byte[] res = exten.getConstantResult(0).toByteArray(); - long resourceAmount = - ByteArray.toLong(ByteArray.subArray(res, 0, 32)); - - logger.info("resourceAmount net: " + resourceAmount + " netAcquiredBalanceV1: " + netAcquiredBalanceV1 - + " netAcquiredBalanceV2: " + netAcquiredBalanceV2 - + " netFrozenBalanceV1: " + netFrozenBalanceV1 + " netFrozenBalanceV2: " + netFrozenBalanceV2); - Assert.assertEquals(resourceAmount, netAcquiredBalanceV1 + netAcquiredBalanceV2 - + netFrozenBalanceV1 + netFrozenBalanceV2); + String methedStr = "getTotalResource(address,uint256)"; + String argsStr = "\"" + queryAdd + "\",0"; + byte[] contract = PublicMethod.decode58Check(con); + + TransactionExtention exten = + PublicMethod.triggerConstantContractForExtention( + contract, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testFoundationAddress, + testFoundationKey, + blockingStubFull); + byte[] res = exten.getConstantResult(0).toByteArray(); + long resourceAmount = ByteArray.toLong(ByteArray.subArray(res, 0, 32)); + + logger.info( + "resourceAmount net: " + + resourceAmount + + " netAcquiredBalanceV1: " + + netAcquiredBalanceV1 + + " netAcquiredBalanceV2: " + + netAcquiredBalanceV2 + + " netFrozenBalanceV1: " + + netFrozenBalanceV1 + + " netFrozenBalanceV2: " + + netFrozenBalanceV2); + Assert.assertEquals( + resourceAmount, + netAcquiredBalanceV1 + netAcquiredBalanceV2 + netFrozenBalanceV1 + netFrozenBalanceV2); argsStr = "\"" + queryAdd + "\",1"; - exten = PublicMethod.triggerConstantContractForExtention( - contract, methedStr, argsStr, false, 0, maxFeeLimit, - "#", 0, testFoundationAddress, testFoundationKey, blockingStubFull); + exten = + PublicMethod.triggerConstantContractForExtention( + contract, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testFoundationAddress, + testFoundationKey, + blockingStubFull); res = exten.getConstantResult(0).toByteArray(); - resourceAmount = - ByteArray.toLong(ByteArray.subArray(res, 0, 32)); - - - logger.info("resourceAmount energy: " + resourceAmount - + " energyFrozenBalanceV1: " + energyFrozenBalanceV1 + "energyFrozenBalanceV2: " - + energyFrozenBalanceV2 + " energyAcquiredBalanceV1: " + energyAcquiredBalanceV1 - + " energyAcquiredBalanceV2: " + energyAcquiredBalanceV2); - Assert.assertEquals(resourceAmount, energyFrozenBalanceV1 + energyFrozenBalanceV2 - + energyAcquiredBalanceV1 + energyAcquiredBalanceV2); - + resourceAmount = ByteArray.toLong(ByteArray.subArray(res, 0, 32)); + + logger.info( + "resourceAmount energy: " + + resourceAmount + + " energyFrozenBalanceV1: " + + energyFrozenBalanceV1 + + "energyFrozenBalanceV2: " + + energyFrozenBalanceV2 + + " energyAcquiredBalanceV1: " + + energyAcquiredBalanceV1 + + " energyAcquiredBalanceV2: " + + energyAcquiredBalanceV2); + Assert.assertEquals( + resourceAmount, + energyFrozenBalanceV1 + + energyFrozenBalanceV2 + + energyAcquiredBalanceV1 + + energyAcquiredBalanceV2); } - // @Test(description = "get the amount that has been delegated to others", groups = {"daily", "serial"}) + // @Test(description = "get the amount that has been delegated to others", groups = {"daily", + // "serial"}) void getTotalDelegatedResource(String queryAdd, String con) { String methedStr = "getTotalDelegatedResource(address,uint256)"; - String argsStr = "\"" + queryAdd + "\",0"; - byte[] contract = PublicMethod.decode58Check(con); - - TransactionExtention exten = PublicMethod.triggerConstantContractForExtention( - contract, methedStr, argsStr, false, 0, maxFeeLimit, - "#", 0, testFoundationAddress, testFoundationKey, blockingStubFull); - byte[] res = exten.getConstantResult(0).toByteArray(); - long delegatedAmount = - ByteArray.toLong(ByteArray.subArray(res, 0, 32)); - long accountDelegateV2 = PublicMethod.queryAccount(PublicMethod.decode58Check(queryAdd), blockingStubFull) - .getDelegatedFrozenV2BalanceForBandwidth(); - long accountDelegateV1 = PublicMethod.queryAccount(PublicMethod.decode58Check(queryAdd), blockingStubFull) - .getDelegatedFrozenBalanceForBandwidth(); - logger.info("delegatedAmount net: " + delegatedAmount + " accountDelegateV2: " + accountDelegateV2 - + " accountDelegateV1: " + accountDelegateV1); + String argsStr = "\"" + queryAdd + "\",0"; + byte[] contract = PublicMethod.decode58Check(con); + + TransactionExtention exten = + PublicMethod.triggerConstantContractForExtention( + contract, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testFoundationAddress, + testFoundationKey, + blockingStubFull); + byte[] res = exten.getConstantResult(0).toByteArray(); + long delegatedAmount = ByteArray.toLong(ByteArray.subArray(res, 0, 32)); + long accountDelegateV2 = + PublicMethod.queryAccount(PublicMethod.decode58Check(queryAdd), blockingStubFull) + .getDelegatedFrozenV2BalanceForBandwidth(); + long accountDelegateV1 = + PublicMethod.queryAccount(PublicMethod.decode58Check(queryAdd), blockingStubFull) + .getDelegatedFrozenBalanceForBandwidth(); + logger.info( + "delegatedAmount net: " + + delegatedAmount + + " accountDelegateV2: " + + accountDelegateV2 + + " accountDelegateV1: " + + accountDelegateV1); Assert.assertEquals(delegatedAmount, accountDelegateV2 + accountDelegateV1); argsStr = "\"" + queryAdd + "\",1"; - exten = PublicMethod.triggerConstantContractForExtention( - contract, methedStr, argsStr, false, 0, maxFeeLimit, - "#", 0, testFoundationAddress, testFoundationKey, blockingStubFull); + exten = + PublicMethod.triggerConstantContractForExtention( + contract, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testFoundationAddress, + testFoundationKey, + blockingStubFull); res = exten.getConstantResult(0).toByteArray(); - delegatedAmount = - ByteArray.toLong(ByteArray.subArray(res, 0, 32)); - accountDelegateV2 = PublicMethod.queryAccount(PublicMethod.decode58Check(queryAdd), blockingStubFull) - .getAccountResource().getDelegatedFrozenV2BalanceForEnergy(); - accountDelegateV1 = PublicMethod.queryAccount(PublicMethod.decode58Check(queryAdd), blockingStubFull) - .getAccountResource().getDelegatedFrozenBalanceForEnergy(); - logger.info("delegatedAmount energy: " + delegatedAmount + " accountDelegateV2: " + accountDelegateV2 - + " accountDelegateV1: " + accountDelegateV1); + delegatedAmount = ByteArray.toLong(ByteArray.subArray(res, 0, 32)); + accountDelegateV2 = + PublicMethod.queryAccount(PublicMethod.decode58Check(queryAdd), blockingStubFull) + .getAccountResource() + .getDelegatedFrozenV2BalanceForEnergy(); + accountDelegateV1 = + PublicMethod.queryAccount(PublicMethod.decode58Check(queryAdd), blockingStubFull) + .getAccountResource() + .getDelegatedFrozenBalanceForEnergy(); + logger.info( + "delegatedAmount energy: " + + delegatedAmount + + " accountDelegateV2: " + + accountDelegateV2 + + " accountDelegateV1: " + + accountDelegateV1); Assert.assertEquals(delegatedAmount, accountDelegateV2 + accountDelegateV1); } - void getTotalAcquiredResource(byte[] con, String queryAdd) { String methedStr = "getTotalAcquiredResource(address,uint256)"; - String argsStr = "\"" + queryAdd + "\",0"; - TransactionExtention exten = PublicMethod.triggerConstantContractForExtention( - con, methedStr, argsStr, false, 0, maxFeeLimit, - "#", 0, testFoundationAddress, testFoundationKey, blockingStubFull); - byte[] res = exten.getConstantResult(0).toByteArray(); - long acquiredAmount = - ByteArray.toLong(ByteArray.subArray(res, 0, 32)); + String argsStr = "\"" + queryAdd + "\",0"; + TransactionExtention exten = + PublicMethod.triggerConstantContractForExtention( + con, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testFoundationAddress, + testFoundationKey, + blockingStubFull); + byte[] res = exten.getConstantResult(0).toByteArray(); + long acquiredAmount = ByteArray.toLong(ByteArray.subArray(res, 0, 32)); HashMap map = getResource(queryAdd, blockingStubFull); long accountAcquiredV1 = map.get("netAcquiredBalanceV1"); long accountAcquiredV2 = map.get("netAcquiredBalanceV2"); -// long accountAcquiredV2 = PublicMethod.queryAccount(PublicMethod.decode58Check(queryAdd),blockingStubFull).getAcquiredDelegatedFrozenV2BalanceForBandwidth(); -// long accountAcquiredV1 = PublicMethod.queryAccount(PublicMethod.decode58Check(queryAdd),blockingStubFull).getAcquiredDelegatedFrozenBalanceForBandwidth(); - logger.info("acquiredAmount net: " + acquiredAmount + " accountAcquiredV2: " + accountAcquiredV2 + " accountAcquiredV1: " + accountAcquiredV1); + // long accountAcquiredV2 = + // PublicMethod.queryAccount(PublicMethod.decode58Check(queryAdd),blockingStubFull) + // .getAcquiredDelegatedFrozenV2BalanceForBandwidth(); + // long accountAcquiredV1 = + // PublicMethod.queryAccount(PublicMethod.decode58Check(queryAdd),blockingStubFull) + // .getAcquiredDelegatedFrozenBalanceForBandwidth(); + logger.info( + "acquiredAmount net: " + + acquiredAmount + + " accountAcquiredV2: " + + accountAcquiredV2 + + " accountAcquiredV1: " + + accountAcquiredV1); Assert.assertEquals(acquiredAmount, accountAcquiredV2 + accountAcquiredV1); - argsStr = "\"" + queryAdd + "\",1"; - exten = PublicMethod.triggerConstantContractForExtention( - con, methedStr, argsStr, false, 0, maxFeeLimit, - "#", 0, testFoundationAddress, testFoundationKey, blockingStubFull); + exten = + PublicMethod.triggerConstantContractForExtention( + con, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testFoundationAddress, + testFoundationKey, + blockingStubFull); res = exten.getConstantResult(0).toByteArray(); - acquiredAmount = - ByteArray.toLong(ByteArray.subArray(res, 0, 32)); + acquiredAmount = ByteArray.toLong(ByteArray.subArray(res, 0, 32)); accountAcquiredV1 = map.get("energyAcquiredBalanceV1"); accountAcquiredV2 = map.get("energyAcquiredBalanceV2"); - logger.info("acquiredAmount energy: " + acquiredAmount + " accountAcquiredV2: " + accountAcquiredV2 + " accountAcquiredV1: " + accountAcquiredV1); + logger.info( + "acquiredAmount energy: " + + acquiredAmount + + " accountAcquiredV2: " + + accountAcquiredV2 + + " accountAcquiredV1: " + + accountAcquiredV1); Assert.assertEquals(acquiredAmount, accountAcquiredV2 + accountAcquiredV1); - } - - public HashMap getResource(String address, WalletGrpc.WalletBlockingStub blockingStub) { - AccountResourceMessage accountResource = PublicMethod.getAccountResource(PublicMethod.decode58Check(address), blockingStub); + public HashMap getResource( + String address, WalletGrpc.WalletBlockingStub blockingStub) { + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(PublicMethod.decode58Check(address), blockingStub); Account account = PublicMethod.queryAccount(PublicMethod.decode58Check(address), blockingStub); - long netFrozenBalanceV1 = account.getFrozenCount() != 0 ? account.getFrozen(0).getFrozenBalance() : 0; + long netFrozenBalanceV1 = + account.getFrozenCount() != 0 ? account.getFrozen(0).getFrozenBalance() : 0; List liV2 = account.getFrozenV2List(); long netFrozenBalanceV2 = 0; for (Account.FreezeV2 tmp : liV2) { @@ -1187,7 +1900,8 @@ public HashMap getResource(String address, WalletGrpc.WalletBlocki long netAcquiredBalanceV1 = account.getAcquiredDelegatedFrozenBalanceForBandwidth(); long netAcquiredBalanceV2 = account.getAcquiredDelegatedFrozenV2BalanceForBandwidth(); - long energyFrozenBalanceV1 = account.getAccountResource().getFrozenBalanceForEnergy().getFrozenBalance(); + long energyFrozenBalanceV1 = + account.getAccountResource().getFrozenBalanceForEnergy().getFrozenBalance(); long energyFrozenBalanceV2 = 0; for (Account.FreezeV2 tmp : liV2) { if (tmp.getType().getNumber() == 1) { @@ -1195,8 +1909,10 @@ public HashMap getResource(String address, WalletGrpc.WalletBlocki break; } } - long energyAcquiredBalanceV1 = account.getAccountResource().getAcquiredDelegatedFrozenBalanceForEnergy(); - long energyAcquiredBalanceV2 = account.getAccountResource().getAcquiredDelegatedFrozenV2BalanceForEnergy(); + long energyAcquiredBalanceV1 = + account.getAccountResource().getAcquiredDelegatedFrozenBalanceForEnergy(); + long energyAcquiredBalanceV2 = + account.getAccountResource().getAcquiredDelegatedFrozenV2BalanceForEnergy(); long netTotalWeight = accountResource.getTotalNetWeight(); long netTotalLimit = accountResource.getTotalNetLimit(); long netUsed = accountResource.getNetUsed(); @@ -1227,32 +1943,33 @@ public HashMap getResource(String address, WalletGrpc.WalletBlocki void consumeResource(byte[] con, long amount) { String methedStr = "testConsumeEnergy(int256,int256)"; - String argsStr = "1,1"; - for(int i = 0; i < 1; i++){ - PublicMethod.triggerContract(contractAddress, methedStr, argsStr, - false, 0, maxFeeLimit, testAddress002, testKey002, blockingStubFull); + String argsStr = "1,1"; + for (int i = 0; i < 1; i++) { + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress002, + testKey002, + blockingStubFull); } PublicMethod.waitProduceNextBlock(blockingStubFull); - checkUnDelegateResource(con, Base58.encode58Check(testAddress002), - "0", amount); - checkUnDelegateResource(con, Base58.encode58Check(testAddress002), - "1", amount); + checkUnDelegateResource(con, Base58.encode58Check(testAddress002), "0", amount); + checkUnDelegateResource(con, Base58.encode58Check(testAddress002), "1", amount); } -// public void printGetAccount(byte[] address, WalletGrpc.WalletBlockingStub full) { -// logger.info("----getaccount begin --address" + Base58.encode58Check(address)); -// logger.info(System.currentTimeMillis() + ""); -// logger.info(PublicMethod.queryAccount(address, full).toString()); -// logger.info(PublicMethod.getAccountResource(address, full).toString()); -// logger.info("----getaccount end----"); -// } + // public void printGetAccount(byte[] address, WalletGrpc.WalletBlockingStub full) { + // logger.info("----getaccount begin --address" + Base58.encode58Check(address)); + // logger.info(System.currentTimeMillis() + ""); + // logger.info(PublicMethod.queryAccount(address, full).toString()); + // logger.info(PublicMethod.getAccountResource(address, full).toString()); + // logger.info("----getaccount end----"); + // } - - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/separateExecution/TransactionFee001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/separateExecution/TransactionFee001.java index 26813869..ff64dd8e 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/separateExecution/TransactionFee001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/separateExecution/TransactionFee001.java @@ -28,8 +28,9 @@ import stest.tron.wallet.common.client.utils.Retry; import stest.tron.wallet.common.client.utils.Sha256Hash; import stest.tron.wallet.common.client.utils.TransactionUtils; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + // import org.tron.common.parameter.CommonParameter; @Slf4j @@ -71,19 +72,25 @@ public class TransactionFee001 extends TronBaseTest { @BeforeClass(enabled = true) public void beforeClass() { initPbftChannel(); - initSolidityChannel(); } + initSolidityChannel(); + } - @Test(enabled = true, retryAnalyzer = Retry.class, priority=2, description = "Test deploy contract with energy fee to sr", groups = {"daily", "serial"}) + @Test( + enabled = true, + retryAnalyzer = Retry.class, + priority = 2, + description = "Test deploy contract with energy fee to sr", + groups = {"daily", "serial"}) public void test01DeployContractEnergyFeeToSr() { Assert.assertTrue( PublicMethod.sendcoin( deployAddress, 20000000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode//contractLinkage003.sol"; - String contractName = "divideIHaveArgsReturnStorage"; + String filePath = "src/test/resources/soliditycode//contractLinkage003.sol"; + String contractName = "divideIHaveArgsReturnStorage"; HashMap retMap = null; - String code = null; - String abi = null; + String code = null; + String abi = null; retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); @@ -134,7 +141,7 @@ public void test01DeployContractEnergyFeeToSr() { .getBalance(); witness02Increase = witness02Allowance2 - witness02Allowance1; witness01Increase = witness01Allowance2 - witness01Allowance1; - // blackHoleIncrease = blackHoleBalance2 - blackHoleBalance1; + // blackHoleIncrease = blackHoleBalance2 - blackHoleBalance1; logger.info("----startNum:" + startNum + " endNum:" + endNum); logger.info( "====== witness02Allowance1 :" @@ -155,12 +162,10 @@ public void test01DeployContractEnergyFeeToSr() { PublicMethod.getAllowance2(startNum, endNum, blockingStubFull); Assert.assertTrue( - (Math.abs( - witnessAllowance.get(ByteArray.toHexString(witnessAddress)) - witness01Increase)) + (Math.abs(witnessAllowance.get(ByteArray.toHexString(witnessAddress)) - witness01Increase)) <= 2); Assert.assertTrue( - (Math.abs( - witnessAllowance.get(ByteArray.toHexString(witnessAddress2)) - witness02Increase)) + (Math.abs(witnessAllowance.get(ByteArray.toHexString(witnessAddress2)) - witness02Increase)) <= 2); Assert.assertEquals(blackHoleBalance1, blackHoleBalance2); Optional infoById = @@ -171,25 +176,31 @@ public void test01DeployContractEnergyFeeToSr() { } @Test( - enabled = true, priority=2, + enabled = true, + priority = 2, retryAnalyzer = Retry.class, description = "Test update account permission fee to black hole," - + "trans with multi sign and fee to sr", groups = {"daily", "serial"}) + + "trans with multi sign and fee to sr", + groups = {"daily", "serial"}) public void test02UpdateAccountPermissionAndMultiSiginTrans() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] ownerAddress = ecKey1.getAddress(); - final String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - ECKey tmpEcKey02 = new ECKey(Utils.getRandom()); - byte[] tmpAddr02 = tmpEcKey02.getAddress(); - final String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); + byte[] ownerAddress = ecKey1.getAddress(); + final String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + ECKey tmpEcKey02 = new ECKey(Utils.getRandom()); + byte[] tmpAddr02 = tmpEcKey02.getAddress(); + final String tmpKey02 = ByteArray.toHexString(tmpEcKey02.getPrivKeyBytes()); long needCoin = updateAccountPermissionFee * 2 + multiSignFee; Assert.assertTrue( PublicMethod.sendcoin( - ownerAddress, needCoin + 1_000_000, foundationAddress, foundationKey, blockingStubFull)); + ownerAddress, + needCoin + 1_000_000, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); PublicMethod.printAddress(ownerKey); PublicMethod.printAddress(tmpKey02); @@ -215,7 +226,7 @@ public void test02UpdateAccountPermissionAndMultiSiginTrans() { PublicMethod.queryAccount(WalletClient.decode58Check(blackHoleAdd), blockingStubFull) .getBalance(); beforeBurnTrxAmount = blockingStubFull.getBurnTrx(EmptyMessage.newBuilder().build()).getNum(); - String accountPermissionJson = + String accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner1\"," + "\"threshold\":1,\"keys\":[" + "{\"address\":\"" @@ -263,7 +274,7 @@ public void test02UpdateAccountPermissionAndMultiSiginTrans() { .getBalance(); witness02Increase = witness02Allowance2 - witness02Allowance1; witness01Increase = witness01Allowance2 - witness01Allowance1; - // blackHoleIncrease = blackHoleBalance2 - blackHoleBalance1; + // blackHoleIncrease = blackHoleBalance2 - blackHoleBalance1; logger.info("----startNum:" + startNum + " endNum:" + endNum); logger.info( "====== witness02Allowance1 :" @@ -284,12 +295,10 @@ public void test02UpdateAccountPermissionAndMultiSiginTrans() { PublicMethod.getAllowance2(startNum, endNum, blockingStubFull); Assert.assertTrue( - (Math.abs( - witnessAllowance.get(ByteArray.toHexString(witnessAddress)) - witness01Increase)) + (Math.abs(witnessAllowance.get(ByteArray.toHexString(witnessAddress)) - witness01Increase)) <= 2); Assert.assertTrue( - (Math.abs( - witnessAllowance.get(ByteArray.toHexString(witnessAddress2)) - witness02Increase)) + (Math.abs(witnessAllowance.get(ByteArray.toHexString(witnessAddress2)) - witness02Increase)) <= 2); Assert.assertEquals(blackHoleBalance2, blackHoleBalance1); @@ -363,7 +372,8 @@ public void test02UpdateAccountPermissionAndMultiSiginTrans() { PublicMethodForMultiSign.getTransactionSignWeight(transaction2, blockingStubFull); logger.info("TransactionSignWeight info : " + txWeight); - Assert.assertTrue(PublicMethodForMultiSign.broadcastTransaction(transaction2, blockingStubFull)); + Assert.assertTrue( + PublicMethodForMultiSign.broadcastTransaction(transaction2, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); endNum = @@ -400,12 +410,10 @@ public void test02UpdateAccountPermissionAndMultiSiginTrans() { witnessAllowance = PublicMethod.getAllowance2(startNum, endNum, blockingStubFull); Assert.assertTrue( - (Math.abs( - witnessAllowance.get(ByteArray.toHexString(witnessAddress)) - witness01Increase)) + (Math.abs(witnessAllowance.get(ByteArray.toHexString(witnessAddress)) - witness01Increase)) <= 2); Assert.assertTrue( - (Math.abs( - witnessAllowance.get(ByteArray.toHexString(witnessAddress2)) - witness02Increase)) + (Math.abs(witnessAllowance.get(ByteArray.toHexString(witnessAddress2)) - witness02Increase)) <= 2); Assert.assertEquals(blackHoleBalance2, blackHoleBalance1); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -416,8 +424,10 @@ public void test02UpdateAccountPermissionAndMultiSiginTrans() { } @Test( - enabled = true, priority=2, - description = "Test trigger result is \"OUT_OF_TIME\"" + " with energy fee to black hole", groups = {"daily", "serial"}) + enabled = true, + priority = 2, + description = "Test trigger result is \"OUT_OF_TIME\"" + " with energy fee to black hole", + groups = {"daily", "serial"}) public void test03OutOfTimeEnergyFeeToBlackHole() { Random rand = new Random(); Integer randNum = rand.nextInt(4000); @@ -426,13 +436,13 @@ public void test03OutOfTimeEnergyFeeToBlackHole() { PublicMethod.sendcoin( deployAddress, maxFeeLimit * 10, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName = "StorageAndCpu" + Integer.toString(randNum); - String code = + String contractName = "StorageAndCpu" + Integer.toString(randNum); + String code = Configuration.getByPath("testng.conf") .getString("code.code_TestStorageAndCpu_storageAndCpu"); - String abi = + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_TestStorageAndCpu_storageAndCpu"); - byte[] contractAddress = null; + byte[] contractAddress = null; contractAddress = PublicMethod.deployContract( contractName, @@ -513,29 +523,34 @@ public void test03OutOfTimeEnergyFeeToBlackHole() { Map witnessAllowance = PublicMethod.getAllowance2(startNum, endNum, blockingStubFull); Assert.assertTrue( - (Math.abs( - witnessAllowance.get(ByteArray.toHexString(witnessAddress)) - witness01Increase)) + (Math.abs(witnessAllowance.get(ByteArray.toHexString(witnessAddress)) - witness01Increase)) <= 2); Assert.assertTrue( - (Math.abs( - witnessAllowance.get(ByteArray.toHexString(witnessAddress2)) - witness02Increase)) + (Math.abs(witnessAllowance.get(ByteArray.toHexString(witnessAddress2)) - witness02Increase)) <= 2); Assert.assertEquals(blackHoleBalance2, blackHoleBalance1); - Long packingFee = infoById.get().getPackingFee(); + Long packingFee = infoById.get().getPackingFee(); logger.info("receipt:" + infoById.get().getReceipt()); Assert.assertTrue(packingFee == infoById.get().getReceipt().getNetFee()); - Assert.assertTrue(infoById.get().getFee() < maxFeeLimit + infoById.get().getReceipt().getNetFee()); + Assert.assertTrue( + infoById.get().getFee() < maxFeeLimit + infoById.get().getReceipt().getNetFee()); afterBurnTrxAmount = blockingStubFull.getBurnTrx(EmptyMessage.newBuilder().build()).getNum(); - Assert.assertTrue(afterBurnTrxAmount - beforeBurnTrxAmount == infoById.get().getReceipt().getEnergyFee()); + Assert.assertTrue( + afterBurnTrxAmount - beforeBurnTrxAmount == infoById.get().getReceipt().getEnergyFee()); } - @Test(enabled = true, priority=2, description = "Test create account with netFee to sr", groups = {"daily", "serial"}) + @Test( + enabled = true, + priority = 2, + description = "Test create account with netFee to sr", + groups = {"daily", "serial"}) public void test04AccountCreate() { - //use new account to create account cost 1.1 TRX + // use new account to create account cost 1.1 TRX ECKey creatorEcKey = new ECKey(Utils.getRandom()); - byte[] creatorAddress = creatorEcKey.getAddress(); - final String creatorKey = ByteArray.toHexString(creatorEcKey.getPrivKeyBytes()); - PublicMethod.sendcoin(creatorAddress, 100000000L, foundationAddress, foundationKey, blockingStubFull); + byte[] creatorAddress = creatorEcKey.getAddress(); + final String creatorKey = ByteArray.toHexString(creatorEcKey.getPrivKeyBytes()); + PublicMethod.sendcoin( + creatorAddress, 100000000L, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); startNum = @@ -552,10 +567,11 @@ public void test04AccountCreate() { PublicMethod.queryAccount(WalletClient.decode58Check(blackHoleAdd), blockingStubFull) .getBalance(); beforeBurnTrxAmount = blockingStubFull.getBurnTrx(EmptyMessage.newBuilder().build()).getNum(); - ECKey ecKey = new ECKey(Utils.getRandom()); - byte[] lowBalAddress = ecKey.getAddress(); + ECKey ecKey = new ECKey(Utils.getRandom()); + byte[] lowBalAddress = ecKey.getAddress(); txid = - PublicMethod.createAccountGetTxid(creatorAddress, lowBalAddress, creatorKey, blockingStubFull); + PublicMethod.createAccountGetTxid( + creatorAddress, lowBalAddress, creatorKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); endNum = @@ -593,12 +609,10 @@ public void test04AccountCreate() { Map witnessAllowance = PublicMethod.getAllowance2(startNum, endNum, blockingStubFull); Assert.assertTrue( - (Math.abs( - witnessAllowance.get(ByteArray.toHexString(witnessAddress)) - witness01Increase)) + (Math.abs(witnessAllowance.get(ByteArray.toHexString(witnessAddress)) - witness01Increase)) <= 2); Assert.assertTrue( - (Math.abs( - witnessAllowance.get(ByteArray.toHexString(witnessAddress2)) - witness02Increase)) + (Math.abs(witnessAllowance.get(ByteArray.toHexString(witnessAddress2)) - witness02Increase)) <= 2); Assert.assertEquals(blackHoleBalance1, blackHoleBalance2); Optional infoById = @@ -610,9 +624,11 @@ public void test04AccountCreate() { } @Test( - enabled = true, priority=2, + enabled = true, + priority = 2, retryAnalyzer = Retry.class, - description = "Test trigger contract with netFee and energyFee to sr", groups = {"daily", "serial"}) + description = "Test trigger contract with netFee and energyFee to sr", + groups = {"daily", "serial"}) public void test05NetFeeAndEnergyFee2Sr() { Random rand = new Random(); Integer randNum = rand.nextInt(30) + 1; @@ -622,13 +638,13 @@ public void test05NetFeeAndEnergyFee2Sr() { PublicMethod.sendcoin( deployAddress, maxFeeLimit * 10, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName = "StorageAndCpu" + Integer.toString(randNum); - String code = + String contractName = "StorageAndCpu" + Integer.toString(randNum); + String code = Configuration.getByPath("testng.conf") .getString("code.code_TestStorageAndCpu_storageAndCpu"); - String abi = + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_TestStorageAndCpu_storageAndCpu"); - byte[] contractAddress = null; + byte[] contractAddress = null; contractAddress = PublicMethod.deployContract( contractName, @@ -683,7 +699,7 @@ public void test05NetFeeAndEnergyFee2Sr() { deployAddress, deployKey, blockingStubFull); - // PublicMethod.waitProduceNextBlock(blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); endNum = blockingStubFull @@ -722,12 +738,10 @@ public void test05NetFeeAndEnergyFee2Sr() { Map witnessAllowance = PublicMethod.getAllowance2(startNum, endNum, blockingStubFull); Assert.assertTrue( - (Math.abs( - witnessAllowance.get(ByteArray.toHexString(witnessAddress)) - witness01Increase)) + (Math.abs(witnessAllowance.get(ByteArray.toHexString(witnessAddress)) - witness01Increase)) <= 2); Assert.assertTrue( - (Math.abs( - witnessAllowance.get(ByteArray.toHexString(witnessAddress2)) - witness02Increase)) + (Math.abs(witnessAllowance.get(ByteArray.toHexString(witnessAddress2)) - witness02Increase)) <= 2); Assert.assertEquals(blackHoleBalance1, blackHoleBalance2); afterBurnTrxAmount = blockingStubFull.getBurnTrx(EmptyMessage.newBuilder().build()).getNum(); @@ -735,12 +749,16 @@ public void test05NetFeeAndEnergyFee2Sr() { } /** constructor. */ - @Test(enabled = true, priority=2, description = "Test create trc10 token with fee not to sr", groups = {"daily", "serial"}) + @Test( + enabled = true, + priority = 2, + description = "Test create trc10 token with fee not to sr", + groups = {"daily", "serial"}) public void test06CreateAssetIssue() { // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] tokenAccountAddress = ecKey1.getAddress(); - final String tokenAccountKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + byte[] tokenAccountAddress = ecKey1.getAddress(); + final String tokenAccountKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); PublicMethod.printAddress(tokenAccountKey); @@ -763,13 +781,13 @@ public void test06CreateAssetIssue() { PublicMethod.queryAccount(WalletClient.decode58Check(blackHoleAdd), blockingStubFull) .getBalance(); beforeBurnTrxAmount = blockingStubFull.getBurnTrx(EmptyMessage.newBuilder().build()).getNum(); - Long start = System.currentTimeMillis() + 2000; - Long end = System.currentTimeMillis() + 1000000000; + Long start = System.currentTimeMillis() + 2000; + Long end = System.currentTimeMillis() + 1000000000; long now = System.currentTimeMillis(); long totalSupply = now; - String description = "for case assetissue016"; - String url = "https://stest.assetissue016.url"; - String name = "AssetIssue016_" + Long.toString(now); + String description = "for case assetissue016"; + String url = "https://stest.assetissue016.url"; + String name = "AssetIssue016_" + Long.toString(now); txid = PublicMethod.createAssetIssueGetTxid( tokenAccountAddress, @@ -826,12 +844,10 @@ public void test06CreateAssetIssue() { Map witnessAllowance = PublicMethod.getAllowance2(startNum, endNum, blockingStubFull); Assert.assertTrue( - (Math.abs( - witnessAllowance.get(ByteArray.toHexString(witnessAddress)) - witness01Increase)) + (Math.abs(witnessAllowance.get(ByteArray.toHexString(witnessAddress)) - witness01Increase)) <= 2); Assert.assertTrue( - (Math.abs( - witnessAllowance.get(ByteArray.toHexString(witnessAddress2)) - witness02Increase)) + (Math.abs(witnessAllowance.get(ByteArray.toHexString(witnessAddress2)) - witness02Increase)) <= 2); Assert.assertEquals(blackHoleBalance1, blackHoleBalance2); Optional infoById = @@ -842,43 +858,53 @@ public void test06CreateAssetIssue() { Assert.assertTrue(afterBurnTrxAmount - beforeBurnTrxAmount == 1024000000L); } - @Test(enabled = true, priority=2, description = "commit NO.47 value can be 1e17 if commit No.63 opened", groups = {"daily", "serial"}) + @Test( + enabled = true, + priority = 2, + description = "commit NO.47 value can be 1e17 if commit No.63 opened", + groups = {"daily", "serial"}) public void test07Commit47Value() { HashMap proposalMap = new HashMap(); proposalMap.put(47L, 100000000000000000L); - org.testng.Assert.assertTrue(PublicMethod.createProposal(witnessAddress, witnessKey, - proposalMap, blockingStubFull)); + org.testng.Assert.assertTrue( + PublicMethod.createProposal(witnessAddress, witnessKey, proposalMap, blockingStubFull)); } /** constructor. */ - @Test(enabled = true, priority=2, description = " create and vote witness, " - + "after this case there will be 3 SR", groups = {"daily", "serial"}) + @Test( + enabled = true, + priority = 2, + description = " create and vote witness, " + "after this case there will be 3 SR", + groups = {"daily", "serial"}) public void test08CreateAndVoteWitness() { - int beforeCreateWitnessCount = PublicMethod.listWitnesses(blockingStubFull) - .get().getWitnessesCount(); + int beforeCreateWitnessCount = + PublicMethod.listWitnesses(blockingStubFull).get().getWitnessesCount(); Assert.assertEquals(2, beforeCreateWitnessCount); - Assert.assertTrue(PublicMethod - .sendcoin(witnessAddress3, costForCreateWitness + 100000000L, foundationAddress, foundationKey, + Assert.assertTrue( + PublicMethod.sendcoin( + witnessAddress3, + costForCreateWitness + 100000000L, + foundationAddress, + foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - org.testng.Assert.assertTrue(PublicMethod.freezeBalanceGetTronPower(witnessAddress3, 1000000L, - 0, 2, null, witnessKey3, blockingStubFull)); + org.testng.Assert.assertTrue( + PublicMethod.freezeBalanceGetTronPower( + witnessAddress3, 1000000L, 0, 2, null, witnessKey3, blockingStubFull)); Assert.assertTrue(createWitness(witnessAddress3, createUrl, witnessKey3)); PublicMethod.waitProduceNextBlock(blockingStubFull); - int afterCreateWitnessCount = PublicMethod.listWitnesses(blockingStubFull) - .get().getWitnessesCount(); + int afterCreateWitnessCount = + PublicMethod.listWitnesses(blockingStubFull).get().getWitnessesCount(); Assert.assertEquals(3, afterCreateWitnessCount); Assert.assertTrue(PublicMethod.queryAccount(witnessAddress3, blockingStubFull).getIsWitness()); HashMap witnessMap = new HashMap<>(); witnessMap.put(witnessAddress3, 1L); - Assert.assertTrue(PublicMethod.voteWitness(witnessAddress3, witnessKey3, witnessMap, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.voteWitness(witnessAddress3, witnessKey3, witnessMap, blockingStubFull)); } - /** - * constructor. - */ + /** constructor. */ public Boolean createWitness(byte[] owner, byte[] url, String priKey) { ECKey temKey = null; try { @@ -889,8 +915,8 @@ public Boolean createWitness(byte[] owner, byte[] url, String priKey) { } final ECKey ecKey = temKey; - WitnessContract.WitnessCreateContract.Builder builder = WitnessContract.WitnessCreateContract - .newBuilder(); + WitnessContract.WitnessCreateContract.Builder builder = + WitnessContract.WitnessCreateContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(owner)); builder.setUrl(ByteString.copyFrom(url)); WitnessContract.WitnessCreateContract contract = builder.build(); @@ -916,7 +942,8 @@ private Protocol.Transaction signTransaction(ECKey ecKey, Protocol.Transaction t @AfterClass public void shutdown() throws InterruptedException { PublicMethod.unFreezeBalance(deployAddress, deployKey, 1, deployAddress, blockingStubFull); - PublicMethod.freeResource(deployAddress, deployKey, foundationAddress, blockingStubFull); if (!srStatus) { + PublicMethod.freeResource(deployAddress, deployKey, foundationAddress, blockingStubFull); + if (!srStatus) { System.exit(1); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/transaction/TransactionPendingQuery001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/transaction/TransactionPendingQuery001.java index 7a073ead..f0635a3d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/transaction/TransactionPendingQuery001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/transaction/TransactionPendingQuery001.java @@ -15,78 +15,76 @@ import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; - @Slf4j - public class TransactionPendingQuery001 extends TronBaseTest { ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] receiverAddress = ecKey1.getAddress(); final String receiverKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); String txid = null; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); initPbftChannel(); } - @Test(enabled = true, description = "Test get pending size", groups = {"daily"}) + @Test( + enabled = true, + description = "Test get pending size", + groups = {"daily"}) public void test01GetPendingSize() { long pendingSizeInFullNode = 0; - int retryTimes = 100; + int retryTimes = 100; while (pendingSizeInFullNode == 0 && retryTimes-- > 0) { - PublicMethod.sendcoin(receiverAddress,1L,foundationAddress,foundationKey,blockingStubFull); + PublicMethod.sendcoin( + receiverAddress, 1L, foundationAddress, foundationKey, blockingStubFull); if (retryTimes % 5 == 0) { - pendingSizeInFullNode = blockingStubFull - .getPendingSize(EmptyMessage.newBuilder().build()).getNum(); + pendingSizeInFullNode = + blockingStubFull.getPendingSize(EmptyMessage.newBuilder().build()).getNum(); } } - Assert.assertNotEquals(pendingSizeInFullNode,0); + Assert.assertNotEquals(pendingSizeInFullNode, 0); } - - @Test(enabled = true, description = "Test get pending transaction list", groups = {"daily"}) + @Test( + enabled = true, + description = "Test get pending transaction list", + groups = {"daily"}) public void test02GetPendingTransactionList() { int retryTimes = 100; - TransactionIdList transactionList = blockingStubFull - .getTransactionListFromPending(EmptyMessage.newBuilder().build()); + TransactionIdList transactionList = + blockingStubFull.getTransactionListFromPending(EmptyMessage.newBuilder().build()); while (transactionList.getTxIdCount() == 0 && retryTimes-- > 0) { - PublicMethod.sendcoin(receiverAddress,1L,foundationAddress,foundationKey,blockingStubFull); + PublicMethod.sendcoin( + receiverAddress, 1L, foundationAddress, foundationKey, blockingStubFull); if (retryTimes % 5 == 0) { - transactionList = blockingStubFull - .getTransactionListFromPending(EmptyMessage.newBuilder().build()); + transactionList = + blockingStubFull.getTransactionListFromPending(EmptyMessage.newBuilder().build()); } } - Assert.assertNotEquals(transactionList.getTxIdCount(),0); + Assert.assertNotEquals(transactionList.getTxIdCount(), 0); txid = transactionList.getTxId(0); logger.info("txid:" + txid); - } - - @Test(enabled = true, description = "Test transaction from pending", groups = {"daily"}) + @Test( + enabled = true, + description = "Test transaction from pending", + groups = {"daily"}) public void test03GetTransactionFromPending() { - Transaction transaction = PublicMethod.getTransactionFromPending(txid,blockingStubFull).get(); - Assert.assertEquals(ByteArray.toHexString(Sha256Hash - .hash(true, transaction.getRawData().toByteArray())),txid); + Transaction transaction = PublicMethod.getTransactionFromPending(txid, blockingStubFull).get(); + Assert.assertEquals( + ByteArray.toHexString(Sha256Hash.hash(true, transaction.getRawData().toByteArray())), txid); } - - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.unFreezeBalance(receiverAddress, receiverKey, 1, receiverAddress, - blockingStubFull); + PublicMethod.unFreezeBalance( + receiverAddress, receiverKey, 1, receiverAddress, blockingStubFull); PublicMethod.freeResource(receiverAddress, receiverKey, foundationAddress, blockingStubFull); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/transaction/WalletTestBlock004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/transaction/WalletTestBlock004.java index 65b38e85..35e97452 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/transaction/WalletTestBlock004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/transaction/WalletTestBlock004.java @@ -18,16 +18,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class WalletTestBlock004 extends TronBaseTest { private final String fullnode = +public class WalletTestBlock004 extends TronBaseTest { + private final String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress = ecKey1.getAddress(); private String txId = null; + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); @@ -36,18 +37,22 @@ public static String loadPubKey() { /** constructor. */ @BeforeClass public void beforeClass() { - initSolidityChannel(); txId = + initSolidityChannel(); + txId = PublicMethod.sendcoinGetTransactionId( testAddress, 10000L, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("txId:" + txId); } - @Test(enabled = true, description = "Get block by limit next.", groups = {"daily"}) + @Test( + enabled = true, + description = "Get block by limit next.", + groups = {"daily"}) public void testGetBlockByLimitNext() { // Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); + Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Assert.assertFalse(currentBlockNum < 0); while (currentBlockNum <= 5) { logger.info("Now has very little block, Please wait"); @@ -92,7 +97,10 @@ public void testGetBlockByLimitNext() { .isEmpty()); } - @Test(enabled = true, description = "Get block by limit next with type is zero.", groups = {"daily"}) + @Test( + enabled = true, + description = "Get block by limit next with type is zero.", + groups = {"daily"}) public void testGetBlockByLimitNextWithTypeIsZero() throws InterruptedException { Long blockNumber = PublicMethod.getTransactionInfoById(txId, blockingStubFull).get().getBlockNumber(); @@ -105,12 +113,15 @@ public void testGetBlockByLimitNextWithTypeIsZero() throws InterruptedException GrpcAPI.BlockList blockList = blockingStubFull.getBlockByLimitNext(builder.build()); Optional getBlockByLimitNext = Optional.ofNullable(blockList); Assert.assertTrue(getBlockByLimitNext.get().getBlockCount() == 1); - Long num = getBlockByLimitNext.get().getBlock(0).getBlockHeader().getRawData().getNumber(); + Long num = getBlockByLimitNext.get().getBlock(0).getBlockHeader().getRawData().getNumber(); Assert.assertEquals(blockNumber, num); Assert.assertTrue(!getBlockByLimitNext.get().getBlock(0).getTransactionsList().isEmpty()); } - @Test(enabled = false, description = "Get block by limit next with type is one.", groups = {"daily"}) + @Test( + enabled = false, + description = "Get block by limit next with type is one.", + groups = {"daily"}) public void testGetBlockByLimitNextWithTypeIsOne() throws InterruptedException { Long blockNumber = PublicMethod.getTransactionInfoById(txId, blockingStubFull).get().getBlockNumber(); @@ -122,15 +133,18 @@ public void testGetBlockByLimitNextWithTypeIsOne() throws InterruptedException { GrpcAPI.BlockList blockList = blockingStubFull.getBlockByLimitNext(builder.build()); Optional getBlockByLimitNext = Optional.ofNullable(blockList); Assert.assertTrue(getBlockByLimitNext.get().getBlockCount() == 1); - Long num = getBlockByLimitNext.get().getBlock(0).getBlockHeader().getRawData().getNumber(); + Long num = getBlockByLimitNext.get().getBlock(0).getBlockHeader().getRawData().getNumber(); Assert.assertEquals(blockNumber, num); Assert.assertTrue(getBlockByLimitNext.get().getBlock(0).getTransactionsList().isEmpty()); } - @Test(enabled = false, description = "Get block by exception limit next.", groups = {"daily"}) + @Test( + enabled = false, + description = "Get block by exception limit next.", + groups = {"daily"}) public void testGetBlockByExceptionLimitNext() { Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); + Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Assert.assertFalse(currentBlockNum < 0); while (currentBlockNum <= 5) { logger.info("Now has very little block, Please wait"); @@ -145,21 +159,21 @@ public void testGetBlockByExceptionLimitNext() { GrpcAPI.BlockList blockList = blockingStubFull.getBlockByLimitNext(builder.build()); Optional getBlockByLimitNext = Optional.ofNullable(blockList); Assert.assertTrue(getBlockByLimitNext.get().getBlockCount() == 0); - // From 3 to 3 + // From 3 to 3 builder = GrpcAPI.BlockLimit.newBuilder(); builder.setStartNum(3); builder.setEndNum(3); blockList = blockingStubFull.getBlockByLimitNext(builder.build()); getBlockByLimitNext = Optional.ofNullable(blockList); Assert.assertTrue(getBlockByLimitNext.get().getBlockCount() == 0); - // From 4 to 2 + // From 4 to 2 builder = GrpcAPI.BlockLimit.newBuilder(); builder.setStartNum(4); builder.setEndNum(2); blockList = blockingStubFull.getBlockByLimitNext(builder.build()); getBlockByLimitNext = Optional.ofNullable(blockList); Assert.assertTrue(getBlockByLimitNext.get().getBlockCount() == 0); - // From 999999990 to 999999999 + // From 999999990 to 999999999 builder = GrpcAPI.BlockLimit.newBuilder(); builder.setStartNum(999999990); builder.setEndNum(999999999); @@ -170,12 +184,12 @@ public void testGetBlockByExceptionLimitNext() { /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} /** constructor. */ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -190,7 +204,7 @@ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockin return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/transaction/WalletTestBlock005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/transaction/WalletTestBlock005.java index 73b85e6b..2150df0d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/transaction/WalletTestBlock005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/transaction/WalletTestBlock005.java @@ -1,7 +1,6 @@ package stest.tron.wallet.dailybuild.transaction; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.math.BigInteger; import java.util.Optional; @@ -20,16 +19,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class WalletTestBlock005 extends TronBaseTest { private String solidityNode = +public class WalletTestBlock005 extends TronBaseTest { + private String solidityNode = Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress = ecKey1.getAddress(); private String txId = null; + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); @@ -38,14 +38,18 @@ public static String loadPubKey() { /** constructor. */ @BeforeClass public void beforeClass() { - initSolidityChannel(); channelSolidity = ManagedChannelBuilder.forTarget(solidityNode).usePlaintext().build(); - } + initSolidityChannel(); + channelSolidity = ManagedChannelBuilder.forTarget(solidityNode).usePlaintext().build(); + } - @Test(enabled = true, description = "Get block by latest num.", groups = {"daily"}) + @Test( + enabled = true, + description = "Get block by latest num.", + groups = {"daily"}) public void testGetBlockByLatestNum() { // Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); + Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Assert.assertFalse(currentBlockNum < 0); while (currentBlockNum <= 5) { logger.info("Now the block num is " + Long.toString(currentBlockNum) + " Please wait"); @@ -72,18 +76,21 @@ public void testGetBlockByLatestNum() { logger.info("TestGetBlockByLatestNum ok!!!"); } - @Test(enabled = false, description = "Get block by latest num with type is zero.", groups = {"daily"}) + @Test( + enabled = false, + description = "Get block by latest num with type is zero.", + groups = {"daily"}) public void testGetBlockByLatestNumWithTypeIsZero() throws InterruptedException { txId = PublicMethod.sendcoinGetTransactionId( testAddress, 10000L, foundationAddress, foundationKey, blockingStubFull); logger.info("txId:" + txId); Thread.sleep(2000); - Long blockNumber = + Long blockNumber = PublicMethod.getTransactionInfoById(txId, blockingStubFull).get().getBlockNumber(); logger.info("blockNumber:" + blockNumber); Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - Long nowBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); + Long nowBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); logger.info("nowBlockNum:" + nowBlockNum); long numDiff = nowBlockNum - nowBlockNum + 3; logger.info("numDiff:" + numDiff); @@ -104,18 +111,21 @@ public void testGetBlockByLatestNumWithTypeIsZero() throws InterruptedException Assert.assertTrue(flag); } - @Test(enabled = false, description = "Get block by latest num with type is one.", groups = {"daily"}) + @Test( + enabled = false, + description = "Get block by latest num with type is one.", + groups = {"daily"}) public void testGetBlockByLatestNumWithTypeIsOne() throws InterruptedException { txId = PublicMethod.sendcoinGetTransactionId( testAddress, 10000L, foundationAddress, foundationKey, blockingStubFull); logger.info("txId:" + txId); Thread.sleep(2000); - Long blockNumber = + Long blockNumber = PublicMethod.getTransactionInfoById(txId, blockingStubFull).get().getBlockNumber(); logger.info("blockNumber:" + blockNumber); Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - Long nowBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); + Long nowBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); logger.info("nowBlockNum:" + nowBlockNum); long numDiff = nowBlockNum - nowBlockNum + 3; logger.info("numDiff:" + numDiff); @@ -135,10 +145,13 @@ public void testGetBlockByLatestNumWithTypeIsOne() throws InterruptedException { Assert.assertTrue(flag); } - @Test(enabled = true, description = "Get block by exception num", groups = {"daily"}) + @Test( + enabled = true, + description = "Get block by exception num", + groups = {"daily"}) public void testGetBlockByExceptionNum() { Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); + Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Assert.assertFalse(currentBlockNum < 0); while (currentBlockNum <= 5) { logger.info("Now the block num is " + Long.toString(currentBlockNum) + " Please wait"); @@ -163,12 +176,12 @@ public void testGetBlockByExceptionNum() { /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} /** constructor. */ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -183,7 +196,7 @@ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockin return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/transaction/WalletTestTransactionMemo.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/transaction/WalletTestTransactionMemo.java index ab23580b..e646743d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/transaction/WalletTestTransactionMemo.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/transaction/WalletTestTransactionMemo.java @@ -9,8 +9,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestTransactionMemo extends TronBaseTest { @@ -18,94 +18,131 @@ public class WalletTestTransactionMemo extends TronBaseTest { ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] memoAddress = ecKey1.getAddress(); String memoKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - //if send coin with value 10000000000L, then the script's max byte size is 511790 + // if send coin with value 10000000000L, then the script's max byte size is 511790 private int maxScriptByteSize = 511790 - 128; // 475 - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(memoKey); Assert.assertTrue(PublicMethod.sendcoin(memoAddress, sendAmount, - foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.printAddress(memoKey); + Assert.assertTrue( + PublicMethod.sendcoin( + memoAddress, sendAmount, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - - } - @Test(enabled = false, description = "Transaction with memo should be pay memo fee", groups = {"daily"}) + @Test( + enabled = false, + description = "Transaction with memo should be pay memo fee", + groups = {"daily"}) public void test01TransactionMemo() { Long memoFee = PublicMethod.getProposalMemoFee(blockingStubFull); logger.info("MemoFee:" + memoFee); - String memo = "PAY FEE"; - Long sendAmount = 1L; - Account account = PublicMethod.queryAccount(memoAddress,blockingStubFull); - final Long beforeBalance = account.getBalance(); - String txid = PublicMethod.sendcoinWithMemoGetTransactionId(foundationAddress,sendAmount,memo, - memoAddress,memoKey,blockingStubFull); + String memo = "PAY FEE"; + Long sendAmount = 1L; + Account account = PublicMethod.queryAccount(memoAddress, blockingStubFull); + final Long beforeBalance = account.getBalance(); + String txid = + PublicMethod.sendcoinWithMemoGetTransactionId( + foundationAddress, sendAmount, memo, memoAddress, memoKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); ; - String dataMemo = PublicMethod.getTransactionById(txid,blockingStubFull) - .get().getRawData().getData().toStringUtf8(); + String dataMemo = + PublicMethod.getTransactionById(txid, blockingStubFull) + .get() + .getRawData() + .getData() + .toStringUtf8(); logger.info(dataMemo); - Assert.assertEquals(dataMemo,memo); + Assert.assertEquals(dataMemo, memo); - account = PublicMethod.queryAccount(memoAddress,blockingStubFull); - final Long afterBalance = account.getBalance(); + account = PublicMethod.queryAccount(memoAddress, blockingStubFull); + final Long afterBalance = account.getBalance(); Assert.assertEquals(beforeBalance - afterBalance, sendAmount + memoFee); - Long transactionFee = PublicMethod.getTransactionInfoById(txid,blockingStubFull).get().getFee(); - Long freeNet = PublicMethod.getTransactionInfoById(txid,blockingStubFull).get().getReceipt().getNetUsage(); - Assert.assertEquals(transactionFee,memoFee); - String txidWithNoMemo = PublicMethod.sendcoinWithMemoGetTransactionId(foundationAddress,sendAmount,null, - memoAddress,memoKey,blockingStubFull); + Long transactionFee = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get().getFee(); + Long freeNet = + PublicMethod.getTransactionInfoById(txid, blockingStubFull) + .get() + .getReceipt() + .getNetUsage(); + Assert.assertEquals(transactionFee, memoFee); + String txidWithNoMemo = + PublicMethod.sendcoinWithMemoGetTransactionId( + foundationAddress, sendAmount, null, memoAddress, memoKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long noMemoFreeNet = PublicMethod.getTransactionInfoById(txidWithNoMemo,blockingStubFull).get().getReceipt().getNetUsage(); + Long noMemoFreeNet = + PublicMethod.getTransactionInfoById(txidWithNoMemo, blockingStubFull) + .get() + .getReceipt() + .getNetUsage(); logger.info("freeNet:" + freeNet); logger.info("noMemoFreeNet:" + noMemoFreeNet); Assert.assertTrue(noMemoFreeNet + 9 == freeNet); - - } - @Test(enabled = false, description = "transaction's max size is 500*1024", groups = {"daily"}) + @Test( + enabled = false, + description = "transaction's max size is 500*1024", + groups = {"daily"}) public void test02TransactionMaxSize() { - Assert.assertTrue(PublicMethod.sendcoinWithScript(memoAddress, 10000000000L, - foundationAddress, foundationKey, maxScriptByteSize, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoinWithScript( + memoAddress, + 10000000000L, + foundationAddress, + foundationKey, + maxScriptByteSize, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Code = TOO_BIG_TRANSACTION_ERROR; Message = Transaction size is too big - Assert.assertFalse(PublicMethod.sendcoinWithScript(memoAddress, 10000000000L, - foundationAddress, foundationKey, maxScriptByteSize + 1, blockingStubFull)); + // Code = TOO_BIG_TRANSACTION_ERROR; Message = Transaction size is too big + Assert.assertFalse( + PublicMethod.sendcoinWithScript( + memoAddress, + 10000000000L, + foundationAddress, + foundationKey, + maxScriptByteSize + 1, + blockingStubFull)); } - @Test(enabled = true, description = "transaction's max size is 1500 when create a new account (proposal 82)", groups = {"daily"}) + @Test( + enabled = true, + description = "transaction's max size is 1500 when create a new account (proposal 82)", + groups = {"daily"}) public void test02TransactionMaxSizeCreateNewAccount() { maxScriptByteSize = 1357; - ECKey key = new ECKey(Utils.getRandom()); + ECKey key = new ECKey(Utils.getRandom()); memoAddress = key.getAddress(); PublicMethod.printAddress(ByteArray.toHexString(key.getPrivKeyBytes())); - Assert.assertTrue(PublicMethod.sendcoinWithScript(memoAddress, 10000000000L, - foundationAddress, foundationKey, maxScriptByteSize, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoinWithScript( + memoAddress, + 10000000000L, + foundationAddress, + foundationKey, + maxScriptByteSize, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - ECKey key1 = new ECKey(Utils.getRandom()); + ECKey key1 = new ECKey(Utils.getRandom()); memoAddress = key1.getAddress(); PublicMethod.printAddress(ByteArray.toHexString(key1.getPrivKeyBytes())); - //Code = TOO_BIG_TRANSACTION_ERROR; Message = Transaction size is too big - Assert.assertFalse(PublicMethod.sendcoinWithScript(memoAddress, 10000000000L, - foundationAddress, foundationKey, maxScriptByteSize + 1, blockingStubFull)); + // Code = TOO_BIG_TRANSACTION_ERROR; Message = Transaction size is too big + Assert.assertFalse( + PublicMethod.sendcoinWithScript( + memoAddress, + 10000000000L, + foundationAddress, + foundationKey, + maxScriptByteSize + 1, + blockingStubFull)); } - - - - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - PublicMethod.freeResource(memoAddress, memoKey, foundationAddress, blockingStubFull); } + PublicMethod.freeResource(memoAddress, memoKey, foundationAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken001.java index 16338415..9d424d7d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken001.java @@ -16,8 +16,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class ContractTrcToken001 extends TronBaseTest { @@ -27,43 +27,61 @@ public class ContractTrcToken001 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; private byte[] transferTokenContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); } - - @Test(enabled = true, description = "DeployContract with correct tokenValue and tokenId", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "DeployContract with correct tokenValue and tokenId", + groups = {"contract", "daily"}) public void deployTransferTokenContract() { - Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 5100_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 5100_000_000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 135678L, blockingStubFull), 0, -// 1, ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); -// -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L, 0, 0, -// ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); -// -// PublicMethod.waitProduceNextBlock(blockingStubFull); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 135678L, + // blockingStubFull), 0, + // 1, ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); + // + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L, 0, 0, + // ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); + // + // PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod - .createAssetIssue(dev001Address, tokenName, TotalSupply, 1, 10000, start, end, 1, - description, url, 100000L, 100000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -71,31 +89,46 @@ public void deployTransferTokenContract() { logger.info("The token name: " + tokenName); logger.info("The token ID: " + assetAccountId.toStringUtf8()); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod - .getAccountResource(dev001Address, blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("before energyLimit is " + energyLimit); logger.info("before energyUsage is " + energyUsage); logger.info("before balanceBefore is " + balanceBefore); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountBefore: " - + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken001.sol"; - String contractName = "tokenTest"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken001.sol"; + String contractName = "tokenTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String tokenId = assetAccountId.toStringUtf8(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String tokenId = assetAccountId.toStringUtf8(); long tokenValue = 200; long callValue = 5; - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callValue, 0, 10000, tokenId, tokenValue, null, dev001Key, dev001Address, + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callValue, + 0, + 10000, + tokenId, + tokenValue, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -104,39 +137,57 @@ public void deployTransferTokenContract() { energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); long balanceAfter = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("after energyLimit is " + energyLimit); logger.info("after energyUsage is " + energyUsage); logger.info("after balanceAfter is " + balanceAfter); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountAfter: " - + devAssetCountAfter); - - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (transferTokenTxid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(transferTokenContractAddress, blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(transferTokenContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - Long contractAssetCount = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); - - Assert.assertEquals(Long.valueOf(tokenValue), - Long.valueOf(devAssetCountBefore - devAssetCountAfter)); + Long contractAssetCount = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); + + Assert.assertEquals( + Long.valueOf(tokenValue), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(tokenValue), contractAssetCount); - final String triggerTxid = PublicMethod - .triggerContract(transferTokenContractAddress, "getResultInCon()", "#", false, 0, - 1000000000L, "0", 0, dev001Address, dev001Key, blockingStubFull); + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "getResultInCon()", + "#", + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -147,11 +198,11 @@ public void deployTransferTokenContract() { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - List retList = PublicMethod - .getStrings(infoById.get().getContractResult(0).toByteArray()); - Long msgId = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); - Long msgTokenValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); - Long msgCallValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(2))); + List retList = + PublicMethod.getStrings(infoById.get().getContractResult(0).toByteArray()); + Long msgId = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + Long msgTokenValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + Long msgCallValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(2))); logger.info("msgId: " + msgId); logger.info("msgTokenValue: " + msgTokenValue); @@ -165,12 +216,9 @@ public void deployTransferTokenContract() { PublicMethod.unFreezeBalance(fromAddress, foundationKey, 0, dev001Address, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); } + PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken002.java index 87c925e9..5d318426 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken002.java @@ -16,8 +16,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class ContractTrcToken002 extends TronBaseTest { @@ -27,10 +27,10 @@ public class ContractTrcToken002 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; private byte[] transferTokenContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -38,71 +38,105 @@ public class ContractTrcToken002 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = true, description = "TriggerContract with correct tokenValue and tokenId", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerContract with correct tokenValue and tokenId", + groups = {"contract", "daily"}) public void deployTransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 3100_000_000L, fromAddress, - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 3000_000_000L, fromAddress, - foundationKey, blockingStubFull)); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 70000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), -// 0, 0, ByteString.copyFrom(dev001Address), -// foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 3100_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 3000_000_000L, fromAddress, foundationKey, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 70000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + + // PublicMethod.randomFreezeAmount.getAndAdd(1), + // 0, 0, ByteString.copyFrom(dev001Address), + // foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, - 100000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); logger.info("The token name: " + tokenName); logger.info("The token ID: " + assetAccountId.toStringUtf8()); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountBefore = PublicMethod.getAssetIssueValue( - dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("before energyLimit is " + energyLimit); logger.info("before energyUsage is " + energyUsage); logger.info("before balanceBefore is " + balanceBefore); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() - + ", devAssetCountBefore: " + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken002.sol"; - String contractName = "tokenTest"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken002.sol"; + String contractName = "tokenTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String tokenId = assetAccountId.toStringUtf8(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String tokenId = assetAccountId.toStringUtf8(); long tokenValue = 200; long callValue = 0; - String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, callValue, 0, 10000, - tokenId, tokenValue, null, dev001Key, - dev001Address, blockingStubFull); + String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callValue, + 0, + 10000, + tokenId, + tokenValue, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (transferTokenTxid == null || infoById.get().getResultValue() != 0) { @@ -110,44 +144,61 @@ public void deployTransferTokenContract() { } transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(transferTokenContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(transferTokenContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); long balanceAfter = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountAfter = PublicMethod.getAssetIssueValue( - dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("after energyLimit is " + energyLimit); logger.info("after energyUsage is " + energyUsage); logger.info("after balanceAfter is " + balanceAfter); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() - + ", devAssetCountAfter: " + devAssetCountAfter); - - Assert.assertFalse(PublicMethod.transferAsset(transferTokenContractAddress, - assetAccountId.toByteArray(), 100L, dev001Address, dev001Key, blockingStubFull)); - Long contractAssetCount = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() - + ", Count: " + contractAssetCount); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + + Assert.assertFalse( + PublicMethod.transferAsset( + transferTokenContractAddress, + assetAccountId.toByteArray(), + 100L, + dev001Address, + dev001Key, + blockingStubFull)); + Long contractAssetCount = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); Assert.assertEquals(Long.valueOf(200), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(200), contractAssetCount); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(user001Address), foundationKey, blockingStubFull)); - - - Assert.assertTrue(PublicMethod.transferAsset(user001Address, - assetAccountId.toByteArray(), 10L, dev001Address, dev001Key, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(user001Address), foundationKey, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.transferAsset( + user001Address, + assetAccountId.toByteArray(), + 10L, + dev001Address, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -159,25 +210,33 @@ public void deployTransferTokenContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + userEnergyLimitBefore); logger.info("before trigger, userEnergyUsageBefore is " + userEnergyUsageBefore); logger.info("before trigger, userBalanceBefore is " + userBalanceBefore); - - PublicMethod - .sendcoin(transferTokenContractAddress, 5000000, fromAddress, foundationKey, blockingStubFull); + PublicMethod.sendcoin( + transferTokenContractAddress, 5000000, fromAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); tokenId = assetAccountId.toStringUtf8(); tokenValue = 10; callValue = 0; - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "msgTokenValueAndTokenIdTest()", "#", false, callValue, - 1000000000L, tokenId, tokenValue, user001Address, user001Key, - blockingStubFull); + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "msgTokenValueAndTokenIdTest()", + "#", + false, + callValue, + 1000000000L, + tokenId, + tokenValue, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -193,26 +252,25 @@ public void deployTransferTokenContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, - blockingStubFull).getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + userEnergyLimitAfter); logger.info("after trigger, userEnergyUsageAfter is " + userEnergyUsageAfter); logger.info("after trigger, userBalanceAfter is " + userBalanceAfter); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (triggerTxid == null || infoById.get().getResultValue() != 0) { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - List retList = PublicMethod - .getStrings(infoById.get().getContractResult(0).toByteArray()); - Long msgId = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); - Long msgTokenValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); - Long msgCallValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(2))); + List retList = + PublicMethod.getStrings(infoById.get().getContractResult(0).toByteArray()); + Long msgId = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + Long msgTokenValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + Long msgCallValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(2))); logger.info("msgId: " + msgId); logger.info("msgTokenValue: " + msgTokenValue); @@ -221,23 +279,23 @@ public void deployTransferTokenContract() { Assert.assertEquals(msgId.toString(), tokenId); Assert.assertEquals(Long.valueOf(msgTokenValue), Long.valueOf(tokenValue)); Assert.assertEquals(Long.valueOf(msgCallValue), Long.valueOf(callValue)); - contractAssetCount = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("after user trigger Contract has AssetId: " + assetAccountId.toStringUtf8() - + ", Count: " + contractAssetCount); - + contractAssetCount = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "after user trigger Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, foundationKey, 0, dev001Address, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, foundationKey, 1, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, foundationKey, 1, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, foundationKey, 1, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken003.java index d4244008..017209ba 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken003.java @@ -15,9 +15,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class ContractTrcToken003 extends TronBaseTest { @@ -27,10 +26,10 @@ public class ContractTrcToken003 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountDev = null; private static ByteString assetAccountUser = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -38,34 +37,54 @@ public class ContractTrcToken003 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); - + public void beforeClass() { + PublicMethod.printAddress(dev001Key); } - @Test(enabled = true, description = "DeployContract with exception condition", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "DeployContract with exception condition", + groups = {"contract", "daily"}) public void deployTransferTokenContract() { - Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 1100_000_000L, fromAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .sendcoin(user001Address, 1100_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1100_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 1100_000_000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 50000L, blockingStubFull), 0, -// 1, ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), 0, 0, -// ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); -// PublicMethod.waitProduceNextBlock(blockingStubFull); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 50000L, + // blockingStubFull), 0, + // 1, ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + + // PublicMethod.randomFreezeAmount.getAndAdd(1), 0, 0, + // ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); + // PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //dev Create a new AssetIssue - Assert.assertTrue(PublicMethod - .createAssetIssue(dev001Address, tokenName, TotalSupply, 1, 10000, start, end, 1, - description, url, 100000L, 100000L, 1L, 1L, dev001Key, blockingStubFull)); + // dev Create a new AssetIssue + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountDev = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); @@ -74,173 +93,342 @@ public void deployTransferTokenContract() { start = System.currentTimeMillis() + 2000; end = System.currentTimeMillis() + 1000000000; - //user Create a new AssetIssue - Assert.assertTrue(PublicMethod - .createAssetIssue(user001Address, tokenName, TotalSupply, 1, 10000, start, end, 1, - description, url, 100000L, 100000L, 1L, 1L, user001Key, blockingStubFull)); + // user Create a new AssetIssue + Assert.assertTrue( + PublicMethod.createAssetIssue( + user001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + user001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - assetAccountUser = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getAssetIssuedID(); + assetAccountUser = + PublicMethod.queryAccount(user001Address, blockingStubFull).getAssetIssuedID(); logger.info("The assetAccountUser token name: " + tokenName); logger.info("The assetAccountUser token ID: " + assetAccountUser.toStringUtf8()); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod - .getAccountResource(dev001Address, blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountDev, blockingStubFull); - Long userAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountUser, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountDev, blockingStubFull); + Long userAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountUser, blockingStubFull); logger.info("before energyLimit is " + energyLimit); logger.info("before energyUsage is " + energyUsage); logger.info("before balanceBefore is " + balanceBefore); logger.info( - "before dev has AssetId: " + assetAccountDev.toStringUtf8() + ", devAssetCountBefore: " + "before dev has AssetId: " + + assetAccountDev.toStringUtf8() + + ", devAssetCountBefore: " + devAssetCountBefore); logger.info( - "before dev has AssetId: " + assetAccountUser.toStringUtf8() + ", userAssetCountBefore: " + "before dev has AssetId: " + + assetAccountUser.toStringUtf8() + + ", userAssetCountBefore: " + userAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken003.sol"; - String contractName = "tokenTest"; + String filePath = "./src/test/resources/soliditycode/contractTrcToken003.sol"; + String contractName = "tokenTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - // the tokenId is not exist + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + // the tokenId is not exist String fakeTokenId = Long.toString(Long.valueOf(assetAccountDev.toStringUtf8()) + 100); - Long fakeTokenValue = 100L; - - GrpcAPI.Return response = PublicMethod - .deployContractAndGetResponse(contractName, abi, code, "", maxFeeLimit, 0L, 0, 10000, - fakeTokenId, fakeTokenValue, null, dev001Key, dev001Address, blockingStubFull); + Long fakeTokenValue = 100L; + + GrpcAPI.Return response = + PublicMethod.deployContractAndGetResponse( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + fakeTokenId, + fakeTokenValue, + null, + dev001Key, + dev001Address, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert - .assertEquals("contract validate error : No asset !".toLowerCase(), - response.getMessage().toStringUtf8().toLowerCase()); - // deployer didn't have any such token + Assert.assertEquals( + "contract validate error : No asset !".toLowerCase(), + response.getMessage().toStringUtf8().toLowerCase()); + // deployer didn't have any such token fakeTokenId = assetAccountUser.toStringUtf8(); fakeTokenValue = 100L; - response = PublicMethod - .deployContractAndGetResponse(contractName, abi, code, "", maxFeeLimit, 0L, 0, 10000, - fakeTokenId, fakeTokenValue, null, dev001Key, dev001Address, blockingStubFull); + response = + PublicMethod.deployContractAndGetResponse( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + fakeTokenId, + fakeTokenValue, + null, + dev001Key, + dev001Address, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("contract validate error : assetBalance must greater than 0.".toLowerCase(), + Assert.assertEquals( + "contract validate error : assetBalance must greater than 0.".toLowerCase(), response.getMessage().toStringUtf8().toLowerCase()); - // deployer didn't have any Long.MAX_VALUE + // deployer didn't have any Long.MAX_VALUE fakeTokenId = Long.toString(Long.MAX_VALUE); fakeTokenValue = 100L; - response = PublicMethod - .deployContractAndGetResponse(contractName, abi, code, "", maxFeeLimit, 0L, 0, 10000, - fakeTokenId, fakeTokenValue, null, dev001Key, dev001Address, blockingStubFull); + response = + PublicMethod.deployContractAndGetResponse( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + fakeTokenId, + fakeTokenValue, + null, + dev001Key, + dev001Address, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("contract validate error : No asset !".toLowerCase(), - response.getMessage().toStringUtf8().toLowerCase()); - // the tokenValue is not enough + Assert.assertEquals( + "contract validate error : No asset !".toLowerCase(), + response.getMessage().toStringUtf8().toLowerCase()); + // the tokenValue is not enough fakeTokenId = assetAccountDev.toStringUtf8(); fakeTokenValue = devAssetCountBefore + 100; - response = PublicMethod - .deployContractAndGetResponse(contractName, abi, code, "", maxFeeLimit, 0L, 0, 10000, - fakeTokenId, fakeTokenValue, null, dev001Key, dev001Address, blockingStubFull); + response = + PublicMethod.deployContractAndGetResponse( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + fakeTokenId, + fakeTokenValue, + null, + dev001Key, + dev001Address, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("contract validate error : assetBalance is not sufficient.".toLowerCase(), + Assert.assertEquals( + "contract validate error : assetBalance is not sufficient.".toLowerCase(), response.getMessage().toStringUtf8().toLowerCase()); - // tokenid is -1 + // tokenid is -1 fakeTokenId = Long.toString(-1); - response = PublicMethod - .deployContractAndGetResponse(contractName, abi, code, "", maxFeeLimit, 0L, 0, 10000, - fakeTokenId, 100, null, dev001Key, dev001Address, blockingStubFull); + response = + PublicMethod.deployContractAndGetResponse( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + fakeTokenId, + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("contract validate error : tokenId must be > 1000000".toLowerCase(), + Assert.assertEquals( + "contract validate error : tokenId must be > 1000000".toLowerCase(), response.getMessage().toStringUtf8().toLowerCase()); PublicMethod.waitProduceNextBlock(blockingStubFull); - // tokenid is 100_0000L + // tokenid is 100_0000L fakeTokenId = Long.toString(100_0000L); - response = PublicMethod - .deployContractAndGetResponse(contractName, abi, code, "", maxFeeLimit, 0L, 0, 10000, - fakeTokenId, 100, null, dev001Key, dev001Address, blockingStubFull); + response = + PublicMethod.deployContractAndGetResponse( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + fakeTokenId, + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("contract validate error : tokenId must be > 1000000".toLowerCase(), + Assert.assertEquals( + "contract validate error : tokenId must be > 1000000".toLowerCase(), response.getMessage().toStringUtf8().toLowerCase()); - // tokenid is Long.MIN_VALUE + // tokenid is Long.MIN_VALUE fakeTokenId = Long.toString(Long.MIN_VALUE); - response = PublicMethod - .deployContractAndGetResponse(contractName, abi, code, "", maxFeeLimit, 0L, 0, 10000, - fakeTokenId, 100, null, dev001Key, dev001Address, blockingStubFull); + response = + PublicMethod.deployContractAndGetResponse( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + fakeTokenId, + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("contract validate error : tokenId must be > 1000000".toLowerCase(), + Assert.assertEquals( + "contract validate error : tokenId must be > 1000000".toLowerCase(), response.getMessage().toStringUtf8().toLowerCase()); PublicMethod.waitProduceNextBlock(blockingStubFull); - // tokenid is 0 + // tokenid is 0 fakeTokenId = Long.toString(0); - response = PublicMethod - .deployContractAndGetResponse(contractName, abi, code, "", maxFeeLimit, 0L, 0, 10000, - fakeTokenId, 100, null, dev001Key, dev001Address, blockingStubFull); + response = + PublicMethod.deployContractAndGetResponse( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + fakeTokenId, + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); Assert.assertEquals( - ("contract validate error : invalid arguments " - + "with tokenValue = 100, tokenId = 0").toLowerCase(), + ("contract validate error : invalid arguments " + "with tokenValue = 100, tokenId = 0") + .toLowerCase(), response.getMessage().toStringUtf8().toLowerCase()); - // tokenvalue is less than 0 + // tokenvalue is less than 0 fakeTokenValue = -1L; - response = PublicMethod - .deployContractAndGetResponse(contractName, abi, code, "", maxFeeLimit, 0L, 0, 10000, - assetAccountDev.toStringUtf8(), fakeTokenValue, null, dev001Key, dev001Address, + response = + PublicMethod.deployContractAndGetResponse( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + assetAccountDev.toStringUtf8(), + fakeTokenValue, + null, + dev001Key, + dev001Address, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("contract validate error : tokenValue must be >= 0".toLowerCase(), + Assert.assertEquals( + "contract validate error : tokenValue must be >= 0".toLowerCase(), response.getMessage().toStringUtf8().toLowerCase()); PublicMethod.waitProduceNextBlock(blockingStubFull); - // tokenvalue is long.min + // tokenvalue is long.min fakeTokenValue = Long.MIN_VALUE; - response = PublicMethod - .deployContractAndGetResponse(contractName, abi, code, "", maxFeeLimit, 0L, 0, 10000, - assetAccountDev.toStringUtf8(), fakeTokenValue, null, dev001Key, dev001Address, + response = + PublicMethod.deployContractAndGetResponse( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + assetAccountDev.toStringUtf8(), + fakeTokenValue, + null, + dev001Key, + dev001Address, blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("contract validate error : tokenValue must be >= 0".toLowerCase(), + Assert.assertEquals( + "contract validate error : tokenValue must be >= 0".toLowerCase(), response.getMessage().toStringUtf8().toLowerCase()); - String tokenId = Long.toString(-1); + String tokenId = Long.toString(-1); long tokenValue = 0; long callValue = 10; - response = PublicMethod - .deployContractAndGetResponse(contractName, abi, code, "", maxFeeLimit, callValue, 0, 10000, - tokenId, tokenValue, null, dev001Key, dev001Address, blockingStubFull); + response = + PublicMethod.deployContractAndGetResponse( + contractName, + abi, + code, + "", + maxFeeLimit, + callValue, + 0, + 10000, + tokenId, + tokenValue, + null, + dev001Key, + dev001Address, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("contract validate error : tokenId must be > 1000000".toLowerCase(), + Assert.assertEquals( + "contract validate error : tokenId must be > 1000000".toLowerCase(), response.getMessage().toStringUtf8().toLowerCase()); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -249,13 +437,27 @@ public void deployTransferTokenContract() { tokenValue = 0; callValue = 10; - response = PublicMethod - .deployContractAndGetResponse(contractName, abi, code, "", maxFeeLimit, callValue, 0, 10000, - tokenId, tokenValue, null, dev001Key, dev001Address, blockingStubFull); + response = + PublicMethod.deployContractAndGetResponse( + contractName, + abi, + code, + "", + maxFeeLimit, + callValue, + 0, + 10000, + tokenId, + tokenValue, + null, + dev001Key, + dev001Address, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("contract validate error : tokenId must be > 1000000".toLowerCase(), + Assert.assertEquals( + "contract validate error : tokenId must be > 1000000".toLowerCase(), response.getMessage().toStringUtf8().toLowerCase()); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -264,48 +466,62 @@ public void deployTransferTokenContract() { tokenValue = 0; callValue = 10; - response = PublicMethod - .deployContractAndGetResponse(contractName, abi, code, "", maxFeeLimit, callValue, 0, 10000, - tokenId, tokenValue, null, dev001Key, dev001Address, blockingStubFull); + response = + PublicMethod.deployContractAndGetResponse( + contractName, + abi, + code, + "", + maxFeeLimit, + callValue, + 0, + 10000, + tokenId, + tokenValue, + null, + dev001Key, + dev001Address, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("contract validate error : tokenId must be > 1000000".toLowerCase(), + Assert.assertEquals( + "contract validate error : tokenId must be > 1000000".toLowerCase(), response.getMessage().toStringUtf8().toLowerCase()); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); long balanceAfter = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountDev, blockingStubFull); - Long userAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountUser, blockingStubFull); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountDev, blockingStubFull); + Long userAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountUser, blockingStubFull); logger.info("after energyLimit is " + energyLimit); logger.info("after energyUsage is " + energyUsage); logger.info("after balanceAfter is " + balanceAfter); logger.info( - "after dev has AssetId: " + assetAccountDev.toStringUtf8() + ", devAssetCountAfter: " + "after dev has AssetId: " + + assetAccountDev.toStringUtf8() + + ", devAssetCountAfter: " + devAssetCountAfter); logger.info( - "after user has AssetId: " + assetAccountDev.toStringUtf8() + ", userAssetCountAfter: " + "after user has AssetId: " + + assetAccountDev.toStringUtf8() + + ", userAssetCountAfter: " + userAssetCountAfter); Assert.assertEquals(devAssetCountBefore, devAssetCountAfter); Assert.assertEquals(userAssetCountBefore, userAssetCountAfter); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, foundationKey, 1, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, foundationKey, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, foundationKey, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken005.java index 269510ba..2041991f 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken005.java @@ -16,10 +16,10 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class ContractTrcToken005 extends TronBaseTest { @@ -29,10 +29,10 @@ public class ContractTrcToken005 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; private byte[] transferTokenContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -40,68 +40,103 @@ public class ContractTrcToken005 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - - @Test(enabled = true, description = "TriggerContract with exception condition", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerContract with exception condition", + groups = {"contract", "daily"}) public void deployTransferTokenContract() { - Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 1100_000_000L, fromAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .sendcoin(user001Address, 2000_000_000L, fromAddress, foundationKey, blockingStubFull)); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 70000L, blockingStubFull), 0, -// 1, ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), 0, 0, -// ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1100_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 2000_000_000L, fromAddress, foundationKey, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 70000L, + // blockingStubFull), 0, + // 1, ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + + // PublicMethod.randomFreezeAmount.getAndAdd(1), 0, 0, + // ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod - .createAssetIssue(dev001Address, tokenName, TotalSupply, 1, 10000, start, end, 1, - description, url, 100000L, 100000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); logger.info("The token name: " + tokenName); logger.info("The token ID: " + assetAccountId.toStringUtf8()); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod - .getAccountResource(dev001Address, blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("before energyLimit is " + energyLimit); logger.info("before energyUsage is " + energyUsage); logger.info("before balanceBefore is " + balanceBefore); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountBefore: " - + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken005.sol"; - String contractName = "tokenTest"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken005.sol"; + String contractName = "tokenTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String tokenId = assetAccountId.toStringUtf8(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String tokenId = assetAccountId.toStringUtf8(); long tokenValue = 200; long callValue = 0; - String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callValue, 0, 10000, tokenId, tokenValue, null, dev001Key, dev001Address, + String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callValue, + 0, + 10000, + tokenId, + tokenValue, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (transferTokenTxid == null || infoById.get().getResultValue() != 0) { @@ -109,33 +144,41 @@ public void deployTransferTokenContract() { } transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(transferTokenContractAddress, blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(transferTokenContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); long balanceAfter = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("after energyLimit is " + energyLimit); logger.info("after energyUsage is " + energyUsage); logger.info("after balanceAfter is " + balanceAfter); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountAfter: " - + devAssetCountAfter); - Long contractAssetCount = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + Long contractAssetCount = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); Assert.assertEquals(Long.valueOf(200), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(200), contractAssetCount); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, blockingStubFull), 0, -// 1, ByteString.copyFrom(user001Address), foundationKey, blockingStubFull)); -// PublicMethod.waitProduceNextBlock(blockingStubFull); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, + // blockingStubFull), 0, + // 1, ByteString.copyFrom(user001Address), foundationKey, blockingStubFull)); + // PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); @@ -149,109 +192,185 @@ public void deployTransferTokenContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + userEnergyLimitBefore); logger.info("before trigger, userEnergyUsageBefore is " + userEnergyUsageBefore); logger.info("before trigger, userBalanceBefore is " + userBalanceBefore); - Long transferAssetBefore = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); + Long transferAssetBefore = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); logger.info( - "before trigger, transferTokenContractAddress has AssetId " + assetAccountId.toStringUtf8() - + ", Count is " + transferAssetBefore); - Long userAssetId = PublicMethod - .getAssetIssueValue(user001Address, ByteString.copyFromUtf8(tokenId), blockingStubFull); + "before trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + transferAssetBefore); + Long userAssetId = + PublicMethod.getAssetIssueValue( + user001Address, ByteString.copyFromUtf8(tokenId), blockingStubFull); logger.info("before userAssetId has AssetId " + tokenId + ", Count is " + userAssetId); - // not such tokenId + // not such tokenId tokenId = Long.toString(Long.valueOf(assetAccountId.toStringUtf8()) + 100000); tokenValue = 10; callValue = 5; - GrpcAPI.Return response = PublicMethod - .triggerContractAndGetResponse(transferTokenContractAddress, - "msgTokenValueAndTokenIdTest()", "#", false, callValue, 1000000000L, tokenId, - tokenValue, user001Address, user001Key, blockingStubFull); + GrpcAPI.Return response = + PublicMethod.triggerContractAndGetResponse( + transferTokenContractAddress, + "msgTokenValueAndTokenIdTest()", + "#", + false, + callValue, + 1000000000L, + tokenId, + tokenValue, + user001Address, + user001Key, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert - .assertEquals("contract validate error : No asset !".toLowerCase(), - response.getMessage().toStringUtf8().toLowerCase()); - // not have this tokenId + Assert.assertEquals( + "contract validate error : No asset !".toLowerCase(), + response.getMessage().toStringUtf8().toLowerCase()); + // not have this tokenId tokenId = assetAccountId.toStringUtf8(); tokenValue = 10; callValue = 5; - response = PublicMethod.triggerContractAndGetResponse(transferTokenContractAddress, - "msgTokenValueAndTokenIdTest()", "#", false, callValue, 1000000000L, tokenId, tokenValue, - user001Address, user001Key, blockingStubFull); + response = + PublicMethod.triggerContractAndGetResponse( + transferTokenContractAddress, + "msgTokenValueAndTokenIdTest()", + "#", + false, + callValue, + 1000000000L, + tokenId, + tokenValue, + user001Address, + user001Key, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("contract validate error : assetbalance must greater than 0.".toLowerCase(), + Assert.assertEquals( + "contract validate error : assetbalance must greater than 0.".toLowerCase(), response.getMessage().toStringUtf8().toLowerCase()); - // tokenId is Long.MAX_VALUE + // tokenId is Long.MAX_VALUE tokenId = Long.toString(Long.MAX_VALUE); tokenValue = 10; callValue = 5; - response = PublicMethod.triggerContractAndGetResponse(transferTokenContractAddress, - "msgTokenValueAndTokenIdTest()", "#", false, callValue, 1000000000L, tokenId, tokenValue, - user001Address, user001Key, blockingStubFull); + response = + PublicMethod.triggerContractAndGetResponse( + transferTokenContractAddress, + "msgTokenValueAndTokenIdTest()", + "#", + false, + callValue, + 1000000000L, + tokenId, + tokenValue, + user001Address, + user001Key, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert - .assertEquals("contract validate error : No asset !".toLowerCase(), - response.getMessage().toStringUtf8().toLowerCase()); + Assert.assertEquals( + "contract validate error : No asset !".toLowerCase(), + response.getMessage().toStringUtf8().toLowerCase()); - Assert.assertTrue(PublicMethod - .transferAsset(user001Address, assetAccountId.toByteArray(), 10L, dev001Address, dev001Key, + Assert.assertTrue( + PublicMethod.transferAsset( + user001Address, + assetAccountId.toByteArray(), + 10L, + dev001Address, + dev001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - // tokenValue is not enough + // tokenValue is not enough tokenId = assetAccountId.toStringUtf8(); tokenValue = 100; callValue = 5; - response = PublicMethod.triggerContractAndGetResponse(transferTokenContractAddress, - "msgTokenValueAndTokenIdTest()", "#", false, callValue, 1000000000L, tokenId, tokenValue, - user001Address, user001Key, blockingStubFull); + response = + PublicMethod.triggerContractAndGetResponse( + transferTokenContractAddress, + "msgTokenValueAndTokenIdTest()", + "#", + false, + callValue, + 1000000000L, + tokenId, + tokenValue, + user001Address, + user001Key, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("contract validate error : assetBalance is not sufficient.".toLowerCase(), + Assert.assertEquals( + "contract validate error : assetBalance is not sufficient.".toLowerCase(), response.getMessage().toStringUtf8().toLowerCase()); - // tokenvalue is less than 0 + // tokenvalue is less than 0 tokenId = assetAccountId.toStringUtf8(); tokenValue = -1; callValue = 5; - response = PublicMethod.triggerContractAndGetResponse(transferTokenContractAddress, - "msgTokenValueAndTokenIdTest()", "#", false, callValue, 1000000000L, tokenId, tokenValue, - user001Address, user001Key, blockingStubFull); + response = + PublicMethod.triggerContractAndGetResponse( + transferTokenContractAddress, + "msgTokenValueAndTokenIdTest()", + "#", + false, + callValue, + 1000000000L, + tokenId, + tokenValue, + user001Address, + user001Key, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("contract validate error : tokenValue must be >= 0".toLowerCase(), + Assert.assertEquals( + "contract validate error : tokenValue must be >= 0".toLowerCase(), response.getMessage().toStringUtf8().toLowerCase()); tokenId = assetAccountId.toStringUtf8(); tokenValue = Long.MIN_VALUE; callValue = 5; - response = PublicMethod.triggerContractAndGetResponse(transferTokenContractAddress, - "msgTokenValueAndTokenIdTest()", "#", false, callValue, 1000000000L, tokenId, tokenValue, - user001Address, user001Key, blockingStubFull); + response = + PublicMethod.triggerContractAndGetResponse( + transferTokenContractAddress, + "msgTokenValueAndTokenIdTest()", + "#", + false, + callValue, + 1000000000L, + tokenId, + tokenValue, + user001Address, + user001Key, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("contract validate error : tokenValue must be >= 0".toLowerCase(), + Assert.assertEquals( + "contract validate error : tokenValue must be >= 0".toLowerCase(), response.getMessage().toStringUtf8().toLowerCase()); /*PublicMethod - .sendcoin(transferTokenContractAddress, 5000000, fromAddress, foundationKey, blockingStubFull); + .sendcoin(transferTokenContractAddress, + 5000000, + fromAddress, + foundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull);*/ // tokenId is 100_0000 @@ -259,85 +378,153 @@ public void deployTransferTokenContract() { tokenValue = 10; callValue = 5; - response = PublicMethod.triggerContractAndGetResponse(transferTokenContractAddress, - "msgTokenValueAndTokenIdTest()", "#", false, callValue, 1000000000L, tokenId, tokenValue, - user001Address, user001Key, blockingStubFull); + response = + PublicMethod.triggerContractAndGetResponse( + transferTokenContractAddress, + "msgTokenValueAndTokenIdTest()", + "#", + false, + callValue, + 1000000000L, + tokenId, + tokenValue, + user001Address, + user001Key, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("contract validate error : tokenId must be > 1000000".toLowerCase(), + Assert.assertEquals( + "contract validate error : tokenId must be > 1000000".toLowerCase(), response.getMessage().toStringUtf8().toLowerCase()); - // tokenId is long.min + // tokenId is long.min tokenId = Long.toString(Long.MIN_VALUE); tokenValue = 10; callValue = 5; - response = PublicMethod.triggerContractAndGetResponse(transferTokenContractAddress, - "msgTokenValueAndTokenIdTest()", "#", false, callValue, 1000000000L, tokenId, tokenValue, - user001Address, user001Key, blockingStubFull); + response = + PublicMethod.triggerContractAndGetResponse( + transferTokenContractAddress, + "msgTokenValueAndTokenIdTest()", + "#", + false, + callValue, + 1000000000L, + tokenId, + tokenValue, + user001Address, + user001Key, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("contract validate error : tokenId must be > 1000000".toLowerCase(), + Assert.assertEquals( + "contract validate error : tokenId must be > 1000000".toLowerCase(), response.getMessage().toStringUtf8().toLowerCase()); - // tokenId is 0 + // tokenId is 0 tokenId = Long.toString(0); tokenValue = 10; callValue = 5; - response = PublicMethod.triggerContractAndGetResponse(transferTokenContractAddress, - "msgTokenValueAndTokenIdTest()", "#", false, callValue, 1000000000L, tokenId, tokenValue, - user001Address, user001Key, blockingStubFull); + response = + PublicMethod.triggerContractAndGetResponse( + transferTokenContractAddress, + "msgTokenValueAndTokenIdTest()", + "#", + false, + callValue, + 1000000000L, + tokenId, + tokenValue, + user001Address, + user001Key, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); Assert.assertEquals( "contract validate error : invalid arguments with tokenValue = 10, tokenId = 0" - .toLowerCase(), response.getMessage().toStringUtf8().toLowerCase()); + .toLowerCase(), + response.getMessage().toStringUtf8().toLowerCase()); /*PublicMethod - .sendcoin(transferTokenContractAddress, 5000000, fromAddress, foundationKey, blockingStubFull); + .sendcoin(transferTokenContractAddress, + 5000000, + fromAddress, + foundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull);*/ tokenId = Long.toString(Long.MIN_VALUE); tokenValue = 0; callValue = 5; - response = PublicMethod.triggerContractAndGetResponse(transferTokenContractAddress, - "msgTokenValueAndTokenIdTest()", "#", false, callValue, 1000000000L, tokenId, tokenValue, - user001Address, user001Key, blockingStubFull); + response = + PublicMethod.triggerContractAndGetResponse( + transferTokenContractAddress, + "msgTokenValueAndTokenIdTest()", + "#", + false, + callValue, + 1000000000L, + tokenId, + tokenValue, + user001Address, + user001Key, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("contract validate error : tokenId must be > 1000000".toLowerCase(), + Assert.assertEquals( + "contract validate error : tokenId must be > 1000000".toLowerCase(), response.getMessage().toStringUtf8().toLowerCase()); - tokenId = Long.toString(-1); tokenValue = 0; callValue = 5; - response = PublicMethod.triggerContractAndGetResponse(transferTokenContractAddress, - "msgTokenValueAndTokenIdTest()", "#", false, callValue, 1000000000L, tokenId, tokenValue, - user001Address, user001Key, blockingStubFull); + response = + PublicMethod.triggerContractAndGetResponse( + transferTokenContractAddress, + "msgTokenValueAndTokenIdTest()", + "#", + false, + callValue, + 1000000000L, + tokenId, + tokenValue, + user001Address, + user001Key, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("contract validate error : tokenId must be > 1000000".toLowerCase(), + Assert.assertEquals( + "contract validate error : tokenId must be > 1000000".toLowerCase(), response.getMessage().toStringUtf8().toLowerCase()); - tokenId = Long.toString(100_0000L); tokenValue = 0; callValue = 5; - response = PublicMethod.triggerContractAndGetResponse(transferTokenContractAddress, - "msgTokenValueAndTokenIdTest()", "#", false, callValue, 1000000000L, tokenId, tokenValue, - user001Address, user001Key, blockingStubFull); + response = + PublicMethod.triggerContractAndGetResponse( + transferTokenContractAddress, + "msgTokenValueAndTokenIdTest()", + "#", + false, + callValue, + 1000000000L, + tokenId, + tokenValue, + user001Address, + user001Key, + blockingStubFull); Assert.assertFalse(response.getResult()); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, response.getCode()); - Assert.assertEquals("contract validate error : tokenId must be > 1000000".toLowerCase(), + Assert.assertEquals( + "contract validate error : tokenId must be > 1000000".toLowerCase(), response.getMessage().toStringUtf8().toLowerCase()); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -352,25 +539,21 @@ public void deployTransferTokenContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + userEnergyLimitAfter); logger.info("after trigger, userEnergyUsageAfter is " + userEnergyUsageAfter); logger.info("after trigger, userBalanceAfter is " + userBalanceAfter); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, foundationKey, 1, dev001Address, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, foundationKey, 0, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, foundationKey, 1, user001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, foundationKey, 1, user001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken011.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken011.java index 56483a57..e7a2f965 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken011.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken011.java @@ -1,7 +1,6 @@ package stest.tron.wallet.dailybuild.trctoken; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.HashMap; import java.util.List; @@ -19,11 +18,12 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ContractTrcToken011 extends TronBaseTest { @@ -33,16 +33,16 @@ public class ContractTrcToken011 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); private byte[] transferTokenContractAddress = null; private byte[] resultContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -50,90 +50,124 @@ public class ContractTrcToken011 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = true, description = "TransferToken with correct value, deploy transfer contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken with correct value, deploy transfer contract", + groups = {"contract", "daily"}) public void test01DeployTransferTokenContract001() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 15048_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 14048_000_000L, fromAddress, - testKey002, blockingStubFull)); - //drop freezeBalanceForReceiver, for transaction null -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), -// 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 15048_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 14048_000_000L, fromAddress, testKey002, blockingStubFull)); + // drop freezeBalanceForReceiver, for transaction null + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + + // PublicMethod.randomFreezeAmount.getAndAdd(1), + // 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, 100000L, - 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Account getAssetIdFromThisAccount = PublicMethod - .queryAccount(dev001Address, blockingStubFull); + Account getAssetIdFromThisAccount = PublicMethod.queryAccount(dev001Address, blockingStubFull); assetAccountId = getAssetIdFromThisAccount.getAssetIssuedID(); logger.info("The token name: " + tokenName); logger.info("The token ID: " + assetAccountId.toStringUtf8()); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("before energyLimit is " + energyLimit); logger.info("before energyUsage is " + energyUsage); logger.info("before balanceBefore is " + balanceBefore); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() - + ", devAssetCountBefore: " + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken011.sol"; - String contractName = "transferTokenContract"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken011.sol"; + String contractName = "transferTokenContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - assetAccountId.toStringUtf8(), 200, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + assetAccountId.toStringUtf8(), + 200, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); long balanceAfter = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("after energyLimit is " + energyLimit); logger.info("after energyUsage is " + energyUsage); logger.info("after balanceAfter is " + balanceAfter); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() - + ", devAssetCountAfter: " + devAssetCountAfter); - - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (infoById.get().getResultValue() != 0) { @@ -141,72 +175,96 @@ public void test01DeployTransferTokenContract001() { } transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(transferTokenContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(transferTokenContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); /*Assert.assertFalse(PublicMethod.transferAsset(transferTokenContractAddress, assetAccountId.toByteArray(), 100L, dev001Address, dev001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull);*/ - Long contractAssetCount = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); + Long contractAssetCount = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); Assert.assertEquals(Long.valueOf(200), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(200), contractAssetCount); } - - @Test(enabled = true, description = "TransferToken with correct value, deploy receive contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken with correct value, deploy receive contract", + groups = {"contract", "daily"}) public void test02DeployRevContract002() { -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 50000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); -// PublicMethod.waitProduceNextBlock(blockingStubFull); - // before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 50000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("before energyLimit is " + energyLimit); logger.info("before energyUsage is " + energyUsage); logger.info("before balance is " + balanceBefore); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() - + ", devAssetCountBefore: " + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken011.sol"; - String contractName = "Result"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken011.sol"; + String contractName = "Result"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String recieveTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 0L, 100, 1000, assetAccountId.toStringUtf8(), - 100, null, dev001Key, dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String recieveTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + 1000, + assetAccountId.toStringUtf8(), + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - // after deploy, check account resource + // after deploy, check account resource accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); long balanceAfter = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("after energyLimit is " + energyLimit); logger.info("after energyUsage is " + energyUsage); logger.info("after balanceAfter is " + balanceAfter); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() - + ", devAssetCountAfter: " + devAssetCountAfter); - - Optional infoById = PublicMethod - .getTransactionInfoById(recieveTokenTxid, blockingStubFull); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + + Optional infoById = + PublicMethod.getTransactionInfoById(recieveTokenTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy receive failed with message: " + infoById.get().getResMessage()); @@ -214,32 +272,43 @@ public void test02DeployRevContract002() { resultContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(resultContractAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(resultContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - Long contractAssetCount = PublicMethod.getAssetIssueValue(resultContractAddress, - assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); + Long contractAssetCount = + PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); Assert.assertEquals(Long.valueOf(100), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(100), contractAssetCount); } - @Test(enabled = true, description = "TransferToken with correct value, transfer to a contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken with correct value, transfer to a contract", + groups = {"contract", "daily"}) public void test03TriggerContract003() { -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.transferAsset(user001Address, - assetAccountId.toByteArray(), 10L, dev001Address, dev001Key, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.transferAsset( + user001Address, + assetAccountId.toByteArray(), + 10L, + dev001Address, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -251,30 +320,45 @@ public void test03TriggerContract003() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + userEnergyLimitBefore); logger.info("before trigger, userEnergyUsageBefore is " + userEnergyUsageBefore); logger.info("before trigger, userBalanceBefore is " + userBalanceBefore); - Long transferAssetBefore = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, + Long transferAssetBefore = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "before trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + transferAssetBefore); + Long receiveAssetBefore = + PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, blockingStubFull); + logger.info( + "before trigger, resultContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + receiveAssetBefore); + String tokenId = assetAccountId.toStringUtf8(); + Long tokenValue = Long.valueOf(1); + Long callValue = Long.valueOf(0); + String param = + "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" + tokenValue + "\"," + tokenId; + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, blockingStubFull); - logger.info("before trigger, transferTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + transferAssetBefore); - Long receiveAssetBefore = PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, - blockingStubFull); - logger.info("before trigger, resultContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + receiveAssetBefore); - String tokenId = assetAccountId.toStringUtf8(); - Long tokenValue = Long.valueOf(1); - Long callValue = Long.valueOf(0); - String param = "\"" + Base58.encode58Check(resultContractAddress) - + "\",\"" + tokenValue + "\"," + tokenId; - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -289,26 +373,26 @@ public void test03TriggerContract003() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + userEnergyLimitAfter); logger.info("after trigger, userEnergyUsageAfter is " + userEnergyUsageAfter); logger.info("after trigger, userBalanceAfter is " + userBalanceAfter); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); TransactionInfo transactionInfo = infoById.get(); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long msgId = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); - Long msgTokenValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); - Long msgCallValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(2))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long msgId = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + Long msgTokenValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + Long msgCallValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(2))); logger.info("msgId: " + msgId); logger.info("msgTokenValue: " + msgTokenValue); @@ -318,33 +402,43 @@ public void test03TriggerContract003() { Assert.assertEquals(tokenValue, msgTokenValue); Assert.assertEquals(callValue, msgCallValue); - SmartContract smartContract = PublicMethod.getContract(infoById.get().getContractAddress() - .toByteArray(), blockingStubFull); - Long transferAssetAfter = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("after trigger, transferTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", transferAssetAfter is " + transferAssetAfter); - Long receiveAssetAfter = PublicMethod.getAssetIssueValue(resultContractAddress, - assetAccountId, blockingStubFull); - logger.info("after trigger, resultContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", receiveAssetAfter is " + receiveAssetAfter); + SmartContract smartContract = + PublicMethod.getContract( + infoById.get().getContractAddress().toByteArray(), blockingStubFull); + Long transferAssetAfter = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "after trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", transferAssetAfter is " + + transferAssetAfter); + Long receiveAssetAfter = + PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, blockingStubFull); + logger.info( + "after trigger, resultContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", receiveAssetAfter is " + + receiveAssetAfter); long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); logger.info("ConsumeURPercent: " + consumeUserPercent); - Assert.assertEquals(receiveAssetAfter - receiveAssetBefore, - transferAssetBefore + 2L - transferAssetAfter); - + Assert.assertEquals( + receiveAssetAfter - receiveAssetBefore, transferAssetBefore + 2L - transferAssetAfter); } - @Test(enabled = true, description = "TransferToken with correct value, get contract tokenBalance", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken with correct value, get contract tokenBalance", + groups = {"contract", "daily"}) public void test04TriggerTokenBalanceContract004() { -// Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(user001Address, 1000_000_000L, -// 0, 1, user001Key, blockingStubFull)); -// PublicMethod.waitProduceNextBlock(blockingStubFull); + // Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(user001Address, 1000_000_000L, + // 0, 1, user001Key, blockingStubFull)); + // PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); @@ -356,18 +450,29 @@ public void test04TriggerTokenBalanceContract004() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, - blockingStubFull).getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, user energy limit is " + userEnergyLimitBefore); logger.info("before trigger, user energy usage is " + userEnergyUsageBefore); logger.info("before trigger, user balance is " + userBalanceBefore); - String param = "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" - + assetAccountId.toStringUtf8() + "\""; - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "getTokenBalnce(address,trcToken)", - param, false, 0, 1000000000L, user001Address, - user001Key, blockingStubFull); + String param = + "\"" + + Base58.encode58Check(resultContractAddress) + + "\",\"" + + assetAccountId.toStringUtf8() + + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "getTokenBalnce(address,trcToken)", + param, + false, + 0, + 1000000000L, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -382,49 +487,42 @@ public void test04TriggerTokenBalanceContract004() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + userEnergyLimitAfter); logger.info("after trigger, userEnergyUsageAfter is " + userEnergyUsageAfter); logger.info("after trigger, userBalanceAfter is " + userBalanceAfter); - Optional infoById = PublicMethod.getTransactionInfoById(triggerTxid, - blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); - SmartContract smartContract = PublicMethod.getContract(infoById.get().getContractAddress() - .toByteArray(), blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract( + infoById.get().getContractAddress().toByteArray(), blockingStubFull); long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); logger.info("ConsumeURPercent: " + consumeUserPercent); - Long triggerResult = ByteArray - .toLong(infoById.get().getContractResult(0).toByteArray()); + Long triggerResult = ByteArray.toLong(infoById.get().getContractResult(0).toByteArray()); logger.info("the receivercontract token by trigger contract: " + triggerResult); - Long assetIssueCount = PublicMethod - .getAssetIssueValue(resultContractAddress, assetAccountId, - blockingStubFull); + Long assetIssueCount = + PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, blockingStubFull); logger.info("the receivercontract token(getaccount): " + assetIssueCount); Assert.assertTrue(assetIssueCount == triggerResult); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); - PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); } + PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken012.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken012.java index 5b29d01d..68d4f1cd 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken012.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken012.java @@ -14,10 +14,11 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j public class ContractTrcToken012 extends TronBaseTest { @@ -26,10 +27,10 @@ public class ContractTrcToken012 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; private byte[] transferTokenContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -37,79 +38,114 @@ public class ContractTrcToken012 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "deploy transfer contract with correct value", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "deploy transfer contract with correct value", + groups = {"contract", "daily"}) public void test01DeployTransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 15048_000_000L, fromAddress, - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 14048_000_000L, fromAddress, - foundationKey, blockingStubFull)); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); -// -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), -// 0, 0, ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 15048_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 14048_000_000L, fromAddress, foundationKey, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); + // + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + + // PublicMethod.randomFreezeAmount.getAndAdd(1), + // 0, 0, ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, 100000L, - 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - assetAccountId = PublicMethod - .queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); + assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); logger.info("The token name: " + tokenName); logger.info("The token ID: " + assetAccountId.toStringUtf8()); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("before energyLimit is " + energyLimit); logger.info("before energyUsage is " + energyUsage); logger.info("before balanceBefore is " + balanceBefore); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() - + ", devAssetCountBefore: " + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken012.sol"; - String contractName = "transferTokenContract"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken012.sol"; + String contractName = "transferTokenContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - assetAccountId.toStringUtf8(), 200, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + assetAccountId.toStringUtf8(), + 200, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); long balanceAfter = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("after energyLimit is " + energyLimit); logger.info("after energyUsage is " + energyUsage); logger.info("after balanceAfter is " + balanceAfter); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() - + ", devAssetCountAfter: " + devAssetCountAfter); - - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (transferTokenTxid == null || infoById.get().getResultValue() != 0) { @@ -117,36 +153,47 @@ public void test01DeployTransferTokenContract() { } transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(transferTokenContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(transferTokenContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); /*Assert.assertFalse(PublicMethod.transferAsset(transferTokenContractAddress, assetAccountId.toByteArray(), 100L, dev001Address, dev001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull);*/ - Long contractAssetCount = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); + Long contractAssetCount = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); Assert.assertEquals(Long.valueOf(200), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(200), contractAssetCount); } - - @Test(description = "TransferToken with correct value, transfer to a normal account", groups = {"contract", "daily"}) + @Test( + description = "TransferToken with correct value, transfer to a normal account", + groups = {"contract", "daily"}) public void test02TriggerContract() { -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(user001Address), foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.transferAsset(user001Address, - assetAccountId.toByteArray(), 10L, dev001Address, dev001Key, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(user001Address), foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + user001Address, + assetAccountId.toByteArray(), + 10L, + dev001Address, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -158,30 +205,45 @@ public void test02TriggerContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + userEnergyLimitBefore); logger.info("before trigger, userEnergyUsageBefore is " + userEnergyUsageBefore); logger.info("before trigger, userBalanceBefore is " + userBalanceBefore); - Long transferAssetBefore = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, + Long transferAssetBefore = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "before trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + transferAssetBefore); + Long receiveAssetBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + logger.info( + "before trigger, receiveTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + receiveAssetBefore); + String tokenId = assetAccountId.toStringUtf8(); + Long tokenValue = Long.valueOf(1); + Long callValue = Long.valueOf(0); + String param = + "\"" + Base58.encode58Check(dev001Address) + "\",\"" + tokenValue + "\"," + tokenId; + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, blockingStubFull); - logger.info("before trigger, transferTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + transferAssetBefore); - Long receiveAssetBefore = PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, - blockingStubFull); - logger.info("before trigger, receiveTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + receiveAssetBefore); - String tokenId = assetAccountId.toStringUtf8(); - Long tokenValue = Long.valueOf(1); - Long callValue = Long.valueOf(0); - String param = "\"" + Base58.encode58Check(dev001Address) - + "\",\"" + tokenValue + "\"," + tokenId; - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -196,47 +258,57 @@ public void test02TriggerContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + userEnergyLimitAfter); logger.info("after trigger, userEnergyUsageAfter is " + userEnergyUsageAfter); logger.info("after trigger, userBalanceAfter is " + userBalanceAfter); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (triggerTxid == null || infoById.get().getResultValue() != 0) { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - SmartContract smartContract = PublicMethod.getContract(infoById.get().getContractAddress() - .toByteArray(), blockingStubFull); - Long transferAssetAfter = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("after trigger, transferTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", transferAssetAfter is " + transferAssetAfter); - Long receiveAssetAfter = PublicMethod.getAssetIssueValue(dev001Address, - assetAccountId, blockingStubFull); - logger.info("after trigger, resultContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", receiveAssetAfter is " + receiveAssetAfter); + SmartContract smartContract = + PublicMethod.getContract( + infoById.get().getContractAddress().toByteArray(), blockingStubFull); + Long transferAssetAfter = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "after trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", transferAssetAfter is " + + transferAssetAfter); + Long receiveAssetAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + logger.info( + "after trigger, resultContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", receiveAssetAfter is " + + receiveAssetAfter); long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); logger.info("ConsumeURPercent: " + consumeUserPercent); - Assert.assertEquals(receiveAssetAfter - receiveAssetBefore, - transferAssetBefore + 2L - transferAssetAfter); + Assert.assertEquals( + receiveAssetAfter - receiveAssetBefore, transferAssetBefore + 2L - transferAssetAfter); } - @Test(description = "TransferToken with correct value, get account tokenBalance", groups = {"contract", "daily"}) + @Test( + description = "TransferToken with correct value, get account tokenBalance", + groups = {"contract", "daily"}) public void test03TriggerTokenBalanceContract() { -// Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(user001Address, 1000_000_000L, -// 0, 1, user001Key, blockingStubFull)); -// PublicMethod.waitProduceNextBlock(blockingStubFull); + // Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(user001Address, 1000_000_000L, + // 0, 1, user001Key, blockingStubFull)); + // PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); @@ -248,18 +320,25 @@ public void test03TriggerTokenBalanceContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, - blockingStubFull).getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, user energy limit is " + userEnergyLimitBefore); logger.info("before trigger, user energy usage is " + userEnergyUsageBefore); logger.info("before trigger, user balance is " + userBalanceBefore); - String param = "\"" + Base58.encode58Check(dev001Address) + "\",\"" - + assetAccountId.toStringUtf8() + "\""; - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "getTokenBalnce(address,trcToken)", - param, false, 0, 1000000000L, user001Address, - user001Key, blockingStubFull); + String param = + "\"" + Base58.encode58Check(dev001Address) + "\",\"" + assetAccountId.toStringUtf8() + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "getTokenBalnce(address,trcToken)", + param, + false, + 0, + 1000000000L, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -275,23 +354,24 @@ public void test03TriggerTokenBalanceContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + userEnergyLimitAfter); logger.info("after trigger, userEnergyUsageAfter is " + userEnergyUsageAfter); logger.info("after trigger, userBalanceAfter is " + userBalanceAfter); - Optional infoById = PublicMethod.getTransactionInfoById(triggerTxid, - blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (triggerTxid == null || infoById.get().getResultValue() != 0) { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - SmartContract smartContract = PublicMethod.getContract(infoById.get().getContractAddress() - .toByteArray(), blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract( + infoById.get().getContractAddress().toByteArray(), blockingStubFull); long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); logger.info("ConsumeURPercent: " + consumeUserPercent); @@ -301,28 +381,23 @@ public void test03TriggerTokenBalanceContract() { if (infoById.get().getResultValue() != 0) { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - Long assetAccountCount = ByteArray - .toLong(infoById.get().getContractResult(0).toByteArray()); + Long assetAccountCount = ByteArray.toLong(infoById.get().getContractResult(0).toByteArray()); logger.info("the receivercontract token from contract: " + assetAccountCount); - Long assetIssueCount = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long assetIssueCount = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("the receivercontract token(getaccount): " + assetIssueCount); Assert.assertEquals(assetIssueCount, assetAccountCount); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); - // unfreeze resource + // unfreeze resource PublicMethod.unFreezeBalance(fromAddress, foundationKey, 1, dev001Address, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, foundationKey, 0, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, foundationKey, 1, user001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, foundationKey, 1, user001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken014.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken014.java index d6402da1..3b6f2a39 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken014.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken014.java @@ -16,11 +16,12 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ContractTrcToken014 extends TronBaseTest { @@ -31,14 +32,14 @@ public class ContractTrcToken014 extends TronBaseTest { private static ByteString assetAccountId = null; private static ByteString assetAccountUser = null; private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] transferTokenContractAddress = null; private byte[] resultContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -46,75 +47,122 @@ public class ContractTrcToken014 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = true, description = "TransferToken with tokenId in exception condition," - + " deploy transfer contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "TransferToken with tokenId in exception condition," + " deploy transfer contract", + groups = {"contract", "daily"}) public void test01DeployTransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 11000_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 11000_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 11000_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 11000_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //dev Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, - 1, 10000, start, end, 1, description, url, 100000L, - 100000L, 1L, 1L, dev001Key, blockingStubFull)); + // dev Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); start = System.currentTimeMillis() + 2000; end = System.currentTimeMillis() + 1000000000; - //user Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(user001Address, tokenName, TotalSupply, - 1, 10000, start, end, 1, description, url, 100000L, - 100000L, 1L, 1L, user001Key, blockingStubFull)); + // user Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + user001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + user001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - assetAccountUser = PublicMethod.queryAccount( - user001Address, blockingStubFull).getAssetIssuedID(); + assetAccountUser = + PublicMethod.queryAccount(user001Address, blockingStubFull).getAssetIssuedID(); logger.info("The assetAccountUser token name: " + tokenName); logger.info("The assetAccountUser token ID: " + assetAccountUser.toStringUtf8()); - assetAccountId = PublicMethod.queryAccount( - dev001Address, blockingStubFull).getAssetIssuedID(); + assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); logger.info("The assetAccountId token name: " + tokenName); logger.info("The assetAccountId token ID: " + assetAccountId.toStringUtf8()); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountBefore = PublicMethod.getAssetIssueValue( - dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("before energyLimit is " + energyLimit); logger.info("before energyUsage is " + energyUsage); logger.info("before balanceBefore is " + balanceBefore); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() - + ", devAssetCountBefore: " + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken014.sol"; - String contractName = "transferTokenContract"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken014.sol"; + String contractName = "transferTokenContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - assetAccountId.toStringUtf8(), 100, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + assetAccountId.toStringUtf8(), + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (transferTokenTxid == null || infoById.get().getResultValue() != 0) { @@ -122,63 +170,88 @@ public void test01DeployTransferTokenContract() { } transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(transferTokenContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(transferTokenContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); long balanceAfter = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("after energyLimit is " + energyLimit); logger.info("after energyUsage is " + energyUsage); logger.info("after balanceAfter is " + balanceAfter); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() - + ", devAssetCountAfter: " + devAssetCountAfter); - Long contractAssetCount = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + Long contractAssetCount = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); Assert.assertEquals(Long.valueOf(100), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(100), contractAssetCount); } - @Test(enabled = true, description = "TransferToken with tokenId in exception condition," - + " deploy receiver contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "TransferToken with tokenId in exception condition," + " deploy receiver contract", + groups = {"contract", "daily"}) public void test02DeployRevContract() { // before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("before energyLimit is " + energyLimit); logger.info("before energyUsage is " + energyUsage); logger.info("before balance is " + balanceBefore); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() - + ", devAssetCountBefore: " + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken014.sol"; - String contractName = "Result"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken014.sol"; + String contractName = "Result"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String recieveTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 0L, 100, 1000, assetAccountId.toStringUtf8(), - 100, null, dev001Key, dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String recieveTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + 1000, + assetAccountId.toStringUtf8(), + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(recieveTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(recieveTokenTxid, blockingStubFull); if (recieveTokenTxid == null || infoById.get().getResultValue() != 0) { Assert.fail("deploy receive failed with message: " + infoById.get().getResMessage()); @@ -186,40 +259,53 @@ public void test02DeployRevContract() { resultContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(resultContractAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(resultContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - Long contractAssetCount = PublicMethod.getAssetIssueValue(resultContractAddress, - assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); - // after deploy, check account resource + Long contractAssetCount = + PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); + // after deploy, check account resource accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); long balanceAfter = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("after energyLimit is " + energyLimit); logger.info("after energyUsage is " + energyUsage); logger.info("after balanceAfter is " + balanceAfter); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() - + ", devAssetCountAfter: " + devAssetCountAfter); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); Assert.assertEquals(Long.valueOf(100), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(100), contractAssetCount); } - @Test(enabled = true, description = "TransferToken with tokenId in exception condition," - + " transfer to contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken with tokenId in exception condition," + " transfer to contract", + groups = {"contract", "daily"}) public void test03TriggerContract() { - Assert.assertTrue(PublicMethod.transferAsset(user001Address, - assetAccountId.toByteArray(), 10L, dev001Address, dev001Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + user001Address, + assetAccountId.toByteArray(), + 10L, + dev001Address, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -231,203 +317,302 @@ public void test03TriggerContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + userEnergyLimitBefore); logger.info("before trigger, userEnergyUsageBefore is " + userEnergyUsageBefore); logger.info("before trigger, userBalanceBefore is " + userBalanceBefore); - Long transferAssetBefore = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("before trigger, transferTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + transferAssetBefore); - Long receiveAssetBefore = PublicMethod.getAssetIssueValue(resultContractAddress, - assetAccountId, blockingStubFull); - logger.info("before trigger, resultContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + receiveAssetBefore); - Long devAssetBefore = PublicMethod.getAssetIssueValue(dev001Address, - assetAccountId, blockingStubFull); - logger.info("before trigger, dev001Address has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + devAssetBefore); - // transfer a not exist TokenId, to a contract + Long transferAssetBefore = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "before trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + transferAssetBefore); + Long receiveAssetBefore = + PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, blockingStubFull); + logger.info( + "before trigger, resultContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + receiveAssetBefore); + Long devAssetBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + logger.info( + "before trigger, dev001Address has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + devAssetBefore); + // transfer a not exist TokenId, to a contract String tokenId = assetAccountUser.toStringUtf8(); - Long tokenValue = Long.valueOf(1); - Long callValue = Long.valueOf(0); - String param = "\"" + Base58.encode58Check(resultContractAddress) - + "\",\"" + tokenValue + "\"," + tokenId; - String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + Long tokenValue = Long.valueOf(1); + Long callValue = Long.valueOf(0); + String param = + "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" + tokenValue + "\"," + tokenId; + String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - Assert.assertEquals("REVERT opcode executed", - infoById.get().getResMessage().toStringUtf8()); - // transfer a not exist TokenId, to a normal account + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); + // transfer a not exist TokenId, to a normal account tokenId = assetAccountUser.toStringUtf8(); tokenValue = Long.valueOf(1); callValue = Long.valueOf(0); - param = "\"" + Base58.encode58Check(dev001Address) - + "\",\"" + tokenValue + "\"," + tokenId; - - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + param = "\"" + Base58.encode58Check(dev001Address) + "\",\"" + tokenValue + "\"," + tokenId; + + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - Assert.assertEquals("REVERT opcode executed", - infoById.get().getResMessage().toStringUtf8()); - // tokenValue is not enough + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); + // tokenValue is not enough tokenId = assetAccountId.toStringUtf8(); tokenValue = transferAssetBefore + 100; callValue = Long.valueOf(0); - param = "\"" + Base58.encode58Check(resultContractAddress) - + "\",\"" + tokenValue + "\"," + tokenId; - - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + param = + "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" + tokenValue + "\"," + tokenId; + + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); - // tokenValue is not enough, transfer to a normal account + // tokenValue is not enough, transfer to a normal account tokenId = assetAccountId.toStringUtf8(); tokenValue = transferAssetBefore + 100; callValue = Long.valueOf(0); - param = "\"" + Base58.encode58Check(dev001Address) - + "\",\"" + tokenValue + "\"," + tokenId; - - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + param = "\"" + Base58.encode58Check(dev001Address) + "\",\"" + tokenValue + "\"," + tokenId; + + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); - // TokenId is long.max, to a contract + // TokenId is long.max, to a contract String fackTokenId = Long.toString(Long.MAX_VALUE); - Long fakeValue = 1L; - - param = "\"" + Base58.encode58Check(resultContractAddress) - + "\"," + fakeValue + ",\"" + fackTokenId + "\""; - - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, 0, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + Long fakeValue = 1L; + + param = + "\"" + + Base58.encode58Check(resultContractAddress) + + "\"," + + fakeValue + + ",\"" + + fackTokenId + + "\""; + + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + 0, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); - // TokenId is not exist, to a contract + // TokenId is not exist, to a contract fackTokenId = Long.toString(Long.valueOf(assetAccountId.toStringUtf8()) + 10000); fakeValue = 1L; - param = "\"" + Base58.encode58Check(resultContractAddress) - + "\"," + fakeValue + ",\"" + fackTokenId + "\""; - - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, 0, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + param = + "\"" + + Base58.encode58Check(resultContractAddress) + + "\"," + + fakeValue + + ",\"" + + fackTokenId + + "\""; + + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + 0, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); - // TokenId is long.max, to a normal account + // TokenId is long.max, to a normal account fackTokenId = Long.toString(Long.MAX_VALUE); fakeValue = 1L; - param = "\"" + Base58.encode58Check(dev001Address) - + "\"," + fakeValue + ",\"" + fackTokenId + "\""; - - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, 0, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + param = + "\"" + Base58.encode58Check(dev001Address) + "\"," + fakeValue + ",\"" + fackTokenId + "\""; + + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + 0, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); - // TokenId is not exist, to a normal account + // TokenId is not exist, to a normal account fackTokenId = Long.toString(Long.valueOf(assetAccountId.toStringUtf8()) + 10000); fakeValue = 1L; - param = "\"" + Base58.encode58Check(dev001Address) - + "\"," + fakeValue + ",\"" + fackTokenId + "\""; - - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, 0, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + param = + "\"" + Base58.encode58Check(dev001Address) + "\"," + fakeValue + ",\"" + fackTokenId + "\""; + + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + 0, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); - // tokenValue is long.min, transfer to a contract + // tokenValue is long.min, transfer to a contract tokenId = assetAccountId.toStringUtf8(); tokenValue = Long.MIN_VALUE; callValue = Long.valueOf(0); - param = "\"" + Base58.encode58Check(resultContractAddress) - + "\",\"" + tokenValue + "\"," + tokenId; - - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + param = + "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" + tokenValue + "\"," + tokenId; + + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - Assert.assertEquals("endowment out of long range", - infoById.get().getResMessage().toStringUtf8()); - // tokenValue is long.min, transfer to a normal account - param = "\"" + Base58.encode58Check(dev001Address) - + "\",\"" + tokenValue + "\"," + tokenId; - - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + Assert.assertEquals( + "endowment out of long range", infoById.get().getResMessage().toStringUtf8()); + // tokenValue is long.min, transfer to a normal account + param = "\"" + Base58.encode58Check(dev001Address) + "\",\"" + tokenValue + "\"," + tokenId; + + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - Assert.assertEquals("endowment out of long range", - infoById.get().getResMessage().toStringUtf8()); + Assert.assertEquals( + "endowment out of long range", infoById.get().getResMessage().toStringUtf8()); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitAfter = accountResource.getEnergyLimit(); @@ -441,27 +626,38 @@ public void test03TriggerContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + userEnergyLimitAfter); logger.info("after trigger, userEnergyUsageAfter is " + userEnergyUsageAfter); logger.info("after trigger, userBalanceAfter is " + userBalanceAfter); - SmartContract smartContract = PublicMethod.getContract(infoById.get().getContractAddress() - .toByteArray(), blockingStubFull); - Long transferAssetAfter = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("after trigger, transferTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", transferAssetAfter is " + transferAssetAfter); - Long receiveAssetAfter = PublicMethod.getAssetIssueValue(resultContractAddress, - assetAccountId, blockingStubFull); - logger.info("after trigger, resultContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", receiveAssetAfter is " + receiveAssetAfter); - Long devAssetAfter = PublicMethod.getAssetIssueValue(dev001Address, - assetAccountId, blockingStubFull); - logger.info("after trigger, dev001Address has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + devAssetAfter); + SmartContract smartContract = + PublicMethod.getContract( + infoById.get().getContractAddress().toByteArray(), blockingStubFull); + Long transferAssetAfter = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "after trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", transferAssetAfter is " + + transferAssetAfter); + Long receiveAssetAfter = + PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, blockingStubFull); + logger.info( + "after trigger, resultContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", receiveAssetAfter is " + + receiveAssetAfter); + Long devAssetAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + logger.info( + "after trigger, dev001Address has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + devAssetAfter); long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); logger.info("ConsumeURPercent: " + consumeUserPercent); @@ -471,16 +667,13 @@ public void test03TriggerContract() { Assert.assertEquals(transferAssetBefore, transferAssetAfter); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken018.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken018.java index bafc37bb..969b1035 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken018.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken018.java @@ -16,10 +16,10 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class ContractTrcToken018 extends TronBaseTest { @@ -31,10 +31,10 @@ public class ContractTrcToken018 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); private byte[] transferTokenContractAddress = null; private byte[] receiveTokenContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -45,65 +45,101 @@ public class ContractTrcToken018 extends TronBaseTest { private byte[] tmpAddress = ecKey3.getAddress(); private String tmp001Key = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = true, description = "Transfer token to an inactive account", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Transfer token to an inactive account", + groups = {"contract", "daily"}) public void testDeployTransferTokenContract() { - Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 1100_000_000L, fromAddress, testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod - .sendcoin(user001Address, 2200_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 2200_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 50000L, blockingStubFull), 0, -// 1, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.addAndGet(1), 0, 0, -// ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); -// PublicMethod.waitProduceNextBlock(blockingStubFull); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 50000L, + // blockingStubFull), 0, + // 1, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + + // PublicMethod.randomFreezeAmount.addAndGet(1), 0, 0, + // ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + // PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod - .createAssetIssue(dev001Address, tokenName, TotalSupply, 1, 10000, start, end, 1, - description, url, 100000L, 100000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); logger.info("The token name: " + tokenName); logger.info("The token ID: " + assetAccountId.toStringUtf8()); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod - .getAccountResource(dev001Address, blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("before energyLimit is " + energyLimit); logger.info("before energyUsage is " + energyUsage); logger.info("before balanceBefore is " + balanceBefore); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountBefore: " - + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken023.sol"; - String contractName = "tokenTest"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken023.sol"; + String contractName = "tokenTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 0, - 10000, assetAccountId.toStringUtf8(), 200, null, dev001Key, dev001Address, + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + assetAccountId.toStringUtf8(), + 200, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); logger.info("Delpoy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (transferTokenTxid == null || infoById.get().getResultValue() != 0) { @@ -111,40 +147,53 @@ public void testDeployTransferTokenContract() { } transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(transferTokenContractAddress, blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(transferTokenContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); long balanceAfter = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("after energyLimit is " + energyLimit); logger.info("after energyUsage is " + energyUsage); logger.info("after balanceAfter is " + balanceAfter); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountAfter: " - + devAssetCountAfter); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); /*Assert.assertFalse(PublicMethod .transferAsset(transferTokenContractAddress, assetAccountId.toByteArray(), 100L, dev001Address, dev001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull);*/ - Long contractAssetCount = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); + Long contractAssetCount = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); Assert.assertEquals(Long.valueOf(200), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(200), contractAssetCount); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, blockingStubFull), 0, -// 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, + // blockingStubFull), 0, + // 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod - .transferAsset(user001Address, assetAccountId.toByteArray(), 10L, dev001Address, dev001Key, + Assert.assertTrue( + PublicMethod.transferAsset( + user001Address, + assetAccountId.toByteArray(), + 10L, + dev001Address, + dev001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -161,28 +210,42 @@ public void testDeployTransferTokenContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + userEnergyLimitBefore); logger.info("before trigger, userEnergyUsageBefore is " + userEnergyUsageBefore); logger.info("before trigger, userBalanceBefore is " + userBalanceBefore); - Long transferAssetBefore = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); + Long transferAssetBefore = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); logger.info( - "before trigger, transferTokenContractAddress has AssetId " + assetAccountId.toStringUtf8() - + ", Count is " + transferAssetBefore); - Long receiveAssetBefore = PublicMethod - .getAssetIssueValue(tmpAddress, assetAccountId, blockingStubFull); + "before trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + transferAssetBefore); + Long receiveAssetBefore = + PublicMethod.getAssetIssueValue(tmpAddress, assetAccountId, blockingStubFull); logger.info( - "before trigger, receiveTokenContractAddress has AssetId " + assetAccountId.toStringUtf8() - + ", Count is " + receiveAssetBefore); - String param = + "before trigger, receiveTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + receiveAssetBefore); + String param = "\"" + Base58.encode58Check(tmpAddress) + "\"," + assetAccountId.toStringUtf8() + ",\"1\""; - final String triggerTxid = PublicMethod - .triggerContract(transferTokenContractAddress, "TransferTokenTo(address,trcToken,uint256)", - param, false, 0, 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, - user001Key, blockingStubFull); + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "TransferTokenTo(address,trcToken,uint256)", + param, + false, + 0, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitAfter = accountResource.getEnergyLimit(); @@ -196,8 +259,8 @@ public void testDeployTransferTokenContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + userEnergyLimitAfter); logger.info("after trigger, userEnergyUsageAfter is " + userEnergyUsageAfter); @@ -206,32 +269,35 @@ public void testDeployTransferTokenContract() { infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(SUCESS, infoById.get().getResult()); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); - logger.info("infoById.get().getResMessage().toStringUtf8(): " + infoById.get().getResMessage() - .toStringUtf8()); + logger.info( + "infoById.get().getResMessage().toStringUtf8(): " + + infoById.get().getResMessage().toStringUtf8()); /*Assert.assertEquals( - "transfer trc10 failed: Validate InternalTransfer error, no ToAccount. " - + "And not allowed to create account in smart contract.", - infoById.get().getResMessage().toStringUtf8());*/ + "transfer trc10 failed: Validate InternalTransfer error, no ToAccount. " + + "And not allowed to create account in smart contract.", + infoById.get().getResMessage().toStringUtf8());*/ - Long transferAssetAfter = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); + Long transferAssetAfter = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); logger.info( - "after trigger, transferTokenContractAddress has AssetId " + assetAccountId.toStringUtf8() - + ", transferAssetAfter is " + transferAssetAfter); - Long receiveAssetAfter = PublicMethod - .getAssetIssueValue(tmpAddress, assetAccountId, blockingStubFull); + "after trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", transferAssetAfter is " + + transferAssetAfter); + Long receiveAssetAfter = + PublicMethod.getAssetIssueValue(tmpAddress, assetAccountId, blockingStubFull); logger.info( - "after trigger, receiveTokenAddress has AssetId " + assetAccountId.toStringUtf8() - + ", receiveAssetAfter is " + receiveAssetAfter); + "after trigger, receiveTokenAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", receiveAssetAfter is " + + receiveAssetAfter); Assert.assertEquals(receiveAssetAfter, Long.valueOf(receiveAssetBefore + 1)); Assert.assertEquals(transferAssetBefore, Long.valueOf(transferAssetAfter - 1)); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); @@ -239,7 +305,6 @@ public void shutdown() throws InterruptedException { PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken023.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken023.java index 260eb3ba..2c6dba45 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken023.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken023.java @@ -14,123 +14,171 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ContractTrcToken023 extends TronBaseTest { - private static final long now = System.currentTimeMillis(); private static final long TotalSupply = 10000000L; private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; byte[] transferTokenContractAddress; byte[] btestAddress; - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] dev001Address = ecKey1.getAddress(); String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] user001Address = ecKey2.getAddress(); String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private static int randomInt(int minInt, int maxInt) { return (int) Math.round(Math.random() * (maxInt - minInt) + minInt); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = true, description = "deploy contract for transfer token", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "deploy contract for transfer token", + groups = {"contract", "daily"}) public void deploy01TransferTokenContract() { - Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 4048000000L, foundationAddress, foundationKey, blockingStubFull)); - // freeze balance - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(dev001Address, 204800000, - 0, 1, dev001Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 4048000000L, foundationAddress, foundationKey, blockingStubFull)); + // freeze balance + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, - 100000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - int i = randomInt(6666666, 9999999); + int i = randomInt(6666666, 9999999); ByteString tokenId1 = ByteString.copyFromUtf8(String.valueOf(i)); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); - // deploy transferTokenContract + // deploy transferTokenContract int originEnergyLimit = 50000; - String filePath2 = "src/test/resources/soliditycode/contractTrcToken023.sol"; - String contractName2 = "tokenTest"; + String filePath2 = "src/test/resources/soliditycode/contractTrcToken023.sol"; + String contractName2 = "tokenTest"; HashMap retMap2 = PublicMethod.getBycodeAbi(filePath2, contractName2); - String code2 = retMap2.get("byteCode").toString(); - String abi2 = retMap2.get("abI").toString(); - transferTokenContractAddress = PublicMethod - .deployContract(contractName2, abi2, code2, "", maxFeeLimit, - 1000000000L, 0, originEnergyLimit, "0", - 0, null, dev001Key, dev001Address, + String code2 = retMap2.get("byteCode").toString(); + String abi2 = retMap2.get("abI").toString(); + transferTokenContractAddress = + PublicMethod.deployContract( + contractName2, + abi2, + code2, + "", + maxFeeLimit, + 1000000000L, + 0, + originEnergyLimit, + "0", + 0, + null, + dev001Key, + dev001Address, blockingStubFull); - String contractName = "B"; + String contractName = "B"; HashMap retMap = PublicMethod.getBycodeAbi(filePath2, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - btestAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000000L, 0, originEnergyLimit, "0", - 0, null, dev001Key, dev001Address, + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + btestAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000000L, + 0, + originEnergyLimit, + "0", + 0, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - /*Assert - .assertFalse(PublicMethod.sendcoin(transferTokenContractAddress, 1000000000L, foundationAddress, - foundationKey, blockingStubFull)); - Assert - .assertFalse(PublicMethod.sendcoin(btestAddress, 1000000000L, foundationAddress, + /*Assert.assertFalse(PublicMethod.sendcoin( + transferTokenContractAddress, 1000000000L, + foundationAddress, foundationKey, blockingStubFull)); + Assert.assertFalse(PublicMethod.sendcoin( + btestAddress, 1000000000L, foundationAddress, foundationKey, blockingStubFull));*/ // devAddress transfer token to userAddress - PublicMethod.transferAsset(transferTokenContractAddress, assetAccountId.toByteArray(), - 100, dev001Address, dev001Key, blockingStubFull); + PublicMethod.transferAsset( + transferTokenContractAddress, + assetAccountId.toByteArray(), + 100, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "transfer token which from address does not have", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "transfer token which from address does not have", + groups = {"contract", "daily"}) public void deploy02TransferTokenContract() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); info = PublicMethod.queryAccount(dev001Address, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long beforeAssetIssueDevAddress = PublicMethod.getAssetIssueValue(dev001Address, - assetAccountId,blockingStubFull); - Long beforeAssetIssueContractAddress = PublicMethod.getAssetIssueValue( - transferTokenContractAddress, assetAccountId,blockingStubFull); - Long beforeAssetIssueBAddress = PublicMethod.getAssetIssueValue(btestAddress, - assetAccountId, blockingStubFull); - Long beforeBalanceContractAddress = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long beforeAssetIssueBAddress = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long beforeBalanceContractAddress = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); @@ -141,29 +189,43 @@ public void deploy02TransferTokenContract() { logger.info("beforeAssetIssueDevAddress:" + beforeAssetIssueDevAddress); logger.info("beforeBalanceContractAddress:" + beforeBalanceContractAddress); - String param = "\"" + Base58.encode58Check(btestAddress) + "\",\"" - + assetAccountId.toStringUtf8() + "\",\"1\""; - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "TransferTokenTo(address,trcToken,uint256)", param, false, 0, - 1000000000L, "0", 0, dev001Address, dev001Key, blockingStubFull); + String param = + "\"" + + Base58.encode58Check(btestAddress) + + "\",\"" + + assetAccountId.toStringUtf8() + + "\",\"1\""; + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "TransferTokenTo(address,trcToken,uint256)", + param, + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account infoafter = PublicMethod.queryAccount(dev001Address, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long afterAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueBAddress = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - Long afterBalanceContractAddress = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); - + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueBAddress = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long afterBalanceContractAddress = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -174,28 +236,22 @@ public void deploy02TransferTokenContract() { logger.info("afterAssetIssueBAddress:" + afterAssetIssueBAddress); logger.info("afterBalanceContractAddress:" + afterBalanceContractAddress); - - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 1); Assert.assertEquals(afterBalanceContractAddress, beforeBalanceContractAddress); Assert.assertTrue(afterAssetIssueContractAddress == beforeAssetIssueContractAddress); Assert.assertTrue(afterAssetIssueBAddress == beforeAssetIssueBAddress); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); - PublicMethod.unFreezeBalance(foundationAddress, foundationKey, 0, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(foundationAddress, foundationKey, 1, dev001Address, blockingStubFull); } - - + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 1, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken026.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken026.java index 5bacf8b5..1377fd57 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken026.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken026.java @@ -14,16 +14,16 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ContractTrcToken026 extends TronBaseTest { - private static final long now = System.currentTimeMillis(); private static final long TotalSupply = 10000000L; private static ByteString assetAccountId = null; @@ -37,99 +37,153 @@ public class ContractTrcToken026 extends TronBaseTest { ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] user001Address = ecKey2.getAddress(); String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private static int randomInt(int minInt, int maxInt) { return (int) Math.round(Math.random() * (maxInt - minInt) + minInt); } - - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Deploy transferToken contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy transferToken contract", + groups = {"contract", "daily"}) public void deploy01TransferTokenContract001() { PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 4048000000L, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 4048000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - // freeze balance - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(dev001Address, 204800000, - 0, 1, dev001Key, blockingStubFull)); + // freeze balance + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 100, start, end, 1, description, url, 10000L, - 10000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); - // deploy transferTokenContract + // deploy transferTokenContract int originEnergyLimit = 50000; - String filePath = "src/test/resources/soliditycode/contractTrcToken026.sol"; - String contractName = "B"; + String filePath = "src/test/resources/soliditycode/contractTrcToken026.sol"; + String contractName = "B"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - btestAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 0, originEnergyLimit, assetAccountId.toStringUtf8(), - 100, null, dev001Key, dev001Address, blockingStubFull); - String contractName1 = "C"; + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + btestAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + originEnergyLimit, + assetAccountId.toStringUtf8(), + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); + String contractName1 = "C"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - ctestAddress = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, - 0L, 0, originEnergyLimit, assetAccountId.toStringUtf8(), - 100, null, dev001Key, dev001Address, + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + ctestAddress = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 0L, + 0, + originEnergyLimit, + assetAccountId.toStringUtf8(), + 100, + null, + dev001Key, + dev001Address, blockingStubFull); - String contractName2 = "token"; + String contractName2 = "token"; HashMap retMap2 = PublicMethod.getBycodeAbi(filePath, contractName2); - String code2 = retMap2.get("byteCode").toString(); - String abi2 = retMap2.get("abI").toString(); - transferTokenContractAddress = PublicMethod - .deployContract(contractName2, abi2, code2, "", maxFeeLimit, - 1000000000L, 0, originEnergyLimit, assetAccountId.toStringUtf8(), - 100, null, dev001Key, dev001Address, + String code2 = retMap2.get("byteCode").toString(); + String abi2 = retMap2.get("abI").toString(); + transferTokenContractAddress = + PublicMethod.deployContract( + contractName2, + abi2, + code2, + "", + maxFeeLimit, + 1000000000L, + 0, + originEnergyLimit, + assetAccountId.toStringUtf8(), + 100, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - } - @Test(enabled = true, description = "Multistage call transferToken use right tokenID", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Multistage call transferToken use right tokenID", + groups = {"contract", "daily"}) public void deploy02TransferTokenContract002() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); info = PublicMethod.queryAccount(dev001Address, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long beforeAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long beforeAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long beforeAssetIssueBAddress = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - Long beforeAssetIssueCAddress = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - Long beforeBalanceContractAddress = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long beforeAssetIssueBAddress = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long beforeAssetIssueCAddress = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + Long beforeBalanceContractAddress = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); @@ -141,34 +195,50 @@ public void deploy02TransferTokenContract002() { logger.info("beforeAssetIssueDevAddress:" + beforeAssetIssueDevAddress); logger.info("beforeBalanceContractAddress:" + beforeBalanceContractAddress); - // 1.user trigger A to transfer token to B + // 1.user trigger A to transfer token to B String param = - "\"" + Base58.encode58Check(btestAddress) + "\",\"" + Base58.encode58Check(ctestAddress) - + "\",\"" + Base58.encode58Check(transferTokenContractAddress) - + "\",1,\"" + assetAccountId.toStringUtf8() + "\""; - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "testInCall(address,address,address,uint256,trcToken)", - param, false, 0, 1000000000L, "0", - 0, dev001Address, dev001Key, blockingStubFull); + "\"" + + Base58.encode58Check(btestAddress) + + "\",\"" + + Base58.encode58Check(ctestAddress) + + "\",\"" + + Base58.encode58Check(transferTokenContractAddress) + + "\",1,\"" + + assetAccountId.toStringUtf8() + + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "testInCall(address,address,address,uint256,trcToken)", + param, + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account infoafter = PublicMethod.queryAccount(dev001Address, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long afterAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueBAddress = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueCAddress = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - Long afterBalanceContractAddress = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueBAddress = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueCAddress = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + Long afterBalanceContractAddress = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -179,8 +249,8 @@ public void deploy02TransferTokenContract002() { logger.info("afterAssetIssueCAddress:" + afterAssetIssueCAddress); logger.info("afterBalanceContractAddress:" + afterBalanceContractAddress); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertEquals(afterBalanceContractAddress, beforeBalanceContractAddress); Assert.assertTrue(afterAssetIssueContractAddress == beforeAssetIssueContractAddress + 1); @@ -188,25 +258,29 @@ public void deploy02TransferTokenContract002() { Assert.assertTrue(afterAssetIssueCAddress == beforeAssetIssueCAddress - 1); } - @Test(enabled = true, description = "Multistage call transferToken use fake tokenID", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Multistage call transferToken use fake tokenID", + groups = {"contract", "daily"}) public void deploy03TransferTokenContract003() { Account infoafter = PublicMethod.queryAccount(dev001Address, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long afterAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueBAddress = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueCAddress = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - Long afterBalanceContractAddress = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueBAddress = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueCAddress = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + Long afterBalanceContractAddress = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -217,40 +291,53 @@ public void deploy03TransferTokenContract003() { logger.info("afterAssetIssueBAddress:" + afterAssetIssueBAddress); logger.info("afterAssetIssueCAddress:" + afterAssetIssueCAddress); logger.info("afterBalanceContractAddress:" + afterBalanceContractAddress); - //3. user trigger A to transfer token to B + // 3. user trigger A to transfer token to B int i = randomInt(6666666, 9999999); ByteString tokenId1 = ByteString.copyFromUtf8(String.valueOf(i)); - String param1 = - "\"" + Base58.encode58Check(btestAddress) + "\",\"" + Base58.encode58Check(ctestAddress) - + "\",\"" + Base58.encode58Check(transferTokenContractAddress) - + "\",1,\"" + tokenId1 - .toStringUtf8() + String param1 = + "\"" + + Base58.encode58Check(btestAddress) + + "\",\"" + + Base58.encode58Check(ctestAddress) + + "\",\"" + + Base58.encode58Check(transferTokenContractAddress) + + "\",1,\"" + + tokenId1.toStringUtf8() + "\""; - final String triggerTxid1 = PublicMethod.triggerContract(transferTokenContractAddress, - "testInCall(address,address,address,uint256,trcToken)", - param1, false, 0, 1000000000L, "0", - 0, dev001Address, dev001Key, - blockingStubFull); + final String triggerTxid1 = + PublicMethod.triggerContract( + transferTokenContractAddress, + "testInCall(address,address,address,uint256,trcToken)", + param1, + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account infoafter1 = PublicMethod.queryAccount(dev001Address, blockingStubFull); - AccountResourceMessage resourceInfoafter1 = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); - Long afterBalance1 = infoafter1.getBalance(); - Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); - Long afterAssetIssueDevAddress1 = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); - Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); - final Long afterAssetIssueContractAddress1 = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueBAddress1 = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueCAddress1 = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - Long afterBalanceContractAddress1 = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); + AccountResourceMessage resourceInfoafter1 = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterAssetIssueDevAddress1 = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + final Long afterAssetIssueContractAddress1 = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueBAddress1 = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueCAddress1 = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + Long afterBalanceContractAddress1 = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("afterBalance1:" + afterBalance1); logger.info("afterEnergyUsed1:" + afterEnergyUsed1); @@ -262,8 +349,8 @@ public void deploy03TransferTokenContract003() { logger.info("afterAssetIssueCAddress1:" + afterAssetIssueCAddress1); logger.info("afterBalanceContractAddress1:" + afterBalanceContractAddress1); - Optional infoById1 = PublicMethod - .getTransactionInfoById(triggerTxid1, blockingStubFull); + Optional infoById1 = + PublicMethod.getTransactionInfoById(triggerTxid1, blockingStubFull); Assert.assertTrue(infoById1.get().getResultValue() == 0); Assert.assertEquals(afterBalanceContractAddress, afterBalanceContractAddress1); Assert.assertTrue(afterAssetIssueContractAddress == afterAssetIssueContractAddress1); @@ -271,45 +358,62 @@ public void deploy03TransferTokenContract003() { Assert.assertTrue(afterAssetIssueCAddress == afterAssetIssueCAddress1); } - @Test(enabled = true, description = "Multistage call transferToken token value not enough", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Multistage call transferToken token value not enough", + groups = {"contract", "daily"}) public void deploy04TransferTokenContract004() { - final Long afterAssetIssueContractAddress1 = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - final Long afterAssetIssueBAddress1 = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - final Long afterAssetIssueCAddress1 = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - final Long afterBalanceContractAddress1 = + final Long afterAssetIssueContractAddress1 = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + final Long afterAssetIssueBAddress1 = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + final Long afterAssetIssueCAddress1 = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + final Long afterBalanceContractAddress1 = PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("afterAssetIssueDevAddress:" + afterAssetIssueContractAddress1); logger.info("afterAssetIssueBAddress:" + afterAssetIssueBAddress1); logger.info("afterAssetIssueCAddress:" + afterAssetIssueCAddress1); logger.info("afterBalanceContractAddress:" + afterBalanceContractAddress1); - //4. user trigger A to transfer token to B + // 4. user trigger A to transfer token to B String param2 = - "\"" + Base58.encode58Check(btestAddress) + "\",\"" + Base58.encode58Check(ctestAddress) - + "\",\"" + Base58.encode58Check(transferTokenContractAddress) - + "\",10000000,\"" + assetAccountId - .toStringUtf8() + "\"" + + Base58.encode58Check(btestAddress) + + "\",\"" + + Base58.encode58Check(ctestAddress) + + "\",\"" + + Base58.encode58Check(transferTokenContractAddress) + + "\",10000000,\"" + + assetAccountId.toStringUtf8() + "\""; - final String triggerTxid2 = PublicMethod.triggerContract(transferTokenContractAddress, - "testInCall(address,address,address,uint256,trcToken)", - param2, false, 0, 1000000000L, "0", - 0, dev001Address, dev001Key, - blockingStubFull); + final String triggerTxid2 = + PublicMethod.triggerContract( + transferTokenContractAddress, + "testInCall(address,address,address,uint256,trcToken)", + param2, + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById2 = PublicMethod - .getTransactionInfoById(triggerTxid2, blockingStubFull); + Optional infoById2 = + PublicMethod.getTransactionInfoById(triggerTxid2, blockingStubFull); Assert.assertTrue(infoById2.get().getResultValue() == 0); - Long afterAssetIssueContractAddress2 = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueBAddress2 = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueCAddress2 = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - Long afterBalanceContractAddress2 = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); + Long afterAssetIssueContractAddress2 = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueBAddress2 = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueCAddress2 = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + Long afterBalanceContractAddress2 = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("afterAssetIssueDevAddress2:" + afterAssetIssueContractAddress2); logger.info("afterAssetIssueBAddress2:" + afterAssetIssueBAddress2); @@ -322,43 +426,61 @@ public void deploy04TransferTokenContract004() { Assert.assertTrue(afterAssetIssueCAddress1 == afterAssetIssueCAddress2); } - @Test(enabled = true, description = "Multistage call transferToken calltoken ID not exist", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Multistage call transferToken calltoken ID not exist", + groups = {"contract", "daily"}) public void deploy05TransferTokenContract005() { - final Long afterAssetIssueContractAddress2 = PublicMethod.getAssetIssueValue( + final Long afterAssetIssueContractAddress2 = + PublicMethod.getAssetIssueValue( transferTokenContractAddress, assetAccountId, blockingStubFull); - final Long afterAssetIssueBAddress2 = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - final Long afterAssetIssueCAddress2 = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - final Long afterBalanceContractAddress2 = PublicMethod - .queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); - //5. user trigger A to transfer token to B + final Long afterAssetIssueBAddress2 = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + final Long afterAssetIssueCAddress2 = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + final Long afterBalanceContractAddress2 = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); + // 5. user trigger A to transfer token to B String param3 = - "\"" + Base58.encode58Check(btestAddress) + "\",\"" + Base58.encode58Check(ctestAddress) - + "\",\"" + Base58.encode58Check(transferTokenContractAddress) - + "\",1,\"" + assetAccountId - .toStringUtf8() + "\"" + + Base58.encode58Check(btestAddress) + + "\",\"" + + Base58.encode58Check(ctestAddress) + + "\",\"" + + Base58.encode58Check(transferTokenContractAddress) + + "\",1,\"" + + assetAccountId.toStringUtf8() + "\""; - int i = randomInt(6666666, 9999999); + int i = randomInt(6666666, 9999999); ByteString tokenId1 = ByteString.copyFromUtf8(String.valueOf(i)); - final String triggerTxid3 = PublicMethod.triggerContract(transferTokenContractAddress, - "testInCall(address,address,address,uint256,trcToken)", - param3, false, 0, 1000000000L, tokenId1 - .toStringUtf8(), 1, dev001Address, dev001Key, blockingStubFull); + final String triggerTxid3 = + PublicMethod.triggerContract( + transferTokenContractAddress, + "testInCall(address,address,address,uint256,trcToken)", + param3, + false, + 0, + 1000000000L, + tokenId1.toStringUtf8(), + 1, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(triggerTxid3 == null); - Long afterAssetIssueDevAddress3 = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long afterAssetIssueContractAddress3 = PublicMethod.getAssetIssueValue( + Long afterAssetIssueDevAddress3 = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterAssetIssueContractAddress3 = + PublicMethod.getAssetIssueValue( transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueBAddress3 = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueCAddress3 = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - Long afterBalanceContractAddress3 = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); + Long afterAssetIssueBAddress3 = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueCAddress3 = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + Long afterBalanceContractAddress3 = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("afterAssetIssueCount3:" + afterAssetIssueDevAddress3); logger.info("afterAssetIssueDevAddress3:" + afterAssetIssueContractAddress3); @@ -372,36 +494,56 @@ public void deploy05TransferTokenContract005() { Assert.assertTrue(afterAssetIssueCAddress2 == afterAssetIssueCAddress3); } - @Test(enabled = true, description = "Multistage call transferToken calltoken value not enough", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Multistage call transferToken calltoken value not enough", + groups = {"contract", "daily"}) public void deploy06TransferTokenContract006() { - final Long afterAssetIssueContractAddress3 = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - final Long afterAssetIssueBAddress3 = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - final Long afterAssetIssueCAddress3 = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - final Long afterBalanceContractAddress3 = + final Long afterAssetIssueContractAddress3 = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + final Long afterAssetIssueBAddress3 = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + final Long afterAssetIssueCAddress3 = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + final Long afterBalanceContractAddress3 = PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); - //6. user trigger A to transfer token to B + // 6. user trigger A to transfer token to B String param4 = - "\"" + Base58.encode58Check(btestAddress) + "\",\"" + Base58.encode58Check(ctestAddress) - + "\",\"" + Base58.encode58Check(transferTokenContractAddress) - + "\",1,\"" + assetAccountId.toStringUtf8() + "\""; - final String triggerTxid4 = PublicMethod.triggerContract(transferTokenContractAddress, - "testInCall(address,address,address,uint256,trcToken)", - param4, false, 0, 1000000000L, assetAccountId - .toStringUtf8(), 100000000, dev001Address, dev001Key, blockingStubFull); + "\"" + + Base58.encode58Check(btestAddress) + + "\",\"" + + Base58.encode58Check(ctestAddress) + + "\",\"" + + Base58.encode58Check(transferTokenContractAddress) + + "\",1,\"" + + assetAccountId.toStringUtf8() + + "\""; + final String triggerTxid4 = + PublicMethod.triggerContract( + transferTokenContractAddress, + "testInCall(address,address,address,uint256,trcToken)", + param4, + false, + 0, + 1000000000L, + assetAccountId.toStringUtf8(), + 100000000, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertTrue(triggerTxid4 == null); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long afterAssetIssueContractAddress4 = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueBAddress4 = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueCAddress4 = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - Long afterBalanceContractAddress4 = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); + Long afterAssetIssueContractAddress4 = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueBAddress4 = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueCAddress4 = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + Long afterBalanceContractAddress4 = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("afterAssetIssueDevAddress4:" + afterAssetIssueContractAddress4); logger.info("afterAssetIssueBAddress4:" + afterAssetIssueBAddress4); @@ -414,62 +556,78 @@ public void deploy06TransferTokenContract006() { Assert.assertTrue(afterAssetIssueCAddress3 == afterAssetIssueCAddress4); } - @Test(enabled = true, description = "Multistage call transferToken use right tokenID,tokenvalue", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Multistage call transferToken use right tokenID,tokenvalue", + groups = {"contract", "daily"}) public void deploy07TransferTokenContract007() { - final Long afterAssetIssueDevAddress4 = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - final Long afterAssetIssueContractAddress4 = PublicMethod.getAssetIssueValue( + final Long afterAssetIssueDevAddress4 = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + final Long afterAssetIssueContractAddress4 = + PublicMethod.getAssetIssueValue( transferTokenContractAddress, assetAccountId, blockingStubFull); - final Long afterAssetIssueBAddress4 = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - final Long afterAssetIssueCAddress4 = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - final Long afterBalanceContractAddress4 = + final Long afterAssetIssueBAddress4 = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + final Long afterAssetIssueCAddress4 = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + final Long afterBalanceContractAddress4 = PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); - //2. user trigger A to transfer token to B + // 2. user trigger A to transfer token to B String param5 = - "\"" + Base58.encode58Check(btestAddress) + "\",\"" + Base58.encode58Check(ctestAddress) - + "\",\"" + Base58.encode58Check(transferTokenContractAddress) - + "\",1,\"" + assetAccountId.toStringUtf8() + "\""; - final String triggerTxid5 = PublicMethod.triggerContract(transferTokenContractAddress, - "testInCall(address,address,address,uint256,trcToken)", - param5, false, 0, 1000000000L, assetAccountId - .toStringUtf8(), 1, dev001Address, dev001Key, blockingStubFull); + "\"" + + Base58.encode58Check(btestAddress) + + "\",\"" + + Base58.encode58Check(ctestAddress) + + "\",\"" + + Base58.encode58Check(transferTokenContractAddress) + + "\",1,\"" + + assetAccountId.toStringUtf8() + + "\""; + final String triggerTxid5 = + PublicMethod.triggerContract( + transferTokenContractAddress, + "testInCall(address,address,address,uint256,trcToken)", + param5, + false, + 0, + 1000000000L, + assetAccountId.toStringUtf8(), + 1, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long afterAssetIssueContractAddress5 = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueBAddress5 = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueCAddress5 = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - Long afterBalanceContractAddress5 = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); + Long afterAssetIssueContractAddress5 = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueBAddress5 = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueCAddress5 = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + Long afterBalanceContractAddress5 = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("afterAssetIssueDevAddress5:" + afterAssetIssueContractAddress5); logger.info("afterAssetIssueBAddress5:" + afterAssetIssueBAddress5); logger.info("afterAssetIssueCAddress5:" + afterAssetIssueCAddress5); logger.info("afterBalanceContractAddress5:" + afterBalanceContractAddress5); - Optional infoById5 = PublicMethod - .getTransactionInfoById(triggerTxid5, blockingStubFull); + Optional infoById5 = + PublicMethod.getTransactionInfoById(triggerTxid5, blockingStubFull); Assert.assertTrue(infoById5.get().getResultValue() == 0); Assert.assertEquals(afterBalanceContractAddress4, afterBalanceContractAddress5); Assert.assertTrue(afterAssetIssueContractAddress4 + 2 == afterAssetIssueContractAddress5); Assert.assertTrue(afterAssetIssueBAddress4 == afterAssetIssueBAddress5); Assert.assertTrue(afterAssetIssueCAddress4 - 1 == afterAssetIssueCAddress5); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); - PublicMethod.unFreezeBalance(foundationAddress, foundationKey, 0, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(foundationAddress, foundationKey, 1, dev001Address, blockingStubFull); } - + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 1, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken027.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken027.java index f0a77e56..28180c94 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken027.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken027.java @@ -14,16 +14,16 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ContractTrcToken027 extends TronBaseTest { - private static final long TotalSupply = 10000000L; private static ByteString assetAccountId = null; byte[] btestAddress; @@ -37,133 +37,200 @@ public class ContractTrcToken027 extends TronBaseTest { ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] user001Address = ecKey2.getAddress(); String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + + /** constructor. */ + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private static int randomInt(int minInt, int maxInt) { return (int) Math.round(Math.random() * (maxInt - minInt) + minInt); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Deploy transferToken contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy transferToken contract", + groups = {"contract", "daily"}) public void deploy01TransferTokenContract() { PublicMethod.printAddress(dev001Key); - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 4048000000L, - foundationAddress, foundationKey, blockingStubFull)); - // freeze balance - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(dev001Address, 204800000, - 0, 1, dev001Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 4048000000L, foundationAddress, foundationKey, blockingStubFull)); + // freeze balance + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String tokenName = "testAI_" + randomInt(10000, 90000); + String tokenName = "testAI_" + randomInt(10000, 90000); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 100, start, end, 1, description, url, 10000L, - 10000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); - // deploy transferTokenContract + // deploy transferTokenContract int originEnergyLimit = 50000; - String filePath = "src/test/resources/soliditycode/contractTrcToken027.sol"; - String contractName = "B"; + String filePath = "src/test/resources/soliditycode/contractTrcToken027.sol"; + String contractName = "B"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - btestAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 0, originEnergyLimit, assetAccountId.toStringUtf8(), - 100, null, dev001Key, dev001Address, blockingStubFull); - String contractName1 = "C"; + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + btestAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + originEnergyLimit, + assetAccountId.toStringUtf8(), + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); + String contractName1 = "C"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - ctestAddress = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, - 0L, 0, originEnergyLimit, assetAccountId.toStringUtf8(), - 100, null, dev001Key, dev001Address, + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + ctestAddress = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 0L, + 0, + originEnergyLimit, + assetAccountId.toStringUtf8(), + 100, + null, + dev001Key, + dev001Address, blockingStubFull); - String contractName2 = "token"; + String contractName2 = "token"; HashMap retMap2 = PublicMethod.getBycodeAbi(filePath, contractName2); - String code2 = retMap2.get("byteCode").toString(); - String abi2 = retMap2.get("abI").toString(); - transferTokenContractAddress = PublicMethod - .deployContract(contractName2, abi2, code2, "", maxFeeLimit, - 1000000000L, 0, originEnergyLimit, assetAccountId.toStringUtf8(), - 100, null, dev001Key, dev001Address, + String code2 = retMap2.get("byteCode").toString(); + String abi2 = retMap2.get("abI").toString(); + transferTokenContractAddress = + PublicMethod.deployContract( + contractName2, + abi2, + code2, + "", + maxFeeLimit, + 1000000000L, + 0, + originEnergyLimit, + assetAccountId.toStringUtf8(), + 100, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); /*Assert.assertFalse(PublicMethod.sendcoin(transferTokenContractAddress, 1000000000L, - foundationAddress, foundationKey, blockingStubFull));*/ + foundationAddress, foundationKey, blockingStubFull));*/ } - @Test(enabled = true, description = "Multistage delegatecall transferToken use right tokenID", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Multistage delegatecall transferToken use right tokenID", + groups = {"contract", "daily"}) public void deploy02TransferTokenContract() { - Long beforeAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long beforeAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long beforeAssetIssueBAddress = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - Long beforeAssetIssueCAddress = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - Long beforeBalanceContractAddress = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); + Long beforeAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long beforeAssetIssueBAddress = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long beforeAssetIssueCAddress = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + Long beforeBalanceContractAddress = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("beforeAssetIssueContractAddress:" + beforeAssetIssueContractAddress); logger.info("beforeAssetIssueBAddress:" + beforeAssetIssueBAddress); logger.info("beforeAssetIssueCAddress:" + beforeAssetIssueCAddress); logger.info("beforeAssetIssueDevAddress:" + beforeAssetIssueDevAddress); logger.info("beforeBalanceContractAddress:" + beforeBalanceContractAddress); - // 1.user trigger A to transfer token to B + // 1.user trigger A to transfer token to B String param = - "\"" + Base58.encode58Check(btestAddress) + "\",\"" + Base58.encode58Check(ctestAddress) - + "\",\"" + Base58.encode58Check(transferTokenContractAddress) - + "\",1,\"" + assetAccountId.toStringUtf8() + "\""; - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "testIndelegateCall(address,address,address,uint256,trcToken)", - param, false, 0, 1000000000L, "0", - 0, dev001Address, dev001Key, - blockingStubFull); + "\"" + + Base58.encode58Check(btestAddress) + + "\",\"" + + Base58.encode58Check(ctestAddress) + + "\",\"" + + Base58.encode58Check(transferTokenContractAddress) + + "\",1,\"" + + assetAccountId.toStringUtf8() + + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "testIndelegateCall(address,address,address,uint256,trcToken)", + param, + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); Account infoafter = PublicMethod.queryAccount(dev001Address, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long afterAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueBAddress = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueCAddress = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - Long afterBalanceContractAddress = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueBAddress = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueCAddress = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + Long afterBalanceContractAddress = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -178,95 +245,129 @@ public void deploy02TransferTokenContract() { Assert.assertTrue(afterAssetIssueContractAddress == beforeAssetIssueContractAddress + 1); Assert.assertTrue(afterAssetIssueBAddress == beforeAssetIssueBAddress); Assert.assertTrue(afterAssetIssueCAddress == beforeAssetIssueCAddress - 1); - } - @Test(enabled = true, description = "Multistage delegatecall transferToken use fake tokenID", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Multistage delegatecall transferToken use fake tokenID", + groups = {"contract", "daily"}) public void deploy03TransferTokenContract() { - Long afterAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - final Long afterAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - final Long afterAssetIssueBAddress = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - final Long afterAssetIssueCAddress = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - final Long afterBalanceContractAddress = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); - String param1 = - "\"" + Base58.encode58Check(btestAddress) + "\",\"" + Base58.encode58Check(ctestAddress) - + "\",\"" + Base58.encode58Check(transferTokenContractAddress) - + "\",1,\"" + tokenId1.toStringUtf8() + "\""; - final String triggerTxid1 = PublicMethod.triggerContract(transferTokenContractAddress, - "testIndelegateCall(address,address,address,uint256,trcToken)", - param1, false, 0, 1000000000L, "0", - 0, dev001Address, dev001Key, - blockingStubFull); + Long afterAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + final Long afterAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + final Long afterAssetIssueBAddress = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + final Long afterAssetIssueCAddress = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + final Long afterBalanceContractAddress = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); + String param1 = + "\"" + + Base58.encode58Check(btestAddress) + + "\",\"" + + Base58.encode58Check(ctestAddress) + + "\",\"" + + Base58.encode58Check(transferTokenContractAddress) + + "\",1,\"" + + tokenId1.toStringUtf8() + + "\""; + final String triggerTxid1 = + PublicMethod.triggerContract( + transferTokenContractAddress, + "testIndelegateCall(address,address,address,uint256,trcToken)", + param1, + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById1 = PublicMethod - .getTransactionInfoById(triggerTxid1, blockingStubFull); + Optional infoById1 = + PublicMethod.getTransactionInfoById(triggerTxid1, blockingStubFull); Assert.assertTrue(infoById1.get().getResultValue() == 0); - Long afterAssetIssueDevAddress1 = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long afterAssetIssueContractAddress1 = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueBAddress1 = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueCAddress1 = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - Long afterBalanceContractAddress1 = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); + Long afterAssetIssueDevAddress1 = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterAssetIssueContractAddress1 = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueBAddress1 = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueCAddress1 = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + Long afterBalanceContractAddress1 = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("afterAssetIssueCount1:" + afterAssetIssueDevAddress1); logger.info("afterAssetIssueDevAddress1:" + afterAssetIssueContractAddress1); logger.info("afterAssetIssueBAddress1:" + afterAssetIssueBAddress1); logger.info("afterAssetIssueCAddress1:" + afterAssetIssueCAddress1); logger.info("afterBalanceContractAddress1:" + afterBalanceContractAddress1); - Assert.assertEquals(afterBalanceContractAddress, afterBalanceContractAddress1); Assert.assertTrue(afterAssetIssueContractAddress == afterAssetIssueContractAddress1); Assert.assertTrue(afterAssetIssueBAddress == afterAssetIssueBAddress1); Assert.assertTrue(afterAssetIssueCAddress == afterAssetIssueCAddress1); } - - @Test(enabled = true, description = "Multistage delegatecall transferToken token value" - + " not enough", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Multistage delegatecall transferToken token value" + " not enough", + groups = {"contract", "daily"}) public void deploy04TransferTokenContract() { - Long afterAssetIssueDevAddress1 = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - final Long afterAssetIssueContractAddress1 = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - final Long afterAssetIssueBAddress1 = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - final Long afterAssetIssueCAddress1 = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - final Long afterBalanceContractAddress1 = PublicMethod - .queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); - String param2 = - "\"" + Base58.encode58Check(btestAddress) + "\",\"" + Base58.encode58Check(ctestAddress) - + "\",\"" + Base58.encode58Check(transferTokenContractAddress) - + "\",10000000,\"" + assetAccountId.toStringUtf8() + "\""; - final String triggerTxid2 = PublicMethod.triggerContract(transferTokenContractAddress, - "testIndelegateCall(address,address,address,uint256,trcToken)", - param2, false, 0, 1000000000L, "0", - 0, dev001Address, dev001Key, - blockingStubFull); + Long afterAssetIssueDevAddress1 = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + final Long afterAssetIssueContractAddress1 = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + final Long afterAssetIssueBAddress1 = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + final Long afterAssetIssueCAddress1 = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + final Long afterBalanceContractAddress1 = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); + String param2 = + "\"" + + Base58.encode58Check(btestAddress) + + "\",\"" + + Base58.encode58Check(ctestAddress) + + "\",\"" + + Base58.encode58Check(transferTokenContractAddress) + + "\",10000000,\"" + + assetAccountId.toStringUtf8() + + "\""; + final String triggerTxid2 = + PublicMethod.triggerContract( + transferTokenContractAddress, + "testIndelegateCall(address,address,address,uint256,trcToken)", + param2, + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById2 = PublicMethod - .getTransactionInfoById(triggerTxid2, blockingStubFull); + Optional infoById2 = + PublicMethod.getTransactionInfoById(triggerTxid2, blockingStubFull); Assert.assertTrue(infoById2.get().getResultValue() == 0); - Long afterAssetIssueDevAddress2 = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long afterAssetIssueContractAddress2 = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueBAddress2 = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueCAddress2 = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - Long afterBalanceContractAddress2 = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); + Long afterAssetIssueDevAddress2 = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterAssetIssueContractAddress2 = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueBAddress2 = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueCAddress2 = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + Long afterBalanceContractAddress2 = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("afterAssetIssueCount2:" + afterAssetIssueDevAddress2); logger.info("afterAssetIssueDevAddress2:" + afterAssetIssueContractAddress2); @@ -280,41 +381,59 @@ public void deploy04TransferTokenContract() { Assert.assertTrue(afterAssetIssueCAddress1 == afterAssetIssueCAddress2); } - @Test(enabled = true, description = "Multistage delegatecall transferToken calltoken ID" - + " not exist", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Multistage delegatecall transferToken calltoken ID" + " not exist", + groups = {"contract", "daily"}) public void deploy05TransferTokenContract() { - Long afterAssetIssueDevAddress2 = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - final Long afterAssetIssueContractAddress2 = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - final Long afterAssetIssueBAddress2 = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - final Long afterAssetIssueCAddress2 = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - final Long afterBalanceContractAddress2 = PublicMethod - .queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); - String param3 = - "\"" + Base58.encode58Check(btestAddress) + "\",\"" + Base58.encode58Check(ctestAddress) - + "\",\"" + Base58.encode58Check(transferTokenContractAddress) - + "\",1,\"" + assetAccountId.toStringUtf8() + "\""; - final String triggerTxid3 = PublicMethod.triggerContract(transferTokenContractAddress, - "testIndelegateCall(address,address,address,uint256,trcToken)", - param3, false, 0, 1000000000L, tokenId1.toStringUtf8(), - 1, dev001Address, dev001Key, blockingStubFull); + Long afterAssetIssueDevAddress2 = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + final Long afterAssetIssueContractAddress2 = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + final Long afterAssetIssueBAddress2 = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + final Long afterAssetIssueCAddress2 = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + final Long afterBalanceContractAddress2 = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); + String param3 = + "\"" + + Base58.encode58Check(btestAddress) + + "\",\"" + + Base58.encode58Check(ctestAddress) + + "\",\"" + + Base58.encode58Check(transferTokenContractAddress) + + "\",1,\"" + + assetAccountId.toStringUtf8() + + "\""; + final String triggerTxid3 = + PublicMethod.triggerContract( + transferTokenContractAddress, + "testIndelegateCall(address,address,address,uint256,trcToken)", + param3, + false, + 0, + 1000000000L, + tokenId1.toStringUtf8(), + 1, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(triggerTxid3 == null); - Long afterAssetIssueDevAddress3 = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, - blockingStubFull); - Long afterAssetIssueContractAddress3 = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueBAddress3 = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueCAddress3 = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - Long afterBalanceContractAddress3 = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); + Long afterAssetIssueDevAddress3 = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterAssetIssueContractAddress3 = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueBAddress3 = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueCAddress3 = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + Long afterBalanceContractAddress3 = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("afterAssetIssueCount3:" + afterAssetIssueDevAddress3); logger.info("afterAssetIssueDevAddress3:" + afterAssetIssueContractAddress3); @@ -328,41 +447,60 @@ public void deploy05TransferTokenContract() { Assert.assertTrue(afterAssetIssueCAddress2 == afterAssetIssueCAddress3); } - @Test(enabled = true, description = "Multistage delegatecall transferToken calltoken value " - + "not enough", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Multistage delegatecall transferToken calltoken value " + "not enough", + groups = {"contract", "daily"}) public void deploy06TransferTokenContract() { - Long afterAssetIssueDevAddress3 = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - final Long afterAssetIssueContractAddress3 = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - final Long afterAssetIssueBAddress3 = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - final Long afterAssetIssueCAddress3 = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - final Long afterBalanceContractAddress3 = PublicMethod - .queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); - String param4 = - "\"" + Base58.encode58Check(btestAddress) + "\",\"" + Base58.encode58Check(ctestAddress) - + "\",\"" + Base58.encode58Check(transferTokenContractAddress) - + "\",1,\"" + assetAccountId.toStringUtf8() + "\""; - final String triggerTxid4 = PublicMethod.triggerContract(transferTokenContractAddress, - "testIndelegateCall(address,address,address,uint256,trcToken)", - param4, false, 0, 1000000000L, assetAccountId.toStringUtf8(), - 100000000, dev001Address, dev001Key, blockingStubFull); + Long afterAssetIssueDevAddress3 = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + final Long afterAssetIssueContractAddress3 = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + final Long afterAssetIssueBAddress3 = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + final Long afterAssetIssueCAddress3 = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + final Long afterBalanceContractAddress3 = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); + String param4 = + "\"" + + Base58.encode58Check(btestAddress) + + "\",\"" + + Base58.encode58Check(ctestAddress) + + "\",\"" + + Base58.encode58Check(transferTokenContractAddress) + + "\",1,\"" + + assetAccountId.toStringUtf8() + + "\""; + final String triggerTxid4 = + PublicMethod.triggerContract( + transferTokenContractAddress, + "testIndelegateCall(address,address,address,uint256,trcToken)", + param4, + false, + 0, + 1000000000L, + assetAccountId.toStringUtf8(), + 100000000, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(triggerTxid4 == null); - Long afterAssetIssueDevAddress4 = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long afterAssetIssueContractAddress4 = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueBAddress4 = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueCAddress4 = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - Long afterBalanceContractAddress4 = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); - Long afterUserBalance4 = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + Long afterAssetIssueDevAddress4 = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterAssetIssueContractAddress4 = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueBAddress4 = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueCAddress4 = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + Long afterBalanceContractAddress4 = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); + Long afterUserBalance4 = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("afterAssetIssueCount4:" + afterAssetIssueDevAddress4); logger.info("afterAssetIssueDevAddress4:" + afterAssetIssueContractAddress4); @@ -377,42 +515,61 @@ public void deploy06TransferTokenContract() { Assert.assertTrue(afterAssetIssueCAddress3 == afterAssetIssueCAddress4); } - @Test(enabled = true, description = "Multistage delegatecall transferToken use right tokenID," - + "tokenvalue", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Multistage delegatecall transferToken use right tokenID," + "tokenvalue", + groups = {"contract", "daily"}) public void deploy07TransferTokenContract() { - final Long afterAssetIssueDevAddress4 = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - final Long afterAssetIssueContractAddress4 = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - final Long afterAssetIssueBAddress4 = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - final Long afterAssetIssueCAddress4 = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - final Long afterBalanceContractAddress4 = PublicMethod - .queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); - String param5 = - "\"" + Base58.encode58Check(btestAddress) + "\",\"" + Base58.encode58Check(ctestAddress) - + "\",\"" + Base58.encode58Check(transferTokenContractAddress) - + "\",1,\"" + assetAccountId.toStringUtf8() + "\""; - final String triggerTxid5 = PublicMethod.triggerContract(transferTokenContractAddress, - "testIndelegateCall(address,address,address,uint256,trcToken)", - param5, false, 0, 1000000000L, assetAccountId - .toStringUtf8(), 1, dev001Address, dev001Key, blockingStubFull); + final Long afterAssetIssueDevAddress4 = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + final Long afterAssetIssueContractAddress4 = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + final Long afterAssetIssueBAddress4 = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + final Long afterAssetIssueCAddress4 = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + final Long afterBalanceContractAddress4 = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); + String param5 = + "\"" + + Base58.encode58Check(btestAddress) + + "\",\"" + + Base58.encode58Check(ctestAddress) + + "\",\"" + + Base58.encode58Check(transferTokenContractAddress) + + "\",1,\"" + + assetAccountId.toStringUtf8() + + "\""; + final String triggerTxid5 = + PublicMethod.triggerContract( + transferTokenContractAddress, + "testIndelegateCall(address,address,address,uint256,trcToken)", + param5, + false, + 0, + 1000000000L, + assetAccountId.toStringUtf8(), + 1, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById5 = PublicMethod - .getTransactionInfoById(triggerTxid5, blockingStubFull); + Optional infoById5 = + PublicMethod.getTransactionInfoById(triggerTxid5, blockingStubFull); Assert.assertTrue(infoById5.get().getResultValue() == 0); - Long afterAssetIssueDevAddress5 = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long afterAssetIssueContractAddress5 = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueBAddress5 = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueCAddress5 = PublicMethod - .getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); - Long afterBalanceContractAddress5 = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); + Long afterAssetIssueDevAddress5 = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterAssetIssueContractAddress5 = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueBAddress5 = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueCAddress5 = + PublicMethod.getAssetIssueValue(ctestAddress, assetAccountId, blockingStubFull); + Long afterBalanceContractAddress5 = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("afterAssetIssueCount5:" + afterAssetIssueDevAddress5); logger.info("afterAssetIssueDevAddress5:" + afterAssetIssueContractAddress5); @@ -425,20 +582,15 @@ public void deploy07TransferTokenContract() { Assert.assertTrue(afterAssetIssueBAddress4 == afterAssetIssueBAddress5); Assert.assertTrue(afterAssetIssueCAddress4 - 1 == afterAssetIssueCAddress5); Assert.assertTrue(afterAssetIssueDevAddress4 - 1 == afterAssetIssueDevAddress5); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); - PublicMethod.unFreezeBalance(foundationAddress, foundationKey, 0, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(foundationAddress, foundationKey, 1, dev001Address, blockingStubFull); } - - + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 1, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken028.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken028.java index d484e706..445652ad 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken028.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken028.java @@ -11,10 +11,11 @@ import org.tron.protos.Protocol.TransactionInfo; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j public class ContractTrcToken028 extends TronBaseTest { @@ -22,10 +23,9 @@ public class ContractTrcToken028 extends TronBaseTest { private static ByteString assetAccountId = null; int i1 = randomInt(6666666, 9999999); ByteString tokenId1 = ByteString.copyFromUtf8(String.valueOf(i1)); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] dev001Address = ecKey1.getAddress(); String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -33,86 +33,124 @@ public class ContractTrcToken028 extends TronBaseTest { byte[] user001Address = ecKey2.getAddress(); String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); private byte[] transferTokenContractAddress; + private static int randomInt(int minInt, int maxInt) { return (int) Math.round(Math.random() * (maxInt - minInt) + minInt); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Deploy tokenBalanceWithSameName contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy tokenBalanceWithSameName contract", + groups = {"contract", "daily"}) public void deploy01TransferTokenContract() { PublicMethod.printAddress(dev001Key); - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 4048000000L, - foundationAddress, foundationKey, blockingStubFull)); - // freeze balance - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(dev001Address, 204800000, - 3, 1, dev001Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 4048000000L, foundationAddress, foundationKey, blockingStubFull)); + // freeze balance + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + dev001Address, 204800000, 3, 1, dev001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String tokenName = "testAI_" + randomInt(10000, 90000); + String tokenName = "testAI_" + randomInt(10000, 90000); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 100, start, end, 1, description, url, 10000L, - 10000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); - // deploy transferTokenContract + // deploy transferTokenContract int originEnergyLimit = 50000; - String filePath = "src/test/resources/soliditycode/contractTrcToken028.sol"; - String contractName = "token"; + String filePath = "src/test/resources/soliditycode/contractTrcToken028.sol"; + String contractName = "token"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - transferTokenContractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000000L, 0, originEnergyLimit, assetAccountId.toStringUtf8(), - 100, null, dev001Key, dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + transferTokenContractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000000L, + 0, + originEnergyLimit, + assetAccountId.toStringUtf8(), + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - } - - @Test(enabled = true, description = "Trigger tokenBalanceWithSameName", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger tokenBalanceWithSameName", + groups = {"contract", "daily"}) public void deploy02TransferTokenContract() { - Long beforeAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long beforeAssetIssueUserAddress = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); - Long beforeAssetIssueContractAddress = PublicMethod.getAssetIssueValue( + Long beforeAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueUserAddress = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( transferTokenContractAddress, assetAccountId, blockingStubFull); - Long beforeBalanceContractAddress = PublicMethod - .queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); + Long beforeBalanceContractAddress = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("beforeAssetIssueCount:" + beforeAssetIssueContractAddress); logger.info("beforeAssetIssueDevAddress:" + beforeAssetIssueDevAddress); logger.info("beforeAssetIssueUserAddress:" + beforeAssetIssueUserAddress); logger.info("beforeBalanceContractAddress:" + beforeBalanceContractAddress); - String param = - "\"" + tokenId1 - .toStringUtf8() - + "\""; - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "tokenBalanceWithSameName(trcToken)", - param, false, 0, 1000000000L, "0", - 0, dev001Address, dev001Key, blockingStubFull); + String param = "\"" + tokenId1.toStringUtf8() + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "tokenBalanceWithSameName(trcToken)", + param, + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - Long afterAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long afterAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterBalanceContractAddress = PublicMethod - .queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); - Long afterUserBalance = PublicMethod - .queryAccount(user001Address, blockingStubFull).getBalance(); + Long afterAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterBalanceContractAddress = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); + Long afterUserBalance = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("afterAssetIssueCount:" + afterAssetIssueDevAddress); logger.info("afterAssetIssueDevAddress:" + afterAssetIssueContractAddress); @@ -121,30 +159,35 @@ public void deploy02TransferTokenContract() { Assert.assertEquals(afterBalanceContractAddress, beforeBalanceContractAddress); Assert.assertTrue(afterAssetIssueContractAddress == beforeAssetIssueContractAddress); - String triggerTxid1 = PublicMethod.triggerContract(transferTokenContractAddress, - "getA()", - "#", false, 0, 1000000000L, "0", - 0, dev001Address, dev001Key, - blockingStubFull); + String triggerTxid1 = + PublicMethod.triggerContract( + transferTokenContractAddress, + "getA()", + "#", + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(triggerTxid1, blockingStubFull); - Long returnnumber1 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Long returnnumber1 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(returnnumber1 == 9); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); - PublicMethod.unFreezeBalance(foundationAddress, foundationKey, 1, dev001Address, blockingStubFull); } - - + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 1, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken029.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken029.java index c65269f4..5899bced 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken029.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken029.java @@ -11,10 +11,11 @@ import org.tron.protos.Protocol.TransactionInfo; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j public class ContractTrcToken029 extends TronBaseTest { @@ -22,113 +23,148 @@ public class ContractTrcToken029 extends TronBaseTest { private static final long TotalSupply = 10000000L; private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] dev001Address = ecKey1.getAddress(); String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] user001Address = ecKey2.getAddress(); String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - byte[] transferTokenContractAddress; /** - * constructor. - */ + byte[] transferTokenContractAddress; + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Deploy transferTokenwithSameName contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy transferTokenwithSameName contract", + groups = {"contract", "daily"}) public void deploy01TransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 4048000000L, - foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 4048000000L, foundationAddress, testKey002, blockingStubFull)); PublicMethod.printAddress(dev001Key); - // freeze balance - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(dev001Address, 204800000, - 0, 1, dev001Key, blockingStubFull)); + // freeze balance + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 100, start, end, 1, description, url, 10000L, - 10000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); - // deploy transferTokenContract + // deploy transferTokenContract int originEnergyLimit = 50000; - String filePath = "src/test/resources/soliditycode/contractTrcToken029.sol"; - String contractName = "token"; + String filePath = "src/test/resources/soliditycode/contractTrcToken029.sol"; + String contractName = "token"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - transferTokenContractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000000L, 0, originEnergyLimit, assetAccountId.toStringUtf8(), - 100, null, dev001Key, dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + transferTokenContractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000000L, + 0, + originEnergyLimit, + assetAccountId.toStringUtf8(), + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); /*Assert.assertFalse(PublicMethod.sendcoin(transferTokenContractAddress, - 1000000000L, foundationAddress, testKey002, blockingStubFull));*/ + 1000000000L, foundationAddress, testKey002, blockingStubFull));*/ } - /** - * constructor. - */ - - @Test(enabled = true, description = "Trigger transferTokenwithSameName", groups = {"contract", "daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Trigger transferTokenwithSameName", + groups = {"contract", "daily"}) public void deploy02TransferTokenContract() { - Long beforeAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long beforeAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long beforeBalanceContractAddress = PublicMethod - .queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); + Long beforeAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long beforeBalanceContractAddress = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("beforeAssetIssueCount:" + beforeAssetIssueContractAddress); logger.info("beforeAssetIssueDevAddress:" + beforeAssetIssueDevAddress); logger.info("beforeBalanceContractAddress:" + beforeBalanceContractAddress); - // user trigger A to transfer token to B - ByteString assetAccountDev = PublicMethod - .queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); - ByteString fakeTokenId = ByteString - .copyFromUtf8(Long.toString(Long.valueOf(assetAccountDev.toStringUtf8()) + 100)); - String param = "\"" + fakeTokenId.toStringUtf8() + "\",\"1\""; - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenWithSameName(trcToken,uint256)", - param, false, 0, 1000000000L, "0", - 0, dev001Address, dev001Key, blockingStubFull); + // user trigger A to transfer token to B + ByteString assetAccountDev = + PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); + ByteString fakeTokenId = + ByteString.copyFromUtf8(Long.toString(Long.valueOf(assetAccountDev.toStringUtf8()) + 100)); + String param = "\"" + fakeTokenId.toStringUtf8() + "\",\"1\""; + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenWithSameName(trcToken,uint256)", + param, + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - Long afterAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long afterAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterBalanceContractAddress = PublicMethod - .queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); + Long afterAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterBalanceContractAddress = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("afterAssetIssueDevAddress:" + afterAssetIssueDevAddress); logger.info("afterAssetIssueCount:" + afterAssetIssueContractAddress); logger.info("afterBalanceContractAddress:" + afterBalanceContractAddress); - Assert.assertEquals(afterBalanceContractAddress, beforeBalanceContractAddress); Assert.assertTrue(afterAssetIssueContractAddress == beforeAssetIssueContractAddress); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); } - - + PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken030.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken030.java index a8f2212a..8c872446 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken030.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken030.java @@ -12,10 +12,11 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j public class ContractTrcToken030 extends TronBaseTest { @@ -23,101 +24,141 @@ public class ContractTrcToken030 extends TronBaseTest { private static final long TotalSupply = 10000000L; private static ByteString assetAccountId = null; private static String tokenName = "testAssetIssue_" + Long.toString(now); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] dev001Address = ecKey1.getAddress(); String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] user001Address = ecKey2.getAddress(); String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - byte[] transferTokenContractAddress; /** - * constructor. - */ - @BeforeClass(enabled = true) - public void beforeClass() { } + byte[] transferTokenContractAddress; + /** constructor. */ + @BeforeClass(enabled = true) + public void beforeClass() {} - @Test(enabled = true, description = "Deploy suicide contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy suicide contract", + groups = {"contract", "daily"}) public void deploy01TransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 4048000000L, - foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 4048000000L, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 4048000000L, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 4048000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - // freeze balance - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(dev001Address, 204800000, - 0, 1, dev001Key, blockingStubFull)); + // freeze balance + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 100, start, end, 1, description, url, 10000L, - 10000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); - // deploy transferTokenContract + // deploy transferTokenContract int originEnergyLimit = 50000; - String filePath = "src/test/resources/soliditycode/contractTrcToken030.sol"; - String contractName = "token"; + String filePath = "src/test/resources/soliditycode/contractTrcToken030.sol"; + String contractName = "token"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - transferTokenContractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000000L, 0, originEnergyLimit, assetAccountId.toStringUtf8(), - 100, null, dev001Key, dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + transferTokenContractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000000L, + 0, + originEnergyLimit, + assetAccountId.toStringUtf8(), + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - } - /** - * constructor. - */ - @Test(enabled = true, description = "Trigger suicide contract,toaddress is other", groups = {"contract", "daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Trigger suicide contract,toaddress is other", + groups = {"contract", "daily"}) public void deploy02TransferTokenContract() { - Long beforeAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long beforeAssetIssueUserAddress = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); - Long beforeAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long beforeBalanceContractAddress = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); - final Long beforeUserBalance = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + Long beforeAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueUserAddress = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long beforeBalanceContractAddress = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); + final Long beforeUserBalance = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("beforeAssetIssueCount:" + beforeAssetIssueContractAddress); logger.info("beforeAssetIssueDevAddress:" + beforeAssetIssueDevAddress); logger.info("beforeAssetIssueUserAddress:" + beforeAssetIssueUserAddress); logger.info("beforeBalanceContractAddress:" + beforeBalanceContractAddress); - // user trigger A to transfer token to B - String param = - "\"" + Base58.encode58Check(user001Address) - + "\""; - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "kill(address)", - param, false, 0, 1000000000L, "0", - 0, dev001Address, dev001Key, blockingStubFull); + // user trigger A to transfer token to B + String param = "\"" + Base58.encode58Check(user001Address) + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "kill(address)", + param, + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - Long afterAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long afterAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueUserAddress = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); - Long afterBalanceContractAddress = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); - final Long afterUserBalance = PublicMethod - .queryAccount(user001Address, blockingStubFull).getBalance(); + Long afterAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueUserAddress = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long afterBalanceContractAddress = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); + final Long afterUserBalance = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("afterAssetIssueCount:" + afterAssetIssueDevAddress); logger.info("afterAssetIssueDevAddress:" + afterAssetIssueContractAddress); @@ -125,24 +166,19 @@ public void deploy02TransferTokenContract() { logger.info("afterBalanceContractAddress:" + afterBalanceContractAddress); Assert.assertTrue(afterBalanceContractAddress == 0); - Assert.assertTrue(beforeAssetIssueUserAddress + beforeAssetIssueContractAddress - == afterAssetIssueUserAddress); - Assert.assertTrue(beforeUserBalance + beforeBalanceContractAddress - == afterUserBalance); + Assert.assertTrue( + beforeAssetIssueUserAddress + beforeAssetIssueContractAddress + == afterAssetIssueUserAddress); + Assert.assertTrue(beforeUserBalance + beforeBalanceContractAddress == afterUserBalance); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull); PublicMethod.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); - PublicMethod.freeResource(user001Address, user001Key, foundationAddress, blockingStubFull); } - - + PublicMethod.freeResource(user001Address, user001Key, foundationAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken031.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken031.java index 61e95664..49284916 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken031.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken031.java @@ -12,17 +12,16 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.ProposalEnum; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ContractTrcToken031 extends TronBaseTest { - private static final long now = System.currentTimeMillis(); private static final long TotalSupply = 10000000L; private static ByteString assetAccountId = null; @@ -33,111 +32,146 @@ public class ContractTrcToken031 extends TronBaseTest { ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] user001Address = ecKey2.getAddress(); String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); byte[] transferTokenContractAddress; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Deploy suicide contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy suicide contract", + groups = {"contract", "daily"}) public void deploy01TransferTokenContract() { PublicMethod.printAddress(dev001Key); - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 4048000000L, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 4048000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - // freeze balance - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(dev001Address, 204800000, - 0, 1, dev001Key, blockingStubFull)); + // freeze balance + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 100, start, end, 1, description, url, 10000L, - 10000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); logger.info("assetId: " + assetAccountId); - // deploy transferTokenContract + // deploy transferTokenContract int originEnergyLimit = 50000; - String filePath = "src/test/resources/soliditycode/contractTrcToken031.sol"; - String contractName = "token"; + String filePath = "src/test/resources/soliditycode/contractTrcToken031.sol"; + String contractName = "token"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - transferTokenContractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000000L, 0, originEnergyLimit, assetAccountId.toStringUtf8(), - 100, null, dev001Key, dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + transferTokenContractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000000L, + 0, + originEnergyLimit, + assetAccountId.toStringUtf8(), + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(transferTokenContractAddress); /*Assert.assertFalse(PublicMethod.sendcoin(transferTokenContractAddress, - 1000000000L, foundationAddress, foundationKey, blockingStubFull));*/ + 1000000000L, foundationAddress, foundationKey, blockingStubFull));*/ } - @Test(enabled = true, description = "Trigger suicide contract,toaddress is myself", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger suicide contract,toaddress is myself", + groups = {"contract", "daily"}) public void deploy02TransferTokenContract() { - Long beforeAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long beforeAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long beforeBalanceContractAddress = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); + Long beforeAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long beforeBalanceContractAddress = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("beforeAssetIssueCount:" + beforeAssetIssueContractAddress); logger.info("beforeAssetIssueDevAddress:" + beforeAssetIssueDevAddress); logger.info("beforeBalanceContractAddress:" + beforeBalanceContractAddress); - String param = - "\"" + Base58.encode58Check(transferTokenContractAddress) - + "\""; - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "kill(address)", param, false, 0, 1000000000L, - "0", 0, dev001Address, dev001Key, blockingStubFull); + String param = "\"" + Base58.encode58Check(transferTokenContractAddress) + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "kill(address)", + param, + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - Long afterAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long afterAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterBalanceContractAddress = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); + Long afterAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterBalanceContractAddress = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("afterAssetIssueCount:" + afterAssetIssueDevAddress); logger.info("afterAssetIssueDevAddress:" + afterAssetIssueContractAddress); logger.info("afterBalanceContractAddress:" + afterBalanceContractAddress); - - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { - Assert.assertEquals(beforeBalanceContractAddress, afterBalanceContractAddress ); + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + Assert.assertEquals(beforeBalanceContractAddress, afterBalanceContractAddress); Assert.assertEquals(beforeAssetIssueContractAddress, afterAssetIssueContractAddress); - }else { + } else { Assert.assertTrue(afterBalanceContractAddress == 0); Assert.assertTrue(afterAssetIssueContractAddress == 0); } } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull); - PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); } - + PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken034.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken034.java index ff422679..cc982401 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken034.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken034.java @@ -14,10 +14,11 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j public class ContractTrcToken034 extends TronBaseTest { @@ -25,76 +26,106 @@ public class ContractTrcToken034 extends TronBaseTest { private static final long TotalSupply = 10000000L; private static ByteString assetAccountId = null; private static String tokenName = "testAssetIssue_" + Long.toString(now); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] dev001Address = ecKey1.getAddress(); String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] user001Address = ecKey2.getAddress(); String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - byte[] transferTokenContractAddress; /** - * constructor. - */ + byte[] transferTokenContractAddress; + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 4048000000L, - foundationAddress, testKey002, blockingStubFull)); - logger.info( - "dev001Address:" + Base58.encode58Check(dev001Address)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 4048000000L, - foundationAddress, testKey002, blockingStubFull)); - logger.info( - "user001Address:" + Base58.encode58Check(user001Address)); + public void beforeClass() { + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 4048000000L, foundationAddress, testKey002, blockingStubFull)); + logger.info("dev001Address:" + Base58.encode58Check(dev001Address)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 4048000000L, foundationAddress, testKey002, blockingStubFull)); + logger.info("user001Address:" + Base58.encode58Check(user001Address)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - - @Test(enabled = true, description = "Deploy after transfertoken execute require contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy after transfertoken execute require contract", + groups = {"contract", "daily"}) public void deploy01TransferTokenContract() { long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 100, start, end, 1, description, url, 10000L, - 10000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); - // deploy transferTokenContract + // deploy transferTokenContract int originEnergyLimit = 50000; - String filePath = "src/test/resources/soliditycode/contractTrcToken034.sol"; - String contractName = "token"; + String filePath = "src/test/resources/soliditycode/contractTrcToken034.sol"; + String contractName = "token"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - transferTokenContractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, - 100000000L, 0, originEnergyLimit, assetAccountId.toStringUtf8(), - 50, null, dev001Key, dev001Address, + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + transferTokenContractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 100000000L, + 0, + originEnergyLimit, + assetAccountId.toStringUtf8(), + 50, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - } - @Test(enabled = true, description = "Trigger after transfertoken execute require contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger after transfertoken execute require contract", + groups = {"contract", "daily"}) public void deploy02TransferTokenContract() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); info = PublicMethod.queryAccount(dev001Address, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long beforeAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long beforeAssetIssueUserAddress = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); - Long beforeAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueUserAddress = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); @@ -103,33 +134,44 @@ public void deploy02TransferTokenContract() { logger.info("beforeAssetIssueCount:" + beforeAssetIssueContractAddress); logger.info("beforeAssetIssueDevAddress:" + beforeAssetIssueDevAddress); logger.info("beforeAssetIssueUserAddress:" + beforeAssetIssueUserAddress); - String param = - "\"" + Base58.encode58Check(user001Address) + "\",1,\"" + assetAccountId - .toStringUtf8() + String param = + "\"" + + Base58.encode58Check(user001Address) + + "\",1,\"" + + assetAccountId.toStringUtf8() + "\""; - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "failTransferTokenRevert(address,uint256,trcToken)", - param, false, 0, 1000000000L, "0", - 0, dev001Address, dev001Key, - blockingStubFull); + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "failTransferTokenRevert(address,uint256,trcToken)", + param, + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 1); Account infoafter = PublicMethod.queryAccount(dev001Address, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long afterAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueUserAddress = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueUserAddress = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -142,20 +184,14 @@ public void deploy02TransferTokenContract() { Assert.assertEquals(beforeAssetIssueDevAddress, afterAssetIssueDevAddress); Assert.assertEquals(beforeAssetIssueUserAddress, afterAssetIssueUserAddress); Assert.assertEquals(beforeAssetIssueContractAddress, afterAssetIssueContractAddress); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); PublicMethod.freeResource(user001Address, user001Key, foundationAddress, blockingStubFull); PublicMethod.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull); } - - + PublicMethod.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken035.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken035.java index e9e43c06..90f71538 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken035.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken035.java @@ -14,24 +14,23 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ContractTrcToken035 extends TronBaseTest { - private static final long now = System.currentTimeMillis(); private static final long TotalSupply = 10000000L; private static ByteString assetAccountId = null; private static String tokenName = "testAssetIssue_" + Long.toString(now); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] dev001Address = ecKey1.getAddress(); String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -39,68 +38,98 @@ public class ContractTrcToken035 extends TronBaseTest { byte[] user001Address = ecKey2.getAddress(); String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); byte[] transferTokenContractAddress; - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } - + public void beforeClass() {} - @Test(enabled = true, description = "Deploy after transfertoken execute assert contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy after transfertoken execute assert contract", + groups = {"contract", "daily"}) public void deploy01TransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 9999000000L, foundationAddress, - testKey002, blockingStubFull)); - logger.info( - "dev001Address:" + Base58.encode58Check(dev001Address)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 4048000000L, foundationAddress, - testKey002, blockingStubFull)); - logger.info( - "user001Address:" + Base58.encode58Check(user001Address)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 9999000000L, foundationAddress, testKey002, blockingStubFull)); + logger.info("dev001Address:" + Base58.encode58Check(dev001Address)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 4048000000L, foundationAddress, testKey002, blockingStubFull)); + logger.info("user001Address:" + Base58.encode58Check(user001Address)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 100, start, end, 1, description, url, 10000L, - 10000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); - // deploy transferTokenContract + // deploy transferTokenContract int originEnergyLimit = 50000; - String filePath = "src/test/resources/soliditycode/contractTrcToken035.sol"; - String contractName = "token"; + String filePath = "src/test/resources/soliditycode/contractTrcToken035.sol"; + String contractName = "token"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - transferTokenContractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, - 100000000L, 0, originEnergyLimit, assetAccountId.toStringUtf8(), - 50, null, dev001Key, dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + transferTokenContractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 100000000L, + 0, + originEnergyLimit, + assetAccountId.toStringUtf8(), + 50, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Trigger after transfertoken execute assert contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger after transfertoken execute assert contract", + groups = {"contract", "daily"}) public void deploy02TransferTokenContract() { Account info; - AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(dev001Address, blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); info = PublicMethod.queryAccount(dev001Address, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long beforeAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long beforeAssetIssueUserAddress = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); - Long beforeAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueUserAddress = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); @@ -109,33 +138,45 @@ public void deploy02TransferTokenContract() { logger.info("beforeAssetIssueCount:" + beforeAssetIssueContractAddress); logger.info("beforeAssetIssueDevAddress:" + beforeAssetIssueDevAddress); logger.info("beforeAssetIssueUserAddress:" + beforeAssetIssueUserAddress); - String param = - "\"" + Base58.encode58Check(user001Address) + "\",1,\"" + assetAccountId - .toStringUtf8() + String param = + "\"" + + Base58.encode58Check(user001Address) + + "\",1,\"" + + assetAccountId.toStringUtf8() + "\""; - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "failTransferTokenError(address,uint256,trcToken)", - param, false, 0, 1000000000L, "0", - 0, dev001Address, dev001Key, blockingStubFull); + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "failTransferTokenError(address,uint256,trcToken)", + param, + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 1); Account infoafter = PublicMethod.queryAccount(dev001Address, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(dev001Address, blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long afterAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueUserAddress = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueUserAddress = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -148,19 +189,14 @@ public void deploy02TransferTokenContract() { Assert.assertEquals(beforeAssetIssueDevAddress, afterAssetIssueDevAddress); Assert.assertEquals(beforeAssetIssueUserAddress, afterAssetIssueUserAddress); Assert.assertEquals(beforeAssetIssueContractAddress, afterAssetIssueContractAddress); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); PublicMethod.freeResource(user001Address, user001Key, foundationAddress, blockingStubFull); PublicMethod.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull); } - + PublicMethod.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken036.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken036.java index 7f014913..e9b3d38d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken036.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken036.java @@ -16,22 +16,20 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class ContractTrcToken036 extends TronBaseTest { - private static final long now = System.currentTimeMillis(); private static final long TotalSupply = 10000000L; private static ByteString assetAccountId = null; private static String tokenName = "testAssetIssue_" + Long.toString(now); byte[] transferTokenContractAddress; - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] dev001Address = ecKey1.getAddress(); String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -39,84 +37,99 @@ public class ContractTrcToken036 extends TronBaseTest { byte[] user001Address = ecKey2.getAddress(); String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); int originEnergyLimit = 50000; - byte[] transferTokenWithPureTestAddress; /** - * constructor. - */ - @BeforeClass(enabled = true) - public void beforeClass() { } + byte[] transferTokenWithPureTestAddress; + /** constructor. */ + @BeforeClass(enabled = true) + public void beforeClass() {} - @Test(enabled = false, description = "Deploy contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Deploy contract", + groups = {"contract", "daily"}) public void deploy01TransferTokenContract() { - Assert - .assertTrue(PublicMethod.sendcoin(dev001Address, 9999000000L, foundationAddress, - testKey002, blockingStubFull)); - logger.info( - "dev001Address:" + Base58.encode58Check(dev001Address)); - Assert - .assertTrue(PublicMethod.sendcoin(user001Address, 4048000000L, foundationAddress, - testKey002, blockingStubFull)); - logger.info( - "user001Address:" + Base58.encode58Check(user001Address)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 9999000000L, foundationAddress, testKey002, blockingStubFull)); + logger.info("dev001Address:" + Base58.encode58Check(dev001Address)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 4048000000L, foundationAddress, testKey002, blockingStubFull)); + logger.info("user001Address:" + Base58.encode58Check(user001Address)); PublicMethod.waitProduceNextBlock(blockingStubFull); - long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 100, start, end, 1, description, url, 10000L, - 10000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); - // deploy transferTokenContract + // deploy transferTokenContract // String filePath = "src/test/resources/soliditycode/contractTrcToken036.sol"; - // String contractName = "IllegalDecorate"; - // HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - // String code = retMap.get("byteCode").toString(); - // String abi = retMap.get("abI").toString(); - // transferTokenContractAddress = PublicMethod + // String contractName = "IllegalDecorate"; + // HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); + // String code = retMap.get("byteCode").toString(); + // String abi = retMap.get("abI").toString(); + // transferTokenContractAddress = PublicMethod // .deployContract(contractName, abi, code, "", maxFeeLimit, // 0L, 0, originEnergyLimit, "0", // 0, null, dev001Key, dev001Address, // blockingStubFull); - // + // // // devAddress transfer token to userAddress // PublicMethod // .transferAsset(transferTokenContractAddress, assetAccountId.toByteArray(), 100, // dev001Address, // dev001Key, // blockingStubFull); - // Assert - // .assertTrue(PublicMethod.sendcoin(transferTokenContractAddress, 100, foundationAddress, + // Assert + // .assertTrue(PublicMethod.sendcoin(transferTokenContractAddress, 100, + // foundationAddress, // testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = false, description = "Trigger transferTokenWithPure contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger transferTokenWithPure contract", + groups = {"contract", "daily"}) public void deploy02TransferTokenContract() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); info = PublicMethod.queryAccount(dev001Address, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long beforeAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, - blockingStubFull); - Long beforeAssetIssueUserAddress = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, - blockingStubFull); - Long beforeAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, - assetAccountId, - blockingStubFull); - Long user001AddressAddressBalance = PublicMethod - .queryAccount(user001Address, blockingStubFull).getBalance(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueUserAddress = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long user001AddressAddressBalance = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -125,36 +138,39 @@ public void deploy02TransferTokenContract() { logger.info("beforeAssetIssueDevAddress:" + beforeAssetIssueDevAddress); logger.info("beforeAssetIssueUserAddress:" + beforeAssetIssueUserAddress); logger.info("user001AddressAddressBalance:" + user001AddressAddressBalance); - // user trigger A to transfer token to B - String param = - "\"" + Base58.encode58Check(user001Address) + "\",\"1\""; - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenWithPure(address,uint256)", - param, false, 10, 1000000000L, assetAccountId - .toStringUtf8(), - 10, dev001Address, dev001Key, - blockingStubFull); + // user trigger A to transfer token to B + String param = "\"" + Base58.encode58Check(user001Address) + "\",\"1\""; + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenWithPure(address,uint256)", + param, + false, + 10, + 1000000000L, + assetAccountId.toStringUtf8(), + 10, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account infoafter = PublicMethod.queryAccount(dev001Address, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, - blockingStubFull); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long afterAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, - assetAccountId, - blockingStubFull); - Long afterAssetIssueUserAddress = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, - blockingStubFull); - Long afteruser001AddressAddressBalance = PublicMethod - .queryAccount(user001Address, blockingStubFull).getBalance(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueUserAddress = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long afteruser001AddressAddressBalance = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -165,58 +181,75 @@ public void deploy02TransferTokenContract() { logger.info("afterAssetIssueUserAddress:" + afterAssetIssueUserAddress); logger.info("afterContractAddressBalance:" + afteruser001AddressAddressBalance); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertTrue(beforeAssetIssueDevAddress - 10 == afterAssetIssueDevAddress); Assert.assertTrue(beforeAssetIssueUserAddress + 10 == afterAssetIssueUserAddress); Assert.assertTrue(user001AddressAddressBalance + 10 == afteruser001AddressAddressBalance); - String filePath = "src/test/resources/soliditycode/contractTrcToken036.sol"; - String contractName1 = "IllegalDecorate1"; + String filePath = "src/test/resources/soliditycode/contractTrcToken036.sol"; + String contractName1 = "IllegalDecorate1"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - transferTokenWithPureTestAddress = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, - 0L, 0, originEnergyLimit, "0", - 0, null, dev001Key, dev001Address, + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + transferTokenWithPureTestAddress = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 0L, + 0, + originEnergyLimit, + "0", + 0, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - // devAddress transfer token to userAddress - PublicMethod - .transferAsset(transferTokenWithPureTestAddress, assetAccountId.toByteArray(), 100, - dev001Address, - dev001Key, - blockingStubFull); - Assert - .assertTrue(PublicMethod.sendcoin(transferTokenWithPureTestAddress, 100, foundationAddress, - testKey002, blockingStubFull)); + // devAddress transfer token to userAddress + PublicMethod.transferAsset( + transferTokenWithPureTestAddress, + assetAccountId.toByteArray(), + 100, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertTrue( + PublicMethod.sendcoin( + transferTokenWithPureTestAddress, + 100, + foundationAddress, + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = false, description = "Trigger transferTokenWithConstant contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger transferTokenWithConstant contract", + groups = {"contract", "daily"}) public void deploy03TransferTokenContract() { Account info1; - AccountResourceMessage resourceInfo1 = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage resourceInfo1 = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); info1 = PublicMethod.queryAccount(dev001Address, blockingStubFull); - Long beforeBalance1 = info1.getBalance(); - Long beforeEnergyUsed1 = resourceInfo1.getEnergyUsed(); - Long beforeNetUsed1 = resourceInfo1.getNetUsed(); - Long beforeFreeNetUsed1 = resourceInfo1.getFreeNetUsed(); - Long beforeAssetIssueDevAddress1 = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, - blockingStubFull); - Long beforeAssetIssueUserAddress1 = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, - blockingStubFull); - Long beforeAssetIssueContractAddress1 = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, - assetAccountId, - blockingStubFull); - Long user001AddressAddressBalance1 = PublicMethod - .queryAccount(user001Address, blockingStubFull).getBalance(); + Long beforeBalance1 = info1.getBalance(); + Long beforeEnergyUsed1 = resourceInfo1.getEnergyUsed(); + Long beforeNetUsed1 = resourceInfo1.getNetUsed(); + Long beforeFreeNetUsed1 = resourceInfo1.getFreeNetUsed(); + Long beforeAssetIssueDevAddress1 = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueUserAddress1 = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueContractAddress1 = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long user001AddressAddressBalance1 = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("beforeBalance:" + beforeBalance1); logger.info("beforeEnergyUsed:" + beforeEnergyUsed1); logger.info("beforeNetUsed:" + beforeNetUsed1); @@ -225,36 +258,39 @@ public void deploy03TransferTokenContract() { logger.info("beforeAssetIssueDevAddress:" + beforeAssetIssueDevAddress1); logger.info("beforeAssetIssueUserAddress:" + beforeAssetIssueUserAddress1); logger.info("user001AddressAddressBalance:" + user001AddressAddressBalance1); - // user trigger A to transfer token to B - String param1 = - "\"" + Base58.encode58Check(user001Address) + "\",\"1\""; - final String triggerTxid1 = PublicMethod.triggerContract(transferTokenWithPureTestAddress, - "transferTokenWithConstant(address,uint256)", - param1, false, 10, 1000000000L, assetAccountId - .toStringUtf8(), - 10, dev001Address, dev001Key, - blockingStubFull); + // user trigger A to transfer token to B + String param1 = "\"" + Base58.encode58Check(user001Address) + "\",\"1\""; + final String triggerTxid1 = + PublicMethod.triggerContract( + transferTokenWithPureTestAddress, + "transferTokenWithConstant(address,uint256)", + param1, + false, + 10, + 1000000000L, + assetAccountId.toStringUtf8(), + 10, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account infoafter1 = PublicMethod.queryAccount(dev001Address, blockingStubFull); - AccountResourceMessage resourceInfoafter1 = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); - Long afterBalance1 = infoafter1.getBalance(); - Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); - Long afterAssetIssueDevAddress1 = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, - blockingStubFull); - Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); - Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); - Long afterAssetIssueContractAddress1 = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, - assetAccountId, - blockingStubFull); - Long afterAssetIssueUserAddress1 = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, - blockingStubFull); - Long afteruser001AddressAddressBalance1 = PublicMethod - .queryAccount(user001Address, blockingStubFull).getBalance(); + AccountResourceMessage resourceInfoafter1 = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterAssetIssueDevAddress1 = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + Long afterAssetIssueContractAddress1 = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueUserAddress1 = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long afteruser001AddressAddressBalance1 = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("afterBalance:" + afterBalance1); logger.info("afterEnergyUsed:" + afterEnergyUsed1); @@ -265,149 +301,181 @@ public void deploy03TransferTokenContract() { logger.info("afterAssetIssueUserAddress:" + afterAssetIssueUserAddress1); logger.info("afterContractAddressBalance:" + afteruser001AddressAddressBalance1); - Optional infoById1 = PublicMethod - .getTransactionInfoById(triggerTxid1, blockingStubFull); + Optional infoById1 = + PublicMethod.getTransactionInfoById(triggerTxid1, blockingStubFull); Assert.assertEquals(beforeBalance1, afterBalance1); Assert.assertEquals(beforeAssetIssueDevAddress1, afterAssetIssueDevAddress1); Assert.assertEquals(beforeAssetIssueUserAddress1, afterAssetIssueUserAddress1); Assert.assertEquals(user001AddressAddressBalance1, afteruser001AddressAddressBalance1); } - @Test(enabled = false, description = "Trigger transferTokenWithView contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger transferTokenWithView contract", + groups = {"contract", "daily"}) public void deploy04TransferTokenContract() { String filePath2 = "src/test/resources/soliditycode/contractTrcToken036.sol"; - String contractName2 = "IllegalDecorate2"; + String contractName2 = "IllegalDecorate2"; HashMap retMap2 = PublicMethod.getBycodeAbi(filePath2, contractName2); - String code2 = retMap2.get("byteCode").toString(); - String abi2 = retMap2.get("abI").toString(); - byte[] transferTokenWithViewAddress = PublicMethod - .deployContract(contractName2, abi2, code2, "", maxFeeLimit, - 0L, 0, originEnergyLimit, "0", - 0, null, dev001Key, dev001Address, - blockingStubFull); - PublicMethod.waitProduceNextBlock(blockingStubFull); - // devAddress transfer token to userAddress - PublicMethod - .transferAsset(transferTokenWithViewAddress, assetAccountId.toByteArray(), 100, - dev001Address, + String code2 = retMap2.get("byteCode").toString(); + String abi2 = retMap2.get("abI").toString(); + byte[] transferTokenWithViewAddress = + PublicMethod.deployContract( + contractName2, + abi2, + code2, + "", + maxFeeLimit, + 0L, + 0, + originEnergyLimit, + "0", + 0, + null, dev001Key, + dev001Address, blockingStubFull); - Assert - .assertTrue(PublicMethod.sendcoin(transferTokenWithViewAddress, 100, foundationAddress, - testKey002, blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + // devAddress transfer token to userAddress + PublicMethod.transferAsset( + transferTokenWithViewAddress, + assetAccountId.toByteArray(), + 100, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertTrue( + PublicMethod.sendcoin( + transferTokenWithViewAddress, 100, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info2; - AccountResourceMessage resourceInfo2 = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage resourceInfo2 = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); info2 = PublicMethod.queryAccount(dev001Address, blockingStubFull); - Long beforeBalance2 = info2.getBalance(); - Long beforeEnergyUsed2 = resourceInfo2.getEnergyUsed(); - Long beforeNetUsed2 = resourceInfo2.getNetUsed(); - Long beforeFreeNetUsed2 = resourceInfo2.getFreeNetUsed(); - Long beforeAssetIssueDevAddress2 = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, - blockingStubFull); - Long beforeAssetIssueUserAddress2 = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, - blockingStubFull); - Long beforeAssetIssueContractAddress2 = PublicMethod - .getAssetIssueValue(transferTokenWithViewAddress, - assetAccountId, - blockingStubFull); - Long user001AddressAddressBalance2 = PublicMethod - .queryAccount(user001Address, blockingStubFull).getBalance(); + Long beforeBalance2 = info2.getBalance(); + Long beforeEnergyUsed2 = resourceInfo2.getEnergyUsed(); + Long beforeNetUsed2 = resourceInfo2.getNetUsed(); + Long beforeFreeNetUsed2 = resourceInfo2.getFreeNetUsed(); + Long beforeAssetIssueDevAddress2 = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueUserAddress2 = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueContractAddress2 = + PublicMethod.getAssetIssueValue( + transferTokenWithViewAddress, assetAccountId, blockingStubFull); + Long user001AddressAddressBalance2 = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("beforeAssetIssueContractAddress2:" + beforeAssetIssueContractAddress2); logger.info("beforeAssetIssueDevAddress2:" + beforeAssetIssueDevAddress2); logger.info("beforeAssetIssueUserAddress2:" + beforeAssetIssueUserAddress2); logger.info("user001AddressAddressBalance2:" + user001AddressAddressBalance2); - // user trigger A to transfer token to B - String param2 = - "\"" + Base58.encode58Check(user001Address) + "\",\"1\""; - String triggerTxid2 = PublicMethod.triggerContract(transferTokenWithViewAddress, - "transferTokenWithView(address,uint256)", - param2, false, 10, 1000000000L, assetAccountId - .toStringUtf8(), - 10, dev001Address, dev001Key, - blockingStubFull); + // user trigger A to transfer token to B + String param2 = "\"" + Base58.encode58Check(user001Address) + "\",\"1\""; + String triggerTxid2 = + PublicMethod.triggerContract( + transferTokenWithViewAddress, + "transferTokenWithView(address,uint256)", + param2, + false, + 10, + 1000000000L, + assetAccountId.toStringUtf8(), + 10, + dev001Address, + dev001Key, + blockingStubFull); Account infoafter2 = PublicMethod.queryAccount(dev001Address, blockingStubFull); - AccountResourceMessage resourceInfoafter2 = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); - Long afterBalance2 = infoafter2.getBalance(); - Long afterEnergyUsed2 = resourceInfoafter2.getEnergyUsed(); - Long afterAssetIssueDevAddress2 = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, - blockingStubFull); - Long afterNetUsed2 = resourceInfoafter2.getNetUsed(); - Long afterFreeNetUsed2 = resourceInfoafter2.getFreeNetUsed(); - Long afterAssetIssueContractAddress2 = PublicMethod - .getAssetIssueValue(transferTokenWithViewAddress, - assetAccountId, - blockingStubFull); - Long afterAssetIssueUserAddress2 = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, - blockingStubFull); - Long afteruser001AddressAddressBalance2 = PublicMethod - .queryAccount(user001Address, blockingStubFull).getBalance(); + AccountResourceMessage resourceInfoafter2 = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance2 = infoafter2.getBalance(); + Long afterEnergyUsed2 = resourceInfoafter2.getEnergyUsed(); + Long afterAssetIssueDevAddress2 = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterNetUsed2 = resourceInfoafter2.getNetUsed(); + Long afterFreeNetUsed2 = resourceInfoafter2.getFreeNetUsed(); + Long afterAssetIssueContractAddress2 = + PublicMethod.getAssetIssueValue( + transferTokenWithViewAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueUserAddress2 = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long afteruser001AddressAddressBalance2 = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("afterAssetIssueDevAddress2:" + afterAssetIssueDevAddress2); logger.info("afterAssetIssueContractAddress2:" + afterAssetIssueContractAddress2); logger.info("afterAssetIssueUserAddress2:" + afterAssetIssueUserAddress2); logger.info("afteruser001AddressAddressBalance2:" + afteruser001AddressAddressBalance2); - Optional infoById2 = PublicMethod - .getTransactionInfoById(triggerTxid2, blockingStubFull); + Optional infoById2 = + PublicMethod.getTransactionInfoById(triggerTxid2, blockingStubFull); Assert.assertEquals(beforeAssetIssueDevAddress2, afterAssetIssueDevAddress2); Assert.assertEquals(beforeAssetIssueUserAddress2, afterAssetIssueUserAddress2); Assert.assertEquals(user001AddressAddressBalance2, afteruser001AddressAddressBalance2); } - @Test(enabled = false, description = "Trigger transferTokenWithNoPayable contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger transferTokenWithNoPayable contract", + groups = {"contract", "daily"}) public void deploy05TransferTokenContract() { String filePath = "src/test/resources/soliditycode/contractTrcToken036.sol"; - String contractName3 = "IllegalDecorate3"; + String contractName3 = "IllegalDecorate3"; HashMap retMap3 = PublicMethod.getBycodeAbi(filePath, contractName3); - String code3 = retMap3.get("byteCode").toString(); - String abi3 = retMap3.get("abI").toString(); - byte[] transferTokenWithOutPayableTestAddress = PublicMethod - .deployContract(contractName3, abi3, code3, "", maxFeeLimit, - 0L, 0, originEnergyLimit, "0", - 0, null, dev001Key, dev001Address, + String code3 = retMap3.get("byteCode").toString(); + String abi3 = retMap3.get("abI").toString(); + byte[] transferTokenWithOutPayableTestAddress = + PublicMethod.deployContract( + contractName3, + abi3, + code3, + "", + maxFeeLimit, + 0L, + 0, + originEnergyLimit, + "0", + 0, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod - .transferAsset(transferTokenWithOutPayableTestAddress, assetAccountId.toByteArray(), 100, - dev001Address, - dev001Key, - blockingStubFull); - Assert - .assertTrue(PublicMethod.sendcoin(transferTokenWithOutPayableTestAddress, 100, foundationAddress, - testKey002, blockingStubFull)); + PublicMethod.transferAsset( + transferTokenWithOutPayableTestAddress, + assetAccountId.toByteArray(), + 100, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertTrue( + PublicMethod.sendcoin( + transferTokenWithOutPayableTestAddress, + 100, + foundationAddress, + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info3; - AccountResourceMessage resourceInfo3 = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage resourceInfo3 = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); info3 = PublicMethod.queryAccount(dev001Address, blockingStubFull); - Long beforeBalance3 = info3.getBalance(); - Long beforeEnergyUsed3 = resourceInfo3.getEnergyUsed(); - Long beforeNetUsed3 = resourceInfo3.getNetUsed(); - Long beforeFreeNetUsed3 = resourceInfo3.getFreeNetUsed(); - Long beforeAssetIssueDevAddress3 = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, - blockingStubFull); - Long beforeAssetIssueUserAddress3 = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, - blockingStubFull); - Long beforeAssetIssueContractAddress3 = PublicMethod - .getAssetIssueValue( - transferTokenWithOutPayableTestAddress, - assetAccountId, - blockingStubFull); - Long user001AddressAddressBalance3 = PublicMethod - .queryAccount(user001Address, blockingStubFull).getBalance(); + Long beforeBalance3 = info3.getBalance(); + Long beforeEnergyUsed3 = resourceInfo3.getEnergyUsed(); + Long beforeNetUsed3 = resourceInfo3.getNetUsed(); + Long beforeFreeNetUsed3 = resourceInfo3.getFreeNetUsed(); + Long beforeAssetIssueDevAddress3 = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueUserAddress3 = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueContractAddress3 = + PublicMethod.getAssetIssueValue( + transferTokenWithOutPayableTestAddress, assetAccountId, blockingStubFull); + Long user001AddressAddressBalance3 = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("beforeBalance:" + beforeBalance3); logger.info("beforeEnergyUsed:" + beforeEnergyUsed3); logger.info("beforeNetUsed:" + beforeNetUsed3); @@ -416,62 +484,57 @@ public void deploy05TransferTokenContract() { logger.info("beforeAssetIssueDevAddress:" + beforeAssetIssueDevAddress3); logger.info("beforeAssetIssueUserAddress:" + beforeAssetIssueUserAddress3); logger.info("user001AddressAddressBalance:" + user001AddressAddressBalance3); - String param3 = - "\"" + Base58.encode58Check(user001Address) + "\",\"1\""; - String triggerTxid3 = PublicMethod.triggerContract(transferTokenWithOutPayableTestAddress, - "transferTokenWithOutPayable(address,uint256)", - param3, false, 10, 1000000000L, assetAccountId - .toStringUtf8(), - 10, dev001Address, dev001Key, - blockingStubFull); + String param3 = "\"" + Base58.encode58Check(user001Address) + "\",\"1\""; + String triggerTxid3 = + PublicMethod.triggerContract( + transferTokenWithOutPayableTestAddress, + "transferTokenWithOutPayable(address,uint256)", + param3, + false, + 10, + 1000000000L, + assetAccountId.toStringUtf8(), + 10, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account infoafter3 = PublicMethod.queryAccount(dev001Address, blockingStubFull); - AccountResourceMessage resourceInfoafter3 = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); - Long afterBalance3 = infoafter3.getBalance(); - Long afterEnergyUsed3 = resourceInfoafter3.getEnergyUsed(); - Long afterAssetIssueDevAddress3 = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, - blockingStubFull); - Long afterNetUsed3 = resourceInfoafter3.getNetUsed(); - Long afterFreeNetUsed3 = resourceInfoafter3.getFreeNetUsed(); - Long afterAssetIssueContractAddress3 = PublicMethod - .getAssetIssueValue( - transferTokenWithOutPayableTestAddress, assetAccountId, - blockingStubFull); - Long afterAssetIssueUserAddress3 = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, - blockingStubFull); - Long afteruser001AddressAddressBalance3 = PublicMethod - .queryAccount(user001Address, blockingStubFull).getBalance(); - - Optional infoById3 = PublicMethod - .getTransactionInfoById(triggerTxid3, blockingStubFull); + AccountResourceMessage resourceInfoafter3 = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance3 = infoafter3.getBalance(); + Long afterEnergyUsed3 = resourceInfoafter3.getEnergyUsed(); + Long afterAssetIssueDevAddress3 = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterNetUsed3 = resourceInfoafter3.getNetUsed(); + Long afterFreeNetUsed3 = resourceInfoafter3.getFreeNetUsed(); + Long afterAssetIssueContractAddress3 = + PublicMethod.getAssetIssueValue( + transferTokenWithOutPayableTestAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueUserAddress3 = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long afteruser001AddressAddressBalance3 = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); + + Optional infoById3 = + PublicMethod.getTransactionInfoById(triggerTxid3, blockingStubFull); Assert.assertTrue(infoById3.get().getResultValue() == 1); Assert.assertEquals(beforeAssetIssueDevAddress3, afterAssetIssueDevAddress3); Assert.assertEquals(beforeAssetIssueUserAddress3, afterAssetIssueUserAddress3); Assert.assertEquals(user001AddressAddressBalance3, afteruser001AddressAddressBalance3); - PublicMethod.unFreezeBalance(dev001Address, dev001Key, 1, - null, blockingStubFull); - PublicMethod.unFreezeBalance(user001Address, user001Key, 1, - null, blockingStubFull); - + PublicMethod.unFreezeBalance(dev001Address, dev001Key, 1, null, blockingStubFull); + PublicMethod.unFreezeBalance(user001Address, user001Key, 1, null, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); PublicMethod.freeResource(user001Address, user001Key, foundationAddress, blockingStubFull); PublicMethod.unFreezeBalance(foundationAddress, testKey002, 0, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(foundationAddress, testKey002, 0, user001Address, blockingStubFull); } - - + PublicMethod.unFreezeBalance( + foundationAddress, testKey002, 0, user001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken037.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken037.java index 4585b069..05b804d9 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken037.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken037.java @@ -16,91 +16,132 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class ContractTrcToken037 extends TronBaseTest { - private static final long now = System.currentTimeMillis(); private static final long TotalSupply = 10000000L; private static ByteString assetAccountId = null; private static String tokenName = "testAssetIssue_" + Long.toString(now); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] dev001Address = ecKey1.getAddress(); String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] user001Address = ecKey2.getAddress(); - String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); /** - * constructor. - */ + String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - - @Test(enabled = true, description = "Multi-level call transferToken tokenBalance", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Multi-level call transferToken tokenBalance", + groups = {"contract", "daily"}) public void deploy01TransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 4048000000L, - foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 4048000000L, foundationAddress, testKey002, blockingStubFull)); logger.info("dev001Address:" + Base58.encode58Check(dev001Address)); - // freeze balance - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(dev001Address, 204800000, - 0, 1, dev001Key, blockingStubFull)); + // freeze balance + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 100, start, end, 1, description, url, 10000L, - 10000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); - // deploy transferTokenContract + // deploy transferTokenContract int originEnergyLimit = 50000; - String filePath = "src/test/resources/soliditycode/contractTrcToken037.sol"; - String contractName = "receiveTrc10"; + String filePath = "src/test/resources/soliditycode/contractTrcToken037.sol"; + String contractName = "receiveTrc10"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] btestAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, - 0, originEnergyLimit, "0", 0, - null, dev001Key, dev001Address, blockingStubFull); - String contractName1 = "transferTrc10"; + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] btestAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + originEnergyLimit, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); + String contractName1 = "transferTrc10"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - byte[] transferTokenContractAddress = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, - 0L, 0, originEnergyLimit, "0", - 0, null, dev001Key, dev001Address, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + byte[] transferTokenContractAddress = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 0L, + 0, + originEnergyLimit, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); info = PublicMethod.queryAccount(dev001Address, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long beforeAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long beforeAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long beforeAssetIssueBAddress = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - Long beforeBalanceContractAddress = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long beforeAssetIssueBAddress = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long beforeBalanceContractAddress = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -110,32 +151,41 @@ public void deploy01TransferTokenContract() { logger.info("beforeAssetIssueDevAddress:" + beforeAssetIssueDevAddress); logger.info("beforeBalanceContractAddress:" + beforeBalanceContractAddress); - String param = - "\"" + Base58.encode58Check(btestAddress) + "\""; - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "receive(address)", - param, false, 0, 1000000000L, assetAccountId.toStringUtf8(), - 10, dev001Address, dev001Key, blockingStubFull); + String param = "\"" + Base58.encode58Check(btestAddress) + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "receive(address)", + param, + false, + 0, + 1000000000L, + assetAccountId.toStringUtf8(), + 10, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); Account infoafter = PublicMethod.queryAccount(dev001Address, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long afterAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueBAddress = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - Long afterBalanceContractAddress = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueBAddress = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long afterBalanceContractAddress = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -149,18 +199,12 @@ public void deploy01TransferTokenContract() { Assert.assertEquals(afterBalanceContractAddress, beforeBalanceContractAddress); Assert.assertTrue(afterAssetIssueDevAddress == beforeAssetIssueDevAddress - 10); Assert.assertTrue(afterAssetIssueBAddress == beforeAssetIssueBAddress + 10); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); - PublicMethod.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull); } - + PublicMethod.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken038.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken038.java index 6111ab02..29749f71 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken038.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken038.java @@ -16,74 +16,114 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class ContractTrcToken038 extends TronBaseTest { - private static final long TotalSupply = 10000000L; private static final long now = System.currentTimeMillis(); private static ByteString assetAccountId = null; private static String tokenName = "testAssetIssue_" + Long.toString(now); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] dev001Address = ecKey1.getAddress(); String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] user001Address = ecKey2.getAddress(); - String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); /** - * constructor. - */ + String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - - @Test(enabled = true, description = "Multi-level call transferToken assert tokenBalance ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Multi-level call transferToken assert tokenBalance ", + groups = {"contract", "daily"}) public void deployTransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 4048000000L, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 4048000000L, foundationAddress, foundationKey, blockingStubFull)); logger.info("dev001Address:" + Base58.encode58Check(dev001Address)); - // freeze balance - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(dev001Address, 204800000, - 3, 1, dev001Key, blockingStubFull)); + // freeze balance + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + dev001Address, 204800000, 3, 1, dev001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 100, start, end, 1, description, url, 10000L, - 10000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); Assert.assertFalse(assetAccountId.toStringUtf8().equals("")); - // deploy transferTokenContract + // deploy transferTokenContract int originEnergyLimit = 50000; - String filePath = "src/test/resources/soliditycode/contractTrcToken038.sol"; - String contractName2 = "transferTrc10"; + String filePath = "src/test/resources/soliditycode/contractTrcToken038.sol"; + String contractName2 = "transferTrc10"; HashMap retMap2 = PublicMethod.getBycodeAbi(filePath, contractName2); - String code2 = retMap2.get("byteCode").toString(); - String abi2 = retMap2.get("abI").toString(); - final byte[] transferTokenContractAddress = PublicMethod - .deployContract(contractName2, abi2, code2, "", maxFeeLimit, - 0L, 0, originEnergyLimit, "0", - 0, null, dev001Key, dev001Address, blockingStubFull); - String contractName = "receiveTrc10"; + String code2 = retMap2.get("byteCode").toString(); + String abi2 = retMap2.get("abI").toString(); + final byte[] transferTokenContractAddress = + PublicMethod.deployContract( + contractName2, + abi2, + code2, + "", + maxFeeLimit, + 0L, + 0, + originEnergyLimit, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); + String contractName = "receiveTrc10"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] btestAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 0, originEnergyLimit, "0", - 0, null, dev001Key, dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] btestAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + originEnergyLimit, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); /*Assert.assertFalse(PublicMethod.sendcoin(transferTokenContractAddress, 1000000000L, @@ -91,21 +131,22 @@ public void deployTransferTokenContract() { Assert.assertFalse(PublicMethod.sendcoin(btestAddress, 1000000000L, foundationAddress, foundationKey, blockingStubFull));*/ Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); info = PublicMethod.queryAccount(dev001Address, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long beforeAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long beforeAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long beforeAssetIssueBAddress = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - Long beforeBalanceContractAddress = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long beforeAssetIssueBAddress = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long beforeBalanceContractAddress = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -114,32 +155,41 @@ public void deployTransferTokenContract() { logger.info("beforeAssetIssueBAddress:" + beforeAssetIssueBAddress); logger.info("beforeAssetIssueDevAddress:" + beforeAssetIssueDevAddress); logger.info("beforeBalanceContractAddress:" + beforeBalanceContractAddress); - String param = - "\"" + Base58.encode58Check(btestAddress) + "\""; - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "receive(address)", - param, false, 0, 1000000000L, assetAccountId.toStringUtf8(), - 1, dev001Address, dev001Key, blockingStubFull); + String param = "\"" + Base58.encode58Check(btestAddress) + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "receive(address)", + param, + false, + 0, + 1000000000L, + assetAccountId.toStringUtf8(), + 1, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 1); Account infoafter = PublicMethod.queryAccount(dev001Address, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long afterAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueBAddress = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); - Long afterBalanceContractAddress = PublicMethod.queryAccount(transferTokenContractAddress, - blockingStubFull).getBalance(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueBAddress = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long afterBalanceContractAddress = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -153,19 +203,12 @@ public void deployTransferTokenContract() { Assert.assertEquals(afterBalanceContractAddress, beforeBalanceContractAddress); Assert.assertTrue(afterAssetIssueContractAddress == beforeAssetIssueContractAddress); Assert.assertTrue(afterAssetIssueBAddress == beforeAssetIssueBAddress); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); - PublicMethod.unFreezeBalance(dev001Address, dev001Key, 1, null, blockingStubFull); } - - + PublicMethod.unFreezeBalance(dev001Address, dev001Key, 1, null, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken039.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken039.java index 0d90f04b..ed8cf392 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken039.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken039.java @@ -14,10 +14,11 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j public class ContractTrcToken039 extends TronBaseTest { @@ -25,10 +26,9 @@ public class ContractTrcToken039 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static ByteString assetAccountId = null; private static String tokenName = "testAssetIssue_" + Long.toString(now); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] dev001Address = ecKey1.getAddress(); String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -37,102 +37,151 @@ public class ContractTrcToken039 extends TronBaseTest { String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); byte[] proxyTestAddress; byte[] atestAddress; - byte[] btestAddress; /** - * constructor. - */ + byte[] btestAddress; + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } - + public void beforeClass() {} - @Test(enabled = true, description = "Deploy Proxy contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy Proxy contract", + groups = {"contract", "daily"}) public void deploy01TransferTokenContract() { - Assert - .assertTrue(PublicMethod.sendcoin(dev001Address, 4048000000L, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 4048000000L, foundationAddress, testKey002, blockingStubFull)); logger.info("dev001Address:" + Base58.encode58Check(dev001Address)); - Assert - .assertTrue(PublicMethod.sendcoin(user001Address, 4048000000L, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 4048000000L, foundationAddress, testKey002, blockingStubFull)); logger.info("user001Address:" + Base58.encode58Check(user001Address)); PublicMethod.waitProduceNextBlock(blockingStubFull); - // freeze balance - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(dev001Address, 204800000, - 0, 1, dev001Key, blockingStubFull)); + // freeze balance + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(user001Address, 2048000000, - 0, 1, user001Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + user001Address, 2048000000, 0, 1, user001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 100, start, end, 1, description, url, 10000L, - 10000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); - // deploy transferTokenContract + // deploy transferTokenContract int originEnergyLimit = 50000; - String filePath = "src/test/resources/soliditycode/contractTrcToken039.sol"; - String contractName = "Proxy"; + String filePath = "src/test/resources/soliditycode/contractTrcToken039.sol"; + String contractName = "Proxy"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - proxyTestAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, - 1000L, 0, originEnergyLimit, assetAccountId.toStringUtf8(), - 1000, null, dev001Key, dev001Address, + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + proxyTestAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000L, + 0, + originEnergyLimit, + assetAccountId.toStringUtf8(), + 1000, + null, + dev001Key, + dev001Address, blockingStubFull); - String contractName1 = "A"; + String contractName1 = "A"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - atestAddress = PublicMethod - .deployContract(contractName1, abi1, code1, "", maxFeeLimit, - 0L, 0, originEnergyLimit, "0", - 0, null, dev001Key, dev001Address, + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + atestAddress = + PublicMethod.deployContract( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 0L, + 0, + originEnergyLimit, + "0", + 0, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName2 = "B"; + String contractName2 = "B"; HashMap retMap2 = PublicMethod.getBycodeAbi(filePath, contractName2); - String code2 = retMap2.get("byteCode").toString(); - String abi2 = retMap2.get("abI").toString(); - btestAddress = PublicMethod - .deployContract(contractName2, abi2, code2, "", maxFeeLimit, - 0L, 0, originEnergyLimit, "0", - 0, null, dev001Key, dev001Address, + String code2 = retMap2.get("byteCode").toString(); + String abi2 = retMap2.get("abI").toString(); + btestAddress = + PublicMethod.deployContract( + contractName2, + abi2, + code2, + "", + maxFeeLimit, + 0L, + 0, + originEnergyLimit, + "0", + 0, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - } - @Test(enabled = true, dependsOnMethods = "deploy01TransferTokenContract", - description = "Trigger Proxy contract use AddressA", groups = {"contract", "daily"}) + @Test( + enabled = true, + dependsOnMethods = "deploy01TransferTokenContract", + description = "Trigger Proxy contract use AddressA", + groups = {"contract", "daily"}) public void deploy02TransferTokenContract() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); info = PublicMethod.queryAccount(dev001Address, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long beforeAssetIssueUserAddress = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, - blockingStubFull); - Long beforeAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(proxyTestAddress, assetAccountId, - blockingStubFull); - Long beforeAssetIssueBAddress = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, - blockingStubFull); - Long beforeAssetIssueAAddress = PublicMethod - .getAssetIssueValue(atestAddress, assetAccountId, - blockingStubFull); - Long beforeBalanceContractAddress = PublicMethod.queryAccount(proxyTestAddress, - blockingStubFull).getBalance(); - Long beforeUserBalance = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + Long beforeBalance = info.getBalance(); + Long beforeAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueUserAddress = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueContractAddress = + PublicMethod.getAssetIssueValue(proxyTestAddress, assetAccountId, blockingStubFull); + Long beforeAssetIssueBAddress = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long beforeAssetIssueAAddress = + PublicMethod.getAssetIssueValue(atestAddress, assetAccountId, blockingStubFull); + Long beforeBalanceContractAddress = + PublicMethod.queryAccount(proxyTestAddress, blockingStubFull).getBalance(); + Long beforeUserBalance = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeAssetIssueContractAddress:" + beforeAssetIssueContractAddress); @@ -140,42 +189,57 @@ public void deploy02TransferTokenContract() { logger.info("beforeAssetIssueDevAddress:" + beforeAssetIssueDevAddress); logger.info("beforeAssetIssueUserAddress:" + beforeAssetIssueUserAddress); - String param = - "\"" + Base58.encode58Check(atestAddress) + "\""; - String param1 = - "\"" + "1" + "\",\"" + Base58.encode58Check(user001Address) + "\",\"" + assetAccountId - .toStringUtf8() + String param = "\"" + Base58.encode58Check(atestAddress) + "\""; + String param1 = + "\"" + + "1" + + "\",\"" + + Base58.encode58Check(user001Address) + + "\",\"" + + assetAccountId.toStringUtf8() + "\""; - String triggerTxid = PublicMethod.triggerContract(proxyTestAddress, - "upgradeTo(address)", - param, false, 0, 1000000000L, "0", - 0, dev001Address, dev001Key, - blockingStubFull); - PublicMethod.waitProduceNextBlock(blockingStubFull); - final String triggerTxid1 = PublicMethod.triggerContract(proxyTestAddress, - "trans(uint256,address,trcToken)", - param1, false, 0, 1000000000L, assetAccountId - .toStringUtf8(), - 1, dev001Address, dev001Key, - blockingStubFull); - PublicMethod.waitProduceNextBlock(blockingStubFull); - Long afterAssetIssueDevAddress = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long afterAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(proxyTestAddress, assetAccountId, - blockingStubFull); - Long afterAssetIssueBAddress = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, + String triggerTxid = + PublicMethod.triggerContract( + proxyTestAddress, + "upgradeTo(address)", + param, + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, blockingStubFull); - Long afterAssetIssueAAddress = PublicMethod - .getAssetIssueValue(atestAddress, assetAccountId, + PublicMethod.waitProduceNextBlock(blockingStubFull); + final String triggerTxid1 = + PublicMethod.triggerContract( + proxyTestAddress, + "trans(uint256,address,trcToken)", + param1, + false, + 0, + 1000000000L, + assetAccountId.toStringUtf8(), + 1, + dev001Address, + dev001Key, blockingStubFull); - Long afterAssetIssueUserAddress = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); - Long afterBalanceContractAddress = PublicMethod.queryAccount(proxyTestAddress, - blockingStubFull).getBalance(); - Long afterUserBalance = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + PublicMethod.waitProduceNextBlock(blockingStubFull); + Long afterAssetIssueDevAddress = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterAssetIssueContractAddress = + PublicMethod.getAssetIssueValue(proxyTestAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueBAddress = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueAAddress = + PublicMethod.getAssetIssueValue(atestAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueUserAddress = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long afterBalanceContractAddress = + PublicMethod.queryAccount(proxyTestAddress, blockingStubFull).getBalance(); + Long afterUserBalance = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("afterAssetIssueCount:" + afterAssetIssueDevAddress); logger.info("afterAssetIssueDevAddress:" + afterAssetIssueContractAddress); logger.info("afterAssetIssueBAddress:" + afterAssetIssueBAddress); @@ -183,8 +247,8 @@ public void deploy02TransferTokenContract() { logger.info("afterBalanceContractAddress:" + afterBalanceContractAddress); logger.info("afterUserBalance:" + afterUserBalance); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid1, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid1, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertTrue(afterAssetIssueUserAddress == beforeAssetIssueUserAddress); Assert.assertTrue(afterBalanceContractAddress == beforeBalanceContractAddress - 1); @@ -195,29 +259,29 @@ public void deploy02TransferTokenContract() { Assert.assertTrue(afterAssetIssueBAddress == beforeAssetIssueBAddress); } - @Test(enabled = true,dependsOnMethods = "deploy02TransferTokenContract", - description = "Trigger Proxy contract use AddressB", groups = {"contract", "daily"}) + @Test( + enabled = true, + dependsOnMethods = "deploy02TransferTokenContract", + description = "Trigger Proxy contract use AddressB", + groups = {"contract", "daily"}) public void deploy03TransferTokenContract() { Account info1; - AccountResourceMessage resourceInfo1 = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage resourceInfo1 = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); info1 = PublicMethod.queryAccount(dev001Address, blockingStubFull); - Long beforeBalance1 = info1.getBalance(); - Long beforeAssetIssueDevAddress1 = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long beforeAssetIssueUserAddress1 = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, - blockingStubFull); - Long beforeAssetIssueContractAddress1 = PublicMethod - .getAssetIssueValue(proxyTestAddress, assetAccountId, - blockingStubFull); - Long beforeAssetIssueBAddress1 = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, - blockingStubFull); - Long beforeBalanceContractAddress1 = PublicMethod.queryAccount(proxyTestAddress, - blockingStubFull).getBalance(); - Long beforeUserBalance1 = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + Long beforeBalance1 = info1.getBalance(); + Long beforeAssetIssueDevAddress1 = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueUserAddress1 = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueContractAddress1 = + PublicMethod.getAssetIssueValue(proxyTestAddress, assetAccountId, blockingStubFull); + Long beforeAssetIssueBAddress1 = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long beforeBalanceContractAddress1 = + PublicMethod.queryAccount(proxyTestAddress, blockingStubFull).getBalance(); + Long beforeUserBalance1 = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("beforeBalance1:" + beforeBalance1); logger.info("beforeAssetIssueContractAddress1:" + beforeAssetIssueContractAddress1); logger.info("beforeAssetIssueBAddress1:" + beforeAssetIssueBAddress1); @@ -226,43 +290,60 @@ public void deploy03TransferTokenContract() { logger.info("beforeAssetIssueUserAddress1:" + beforeAssetIssueUserAddress1); logger.info("beforeBalanceContractAddress1:" + beforeBalanceContractAddress1); logger.info("beforeUserBalance1:" + beforeUserBalance1); - String param3 = - "\"" + Base58.encode58Check(btestAddress) + "\""; - String param2 = - "\"" + "1" + "\",\"" + Base58.encode58Check(user001Address) + "\",\"" + assetAccountId - .toStringUtf8() + String param3 = "\"" + Base58.encode58Check(btestAddress) + "\""; + String param2 = + "\"" + + "1" + + "\",\"" + + Base58.encode58Check(user001Address) + + "\",\"" + + assetAccountId.toStringUtf8() + "\""; - String triggerTxid2 = PublicMethod.triggerContract(proxyTestAddress, - "upgradeTo(address)", param3, false, 0, 1000000000L, - assetAccountId.toStringUtf8(), 1, dev001Address, dev001Key, blockingStubFull); - String triggerTxid3 = PublicMethod.triggerContract(proxyTestAddress, - "trans(uint256,address,trcToken)", - param2, false, 0, 1000000000L, assetAccountId - .toStringUtf8(), - 1, dev001Address, dev001Key, - blockingStubFull); + String triggerTxid2 = + PublicMethod.triggerContract( + proxyTestAddress, + "upgradeTo(address)", + param3, + false, + 0, + 1000000000L, + assetAccountId.toStringUtf8(), + 1, + dev001Address, + dev001Key, + blockingStubFull); + String triggerTxid3 = + PublicMethod.triggerContract( + proxyTestAddress, + "trans(uint256,address,trcToken)", + param2, + false, + 0, + 1000000000L, + assetAccountId.toStringUtf8(), + 1, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account infoafter1 = PublicMethod.queryAccount(dev001Address, blockingStubFull); - AccountResourceMessage resourceInfoafter1 = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); - Long afterBalance1 = infoafter1.getBalance(); - Long afterAssetIssueDevAddress1 = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - Long afterAssetIssueContractAddress1 = PublicMethod - .getAssetIssueValue(proxyTestAddress, assetAccountId, - blockingStubFull); - Long afterAssetIssueBAddress1 = PublicMethod - .getAssetIssueValue(btestAddress, assetAccountId, - blockingStubFull); - Long afterAssetIssueUserAddress1 = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, - blockingStubFull); - Long afterBalanceContractAddress1 = PublicMethod.queryAccount(proxyTestAddress, - blockingStubFull).getBalance(); - Long afterUserBalance1 = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + AccountResourceMessage resourceInfoafter1 = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterAssetIssueDevAddress1 = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long afterAssetIssueContractAddress1 = + PublicMethod.getAssetIssueValue(proxyTestAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueBAddress1 = + PublicMethod.getAssetIssueValue(btestAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueUserAddress1 = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long afterBalanceContractAddress1 = + PublicMethod.queryAccount(proxyTestAddress, blockingStubFull).getBalance(); + Long afterUserBalance1 = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("afterBalance1:" + afterBalance1); logger.info("afterAssetIssueCount1:" + afterAssetIssueDevAddress1); @@ -272,8 +353,8 @@ public void deploy03TransferTokenContract() { logger.info("afterBalanceContractAddress1:" + afterBalanceContractAddress1); logger.info("afterUserBalance1:" + afterUserBalance1); - Optional infoById2 = PublicMethod - .getTransactionInfoById(triggerTxid3, blockingStubFull); + Optional infoById2 = + PublicMethod.getTransactionInfoById(triggerTxid3, blockingStubFull); Assert.assertTrue(infoById2.get().getResultValue() == 0); Assert.assertTrue(afterAssetIssueUserAddress1 == beforeAssetIssueUserAddress1); Assert.assertTrue(afterBalanceContractAddress1 == beforeBalanceContractAddress1 - 1); @@ -281,22 +362,14 @@ public void deploy03TransferTokenContract() { Assert.assertTrue(afterAssetIssueDevAddress1 == beforeAssetIssueDevAddress1 - 1); Assert.assertTrue(afterUserBalance1 == beforeUserBalance1 + 1); Assert.assertTrue(afterAssetIssueUserAddress1 == afterAssetIssueUserAddress1); - PublicMethod.unFreezeBalance(dev001Address, dev001Key, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(user001Address, user001Key, 1, - user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); - PublicMethod.freeResource(user001Address, user001Key, foundationAddress, blockingStubFull); } - - + PublicMethod.freeResource(user001Address, user001Key, foundationAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken041.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken041.java index 7dc77900..8e287961 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken041.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken041.java @@ -15,22 +15,21 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j public class ContractTrcToken041 extends TronBaseTest { - private static final long TotalSupply = 10000000L; private static final long now = System.currentTimeMillis(); private static ByteString assetAccountId = null; private static String tokenName = "testAssetIssue_" + Long.toString(now); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] dev001Address = ecKey1.getAddress(); String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -38,71 +37,101 @@ public class ContractTrcToken041 extends TronBaseTest { byte[] user001Address = ecKey2.getAddress(); String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; + private static int randomInt(int minInt, int maxInt) { return (int) Math.round(Math.random() * (maxInt - minInt) + minInt); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "Trigger contract msg.tokenId add 1,msg.tokenValue add 1", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger contract msg.tokenId add 1,msg.tokenValue add 1", + groups = {"contract", "daily"}) public void deployTransferTokenContract() { PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 2048000000, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 2048000000, foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 4048000000L, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 4048000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - // freeze balance - PublicMethod.freezeBalanceGetEnergy(dev001Address, 204800000, - 0, 1, dev001Key, blockingStubFull); + // freeze balance + PublicMethod.freezeBalanceGetEnergy( + dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull); - PublicMethod.freezeBalanceGetEnergy(user001Address, 2048000000, - 0, 1, user001Key, blockingStubFull); + PublicMethod.freezeBalanceGetEnergy( + user001Address, 2048000000, 0, 1, user001Key, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 100, start, end, 1, description, url, 10000L, - 10000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); - final ByteString fakeTokenId = ByteString - .copyFromUtf8(Long.toString(Long.valueOf(assetAccountId.toStringUtf8()) + 100)); - // deploy transferTokenContract + final ByteString fakeTokenId = + ByteString.copyFromUtf8(Long.toString(Long.valueOf(assetAccountId.toStringUtf8()) + 100)); + // deploy transferTokenContract String filePath = "src/test/resources/soliditycode/contractTrcToken041.sol"; - String contractName = "tokenTest"; + String contractName = "tokenTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] transferTokenContractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, 10000, assetAccountId.toStringUtf8(), - 0, null, dev001Key, dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] transferTokenContractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + 10000, + assetAccountId.toStringUtf8(), + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(user001Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(user001Address, blockingStubFull); info = PublicMethod.queryAccount(user001Address, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long beforeAssetIssueCount = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); - Long beforeAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeAssetIssueCount = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); @@ -110,31 +139,43 @@ public void deployTransferTokenContract() { logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("beforeAssetIssueCount:" + beforeAssetIssueCount); logger.info("beforeAssetIssueContractAddress:" + beforeAssetIssueContractAddress); - // user trigger A to transfer token to B + // user trigger A to transfer token to B String param = - "\"" + Base58.encode58Check(dev001Address) + "\",\"" + fakeTokenId - .toStringUtf8() + "\"" + + Base58.encode58Check(dev001Address) + + "\",\"" + + fakeTokenId.toStringUtf8() + "\",\"105\""; - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "TransferTokenTo(address,trcToken,uint256)", - param, false, 0, 100000000L, fakeTokenId.toStringUtf8(), - 10000000L, user001Address, user001Key, blockingStubFull); + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "TransferTokenTo(address,trcToken,uint256)", + param, + false, + 0, + 100000000L, + fakeTokenId.toStringUtf8(), + 10000000L, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); Account infoafter = PublicMethod.queryAccount(user001Address, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(user001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterAssetIssueCount = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long afterAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(user001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterAssetIssueCount = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -147,20 +188,14 @@ public void deployTransferTokenContract() { Assert.assertEquals(beforeAssetIssueCount, afterAssetIssueCount); Assert.assertEquals(beforeAssetIssueContractAddress, afterAssetIssueContractAddress); Assert.assertTrue(afterEnergyUsed == 0L); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); PublicMethod.freeResource(user001Address, user001Key, foundationAddress, blockingStubFull); PublicMethod.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull); } - + PublicMethod.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken043.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken043.java index a34211c0..095f1417 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken043.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken043.java @@ -16,11 +16,12 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ContractTrcToken043 extends TronBaseTest { @@ -31,14 +32,14 @@ public class ContractTrcToken043 extends TronBaseTest { private static ByteString assetAccountId = null; private static ByteString assetAccountUser = null; private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] transferTokenContractAddress = null; private byte[] resultContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -49,67 +50,99 @@ public class ContractTrcToken043 extends TronBaseTest { private byte[] user002Address = ecKey3.getAddress(); private String user002Key = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - - @Test(enabled = true, description = "TransferToken with invalid tokenId, deploy transferContract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken with invalid tokenId, deploy transferContract", + groups = {"contract", "daily"}) public void test01DeployTransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 5048_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 5048_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user002Address, 5048_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 5048_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 5048_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user002Address, 5048_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, 100000L, - 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - assetAccountId = PublicMethod - .queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); + assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); logger.info("The token name: " + tokenName); logger.info("The token ID: " + assetAccountId.toStringUtf8()); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("before energyLimit is " + energyLimit); logger.info("before energyUsage is " + energyUsage); logger.info("before balanceBefore is " + balanceBefore); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() - + ", devAssetCountBefore: " + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken043.sol"; - String contractName = "transferTokenContract"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken043.sol"; + String contractName = "transferTokenContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - assetAccountId.toStringUtf8(), 100, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + assetAccountId.toStringUtf8(), + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (transferTokenTxid == null || infoById.get().getResultValue() != 0) { @@ -117,61 +150,86 @@ public void test01DeployTransferTokenContract() { } transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(transferTokenContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(transferTokenContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); long balanceAfter = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("after energyLimit is " + energyLimit); logger.info("after energyUsage is " + energyUsage); logger.info("after balanceAfter is " + balanceAfter); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() - + ", devAssetCountAfter: " + devAssetCountAfter); - Long contractAssetCount = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + Long contractAssetCount = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); Assert.assertEquals(Long.valueOf(100), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(100), contractAssetCount); } - @Test(enabled = true, description = "TransferToken with invalid tokenId, deploy receive contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken with invalid tokenId, deploy receive contract", + groups = {"contract", "daily"}) public void test02DeployRevContract() { // before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("before energyLimit is " + energyLimit); logger.info("before energyUsage is " + energyUsage); logger.info("before balance is " + balanceBefore); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() - + ", devAssetCountBefore: " + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken043.sol"; - String contractName = "Result"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken043.sol"; + String contractName = "Result"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String recieveTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 0L, 100, 1000, assetAccountId.toStringUtf8(), - 100, null, dev001Key, dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String recieveTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + 1000, + assetAccountId.toStringUtf8(), + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(recieveTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(recieveTokenTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (recieveTokenTxid == null || infoById.get().getResultValue() != 0) { @@ -180,47 +238,67 @@ public void test02DeployRevContract() { resultContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(resultContractAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(resultContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - // after deploy, check account resource + // after deploy, check account resource accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); long balanceAfter = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("after energyLimit is " + energyLimit); logger.info("after energyUsage is " + energyUsage); logger.info("after balanceAfter is " + balanceAfter); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() - + ", devAssetCountAfter: " + devAssetCountAfter); - Long contractAssetCount = PublicMethod.getAssetIssueValue(resultContractAddress, - assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + Long contractAssetCount = + PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); Assert.assertEquals(Long.valueOf(100), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(100), contractAssetCount); } - @Test(enabled = true, description = "TransferToken with invalid tokenId, transferToken", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken with invalid tokenId, transferToken", + groups = {"contract", "daily"}) public void test03TriggerContract() { -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.transferAsset(user001Address, - assetAccountId.toByteArray(), 10L, dev001Address, dev001Key, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.transferAsset( + user001Address, + assetAccountId.toByteArray(), + 10L, + dev001Address, + dev001Key, + blockingStubFull)); - Assert.assertTrue(PublicMethod.transferAsset(user002Address, - assetAccountId.toByteArray(), 10L, dev001Address, dev001Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + user002Address, + assetAccountId.toByteArray(), + 10L, + dev001Address, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -232,183 +310,230 @@ public void test03TriggerContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + userEnergyLimitBefore); logger.info("before trigger, userEnergyUsageBefore is " + userEnergyUsageBefore); logger.info("before trigger, userBalanceBefore is " + userBalanceBefore); - Long transferAssetBefore = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, - blockingStubFull); - logger.info("before trigger, transferTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + transferAssetBefore); - Long receiveAssetBefore = PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, - blockingStubFull); - logger.info("before trigger, resultContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + receiveAssetBefore); - // tokenId is 100_0000 + Long transferAssetBefore = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "before trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + transferAssetBefore); + Long receiveAssetBefore = + PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, blockingStubFull); + logger.info( + "before trigger, resultContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + receiveAssetBefore); + // tokenId is 100_0000 String tokenId = Long.toString(100_0000); - Long tokenValue = Long.valueOf(1); - Long callValue = Long.valueOf(0); - String param = "\"" + Base58.encode58Check(resultContractAddress) - + "\",\"" + tokenValue + "\"," + tokenId; - String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + Long tokenValue = Long.valueOf(1); + Long callValue = Long.valueOf(0); + String param = + "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" + tokenValue + "\"," + tokenId; + String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Triger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - Assert.assertEquals("REVERT opcode executed", - infoById.get().getResMessage().toStringUtf8()); - // tokenId is -1 + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); + // tokenId is -1 tokenId = Long.toString(-1); tokenValue = Long.valueOf(1); callValue = Long.valueOf(0); - param = "\"" + Base58.encode58Check(resultContractAddress) - + "\",\"" + tokenValue + "\"," + tokenId; - - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + param = + "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" + tokenValue + "\"," + tokenId; + + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - //Assert.assertEquals("validateForSmartContract failure, not valid token id", - Assert.assertEquals("REVERT opcode executed", - infoById.get().getResMessage().toStringUtf8()); - // tokenId is long.min + // Assert.assertEquals("validateForSmartContract failure, not valid token id", + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); + // tokenId is long.min tokenId = Long.toString(Long.MIN_VALUE); tokenValue = Long.valueOf(1); callValue = Long.valueOf(0); - param = "\"" + Base58.encode58Check(resultContractAddress) - + "\",\"" + tokenValue + "\"," + tokenId; - - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + param = + "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" + tokenValue + "\"," + tokenId; + + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - Assert.assertEquals("REVERT opcode executed", - infoById.get().getResMessage().toStringUtf8()); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - // tokenId is 0, contract not have trx + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + // tokenId is 0, contract not have trx tokenId = Long.toString(0); tokenValue = Long.valueOf(1); callValue = Long.valueOf(0); - param = "\"" + Base58.encode58Check(resultContractAddress) - + "\",\"" + tokenValue + "\"," + tokenId; - - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + param = + "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" + tokenValue + "\"," + tokenId; + + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - Assert.assertEquals("REVERT opcode executed", - infoById.get().getResMessage().toStringUtf8()); + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); - Assert.assertFalse(PublicMethod - .sendcoin(transferTokenContractAddress, 5000000, fromAddress, testKey002, - blockingStubFull)); - Assert.assertTrue(PublicMethod - .sendcoin(user002Address, 5000000, fromAddress, testKey002, - blockingStubFull)); + Assert.assertFalse( + PublicMethod.sendcoin( + transferTokenContractAddress, 5000000, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin(user002Address, 5000000, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //tokenId is 0, transfer contract has trx, transfer to normal account + // tokenId is 0, transfer contract has trx, transfer to normal account tokenId = Long.toString(0); tokenValue = Long.valueOf(1); callValue = Long.valueOf(1); - param = "\"" + Base58.encode58Check(dev001Address) - + "\",\"" + tokenValue + "\"," + tokenId; - - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user002Address, user002Key, - blockingStubFull); + param = "\"" + Base58.encode58Check(dev001Address) + "\",\"" + tokenValue + "\"," + tokenId; + + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user002Address, + user002Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - Assert.assertEquals("REVERT opcode executed", - infoById.get().getResMessage().toStringUtf8()); - // tokenid bigger than long.max, trigger to a contract + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); + // tokenid bigger than long.max, trigger to a contract callValue = Long.valueOf(0); param = "\"" + Base58.encode58Check(resultContractAddress) + "\""; - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTestIDOverBigInteger(address)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user002Address, user002Key, - blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTestIDOverBigInteger(address)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user002Address, + user002Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - Assert.assertEquals("REVERT opcode executed", - infoById.get().getResMessage().toStringUtf8()); - Long transferAssetAfter = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("after trigger, transferTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", transferAssetAfter is " + transferAssetAfter); - Long receiveAssetAfter = PublicMethod.getAssetIssueValue(resultContractAddress, - assetAccountId, blockingStubFull); - logger.info("after trigger, resultContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", receiveAssetAfter is " + receiveAssetAfter); + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); + Long transferAssetAfter = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "after trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", transferAssetAfter is " + + transferAssetAfter); + Long receiveAssetAfter = + PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, blockingStubFull); + logger.info( + "after trigger, resultContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", receiveAssetAfter is " + + receiveAssetAfter); Assert.assertEquals(receiveAssetAfter, receiveAssetBefore); Assert.assertEquals(transferAssetBefore, transferAssetAfter); - // unfreeze resource - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user002Address, blockingStubFull); + // unfreeze resource + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user002Address, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken048.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken048.java index 44e9ee79..02f3ecdc 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken048.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken048.java @@ -13,11 +13,12 @@ import org.tron.protos.Protocol.TransactionInfo; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ContractTrcToken048 extends TronBaseTest { @@ -26,78 +27,108 @@ public class ContractTrcToken048 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] dev001Address = ecKey1.getAddress(); String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] user001Address = ecKey2.getAddress(); String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - - @Test(enabled = true, description = "TransferToken msg.value msg,tokenvalue is negative number", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken msg.value msg,tokenvalue is negative number", + groups = {"contract", "daily"}) public void deployTransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 2048000000, - foundationAddress, testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 4048000000L, - foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 2048000000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 4048000000L, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - // freeze balance - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(dev001Address, 204800000, - 0, 1, dev001Key, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(user001Address, 2048000000, - 0, 1, user001Key, blockingStubFull)); + // freeze balance + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + user001Address, 2048000000, 0, 1, user001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 100, start, end, 1, description, url, 10000L, - 10000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); - final ByteString fakeassetAccountId = ByteString - .copyFromUtf8(Long.toString(Long.valueOf(assetAccountId.toStringUtf8()) + 100)); - // deploy transferTokenContract + final ByteString fakeassetAccountId = + ByteString.copyFromUtf8(Long.toString(Long.valueOf(assetAccountId.toStringUtf8()) + 100)); + // deploy transferTokenContract String filePath = "./src/test/resources/soliditycode/contractTrcToken048.sol"; - String contractName = "Test"; + String contractName = "Test"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] transferTokenContractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, 10000, "0", - 0, null, dev001Key, dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] transferTokenContractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(user001Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(user001Address, blockingStubFull); info = PublicMethod.queryAccount(user001Address, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long beforeAssetIssueCount = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); - Long beforeAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeAssetIssueCount = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); @@ -105,27 +136,46 @@ public void deployTransferTokenContract() { logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("beforeAssetIssueCount:" + beforeAssetIssueCount); logger.info("beforeAssetIssueContractAddress:" + beforeAssetIssueContractAddress); - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "testMsgTokenValue()", - "#", false, 0, 100000000L, fakeassetAccountId.toStringUtf8(), - -1000, user001Address, user001Key, blockingStubFull); - String triggerTxid1 = PublicMethod.triggerContract(transferTokenContractAddress, - "testMsgValue()", - "#", false, -1000, 100000000L, "0", - 0, user001Address, user001Key, blockingStubFull); + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "testMsgTokenValue()", + "#", + false, + 0, + 100000000L, + fakeassetAccountId.toStringUtf8(), + -1000, + user001Address, + user001Key, + blockingStubFull); + String triggerTxid1 = + PublicMethod.triggerContract( + transferTokenContractAddress, + "testMsgValue()", + "#", + false, + -1000, + 100000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account infoafter = PublicMethod.queryAccount(user001Address, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(user001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterAssetIssueCount = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long afterAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(user001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterAssetIssueCount = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -134,27 +184,21 @@ public void deployTransferTokenContract() { logger.info("afterAssetIssueCount:" + afterAssetIssueCount); logger.info("afterAssetIssueContractAddress:" + afterAssetIssueContractAddress); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); Assert.assertEquals(beforeBalance, afterBalance); Assert.assertEquals(beforeAssetIssueCount, afterAssetIssueCount); Assert.assertEquals(beforeAssetIssueContractAddress, afterAssetIssueContractAddress); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); PublicMethod.freeResource(user001Address, user001Key, foundationAddress, blockingStubFull); PublicMethod.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull); } - + PublicMethod.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken049.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken049.java index 9e11a0de..1b0785a2 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken049.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken049.java @@ -16,21 +16,20 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ContractTrcToken049 extends TronBaseTest { - private static final long TotalSupply = 10000000L; - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] dev001Address = ecKey1.getAddress(); String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -39,121 +38,156 @@ public class ContractTrcToken049 extends TronBaseTest { String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private static int randomInt(int minInt, int maxInt) { return (int) Math.round(Math.random() * (maxInt - minInt) + minInt); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - /** - * constructor. - */ + /** constructor. */ public ByteString createAssetissue(byte[] devAddress, String devKey, String tokenName) { Long start = System.currentTimeMillis() + 2000; - Long end = System.currentTimeMillis() + 1000000000; + Long end = System.currentTimeMillis() + 1000000000; logger.info("The token name: " + tokenName); - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(devAddress, tokenName, TotalSupply, 1, - 100, start, end, 1, description, url, 10000L, 10000L, - 1L, 1L, devKey, blockingStubFull)); - - ByteString assetAccountId = PublicMethod.queryAccount(devAddress, blockingStubFull) - .getAssetIssuedID(); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + devAddress, + tokenName, + TotalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + devKey, + blockingStubFull)); + + ByteString assetAccountId = + PublicMethod.queryAccount(devAddress, blockingStubFull).getAssetIssuedID(); logger.info("The tokenID: " + assetAccountId); return assetAccountId; } - @Test(enabled = true, description = "TransferToken to myself", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken to myself", + groups = {"contract", "daily"}) public void deployTransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 2048000000, - foundationAddress, testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 4048000000L, - foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 2048000000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 4048000000L, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - // freeze balance - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(dev001Address, 204800000, - 0, 1, dev001Key, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(user001Address, 2048000000, - 0, 1, user001Key, blockingStubFull)); + // freeze balance + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + user001Address, 2048000000, 0, 1, user001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String tokenName = "testAI_" + randomInt(10000, 90000); + String tokenName = "testAI_" + randomInt(10000, 90000); ByteString tokenId = createAssetissue(user001Address, user001Key, tokenName); - PublicMethod.transferAsset(dev001Address, tokenId.toByteArray(), 101, user001Address, - user001Key, blockingStubFull); + PublicMethod.transferAsset( + dev001Address, tokenId.toByteArray(), 101, user001Address, user001Key, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - // deploy transferTokenContract + // deploy transferTokenContract String filePath = "./src/test/resources/soliditycode/contractTrcToken049.sol"; - String contractName = "tokenTest"; + String contractName = "tokenTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 0L, 100, 10000, tokenId.toStringUtf8(), - 0, null, dev001Key, dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + 10000, + tokenId.toStringUtf8(), + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); - byte[] transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); - - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(user001Address, - blockingStubFull); - Long beforeBalance = PublicMethod - .queryAccount(user001Address, blockingStubFull).getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long beforeAssetIssueCount = + byte[] transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); + + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(user001Address, blockingStubFull); + Long beforeBalance = PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeAssetIssueCount = PublicMethod.getAssetIssueValue(user001Address, tokenId, blockingStubFull); - Long beforeAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, tokenId, blockingStubFull); - final Long beforeAssetIssueDev = PublicMethod.getAssetIssueValue(dev001Address, tokenId, - blockingStubFull); + Long beforeAssetIssueContractAddress = + PublicMethod.getAssetIssueValue(transferTokenContractAddress, tokenId, blockingStubFull); + final Long beforeAssetIssueDev = + PublicMethod.getAssetIssueValue(dev001Address, tokenId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("beforeAssetIssueCount:" + beforeAssetIssueCount); logger.info("beforeAssetIssueContractAddress:" + beforeAssetIssueContractAddress); - // user trigger A to transfer token to B + // user trigger A to transfer token to B String param = - "\"" + Base58.encode58Check(dev001Address) + "\",\"" + tokenId - .toStringUtf8() - + "\",\"1\""; - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "TransferTokenTo(address,trcToken,uint256)", - param, false, 0, 100000000L, "0", - 0, user001Address, user001Key, blockingStubFull); + "\"" + Base58.encode58Check(dev001Address) + "\",\"" + tokenId.toStringUtf8() + "\",\"1\""; + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "TransferTokenTo(address,trcToken,uint256)", + param, + false, + 0, + 100000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account infoafter = PublicMethod.queryAccount(user001Address, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(user001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterAssetIssueCount = + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(user001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterAssetIssueCount = PublicMethod.getAssetIssueValue(user001Address, tokenId, blockingStubFull); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long afterAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, tokenId, blockingStubFull); - final Long afterAssetIssueDev = PublicMethod.getAssetIssueValue(dev001Address, tokenId, - blockingStubFull); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterAssetIssueContractAddress = + PublicMethod.getAssetIssueValue(transferTokenContractAddress, tokenId, blockingStubFull); + final Long afterAssetIssueDev = + PublicMethod.getAssetIssueValue(dev001Address, tokenId, blockingStubFull); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -161,8 +195,7 @@ public void deployTransferTokenContract() { logger.info("afterAssetIssueCount:" + afterAssetIssueCount); logger.info("afterAssetIssueContractAddress:" + afterAssetIssueContractAddress); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); Assert.assertTrue(infoById.get().getResultValue() == 1); @@ -171,23 +204,17 @@ public void deployTransferTokenContract() { Assert.assertTrue(beforeAssetIssueContractAddress == afterAssetIssueContractAddress); Assert.assertTrue(beforeAssetIssueDev == afterAssetIssueDev); - PublicMethod.unFreezeBalance(dev001Address, dev001Key, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(user001Address, user001Key, 1, - user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); PublicMethod.freeResource(user001Address, user001Key, foundationAddress, blockingStubFull); PublicMethod.unFreezeBalance(foundationAddress, testKey002, 0, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(foundationAddress, testKey002, 0, user001Address, blockingStubFull); } - + PublicMethod.unFreezeBalance( + foundationAddress, testKey002, 0, user001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken050.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken050.java index 302ecb7c..b9fcb33b 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken050.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken050.java @@ -14,11 +14,12 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ContractTrcToken050 extends TronBaseTest { @@ -27,85 +28,112 @@ public class ContractTrcToken050 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] dev001Address = ecKey1.getAddress(); String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] user001Address = ecKey2.getAddress(); String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - - @Test(enabled = true, description = "TransferToken to contract address ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken to contract address ", + groups = {"contract", "daily"}) public void deployTransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 2048000000, - foundationAddress, testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 4048000000L, - foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 2048000000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 4048000000L, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - // freeze balance - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(dev001Address, 204800000, - 0, 1, dev001Key, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(user001Address, 2048000000, - 0, 1, user001Key, blockingStubFull)); + // freeze balance + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + user001Address, 2048000000, 0, 1, user001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 100, start, end, 1, description, url, 10000L, - 10000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); - String filePath = "./src/test/resources/soliditycode/contractTrcToken050.sol"; - String contractName = "tokenTest"; + String filePath = "./src/test/resources/soliditycode/contractTrcToken050.sol"; + String contractName = "tokenTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] transferTokenContractAddress; - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 0L, 100, 10000, assetAccountId.toStringUtf8(), - 0, null, dev001Key, dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] transferTokenContractAddress; + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + 10000, + assetAccountId.toStringUtf8(), + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(user001Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(user001Address, blockingStubFull); info = PublicMethod.queryAccount(user001Address, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long beforeAssetIssueCount = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, - blockingStubFull); - Long beforeAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, - assetAccountId, - blockingStubFull); - final Long beforeAssetIssueDev = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeAssetIssueCount = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + final Long beforeAssetIssueDev = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -113,30 +141,42 @@ public void deployTransferTokenContract() { logger.info("beforeAssetIssueCount:" + beforeAssetIssueCount); logger.info("beforeAssetIssueContractAddress:" + beforeAssetIssueContractAddress); logger.info("beforeAssetIssueDev:" + beforeAssetIssueDev); - // user trigger A to transfer token to B + // user trigger A to transfer token to B String param = - "\"" + Base58.encode58Check(transferTokenContractAddress) + "\",\"" + assetAccountId - .toStringUtf8() + "\"" + + Base58.encode58Check(transferTokenContractAddress) + + "\",\"" + + assetAccountId.toStringUtf8() + "\",\"1\""; - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "TransferTokenTo(address,trcToken,uint256)", - param, false, 0, 100000000L, "0", - 0, user001Address, user001Key, blockingStubFull); + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "TransferTokenTo(address,trcToken,uint256)", + param, + false, + 0, + 100000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account infoafter = PublicMethod.queryAccount(user001Address, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(user001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterAssetIssueCount = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long afterAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - final Long afterAssetIssueDev = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(user001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterAssetIssueCount = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + final Long afterAssetIssueDev = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -152,20 +192,14 @@ public void deployTransferTokenContract() { Assert.assertEquals(beforeAssetIssueCount, afterAssetIssueCount); Assert.assertTrue(beforeAssetIssueContractAddress == afterAssetIssueContractAddress); Assert.assertEquals(beforeAssetIssueDev, afterAssetIssueDev); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); PublicMethod.freeResource(user001Address, user001Key, foundationAddress, blockingStubFull); PublicMethod.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull); } - + PublicMethod.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken051.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken051.java index cb8b08d4..868e2db6 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken051.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken051.java @@ -16,10 +16,11 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j public class ContractTrcToken051 extends TronBaseTest { @@ -27,80 +28,112 @@ public class ContractTrcToken051 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] dev001Address = ecKey1.getAddress(); String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] user001Address = ecKey2.getAddress(); - String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); /** - * constructor. - */ + String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } - + public void beforeClass() {} - @Test(enabled = true, description = "TransferToken to contract developer tokenID is 0", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken to contract developer tokenID is 0", + groups = {"contract", "daily"}) public void deployTransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 2048000000, - foundationAddress, testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 6048000000L, - foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 2048000000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 6048000000L, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - // freeze balance - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(dev001Address, 204800000, - 0, 1, dev001Key, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(user001Address, 2048000000, - 0, 1, user001Key, blockingStubFull)); + // freeze balance + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + user001Address, 2048000000, 0, 1, user001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 100, start, end, 1, description, url, 10000L, - 10000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); - // deploy transferTokenContract + // deploy transferTokenContract String filePath = "./src/test/resources/soliditycode/contractTrcToken051.sol"; - String contractName = "tokenTest"; + String contractName = "tokenTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] transferTokenContractAddress; - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 0L, 100, 10000, assetAccountId.toStringUtf8(), - 0, null, dev001Key, dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] transferTokenContractAddress; + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + 10000, + assetAccountId.toStringUtf8(), + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(user001Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(user001Address, blockingStubFull); info = PublicMethod.queryAccount(user001Address, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long beforeAssetIssueCount = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); - Long beforeAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long beforeAssetIssueDev = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeAssetIssueCount = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long beforeAssetIssueDev = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -108,33 +141,41 @@ public void deployTransferTokenContract() { logger.info("beforeAssetIssueCount:" + beforeAssetIssueCount); logger.info("beforeAssetIssueContractAddress:" + beforeAssetIssueContractAddress); logger.info("beforeAssetIssueDev:" + beforeAssetIssueDev); - String fakeassetAccountId = Long.toString(0L); - String param = "\"" + Base58.encode58Check(dev001Address) - + "\"," + fakeassetAccountId + ",\"1\""; - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "TransferTokenTo(address,trcToken,uint256)", - param, false, 0, 100000000L, "0", - 0, user001Address, user001Key, blockingStubFull); + String fakeassetAccountId = Long.toString(0L); + String param = + "\"" + Base58.encode58Check(dev001Address) + "\"," + fakeassetAccountId + ",\"1\""; + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "TransferTokenTo(address,trcToken,uint256)", + param, + false, + 0, + 100000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertFalse(infoById.get().getResultValue() == 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - Assert.assertEquals("REVERT opcode executed", - infoById.get().getResMessage().toStringUtf8()); + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); Account infoafter = PublicMethod.queryAccount(user001Address, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(user001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterAssetIssueCount = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long afterAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueDev = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(user001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterAssetIssueCount = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueDev = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); @@ -147,20 +188,14 @@ public void deployTransferTokenContract() { Assert.assertEquals(beforeAssetIssueCount, afterAssetIssueCount); Assert.assertEquals(beforeAssetIssueContractAddress, afterAssetIssueContractAddress); Assert.assertEquals(beforeAssetIssueDev, afterAssetIssueDev); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull); PublicMethod.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); - PublicMethod.freeResource(user001Address, user001Key, foundationAddress, blockingStubFull); } - - + PublicMethod.freeResource(user001Address, user001Key, foundationAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken052.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken052.java index 26c22936..9a6ce4b5 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken052.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken052.java @@ -14,10 +14,11 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j public class ContractTrcToken052 extends TronBaseTest { @@ -25,78 +26,110 @@ public class ContractTrcToken052 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] dev001Address = ecKey1.getAddress(); String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] user001Address = ecKey2.getAddress(); - String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); /** - * constructor. - */ + String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - - @Test(enabled = true, description = "TransferToken to contract address tokenID is 0", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken to contract address tokenID is 0", + groups = {"contract", "daily"}) public void deployTransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 2048000000, - foundationAddress, testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 6048000000L, - foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 2048000000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 6048000000L, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - // freeze balance - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(dev001Address, 204800000, - 0, 1, dev001Key, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(user001Address, 2048000000, - 0, 1, user001Key, blockingStubFull)); + // freeze balance + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + user001Address, 2048000000, 0, 1, user001Key, blockingStubFull)); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 100, start, end, 1, description, url, 10000L, - 10000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); - // deploy transferTokenContract + // deploy transferTokenContract String filePath = "./src/test/resources/soliditycode/contractTrcToken052.sol"; - String contractName = "tokenTest"; + String contractName = "tokenTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] transferTokenContractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, 10000, assetAccountId.toStringUtf8(), - 0, null, dev001Key, dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] transferTokenContractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + 10000, + assetAccountId.toStringUtf8(), + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); /*Assert.assertFalse(PublicMethod.sendcoin(transferTokenContractAddress, 2048000000, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull);*/ Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(user001Address, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(user001Address, blockingStubFull); info = PublicMethod.queryAccount(user001Address, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long beforeAssetIssueCount = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); - Long beforeAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long beforeAssetIssueDev = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - final Long beforetransferTokenContractAddressBalance = PublicMethod - .queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); - final Long beforeDevBalance = PublicMethod - .queryAccount(dev001Address, blockingStubFull).getBalance(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeAssetIssueCount = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long beforeAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long beforeAssetIssueDev = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + final Long beforetransferTokenContractAddressBalance = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); + final Long beforeDevBalance = + PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -104,36 +137,50 @@ public void deployTransferTokenContract() { logger.info("beforeAssetIssueCount:" + beforeAssetIssueCount); logger.info("beforeAssetIssueContractAddress:" + beforeAssetIssueContractAddress); logger.info("beforeAssetIssueDev:" + beforeAssetIssueDev); - String fakeassetAccountId = Long.toString(0L); - String param = "\"" + Base58.encode58Check(transferTokenContractAddress) - + "\"," + fakeassetAccountId + ",\"1\""; - // user trigger A to transfer token to B - - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "TransferTokenTo(address,trcToken,uint256)", - param, false, 0, 100000000L, "0", - 0, user001Address, user001Key, blockingStubFull); + String fakeassetAccountId = Long.toString(0L); + String param = + "\"" + + Base58.encode58Check(transferTokenContractAddress) + + "\"," + + fakeassetAccountId + + ",\"1\""; + // user trigger A to transfer token to B + + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "TransferTokenTo(address,trcToken,uint256)", + param, + false, + 0, + 100000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 1); Account infoafter = PublicMethod.queryAccount(user001Address, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(user001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterAssetIssueCount = PublicMethod - .getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long afterAssetIssueContractAddress = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - Long afterAssetIssueDev = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - final Long aftertransferTokenContractAddressBalance = PublicMethod - .queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); - final Long afterDevBalance = PublicMethod - .queryAccount(dev001Address, blockingStubFull).getBalance(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(user001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterAssetIssueCount = + PublicMethod.getAssetIssueValue(user001Address, assetAccountId, blockingStubFull); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterAssetIssueContractAddress = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + Long afterAssetIssueDev = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + final Long aftertransferTokenContractAddressBalance = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); + final Long afterDevBalance = + PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -149,23 +196,15 @@ public void deployTransferTokenContract() { Assert.assertEquals(beforeAssetIssueCount, afterAssetIssueCount); Assert.assertEquals(beforeAssetIssueContractAddress, afterAssetIssueContractAddress); Assert.assertEquals(beforeAssetIssueDev, afterAssetIssueDev); - } - /** - * constructor. - */ - - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.unFreezeBalance(dev001Address, dev001Key, 1, dev001Address, blockingStubFull); PublicMethod.unFreezeBalance(user001Address, user001Key, 1, user001Address, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, foundationAddress, blockingStubFull); - PublicMethod.freeResource(user001Address, user001Key, foundationAddress, blockingStubFull); } - - + PublicMethod.freeResource(user001Address, user001Key, foundationAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken054.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken054.java index c63f5295..9e73b090 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken054.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken054.java @@ -14,11 +14,12 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ContractTrcToken054 extends TronBaseTest { @@ -28,13 +29,13 @@ public class ContractTrcToken054 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] transferTokenContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -42,70 +43,103 @@ public class ContractTrcToken054 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = true, description = "Trigger transferToken with 0 tokenValue", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger transferToken with 0 tokenValue", + groups = {"contract", "daily"}) public void testTriggerTransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 3100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 70000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L, -// 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 3100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 70000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L, + // 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, 100000L, - 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); logger.info("The token name: " + tokenName); logger.info("The token ID: " + assetAccountId.toStringUtf8()); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("before energyLimit is " + energyLimit); logger.info("before energyUsage is " + energyUsage); logger.info("before balanceBefore is " + balanceBefore); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() - + ", devAssetCountBefore: " + devAssetCountBefore); - //String contractName = "transferTokenContract"; - String filePath = "./src/test/resources/soliditycode/contractTrcToken054.sol"; - String contractName = "tokenTest"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + // String contractName = "transferTokenContract"; + String filePath = "./src/test/resources/soliditycode/contractTrcToken054.sol"; + String contractName = "tokenTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String tokenId = assetAccountId.toStringUtf8(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String tokenId = assetAccountId.toStringUtf8(); long tokenValue = 200; long callValue = 0; - String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, callValue, 0, 10000, - tokenId, tokenValue, null, dev001Key, - dev001Address, blockingStubFull); + String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callValue, + 0, + 10000, + tokenId, + tokenValue, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (transferTokenTxid == null || infoById.get().getResultValue() != 0) { @@ -113,39 +147,51 @@ public void testTriggerTransferTokenContract() { } transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(transferTokenContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(transferTokenContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); long balanceAfter = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("after energyLimit is " + energyLimit); logger.info("after energyUsage is " + energyUsage); logger.info("after balanceAfter is " + balanceAfter); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() - + ", devAssetCountAfter: " + devAssetCountAfter); - Long contractAssetCount = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("before trigger, transferTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + contractAssetCount); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + Long contractAssetCount = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "before trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + contractAssetCount); Assert.assertEquals(Long.valueOf(200), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(200), contractAssetCount); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.transferAsset(user001Address, - assetAccountId.toByteArray(), 10L, dev001Address, dev001Key, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + user001Address, + assetAccountId.toByteArray(), + 10L, + dev001Address, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -157,8 +203,8 @@ public void testTriggerTransferTokenContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + userEnergyLimitBefore); logger.info("before trigger, userEnergyUsageBefore is " + userEnergyUsageBefore); @@ -167,14 +213,22 @@ public void testTriggerTransferTokenContract() { tokenId = assetAccountId.toStringUtf8(); tokenValue = 0; callValue = 5; - String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "msgTokenValueAndTokenIdTest()", "#", false, callValue, - 1000000000L, tokenId, tokenValue, user001Address, user001Key, - blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "msgTokenValueAndTokenIdTest()", + "#", + false, + callValue, + 1000000000L, + tokenId, + tokenValue, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (triggerTxid == null || infoById.get().getResultValue() != 0) { @@ -184,11 +238,11 @@ public void testTriggerTransferTokenContract() { logger.info( "the value: " + PublicMethod.getStrings(infoById.get().getContractResult(0).toByteArray())); - List retList = PublicMethod - .getStrings(infoById.get().getContractResult(0).toByteArray()); - Long msgId = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); - Long msgTokenValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); - Long msgCallValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(2))); + List retList = + PublicMethod.getStrings(infoById.get().getContractResult(0).toByteArray()); + Long msgId = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + Long msgTokenValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + Long msgCallValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(2))); logger.info("msgId: " + msgId); logger.info("msgTokenValue: " + msgTokenValue); @@ -206,8 +260,8 @@ public void testTriggerTransferTokenContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + userEnergyLimitAfter); logger.info("after trigger, userEnergyUsageAfter is " + userEnergyUsageAfter); @@ -216,19 +270,15 @@ public void testTriggerTransferTokenContract() { Assert.assertEquals(msgId.toString(), tokenId); Assert.assertEquals(Long.valueOf(msgTokenValue), Long.valueOf(tokenValue)); Assert.assertEquals(Long.valueOf(msgCallValue), Long.valueOf(callValue)); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken055.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken055.java index ea5ab128..068d41ab 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken055.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken055.java @@ -14,11 +14,12 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ContractTrcToken055 extends TronBaseTest { @@ -28,13 +29,13 @@ public class ContractTrcToken055 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] transferTokenContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -42,73 +43,104 @@ public class ContractTrcToken055 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - /** - * constructor. - */ - @Test(enabled = true, description = "Trigger TransferToken with long.max tokenId," - + " and 0tokenValue", groups = {"contract", "daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "Trigger TransferToken with long.max tokenId," + " and 0tokenValue", + groups = {"contract", "daily"}) public void triggerTransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 1100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 1000_000_000L, fromAddress, - testKey002, blockingStubFull)); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 70000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), -// 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 1000_000_000L, fromAddress, testKey002, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 70000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + + // PublicMethod.randomFreezeAmount.getAndAdd(1), + // 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, 100000L, - 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - assetAccountId = PublicMethod - .queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); + assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); logger.info("The token name: " + tokenName); logger.info("The token ID: " + assetAccountId.toStringUtf8()); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("before energyLimit is " + energyLimit); logger.info("before energyUsage is " + energyUsage); logger.info("before balanceBefore is " + balanceBefore); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() - + ", devAssetCountBefore: " + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken055.sol"; - String contractName = "tokenTest"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken055.sol"; + String contractName = "tokenTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String tokenId = assetAccountId.toStringUtf8(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String tokenId = assetAccountId.toStringUtf8(); long tokenValue = 200; long callValue = 0; - String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, callValue, 0, 10000, - tokenId, tokenValue, null, dev001Key, dev001Address, blockingStubFull); + String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callValue, + 0, + 10000, + tokenId, + tokenValue, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (transferTokenTxid == null || infoById.get().getResultValue() != 0) { @@ -116,36 +148,49 @@ public void triggerTransferTokenContract() { } transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(transferTokenContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(transferTokenContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); long balanceAfter = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("after energyLimit is " + energyLimit); logger.info("after energyUsage is " + energyUsage); logger.info("after balanceAfter is " + balanceAfter); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountAfter: " - + devAssetCountAfter); - Long contractAssetCount = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + Long contractAssetCount = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); Assert.assertEquals(Long.valueOf(200), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(200), contractAssetCount); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.transferAsset(user001Address, - assetAccountId.toByteArray(), 10L, dev001Address, dev001Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + user001Address, + assetAccountId.toByteArray(), + 10L, + dev001Address, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -160,24 +205,37 @@ public void triggerTransferTokenContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + userEnergyLimitBefore); logger.info("before trigger, userEnergyUsageBefore is " + userEnergyUsageBefore); logger.info("before trigger, userBalanceBefore is " + userBalanceBefore); - Long transferAssetBefore = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - logger.info("before trigger, transferTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + transferAssetBefore); + Long transferAssetBefore = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "before trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + transferAssetBefore); tokenId = Long.toString(Long.MAX_VALUE); tokenValue = 0; callValue = 5; - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "msgTokenValueAndTokenIdTest()", "", false, callValue, - 1000000000L, tokenId, tokenValue, user001Address, user001Key, - blockingStubFull); + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "msgTokenValueAndTokenIdTest()", + "", + false, + callValue, + 1000000000L, + tokenId, + tokenValue, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -192,15 +250,14 @@ public void triggerTransferTokenContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + userEnergyLimitAfter); logger.info("after trigger, userEnergyUsageAfter is " + userEnergyUsageAfter); logger.info("after trigger, userBalanceAfter is " + userBalanceAfter); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (triggerTxid == null || infoById.get().getResultValue() != 0) { @@ -210,11 +267,11 @@ public void triggerTransferTokenContract() { logger.info( "the value: " + PublicMethod.getStrings(infoById.get().getContractResult(0).toByteArray())); - List retList = PublicMethod - .getStrings(infoById.get().getContractResult(0).toByteArray()); - Long msgId = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); - Long msgTokenValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); - Long msgCallValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(2))); + List retList = + PublicMethod.getStrings(infoById.get().getContractResult(0).toByteArray()); + Long msgId = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + Long msgTokenValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + Long msgCallValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(2))); logger.info("msgId: " + msgId); logger.info("msgTokenValue: " + msgTokenValue); @@ -225,16 +282,13 @@ public void triggerTransferTokenContract() { Assert.assertEquals(Long.valueOf(msgCallValue), Long.valueOf(callValue)); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken060.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken060.java index f5ddf11b..6dabacbf 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken060.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken060.java @@ -14,11 +14,12 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ContractTrcToken060 extends TronBaseTest { @@ -28,76 +29,110 @@ public class ContractTrcToken060 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] transferTokenContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); } - @Test(enabled = true, description = "DeployContract with 0 tokenValue", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "DeployContract with 0 tokenValue", + groups = {"contract", "daily"}) public void deployTransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 2100_000_000L, fromAddress, - testKey002, blockingStubFull)); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 130000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), -// 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 2100_000_000L, fromAddress, testKey002, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 130000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + + // PublicMethod.randomFreezeAmount.getAndAdd(1), + // 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, 100000L, - 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); logger.info("The token name: " + tokenName); logger.info("The token ID: " + assetAccountId.toStringUtf8()); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("before energyLimit is " + energyLimit); logger.info("before energyUsage is " + energyUsage); logger.info("before balanceBefore is " + balanceBefore); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountBefore: " - + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken060.sol"; - String contractName = "tokenTest"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken060.sol"; + String contractName = "tokenTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String tokenId = assetAccountId.toStringUtf8(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String tokenId = assetAccountId.toStringUtf8(); long tokenValue = 0; long callValue = 5; - String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callValue, 0, 10000, tokenId, tokenValue, - null, dev001Key, dev001Address, blockingStubFull); + String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callValue, + 0, + 10000, + tokenId, + tokenValue, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (transferTokenTxid == null || infoById.get().getResultValue() != 0) { @@ -105,31 +140,38 @@ public void deployTransferTokenContract() { } transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(transferTokenContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(transferTokenContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); long balanceAfter = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("after energyLimit is " + energyLimit); logger.info("after energyUsage is " + energyUsage); logger.info("after balanceAfter is " + balanceAfter); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountAfter: " - + devAssetCountAfter); - Long contractAssetCount = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); - - Assert.assertEquals(Long.valueOf(tokenValue), - Long.valueOf(devAssetCountBefore - devAssetCountAfter)); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + Long contractAssetCount = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); + + Assert.assertEquals( + Long.valueOf(tokenValue), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(tokenValue), contractAssetCount); - // get and verify the msg.value and msg.id + // get and verify the msg.value and msg.id accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); @@ -139,14 +181,27 @@ public void deployTransferTokenContract() { logger.info("before trigger, devEnergyLimitBefore is " + devEnergyLimitBefore); logger.info("before trigger, devEnergyUsageBefore is " + devEnergyUsageBefore); logger.info("before trigger, devBalanceBefore is " + devBalanceBefore); - Long transferAssetBefore = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("before trigger, transferTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + transferAssetBefore); - final String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "getResultInCon()", "#", false, 0, - 1000000000L, "0", 0, dev001Address, dev001Key, - blockingStubFull); + Long transferAssetBefore = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "before trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + transferAssetBefore); + final String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "getResultInCon()", + "#", + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -158,22 +213,22 @@ public void deployTransferTokenContract() { logger.info("after trigger, devEnergyUsageAfter is " + devEnergyUsageAfter); logger.info("after trigger, devBalanceAfter is " + devBalanceAfter); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (triggerTxid == null || infoById.get().getResultValue() != 0) { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - logger.info("The msg value: " + PublicMethod.getStrings(infoById.get() - .getContractResult(0).toByteArray())); + logger.info( + "The msg value: " + + PublicMethod.getStrings(infoById.get().getContractResult(0).toByteArray())); - List retList = PublicMethod.getStrings(infoById.get() - .getContractResult(0).toByteArray()); - Long msgId = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); - Long msgTokenValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); - Long msgCallValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(2))); + List retList = + PublicMethod.getStrings(infoById.get().getContractResult(0).toByteArray()); + Long msgId = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + Long msgTokenValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + Long msgCallValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(2))); logger.info("msgId: " + msgId); logger.info("msgTokenValue: " + msgTokenValue); @@ -182,17 +237,13 @@ public void deployTransferTokenContract() { Assert.assertEquals(msgId.toString(), tokenId); Assert.assertEquals(Long.valueOf(msgTokenValue), Long.valueOf(tokenValue)); Assert.assertEquals(Long.valueOf(msgCallValue), Long.valueOf(callValue)); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken061.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken061.java index 65b0c414..462463c6 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken061.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken061.java @@ -14,11 +14,12 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ContractTrcToken061 extends TronBaseTest { @@ -28,79 +29,112 @@ public class ContractTrcToken061 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] transferTokenContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); } - @Test(enabled = true, description = "DeployContract with 0 tokenValue and long.max tokenId", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "DeployContract with 0 tokenValue and long.max tokenId", + groups = {"contract", "daily"}) public void deployTransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 2100_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 2100_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 130000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); -// -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), -// 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 130000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + // + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + + // PublicMethod.randomFreezeAmount.getAndAdd(1), + // 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, 100000L, - 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - assetAccountId = PublicMethod - .queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); + assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); logger.info("The token name: " + tokenName); logger.info("The token ID: " + assetAccountId.toStringUtf8()); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountBefore = PublicMethod.getAssetIssueValue(dev001Address, - assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("before energyLimit is " + energyLimit); logger.info("before energyUsage is " + energyUsage); logger.info("before balanceBefore is " + balanceBefore); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountBefore: " - + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken061.sol"; - String contractName = "tokenTest"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken061.sol"; + String contractName = "tokenTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String tokenId = Long.toString(Long.MAX_VALUE); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String tokenId = Long.toString(Long.MAX_VALUE); long tokenValue = 0; long callValue = 10; - String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callValue, 0, 10000, tokenId, tokenValue, - null, dev001Key, dev001Address, blockingStubFull); + String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callValue, + 0, + 10000, + tokenId, + tokenValue, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (transferTokenTxid == null || infoById.get().getResultValue() != 0) { @@ -108,58 +142,78 @@ public void deployTransferTokenContract() { } transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(transferTokenContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(transferTokenContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); long balanceAfter = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountAfter = PublicMethod.getAssetIssueValue(dev001Address, - assetAccountId, blockingStubFull); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("after energyLimit is " + energyLimit); logger.info("after energyUsage is " + energyUsage); logger.info("after balanceAfter is " + balanceAfter); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountAfter: " - + devAssetCountAfter); - Long contractAssetCount = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); - - Assert.assertEquals(Long.valueOf(tokenValue), - Long.valueOf(devAssetCountBefore - devAssetCountAfter)); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + Long contractAssetCount = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); + + Assert.assertEquals( + Long.valueOf(tokenValue), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(tokenValue), contractAssetCount); - // get and verify the msg.value and msg.id - - Long transferAssetBefore = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("before trigger, transferTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + transferAssetBefore); - String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "getResultInCon()", "#", false, 0, - 1000000000L, "0", 0, dev001Address, dev001Key, - blockingStubFull); + // get and verify the msg.value and msg.id + + Long transferAssetBefore = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "before trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + transferAssetBefore); + String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "getResultInCon()", + "#", + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (triggerTxid == null || infoById.get().getResultValue() != 0) { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - logger.info("The msg value: " + PublicMethod.getStrings(infoById.get() - .getContractResult(0).toByteArray())); + logger.info( + "The msg value: " + + PublicMethod.getStrings(infoById.get().getContractResult(0).toByteArray())); - List retList = PublicMethod.getStrings(infoById.get() - .getContractResult(0).toByteArray()); - Long msgId = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); - Long msgTokenValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); - Long msgCallValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(2))); + List retList = + PublicMethod.getStrings(infoById.get().getContractResult(0).toByteArray()); + Long msgId = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + Long msgTokenValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + Long msgCallValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(2))); logger.info("msgId: " + msgId); logger.info("msgTokenValue: " + msgTokenValue); @@ -168,17 +222,13 @@ public void deployTransferTokenContract() { Assert.assertEquals(msgId.toString(), tokenId); Assert.assertEquals(Long.valueOf(msgTokenValue), Long.valueOf(tokenValue)); Assert.assertEquals(Long.valueOf(msgCallValue), Long.valueOf(callValue)); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken064.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken064.java index fb124828..b68da5fc 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken064.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken064.java @@ -16,11 +16,11 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode @@ -32,14 +32,14 @@ public class ContractTrcToken064 extends TronBaseTest { private static ByteString assetAccountId = null; private static ByteString assetAccountUser = null; private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] transferTokenContractAddress = null; private byte[] resultContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -47,36 +47,56 @@ public class ContractTrcToken064 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = true, description = "TransferToken with 0 tokenValue and " - + "tokenId in exception condition, deploy transfer contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "TransferToken with 0 tokenValue and " + + "tokenId in exception condition, deploy transfer contract", + groups = {"contract", "daily"}) public void test01DeployTransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 5100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 5100_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 5100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 5100_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L, -// 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); -// PublicMethod.waitProduceNextBlock(blockingStubFull); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L, + // 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + // PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, 100000L, - 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); for (int i = 0; i < 2; i++) { PublicMethod.waitProduceNextBlock(blockingStubFull); } @@ -86,326 +106,468 @@ public void test01DeployTransferTokenContract() { start = System.currentTimeMillis() + 2000; end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(user001Address, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, 100000L, - 1L, 1L, user001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + user001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + user001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - assetAccountUser = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getAssetIssuedID(); + assetAccountUser = + PublicMethod.queryAccount(user001Address, blockingStubFull).getAssetIssuedID(); logger.info("The assetAccountUser token name: " + tokenName); logger.info("The assetAccountUser token ID: " + assetAccountUser.toStringUtf8()); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("before energyLimit is " + energyLimit); logger.info("before energyUsage is " + energyUsage); logger.info("before balanceBefore is " + balanceBefore); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountBefore: " - + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken064.sol"; - String contractName = "transferTokenContract"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken064.sol"; + String contractName = "transferTokenContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - assetAccountId.toStringUtf8(), 100, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + assetAccountId.toStringUtf8(), + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (transferTokenTxid == null || infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); } transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(transferTokenContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(transferTokenContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); long balanceAfter = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("after energyLimit is " + energyLimit); logger.info("after energyUsage is " + energyUsage); logger.info("after balanceAfter is " + balanceAfter); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountAfter: " - + devAssetCountAfter); - Long contractAssetCount = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + Long contractAssetCount = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); Assert.assertEquals(Long.valueOf(100), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(100), contractAssetCount); } - @Test(enabled = true, description = "TransferToken with 0 tokenValue and " - + "tokenId in exception condition, deploy receiver contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "TransferToken with 0 tokenValue and " + + "tokenId in exception condition, deploy receiver contract", + groups = {"contract", "daily"}) public void test02DeployRevContract() { -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 50000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - // before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 50000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("before energyLimit is " + energyLimit); logger.info("before energyUsage is " + energyUsage); logger.info("before balance is " + balanceBefore); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountBefore: " - + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken064.sol"; - String contractName = "Result"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken064.sol"; + String contractName = "Result"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String recieveTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 0L, 100, 1000, assetAccountId.toStringUtf8(), - 100, null, dev001Key, dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String recieveTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + 1000, + assetAccountId.toStringUtf8(), + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(recieveTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(recieveTokenTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (recieveTokenTxid == null || infoById.get().getResultValue() != 0) { Assert.fail("deploy receive failed with message: " + infoById.get().getResMessage()); } resultContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(resultContractAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(resultContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - // after deploy, check account resource + // after deploy, check account resource accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); long balanceAfter = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("after energyLimit is " + energyLimit); logger.info("after energyUsage is " + energyUsage); logger.info("after balanceAfter is " + balanceAfter); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountAfter: " - + devAssetCountAfter); - Long contractAssetCount = PublicMethod.getAssetIssueValue(resultContractAddress, - assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + Long contractAssetCount = + PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); Assert.assertEquals(Long.valueOf(100), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(100), contractAssetCount); } - @Test(enabled = true, description = "TransferToken with 0 tokenValue and " - + "tokenId in exception condition, trigger contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "TransferToken with 0 tokenValue and " + + "tokenId in exception condition, trigger contract", + groups = {"contract", "daily"}) public void test03TriggerContract() { -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.transferAsset(user001Address, - assetAccountId.toByteArray(), 10L, dev001Address, dev001Key, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.transferAsset( + user001Address, + assetAccountId.toByteArray(), + 10L, + dev001Address, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); - Long transferAssetBefore = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("before trigger, transferTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + transferAssetBefore); - Long receiveAssetBefore = PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, - blockingStubFull); - logger.info("before trigger, resultContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + receiveAssetBefore); - Long callValue = Long.valueOf(0); - String param = "\"" + Base58.encode58Check(resultContractAddress) + "\""; - String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTestValue0IdBigInteger(address)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long transferAssetBefore = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "before trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + transferAssetBefore); + Long receiveAssetBefore = + PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, blockingStubFull); + logger.info( + "before trigger, resultContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + receiveAssetBefore); + Long callValue = Long.valueOf(0); + String param = "\"" + Base58.encode58Check(resultContractAddress) + "\""; + String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTestValue0IdBigInteger(address)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info(infoById.get().getResMessage().toStringUtf8()); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - Assert.assertEquals("REVERT opcode executed", - //Assert.assertEquals("BigInteger out of long range", + Assert.assertEquals( + "REVERT opcode executed", + // Assert.assertEquals("BigInteger out of long range", infoById.get().getResMessage().toStringUtf8()); - //transfer to a normal account + // transfer to a normal account param = "\"" + Base58.encode58Check(dev001Address) + "\""; - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTestValue0IdBigInteger(address)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTestValue0IdBigInteger(address)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - //Assert.assertEquals("BigInteger out of long range", - Assert.assertEquals("REVERT opcode executed", - infoById.get().getResMessage().toStringUtf8()); - String tokenId = Long.toString(Long.MIN_VALUE); - Long tokenValue = Long.valueOf(0); + // Assert.assertEquals("BigInteger out of long range", + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); + String tokenId = Long.toString(Long.MIN_VALUE); + Long tokenValue = Long.valueOf(0); callValue = Long.valueOf(0); - param = "\"" + Base58.encode58Check(resultContractAddress) - + "\",\"" + tokenValue + "\"," + tokenId; - - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + param = + "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" + tokenValue + "\"," + tokenId; + + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - Assert.assertEquals("REVERT opcode executed", - infoById.get().getResMessage().toStringUtf8()); + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); tokenId = Long.toString(100_0000); tokenValue = Long.valueOf(0); callValue = Long.valueOf(0); - param = "\"" + Base58.encode58Check(resultContractAddress) - + "\",\"" + tokenValue + "\"," + tokenId; - - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + param = + "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" + tokenValue + "\"," + tokenId; + + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - Assert.assertEquals("REVERT opcode executed", - infoById.get().getResMessage().toStringUtf8()); + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); tokenId = Long.toString(-1); tokenValue = Long.valueOf(0); callValue = Long.valueOf(0); - param = "\"" + Base58.encode58Check(resultContractAddress) - + "\",\"" + tokenValue + "\"," + tokenId; - - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + param = + "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" + tokenValue + "\"," + tokenId; + + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - Assert.assertEquals("REVERT opcode executed", - infoById.get().getResMessage().toStringUtf8()); + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); tokenId = Long.toString(0); tokenValue = Long.valueOf(0); callValue = Long.valueOf(0); - param = "\"" + Base58.encode58Check(resultContractAddress) - + "\",\"" + tokenValue + "\"," + tokenId; - - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + param = + "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" + tokenValue + "\"," + tokenId; + + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - Assert.assertEquals("REVERT opcode executed", - infoById.get().getResMessage().toStringUtf8()); + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); callValue = Long.valueOf(0); param = "\"" + Base58.encode58Check(resultContractAddress) + "\""; - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTestValueMaxLong(address)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTestValueMaxLong(address)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); PublicMethod.waitProduceNextBlock(blockingStubFull); - //transfer to a normal account + // transfer to a normal account param = "\"" + Base58.encode58Check(dev001Address) + "\""; - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTestValueMaxLong(address)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTestValueMaxLong(address)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); - Long transferAssetAfter = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("after trigger, transferTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", transferAssetAfter is " + transferAssetAfter); - Long receiveAssetAfter = PublicMethod.getAssetIssueValue(resultContractAddress, - assetAccountId, blockingStubFull); - logger.info("after trigger, resultContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", receiveAssetAfter is " + receiveAssetAfter); + Long transferAssetAfter = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "after trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", transferAssetAfter is " + + transferAssetAfter); + Long receiveAssetAfter = + PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, blockingStubFull); + logger.info( + "after trigger, resultContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", receiveAssetAfter is " + + receiveAssetAfter); Assert.assertEquals(receiveAssetAfter, receiveAssetBefore); Assert.assertEquals(transferAssetBefore, transferAssetAfter); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken066.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken066.java index da537eca..284772e9 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken066.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken066.java @@ -15,11 +15,12 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ContractTrcToken066 extends TronBaseTest { @@ -29,14 +30,14 @@ public class ContractTrcToken066 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] transferTokenContractAddress = null; private byte[] resultContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -44,61 +45,94 @@ public class ContractTrcToken066 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = true, description = "TransferToken with 0 tokenValue, deploy transferContract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken with 0 tokenValue, deploy transferContract", + groups = {"contract", "daily"}) public void test01DeployTransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 5048_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 4048_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 5048_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 4048_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, 100000L, - 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); logger.info("The token name: " + tokenName); logger.info("The token ID: " + assetAccountId.toStringUtf8()); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("before energyLimit is " + energyLimit); logger.info("before energyUsage is " + energyUsage); logger.info("before balanceBefore is " + balanceBefore); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountBefore: " - + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken066.sol"; - String contractName = "transferTokenContract"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken066.sol"; + String contractName = "transferTokenContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - assetAccountId.toStringUtf8(), 100, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + assetAccountId.toStringUtf8(), + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (transferTokenTxid == null || infoById.get().getResultValue() != 0) { @@ -106,52 +140,77 @@ public void test01DeployTransferTokenContract() { } transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(transferTokenContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(transferTokenContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); long balanceAfter = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("after energyLimit is " + energyLimit); logger.info("after energyUsage is " + energyUsage); logger.info("after balanceAfter is " + balanceAfter); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountAfter: " - + devAssetCountAfter); - Long contractAssetCount = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + Long contractAssetCount = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); Assert.assertEquals(Long.valueOf(100), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(100), contractAssetCount); } - @Test(enabled = true, description = "TransferToken with 0 tokenValue, deploy receive contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken with 0 tokenValue, deploy receive contract", + groups = {"contract", "daily"}) public void test02DeployRevContract() { - Long devAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountBefore: " - + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken066.sol"; - String contractName = "Result"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken066.sol"; + String contractName = "Result"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String recieveTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 0L, 100, 1000, assetAccountId.toStringUtf8(), - 100, null, dev001Key, dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String recieveTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + 1000, + assetAccountId.toStringUtf8(), + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(recieveTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(recieveTokenTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (recieveTokenTxid == null || infoById.get().getResultValue() != 0) { @@ -160,50 +219,80 @@ public void test02DeployRevContract() { resultContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(resultContractAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(resultContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - Long devAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountAfter: " - + devAssetCountAfter); - Long contractAssetCount = PublicMethod.getAssetIssueValue(resultContractAddress, - assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + Long contractAssetCount = + PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); Assert.assertEquals(Long.valueOf(100), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(100), contractAssetCount); } - @Test(enabled = true, description = "TransferToken with 0 tokenValue, trigger transferContract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken with 0 tokenValue, trigger transferContract", + groups = {"contract", "daily"}) public void test03TriggerContract() { - Assert.assertTrue(PublicMethod.transferAsset(user001Address, - assetAccountId.toByteArray(), 10L, dev001Address, dev001Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + user001Address, + assetAccountId.toByteArray(), + 10L, + dev001Address, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long transferAssetBefore = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - logger.info("before trigger, transferTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + transferAssetBefore); - Long receiveAssetBefore = PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, - blockingStubFull); - logger.info("before trigger, resultContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + receiveAssetBefore); - String tokenId = assetAccountId.toStringUtf8(); - Long tokenValue = Long.valueOf(0); - Long callValue = Long.valueOf(0); - String param = "\"" + Base58.encode58Check(resultContractAddress) - + "\",\"" + tokenValue + "\"," + tokenId; - String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + Long transferAssetBefore = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "before trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + transferAssetBefore); + Long receiveAssetBefore = + PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, blockingStubFull); + logger.info( + "before trigger, resultContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + receiveAssetBefore); + String tokenId = assetAccountId.toStringUtf8(); + Long tokenValue = Long.valueOf(0); + Long callValue = Long.valueOf(0); + String param = + "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" + tokenValue + "\"," + tokenId; + String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); TransactionInfo transactionInfo = infoById.get(); @@ -211,13 +300,13 @@ public void test03TriggerContract() { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); logger.info("the value: " + retList); - Long msgId = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); - Long msgTokenValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); - Long msgCallValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(2))); + Long msgId = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + Long msgTokenValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + Long msgCallValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(2))); logger.info("msgId: " + msgId); logger.info("msgTokenValue: " + msgTokenValue); @@ -226,63 +315,81 @@ public void test03TriggerContract() { Assert.assertEquals(tokenId, msgId.toString()); Assert.assertEquals(tokenValue, msgTokenValue); Assert.assertEquals(callValue, msgCallValue); - Long transferAssetAfter = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("after trigger, transferTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", transferAssetAfter is " + transferAssetAfter); - Long receiveAssetAfter = PublicMethod.getAssetIssueValue(resultContractAddress, - assetAccountId, blockingStubFull); - logger.info("after trigger, resultContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", receiveAssetAfter is " + receiveAssetAfter); - - Assert.assertEquals(receiveAssetAfter - receiveAssetBefore, - transferAssetBefore + 2L - transferAssetAfter); - + Long transferAssetAfter = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "after trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", transferAssetAfter is " + + transferAssetAfter); + Long receiveAssetAfter = + PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, blockingStubFull); + logger.info( + "after trigger, resultContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", receiveAssetAfter is " + + receiveAssetAfter); + + Assert.assertEquals( + receiveAssetAfter - receiveAssetBefore, transferAssetBefore + 2L - transferAssetAfter); } - @Test(enabled = true, description = "TransferToken with 0 tokenValue, get contract tokenBalance", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken with 0 tokenValue, get contract tokenBalance", + groups = {"contract", "daily"}) public void test04TriggerTokenBalanceContract() { - - String param = "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" - + assetAccountId.toStringUtf8() + "\""; - String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "getTokenBalnce(address,trcToken)", - param, false, 0, 1000000000L, user001Address, - user001Key, blockingStubFull); + String param = + "\"" + + Base58.encode58Check(resultContractAddress) + + "\",\"" + + assetAccountId.toStringUtf8() + + "\""; + String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "getTokenBalnce(address,trcToken)", + param, + false, + 0, + 1000000000L, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod.getTransactionInfoById(triggerTxid, - blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (triggerTxid == null || infoById.get().getResultValue() != 0) { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - logger.info("the receivercontract token: " + ByteArray - .toLong(infoById.get().getContractResult(0).toByteArray())); - Long assetIssueCount = PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, - blockingStubFull); + logger.info( + "the receivercontract token: " + + ByteArray.toLong(infoById.get().getContractResult(0).toByteArray())); + Long assetIssueCount = + PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, blockingStubFull); logger.info("the receivercontract token(getaccount): " + assetIssueCount); - Assert.assertTrue(assetIssueCount == ByteArray - .toLong(ByteArray.fromHexString( - ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); - + Assert.assertTrue( + assetIssueCount + == ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken067.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken067.java index 574ffbb3..8dd3fad8 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken067.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken067.java @@ -14,11 +14,12 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ContractTrcToken067 extends TronBaseTest { @@ -28,14 +29,14 @@ public class ContractTrcToken067 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] transferTokenContractAddress = null; private byte[] resultContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -43,60 +44,94 @@ public class ContractTrcToken067 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = true, description = "TransferToken with 0 tokenValue, " - + "and not existed tokenId, deploy transfer contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "TransferToken with 0 tokenValue, " + "and not existed tokenId, deploy transfer contract", + groups = {"contract", "daily"}) public void test01DeployTransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 5048_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 4048_000_000L, fromAddress, - testKey002, blockingStubFull)); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); -// -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), -// 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 5048_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 4048_000_000L, fromAddress, testKey002, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + // + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + + // PublicMethod.randomFreezeAmount.getAndAdd(1), + // 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, 100000L, - 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); logger.info("The token name: " + tokenName); logger.info("The token ID: " + assetAccountId.toStringUtf8()); - Long devAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountBefore: " - + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken067.sol"; - String contractName = "transferTokenContract"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken067.sol"; + String contractName = "transferTokenContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - assetAccountId.toStringUtf8(), 100, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + assetAccountId.toStringUtf8(), + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (transferTokenTxid == null || infoById.get().getResultValue() != 0) { @@ -104,105 +139,161 @@ public void test01DeployTransferTokenContract() { } transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(transferTokenContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(transferTokenContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - Long devAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountAfter: " - + devAssetCountAfter); - Long contractAssetCount = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + Long contractAssetCount = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); Assert.assertEquals(Long.valueOf(100), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(100), contractAssetCount); } - @Test(enabled = true, description = "TransferToken with 0 tokenValue, " - + "and not existed tokenId, deploy receive contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "TransferToken with 0 tokenValue, " + "and not existed tokenId, deploy receive contract", + groups = {"contract", "daily"}) public void test02DeployRevContract() { -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 50000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - Long devAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountBefore: " - + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken067.sol"; - String contractName = "Result"; + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 50000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken067.sol"; + String contractName = "Result"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String recieveTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 0L, 100, 1000, assetAccountId.toStringUtf8(), - 100, null, dev001Key, dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String recieveTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + 1000, + assetAccountId.toStringUtf8(), + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(recieveTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(recieveTokenTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (recieveTokenTxid == null || infoById.get().getResultValue() != 0) { Assert.fail("deploy receive failed with message: " + infoById.get().getResMessage()); } - Long devAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountAfter: " - + devAssetCountAfter); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); resultContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(resultContractAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(resultContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - Long contractAssetCount = PublicMethod.getAssetIssueValue(resultContractAddress, - assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); + Long contractAssetCount = + PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); Assert.assertEquals(Long.valueOf(100), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(100), contractAssetCount); } - @Test(enabled = true, description = "TransferToken with 0 tokenValue, " - + "and not existed tokenId, trigger transfer contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "TransferToken with 0 tokenValue, " + + "and not existed tokenId, trigger transfer contract", + groups = {"contract", "daily"}) public void test03TriggerContract() { -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.transferAsset(user001Address, - assetAccountId.toByteArray(), 10L, dev001Address, dev001Key, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.transferAsset( + user001Address, + assetAccountId.toByteArray(), + 10L, + dev001Address, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long transferAssetBefore = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("before trigger, transferTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + transferAssetBefore); - Long receiveAssetBefore = PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, - blockingStubFull); - logger.info("before trigger, resultContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + receiveAssetBefore); - String tokenId = Long.toString(Long.MAX_VALUE); - Long tokenValue = Long.valueOf(0); - Long callValue = Long.valueOf(0); - String param = "\"" + Base58.encode58Check(resultContractAddress) - + "\",\"" + tokenValue + "\"," + tokenId; - String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "transferTokenTest(address,uint256,trcToken)", param, false, callValue, - 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, - blockingStubFull); + Long transferAssetBefore = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "before trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + transferAssetBefore); + Long receiveAssetBefore = + PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, blockingStubFull); + logger.info( + "before trigger, resultContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + receiveAssetBefore); + String tokenId = Long.toString(Long.MAX_VALUE); + Long tokenValue = Long.valueOf(0); + Long callValue = Long.valueOf(0); + String param = + "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" + tokenValue + "\"," + tokenId; + String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "transferTokenTest(address,uint256,trcToken)", + param, + false, + callValue, + 1000000000L, + assetAccountId.toStringUtf8(), + 2, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (triggerTxid == null || infoById.get().getResultValue() != 0) { @@ -211,14 +302,14 @@ public void test03TriggerContract() { TransactionInfo transactionInfo = infoById.get(); logger.info( - "the value: " + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData() - .toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod.getStrings(transactionInfo.getLogList().get(0) - .getData().toByteArray()); - Long msgId = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); - Long msgTokenValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); - Long msgCallValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(2))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long msgId = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + Long msgTokenValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + Long msgCallValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(2))); logger.info("msgId: " + msgId); logger.info("msgTokenValue: " + msgTokenValue); @@ -227,63 +318,84 @@ public void test03TriggerContract() { Assert.assertEquals(tokenId, msgId.toString()); Assert.assertEquals(tokenValue, msgTokenValue); Assert.assertEquals(callValue, msgCallValue); - Long transferAssetAfter = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("after trigger, transferTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", transferAssetAfter is " + transferAssetAfter); - Long receiveAssetAfter = PublicMethod.getAssetIssueValue(resultContractAddress, - assetAccountId, blockingStubFull); - logger.info("after trigger, resultContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", receiveAssetAfter is " + receiveAssetAfter); - - Assert.assertEquals(receiveAssetAfter - receiveAssetBefore, - transferAssetBefore + 2L - transferAssetAfter); + Long transferAssetAfter = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "after trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", transferAssetAfter is " + + transferAssetAfter); + Long receiveAssetAfter = + PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, blockingStubFull); + logger.info( + "after trigger, resultContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", receiveAssetAfter is " + + receiveAssetAfter); + + Assert.assertEquals( + receiveAssetAfter - receiveAssetBefore, transferAssetBefore + 2L - transferAssetAfter); } - @Test(enabled = true, description = "TransferToken with 0 tokenValue, " - + "and not existed tokenId, get tokenBalance", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "TransferToken with 0 tokenValue, " + "and not existed tokenId, get tokenBalance", + groups = {"contract", "daily"}) public void test04TriggerTokenBalanceContract() { - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(user001Address, 1000_000_000L, - 0, 1, user001Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + user001Address, 1000_000_000L, 0, 1, user001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String param = "\"" + Base58.encode58Check(resultContractAddress) + "\",\"" - + assetAccountId.toStringUtf8() + "\""; - String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "getTokenBalnce(address,trcToken)", - param, false, 0, 1000000000L, user001Address, - user001Key, blockingStubFull); + String param = + "\"" + + Base58.encode58Check(resultContractAddress) + + "\",\"" + + assetAccountId.toStringUtf8() + + "\""; + String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "getTokenBalnce(address,trcToken)", + param, + false, + 0, + 1000000000L, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod.getTransactionInfoById(triggerTxid, - blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (triggerTxid == null || infoById.get().getResultValue() != 0) { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - logger.info("the receivercontract token: " + ByteArray - .toLong(infoById.get().getContractResult(0).toByteArray())); - Long assetIssueCount = PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, - blockingStubFull); + logger.info( + "the receivercontract token: " + + ByteArray.toLong(infoById.get().getContractResult(0).toByteArray())); + Long assetIssueCount = + PublicMethod.getAssetIssueValue(resultContractAddress, assetAccountId, blockingStubFull); logger.info("the receivercontract token(getaccount): " + assetIssueCount); - Assert.assertTrue(assetIssueCount == ByteArray - .toLong(ByteArray.fromHexString( - ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); - + Assert.assertTrue( + assetIssueCount + == ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken073.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken073.java index 5f3a80eb..f1f8af8a 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken073.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken073.java @@ -12,10 +12,11 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j public class ContractTrcToken073 extends TronBaseTest { @@ -24,65 +25,99 @@ public class ContractTrcToken073 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; private byte[] transferTokenContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); } - @Test(enabled = true, description = "TokenBalance with correct tokenValue and tokenId", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TokenBalance with correct tokenValue and tokenId", + groups = {"contract", "daily"}) public void testTokenBalanceContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 11000_000_000L, fromAddress, - foundationKey, blockingStubFull)); -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 300000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); -// -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), -// 0, 0, ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 11000_000_000L, fromAddress, foundationKey, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 300000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); + // + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + + // PublicMethod.randomFreezeAmount.getAndAdd(1), + // 0, 0, ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, 100000L, - 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); logger.info("The token name: " + tokenName); logger.info("The token ID: " + assetAccountId.toStringUtf8()); - Long devAssetCountBefore = PublicMethod.getAssetIssueValue(dev001Address, - assetAccountId, blockingStubFull); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountBefore: " - + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken073.sol"; - String contractName = "Dest"; + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken073.sol"; + String contractName = "Dest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String tokenId = assetAccountId.toStringUtf8(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String tokenId = assetAccountId.toStringUtf8(); long tokenValue = 200; long callValue = 5; - String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callValue, 0, 10000, tokenId, tokenValue, - null, dev001Key, dev001Address, blockingStubFull); + String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callValue, + 0, + 10000, + tokenId, + tokenValue, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (transferTokenTxid == null || infoById.get().getResultValue() != 0) { @@ -90,40 +125,62 @@ public void testTokenBalanceContract() { } transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(transferTokenContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(transferTokenContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - Long devAssetCountAfter = PublicMethod.getAssetIssueValue(dev001Address, - assetAccountId, blockingStubFull); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountAfter: " - + devAssetCountAfter); - Long contractAssetCount = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); - - Assert.assertEquals(Long.valueOf(tokenValue), - Long.valueOf(devAssetCountBefore - devAssetCountAfter)); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + Long contractAssetCount = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); + + Assert.assertEquals( + Long.valueOf(tokenValue), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(tokenValue), contractAssetCount); - // get and verify the msg.value and msg.id - Long transferAssetBefore = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("before trigger, transferTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + transferAssetBefore); - Long devAssetBefore = PublicMethod.getAssetIssueValue(dev001Address, - assetAccountId, blockingStubFull); - logger.info("before trigger, dev001Address has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + devAssetBefore); + // get and verify the msg.value and msg.id + Long transferAssetBefore = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "before trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + transferAssetBefore); + Long devAssetBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + logger.info( + "before trigger, dev001Address has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + devAssetBefore); tokenId = assetAccountId.toStringUtf8(); - String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "getToken(trcToken)", tokenId, false, 0, - 1000000000L, "0", 0, dev001Address, dev001Key, - blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "getToken(trcToken)", + tokenId, + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (triggerTxid == null || infoById.get().getResultValue() != 0) { @@ -131,12 +188,12 @@ public void testTokenBalanceContract() { } logger.info("The msg value: " + infoById.get().getLogList().get(0).getTopicsList()); - Long msgTokenBalance = ByteArray - .toLong(infoById.get().getLogList().get(0).getTopicsList().get(1).toByteArray()); - Long msgId = ByteArray - .toLong(infoById.get().getLogList().get(0).getTopicsList().get(2).toByteArray()); - Long msgTokenValue = ByteArray - .toLong(infoById.get().getLogList().get(0).getTopicsList().get(3).toByteArray()); + Long msgTokenBalance = + ByteArray.toLong(infoById.get().getLogList().get(0).getTopicsList().get(1).toByteArray()); + Long msgId = + ByteArray.toLong(infoById.get().getLogList().get(0).getTopicsList().get(2).toByteArray()); + Long msgTokenValue = + ByteArray.toLong(infoById.get().getLogList().get(0).getTopicsList().get(3).toByteArray()); logger.info("msgTokenBalance: " + msgTokenBalance); logger.info("msgId: " + msgId); @@ -145,14 +202,22 @@ public void testTokenBalanceContract() { Assert.assertEquals(msgTokenBalance, devAssetBefore); tokenId = Long.toString(Long.valueOf(assetAccountId.toStringUtf8()) + 1000); - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "getToken(trcToken)", tokenId, false, 0, - 1000000000L, "0", 0, dev001Address, dev001Key, - blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "getToken(trcToken)", + tokenId, + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (triggerTxid == null || infoById.get().getResultValue() != 0) { @@ -161,12 +226,12 @@ public void testTokenBalanceContract() { logger.info("The msg value: " + infoById.get().getLogList().get(0).getTopicsList()); - msgTokenBalance = ByteArray - .toLong(infoById.get().getLogList().get(0).getTopicsList().get(1).toByteArray()); - msgId = ByteArray - .toLong(infoById.get().getLogList().get(0).getTopicsList().get(2).toByteArray()); - msgTokenValue = ByteArray - .toLong(infoById.get().getLogList().get(0).getTopicsList().get(3).toByteArray()); + msgTokenBalance = + ByteArray.toLong(infoById.get().getLogList().get(0).getTopicsList().get(1).toByteArray()); + msgId = + ByteArray.toLong(infoById.get().getLogList().get(0).getTopicsList().get(2).toByteArray()); + msgTokenValue = + ByteArray.toLong(infoById.get().getLogList().get(0).getTopicsList().get(3).toByteArray()); logger.info("msgTokenBalance: " + msgTokenBalance); logger.info("msgId: " + msgId); @@ -176,14 +241,22 @@ public void testTokenBalanceContract() { tokenId = Long.toString(Long.MAX_VALUE); - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "getToken(trcToken)", tokenId, false, 0, - 1000000000L, "0", 0, dev001Address, dev001Key, - blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "getToken(trcToken)", + tokenId, + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (triggerTxid == null || infoById.get().getResultValue() != 0) { @@ -192,12 +265,12 @@ public void testTokenBalanceContract() { logger.info("The msg value: " + infoById.get().getLogList().get(0).getTopicsList()); - msgTokenBalance = ByteArray - .toLong(infoById.get().getLogList().get(0).getTopicsList().get(1).toByteArray()); - msgId = ByteArray - .toLong(infoById.get().getLogList().get(0).getTopicsList().get(2).toByteArray()); - msgTokenValue = ByteArray - .toLong(infoById.get().getLogList().get(0).getTopicsList().get(3).toByteArray()); + msgTokenBalance = + ByteArray.toLong(infoById.get().getLogList().get(0).getTopicsList().get(1).toByteArray()); + msgId = + ByteArray.toLong(infoById.get().getLogList().get(0).getTopicsList().get(2).toByteArray()); + msgTokenValue = + ByteArray.toLong(infoById.get().getLogList().get(0).getTopicsList().get(3).toByteArray()); logger.info("msgTokenBalance: " + msgTokenBalance); logger.info("msgId: " + msgId); @@ -206,14 +279,11 @@ public void testTokenBalanceContract() { Assert.assertEquals(Long.valueOf(0), msgTokenBalance); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, foundationKey, 1, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, foundationKey, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, foundationKey, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken075.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken075.java index d2c01d5d..cb96a381 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken075.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken075.java @@ -14,10 +14,11 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j public class ContractTrcToken075 extends TronBaseTest { @@ -26,66 +27,99 @@ public class ContractTrcToken075 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; private byte[] transferTokenContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); } - @Test(enabled = true, description = "TokenBalance with exception condition", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TokenBalance with exception condition", + groups = {"contract", "daily"}) public void testTokenBalanceContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 11000_000_000L, fromAddress, - foundationKey, blockingStubFull)); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 130000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); -// -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), -// 0, 0, ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 11000_000_000L, fromAddress, foundationKey, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 130000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); + // + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + + // PublicMethod.randomFreezeAmount.getAndAdd(1), + // 0, 0, ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, 100000L, - 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - assetAccountId = PublicMethod - .queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); + assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); logger.info("The token name: " + tokenName); logger.info("The token ID: " + assetAccountId.toStringUtf8()); - Long devAssetCountBefore = PublicMethod.getAssetIssueValue(dev001Address, - assetAccountId, blockingStubFull); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountBefore: " - + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken075.sol"; - String contractName = "Dest"; + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken075.sol"; + String contractName = "Dest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String tokenId = assetAccountId.toStringUtf8(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String tokenId = assetAccountId.toStringUtf8(); long tokenValue = 200; long callValue = 5; - String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callValue, 0, 10000, tokenId, tokenValue, - null, dev001Key, dev001Address, blockingStubFull); + String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callValue, + 0, + 10000, + tokenId, + tokenValue, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (transferTokenTxid == null || infoById.get().getResultValue() != 0) { @@ -93,135 +127,187 @@ public void testTokenBalanceContract() { } transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(transferTokenContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(transferTokenContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - Long devAssetCountAfter = PublicMethod.getAssetIssueValue(dev001Address, - assetAccountId, blockingStubFull); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountAfter: " - + devAssetCountAfter); - Long contractAssetCount = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); - - Assert.assertEquals(Long.valueOf(tokenValue), - Long.valueOf(devAssetCountBefore - devAssetCountAfter)); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + Long contractAssetCount = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); + + Assert.assertEquals( + Long.valueOf(tokenValue), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(tokenValue), contractAssetCount); - // get and verify the msg.value and msg.id + // get and verify the msg.value and msg.id - Long transferAssetBefore = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("before trigger, transferTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + transferAssetBefore); - Long devAssetBefore = PublicMethod.getAssetIssueValue(dev001Address, - assetAccountId, blockingStubFull); - logger.info("before trigger, dev001Address has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + devAssetBefore); + Long transferAssetBefore = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "before trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + transferAssetBefore); + Long devAssetBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + logger.info( + "before trigger, dev001Address has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + devAssetBefore); tokenId = Long.toString(100_0000); - String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "getToken(trcToken)", tokenId, false, 0, - 1000000000L, "0", 0, dev001Address, dev001Key, - blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "getToken(trcToken)", + tokenId, + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - Assert.assertEquals("REVERT opcode executed", - infoById.get().getResMessage().toStringUtf8()); + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); tokenId = Long.toString(0); - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "getToken(trcToken)", tokenId, false, 0, - 1000000000L, "0", 0, dev001Address, dev001Key, - blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "getToken(trcToken)", + tokenId, + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - Assert.assertEquals("REVERT opcode executed", - infoById.get().getResMessage().toStringUtf8()); + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); tokenId = Long.toString(-1); - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "getToken(trcToken)", tokenId, false, 0, - 1000000000L, "0", 0, dev001Address, dev001Key, - blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "getToken(trcToken)", + tokenId, + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - Assert.assertEquals("REVERT opcode executed", - infoById.get().getResMessage().toStringUtf8()); + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); tokenId = Long.toString(Long.MIN_VALUE); - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "getToken(trcToken)", tokenId, false, 0, - 1000000000L, "0", 0, dev001Address, dev001Key, - blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "getToken(trcToken)", + tokenId, + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - Assert.assertEquals("REVERT opcode executed", - infoById.get().getResMessage().toStringUtf8()); + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "getTokenLongMin()", "#", false, 0, - 1000000000L, "0", 0, dev001Address, dev001Key, - blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "getTokenLongMin()", + "#", + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - Assert.assertEquals("REVERT opcode executed", - infoById.get().getResMessage().toStringUtf8()); + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "getTokenLongMax()", "#", false, 0, - 1000000000L, "0", 0, dev001Address, dev001Key, - blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "getTokenLongMax()", + "#", + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); - //Assert.assertEquals("BigInteger out of long range", - Assert.assertEquals("REVERT opcode executed", - infoById.get().getResMessage().toStringUtf8()); - + // Assert.assertEquals("BigInteger out of long range", + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, foundationKey, 0, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, foundationKey, 1, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, foundationKey, 1, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken076.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken076.java index f59c0208..3e58bb5e 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken076.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken076.java @@ -10,16 +10,15 @@ import org.testng.annotations.Test; import org.tron.api.WalletGrpc; import org.tron.protos.Protocol.TransactionInfo; -import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j public class ContractTrcToken076 extends TronBaseTest { - byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] grammarAddress = ecKey1.getAddress(); @@ -27,62 +26,96 @@ public class ContractTrcToken076 extends TronBaseTest { private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(testKeyForGrammarAddress); logger.info(Long.toString(PublicMethod.queryAccount(foundationKey, blockingStubFull) - .getBalance())); + PublicMethod.printAddress(testKeyForGrammarAddress); + logger.info( + Long.toString(PublicMethod.queryAccount(foundationKey, blockingStubFull).getBalance())); } - @Test(enabled = true, description = "Origin test ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Origin test ", + groups = {"contract", "daily"}) public void testDeployTransferTokenContract() { - PublicMethod - .sendcoin(grammarAddress, 100000000000L, foundationAddress, foundationKey, - blockingStubFull); + PublicMethod.sendcoin( + grammarAddress, 100000000000L, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/contractTrcToken076.sol"; - String contractName = "Test"; + String filePath = "./src/test/resources/soliditycode/contractTrcToken076.sol"; + String contractName = "Test"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress, - grammarAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress, + grammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); contractAddress = infoById.get().getContractAddress().toByteArray(); - PublicMethod.triggerContract(contractAddress, - "test()", "#", false, - 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + PublicMethod.triggerContract( + contractAddress, + "test()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - txid = PublicMethod.triggerContract(contractAddress, - "getResult1()", "#", false, - 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "getResult1()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); logger.info("infoById:" + infoById); - Long returnnumber = ByteArray.toLong(ByteArray.fromHexString(ByteArray.toHexString( - infoById.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(returnnumber == 1); - txid = PublicMethod.triggerContract(contractAddress, - "getResult2()", "#", false, - 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "getResult2()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -91,19 +124,18 @@ public void testDeployTransferTokenContract() { logger.info("-------------------------"); logger.info("infoById:" + infoById); - Long returnnumber2 = ByteArray.toLong(ByteArray.fromHexString( - ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Long returnnumber2 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(returnnumber2 == 1); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(grammarAddress, testKeyForGrammarAddress, foundationAddress, - blockingStubFull); } - + PublicMethod.freeResource( + grammarAddress, testKeyForGrammarAddress, foundationAddress, blockingStubFull); + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java index 0871cdfe..44e95ec2 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java @@ -10,16 +10,15 @@ import org.testng.annotations.Test; import org.tron.api.WalletGrpc; import org.tron.protos.Protocol.TransactionInfo; -import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j public class ContractTrcToken077 extends TronBaseTest { - byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] grammarAddress = ecKey1.getAddress(); @@ -27,75 +26,116 @@ public class ContractTrcToken077 extends TronBaseTest { private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(testKeyForGrammarAddress); logger.info(Long.toString(PublicMethod.queryAccount(foundationKey, blockingStubFull) - .getBalance())); + PublicMethod.printAddress(testKeyForGrammarAddress); + logger.info( + Long.toString(PublicMethod.queryAccount(foundationKey, blockingStubFull).getBalance())); } - @Test(enabled = false, groups = {"contract", "daily"}) + @Test( + enabled = false, + groups = {"contract", "daily"}) public void testAddress001() { - PublicMethod - .sendcoin(grammarAddress, 100000000000L, foundationAddress, foundationKey, - blockingStubFull); - String filePath = "./src/test/resources/soliditycode/contractTrcToken077.sol"; - String contractName = "trcToken077"; + PublicMethod.sendcoin( + grammarAddress, 100000000000L, foundationAddress, foundationKey, blockingStubFull); + String filePath = "./src/test/resources/soliditycode/contractTrcToken077.sol"; + String contractName = "trcToken077"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String deployTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress, - grammarAddress, blockingStubFull); - Optional deployInfo = PublicMethod - .getTransactionInfoById(deployTxid, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String deployTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress, + grammarAddress, + blockingStubFull); + Optional deployInfo = + PublicMethod.getTransactionInfoById(deployTxid, blockingStubFull); contractAddress = deployInfo.get().getContractAddress().toByteArray(); logger.info("Deploy energy is " + deployInfo.get().getReceipt().getEnergyUsageTotal()); - String txid = ""; - txid = PublicMethod.triggerContract(contractAddress, - "addressTest()", "#", false, - 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + String txid = ""; + txid = + PublicMethod.triggerContract( + contractAddress, + "addressTest()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById:" + infoById); logger.info("Trigger energy is " + infoById.get().getReceipt().getEnergyUsageTotal()); - } - @Test(enabled = true, description = "The value of address is not at the beginning of 41", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "The value of address is not at the beginning of 41", + groups = {"contract", "daily"}) public void testAddress002() { - PublicMethod - .sendcoin(grammarAddress, 100000000000L, foundationAddress, foundationKey, - blockingStubFull); + PublicMethod.sendcoin( + grammarAddress, 100000000000L, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName = "trcToken077"; - String code = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a57600" - + "080fd5b5060b0806100396000396000f3fe6080604052348015600f57600080fd5b50d38015601b57600080" - + "fd5b50d28015602757600080fd5b5060043610605c577c01000000000000000000000000000000000000000" - + "0000000000000000060003504636241c1d881146061575b600080fd5b60676079565b604080519182525190" - + "81900360200190f35b60405130908190529056fea165627a7a723058207b9b52e71420f2fa4cb55ffd55641" - + "355ec84e09d6d4545c629dde7cc01d74a100029"; - String abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"addressTest\",\"outputs\":[{\"name" - + "\":\"addressValue\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"nonp" - + "ayable\",\"type\":\"function\"}]"; - String deploytxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress, - grammarAddress, blockingStubFull); + String contractName = "trcToken077"; + String code = + "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a57600" + + "080fd5b5060b0806100396000396000f3fe6080604052348015600f57600080fd5b50d38015601b57600" + + "080" + + "fd5b50d28015602757600080fd5b5060043610605c577c01000000000000000000000000000000000000" + + "000" + + "0000000000000000060003504636241c1d881146061575b600080fd5b60676079565b604080519182525" + + "190" + + "81900360200190f35b60405130908190529056fea165627a7a723058207b9b52e71420f2fa4cb55ffd55" + + "641" + + "355ec84e09d6d4545c629dde7cc01d74a100029"; + String abi = + "[{\"constant\":false,\"inputs\":[],\"name\":\"addressTest\",\"outputs\":[{\"name" + + "\":\"addressValue\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"n" + + "onp" + + "ayable\",\"type\":\"function\"}]"; + String deploytxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKeyForGrammarAddress, + grammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional deployById = PublicMethod - .getTransactionInfoById(deploytxid, blockingStubFull); + Optional deployById = + PublicMethod.getTransactionInfoById(deploytxid, blockingStubFull); contractAddress = deployById.get().getContractAddress().toByteArray(); logger.info("infoById:" + deployById); - String txid = ""; - txid = PublicMethod.triggerContract(contractAddress, - "addressTest()", "#", false, - 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + String txid = ""; + txid = + PublicMethod.triggerContract( + contractAddress, + "addressTest()", + "#", + false, + 0, + maxFeeLimit, + grammarAddress, + testKeyForGrammarAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -103,11 +143,11 @@ public void testAddress002() { logger.info("infoById:" + infoById); Assert.assertNotNull(infoById); - byte[] a = infoById.get().getContractResult(0).toByteArray(); - byte[] b = subByte(a, 11, 1); - byte[] c = subByte(a, 0, 11); - byte[] e = "41".getBytes(); - byte[] d = subByte(a, 12, 20); + byte[] a = infoById.get().getContractResult(0).toByteArray(); + byte[] b = subByte(a, 11, 1); + byte[] c = subByte(a, 0, 11); + byte[] e = "41".getBytes(); + byte[] d = subByte(a, 12, 20); logger.info("a:" + ByteArray.toHexString(a)); @@ -117,32 +157,25 @@ public void testAddress002() { logger.info("d:" + ByteArray.toHexString(d)); logger.info("41" + ByteArray.toHexString(d)); - String exceptedResult = "41" + ByteArray.toHexString(d); - String realResult = ByteArray.toHexString(b); + String exceptedResult = "41" + ByteArray.toHexString(d); + String realResult = ByteArray.toHexString(b); Assert.assertEquals(realResult, "00"); Assert.assertNotEquals(realResult, "41"); Assert.assertEquals(exceptedResult, ByteArray.toHexString(contractAddress)); - } - - /** - * constructor. - */ + /** constructor. */ public byte[] subByte(byte[] b, int off, int length) { byte[] b1 = new byte[length]; System.arraycopy(b, off, b1, 0, length); return b1; - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(grammarAddress, testKeyForGrammarAddress, foundationAddress, - blockingStubFull); } + PublicMethod.freeResource( + grammarAddress, testKeyForGrammarAddress, foundationAddress, blockingStubFull); + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken078.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken078.java index dcb08010..a5f969aa 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken078.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken078.java @@ -14,15 +14,14 @@ import org.tron.api.WalletGrpc; import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.TransactionInfo; -import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; -@Slf4j +import stest.tron.wallet.common.client.utils.Utils; +@Slf4j public class ContractTrcToken078 extends TronBaseTest { byte[] contractAddress = null; @@ -33,9 +32,7 @@ public class ContractTrcToken078 extends TronBaseTest { private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - /** - * constructor. - */ + /** constructor. */ public static String byte2HexStr(byte[] b, int offset, int length) { String stmp = ""; StringBuilder sb = new StringBuilder(""); @@ -46,154 +43,225 @@ public static String byte2HexStr(byte[] b, int offset, int length) { return sb.toString().toUpperCase().trim(); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(testKeyForinternalTxsAddress); logger.info(Long.toString(PublicMethod.queryAccount(foundationKey, blockingStubFull) - .getBalance())); + PublicMethod.printAddress(testKeyForinternalTxsAddress); + logger.info( + Long.toString(PublicMethod.queryAccount(foundationKey, blockingStubFull).getBalance())); } - @Test(enabled = true, description = "Origin test call", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Origin test call", + groups = {"contract", "daily"}) public void testOriginCall001() { - PublicMethod - .sendcoin(internalTxsAddress, 100000000000L, foundationAddress, foundationKey, - blockingStubFull); + PublicMethod.sendcoin( + internalTxsAddress, 100000000000L, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/contractTrcToken078.sol"; - String contractName = "callerContract"; + String filePath = "./src/test/resources/soliditycode/contractTrcToken078.sol"; + String contractName = "callerContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById : " + infoById); contractAddress = infoById.get().getContractAddress().toByteArray(); - String filePath1 = "./src/test/resources/soliditycode/contractTrcToken078.sol"; - String contractName1 = "calledContract"; + String filePath1 = "./src/test/resources/soliditycode/contractTrcToken078.sol"; + String contractName1 = "calledContract"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath1, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); - txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName1, abi1, code1, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById : " + infoById); - byte[] contractAddress1; + byte[] contractAddress1; contractAddress1 = infoById.get().getContractAddress().toByteArray(); - String filePath2 = "./src/test/resources/soliditycode/contractTrcToken078.sol"; - String contractName2 = "c"; + String filePath2 = "./src/test/resources/soliditycode/contractTrcToken078.sol"; + String contractName2 = "c"; HashMap retMap2 = PublicMethod.getBycodeAbi(filePath2, contractName2); - String code2 = retMap2.get("byteCode").toString(); - String abi2 = retMap2.get("abI").toString(); + String code2 = retMap2.get("byteCode").toString(); + String abi2 = retMap2.get("abI").toString(); - txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName2, abi2, code2, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName2, + abi2, + code2, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - byte[] contractAddress2 = infoById.get().getContractAddress().toByteArray(); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); + byte[] contractAddress2 = infoById.get().getContractAddress().toByteArray(); logger.info("infoById : " + infoById); - String initParmes = "\"" + Base58.encode58Check(contractAddress1) - + "\",\"" + Base58.encode58Check(contractAddress2) + "\""; - String txid2 = ""; - txid2 = PublicMethod.triggerContract(contractAddress, - "sendToB2(address,address)", initParmes, false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + String initParmes = + "\"" + + Base58.encode58Check(contractAddress1) + + "\",\"" + + Base58.encode58Check(contractAddress2) + + "\""; + String txid2 = ""; + txid2 = + PublicMethod.triggerContract( + contractAddress, + "sendToB2(address,address)", + initParmes, + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById2 = null; infoById2 = PublicMethod.getTransactionInfoById(txid2, blockingStubFull); logger.info("Trigger InfobyId: " + infoById2); Account info1 = PublicMethod.queryAccount(internalTxsAddress, blockingStubFull); - AccountResourceMessage resourceInfo1 = PublicMethod.getAccountResource(internalTxsAddress, - blockingStubFull); + AccountResourceMessage resourceInfo1 = + PublicMethod.getAccountResource(internalTxsAddress, blockingStubFull); logger.info("getEnergyUsed " + resourceInfo1.getEnergyUsed()); logger.info("getEnergyLimit " + resourceInfo1.getEnergyLimit()); Assert.assertTrue(infoById2.get().getResultValue() == 0); - - } - @Test(enabled = true, description = "Origin test delegatecall", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Origin test delegatecall", + groups = {"contract", "daily"}) public void testOriginDelegatecall001() { - PublicMethod - .sendcoin(internalTxsAddress, 100000000000L, foundationAddress, foundationKey, - blockingStubFull); + PublicMethod.sendcoin( + internalTxsAddress, 100000000000L, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/contractTrcToken078.sol"; - String contractName = "callerContract"; + String filePath = "./src/test/resources/soliditycode/contractTrcToken078.sol"; + String contractName = "callerContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById : " + infoById); contractAddress = infoById.get().getContractAddress().toByteArray(); - String filePath1 = "./src/test/resources/soliditycode/contractTrcToken078.sol"; - String contractName1 = "calledContract"; + String filePath1 = "./src/test/resources/soliditycode/contractTrcToken078.sol"; + String contractName1 = "calledContract"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath1, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName1, abi1, code1, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById : " + infoById); - byte[] contractAddress1; + byte[] contractAddress1; contractAddress1 = infoById.get().getContractAddress().toByteArray(); - String filePath2 = "./src/test/resources/soliditycode/contractTrcToken078.sol"; - String contractName2 = "c"; + String filePath2 = "./src/test/resources/soliditycode/contractTrcToken078.sol"; + String contractName2 = "c"; HashMap retMap2 = PublicMethod.getBycodeAbi(filePath2, contractName2); - String code2 = retMap2.get("byteCode").toString(); - String abi2 = retMap2.get("abI").toString(); - txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName2, abi2, code2, "", maxFeeLimit, - 1000000L, 100, null, testKeyForinternalTxsAddress, - internalTxsAddress, blockingStubFull); + String code2 = retMap2.get("byteCode").toString(); + String abi2 = retMap2.get("abI").toString(); + txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName2, + abi2, + code2, + "", + maxFeeLimit, + 1000000L, + 100, + null, + testKeyForinternalTxsAddress, + internalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById : " + infoById); - byte[] contractAddress2 = infoById.get().getContractAddress().toByteArray(); - String initParmes = "\"" + Base58.encode58Check(contractAddress1) - + "\",\"" + Base58.encode58Check(contractAddress2) + "\""; - String txid2 = ""; - txid2 = PublicMethod.triggerContract(contractAddress, - "sendToB(address,address)", initParmes, false, - 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); + byte[] contractAddress2 = infoById.get().getContractAddress().toByteArray(); + String initParmes = + "\"" + + Base58.encode58Check(contractAddress1) + + "\",\"" + + Base58.encode58Check(contractAddress2) + + "\""; + String txid2 = ""; + txid2 = + PublicMethod.triggerContract( + contractAddress, + "sendToB(address,address)", + initParmes, + false, + 0, + maxFeeLimit, + internalTxsAddress, + testKeyForinternalTxsAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById2 = null; infoById2 = PublicMethod.getTransactionInfoById(txid2, blockingStubFull); logger.info("infoById : " + infoById2); Assert.assertTrue(infoById2.get().getResultValue() == 0); - - } private List getStrings(byte[] data) { @@ -206,23 +274,17 @@ private List getStrings(byte[] data) { return ret; } - /** - * constructor. - */ + /** constructor. */ public byte[] subByte(byte[] b, int off, int length) { byte[] b1 = new byte[length]; System.arraycopy(b, off, b1, 0, length); return b1; - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(internalTxsAddress, testKeyForinternalTxsAddress, foundationAddress, - blockingStubFull); } + PublicMethod.freeResource( + internalTxsAddress, testKeyForinternalTxsAddress, foundationAddress, blockingStubFull); + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken079.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken079.java index 22737a68..030f7f48 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken079.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken079.java @@ -15,8 +15,9 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j public class ContractTrcToken079 extends TronBaseTest { @@ -25,10 +26,10 @@ public class ContractTrcToken079 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; private byte[] transferTokenContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -36,120 +37,179 @@ public class ContractTrcToken079 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = true, description = "Trigger transferToken with 0 tokenValue and tokenId", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger transferToken with 0 tokenValue and tokenId", + groups = {"contract", "daily"}) public void triggerTransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 1100_000_000L, fromAddress, - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 1000_000_000L, fromAddress, - foundationKey, blockingStubFull)); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 70000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), -// 0, 0, ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1100_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 1000_000_000L, fromAddress, foundationKey, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 70000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + + // PublicMethod.randomFreezeAmount.getAndAdd(1), + // 0, 0, ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, 100000L, - 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); logger.info("The token name: " + tokenName); logger.info("The token ID: " + assetAccountId.toStringUtf8()); - Long devAssetCountBefore = PublicMethod.getAssetIssueValue(dev001Address, - assetAccountId, blockingStubFull); - - logger.info("before AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountBefore: " - + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken079.sol"; - String contractName = "tokenTest"; + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken079.sol"; + String contractName = "tokenTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String tokenId = assetAccountId.toStringUtf8(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String tokenId = assetAccountId.toStringUtf8(); long tokenValue = 200; long callValue = 0; - String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, callValue, 0, 10000, - tokenId, tokenValue, null, dev001Key, - dev001Address, blockingStubFull); + String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callValue, + 0, + 10000, + tokenId, + tokenValue, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (transferTokenTxid == null || infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); } transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(transferTokenContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(transferTokenContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - Long devAssetCountAfter = PublicMethod.getAssetIssueValue(dev001Address, - assetAccountId, blockingStubFull); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountAfter: " - + devAssetCountAfter); - Long contractAssetCount = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + Long contractAssetCount = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); Assert.assertEquals(Long.valueOf(200), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(200), contractAssetCount); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(user001Address), foundationKey, blockingStubFull)); - - Assert.assertTrue(PublicMethod.transferAsset(user001Address, - assetAccountId.toByteArray(), 10L, dev001Address, dev001Key, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(user001Address), foundationKey, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.transferAsset( + user001Address, + assetAccountId.toByteArray(), + 10L, + dev001Address, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long transferAssetBefore = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("before trigger, transferTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + transferAssetBefore); - - PublicMethod - .sendcoin(transferTokenContractAddress, 5000000, fromAddress, foundationKey, blockingStubFull); + Long transferAssetBefore = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "before trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + transferAssetBefore); + + PublicMethod.sendcoin( + transferTokenContractAddress, 5000000, fromAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); tokenId = Long.toString(0); tokenValue = 0; callValue = 5; - String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "msgTokenValueAndTokenIdTest()", "#", false, callValue, - 1000000000L, tokenId, tokenValue, user001Address, user001Key, - blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "msgTokenValueAndTokenIdTest()", + "#", + false, + callValue, + 1000000000L, + tokenId, + tokenValue, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); if (triggerTxid == null || infoById.get().getResultValue() != 0) { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - List retList = PublicMethod.getStrings(infoById.get() - .getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(infoById.get().getContractResult(0).toByteArray()); logger.info("the value: " + retList); - Long msgId = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); - Long msgTokenValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); - Long msgCallValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(2))); + Long msgId = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + Long msgTokenValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + Long msgCallValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(2))); logger.info("msgId: " + msgId); logger.info("msgTokenValue: " + msgTokenValue); @@ -158,19 +218,15 @@ public void triggerTransferTokenContract() { Assert.assertEquals(msgId.toString(), tokenId); Assert.assertEquals(Long.valueOf(msgTokenValue), Long.valueOf(tokenValue)); Assert.assertEquals(Long.valueOf(msgCallValue), Long.valueOf(callValue)); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, foundationKey, 0, dev001Address, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, foundationKey, 1, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, foundationKey, 1, user001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, foundationKey, 1, user001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken080.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken080.java index e8898c46..11e37565 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken080.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken080.java @@ -13,10 +13,11 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j public class ContractTrcToken080 extends TronBaseTest { @@ -25,111 +26,164 @@ public class ContractTrcToken080 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; private byte[] transferTokenContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); } - @Test(enabled = true, description = "DeployContract with 0 tokenValue and tokenId", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "DeployContract with 0 tokenValue and tokenId", + groups = {"contract", "daily"}) public void deployTransferTokenContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 2100_000_000L, fromAddress, - foundationKey, blockingStubFull)); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 130000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); -// -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), -// 0, 0, ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 2100_000_000L, fromAddress, foundationKey, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 130000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); + // + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + + // PublicMethod.randomFreezeAmount.getAndAdd(1), + // 0, 0, ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(dev001Address, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, 100000L, - 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); logger.info("The token name: " + tokenName); logger.info("The token ID: " + assetAccountId.toStringUtf8()); - Long devAssetCountBefore = PublicMethod.getAssetIssueValue(dev001Address, - assetAccountId, blockingStubFull); - - logger.info("before AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountBefore: " - + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken080.sol"; - String contractName = "tokenTest"; + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken080.sol"; + String contractName = "tokenTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String tokenId = assetAccountId.toStringUtf8(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String tokenId = assetAccountId.toStringUtf8(); long tokenValue = 100; long callValue = 10; - String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callValue, 0, 10000, tokenId, tokenValue, - null, dev001Key, dev001Address, blockingStubFull); + String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callValue, + 0, + 10000, + tokenId, + tokenValue, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (transferTokenTxid == null || infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); } transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(transferTokenContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(transferTokenContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - Long devAssetCountAfter = PublicMethod.getAssetIssueValue(dev001Address, - assetAccountId, blockingStubFull); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountAfter: " - + devAssetCountAfter); - Long contractAssetCount = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); - - Assert.assertEquals(Long.valueOf(tokenValue), - Long.valueOf(devAssetCountBefore - devAssetCountAfter)); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + Long contractAssetCount = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); + + Assert.assertEquals( + Long.valueOf(tokenValue), Long.valueOf(devAssetCountBefore - devAssetCountAfter)); Assert.assertEquals(Long.valueOf(tokenValue), contractAssetCount); - // get and verify the msg.value and msg.id - Long transferAssetBefore = PublicMethod.getAssetIssueValue(transferTokenContractAddress, - assetAccountId, blockingStubFull); - logger.info("before trigger, transferTokenContractAddress has AssetId " - + assetAccountId.toStringUtf8() + ", Count is " + transferAssetBefore); - String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "getResultInCon()", "#", false, 0, - 1000000000L, "0", 0, dev001Address, dev001Key, - blockingStubFull); + // get and verify the msg.value and msg.id + Long transferAssetBefore = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "before trigger, transferTokenContractAddress has AssetId " + + assetAccountId.toStringUtf8() + + ", Count is " + + transferAssetBefore); + String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "getResultInCon()", + "#", + false, + 0, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - List retList = PublicMethod.getStrings(infoById.get() - .getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(infoById.get().getContractResult(0).toByteArray()); logger.info("The msg value: " + retList); - Long msgId = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); - Long msgTokenValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); - Long msgCallValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(2))); + Long msgId = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + Long msgTokenValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + Long msgCallValue = ByteArray.toLong(ByteArray.fromHexString(retList.get(2))); logger.info("msgId: " + msgId); logger.info("msgTokenValue: " + msgTokenValue); @@ -138,17 +192,13 @@ public void deployTransferTokenContract() { Assert.assertEquals(msgId.toString(), tokenId); Assert.assertEquals(Long.valueOf(msgTokenValue), Long.valueOf(tokenValue)); Assert.assertEquals(Long.valueOf(msgCallValue), Long.valueOf(callValue)); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, foundationKey, 0, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, foundationKey, 1, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, foundationKey, 1, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken081.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken081.java index 560b11be..f18a2b94 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken081.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken081.java @@ -13,10 +13,10 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class ContractTrcToken081 extends TronBaseTest { @@ -27,38 +27,55 @@ public class ContractTrcToken081 extends TronBaseTest { private static ByteString assetAccountId = null; private byte[] tokenReceiver = null; private byte[] tokenSender = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); - Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 3100_000_000L, fromAddress, foundationKey, blockingStubFull)); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 3100_000_000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 130000L, blockingStubFull), 0, -// 1, ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); -// -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), 0, 0, -// ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); -// -// PublicMethod.waitProduceNextBlock(blockingStubFull); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 130000L, + // blockingStubFull), 0, + // 1, ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); + // + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + + // PublicMethod.randomFreezeAmount.getAndAdd(1), 0, 0, + // ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); + // + // PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod - .createAssetIssue(dev001Address, tokenName, TotalSupply, 1, 10000, start, end, 1, - description, url, 100000L, 100000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -66,136 +83,210 @@ public class ContractTrcToken081 extends TronBaseTest { logger.info("The token name: " + tokenName); logger.info("The token ID: " + assetAccountId.toStringUtf8()); - Long devAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountBefore: " - + devAssetCountBefore); - String filePath = "./src/test/resources/soliditycode/contractTrcToken081.sol"; - String contractName = "TokenReceiver"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "./src/test/resources/soliditycode/contractTrcToken081.sol"; + String contractName = "TokenReceiver"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String tokenId = assetAccountId.toStringUtf8(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String tokenId = assetAccountId.toStringUtf8(); - tokenReceiver = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 500000000L, 100, null, dev001Key, dev001Address, blockingStubFull); + tokenReceiver = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 500000000L, + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethod - .getContract(tokenReceiver, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(tokenReceiver, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - contractName = "TokenSender"; retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - tokenSender = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 500000000L, 100, 10000L, assetAccountId.toStringUtf8(), - 10L, null, dev001Key, dev001Address, blockingStubFull); + tokenSender = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 500000000L, + 100, + 10000L, + assetAccountId.toStringUtf8(), + 10L, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - smartContract = PublicMethod.getContract(tokenSender, - blockingStubFull); + smartContract = PublicMethod.getContract(tokenSender, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - Long contractAssetCount = PublicMethod - .getAssetIssueValue(tokenSender, assetAccountId, blockingStubFull); - logger.info("tokenSender has AssetId before: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); - Long devAssetCountAfterDeploy = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - logger.info("after deploy tokenSender AssetId: " + assetAccountId.toStringUtf8() - + ", devAssetCountAfter: " + devAssetCountAfterDeploy); + Long contractAssetCount = + PublicMethod.getAssetIssueValue(tokenSender, assetAccountId, blockingStubFull); + logger.info( + "tokenSender has AssetId before: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); + Long devAssetCountAfterDeploy = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + logger.info( + "after deploy tokenSender AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfterDeploy); Assert.assertTrue(10 == devAssetCountBefore - devAssetCountAfterDeploy); Assert.assertTrue(10 == contractAssetCount); - } - - @Test(enabled = true, description = "transfer 1 trc10 to contract by assembly", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "transfer 1 trc10 to contract by assembly", + groups = {"contract", "daily"}) public void transferTokenToContract() { - Long senderAssetCountBefore = PublicMethod - .getAssetIssueValue(tokenSender, assetAccountId, blockingStubFull); - logger.info("before trigger tokenSender has AssetId before: " + assetAccountId.toStringUtf8() - + ", Count: " + senderAssetCountBefore); - Long receiverAssetCountBefore = PublicMethod - .getAssetIssueValue(tokenReceiver, assetAccountId, blockingStubFull); - logger.info("before trigger tokenReceiver AssetId: " + assetAccountId.toStringUtf8() - + ", Count: " + receiverAssetCountBefore); - String args = "\"" + Base58.encode58Check(tokenReceiver) + "\""; + Long senderAssetCountBefore = + PublicMethod.getAssetIssueValue(tokenSender, assetAccountId, blockingStubFull); + logger.info( + "before trigger tokenSender has AssetId before: " + + assetAccountId.toStringUtf8() + + ", Count: " + + senderAssetCountBefore); + Long receiverAssetCountBefore = + PublicMethod.getAssetIssueValue(tokenReceiver, assetAccountId, blockingStubFull); + logger.info( + "before trigger tokenReceiver AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + receiverAssetCountBefore); + String args = "\"" + Base58.encode58Check(tokenReceiver) + "\""; logger.info("args: " + args); - String triggerTxid = PublicMethod - .triggerContract(tokenSender, "sendTRC10(address)", args, false, 0, 1000000000L, - assetAccountId.toStringUtf8(), 0, dev001Address, dev001Key, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + tokenSender, + "sendTRC10(address)", + args, + false, + 0, + 1000000000L, + assetAccountId.toStringUtf8(), + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = + Optional infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - Long senderAssetCountAfter = PublicMethod - .getAssetIssueValue(tokenSender, assetAccountId, blockingStubFull); - logger.info("tokenSender has AssetId After trigger: " + assetAccountId.toStringUtf8() - + ", Count: " + senderAssetCountAfter); - Long receiverAssetCountAfterTrigger = PublicMethod - .getAssetIssueValue(tokenReceiver, assetAccountId, blockingStubFull); - logger.info("after trigger AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + receiverAssetCountAfterTrigger); + Long senderAssetCountAfter = + PublicMethod.getAssetIssueValue(tokenSender, assetAccountId, blockingStubFull); + logger.info( + "tokenSender has AssetId After trigger: " + + assetAccountId.toStringUtf8() + + ", Count: " + + senderAssetCountAfter); + Long receiverAssetCountAfterTrigger = + PublicMethod.getAssetIssueValue(tokenReceiver, assetAccountId, blockingStubFull); + logger.info( + "after trigger AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + receiverAssetCountAfterTrigger); Assert.assertTrue(1 == senderAssetCountBefore - senderAssetCountAfter); Assert.assertTrue(1 == receiverAssetCountAfterTrigger - receiverAssetCountBefore); - } - @Test(enabled = true, description = "transfer 1 trc10 to normal address by assembly", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "transfer 1 trc10 to normal address by assembly", + groups = {"contract", "daily"}) public void transferTokenToNormalAddress() { - long senderAssetCountBefore = PublicMethod - .getAssetIssueValue(tokenSender, assetAccountId, blockingStubFull); - logger.info("tokenSender has AssetId After trigger: " + assetAccountId.toStringUtf8() - + ", Count: " + senderAssetCountBefore); - - long devAssetCountBeforeTrigger = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - logger.info("after trigger AssetId: " + assetAccountId.toStringUtf8() - + ", devAssetCountAfterTrigger: " + devAssetCountBeforeTrigger); - String args = "\"" + Base58.encode58Check(dev001Address) + "\""; + long senderAssetCountBefore = + PublicMethod.getAssetIssueValue(tokenSender, assetAccountId, blockingStubFull); + logger.info( + "tokenSender has AssetId After trigger: " + + assetAccountId.toStringUtf8() + + ", Count: " + + senderAssetCountBefore); + + long devAssetCountBeforeTrigger = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + logger.info( + "after trigger AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfterTrigger: " + + devAssetCountBeforeTrigger); + String args = "\"" + Base58.encode58Check(dev001Address) + "\""; logger.info("args: " + args); - String triggerTxid = PublicMethod - .triggerContract(tokenSender, "sendTRC10(address)", args, false, 0, 1000000000L, - assetAccountId.toStringUtf8(), 0, dev001Address, dev001Key, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + tokenSender, + "sendTRC10(address)", + args, + false, + 0, + 1000000000L, + assetAccountId.toStringUtf8(), + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = + Optional infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - long senderAssetCountAfter = PublicMethod - .getAssetIssueValue(tokenSender, assetAccountId, blockingStubFull); - logger.info("tokenSender has AssetId After trigger: " + assetAccountId.toStringUtf8() - + ", Count: " + senderAssetCountAfter); - - long devAssetCountAfterTrigger = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); - logger.info("after trigger AssetId: " + assetAccountId.toStringUtf8() - + ", devAssetCountAfterTrigger: " + devAssetCountAfterTrigger); + long senderAssetCountAfter = + PublicMethod.getAssetIssueValue(tokenSender, assetAccountId, blockingStubFull); + logger.info( + "tokenSender has AssetId After trigger: " + + assetAccountId.toStringUtf8() + + ", Count: " + + senderAssetCountAfter); + + long devAssetCountAfterTrigger = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + logger.info( + "after trigger AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfterTrigger: " + + devAssetCountAfterTrigger); Assert.assertTrue(1 == senderAssetCountBefore - senderAssetCountAfter); Assert.assertTrue(1 == devAssetCountAfterTrigger - devAssetCountBeforeTrigger); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, foundationKey, 1, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, foundationKey, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, foundationKey, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken082.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken082.java index 917e02b9..dcedaf1e 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken082.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken082.java @@ -12,9 +12,13 @@ import org.tron.protos.Protocol.TransactionInfo; import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.Retry; import stest.tron.wallet.common.client.utils.TronBaseTest; - +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class ContractTrcToken082 extends TronBaseTest { @@ -24,10 +28,10 @@ public class ContractTrcToken082 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -39,121 +43,215 @@ public class ContractTrcToken082 extends TronBaseTest { byte[] create2Address; String create2Str; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); } - @Test(enabled = true, description = "deploy contract and generate create2 address", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "deploy contract and generate create2 address", + groups = {"contract", "daily"}) public void test01DeployContract() { - Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 300100_000_000L, - fromAddress, testKey002, blockingStubFull)); -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 130000L, blockingStubFull), 0, -// 1, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 100000_000_000L, 0, 0, -// ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 300100_000_000L, fromAddress, testKey002, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 130000L, + // blockingStubFull), 0, + // 1, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 100000_000_000L, 0, + // 0, + // ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod - .createAssetIssue(dev001Address, tokenName, TotalSupply, 1, 1000, start, end, 1, - description, url, 100000L, 100000L, 3L, 30L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 1000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 3L, + 30L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); logger.info("The token name: " + tokenName); logger.info("The token ID: " + assetAccountId.toStringUtf8()); - String filePath = "src/test/resources/soliditycode/contractTrcToken082.sol"; - String contractName = "D"; + String filePath = "src/test/resources/soliditycode/contractTrcToken082.sol"; + String contractName = "D"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String tokenId = assetAccountId.toStringUtf8(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String tokenId = assetAccountId.toStringUtf8(); long tokenValue = 350; long callValue = 5; - String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callValue, 0, 10000, tokenId, tokenValue, null, dev001Key, dev001Address, + String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callValue, + 0, + 10000, + tokenId, + tokenValue, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (transferTokenTxid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } contractD = infoById.get().getContractAddress().toByteArray(); SmartContract smartContract = PublicMethod.getContract(contractD, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - Long contractAssetCount = PublicMethod - .getAssetIssueValue(contractD, assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); + Long contractAssetCount = + PublicMethod.getAssetIssueValue(contractD, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); Assert.assertEquals(Long.valueOf(tokenValue), contractAssetCount); - String methedStr = "deploy(uint256)"; - String argsStr = "7"; - String txid = PublicMethod.triggerContract(contractD, methedStr, argsStr, - false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methedStr = "deploy(uint256)"; + String argsStr = "7"; + String txid = + PublicMethod.triggerContract( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, - info.get().getReceipt().getResult()); - String create2Str = - "41" + ByteArray.toHexString(info.get().getContractResult(0).toByteArray()) - .substring(24); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.get().getReceipt().getResult()); + String create2Str = + "41" + ByteArray.toHexString(info.get().getContractResult(0).toByteArray()).substring(24); logger.info("hex create2 address: " + create2Str); create2Address = ByteArray.fromHexString(create2Str); create2Str = Base58.encode58Check(create2Address); logger.info("create2Address: " + create2Str); - String toCreate2Num = "1"; - String param = "\"" + create2Str + "\",\"" + assetAccountId.toStringUtf8() - + "\",\"" + toCreate2Num + "\""; - String txid1 = PublicMethod.triggerContract(contractD, - "TransferTokenTo(address,trcToken,uint256)", - param, false, 0, 100000000L, "0", - 0, dev001Address, dev001Key, blockingStubFull); + String toCreate2Num = "1"; + String param = + "\"" + create2Str + "\",\"" + assetAccountId.toStringUtf8() + "\",\"" + toCreate2Num + "\""; + String txid1 = + PublicMethod.triggerContract( + contractD, + "TransferTokenTo(address,trcToken,uint256)", + param, + false, + 0, + 100000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, info.get().getResultValue()); - Long create2Count = PublicMethod - .getAssetIssueValue(create2Address, assetAccountId, blockingStubFull); + Long create2Count = + PublicMethod.getAssetIssueValue(create2Address, assetAccountId, blockingStubFull); Assert.assertEquals(Long.valueOf(toCreate2Num), create2Count); } - @Test(enabled = true, description = "kill,create2,kill,and check trc10 amount" + - "when No.94 committee is been opened,after contracts been killed, " + - "cannot create the contract again, the transaction will be rejected as a result",retryAnalyzer = Retry.class, groups = {"contract", "daily"}) - public void test02KillCreate2Kill() throws Exception{ - PublicMethod.triggerContract(contractD, "deploy(uint256)", "7", - false, 0, maxFeeLimit, fromAddress, testKey002, blockingStubFull); + @Test( + enabled = true, + description = + "kill,create2,kill,and check trc10 amount" + + "when No.94 committee is been opened,after contracts been killed, " + + "cannot create the contract again, the transaction will be rejected as a result", + retryAnalyzer = Retry.class, + groups = {"contract", "daily"}) + public void test02KillCreate2Kill() throws Exception { + PublicMethod.triggerContract( + contractD, + "deploy(uint256)", + "7", + false, + 0, + maxFeeLimit, + fromAddress, + testKey002, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String param1 = "\"" + receiveStr + "\""; - String txid1 = PublicMethod.triggerContract(create2Address, - "kill(address)", - param1, false, 0, 100000000L, "0", - 0, fromAddress, testKey002, blockingStubFull); + String param1 = "\"" + receiveStr + "\""; + String txid1 = + PublicMethod.triggerContract( + create2Address, + "kill(address)", + param1, + false, + 0, + 100000000L, + "0", + 0, + fromAddress, + testKey002, + blockingStubFull); Thread.sleep(30); - String methedStr = "deploy(uint256)"; - String argsStr = "7"; - String txid2 = PublicMethod.triggerContract(contractD, methedStr, argsStr, - false, 0, maxFeeLimit, fromAddress, testKey002, blockingStubFull); - logger.info("test02KillCreate2Kill create2Address: " + PublicMethod.getContract(create2Address,blockingStubFull).toString()); + String methedStr = "deploy(uint256)"; + String argsStr = "7"; + String txid2 = + PublicMethod.triggerContract( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + fromAddress, + testKey002, + blockingStubFull); + logger.info( + "test02KillCreate2Kill create2Address: " + + PublicMethod.getContract(create2Address, blockingStubFull).toString()); Thread.sleep(30); - String txid3 = PublicMethod.triggerContract(create2Address, - "kill(address)", - param1, false, 0, 100000000L, "0", - 0, fromAddress, testKey002, blockingStubFull); + String txid3 = + PublicMethod.triggerContract( + create2Address, + "kill(address)", + param1, + false, + 0, + 100000000L, + "0", + 0, + fromAddress, + testKey002, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); @@ -162,7 +260,7 @@ public void test02KillCreate2Kill() throws Exception{ Optional info2 = PublicMethod.getTransactionInfoById(txid2, blockingStubFull); Assert.assertEquals(TransactionInfo.code.SUCESS, info2.get().getResult()); - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { Assert.assertTrue(info2.get().getInternalTransactions(0).getRejected()); } Optional info3 = @@ -170,30 +268,25 @@ public void test02KillCreate2Kill() throws Exception{ Assert.assertEquals(TransactionInfo.code.SUCESS, info3.get().getResult()); Protocol.Account create2Account = PublicMethod.queryAccount(create2Address, blockingStubFull); - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { Assert.assertNotEquals(create2Account.toString(), ""); Assert.assertEquals(0L, create2Account.getBalance()); Assert.assertEquals(0L, create2Account.getFrozenV2(0).getAmount()); Assert.assertEquals(0L, create2Account.getFrozenV2(1).getAmount()); Assert.assertEquals(0L, create2Account.getFrozenV2(2).getAmount()); - }else { + } else { Assert.assertEquals(create2Account.toString(), ""); } - Long create2AssetCount = PublicMethod - .getAssetIssueValue(receiveAdderss, assetAccountId, blockingStubFull); + Long create2AssetCount = + PublicMethod.getAssetIssueValue(receiveAdderss, assetAccountId, blockingStubFull); Assert.assertEquals(create2AssetCount, Long.valueOf("1")); Assert.assertEquals(info1.get().getBlockNumber(), info2.get().getBlockNumber()); Assert.assertEquals(info2.get().getBlockNumber(), info3.get().getBlockNumber()); - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); } + PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/addressStrictCheck/AddressStrictCheck001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/addressStrictCheck/AddressStrictCheck001.java index 9de745a9..703c0060 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/addressStrictCheck/AddressStrictCheck001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/addressStrictCheck/AddressStrictCheck001.java @@ -16,17 +16,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class AddressStrictCheck001 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -34,88 +34,130 @@ public class AddressStrictCheck001 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } - - @Test(enabled = true, description = "Open experimental check address ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Open experimental check address ", + groups = {"contract", "daily"}) public void test01CheckAddressNew() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/addressCheckNew.sol"; - String contractName = "testIsContract"; + String filePath = "src/test/resources/soliditycode/addressCheckNew.sol"; + String contractName = "testIsContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = ""; - String num = "00000000000000000000004108362A6DB594586C035758ECA382A49FDF13EF61"; - txid = PublicMethod.triggerContract(contractAddress, - "checkAddress(address)", num, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "00000000000000000000004108362A6DB594586C035758ECA382A49FDF13EF61"; + txid = + PublicMethod.triggerContract( + contractAddress, + "checkAddress(address)", + num, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "checkAddress2(address)", num, true, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "checkAddress2(address)", + num, + true, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); num = "10000000000000000000004108362A6DB594586C035758ECA382A49FDF13EF61"; - txid = PublicMethod.triggerContract(contractAddress, - "checkAddress(address)", num, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "checkAddress(address)", + num, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(1, infoById.get().getResultValue()); Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); - transactionExtention = PublicMethod.triggerConstantContractForExtention(contractAddress, - "checkAddress2(address)", num, true, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "checkAddress2(address)", + num, + true, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("AAAAA:" + transactionExtention.toString()); - Assert.assertEquals("FAILED", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("REVERT opcode executed", - transactionExtention.getResult().getMessage().toStringUtf8()); + Assert.assertEquals( + "FAILED", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "REVERT opcode executed", transactionExtention.getResult().getMessage().toStringUtf8()); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(contractExcKey, blockingStubFull).getBalance(); - PublicMethod.sendcoin(testNetAccountAddress, balance, contractExcAddress, contractExcKey, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.sendcoin( + testNetAccountAddress, balance, contractExcAddress, contractExcKey, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - - } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/addressStrictCheck/AddressStrictCheck002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/addressStrictCheck/AddressStrictCheck002.java index 329b3e18..80a1d62b 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/addressStrictCheck/AddressStrictCheck002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/addressStrictCheck/AddressStrictCheck002.java @@ -16,17 +16,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class AddressStrictCheck002 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -34,86 +34,127 @@ public class AddressStrictCheck002 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } - - @Test(enabled = true, description = "Close experimental check address", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Close experimental check address", + groups = {"contract", "daily"}) public void test01AddressOld() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/addressCheckOld.sol"; - String contractName = "testIsContract"; + String filePath = "src/test/resources/soliditycode/addressCheckOld.sol"; + String contractName = "testIsContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = ""; - String num = "00000000000000000000004108362A6DB594586C035758ECA382A49FDF13EF61"; - txid = PublicMethod.triggerContract(contractAddress, - "checkAddress(address)", num, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "00000000000000000000004108362A6DB594586C035758ECA382A49FDF13EF61"; + txid = + PublicMethod.triggerContract( + contractAddress, + "checkAddress(address)", + num, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); logger.info(infoById.toString()); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "checkAddress2(address)", num, true, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "checkAddress2(address)", + num, + true, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); num = "10000000000000000000004108362A6DB594586C035758ECA382A49FDF13EF61"; - txid = PublicMethod.triggerContract(contractAddress, - "checkAddress(address)", num, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "checkAddress(address)", + num, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(1, infoById.get().getResultValue()); logger.info(infoById.toString()); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "checkAddress2(address)", num, true, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "checkAddress2(address)", + num, + true, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert.assertEquals("REVERT opcode executed", - transactionExtention.getResult().getMessage().toStringUtf8()); + Assert.assertEquals( + "REVERT opcode executed", transactionExtention.getResult().getMessage().toStringUtf8()); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(contractExcKey, blockingStubFull).getBalance(); - PublicMethod.sendcoin(testNetAccountAddress, balance, contractExcAddress, contractExcKey, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.sendcoin( + testNetAccountAddress, balance, contractExcAddress, contractExcKey, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - - } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract001.java index b728e51e..5a86bf9e 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract001.java @@ -20,16 +20,17 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.Hash; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class batchValidateSignContract001 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -38,48 +39,74 @@ public class batchValidateSignContract001 extends TronBaseTest { String txid = ""; private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - txid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 1000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); + txid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/batchvalidatesign001.sol"; - String contractName = "Demo"; + String filePath = "src/test/resources/soliditycode/batchvalidatesign001.sol"; + String contractName = "Demo"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Correct 16 signatures test pure multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Correct 16 signatures test pure multivalidatesign", + groups = {"contract", "daily"}) public void test01Correct16signatures() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { @@ -88,85 +115,124 @@ public void test01Correct16signatures() { + ": CPU timeout for 'ISZERO' operation executing", transactionExtention.getResult().getMessage().toStringUtf8()); } else { - Assert.assertEquals("11111111111111110000000000000000", + Assert.assertEquals( + "11111111111111110000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "14 signatures with 1st incorrect signatures test" - + " pure multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "14 signatures with 1st incorrect signatures test" + " pure multivalidatesign", + groups = {"contract", "daily"}) public void test02Incorrect1stSignatures() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 14; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } byte[] sign = new ECKey().sign(Hash.sha3("sdifhsdfihyw888w7".getBytes())).toByteArray(); signatures.set(0, Hex.toHexString(sign)); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("01111111111111000000000000000000", + Assert.assertEquals( + "01111111111111000000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "13 signatures with 1st incorrect address test" - + " pure multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "13 signatures with 1st incorrect address test" + " pure multivalidatesign", + groups = {"contract", "daily"}) public void test03Incorrect1stAddress() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 13; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } addresses.set(0, WalletClient.encode58Check(new ECKey().getAddress())); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("01111111111110000000000000000000", + Assert.assertEquals( + "01111111111110000000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "16 signatures with 15th incorrect signatures" - + " test pure multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "16 signatures with 15th incorrect signatures" + " test pure multivalidatesign", + groups = {"contract", "daily"}) public void test04Incorrect15thSignatures() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); if (i == 14) { signatures.add( Hex.toHexString(key.sign("dgjjsldgjljvjjfdshkh123770807779".getBytes()).toByteArray())); @@ -176,32 +242,51 @@ public void test04Incorrect15thSignatures() { addresses.add(WalletClient.encode58Check(key.getAddress())); } List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("11111111111111010000000000000000", + Assert.assertEquals( + "11111111111111010000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "15 signatures with 10th-15th incorrect address" - + " test pure multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "15 signatures with 10th-15th incorrect address" + " test pure multivalidatesign", + groups = {"contract", "daily"}) public void test05Incorrect15thTo30thAddress() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 15; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } @@ -209,32 +294,51 @@ public void test05Incorrect15thTo30thAddress() { addresses.set(i, WalletClient.encode58Check(new ECKey().getAddress())); } List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("11111111100000100000000000000000", + Assert.assertEquals( + "11111111100000100000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "16 signatures with 2nd/16th incorrect signatures" - + " test pure multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "16 signatures with 2nd/16th incorrect signatures" + " test pure multivalidatesign", + groups = {"contract", "daily"}) public void test06Incorrect2ndAnd32ndIncorrectSignatures() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); if (i == 1 || i == 15) { signatures.add( Hex.toHexString(key.sign("dgjjsldgjljvjjfdshkh1hgsk0807779".getBytes()).toByteArray())); @@ -244,32 +348,51 @@ public void test06Incorrect2ndAnd32ndIncorrectSignatures() { addresses.add(WalletClient.encode58Check(key.getAddress())); } List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("10111111111111100000000000000000", + Assert.assertEquals( + "10111111111111100000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "16 signatures with 6th/9th/11th/13nd incorrect address" - + " test pure multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "16 signatures with 6th/9th/11th/13nd incorrect address" + " test pure multivalidatesign", + groups = {"contract", "daily"}) public void test07IncorrectAddress() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } @@ -278,69 +401,111 @@ public void test07IncorrectAddress() { addresses.set(10, WalletClient.encode58Check(new ECKey().getAddress())); addresses.set(12, WalletClient.encode58Check(new ECKey().getAddress())); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("11111011010101110000000000000000", + Assert.assertEquals( + "11111011010101110000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "16 signatures with Incorrect hash" - + " test pure multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "16 signatures with Incorrect hash" + " test pure multivalidatesign", + groups = {"contract", "daily"}) public void test08IncorrectHash() { - String txid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 1000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); - String incorrecttxid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 1000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); + String txid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); + String incorrecttxid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } - List parameters = Arrays - .asList("0x" + Hex.toHexString(Hash.sha3(incorrecttxid.getBytes())), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + List parameters = + Arrays.asList( + "0x" + Hex.toHexString(Hash.sha3(incorrecttxid.getBytes())), signatures, addresses); + String input = PublicMethod.parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(contractExcKey, blockingStubFull).getBalance(); - PublicMethod.sendcoin(testNetAccountAddress, balance, contractExcAddress, contractExcKey, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.sendcoin( + testNetAccountAddress, balance, contractExcAddress, contractExcKey, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract002.java index 67ae29c7..e3c4efca 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract002.java @@ -23,16 +23,16 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.Hash; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class batchValidateSignContract002 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -41,40 +41,56 @@ public class batchValidateSignContract002 extends TronBaseTest { String txid = ""; private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - txid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 1000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); + txid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/batchvalidatesign001.sol"; - String contractName = "Demo"; + String filePath = "src/test/resources/soliditycode/batchvalidatesign001.sol"; + String contractName = "Demo"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Correct 16 signatures test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Correct 16 signatures test multivalidatesign", + groups = {"contract", "daily"}) public void test01Correct16signatures() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -82,36 +98,46 @@ public void test01Correct16signatures() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, + String input = PublicMethod.parametersString(parameters); + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("11111111111111110000000000000000", + Assert.assertEquals( + "11111111111111110000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); PublicMethod.waitProduceNextBlock(blockingStubFull); } Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -119,12 +145,12 @@ public void test01Correct16signatures() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -135,16 +161,18 @@ public void test01Correct16signatures() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "14 signatures with 1st incorrect signatures" - + " test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "14 signatures with 1st incorrect signatures" + " test multivalidatesign", + groups = {"contract", "daily"}) public void test02Incorrect1stSignatures() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -152,38 +180,48 @@ public void test02Incorrect1stSignatures() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 14; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } byte[] sign = new ECKey().sign(Hash.sha3("sdifhsdfihyw888w7".getBytes())).toByteArray(); signatures.set(0, Hex.toHexString(sign)); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, + String input = PublicMethod.parametersString(parameters); + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("01111111111111000000000000000000", + Assert.assertEquals( + "01111111111111000000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); PublicMethod.waitProduceNextBlock(blockingStubFull); } Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -191,12 +229,12 @@ public void test02Incorrect1stSignatures() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -207,16 +245,18 @@ public void test02Incorrect1stSignatures() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "13 signatures with 1st incorrect address" - + " test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "13 signatures with 1st incorrect address" + " test multivalidatesign", + groups = {"contract", "daily"}) public void test03Incorrect1stAddress() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -224,37 +264,47 @@ public void test03Incorrect1stAddress() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 13; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } addresses.set(0, WalletClient.encode58Check(new ECKey().getAddress())); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, + String input = PublicMethod.parametersString(parameters); + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("01111111111110000000000000000000", + Assert.assertEquals( + "01111111111110000000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); PublicMethod.waitProduceNextBlock(blockingStubFull); } Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -262,12 +312,12 @@ public void test03Incorrect1stAddress() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -278,16 +328,18 @@ public void test03Incorrect1stAddress() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "16 signatures with 15th incorrect signatures" - + " test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "16 signatures with 15th incorrect signatures" + " test multivalidatesign", + groups = {"contract", "daily"}) public void test04Incorrect15thSignatures() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -295,10 +347,10 @@ public void test04Incorrect15thSignatures() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); if (i == 14) { signatures.add( Hex.toHexString(key.sign("dgjjsldgjljvjjfdshkh123770807779".getBytes()).toByteArray())); @@ -308,22 +360,31 @@ public void test04Incorrect15thSignatures() { addresses.add(WalletClient.encode58Check(key.getAddress())); } List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, + String input = PublicMethod.parametersString(parameters); + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); - Assert.assertEquals("11111111111111010000000000000000", + Assert.assertEquals( + "11111111111111010000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -331,12 +392,12 @@ public void test04Incorrect15thSignatures() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -347,16 +408,18 @@ public void test04Incorrect15thSignatures() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "15 signatures with 10th-15th incorrect address" - + " test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "15 signatures with 10th-15th incorrect address" + " test multivalidatesign", + groups = {"contract", "daily"}) public void test05Incorrect15thTo30thAddress() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -364,10 +427,10 @@ public void test05Incorrect15thTo30thAddress() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 15; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } @@ -375,28 +438,38 @@ public void test05Incorrect15thTo30thAddress() { addresses.set(i, WalletClient.encode58Check(new ECKey().getAddress())); } List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, + String input = PublicMethod.parametersString(parameters); + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("11111111100000100000000000000000", + Assert.assertEquals( + "11111111100000100000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); PublicMethod.waitProduceNextBlock(blockingStubFull); } Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -404,12 +477,12 @@ public void test05Incorrect15thTo30thAddress() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -420,16 +493,18 @@ public void test05Incorrect15thTo30thAddress() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "16 signatures with 2nd、16th incorrect signatures" - + " test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "16 signatures with 2nd、16th incorrect signatures" + " test multivalidatesign", + groups = {"contract", "daily"}) public void test06Incorrect2ndAnd32ndIncorrectSignatures() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -437,10 +512,10 @@ public void test06Incorrect2ndAnd32ndIncorrectSignatures() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); if (i == 1 || i == 15) { signatures.add( Hex.toHexString(key.sign("dgjjsldgjljvjjfdshkh1hgsk0807779".getBytes()).toByteArray())); @@ -450,28 +525,38 @@ public void test06Incorrect2ndAnd32ndIncorrectSignatures() { addresses.add(WalletClient.encode58Check(key.getAddress())); } List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, + String input = PublicMethod.parametersString(parameters); + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("10111111111111100000000000000000", + Assert.assertEquals( + "10111111111111100000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); PublicMethod.waitProduceNextBlock(blockingStubFull); } Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -479,12 +564,12 @@ public void test06Incorrect2ndAnd32ndIncorrectSignatures() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -495,16 +580,19 @@ public void test06Incorrect2ndAnd32ndIncorrectSignatures() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "16 signatures with 6th/9th/11th/13nd incorrect address" - + " test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "16 signatures with 6th/9th/11th/13nd incorrect address" + " test multivalidatesign", + groups = {"contract", "daily"}) public void test07IncorrectAddress() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -512,10 +600,10 @@ public void test07IncorrectAddress() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } @@ -524,27 +612,37 @@ public void test07IncorrectAddress() { addresses.set(10, WalletClient.encode58Check(new ECKey().getAddress())); addresses.set(12, WalletClient.encode58Check(new ECKey().getAddress())); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, + String input = PublicMethod.parametersString(parameters); + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("11111011010101110000000000000000", + Assert.assertEquals( + "11111011010101110000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); PublicMethod.waitProduceNextBlock(blockingStubFull); } Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -552,12 +650,12 @@ public void test07IncorrectAddress() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -568,19 +666,26 @@ public void test07IncorrectAddress() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "16 signatures with Incorrect hash test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "16 signatures with Incorrect hash test multivalidatesign", + groups = {"contract", "daily"}) public void test08IncorrectHash() { - String incorrecttxid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 1000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); + String incorrecttxid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -588,36 +693,47 @@ public void test08IncorrectHash() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } - List parameters = Arrays - .asList("0x" + Hex.toHexString(Hash.sha3(incorrecttxid.getBytes())), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, + List parameters = + Arrays.asList( + "0x" + Hex.toHexString(Hash.sha3(incorrecttxid.getBytes())), signatures, addresses); + String input = PublicMethod.parametersString(parameters); + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); PublicMethod.waitProduceNextBlock(blockingStubFull); } Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -625,12 +741,12 @@ public void test08IncorrectHash() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -641,14 +757,13 @@ public void test08IncorrectHash() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(contractExcKey, blockingStubFull).getBalance(); - PublicMethod.sendcoin(testNetAccountAddress, balance, contractExcAddress, contractExcKey, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.sendcoin( + testNetAccountAddress, balance, contractExcAddress, contractExcKey, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract003.java index ced2fb96..3cda5958 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract003.java @@ -21,16 +21,16 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.Hash; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class batchValidateSignContract003 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -39,127 +39,200 @@ public class batchValidateSignContract003 extends TronBaseTest { String txid = ""; private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - txid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 1000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); + txid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/batchvalidatesign001.sol"; - String contractName = "Demo"; + String filePath = "src/test/resources/soliditycode/batchvalidatesign001.sol"; + String contractName = "Demo"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "13 signatures and 12 address test pure multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "13 signatures and 12 address test pure multivalidatesign", + groups = {"contract", "daily"}) public void test01With25SignaturesAnd24Address() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 12; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } byte[] sign = new ECKey().sign(Hash.sha3("sdifhsdfihyw888w7".getBytes())).toByteArray(); signatures.add(Hex.toHexString(sign)); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "7 signatures and 8 address test pure multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "7 signatures and 8 address test pure multivalidatesign", + groups = {"contract", "daily"}) public void test02With15SignaturesAnd16Address() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 7; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } addresses.add(WalletClient.encode58Check(new ECKey().getAddress())); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "150 signatures and 1 address test pure multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "150 signatures and 1 address test pure multivalidatesign", + groups = {"contract", "daily"}) public void test03With150SignaturesAnd1Address() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 150; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); } addresses.add(WalletClient.encode58Check(new ECKey().getAddress())); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "1 signatures and 160 address test pure multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "1 signatures and 160 address test pure multivalidatesign", + groups = {"contract", "daily"}) public void test04With1SignaturesAnd160Address() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 160; i++) { ECKey key = new ECKey(); addresses.add(WalletClient.encode58Check(key.getAddress())); @@ -167,99 +240,152 @@ public void test04With1SignaturesAnd160Address() { byte[] sign = new ECKey().sign(Hash.sha3("sdifhsdfihyw888w7".getBytes())).toByteArray(); signatures.add(Hex.toHexString(sign)); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "16 signatures and 17 address test pure multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "16 signatures and 17 address test pure multivalidatesign", + groups = {"contract", "daily"}) public void test05With32SignaturesAnd33Address() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } addresses.add(WalletClient.encode58Check(new ECKey().getAddress())); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "17 signatures and 16 address test pure multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "17 signatures and 16 address test pure multivalidatesign", + groups = {"contract", "daily"}) public void test06With33SignaturesAnd32Address() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } byte[] sign = new ECKey().sign(Hash.sha3("sdifhsdfihyw888w7".getBytes())).toByteArray(); signatures.add(Hex.toHexString(sign)); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(contractExcKey, blockingStubFull).getBalance(); - PublicMethod.sendcoin(testNetAccountAddress, balance, contractExcAddress, contractExcKey, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.sendcoin( + testNetAccountAddress, balance, contractExcAddress, contractExcKey, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } private String parametersString(List parameters) { String[] inputArr = new String[parameters.size()]; - int i = 0; + int i = 0; for (Object parameter : parameters) { if (parameter instanceof List) { StringBuilder sb = new StringBuilder(); diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract004.java index b846a681..1ad4c5d2 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract004.java @@ -24,17 +24,17 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.Hash; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class batchValidateSignContract004 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -43,41 +43,57 @@ public class batchValidateSignContract004 extends TronBaseTest { String txid = ""; private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - txid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 1000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); + txid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/batchvalidatesign001.sol"; - String contractName = "Demo"; + String filePath = "src/test/resources/soliditycode/batchvalidatesign001.sol"; + String contractName = "Demo"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "10 signatures and 9 address test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "10 signatures and 9 address test multivalidatesign", + groups = {"contract", "daily"}) public void test01With25SignaturesAnd24Address() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -85,32 +101,41 @@ public void test01With25SignaturesAnd24Address() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 9; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } byte[] sign = new ECKey().sign(Hash.sha3("sdifhsdfihyw888w7".getBytes())).toByteArray(); signatures.add(Hex.toHexString(sign)); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = parametersString(parameters); - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, + String input = parametersString(parameters); + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -118,12 +143,12 @@ public void test01With25SignaturesAnd24Address() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -134,15 +159,18 @@ public void test01With25SignaturesAnd24Address() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "14 signatures and 15 address test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "14 signatures and 15 address test multivalidatesign", + groups = {"contract", "daily"}) public void test02With15SignaturesAnd16Address() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -150,36 +178,46 @@ public void test02With15SignaturesAnd16Address() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 14; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } addresses.add(WalletClient.encode58Check(new ECKey().getAddress())); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = parametersString(parameters); - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, + String input = parametersString(parameters); + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); PublicMethod.waitProduceNextBlock(blockingStubFull); } Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -187,12 +225,12 @@ public void test02With15SignaturesAnd16Address() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -203,15 +241,18 @@ public void test02With15SignaturesAnd16Address() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "40 signatures and 1 address test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "40 signatures and 1 address test multivalidatesign", + groups = {"contract", "daily"}) public void test03With40SignaturesAnd1Address() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -219,35 +260,45 @@ public void test03With40SignaturesAnd1Address() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 40; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); } addresses.add(WalletClient.encode58Check(new ECKey().getAddress())); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = parametersString(parameters); - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, + String input = parametersString(parameters); + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); PublicMethod.waitProduceNextBlock(blockingStubFull); } Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -255,12 +306,12 @@ public void test03With40SignaturesAnd1Address() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -271,15 +322,18 @@ public void test03With40SignaturesAnd1Address() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "1 signatures and 50 address test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "1 signatures and 50 address test multivalidatesign", + groups = {"contract", "daily"}) public void test04With1SignaturesAnd50Address() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -287,7 +341,7 @@ public void test04With1SignaturesAnd50Address() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 50; i++) { ECKey key = new ECKey(); addresses.add(WalletClient.encode58Check(key.getAddress())); @@ -295,27 +349,37 @@ public void test04With1SignaturesAnd50Address() { byte[] sign = new ECKey().sign(Hash.sha3("sdifhsdfihyw888w7".getBytes())).toByteArray(); signatures.add(Hex.toHexString(sign)); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = parametersString(parameters); - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, + String input = parametersString(parameters); + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); PublicMethod.waitProduceNextBlock(blockingStubFull); } Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -323,12 +387,12 @@ public void test04With1SignaturesAnd50Address() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -339,15 +403,18 @@ public void test04With1SignaturesAnd50Address() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "16 signatures and 17 address test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "16 signatures and 17 address test multivalidatesign", + groups = {"contract", "daily"}) public void test05With32SignaturesAnd33Address() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -355,36 +422,46 @@ public void test05With32SignaturesAnd33Address() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } addresses.add(WalletClient.encode58Check(new ECKey().getAddress())); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = parametersString(parameters); - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, + String input = parametersString(parameters); + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); PublicMethod.waitProduceNextBlock(blockingStubFull); } Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -392,12 +469,12 @@ public void test05With32SignaturesAnd33Address() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -408,15 +485,18 @@ public void test05With32SignaturesAnd33Address() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "17 signatures and 16 address test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "17 signatures and 16 address test multivalidatesign", + groups = {"contract", "daily"}) public void test06With33SignaturesAnd32Address() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -424,37 +504,47 @@ public void test06With33SignaturesAnd32Address() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } byte[] sign = new ECKey().sign(Hash.sha3("sdifhsdfihyw888w7".getBytes())).toByteArray(); signatures.add(Hex.toHexString(sign)); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = parametersString(parameters); - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, + String input = parametersString(parameters); + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); PublicMethod.waitProduceNextBlock(blockingStubFull); } Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -462,12 +552,12 @@ public void test06With33SignaturesAnd32Address() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -478,21 +568,20 @@ public void test06With33SignaturesAnd32Address() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(contractExcKey, blockingStubFull).getBalance(); - PublicMethod.sendcoin(testNetAccountAddress, balance, contractExcAddress, contractExcKey, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.sendcoin( + testNetAccountAddress, balance, contractExcAddress, contractExcKey, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } private String parametersString(List parameters) { String[] inputArr = new String[parameters.size()]; - int i = 0; + int i = 0; for (Object parameter : parameters) { if (parameter instanceof List) { StringBuilder sb = new StringBuilder(); diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract005.java index 3074e511..d84ef5fd 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract005.java @@ -20,18 +20,17 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.Hash; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j - @MultiNode public class batchValidateSignContract005 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -40,173 +39,279 @@ public class batchValidateSignContract005 extends TronBaseTest { String txid = ""; private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - txid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 1000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); + txid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/batchvalidatesign001.sol"; - String contractName = "Demo"; + String filePath = "src/test/resources/soliditycode/batchvalidatesign001.sol"; + String contractName = "Demo"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Hash is empty test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Hash is empty test multivalidatesign", + groups = {"contract", "daily"}) public void test01HashIsEmpty() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } List parameters = Arrays.asList("0x" + "", signatures, addresses); - String input = PublicMethod.parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "Address is empty test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Address is empty test multivalidatesign", + groups = {"contract", "daily"}) public void test02AddressIsEmpty() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); } List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "Signatures is empty test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Signatures is empty test multivalidatesign", + groups = {"contract", "daily"}) public void test03SignaturesIsEmpty() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); addresses.add(WalletClient.encode58Check(key.getAddress())); } List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "Signatures and addresses are empty test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Signatures and addresses are empty test multivalidatesign", + groups = {"contract", "daily"}) public void test04SignaturesAndAddressesAreEmpty() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "All empty test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "All empty test multivalidatesign", + groups = {"contract", "daily"}) public void test05AllEmpty() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); List parameters = Arrays.asList("0x" + "", signatures, addresses); - String input = PublicMethod.parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(contractExcKey, blockingStubFull).getBalance(); - PublicMethod.sendcoin(testNetAccountAddress, balance, contractExcAddress, contractExcKey, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.sendcoin( + testNetAccountAddress, balance, contractExcAddress, contractExcKey, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract006.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract006.java index 4f27d88f..8beae38e 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract006.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract006.java @@ -23,18 +23,17 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.Hash; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j - @MultiNode public class batchValidateSignContract006 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -43,43 +42,58 @@ public class batchValidateSignContract006 extends TronBaseTest { String txid = ""; private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - txid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 1000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); + txid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/batchvalidatesign001.sol"; - String contractName = "Demo"; + String filePath = "src/test/resources/soliditycode/batchvalidatesign001.sol"; + String contractName = "Demo"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Hash is empty test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Hash is empty test multivalidatesign", + groups = {"contract", "daily"}) public void test01HashIsEmpty() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -87,34 +101,44 @@ public void test01HashIsEmpty() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } List parameters = Arrays.asList("0x" + "", signatures, addresses); - String input = PublicMethod.parametersString(parameters); - txid = PublicMethod - .triggerContract(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + txid = + PublicMethod.triggerContract( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); PublicMethod.waitProduceNextBlock(blockingStubFull); } Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -122,12 +146,12 @@ public void test01HashIsEmpty() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -138,15 +162,18 @@ public void test01HashIsEmpty() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "Address is empty test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Address is empty test multivalidatesign", + groups = {"contract", "daily"}) public void test02AddressIsEmpty() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -154,33 +181,43 @@ public void test02AddressIsEmpty() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); } List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - txid = PublicMethod - .triggerContract(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + txid = + PublicMethod.triggerContract( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); PublicMethod.waitProduceNextBlock(blockingStubFull); } Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -188,12 +225,12 @@ public void test02AddressIsEmpty() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -204,15 +241,18 @@ public void test02AddressIsEmpty() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "Signatures is empty test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Signatures is empty test multivalidatesign", + groups = {"contract", "daily"}) public void test03SignaturesIsEmpty() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -220,33 +260,43 @@ public void test03SignaturesIsEmpty() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); addresses.add(WalletClient.encode58Check(key.getAddress())); } List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - txid = PublicMethod - .triggerContract(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + txid = + PublicMethod.triggerContract( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); PublicMethod.waitProduceNextBlock(blockingStubFull); } Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -254,12 +304,12 @@ public void test03SignaturesIsEmpty() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -270,15 +320,18 @@ public void test03SignaturesIsEmpty() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "Signatures and addresses are empty test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Signatures and addresses are empty test multivalidatesign", + groups = {"contract", "daily"}) public void test04SignaturesAndAddressesAreEmpty() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -286,28 +339,38 @@ public void test04SignaturesAndAddressesAreEmpty() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - txid = PublicMethod - .triggerContract(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + txid = + PublicMethod.triggerContract( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); PublicMethod.waitProduceNextBlock(blockingStubFull); } Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -315,12 +378,12 @@ public void test04SignaturesAndAddressesAreEmpty() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -331,15 +394,18 @@ public void test04SignaturesAndAddressesAreEmpty() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "All empty test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "All empty test multivalidatesign", + groups = {"contract", "daily"}) public void test05AllEmpty() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -347,28 +413,38 @@ public void test05AllEmpty() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); List parameters = Arrays.asList("0x" + "", signatures, addresses); - String input = PublicMethod.parametersString(parameters); - txid = PublicMethod - .triggerContract(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + txid = + PublicMethod.triggerContract( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); PublicMethod.waitProduceNextBlock(blockingStubFull); } Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -376,12 +452,12 @@ public void test05AllEmpty() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -392,14 +468,13 @@ public void test05AllEmpty() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(contractExcKey, blockingStubFull).getBalance(); - PublicMethod.sendcoin(testNetAccountAddress, balance, contractExcAddress, contractExcKey, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.sendcoin( + testNetAccountAddress, balance, contractExcAddress, contractExcKey, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract007.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract007.java index 09b9308a..bf8a6017 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract007.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract007.java @@ -24,16 +24,16 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.Hash; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class batchValidateSignContract007 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -41,67 +41,84 @@ public class batchValidateSignContract007 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } - @Test(enabled = true, description = "Constructor test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Constructor test multivalidatesign", + groups = {"contract", "daily"}) public void test01Constructor() { - String txid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 2000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); + String txid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 2000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String filePath = "src/test/resources/soliditycode/batchvalidatesign007.sol"; - String contractName = "Demo"; + String filePath = "src/test/resources/soliditycode/batchvalidatesign007.sol"; + String contractName = "Demo"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String data = PublicMethod.parametersString(parameters); - String constructorStr = "constructor(bytes32,bytes[],address[])"; - txid = PublicMethod - .deployContractWithConstantParame(contractName, abi, code, constructorStr, data, "", - maxFeeLimit, 0L, 100, null, contractExcKey, contractExcAddress, blockingStubFull); + String data = PublicMethod.parametersString(parameters); + String constructorStr = "constructor(bytes32,bytes[],address[])"; + txid = + PublicMethod.deployContractWithConstantParame( + contractName, + abi, + code, + constructorStr, + data, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); - Long fee1 = infoById.get().getFee(); - Long netUsed1 = infoById.get().getReceipt().getNetUsage(); - Long energyUsed1 = infoById.get().getReceipt().getEnergyUsage(); - Long netFee1 = infoById.get().getReceipt().getNetFee(); + Long fee1 = infoById.get().getFee(); + Long netUsed1 = infoById.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById.get().getReceipt().getNetFee(); long energyUsageTotal1 = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee1:" + fee1); logger.info("netUsed1:" + netUsed1); @@ -110,33 +127,54 @@ public void test01Constructor() { logger.info("energyUsageTotal1:" + energyUsageTotal1); contractAddress = infoById.get().getContractAddress().toByteArray(); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testConstructorPure()", "", false, 0, - 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testConstructorPure()", + "", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); - Assert.assertEquals("11111111111111110000000000000000", + Assert.assertEquals( + "11111111111111110000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - txid = PublicMethod - .triggerContract(contractAddress, "testConstructor()", "", false, 0, maxFeeLimit, - contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "testConstructor()", + "", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById2 = null; infoById2 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById2.get().getResultValue() == 0) { - Assert.assertEquals("11111111111111110000000000000000", + Assert.assertEquals( + "11111111111111110000000000000000", PublicMethod.bytes32ToString(infoById2.get().getContractResult(0).toByteArray())); } else { - Assert.assertTrue(infoById2.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById2.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById2.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById2.get().getResMessage().toStringUtf8())); PublicMethod.waitProduceNextBlock(blockingStubFull); } Long fee2 = infoById2.get().getFee(); - Long netUsed2 = infoById2.get().getReceipt().getNetUsage(); - Long energyUsed2 = infoById2.get().getReceipt().getEnergyUsage(); - Long netFee2 = infoById2.get().getReceipt().getNetFee(); + Long netUsed2 = infoById2.get().getReceipt().getNetUsage(); + Long energyUsed2 = infoById2.get().getReceipt().getEnergyUsage(); + Long netFee2 = infoById2.get().getReceipt().getNetFee(); long energyUsageTotal2 = infoById2.get().getReceipt().getEnergyUsageTotal(); logger.info("fee2:" + fee2); logger.info("netUsed2:" + netUsed2); @@ -145,12 +183,12 @@ public void test01Constructor() { logger.info("energyUsageTotal2:" + energyUsageTotal2); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -161,14 +199,13 @@ public void test01Constructor() { Assert.assertTrue(beforeNetUsed + netUsed1 + netUsed2 >= afterNetUsed); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(contractExcKey, blockingStubFull).getBalance(); - PublicMethod.sendcoin(testNetAccountAddress, balance, contractExcAddress, contractExcKey, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.sendcoin( + testNetAccountAddress, balance, contractExcAddress, contractExcKey, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract008.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract008.java index d855a990..6e2bcf9d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract008.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract008.java @@ -14,17 +14,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class batchValidateSignContract008 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -33,93 +33,152 @@ public class batchValidateSignContract008 extends TronBaseTest { String txid = ""; private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - txid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 1000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); + txid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/batchvalidatesign001.sol"; - String contractName = "Demo"; + String filePath = "src/test/resources/soliditycode/batchvalidatesign001.sol"; + String contractName = "Demo"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Incorrect address hex test pure multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Incorrect address hex test pure multivalidatesign", + groups = {"contract", "daily"}) public void test01IncorrectAddressHex() { - String input = "7d889f42b4a56ebe78264631a3b4daf21019e1170cce71929fb396761cdf532e00000000000000" - + "000000000000000000000000000000000000000000000000600000000000000000000000000000000000000" - + "0000000000000000000000001c0000000000000000000000000000000000000000000000000000000000000" - + "000200000000000000000000000000000000000000000000000000000000000000400000000000000000000" - + "0000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000" - + "0000000000000000000041ad7ca8100cf0ce028b83ac719c8458655a6605317abfd071b91f5cc14d53e87a2" - + "99fe0cdf6a8567074e9be3944affba33b1e15d14b7cb9003ec2c87cb1a56405000000000000000000000000" - + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - + "000000000000000417ce31e565fb99451f87db65e75f46672e8a8f7b29e6589e60fd11e076550d0a66d0b05" - + "e4b4d7d40bd34140f13dc3632d3ce0f25e4cf75840238b6fe2346c94fa01000000000000000000000000000" - + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - + "0000000000020000000000000000000000410d6b1de9e84c1d7a9a5b43d93dbe4a5aae79b18900000000000" - + "00000000000123456"; - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, true, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = + "7d889f42b4a56ebe78264631a3b4daf21019e1170cce71929fb396761cdf532e00000000000000" + + "000000000000000000000000000000000000000000000000600000000000000000000000000000000000" + + "000" + + "0000000000000000000000001c0000000000000000000000000000000000000000000000000000000000" + + "000" + + "000200000000000000000000000000000000000000000000000000000000000000400000000000000000" + + "000" + + "0000000000000000000000000000000000000000000c0000000000000000000000000000000000000000" + + "000" + + "0000000000000000000041ad7ca8100cf0ce028b83ac719c8458655a6605317abfd071b91f5cc14d53e8" + + "7a2" + + "99fe0cdf6a8567074e9be3944affba33b1e15d14b7cb9003ec2c87cb1a56405000000000000000000000" + + "000" + + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + + "000" + + "000000000000000417ce31e565fb99451f87db65e75f46672e8a8f7b29e6589e60fd11e076550d0a66d0" + + "b05" + + "e4b4d7d40bd34140f13dc3632d3ce0f25e4cf75840238b6fe2346c94fa01000000000000000000000000" + + "000" + + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + + "000" + + "0000000000020000000000000000000000410d6b1de9e84c1d7a9a5b43d93dbe4a5aae79b18900000000" + + "000" + + "00000000000123456"; + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + true, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); - Assert.assertEquals("", - PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("REVERT opcode executed", + Assert.assertEquals( + "", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + "REVERT opcode executed", ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); - Assert.assertEquals("FAILED", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "FAILED", transactionExtention.getTransaction().getRet(0).getRet().toString()); } - @Test(enabled = true, description = "Empty address and signatures hex" - + " test pure multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Empty address and signatures hex" + " test pure multivalidatesign", + groups = {"contract", "daily"}) public void test02EmptyAddressAndSignaturesHex() { - String input = "da586d881362c0c38eb31b556ce0f7c2837a3ebb60080e8e665a6b92c7541837b95064ba000000" - + "000000000000000000000000000000000000000000000000000000006000000000000000000000000000000" - + "000000000000000000000000000000001200000000000000000000000000000000000000000000000000000" - + "000000000001000000000000000000000000000000000000000000000000000000000000002000000000000" - + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - + "000000000000000000000000000000000000000000000001000000000000000000000000000000000000000" - + "0000000000000000000000000"; - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, true, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = + "da586d881362c0c38eb31b556ce0f7c2837a3ebb60080e8e665a6b92c7541837b95064ba000000" + + "000000000000000000000000000000000000000000000000000000006000000000000000000000000000" + + "000" + + "000000000000000000000000000000001200000000000000000000000000000000000000000000000000" + + "000" + + "000000000001000000000000000000000000000000000000000000000000000000000000002000000000" + + "000" + + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + + "000" + + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + + "000" + + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + + "000" + + "000000000000000000000000000000000000000000000001000000000000000000000000000000000000" + + "000" + + "0000000000000000000000000"; + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + true, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); - Assert.assertEquals("", - PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("REVERT opcode executed", + Assert.assertEquals( + "", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + "REVERT opcode executed", ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); - Assert.assertEquals("FAILED", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "FAILED", transactionExtention.getTransaction().getRet(0).getRet().toString()); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(contractExcKey, blockingStubFull).getBalance(); - PublicMethod.sendcoin(testNetAccountAddress, balance, contractExcAddress, contractExcKey, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.sendcoin( + testNetAccountAddress, balance, contractExcAddress, contractExcKey, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract009.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract009.java index 57558adb..48c14024 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract009.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract009.java @@ -17,16 +17,16 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class batchValidateSignContract009 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -35,64 +35,99 @@ public class batchValidateSignContract009 extends TronBaseTest { String txid = ""; private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - txid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 1000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); + txid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/batchvalidatesign001.sol"; - String contractName = "Demo"; + String filePath = "src/test/resources/soliditycode/batchvalidatesign001.sol"; + String contractName = "Demo"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Incorrect address hex test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Incorrect address hex test multivalidatesign", + groups = {"contract", "daily"}) public void test02IncorrectAddressHex() { Protocol.Account info; - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String input = "7d889f42b4a56ebe78264631a3b4daf21019e1170cce71929fb396761cdf532e00000000000000" - + "000000000000000000000000000000000000000000000000600000000000000000000000000000000000000" - + "0000000000000000000000001c0000000000000000000000000000000000000000000000000000000000000" - + "000200000000000000000000000000000000000000000000000000000000000000400000000000000000000" - + "0000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000" - + "0000000000000000000041ad7ca8100cf0ce028b83ac719c8458655a6605317abfd071b91f5cc14d53e87a2" - + "99fe0cdf6a8567074e9be3944affba33b1e15d14b7cb9003ec2c87cb1a56405000000000000000000000000" - + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - + "000000000000000417ce31e565fb99451f87db65e75f46672e8a8f7b29e6589e60fd11e076550d0a66d0b05" - + "e4b4d7d40bd34140f13dc3632d3ce0f25e4cf75840238b6fe2346c94fa01000000000000000000000000000" - + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - + "0000000000020000000000000000000000410d6b1de9e84c1d7a9a5b43d93dbe4a5aae79b18900000000000" - + "00000000000123456"; - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, true, + String input = + "7d889f42b4a56ebe78264631a3b4daf21019e1170cce71929fb396761cdf532e00000000000000" + + "000000000000000000000000000000000000000000000000600000000000000000000000000000000000" + + "000" + + "0000000000000000000000001c0000000000000000000000000000000000000000000000000000000000" + + "000" + + "000200000000000000000000000000000000000000000000000000000000000000400000000000000000" + + "000" + + "0000000000000000000000000000000000000000000c0000000000000000000000000000000000000000" + + "000" + + "0000000000000000000041ad7ca8100cf0ce028b83ac719c8458655a6605317abfd071b91f5cc14d53e8" + + "7a2" + + "99fe0cdf6a8567074e9be3944affba33b1e15d14b7cb9003ec2c87cb1a56405000000000000000000000" + + "000" + + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + + "000" + + "000000000000000417ce31e565fb99451f87db65e75f46672e8a8f7b29e6589e60fd11e076550d0a66d0" + + "b05" + + "e4b4d7d40bd34140f13dc3632d3ce0f25e4cf75840238b6fe2346c94fa01000000000000000000000000" + + "000" + + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + + "000" + + "0000000000020000000000000000000000410d6b1de9e84c1d7a9a5b43d93dbe4a5aae79b18900000000" + + "000" + + "00000000000123456"; + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + true, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -100,10 +135,10 @@ public void test02IncorrectAddressHex() { Assert.assertEquals(1, infoById.get().getResultValue()); Assert.assertTrue( infoById.get().getResMessage().toStringUtf8().contains("REVERT opcode executed")); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -111,12 +146,12 @@ public void test02IncorrectAddressHex() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -127,33 +162,52 @@ public void test02IncorrectAddressHex() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "Empty address and signatures hex test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Empty address and signatures hex test multivalidatesign", + groups = {"contract", "daily"}) public void test03EmptyAddressAndSignaturesHex() { Protocol.Account info; - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String input = "da586d881362c0c38eb31b556ce0f7c2837a3ebb60080e8e665a6b92c7541837b95064ba000000" - + "000000000000000000000000000000000000000000000000000000006000000000000000000000000000000" - + "000000000000000000000000000000001200000000000000000000000000000000000000000000000000000" - + "000000000001000000000000000000000000000000000000000000000000000000000000002000000000000" - + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - + "000000000000000000000000000000000000000000000001000000000000000000000000000000000000000" - + "0000000000000000000000000"; - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, true, + String input = + "da586d881362c0c38eb31b556ce0f7c2837a3ebb60080e8e665a6b92c7541837b95064ba000000" + + "000000000000000000000000000000000000000000000000000000006000000000000000000000000000" + + "000" + + "000000000000000000000000000000001200000000000000000000000000000000000000000000000000" + + "000" + + "000000000001000000000000000000000000000000000000000000000000000000000000002000000000" + + "000" + + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + + "000" + + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + + "000" + + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + + "000" + + "000000000000000000000000000000000000000000000001000000000000000000000000000000000000" + + "000" + + "0000000000000000000000000"; + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + true, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -161,10 +215,10 @@ public void test03EmptyAddressAndSignaturesHex() { Assert.assertEquals(1, infoById.get().getResultValue()); Assert.assertTrue( infoById.get().getResMessage().toStringUtf8().contains("REVERT opcode executed")); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -172,12 +226,12 @@ public void test03EmptyAddressAndSignaturesHex() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -188,14 +242,13 @@ public void test03EmptyAddressAndSignaturesHex() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(contractExcKey, blockingStubFull).getBalance(); - PublicMethod.sendcoin(testNetAccountAddress, balance, contractExcAddress, contractExcKey, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.sendcoin( + testNetAccountAddress, balance, contractExcAddress, contractExcKey, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract010.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract010.java index 4fcc27a2..5304aed4 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract010.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract010.java @@ -20,17 +20,17 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.Hash; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class batchValidateSignContract010 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -39,165 +39,252 @@ public class batchValidateSignContract010 extends TronBaseTest { String txid = ""; private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - txid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 1000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); + txid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/batchvalidatesign001.sol"; - String contractName = "Demo"; + String filePath = "src/test/resources/soliditycode/batchvalidatesign001.sol"; + String contractName = "Demo"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Correct 50 signatures test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Correct 50 signatures test multivalidatesign", + groups = {"contract", "daily"}) public void test01Correct50Signatures() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 50; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "2 signatures with 1st incorrect signatures" - + " test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "2 signatures with 1st incorrect signatures" + " test multivalidatesign", + groups = {"contract", "daily"}) public void test02Incorrect1stSignatures() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 2; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } byte[] sign = new ECKey().sign(Hash.sha3("sdifhsdfihyw888w7".getBytes())).toByteArray(); signatures.set(0, Hex.toHexString(sign)); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("01000000000000000000000000000000", + Assert.assertEquals( + "01000000000000000000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "3 signatures with 1st incorrect address" - + " test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "3 signatures with 1st incorrect address" + " test multivalidatesign", + groups = {"contract", "daily"}) public void test03Incorrect1stAddress() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 3; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } addresses.set(0, WalletClient.encode58Check(new ECKey().getAddress())); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("01100000000000000000000000000000", + Assert.assertEquals( + "01100000000000000000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "9 signatures with 7th incorrect signatures" - + " test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "9 signatures with 7th incorrect signatures" + " test multivalidatesign", + groups = {"contract", "daily"}) public void test04Incorrect15thSignatures() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 9; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } byte[] sign = new ECKey().sign(Hash.sha3("sdifhsdfihyw888w7".getBytes())).toByteArray(); signatures.set(6, Hex.toHexString(sign)); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("11111101100000000000000000000000", + Assert.assertEquals( + "11111101100000000000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "5 signatures with 2th-4th incorrect address" - + " test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "5 signatures with 2th-4th incorrect address" + " test multivalidatesign", + groups = {"contract", "daily"}) public void test05Incorrect15thTo30thAddress() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 5; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } @@ -205,32 +292,50 @@ public void test05Incorrect15thTo30thAddress() { addresses.set(i, WalletClient.encode58Check(new ECKey().getAddress())); } List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("10001000000000000000000000000000", + Assert.assertEquals( + "10001000000000000000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "150 signatures with 2nd/32nd incorrect signatures" - + " test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "150 signatures with 2nd/32nd incorrect signatures" + " test multivalidatesign", + groups = {"contract", "daily"}) public void test06Incorrect2ndAnd32ndIncorrectSignatures() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 150; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); if (i == 1 || i == 31) { signatures.add( Hex.toHexString(key.sign("dgjjsldgjljvjjfdshkh1hgsk0807779".getBytes()).toByteArray())); @@ -240,32 +345,51 @@ public void test06Incorrect2ndAnd32ndIncorrectSignatures() { addresses.add(WalletClient.encode58Check(key.getAddress())); } List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "88 signatures with 9th/11th/28th/32nd incorrect address" - + " test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "88 signatures with 9th/11th/28th/32nd incorrect address" + " test multivalidatesign", + groups = {"contract", "daily"}) public void test07IncorrectAddress() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 88; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } @@ -274,65 +398,104 @@ public void test07IncorrectAddress() { addresses.set(27, WalletClient.encode58Check(new ECKey().getAddress())); addresses.set(31, WalletClient.encode58Check(new ECKey().getAddress())); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String input = PublicMethod.parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - @Test(enabled = true, description = "105 signatures with Incorrect hash test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "105 signatures with Incorrect hash test multivalidatesign", + groups = {"contract", "daily"}) public void test08IncorrectHash() { - String incorrecttxid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 1000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); + String incorrecttxid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 105; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } - List parameters = Arrays - .asList("0x" + Hex.toHexString(Hash.sha3(incorrecttxid.getBytes())), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPure(bytes32,bytes[],address[])", - input, false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + List parameters = + Arrays.asList( + "0x" + Hex.toHexString(Hash.sha3(incorrecttxid.getBytes())), signatures, addresses); + String input = PublicMethod.parametersString(parameters); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure(bytes32,bytes[],address[])", + input, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); if (transactionExtention.getResult().getCode().toString().equals("CONTRACT_EXE_ERROR")) { - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8().contains( - "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() + .contains( + "class org.tron.core.vm.program.Program$OutOfTimeException : CPU timeout for")); } else { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(contractExcKey, blockingStubFull).getBalance(); - PublicMethod.sendcoin(testNetAccountAddress, balance, contractExcAddress, contractExcKey, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.sendcoin( + testNetAccountAddress, balance, contractExcAddress, contractExcKey, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract011.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract011.java index 370f3a3d..2e71007d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract011.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract011.java @@ -23,16 +23,16 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.Hash; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class batchValidateSignContract011 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -41,41 +41,56 @@ public class batchValidateSignContract011 extends TronBaseTest { String txid = ""; private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - txid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 1000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); + txid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/batchvalidatesign001.sol"; - String contractName = "Demo"; + String filePath = "src/test/resources/soliditycode/batchvalidatesign001.sol"; + String contractName = "Demo"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Correct 17 signatures test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Correct 17 signatures test multivalidatesign", + groups = {"contract", "daily"}) public void test01Correct33Signatures() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -83,27 +98,35 @@ public void test01Correct33Signatures() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 17; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, + String input = PublicMethod.parametersString(parameters); + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -111,28 +134,34 @@ public void test01Correct33Signatures() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); Assert.assertTrue(afterBalance + fee == beforeBalance); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); Assert.assertTrue(afterBalance == 0); - txid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 1000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); + txid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); @@ -140,16 +169,18 @@ public void test01Correct33Signatures() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "14 signatures with 1st incorrect signatures" - + " test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "14 signatures with 1st incorrect signatures" + " test multivalidatesign", + groups = {"contract", "daily"}) public void test02Incorrect1stSignatures() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -157,37 +188,47 @@ public void test02Incorrect1stSignatures() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 14; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } byte[] sign = new ECKey().sign(Hash.sha3("sdifhsdfihyw888w7".getBytes())).toByteArray(); signatures.set(0, Hex.toHexString(sign)); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, + String input = PublicMethod.parametersString(parameters); + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("01111111111111000000000000000000", + Assert.assertEquals( + "01111111111111000000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); PublicMethod.waitProduceNextBlock(blockingStubFull); } Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -195,12 +236,12 @@ public void test02Incorrect1stSignatures() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -211,16 +252,18 @@ public void test02Incorrect1stSignatures() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "8 signatures with 1st incorrect address" - + " test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "8 signatures with 1st incorrect address" + " test multivalidatesign", + groups = {"contract", "daily"}) public void test03Incorrect1stAddress() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -228,36 +271,46 @@ public void test03Incorrect1stAddress() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 8; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } addresses.set(0, WalletClient.encode58Check(new ECKey().getAddress())); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, + String input = PublicMethod.parametersString(parameters); + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("01111111000000000000000000000000", + Assert.assertEquals( + "01111111000000000000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); PublicMethod.waitProduceNextBlock(blockingStubFull); } Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -265,12 +318,12 @@ public void test03Incorrect1stAddress() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -281,16 +334,18 @@ public void test03Incorrect1stAddress() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "6 signatures with 3th incorrect signatures" - + " test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "6 signatures with 3th incorrect signatures" + " test multivalidatesign", + groups = {"contract", "daily"}) public void test04Incorrect15thSignatures() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -298,37 +353,47 @@ public void test04Incorrect15thSignatures() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 6; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } byte[] sign = new ECKey().sign(Hash.sha3("sdifhsdfihyw888w7".getBytes())).toByteArray(); signatures.set(2, Hex.toHexString(sign)); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, + String input = PublicMethod.parametersString(parameters); + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("11011100000000000000000000000000", + Assert.assertEquals( + "11011100000000000000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); PublicMethod.waitProduceNextBlock(blockingStubFull); } Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -336,12 +401,12 @@ public void test04Incorrect15thSignatures() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -352,16 +417,18 @@ public void test04Incorrect15thSignatures() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "11 signatures with 7th-9th incorrect address" - + " test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "11 signatures with 7th-9th incorrect address" + " test multivalidatesign", + groups = {"contract", "daily"}) public void test05Incorrect15thTo30thAddress() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -369,10 +436,10 @@ public void test05Incorrect15thTo30thAddress() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 11; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } @@ -380,27 +447,37 @@ public void test05Incorrect15thTo30thAddress() { addresses.set(i, WalletClient.encode58Check(new ECKey().getAddress())); } List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, + String input = PublicMethod.parametersString(parameters); + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("11111100011000000000000000000000", + Assert.assertEquals( + "11111100011000000000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); PublicMethod.waitProduceNextBlock(blockingStubFull); } Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -408,12 +485,12 @@ public void test05Incorrect15thTo30thAddress() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -424,16 +501,18 @@ public void test05Incorrect15thTo30thAddress() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "40 signatures with 2nd、32nd incorrect signatures" - + " test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "40 signatures with 2nd、32nd incorrect signatures" + " test multivalidatesign", + groups = {"contract", "daily"}) public void test06Incorrect2ndAnd32ndIncorrectSignatures() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -441,10 +520,10 @@ public void test06Incorrect2ndAnd32ndIncorrectSignatures() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 40; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); if (i == 1 || i == 31) { signatures.add( Hex.toHexString(key.sign("dgjjsldgjljvjjfdshkh1hgsk0807779".getBytes()).toByteArray())); @@ -454,20 +533,28 @@ public void test06Incorrect2ndAnd32ndIncorrectSignatures() { addresses.add(WalletClient.encode58Check(key.getAddress())); } List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, + String input = PublicMethod.parametersString(parameters); + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -475,28 +562,34 @@ public void test06Incorrect2ndAnd32ndIncorrectSignatures() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); Assert.assertTrue(afterBalance + fee == beforeBalance); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); Assert.assertTrue(afterBalance == 0); - txid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 1000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); + txid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); @@ -504,16 +597,19 @@ public void test06Incorrect2ndAnd32ndIncorrectSignatures() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "44 signatures with 9th/11th/28th/32nd incorrect address" - + " test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "44 signatures with 9th/11th/28th/32nd incorrect address" + " test multivalidatesign", + groups = {"contract", "daily"}) public void test07IncorrectAddress() { - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -521,10 +617,10 @@ public void test07IncorrectAddress() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 44; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } @@ -533,19 +629,27 @@ public void test07IncorrectAddress() { addresses.set(27, WalletClient.encode58Check(new ECKey().getAddress())); addresses.set(31, WalletClient.encode58Check(new ECKey().getAddress())); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, + String input = PublicMethod.parametersString(parameters); + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -553,28 +657,34 @@ public void test07IncorrectAddress() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); Assert.assertTrue(afterBalance + fee == beforeBalance); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); Assert.assertTrue(afterBalance == 0); - txid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 1000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); + txid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); @@ -582,19 +692,26 @@ public void test07IncorrectAddress() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "16 signatures with Incorrect hash test multivalidatesign", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "16 signatures with Incorrect hash test multivalidatesign", + groups = {"contract", "daily"}) public void test08IncorrectHash() { - String incorrecttxid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 1000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); + String incorrecttxid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -602,28 +719,37 @@ public void test08IncorrectHash() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } - List parameters = Arrays - .asList("0x" + Hex.toHexString(Hash.sha3(incorrecttxid.getBytes())), signatures, addresses); - String input = PublicMethod.parametersString(parameters); - txid = PublicMethod - .triggerContractBoth(contractAddress, "testArray(bytes32,bytes[],address[])", input, false, + List parameters = + Arrays.asList( + "0x" + Hex.toHexString(Hash.sha3(incorrecttxid.getBytes())), signatures, addresses); + String input = PublicMethod.parametersString(parameters); + txid = + PublicMethod.triggerContractBoth( + contractAddress, + "testArray(bytes32,bytes[],address[])", + input, + false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -631,28 +757,34 @@ public void test08IncorrectHash() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); if (infoById.get().getResultValue() == 0) { - Assert.assertEquals("00000000000000000000000000000000", + Assert.assertEquals( + "00000000000000000000000000000000", PublicMethod.bytes32ToString(infoById.get().getContractResult(0).toByteArray())); Assert.assertTrue(afterBalance + fee == beforeBalance); } else { - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") - || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("CPU timeout for") + || "Already Time Out".equals(infoById.get().getResMessage().toStringUtf8())); Assert.assertTrue(afterBalance == 0); - txid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 1000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); + txid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); @@ -660,14 +792,13 @@ public void test08IncorrectHash() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(contractExcKey, blockingStubFull).getBalance(); - PublicMethod.sendcoin(testNetAccountAddress, balance, contractExcAddress, contractExcKey, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.sendcoin( + testNetAccountAddress, balance, contractExcAddress, contractExcKey, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract012.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract012.java index db686b7b..e1cc9799 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract012.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/batchValidateSignContract/batchValidateSignContract012.java @@ -22,16 +22,16 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.Hash; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class batchValidateSignContract012 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; String txid; @@ -40,51 +40,75 @@ public class batchValidateSignContract012 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - txid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 10000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); + txid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/batchvalidatesign005.sol"; - String contractName = "Demo"; + String filePath = "src/test/resources/soliditycode/batchvalidatesign005.sol"; + String contractName = "Demo"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Trigger precompile multivalisign function with correct data", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger precompile multivalisign function with correct data", + groups = {"contract", "daily"}) public void test01TriggerPrecompileMultivalisignWithCorrectData() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String argsStr = PublicMethod.parametersString(parameters); - String input = AbiUtil.parseParameters("batchvalidatesign(bytes32,bytes[],address[])", argsStr); - String method = "testArray2(bytes)"; - txid = PublicMethod.triggerContractBoth(contractAddress, method, - AbiUtil.parseParameters(method, Arrays.asList(input)), true, 0, maxFeeLimit, - contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + String argsStr = PublicMethod.parametersString(parameters); + String input = AbiUtil.parseParameters("batchvalidatesign(bytes32,bytes[],address[])", argsStr); + String method = "testArray2(bytes)"; + txid = + PublicMethod.triggerContractBoth( + contractAddress, + method, + AbiUtil.parseParameters(method, Arrays.asList(input)), + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.getTransactionById(txid, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -92,34 +116,47 @@ public void test01TriggerPrecompileMultivalisignWithCorrectData() { Assert.assertEquals(0, infoById.get().getResultValue()); logger.info( "infoById:" + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); - Assert.assertTrue(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()) - .equals("0000000000000000000000000000000000000000000000000000000000000001" - + "0000000000000000000000000000000000000000000000000000000000000040" - + "0000000000000000000000000000000000000000000000000000000000000020" - + "0101010101010101010101010101010100000000000000000000000000000000")); + Assert.assertTrue( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()) + .equals( + "0000000000000000000000000000000000000000000000000000000000000001" + + "0000000000000000000000000000000000000000000000000000000000000040" + + "0000000000000000000000000000000000000000000000000000000000000020" + + "0101010101010101010101010101010100000000000000000000000000000000")); } - @Test(enabled = true, description = "Trigger precompile multivalidatesign function with incor" - + "rect data", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger precompile multivalidatesign function with incor" + "rect data", + groups = {"contract", "daily"}) public void test02TriggerPrecompileMultivalisignWithIncorrectData() { List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - byte[] hash = Hash.sha3(txid.getBytes()); + byte[] hash = Hash.sha3(txid.getBytes()); for (int i = 0; i < 16; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } byte[] sign = new ECKey().sign(Hash.sha3("sdifhsdfihyw888w7".getBytes())).toByteArray(); signatures.set(0, Hex.toHexString(sign)); List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); - String argsStr = PublicMethod.parametersString(parameters); - String input = AbiUtil.parseParameters("batchvalidatesign(bytes32,bytes[],address[])", argsStr); - String method = "testArray2(bytes)"; - txid = PublicMethod.triggerContractBoth(contractAddress, method, - AbiUtil.parseParameters(method, Arrays.asList(input)), true, 0, maxFeeLimit, - contractExcAddress, contractExcKey, blockingStubFull, blockingStubFull1); + String argsStr = PublicMethod.parametersString(parameters); + String input = AbiUtil.parseParameters("batchvalidatesign(bytes32,bytes[],address[])", argsStr); + String method = "testArray2(bytes)"; + txid = + PublicMethod.triggerContractBoth( + contractAddress, + method, + AbiUtil.parseParameters(method, Arrays.asList(input)), + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull, + blockingStubFull1); PublicMethod.getTransactionById(txid, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -127,23 +164,23 @@ public void test02TriggerPrecompileMultivalisignWithIncorrectData() { Assert.assertEquals(0, infoById.get().getResultValue()); logger.info( "infoById:" + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); - Assert.assertTrue(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()) - .equals("0000000000000000000000000000000000000000000000000000000000000001" - + "0000000000000000000000000000000000000000000000000000000000000040" - + "0000000000000000000000000000000000000000000000000000000000000020" - + "0001010101010101010101010101010100000000000000000000000000000000")); + Assert.assertTrue( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()) + .equals( + "0000000000000000000000000000000000000000000000000000000000000001" + + "0000000000000000000000000000000000000000000000000000000000000040" + + "0000000000000000000000000000000000000000000000000000000000000020" + + "0001010101010101010101010101010100000000000000000000000000000000")); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(contractExcKey, blockingStubFull).getBalance(); - PublicMethod.sendcoin(testNetAccountAddress, balance, contractExcAddress, contractExcKey, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.sendcoin( + testNetAccountAddress, balance, contractExcAddress, contractExcKey, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java index 817a865a..999ed06a 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java @@ -20,17 +20,18 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ClearAbi001 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -41,46 +42,61 @@ public class ClearAbi001 extends TronBaseTest { String contractExcKey1 = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress1, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress1, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Clear a contract created by other account", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Clear a contract created by other account", + groups = {"contract", "daily"}) public void testClearAbi001() { String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; - String contractName = "testConstantContract"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); @@ -88,38 +104,38 @@ public void testClearAbi001() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - TransactionExtention transactionExtention = PublicMethod - .clearContractAbiForExtention(contractAddress, contractExcAddress1, contractExcKey1, - blockingStubFull); - Assert - .assertThat(transactionExtention.getResult().getCode().toString(), - containsString("CONTRACT_VALIDATE_ERROR")); - Assert - .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), - containsString("is not the owner of the contract")); + TransactionExtention transactionExtention = + PublicMethod.clearContractAbiForExtention( + contractAddress, contractExcAddress1, contractExcKey1, blockingStubFull); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_VALIDATE_ERROR")); + Assert.assertThat( + transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("is not the owner of the contract")); smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - - } - - @Test(enabled = true, description = "Clear a contract with ABI created by itself", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Clear a contract with ABI created by itself", + groups = {"contract", "daily"}) public void testClearAbi002() { String contractName = "testConstantContract"; @@ -129,27 +145,27 @@ public void testClearAbi002() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = PublicMethod - .clearContractAbi(contractAddress, contractExcAddress, contractExcKey, - blockingStubFull); + String txid = + PublicMethod.clearContractAbi( + contractAddress, contractExcAddress, contractExcKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - String txid1 = PublicMethod - .clearContractAbi(contractAddress, contractExcAddress, contractExcKey, - blockingStubFull); + String txid1 = + PublicMethod.clearContractAbi( + contractAddress, contractExcAddress, contractExcKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); @@ -161,8 +177,10 @@ public void testClearAbi002() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); } - - @Test(enabled = true, description = "Clear a contract without ABI", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Clear a contract without ABI", + groups = {"contract", "daily"}) public void testClearAbi003() { String contractName = "testConstantContract"; @@ -172,20 +190,20 @@ public void testClearAbi003() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = PublicMethod - .clearContractAbi(contractAddress, contractExcAddress, contractExcKey, - blockingStubFull); + String txid = + PublicMethod.clearContractAbi( + contractAddress, contractExcAddress, contractExcKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -195,79 +213,82 @@ public void testClearAbi003() { Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - - } - @Test(enabled = true, description = "Clear a account address", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Clear a account address", + groups = {"contract", "daily"}) public void testClearAbi004() { - TransactionExtention transactionExtention = PublicMethod - .clearContractAbiForExtention(contractExcAddress, contractExcAddress, contractExcKey, - blockingStubFull); - Assert - .assertThat(transactionExtention.getResult().getCode().toString(), - containsString("CONTRACT_VALIDATE_ERROR")); - Assert - .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), - containsString("Contract validate error : Contract not exists")); + TransactionExtention transactionExtention = + PublicMethod.clearContractAbiForExtention( + contractExcAddress, contractExcAddress, contractExcKey, blockingStubFull); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_VALIDATE_ERROR")); + Assert.assertThat( + transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Contract validate error : Contract not exists")); } - - @Test(enabled = true, description = "Clear a uninitialized account", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Clear a uninitialized account", + groups = {"contract", "daily"}) public void testClearAbi005() { ECKey ecKeyN = new ECKey(Utils.getRandom()); - byte[] contractExcAddressN = ecKeyN.getAddress(); - String contractExcKeyN = ByteArray.toHexString(ecKeyN.getPrivKeyBytes()); - - TransactionExtention transactionExtention = PublicMethod - .clearContractAbiForExtention(contractExcAddressN, contractExcAddress, contractExcKey, - blockingStubFull); - Assert.assertThat(transactionExtention.getResult().getCode().toString(), + byte[] contractExcAddressN = ecKeyN.getAddress(); + String contractExcKeyN = ByteArray.toHexString(ecKeyN.getPrivKeyBytes()); + + TransactionExtention transactionExtention = + PublicMethod.clearContractAbiForExtention( + contractExcAddressN, contractExcAddress, contractExcKey, blockingStubFull); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), containsString("CONTRACT_VALIDATE_ERROR")); - Assert.assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + Assert.assertThat( + transactionExtention.getResult().getMessage().toStringUtf8(), containsString("Contract validate error : Contract not exists")); - } - @Test(enabled = true, description = "Clear a not meet the rules address", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Clear a not meet the rules address", + groups = {"contract", "daily"}) public void testClearAbi006() { byte[] fakeAddress = "412B5D".getBytes(); - TransactionExtention transactionExtention = PublicMethod - .clearContractAbiForExtention(fakeAddress, contractExcAddress, contractExcKey, - blockingStubFull); - Assert - .assertThat(transactionExtention.getResult().getCode().toString(), - containsString("CONTRACT_VALIDATE_ERROR")); - Assert - .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), - containsString("Contract validate error : Contract not exists")); - byte[] fakeAddress1 = "412B5D3405B2D26767C9C09886D53DEAFF6EB718AC111".getBytes(); - - TransactionExtention transactionExtention1 = PublicMethod - .clearContractAbiForExtention(fakeAddress1, contractExcAddress, contractExcKey, - blockingStubFull); - Assert - .assertThat(transactionExtention1.getResult().getCode().toString(), - containsString("CONTRACT_VALIDATE_ERROR")); - Assert - .assertThat(transactionExtention1.getResult().getMessage().toStringUtf8(), - containsString("Contract validate error : Contract not exists")); - + TransactionExtention transactionExtention = + PublicMethod.clearContractAbiForExtention( + fakeAddress, contractExcAddress, contractExcKey, blockingStubFull); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_VALIDATE_ERROR")); + Assert.assertThat( + transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Contract validate error : Contract not exists")); + byte[] fakeAddress1 = "412B5D3405B2D26767C9C09886D53DEAFF6EB718AC111".getBytes(); + TransactionExtention transactionExtention1 = + PublicMethod.clearContractAbiForExtention( + fakeAddress1, contractExcAddress, contractExcKey, blockingStubFull); + Assert.assertThat( + transactionExtention1.getResult().getCode().toString(), + containsString("CONTRACT_VALIDATE_ERROR")); + Assert.assertThat( + transactionExtention1.getResult().getMessage().toStringUtf8(), + containsString("Contract validate error : Contract not exists")); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); - PublicMethod.freeResource(contractExcAddress1, contractExcKey1, testNetAccountAddress, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + PublicMethod.freeResource( + contractExcAddress1, contractExcKey1, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi002.java index adaebdd3..aeb7965b 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi002.java @@ -17,17 +17,18 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ClearAbi002 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -35,44 +36,55 @@ public class ClearAbi002 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = true, description = "Clear a contract with ABI created by itself", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Clear a contract with ABI created by itself", + groups = {"contract", "daily"}) public void testClearAbi() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); @@ -80,20 +92,20 @@ public void testClearAbi() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = PublicMethod - .clearContractAbi(contractAddress, contractExcAddress, contractExcKey, - blockingStubFull); + String txid = + PublicMethod.clearContractAbi( + contractAddress, contractExcAddress, contractExcKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -104,20 +116,15 @@ public void testClearAbi() { Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi003.java index 6d204f37..da8a510e 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi003.java @@ -17,17 +17,18 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ClearAbi003 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -35,44 +36,55 @@ public class ClearAbi003 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = true, description = "Clear a contract without ABI", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Clear a contract without ABI", + groups = {"contract", "daily"}) public void testClearAbi() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, "[]", code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + "[]", + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); @@ -80,20 +92,20 @@ public void testClearAbi() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = PublicMethod - .clearContractAbi(contractAddress, contractExcAddress, contractExcKey, - blockingStubFull); + String txid = + PublicMethod.clearContractAbi( + contractAddress, contractExcAddress, contractExcKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -103,20 +115,15 @@ public void testClearAbi() { Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi004.java index 7bbf6e15..a7752e33 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi004.java @@ -14,17 +14,18 @@ import org.tron.api.WalletGrpc; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ClearAbi004 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -32,59 +33,55 @@ public class ClearAbi004 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = true, description = "Clear a account address", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Clear a account address", + groups = {"contract", "daily"}) public void testClearAbi() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionExtention transactionExtention = PublicMethod - .clearContractAbiForExtention(contractExcAddress, contractExcAddress, contractExcKey, - blockingStubFull); - Assert - .assertThat(transactionExtention.getResult().getCode().toString(), - containsString("CONTRACT_VALIDATE_ERROR")); - Assert - .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), - containsString("Contract validate error : Contract not exists")); - - + TransactionExtention transactionExtention = + PublicMethod.clearContractAbiForExtention( + contractExcAddress, contractExcAddress, contractExcKey, blockingStubFull); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_VALIDATE_ERROR")); + Assert.assertThat( + transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Contract validate error : Contract not exists")); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi005.java index 52b29d3c..cbdf7fd4 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi005.java @@ -21,17 +21,18 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ClearAbi005 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -39,76 +40,96 @@ public class ClearAbi005 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = true, description = "Clear a contract created by create2 (without ABI)", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Clear a contract created by create2 (without ABI)", + groups = {"contract", "daily"}) public void testClearAbi() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/ClearAbi005.sol"; - String contractName = "Factory"; + String filePath = "src/test/resources/soliditycode/ClearAbi005.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String contractName1 = "TestConstract"; + String contractName1 = "TestConstract"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - String txid = ""; - String num = "\"" + code1 + "\"" + "," + 1; - txid = PublicMethod - .triggerContract(contractAddress, - "deploy(bytes,uint256)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + "," + 1; + txid = + PublicMethod.triggerContract( + contractAddress, + "deploy(bytes,uint256)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -118,12 +139,12 @@ public void testClearAbi() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -134,38 +155,35 @@ public void testClearAbi() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() - .toByteArray(); - String returnAddress = Base58.encode58Check(returnAddressBytes); + byte[] returnAddressBytes = + infoById.get().getInternalTransactions(0).getTransferToAddress().toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); SmartContract smartContract = PublicMethod.getContract(returnAddressBytes, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - TransactionExtention transactionExtention = PublicMethod - .clearContractAbiForExtention(returnAddressBytes, contractExcAddress, contractExcKey, - blockingStubFull); - Assert - .assertThat(transactionExtention.getResult().getCode().toString(), - containsString("CONTRACT_VALIDATE_ERROR")); - Assert - .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), - containsString("is not the owner of the contract")); + TransactionExtention transactionExtention = + PublicMethod.clearContractAbiForExtention( + returnAddressBytes, contractExcAddress, contractExcKey, blockingStubFull); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_VALIDATE_ERROR")); + Assert.assertThat( + transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("is not the owner of the contract")); smartContract = PublicMethod.getContract(returnAddressBytes, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); } - - /** - * testClearAbitestClearAbi constructor. - */ + /** testClearAbitestClearAbi constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java index 33042c78..db8713f2 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java @@ -14,17 +14,18 @@ import org.tron.api.WalletGrpc; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ClearAbi006 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -35,55 +36,55 @@ public class ClearAbi006 extends TronBaseTest { String contractExcKey1 = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = true, description = "Clear a uninitialized account", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Clear a uninitialized account", + groups = {"contract", "daily"}) public void testClearAbi() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionExtention transactionExtention = PublicMethod - .clearContractAbiForExtention(contractExcAddress1, contractExcAddress, contractExcKey, - blockingStubFull); - Assert.assertThat(transactionExtention.getResult().getCode().toString(), + TransactionExtention transactionExtention = + PublicMethod.clearContractAbiForExtention( + contractExcAddress1, contractExcAddress, contractExcKey, blockingStubFull); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), containsString("CONTRACT_VALIDATE_ERROR")); - Assert.assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + Assert.assertThat( + transactionExtention.getResult().getMessage().toStringUtf8(), containsString("Contract validate error : Contract not exists")); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java index 712bdaea..f8cf419b 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java @@ -14,17 +14,18 @@ import org.tron.api.WalletGrpc; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ClearAbi007 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -35,70 +36,66 @@ public class ClearAbi007 extends TronBaseTest { String contractExcKey1 = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = true, description = "Clear a not meet the rules address", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Clear a not meet the rules address", + groups = {"contract", "daily"}) public void testClearAbi() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - byte[] fakeAddress = "412B5D".getBytes(); - TransactionExtention transactionExtention = PublicMethod - .clearContractAbiForExtention(fakeAddress, contractExcAddress, contractExcKey, - blockingStubFull); - Assert - .assertThat(transactionExtention.getResult().getCode().toString(), - containsString("CONTRACT_VALIDATE_ERROR")); - Assert - .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), - containsString("Contract validate error : Contract not exists")); - byte[] fakeAddress1 = "412B5D3405B2D26767C9C09886D53DEAFF6EB718AC111".getBytes(); - - TransactionExtention transactionExtention1 = PublicMethod - .clearContractAbiForExtention(fakeAddress1, contractExcAddress, contractExcKey, - blockingStubFull); - Assert - .assertThat(transactionExtention1.getResult().getCode().toString(), - containsString("CONTRACT_VALIDATE_ERROR")); - Assert - .assertThat(transactionExtention1.getResult().getMessage().toStringUtf8(), - containsString("Contract validate error : Contract not exists")); - + byte[] fakeAddress = "412B5D".getBytes(); + TransactionExtention transactionExtention = + PublicMethod.clearContractAbiForExtention( + fakeAddress, contractExcAddress, contractExcKey, blockingStubFull); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_VALIDATE_ERROR")); + Assert.assertThat( + transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Contract validate error : Contract not exists")); + byte[] fakeAddress1 = "412B5D3405B2D26767C9C09886D53DEAFF6EB718AC111".getBytes(); + TransactionExtention transactionExtention1 = + PublicMethod.clearContractAbiForExtention( + fakeAddress1, contractExcAddress, contractExcKey, blockingStubFull); + Assert.assertThat( + transactionExtention1.getResult().getCode().toString(), + containsString("CONTRACT_VALIDATE_ERROR")); + Assert.assertThat( + transactionExtention1.getResult().getMessage().toStringUtf8(), + containsString("Contract validate error : Contract not exists")); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi008.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi008.java index 036f5f61..ec77e87a 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi008.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi008.java @@ -17,17 +17,18 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ClearAbi008 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -35,45 +36,56 @@ public class ClearAbi008 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = true, description = "Clear a contract with ABI created by itself," - + "clear a contract by itself again", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Clear a contract with ABI created by itself," + "clear a contract by itself again", + groups = {"contract", "daily"}) public void testClearAbi() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); @@ -81,20 +93,20 @@ public void testClearAbi() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = PublicMethod - .clearContractAbi(contractAddress, contractExcAddress, contractExcKey, - blockingStubFull); + String txid = + PublicMethod.clearContractAbi( + contractAddress, contractExcAddress, contractExcKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -104,9 +116,9 @@ public void testClearAbi() { Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - String txid1 = PublicMethod - .clearContractAbi(contractAddress, contractExcAddress, contractExcKey, - blockingStubFull); + String txid1 = + PublicMethod.clearContractAbi( + contractAddress, contractExcAddress, contractExcKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); @@ -116,20 +128,15 @@ public void testClearAbi() { Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/NoAbi009.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/NoAbi009.java index 663f97ff..8ed32930 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/NoAbi009.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/NoAbi009.java @@ -24,18 +24,18 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class NoAbi009 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); @@ -45,45 +45,60 @@ public class NoAbi009 extends TronBaseTest { String contractExcKey1 = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress1, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress1, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "clearabi contract with event", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "clearabi contract with event", + groups = {"contract", "daily"}) public void testNoAbi001() { String filePath = "src/test/resources/soliditycode/NoAbi001.sol"; - String contractName = "testNoABiContract"; + String contractName = "testNoABiContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); @@ -91,124 +106,178 @@ public void testNoAbi001() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = PublicMethod - .clearContractAbi(contractAddress, contractExcAddress, contractExcKey, - blockingStubFull); + String txid = + PublicMethod.clearContractAbi( + contractAddress, contractExcAddress, contractExcKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - // getcontract + // getcontract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); System.out.println("smartContract:" + smartContract.toString()); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - // getcontractinfo - SmartContractDataWrapper contractInfo = PublicMethod - .getContractInfo(contractAddress, blockingStubFull); + // getcontractinfo + SmartContractDataWrapper contractInfo = + PublicMethod.getContractInfo(contractAddress, blockingStubFull); System.out.println("contractInfo.toString():" + contractInfo.toString()); Assert.assertTrue(contractInfo.getSmartContract().getAbi().toString().isEmpty()); Assert.assertTrue(contractInfo.getSmartContract().getName().equalsIgnoreCase(contractName)); Assert.assertTrue(contractInfo.getRuntimecode().size() > 0); Assert.assertFalse(contractInfo.getSmartContract().getBytecode().toString().isEmpty()); - // triggerconstantcontract fullnode - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testTrigger()", "#", false, 0, - 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + // triggerconstantcontract fullnode + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testTrigger()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("Code = " + transactionExtention.getResult().getCode()); logger.info("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); - Assert.assertThat(transactionExtention.getResult().getCode().toString(), - containsString("SUCCESS")); - Assert.assertEquals(3, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - // triggercontract - txid = PublicMethod - .triggerContract(contractAddress, "testTrigger()", "#", false, 0, maxFeeLimit, "0", 0, - contractExcAddress, contractExcKey, blockingStubFull); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), containsString("SUCCESS")); + Assert.assertEquals( + 3, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + // triggercontract + txid = + PublicMethod.triggerContract( + contractAddress, + "testTrigger()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - Long returnNumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Long returnNumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(3 == returnNumber); - List retList = PublicMethod - .getStrings(infoById.get().getLogList().get(0).getData().toByteArray()); + List retList = + PublicMethod.getStrings(infoById.get().getLogList().get(0).getData().toByteArray()); logger.info("retList:" + retList.toString()); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(1)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); - Assert.assertEquals(WalletClient.encode58Check(contractExcAddress),addressFinal); - Long actualNum = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); - Assert.assertEquals(returnNumber,actualNum); - // triggerconstantcontract solidity + Assert.assertEquals(WalletClient.encode58Check(contractExcAddress), addressFinal); + Long actualNum = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + Assert.assertEquals(returnNumber, actualNum); + // triggerconstantcontract solidity PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - transactionExtention = PublicMethod - .triggerConstantContractForExtentionOnSolidity(contractAddress, "testTrigger()", "#", - false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubSolidity); + transactionExtention = + PublicMethod.triggerConstantContractForExtentionOnSolidity( + contractAddress, + "testTrigger()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubSolidity); logger.info("Code = " + transactionExtention.getResult().getCode()); logger.info("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); - Assert.assertThat(transactionExtention.getResult().getCode().toString(), - containsString("SUCCESS")); - Assert.assertEquals(4, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), containsString("SUCCESS")); + Assert.assertEquals( + 4, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); } - @Test(enabled = true, description = "create2 contract with event", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "create2 contract with event", + groups = {"contract", "daily"}) public void testNoAbi002() { String filePath = "./src/test/resources/soliditycode/NoAbi002.sol"; - String contractName = "Factory"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, contractExcKey1, - contractExcAddress1, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + contractExcKey1, + contractExcAddress1, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); } TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); - byte[] factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + byte[] factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); contractName = "testNoABiContract"; retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testNoABiContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; - String param = "\"" + testNoABiContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, Long.valueOf(0), - 1000000000L, "0", 0, contractExcAddress1, contractExcKey1, - blockingStubFull); + String testNoABiContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + String param = "\"" + testNoABiContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + Long.valueOf(0), + 1000000000L, + "0", + 0, + contractExcAddress1, + contractExcKey1, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); @@ -218,62 +287,85 @@ public void testNoAbi002() { } // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - byte[] tmpAddress = new byte[20]; + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); - byte[] testNoABiContractAddress = WalletClient.decodeFromBase58Check(addressFinal); - // getcontract + byte[] testNoABiContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + // getcontract smartContract = PublicMethod.getContract(testNoABiContractAddress, blockingStubFull); System.out.println("smartContract:" + smartContract.toString()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); - // Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + // Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - // getcontractinfo - SmartContractDataWrapper contractInfo = PublicMethod - .getContractInfo(testNoABiContractAddress, blockingStubFull); + // getcontractinfo + SmartContractDataWrapper contractInfo = + PublicMethod.getContractInfo(testNoABiContractAddress, blockingStubFull); System.out.println("contractInfo.toString():" + contractInfo.toString()); Assert.assertTrue(contractInfo.getSmartContract().getAbi().toString().isEmpty()); - // Assert.assertTrue(contractInfo.getSmartContract().getName().equalsIgnoreCase(contractName)); + // Assert.assertTrue(contractInfo.getSmartContract().getName().equalsIgnoreCase(contractName)); Assert.assertTrue(contractInfo.getRuntimecode().size() > 0); Assert.assertFalse(contractInfo.getSmartContract().getBytecode().toString().isEmpty()); - // triggerconstantcontract fullnode - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(testNoABiContractAddress, "plusOne()", "#", false, 0, - 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + // triggerconstantcontract fullnode + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + testNoABiContractAddress, + "plusOne()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("Code = " + transactionExtention.getResult().getCode()); logger.info("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); - Assert.assertThat(transactionExtention.getResult().getCode().toString(), - containsString("SUCCESS")); - Assert.assertEquals(1, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - // triggercontract - String txid = PublicMethod - .triggerContract(testNoABiContractAddress, "plusOne()", "#", false, 0, maxFeeLimit, "0", 0, - contractExcAddress, contractExcKey, blockingStubFull); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), containsString("SUCCESS")); + Assert.assertEquals( + 1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + // triggercontract + String txid = + PublicMethod.triggerContract( + testNoABiContractAddress, + "plusOne()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - Long returnNumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Long returnNumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnNumber); - retList = PublicMethod - .getStrings(infoById.get().getLogList().get(0).getData().toByteArray()); + retList = PublicMethod.getStrings(infoById.get().getLogList().get(0).getData().toByteArray()); logger.info("retList:" + retList.toString()); tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(1)), 12, tmpAddress, 0, 20); @@ -281,35 +373,43 @@ public void testNoAbi002() { logger.info("address_hex: " + addressHex); addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); - Assert.assertEquals(WalletClient.encode58Check(contractExcAddress),addressFinal); - Long actualNum = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); - Assert.assertEquals(returnNumber,actualNum); - // triggerconstantcontract solidity + Assert.assertEquals(WalletClient.encode58Check(contractExcAddress), addressFinal); + Long actualNum = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + Assert.assertEquals(returnNumber, actualNum); + // triggerconstantcontract solidity PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - transactionExtention = PublicMethod - .triggerConstantContractForExtentionOnSolidity(testNoABiContractAddress, "plusOne()", "#", - false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubSolidity); + transactionExtention = + PublicMethod.triggerConstantContractForExtentionOnSolidity( + testNoABiContractAddress, + "plusOne()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubSolidity); logger.info("Code = " + transactionExtention.getResult().getCode()); logger.info("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); - Assert.assertThat(transactionExtention.getResult().getCode().toString(), - containsString("SUCCESS")); - Assert.assertEquals(2, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), containsString("SUCCESS")); + Assert.assertEquals( + 2, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); - PublicMethod.freeResource(contractExcAddress1, contractExcKey1, testNetAccountAddress, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + PublicMethod.freeResource( + contractExcAddress1, contractExcKey1, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/contractselfdestruct/KillContract01.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/contractselfdestruct/KillContract01.java index 3669b54d..cd2800c3 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/contractselfdestruct/KillContract01.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/contractselfdestruct/KillContract01.java @@ -1,39 +1,36 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.contractselfdestruct; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.AccountResourceMessage; import org.tron.api.GrpcAPI.TransactionExtention; -import org.tron.protos.Protocol; import org.tron.protos.Protocol.Account; -import org.tron.protos.Protocol.Transaction.Result.contractResult; import org.tron.protos.Protocol.TransactionInfo; import org.tron.protos.Protocol.TransactionInfo.code; import org.tron.protos.contract.SmartContractOuterClass; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; - -import java.util.HashMap; -import java.util.List; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.Flaky; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -@Flaky(reason = "Selfdestruct timing between blocks", - since = "2026-04-03") +@Flaky(reason = "Selfdestruct timing between blocks", since = "2026-04-03") public class KillContract01 extends TronBaseTest { - private String testFoundationKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private String testFoundationKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); - private Long maxFeeLimit = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.maxFeeLimit"); + private Long maxFeeLimit = + Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit"); ECKey ecKeyExc = new ECKey(Utils.getRandom()); byte[] excAdd = ecKeyExc.getAddress(); String excKey = ByteArray.toHexString(ecKeyExc.getPrivKeyBytes()); @@ -53,25 +50,29 @@ public class KillContract01 extends TronBaseTest { private static final long TotalSupply = 1000L; private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - /** - * constructor. - */ + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(excKey); PublicMethod.printAddress(targetKey); PublicMethod.printAddress(delegateReceiverEckeyKey); - channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); Assert.assertTrue(PublicMethod.sendcoin(excAdd, 100000_000000L, - testFoundationAddress, testFoundationKey, blockingStubFull)); + channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); + Assert.assertTrue( + PublicMethod.sendcoin( + excAdd, 100000_000000L, testFoundationAddress, testFoundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(delegateReceiverAdd, 1_000000L, - testFoundationAddress, testFoundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + delegateReceiverAdd, + 1_000000L, + testFoundationAddress, + testFoundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/killcontract01.sol"; @@ -79,143 +80,264 @@ public void beforeClass() { HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - contractAddressD = PublicMethod - .deployContractFallback(contractName, abi, code, "", maxFeeLimit, 0L, - 100, null, excKey, - excAdd, blockingStubFull); + contractAddressD = + PublicMethod.deployContractFallback( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + excKey, + excAdd, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(contractAddressD, blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(contractAddressD, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod - .createAssetIssue(excAdd, tokenName, TotalSupply, 1, 1000, start, end, 1, - description, url, 100000L, 100000L, 3L, 30L, excKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.createAssetIssue( + excAdd, + tokenName, + TotalSupply, + 1, + 1000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 3L, + 30L, + excKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethod.queryAccount(excAdd, blockingStubFull).getAssetIssuedID(); logger.info("The token name: " + tokenName); logger.info("The token ID: " + assetAccountId.toStringUtf8()); - //init sr and vote array + // init sr and vote array String methedStr = "initArray()"; - String txid = PublicMethod.triggerContract(contractAddressD, methedStr, "", - false, 0, maxFeeLimit, testFoundationAddress, testFoundationKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddressD, + methedStr, + "", + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo info = PublicMethod.getTransactionInfoById(txid,blockingStubFull).get(); - logger.info("before class initArray: " +info); + TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + logger.info("before class initArray: " + info); Assert.assertEquals(TransactionInfo.code.SUCESS, info.getResult()); } - @Test(enabled = true, description = "getPredictedAddress,sendcoin,transferAsset,and then " + - "make create2,freezev2,delegateResource,delegateResource,unfreezeBalanceV2,cancelAllUnfreezeV2,vote,kill " + - "into one tranaction", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "getPredictedAddress,sendcoin,transferAsset,and then " + + "make create2,freezev2,delegateResource,delegateResource,unfreezeBalanceV2,cancelAl" + + "lUnfreezeV2,vote,kill " + + "into one tranaction", + groups = {"contract", "daily"}) void kill01() { String methedStr = "getPredictedAddress(bytes32)"; String argsStr = "1122"; TransactionExtention transactionExtention = - PublicMethod.triggerConstantContractForExtention(contractAddressD, methedStr, argsStr, - false, 0, maxFeeLimit, "0", 0, excAdd, excKey, blockingStubFull); + PublicMethod.triggerConstantContractForExtention( + contractAddressD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "0", + 0, + excAdd, + excKey, + blockingStubFull); logger.info("getPredictedAddress transactionExtention: " + transactionExtention.toString()); - String create2Add41 = "41" + ByteArray.toHexString(transactionExtention.getConstantResult(0) - .toByteArray()).substring(24); + String create2Add41 = + "41" + + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()) + .substring(24); byte[] create2AddBytes = ByteArray.fromHexString(create2Add41); String create2Add58 = Base58.encode58Check(create2AddBytes); - Assert.assertTrue(PublicMethod.sendcoin(create2AddBytes, 2001000000L, - testFoundationAddress, testFoundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.transferAsset(create2AddBytes, - assetAccountId.toByteArray(), 100L, excAdd, excKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + create2AddBytes, + 2001000000L, + testFoundationAddress, + testFoundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + create2AddBytes, assetAccountId.toByteArray(), 100L, excAdd, excKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); methedStr = "complexCreateKill(bytes32,address,address)"; - String args = argsStr +",\"" + target58 + "\",\"" + delegateReceiver58 + "\""; - String txid = PublicMethod.triggerContract(contractAddressD, methedStr, args, - false, 0, maxFeeLimit, testFoundationAddress, testFoundationKey, blockingStubFull); + String args = argsStr + ",\"" + target58 + "\",\"" + delegateReceiver58 + "\""; + String txid = + PublicMethod.triggerContract( + contractAddressD, + methedStr, + args, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo info = PublicMethod.getTransactionInfoById(txid,blockingStubFull).get(); - logger.info("kill01: " +info); + TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + logger.info("kill01: " + info); Assert.assertEquals(code.SUCESS, info.getResult()); Assert.assertEquals(23, info.getInternalTransactionsCount()); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(create2AddBytes, blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(create2AddBytes, blockingStubFull); Account create2Account = PublicMethod.queryAccount(create2AddBytes, blockingStubFull); logger.info("kill01 create2Account: " + create2Account.toString()); logger.info("kill01 smartContract: " + smartContract.toString()); Assert.assertEquals("", smartContract.toString()); Assert.assertEquals("", create2Account.toString()); - Account targetAccount = PublicMethod.queryAccount(targetAdd,blockingStubFull); - Account delegateReceiverAccount = PublicMethod.queryAccount(delegateReceiverAdd,blockingStubFull); + Account targetAccount = PublicMethod.queryAccount(targetAdd, blockingStubFull); + Account delegateReceiverAccount = + PublicMethod.queryAccount(delegateReceiverAdd, blockingStubFull); Assert.assertEquals(1801000000L, targetAccount.getBalance()); Assert.assertEquals(100000000L, targetAccount.getFrozenV2(0).getAmount()); Assert.assertEquals(100000000L, targetAccount.getFrozenV2(1).getAmount()); Assert.assertEquals(0, targetAccount.getVotesList().size()); - long targetAssetCount = PublicMethod.getAssetIssueValue(targetAdd, - assetAccountId, blockingStubFull); + long targetAssetCount = + PublicMethod.getAssetIssueValue(targetAdd, assetAccountId, blockingStubFull); Assert.assertEquals(100, targetAssetCount); Assert.assertEquals(1_000000L, delegateReceiverAccount.getBalance()); - AccountResourceMessage delegateReceiverResource = PublicMethod.getAccountResource(delegateReceiverAdd, blockingStubFull); + AccountResourceMessage delegateReceiverResource = + PublicMethod.getAccountResource(delegateReceiverAdd, blockingStubFull); Assert.assertEquals(0, delegateReceiverResource.getNetLimit()); Assert.assertEquals(0, delegateReceiverResource.getEnergyLimit()); - AccountResourceMessage targetResource = PublicMethod.getAccountResource(targetAdd, blockingStubFull); + AccountResourceMessage targetResource = + PublicMethod.getAccountResource(targetAdd, blockingStubFull); Assert.assertNotEquals(0, targetResource.getNetLimit()); Assert.assertNotEquals(0, targetResource.getEnergyLimit()); - long delegateReceiverAssetCount = PublicMethod.getAssetIssueValue(delegateReceiverAdd, - assetAccountId, blockingStubFull); + long delegateReceiverAssetCount = + PublicMethod.getAssetIssueValue(delegateReceiverAdd, assetAccountId, blockingStubFull); Assert.assertEquals(0, delegateReceiverAssetCount); - long execAssetCount = PublicMethod.getAssetIssueValue(excAdd, - assetAccountId, blockingStubFull); + long execAssetCount = PublicMethod.getAssetIssueValue(excAdd, assetAccountId, blockingStubFull); Assert.assertEquals(897, execAssetCount); } - @Test(enabled = true, description = "getPredictedAddress,sendcoin,transferAsset,and then " + - "make create2,freezev2,delegateResource,delegateResource,unfreezeBalanceV2,cancelAllUnfreezeV2," + - "vote into one transaction, and kill in another transaction. and can not static call kill", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "getPredictedAddress,sendcoin,transferAsset,and then " + + "make create2,freezev2,delegateResource,delegateResource,unfreezeBalanceV2,cancelAl" + + "lUnfreezeV2," + + "vote into one transaction, and kill in another transaction. and can not static cal" + + "l kill", + groups = {"contract", "daily"}) void kill02() { String methedStr = "getPredictedAddress(bytes32)"; String argsStr = "1122"; TransactionExtention transactionExtention = - PublicMethod.triggerConstantContractForExtention(contractAddressD, methedStr, argsStr, - false, 0, maxFeeLimit, "0", 0, excAdd, excKey, blockingStubFull); + PublicMethod.triggerConstantContractForExtention( + contractAddressD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "0", + 0, + excAdd, + excKey, + blockingStubFull); logger.info("getPredictedAddress transactionExtention: " + transactionExtention.toString()); - String create2Add41 = "41" + ByteArray.toHexString(transactionExtention.getConstantResult(0) - .toByteArray()).substring(24); + String create2Add41 = + "41" + + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()) + .substring(24); byte[] create2AddBytes = ByteArray.fromHexString(create2Add41); String create2Add58 = Base58.encode58Check(create2AddBytes); - Assert.assertTrue(PublicMethod.sendcoin(create2AddBytes, 2001000000L, - testFoundationAddress, testFoundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.transferAsset(create2AddBytes, - assetAccountId.toByteArray(), 100L, excAdd, excKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + create2AddBytes, + 2001000000L, + testFoundationAddress, + testFoundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + create2AddBytes, assetAccountId.toByteArray(), 100L, excAdd, excKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); methedStr = "complexCreate(bytes32,address,address)"; - String args = argsStr +",\"" + target58 + "\",\"" + delegateReceiver58 + "\""; - String txid1 = PublicMethod.triggerContract(contractAddressD, methedStr, args, - false, 0, maxFeeLimit, testFoundationAddress, testFoundationKey, blockingStubFull); + String args = argsStr + ",\"" + target58 + "\",\"" + delegateReceiver58 + "\""; + String txid1 = + PublicMethod.triggerContract( + contractAddressD, + methedStr, + args, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - //can not static call kill + // can not static call kill methedStr = "staticcallSelfdestruct(address,address)"; args = "\"" + create2Add58 + "\"," + "\"" + target58 + "\""; - String txid22 = PublicMethod.triggerContract(contractAddressD, methedStr, args, - false, 0, maxFeeLimit, testFoundationAddress, testFoundationKey, blockingStubFull); + String txid22 = + PublicMethod.triggerContract( + contractAddressD, + methedStr, + args, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo info22 = PublicMethod.getTransactionInfoById(txid22,blockingStubFull).get(); - logger.info("kill02-info22: " +info22); + TransactionInfo info22 = PublicMethod.getTransactionInfoById(txid22, blockingStubFull).get(); + logger.info("kill02-info22: " + info22); Assert.assertEquals(code.SUCESS, info22.getResult()); methedStr = "killme(address)"; args = "\"" + target58 + "\""; - String txid2 = PublicMethod.triggerContract(create2AddBytes, methedStr, args, - false, 0, maxFeeLimit, testFoundationAddress, testFoundationKey, blockingStubFull); + String txid2 = + PublicMethod.triggerContract( + create2AddBytes, + methedStr, + args, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - //check result - TransactionInfo info1 = PublicMethod.getTransactionInfoById(txid1,blockingStubFull).get(); - logger.info("kill02: " +info1); + // check result + TransactionInfo info1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull).get(); + logger.info("kill02: " + info1); Assert.assertEquals(code.SUCESS, info1.getResult()); Assert.assertEquals(21, info1.getInternalTransactionsCount()); TransactionInfo info2 = PublicMethod.getTransactionInfoById(txid2, blockingStubFull).get(); - logger.info("kill02 info2 : " +info2); + logger.info("kill02 info2 : " + info2); Assert.assertEquals(code.SUCESS, info2.getResult()); Assert.assertEquals(1, info2.getInternalTransactionsCount()); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(create2AddBytes, blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(create2AddBytes, blockingStubFull); Account create2Account = PublicMethod.queryAccount(create2AddBytes, blockingStubFull); logger.info("kill02 create2Account: " + create2Account.toString()); logger.info("kill02 smartContract: " + smartContract.toString()); @@ -226,32 +348,38 @@ void kill02() { Assert.assertEquals(0, create2Account.getFrozenV2(1).getAmount()); Assert.assertEquals(0, create2Account.getVotesList().size()); - Account targetAccount = PublicMethod.queryAccount(targetAdd,blockingStubFull); - Account delegateReceiverAccount = PublicMethod.queryAccount(delegateReceiverAdd,blockingStubFull); - Assert.assertEquals(1801000000L*2, targetAccount.getBalance()); - Assert.assertEquals(100000000L*2, targetAccount.getFrozenV2(0).getAmount()); - Assert.assertEquals(100000000L*2, targetAccount.getFrozenV2(1).getAmount()); + Account targetAccount = PublicMethod.queryAccount(targetAdd, blockingStubFull); + Account delegateReceiverAccount = + PublicMethod.queryAccount(delegateReceiverAdd, blockingStubFull); + Assert.assertEquals(1801000000L * 2, targetAccount.getBalance()); + Assert.assertEquals(100000000L * 2, targetAccount.getFrozenV2(0).getAmount()); + Assert.assertEquals(100000000L * 2, targetAccount.getFrozenV2(1).getAmount()); Assert.assertEquals(0, targetAccount.getVotesList().size()); - long targetAssetCount = PublicMethod.getAssetIssueValue(targetAdd, - assetAccountId, blockingStubFull); - Assert.assertEquals(100*2, targetAssetCount); + long targetAssetCount = + PublicMethod.getAssetIssueValue(targetAdd, assetAccountId, blockingStubFull); + Assert.assertEquals(100 * 2, targetAssetCount); Assert.assertEquals(1_000000L, delegateReceiverAccount.getBalance()); - AccountResourceMessage delegateReceiverResource = PublicMethod.getAccountResource(delegateReceiverAdd, blockingStubFull); + AccountResourceMessage delegateReceiverResource = + PublicMethod.getAccountResource(delegateReceiverAdd, blockingStubFull); Assert.assertEquals(0, delegateReceiverResource.getNetLimit()); Assert.assertEquals(0, delegateReceiverResource.getEnergyLimit()); - AccountResourceMessage targetResource = PublicMethod.getAccountResource(targetAdd, blockingStubFull); + AccountResourceMessage targetResource = + PublicMethod.getAccountResource(targetAdd, blockingStubFull); Assert.assertNotEquals(0, targetResource.getNetLimit()); Assert.assertNotEquals(0, targetResource.getEnergyLimit()); - long delegateReceiverAssetCount = PublicMethod.getAssetIssueValue(delegateReceiverAdd, - assetAccountId, blockingStubFull); + long delegateReceiverAssetCount = + PublicMethod.getAssetIssueValue(delegateReceiverAdd, assetAccountId, blockingStubFull); Assert.assertEquals(0, delegateReceiverAssetCount); - long execAssetCount = PublicMethod.getAssetIssueValue(excAdd, - assetAccountId, blockingStubFull); + long execAssetCount = PublicMethod.getAssetIssueValue(excAdd, assetAccountId, blockingStubFull); Assert.assertEquals(797, execAssetCount); } - @Test(enabled = true, description = "getPredictedAddress,sendcoin,transferAsset,and then " + - "make create2,freezev2,kill into one transaction, and kill through 3 call", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "getPredictedAddress,sendcoin,transferAsset,and then " + + "make create2,freezev2,kill into one transaction, and kill through 3 call", + groups = {"contract", "daily"}) void kill03() { ECKey targetEckey = new ECKey(Utils.getRandom()); byte[] targetAdd03 = targetEckey.getAddress(); @@ -262,21 +390,42 @@ void kill03() { HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); String code1 = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - byte[] contractC = PublicMethod - .deployContractFallback(contractName, abi, code1, "", maxFeeLimit, 0L, - 100, null, excKey, excAdd, blockingStubFull); + byte[] contractC = + PublicMethod.deployContractFallback( + contractName, + abi, + code1, + "", + maxFeeLimit, + 0L, + 100, + null, + excKey, + excAdd, + blockingStubFull); String contractCBase58 = Base58.encode58Check(contractC); contractName = "B"; retMap = PublicMethod.getBycodeAbi(filePath, contractName); code1 = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - byte[] contractB = PublicMethod - .deployContractFallback(contractName, abi, code1, "", maxFeeLimit, 0L, - 100, null, excKey, excAdd, blockingStubFull); + byte[] contractB = + PublicMethod.deployContractFallback( + contractName, + abi, + code1, + "", + maxFeeLimit, + 0L, + 100, + null, + excKey, + excAdd, + blockingStubFull); String contractBBase58 = Base58.encode58Check(contractB); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(contractC, blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(contractC, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); @@ -287,27 +436,56 @@ void kill03() { String methedStr = "getPredictedAddress(bytes32)"; String argsStr = "1123"; TransactionExtention transactionExtention = - PublicMethod.triggerConstantContractForExtention(contractAddressD, methedStr, argsStr, - false, 0, maxFeeLimit, "0", 0, excAdd, excKey, blockingStubFull); + PublicMethod.triggerConstantContractForExtention( + contractAddressD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "0", + 0, + excAdd, + excKey, + blockingStubFull); - logger.info("kill03 getPredictedAddress transactionExtention: " + transactionExtention.toString()); - String create2Add41 = "41" + ByteArray.toHexString(transactionExtention.getConstantResult(0) - .toByteArray()).substring(24); + logger.info( + "kill03 getPredictedAddress transactionExtention: " + transactionExtention.toString()); + String create2Add41 = + "41" + + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()) + .substring(24); byte[] create2AddBytes = ByteArray.fromHexString(create2Add41); String create2Add58 = Base58.encode58Check(create2AddBytes); - Assert.assertTrue(PublicMethod.sendcoin(create2AddBytes, 2001000000L, - testFoundationAddress, testFoundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.transferAsset(create2AddBytes, - assetAccountId.toByteArray(), 100L, excAdd, excKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + create2AddBytes, + 2001000000L, + testFoundationAddress, + testFoundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + create2AddBytes, assetAccountId.toByteArray(), 100L, excAdd, excKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); methedStr = "createKill(bytes32,address,address,address)"; - String args = argsStr +",\"" + contractCBase58 + "\",\"" + contractBBase58 + "\",\"" +target03 + "\"" ; - String txid1 = PublicMethod.triggerContract(contractAddressD, methedStr, args, - false, 0, maxFeeLimit, testFoundationAddress, testFoundationKey, blockingStubFull); + String args = + argsStr + ",\"" + contractCBase58 + "\",\"" + contractBBase58 + "\",\"" + target03 + "\""; + String txid1 = + PublicMethod.triggerContract( + contractAddressD, + methedStr, + args, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo info1 = PublicMethod.getTransactionInfoById(txid1,blockingStubFull).get(); - logger.info("kill03 info1: " +info1); + TransactionInfo info1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull).get(); + logger.info("kill03 info1: " + info1); Assert.assertEquals(code.SUCESS, info1.getResult()); System.out.println(PublicMethod.queryAccount(create2AddBytes, blockingStubFull)); Assert.assertEquals(9, info1.getInternalTransactionsCount()); @@ -315,16 +493,17 @@ void kill03() { Account create2Account = PublicMethod.queryAccount(create2AddBytes, blockingStubFull); logger.info("kill02 create2Account: " + create2Account.toString()); Assert.assertEquals("", create2Account.toString()); - Account targetAccount = PublicMethod.queryAccount(targetAdd03,blockingStubFull); + Account targetAccount = PublicMethod.queryAccount(targetAdd03, blockingStubFull); Assert.assertEquals(1801000000L, targetAccount.getBalance()); Assert.assertEquals(100000000L, targetAccount.getFrozenV2(0).getAmount()); Assert.assertEquals(100000000L, targetAccount.getFrozenV2(1).getAmount()); Assert.assertEquals(0, targetAccount.getVotesList().size()); - long targetAssetCount = PublicMethod.getAssetIssueValue(targetAdd03, assetAccountId, blockingStubFull); + long targetAssetCount = + PublicMethod.getAssetIssueValue(targetAdd03, assetAccountId, blockingStubFull); Assert.assertEquals(100, targetAssetCount); - AccountResourceMessage targetResource = PublicMethod.getAccountResource(targetAdd03, blockingStubFull); + AccountResourceMessage targetResource = + PublicMethod.getAccountResource(targetAdd03, blockingStubFull); Assert.assertNotEquals(0, targetResource.getNetLimit()); Assert.assertNotEquals(0, targetResource.getEnergyLimit()); } - - } +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test001.java index e48051fe..fea0ffdc 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test001.java @@ -15,17 +15,18 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test001 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] factoryContractAddress2 = null; private byte[] testContractAddress = null; @@ -36,35 +37,50 @@ public class Create2Test001 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy factory contract generated by new solidity", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy factory contract generated by new solidity", + groups = {"contract", "daily"}) public void test01DeployFactoryContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 10000_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 10000_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 10000_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 10000_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "Factory"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -75,29 +91,41 @@ public void test01DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "Trigger create2 command with test bytecode using factory", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger create2 command with test bytecode using factory", + groups = {"contract", "daily"}) public void test02TriggerCreate2ToDeployTestContract() { Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -109,56 +137,70 @@ public void test02TriggerCreate2ToDeployTestContract() { } logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); - // different contract address with different bytecode, same salt and address - Assert.assertNotEquals(Base58.encode58Check(factoryContractAddress), - Base58.encode58Check(testContractAddress)); + // different contract address with different bytecode, same salt and address + Assert.assertNotEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(testContractAddress)); } - @Test(enabled = true, description = "Trigger create2 command with factory bytecode", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger create2 command with factory bytecode", + groups = {"contract", "daily"}) public void test02TriggerCreate2ToDeployFactory2Contract() { Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "Factory"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -170,67 +212,84 @@ public void test02TriggerCreate2ToDeployFactory2Contract() { } logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); factoryContractAddress2 = WalletClient.decodeFromBase58Check(addressFinal); - SmartContract smartContract = PublicMethod - .getContract(factoryContractAddress2, blockingStubFull); - // contract created by create2, doesn't have ABI + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress2, blockingStubFull); + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = true, description = "Trigger create2 command with test bytecode using factory2", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger create2 command with test bytecode using factory2", + groups = {"contract", "daily"}) public void test03TriggerCreate2ToDeployTestContract2() { Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress2, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress2, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); - // Istanbul change create2 algorithm + // Istanbul change create2 algorithm Assert.assertEquals(0, infoById.get().getResultValue()); } - @Test(enabled = true, description = "Trigger create2 command without meta data hash in bytecode", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger create2 command without meta data hash in bytecode", + groups = {"contract", "daily"}) public void test04TriggerCreate2ToDeployTestContract() { - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -242,25 +301,39 @@ public void test04TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String testContractCode = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801" - + "561002a57600080fd5b5060c9806100396000396000f3fe6080604052348015600f57600080fd5b50d38015" - + "601b57600080fd5b50d28015602757600080fd5b50600436106066577c01000000000000000000000000000" - + "00000000000000000000000000000600035046368e5c0668114606b578063e5aa3d58146083575b600080fd" - + "5b60716089565b60408051918252519081900360200190f35b60716097565b6000805460010190819055905" - + "65b6000548156fe"; - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + String testContractCode = + "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801" + + "561002a57600080fd5b5060c9806100396000396000f3fe6080604052348015600f57600080fd5b50d38" + + "015" + + "601b57600080fd5b50d28015602757600080fd5b50600436106066577c01000000000000000000000000" + + "000" + + "00000000000000000000000000000600035046368e5c0668114606b578063e5aa3d58146083575b60008" + + "0fd" + + "5b60716089565b60408051918252519081900360200190f35b60716097565b6000805460010190819055" + + "905" + + "65b6000548156fe"; + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -275,15 +348,15 @@ public void test04TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -295,56 +368,76 @@ public void test04TriggerCreate2ToDeployTestContract() { } logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); - String msgSender = Base58.encode58Check(ByteArray.fromHexString(retList.get(2))); + String msgSender = Base58.encode58Check(ByteArray.fromHexString(retList.get(2))); Assert.assertNotEquals(msgSender, Base58.encode58Check(user001Address)); } - @Test(enabled = true, description = "Trigger create2 command with 0 extended bytecode", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger create2 command with 0 extended bytecode", + groups = {"contract", "daily"}) public void test05TriggerCreate2ToDeployTestContract() { Long callValue = Long.valueOf(0); - String testContractCode = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801" - + "561002a57600080fd5b5060c9806100396000396000f3fe6080604052348015600f57600080fd5b50d38015" - + "601b57600080fd5b50d28015602757600080fd5b50600436106066577c01000000000000000000000000000" - + "00000000000000000000000000000600035046368e5c0668114606b578063e5aa3d58146083575b600080fd" - + "5b60716089565b60408051918252519081900360200190f35b60716097565b6000805460010190819055905" - + "65b6000548156fe0000000000000000000000000000000000000000000000000000000000000000000000"; - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = + "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801" + + "561002a57600080fd5b5060c9806100396000396000f3fe6080604052348015600f57600080fd5b50d38" + + "015" + + "601b57600080fd5b50d28015602757600080fd5b50600436106066577c01000000000000000000000000" + + "000" + + "00000000000000000000000000000600035046368e5c0668114606b578063e5aa3d58146083575b60008" + + "0fd" + + "5b60716089565b60408051918252519081900360200190f35b60716097565b6000805460010190819055" + + "905" + + "65b6000548156fe000000000000000000000000000000000000000000000000000000000000000000000" + + "0"; + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -356,41 +449,45 @@ public void test05TriggerCreate2ToDeployTestContract() { } logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); - } - @Test(enabled = true, description = "Trigger Test contact", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger Test contact", + groups = {"contract", "daily"}) public void test04TriggerTestContract() { - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -402,17 +499,26 @@ public void test04TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - final String triggerTxid = PublicMethod.triggerContract(testContractAddress, - "plusOne()", "#", false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + final String triggerTxid = + PublicMethod.triggerContract( + testContractAddress, + "plusOne()", + "#", + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -427,27 +533,27 @@ public void test04TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); - Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); logger.info("ret: " + ret); @@ -455,50 +561,68 @@ public void test04TriggerTestContract() { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - SmartContract smartContract = PublicMethod.getContract(infoById.get().getContractAddress() - .toByteArray(), blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract( + infoById.get().getContractAddress().toByteArray(), blockingStubFull); long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); logger.info("ConsumeURPercent: " + consumeUserPercent); - - } - @Test(enabled = true, description = "test create2 with constructor has params", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test create2 with constructor has params", + groups = {"contract", "daily"}) public void test06TriggerTestContract() { int start = 3; - String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "create2WithParams(bytes32,uint256)", "1," + start, false, 0, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "create2WithParams(bytes32,uint256)", + "1," + start, + false, + 0, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info(infoById.get().toString()); - String trueRes = ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); - String create2Hex = "41"+trueRes.substring(24); - String create2Base58 = Base58.encode58Check(ByteArray.fromHexString(create2Hex)); + String trueRes = ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); + String create2Hex = "41" + trueRes.substring(24); + String create2Base58 = Base58.encode58Check(ByteArray.fromHexString(create2Hex)); logger.info(create2Hex); logger.info(create2Base58); - triggerTxid = PublicMethod.triggerContract(PublicMethod.decode58Check(create2Base58), - "plusOne()", "#", false, 0, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + PublicMethod.decode58Check(create2Base58), + "plusOne()", + "#", + false, + 0, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info(infoById.get().toString()); - Assert.assertEquals(start + 1, ByteArray.toLong(infoById.get().getContractResult(0).toByteArray())); + Assert.assertEquals( + start + 1, ByteArray.toLong(infoById.get().getContractResult(0).toByteArray())); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); - PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); } + PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test002.java index 3ddc3e92..b619b162 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test002.java @@ -16,18 +16,19 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test002 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] testContractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,47 +38,74 @@ public class Create2Test002 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = false, description = "Deploy factory contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Deploy factory contract", + groups = {"contract", "daily"}) public void test01DeployFactoryContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - //PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "Factory"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -89,8 +117,8 @@ public void test01DeployFactoryContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -101,35 +129,57 @@ public void test01DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - - @Test(enabled = false, description = "Trigger create2 command without meta data hash in bytecode", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger create2 command without meta data hash in bytecode", + groups = {"contract", "daily"}) public void test02TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - Long callValue = Long.valueOf(0); - String testContractCode = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801" - + "561002a57600080fd5b5060c9806100396000396000f3fe6080604052348015600f57600080fd5b50d38015" - + "601b57600080fd5b50d28015602757600080fd5b50600436106066577c01000000000000000000000000000" - + "00000000000000000000000000000600035046368e5c0668114606b578063e5aa3d58146083575b600080fd" - + "5b60716089565b60408051918252519081900360200190f35b60716097565b6000805460010190819055905" - + "65b6000548156fe"; - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + Long callValue = Long.valueOf(0); + String testContractCode = + "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801" + + "561002a57600080fd5b5060c9806100396000396000f3fe6080604052348015600f57600080fd5b50d38" + + "015" + + "601b57600080fd5b50d28015602757600080fd5b50600436106066577c01000000000000000000000000" + + "000" + + "00000000000000000000000000000600035046368e5c0668114606b578063e5aa3d58146083575b60008" + + "0fd" + + "5b60716089565b60408051918252519081900360200190f35b60716097565b6000805460010190819055" + + "905" + + "65b6000548156fe"; + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -141,48 +191,58 @@ public void test02TriggerCreate2ToDeployTestContract() { } logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); - String msgSender = Base58.encode58Check(ByteArray.fromHexString(retList.get(2))); + String msgSender = Base58.encode58Check(ByteArray.fromHexString(retList.get(2))); Assert.assertNotEquals(msgSender, Base58.encode58Check(user001Address)); } - - @Test(enabled = false, description = "Trigger Test contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger Test contract", + groups = {"contract", "daily"}) public void test03TriggerTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -194,17 +254,26 @@ public void test03TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - final String triggerTxid = PublicMethod.triggerContract(testContractAddress, - "plusOne()", "#", false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + final String triggerTxid = + PublicMethod.triggerContract( + testContractAddress, + "plusOne()", + "#", + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -219,27 +288,27 @@ public void test03TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); - Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); logger.info("ret: " + ret); @@ -247,31 +316,25 @@ public void test03TriggerTestContract() { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - SmartContract smartContract = PublicMethod.getContract(infoById.get().getContractAddress() - .toByteArray(), blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract( + infoById.get().getContractAddress().toByteArray(), blockingStubFull); long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); logger.info("ConsumeURPercent: " + consumeUserPercent); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test003.java index 61364b81..0c4e84d1 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test003.java @@ -15,18 +15,19 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test003 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] testContractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -36,43 +37,70 @@ public class Create2Test003 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy factory contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy factory contract", + groups = {"contract", "daily"}) public void test01DeployFactoryContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "Factory"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -83,20 +111,29 @@ public void test01DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "Trigger create2 command with invalid bytecode", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger create2 command with invalid bytecode", + groups = {"contract", "daily"}) public void test02TriggerCreate2WithInvalidBytecode() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -108,26 +145,41 @@ public void test02TriggerCreate2WithInvalidBytecode() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String testContractCode = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801" - + "561002a57600080fd5b5060c9806100396000396000f5fe6080604052348015600f57600080fd5b50d38015" - + "601b57600080fd5b50d28015602757600080fd5b50600436106066577c01000000000000000000000000000" - + "00000000000000000000000000000600035046368e5c0668114606b578063e5aa3d58146083575b600080fd" - + "5b60716089565b60408051918252519081900360200190f35b60716097565b6000805460010190819055905" - + "65b6000548156fea165627a7a72305820f3e3c0646a8c8d521fe819f10a592327469f611f0d9e8206697f7f" - + "3436ff3c7d0029"; - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + String testContractCode = + "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801" + + "561002a57600080fd5b5060c9806100396000396000f5fe6080604052348015600f57600080fd5b50d38" + + "015" + + "601b57600080fd5b50d28015602757600080fd5b50600436106066577c01000000000000000000000000" + + "000" + + "00000000000000000000000000000600035046368e5c0668114606b578063e5aa3d58146083575b60008" + + "0fd" + + "5b60716089565b60408051918252519081900360200190f35b60716097565b6000805460010190819055" + + "905" + + "65b6000548156fea165627a7a72305820f3e3c0646a8c8d521fe819f10a592327469f611f0d9e8206697" + + "f7f" + + "3436ff3c7d0029"; + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -142,35 +194,43 @@ public void test02TriggerCreate2WithInvalidBytecode() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); Assert.assertEquals(1, infoById.get().getResultValue()); - Assert - .assertThat(infoById.get().getResMessage().toStringUtf8(), - containsString("REVERT opcode executed")); + Assert.assertThat( + infoById.get().getResMessage().toStringUtf8(), containsString("REVERT opcode executed")); } - @Test(enabled = true, description = "Trigger create2 command with empty bytecode", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger create2 command with empty bytecode", + groups = {"contract", "daily"}) public void test03TriggerCreate2WithEmptyBytecode() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -182,20 +242,29 @@ public void test03TriggerCreate2WithEmptyBytecode() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String testContractCode = ""; - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + String testContractCode = ""; + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -210,35 +279,43 @@ public void test03TriggerCreate2WithEmptyBytecode() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); Assert.assertEquals(1, infoById.get().getResultValue()); - Assert - .assertThat(infoById.get().getResMessage().toStringUtf8(), - containsString("REVERT opcode executed")); + Assert.assertThat( + infoById.get().getResMessage().toStringUtf8(), containsString("REVERT opcode executed")); } - @Test(enabled = true, description = "Trigger create2 command with \"6080\" bytecode", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger create2 command with \"6080\" bytecode", + groups = {"contract", "daily"}) public void test04TriggerCreate2WithShortBytecode() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -250,20 +327,29 @@ public void test04TriggerCreate2WithShortBytecode() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String testContractCode = "6080"; - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + String testContractCode = "6080"; + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -278,35 +364,43 @@ public void test04TriggerCreate2WithShortBytecode() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); Assert.assertEquals(1, infoById.get().getResultValue()); - Assert - .assertThat(infoById.get().getResMessage().toStringUtf8(), - containsString("REVERT opcode executed")); + Assert.assertThat( + infoById.get().getResMessage().toStringUtf8(), containsString("REVERT opcode executed")); } - @Test(enabled = true, description = "Trigger create2 command with \"00000000000\" bytecode", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger create2 command with \"00000000000\" bytecode", + groups = {"contract", "daily"}) public void test05TriggerCreate2WithZeroBytecode() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -318,20 +412,29 @@ public void test05TriggerCreate2WithZeroBytecode() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String testContractCode = "000000000000000000000000000000"; - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + String testContractCode = "000000000000000000000000000000"; + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -346,35 +449,43 @@ public void test05TriggerCreate2WithZeroBytecode() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); Assert.assertEquals(1, infoById.get().getResultValue()); - Assert - .assertThat(infoById.get().getResMessage().toStringUtf8(), - containsString("REVERT opcode executed")); + Assert.assertThat( + infoById.get().getResMessage().toStringUtf8(), containsString("REVERT opcode executed")); } - @Test(enabled = true, description = "Trigger create2 command with NULL bytecode", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger create2 command with NULL bytecode", + groups = {"contract", "daily"}) public void test06TriggerCreate2WithNullBytecode() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -386,49 +497,50 @@ public void test06TriggerCreate2WithNullBytecode() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String testContractCode = null; - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; + Long callValue = Long.valueOf(0); + String testContractCode = null; + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; boolean ret = false; try { - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); } catch (org.bouncycastle.util.encoders.DecoderException e) { logger.info("Expected org.bouncycastle.util.encoders.DecoderException!"); ret = true; } Assert.assertTrue(ret); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test004.java index 89a246ec..0c4b4cec 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test004.java @@ -17,18 +17,19 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test004 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] factoryContractAddress2 = null; private byte[] testContractAddress = null; @@ -40,30 +41,46 @@ public class Create2Test004 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = false, description = "Deploy factory contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Deploy factory contract", + groups = {"contract", "daily"}) public void test01DeployFactoryContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource + // before deploy, check account resource /*AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); @@ -74,15 +91,26 @@ public void test01DeployFactoryContract() { logger.info("before balanceBefore is " + Long.toString(balanceBefore));*/ String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "Factory"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); /*accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -94,8 +122,8 @@ public void test01DeployFactoryContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter));*/ - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -106,17 +134,26 @@ public void test01DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = false, description = "Trigger create2 command with factory bytecode", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger create2 command with factory bytecode", + groups = {"contract", "daily"}) public void test02TriggerCreate2ToDeployFactory2Contract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 150000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 150000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); /*AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -139,16 +176,25 @@ public void test02TriggerCreate2ToDeployFactory2Contract() { logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));*/ Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "Factory"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); /*accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -170,8 +216,8 @@ public void test02TriggerCreate2ToDeployFactory2Contract() { logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));*/ - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -183,43 +229,53 @@ public void test02TriggerCreate2ToDeployFactory2Contract() { } logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); factoryContractAddress2 = WalletClient.decodeFromBase58Check(addressFinal); - SmartContract smartContract = PublicMethod - .getContract(factoryContractAddress2, blockingStubFull); - // contract created by create2, doesn't have ABI + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress2, blockingStubFull); + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - - @Test(enabled = false, description = "Trigger create2 command with test bytecode using factory", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger create2 command with test bytecode using factory", + groups = {"contract", "daily"}) public void test03TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 80000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 80000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); /*AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -242,16 +298,25 @@ public void test03TriggerCreate2ToDeployTestContract() { logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));*/ Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); /*accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -273,8 +338,8 @@ public void test03TriggerCreate2ToDeployTestContract() { logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));*/ - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -286,44 +351,55 @@ public void test03TriggerCreate2ToDeployTestContract() { } logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); - // different contract address with different bytecode, same salt and address - Assert.assertNotEquals(Base58.encode58Check(factoryContractAddress), - Base58.encode58Check(testContractAddress)); + // different contract address with different bytecode, same salt and address + Assert.assertNotEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(testContractAddress)); } - @Test(enabled = false, description = "Trigger create2 command with test bytecode using factory2", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger create2 command with test bytecode using factory2", + groups = {"contract", "daily"}) public void test04TriggerCreate2ToDeployTestContract2() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 80000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 80000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); /*AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -346,16 +422,25 @@ public void test04TriggerCreate2ToDeployTestContract2() { logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));*/ Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress2, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress2, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); /*accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -377,37 +462,29 @@ public void test04TriggerCreate2ToDeployTestContract2() { logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));*/ - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); Assert.assertEquals(1, infoById.get().getResultValue()); - Assert - .assertThat(infoById.get().getResMessage().toStringUtf8(), - containsString("Not enough energy for 'SWAP1' operation executing")); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); + Assert.assertThat( + infoById.get().getResMessage().toStringUtf8(), + containsString("Not enough energy for 'SWAP1' operation executing")); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test005.java index cbdda332..b2c11f3c 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test005.java @@ -16,18 +16,19 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test005 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] testContractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,48 +38,75 @@ public class Create2Test005 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = false, description = "Deploy factory contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Deploy factory contract", + groups = {"contract", "daily"}) public void test01DeployFactoryContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "Factory"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -90,8 +118,8 @@ public void test01DeployFactoryContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -102,21 +130,29 @@ public void test01DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - - @Test(enabled = false, description = "Trigger create2 command with 0 extended bytecode", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger create2 command with 0 extended bytecode", + groups = {"contract", "daily"}) public void test02TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -128,25 +164,40 @@ public void test02TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String testContractCode = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801" - + "561002a57600080fd5b5060c9806100396000396000f3fe6080604052348015600f57600080fd5b50d38015" - + "601b57600080fd5b50d28015602757600080fd5b50600436106066577c01000000000000000000000000000" - + "00000000000000000000000000000600035046368e5c0668114606b578063e5aa3d58146083575b600080fd" - + "5b60716089565b60408051918252519081900360200190f35b60716097565b6000805460010190819055905" - + "65b6000548156fe0000000000000000000000000000000000000000000000000000000000000000000000"; - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + String testContractCode = + "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801" + + "561002a57600080fd5b5060c9806100396000396000f3fe6080604052348015600f57600080fd5b50d38" + + "015" + + "601b57600080fd5b50d28015602757600080fd5b50600436106066577c01000000000000000000000000" + + "000" + + "00000000000000000000000000000600035046368e5c0668114606b578063e5aa3d58146083575b60008" + + "0fd" + + "5b60716089565b60408051918252519081900360200190f35b60716097565b6000805460010190819055" + + "905" + + "65b6000548156fe000000000000000000000000000000000000000000000000000000000000000000000" + + "0"; + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -161,15 +212,15 @@ public void test02TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -181,45 +232,56 @@ public void test02TriggerCreate2ToDeployTestContract() { } logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = false, description = "Trigger test contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger test contract", + groups = {"contract", "daily"}) public void test03TriggerTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -231,17 +293,26 @@ public void test03TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - final String triggerTxid = PublicMethod.triggerContract(testContractAddress, - "plusOne()", "#", false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + final String triggerTxid = + PublicMethod.triggerContract( + testContractAddress, + "plusOne()", + "#", + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -256,27 +327,27 @@ public void test03TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); - Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); logger.info("ret: " + ret); @@ -284,30 +355,24 @@ public void test03TriggerTestContract() { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - SmartContract smartContract = PublicMethod.getContract(infoById.get().getContractAddress() - .toByteArray(), blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract( + infoById.get().getContractAddress().toByteArray(), blockingStubFull); long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); logger.info("ConsumeURPercent: " + consumeUserPercent); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test006.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test006.java index a259ed18..d3ef5f5d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test006.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test006.java @@ -16,18 +16,19 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test006 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] testContractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,48 +38,75 @@ public class Create2Test006 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy factory contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy factory contract", + groups = {"contract", "daily"}) public void test01DeployFactoryContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "Factory"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -90,8 +118,8 @@ public void test01DeployFactoryContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -102,20 +130,29 @@ public void test01DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "Trigger create2 with salt empty", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger create2 with salt empty", + groups = {"contract", "daily"}) public void test02TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -127,49 +164,63 @@ public void test02TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - String param = "\"" + testContractCode + "\"," + null; + String testContractCode = retMap.get("byteCode").toString(); + String param = "\"" + testContractCode + "\"," + null; boolean ret = false; try { - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); } catch (NullPointerException e) { logger.info("Expected NullPointerException!"); ret = true; } Assert.assertTrue(ret); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } - @Test(enabled = true, description = "Trigger create2 with salt 0", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger create2 with salt 0", + groups = {"contract", "daily"}) public void test03TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -181,23 +232,32 @@ public void test03TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 0L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 0L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -212,34 +272,34 @@ public void test03TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); @@ -252,26 +312,37 @@ public void test03TriggerCreate2ToDeployTestContract() { SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); Assert.assertEquals(salt, actualSalt); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = true, description = "Trigger create2 with salt -1", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger create2 with salt -1", + groups = {"contract", "daily"}) public void test04TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -283,23 +354,32 @@ public void test04TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = -1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = -1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -314,34 +394,34 @@ public void test04TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); @@ -354,26 +434,37 @@ public void test04TriggerCreate2ToDeployTestContract() { SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); Assert.assertEquals(salt, actualSalt); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = true, description = "Trigger create2 with salt 100", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger create2 with salt 100", + groups = {"contract", "daily"}) public void test05TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -385,23 +476,32 @@ public void test05TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 100L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 100L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -416,34 +516,34 @@ public void test05TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); @@ -456,27 +556,38 @@ public void test05TriggerCreate2ToDeployTestContract() { SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); Assert.assertEquals(salt, actualSalt); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } // Istanbul change create2 algorithm - @Test(enabled = false, description = "Trigger create2 with salt f * 64", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger create2 with salt f * 64", + groups = {"contract", "daily"}) public void test06TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -488,24 +599,33 @@ public void test06TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - String saltHexString = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; + String testContractCode = retMap.get("byteCode").toString(); + String saltHexString = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; logger.info("saltHexString: " + saltHexString); - String param = "\"" + testContractCode + "\",\"" + saltHexString + "\""; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,bytes32)", param, false, callValue, - 1000000000L, "0", 0, dev001Address, dev001Key, - blockingStubFull); + String param = "\"" + testContractCode + "\",\"" + saltHexString + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,bytes32)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -521,41 +641,41 @@ public void test06TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - // The first + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + // The first byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("addressHex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("addressFinal: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); - String actualSalt = retList.get(1); + String actualSalt = retList.get(1); logger.info("actualSalt: " + actualSalt); - byte[] tmpSenderAddress = new byte[20]; + byte[] tmpSenderAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(2)), 12, tmpSenderAddress, 0, 20); - String senderAddressHex = "41" + ByteArray.toHexString(tmpAddress); + String senderAddressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("senderAddressHex: " + senderAddressHex); - String senderAddressFinal = Base58.encode58Check(ByteArray.fromHexString(senderAddressHex)); + String senderAddressFinal = Base58.encode58Check(ByteArray.fromHexString(senderAddressHex)); logger.info("senderAddressFinal: " + senderAddressFinal); if (infoById.get().getResultValue() != 0) { @@ -566,26 +686,37 @@ public void test06TriggerCreate2ToDeployTestContract() { SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); Assert.assertEquals(saltHexString, actualSalt); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = true, description = "Trigger create2 with salt efffe", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger create2 with salt efffe", + groups = {"contract", "daily"}) public void test07TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -597,26 +728,35 @@ public void test07TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - final String saltHexString = "EFFFE"; - final String expectedSalt = "0EFFFE0000000000000000000000000000000000000000000000000000000000"; + String testContractCode = retMap.get("byteCode").toString(); + final String saltHexString = "EFFFE"; + final String expectedSalt = "0EFFFE0000000000000000000000000000000000000000000000000000000000"; logger.info("saltHexString: " + saltHexString); - String param = "\"" + testContractCode + "\",\"" + saltHexString + "\""; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,bytes32)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String param = "\"" + testContractCode + "\",\"" + saltHexString + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,bytes32)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -631,41 +771,41 @@ public void test07TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - // The first + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + // The first byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("addressHex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("addressFinal: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); - String actualSalt = retList.get(1); + String actualSalt = retList.get(1); logger.info("actualSalt: " + actualSalt); - byte[] tmpSenderAddress = new byte[20]; + byte[] tmpSenderAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(2)), 12, tmpSenderAddress, 0, 20); - String senderAddressHex = "41" + ByteArray.toHexString(tmpAddress); + String senderAddressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("senderAddressHex: " + senderAddressHex); - String senderAddressFinal = Base58.encode58Check(ByteArray.fromHexString(senderAddressHex)); + String senderAddressFinal = Base58.encode58Check(ByteArray.fromHexString(senderAddressHex)); logger.info("senderAddressFinal: " + senderAddressFinal); if (infoById.get().getResultValue() != 0) { @@ -676,26 +816,37 @@ public void test07TriggerCreate2ToDeployTestContract() { SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); Assert.assertEquals(expectedSalt, actualSalt); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = true, description = "Trigger create2 with salt affffa", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger create2 with salt affffa", + groups = {"contract", "daily"}) public void test08TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -707,25 +858,34 @@ public void test08TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - final String saltHexString = "AFFFFA"; - final String expectedSalt = "AFFFFA0000000000000000000000000000000000000000000000000000000000"; + String testContractCode = retMap.get("byteCode").toString(); + final String saltHexString = "AFFFFA"; + final String expectedSalt = "AFFFFA0000000000000000000000000000000000000000000000000000000000"; logger.info("saltHexString: " + saltHexString); - String param = "\"" + testContractCode + "\",\"" + saltHexString + "\""; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,bytes32)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String param = "\"" + testContractCode + "\",\"" + saltHexString + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,bytes32)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -740,41 +900,41 @@ public void test08TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - // The first + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + // The first byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("addressHex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("addressFinal: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); - String actualSalt = retList.get(1); + String actualSalt = retList.get(1); logger.info("actualSalt: " + actualSalt); - byte[] tmpSenderAddress = new byte[20]; + byte[] tmpSenderAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(2)), 12, tmpSenderAddress, 0, 20); - String senderAddressHex = "41" + ByteArray.toHexString(tmpAddress); + String senderAddressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("senderAddressHex: " + senderAddressHex); - String senderAddressFinal = Base58.encode58Check(ByteArray.fromHexString(senderAddressHex)); + String senderAddressFinal = Base58.encode58Check(ByteArray.fromHexString(senderAddressHex)); logger.info("senderAddressFinal: " + senderAddressFinal); if (infoById.get().getResultValue() != 0) { @@ -785,36 +945,43 @@ public void test08TriggerCreate2ToDeployTestContract() { SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); Assert.assertEquals(expectedSalt, actualSalt); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } - @Test(enabled = true, description = "Trigger test contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger test contract", + groups = {"contract", "daily"}) public void test09TriggerTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -826,17 +993,26 @@ public void test09TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - final String triggerTxid = PublicMethod.triggerContract(testContractAddress, - "plusOne()", "#", false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + final String triggerTxid = + PublicMethod.triggerContract( + testContractAddress, + "plusOne()", + "#", + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -851,27 +1027,27 @@ public void test09TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); - Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); logger.info("ret: " + ret); @@ -879,31 +1055,25 @@ public void test09TriggerTestContract() { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - SmartContract smartContract = PublicMethod.getContract(infoById.get().getContractAddress() - .toByteArray(), blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract( + infoById.get().getContractAddress().toByteArray(), blockingStubFull); long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); logger.info("ConsumeURPercent: " + consumeUserPercent); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test007.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test007.java index d549c684..d1f9f70a 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test007.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test007.java @@ -16,18 +16,19 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test007 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] testContractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,48 +38,75 @@ public class Create2Test007 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = false, description = "Deploy factory contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Deploy factory contract", + groups = {"contract", "daily"}) public void test01DeployFactoryContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "Factory"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -90,8 +118,8 @@ public void test01DeployFactoryContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -102,20 +130,29 @@ public void test01DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = false, description = "Trigger create2 with salt -1", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger create2 with salt -1", + groups = {"contract", "daily"}) public void test02TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -127,23 +164,32 @@ public void test02TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = -1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = -1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -158,34 +204,34 @@ public void test02TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); @@ -198,27 +244,38 @@ public void test02TriggerCreate2ToDeployTestContract() { SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); Assert.assertEquals(salt, actualSalt); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = false, description = "Trigger test contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger test contract", + groups = {"contract", "daily"}) public void test03TriggerTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -230,17 +287,26 @@ public void test03TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - final String triggerTxid = PublicMethod.triggerContract(testContractAddress, - "plusOne()", "#", false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + final String triggerTxid = + PublicMethod.triggerContract( + testContractAddress, + "plusOne()", + "#", + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -255,27 +321,27 @@ public void test03TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); - Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); logger.info("ret: " + ret); @@ -283,31 +349,25 @@ public void test03TriggerTestContract() { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - SmartContract smartContract = PublicMethod.getContract(infoById.get().getContractAddress() - .toByteArray(), blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract( + infoById.get().getContractAddress().toByteArray(), blockingStubFull); long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); logger.info("ConsumeURPercent: " + consumeUserPercent); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test008.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test008.java index 3570c97d..5d3a1f1d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test008.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test008.java @@ -16,18 +16,19 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test008 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] testContractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,48 +38,75 @@ public class Create2Test008 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = false, description = "Deploy factory contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Deploy factory contract", + groups = {"contract", "daily"}) public void test01DeployFactoryContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "Factory"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -90,8 +118,8 @@ public void test01DeployFactoryContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -102,20 +130,29 @@ public void test01DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = false, description = "Trigger create2 with salt 100", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger create2 with salt 100", + groups = {"contract", "daily"}) public void test02TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -127,23 +164,32 @@ public void test02TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 100L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 100L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -158,34 +204,34 @@ public void test02TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); @@ -198,27 +244,38 @@ public void test02TriggerCreate2ToDeployTestContract() { SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); Assert.assertEquals(salt, actualSalt); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = false, description = "Trigger test contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger test contract", + groups = {"contract", "daily"}) public void test03TriggerTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -230,17 +287,26 @@ public void test03TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - final String triggerTxid = PublicMethod.triggerContract(testContractAddress, - "plusOne()", "#", false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + final String triggerTxid = + PublicMethod.triggerContract( + testContractAddress, + "plusOne()", + "#", + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -255,27 +321,27 @@ public void test03TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); - Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); logger.info("ret: " + ret); @@ -283,31 +349,25 @@ public void test03TriggerTestContract() { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - SmartContract smartContract = PublicMethod.getContract(infoById.get().getContractAddress() - .toByteArray(), blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract( + infoById.get().getContractAddress().toByteArray(), blockingStubFull); long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); logger.info("ConsumeURPercent: " + consumeUserPercent); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test009.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test009.java index ef80c601..28718eb4 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test009.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test009.java @@ -16,18 +16,19 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test009 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] testContractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,48 +38,75 @@ public class Create2Test009 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = false, description = "Deploy factory contract generated by new solidity", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Deploy factory contract generated by new solidity", + groups = {"contract", "daily"}) public void test01DeployFactoryContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "Factory"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -90,8 +118,8 @@ public void test01DeployFactoryContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -102,21 +130,29 @@ public void test01DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - - @Test(enabled = false, description = "Trigger create2 function to deploy test contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger create2 function to deploy test contract", + groups = {"contract", "daily"}) public void test02TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -128,23 +164,32 @@ public void test02TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -159,34 +204,34 @@ public void test02TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); @@ -197,34 +242,43 @@ public void test02TriggerCreate2ToDeployTestContract() { } SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); String[] parameter = {Base58.encode58Check(user001Address), testContractCode, salt.toString()}; logger.info(PublicMethod.create2(parameter)); Assert.assertEquals(Base58.encode58Check(testContractAddress), PublicMethod.create2(parameter)); - } - - @Test(enabled = false, description = "Trigger Test contact", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger Test contact", + groups = {"contract", "daily"}) public void test03TriggerTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -236,17 +290,26 @@ public void test03TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - final String triggerTxid = PublicMethod.triggerContract(testContractAddress, - "plusOne()", "#", false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + final String triggerTxid = + PublicMethod.triggerContract( + testContractAddress, + "plusOne()", + "#", + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -261,27 +324,27 @@ public void test03TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); - Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); logger.info("ret: " + ret); @@ -289,31 +352,25 @@ public void test03TriggerTestContract() { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - SmartContract smartContract = PublicMethod.getContract(infoById.get().getContractAddress() - .toByteArray(), blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract( + infoById.get().getContractAddress().toByteArray(), blockingStubFull); long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); logger.info("ConsumeURPercent: " + consumeUserPercent); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test010.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test010.java index e7a1f043..5ca86951 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test010.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test010.java @@ -13,18 +13,19 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test010 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] testContractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -34,48 +35,75 @@ public class Create2Test010 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = false, description = "TransferToken with correct value, deploy transfer contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TransferToken with correct value, deploy transfer contract", + groups = {"contract", "daily"}) public void test01DeployFactoryContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "Factory"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -87,8 +115,8 @@ public void test01DeployFactoryContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -99,21 +127,29 @@ public void test01DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - - @Test(enabled = false, description = "Trigger create2 with salt empty", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger create2 with salt empty", + groups = {"contract", "daily"}) public void test02TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -125,50 +161,51 @@ public void test02TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - String param = "\"" + testContractCode + "\"," + null; + String testContractCode = retMap.get("byteCode").toString(); + String param = "\"" + testContractCode + "\"," + null; boolean ret = false; try { - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); } catch (NullPointerException e) { logger.info("Expected NullPointerException!"); ret = true; } Assert.assertTrue(ret); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test011.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test011.java index 5af90f47..a5155e7f 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test011.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test011.java @@ -16,18 +16,19 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test011 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] testContractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,48 +38,75 @@ public class Create2Test011 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = false, description = "Deploy factory contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Deploy factory contract", + groups = {"contract", "daily"}) public void test01DeployFactoryContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "FactoryBytes"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "FactoryBytes"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -90,8 +118,8 @@ public void test01DeployFactoryContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -102,21 +130,29 @@ public void test01DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - - @Test(enabled = false, description = "Trigger create2 with salt f * 64", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger create2 with salt f * 64", + groups = {"contract", "daily"}) public void test02TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -128,24 +164,33 @@ public void test02TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - String saltHexString = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; + String testContractCode = retMap.get("byteCode").toString(); + String saltHexString = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; logger.info("saltHexString: " + saltHexString); - String param = "\"" + testContractCode + "\",\"" + saltHexString + "\""; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,bytes32)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String param = "\"" + testContractCode + "\",\"" + saltHexString + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,bytes32)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -161,41 +206,41 @@ public void test02TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - // The first + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + // The first byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("addressHex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("addressFinal: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); - String actualSalt = retList.get(1); + String actualSalt = retList.get(1); logger.info("actualSalt: " + actualSalt); - byte[] tmpSenderAddress = new byte[20]; + byte[] tmpSenderAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(2)), 12, tmpSenderAddress, 0, 20); - String senderAddressHex = "41" + ByteArray.toHexString(tmpAddress); + String senderAddressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("senderAddressHex: " + senderAddressHex); - String senderAddressFinal = Base58.encode58Check(ByteArray.fromHexString(senderAddressHex)); + String senderAddressFinal = Base58.encode58Check(ByteArray.fromHexString(senderAddressHex)); logger.info("senderAddressFinal: " + senderAddressFinal); if (infoById.get().getResultValue() != 0) { @@ -206,28 +251,38 @@ public void test02TriggerCreate2ToDeployTestContract() { SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); Assert.assertEquals(saltHexString, actualSalt); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - - @Test(enabled = false, description = "Trigger test contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger test contract", + groups = {"contract", "daily"}) public void test03TriggerTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -239,17 +294,26 @@ public void test03TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - final String triggerTxid = PublicMethod.triggerContract(testContractAddress, - "plusOne()", "#", false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + final String triggerTxid = + PublicMethod.triggerContract( + testContractAddress, + "plusOne()", + "#", + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -264,27 +328,27 @@ public void test03TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); - Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); logger.info("ret: " + ret); @@ -292,31 +356,25 @@ public void test03TriggerTestContract() { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - SmartContract smartContract = PublicMethod.getContract(infoById.get().getContractAddress() - .toByteArray(), blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract( + infoById.get().getContractAddress().toByteArray(), blockingStubFull); long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); logger.info("ConsumeURPercent: " + consumeUserPercent); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test012.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test012.java index cb7abb13..08de8506 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test012.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test012.java @@ -16,18 +16,19 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test012 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] testContractAddress = null; private byte[] testContractAddress2 = null; @@ -38,48 +39,75 @@ public class Create2Test012 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = false, description = "Deploy factory contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Deploy factory contract", + groups = {"contract", "daily"}) public void test01DeployFactoryContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "Factory"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -91,8 +119,8 @@ public void test01DeployFactoryContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -103,21 +131,29 @@ public void test01DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - - @Test(enabled = false, description = "Trigger create2 command with test bytecode and salt 1", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger create2 command with test bytecode and salt 1", + groups = {"contract", "daily"}) public void test02TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 80000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 80000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -129,23 +165,32 @@ public void test02TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -160,15 +205,15 @@ public void test02TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -180,19 +225,19 @@ public void test02TriggerCreate2ToDeployTestContract() { } logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); @@ -200,27 +245,37 @@ public void test02TriggerCreate2ToDeployTestContract() { SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); Assert.assertEquals(salt, actualSalt); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - - @Test(enabled = false, description = "Trigger create2 command with test bytecode and salt 2", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger create2 command with test bytecode and salt 2", + groups = {"contract", "daily"}) public void test03TriggerCreate2ToDeployTestContract2() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 80000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 80000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -232,23 +287,32 @@ public void test03TriggerCreate2ToDeployTestContract2() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 2L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 2L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -263,15 +327,15 @@ public void test03TriggerCreate2ToDeployTestContract2() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -283,19 +347,19 @@ public void test03TriggerCreate2ToDeployTestContract2() { } logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); testContractAddress2 = WalletClient.decodeFromBase58Check(addressFinal); @@ -303,39 +367,33 @@ public void test03TriggerCreate2ToDeployTestContract2() { SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); Assert.assertEquals(salt, actualSalt); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); - // contract address are different with different salt - Assert.assertNotEquals(Base58.encode58Check(testContractAddress), - Base58.encode58Check(testContractAddress2)); - - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); - } + // contract address are different with different salt + Assert.assertNotEquals( + Base58.encode58Check(testContractAddress), Base58.encode58Check(testContractAddress2)); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); + } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test013.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test013.java index 8ce40404..44b8e261 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test013.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test013.java @@ -18,18 +18,19 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test013 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] testContractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -39,48 +40,75 @@ public class Create2Test013 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = false, description = "Deploy factory contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Deploy factory contract", + groups = {"contract", "daily"}) public void test01DeployFactoryContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "Factory"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -92,8 +120,8 @@ public void test01DeployFactoryContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -104,20 +132,29 @@ public void test01DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = false, description = "Trigger factory contract to deploy test contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger factory contract to deploy test contract", + groups = {"contract", "daily"}) public void test02TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -129,23 +166,32 @@ public void test02TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -160,34 +206,34 @@ public void test02TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); @@ -198,27 +244,39 @@ public void test02TriggerCreate2ToDeployTestContract() { } SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = false, description = "Trigger factory contract to deploy test contract again " - + "with same code, salt and address", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = + "Trigger factory contract to deploy test contract again " + + "with same code, salt and address", + groups = {"contract", "daily"}) public void test03TriggerCreate2ToDeployTestContractAgain() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -230,23 +288,32 @@ public void test03TriggerCreate2ToDeployTestContractAgain() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -261,36 +328,45 @@ public void test03TriggerCreate2ToDeployTestContractAgain() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); Assert.assertEquals(1, infoById.get().getResultValue()); - Assert - .assertThat(infoById.get().getResMessage().toStringUtf8(), - containsString("Not enough energy for 'SWAP1' operation executing")); + Assert.assertThat( + infoById.get().getResMessage().toStringUtf8(), + containsString("Not enough energy for 'SWAP1' operation executing")); } - @Test(enabled = false, description = "Trigger test1 contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger test1 contract", + groups = {"contract", "daily"}) public void test04TriggerTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -302,17 +378,26 @@ public void test04TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - final String triggerTxid = PublicMethod.triggerContract(testContractAddress, - "plusOne()", "#", false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + final String triggerTxid = + PublicMethod.triggerContract( + testContractAddress, + "plusOne()", + "#", + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -327,27 +412,27 @@ public void test04TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); - Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); logger.info("ret: " + ret); @@ -355,31 +440,25 @@ public void test04TriggerTestContract() { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - SmartContract smartContract = PublicMethod.getContract(infoById.get().getContractAddress() - .toByteArray(), blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract( + infoById.get().getContractAddress().toByteArray(), blockingStubFull); long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); logger.info("ConsumeURPercent: " + consumeUserPercent); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test014.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test014.java index 99cdbd74..7264dd65 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test014.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test014.java @@ -18,18 +18,19 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test014 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] testContractAddress = null; private byte[] testContractAddress2 = null; @@ -40,49 +41,76 @@ public class Create2Test014 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy factory contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy factory contract", + groups = {"contract", "daily"}) public void test01DeployFactoryContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "Factory"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -94,8 +122,8 @@ public void test01DeployFactoryContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -106,23 +134,30 @@ public void test01DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - - @Test(enabled = true, description = "Trigger factory contract with Test " - + "bytecode and salt using user account", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger factory contract with Test " + "bytecode and salt using user account", + groups = {"contract", "daily"}) public void test02TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -134,23 +169,32 @@ public void test02TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -165,34 +209,34 @@ public void test02TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); @@ -203,28 +247,40 @@ public void test02TriggerCreate2ToDeployTestContract() { } SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = true, description = "Trigger factory contract to deploy test contract again " - + "with same code, salt and address", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger factory contract to deploy test contract again " + + "with same code, salt and address", + groups = {"contract", "daily"}) public void test02TriggerCreate2ToDeployTestContractAgain() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -236,23 +292,32 @@ public void test02TriggerCreate2ToDeployTestContractAgain() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -267,38 +332,44 @@ public void test02TriggerCreate2ToDeployTestContractAgain() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); Assert.assertEquals(1, infoById.get().getResultValue()); - Assert - .assertThat(infoById.get().getResMessage().toStringUtf8(), - containsString("REVERT opcode executed")); + Assert.assertThat( + infoById.get().getResMessage().toStringUtf8(), containsString("REVERT opcode executed")); } // Istanbul change create2 algorithm - @Test(enabled = false, description = "Same code, salt and address," - + " create contract using develop account", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Same code, salt and address," + " create contract using develop account", + groups = {"contract", "daily"}) public void test03TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -310,23 +381,32 @@ public void test03TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, dev001Address, dev001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -341,34 +421,34 @@ public void test03TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); testContractAddress2 = WalletClient.decodeFromBase58Check(addressFinal); @@ -379,31 +459,42 @@ public void test03TriggerCreate2ToDeployTestContract() { } SmartContract smartContract = PublicMethod.getContract(testContractAddress2, blockingStubFull); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); - // contract address are different - Assert.assertNotEquals(Base58.encode58Check(testContractAddress), - Base58.encode58Check(testContractAddress2)); + // contract address are different + Assert.assertNotEquals( + Base58.encode58Check(testContractAddress), Base58.encode58Check(testContractAddress2)); } - @Test(enabled = true, description = "Trigger test1 contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger test1 contract", + groups = {"contract", "daily"}) public void test04TriggerTest1Contract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -415,17 +506,26 @@ public void test04TriggerTest1Contract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - final String triggerTxid = PublicMethod.triggerContract(testContractAddress, - "plusOne()", "#", false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + final String triggerTxid = + PublicMethod.triggerContract( + testContractAddress, + "plusOne()", + "#", + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -440,27 +540,27 @@ public void test04TriggerTest1Contract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); - Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); logger.info("ret: " + ret); @@ -468,24 +568,34 @@ public void test04TriggerTest1Contract() { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - SmartContract smartContract = PublicMethod.getContract(infoById.get().getContractAddress() - .toByteArray(), blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract( + infoById.get().getContractAddress().toByteArray(), blockingStubFull); long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); logger.info("ConsumeURPercent: " + consumeUserPercent); } // Istanbul change create2 algorithm - @Test(enabled = false, description = "Trigger test2 contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger test2 contract", + groups = {"contract", "daily"}) public void test05TriggerTest2Contract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -497,17 +607,26 @@ public void test05TriggerTest2Contract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - final String triggerTxid = PublicMethod.triggerContract(testContractAddress2, - "plusOne()", "#", false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + final String triggerTxid = + PublicMethod.triggerContract( + testContractAddress2, + "plusOne()", + "#", + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -522,27 +641,27 @@ public void test05TriggerTest2Contract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); - Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); logger.info("ret: " + ret); @@ -550,31 +669,25 @@ public void test05TriggerTest2Contract() { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - SmartContract smartContract = PublicMethod.getContract(infoById.get().getContractAddress() - .toByteArray(), blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract( + infoById.get().getContractAddress().toByteArray(), blockingStubFull); long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); logger.info("ConsumeURPercent: " + consumeUserPercent); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test015.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test015.java index 075fe699..4b1af191 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test015.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test015.java @@ -15,18 +15,19 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test015 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] callerContractAddress = null; private byte[] callContractAddress = null; @@ -38,41 +39,56 @@ public class Create2Test015 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy caller contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy caller contract", + groups = {"contract", "daily"}) public void test01DeployCallerContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 1000_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 1000_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1000_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 1000_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/create2CallContract.sol"; - String contractName = "callerContract"; + String filePath = "./src/test/resources/soliditycode/create2CallContract.sol"; + String contractName = "callerContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -84,8 +100,8 @@ public void test01DeployCallerContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -96,33 +112,46 @@ public void test01DeployCallerContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); callerContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(callerContractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(callerContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "Deploy factory contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy factory contract", + groups = {"contract", "daily"}) public void test02DeployFactoryContract() { - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "Factory"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -134,8 +163,8 @@ public void test02DeployFactoryContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -146,17 +175,20 @@ public void test02DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "Trigger callCreate2 function in caller contract " - + "with factory contract address", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger callCreate2 function in caller contract " + "with factory contract address", + groups = {"contract", "daily"}) public void test03TriggerCreate2ToDeployTestContract() { - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -168,24 +200,38 @@ public void test03TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; - String param = "\"" + Base58.encode58Check(factoryContractAddress) - + "\",\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(callerContractAddress, - "callCreate2(address,bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + String param = + "\"" + + Base58.encode58Check(factoryContractAddress) + + "\",\"" + + testContractCode + + "\"," + + salt; + final String triggerTxid = + PublicMethod.triggerContract( + callerContractAddress, + "callCreate2(address,bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -200,35 +246,34 @@ public void test03TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; - System.arraycopy(ByteArray.fromHexString(retList.get(0)), - 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); callContractAddress = WalletClient.decodeFromBase58Check(addressFinal); @@ -239,23 +284,29 @@ public void test03TriggerCreate2ToDeployTestContract() { } SmartContract smartContract = PublicMethod.getContract(callContractAddress, blockingStubFull); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // call type make the caller contract to be the owner of + // call type make the caller contract to be the owner of // test contract (the contract address in transaction info) - Assert.assertEquals(Base58.encode58Check(callerContractAddress), + Assert.assertEquals( + Base58.encode58Check(callerContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = true, description = "Trigger delegateCallCreate2 function in caller contract " - + "with factory contract address", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger delegateCallCreate2 function in caller contract " + + "with factory contract address", + groups = {"contract", "daily"}) public void test04TriggerCreate2ToDeployTestContract() { - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -267,24 +318,38 @@ public void test04TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; - String param = "\"" + Base58.encode58Check(factoryContractAddress) - + "\",\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(callerContractAddress, - "delegateCallCreate2(address,bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + String param = + "\"" + + Base58.encode58Check(factoryContractAddress) + + "\",\"" + + testContractCode + + "\"," + + salt; + final String triggerTxid = + PublicMethod.triggerContract( + callerContractAddress, + "delegateCallCreate2(address,bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -299,34 +364,34 @@ public void test04TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); delegateCallContractAddress = WalletClient.decodeFromBase58Check(addressFinal); @@ -336,24 +401,29 @@ public void test04TriggerCreate2ToDeployTestContract() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - SmartContract smartContract = PublicMethod - .getContract(delegateCallContractAddress, blockingStubFull); - // contract created by create2, doesn't have ABI + SmartContract smartContract = + PublicMethod.getContract(delegateCallContractAddress, blockingStubFull); + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // delegatecall type make the caller contract to be the owner of test contract (contract info) - Assert.assertEquals(Base58.encode58Check(callerContractAddress), + // delegatecall type make the caller contract to be the owner of test contract (contract info) + Assert.assertEquals( + Base58.encode58Check(callerContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // call type make the caller contract to be the owner of test contract + // call type make the caller contract to be the owner of test contract // (the contract address in transaction info) - Assert.assertEquals(Base58.encode58Check(callerContractAddress), + Assert.assertEquals( + Base58.encode58Check(callerContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = true, description = "Trigger test contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger test contract", + groups = {"contract", "daily"}) public void test09TriggerTestContract() { - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -365,17 +435,26 @@ public void test09TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - final String triggerTxid = PublicMethod.triggerContract(callContractAddress, - "plusOne()", "#", false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + final String triggerTxid = + PublicMethod.triggerContract( + callContractAddress, + "plusOne()", + "#", + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -390,27 +469,27 @@ public void test09TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); - Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); logger.info("ret: " + ret); @@ -418,23 +497,20 @@ public void test09TriggerTestContract() { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - SmartContract smartContract = PublicMethod.getContract(infoById.get().getContractAddress() - .toByteArray(), blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract( + infoById.get().getContractAddress().toByteArray(), blockingStubFull); long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); logger.info("ConsumeURPercent: " + consumeUserPercent); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test016.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test016.java index e249a1be..c4bf2f39 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test016.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test016.java @@ -16,18 +16,19 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test016 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] callerContractAddress = null; private byte[] testContractAddress = null; @@ -38,48 +39,75 @@ public class Create2Test016 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = false, description = "Deploy caller contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Deploy caller contract", + groups = {"contract", "daily"}) public void test01DeployCallerContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/create2CallContract.sol"; - String contractName = "callerContract"; + String filePath = "./src/test/resources/soliditycode/create2CallContract.sol"; + String contractName = "callerContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -91,8 +119,8 @@ public void test01DeployCallerContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -103,41 +131,66 @@ public void test01DeployCallerContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); callerContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(callerContractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(callerContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = false, description = "Deploy factory contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Deploy factory contract", + groups = {"contract", "daily"}) public void test02DeployFactoryContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "Factory"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -149,8 +202,8 @@ public void test02DeployFactoryContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -161,21 +214,31 @@ public void test02DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = false, description = "Trigger delegateCallCreate2 function in caller contract " - + "with factory contract address", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = + "Trigger delegateCallCreate2 function in caller contract " + + "with factory contract address", + groups = {"contract", "daily"}) public void test03TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -187,24 +250,38 @@ public void test03TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; - String param = "\"" + Base58.encode58Check(factoryContractAddress) - + "\",\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(callerContractAddress, - "delegateCallCreate2(address,bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + String param = + "\"" + + Base58.encode58Check(factoryContractAddress) + + "\",\"" + + testContractCode + + "\"," + + salt; + final String triggerTxid = + PublicMethod.triggerContract( + callerContractAddress, + "delegateCallCreate2(address,bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -219,34 +296,34 @@ public void test03TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); @@ -257,27 +334,38 @@ public void test03TriggerCreate2ToDeployTestContract() { } SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // delegatecall type make the caller contract to be the owner of test contract (contract info) - Assert.assertEquals(Base58.encode58Check(callerContractAddress), + // delegatecall type make the caller contract to be the owner of test contract (contract info) + Assert.assertEquals( + Base58.encode58Check(callerContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // call type make the caller contract to be the owner of test contract + // call type make the caller contract to be the owner of test contract // (the contract address in transaction info) - Assert.assertEquals(Base58.encode58Check(callerContractAddress), + Assert.assertEquals( + Base58.encode58Check(callerContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = false, description = "Trigger test contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger test contract", + groups = {"contract", "daily"}) public void test04TriggerTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -289,17 +377,26 @@ public void test04TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - final String triggerTxid = PublicMethod.triggerContract(testContractAddress, - "plusOne()", "#", false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + final String triggerTxid = + PublicMethod.triggerContract( + testContractAddress, + "plusOne()", + "#", + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -314,27 +411,27 @@ public void test04TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); - Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); logger.info("ret: " + ret); @@ -342,31 +439,25 @@ public void test04TriggerTestContract() { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - SmartContract smartContract = PublicMethod.getContract(infoById.get().getContractAddress() - .toByteArray(), blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract( + infoById.get().getContractAddress().toByteArray(), blockingStubFull); long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); logger.info("ConsumeURPercent: " + consumeUserPercent); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test017.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test017.java index 5e84f96e..78fa3e74 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test017.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test017.java @@ -16,18 +16,19 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test017 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] testContractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,48 +38,75 @@ public class Create2Test017 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = false, description = "Deploy factory contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Deploy factory contract", + groups = {"contract", "daily"}) public void test01DeployFactoryContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "FactoryBytes"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "FactoryBytes"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -90,8 +118,8 @@ public void test01DeployFactoryContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -102,20 +130,29 @@ public void test01DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = false, description = "Trigger create2 with salt efffe", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger create2 with salt efffe", + groups = {"contract", "daily"}) public void test02TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -127,26 +164,35 @@ public void test02TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - final String saltHexString = "EFFFE"; - final String expectedSalt = "0EFFFE0000000000000000000000000000000000000000000000000000000000"; + String testContractCode = retMap.get("byteCode").toString(); + final String saltHexString = "EFFFE"; + final String expectedSalt = "0EFFFE0000000000000000000000000000000000000000000000000000000000"; logger.info("saltHexString: " + saltHexString); - String param = "\"" + testContractCode + "\",\"" + saltHexString + "\""; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,bytes32)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String param = "\"" + testContractCode + "\",\"" + saltHexString + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,bytes32)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -161,41 +207,41 @@ public void test02TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - // The first + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + // The first byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("addressHex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("addressFinal: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); - String actualSalt = retList.get(1); + String actualSalt = retList.get(1); logger.info("actualSalt: " + actualSalt); - byte[] tmpSenderAddress = new byte[20]; + byte[] tmpSenderAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(2)), 12, tmpSenderAddress, 0, 20); - String senderAddressHex = "41" + ByteArray.toHexString(tmpAddress); + String senderAddressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("senderAddressHex: " + senderAddressHex); - String senderAddressFinal = Base58.encode58Check(ByteArray.fromHexString(senderAddressHex)); + String senderAddressFinal = Base58.encode58Check(ByteArray.fromHexString(senderAddressHex)); logger.info("senderAddressFinal: " + senderAddressFinal); if (infoById.get().getResultValue() != 0) { @@ -206,26 +252,37 @@ public void test02TriggerCreate2ToDeployTestContract() { SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); Assert.assertEquals(expectedSalt, actualSalt); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = false, description = "Trigger create2 with salt affffa", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger create2 with salt affffa", + groups = {"contract", "daily"}) public void test03TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -237,25 +294,34 @@ public void test03TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - final String saltHexString = "AFFFFA"; - final String expectedSalt = "AFFFFA0000000000000000000000000000000000000000000000000000000000"; + String testContractCode = retMap.get("byteCode").toString(); + final String saltHexString = "AFFFFA"; + final String expectedSalt = "AFFFFA0000000000000000000000000000000000000000000000000000000000"; logger.info("saltHexString: " + saltHexString); - String param = "\"" + testContractCode + "\",\"" + saltHexString + "\""; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,bytes32)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String param = "\"" + testContractCode + "\",\"" + saltHexString + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,bytes32)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -270,41 +336,41 @@ public void test03TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - // The first + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + // The first byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("addressHex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("addressFinal: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); - String actualSalt = retList.get(1); + String actualSalt = retList.get(1); logger.info("actualSalt: " + actualSalt); - byte[] tmpSenderAddress = new byte[20]; + byte[] tmpSenderAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(2)), 12, tmpSenderAddress, 0, 20); - String senderAddressHex = "41" + ByteArray.toHexString(tmpAddress); + String senderAddressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("senderAddressHex: " + senderAddressHex); - String senderAddressFinal = Base58.encode58Check(ByteArray.fromHexString(senderAddressHex)); + String senderAddressFinal = Base58.encode58Check(ByteArray.fromHexString(senderAddressHex)); logger.info("senderAddressFinal: " + senderAddressFinal); if (infoById.get().getResultValue() != 0) { @@ -315,35 +381,30 @@ public void test03TriggerCreate2ToDeployTestContract() { SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); Assert.assertEquals(expectedSalt, actualSalt); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test018.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test018.java index cab03ceb..698237cd 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test018.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test018.java @@ -17,66 +17,94 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test018 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] testContractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(witnessKey2); } - @Test(enabled = false, description = "Deploy factory contract generated by new solidity", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Deploy factory contract generated by new solidity", + groups = {"contract", "daily"}) public void test01DeployFactoryContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(witnessAddress2, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + witnessAddress2, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "Factory"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -88,8 +116,8 @@ public void test01DeployFactoryContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -100,19 +128,28 @@ public void test01DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = false, description = "Trigger create2 function to deploy test contract " - + "using Witness account", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger create2 function to deploy test contract " + "using Witness account", + groups = {"contract", "daily"}) public void test02TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 9000_000_000_000L, 0, 1, - ByteString.copyFrom(witnessAddress2), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 9000_000_000_000L, + 0, + 1, + ByteString.copyFrom(witnessAddress2), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -124,23 +161,32 @@ public void test02TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(witnessAddress2, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(witnessAddress2, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(witnessAddress2, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = new Random().nextLong(); - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, witnessAddress2, witnessKey2, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = new Random().nextLong(); + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + witnessAddress2, + witnessKey2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -155,34 +201,34 @@ public void test02TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(witnessAddress2, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(witnessAddress2, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(witnessAddress2, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); @@ -193,27 +239,38 @@ public void test02TriggerCreate2ToDeployTestContract() { } SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = false, description = "Trigger Test contact", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger Test contact", + groups = {"contract", "daily"}) public void test03TriggerTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(witnessAddress2, witnessKey2, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(witnessAddress2), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + witnessAddress2, witnessKey2, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(witnessAddress2), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -225,17 +282,26 @@ public void test03TriggerTestContract() { accountResource = PublicMethod.getAccountResource(witnessAddress2, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(witnessAddress2, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(witnessAddress2, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - final String triggerTxid = PublicMethod.triggerContract(testContractAddress, - "plusOne()", "#", false, callValue, - 1000000000L, "0", 0, witnessAddress2, witnessKey2, - blockingStubFull); + Long callValue = Long.valueOf(0); + final String triggerTxid = + PublicMethod.triggerContract( + testContractAddress, + "plusOne()", + "#", + false, + callValue, + 1000000000L, + "0", + 0, + witnessAddress2, + witnessKey2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -250,27 +316,27 @@ public void test03TriggerTestContract() { accountResource = PublicMethod.getAccountResource(witnessAddress2, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(witnessAddress2, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(witnessAddress2, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); - Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); logger.info("ret: " + ret); @@ -278,29 +344,23 @@ public void test03TriggerTestContract() { Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); } - SmartContract smartContract = PublicMethod.getContract(infoById.get().getContractAddress() - .toByteArray(), blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract( + infoById.get().getContractAddress().toByteArray(), blockingStubFull); long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); logger.info("ConsumeURPercent: " + consumeUserPercent); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - witnessAddress2, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - witnessAddress2, blockingStubFull); - + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, witnessAddress2, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, witnessAddress2, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java index 44a166b5..1d70448a 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java @@ -7,10 +7,8 @@ import io.grpc.ManagedChannelBuilder; import java.util.HashMap; import java.util.Optional; -import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.AccountResourceMessage; @@ -23,18 +21,18 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.ProposalEnum; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test019 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -42,92 +40,115 @@ public class Create2Test019 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = true, description = "seted Value of Contract that created by create2," - + " should not be stored after contact suicided ande create2 again", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "seted Value of Contract that created by create2," + + " should not be stored after contact suicided ande create2 again", + groups = {"contract", "daily"}) public void testTriggerContract() { - String sendcoin = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 1000000000L, testNetAccountAddress, + String sendcoin = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 1000000000L, + testNetAccountAddress, testNetAccountKey, blockingStubFull); - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById0 = null; infoById0 = PublicMethod.getTransactionInfoById(sendcoin, blockingStubFull); logger.info("infoById0 " + infoById0.get()); - Assert.assertEquals(ByteArray.toHexString(infoById0.get().getContractResult(0).toByteArray()), - ""); + Assert.assertEquals( + ByteArray.toHexString(infoById0.get().getContractResult(0).toByteArray()), ""); Assert.assertEquals(infoById0.get().getResult().getNumber(), 0); Optional ById = PublicMethod.getTransactionById(sendcoin, blockingStubFull); - Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(), - SUCCESS_VALUE); + Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(), SUCCESS_VALUE); Assert.assertEquals(ById.get().getRet(0).getContractRetValue(), SUCCESS_VALUE); Assert.assertEquals(ById.get().getRet(0).getContractRet(), contractResult.SUCCESS); - String filePath = "src/test/resources/soliditycode/create2contractn2.sol"; - String contractName = "Factory"; + String filePath = "src/test/resources/soliditycode/create2contractn2.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String contractName1 = "TestConstract"; + String contractName1 = "TestConstract"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - String txid = ""; - String num = "\"" + code1 + "\"" + "," + 1; - txid = PublicMethod - .triggerContract(contractAddress, - "deploy(bytes,uint256)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + "," + 1; + txid = + PublicMethod.triggerContract( + contractAddress, + "deploy(bytes,uint256)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -137,12 +158,12 @@ public void testTriggerContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -153,21 +174,30 @@ public void testTriggerContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() - .toByteArray(); - String returnAddress = Base58.encode58Check(returnAddressBytes); + byte[] returnAddressBytes = + infoById.get().getInternalTransactions(0).getTransferToAddress().toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); - txid = PublicMethod - .triggerContract(returnAddressBytes, - "i()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + returnAddressBytes, + "i()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee1 = infoById1.get().getFee(); - Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); - Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); - Long netFee1 = infoById1.get().getReceipt().getNetFee(); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); logger.info("fee1:" + fee1); @@ -177,12 +207,12 @@ public void testTriggerContract() { logger.info("energyUsageTotal1:" + energyUsageTotal1); Account infoafter1 = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter1 = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance1 = infoafter1.getBalance(); - Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); - Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); - Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter1 = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance1); logger.info("afterEnergyUsed:" + afterEnergyUsed1); logger.info("afterNetUsed:" + afterNetUsed1); @@ -191,80 +221,140 @@ public void testTriggerContract() { Assert.assertTrue(infoById1.get().getResultValue() == 0); Assert.assertTrue(afterBalance1 + fee1 == afterBalance); Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); - txid = PublicMethod - .triggerContract(returnAddressBytes, - "set()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + returnAddressBytes, + "set()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - txid = PublicMethod - .triggerContract(returnAddressBytes, - "i()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + returnAddressBytes, + "i()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById1 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(5 == returnnumber); - String param1 = "\"" + Base58.encode58Check(returnAddressBytes) + "\""; + String param1 = "\"" + Base58.encode58Check(returnAddressBytes) + "\""; - txid = PublicMethod - .triggerContract(returnAddressBytes, - "testSuicideNonexistentTarget(address)", param1, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + returnAddressBytes, + "testSuicideNonexistentTarget(address)", + param1, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById2 = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById2 = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals("suicide", ByteArray - .toStr(infoById2.get().getInternalTransactions(0).getNote().toByteArray())); - TransactionExtention transactionExtention = PublicMethod - .triggerContractForExtention(returnAddressBytes, - "i()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); + Assert.assertEquals( + "suicide", + ByteArray.toStr(infoById2.get().getInternalTransactions(0).getNote().toByteArray())); + TransactionExtention transactionExtention = + PublicMethod.triggerContractForExtention( + returnAddressBytes, + "i()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull); System.out.println(transactionExtention.toString()); - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { Assert.assertEquals(true, transactionExtention.getResult().getResult()); - }else { - Assert.assertThat(transactionExtention.getResult().getCode().toString(), - containsString("CONTRACT_VALIDATE_ERROR")); - Assert.assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), - containsString("Contract validate error : No contract or not a valid smart contract")); + } else { + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_VALIDATE_ERROR")); + Assert.assertThat( + transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Contract validate error : No contract or not a valid smart contract")); } - txid = PublicMethod - .triggerContract(contractAddress, - "deploy(bytes,uint256)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "deploy(bytes,uint256)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById3 = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + Optional infoById3 = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { System.out.println(infoById3); Assert.assertEquals(TransactionInfo.code.FAILED, infoById3.get().getResult()); - }else { - byte[] returnAddressBytes1 = infoById3.get().getInternalTransactions(0).getTransferToAddress() - .toByteArray(); + } else { + byte[] returnAddressBytes1 = + infoById3.get().getInternalTransactions(0).getTransferToAddress().toByteArray(); String returnAddress1 = Base58.encode58Check(returnAddressBytes1); Assert.assertEquals(returnAddress1, returnAddress); - txid = PublicMethod - .triggerContract(returnAddressBytes1, - "i()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + returnAddressBytes1, + "i()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById1 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); } - } - - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java index f890b21c..367e0ca3 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java @@ -19,17 +19,18 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test020 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,75 +38,95 @@ public class Create2Test020 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = true, description = "Deploy Factory contract, create2 with salt type : trcToken", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy Factory contract, create2 with salt type : trcToken", + groups = {"contract", "daily"}) public void testTriggerContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 500000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 500000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/create2contract22.sol"; - String contractName = "Factory"; + String filePath = "src/test/resources/soliditycode/create2contract22.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String contractName1 = "TestConstract"; + String contractName1 = "TestConstract"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - String txid = ""; - String num = "\"" + code1 + "\"" + "," + 1000001; - txid = PublicMethod - .triggerContract(contractAddress, - "deploy(bytes,trcToken)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + "," + 1000001; + txid = + PublicMethod.triggerContract( + contractAddress, + "deploy(bytes,trcToken)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -115,12 +136,12 @@ public void testTriggerContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -131,21 +152,30 @@ public void testTriggerContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() - .toByteArray(); - String returnAddress = Base58.encode58Check(returnAddressBytes); + byte[] returnAddressBytes = + infoById.get().getInternalTransactions(0).getTransferToAddress().toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); - txid = PublicMethod - .triggerContract(returnAddressBytes, - "i()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + returnAddressBytes, + "i()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee1 = infoById1.get().getFee(); - Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); - Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); - Long netFee1 = infoById1.get().getReceipt().getNetFee(); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); logger.info("fee1:" + fee1); @@ -155,12 +185,12 @@ public void testTriggerContract() { logger.info("energyUsageTotal1:" + energyUsageTotal1); Account infoafter1 = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter1 = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance1 = infoafter1.getBalance(); - Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); - Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); - Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter1 = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance1); logger.info("afterEnergyUsed:" + afterEnergyUsed1); logger.info("afterNetUsed:" + afterNetUsed1); @@ -169,47 +199,59 @@ public void testTriggerContract() { Assert.assertTrue(infoById1.get().getResultValue() == 0); Assert.assertTrue(afterBalance1 + fee1 == afterBalance); Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); - } - - @Test(enabled = true, description = "Deploy Factory contract, create2 with salt type : uint8", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy Factory contract, create2 with salt type : uint8", + groups = {"contract", "daily"}) public void testTriggerContract1() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String contractName1 = "TestConstract"; - String filePath = "src/test/resources/soliditycode/create2contract22.sol"; + String contractName1 = "TestConstract"; + String filePath = "src/test/resources/soliditycode/create2contract22.sol"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - String txid = ""; - String num = "\"" + code1 + "\"" + "," + 1000031; - txid = PublicMethod - .triggerContract(contractAddress, - "deploy1(bytes,uint256)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + "," + 1000031; + txid = + PublicMethod.triggerContract( + contractAddress, + "deploy1(bytes,uint256)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -219,12 +261,12 @@ public void testTriggerContract1() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -235,21 +277,30 @@ public void testTriggerContract1() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() - .toByteArray(); - String returnAddress = Base58.encode58Check(returnAddressBytes); + byte[] returnAddressBytes = + infoById.get().getInternalTransactions(0).getTransferToAddress().toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); - txid = PublicMethod - .triggerContract(returnAddressBytes, - "i()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + returnAddressBytes, + "i()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee1 = infoById1.get().getFee(); - Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); - Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); - Long netFee1 = infoById1.get().getReceipt().getNetFee(); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); logger.info("fee1:" + fee1); @@ -259,12 +310,12 @@ public void testTriggerContract1() { logger.info("energyUsageTotal1:" + energyUsageTotal1); Account infoafter1 = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter1 = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance1 = infoafter1.getBalance(); - Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); - Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); - Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter1 = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance1); logger.info("afterEnergyUsed:" + afterEnergyUsed1); logger.info("afterNetUsed:" + afterNetUsed1); @@ -273,48 +324,59 @@ public void testTriggerContract1() { Assert.assertTrue(infoById1.get().getResultValue() == 0); Assert.assertTrue(afterBalance1 + fee1 == afterBalance); Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); - - } - - @Test(enabled = true, description = "Deploy Factory contract, create2 with salt type : address", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy Factory contract, create2 with salt type : address", + groups = {"contract", "daily"}) public void testTriggerContract2() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String contractName1 = "TestConstract"; - String filePath = "src/test/resources/soliditycode/create2contract22.sol"; + String contractName1 = "TestConstract"; + String filePath = "src/test/resources/soliditycode/create2contract22.sol"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - String txid = ""; - String num = "\"" + code1 + "\"" + ",\"" + Base58.encode58Check(contractExcAddress) + "\""; - txid = PublicMethod - .triggerContract(contractAddress, - "deploy2(bytes,address)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + ",\"" + Base58.encode58Check(contractExcAddress) + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "deploy2(bytes,address)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -324,12 +386,12 @@ public void testTriggerContract2() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -340,21 +402,30 @@ public void testTriggerContract2() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() - .toByteArray(); - String returnAddress = Base58.encode58Check(returnAddressBytes); + byte[] returnAddressBytes = + infoById.get().getInternalTransactions(0).getTransferToAddress().toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); - txid = PublicMethod - .triggerContract(returnAddressBytes, - "i()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + returnAddressBytes, + "i()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee1 = infoById1.get().getFee(); - Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); - Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); - Long netFee1 = infoById1.get().getReceipt().getNetFee(); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); logger.info("fee1:" + fee1); @@ -364,12 +435,12 @@ public void testTriggerContract2() { logger.info("energyUsageTotal1:" + energyUsageTotal1); Account infoafter1 = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter1 = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance1 = infoafter1.getBalance(); - Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); - Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); - Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter1 = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance1); logger.info("afterEnergyUsed:" + afterEnergyUsed1); logger.info("afterNetUsed:" + afterNetUsed1); @@ -378,48 +449,59 @@ public void testTriggerContract2() { Assert.assertTrue(infoById1.get().getResultValue() == 0); Assert.assertTrue(afterBalance1 + fee1 == afterBalance); Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); - - } - - @Test(enabled = true, description = "Deploy Factory contract, create2 with salt type : string", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy Factory contract, create2 with salt type : string", + groups = {"contract", "daily"}) public void testTriggerContract3() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String contractName1 = "TestConstract"; - String filePath = "src/test/resources/soliditycode/create2contract22.sol"; + String contractName1 = "TestConstract"; + String filePath = "src/test/resources/soliditycode/create2contract22.sol"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - String txid = ""; - String num = "\"" + code1 + "\"" + ",\"" + Base58.encode58Check(contractExcAddress) + "\""; - txid = PublicMethod - .triggerContract(contractAddress, - "deploy3(bytes,string)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + ",\"" + Base58.encode58Check(contractExcAddress) + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "deploy3(bytes,string)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -429,12 +511,12 @@ public void testTriggerContract3() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -445,21 +527,30 @@ public void testTriggerContract3() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() - .toByteArray(); - String returnAddress = Base58.encode58Check(returnAddressBytes); + byte[] returnAddressBytes = + infoById.get().getInternalTransactions(0).getTransferToAddress().toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); - txid = PublicMethod - .triggerContract(returnAddressBytes, - "i()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + returnAddressBytes, + "i()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee1 = infoById1.get().getFee(); - Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); - Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); - Long netFee1 = infoById1.get().getReceipt().getNetFee(); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); logger.info("fee1:" + fee1); @@ -469,12 +560,12 @@ public void testTriggerContract3() { logger.info("energyUsageTotal1:" + energyUsageTotal1); Account infoafter1 = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter1 = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance1 = infoafter1.getBalance(); - Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); - Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); - Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter1 = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance1); logger.info("afterEnergyUsed:" + afterEnergyUsed1); logger.info("afterNetUsed:" + afterNetUsed1); @@ -483,48 +574,60 @@ public void testTriggerContract3() { Assert.assertTrue(infoById1.get().getResultValue() == 0); Assert.assertTrue(afterBalance1 + fee1 == afterBalance); Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); - - } - - @Test(enabled = true, description = "TriggerContract a constant function created by create2" - + "can not create2 twice if salt type is string", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "TriggerContract a constant function created by create2" + + "can not create2 twice if salt type is string", + groups = {"contract", "daily"}) public void testTriggerContract4() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String contractName1 = "TestConstract1"; - String filePath = "src/test/resources/soliditycode/create2contract22.sol"; + String contractName1 = "TestConstract1"; + String filePath = "src/test/resources/soliditycode/create2contract22.sol"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - String txid = ""; - String num = "\"" + code1 + "\"" + ",\"" + Base58.encode58Check(contractAddress) + "\""; - txid = PublicMethod - .triggerContract(contractAddress, - "deploy3(bytes,string)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + ",\"" + Base58.encode58Check(contractAddress) + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "deploy3(bytes,string)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -534,12 +637,12 @@ public void testTriggerContract4() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -550,21 +653,30 @@ public void testTriggerContract4() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() - .toByteArray(); - String returnAddress = Base58.encode58Check(returnAddressBytes); + byte[] returnAddressBytes = + infoById.get().getInternalTransactions(0).getTransferToAddress().toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); - txid = PublicMethod - .triggerContract(returnAddressBytes, - "i()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + returnAddressBytes, + "i()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee1 = infoById1.get().getFee(); - Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); - Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); - Long netFee1 = infoById1.get().getReceipt().getNetFee(); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); logger.info("fee1:" + fee1); @@ -574,12 +686,12 @@ public void testTriggerContract4() { logger.info("energyUsageTotal1:" + energyUsageTotal1); Account infoafter1 = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter1 = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance1 = infoafter1.getBalance(); - Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); - Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); - Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter1 = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance1); logger.info("afterEnergyUsed:" + afterEnergyUsed1); logger.info("afterNetUsed:" + afterNetUsed1); @@ -588,62 +700,84 @@ public void testTriggerContract4() { Assert.assertTrue(infoById1.get().getResultValue() == 0); Assert.assertTrue(afterBalance1 + fee1 == afterBalance); Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(2 == returnnumber); - txid = PublicMethod - .triggerContract(contractAddress, - "deploy3(bytes,string)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "deploy3(bytes,string)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById2 = null; infoById2 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById2.get().getResultValue() != 0); - Assert - .assertThat(ByteArray - .toStr(infoById2.get().getResMessage().toByteArray()), - containsString("REVERT opcode executed")); + Assert.assertThat( + ByteArray.toStr(infoById2.get().getResMessage().toByteArray()), + containsString("REVERT opcode executed")); } - - @Test(enabled = true, description = "TriggerContract a constant function created by create2" - + "can not create2 twice if salt type is string", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "TriggerContract a constant function created by create2" + + "can not create2 twice if salt type is string", + groups = {"contract", "daily"}) public void testTriggerContract5() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String contractName1 = "TestConstract2"; - String filePath = "src/test/resources/soliditycode/create2contract22.sol"; + String contractName1 = "TestConstract2"; + String filePath = "src/test/resources/soliditycode/create2contract22.sol"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - String txid = ""; - String num = "\"" + code1 + "\"" + ",\"" + Base58.encode58Check(contractAddress) + "\""; - txid = PublicMethod - .triggerContract(contractAddress, - "deploy3(bytes,string)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + ",\"" + Base58.encode58Check(contractAddress) + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "deploy3(bytes,string)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -653,12 +787,12 @@ public void testTriggerContract5() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -669,21 +803,30 @@ public void testTriggerContract5() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() - .toByteArray(); - String returnAddress = Base58.encode58Check(returnAddressBytes); + byte[] returnAddressBytes = + infoById.get().getInternalTransactions(0).getTransferToAddress().toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); - txid = PublicMethod - .triggerContract(returnAddressBytes, - "i()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + returnAddressBytes, + "i()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee1 = infoById1.get().getFee(); - Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); - Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); - Long netFee1 = infoById1.get().getReceipt().getNetFee(); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); logger.info("fee1:" + fee1); @@ -693,12 +836,12 @@ public void testTriggerContract5() { logger.info("energyUsageTotal1:" + energyUsageTotal1); Account infoafter1 = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter1 = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance1 = infoafter1.getBalance(); - Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); - Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); - Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter1 = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance1); logger.info("afterEnergyUsed:" + afterEnergyUsed1); logger.info("afterNetUsed:" + afterNetUsed1); @@ -707,63 +850,85 @@ public void testTriggerContract5() { Assert.assertTrue(infoById1.get().getResultValue() == 0); Assert.assertTrue(afterBalance1 + fee1 == afterBalance); Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(3 == returnnumber); num = "\"" + code1 + "\"" + ",\"" + Base58.encode58Check(testNetAccountAddress) + "\""; - txid = PublicMethod - .triggerContract(contractAddress, - "deploy3(bytes,string)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "deploy3(bytes,string)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById2 = null; infoById2 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById2.get().getResultValue() != 0); - Assert - .assertThat(ByteArray - .toStr(infoById2.get().getResMessage().toByteArray()), - containsString("REVERT opcode executed")); + Assert.assertThat( + ByteArray.toStr(infoById2.get().getResMessage().toByteArray()), + containsString("REVERT opcode executed")); } - - @Test(enabled = true, description = "TriggerContract a constant function created by create2" - + "can not create2 twice if salt type is string", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "TriggerContract a constant function created by create2" + + "can not create2 twice if salt type is string", + groups = {"contract", "daily"}) public void testTriggerContract6() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String contractName1 = "TestConstract3"; - String filePath = "src/test/resources/soliditycode/create2contract22.sol"; + String contractName1 = "TestConstract3"; + String filePath = "src/test/resources/soliditycode/create2contract22.sol"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - String txid = ""; - String num = "\"" + code1 + "\"" + ",\"" + Base58.encode58Check(contractAddress) + "\""; - txid = PublicMethod - .triggerContract(contractAddress, - "deploy3(bytes,string)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + ",\"" + Base58.encode58Check(contractAddress) + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "deploy3(bytes,string)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -773,12 +938,12 @@ public void testTriggerContract6() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -789,21 +954,30 @@ public void testTriggerContract6() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() - .toByteArray(); - String returnAddress = Base58.encode58Check(returnAddressBytes); + byte[] returnAddressBytes = + infoById.get().getInternalTransactions(0).getTransferToAddress().toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); - txid = PublicMethod - .triggerContract(returnAddressBytes, - "i()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + returnAddressBytes, + "i()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee1 = infoById1.get().getFee(); - Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); - Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); - Long netFee1 = infoById1.get().getReceipt().getNetFee(); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); logger.info("fee1:" + fee1); @@ -813,12 +987,12 @@ public void testTriggerContract6() { logger.info("energyUsageTotal1:" + energyUsageTotal1); Account infoafter1 = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter1 = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance1 = infoafter1.getBalance(); - Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); - Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); - Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter1 = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance1); logger.info("afterEnergyUsed:" + afterEnergyUsed1); logger.info("afterNetUsed:" + afterNetUsed1); @@ -827,38 +1001,46 @@ public void testTriggerContract6() { Assert.assertTrue(infoById1.get().getResultValue() == 0); Assert.assertTrue(afterBalance1 + fee1 == afterBalance); Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(4 == returnnumber); - String fakeAddress = "FFFFFFF"; + String fakeAddress = "FFFFFFF"; num = "\"" + code1 + "\"" + ",\"" + fakeAddress + "\""; - txid = PublicMethod - .triggerContract(contractAddress, - "deploy3(bytes,string)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "deploy3(bytes,string)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById2 = null; infoById2 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById2.get().getResultValue() != 0); - Assert - .assertThat(ByteArray - .toStr(infoById2.get().getResMessage().toByteArray()), - containsString("REVERT opcode executed")); + Assert.assertThat( + ByteArray.toStr(infoById2.get().getResMessage().toByteArray()), + containsString("REVERT opcode executed")); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java index a6f2a071..d7daf6ec 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java @@ -19,11 +19,12 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test021 extends TronBaseTest { @@ -31,8 +32,8 @@ public class Create2Test021 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final String name = "Asset008_" + Long.toString(now); private static final long totalSupply = now; - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -45,99 +46,151 @@ public class Create2Test021 extends TronBaseTest { String resourceOnwerKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); ECKey ecKey3 = new ECKey(Utils.getRandom()); private byte[] contractExcAddress = ecKey3.getAddress(); private String contractExcKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() throws Exception { initSolidityChannel(); PublicMethod.printAddress(contractExcKey); - PublicMethod.printAddress(resourceOnwerKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(resourceOnwerKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - if(PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { throw new SkipException("Skipping freezeV2 test case"); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + if (PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + throw new SkipException("Skipping freezeV2 test case"); } - } - @Test(enabled = true, description = "resource delegate with create2 contract, and suicide ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "resource delegate with create2 contract, and suicide ", + groups = {"contract", "daily"}) public void test1TriggerContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .sendcoin(resourceOnwerAddress, 1000000000L + 1024000000L, testNetAccountAddress, + Assert.assertTrue( + PublicMethod.sendcoin( + resourceOnwerAddress, + 1000000000L + 1024000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + testNetAccountAddress, + 10000000000L, + 0, + 0, + ByteString.copyFrom(resourceOnwerAddress), + testNetAccountKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + testNetAccountAddress, + 10000000000L, + 0, + 1, + ByteString.copyFrom(resourceOnwerAddress), testNetAccountKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(testNetAccountAddress, 10000000000L, 0, 0, - ByteString.copyFrom(resourceOnwerAddress), testNetAccountKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(testNetAccountAddress, 10000000000L, 0, 1, - ByteString.copyFrom(resourceOnwerAddress), testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Create 3 the same name token. + // Create 3 the same name token. Long start = System.currentTimeMillis() + 2000; - Long end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod.createAssetIssue(resourceOnwerAddress, - name, totalSupply, 1, 1, start, end, 1, description, url, - 2000L, 2000L, 1L, 1L, resourceOnwerKey, blockingStubFull)); - String filePath = "src/test/resources/soliditycode/create2contractn.sol"; - String contractName = "Factory"; + Long end = System.currentTimeMillis() + 1000000000; + Assert.assertTrue( + PublicMethod.createAssetIssue( + resourceOnwerAddress, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + resourceOnwerKey, + blockingStubFull)); + String filePath = "src/test/resources/soliditycode/create2contractn.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - Long beforeExcAccountBalance = PublicMethod - .queryAccount(resourceOnwerAddress, blockingStubFull).getBalance(); - // create2 TestContract + Long beforeExcAccountBalance = + PublicMethod.queryAccount(resourceOnwerAddress, blockingStubFull).getBalance(); + // create2 TestContract String contractName1 = "TestConstract"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String txid = ""; - String num = "\"" + code1 + "\"" + "," + 1; - txid = PublicMethod - .triggerContract(contractAddress, - "deploy(bytes,uint256)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + "," + 1; + txid = + PublicMethod.triggerContract( + contractAddress, + "deploy(bytes,uint256)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -147,99 +200,161 @@ public void test1TriggerContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); Assert.assertTrue(infoById.get().getResultValue() == 0); - byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() - .toByteArray(); - String returnAddress = Base58.encode58Check(returnAddressBytes); + byte[] returnAddressBytes = + infoById.get().getInternalTransactions(0).getTransferToAddress().toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); bytes = returnAddressBytes; - // freezeBalanceForReceiver to create2 contract Address, transaction Failed + // freezeBalanceForReceiver to create2 contract Address, transaction Failed - Assert.assertFalse(PublicMethod.freezeBalanceForReceiver(resourceOnwerAddress, 5000000L, 0, 0, - ByteString.copyFrom(bytes), resourceOnwerKey, blockingStubFull)); - Assert.assertFalse(PublicMethod.freezeBalanceForReceiver(resourceOnwerAddress, 5000000L, 0, 1, - ByteString.copyFrom(bytes), resourceOnwerKey, blockingStubFull)); - Long afterExcAccountBalance = PublicMethod.queryAccount(resourceOnwerAddress, blockingStubFull) - .getBalance(); + Assert.assertFalse( + PublicMethod.freezeBalanceForReceiver( + resourceOnwerAddress, + 5000000L, + 0, + 0, + ByteString.copyFrom(bytes), + resourceOnwerKey, + blockingStubFull)); + Assert.assertFalse( + PublicMethod.freezeBalanceForReceiver( + resourceOnwerAddress, + 5000000L, + 0, + 1, + ByteString.copyFrom(bytes), + resourceOnwerKey, + blockingStubFull)); + Long afterExcAccountBalance = + PublicMethod.queryAccount(resourceOnwerAddress, blockingStubFull).getBalance(); Assert.assertTrue(PublicMethod.getAccountResource(bytes, blockingStubFull).getNetLimit() == 0); - Assert - .assertTrue(PublicMethod.getAccountResource(bytes, blockingStubFull).getEnergyLimit() == 0); + Assert.assertTrue( + PublicMethod.getAccountResource(bytes, blockingStubFull).getEnergyLimit() == 0); logger.info("afterExcAccountBalance: " + afterExcAccountBalance); logger.info("beforeExcAccountBalance:" + beforeExcAccountBalance); Assert.assertTrue(afterExcAccountBalance - beforeExcAccountBalance == 0); - // create2 Address Suicide + // create2 Address Suicide String param2 = "\"" + Base58.encode58Check(contractExcAddress) + "\""; - String txidn = PublicMethod - .triggerContract(bytes, - "testSuicideNonexistentTarget(address)", param2, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String txidn = + PublicMethod.triggerContract( + bytes, + "testSuicideNonexistentTarget(address)", + param2, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - // active create2 Address to normal Address - Assert.assertTrue(PublicMethod - .sendcoin(bytes, 1000000L, contractExcAddress, contractExcKey, blockingStubFull)); - //Trigger contract to transfer trx and token. - Account getAssetIdFromAccount = PublicMethod - .queryAccount(resourceOnwerAddress, blockingStubFull); + // active create2 Address to normal Address + Assert.assertTrue( + PublicMethod.sendcoin( + bytes, 1000000L, contractExcAddress, contractExcKey, blockingStubFull)); + // Trigger contract to transfer trx and token. + Account getAssetIdFromAccount = + PublicMethod.queryAccount(resourceOnwerAddress, blockingStubFull); assetAccountId = getAssetIdFromAccount.getAssetIssuedID(); - Long contractBeforeBalance = PublicMethod.queryAccount(bytes, blockingStubFull).getBalance(); + Long contractBeforeBalance = PublicMethod.queryAccount(bytes, blockingStubFull).getBalance(); Assert.assertTrue( - PublicMethod.transferAsset(bytes, assetAccountId.toByteArray(), 100, resourceOnwerAddress, + PublicMethod.transferAsset( + bytes, + assetAccountId.toByteArray(), + 100, + resourceOnwerAddress, resourceOnwerKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account account1 = PublicMethod.queryAccount(bytes, blockingStubFull); - int typeValue1 = account1.getTypeValue(); + int typeValue1 = account1.getTypeValue(); Assert.assertEquals(0, typeValue1); - // freezeBalanceForReceiver to "create2" contract Address, transaction SUCCESS - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(resourceOnwerAddress, 1000000L, 0, 0, - ByteString.copyFrom(bytes), resourceOnwerKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(resourceOnwerAddress, 1000000L, 0, 1, - ByteString.copyFrom(bytes), resourceOnwerKey, blockingStubFull)); + // freezeBalanceForReceiver to "create2" contract Address, transaction SUCCESS + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + resourceOnwerAddress, + 1000000L, + 0, + 0, + ByteString.copyFrom(bytes), + resourceOnwerKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + resourceOnwerAddress, + 1000000L, + 0, + 1, + ByteString.copyFrom(bytes), + resourceOnwerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - beforeExcAccountBalance = PublicMethod.queryAccount(resourceOnwerAddress, blockingStubFull) - .getBalance(); + beforeExcAccountBalance = + PublicMethod.queryAccount(resourceOnwerAddress, blockingStubFull).getBalance(); - Assert.assertTrue(PublicMethod.unFreezeBalance(resourceOnwerAddress, resourceOnwerKey, - 0, bytes, blockingStubFull)); - Assert.assertTrue(PublicMethod.unFreezeBalance(resourceOnwerAddress, resourceOnwerKey, - 1, bytes, blockingStubFull)); + Assert.assertTrue( + PublicMethod.unFreezeBalance( + resourceOnwerAddress, resourceOnwerKey, 0, bytes, blockingStubFull)); + Assert.assertTrue( + PublicMethod.unFreezeBalance( + resourceOnwerAddress, resourceOnwerKey, 1, bytes, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long afterUnfreezeBalance = PublicMethod.queryAccount(resourceOnwerAddress, blockingStubFull) - .getBalance(); + Long afterUnfreezeBalance = + PublicMethod.queryAccount(resourceOnwerAddress, blockingStubFull).getBalance(); Assert.assertTrue(afterUnfreezeBalance == beforeExcAccountBalance + 1000000L * 2); - // create2 TestContract to turn AccountType To create2 Contract Address - txid = PublicMethod - .triggerContract(contractAddress, - "deploy(bytes,uint256)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - // triggercontract Create2 address, function normal - txid = PublicMethod - .triggerContract(returnAddressBytes, - "i()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + // create2 TestContract to turn AccountType To create2 Contract Address + txid = + PublicMethod.triggerContract( + contractAddress, + "deploy(bytes,uint256)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + // triggercontract Create2 address, function normal + txid = + PublicMethod.triggerContract( + returnAddressBytes, + "i()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee1 = infoById1.get().getFee(); - Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); - Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); - Long netFee1 = infoById1.get().getReceipt().getNetFee(); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); logger.info("fee1:" + fee1); @@ -249,91 +364,114 @@ public void test1TriggerContract() { logger.info("energyUsageTotal1:" + energyUsageTotal1); Account infoafter1 = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter1 = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance1 = infoafter1.getBalance(); - Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); - Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); - Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter1 = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance1); logger.info("afterEnergyUsed:" + afterEnergyUsed1); logger.info("afterNetUsed:" + afterNetUsed1); logger.info("afterFreeNetUsed:" + afterFreeNetUsed1); Assert.assertTrue(infoById1.get().getResultValue() == 0); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); Account account = PublicMethod.queryAccount(returnAddressBytes, blockingStubFull); - int typeValue = account.getTypeValue(); + int typeValue = account.getTypeValue(); Assert.assertEquals(2, typeValue); Assert.assertEquals(account.getBalance(), 1000000); } - @Test(enabled = true, description = "Create2 contract can transfer trx and token.", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Create2 contract can transfer trx and token.", + groups = {"contract", "daily"}) public void test2TriggerContract() { Account accountbefore = PublicMethod.queryAccount(bytes, blockingStubFull); - int typeValue = accountbefore.getTypeValue(); + int typeValue = accountbefore.getTypeValue(); Assert.assertEquals(2, typeValue); long accountbeforeBalance = accountbefore.getBalance(); Assert.assertEquals(accountbeforeBalance, 1000000); - Account contractExcAddressbefore = PublicMethod - .queryAccount(contractExcAddress, blockingStubFull); + Account contractExcAddressbefore = + PublicMethod.queryAccount(contractExcAddress, blockingStubFull); long contractExcAddressbeforeBalance = contractExcAddressbefore.getBalance(); - String num = "1"; - String txid = PublicMethod - .triggerContract(bytes, - "testTransfer(uint256)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String num = "1"; + String txid = + PublicMethod.triggerContract( + bytes, + "testTransfer(uint256)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional transactionInfoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(transactionInfoById.get().getResultValue() == 0); - Long fee1 = transactionInfoById.get().getFee(); + Long fee1 = transactionInfoById.get().getFee(); Account accountafter = PublicMethod.queryAccount(bytes, blockingStubFull); long accountafterBalance = accountafter.getBalance(); Assert.assertTrue(accountbeforeBalance - 1 == accountafterBalance); - Account contractExcAddressafter = PublicMethod - .queryAccount(contractExcAddress, blockingStubFull); + Account contractExcAddressafter = + PublicMethod.queryAccount(contractExcAddress, blockingStubFull); long contractExcAddressafterBalance = contractExcAddressafter.getBalance(); Assert.assertTrue(contractExcAddressbeforeBalance + 1 - fee1 == contractExcAddressafterBalance); num = "1" + ",\"" + assetAccountId.toStringUtf8() + "\""; - Long returnAddressBytesAccountCountBefore = PublicMethod - .getAssetIssueValue(bytes, assetAccountId, blockingStubFull); - Long contractExcAddressAccountCountBefore = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - String txid1 = PublicMethod - .triggerContract(bytes, - "testTransferToken(uint256,trcToken)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + Long returnAddressBytesAccountCountBefore = + PublicMethod.getAssetIssueValue(bytes, assetAccountId, blockingStubFull); + Long contractExcAddressAccountCountBefore = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + bytes, + "testTransferToken(uint256,trcToken)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfoById1 = PublicMethod - .getTransactionInfoById(txid1, blockingStubFull); + Optional transactionInfoById1 = + PublicMethod.getTransactionInfoById(txid1, blockingStubFull); Assert.assertTrue(transactionInfoById1.get().getResultValue() == 0); - Long returnAddressBytesAccountCountAfter = PublicMethod - .getAssetIssueValue(bytes, assetAccountId, blockingStubFull); - Long contractExcAddressAccountCountAfter = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long returnAddressBytesAccountCountAfter = + PublicMethod.getAssetIssueValue(bytes, assetAccountId, blockingStubFull); + Long contractExcAddressAccountCountAfter = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); Assert.assertTrue( returnAddressBytesAccountCountBefore - 1 == returnAddressBytesAccountCountAfter); Assert.assertTrue( contractExcAddressAccountCountBefore + 1 == contractExcAddressAccountCountAfter); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - Assert.assertTrue(PublicMethod.unFreezeBalance(testNetAccountAddress, testNetAccountKey, - 0, resourceOnwerAddress, blockingStubFull)); - Assert.assertTrue(PublicMethod.unFreezeBalance(testNetAccountAddress, testNetAccountKey, - 1, resourceOnwerAddress, blockingStubFull)); if (channelFull1 != null) { + Assert.assertTrue( + PublicMethod.unFreezeBalance( + testNetAccountAddress, testNetAccountKey, 0, resourceOnwerAddress, blockingStubFull)); + Assert.assertTrue( + PublicMethod.unFreezeBalance( + testNetAccountAddress, testNetAccountKey, 1, resourceOnwerAddress, blockingStubFull)); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - -} \ No newline at end of file + } + } +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test023.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test023.java index c53363c3..3c5c3af0 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test023.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test023.java @@ -14,18 +14,19 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test023 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] testContractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -35,56 +36,82 @@ public class Create2Test023 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - public byte[] subByte(byte[] b, int off, int length) { byte[] b1 = new byte[length]; System.arraycopy(b, off, b1, 0, length); return b1; - } - @Test(enabled = true, description = "Deploy factory contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy factory contract", + groups = {"contract", "daily"}) public void test01DeployFactoryContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 10000_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 10000_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L * 2, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 10000_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 10000_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + dev001Address, dev001Key, 170000L * 2, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/Create2Test023.sol"; - String contractName = "factory"; + String filePath = "./src/test/resources/soliditycode/Create2Test023.sol"; + String contractName = "factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -96,8 +123,8 @@ public void test01DeployFactoryContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -108,21 +135,30 @@ public void test01DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "contract A new B contract,A suicide,contract B still exist", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "contract A new B contract,A suicide,contract B still exist", + groups = {"contract", "daily"}) public void test02TriggerTestContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000 * 5L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000 * 5L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -134,17 +170,26 @@ public void test02TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "testCreate()", "#", false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "testCreate()", + "#", + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -159,24 +204,24 @@ public void test02TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); - byte[] a = infoById.get().getContractResult(0).toByteArray(); - byte[] b = subByte(a, 11, 1); - byte[] c = subByte(a, 0, 11); - byte[] e = "41".getBytes(); - byte[] d = subByte(a, 12, 20); + byte[] a = infoById.get().getContractResult(0).toByteArray(); + byte[] b = subByte(a, 11, 1); + byte[] c = subByte(a, 0, 11); + byte[] e = "41".getBytes(); + byte[] d = subByte(a, 12, 20); logger.info("a:" + ByteArray.toHexString(a)); @@ -186,60 +231,80 @@ public void test02TriggerTestContract() { logger.info("d:" + ByteArray.toHexString(d)); logger.info("41" + ByteArray.toHexString(d)); - String exceptedResult = "41" + ByteArray.toHexString(d); - String realResult = ByteArray.toHexString(b); + String exceptedResult = "41" + ByteArray.toHexString(d); + String realResult = ByteArray.toHexString(b); Assert.assertEquals(realResult, "00"); Assert.assertNotEquals(realResult, "41"); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(exceptedResult)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(exceptedResult)); logger.info("B Address : " + addressFinal); - //B Address is created by A, Trigger contract B - triggerTxid = PublicMethod.triggerContract(ByteArray.fromHexString(exceptedResult), - "test()", "#", false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + // B Address is created by A, Trigger contract B + triggerTxid = + PublicMethod.triggerContract( + ByteArray.fromHexString(exceptedResult), + "test()", + "#", + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(infoById.get().getResultValue(), 0); Assert.assertEquals(ByteArray.toLong(infoById.get().getContractResult(0).toByteArray()), 1); Assert.assertEquals("SUCESS", infoById.get().getResult().toString()); - triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "kill()", "#", false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "kill()", + "#", + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); - String note = ByteArray - .toStr(infoById.get().getInternalTransactions(0).getNote().toByteArray()); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); + String note = + ByteArray.toStr(infoById.get().getInternalTransactions(0).getNote().toByteArray()); Assert.assertEquals(infoById.get().getResultValue(), 0); Assert.assertEquals("SUCESS", infoById.get().getResult().toString()); Assert.assertEquals("suicide", note); - triggerTxid = PublicMethod.triggerContract(ByteArray.fromHexString(exceptedResult), - "test()", "#", false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + ByteArray.fromHexString(exceptedResult), + "test()", + "#", + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(infoById.get().getResultValue(), 0); Assert.assertEquals("SUCESS", infoById.get().getResult().toString()); Assert.assertEquals(1, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test024.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test024.java index 4f9b8216..3c1f7b26 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test024.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test024.java @@ -15,18 +15,19 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test024 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] testContractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -36,48 +37,61 @@ public class Create2Test024 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - public byte[] subByte(byte[] b, int off, int length) { byte[] b1 = new byte[length]; System.arraycopy(b, off, b1, 0, length); return b1; - } - @Test(enabled = true, description = "Deploy factory contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy factory contract", + groups = {"contract", "daily"}) public void test01DeployFactoryContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 10000_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 10000_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 10000_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 10000_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/Create2Test024.sol"; - String contractName = "Factory"; + String filePath = "./src/test/resources/soliditycode/Create2Test024.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -89,8 +103,8 @@ public void test01DeployFactoryContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -101,16 +115,19 @@ public void test01DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "create2 not allowed create2 twice in function", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "create2 not allowed create2 twice in function", + groups = {"contract", "daily"}) public void test02TriggerTestContract() { - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -122,23 +139,32 @@ public void test02TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/Create2Test024.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/Create2Test024.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 4L; - String param = "\"" + testContractCode + "\"," + salt; - String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 4L; + String param = "\"" + testContractCode + "\"," + salt; + String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -153,20 +179,20 @@ public void test02TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); - byte[] a = infoById.get().getContractResult(0).toByteArray(); - byte[] b = subByte(a, 11, 1); - byte[] c = subByte(a, 0, 11); - byte[] e = "41".getBytes(); - byte[] d = subByte(a, 12, 20); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); + byte[] a = infoById.get().getContractResult(0).toByteArray(); + byte[] b = subByte(a, 11, 1); + byte[] c = subByte(a, 0, 11); + byte[] e = "41".getBytes(); + byte[] d = subByte(a, 12, 20); logger.info("a:" + ByteArray.toHexString(a)); @@ -176,23 +202,31 @@ public void test02TriggerTestContract() { logger.info("d:" + ByteArray.toHexString(d)); logger.info("41" + ByteArray.toHexString(d)); - String exceptedResult = "41" + ByteArray.toHexString(d); - String realResult = ByteArray.toHexString(b); + String exceptedResult = "41" + ByteArray.toHexString(d); + String realResult = ByteArray.toHexString(b); Assert.assertEquals(realResult, "00"); Assert.assertNotEquals(realResult, "41"); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(exceptedResult)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(exceptedResult)); logger.info("create2 Address : " + addressFinal); Assert.assertEquals(infoById.get().getResult().toString(), "SUCESS"); Assert.assertEquals(infoById.get().getResultValue(), 0); - triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy2(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy2(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); devEnergyLimitAfter = accountResource.getEnergyLimit(); @@ -206,8 +240,7 @@ public void test02TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); userEnergyLimitAfter = accountResource.getEnergyLimit(); userEnergyUsageAfter = accountResource.getEnergyUsed(); - userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); @@ -218,21 +251,17 @@ public void test02TriggerTestContract() { Assert.assertEquals(infoById.get().getResultValue(), 1); Assert.assertEquals(infoById.get().getResult().toString(), "FAILED"); - Assert.assertThat(ByteArray.toStr(infoById.get().getResMessage().toByteArray()), + Assert.assertThat( + ByteArray.toStr(infoById.get().getResMessage().toByteArray()), containsString("REVERT opcode executed")); - - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test025.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test025.java index 64693afa..3b0ae585 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test025.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test025.java @@ -15,18 +15,19 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class Create2Test025 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] testContractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -36,43 +37,58 @@ public class Create2Test025 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = false, description = "Deploy factory contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Deploy factory contract", + groups = {"contract", "daily"}) public void test01DeployFactoryContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 10000_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 10000_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 10000_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 10000_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/Create2Test025.sol"; - String contractName = "Factory"; + String filePath = "./src/test/resources/soliditycode/Create2Test025.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); code += "05"; - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -84,8 +100,8 @@ public void test01DeployFactoryContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -96,20 +112,23 @@ public void test01DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = false, description = "create2 bytecode with parm", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "create2 bytecode with parm", + groups = {"contract", "daily"}) public void test02TriggerTestContract() { - //Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, // PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, // blockingStubFull), 0, 1, // ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -121,24 +140,33 @@ public void test02TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - String filePath = "./src/test/resources/soliditycode/Create2Test025.sol"; - String contractName = "TestContract"; + String filePath = "./src/test/resources/soliditycode/Create2Test025.sol"; + String contractName = "TestContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); + String testContractCode = retMap.get("byteCode").toString(); testContractCode += "0000000000000000000000000000000000000000000000000000000000000005"; - Long salt = 4L; - String param = "\"" + testContractCode + "\"," + salt; - String triggerTxid = null; - triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "create2(bytes,uint256)", param, false, 0L, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long salt = 4L; + String param = "\"" + testContractCode + "\"," + salt; + String triggerTxid = null; + triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "create2(bytes,uint256)", + param, + false, + 0L, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -153,51 +181,59 @@ public void test02TriggerTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); - String txid = PublicMethod.triggerContract(testContractAddress, - "getNum()", "#", false, 0L, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); - Optional infoById2 = PublicMethod.getTransactionInfoById(txid, - blockingStubFull); + String txid = + PublicMethod.triggerContract( + testContractAddress, + "getNum()", + "#", + false, + 0L, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); + Optional infoById2 = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); TransactionInfo transactionInfo2 = infoById2.get(); - final int Num = ByteArray.toInt(transactionInfo2.getContractResult(0).toByteArray()); + final int Num = ByteArray.toInt(transactionInfo2.getContractResult(0).toByteArray()); accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); userEnergyLimitAfter = accountResource.getEnergyLimit(); userEnergyUsageAfter = accountResource.getEnergyUsed(); - userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); @@ -207,19 +243,14 @@ public void test02TriggerTestContract() { Assert.assertEquals(infoById.get().getResult().toString(), "SUCESS"); Assert.assertEquals(infoById.get().getResultValue(), 0); Assert.assertEquals(5, Num); - - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java index e0896e4a..78d7b9c1 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java @@ -19,17 +19,18 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.Hash; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ExtCodeHashTest001 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] extCodeHashContractAddress = null; private byte[] testContractAddress = null; private String testContractAddress2 = null; @@ -44,51 +45,78 @@ public class ExtCodeHashTest001 extends TronBaseTest { private byte[] testAddress = ecKey3.getAddress(); private String testKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy extcodehash contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy extcodehash contract", + groups = {"contract", "daily"}) public void test01DeployExtCodeHashContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; - String contractName = "TestExtCodeHash"; + String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; + String contractName = "TestExtCodeHash"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); expectedCodeHash = ByteArray.toHexString(Hash.sha3(Hex.decode(code))); logger.info("expectedCodeHash: " + expectedCodeHash); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -100,8 +128,8 @@ public void test01DeployExtCodeHashContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -112,20 +140,29 @@ public void test01DeployExtCodeHashContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(extCodeHashContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(extCodeHashContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = false, description = "Get the extcodehash of a normal address", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Get the extcodehash of a normal address", + groups = {"contract", "daily"}) public void test02GetNormalAddressCodeHash() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -137,18 +174,27 @@ public void test02GetNormalAddressCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String param = "\"" + Base58.encode58Check(dev001Address) + "\""; - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByAddr(address)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + String param = "\"" + Base58.encode58Check(dev001Address) + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByAddr(address)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -164,41 +210,42 @@ public void test02GetNormalAddressCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); if (infoById.get().getResultValue() != 0) { - Assert.fail("transaction failed with message: " - + infoById.get().getResMessage().toStringUtf8()); + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); - - logger.info( - "the value: " + retList); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); - Assert.assertEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", - retList.get(0)); + logger.info("the value: " + retList); + Assert.assertEquals( + "C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", retList.get(0)); } - @Test(enabled = true, description = "Get a contract extcodehash", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Get a contract extcodehash", + groups = {"contract", "daily"}) public void test03GetContactCodeHash() { - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -210,18 +257,27 @@ public void test03GetContactCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String param = "\"" + Base58.encode58Check(extCodeHashContractAddress) + "\""; - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByAddr(address)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + String param = "\"" + Base58.encode58Check(extCodeHashContractAddress) + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByAddr(address)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -237,15 +293,15 @@ public void test03GetContactCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -256,36 +312,39 @@ public void test03GetContactCodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); logger.info("the value: " + retList); Assert.assertFalse(retList.isEmpty()); - Assert.assertNotEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", - retList.get(0)); - Assert.assertNotEquals("0000000000000000000000000000000000000000000000000000000000000000", - retList.get(0)); + Assert.assertNotEquals( + "C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", retList.get(0)); + Assert.assertNotEquals( + "0000000000000000000000000000000000000000000000000000000000000000", retList.get(0)); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } - @Test(enabled = true, description = "Get a not exist account extcodehash", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Get a not exist account extcodehash", + groups = {"contract", "daily"}) public void test04GetNotExistAddressCodeHash() { - PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, blockingStubFull); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -297,18 +356,27 @@ public void test04GetNotExistAddressCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String param = "\"" + Base58.encode58Check(testAddress) + "\""; - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByAddr(address)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + String param = "\"" + Base58.encode58Check(testAddress) + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByAddr(address)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -324,15 +392,15 @@ public void test04GetNotExistAddressCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -343,33 +411,41 @@ public void test04GetNotExistAddressCodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); - logger.info( - "the value: " + retList); + logger.info("the value: " + retList); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", - retList.get(0)); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000000", retList.get(0)); - SmartContract smartContract = PublicMethod - .getContract(extCodeHashContractAddress, blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(extCodeHashContractAddress, blockingStubFull); logger.info(smartContract.getBytecode().toStringUtf8()); } - @Test(enabled = true, description = "Active the account and get extcodehash again", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Active the account and get extcodehash again", + groups = {"contract", "daily"}) public void test05ActiveAccountGetCodeHash() { - Assert.assertTrue(PublicMethod.sendcoin(testAddress, 1000000, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin(testAddress, 1000000, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -381,18 +457,27 @@ public void test05ActiveAccountGetCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String param = "\"" + Base58.encode58Check(testAddress) + "\""; - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByAddr(address)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + String param = "\"" + Base58.encode58Check(testAddress) + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByAddr(address)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -408,15 +493,15 @@ public void test05ActiveAccountGetCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -427,29 +512,37 @@ public void test05ActiveAccountGetCodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); logger.info("the value: " + retList); - Assert.assertEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", - retList.get(0)); + Assert.assertEquals( + "C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", retList.get(0)); - SmartContract smartContract = PublicMethod - .getContract(extCodeHashContractAddress, blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(extCodeHashContractAddress, blockingStubFull); logger.info(smartContract.getBytecode().toStringUtf8()); - } - @Test(enabled = true, description = "Get a not deployed create2 extcodehash", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Get a not deployed create2 extcodehash", + groups = {"contract", "daily"}) public void test06GetCreate2CodeHash() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -461,28 +554,39 @@ public void test06GetCreate2CodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; - String contractName = "TestExtCodeHash"; + String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; + String contractName = "TestExtCodeHash"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - final String abi = retMap.get("abI").toString(); - Long salt = 100L; + String code = retMap.get("byteCode").toString(); + final String abi = retMap.get("abI").toString(); + Long salt = 100L; String[] parameter = {Base58.encode58Check(user001Address), code, salt.toString()}; logger.info(PublicMethod.create2(parameter)); testContractAddress2 = PublicMethod.create2(parameter); - Long callValue = Long.valueOf(0); - String param = "\"" - + Base58.encode58Check(WalletClient.decodeFromBase58Check(testContractAddress2)) + "\""; - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByAddr(address)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + String param = + "\"" + + Base58.encode58Check(WalletClient.decodeFromBase58Check(testContractAddress2)) + + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByAddr(address)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -498,15 +602,15 @@ public void test06GetCreate2CodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -517,14 +621,13 @@ public void test06GetCreate2CodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); - logger.info( - "the value: " + retList); + logger.info("the value: " + retList); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", - retList.get(0)); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000000", retList.get(0)); /*PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); @@ -536,41 +639,68 @@ public void test06GetCreate2CodeHash() { user001Address, blockingStubFull);*/ } - @Test(enabled = true, description = "Get the EXTCODEHASH of an account created " - + "in the current transaction", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Get the EXTCODEHASH of an account created " + "in the current transaction", + groups = {"contract", "daily"}) public void test07DeployExtCodeHashContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/extCodeHashConstruct.sol"; - String contractName = "CounterConstruct"; + String filePath = "./src/test/resources/soliditycode/extCodeHashConstruct.sol"; + String contractName = "CounterConstruct"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -582,8 +712,8 @@ public void test07DeployExtCodeHashContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -594,8 +724,8 @@ public void test07DeployExtCodeHashContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(extCodeHashContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(extCodeHashContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); if (infoById.get().getResultValue() != 0) { @@ -603,22 +733,19 @@ public void test07DeployExtCodeHashContract() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getTopics(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getTopics(0).toByteArray()); logger.info("the value: " + retList); Assert.assertFalse(retList.isEmpty()); - Assert.assertNotEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", - retList.get(0)); - Assert.assertNotEquals("0000000000000000000000000000000000000000000000000000000000000000", - retList.get(0)); - + Assert.assertNotEquals( + "C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", retList.get(0)); + Assert.assertNotEquals( + "0000000000000000000000000000000000000000000000000000000000000000", retList.get(0)); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); @@ -626,7 +753,6 @@ public void shutdown() throws InterruptedException { PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest002.java index 57511adb..5189f7c2 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest002.java @@ -15,19 +15,20 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ExtCodeHashTest002 extends TronBaseTest { private final boolean AllTest = false; private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] extCodeHashContractAddress = null; private byte[] testContractAddress = null; private String expectedCodeHash = null; @@ -38,48 +39,75 @@ public class ExtCodeHashTest002 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = AllTest, description = "Deploy extcodehash contract", groups = {"contract", "daily"}) + @Test( + enabled = AllTest, + description = "Deploy extcodehash contract", + groups = {"contract", "daily"}) public void test01DeployExtCodeHashContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; - String contractName = "TestExtCodeHash"; + String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; + String contractName = "TestExtCodeHash"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -91,8 +119,8 @@ public void test01DeployExtCodeHashContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -103,20 +131,29 @@ public void test01DeployExtCodeHashContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(extCodeHashContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(extCodeHashContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = AllTest, description = "Get a contract extcodehash", groups = {"contract", "daily"}) + @Test( + enabled = AllTest, + description = "Get a contract extcodehash", + groups = {"contract", "daily"}) public void test02GetContactCodeHash() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -128,18 +165,27 @@ public void test02GetContactCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String param = "\"" + Base58.encode58Check(extCodeHashContractAddress) + "\""; - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByAddr(address)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + String param = "\"" + Base58.encode58Check(extCodeHashContractAddress) + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByAddr(address)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -155,15 +201,15 @@ public void test02GetContactCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -174,37 +220,29 @@ public void test02GetContactCodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); logger.info("the value: " + retList); Assert.assertFalse(retList.isEmpty()); - Assert.assertNotEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", - retList.get(0)); - Assert.assertNotEquals("0000000000000000000000000000000000000000000000000000000000000000", - retList.get(0)); - - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); + Assert.assertNotEquals( + "C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", retList.get(0)); + Assert.assertNotEquals( + "0000000000000000000000000000000000000000000000000000000000000000", retList.get(0)); + + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest003.java index c26f7b34..e7ce72de 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest003.java @@ -15,19 +15,20 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ExtCodeHashTest003 extends TronBaseTest { private final boolean AllTest = false; private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] extCodeHashContractAddress = null; private byte[] testContractAddress = null; private String expectedCodeHash = null; @@ -41,48 +42,75 @@ public class ExtCodeHashTest003 extends TronBaseTest { private byte[] testAddress = ecKey3.getAddress(); private String testKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = AllTest, description = "Deploy extcodehash contract", groups = {"contract", "daily"}) + @Test( + enabled = AllTest, + description = "Deploy extcodehash contract", + groups = {"contract", "daily"}) public void test01DeployExtCodeHashContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; - String contractName = "TestExtCodeHash"; + String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; + String contractName = "TestExtCodeHash"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -94,8 +122,8 @@ public void test01DeployExtCodeHashContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -106,20 +134,29 @@ public void test01DeployExtCodeHashContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(extCodeHashContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(extCodeHashContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = AllTest, description = "Get a not exist account extcodehash", groups = {"contract", "daily"}) + @Test( + enabled = AllTest, + description = "Get a not exist account extcodehash", + groups = {"contract", "daily"}) public void test02GetNotExistAddressCodeHash() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -131,18 +168,27 @@ public void test02GetNotExistAddressCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String param = "\"" + Base58.encode58Check(testAddress) + "\""; - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByAddr(address)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + String param = "\"" + Base58.encode58Check(testAddress) + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByAddr(address)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -158,15 +204,15 @@ public void test02GetNotExistAddressCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -177,33 +223,41 @@ public void test02GetNotExistAddressCodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); - logger.info( - "the value: " + retList); + logger.info("the value: " + retList); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", - retList.get(0)); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000000", retList.get(0)); - SmartContract smartContract = PublicMethod - .getContract(extCodeHashContractAddress, blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(extCodeHashContractAddress, blockingStubFull); logger.info(smartContract.getBytecode().toStringUtf8()); } - @Test(enabled = AllTest, description = "Active the account and get extcodehash again", groups = {"contract", "daily"}) + @Test( + enabled = AllTest, + description = "Active the account and get extcodehash again", + groups = {"contract", "daily"}) public void test03ActiveAccountGetCodeHash() { - Assert.assertTrue(PublicMethod.sendcoin(testAddress, 1000000, fromAddress, - testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.sendcoin(testAddress, 1000000, fromAddress, testKey002, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -215,18 +269,27 @@ public void test03ActiveAccountGetCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String param = "\"" + Base58.encode58Check(testAddress) + "\""; - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByAddr(address)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + String param = "\"" + Base58.encode58Check(testAddress) + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByAddr(address)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -242,15 +305,15 @@ public void test03ActiveAccountGetCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -261,37 +324,30 @@ public void test03ActiveAccountGetCodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); logger.info("the value: " + retList); - Assert.assertEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", - retList.get(0)); + Assert.assertEquals( + "C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", retList.get(0)); - SmartContract smartContract = PublicMethod - .getContract(extCodeHashContractAddress, blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(extCodeHashContractAddress, blockingStubFull); logger.info(smartContract.getBytecode().toStringUtf8()); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest004.java index a130fa9d..92a7bc90 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest004.java @@ -1,6 +1,5 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.extCodeHash; - import com.google.protobuf.ByteString; import java.util.HashMap; import java.util.List; @@ -20,18 +19,19 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.Hash; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ExtCodeHashTest004 extends TronBaseTest { private final boolean AllTest = false; private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] extCodeHashContractAddress = null; private String testContractAddress = null; private String expectedCodeHash = null; @@ -42,56 +42,83 @@ public class ExtCodeHashTest004 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = AllTest, description = "Deploy extcodehash contract", groups = {"contract", "daily"}) + @Test( + enabled = AllTest, + description = "Deploy extcodehash contract", + groups = {"contract", "daily"}) public void test01DeployExtCodeHashContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; - String contractName = "TestExtCodeHash"; + String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; + String contractName = "TestExtCodeHash"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - final String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + final String abi = retMap.get("abI").toString(); expectedCodeHash = ByteArray.toHexString(Hash.sha3(Hex.decode(code))); logger.info("expectedCodeHash: " + expectedCodeHash); - Long salt = 100L; + Long salt = 100L; String[] parameter = {Base58.encode58Check(user001Address), code, salt.toString()}; logger.info(PublicMethod.create2(parameter)); testContractAddress = PublicMethod.create2(parameter); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -103,8 +130,8 @@ public void test01DeployExtCodeHashContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -115,20 +142,29 @@ public void test01DeployExtCodeHashContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(extCodeHashContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(extCodeHashContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = AllTest, description = "Get a not deployed create2 extcodehash", groups = {"contract", "daily"}) + @Test( + enabled = AllTest, + description = "Get a not deployed create2 extcodehash", + groups = {"contract", "daily"}) public void test02GetCreate2CodeHash() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -140,19 +176,28 @@ public void test02GetCreate2CodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String param = + Long callValue = Long.valueOf(0); + String param = "\"" + Base58.encode58Check(WalletClient.decodeFromBase58Check(testContractAddress)) + "\""; - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByAddr(address)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByAddr(address)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -168,15 +213,15 @@ public void test02GetCreate2CodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -187,34 +232,26 @@ public void test02GetCreate2CodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); - logger.info( - "the value: " + retList); + logger.info("the value: " + retList); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", - retList.get(0)); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000000", retList.get(0)); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest005.java index 4e0ad023..f097b013 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest005.java @@ -18,17 +18,18 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.DataWord; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ExtCodeHashTest005 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] extCodeHashContractAddress = null; private byte[] testContractAddress = null; private String contractCodeHash = null; @@ -42,16 +43,15 @@ public class ExtCodeHashTest005 extends TronBaseTest { private byte[] testAddress = ecKey3.getAddress(); private String testKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); - String fakeAddress = ""; + String fakeAddress = ""; logger.info("realAddress: " + fakeAddress); - byte[] fullHexAddr = new DataWord(fakeAddress).getData(); + byte[] fullHexAddr = new DataWord(fakeAddress).getData(); logger.info("fullHexAddr ++= " + Hex.toHexString(fullHexAddr)); fakeAddress = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; @@ -59,41 +59,67 @@ public class ExtCodeHashTest005 extends TronBaseTest { logger.info("realAddress: " + fakeAddress); fullHexAddr = new DataWord(fakeAddress).getData(); logger.info("fullHexAddr ++= " + Hex.toHexString(fullHexAddr)); - } - @Test(enabled = true, description = "Deploy extcodehash contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy extcodehash contract", + groups = {"contract", "daily"}) public void test01DeployExtCodeHashContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 1000_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1000_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; - String contractName = "TestExtCodeHash"; + String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; + String contractName = "TestExtCodeHash"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -105,8 +131,8 @@ public void test01DeployExtCodeHashContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -117,24 +143,34 @@ public void test01DeployExtCodeHashContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(extCodeHashContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(extCodeHashContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "Get codehash of a real contract by uint", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Get codehash of a real contract by uint", + groups = {"contract", "daily"}) public void test02GetContractCodeHash() { - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -146,20 +182,29 @@ public void test02GetContractCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String testAddress = ByteArray.toHexString(extCodeHashContractAddress); + Long callValue = Long.valueOf(0); + String testAddress = ByteArray.toHexString(extCodeHashContractAddress); logger.info("realAddress: " + testAddress); - byte[] fullHexAddr = new DataWord(testAddress).getData(); - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByUint(uint256)", Hex.toHexString(fullHexAddr), true, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + byte[] fullHexAddr = new DataWord(testAddress).getData(); + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByUint(uint256)", + Hex.toHexString(fullHexAddr), + true, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -175,15 +220,15 @@ public void test02GetContractCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -194,33 +239,40 @@ public void test02GetContractCodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); logger.info("the value: " + retList); Assert.assertFalse(retList.isEmpty()); - Assert.assertNotEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", - retList.get(0)); - Assert.assertNotEquals("0000000000000000000000000000000000000000000000000000000000000000", - retList.get(0)); + Assert.assertNotEquals( + "C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", retList.get(0)); + Assert.assertNotEquals( + "0000000000000000000000000000000000000000000000000000000000000000", retList.get(0)); contractCodeHash = retList.get(0); - SmartContract smartContract = PublicMethod - .getContract(extCodeHashContractAddress, blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(extCodeHashContractAddress, blockingStubFull); logger.info(smartContract.getBytecode().toStringUtf8()); } - @Test(enabled = true, description = "Get codehash of a fake address by uint", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Get codehash of a fake address by uint", + groups = {"contract", "daily"}) public void test03GetInvalidAddressCodeHash() { - PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, blockingStubFull); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -232,20 +284,29 @@ public void test03GetInvalidAddressCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String fakeAddress = "41660757B2543F4849D3F42B90F58DE1C14C7E0038"; + Long callValue = Long.valueOf(0); + String fakeAddress = "41660757B2543F4849D3F42B90F58DE1C14C7E0038"; logger.info("realAddress: " + fakeAddress); - byte[] fullHexAddr = new DataWord(fakeAddress).getData(); - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByUint(uint256)", Hex.toHexString(fullHexAddr), true, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + byte[] fullHexAddr = new DataWord(fakeAddress).getData(); + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByUint(uint256)", + Hex.toHexString(fullHexAddr), + true, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -261,15 +322,15 @@ public void test03GetInvalidAddressCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -280,30 +341,39 @@ public void test03GetInvalidAddressCodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); logger.info("the value: " + retList); Assert.assertFalse(retList.isEmpty()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", - retList.get(0)); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000000", retList.get(0)); - SmartContract smartContract = PublicMethod - .getContract(extCodeHashContractAddress, blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(extCodeHashContractAddress, blockingStubFull); logger.info(smartContract.getBytecode().toStringUtf8()); } - @Test(enabled = true, description = "Get codehash of a normal account by uint", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Get codehash of a normal account by uint", + groups = {"contract", "daily"}) public void test04GetNormalAddressCodeHash() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -315,20 +385,29 @@ public void test04GetNormalAddressCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String fakeAddress = ByteArray.toHexString(user001Address); + Long callValue = Long.valueOf(0); + String fakeAddress = ByteArray.toHexString(user001Address); logger.info("realAddress: " + fakeAddress); - byte[] fullHexAddr = new DataWord(fakeAddress).getData(); - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByUint(uint256)", Hex.toHexString(fullHexAddr), true, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + byte[] fullHexAddr = new DataWord(fakeAddress).getData(); + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByUint(uint256)", + Hex.toHexString(fullHexAddr), + true, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -344,15 +423,15 @@ public void test04GetNormalAddressCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -363,32 +442,40 @@ public void test04GetNormalAddressCodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); logger.info("the value: " + retList); Assert.assertFalse(retList.isEmpty()); - Assert.assertEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", - retList.get(0)); + Assert.assertEquals( + "C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", retList.get(0)); - SmartContract smartContract = PublicMethod - .getContract(extCodeHashContractAddress, blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(extCodeHashContractAddress, blockingStubFull); logger.info(smartContract.getBytecode().toStringUtf8()); } - @Test(enabled = true, description = "Get codehash of a empty address by uint", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Get codehash of a empty address by uint", + groups = {"contract", "daily"}) public void test05GetEmptyAddressCodeHash() { - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 1000_000_000L, fromAddress, - testKey002, blockingStubFull)); - - PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 1000_000_000L, fromAddress, testKey002, blockingStubFull)); + + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, blockingStubFull); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -400,22 +487,31 @@ public void test05GetEmptyAddressCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String fakeAddress = ""; + Long callValue = Long.valueOf(0); + String fakeAddress = ""; logger.info("realAddress: " + fakeAddress); - byte[] fullHexAddr = new DataWord(fakeAddress).getData(); + byte[] fullHexAddr = new DataWord(fakeAddress).getData(); logger.info("fullHexAddr ++= " + Hex.toHexString(fullHexAddr)); - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByUint(uint256)", Hex.toHexString(fullHexAddr), true, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByUint(uint256)", + Hex.toHexString(fullHexAddr), + true, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -431,15 +527,15 @@ public void test05GetEmptyAddressCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -450,32 +546,42 @@ public void test05GetEmptyAddressCodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); logger.info("the value: " + retList); Assert.assertFalse(retList.isEmpty()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", - retList.get(0)); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000000", retList.get(0)); - SmartContract smartContract = PublicMethod - .getContract(extCodeHashContractAddress, blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(extCodeHashContractAddress, blockingStubFull); logger.info(smartContract.getBytecode().toStringUtf8()); } - @Test(enabled = true, description = "Get codehash of a fffffff*64 address by uint", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Get codehash of a fffffff*64 address by uint", + groups = {"contract", "daily"}) public void test06GetFakeAddressCodeHash() { - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -487,22 +593,31 @@ public void test06GetFakeAddressCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String fakeAddress = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; + Long callValue = Long.valueOf(0); + String fakeAddress = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; logger.info("realAddress: " + fakeAddress); - byte[] fullHexAddr = new DataWord(fakeAddress).getData(); + byte[] fullHexAddr = new DataWord(fakeAddress).getData(); logger.info("fullHexAddr ++= " + Hex.toHexString(fullHexAddr)); - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByUint(uint256)", Hex.toHexString(fullHexAddr), true, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByUint(uint256)", + Hex.toHexString(fullHexAddr), + true, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -518,15 +633,15 @@ public void test06GetFakeAddressCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -537,32 +652,42 @@ public void test06GetFakeAddressCodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); logger.info("the value: " + retList); Assert.assertFalse(retList.isEmpty()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", - retList.get(0)); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000000", retList.get(0)); - SmartContract smartContract = PublicMethod - .getContract(extCodeHashContractAddress, blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(extCodeHashContractAddress, blockingStubFull); logger.info(smartContract.getBytecode().toStringUtf8()); } - @Test(enabled = true, description = "Get codehash of a real contract plus 2**160 by uint", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Get codehash of a real contract plus 2**160 by uint", + groups = {"contract", "daily"}) public void test07GetContractAddress96CodeHash() { - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -574,21 +699,30 @@ public void test07GetContractAddress96CodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); + Long callValue = Long.valueOf(0); BigInteger bigIntAddr = new DataWord(extCodeHashContractAddress).sValue(); - String bigIntAddrChange = BigInteger.valueOf(2).pow(160).add(bigIntAddr).toString(16); - byte[] fullHexAddr = new DataWord(bigIntAddrChange).getData(); - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByUint(uint256)", Hex.toHexString(fullHexAddr), true, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String bigIntAddrChange = BigInteger.valueOf(2).pow(160).add(bigIntAddr).toString(16); + byte[] fullHexAddr = new DataWord(bigIntAddrChange).getData(); + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByUint(uint256)", + Hex.toHexString(fullHexAddr), + true, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -604,15 +738,15 @@ public void test07GetContractAddress96CodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -623,24 +757,20 @@ public void test07GetContractAddress96CodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); logger.info("the value: " + retList); Assert.assertFalse(retList.isEmpty()); - // expect the code hash same + // expect the code hash same Assert.assertEquals(contractCodeHash, retList.get(0)); - SmartContract smartContract = PublicMethod - .getContract(extCodeHashContractAddress, blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(extCodeHashContractAddress, blockingStubFull); logger.info(smartContract.getBytecode().toStringUtf8()); - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); @@ -648,7 +778,6 @@ public void shutdown() throws InterruptedException { PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest006.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest006.java index a3f18a24..6a2f6809 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest006.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest006.java @@ -14,19 +14,20 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ExtCodeHashTest006 extends TronBaseTest { private final boolean AllTest = false; private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] extCodeHashContractAddress = null; private byte[] testContractAddress = null; private String expectedCodeHash = null; @@ -40,49 +41,75 @@ public class ExtCodeHashTest006 extends TronBaseTest { private byte[] testAddress = ecKey3.getAddress(); private String testKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = AllTest, description = "Get the EXTCODEHASH of an account created " - + "in the current transaction", groups = {"contract", "daily"}) + @Test( + enabled = AllTest, + description = "Get the EXTCODEHASH of an account created " + "in the current transaction", + groups = {"contract", "daily"}) public void test01DeployExtCodeHashContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/extCodeHashConstruct.sol"; - String contractName = "CounterConstruct"; + String filePath = "./src/test/resources/soliditycode/extCodeHashConstruct.sol"; + String contractName = "CounterConstruct"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -94,8 +121,8 @@ public void test01DeployExtCodeHashContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -106,8 +133,8 @@ public void test01DeployExtCodeHashContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(extCodeHashContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(extCodeHashContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); if (infoById.get().getResultValue() != 0) { @@ -115,37 +142,29 @@ public void test01DeployExtCodeHashContract() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getTopics(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getTopics(0).toByteArray()); logger.info("the value: " + retList); Assert.assertFalse(retList.isEmpty()); - Assert.assertNotEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", - retList.get(0)); - Assert.assertNotEquals("0000000000000000000000000000000000000000000000000000000000000000", - retList.get(0)); - - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); + Assert.assertNotEquals( + "C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", retList.get(0)); + Assert.assertNotEquals( + "0000000000000000000000000000000000000000000000000000000000000000", retList.get(0)); + + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java index 845441f1..c0c01986 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java @@ -11,22 +11,22 @@ import org.testng.annotations.Test; import org.tron.api.GrpcAPI.AccountResourceMessage; import org.tron.protos.Protocol.TransactionInfo; -import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ExtCodeHashTest007 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] testAddressOld = null; private byte[] testAddressNew = null; private byte[] testAddress2 = null; @@ -40,55 +40,79 @@ public class ExtCodeHashTest007 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy testNoPayable contract using old solidity", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy testNoPayable contract using old solidity", + groups = {"contract", "daily"}) public void test01DeployTestContractOld() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 10000_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 10000_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceV2(dev001Address, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, dev001Key, blockingStubFull)); - + Assert.assertTrue( + PublicMethod.freezeBalanceV2( + dev001Address, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + dev001Key, + blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceV2(dev001Address, 10_000_000L, - 0, dev001Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2(dev001Address, 10_000_000L, 0, dev001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String contractName = "testExtHashContract"; - String code = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a576000" - + "80fd5b5060ef806100396000396000f30060806040526004361060485763ffffffff7c010000000000000000" - + "0000000000000000000000000000000000000000600035041663c518aa0f8114604d578063e5aa3d58146089" - + "575b600080fd5b348015605857600080fd5b50d38015606457600080fd5b50d28015607057600080fd5b5060" - + "7760b3565b60408051918252519081900360200190f35b348015609457600080fd5b50d3801560a057600080" - + "fd5b50d2801560ac57600080fd5b50607760bd565b6001600081905590565b600054815600a165627a7a7230" - + "5820766b4e2fca9081689cd89419411d2cbc5588a17a5c9fa900fd9cfe4b0d9652be0029"; - String abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"testNoPayable\"," - + "\"outputs\":[{\"name\":\"z\",\"type\":\"uint256\"}],\"payable\":false," - + "\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true," - + "\"inputs\":[],\"name\":\"i\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}]," - + "\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"}]"; - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String contractName = "testExtHashContract"; + String code = + "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a576000" + + "80fd5b5060ef806100396000396000f30060806040526004361060485763ffffffff7c01000000000000" + + "0000" + + "0000000000000000000000000000000000000000600035041663c518aa0f8114604d578063e5aa3d5814" + + "6089" + + "575b600080fd5b348015605857600080fd5b50d38015606457600080fd5b50d28015607057600080fd5b" + + "5060" + + "7760b3565b60408051918252519081900360200190f35b348015609457600080fd5b50d3801560a05760" + + "0080" + + "fd5b50d2801560ac57600080fd5b50607760bd565b6001600081905590565b600054815600a165627a7a" + + "7230" + + "5820766b4e2fca9081689cd89419411d2cbc5588a17a5c9fa900fd9cfe4b0d9652be0029"; + String abi = + "[{\"constant\":false,\"inputs\":[],\"name\":\"testNoPayable\"," + + "\"outputs\":[{\"name\":\"z\",\"type\":\"uint256\"}],\"payable\":false," + + "\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true," + + "\"inputs\":[],\"name\":\"i\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}]," + + "\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"}]"; + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -100,8 +124,8 @@ public void test01DeployTestContractOld() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -112,47 +136,70 @@ public void test01DeployTestContractOld() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); testAddressOld = infoById.get().getContractAddress().toByteArray(); -// SmartContract smartContract = PublicMethod.getContract(testAddressOld, -// blockingStubFull); + // SmartContract smartContract = PublicMethod.getContract(testAddressOld, + // blockingStubFull); } - @Test(enabled = true, description = "Deploy testNoPayable contract using new solidity", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy testNoPayable contract using new solidity", + groups = {"contract", "daily"}) public void test02DeployTestContractNew() { -// PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(dev001Address), testKey002, blockingStubFull); -// -// PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L, -// 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull); -// -// PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(dev001Address), testKey002, blockingStubFull); + // + // PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L, + // 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull); + // + // PublicMethod.waitProduceNextBlock(blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String contractName = "testConstantContract"; - String code = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a5760" - + "0080fd5b5060c5806100396000396000f3fe6080604052348015600f57600080fd5b50d38015601b576000" - + "80fd5b50d28015602757600080fd5b50600436106066577c01000000000000000000000000000000000000" - + "000000000000000000006000350463c518aa0f8114606b578063e5aa3d58146083575b600080fd5b607160" - + "89565b60408051918252519081900360200190f35b60716093565b6001600081905590565b6000548156fe" - + "a165627a7a723058205c5aadfbd06ea264db7b73e7b7f3c36ac64a9d520ba46b4bc7f1dc56252f17ac0029"; - String abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"testNoPayable\",\"outputs\":[{\"" - + "name\":\"z\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable" - + "\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"i\",\"outputs\":" - + "[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"" - + "type\":\"function\"}]"; - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String contractName = "testConstantContract"; + String code = + "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a5760" + + "0080fd5b5060c5806100396000396000f3fe6080604052348015600f57600080fd5b50d38015601b5760" + + "00" + + "80fd5b50d28015602757600080fd5b50600436106066577c010000000000000000000000000000000000" + + "00" + + "000000000000000000006000350463c518aa0f8114606b578063e5aa3d58146083575b600080fd5b6071" + + "60" + + "89565b60408051918252519081900360200190f35b60716093565b6001600081905590565b6000548156" + + "fe" + + "a165627a7a723058205c5aadfbd06ea264db7b73e7b7f3c36ac64a9d520ba46b4bc7f1dc56252f17ac00" + + "29"; + String abi = + "[{\"constant\":false,\"inputs\":[],\"name\":\"testNoPayable\"," + + "\"outputs\":[{\"name\":\"z\",\"type\":\"uint256\"}],\"payable\":false," + + "\"stateMutability\":\"nonpayable\",\"type\":\"function\"}," + + "{\"constant\":true,\"inputs\":[],\"name\":\"i\"," + + "\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}]," + + "\"payable\":false,\"stateMutability\":\"view\"," + + "\"type\":\"function\"}]"; + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -164,8 +211,8 @@ public void test02DeployTestContractNew() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -176,42 +223,56 @@ public void test02DeployTestContractNew() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); testAddressNew = infoById.get().getContractAddress().toByteArray(); -// SmartContract smartContract = PublicMethod.getContract(testAddressNew, -// blockingStubFull); + // SmartContract smartContract = PublicMethod.getContract(testAddressNew, + // blockingStubFull); } - @Test(enabled = true, description = "Deploy extcodehash contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy extcodehash contract", + groups = {"contract", "daily"}) public void test03DeployExtCodeHashContract() { -// PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 370000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(dev001Address), testKey002, blockingStubFull); -// -// PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L, -// 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull); -// -// PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 370000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(dev001Address), testKey002, blockingStubFull); + // + // PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L, + // 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull); + // + // PublicMethod.waitProduceNextBlock(blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; - String contractName = "TestExtCodeHash"; + String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; + String contractName = "TestExtCodeHash"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); energyLimit = accountResource.getEnergyLimit(); @@ -222,8 +283,8 @@ public void test03DeployExtCodeHashContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -234,22 +295,32 @@ public void test03DeployExtCodeHashContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); -// SmartContract smartContract = PublicMethod.getContract(extCodeHashContractAddress, -// blockingStubFull); + // SmartContract smartContract = PublicMethod.getContract(extCodeHashContractAddress, + // blockingStubFull); } - @Test(enabled = true, description = "Get contract code hash with old solidity", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Get contract code hash with old solidity", + groups = {"contract", "daily"}) public void test04GetTestOldCodeHash() { - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -261,18 +332,27 @@ public void test04GetTestOldCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String param = "\"" + Base58.encode58Check(testAddressOld) + "\""; - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByAddr(address)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + String param = "\"" + Base58.encode58Check(testAddressOld) + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByAddr(address)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -288,15 +368,15 @@ public void test04GetTestOldCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -307,11 +387,10 @@ public void test04GetTestOldCodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); - logger.info( - "the value: " + retList); + logger.info("the value: " + retList); expectedCodeHashOld = retList.get(0); Assert.assertEquals( @@ -319,18 +398,21 @@ public void test04GetTestOldCodeHash() { Assert.assertFalse(retList.isEmpty()); } - @Test(enabled = true, description = "Get contract code hash with new solidity", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Get contract code hash with new solidity", + groups = {"contract", "daily"}) public void test05GetTestNewCodeHash() { -// Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, -// testKey002, blockingStubFull)); -// -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, + // testKey002, blockingStubFull)); + // + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -342,18 +424,27 @@ public void test05GetTestNewCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String param = "\"" + Base58.encode58Check(testAddressNew) + "\""; - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByAddr(address)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + String param = "\"" + Base58.encode58Check(testAddressNew) + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByAddr(address)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -369,15 +460,15 @@ public void test05GetTestNewCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -388,8 +479,8 @@ public void test05GetTestNewCodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); logger.info("the value: " + retList); Assert.assertFalse(retList.isEmpty()); @@ -400,46 +491,69 @@ public void test05GetTestNewCodeHash() { "34DB53BD1F7214367E8D6B2A7A6FBBF0E3B7DDB4939ECADE4CDEF6749C27A2DA", expectedCodeHash); } - @Test(enabled = true, description = "Deploy contract using new solidity again", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy contract using new solidity again", + groups = {"contract", "daily"}) public void test06DeployTest2Contract() { -// Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, -// testKey002, blockingStubFull)); -// PublicMethod.waitProduceNextBlock(blockingStubFull); -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); -// -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L, -// 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); -// -// PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, + // testKey002, blockingStubFull)); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + // + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L, + // 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + // + // PublicMethod.waitProduceNextBlock(blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String contractName = "testConstantContract"; - String code = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a5760" - + "0080fd5b5060c5806100396000396000f3fe6080604052348015600f57600080fd5b50d38015601b576000" - + "80fd5b50d28015602757600080fd5b50600436106066577c01000000000000000000000000000000000000" - + "000000000000000000006000350463c518aa0f8114606b578063e5aa3d58146083575b600080fd5b607160" - + "89565b60408051918252519081900360200190f35b60716093565b6001600081905590565b6000548156fe" - + "a165627a7a723058205c5aadfbd06ea264db7b73e7b7f3c36ac64a9d520ba46b4bc7f1dc56252f17ac0029"; - String abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"testNoPayable\",\"outputs\":[{\"" - + "name\":\"z\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable" - + "\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"i\",\"outputs\":" - + "[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"" - + "type\":\"function\"}]"; - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String contractName = "testConstantContract"; + String code = + "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a5760" + + "0080fd5b5060c5806100396000396000f3fe6080604052348015600f57600080fd5b50d38015601b5760" + + "00" + + "80fd5b50d28015602757600080fd5b50600436106066577c010000000000000000000000000000000000" + + "00" + + "000000000000000000006000350463c518aa0f8114606b578063e5aa3d58146083575b600080fd5b6071" + + "60" + + "89565b60408051918252519081900360200190f35b60716093565b6001600081905590565b6000548156" + + "fe" + + "a165627a7a723058205c5aadfbd06ea264db7b73e7b7f3c36ac64a9d520ba46b4bc7f1dc56252f17ac00" + + "29"; + String abi = + "[{\"constant\":false,\"inputs\":[],\"name\":\"testNoPayable\"," + + "\"outputs\":[{\"name\":\"z\",\"type\":\"uint256\"}],\"payable\":false," + + "\"stateMutability\":\"nonpayable\",\"type\":\"function\"}," + + "{\"constant\":true,\"inputs\":[],\"name\":\"i\"," + + "\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}]," + + "\"payable\":false,\"stateMutability\":\"view\"," + + "\"type\":\"function\"}]"; + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -451,8 +565,8 @@ public void test06DeployTest2Contract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -463,22 +577,25 @@ public void test06DeployTest2Contract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); testAddress2 = infoById.get().getContractAddress().toByteArray(); -// SmartContract smartContract = PublicMethod.getContract(testAddress2, -// blockingStubFull); + // SmartContract smartContract = PublicMethod.getContract(testAddress2, + // blockingStubFull); } - @Test(enabled = true, description = "Get contract code hash with test2", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Get contract code hash with test2", + groups = {"contract", "daily"}) public void test07GetTest2CodeHash() { -// Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, -// testKey002, blockingStubFull)); -// -// Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, -// PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, -// blockingStubFull), 0, 1, -// ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, + // testKey002, blockingStubFull)); + // + // Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, + // PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -490,18 +607,27 @@ public void test07GetTest2CodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String param = "\"" + Base58.encode58Check(testAddress2) + "\""; - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByAddr(address)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + String param = "\"" + Base58.encode58Check(testAddress2) + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByAddr(address)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -517,15 +643,15 @@ public void test07GetTest2CodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -536,19 +662,16 @@ public void test07GetTest2CodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); logger.info("the value: " + retList); Assert.assertFalse(retList.isEmpty()); Assert.assertEquals(expectedCodeHash, retList.get(0)); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); @@ -556,7 +679,6 @@ public void shutdown() throws InterruptedException { PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest008.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest008.java index 7e5b75a3..bc7dc900 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest008.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest008.java @@ -16,18 +16,19 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ExtCodeHashTest008 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] extCodeHashContractAddress = null; private byte[] testContractAddress = null; @@ -39,46 +40,72 @@ public class ExtCodeHashTest008 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy extcodehash contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy extcodehash contract", + groups = {"contract", "daily"}) public void test01DeployExtCodeHashContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; - String contractName = "TestExtCodeHash"; + String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; + String contractName = "TestExtCodeHash"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -90,8 +117,8 @@ public void test01DeployExtCodeHashContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -102,22 +129,32 @@ public void test01DeployExtCodeHashContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(extCodeHashContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(extCodeHashContractAddress, blockingStubFull); } - @Test(enabled = true, description = "Get code hash of create2 empty contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Get code hash of create2 empty contract", + groups = {"contract", "daily"}) public void test02GetTestContractCodeHash() { - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -129,26 +166,35 @@ public void test02GetTestContractCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; String[] parameter = {Base58.encode58Check(user001Address), testContractCode, salt.toString()}; logger.info(PublicMethod.create2(parameter)); - Long callValue = Long.valueOf(0); - String param = "\"" + PublicMethod.create2(parameter) + "\""; - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByAddr(address)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + String param = "\"" + PublicMethod.create2(parameter) + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByAddr(address)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -164,15 +210,15 @@ public void test02GetTestContractCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -183,46 +229,70 @@ public void test02GetTestContractCodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); logger.info("the value: " + retList); Assert.assertFalse(retList.isEmpty()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", - retList.get(0)); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000000", retList.get(0)); } - @Test(enabled = true, description = "Deploy factory contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy factory contract", + groups = {"contract", "daily"}) public void test03DeployFactoryContract() { - PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull); + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull); - PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull); + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "Factory"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -234,8 +304,8 @@ public void test03DeployFactoryContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -246,23 +316,31 @@ public void test03DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "Trigger create2 function to deploy test contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger create2 function to deploy test contract", + groups = {"contract", "daily"}) public void test04TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 1000_000_000L, fromAddress, - testKey002, blockingStubFull)); - - PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 150000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 1000_000_000L, fromAddress, testKey002, blockingStubFull)); + + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 150000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, blockingStubFull); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -274,23 +352,32 @@ public void test04TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -305,34 +392,34 @@ public void test04TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); @@ -343,29 +430,41 @@ public void test04TriggerCreate2ToDeployTestContract() { } SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = true, description = "Get code hash of test contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Get code hash of test contract", + groups = {"contract", "daily"}) public void test05GetTestContractCodeHash() { - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -377,18 +476,27 @@ public void test05GetTestContractCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String param = "\"" + Base58.encode58Check(testContractAddress) + "\""; - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByAddr(address)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + String param = "\"" + Base58.encode58Check(testContractAddress) + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByAddr(address)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -404,15 +512,15 @@ public void test05GetTestContractCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -423,23 +531,19 @@ public void test05GetTestContractCodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); logger.info("the value: " + retList); Assert.assertFalse(retList.isEmpty()); - Assert.assertNotEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", - retList.get(0)); - Assert.assertNotEquals("0000000000000000000000000000000000000000000000000000000000000000", - retList.get(0)); - + Assert.assertNotEquals( + "C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", retList.get(0)); + Assert.assertNotEquals( + "0000000000000000000000000000000000000000000000000000000000000000", retList.get(0)); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); @@ -447,7 +551,6 @@ public void shutdown() throws InterruptedException { PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest009.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest009.java index 06554174..87110d27 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest009.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest009.java @@ -16,18 +16,19 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ExtCodeHashTest009 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] extCodeHashContractAddress = null; private byte[] testContractAddress = null; @@ -39,46 +40,72 @@ public class ExtCodeHashTest009 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy extcodehash contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy extcodehash contract", + groups = {"contract", "daily"}) public void test01DeployExtCodeHashContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 180000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 180000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; - String contractName = "TestExtCodeHash"; + String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; + String contractName = "TestExtCodeHash"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -90,8 +117,8 @@ public void test01DeployExtCodeHashContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -102,22 +129,30 @@ public void test01DeployExtCodeHashContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(extCodeHashContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(extCodeHashContractAddress, blockingStubFull); } - @Test(enabled = true, description = "Get code hash of create2 empty contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Get code hash of create2 empty contract", + groups = {"contract", "daily"}) public void test02GetTestContractCodeHash() { - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - - PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, blockingStubFull); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -129,26 +164,35 @@ public void test02GetTestContractCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; String[] parameter = {Base58.encode58Check(user001Address), testContractCode, salt.toString()}; logger.info(PublicMethod.create2(parameter)); - Long callValue = Long.valueOf(0); - String param = "\"" + PublicMethod.create2(parameter) + "\""; - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByAddr(address)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + String param = "\"" + PublicMethod.create2(parameter) + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByAddr(address)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -164,15 +208,15 @@ public void test02GetTestContractCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -183,46 +227,72 @@ public void test02GetTestContractCodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); logger.info("the value: " + retList); Assert.assertFalse(retList.isEmpty()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", - retList.get(0)); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000000", retList.get(0)); } - @Test(enabled = true, description = "Deploy factory contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy factory contract", + groups = {"contract", "daily"}) public void test03DeployFactoryContract() { - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "Factory"; + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -234,8 +304,8 @@ public void test03DeployFactoryContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -246,23 +316,33 @@ public void test03DeployFactoryContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); factoryContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(factoryContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(factoryContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "Trigger create2 function to deploy test contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger create2 function to deploy test contract", + groups = {"contract", "daily"}) public void test04TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -274,23 +354,32 @@ public void test04TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; + Long callValue = Long.valueOf(0); + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethod.triggerContract(factoryContractAddress, - "deploy(bytes,uint256)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + final String triggerTxid = + PublicMethod.triggerContract( + factoryContractAddress, + "deploy(bytes,uint256)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -305,34 +394,34 @@ public void test04TriggerCreate2ToDeployTestContract() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; + byte[] tmpAddress = new byte[20]; System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); @@ -343,29 +432,41 @@ public void test04TriggerCreate2ToDeployTestContract() { } SmartContract smartContract = PublicMethod.getContract(testContractAddress, blockingStubFull); - // contract created by create2, doesn't have ABI + // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); - // the contract owner of contract created by create2 is the factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); - // the contract address in transaction info, + // the contract address in transaction info, // contract address of create2 contract is factory contract - Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Assert.assertEquals( + Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = true, description = "Get code hash of test contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Get code hash of test contract", + groups = {"contract", "daily"}) public void test05GetTestContractCodeHash() { - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -377,18 +478,27 @@ public void test05GetTestContractCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); - String param = "\"" + Base58.encode58Check(testContractAddress) + "\""; - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByAddr(address)", param, false, callValue, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + Long callValue = Long.valueOf(0); + String param = "\"" + Base58.encode58Check(testContractAddress) + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByAddr(address)", + param, + false, + callValue, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -404,15 +514,15 @@ public void test05GetTestContractCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -423,23 +533,19 @@ public void test05GetTestContractCodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); logger.info("the value: " + retList); Assert.assertFalse(retList.isEmpty()); - Assert.assertNotEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", - retList.get(0)); - Assert.assertNotEquals("0000000000000000000000000000000000000000000000000000000000000000", - retList.get(0)); - + Assert.assertNotEquals( + "C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", retList.get(0)); + Assert.assertNotEquals( + "0000000000000000000000000000000000000000000000000000000000000000", retList.get(0)); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); @@ -447,7 +553,6 @@ public void shutdown() throws InterruptedException { PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest010.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest010.java index 8b03aaa5..d18f0bf6 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest010.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest010.java @@ -14,19 +14,20 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ExtCodeHashTest010 extends TronBaseTest { final boolean AllTest = false; private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] factoryContractAddress = null; private byte[] extCodeHashContractAddress = null; private byte[] testContractAddress = null; @@ -38,39 +39,53 @@ public class ExtCodeHashTest010 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = AllTest, description = "Deploy extcodehash contract", groups = {"contract", "daily"}) + @Test( + enabled = AllTest, + description = "Deploy extcodehash contract", + groups = {"contract", "daily"}) public void test01DeployExtCodeHashContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/ExtCodeHashTest010.sol"; - String contractName = "Counter"; + String filePath = "./src/test/resources/soliditycode/ExtCodeHashTest010.sol"; + String contractName = "Counter"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -82,8 +97,8 @@ public void test01DeployExtCodeHashContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -94,19 +109,23 @@ public void test01DeployExtCodeHashContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(extCodeHashContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(extCodeHashContractAddress, blockingStubFull); } - - @Test(enabled = AllTest, description = "The EXTCODEHASH of an account that selfdestructed in the " - + "current transaction. but later been revert", groups = {"contract", "daily"}) + @Test( + enabled = AllTest, + description = + "The EXTCODEHASH of an account that selfdestructed in the " + + "current transaction. but later been revert", + groups = {"contract", "daily"}) public void test02GetTestContractCodeHash() { - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -118,16 +137,25 @@ public void test02GetTestContractCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashRevert()", "#", false, 0L, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashRevert()", + "#", + false, + 0L, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -143,15 +171,15 @@ public void test02GetTestContractCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -162,25 +190,29 @@ public void test02GetTestContractCodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); logger.info("the value: " + retList); Assert.assertFalse(retList.isEmpty()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", - retList.get(0)); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000000", retList.get(0)); } - - @Test(enabled = AllTest, description = "The EXTCODEHASH of an account that create in the current " - + "transaction. but later been revert", groups = {"contract", "daily"}) + @Test( + enabled = AllTest, + description = + "The EXTCODEHASH of an account that create in the current " + + "transaction. but later been revert", + groups = {"contract", "daily"}) public void test03GetTestContractCodeHash() { - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -192,16 +224,25 @@ public void test03GetTestContractCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashCreate()", "#", false, 0L, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashCreate()", + "#", + false, + 0L, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -217,15 +258,15 @@ public void test03GetTestContractCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -236,24 +277,28 @@ public void test03GetTestContractCodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); logger.info("the value: " + retList); Assert.assertFalse(retList.isEmpty()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", - retList.get(0)); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000000", retList.get(0)); } - @Test(enabled = AllTest, description = "The EXTCODEHASH of an account that selfdestructed in the" - + " current transaction.", groups = {"contract", "daily"}) + @Test( + enabled = AllTest, + description = + "The EXTCODEHASH of an account that selfdestructed in the" + " current transaction.", + groups = {"contract", "daily"}) public void test04GetTestContractCodeHash() { - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); long devBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -265,17 +310,26 @@ public void test04GetTestContractCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitBefore = accountResource.getEnergyLimit(); long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceBefore = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - String param = "\"" + Base58.encode58Check(extCodeHashContractAddress) + "\""; - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashSuicide(address)", param, false, 0L, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String param = "\"" + Base58.encode58Check(extCodeHashContractAddress) + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashSuicide(address)", + param, + false, + 0L, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -291,15 +345,15 @@ public void test04GetTestContractCodeHash() { accountResource = PublicMethod.getAccountResource(user001Address, blockingStubFull); long userEnergyLimitAfter = accountResource.getEnergyLimit(); long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethod.queryAccount(user001Address, blockingStubFull) - .getBalance(); + long userBalanceAfter = + PublicMethod.queryAccount(user001Address, blockingStubFull).getBalance(); logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); @@ -310,25 +364,22 @@ public void test04GetTestContractCodeHash() { "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); logger.info("the value: " + retList); Assert.assertFalse(retList.isEmpty()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", - retList.get(0)); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000000", retList.get(0)); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest011.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest011.java index b201f7e5..d8c17199 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest011.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest011.java @@ -19,17 +19,18 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.Hash; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ExtCodeHashTest011 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] extCodeHashContractAddress = null; private byte[] testContractAddress = null; private String expectedCodeHash = null; @@ -40,47 +41,62 @@ public class ExtCodeHashTest011 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy extcodehash contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy extcodehash contract", + groups = {"contract", "daily"}) public void test01DeployExtCodeHashContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/extCodeHash11.sol"; - String contractName = "Counter"; + String filePath = "./src/test/resources/soliditycode/extCodeHash11.sol"; + String contractName = "Counter"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); expectedCodeHash = ByteArray.toHexString(Hash.sha3(Hex.decode(code))); logger.info("expectedCodeHash: " + expectedCodeHash); - String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -91,55 +107,77 @@ public void test01DeployExtCodeHashContract() { logger.info("after energyLimit is " + Long.toString(energyLimit)); logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - transferTokenTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByAddr()", "#", false, 0, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + transferTokenTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByAddr()", + "#", + false, + 0, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); - Assert - .assertThat(ByteArray - .toStr(infoById.get().getResMessage().toByteArray()), - containsString("REVERT opcode executed")); + Assert.assertThat( + ByteArray.toStr(infoById.get().getResMessage().toByteArray()), + containsString("REVERT opcode executed")); } - - @Test(enabled = true, description = "Deploy extcodehash contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy extcodehash contract", + groups = {"contract", "daily"}) public void test01DeployExtCodeHashContract1() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/extCodeHash11.sol"; - String contractName = "Counter1"; + String filePath = "./src/test/resources/soliditycode/extCodeHash11.sol"; + String contractName = "Counter1"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); expectedCodeHash = ByteArray.toHexString(Hash.sha3(Hex.decode(code))); logger.info("expectedCodeHash: " + expectedCodeHash); - String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -150,67 +188,88 @@ public void test01DeployExtCodeHashContract1() { logger.info("after energyLimit is " + Long.toString(energyLimit)); logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - transferTokenTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByAddr()", "#", false, 0, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + transferTokenTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByAddr()", + "#", + false, + 0, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); - logger.info( - "the value: " + retList); + logger.info("the value: " + retList); - Assert.assertEquals(retList.get(1), - retList.get(0)); + Assert.assertEquals(retList.get(1), retList.get(0)); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(extCodeHashContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(extCodeHashContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - - @Test(enabled = true, description = "Deploy extcodehash contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy extcodehash contract", + groups = {"contract", "daily"}) public void test01DeployExtCodeHashContract2() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/extCodeHash11.sol"; - String contractName = "Counter2"; + String filePath = "./src/test/resources/soliditycode/extCodeHash11.sol"; + String contractName = "Counter2"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); expectedCodeHash = ByteArray.toHexString(Hash.sha3(Hex.decode(code))); logger.info("expectedCodeHash: " + expectedCodeHash); - String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -221,60 +280,81 @@ public void test01DeployExtCodeHashContract2() { logger.info("after energyLimit is " + Long.toString(energyLimit)); logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - String num = "\"" + Base58.encode58Check(dev001Address) + "\""; - - transferTokenTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByAddr(address)", num, false, 0, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String num = "\"" + Base58.encode58Check(dev001Address) + "\""; + + transferTokenTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByAddr(address)", + num, + false, + 0, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); - logger.info( - "the value: " + retList); - Assert.assertEquals(retList.get(1), - retList.get(0)); + logger.info("the value: " + retList); + Assert.assertEquals(retList.get(1), retList.get(0)); } - - @Test(enabled = true, description = "Deploy extcodehash contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy extcodehash contract", + groups = {"contract", "daily"}) public void test01DeployExtCodeHashContract3() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/extCodeHash11.sol"; - String contractName = "Counter2"; + String filePath = "./src/test/resources/soliditycode/extCodeHash11.sol"; + String contractName = "Counter2"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); expectedCodeHash = ByteArray.toHexString(Hash.sha3(Hex.decode(code))); logger.info("expectedCodeHash: " + expectedCodeHash); - String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); accountResource = PublicMethod.getAccountResource(dev001Address, blockingStubFull); @@ -285,38 +365,40 @@ public void test01DeployExtCodeHashContract3() { logger.info("after energyLimit is " + Long.toString(energyLimit)); logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - String num = "\"" + Base58.encode58Check(dev001Address) + "\""; - - transferTokenTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "getCodeHashByAddr(address)", num, false, 0, - 1000000000L, "0", 0, user001Address, user001Key, - blockingStubFull); + String num = "\"" + Base58.encode58Check(dev001Address) + "\""; + + transferTokenTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "getCodeHashByAddr(address)", + num, + false, + 0, + 1000000000L, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); - List retList = PublicMethod - .getStrings(transactionInfo.getContractResult(0).toByteArray()); + List retList = + PublicMethod.getStrings(transactionInfo.getContractResult(0).toByteArray()); - logger.info( - "the value: " + retList); - Assert.assertEquals(retList.get(1), - retList.get(0)); + logger.info("the value: " + retList); + Assert.assertEquals(retList.get(1), retList.get(0)); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(user001Address, user001Key, fromAddress, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); } + PublicMethod.unFreezeBalance(fromAddress, testKey002, 0, dev001Address, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/isContract/isContractCommand001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/isContract/isContractCommand001.java index 4be6371a..fd277156 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/isContract/isContractCommand001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/isContract/isContractCommand001.java @@ -18,17 +18,17 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class isContractCommand001 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; byte[] contractA = null; @@ -40,74 +40,104 @@ public class isContractCommand001 extends TronBaseTest { byte[] nonexistentAddress = ecKey2.getAddress(); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - PublicMethod - .sendcoin(contractExcAddress, 1000_000_000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull); + PublicMethod.sendcoin( + contractExcAddress, + 1000_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TvmIsContract001.sol"; - String contractName = "testIsContract"; + String filePath = "src/test/resources/soliditycode/TvmIsContract001.sol"; + String contractName = "testIsContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); contractName = "C"; retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - contractC = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractC = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - - @Test(enabled = true, description = "Correct contract address test", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Correct contract address test", + groups = {"contract", "daily"}) public void test01CorrectContractAddress() { PublicMethod.waitProduceNextBlock(blockingStubFull); Protocol.Account info; - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - String num = "\"" + Base58.encode58Check(contractAddress) + "\""; - txid = PublicMethod - .triggerContract(contractAddress, "testIsContractCommand(address)", num, false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "\"" + Base58.encode58Check(contractAddress) + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testIsContractCommand(address)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertEquals(1, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -115,12 +145,12 @@ public void test01CorrectContractAddress() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -130,43 +160,64 @@ public void test01CorrectContractAddress() { Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testIsContractView(address)", num, - false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testIsContractView(address)", + num, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + 1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); } - @Test(enabled = true, description = "Account address test", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Account address test", + groups = {"contract", "daily"}) public void test02AccountAddress() { PublicMethod.waitProduceNextBlock(blockingStubFull); Protocol.Account info; - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - String num = "\"" + Base58.encode58Check(contractExcAddress) + "\""; - txid = PublicMethod - .triggerContract(contractAddress, "testIsContractCommand(address)", num, false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "\"" + Base58.encode58Check(contractExcAddress) + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testIsContractCommand(address)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -175,12 +226,12 @@ public void test02AccountAddress() { logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -190,43 +241,64 @@ public void test02AccountAddress() { Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testIsContractView(address)", num, - false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testIsContractView(address)", + num, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(0, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + 0, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); } - @Test(enabled = true, description = "Nonexistent account address test", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Nonexistent account address test", + groups = {"contract", "daily"}) public void test03NonexistentAddress() { PublicMethod.waitProduceNextBlock(blockingStubFull); Protocol.Account info; - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - String num = "\"" + Base58.encode58Check(nonexistentAddress) + "\""; - txid = PublicMethod - .triggerContract(contractAddress, "testIsContractCommand(address)", num, false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "\"" + Base58.encode58Check(nonexistentAddress) + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testIsContractCommand(address)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -234,12 +306,12 @@ public void test03NonexistentAddress() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -249,43 +321,64 @@ public void test03NonexistentAddress() { Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testIsContractView(address)", num, - false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testIsContractView(address)", + num, + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(0, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + 0, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); } - @Test(enabled = true, description = "Constructor return test", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Constructor return test", + groups = {"contract", "daily"}) public void test04ConstructorReturn() { PublicMethod.waitProduceNextBlock(blockingStubFull); Protocol.Account info; - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - txid = PublicMethod - .triggerContract(contractAddress, "testConstructor()", "", false, 0, maxFeeLimit, - contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testConstructor()", + "", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertEquals(1, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -293,12 +386,12 @@ public void test04ConstructorReturn() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -308,133 +401,228 @@ public void test04ConstructorReturn() { Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testConstructorView()", "", false, 0, - 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testConstructorView()", + "", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + 1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); } - - @Test(enabled = true, description = "active contract address before deploy contract,then deploy will fail", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "active contract address before deploy contract,then deploy will fail", + groups = {"contract", "daily"}) public void test05ActiveContractBeforeDeploy() { String filePath = "src/test/resources/soliditycode/TvmIsContract001.sol"; - String contractName = "testIsContract"; + String contractName = "testIsContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - Protocol.Transaction transaction = PublicMethod - .deployContractWithoutBroadcast(contractName, abi, code, "", maxFeeLimit, 0L, - 100, 1000L, "0", 0L, - null, contractExcKey, contractExcAddress, blockingStubFull); - byte[] contractAdd = PublicMethod.generateContractAddress(transaction, contractExcAddress); - Assert.assertTrue(PublicMethod.sendcoin(contractAdd, 1L, testNetAccountAddress, - testNetAccountKey, blockingStubFull )); - //Code = CONTRACT_VALIDATE_ERROR - //Message = Contract validate error : Trying to create a contract with existing contract address + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + Protocol.Transaction transaction = + PublicMethod.deployContractWithoutBroadcast( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + 1000L, + "0", + 0L, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); + byte[] contractAdd = PublicMethod.generateContractAddress(transaction, contractExcAddress); + Assert.assertTrue( + PublicMethod.sendcoin( + contractAdd, 1L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); + // Code = CONTRACT_VALIDATE_ERROR + // Message = Contract validate error : Trying to create a contract with existing contract + // address GrpcAPI.Return response = PublicMethod.broadcastTransaction(transaction, blockingStubFull); Assert.assertEquals("CONTRACT_VALIDATE_ERROR", response.getCode().name()); Assert.assertFalse(response.getResult()); } - @Test(enabled = true, description = "deploy A in create2, A trigger B's iscontract in it's constructor", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "deploy A in create2, A trigger B's iscontract in it's constructor", + groups = {"contract", "daily"}) public void test06TriggerInCreate2Constructor() { String contractName = "A"; - String filePath = "src/test/resources/soliditycode/TvmIsContract001.sol"; + String filePath = "src/test/resources/soliditycode/TvmIsContract001.sol"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String hexB = ByteArray.toHexString(contractAddress); - String testContractCode = code; + String code = retMap.get("byteCode").toString(); + String hexB = ByteArray.toHexString(contractAddress); + String testContractCode = code; testContractCode += "000000000000000000000000" + hexB; - Long salt = 7L; - String param = "\"" + testContractCode + "\"," + salt; - String triggerTxid = PublicMethod.triggerContract(contractC, - "create2(bytes,uint256)", param, false, 0L, - 1000000000L, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + Long salt = 7L; + String param = "\"" + testContractCode + "\"," + salt; + String triggerTxid = + PublicMethod.triggerContract( + contractC, + "create2(bytes,uint256)", + param, + false, + 0L, + 1000000000L, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional info = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(info.get().getResultValue() == 0); - String hexA = "41" + ByteArray.toHexString(info.get().getContractResult(0).toByteArray()).substring(24); + String hexA = + "41" + ByteArray.toHexString(info.get().getContractResult(0).toByteArray()).substring(24); logger.info("hexA: " + hexA); contractA = ByteArray.fromHexString(hexA); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractA, "testConstructorView()", "", false, 0, - 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractA, + "testConstructorView()", + "", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("trigger A testConstructorView : " + transactionExtention.toString()); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + 1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); } - @Test(enabled = true, description = "deploy A in create, A trigger B's iscontract in it's constructor", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "deploy A in create, A trigger B's iscontract in it's constructor", + groups = {"contract", "daily"}) public void test07TriggerInCreateConstructor() { String contractName = "A"; - String filePath = "src/test/resources/soliditycode/TvmIsContract001.sol"; + String filePath = "src/test/resources/soliditycode/TvmIsContract001.sol"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String hexB = ByteArray.toHexString(contractAddress); - String testContractCode = code; + String code = retMap.get("byteCode").toString(); + String hexB = ByteArray.toHexString(contractAddress); + String testContractCode = code; testContractCode += "000000000000000000000000" + hexB; - String param = "\"" + testContractCode + "\""; - String triggerTxid = PublicMethod.triggerContract(contractC, - "create(bytes)", param, false, 0L, - 1000000000L, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String param = "\"" + testContractCode + "\""; + String triggerTxid = + PublicMethod.triggerContract( + contractC, + "create(bytes)", + param, + false, + 0L, + 1000000000L, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional info = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(info.get().getResultValue() == 0); - String hexA = "41" + ByteArray.toHexString(info.get().getContractResult(0).toByteArray()).substring(24); + String hexA = + "41" + ByteArray.toHexString(info.get().getContractResult(0).toByteArray()).substring(24); logger.info("hexA: " + hexA); contractA = ByteArray.fromHexString(hexA); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractA, "testConstructorView()", "", false, 0, - 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractA, + "testConstructorView()", + "", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("trigger A testConstructorView : " + transactionExtention.toString()); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + 1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); } - - @Test(enabled = true, description = "A call B's iscontract in it's constructor", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "A call B's iscontract in it's constructor", + groups = {"contract", "daily"}) public void test08ConstructorCall() { String filePath = "src/test/resources/soliditycode/TvmIsContract001.sol"; - String contractName = "A"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String param = "\"" + Base58.encode58Check(contractAddress) + "\""; - String txid = PublicMethod - .deployContractWithConstantParame(contractName, abi, code, "constructor(address)",param,null, - maxFeeLimit, 0L, 100, - null, contractExcKey, contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String param = "\"" + Base58.encode58Check(contractAddress) + "\""; + String txid = + PublicMethod.deployContractWithConstantParame( + contractName, + abi, + code, + "constructor(address)", + param, + null, + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Optional info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(info.get().getResultValue() == 0); - byte[] aContract = info.get().getContractAddress().toByteArray(); + byte[] aContract = info.get().getContractAddress().toByteArray(); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(aContract, "testConstructorView()", "", false, 0, - 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + aContract, + "testConstructorView()", + "", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("test08 A call B in constructor :" + transactionExtention.toString()); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + 1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(contractExcKey, blockingStubFull).getBalance(); - PublicMethod.sendcoin(testNetAccountAddress, balance, contractExcAddress, contractExcKey, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.sendcoin( + testNetAccountAddress, balance, contractExcAddress, contractExcKey, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/isContract/isContractCommand002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/isContract/isContractCommand002.java index 085cc7b0..3eb3adda 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/isContract/isContractCommand002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/isContract/isContractCommand002.java @@ -18,18 +18,17 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; -import stest.tron.wallet.common.client.utils.ProposalEnum; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class isContractCommand002 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; byte[] selfdestructContractAddress = null; @@ -40,135 +39,214 @@ public class isContractCommand002 extends TronBaseTest { String selfdestructContractKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(contractExcKey); - PublicMethod.printAddress(selfdestructContractKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(selfdestructContractKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } - - @Test(enabled = true, description = "Selfdestruct contract test isContract Command", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Selfdestruct contract test isContract Command", + groups = {"contract", "daily"}) public void test01SelfdestructContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TvmIsContract001.sol"; - String contractName = "testIsContract"; + String filePath = "src/test/resources/soliditycode/TvmIsContract001.sol"; + String contractName = "testIsContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = ""; - String num = "\"" + Base58.encode58Check(contractAddress) + "\""; - Assert.assertTrue(PublicMethod - .sendcoin(selfdestructContractExcAddress, 10000000000L, testNetAccountAddress, + String txid = ""; + String num = "\"" + Base58.encode58Check(contractAddress) + "\""; + Assert.assertTrue( + PublicMethod.sendcoin( + selfdestructContractExcAddress, + 10000000000L, + testNetAccountAddress, testNetAccountKey, blockingStubFull)); - selfdestructContractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, selfdestructContractKey, - selfdestructContractExcAddress, blockingStubFull); + selfdestructContractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + selfdestructContractKey, + selfdestructContractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - txid = PublicMethod.triggerContract(selfdestructContractAddress, - "testIsContractCommand(address)", num, false, - 0, maxFeeLimit, selfdestructContractExcAddress, selfdestructContractKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + selfdestructContractAddress, + "testIsContractCommand(address)", + num, + false, + 0, + maxFeeLimit, + selfdestructContractExcAddress, + selfdestructContractKey, + blockingStubFull); Optional infoById1 = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById1 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(1, ByteArray.toInt(infoById1.get().getContractResult(0).toByteArray())); logger.info(infoById1.toString()); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(selfdestructContractAddress, - "testIsContractView(address)", num, false, - 0, 0, "0", 0, selfdestructContractExcAddress, selfdestructContractKey, + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + selfdestructContractAddress, + "testIsContractView(address)", + num, + false, + 0, + 0, + "0", + 0, + selfdestructContractExcAddress, + selfdestructContractKey, blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - String txid1 = ""; - txid1 = PublicMethod.triggerContract(contractAddress, - "selfdestructContract(address)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Assert.assertEquals( + 1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + String txid1 = ""; + txid1 = + PublicMethod.triggerContract( + contractAddress, + "selfdestructContract(address)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); logger.info(infoById1.toString()); - txid1 = PublicMethod.triggerContract(selfdestructContractAddress, - "testIsContractCommand(address)", num, false, - 0, maxFeeLimit, selfdestructContractExcAddress, selfdestructContractKey, blockingStubFull); + txid1 = + PublicMethod.triggerContract( + selfdestructContractAddress, + "testIsContractCommand(address)", + num, + false, + 0, + maxFeeLimit, + selfdestructContractExcAddress, + selfdestructContractKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); logger.info(infoById1.toString()); - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { Assert.assertEquals(1, ByteArray.toInt(infoById1.get().getContractResult(0).toByteArray())); - }else { + } else { Assert.assertEquals(0, ByteArray.toInt(infoById1.get().getContractResult(0).toByteArray())); } - transactionExtention = PublicMethod - .triggerConstantContractForExtention(selfdestructContractAddress, - "testIsContractView(address)", num, false, - 0, 0, "0", 0, selfdestructContractExcAddress, selfdestructContractKey, + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + selfdestructContractAddress, + "testIsContractView(address)", + num, + false, + 0, + 0, + "0", + 0, + selfdestructContractExcAddress, + selfdestructContractKey, blockingStubFull); logger.info("transactionExtention:" + transactionExtention.toString()); - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert.assertEquals(1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - }else { + Assert.assertEquals( + 1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + } else { Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert.assertEquals(0, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + 0, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); } } - @Test(enabled = true, description = "No constructor test isContract Command", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "No constructor test isContract Command", + groups = {"contract", "daily"}) public void test02NoConstructorContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TvmIsContract002.sol"; - String contractName = "testIsContract"; + String filePath = "src/test/resources/soliditycode/TvmIsContract002.sol"; + String contractName = "testIsContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(info.get().toString()); Assert.assertEquals(0, info.get().getResultValue()); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(contractExcKey, blockingStubFull).getBalance(); - PublicMethod.sendcoin(testNetAccountAddress, balance, contractExcAddress, contractExcKey, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.sendcoin( + testNetAccountAddress, balance, contractExcAddress, contractExcKey, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/isContract/isContractCommand003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/isContract/isContractCommand003.java index 7e67ac14..a80260aa 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/isContract/isContractCommand003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/isContract/isContractCommand003.java @@ -18,17 +18,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class isContractCommand003 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -38,68 +38,87 @@ public class isContractCommand003 extends TronBaseTest { String selfdestructContractKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(contractExcKey); - PublicMethod.printAddress(selfdestructContractKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(selfdestructContractKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } - @Test(enabled = true, description = "Incorrect address hex test isContract Command", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Incorrect address hex test isContract Command", + groups = {"contract", "daily"}) public void test01IncorrectHashContract() { - PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull); + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TvmIsContract001.sol"; - String contractName = "testIsContract"; + String filePath = "src/test/resources/soliditycode/TvmIsContract001.sol"; + String contractName = "testIsContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Protocol.Account info; - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, - blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String input = "ac5a3e290000000000000000000000123456789123456789"; - String txid = ""; - txid = PublicMethod.triggerContract(contractAddress, - "testIsContractCommand(address)", input, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String input = "ac5a3e290000000000000000000000123456789123456789"; + String txid = ""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testIsContractCommand(address)", + input, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertTrue(infoById.get().getResultValue() == 1); - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8() - .contains("REVERT opcode executed")); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("REVERT opcode executed")); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -107,13 +126,12 @@ public void test01IncorrectHashContract() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -123,62 +141,94 @@ public void test01IncorrectHashContract() { Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "testIsContractView(address)", input, true, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("FAILED", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("REVERT opcode executed", - transactionExtention.getResult().getMessage().toStringUtf8()); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testIsContractView(address)", + input, + true, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "FAILED", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "REVERT opcode executed", transactionExtention.getResult().getMessage().toStringUtf8()); } - @Test(enabled = true, description = "Empty addresses hash test isContract Command", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Empty addresses hash test isContract Command", + groups = {"contract", "daily"}) public void test02EmptyAddressHashContract() { - PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull); + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TvmIsContract001.sol"; - String contractName = "testIsContract"; + String filePath = "src/test/resources/soliditycode/TvmIsContract001.sol"; + String contractName = "testIsContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Protocol.Account info; - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, - blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String input = "ac5a3e29"; - String txid = ""; - txid = PublicMethod.triggerContract(contractAddress, - "testIsContractCommand(address)", input, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String input = "ac5a3e29"; + String txid = ""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testIsContractCommand(address)", + input, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertTrue(infoById.get().getResultValue() == 1); - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8() - .contains("REVERT opcode executed")); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("REVERT opcode executed")); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -186,13 +236,12 @@ public void test02EmptyAddressHashContract() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -202,28 +251,33 @@ public void test02EmptyAddressHashContract() { Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "testIsContractView(address)", input, true, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("FAILED", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("REVERT opcode executed", - transactionExtention.getResult().getMessage().toStringUtf8()); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testIsContractView(address)", + input, + true, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "FAILED", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "REVERT opcode executed", transactionExtention.getResult().getMessage().toStringUtf8()); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(contractExcKey, blockingStubFull).getBalance(); - PublicMethod.sendcoin(testNetAccountAddress, balance, contractExcAddress, contractExcKey, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.sendcoin( + testNetAccountAddress, balance, contractExcAddress, contractExcKey, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/istanbul/AltbnTest001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/istanbul/AltbnTest001.java index 5541d0b5..6ccc4def 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/istanbul/AltbnTest001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/istanbul/AltbnTest001.java @@ -12,115 +12,158 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j public class AltbnTest001 extends TronBaseTest { - private String testFoundationKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); - private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); + private String testFoundationKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); + private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey1.getAddress(); String testKey001 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private byte[] contractAddress; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(testKey001); PublicMethod - .sendcoin(testAddress001, 1000_000_000L, testFoundationAddress, testFoundationKey, - blockingStubFull); + PublicMethod.printAddress(testKey001); + PublicMethod.sendcoin( + testAddress001, 1000_000_000L, testFoundationAddress, testFoundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/altbn.sol"; - String contractName = "AltBn128"; + String filePath = "src/test/resources/soliditycode/altbn.sol"; + String contractName = "AltBn128"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, testKey001, - testAddress001, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); } - @Test(enabled = true, description = "bn256add energyCost reduced from 500 to 150", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "bn256add energyCost reduced from 500 to 150", + groups = {"contract", "daily"}) public void bn256addTest001() { String methodStr = "callBn256Add(bytes32,bytes32,bytes32,bytes32)"; - String data = "" - + "\"0000000000000000000000000000000000000000000000000000000000000001\"," - + "\"0000000000000000000000000000000000000000000000000000000000000002\"," - + "\"0000000000000000000000000000000000000000000000000000000000000001\"," - + "\"0000000000000000000000000000000000000000000000000000000000000002\""; - - logger.info("data: " + data); - String txid = PublicMethod - .triggerContract(contractAddress, methodStr, data, false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + String data = + "" + + "\"0000000000000000000000000000000000000000000000000000000000000001\"," + + "\"0000000000000000000000000000000000000000000000000000000000000002\"," + + "\"0000000000000000000000000000000000000000000000000000000000000001\"," + + "\"0000000000000000000000000000000000000000000000000000000000000002\""; + + logger.info("data: " + data); + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + data, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo option = PublicMethod - .getTransactionInfoById(txid, blockingStubFull).get(); + TransactionInfo option = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); long energyCost = option.getReceipt().getEnergyUsageTotal(); logger.info("energyCost: " + energyCost); - Assert.assertEquals(0,option.getResultValue()); + Assert.assertEquals(0, option.getResultValue()); } - @Test(enabled = true, description = "bn256add energyCost reduced from 40000 to 6000", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "bn256add energyCost reduced from 40000 to 6000", + groups = {"contract", "daily"}) public void bn256ScalarMulTest001() { String methodStr = "callBn256ScalarMul(bytes32,bytes32,bytes32)"; - String data = "" - + "\"0000000000000000000000000000000000000000000000000000000000000001\"," - + "\"0000000000000000000000000000000000000000000000000000000000000002\"," - + "\"0000000000000000000000000000000000000000000000000000000000000001\""; - - logger.info("data: " + data); - String txid = PublicMethod - .triggerContract(contractAddress, methodStr, data, false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + String data = + "" + + "\"0000000000000000000000000000000000000000000000000000000000000001\"," + + "\"0000000000000000000000000000000000000000000000000000000000000002\"," + + "\"0000000000000000000000000000000000000000000000000000000000000001\""; + + logger.info("data: " + data); + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + data, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo option = PublicMethod - .getTransactionInfoById(txid, blockingStubFull).get(); + TransactionInfo option = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); long energyCost = option.getReceipt().getEnergyUsageTotal(); logger.info("energyCost: " + energyCost); - Assert.assertEquals(0,option.getResultValue()); + Assert.assertEquals(0, option.getResultValue()); Assert.assertTrue(energyCost < 40000L); Assert.assertTrue(energyCost > 6000L); } - @Test(enabled = true, description = "bn256add energyCost reduced from ( 80000 * pairNum + 100000)" - + "to ( 34000 * pairNum + 45000) ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "bn256add energyCost reduced from ( 80000 * pairNum + 100000)" + + "to ( 34000 * pairNum + 45000) ", + groups = {"contract", "daily"}) public void bn256paringTest001() { String methodStr = "callBn256Pairing(bytes)"; - String data = "" - + "0000000000000000000000000000000000000000000000000000000000000020" - + "0000000000000000000000000000000000000000000000000000000000000180" - + "1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f59" - + "3034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41" - + "209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf7" - + "04bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a41678" - + "2bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d" - + "120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550" - + "111e129f1cf1097710d41c4ac70fcdfa5ba2023c6ff1cbeac322de49d1b6df7c" - + "2032c61a830e3c17286de9462bf242fca2883585b93870a73853face6a6bf411" - + "198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c2" - + "1800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed" - + "090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b" - + "12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa"; - - logger.info("data: " + data); - String txid = PublicMethod - .triggerContract(contractAddress, methodStr, data, true, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + String data = + "" + + "0000000000000000000000000000000000000000000000000000000000000020" + + "0000000000000000000000000000000000000000000000000000000000000180" + + "1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f59" + + "3034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41" + + "209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf7" + + "04bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a41678" + + "2bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d" + + "120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550" + + "111e129f1cf1097710d41c4ac70fcdfa5ba2023c6ff1cbeac322de49d1b6df7c" + + "2032c61a830e3c17286de9462bf242fca2883585b93870a73853face6a6bf411" + + "198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c2" + + "1800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed" + + "090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b" + + "12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa"; + + logger.info("data: " + data); + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + data, + true, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo option = PublicMethod - .getTransactionInfoById(txid, blockingStubFull).get(); + TransactionInfo option = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); long energyCost = option.getReceipt().getEnergyUsageTotal(); logger.info("energyCost: " + energyCost); @@ -129,9 +172,8 @@ public void bn256paringTest001() { return; } - Assert.assertEquals(0,option.getResultValue()); + Assert.assertEquals(0, option.getResultValue()); Assert.assertTrue(energyCost < 80000L * 2 + 100000L); Assert.assertTrue(energyCost > 34000L * 2 + 45000L); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/istanbul/ChainidAndSelfBalance001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/istanbul/ChainidAndSelfBalance001.java index df36adc9..da053572 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/istanbul/ChainidAndSelfBalance001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/istanbul/ChainidAndSelfBalance001.java @@ -11,12 +11,14 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + public class ChainidAndSelfBalance001 extends TronBaseTest { - private String testFoundationKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); - private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); + private String testFoundationKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); + private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey1.getAddress(); String testKey001 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); ECKey ecKey2 = new ECKey(Utils.getRandom()); @@ -24,40 +26,59 @@ public class ChainidAndSelfBalance001 extends TronBaseTest { String testKey002 = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); private byte[] contractAddress; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(testKey001); PublicMethod - .sendcoin(testAddress001, 1000_000_000L, testFoundationAddress, testFoundationKey, - blockingStubFull); - PublicMethod - .sendcoin(testAddress002, 1_000_000L, testFoundationAddress, testFoundationKey, - blockingStubFull); + PublicMethod.printAddress(testKey001); + PublicMethod.sendcoin( + testAddress001, 1000_000_000L, testFoundationAddress, testFoundationKey, blockingStubFull); + PublicMethod.sendcoin( + testAddress002, 1_000_000L, testFoundationAddress, testFoundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/chainid001.sol"; - String contractName = "IstanbulTest"; + String filePath = "src/test/resources/soliditycode/chainid001.sol"; + String contractName = "IstanbulTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 123456789L, 100, null, testKey001, - testAddress001, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 123456789L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); } - @Test(enabled = true, description = "chainId should be block zero`s Hash", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "chainId should be block zero`s Hash", + groups = {"contract", "daily"}) public void chainidTest001() { String methodStr = "getId()"; - TransactionExtention returns = PublicMethod - .triggerConstantContractForExtention(contractAddress, methodStr, "#", - false, 0, maxFeeLimit, "0", 0, testAddress001, testKey001, blockingStubFull); - String chainIdHex = ByteArray.toHexString(returns.getConstantResult(0).toByteArray()); + TransactionExtention returns = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methodStr, + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress001, + testKey001, + blockingStubFull); + String chainIdHex = ByteArray.toHexString(returns.getConstantResult(0).toByteArray()); BlockExtention blockZero = PublicMethod.getBlock2(0, blockingStubFull); - String tem = ByteArray.toHexString(blockZero.getBlockid().toByteArray()).substring(56); - String blockZeroId = "00000000000000000000000000000000000000000000000000000000" + tem; + String tem = ByteArray.toHexString(blockZero.getBlockid().toByteArray()).substring(56); + String blockZeroId = "00000000000000000000000000000000000000000000000000000000" + tem; Assert.assertEquals(chainIdHex, blockZeroId); } @@ -67,67 +88,111 @@ public void chainidTest001() { * optimize address.balance when contract`s balance */ - @Test(enabled = true, description = "selfBalance of addres(this).balance", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "selfBalance of addres(this).balance", + groups = {"contract", "daily"}) public void getBalanceTest001() { String methodStr = "getBalance()"; - String argsStr = ""; - TransactionExtention returns = PublicMethod - .triggerConstantContractForExtention(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, "", 0, testAddress001, testKey001, blockingStubFull); - Long getBalance = ByteArray.toLong(returns.getConstantResult(0).toByteArray()); - Long contractBalance = PublicMethod - .queryAccount(contractAddress, blockingStubFull).getBalance(); + String argsStr = ""; + TransactionExtention returns = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + "", + 0, + testAddress001, + testKey001, + blockingStubFull); + Long getBalance = ByteArray.toLong(returns.getConstantResult(0).toByteArray()); + Long contractBalance = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(contractBalance, getBalance); - } - - @Test(enabled = true, description = "selfBalance of contractAddress", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "selfBalance of contractAddress", + groups = {"contract", "daily"}) public void getBalanceTest002() { String methodStr = "getBalance(address)"; - String argsStr = "\"" + Base58.encode58Check(contractAddress) + "\""; - TransactionExtention returns = PublicMethod - .triggerConstantContractForExtention(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, "", 0, testAddress001, testKey001, blockingStubFull); - Long getBalance = ByteArray.toLong(returns.getConstantResult(0).toByteArray()); - Long contractBalance = PublicMethod - .queryAccount(contractAddress, blockingStubFull).getBalance(); + String argsStr = "\"" + Base58.encode58Check(contractAddress) + "\""; + TransactionExtention returns = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + "", + 0, + testAddress001, + testKey001, + blockingStubFull); + Long getBalance = ByteArray.toLong(returns.getConstantResult(0).toByteArray()); + Long contractBalance = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(contractBalance, getBalance); - } - @Test(enabled = true, description = "selfBalance of normal Address", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "selfBalance of normal Address", + groups = {"contract", "daily"}) public void getBalanceTest003() { String methodStr = "getBalance(address)"; - String argsStr = "\"" + Base58.encode58Check(testAddress002) + "\""; - TransactionExtention returns = PublicMethod - .triggerConstantContractForExtention(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, "", 0, testAddress001, testKey001, blockingStubFull); - Long getBalance = ByteArray.toLong(returns.getConstantResult(0).toByteArray()); - Long accountBalance = PublicMethod - .queryAccount(testAddress002, blockingStubFull).getBalance(); + String argsStr = "\"" + Base58.encode58Check(testAddress002) + "\""; + TransactionExtention returns = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + "", + 0, + testAddress001, + testKey001, + blockingStubFull); + Long getBalance = ByteArray.toLong(returns.getConstantResult(0).toByteArray()); + Long accountBalance = PublicMethod.queryAccount(testAddress002, blockingStubFull).getBalance(); Assert.assertEquals(accountBalance, getBalance); - } - @Test(enabled = true, description = "selfBalance of unActive Address", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "selfBalance of unActive Address", + groups = {"contract", "daily"}) public void getBalanceTest004() { String methodStr = "getBalance(address)"; - byte[] unActiveAddress = new ECKey(Utils.getRandom()).getAddress(); - String argsStr = "\"" + Base58.encode58Check(unActiveAddress) + "\""; - TransactionExtention returns = PublicMethod - .triggerConstantContractForExtention(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, "", 0, testAddress001, testKey001, blockingStubFull); - Long getBalance = ByteArray.toLong(returns.getConstantResult(0).toByteArray()); + byte[] unActiveAddress = new ECKey(Utils.getRandom()).getAddress(); + String argsStr = "\"" + Base58.encode58Check(unActiveAddress) + "\""; + TransactionExtention returns = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + "", + 0, + testAddress001, + testKey001, + blockingStubFull); + Long getBalance = ByteArray.toLong(returns.getConstantResult(0).toByteArray()); Assert.assertEquals(0, getBalance.longValue()); - } - - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/istanbul/Create2IstanbulTest001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/istanbul/Create2IstanbulTest001.java index 0766ae61..a3aab121 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/istanbul/Create2IstanbulTest001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/istanbul/Create2IstanbulTest001.java @@ -10,70 +10,95 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + public class Create2IstanbulTest001 extends TronBaseTest { - private String testFoundationKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); - private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); + private String testFoundationKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); + private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey1.getAddress(); String testKey001 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private byte[] contractAddress; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(testKey001); PublicMethod - .sendcoin(testAddress001, 1000_000_000L, testFoundationAddress, testFoundationKey, - blockingStubFull); + PublicMethod.printAddress(testKey001); + PublicMethod.sendcoin( + testAddress001, 1000_000_000L, testFoundationAddress, testFoundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/create2Istanbul.sol"; - String contractName = "create2Istanbul"; + String filePath = "src/test/resources/soliditycode/create2Istanbul.sol"; + String contractName = "create2Istanbul"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, testKey001, - testAddress001, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); } /** - * Create2 Algorithm Changed - * Before: according to msg.sender`s Address, salt, bytecode to get create2 Address - * After : according to contract`s Address, salt, bytecode to get create2 Address + * Create2 Algorithm Changed Before: according to msg.sender`s Address, salt, bytecode to get + * create2 Address After : according to contract`s Address, salt, bytecode to get create2 Address * The calculated Create2 address should be same as get(bytes1,bytes,uint256) */ - - @Test(enabled = true, description = "create2 Algorithm Change", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "create2 Algorithm Change", + groups = {"contract", "daily"}) public void create2IstanbulTest001() { String filePath = "src/test/resources/soliditycode/create2Istanbul.sol"; - String contractName = "B"; + String contractName = "B"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String methodStr = "deploy(bytes,uint256)"; - String argStr = "\"" + code + "\"," + "1"; - String txid = PublicMethod - .triggerContract(contractAddress, methodStr, argStr, false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String methodStr = "deploy(bytes,uint256)"; + String argStr = "\"" + code + "\"," + "1"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo option = PublicMethod - .getTransactionInfoById(txid, blockingStubFull).get(); - String returnHex = ByteArray.toHexString(option.getContractResult(0).toByteArray()); - - Assert.assertEquals(0,option.getResultValue()); - String methodStr2 = "get(bytes1,bytes,uint256)"; - String argStr2 = "\"41\",\"" + code + "\"," + 1; - TransactionExtention returns = PublicMethod - .triggerConstantContractForExtention(contractAddress, methodStr2, argStr2, - false, 0, - maxFeeLimit, "0", 0, testAddress001, testKey001, blockingStubFull); - String getHex = ByteArray.toHexString(returns.getConstantResult(0).toByteArray()); + TransactionInfo option = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + String returnHex = ByteArray.toHexString(option.getContractResult(0).toByteArray()); - Assert.assertEquals(returnHex,getHex); + Assert.assertEquals(0, option.getResultValue()); + String methodStr2 = "get(bytes1,bytes,uint256)"; + String argStr2 = "\"41\",\"" + code + "\"," + 1; + TransactionExtention returns = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methodStr2, + argStr2, + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress001, + testKey001, + blockingStubFull); + String getHex = ByteArray.toHexString(returns.getConstantResult(0).toByteArray()); + Assert.assertEquals(returnHex, getHex); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/AbiEncodeTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/AbiEncodeTest.java index ad2d82ff..dfe23364 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/AbiEncodeTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/AbiEncodeTest.java @@ -14,60 +14,82 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class AbiEncodeTest extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] contractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); } - @Test(enabled = true, description = "Deploy contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy contract", + groups = {"contract", "daily"}) public void test01DeployContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 1000_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 100_000_000L, - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1000_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 100_000_000L, + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(dev001Key, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = accountResource.getEnergyUsed(); - Long beforeNetUsed = accountResource.getNetUsed(); - Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = accountResource.getEnergyUsed(); + Long beforeNetUsed = accountResource.getNetUsed(); + Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String filePath = "./src/test/resources/soliditycode/abiencode.sol"; - String contractName = "AbiEncode"; + String filePath = "./src/test/resources/soliditycode/abiencode.sol"; + String contractName = "AbiEncode"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); logger.info("abi:" + abi); - final String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + final String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -82,13 +104,12 @@ public void test01DeployContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -97,13 +118,12 @@ public void test01DeployContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(dev001Key, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(dev001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -115,25 +135,43 @@ public void test01DeployContract() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "Trigger contract with ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger contract with ", + groups = {"contract", "daily"}) public void test02TriggerContract() { String methodStr = "h(int256[2][])"; - String argStr = "00000000000000000000000000000000000000000000000000000000000000200000000000000" - + "000000000000000000000000000000000000000000000000003000000000000000000000000000000000000" - + "000000000000000000000000000300000000000000000000000000000000000000000000000000000000000" - + "000040000000000000000000000000000000000000000000000000000000000000000000000000000000000" - + "000000000000000000000000000000000000000000006300000000000000000000000000000000000000000" - + "000000000000000000000060000000000000000000000000000000000000000000000000000000000000008"; - String txid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, true, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String argStr = + "00000000000000000000000000000000000000000000000000000000000000200000000000000" + + "000000000000000000000000000000000000000000000000003000000000000000000000000000000000" + + "000" + + "000000000000000000000000000300000000000000000000000000000000000000000000000000000000" + + "000" + + "000040000000000000000000000000000000000000000000000000000000000000000000000000000000" + + "000" + + "000000000000000000000000000000000000000000006300000000000000000000000000000000000000" + + "000" + + "000000000000000000000060000000000000000000000000000000000000000000000000000000000000" + + "008"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + true, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("trigger contract failed with message: " + infoById.get().getResMessage()); } logger.info("infoById" + infoById); - String contractResult = + String contractResult = ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); Assert.assertEquals( "000000000000000000000000000000000000000000000000000000000000002000000000000000000" @@ -145,21 +183,33 @@ public void test02TriggerContract() { + "00000000000000630000000000000000000000000000000000000000000000000000000000000006000" + "0000000000000000000000000000000000000000000000000000000000008", contractResult); - String methodStr1 = "i(int256[2][2])"; - String argStr1 = "0000000000000000000000000000000000000000000000000000000000000005000000000000" - + "000000000000000000000000000000000000000000000000000700000000000000000000000000000000000" - + "000000000000000000000000003e80000000000000000000000000000000000000000000000000000000000" - + "000065"; - String txid1 = PublicMethod.triggerContract(contractAddress, methodStr1, argStr1, true, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodStr1 = "i(int256[2][2])"; + String argStr1 = + "0000000000000000000000000000000000000000000000000000000000000005000000000000" + + "000000000000000000000000000000000000000000000000000700000000000000000000000000000000" + + "000" + + "000000000000000000000000003e80000000000000000000000000000000000000000000000000000000" + + "000" + + "000065"; + String txid1 = + PublicMethod.triggerContract( + contractAddress, + methodStr1, + argStr1, + true, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById1 = PublicMethod - .getTransactionInfoById(txid1, blockingStubFull); + Optional infoById1 = + PublicMethod.getTransactionInfoById(txid1, blockingStubFull); if (infoById1.get().getResultValue() != 0) { Assert.fail("trigger contract failed with message: " + infoById1.get().getResMessage()); } logger.info("infoById1" + infoById1); - String contractResult1 = + String contractResult1 = ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()); Assert.assertEquals( "000000000000000000000000000000000000000000000000000000000000002000000000000000000" @@ -170,25 +220,43 @@ public void test02TriggerContract() { contractResult1); } - @Test(enabled = true, description = "Trigger contract with negative number", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger contract with negative number", + groups = {"contract", "daily"}) public void test03TriggerContract() { String methodStr = "h(int256[2][])"; - String argStr = "00000000000000000000000000000000000000000000000000000000000000200000000000000" - + "000000000000000000000000000000000000000000000000003ffffffffffffffffffffffffffffffffffff" - + "ffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000" - + "000090000000000000000000000000000000000000000000000000000000000000042ffffffffffffffffff" - + "ffffffffffffffffffffffffffffffffffffffffffffbe00000000000000000000000000000000000000000" - + "000000000000000000000b1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa8"; - String txid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, true, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String argStr = + "00000000000000000000000000000000000000000000000000000000000000200000000000000" + + "000000000000000000000000000000000000000000000000003fffffffffffffffffffffffffffffffff" + + "fff" + + "ffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000" + + "000" + + "000090000000000000000000000000000000000000000000000000000000000000042fffffffffffffff" + + "fff" + + "ffffffffffffffffffffffffffffffffffffffffffffbe00000000000000000000000000000000000000" + + "000" + + "000000000000000000000b1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + + "fa8"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + true, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("trigger contract failed with message: " + infoById.get().getResMessage()); } logger.info("infoById" + infoById); - String contractResult = + String contractResult = ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); Assert.assertEquals( "000000000000000000000000000000000000000000000000000000000000002000000000000000000" @@ -200,21 +268,33 @@ public void test03TriggerContract() { + "ffffffffffffffbe00000000000000000000000000000000000000000000000000000000000000b1fff" + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa8", contractResult); - String methodStr1 = "i(int256[2][2])"; - String argStr1 = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000" - + "000000000000000000000000000000000000000000000000000900000000000000000000000000000000000" - + "00000000000000000000000000042ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - + "ffffbe"; - String txid1 = PublicMethod.triggerContract(contractAddress, methodStr1, argStr1, true, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodStr1 = "i(int256[2][2])"; + String argStr1 = + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000" + + "000000000000000000000000000000000000000000000000000900000000000000000000000000000000" + + "000" + + "00000000000000000000000000042fffffffffffffffffffffffffffffffffffffffffffffffffffffff" + + "fff" + + "ffffbe"; + String txid1 = + PublicMethod.triggerContract( + contractAddress, + methodStr1, + argStr1, + true, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById1 = PublicMethod - .getTransactionInfoById(txid1, blockingStubFull); + Optional infoById1 = + PublicMethod.getTransactionInfoById(txid1, blockingStubFull); if (infoById1.get().getResultValue() != 0) { Assert.fail("trigger contract failed with message: " + infoById1.get().getResMessage()); } logger.info("infoById1" + infoById1); - String contractResult1 = + String contractResult1 = ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()); Assert.assertEquals( "00000000000000000000000000000000000000000000000000000000000000200000000000000000" @@ -228,8 +308,6 @@ public void test03TriggerContract() { @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, - blockingStubFull); } + PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/AbstractTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/AbstractTest.java index fc71aef9..38ef9a76 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/AbstractTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/AbstractTest.java @@ -7,48 +7,50 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import stest.tron.wallet.common.client.Configuration; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; @Slf4j @MultiNode public class AbstractTest extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, description = "compile abstract contract 001", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "compile abstract contract 001", + groups = {"contract", "daily"}) public void test01CompileAbstractContract001() { String filePath = "./src/test/resources/soliditycode/abstract001.sol"; - String contractName = "abstract001"; + String contractName = "abstract001"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); Assert.assertTrue(abi.length() > 0); Assert.assertTrue(code.length() == 0); } - @Test(enabled = true, description = "compile abstract contract 002", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "compile abstract contract 002", + groups = {"contract", "daily"}) public void test02CompileAbstractContract002() { String filePath = "./src/test/resources/soliditycode/abstract002.sol"; - String contractName = "abstract002"; + String contractName = "abstract002"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); Assert.assertTrue(abi.length() > 0); Assert.assertTrue(code.length() == 0); } @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/AddressChange.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/AddressChange.java index b2462273..f8c42588 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/AddressChange.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/AddressChange.java @@ -16,15 +16,16 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class AddressChange extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; byte[] contractAddressOld = null; @@ -33,77 +34,119 @@ public class AddressChange extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - PublicMethod - .sendcoin(contractExcAddress, 1000_000_000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + PublicMethod.sendcoin( + contractExcAddress, + 1000_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/getAddressChange.sol"; - String contractName = "getAddressChange"; + String filePath = "src/test/resources/soliditycode/getAddressChange.sol"; + String contractName = "getAddressChange"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_getAddressChange"); - code = Configuration.getByPath("testng.conf") - .getString("code.code_getAddressChange"); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); + abi = Configuration.getByPath("testng.conf").getString("abi.abi_getAddressChange"); + code = Configuration.getByPath("testng.conf").getString("code.code_getAddressChange"); contractName = "getAddressChangeOldVersion"; - contractAddressOld = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractAddressOld = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "get external function address", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "get external function address", + groups = {"contract", "daily"}) public void test01GetExternalAddress() { String txid = ""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testaddress1()", "#", false, 0, 0, - "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testaddress1()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); - byte[] b1 = new byte[21]; + byte[] b1 = new byte[21]; b1[0] = 0x41; System.arraycopy(result, 12, b1, 1, 20); Assert.assertEquals(Base58.encode58Check(contractAddress), Base58.encode58Check(b1)); } - @Test(enabled = true, description = "get external function address, solidity version < 0.6.0", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "get external function address, solidity version < 0.6.0", + groups = {"contract", "daily"}) public void test02GetExternalAddressOldVersion() { String txid = ""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddressOld, "testaddress1()", "#", false, 0, 0, - "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddressOld, + "testaddress1()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); - byte[] b1 = new byte[21]; + byte[] b1 = new byte[21]; b1[0] = 0x41; System.arraycopy(result, 12, b1, 1, 20); Assert.assertEquals(Base58.encode58Check(contractAddressOld), Base58.encode58Check(b1)); @@ -111,10 +154,12 @@ public void test02GetExternalAddressOldVersion() { @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractAddress, contractExcKey, testNetAccountAddress, blockingStubFull); - PublicMethod - .freeResource(contractAddressOld, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + PublicMethod.freeResource( + contractAddressOld, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/AssignToExternalTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/AssignToExternalTest.java index 9b522f60..acafd2e6 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/AssignToExternalTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/AssignToExternalTest.java @@ -13,57 +13,72 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class AssignToExternalTest extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] contractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); } - @Test(enabled = true, description = "Deploy contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy contract", + groups = {"contract", "daily"}) public void test01DeployContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 1000_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1000_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(dev001Key, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = accountResource.getEnergyUsed(); - Long beforeNetUsed = accountResource.getNetUsed(); - Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = accountResource.getEnergyUsed(); + Long beforeNetUsed = accountResource.getNetUsed(); + Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String filePath = "./src/test/resources/soliditycode/AssignToExternal.sol"; - String contractName = "AssignToExternal"; + String filePath = "./src/test/resources/soliditycode/AssignToExternal.sol"; + String contractName = "AssignToExternal"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -78,13 +93,12 @@ public void test01DeployContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -93,13 +107,12 @@ public void test01DeployContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(dev001Key, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(dev001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -111,108 +124,168 @@ public void test01DeployContract() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "Trigger contract with ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger contract with ", + groups = {"contract", "daily"}) public void test02TriggerContract() { String methodStr = "f(uint256)"; - String argStr = "2"; - String txid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String argStr = "2"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("trigger contract failed with message: " + infoById.get().getResMessage()); } logger.info("infoById" + infoById); - int contractResult = - ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); + int contractResult = ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); Assert.assertEquals(3, contractResult); } - @Test(enabled = true, description = "Trigger contract with ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger contract with ", + groups = {"contract", "daily"}) public void test03TriggerContract() { String methodStr = "StringSet(string)"; - String argStr = "\"test\""; - String txid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String argStr = "\"test\""; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("trigger contract failed with message: " + infoById.get().getResMessage()); } logger.info("infoById" + infoById); - String contractResult = + String contractResult = ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000020" - + "0000000000000000000000000000000000000000000000000000000000000004" - + "7465737400000000000000000000000000000000000000000000000000000000", contractResult); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000020" + + "0000000000000000000000000000000000000000000000000000000000000004" + + "7465737400000000000000000000000000000000000000000000000000000000", + contractResult); } - @Test(enabled = true, description = "Trigger contract with ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger contract with ", + groups = {"contract", "daily"}) public void test04TriggerContract() { String methodStr = "ByteSet(bytes32)"; - String argStr = "00000000000000000000000000000000000000000000000000000000000003e9"; - String txid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, true, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String argStr = "00000000000000000000000000000000000000000000000000000000000003e9"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + true, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("trigger contract failed with message: " + infoById.get().getResMessage()); } logger.info("infoById" + infoById); - int contractResult = - ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); + int contractResult = ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); Assert.assertEquals(1001, contractResult); } - @Test(enabled = true, description = "Trigger contract with ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger contract with ", + groups = {"contract", "daily"}) public void test05TriggerContract() { String methodStr = "UintArraySet(uint256[2])"; - String argStr = "00000000000000000000000000000000000000000000000000000000000003e9" - + "00000000000000000000000000000000000000000000000000000000000003e9"; - String txid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, true, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String argStr = + "00000000000000000000000000000000000000000000000000000000000003e9" + + "00000000000000000000000000000000000000000000000000000000000003e9"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + true, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("trigger contract failed with message: " + infoById.get().getResMessage()); } logger.info("infoById" + infoById); - String contractResult = + String contractResult = ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); - Assert.assertEquals("00000000000000000000000000000000000000000000000000000000000003e9" - + "00000000000000000000000000000000000000000000000000000000000003e9", contractResult); + Assert.assertEquals( + "00000000000000000000000000000000000000000000000000000000000003e9" + + "00000000000000000000000000000000000000000000000000000000000003e9", + contractResult); } - @Test(enabled = true, description = "Trigger contract with ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger contract with ", + groups = {"contract", "daily"}) public void test06TriggerContract() { String methodStr = "AddSet(address)"; - String argStr = "\"TYVT8YJYis13NdrzdE7yVuwVxjsaRy2UsM\""; - String txid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String argStr = "\"TYVT8YJYis13NdrzdE7yVuwVxjsaRy2UsM\""; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("trigger contract failed with message: " + infoById.get().getResMessage()); } logger.info("infoById" + infoById); - String contractResult = + String contractResult = ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); - Assert.assertEquals("000000000000000000000000f70b0a56acf4b0af44723c329ff113a677b5f589", - contractResult); + Assert.assertEquals( + "000000000000000000000000f70b0a56acf4b0af44723c329ff113a677b5f589", contractResult); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, - blockingStubFull); } + PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, blockingStubFull); + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/BlobTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/BlobTest.java index 11e8b08f..936bff4c 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/BlobTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/BlobTest.java @@ -1,5 +1,6 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.newGrammar; +import java.util.HashMap; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.testng.annotations.AfterClass; @@ -9,334 +10,618 @@ import org.tron.protos.Protocol; import org.tron.protos.contract.SmartContractOuterClass; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; - -import java.util.HashMap; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class BlobTest extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - byte[] contractC,contractD; + byte[] contractC; + byte[] contractD; String base58contractC; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 50100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 50100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/blob.sol"; - String contractName = "C"; - String compileParam = "--experimental-via-ir"; + String filePath = "src/test/resources/soliditycode/blob.sol"; + String contractName = "C"; + String compileParam = "--experimental-via-ir"; HashMap retMap = PublicMethod.getBycodeAbiWithParam(filePath, contractName, compileParam); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractC = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractC = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); base58contractC = Base58.encode58Check(contractC); contractName = "D"; retMap = PublicMethod.getBycodeAbiWithParam(filePath, contractName, compileParam); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - contractD = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractD = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(contractC, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(contractC, blockingStubFull); Assert.assertNotNull(smartContract.getAbi().toString()); smartContract = PublicMethod.getContract(contractD, blockingStubFull); Assert.assertNotNull(smartContract.getAbi().toString()); } - @Test(enabled = true, description = "test blobhash in assembly", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test blobhash in assembly", + groups = {"contract", "daily"}) public void test01AssemblyBlobhash() { - String txid = PublicMethod.triggerContract(contractC, - "assemblyBlobhash()", "#", - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractC, + "assemblyBlobhash()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, info.getResult()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); - String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000",result); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); + String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); + Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", result); } - @Test(enabled = true, description = "test blobbasefee in assembly", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test blobbasefee in assembly", + groups = {"contract", "daily"}) public void test02assemblyBlobbasefee() { - String txid = PublicMethod.triggerContract(contractC, - "assemblyBlobbasefee()", "#", - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractC, + "assemblyBlobbasefee()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, info.getResult()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); - String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000",result); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); + String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); + Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", result); } - @Test(enabled = true, description = "test blobhash(index)", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test blobhash(index)", + groups = {"contract", "daily"}) public void test03GlobalBlobHash() { String args = "1"; - String txid = PublicMethod.triggerContract(contractC, - "globalBlobHash(uint256)", args, - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractC, + "globalBlobHash(uint256)", + args, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, info.getResult()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); - String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000",result); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); + String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); + Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", result); } - @Test(enabled = true, description = "test block.blobbasefee", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test block.blobbasefee", + groups = {"contract", "daily"}) public void test04GlobalBlobbasefee() { - String txid = PublicMethod.triggerContract(contractC, - "globalBlobbasefee()", "#", - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractC, + "globalBlobbasefee()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, info.getResult()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); - String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000",result); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); + String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); + Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", result); } - @Test(enabled = true, description = "test blob KZGPointEvaluation", groups = {"contract", "daily"}) - public void test05KZGPointEvaluation(){ - String versionedHash ="015a4cab4911426699ed34483de6640cf55a568afc5c5edffdcbd8bcd4452f68"; - String z = "0000000000000000000000000000000000000000000000000000000000000065"; - String y = "60f557194475973322b33dc989896381844508234bfa6fbeefe5fa165ae15a0a"; - String commitment = "a70477b56251e8770969c83eaed665d3ab99b96b72270a4" - + "1009f2752b5c06a06bd089ad48952c12b1dbf83dccd9d373f"; - String proof = "879f9a41956deae578bc65e7133f164394b8677bc2e7b1356be61" + @Test( + enabled = true, + description = "test blob KZGPointEvaluation", + groups = {"contract", "daily"}) + public void test05KZGPointEvaluation() { + String versionedHash = "015a4cab4911426699ed34483de6640cf55a568afc5c5edffdcbd8bcd4452f68"; + String z = "0000000000000000000000000000000000000000000000000000000000000065"; + String y = "60f557194475973322b33dc989896381844508234bfa6fbeefe5fa165ae15a0a"; + String commitment = + "a70477b56251e8770969c83eaed665d3ab99b96b72270a4" + + "1009f2752b5c06a06bd089ad48952c12b1dbf83dccd9d373f"; + String proof = + "879f9a41956deae578bc65e7133f164394b8677bc2e7b1356be61" + "d47720ed2a3326bfddebc67cd37ee9e7537d7814afe"; -String args = "\""+ versionedHash+"\",\"" + commitment +"\",\""+z+"\",\""+y+"\",\""+proof+"\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtention(contractC, - "verifyKZG(bytes,bytes,bytes,bytes,bytes)", args, - false, 0, maxFeeLimit,"0",0, contractExcAddress, contractExcKey, blockingStubFull); + String args = + "\"" + + versionedHash + + "\",\"" + + commitment + + "\",\"" + + z + + "\",\"" + + y + + "\",\"" + + proof + + "\""; + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractC, + "verifyKZG(bytes,bytes,bytes,bytes,bytes)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); System.out.println(transactionExtention.toString()); - String result = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); - //KZG removed -// Assert.assertEquals( -// "0000000000000000000000000000000000000000000000000000000000000001" + -// "0000000000000000000000000000000000000000000000000000000000000040" + -// "0000000000000000000000000000000000000000000000000000000000000040" + -// "0000000000000000000000000000000000000000000000000000000000001000" + -// "73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001", result); + String result = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + // KZG removed + // Assert.assertEquals( + // "0000000000000000000000000000000000000000000000000000000000000001" + + // "0000000000000000000000000000000000000000000000000000000000000040" + + // "0000000000000000000000000000000000000000000000000000000000000040" + + // "0000000000000000000000000000000000000000000000000000000000001000" + + // "73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001", + // result); Assert.assertEquals( - "00000000000000000000000000000000000000000000000000000000000000010" + - "000000000000000000000000000000000000000000000000000000000000040" + - "0000000000000000000000000000000000000000000000000000000000000000", result); + "00000000000000000000000000000000000000000000000000000000000000010" + + "000000000000000000000000000000000000000000000000000000000000040" + + "0000000000000000000000000000000000000000000000000000000000000000", + result); } - @Test(enabled = true, description = "test blob KZGPointEvaluation", groups = {"contract", "daily"}) - public void test06KZGPointEvaluation(){ - String versionedHash ="015a4cab4911426699ed34483de6640cf55a568afc5c5edffdcbd8bcd4452f68"; - String z = "0000000000000000000000000000000000000000000000000000000000000065"; - String y = "60f557194475973322b33dc989896381844508234bfa6fbeefe5fa165ae15a0a"; - String commitment = "a70477b56251e8770969c83eaed665d3ab99b96b72270a4" + @Test( + enabled = true, + description = "test blob KZGPointEvaluation", + groups = {"contract", "daily"}) + public void test06KZGPointEvaluation() { + String versionedHash = "015a4cab4911426699ed34483de6640cf55a568afc5c5edffdcbd8bcd4452f68"; + String z = "0000000000000000000000000000000000000000000000000000000000000065"; + String y = "60f557194475973322b33dc989896381844508234bfa6fbeefe5fa165ae15a0a"; + String commitment = + "a70477b56251e8770969c83eaed665d3ab99b96b72270a4" + "1009f2752b5c06a06bd089ad48952c12b1dbf83dccd9d373f"; - String proof = "879f9a41956deae578bc65e7133f164394b8677bc2e7b1356be61" + String proof = + "879f9a41956deae578bc65e7133f164394b8677bc2e7b1356be61" + "d47720ed2a3326bfddebc67cd37ee9e7537d7814afe"; - String args = "\""+ versionedHash+"\",\"" + commitment +"\",\""+z+"\",\""+y+"\",\""+proof+"\""; - String txid = PublicMethod.triggerContract(contractC, - "verifyKZG1(bytes,bytes,bytes,bytes,bytes)", args, - false, 0, maxFeeLimit,"0",0, contractExcAddress, contractExcKey, blockingStubFull); + String args = + "\"" + + versionedHash + + "\",\"" + + commitment + + "\",\"" + + z + + "\",\"" + + y + + "\",\"" + + proof + + "\""; + String txid = + PublicMethod.triggerContract( + contractC, + "verifyKZG1(bytes,bytes,bytes,bytes,bytes)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, info.getResult()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); - String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); - // KZG removed -// Assert.assertEquals( -// "0000000000000000000000000000000000000000000000000000000000000001" + -// "0000000000000000000000000000000000000000000000000000000000000040" + -// "0000000000000000000000000000000000000000000000000000000000000040" + -// "0000000000000000000000000000000000000000000000000000000000001000" + -// "73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001", result); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); + String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); + // KZG removed + // Assert.assertEquals( + // "0000000000000000000000000000000000000000000000000000000000000001" + + // "0000000000000000000000000000000000000000000000000000000000000040" + + // "0000000000000000000000000000000000000000000000000000000000000040" + + // "0000000000000000000000000000000000000000000000000000000000001000" + + // "73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001", + // result); Assert.assertEquals( - "00000000000000000000000000000000000000000000000000000000000000010" + - "000000000000000000000000000000000000000000000000000000000000040" + - "0000000000000000000000000000000000000000000000000000000000000000", result); + "00000000000000000000000000000000000000000000000000000000000000010" + + "000000000000000000000000000000000000000000000000000000000000040" + + "0000000000000000000000000000000000000000000000000000000000000000", + result); } - - @Test(enabled = true, description = "test blob KZGPointEvaluation", groups = {"contract", "daily"}) - public void test07callKZGPointEvaluation(){ - String versionedHash ="01a327088bb2b13151449d8313c281d0006d12e8453e863637b746898b6ad5a6"; - String z = "0000000000000000000000000000000000000000000000000000000000000000"; - String y = "0000000010000000000000000000000000000000000000000000000000000000"; - String commitment = "8f26f349339c68b33ce856aa2c05b8f89e7c23db0c00817550679998efcbd8f2464f9e1ea6c3172b0b750603d1e4ea38"; - String proof = "97d8c90897645ac9e31e8017981de0f9d0d5de4cec12899680ee4e810f4f7f56ac765e46a801f2f1046f8f305d33e27c"; - String args = "\""+ versionedHash+"\",\"" + commitment +"\",\""+z+"\",\""+y+"\",\""+proof+"\""; - String txid = PublicMethod.triggerContract(contractC, - "verifyKZGCall(bytes,bytes,bytes,bytes,bytes)", args, - false, 0, maxFeeLimit,"0",0, contractExcAddress, contractExcKey, blockingStubFull); + @Test( + enabled = true, + description = "test blob KZGPointEvaluation", + groups = {"contract", "daily"}) + public void test07callKZGPointEvaluation() { + String versionedHash = "01a327088bb2b13151449d8313c281d0006d12e8453e863637b746898b6ad5a6"; + String z = "0000000000000000000000000000000000000000000000000000000000000000"; + String y = "0000000010000000000000000000000000000000000000000000000000000000"; + String commitment = + "8f26f349339c68b33ce856aa2c05b8f89e7c23db0c00817550679998efcbd8f2464f9e1ea6c3172b0b750603d1" + + "e4ea38"; + String proof = + "97d8c90897645ac9e31e8017981de0f9d0d5de4cec12899680ee4e810f4f7f56ac765e46a801f2f1046f8f305d" + + "33e27c"; + String args = + "\"" + + versionedHash + + "\",\"" + + commitment + + "\",\"" + + z + + "\",\"" + + y + + "\",\"" + + proof + + "\""; + String txid = + PublicMethod.triggerContract( + contractC, + "verifyKZGCall(bytes,bytes,bytes,bytes,bytes)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, info.getResult()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); - String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); - // KZG removed -// Assert.assertEquals( -// "0000000000000000000000000000000000000000000000000000000000000001" + -// "0000000000000000000000000000000000000000000000000000000000000040" + -// "0000000000000000000000000000000000000000000000000000000000000040" + -// "0000000000000000000000000000000000000000000000000000000000001000" + -// "73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001", result); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); + String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); + // KZG removed + // Assert.assertEquals( + // "0000000000000000000000000000000000000000000000000000000000000001" + + // "0000000000000000000000000000000000000000000000000000000000000040" + + // "0000000000000000000000000000000000000000000000000000000000000040" + + // "0000000000000000000000000000000000000000000000000000000000001000" + + // "73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001", + // result); Assert.assertEquals( - "00000000000000000000000000000000000000000000000000000000000000010" + - "000000000000000000000000000000000000000000000000000000000000040" + - "0000000000000000000000000000000000000000000000000000000000000000", result); + "00000000000000000000000000000000000000000000000000000000000000010" + + "000000000000000000000000000000000000000000000000000000000000040" + + "0000000000000000000000000000000000000000000000000000000000000000", + result); } - @Test(enabled = true, description = "test staticcallBlobhash", groups = {"contract", "daily"}) - public void test08StaticcallBlobhashn(){ + @Test( + enabled = true, + description = "test staticcallBlobhash", + groups = {"contract", "daily"}) + public void test08StaticcallBlobhashn() { String args = "\"" + base58contractC + "\""; - String txid = PublicMethod.triggerContract(contractD, - "staticcallBlobhash(address)", args, - false, 0, maxFeeLimit,"0",0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractD, + "staticcallBlobhash(address)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, info.getResult()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); - String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); + String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", result); } - @Test(enabled = true, description = "test StaticcallBlobBaseFee", groups = {"contract", "daily"}) - public void test09StaticcallBlobBaseFee(){ + @Test( + enabled = true, + description = "test StaticcallBlobBaseFee", + groups = {"contract", "daily"}) + public void test09StaticcallBlobBaseFee() { String args = "\"" + base58contractC + "\""; - String txid = PublicMethod.triggerContract(contractD, - "staticcallBlobBaseFee(address)", args, - false, 0, maxFeeLimit,"0",0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractD, + "staticcallBlobBaseFee(address)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, info.getResult()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); - String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); + String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", result); } - @Test(enabled = true, description = "test blob KZGPointEvaluation", groups = {"contract", "daily"}) - public void test10callBlobhash(){ + @Test( + enabled = true, + description = "test blob KZGPointEvaluation", + groups = {"contract", "daily"}) + public void test10callBlobhash() { String args = "\"" + base58contractC + "\""; - String txid = PublicMethod.triggerContract(contractD, - "callBlobhash(address)", args, - false, 0, maxFeeLimit,"0",0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractD, + "callBlobhash(address)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, info.getResult()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); - String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); + String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", result); } - @Test(enabled = true, description = "test StaticcallBlobBaseFee", groups = {"contract", "daily"}) - public void test11CallBlobBaseFee(){ + @Test( + enabled = true, + description = "test StaticcallBlobBaseFee", + groups = {"contract", "daily"}) + public void test11CallBlobBaseFee() { String args = "\"" + base58contractC + "\""; - String txid = PublicMethod.triggerContract(contractD, - "callBlobBaseFee(address)", args, - false, 0, maxFeeLimit,"0",0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractD, + "callBlobBaseFee(address)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, info.getResult()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); - String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); + String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", result); } - @Test(enabled = true, description = "test delegatecallBlobhash", groups = {"contract", "daily"}) - public void test12delegatecallBlobhash(){ + @Test( + enabled = true, + description = "test delegatecallBlobhash", + groups = {"contract", "daily"}) + public void test12delegatecallBlobhash() { String args = "\"" + base58contractC + "\""; - String txid = PublicMethod.triggerContract(contractD, - "delegatecallBlobhash(address)", args, - false, 0, maxFeeLimit,"0",0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractD, + "delegatecallBlobhash(address)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, info.getResult()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); - String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); + String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", result); } - @Test(enabled = true, description = "test delegatecallBlobBaseFee", groups = {"contract", "daily"}) - public void test13delegatecallBlobBaseFee(){ + @Test( + enabled = true, + description = "test delegatecallBlobBaseFee", + groups = {"contract", "daily"}) + public void test13delegatecallBlobBaseFee() { String args = "\"" + base58contractC + "\""; - String txid = PublicMethod.triggerContract(contractD, - "delegatecallBlobBaseFee(address)", args, - false, 0, maxFeeLimit,"0",0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractD, + "delegatecallBlobBaseFee(address)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, info.getResult()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); - String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); + String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", result); } - @Test(enabled = false, description = "test blob KZGPointEvaluation", groups = {"contract", "daily"}) - public void test14delegatecallKZGPointEvaluation(){ - String versionedHash ="0000000000000000000000000000000000000000000000000000000000000000"; - String z = "0000000000000000000000000000000000000000000000000000000000000000"; - String y = "0000000000000000000000000000000000000000000000000000000000000000"; - String commitment = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; - String proof = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; - String args = "\""+ versionedHash+"\",\"" + commitment +"\",\""+z+"\",\""+y+"\",\""+proof+"\""; - String txid = PublicMethod.triggerContract(contractC, - "verifyKZG1(bytes,bytes,bytes,bytes,bytes)", args, - false, 0, maxFeeLimit,"0",0, contractExcAddress, contractExcKey, blockingStubFull); + @Test( + enabled = false, + description = "test blob KZGPointEvaluation", + groups = {"contract", "daily"}) + public void test14delegatecallKZGPointEvaluation() { + String versionedHash = "0000000000000000000000000000000000000000000000000000000000000000"; + String z = "0000000000000000000000000000000000000000000000000000000000000000"; + String y = "0000000000000000000000000000000000000000000000000000000000000000"; + String commitment = + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + + "000000"; + String proof = + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + + "000000"; + String args = + "\"" + + versionedHash + + "\",\"" + + commitment + + "\",\"" + + z + + "\",\"" + + y + + "\",\"" + + proof + + "\""; + String txid = + PublicMethod.triggerContract( + contractC, + "verifyKZG1(bytes,bytes,bytes,bytes,bytes)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, info.getResult()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); - String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); Assert.assertEquals( - "0000000000000000000000000000000000000000000000000000000000000001" + - "0000000000000000000000000000000000000000000000000000000000000040" + - "0000000000000000000000000000000000000000000000000000000000000040" + - "0000000000000000000000000000000000000000000000000000000000001000" + - "73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001", result); + Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); + String result = ByteArray.toHexString(info.getContractResult(0).toByteArray()); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000001" + + "0000000000000000000000000000000000000000000000000000000000000040" + + "0000000000000000000000000000000000000000000000000000000000000040" + + "0000000000000000000000000000000000000000000000000000000000001000" + + "73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001", + result); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/BlockhashTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/BlockhashTest.java index 5bdf3232..099042d6 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/BlockhashTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/BlockhashTest.java @@ -9,139 +9,207 @@ import org.tron.protos.Protocol.TransactionInfo; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class BlockhashTest extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] contractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/BlockHash.sol"; - String contractName = "TestBlockHash"; + String filePath = "./src/test/resources/soliditycode/BlockHash.sol"; + String contractName = "TestBlockHash"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "BlockHash should not be change after command OR", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "BlockHash should not be change after command OR", + groups = {"contract", "daily"}) public void test01BlockHashWithOR() { String methodStr = "testOR1(bytes32)"; - String argStr = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; - String txid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, true, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String argStr = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + true, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); - String ContractResult = ByteArray.toHexString(infoById.get() - .getContractResult(0).toByteArray()); - // 3 bytes32 + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); + String ContractResult = + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); + // 3 bytes32 Assert.assertEquals(192, ContractResult.length()); - // blockHash before OR should equals to blockHash after OR - Assert.assertEquals(ContractResult.substring(0,64),ContractResult.substring(128)); + // blockHash before OR should equals to blockHash after OR + Assert.assertEquals(ContractResult.substring(0, 64), ContractResult.substring(128)); methodStr = "testOR2(bytes32)"; - txid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, true, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + true, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); - ContractResult = ByteArray.toHexString(infoById.get() - .getContractResult(0).toByteArray()); - // 3 bytes32 + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); + ContractResult = ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); + // 3 bytes32 Assert.assertEquals(192, ContractResult.length()); - // blockHash before OR should equals to blockHash after OR - Assert.assertEquals(ContractResult.substring(0,64),ContractResult.substring(128)); + // blockHash before OR should equals to blockHash after OR + Assert.assertEquals(ContractResult.substring(0, 64), ContractResult.substring(128)); } - @Test(enabled = true, description = "BlockHash should not be change after command AND", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "BlockHash should not be change after command AND", + groups = {"contract", "daily"}) public void test02BlockHashWithAND() { String methodStr = "testAND1(bytes32)"; - String argStr = "0000000000000000000000000000000000000000000000000000000000000000"; - String txid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, true, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String argStr = "0000000000000000000000000000000000000000000000000000000000000000"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + true, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); - String ContractResult = ByteArray.toHexString(infoById.get() - .getContractResult(0).toByteArray()); - // 3 bytes32 + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); + String ContractResult = + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); + // 3 bytes32 Assert.assertEquals(192, ContractResult.length()); - // blockHash before AND should equals to blockHash after AND - Assert.assertEquals(ContractResult.substring(0,64),ContractResult.substring(128)); + // blockHash before AND should equals to blockHash after AND + Assert.assertEquals(ContractResult.substring(0, 64), ContractResult.substring(128)); methodStr = "testAND2(bytes32)"; - txid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, true, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + true, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); - ContractResult = ByteArray.toHexString(infoById.get() - .getContractResult(0).toByteArray()); - // 3 bytes32 + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); + ContractResult = ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); + // 3 bytes32 Assert.assertEquals(192, ContractResult.length()); - // blockHash before AND should equals to blockHash after AND - Assert.assertEquals(ContractResult.substring(0,64),ContractResult.substring(128)); + // blockHash before AND should equals to blockHash after AND + Assert.assertEquals(ContractResult.substring(0, 64), ContractResult.substring(128)); } - @Test(enabled = true, description = "BlockHash should not be change after command XOR", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "BlockHash should not be change after command XOR", + groups = {"contract", "daily"}) public void test03BlockHashWithXOR() { String methodStr = "testXOR1(bytes32)"; - String argStr = "00000000000000000000000000000000ffffffffffffffffffffffffffffffff"; - String txid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, true, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String argStr = "00000000000000000000000000000000ffffffffffffffffffffffffffffffff"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + true, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); - String ContractResult = ByteArray.toHexString(infoById.get() - .getContractResult(0).toByteArray()); - // 3 bytes32 + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); + String ContractResult = + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); + // 3 bytes32 Assert.assertEquals(192, ContractResult.length()); - // blockHash before XOR should equals to blockHash after XOR - Assert.assertEquals(ContractResult.substring(0,64),ContractResult.substring(128)); + // blockHash before XOR should equals to blockHash after XOR + Assert.assertEquals(ContractResult.substring(0, 64), ContractResult.substring(128)); methodStr = "testXOR2(bytes32)"; - txid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, true, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + true, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); - ContractResult = ByteArray.toHexString(infoById.get() - .getContractResult(0).toByteArray()); - // 3 bytes32 + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); + ContractResult = ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); + // 3 bytes32 Assert.assertEquals(192, ContractResult.length()); - // blockHash before XOR should equals to blockHash after XOR - Assert.assertEquals(ContractResult.substring(0,64),ContractResult.substring(128)); + // blockHash before XOR should equals to blockHash after XOR + Assert.assertEquals(ContractResult.substring(0, 64), ContractResult.substring(128)); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/CallValueGasPureTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/CallValueGasPureTest.java index a8f6e4a1..f6f39f59 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/CallValueGasPureTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/CallValueGasPureTest.java @@ -16,57 +16,83 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j public class CallValueGasPureTest extends TronBaseTest { - private final String foundationKey001 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String foundationKey001 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] foundationAddress001 = PublicMethod.getFinalAddress(foundationKey001); private byte[] contractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] testAddress001 = ecKey1.getAddress(); private String testKey001 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(testKey001); + public void beforeClass() { + PublicMethod.printAddress(testKey001); } - @Test(enabled = true, description = "call.value.gas be pure", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "call.value.gas be pure", + groups = {"contract", "daily"}) public void test01DeployContract() { - Assert.assertTrue(PublicMethod - .sendcoin(testAddress001, 1000_000_000L, foundationAddress001, foundationKey001, + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress001, + 1000_000_000L, + foundationAddress001, + foundationKey001, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress001, + 100_000_000L, + 0, + 0, + ByteString.copyFrom(testAddress001), + foundationKey001, blockingStubFull)); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress001, 100_000_000L, 0, 0, - ByteString.copyFrom(testAddress001), foundationKey001, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod - .getAccountResource(testAddress001, blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(testAddress001, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(testKey001, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = accountResource.getEnergyUsed(); - Long beforeNetUsed = accountResource.getNetUsed(); - Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = accountResource.getEnergyUsed(); + Long beforeNetUsed = accountResource.getNetUsed(); + Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String filePath = "./src/test/resources/soliditycode/callValueGasPure.sol"; - String contractName = "C"; + String filePath = "./src/test/resources/soliditycode/callValueGasPure.sol"; + String contractName = "C"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 0, - 10000, "0", 0, null, testKey001, testAddress001, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + testKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -83,23 +109,30 @@ public void test01DeployContract() { contractAddress = infoById.get().getContractAddress().toByteArray(); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - String param = "\"" + Base58.encode58Check(testAddress001) + "\""; - TransactionExtention extention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "check(address)", - param, false, 0, 1000000000L, "0", 0, testAddress001, - testKey001, blockingStubFull); + String param = "\"" + Base58.encode58Check(testAddress001) + "\""; + TransactionExtention extention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "check(address)", + param, + false, + 0, + 1000000000L, + "0", + 0, + testAddress001, + testKey001, + blockingStubFull); Assert.assertNotNull(extention); Assert.assertTrue(extention.hasResult()); Assert.assertTrue(extention.getResult().getResult()); - } @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(testKey001, blockingStubFull).getBalance(); - PublicMethod - .sendcoin(foundationAddress001, balance, testAddress001, testKey001, blockingStubFull); } + PublicMethod.sendcoin( + foundationAddress001, balance, testAddress001, testKey001, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/CallvalueTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/CallvalueTest.java index bfe7b384..5090805f 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/CallvalueTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/CallvalueTest.java @@ -14,59 +14,81 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class CallvalueTest extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] contractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); } - @Test(enabled = true, description = "Deploy contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy contract", + groups = {"contract", "daily"}) public void test01DeployContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 3147483647L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 100_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 3147483647L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 100_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(dev001Key, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = accountResource.getEnergyUsed(); - Long beforeNetUsed = accountResource.getNetUsed(); - Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = accountResource.getEnergyUsed(); + Long beforeNetUsed = accountResource.getNetUsed(); + Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String filePath = "./src/test/resources/soliditycode/callvalue.sol"; - String contractName = "Callvalue"; + String filePath = "./src/test/resources/soliditycode/callvalue.sol"; + String contractName = "Callvalue"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -81,13 +103,12 @@ public void test01DeployContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -96,13 +117,12 @@ public void test01DeployContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(dev001Key, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(dev001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -114,48 +134,78 @@ public void test01DeployContract() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "Trigger contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger contract", + groups = {"contract", "daily"}) public void test02TriggerContract() { String methodStr = "check()"; - // 15 - String triggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, "", true, - 15, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + // 15 + String triggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + "", + true, + 15, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("trigger contract failed with message: " + infoById.get().getResMessage()); } logger.info("infoById" + infoById); - String contractResult = + String contractResult = ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); logger.info("contractResult:" + contractResult); Assert.assertEquals(Long.parseLong(contractResult, 16), 15); - // 0 - String triggerTxid1 = PublicMethod.triggerContract(contractAddress, methodStr, "", true, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + // 0 + String triggerTxid1 = + PublicMethod.triggerContract( + contractAddress, + methodStr, + "", + true, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById1 = PublicMethod - .getTransactionInfoById(triggerTxid1, blockingStubFull); + Optional infoById1 = + PublicMethod.getTransactionInfoById(triggerTxid1, blockingStubFull); if (infoById1.get().getResultValue() != 0) { Assert.fail("trigger contract failed with message: " + infoById1.get().getResMessage()); } logger.info("infoById1" + infoById1); - String contractResult1 = + String contractResult1 = ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()); logger.info("contractResult1:" + contractResult1); Assert.assertEquals(Long.parseLong(contractResult1, 16), 0); - // Integer.MAX_VALUE - String triggerTxid2 = PublicMethod.triggerContract(contractAddress, methodStr, "", true, - Integer.MAX_VALUE, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + // Integer.MAX_VALUE + String triggerTxid2 = + PublicMethod.triggerContract( + contractAddress, + methodStr, + "", + true, + Integer.MAX_VALUE, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById2 = PublicMethod - .getTransactionInfoById(triggerTxid2, blockingStubFull); + Optional infoById2 = + PublicMethod.getTransactionInfoById(triggerTxid2, blockingStubFull); if (infoById2.get().getResultValue() != 0) { Assert.fail("trigger contract failed with message: " + infoById2.get().getResMessage()); } logger.info("infoById2" + infoById2); - String contractResult2 = + String contractResult2 = ByteArray.toHexString(infoById2.get().getContractResult(0).toByteArray()); logger.info("contractResult2:" + contractResult2); Assert.assertEquals(Long.parseLong(contractResult2, 16), Integer.MAX_VALUE); @@ -164,8 +214,6 @@ public void test02TriggerContract() { @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, - blockingStubFull); } + PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/CanCunTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/CanCunTest.java index 907e4253..d7b035ab 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/CanCunTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/CanCunTest.java @@ -1,160 +1,262 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.newGrammar; +import java.util.HashMap; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.tron.api.GrpcAPI; import org.tron.protos.Protocol; import org.tron.protos.contract.SmartContractOuterClass; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; - -import java.util.HashMap; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class CanCunTest extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - byte[] contractA,contractB; + byte[] contractA; + byte[] contractB; String base58ContractA; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 50100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 50100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/CanCun.sol"; - String contractName = "A"; + String filePath = "src/test/resources/soliditycode/CanCun.sol"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractA = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 10000000L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractA = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 10000000L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); base58ContractA = Base58.encode58Check(contractA); contractName = "B"; retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - contractB = PublicMethod.deployContractFallback(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractB = + PublicMethod.deployContractFallback( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(contractA, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(contractA, blockingStubFull); Assert.assertNotNull(smartContract.getAbi().toString()); smartContract = PublicMethod.getContract(contractB, blockingStubFull); Assert.assertNotNull(smartContract.getAbi().toString()); } - @Test(enabled = true, description = "tload and tstore", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "tload and tstore", + groups = {"contract", "daily"}) public void test01TloadTstore() { - String txid = PublicMethod.triggerContract(contractA, - "tstoreAndTload()", "#", - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractA, + "tstoreAndTload()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, info.getResult()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); } - @Test(enabled = true, description = "nonreentrant for entrant 1 time", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "nonreentrant for entrant 1 time", + groups = {"contract", "daily"}) public void test02TloadTstore() { - String txid = PublicMethod.triggerContract(contractA, - "claimGift()", "#", - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractA, + "claimGift()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, info.getResult()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); long callValue = info.getInternalTransactions(0).getCallValueInfo(0).getCallValue(); Assert.assertEquals(1000000, callValue); } - @Test(enabled = true, description = "call nonreentrant once", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "call nonreentrant once", + groups = {"contract", "daily"}) public void test03TloadTstore() { String args = "\"" + base58ContractA + "\""; - String txid = PublicMethod.triggerContract(contractB, - "claimGiftOnce(address)", args, - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractB, + "claimGiftOnce(address)", + args, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, info.getResult()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); long callValue = info.getInternalTransactions(1).getCallValueInfo(0).getCallValue(); Assert.assertEquals(1000000, callValue); - long balance = PublicMethod.queryAccount(contractB,blockingStubFull).getBalance(); + long balance = PublicMethod.queryAccount(contractB, blockingStubFull).getBalance(); Assert.assertEquals(callValue, balance); } - @Test(enabled = true, description = "call nonreentrant for 2 times ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "call nonreentrant for 2 times ", + groups = {"contract", "daily"}) public void test04TloadTstore() { String args = "\"" + base58ContractA + "\""; - String txid = PublicMethod.triggerContract(contractB, - "claimGiftTwice(address)", args, - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractB, + "claimGiftTwice(address)", + args, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); Assert.assertEquals(Protocol.TransactionInfo.code.FAILED, info.getResult()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.REVERT, info.getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.REVERT, info.getReceipt().getResult()); } - @Test(enabled = true, description = "", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "", + groups = {"contract", "daily"}) public void test05MemoryCopy() { - String txid = PublicMethod.triggerContract(contractA, - "memoryCopy()", "#", - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractA, + "memoryCopy()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000050",ByteArray.toHexString(info.getContractResult(0).toByteArray())); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000050", + ByteArray.toHexString(info.getContractResult(0).toByteArray())); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, info.getResult()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); } - @Test(enabled = true, description = "TSTORE will also REVERT if called during a STATICCALL", groups = {"contract", "daily"}) + + @Test( + enabled = true, + description = "TSTORE will also REVERT if called during a STATICCALL", + groups = {"contract", "daily"}) public void test06StaticcallTstore() { String args = "\"" + base58ContractA + "\""; - String txid = PublicMethod.triggerContract(contractB, - "staticcallTstore(address)", args, - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractB, + "staticcallTstore(address)", + args, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, info.getResult()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/ConstantCallStorage001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/ConstantCallStorage001.java index 7626b0a5..d2274aee 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/ConstantCallStorage001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/ConstantCallStorage001.java @@ -5,10 +5,8 @@ import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.HashMap; -import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.AccountResourceMessage; @@ -19,17 +17,18 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ConstantCallStorage001 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,131 +36,202 @@ public class ConstantCallStorage001 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = false) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerconstantContract trigger modidy storage date", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerconstantContract trigger modidy storage date", + groups = {"contract", "daily"}) public void testConstantCallStorage001() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/constantCallStorage001.sol"; - String contractName = "NotView"; + String filePath = "src/test/resources/soliditycode/constantCallStorage001.sol"; + String contractName = "NotView"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, "[]", code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + "[]", + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); - //Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + // Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "setnum()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "setnum()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention: " + transactionExtention); Assert.assertTrue(transactionExtention.getResult().getResult()); - Assert.assertEquals(138, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + 138, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); logger.info("transactionExtention: " + transactionExtention); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "num()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "num()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertTrue(transactionExtention.getResult().getResult()); - Assert.assertEquals(123, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + 123, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); } - @Test(enabled = false, description = "TriggerconstantContract storage date by another contract ", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerconstantContract storage date by another contract ", + groups = {"contract", "daily"}) public void testConstantCallStorage002() { String filePath = "src/test/resources/soliditycode/constantCallStorage001.sol"; - String contractName = "UseNotView"; + String contractName = "UseNotView"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] contractAddress002 = PublicMethod - .deployContract(contractName, "[]", code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress002 = + PublicMethod.deployContract( + contractName, + "[]", + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress002, blockingStubFull); - //Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + // Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress002, - "setnumuseproxy(address)", "\"" + WalletClient.encode58Check(contractAddress) + "\"", + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress002, + "setnumuseproxy(address)", + "\"" + WalletClient.encode58Check(contractAddress) + "\"", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention: " + transactionExtention); - Assert.assertEquals(138, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + 138, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "num()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "num()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertTrue(transactionExtention.getResult().getResult()); - Assert.assertEquals(123, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - + Assert.assertEquals( + 123, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); } - - @Test(enabled = false, description = "TriggerconstantContract storage date by another contract " - + "view function, use 0.5.* version solidity complier", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = + "TriggerconstantContract storage date by another contract " + + "view function, use 0.5.* version solidity complier", + groups = {"contract", "daily"}) public void testConstantCallStorage003() { String filePath = "src/test/resources/soliditycode/constantCallStorage002.sol"; - String contractName = "UseNotView"; + String contractName = "UseNotView"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] contractAddress002 = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress002 = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress002, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); @@ -169,29 +239,51 @@ public void testConstantCallStorage003() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress002, - "setnumuseproxy(address)", "\"" + WalletClient.encode58Check(contractAddress) + "\"", + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress002, + "setnumuseproxy(address)", + "\"" + WalletClient.encode58Check(contractAddress) + "\"", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention: " + transactionExtention); Assert.assertFalse(transactionExtention.getResult().getResult()); - Assert.assertThat(ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray()), + Assert.assertThat( + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray()), containsString("Not enough energy")); } - - @Test(enabled = false, description = "TriggerconstantContract storage date by another contract " - + "view function, use 0.4.* version solidity complier", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = + "TriggerconstantContract storage date by another contract " + + "view function, use 0.4.* version solidity complier", + groups = {"contract", "daily"}) public void testConstantCallStorage004() { String filePath = "src/test/resources/soliditycode/constantCallStorage002.sol"; - String contractName = "UseNotView"; + String contractName = "UseNotView"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] contractAddress002 = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress002 = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress002, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); @@ -199,27 +291,40 @@ public void testConstantCallStorage004() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress002, - "setnumuseproxy(address)", "\"" + WalletClient.encode58Check(contractAddress) + "\"", + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress002, + "setnumuseproxy(address)", + "\"" + WalletClient.encode58Check(contractAddress) + "\"", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention: " + transactionExtention); - Assert.assertEquals(138, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + 138, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "num()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "num()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertTrue(transactionExtention.getResult().getResult()); - Assert.assertEquals(123, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + 123, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); } - /** - * constructor. - */ - - + /** constructor. */ } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/ConstantCallStorage002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/ConstantCallStorage002.java index b8997130..b3b9d607 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/ConstantCallStorage002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/ConstantCallStorage002.java @@ -3,10 +3,8 @@ import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.HashMap; -import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.AccountResourceMessage; @@ -18,17 +16,18 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ConstantCallStorage002 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -36,237 +35,393 @@ public class ConstantCallStorage002 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = false) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerconstantContract trigger modidy storage date with " - + "difference date type", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = + "TriggerconstantContract trigger modidy storage date with " + "difference date type", + groups = {"contract", "daily"}) public void testConstantCallStorage001() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/constantCallStorage001.sol"; - String contractName = "viewCall"; + String filePath = "src/test/resources/soliditycode/constantCallStorage001.sol"; + String contractName = "viewCall"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, "[]", code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + "[]", + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - // modify bool type - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "changeBool(bool)", "true", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals(1, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + // modify bool type + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "changeBool(bool)", + "true", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + 1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "getBool()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals(0, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - // modify NegativeInt type - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "changeNegativeInt(int256)", "-2", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals(-2, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getBool()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + 0, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + // modify NegativeInt type + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "changeNegativeInt(int256)", + "-2", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + -2, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "getNegativeInt()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals(-32482989, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - // modify address type - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "changeAddress(address)", "\"" + WalletClient.encode58Check(contractAddress) + "\"", + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getNegativeInt()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + -32482989, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + // modify address type + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "changeAddress(address)", + "\"" + WalletClient.encode58Check(contractAddress) + "\"", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - String ContractResult = + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + String ContractResult = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); - String tmpAddress = + String tmpAddress = Base58.encode58Check(ByteArray.fromHexString("41" + ContractResult.substring(24))); Assert.assertEquals(WalletClient.encode58Check(contractAddress), tmpAddress); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "getAddress()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("000000000000000000000000dcad3a6d3569df655070ded06cb7a1b2ccd1d3af", + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getAddress()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "000000000000000000000000dcad3a6d3569df655070ded06cb7a1b2ccd1d3af", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - // modify byte32s type - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "changeBytes32(bytes32)", "\"0xdCad3a6d3569DF655070DEd1\"", + // modify byte32s type + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "changeBytes32(bytes32)", + "\"0xdCad3a6d3569DF655070DEd1\"", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("dcad3a6d3569df655070ded10000000000000000000000000000000000000000", + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "dcad3a6d3569df655070ded10000000000000000000000000000000000000000", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "getBytes32()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("0000000000000000000000000000000000000000dcad3a6d3569df655070ded0", + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getBytes32()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "0000000000000000000000000000000000000000dcad3a6d3569df655070ded0", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - // modify bytes type - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "changeBytes(bytes)", "\"0x05\"", + // modify bytes type + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "changeBytes(bytes)", + "\"0x05\"", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000020" + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000020" + "0000000000000000000000000000000000000000000000000000000000000001" + "0500000000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "getBytes()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000020" + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getBytes()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000020" + "0000000000000000000000000000000000000000000000000000000000000003" + "0000000000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - // modify string type - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "changeString(string)", "\"321test\"", + // modify string type + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "changeString(string)", + "\"321test\"", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("321test", - ByteArray.toStr(transactionExtention - .getConstantResult(0).substring(64, 64 + 7).toByteArray())); + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "321test", + ByteArray.toStr( + transactionExtention.getConstantResult(0).substring(64, 64 + 7).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "getString()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("123qwe", - ByteArray.toStr(transactionExtention - .getConstantResult(0).substring(64, 64 + 6).toByteArray())); - // modify enum type - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "changeActionChoices(uint8)", "3", + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getString()", + "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals(3, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "123qwe", + ByteArray.toStr( + transactionExtention.getConstantResult(0).substring(64, 64 + 6).toByteArray())); + // modify enum type + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "changeActionChoices(uint8)", + "3", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + 3, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "getActionChoices()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals(1, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - // modify Int64NegativeArray type - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getActionChoices()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + 1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + // modify Int64NegativeArray type + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, "changeInt64NegativeArray(int64[])", "0000000000000000000000000000000000000000000000000000000000000020" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000003" + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", true, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000020" + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000020" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000003" + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - ByteArray.toHexString(transactionExtention - .getConstantResult(0).toByteArray())); + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "getInt64NegativeArray()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000020" + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getInt64NegativeArray()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000020" + "0000000000000000000000000000000000000000000000000000000000000003" + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + "0000000000000000000000000000000000000000000000000000000000000002" + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd", - ByteArray.toHexString(transactionExtention - .getConstantResult(0).toByteArray())); - // modify Int32Array[2][] type - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); + // modify Int32Array[2][] type + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, "changeInt32Array(int32[2][])", "0000000000000000000000000000000000000000000000000000000000000020" + "0000000000000000000000000000000000000000000000000000000000000005" @@ -281,10 +436,17 @@ public void testConstantCallStorage001() { + "0000000000000000000000000000000000000000000000000000000000000009" + "000000000000000000000000000000000000000000000000000000000000000a", true, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000020" + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000020" + "0000000000000000000000000000000000000000000000000000000000000005" + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000002" @@ -296,16 +458,25 @@ public void testConstantCallStorage001() { + "0000000000000000000000000000000000000000000000000000000000000008" + "0000000000000000000000000000000000000000000000000000000000000009" + "000000000000000000000000000000000000000000000000000000000000000a", - ByteArray.toHexString(transactionExtention - .getConstantResult(0).toByteArray())); + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "getInt32Array()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000020" + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getInt32Array()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000020" + "0000000000000000000000000000000000000000000000000000000000000003" + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000002" @@ -313,67 +484,91 @@ public void testConstantCallStorage001() { + "0000000000000000000000000000000000000000000000000000000000000004" + "0000000000000000000000000000000000000000000000000000000000000005" + "0000000000000000000000000000000000000000000000000000000000000006", - ByteArray.toHexString(transactionExtention - .getConstantResult(0).toByteArray())); - // modify Int256Array[2][2] type - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); + // modify Int256Array[2][2] type + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, "changeInt256Array(int256[2][2])", - "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000003" + "0000000000000000000000000000000000000000000000000000000000000004", true, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000001" + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000003" + "0000000000000000000000000000000000000000000000000000000000000004", - ByteArray.toHexString(transactionExtention - .getConstantResult(0).toByteArray())); + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "getInt256Array()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getInt256Array()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals( "000000000000000000000000000000000000000000000000000000000000000b" + "0000000000000000000000000000000000000000000000000000000000000016" + "0000000000000000000000000000000000000000000000000000000000000021" + "000000000000000000000000000000000000000000000000000000000000002c", - ByteArray.toHexString(transactionExtention - .getConstantResult(0).toByteArray())); - // modify mapping type - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "setMapping(uint256)", "55", + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); + // modify mapping type + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "setMapping(uint256)", + "55", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals(55, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "mapa(address)", "\"T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb\"", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals(34, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + 55, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "mapa(address)", + "\"T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb\"", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + 34, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); } - - /** - * constructor. - */ - - + /** constructor. */ } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/ConstantCallStorage0425.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/ConstantCallStorage0425.java index 9a33b4c5..2a30c3ef 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/ConstantCallStorage0425.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/ConstantCallStorage0425.java @@ -16,59 +16,81 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class ConstantCallStorage0425 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] contractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = false) - public void beforeClass() { PublicMethod.printAddress(dev001Key); - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 1000_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 100_000_000L, - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1000_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 100_000_000L, + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = false, description = "Deploy contract without abi", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Deploy contract without abi", + groups = {"contract", "daily"}) public void test01DeployContract() { - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(dev001Key, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = accountResource.getEnergyUsed(); - Long beforeNetUsed = accountResource.getNetUsed(); - Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = accountResource.getEnergyUsed(); + Long beforeNetUsed = accountResource.getNetUsed(); + Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String filePath = "./src/test/resources/soliditycode/constantCallStorage0425.sol"; - String contractName = "constantCall"; + String filePath = "./src/test/resources/soliditycode/constantCallStorage0425.sol"; + String contractName = "constantCall"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, "[]", code, "", - maxFeeLimit, 0L, 0, 1000000000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + "[]", + code, + "", + maxFeeLimit, + 0L, + 0, + 1000000000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -83,13 +105,12 @@ public void test01DeployContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -98,13 +119,12 @@ public void test01DeployContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(dev001Key, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(dev001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -116,227 +136,442 @@ public void test01DeployContract() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = false, description = "Trigger contract constant function without ABI", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Trigger contract constant function without ABI", + groups = {"contract", "daily"}) public void test02TriggerContract() { - String triggerTxid = PublicMethod - .triggerContract(contractAddress, "changeBool(bool)", "true", false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + contractAddress, + "changeBool(bool)", + "true", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals(1, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(1, ByteArray.toInt(infoById.get().getLog(0).getData().toByteArray())); - String triggerTxid2 = PublicMethod - .triggerContract(contractAddress, "getBool()", "", false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String triggerTxid2 = + PublicMethod.triggerContract( + contractAddress, + "getBool()", + "", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById1 = PublicMethod - .getTransactionInfoById(triggerTxid2, blockingStubFull); + Optional infoById1 = + PublicMethod.getTransactionInfoById(triggerTxid2, blockingStubFull); Assert.assertEquals(0, infoById1.get().getResultValue()); Assert.assertEquals(1, ByteArray.toInt(infoById1.get().getContractResult(0).toByteArray())); Assert.assertEquals(1, ByteArray.toInt(infoById1.get().getLog(0).getData().toByteArray())); } - @Test(enabled = false, description = "TriggerConstantContract bool constant function", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerConstantContract bool constant function", + groups = {"contract", "daily"}) public void test03TriggerConstantContract() { // bool - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "changeBool(bool)", "false", false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert - .assertEquals(0, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "getBool()", "", false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert - .assertEquals(1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - // int - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "changeInt(int256)", "30", false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert - .assertEquals(30, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "getInt()", "", false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals(32482989, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - // negative int - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "changeNegativeInt(int256)", "-111", - false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert - .assertEquals(-111, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "getNegativeInt()", "", false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert - .assertEquals(-32482989, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - // uint - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "changeUint(uint256)", "1024", false, - 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert - .assertEquals(1024, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "getUint()", "", false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert - .assertEquals(23487823, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - // address + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "changeBool(bool)", + "false", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + 0, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getBool()", + "", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + 1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + // int + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "changeInt(int256)", + "30", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + 30, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getInt()", + "", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + 32482989, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + // negative int + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "changeNegativeInt(int256)", + "-111", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + -111, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getNegativeInt()", + "", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + -32482989, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + // uint + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "changeUint(uint256)", + "1024", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + 1024, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getUint()", + "", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + 23487823, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + // address String param = "\"" + Base58.encode58Check(dev001Address) + "\""; - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "changeAddress(address)", param, - false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - byte[] tmpAddress = new byte[20]; - System - .arraycopy(transactionExtention.getConstantResult(0).toByteArray(), 12, tmpAddress, 0, 20); - Assert.assertEquals(Base58.encode58Check(dev001Address), + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "changeAddress(address)", + param, + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + byte[] tmpAddress = new byte[20]; + System.arraycopy( + transactionExtention.getConstantResult(0).toByteArray(), 12, tmpAddress, 0, 20); + Assert.assertEquals( + Base58.encode58Check(dev001Address), Base58.encode58Check(ByteArray.fromHexString("41" + ByteArray.toHexString(tmpAddress)))); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "getAddress()", "", false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getAddress()", + "", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); tmpAddress = new byte[20]; - System - .arraycopy(transactionExtention.getConstantResult(0).toByteArray(), 12, tmpAddress, 0, 20); - Assert.assertEquals("TW63BNR5M7LuH1fjXS7Smyza3PZXfHAAs2", + System.arraycopy( + transactionExtention.getConstantResult(0).toByteArray(), 12, tmpAddress, 0, 20); + Assert.assertEquals( + "TW63BNR5M7LuH1fjXS7Smyza3PZXfHAAs2", Base58.encode58Check(ByteArray.fromHexString("41" + ByteArray.toHexString(tmpAddress)))); - // bytes32 - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "changeBytes32(bytes32)", + // bytes32 + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "changeBytes32(bytes32)", "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a", - true, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a", + true, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "getBytes32()", "", false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105c", + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getBytes32()", + "", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105c", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - // bytes - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "changeBytes(bytes)", "\"0x06\"", + // bytes + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "changeBytes(bytes)", + "\"0x06\"", false, - 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals( "0000000000000000000000000000000000000000000000000000000000000020000000000000000000" + "000000000000000000000000000000000000000000000106000000000000000000000000000000000000" + "00000000000000000000000000", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "getBytes()", "", false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getBytes()", + "", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals( "0000000000000000000000000000000000000000000000000000000000000020000000000000000000" + "000000000000000000000000000000000000000000000900000000000000000000000000000000000000" + "00000000000000000000000000", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - // string - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "changeString(string)", + // string + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "changeString(string)", "\"1q2w\"", - false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("000000000000000000000000000000000000000000000000000000000000002000" + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "000000000000000000000000000000000000000000000000000000000000002000" + "000000000000000000000000000000000000000000000000000000000000043171327700000000000000" + "000000000000000000000000000000000000000000", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "getString()", "", false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("000000000000000000000000000000000000000000000000000000000000002000" + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getString()", + "", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "000000000000000000000000000000000000000000000000000000000000002000" + "000000000000000000000000000000000000000000000000000000000000063132337177650000000000" + "000000000000000000000000000000000000000000", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - // enum - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "changeActionChoices(uint8)", + // enum + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "changeActionChoices(uint8)", "1", - false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000001", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000001", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "getActionChoices()", "", false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000003", + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getActionChoices()", + "", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000003", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - // int64[] include negative number - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "changeInt64NegativeArray(int64[])", + // int64[] include negative number + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "changeInt64NegativeArray(int64[])", "0000000000000000000000000000000000000000000000000000000000000020000000000000000" + "00000000000000000000000000000000000000000000000040000000000000000000000000000000" + "00000000000000000000000000000000b00000000000000000000000000000000000000000000000" + "00000000000000063000000000000000000000000000000000000000000000000000000000000004" + "1000000000000000000000000000000000000000000000000000000000000005a", - true, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("000000000000000000000000000000000000000000000000000000000000002000" + true, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "000000000000000000000000000000000000000000000000000000000000002000" + "000000000000000000000000000000000000000000000000000000000000040000000000000000000000" + "00000000000000000000000000000000000000000b000000000000000000000000000000000000000000" + "000000000000000000006300000000000000000000000000000000000000000000000000000000000000" + "41000000000000000000000000000000000000000000000000000000000000005a", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "getInt64NegativeArray()", "", false, + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getInt64NegativeArray()", + "", + false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("000000000000000000000000000000000000000000000000000000000000002000" + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "000000000000000000000000000000000000000000000000000000000000002000" + "000000000000000000000000000000000000000000000000000000000000030000000000000000000000" + "00000000000000000000000000000000000000005b000000000000000000000000000000000000000000" + "000000000000000000000200000000000000000000000000000000000000000000000000000000000001" + "4d", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - // int32[2][] + // int32[2][] String argsStr = "0000000000000000000000000000000000000000000000000000000000000020000000000000000" + "00000000000000000000000000000000000000000000000030000000000000000000000000000000" @@ -345,20 +580,40 @@ public void test03TriggerConstantContract() { + "70000000000000000000000000000000000000000000000000000000000000022000000000000000" + "0000000000000000000000000000000000000000000000063fffffffffffffffffffffffffffffff" + "fffffffffffffffffffffffffffffffc8"; - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "changeInt32Array(int32[2][])", - argsStr, true, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals(argsStr, - ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "getInt32Array()", "", false, + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "changeInt32Array(int32[2][])", + argsStr, + true, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + argsStr, ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getInt32Array()", + "", + false, + 0, + 0, + "0", 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("000000000000000000000000000000000000000000000000000000000000002000" + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "000000000000000000000000000000000000000000000000000000000000002000" + "000000000000000000000000000000000000000000000000000000000000030000000000000000000000" + "000000000000000000000000000000000000000001000000000000000000000000000000000000000000" + "000000000000000000000200000000000000000000000000000000000000000000000000000000000000" @@ -366,54 +621,91 @@ public void test03TriggerConstantContract() { + "000000000000000000000000000000000000000000000500000000000000000000000000000000000000" + "00000000000000000000000006", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - // int256[2][2] + // int256[2][2] String argsStr1 = "0000000000000000000000000000000000000000000000000000000000000013000000000000000" + "00000000000000000000000000000000000000000000000440000000000000000000000000000000" + "000000000000000000000000000000037fffffffffffffffffffffffffffffffffffffffffffffff" + "fffffffffffffffde"; - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "changeInt256Array(int256[2][2])", - argsStr1, true, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals(argsStr1, - ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "getInt256Array()", "", false, + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "changeInt256Array(int256[2][2])", + argsStr1, + true, + 0, + 0, + "0", 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("000000000000000000000000000000000000000000000000000000000000000b00" + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + argsStr1, ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getInt256Array()", + "", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "000000000000000000000000000000000000000000000000000000000000000b00" + "000000000000000000000000000000000000000000000000000000000000160000000000000000000000" + "000000000000000000000000000000000000000021000000000000000000000000000000000000000000" + "000000000000000000002c", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - // modify mapping type - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "setMapping(uint256)", "39", + // modify mapping type + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "setMapping(uint256)", + "39", false, - 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals(39, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + 39, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "mapa(address)", "\"T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb\"", false, - 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals(88, - ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "mapa(address)", + "\"T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb\"", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + 88, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); } @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, - blockingStubFull); } -} \ No newline at end of file + PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, blockingStubFull); + } +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/EnergyAdjustmentTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/EnergyAdjustmentTest.java index 590c1491..7d3efc3c 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/EnergyAdjustmentTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/EnergyAdjustmentTest.java @@ -1,5 +1,6 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.newGrammar; +import java.util.HashMap; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.testng.annotations.AfterClass; @@ -12,18 +13,20 @@ import org.tron.protos.Protocol.TransactionInfo.code; import org.tron.protos.contract.SmartContractOuterClass; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; - -import java.util.HashMap; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; - +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class EnergyAdjustmentTest extends TronBaseTest { - private String testFoundationKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); - private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); + private String testFoundationKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); + private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey1.getAddress(); String testKey001 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private byte[] contractAddressC; @@ -34,38 +37,59 @@ public class EnergyAdjustmentTest extends TronBaseTest { long trxValue = 100L; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(testKey001); - PublicMethod.printAddress(testKey002); Assert.assertTrue(PublicMethod.sendcoin(testAddress001, 100000_000000L, - testFoundationAddress, testFoundationKey, blockingStubFull)); + PublicMethod.printAddress(testKey002); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress001, + 100000_000000L, + testFoundationAddress, + testFoundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/energyAdjustment.sol"; - String contractName = "C"; + String filePath = "src/test/resources/soliditycode/energyAdjustment.sol"; + String contractName = "C"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddressC = PublicMethod - .deployContractFallback(contractName, abi, code, "", maxFeeLimit, trxValue, - 100, null, testKey001, - testAddress001, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddressC = + PublicMethod.deployContractFallback( + contractName, + abi, + code, + "", + maxFeeLimit, + trxValue, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); contractName = "D"; retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - contractAddressD = PublicMethod - .deployContractFallback(contractName, abi, code, "", maxFeeLimit, 0L, - 100, null, testKey001, - testAddress001, blockingStubFull); + contractAddressD = + PublicMethod.deployContractFallback( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod - .getContract(contractAddressC, blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(contractAddressC, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); smartContract = PublicMethod.getContract(contractAddressD, blockingStubFull); @@ -73,14 +97,28 @@ public void beforeClass() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); } - @Test(enabled = true, description = "before committe no.81,memory extend does not cost fee," - + " offset too big will result in cpu time out. after committe no.81, offset too big will result in out of memory," - + " and offset le 3145696 will cost memory extend fee.", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "before committe no.81,memory extend does not cost fee," + + " offset too big will result in cpu time out. after committe no.81, offset too big " + + "will result in out of memory," + + " and offset le 3145696 will cost memory extend fee.", + groups = {"contract", "daily"}) void voteCostExtraEnergy01() { String methedStr = "test(int256,int256)"; - String argsStr = "0,3145697"; - String txid = PublicMethod.triggerContract(contractAddressD, methedStr, argsStr, - false, 0, 15000000000L, testFoundationAddress, testFoundationKey, blockingStubFull); + String argsStr = "0,3145697"; + String txid = + PublicMethod.triggerContract( + contractAddressD, + methedStr, + argsStr, + false, + 0, + 15000000000L, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("voteCostExtraEnergy01 txid: " + txid); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); @@ -89,15 +127,28 @@ void voteCostExtraEnergy01() { Assert.assertEquals(contractResult.OUT_OF_MEMORY, info.getReceipt().getResult()); } - @Test(enabled = true, description = "before committe no.81,memory extend does not cost fee," - + " offset too big will result in cpu time out. after committe no.81, " - + "offset gt 3145696 will result in out of memory," - + " and offset smaller than 3145696 will cost memory extend fee.", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "before committe no.81,memory extend does not cost fee," + + " offset too big will result in cpu time out. after committe no.81, " + + "offset gt 3145696 will result in out of memory," + + " and offset smaller than 3145696 will cost memory extend fee.", + groups = {"contract", "daily"}) void voteCostExtraEnergy02() { String methedStr = "test(int256,int256)"; - String argsStr = "0,3145696"; - String txid = PublicMethod.triggerContract(contractAddressD, methedStr, argsStr, - false, 0, 15000000000L, testFoundationAddress, testFoundationKey, blockingStubFull); + String argsStr = "0,3145696"; + String txid = + PublicMethod.triggerContract( + contractAddressD, + methedStr, + argsStr, + false, + 0, + 15000000000L, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("voteCostExtraEnergy02 txid: " + txid); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); @@ -105,234 +156,331 @@ void voteCostExtraEnergy02() { long energyUsageTotal = info.getReceipt().getEnergyUsageTotal(); Assert.assertTrue(energyUsageTotal > 31000); Assert.assertEquals(19199554, energyUsageTotal); - } - @Test(enabled = true, description = "sucide to active one account, active 1 account cost 25000 energy extra", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "sucide to active one account, active 1 account cost 25000 energy extra", + groups = {"contract", "daily"}) void suicideToActiveAccount01() { String methedStr = "killme(address)"; - String argsStr = "\"" + Base58.encode58Check(testAddress002) + "\""; - String txid = PublicMethod.triggerContract(contractAddressC, methedStr, argsStr, - false, 0, maxFeeLimit, testFoundationAddress, testFoundationKey, blockingStubFull); + String argsStr = "\"" + Base58.encode58Check(testAddress002) + "\""; + String txid = + PublicMethod.triggerContract( + contractAddressC, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("suicideToActiveAccount01 txid: " + txid); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("voteCostExtraEnergy02 info: " + info.toString()); Assert.assertEquals(code.SUCESS, info.getResult()); Assert.assertEquals(contractResult.SUCCESS, info.getReceipt().getResult()); - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { Assert.assertEquals(30319, info.getReceipt().getEnergyUsageTotal()); - }else { + } else { Assert.assertEquals(25319, info.getReceipt().getEnergyUsageTotal()); } Protocol.Account contractC = PublicMethod.queryAccount(contractAddressC, blockingStubFull); System.out.println("contractC ccc: " + contractC); - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { Assert.assertNotEquals("", contractC.toString()); Assert.assertEquals(0L, contractC.getBalance()); Assert.assertEquals(0L, contractC.getFrozenV2(0).getAmount()); Assert.assertEquals(0L, contractC.getFrozenV2(1).getAmount()); Assert.assertEquals(0L, contractC.getFrozenV2(2).getAmount()); - }else { + } else { Assert.assertEquals("", contractC.toString()); } long balance = PublicMethod.queryAccount(testAddress002, blockingStubFull).getBalance(); Assert.assertEquals(trxValue, balance); } - @Test(enabled = true, description = "call sucide twice to active the same account", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "call sucide twice to active the same account", + groups = {"contract", "daily"}) void suicideToActiveAccount02() { deployContractC(); - ECKey ecKey3 = new ECKey(Utils.getRandom()); - byte[] testAddress003 = ecKey3.getAddress(); - String testKey003 = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); + ECKey ecKey3 = new ECKey(Utils.getRandom()); + byte[] testAddress003 = ecKey3.getAddress(); + String testKey003 = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); PublicMethod.printAddress(testKey003); - String methedStr = "testKill(address,address,address)"; - String argsStr = "\"" + Base58.encode58Check(contractAddressC) + "\",\"" + Base58.encode58Check(testAddress003) - + "\",\"" + Base58.encode58Check(testAddress003)+"\""; - String txid = PublicMethod.triggerContract(contractAddressD, methedStr, argsStr, - false, 0, maxFeeLimit, testFoundationAddress, testFoundationKey, blockingStubFull); + String methedStr = "testKill(address,address,address)"; + String argsStr = + "\"" + + Base58.encode58Check(contractAddressC) + + "\",\"" + + Base58.encode58Check(testAddress003) + + "\",\"" + + Base58.encode58Check(testAddress003) + + "\""; + String txid = + PublicMethod.triggerContract( + contractAddressD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("suicideToActiveAccount02 txid: " + txid); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("suicideToActiveAccount02 info: " + info.toString()); Assert.assertEquals(code.SUCESS, info.getResult()); Assert.assertEquals(contractResult.SUCCESS, info.getReceipt().getResult()); - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { Assert.assertEquals(36992, info.getReceipt().getEnergyUsageTotal()); - }else { + } else { Assert.assertEquals(26993, info.getReceipt().getEnergyUsageTotal()); } String contractC = PublicMethod.queryAccount(contractAddressC, blockingStubFull).toString(); System.out.println("contractC ccc: " + contractC); - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { Assert.assertNotEquals("", contractC); - }else { + } else { Assert.assertEquals("", contractC); } long balance = PublicMethod.queryAccount(testAddress003, blockingStubFull).getBalance(); Assert.assertEquals(trxValue, balance); - } - @Test(enabled = true, description = "call sucide twice to active two different accounts," - + " active 1 account cost 25000 energy extra", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "call sucide twice to active two different accounts," + + " active 1 account cost 25000 energy extra", + groups = {"contract", "daily"}) void suicideToActiveAccount03() { deployContractC(); - ECKey ecKey3 = new ECKey(Utils.getRandom()); - byte[] testAddress003 = ecKey3.getAddress(); - String testKey003 = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - ECKey ecKey4 = new ECKey(Utils.getRandom()); - byte[] testAddress004 = ecKey4.getAddress(); - String testKey004 = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); + ECKey ecKey3 = new ECKey(Utils.getRandom()); + byte[] testAddress003 = ecKey3.getAddress(); + String testKey003 = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); + ECKey ecKey4 = new ECKey(Utils.getRandom()); + byte[] testAddress004 = ecKey4.getAddress(); + String testKey004 = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); PublicMethod.printAddress(testKey003); PublicMethod.printAddress(testKey004); - String methedStr = "testKill(address,address,address)"; - String argsStr = "\"" + Base58.encode58Check(contractAddressC) + "\",\"" + Base58.encode58Check(testAddress003) - + "\",\"" + Base58.encode58Check(testAddress004)+"\""; - String txid = PublicMethod.triggerContract(contractAddressD, methedStr, argsStr, - false, 0, maxFeeLimit, testFoundationAddress, testFoundationKey, blockingStubFull); + String methedStr = "testKill(address,address,address)"; + String argsStr = + "\"" + + Base58.encode58Check(contractAddressC) + + "\",\"" + + Base58.encode58Check(testAddress003) + + "\",\"" + + Base58.encode58Check(testAddress004) + + "\""; + String txid = + PublicMethod.triggerContract( + contractAddressD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("suicideToActiveAccount03 txid: " + txid); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("suicideToActiveAccount03 info: " + info.toString()); Assert.assertEquals(code.SUCESS, info.getResult()); Assert.assertEquals(contractResult.SUCCESS, info.getReceipt().getResult()); - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { Assert.assertEquals(61992, info.getReceipt().getEnergyUsageTotal()); - }else { + } else { Assert.assertEquals(51993, info.getReceipt().getEnergyUsageTotal()); } String contractC = PublicMethod.queryAccount(contractAddressC, blockingStubFull).toString(); System.out.println("contractC ccc: " + contractC); - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { Assert.assertNotEquals("", contractC); - }else { + } else { Assert.assertEquals("", contractC); } long balance03 = PublicMethod.queryAccount(testAddress003, blockingStubFull).getBalance(); Assert.assertEquals(trxValue, balance03); long balance04 = PublicMethod.queryAccount(testAddress004, blockingStubFull).getBalance(); Assert.assertEquals(0, balance04); - } - @Test(enabled = true, description = "sucide: receiver account only the last char is different with the contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "sucide: receiver account only the last char is different with the contract", + groups = {"contract", "daily"}) void suicideToActiveAccount04() { deployContractC(); - String hex41 = ByteArray.toHexString(contractAddressC); - int len = hex41.length(); - int c = hex41.charAt(len - 1) - '0'; - int last = c % 9 + 1; - String sub = hex41.substring(0,len - 1) + last; + String hex41 = ByteArray.toHexString(contractAddressC); + int len = hex41.length(); + int c = hex41.charAt(len - 1) - '0'; + int last = c % 9 + 1; + String sub = hex41.substring(0, len - 1) + last; logger.info("hex41: " + hex41); logger.info("sub: " + sub); - String methedStr = "killme(address)"; - String argsStr = "\"" + Base58.encode58Check(ByteArray.fromHexString(sub)) + "\""; - String txid = PublicMethod.triggerContract(contractAddressC, methedStr, argsStr, - false, 0, maxFeeLimit, testFoundationAddress, testFoundationKey, blockingStubFull); + String methedStr = "killme(address)"; + String argsStr = "\"" + Base58.encode58Check(ByteArray.fromHexString(sub)) + "\""; + String txid = + PublicMethod.triggerContract( + contractAddressC, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("suicideToActiveAccount04 txid: " + txid); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("suicideToActiveAccount04 info: " + info.toString()); Assert.assertEquals(code.SUCESS, info.getResult()); Assert.assertEquals(contractResult.SUCCESS, info.getReceipt().getResult()); - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { Assert.assertEquals(30319, info.getReceipt().getEnergyUsageTotal()); - }else { + } else { Assert.assertEquals(25319, info.getReceipt().getEnergyUsageTotal()); } String contractC = PublicMethod.queryAccount(contractAddressC, blockingStubFull).toString(); System.out.println("contractC ccc: " + contractC); - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { Assert.assertNotEquals("", contractC); - }else { + } else { Assert.assertEquals("", contractC); } - long balance = PublicMethod.queryAccount(ByteArray.fromHexString(sub), blockingStubFull).getBalance(); + long balance = + PublicMethod.queryAccount(ByteArray.fromHexString(sub), blockingStubFull).getBalance(); Assert.assertEquals(trxValue, balance); - } - @Test(enabled = true, description = "create2 address sucide to active one account", groups = {"contract", "daily"}) + + @Test( + enabled = true, + description = "create2 address sucide to active one account", + groups = {"contract", "daily"}) void suicideToActiveAccount05() { ECKey ecKey3 = new ECKey(Utils.getRandom()); - byte[] testAddress003 = ecKey3.getAddress(); - String testKey003 = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); + byte[] testAddress003 = ecKey3.getAddress(); + String testKey003 = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); PublicMethod.printAddress(testKey003); - byte[] create2Add = create2NewFreezeContract(); - String methedStr = "killme(address)"; - String argsStr = "\"" + Base58.encode58Check(testAddress003) + "\""; - String txid = PublicMethod.triggerContract(create2Add, methedStr, argsStr, - false, 0, maxFeeLimit, testFoundationAddress, testFoundationKey, blockingStubFull); + byte[] create2Add = create2NewFreezeContract(); + String methedStr = "killme(address)"; + String argsStr = "\"" + Base58.encode58Check(testAddress003) + "\""; + String txid = + PublicMethod.triggerContract( + create2Add, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("suicideToActiveAccount05 txid: " + txid); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("suicideToActiveAccount05 info: " + info.toString()); Assert.assertEquals(code.SUCESS, info.getResult()); Assert.assertEquals(contractResult.SUCCESS, info.getReceipt().getResult()); - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { Assert.assertEquals(30319, info.getReceipt().getEnergyUsageTotal()); - }else { + } else { Assert.assertEquals(25319, info.getReceipt().getEnergyUsageTotal()); } String contractC = PublicMethod.queryAccount(create2Add, blockingStubFull).toString(); System.out.println("contractC ccc: " + contractC); - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { Assert.assertNotEquals("", contractC); - }else { + } else { Assert.assertEquals("", contractC); } long balance = PublicMethod.queryAccount(testAddress003, blockingStubFull).getBalance(); Assert.assertEquals(trxValue, balance); - } - void deployContractC(){ + void deployContractC() { String filePath = "src/test/resources/soliditycode/energyAdjustment.sol"; - String contractName = "C"; + String contractName = "C"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddressC = PublicMethod - .deployContractFallback(contractName, abi, code, "", maxFeeLimit, trxValue, - 100, null, testKey001, - testAddress001, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddressC = + PublicMethod.deployContractFallback( + contractName, + abi, + code, + "", + maxFeeLimit, + trxValue, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod - .getContract(contractAddressC, blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(contractAddressC, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); } - byte[] create2NewFreezeContract() { + byte[] create2NewFreezeContract() { String methedStr = "getPredictedAddress(bytes32)"; - String argsStr = "1232"; + String argsStr = "1232"; GrpcAPI.TransactionExtention transactionExtention = - PublicMethod.triggerConstantContractForExtention(contractAddressD, methedStr, argsStr, - false, 0, maxFeeLimit, "0", 0, testFoundationAddress, testFoundationKey, blockingStubFull); + PublicMethod.triggerConstantContractForExtention( + contractAddressD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "0", + 0, + testFoundationAddress, + testFoundationKey, + blockingStubFull); logger.info("getPredictedAddress transactionExtention: " + transactionExtention.toString()); - String create2Add41 = "41" + ByteArray.toHexString(transactionExtention.getConstantResult(0) - .toByteArray()).substring(24); - byte[] create2AddBytes = ByteArray.fromHexString(create2Add41); - String create2Add58 = Base58.encode58Check(create2AddBytes); - PublicMethod.sendcoin(create2AddBytes, trxValue, testFoundationAddress, testFoundationKey, blockingStubFull); + String create2Add41 = + "41" + + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()) + .substring(24); + byte[] create2AddBytes = ByteArray.fromHexString(create2Add41); + String create2Add58 = Base58.encode58Check(create2AddBytes); + PublicMethod.sendcoin( + create2AddBytes, trxValue, testFoundationAddress, testFoundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); methedStr = "createDSalted(bytes32)"; - PublicMethod.triggerContract(contractAddressD, methedStr, argsStr, - false, 0, maxFeeLimit, testFoundationAddress, testFoundationKey, blockingStubFull); + PublicMethod.triggerContract( + contractAddressD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(create2AddBytes, blockingStubFull); -// Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(create2AddBytes, blockingStubFull); + // Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); return create2AddBytes; } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - - + public void shutdown() throws InterruptedException {} } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/EthGrammar.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/EthGrammar.java index b0a20822..d859c496 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/EthGrammar.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/EthGrammar.java @@ -15,14 +15,14 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class EthGrammar extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); private final byte[] witness001Address = PublicMethod.getFinalAddress(witnessKey); byte[] contractC = null; @@ -32,27 +32,40 @@ public class EthGrammar extends TronBaseTest { ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 300100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 300100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/EthGrammar.sol"; - String contractName = "C"; + String filePath = "src/test/resources/soliditycode/EthGrammar.sol"; + String contractName = "C"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractC = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 500000000L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractC = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 500000000L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(contractC, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(contractC, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); contractName = "D"; @@ -60,33 +73,53 @@ public void beforeClass() { code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - contractD = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 500000000L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractD = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 500000000L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - smartContract = PublicMethod.getContract(contractD, - blockingStubFull); + smartContract = PublicMethod.getContract(contractD, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - - @Test(enabled = true, description = "test get base fee value = commit.No 11 energy fee", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test get base fee value = commit.No 11 energy fee", + groups = {"contract", "daily"}) public void test01baseFee() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractC, - "baseFee()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractC, + "baseFee()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); long basefee = ByteArray.toLong(transactionExtention.getConstantResult(0).toByteArray()); logger.info("basefee: " + basefee); long energyfee; - Protocol.ChainParameters chainParameters = blockingStubFull - .getChainParameters(GrpcAPI.EmptyMessage.newBuilder().build()); + Protocol.ChainParameters chainParameters = + blockingStubFull.getChainParameters(GrpcAPI.EmptyMessage.newBuilder().build()); Optional getChainParameters = Optional.ofNullable(chainParameters); logger.info(Long.toString(getChainParameters.get().getChainParameterCount())); - String key = ""; + String key = ""; boolean flag = false; for (Integer i = 0; i < getChainParameters.get().getChainParameterCount(); i++) { key = getChainParameters.get().getChainParameter(i).getKey(); @@ -100,52 +133,83 @@ public void test01baseFee() { Assert.assertTrue(flag); } - @Test(enabled = true, description = "test get gas price value = commit.No 11 energy fee", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test get gas price value = commit.No 11 energy fee", + groups = {"contract", "daily"}) public void test02GasPrice() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractC, - "gasPrice()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractC, + "gasPrice()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } - @Test(enabled = true, description = "get create2 address, test get base fee ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "get create2 address, test get base fee ", + groups = {"contract", "daily"}) public void test03BaseFeeFromCreate2() { String methedStr = "deploy(uint256)"; - String argsStr = "1"; - String txid = PublicMethod.triggerContract(contractD, methedStr, argsStr, - false, 0, maxFeeLimit, contractExcAddress, - contractExcKey, blockingStubFull); + String argsStr = "1"; + String txid = + PublicMethod.triggerContract( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, - info.get().getReceipt().getResult()); - String create2Str = - "41" + ByteArray.toHexString(info.get().getContractResult(0).toByteArray()) - .substring(24); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.get().getReceipt().getResult()); + String create2Str = + "41" + ByteArray.toHexString(info.get().getContractResult(0).toByteArray()).substring(24); logger.info("hex create2 address: " + create2Str); create2Address = ByteArray.fromHexString(create2Str); logger.info("create2Address: " + Base58.encode58Check(create2Address)); - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(create2Address, - "baseFeeOnly()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + create2Address, + "baseFeeOnly()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); long basefee = ByteArray.toLong(transactionExtention.getConstantResult(0).toByteArray()); logger.info("basefee: " + basefee); long energyfee; - Protocol.ChainParameters chainParameters = blockingStubFull - .getChainParameters(GrpcAPI.EmptyMessage.newBuilder().build()); + Protocol.ChainParameters chainParameters = + blockingStubFull.getChainParameters(GrpcAPI.EmptyMessage.newBuilder().build()); Optional getChainParameters = Optional.ofNullable(chainParameters); logger.info(Long.toString(getChainParameters.get().getChainParameterCount())); - String key = ""; + String key = ""; boolean flag = false; for (Integer i = 0; i < getChainParameters.get().getChainParameterCount(); i++) { key = getChainParameters.get().getChainParameter(i).getKey(); @@ -158,31 +222,57 @@ public void test03BaseFeeFromCreate2() { } Assert.assertTrue(flag); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(create2Address, - "gasPriceOnly()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + create2Address, + "gasPriceOnly()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); long gasprice = ByteArray.toLong(transactionExtention.getConstantResult(0).toByteArray()); logger.info("gasprice: " + gasprice); Assert.assertEquals(basefee, gasprice); } - @Test(enabled = true, description = "call can use 63/64 energy in new contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "call can use 63/64 energy in new contract", + groups = {"contract", "daily"}) public void test04CallEnergy() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] transferToAddress = ecKey1.getAddress(); - String transferToKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + byte[] transferToAddress = ecKey1.getAddress(); + String transferToKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); PublicMethod.printAddress(transferToKey); - Long temMaxLimitFee = 200000000L; - String methedStr = "testCall(address,address)"; - String argsStr = "\"" + Base58.encode58Check(contractD) + "\"," + "\"" - + Base58.encode58Check(transferToAddress) + "\""; - String txid = PublicMethod.triggerContract(contractC, methedStr, argsStr, - false, 0, temMaxLimitFee, contractExcAddress, contractExcKey, blockingStubFull); + Long temMaxLimitFee = 200000000L; + String methedStr = "testCall(address,address)"; + String argsStr = + "\"" + + Base58.encode58Check(contractD) + + "\"," + + "\"" + + Base58.encode58Check(transferToAddress) + + "\""; + String txid = + PublicMethod.triggerContract( + contractC, + methedStr, + argsStr, + false, + 0, + temMaxLimitFee, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -190,40 +280,65 @@ public void test04CallEnergy() { PublicMethod.queryAccountByAddress(transferToAddress, blockingStubFull); logger.info("testAccount: " + testAccount.toString()); Assert.assertEquals(1, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.REVERT, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.REVERT, info.get().getReceipt().getResult()); Assert.assertTrue(info.get().getInternalTransactions(0).getRejected()); Assert.assertTrue(info.get().getReceipt().getEnergyFee() < temMaxLimitFee); } - @Test(enabled = true, description = "create2 address call can use 63/64 energy in new contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "create2 address call can use 63/64 energy in new contract", + groups = {"contract", "daily"}) public void test05Create2AddressCallEnergy() { String methedStr = "deploy(uint256)"; - String argsStr = "2"; - String txid = PublicMethod.triggerContract(contractD, methedStr, argsStr, - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String argsStr = "2"; + String txid = + PublicMethod.triggerContract( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, - info.get().getReceipt().getResult()); - String create2Str = - "41" + ByteArray.toHexString(info.get().getContractResult(0).toByteArray()) - .substring(24); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.get().getReceipt().getResult()); + String create2Str = + "41" + ByteArray.toHexString(info.get().getContractResult(0).toByteArray()).substring(24); logger.info("hex create2 address: " + create2Str); create2Address = ByteArray.fromHexString(create2Str); logger.info("create2Address: " + Base58.encode58Check(create2Address)); - ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] transferToAddress = ecKey1.getAddress(); - String transferToKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] transferToAddress = ecKey1.getAddress(); + String transferToKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); PublicMethod.printAddress(transferToKey); - Long temMaxLimitFee = 200000000L; + Long temMaxLimitFee = 200000000L; methedStr = "testCall(address,address)"; - argsStr = "\"" + Base58.encode58Check(contractD) + "\"," + "\"" - + Base58.encode58Check(transferToAddress) + "\""; - txid = PublicMethod.triggerContract(create2Address, methedStr, argsStr, - false, 0, temMaxLimitFee, contractExcAddress, contractExcKey, blockingStubFull); + argsStr = + "\"" + + Base58.encode58Check(contractD) + + "\"," + + "\"" + + Base58.encode58Check(transferToAddress) + + "\""; + txid = + PublicMethod.triggerContract( + create2Address, + methedStr, + argsStr, + false, + 0, + temMaxLimitFee, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -231,41 +346,65 @@ public void test05Create2AddressCallEnergy() { PublicMethod.queryAccountByAddress(transferToAddress, blockingStubFull); Assert.assertEquals("", testAccount.toString()); Assert.assertEquals(1, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.REVERT, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.REVERT, info.get().getReceipt().getResult()); Assert.assertTrue(info.get().getInternalTransactions(0).getRejected()); Assert.assertTrue(info.get().getReceipt().getEnergyFee() < temMaxLimitFee); } - @Test(enabled = true, description = "create2 address delegatecall " - + "can use 63/64 energy in new contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "create2 address delegatecall " + "can use 63/64 energy in new contract", + groups = {"contract", "daily"}) public void test06Create2AddressDelegateCallEnergy() { String methedStr = "deploy(uint256)"; - String argsStr = "5"; - String txid = PublicMethod.triggerContract(contractD, methedStr, argsStr, - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String argsStr = "5"; + String txid = + PublicMethod.triggerContract( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, - info.get().getReceipt().getResult()); - String create2Str = - "41" + ByteArray.toHexString(info.get().getContractResult(0).toByteArray()) - .substring(24); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.get().getReceipt().getResult()); + String create2Str = + "41" + ByteArray.toHexString(info.get().getContractResult(0).toByteArray()).substring(24); logger.info("hex create2 address: " + create2Str); create2Address = ByteArray.fromHexString(create2Str); logger.info("create2Address: " + Base58.encode58Check(create2Address)); - ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] transferToAddress = ecKey1.getAddress(); - String transferToKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] transferToAddress = ecKey1.getAddress(); + String transferToKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); PublicMethod.printAddress(transferToKey); - Long temMaxLimitFee = 200000000L; + Long temMaxLimitFee = 200000000L; methedStr = "testDelegateCall(address,address)"; - argsStr = "\"" + Base58.encode58Check(contractD) + "\"," + "\"" - + Base58.encode58Check(transferToAddress) + "\""; - txid = PublicMethod.triggerContract(create2Address, methedStr, argsStr, - false, 0, temMaxLimitFee, contractExcAddress, contractExcKey, blockingStubFull); + argsStr = + "\"" + + Base58.encode58Check(contractD) + + "\"," + + "\"" + + Base58.encode58Check(transferToAddress) + + "\""; + txid = + PublicMethod.triggerContract( + create2Address, + methedStr, + argsStr, + false, + 0, + temMaxLimitFee, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -273,40 +412,59 @@ public void test06Create2AddressDelegateCallEnergy() { PublicMethod.queryAccountByAddress(transferToAddress, blockingStubFull); Assert.assertEquals("", testAccount.toString()); Assert.assertEquals(1, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.REVERT, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.REVERT, info.get().getReceipt().getResult()); Assert.assertTrue(info.get().getInternalTransactions(0).getRejected()); Assert.assertTrue(info.get().getReceipt().getEnergyFee() < temMaxLimitFee); } - @Test(enabled = true, description = "create2 address this.function " - + "can use 63/64 energy in new contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "create2 address this.function " + "can use 63/64 energy in new contract", + groups = {"contract", "daily"}) public void test07Create2AddressCallFunctionEnergy() { String methedStr = "deploy(uint256)"; - String argsStr = "6"; - String txid = PublicMethod.triggerContract(contractD, methedStr, argsStr, - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String argsStr = "6"; + String txid = + PublicMethod.triggerContract( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, - info.get().getReceipt().getResult()); - String create2Str = - "41" + ByteArray.toHexString(info.get().getContractResult(0).toByteArray()) - .substring(24); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.get().getReceipt().getResult()); + String create2Str = + "41" + ByteArray.toHexString(info.get().getContractResult(0).toByteArray()).substring(24); logger.info("hex create2 address: " + create2Str); create2Address = ByteArray.fromHexString(create2Str); logger.info("create2Address: " + Base58.encode58Check(create2Address)); - ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] transferToAddress = ecKey1.getAddress(); - String transferToKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] transferToAddress = ecKey1.getAddress(); + String transferToKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); PublicMethod.printAddress(transferToKey); - Long temMaxLimitFee = 200000000L; + Long temMaxLimitFee = 200000000L; methedStr = "testCallFunctionInContract(address)"; argsStr = "\"" + Base58.encode58Check(transferToAddress) + "\""; - txid = PublicMethod.triggerContract(create2Address, methedStr, argsStr, - false, 0, temMaxLimitFee, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + create2Address, + methedStr, + argsStr, + false, + 0, + temMaxLimitFee, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -314,180 +472,289 @@ public void test07Create2AddressCallFunctionEnergy() { PublicMethod.queryAccountByAddress(transferToAddress, blockingStubFull); Assert.assertEquals("", testAccount.toString()); Assert.assertEquals(1, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.REVERT, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.REVERT, info.get().getReceipt().getResult()); Assert.assertTrue(info.get().getInternalTransactions(0).getRejected()); Assert.assertTrue(info.get().getReceipt().getEnergyFee() < temMaxLimitFee); } // - @Test(enabled = true, description = "test get Ripemd160 input is 123", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test get Ripemd160 input is 123", + groups = {"contract", "daily"}) public void test08getRipemd160() { String args = "\"123\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractC, - "getRipemd160(string)", args, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - String result = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractC, + "getRipemd160(string)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + String result = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals("e3431a8e0adbf96fd140103dc6f63a3f8fa343ab000000000000000000000000", result); } - @Test(enabled = true, description = "test get Ripemd160 input is empty", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test get Ripemd160 input is empty", + groups = {"contract", "daily"}) public void test09getRipemd160() { String args = "\"\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractC, - "getRipemd160(string)", args, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - String result = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractC, + "getRipemd160(string)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + String result = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals("9c1185a5c5e9fc54612808977ee8f548b2258d31000000000000000000000000", result); } - @Test(enabled = true, description = "test get Ripemd160 input length is greater than 256", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test get Ripemd160 input length is greater than 256", + groups = {"contract", "daily"}) public void test10getRipemd160() { - String args = "\"111111111111ddddddddddddd0x0000000000000000000000008b56a0602cc81fb0" - + "b99bce992b3198c0bab181ac111111111111ddddddddddddd0x0000000000000000000000008b56" - + "a0602cc81fb0b99bce992b3198c0bab181ac%^$#0000008b56a0602cc81fb0b99bce99" - + "2b3198c0bab181ac%^$#0000008b56a0602cc81fb0b99bce992b3198c0bab181ac%^$#\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractC, - "getRipemd160(string)", args, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - String result = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + String args = + "\"111111111111ddddddddddddd0x0000000000000000000000008b56a0602cc81fb0" + + "b99bce992b3198c0bab181ac111111111111ddddddddddddd0x0000000000000000000000008b56" + + "a0602cc81fb0b99bce992b3198c0bab181ac%^$#0000008b56a0602cc81fb0b99bce99" + + "2b3198c0bab181ac%^$#0000008b56a0602cc81fb0b99bce992b3198c0bab181ac%^$#\""; + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractC, + "getRipemd160(string)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + String result = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals("173c283ebcbad0e1c623a5c0f6813cb663338369000000000000000000000000", result); } - @Test(enabled = true, description = "test get Ripemd160 input is string " - + "and do not convert to bytes", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test get Ripemd160 input is string " + "and do not convert to bytes", + groups = {"contract", "daily"}) public void test11getRipemd160Str() { String args = "\"data\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractC, - "getRipemd160Str(string)", args, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - String result = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractC, + "getRipemd160Str(string)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + String result = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals("cd43325b85172ca28e96785d0cb4832fd62cdf43000000000000000000000000", result); } - @Test(enabled = true, description = "test get Ripemd160 input is string and " - + "do not convert to bytes", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test get Ripemd160 input is string and " + "do not convert to bytes", + groups = {"contract", "daily"}) public void test12getRipemd160Str() { - String args = "\"000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractC, - "getRipemd160Str(string)", args, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - String result = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + String args = + "\"000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000\""; + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractC, + "getRipemd160Str(string)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + String result = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals("efe2df697b79b5eb73a577251ce3911078811fa4000000000000000000000000", result); } - @Test(enabled = true, description = "test blake2f", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test blake2f", + groups = {"contract", "daily"}) public void test13getBlak2f() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractC, - "callF()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - String result = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractC, + "callF()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + String result = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac" - + "4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923", + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac" + + "4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923", result); - } - @Test(enabled = true, description = "when call create2, stack depth will be checked" - + "if stack depth is greater than 64, then create command will revert" - + "but run environment can not compute so much, so the actual result is time out", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "when call create2, stack depth will be checked" + + "if stack depth is greater than 64, then create command will revert" + + "but run environment can not compute so much, so the actual result is time out", + groups = {"contract", "daily"}) public void test14FixCreate2StackDepth() { String methedStr = "fixCreate2StackDepth(uint256)"; - String argsStr = "123"; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractD, - methedStr, argsStr, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String argsStr = "123"; + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info("transactionExtention: " + transactionExtention.toString()); - String message = ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray()); + String message = ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray()); Assert.assertTrue(message.contains("CPU timeout")); /*int interCount = transactionExtention.getInternalTransactionsCount(); - int createCount = 0; - for(int i=0;i= 15 && createCount <= 64);*/ + Assert.assertTrue(createCount >= 15 && createCount <= 64);*/ } - @Test(enabled = true, description = "when call create, stack depth will be checked." - + "if stack depth is greater than 64, then create command will revert" - + "but run environment can not compute so much, so the actual result is time out", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "when call create, stack depth will be checked." + + "if stack depth is greater than 64, then create command will revert" + + "but run environment can not compute so much, so the actual result is time out", + groups = {"contract", "daily"}) public void test15FixCreateStackDepth() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractD, - "fixCreateStackDepth()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - String message = ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractD, + "fixCreateStackDepth()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + String message = ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray()); logger.info("transactionExtention: " + transactionExtention.toString()); Assert.assertTrue(message.contains("CPU timeout")); /*int interCount = transactionExtention.getInternalTransactionsCount(); - int createCount = 0; - for(int i=0;i= 15 && createCount <= 64);*/ + Assert.assertTrue(createCount >= 15 && createCount <= 64);*/ } - @Test(enabled = false, description = "test max Energy Limit For trigger Constant contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "test max Energy Limit For trigger Constant contract", + groups = {"contract", "daily"}) public void test16MaxEnergyLimitForConstant() { String methedStr = "transfer(address)"; - String argsStr = "\"" + Base58.encode58Check(testNetAccountAddress) + "\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractD, - methedStr, argsStr, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String argsStr = "\"" + Base58.encode58Check(testNetAccountAddress) + "\""; + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); System.out.println("transactionExtention: " + transactionExtention.toString()); } - @Test(enabled = false, description = "commit NO.47 value can be 1e17 if commit No.63 opened" - + " move this case to TransactionFee001.java", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = + "commit NO.47 value can be 1e17 if commit No.63 opened" + + " move this case to TransactionFee001.java", + groups = {"contract", "daily"}) public void test17Commit47Value() { HashMap proposalMap = new HashMap(); proposalMap.put(47L, 100000000000000000L); - org.testng.Assert.assertTrue(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + org.testng.Assert.assertTrue( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/EthGrammar02.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/EthGrammar02.java index 1e40a921..5e83591d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/EthGrammar02.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/EthGrammar02.java @@ -14,14 +14,14 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class EthGrammar02 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractD = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -29,494 +29,826 @@ public class EthGrammar02 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); int salt = 11; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 300100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 300100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/EthGrammar02.sol"; - String contractName = "D"; + String filePath = "src/test/resources/soliditycode/EthGrammar02.sol"; + String contractName = "D"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractD = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 500000000L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractD = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 500000000L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(contractD, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(contractD, blockingStubFull); Assert.assertEquals(1, smartContract.getVersion()); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "can not deploy contract with bytecode ef", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "can not deploy contract with bytecode ef", + groups = {"contract", "daily"}) public void test16forbiddenBytecodeStartWithEf() { String code = "60ef60005360016000f3"; - String abi = "[{\"inputs\":[],\"stateMutability\":\"payable\",\"type\":\"constructor\"}]"; - String txid = PublicMethod.deployContractAndGetTransactionInfoById("test", - abi, code, "", maxFeeLimit, - 500000000L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String abi = "[{\"inputs\":[],\"stateMutability\":\"payable\",\"type\":\"constructor\"}]"; + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + "test", + abi, + code, + "", + maxFeeLimit, + 500000000L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("info: " + info.get().toString()); Assert.assertEquals(1, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.INVALID_CODE, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.INVALID_CODE, info.get().getReceipt().getResult()); - Assert.assertEquals("invalid code: must not begin with 0xef".toLowerCase(), + Assert.assertEquals( + "invalid code: must not begin with 0xef".toLowerCase(), ByteArray.toStr(info.get().getResMessage().toByteArray()).toLowerCase()); } - @Test(enabled = true, description = "can not deploy contract with bytecode ef00", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "can not deploy contract with bytecode ef00", + groups = {"contract", "daily"}) public void test17forbiddenBytecodeStartWithEf() { String code = "60ef60005360026000f3"; - String abi = "[{\"inputs\":[],\"stateMutability\":\"payable\",\"type\":\"constructor\"}]"; - String txid = PublicMethod.deployContractAndGetTransactionInfoById("test", - abi, code, "", maxFeeLimit, 500000000L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String abi = "[{\"inputs\":[],\"stateMutability\":\"payable\",\"type\":\"constructor\"}]"; + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + "test", + abi, + code, + "", + maxFeeLimit, + 500000000L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("info: " + info.get().toString()); Assert.assertEquals(1, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.INVALID_CODE, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.INVALID_CODE, info.get().getReceipt().getResult()); - Assert.assertEquals("invalid code: must not begin with 0xef".toLowerCase(), + Assert.assertEquals( + "invalid code: must not begin with 0xef".toLowerCase(), ByteArray.toStr(info.get().getResMessage().toByteArray()).toLowerCase()); } - @Test(enabled = true, description = "can not deploy contract with bytecode ef0000", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "can not deploy contract with bytecode ef0000", + groups = {"contract", "daily"}) public void test18forbiddenBytecodeStartWithEf() { String code = "60ef60005360036000f3"; - String abi = "[{\"inputs\":[],\"stateMutability\":\"payable\",\"type\":\"constructor\"}]"; - String txid = PublicMethod.deployContractAndGetTransactionInfoById("test", abi, - code, "", maxFeeLimit, 500000000L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String abi = "[{\"inputs\":[],\"stateMutability\":\"payable\",\"type\":\"constructor\"}]"; + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + "test", + abi, + code, + "", + maxFeeLimit, + 500000000L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("info: " + info.get().toString()); Assert.assertEquals(1, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.INVALID_CODE, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.INVALID_CODE, info.get().getReceipt().getResult()); - Assert.assertEquals("invalid code: must not begin with 0xef".toLowerCase(), + Assert.assertEquals( + "invalid code: must not begin with 0xef".toLowerCase(), ByteArray.toStr(info.get().getResMessage().toByteArray()).toLowerCase()); } - @Test(enabled = true, description = "can not deploy contract with bytecode" - + " ef00000000000000000000000000000000000000000000000000000000000000", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "can not deploy contract with bytecode" + + " ef00000000000000000000000000000000000000000000000000000000000000", + groups = {"contract", "daily"}) public void test19forbiddenBytecodeStartWithEf() { String code = "60ef60005360206000f3"; - String abi = "[{\"inputs\":[],\"stateMutability\":\"payable\",\"type\":\"constructor\"}]"; - String txid = PublicMethod.deployContractAndGetTransactionInfoById("test", abi, - code, "", maxFeeLimit, 500000000L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String abi = "[{\"inputs\":[],\"stateMutability\":\"payable\",\"type\":\"constructor\"}]"; + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + "test", + abi, + code, + "", + maxFeeLimit, + 500000000L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("info: " + info.get().toString()); Assert.assertEquals(1, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.INVALID_CODE, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.INVALID_CODE, info.get().getReceipt().getResult()); - Assert.assertEquals("invalid code: must not begin with 0xef".toLowerCase(), + Assert.assertEquals( + "invalid code: must not begin with 0xef".toLowerCase(), ByteArray.toStr(info.get().getResMessage().toByteArray()).toLowerCase()); } - @Test(enabled = true, description = "can deploy contract with bytecode fe", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "can deploy contract with bytecode fe", + groups = {"contract", "daily"}) public void test20forbiddenBytecodeStartWithEf() { String code = "60fe60005360016000f3"; - String abi = "[{\"inputs\":[],\"stateMutability\":\"payable\",\"type\":\"constructor\"}]"; - String txid = PublicMethod.deployContractAndGetTransactionInfoById("test", abi, - code, "", maxFeeLimit, 500000000L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String abi = "[{\"inputs\":[],\"stateMutability\":\"payable\",\"type\":\"constructor\"}]"; + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + "test", + abi, + code, + "", + maxFeeLimit, + 500000000L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("info: " + info.get().toString()); Assert.assertEquals(0, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.get().getReceipt().getResult()); } - @Test(enabled = true, description = "can not deploy contract by create with bytecode ef", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "can not deploy contract by create with bytecode ef", + groups = {"contract", "daily"}) public void test21forbiddenBytecodeStartWithEf() { String methedStr = "createDeployEf(bytes)"; - String argsStr = "\"0x60ef60005360016000f3\""; - String txid = PublicMethod.triggerContract(contractD, methedStr, argsStr, - false, 0, maxFeeLimit, contractExcAddress, - contractExcKey, blockingStubFull); + String argsStr = "\"0x60ef60005360016000f3\""; + String txid = + PublicMethod.triggerContract( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(1, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.REVERT, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.REVERT, info.get().getReceipt().getResult()); } - @Test(enabled = true, description = "can not deploy contract by create with bytecode ef00", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "can not deploy contract by create with bytecode ef00", + groups = {"contract", "daily"}) public void test22forbiddenBytecodeStartWithEf() { String methedStr = "createDeployEf(bytes)"; - String argsStr = "\"0x60ef60005360026000f3\""; - String txid = PublicMethod.triggerContract(contractD, methedStr, argsStr, - false, 0, maxFeeLimit, contractExcAddress, - contractExcKey, blockingStubFull); + String argsStr = "\"0x60ef60005360026000f3\""; + String txid = + PublicMethod.triggerContract( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(1, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.REVERT, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.REVERT, info.get().getReceipt().getResult()); } - @Test(enabled = true, description = "can not deploy contract by create with bytecode ef0000", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "can not deploy contract by create with bytecode ef0000", + groups = {"contract", "daily"}) public void test23forbiddenBytecodeStartWithEf() { String methedStr = "createDeployEf(bytes)"; - String argsStr = "\"0x60ef60005360036000f3\""; - String txid = PublicMethod.triggerContract(contractD, methedStr, argsStr, - false, 0, maxFeeLimit, contractExcAddress, - contractExcKey, blockingStubFull); + String argsStr = "\"0x60ef60005360036000f3\""; + String txid = + PublicMethod.triggerContract( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(1, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.REVERT, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.REVERT, info.get().getReceipt().getResult()); } - @Test(enabled = true, description = "can not deploy contract by create with bytecode " - + "ef00000000000000000000000000000000000000000000000000000000000000", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "can not deploy contract by create with bytecode " + + "ef00000000000000000000000000000000000000000000000000000000000000", + groups = {"contract", "daily"}) public void test24forbiddenBytecodeStartWithEf() { String methedStr = "createDeployEf(bytes)"; - String argsStr = "\"0x60ef60005360206000f3\""; - String txid = PublicMethod.triggerContract(contractD, methedStr, argsStr, - false, 0, maxFeeLimit, contractExcAddress, - contractExcKey, blockingStubFull); + String argsStr = "\"0x60ef60005360206000f3\""; + String txid = + PublicMethod.triggerContract( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(1, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.REVERT, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.REVERT, info.get().getReceipt().getResult()); } - @Test(enabled = true, description = "can deploy contract by create with bytecode fe", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "can deploy contract by create with bytecode fe", + groups = {"contract", "daily"}) public void test25forbiddenBytecodeStartWithEf() { String methedStr = "createDeployEf(bytes)"; - String argsStr = "\"0x60fe60005360016000f3\""; - String txid = PublicMethod.triggerContract(contractD, methedStr, argsStr, - false, 0, maxFeeLimit, contractExcAddress, - contractExcKey, blockingStubFull); + String argsStr = "\"0x60fe60005360016000f3\""; + String txid = + PublicMethod.triggerContract( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.get().getReceipt().getResult()); } - @Test(enabled = true, description = "can not deploy contract by create2 with bytecode ef", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "can not deploy contract by create2 with bytecode ef", + groups = {"contract", "daily"}) public void test26forbiddenBytecodeStartWithEf() { String methedStr = "create2DeployEf(bytes,uint256)"; - String argsStr = "\"0x60ef60005360016000f3\"," + salt; - String txid = PublicMethod.triggerContract(contractD, methedStr, argsStr, - false, 0, maxFeeLimit, contractExcAddress, - contractExcKey, blockingStubFull); + String argsStr = "\"0x60ef60005360016000f3\"," + salt; + String txid = + PublicMethod.triggerContract( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(1, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.REVERT, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.REVERT, info.get().getReceipt().getResult()); } - @Test(enabled = true, description = "can not deploy contract by create2 with bytecode ef00", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "can not deploy contract by create2 with bytecode ef00", + groups = {"contract", "daily"}) public void test27forbiddenBytecodeStartWithEf() { salt++; - String methedStr = "create2DeployEf(bytes,uint256)"; - String argsStr = "\"0x60ef60005360026000f3\"," + salt; - String txid = PublicMethod.triggerContract(contractD, methedStr, argsStr, - false, 0, maxFeeLimit, contractExcAddress, - contractExcKey, blockingStubFull); + String methedStr = "create2DeployEf(bytes,uint256)"; + String argsStr = "\"0x60ef60005360026000f3\"," + salt; + String txid = + PublicMethod.triggerContract( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(1, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.REVERT, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.REVERT, info.get().getReceipt().getResult()); } - @Test(enabled = true, description = "can not deploy contract by create2 with bytecode ef0000", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "can not deploy contract by create2 with bytecode ef0000", + groups = {"contract", "daily"}) public void test28forbiddenBytecodeStartWithEf() { salt++; - String methedStr = "create2DeployEf(bytes,uint256)"; - String argsStr = "\"0x60ef60005360036000f3\"," + salt; - String txid = PublicMethod.triggerContract(contractD, methedStr, argsStr, - false, 0, maxFeeLimit, contractExcAddress, - contractExcKey, blockingStubFull); + String methedStr = "create2DeployEf(bytes,uint256)"; + String argsStr = "\"0x60ef60005360036000f3\"," + salt; + String txid = + PublicMethod.triggerContract( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(1, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.REVERT, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.REVERT, info.get().getReceipt().getResult()); } - @Test(enabled = true, description = "can not deploy contract by create2 with bytecode " - + "ef00000000000000000000000000000000000000000000000000000000000000", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "can not deploy contract by create2 with bytecode " + + "ef00000000000000000000000000000000000000000000000000000000000000", + groups = {"contract", "daily"}) public void test29forbiddenBytecodeStartWithEf() { salt++; - String methedStr = "create2DeployEf(bytes,uint256)"; - String argsStr = "\"0x60ef60005360206000f3\"," + salt; - String txid = PublicMethod.triggerContract(contractD, methedStr, argsStr, - false, 0, maxFeeLimit, contractExcAddress, - contractExcKey, blockingStubFull); + String methedStr = "create2DeployEf(bytes,uint256)"; + String argsStr = "\"0x60ef60005360206000f3\"," + salt; + String txid = + PublicMethod.triggerContract( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(1, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.REVERT, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.REVERT, info.get().getReceipt().getResult()); } - @Test(enabled = true, description = "can deploy contract by create2 with bytecode fe", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "can deploy contract by create2 with bytecode fe", + groups = {"contract", "daily"}) public void test30forbiddenBytecodeStartWithEf() { salt++; - String methedStr = "create2DeployEf(bytes,uint256)"; - String argsStr = "\"0x60fe60005360016000f3\"," + salt; - String txid = PublicMethod.triggerContract(contractD, methedStr, argsStr, - false, 0, maxFeeLimit, contractExcAddress, - contractExcKey, blockingStubFull); + String methedStr = "create2DeployEf(bytes,uint256)"; + String argsStr = "\"0x60fe60005360016000f3\"," + salt; + String txid = + PublicMethod.triggerContract( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.get().getReceipt().getResult()); } - @Test(enabled = true, description = "can not sendcoin to contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "can not sendcoin to contract", + groups = {"contract", "daily"}) public void test31forbiddenSendTrxToContract() { - Assert.assertFalse(PublicMethod - .sendcoin(contractD, 100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + Assert.assertFalse( + PublicMethod.sendcoin( + contractD, 100_000_000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); } - @Test(enabled = true, description = "db key can use high 16 bytes," - + "0x6162630000000000000000000000000000000000000000000000000000000000", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "db key can use high 16 bytes," + + "0x6162630000000000000000000000000000000000000000000000000000000000", + groups = {"contract", "daily"}) public void test32DbKeyUseHigh16Bytes() { String slot = "0x6162630000000000000000000000000000000000000000000000000000000000"; long value = 121; - String methedStr = "setSlot(bytes,uint256)"; - String argsStr = "\"" + slot + "\"," + value; - String txid = PublicMethod.triggerContract(contractD, methedStr, argsStr, - false, 0, maxFeeLimit, contractExcAddress, - contractExcKey, blockingStubFull); + String methedStr = "setSlot(bytes,uint256)"; + String argsStr = "\"" + slot + "\"," + value; + String txid = + PublicMethod.triggerContract( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.get().getReceipt().getResult()); methedStr = "getSlot(bytes)"; argsStr = "\"" + slot + "\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractD, - methedStr, argsStr, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); long result = ByteArray.toLong(transactionExtention.getConstantResult(0).toByteArray()); logger.info("result: " + result); Assert.assertEquals(value, result); } - @Test(enabled = true, description = "slot high 16bytes all f," - + "0xffffffffffffffffffffffffffffffff00000000000000000000000000000000", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "slot high 16bytes all f," + + "0xffffffffffffffffffffffffffffffff00000000000000000000000000000000", + groups = {"contract", "daily"}) public void test33DbKeyUseHigh16Bytes() { String slot = "0xffffffffffffffffffffffffffffffff00000000000000000000000000000000"; long value = 122; - String methedStr = "setSlot(bytes,uint256)"; - String argsStr = "\"" + slot + "\"," + value; - String txid = PublicMethod.triggerContract(contractD, methedStr, argsStr, - false, 0, maxFeeLimit, contractExcAddress, - contractExcKey, blockingStubFull); + String methedStr = "setSlot(bytes,uint256)"; + String argsStr = "\"" + slot + "\"," + value; + String txid = + PublicMethod.triggerContract( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.get().getReceipt().getResult()); methedStr = "getSlot(bytes)"; argsStr = "\"" + slot + "\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractD, - methedStr, argsStr, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); long result = ByteArray.toLong(transactionExtention.getConstantResult(0).toByteArray()); logger.info("result: " + result); Assert.assertEquals(value, result); } - @Test(enabled = true, description = "slot high 16bytes 1," - + " 0x0000000000000000000000000000000100000000000000000000000000000000", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "slot high 16bytes 1," + + " 0x0000000000000000000000000000000100000000000000000000000000000000", + groups = {"contract", "daily"}) public void test34DbKeyUseHigh16Bytes() { String slot = "0x0000000000000000000000000000000100000000000000000000000000000000"; long value = 123; - String methedStr = "setSlot(bytes,uint256)"; - String argsStr = "\"" + slot + "\"," + value; - String txid = PublicMethod.triggerContract(contractD, methedStr, argsStr, - false, 0, maxFeeLimit, contractExcAddress, - contractExcKey, blockingStubFull); + String methedStr = "setSlot(bytes,uint256)"; + String argsStr = "\"" + slot + "\"," + value; + String txid = + PublicMethod.triggerContract( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.get().getReceipt().getResult()); methedStr = "getSlot(bytes)"; argsStr = "\"" + slot + "\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractD, - methedStr, argsStr, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); long result = ByteArray.toLong(transactionExtention.getConstantResult(0).toByteArray()); logger.info("result: " + result); Assert.assertEquals(value, result); } - @Test(enabled = true, description = "slot high 16bytes all 0,low 16bytes 1." - + " 0x0000000000000000000000000000000000000000000000000000000000000001", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "slot high 16bytes all 0,low 16bytes 1." + + " 0x0000000000000000000000000000000000000000000000000000000000000001", + groups = {"contract", "daily"}) public void test35DbKeyUseHigh16Bytes() { String slot = "0x0000000000000000000000000000000000000000000000000000000000000001"; long value = 124; - String methedStr = "setSlot(bytes,uint256)"; - String argsStr = "\"" + slot + "\"," + value; - String txid = PublicMethod.triggerContract(contractD, methedStr, argsStr, - false, 0, maxFeeLimit, contractExcAddress, - contractExcKey, blockingStubFull); + String methedStr = "setSlot(bytes,uint256)"; + String argsStr = "\"" + slot + "\"," + value; + String txid = + PublicMethod.triggerContract( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.get().getReceipt().getResult()); methedStr = "getSlot(bytes)"; argsStr = "\"" + slot + "\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractD, - methedStr, argsStr, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); long result = ByteArray.toLong(transactionExtention.getConstantResult(0).toByteArray()); logger.info("result: " + result); Assert.assertEquals(value, result); } - @Test(enabled = true, description = "slot all 0," - + " 0x0000000000000000000000000000000000000000000000000000000000000000", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "slot all 0," + " 0x0000000000000000000000000000000000000000000000000000000000000000", + groups = {"contract", "daily"}) public void test36DbKeyUseHigh16BytesAllBytes0() { String slot = "0x0000000000000000000000000000000000000000000000000000000000000000"; long value = 125; - String methedStr = "setSlot(bytes,uint256)"; - String argsStr = "\"" + slot + "\"," + value; - String txid = PublicMethod.triggerContract(contractD, methedStr, argsStr, - false, 0, maxFeeLimit, contractExcAddress, - contractExcKey, blockingStubFull); + String methedStr = "setSlot(bytes,uint256)"; + String argsStr = "\"" + slot + "\"," + value; + String txid = + PublicMethod.triggerContract( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.get().getReceipt().getResult()); methedStr = "getSlot(bytes)"; argsStr = "\"" + slot + "\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractD, - methedStr, argsStr, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); long result = ByteArray.toLong(transactionExtention.getConstantResult(0).toByteArray()); logger.info("result: " + result); Assert.assertEquals(value, result); } - @Test(enabled = true, description = "slot all f," - + " 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "slot all f," + " 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + groups = {"contract", "daily"}) public void test37DbKeyUseHigh16BytesAllBytesF() { String slot = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; long value = 126; - String methedStr = "setSlot(bytes,uint256)"; - String argsStr = "\"" + slot + "\"," + value; - String txid = PublicMethod.triggerContract(contractD, methedStr, argsStr, - false, 0, maxFeeLimit, contractExcAddress, - contractExcKey, blockingStubFull); + String methedStr = "setSlot(bytes,uint256)"; + String argsStr = "\"" + slot + "\"," + value; + String txid = + PublicMethod.triggerContract( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, info.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, - info.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.get().getReceipt().getResult()); methedStr = "getSlot(bytes)"; argsStr = "\"" + slot + "\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractD, - methedStr, argsStr, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); long result = ByteArray.toLong(transactionExtention.getConstantResult(0).toByteArray()); logger.info("result: " + result); Assert.assertEquals(value, result); } - @Test(enabled = true, description = "TransactionExtention has logs and internal_transactions", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransactionExtention has logs and internal_transactions", + groups = {"contract", "daily"}) public void test38ConstantLogEven() { salt++; - String methedStr = "create2DeployEf(bytes,uint256)"; - String argsStr = "\"0x60fe60005360016000f3\"," + salt; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractD, - methedStr, argsStr, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String methedStr = "create2DeployEf(bytes,uint256)"; + String argsStr = "\"0x60fe60005360016000f3\"," + salt; + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractD, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(1, transactionExtention.getLogsCount()); Assert.assertEquals(1, transactionExtention.getInternalTransactionsCount()); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/FixbugTest086.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/FixbugTest086.java index 4a9a861d..8a7dd794 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/FixbugTest086.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/FixbugTest086.java @@ -16,14 +16,14 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.HttpMethod; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class FixbugTest086 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] mapKeyContract = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -32,100 +32,142 @@ public class FixbugTest086 extends TronBaseTest { private String wrongProtoFixed64TypeTxid; private JSONObject responseContent; private HttpResponse response; - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(0); - - /** - * constructor. - */ + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 300100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 300100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = + String filePath = "src/test/resources/soliditycode/abstractContractWithMapParamsConstructor.sol"; - String contractName = "Cat"; + String contractName = "Cat"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - mapKeyContract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + mapKeyContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(mapKeyContract, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(mapKeyContract, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - - @Test(enabled = true, description = "abstract With Map Params", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "abstract With Map Params", + groups = {"contract", "daily"}) public void test01ContractWithMapParams() { - String triggerTxid = PublicMethod.triggerContract(mapKeyContract, "getMapValue()", "#", false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + "getMapValue()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); - Assert.assertEquals(20, - ByteArray.toInt(transactionInfo.get().getContractResult(0).toByteArray())); + Assert.assertEquals( + 20, ByteArray.toInt(transactionInfo.get().getContractResult(0).toByteArray())); } - - @Test(enabled = true, description = " super skip unimplemented in abstract contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = " super skip unimplemented in abstract contract", + groups = {"contract", "daily"}) public void test02SkipUnimplemented() { String filePath = "src/test/resources/soliditycode/super_skip_unimplemented_in_abstract_contract.sol"; - String contractName = "B"; + String contractName = "B"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - mapKeyContract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + mapKeyContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(mapKeyContract, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(mapKeyContract, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - String triggerTxid = PublicMethod.triggerContract(mapKeyContract, "f()", "#", false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + "f()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); wrongProtoFixed64TypeTxid = triggerTxid; - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); - Assert.assertEquals(42, - ByteArray.toInt(transactionInfo.get().getContractResult(0).toByteArray())); + Assert.assertEquals( + 42, ByteArray.toInt(transactionInfo.get().getContractResult(0).toByteArray())); } - - @Test(enabled = true, description = "Fixed wrong fixed64 proto type transaction print bug", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Fixed wrong fixed64 proto type transaction print bug", + groups = {"contract", "daily"}) public void test03FixedWrongFixed64ProtoTypeTransaction() { response = HttpMethod.getTransactionById(httpnode, wrongProtoFixed64TypeTxid); responseContent = HttpMethod.parseResponseContent(response); HttpMethod.printJsonContent(responseContent); Assert.assertEquals(wrongProtoFixed64TypeTxid, responseContent.getString("txID")); - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/FunctionArray2Storage086.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/FunctionArray2Storage086.java index 91585784..98c96b72 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/FunctionArray2Storage086.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/FunctionArray2Storage086.java @@ -13,111 +13,159 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class FunctionArray2Storage086 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] mapKeyContract = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 300100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 300100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/function_type_array_to_storage.sol"; - String contractName = "C"; + String filePath = "src/test/resources/soliditycode/function_type_array_to_storage.sol"; + String contractName = "C"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - mapKeyContract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 500000000L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + mapKeyContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 500000000L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(mapKeyContract, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(mapKeyContract, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - - @Test(enabled = true, description = "function array test view to default", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "function array test view to default", + groups = {"contract", "daily"}) public void test01View2Default() { String triggerTxid = - PublicMethod.triggerContract(mapKeyContract, "testViewToDefault()", "#", false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethod.triggerContract( + mapKeyContract, + "testViewToDefault()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); - Assert.assertEquals(12, + Assert.assertEquals( + 12, ByteArray.toInt(transactionInfo.get().getContractResult(0).substring(0, 32).toByteArray())); - Assert.assertEquals(22, - ByteArray.toInt(transactionInfo.get().getContractResult(0) - .substring(32, 64).toByteArray())); + Assert.assertEquals( + 22, + ByteArray.toInt( + transactionInfo.get().getContractResult(0).substring(32, 64).toByteArray())); } - @Test(enabled = true, description = "function array pure to default", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "function array pure to default", + groups = {"contract", "daily"}) public void test02Pure2Default() { String triggerTxid = - PublicMethod.triggerContract(mapKeyContract, "testPureToDefault()", "#", false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethod.triggerContract( + mapKeyContract, + "testPureToDefault()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); - Assert.assertEquals(13, + Assert.assertEquals( + 13, ByteArray.toInt(transactionInfo.get().getContractResult(0).substring(0, 32).toByteArray())); - Assert.assertEquals(23, - ByteArray.toInt(transactionInfo.get().getContractResult(0) - .substring(32, 64).toByteArray())); - + Assert.assertEquals( + 23, + ByteArray.toInt( + transactionInfo.get().getContractResult(0).substring(32, 64).toByteArray())); } - @Test(enabled = true, description = "function array pure to view ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "function array pure to view ", + groups = {"contract", "daily"}) public void test03Pure2View() { String triggerTxid = - PublicMethod.triggerContract(mapKeyContract, "testPureToView()", "#", false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethod.triggerContract( + mapKeyContract, + "testPureToView()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); - Assert.assertEquals(13, + Assert.assertEquals( + 13, ByteArray.toInt(transactionInfo.get().getContractResult(0).substring(0, 32).toByteArray())); - Assert.assertEquals(23, - ByteArray.toInt(transactionInfo.get().getContractResult(0) - .substring(32, 64).toByteArray())); + Assert.assertEquals( + 23, + ByteArray.toInt( + transactionInfo.get().getContractResult(0).substring(32, 64).toByteArray())); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/LengthTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/LengthTest.java index a898b9ea..dbabb0e0 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/LengthTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/LengthTest.java @@ -11,76 +11,111 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j public class LengthTest extends TronBaseTest { - private String testFoundationKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); - private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); + private String testFoundationKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); + private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey1.getAddress(); String testKey001 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private byte[] contractAddress; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(testKey001); PublicMethod - .sendcoin(testAddress001, 10000_000_000L, testFoundationAddress, testFoundationKey, - blockingStubFull); - String filePath = "src/test/resources/soliditycode/arrayLength001.sol"; - String contractName = "arrayLength"; + PublicMethod.printAddress(testKey001); + PublicMethod.sendcoin( + testAddress001, 10000_000_000L, testFoundationAddress, testFoundationKey, blockingStubFull); + String filePath = "src/test/resources/soliditycode/arrayLength001.sol"; + String contractName = "arrayLength"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0, 100, null, - testFoundationKey, testFoundationAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0, + 100, + null, + testFoundationKey, + testFoundationAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "push() increase Array length", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "push() increase Array length", + groups = {"contract", "daily"}) public void arrayLengthTest001() { String methodStr = "arrayPush()"; - String argStr = ""; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = ""; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); + Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); - Assert.assertEquals("" - + "0000000000000000000000000000000000000000000000000000000000000020" - + "0000000000000000000000000000000000000000000000000000000000000002" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000", + Assert.assertEquals( + "" + + "0000000000000000000000000000000000000000000000000000000000000020" + + "0000000000000000000000000000000000000000000000000000000000000002" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "push(value) increase Array length", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "push(value) increase Array length", + groups = {"contract", "daily"}) public void arrayLengthTest002() { String methodStr = "arrayPushValue()"; - String argStr = ""; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = ""; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); + Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); - Assert.assertEquals("" + Assert.assertEquals( + "" + "0000000000000000000000000000000000000000000000000000000000000020" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000000" @@ -88,169 +123,272 @@ public void arrayLengthTest002() { ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "pop() decrease Array length", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "pop() decrease Array length", + groups = {"contract", "daily"}) public void arrayLengthTest003() { String methodStr = "arrayPop()"; - String argStr = ""; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = ""; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); + Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); - Assert.assertEquals("" + Assert.assertEquals( + "" + "0000000000000000000000000000000000000000000000000000000000000020" + "0000000000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "push() return no value", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "push() return no value", + groups = {"contract", "daily"}) public void arrayLengthTest004() { String methodStr = "arrayPushReturn()"; - String argStr = ""; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = ""; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); + Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); - Assert.assertEquals("" - + "0000000000000000000000000000000000000000000000000000000000000000", + Assert.assertEquals( + "" + "0000000000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "push(value) return value", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "push(value) return value", + groups = {"contract", "daily"}) public void arrayLengthTest005() { String methodStr = "arrayPushValueReturn()"; - String argStr = ""; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = ""; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); + Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); - Assert.assertEquals("", - ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); + Assert.assertEquals( + "", ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "pop() return no value", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "pop() return no value", + groups = {"contract", "daily"}) public void arrayLengthTest006() { String methodStr = "arrayPopReturn()"; - String argStr = ""; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = ""; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); + Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); - Assert.assertEquals("", - ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); + Assert.assertEquals( + "", ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "bytes push() return value", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "bytes push() return value", + groups = {"contract", "daily"}) public void arrayLengthTest007() { String methodStr = "bytesPush()"; - String argStr = ""; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = ""; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); + Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); - Assert.assertEquals("" - + "0000000000000000000000000000000000000000000000000000000000000000", + Assert.assertEquals( + "" + "0000000000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "bytes push(value) return no value", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "bytes push(value) return no value", + groups = {"contract", "daily"}) public void arrayLengthTest008() { String methodStr = "bytesPushValue()"; - String argStr = ""; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = ""; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); + Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); - Assert.assertEquals("", - ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); + Assert.assertEquals( + "", ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "bytes pop() return no value", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "bytes pop() return no value", + groups = {"contract", "daily"}) public void arrayLengthTest009() { String methodStr = "bytesPop()"; - String argStr = ""; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = ""; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); + Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); - Assert.assertEquals("", - ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); + Assert.assertEquals( + "", ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); } - - @Test(enabled = true, description = "array length change before v0.5.15", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "array length change before v0.5.15", + groups = {"contract", "daily"}) public void arrayLengthV0515() { - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_arrayLenth_0.5.15"); - String code = Configuration.getByPath("testng.conf") - .getString("code.code_arrayLength_0.5.15"); - String contractName = "arrayLength"; - byte[] v0515Address = PublicMethod.deployContract(contractName,abi,code,"",maxFeeLimit,0,100, - null, testKey001, testAddress001, blockingStubFull); + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_arrayLenth_0.5.15"); + String code = Configuration.getByPath("testng.conf").getString("code.code_arrayLength_0.5.15"); + String contractName = "arrayLength"; + byte[] v0515Address = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String Txid = PublicMethod.triggerContract(v0515Address,"ChangeSize()","",false,0,maxFeeLimit, - testAddress001,testKey001,blockingStubFull); + String Txid = + PublicMethod.triggerContract( + v0515Address, + "ChangeSize()", + "", + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(Txid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(Txid, blockingStubFull); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); - Assert.assertEquals("" - + "0000000000000000000000000000000000000000000000000000000000000020" - + "0000000000000000000000000000000000000000000000000000000000000001" - + "0100000000000000000000000000000000000000000000000000000000000000", + Assert.assertEquals(0, transactionInfo.get().getResultValue()); + Assert.assertEquals( + "" + + "0000000000000000000000000000000000000000000000000000000000000020" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "0100000000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); - } - - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/MappingFixTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/MappingFixTest.java index 82245d27..6d323de8 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/MappingFixTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/MappingFixTest.java @@ -18,63 +18,85 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class MappingFixTest extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] contractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); } // after solidity version 0.5.4. // Tron Solidity compiler is no longer compatible with Ethereum // Tron handles 41 Address in contract, and Ethereum do not - @Test(enabled = true, description = "Deploy contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy contract", + groups = {"contract", "daily"}) public void test01DeployContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 1000_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 100_000_000L, - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1000_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 100_000_000L, + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(dev001Key, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = accountResource.getEnergyUsed(); - Long beforeNetUsed = accountResource.getNetUsed(); - Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = accountResource.getEnergyUsed(); + Long beforeNetUsed = accountResource.getNetUsed(); + Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String filePath = "./src/test/resources/soliditycode/SolidityMappingFix.sol"; - String contractName = "Tests"; + String filePath = "./src/test/resources/soliditycode/SolidityMappingFix.sol"; + String contractName = "Tests"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -89,29 +111,39 @@ public void test01DeployContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - } - @Test(enabled = true, description = "Trigger contract,set balances[msg.sender]", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger contract,set balances[msg.sender]", + groups = {"contract", "daily"}) public void test02TriggerContract() { - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(dev001Key, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = accountResource.getEnergyUsed(); - Long beforeNetUsed = accountResource.getNetUsed(); - Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = accountResource.getEnergyUsed(); + Long beforeNetUsed = accountResource.getNetUsed(); + Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String methodStr = "update(uint256)"; - String argStr = "123"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodStr = "update(uint256)"; + String argStr = "123"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -122,9 +154,9 @@ public void test02TriggerContract() { } TransactionInfo transactionInfo = infoById.get(); logger.info("infoById" + infoById); - String ContractResult = + String ContractResult = ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); - String tmpAddress = + String tmpAddress = Base58.encode58Check(ByteArray.fromHexString("41" + ContractResult.substring(24))); Assert.assertEquals(WalletClient.encode58Check(dev001Address), tmpAddress); @@ -133,22 +165,29 @@ public void test02TriggerContract() { methodStr = "balances(address)"; argStr = "\"" + WalletClient.encode58Check(dev001Address) + "\""; - TransactionExtention return1 = PublicMethod - .triggerContractForExtention(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, "0", 0L, dev001Address, dev001Key, blockingStubFull); + TransactionExtention return1 = + PublicMethod.triggerContractForExtention( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + "0", + 0L, + dev001Address, + dev001Key, + blockingStubFull); logger.info("return1: " + return1); logger.info(Hex.toHexString(return1.getConstantResult(0).toByteArray())); - int ContractRestult = ByteArray.toInt(return1.getConstantResult(0).toByteArray()); + int ContractRestult = ByteArray.toInt(return1.getConstantResult(0).toByteArray()); Assert.assertEquals(123, ContractRestult); - } @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, - blockingStubFull); } + PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/MappingPopingTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/MappingPopingTest.java index b6aa8f15..840c5fe2 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/MappingPopingTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/MappingPopingTest.java @@ -13,57 +13,72 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class MappingPopingTest extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] contractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); } - @Test(enabled = true, description = "Deploy contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy contract", + groups = {"contract", "daily"}) public void test01DeployContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 1000_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1000_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(dev001Key, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = accountResource.getEnergyUsed(); - Long beforeNetUsed = accountResource.getNetUsed(); - Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = accountResource.getEnergyUsed(); + Long beforeNetUsed = accountResource.getNetUsed(); + Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String filePath = "./src/test/resources/soliditycode/TestMappings_array_pop.sol"; - String contractName = "C"; + String filePath = "./src/test/resources/soliditycode/TestMappings_array_pop.sol"; + String contractName = "C"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -78,13 +93,12 @@ public void test01DeployContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -93,13 +107,12 @@ public void test01DeployContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(dev001Key, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(dev001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -111,42 +124,64 @@ public void test01DeployContract() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "Trigger contract ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger contract ", + groups = {"contract", "daily"}) public void test02TriggerContract() { String methodStr = "n1(uint256,uint256)"; - String argStr = "1,1001"; - String txid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String argStr = "1,1001"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("trigger contract failed with message: " + infoById.get().getResMessage()); } logger.info("infoById" + infoById); } - @Test(enabled = true, description = "Trigger contract ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger contract ", + groups = {"contract", "daily"}) public void test03TriggerContract() { String methodStr = "p()"; - String argStr = ""; - String txid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String argStr = ""; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("trigger contract failed with message: " + infoById.get().getResMessage()); } logger.info("infoById" + infoById); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, - blockingStubFull); } + PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, blockingStubFull); + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NegativeArrayTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NegativeArrayTest.java index 379104a1..8e6c9bd4 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NegativeArrayTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NegativeArrayTest.java @@ -15,59 +15,81 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class NegativeArrayTest extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] contractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); } - @Test(enabled = true, description = "Deploy contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy contract", + groups = {"contract", "daily"}) public void test01DeployContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 1000_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 100_000_000L, - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1000_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 100_000_000L, + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(dev001Key, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = accountResource.getEnergyUsed(); - Long beforeNetUsed = accountResource.getNetUsed(); - Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = accountResource.getEnergyUsed(); + Long beforeNetUsed = accountResource.getNetUsed(); + Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String filePath = "./src/test/resources/soliditycode/negativeArray.sol"; - String contractName = "NegativeArray"; + String filePath = "./src/test/resources/soliditycode/negativeArray.sol"; + String contractName = "NegativeArray"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -82,13 +104,12 @@ public void test01DeployContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -97,13 +118,12 @@ public void test01DeployContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(dev001Key, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(dev001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -115,108 +135,158 @@ public void test01DeployContract() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - @Test(enabled = true, description = "Trigger contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger contract", + groups = {"contract", "daily"}) public void test02TriggerContract() { // get[2] String methodStr = "get(uint256)"; - String argStr = "2"; - String triggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String argStr = "2"; + String triggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("trigger contract failed with message: " + infoById.get().getResMessage()); } logger.info("infoById" + infoById); - String contractResult = + String contractResult = ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); logger.info("contractResult:" + contractResult); Assert.assertEquals(new BigInteger(contractResult, 16).intValue(), -3); - // get[1] + // get[1] String argStr1 = "1"; - String triggerTxid1 = PublicMethod.triggerContract(contractAddress, methodStr, argStr1, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String triggerTxid1 = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr1, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById1 = PublicMethod - .getTransactionInfoById(triggerTxid1, blockingStubFull); + Optional infoById1 = + PublicMethod.getTransactionInfoById(triggerTxid1, blockingStubFull); if (infoById1.get().getResultValue() != 0) { Assert.fail("trigger contract failed with message: " + infoById1.get().getResMessage()); } logger.info("infoById1" + infoById1); - String contractResult1 = + String contractResult1 = ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()); logger.info("contractResult1:" + contractResult1); Assert.assertEquals(new BigInteger(contractResult1, 16).intValue(), 2); - // change array value - String triggerTxid2 = PublicMethod.triggerContract(contractAddress, "set()", "", false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + // change array value + String triggerTxid2 = + PublicMethod.triggerContract( + contractAddress, + "set()", + "", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById2 = PublicMethod - .getTransactionInfoById(triggerTxid2, blockingStubFull); + Optional infoById2 = + PublicMethod.getTransactionInfoById(triggerTxid2, blockingStubFull); if (infoById2.get().getResultValue() != 0) { Assert.fail("trigger contract failed with message: " + infoById2.get().getResMessage()); } logger.info("infoById2" + infoById2); - String log1 = - ByteArray.toHexString(infoById2.get().getLog(0).getData().toByteArray()); + String log1 = ByteArray.toHexString(infoById2.get().getLog(0).getData().toByteArray()); logger.info("log1:" + log1); Assert.assertEquals(new BigInteger(log1, 16).intValue(), -1); - String log2 = ByteArray.toHexString(infoById2.get().getLog(1).getData().toByteArray()); + String log2 = ByteArray.toHexString(infoById2.get().getLog(1).getData().toByteArray()); logger.info("log2:" + log2); Assert.assertEquals(new BigInteger(log2, 16).intValue(), 3); - String log3 = - ByteArray.toHexString(infoById2.get().getLog(2).getData().toByteArray()); + String log3 = ByteArray.toHexString(infoById2.get().getLog(2).getData().toByteArray()); logger.info("log3:" + log3); Assert.assertEquals(new BigInteger(log3, 16).intValue(), -8); - // get[2] - String triggerTxid3 = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + // get[2] + String triggerTxid3 = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById3 = PublicMethod - .getTransactionInfoById(triggerTxid3, blockingStubFull); + Optional infoById3 = + PublicMethod.getTransactionInfoById(triggerTxid3, blockingStubFull); if (infoById3.get().getResultValue() != 0) { Assert.fail("trigger contract failed with message: " + infoById3.get().getResMessage()); } logger.info("infoById3" + infoById3); - String contractResult3 = + String contractResult3 = ByteArray.toHexString(infoById3.get().getContractResult(0).toByteArray()); logger.info("contractResult3:" + contractResult3); Assert.assertEquals(new BigInteger(contractResult3, 16).intValue(), -8); - // get[1] - String triggerTxid4 = PublicMethod.triggerContract(contractAddress, methodStr, argStr1, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + // get[1] + String triggerTxid4 = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr1, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById4 = PublicMethod - .getTransactionInfoById(triggerTxid4, blockingStubFull); + Optional infoById4 = + PublicMethod.getTransactionInfoById(triggerTxid4, blockingStubFull); if (infoById4.get().getResultValue() != 0) { Assert.fail("trigger contract failed with message: " + infoById4.get().getResMessage()); } logger.info("infoById4" + infoById4); - String contractResult4 = + String contractResult4 = ByteArray.toHexString(infoById4.get().getContractResult(0).toByteArray()); logger.info("contractResult4:" + contractResult4); Assert.assertEquals(new BigInteger(contractResult4, 16).intValue(), 3); - // get[3] - String triggerTxid5 = PublicMethod.triggerContract(contractAddress, methodStr, "3", false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + // get[3] + String triggerTxid5 = + PublicMethod.triggerContract( + contractAddress, + methodStr, + "3", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById5 = PublicMethod - .getTransactionInfoById(triggerTxid5, blockingStubFull); + Optional infoById5 = + PublicMethod.getTransactionInfoById(triggerTxid5, blockingStubFull); logger.info("infoById5" + infoById5); Assert.assertEquals(1, infoById5.get().getResultValue()); - Assert.assertEquals("REVERT opcode executed", infoById5.get() - .getResMessage().toStringUtf8()); + Assert.assertEquals("REVERT opcode executed", infoById5.get().getResMessage().toStringUtf8()); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, - blockingStubFull); } + PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc068.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc068.java index 5f2364fc..bf93957c 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc068.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc068.java @@ -14,222 +14,372 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class NewFeatureForSolc068 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] getSelectorContract = null; byte[] mapKeyContract = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 300100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 300100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/NewFeature068.sol"; - String contractName = "testMapKey"; + String filePath = "src/test/resources/soliditycode/NewFeature068.sol"; + String contractName = "testMapKey"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - mapKeyContract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + mapKeyContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(mapKeyContract, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(mapKeyContract, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - - @Test(enabled = true, description = "map with enum key", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "map with enum key", + groups = {"contract", "daily"}) public void test01MapWithEnumKey() { - String txid = PublicMethod.triggerContract(mapKeyContract, - "setEnumValue(uint256)", "1", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + mapKeyContract, + "setEnumValue(uint256)", + "1", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("txid: " + txid + "\n" + infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "getEnumValue()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "getEnumValue()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); Assert.assertEquals(1, trueRes); } - @Test(enabled = true, description = "map with contract key", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "map with contract key", + groups = {"contract", "daily"}) public void test02MapWithContractKey() { - String txid = PublicMethod.triggerContract(mapKeyContract, - "setContractValue()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + mapKeyContract, + "setContractValue()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("txid: " + txid + "\n" + infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "getContractValue()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "getContractValue()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); Assert.assertEquals(2, trueRes); } - @Test(enabled = true, description = "get function selector during compile period", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "get function selector during compile period", + groups = {"contract", "daily"}) public void test03GetSelectorDuringCompile() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "getfunctionSelector()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "getfunctionSelector()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - String trueRes = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + String trueRes = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); logger.info("trueRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); Assert.assertTrue(trueRes.startsWith("48593bae")); } - @Test(enabled = true, description = "test storage variable init before been used", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test storage variable init before been used", + groups = {"contract", "daily"}) public void test04StorageValInit() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "testStorage()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "testStorage()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - String trueRes = PublicMethod - .getContractStringMsg(transactionExtention.getConstantResult(0).toByteArray()); + String trueRes = + PublicMethod.getContractStringMsg(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); Assert.assertEquals("test", trueRes); } - @Test(enabled = true, description = "test immutable variable inited when declared", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test immutable variable inited when declared", + groups = {"contract", "daily"}) public void test05ImmutableInit() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "getOwner()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "getOwner()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - String trueRes = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + String trueRes = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); - Assert.assertEquals(ByteArray.toHexString(PublicMethod - .getFinalAddress(contractExcKey)).substring(2), trueRes.substring(24)); - + Assert.assertEquals( + ByteArray.toHexString(PublicMethod.getFinalAddress(contractExcKey)).substring(2), + trueRes.substring(24)); } - @Test(enabled = true, description = "test immutable variable inited in construct", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test immutable variable inited in construct", + groups = {"contract", "daily"}) public void test06ImmutableInit() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "getImmutableVal()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "getImmutableVal()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); Assert.assertEquals(5, trueRes); } - @Test(enabled = true, description = "get interface id," - + "interface id is result of all function selector's XOR ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "get interface id," + "interface id is result of all function selector's XOR ", + groups = {"contract", "daily"}) public void test07GetInterfaceId() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "getInterfaceId()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "getInterfaceId()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); - String trueRes = ByteArray.toHexString(ByteArray.subArray(result, 0, 4)); - String trueRes1 = ByteArray.toHexString(ByteArray.subArray(result, 32, 36)); - - logger.info("truerRes: " + trueRes + " truerRes1: " + trueRes1 - + " message:" + transaction.getRet(0).getRet()); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + String trueRes = ByteArray.toHexString(ByteArray.subArray(result, 0, 4)); + String trueRes1 = ByteArray.toHexString(ByteArray.subArray(result, 32, 36)); + + logger.info( + "truerRes: " + + trueRes + + " truerRes1: " + + trueRes1 + + " message:" + + transaction.getRet(0).getRet()); Assert.assertEquals("a9ab72bd", trueRes); Assert.assertEquals(trueRes, trueRes1); - } - @Test(enabled = true, description = "abstract contract can have vitrual modifier with empty body", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "abstract contract can have vitrual modifier with empty body", + groups = {"contract", "daily"}) public void test08VirtualModifier() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "requireOwner()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "requireOwner()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); - int trueRes = ByteArray.toInt(result); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + int trueRes = ByteArray.toInt(result); logger.info("truerRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); Assert.assertEquals(6, trueRes); - } - @Test(enabled = true, description = "uint256 max and mine", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "uint256 max and mine", + groups = {"contract", "daily"}) public void test09Uint256MaxMine() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "getUint256MinAndMax()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "getUint256MinAndMax()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); - String trueRes = ByteArray.toHexString(ByteArray.subArray(result, 0, 32)); - String trueRes1 = ByteArray.toHexString(ByteArray.subArray(result, 32, 64)); - logger.info("truerRes: " + trueRes + "truerRes1: " + trueRes1 - + " message:" + transaction.getRet(0).getRet()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", - trueRes); - Assert.assertEquals("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - trueRes1); - + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + String trueRes = ByteArray.toHexString(ByteArray.subArray(result, 0, 32)); + String trueRes1 = ByteArray.toHexString(ByteArray.subArray(result, 32, 64)); + logger.info( + "truerRes: " + + trueRes + + "truerRes1: " + + trueRes1 + + " message:" + + transaction.getRet(0).getRet()); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000000", trueRes); + Assert.assertEquals( + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", trueRes1); } - @Test(enabled = true, description = "solidity 0.6.12 test Reference " - + "variable can be marked by calldata", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "solidity 0.6.12 test Reference " + "variable can be marked by calldata", + groups = {"contract", "daily"}) public void test10CalldataModifier() { String hexAdd = ByteArray.toHexString(PublicMethod.getFinalAddress(contractExcKey)); - String args = "\"0x" + hexAdd + "\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "calldataModifier(bytes)", args, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String args = "\"0x" + hexAdd + "\""; + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "calldataModifier(bytes)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); - String trueRes = ByteArray.toHexString(result); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + String trueRes = ByteArray.toHexString(result); logger.info("truerRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); Assert.assertTrue(trueRes.contains(hexAdd)); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc076.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc076.java index c295cfa1..56100000 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc076.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc076.java @@ -13,87 +13,126 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class NewFeatureForSolc076 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] mapKeyContract = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 300100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 300100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/NewFeature076.sol"; - String contractName = "C"; + String filePath = "src/test/resources/soliditycode/NewFeature076.sol"; + String contractName = "C"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - mapKeyContract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + mapKeyContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(mapKeyContract, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(mapKeyContract, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - - @Test(enabled = true, description = "call method outside contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "call method outside contract", + groups = {"contract", "daily"}) public void test01CallOutsideMethod() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "getOutsideMethod()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "getOutsideMethod()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); Assert.assertEquals(1, trueRes); } - @Test(enabled = true, description = "get abstract contract and interface name", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "get abstract contract and interface name", + groups = {"contract", "daily"}) public void test02GetTypeName() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "getAbstractName()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "getAbstractName()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - String trueRes = ByteArray.toStr(transactionExtention.getConstantResult(0).toByteArray()); + String trueRes = ByteArray.toStr(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); Assert.assertTrue(trueRes.contains("abvd")); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "getInterfaceName()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "getInterfaceName()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); transaction = transactionExtention.getTransaction(); trueRes = ByteArray.toStr(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); Assert.assertTrue(trueRes.contains("qwer")); - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc080.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc080.java index c6774b0a..276c78db 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc080.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc080.java @@ -15,265 +15,449 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class NewFeatureForSolc080 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] mapKeyContract = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 300100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 300100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/NewFeature080.sol"; - String contractName = "C"; + String filePath = "src/test/resources/soliditycode/NewFeature080.sol"; + String contractName = "C"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - mapKeyContract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 5000000L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + mapKeyContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 5000000L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(mapKeyContract, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(mapKeyContract, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - - @Test(enabled = true, description = "math sub without unchecked, transaction revert", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "math sub without unchecked, transaction revert", + groups = {"contract", "daily"}) public void test01MathSubNoUncheck() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "subNoUncheck()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("REVERT opcode executed", - transactionExtention.getResult().getMessage().toStringUtf8()); - Assert.assertEquals("FAILED", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "subNoUncheck()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "REVERT opcode executed", transactionExtention.getResult().getMessage().toStringUtf8()); + Assert.assertEquals( + "FAILED", transactionExtention.getTransaction().getRet(0).getRet().toString()); } - @Test(enabled = true, description = "math sub with uncheck,transaction success", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "math sub with uncheck,transaction success", + groups = {"contract", "daily"}) public void test02SubWithUncheck() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "subWithUncheck()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "subWithUncheck()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(255, trueRes); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertTrue(transactionExtention.getEnergyUsed() > 300); - } - @Test(enabled = true, description = "math add overflow without unchecked, transaction revert", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "math add overflow without unchecked, transaction revert", + groups = {"contract", "daily"}) public void test03MathAddNoUncheck() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "addNoUncheck()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("REVERT opcode executed", - transactionExtention.getResult().getMessage().toStringUtf8()); - Assert.assertEquals("FAILED", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "addNoUncheck()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "REVERT opcode executed", transactionExtention.getResult().getMessage().toStringUtf8()); + Assert.assertEquals( + "FAILED", transactionExtention.getTransaction().getRet(0).getRet().toString()); } - @Test(enabled = true, description = "math divide zero without unchecked, transaction revert", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "math divide zero without unchecked, transaction revert", + groups = {"contract", "daily"}) public void test04DivideZeroNoUncheck() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "divideZeroNoUncheck()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("REVERT opcode executed", - transactionExtention.getResult().getMessage().toStringUtf8()); - Assert.assertEquals("FAILED", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "divideZeroNoUncheck()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "REVERT opcode executed", transactionExtention.getResult().getMessage().toStringUtf8()); + Assert.assertEquals( + "FAILED", transactionExtention.getTransaction().getRet(0).getRet().toString()); } - @Test(enabled = true, description = "assert fail without unchecked, transaction revert", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "assert fail without unchecked, transaction revert", + groups = {"contract", "daily"}) public void test05AssertFailNoUncheck() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "assertFailNoUncheck()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("REVERT opcode executed", - transactionExtention.getResult().getMessage().toStringUtf8()); - Assert.assertEquals("FAILED", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "assertFailNoUncheck()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "REVERT opcode executed", transactionExtention.getResult().getMessage().toStringUtf8()); + Assert.assertEquals( + "FAILED", transactionExtention.getTransaction().getRet(0).getRet().toString()); } - @Test(enabled = true, description = "array out of index without unchecked, transaction revert", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "array out of index without unchecked, transaction revert", + groups = {"contract", "daily"}) public void test06AssertFailNoUncheck() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "arrayOutofIndex()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Assert.assertEquals("REVERT opcode executed", - transactionExtention.getResult().getMessage().toStringUtf8()); - Assert.assertEquals("FAILED", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "arrayOutofIndex()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Assert.assertEquals( + "REVERT opcode executed", transactionExtention.getResult().getMessage().toStringUtf8()); + Assert.assertEquals( + "FAILED", transactionExtention.getTransaction().getRet(0).getRet().toString()); } - @Test(enabled = true, description = "type convert", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "type convert", + groups = {"contract", "daily"}) public void test07TypeConvert() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "typeConvert()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "typeConvert()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(65535, trueRes); - Assert.assertEquals(true, - transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals(true, transactionExtention.getResult().getResult()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } - @Test(enabled = true, description = "power multi by default turn: right to left", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "power multi by default turn: right to left", + groups = {"contract", "daily"}) public void test08PowerMultiRightToLeft() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "powerMultiRightToLeft()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "powerMultiRightToLeft()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(2, trueRes); - Assert.assertEquals(true, - transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals(true, transactionExtention.getResult().getResult()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } - @Test(enabled = true, description = "power multi: left to right ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "power multi: left to right ", + groups = {"contract", "daily"}) public void test09PowerMultiLeftToRight() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "powerMultiLeftToRight()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "powerMultiLeftToRight()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(64, trueRes); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } - @Test(enabled = true, description = "power multi with 2 params ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "power multi with 2 params ", + groups = {"contract", "daily"}) public void test10PowerMultiWith2Params() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "powerMultiWith2Params()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "powerMultiWith2Params()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(8, trueRes); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } - @Test(enabled = true, description = "get block chain id ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "get block chain id ", + groups = {"contract", "daily"}) public void test11GetBlockChainId() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "getBlockChainId()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - String chainId = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); - logger.info("chainId: " + chainId); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "getBlockChainId()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + String chainId = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + logger.info("chainId: " + chainId); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } - @Test(enabled = true, description = "get normal account address hashcode ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "get normal account address hashcode ", + groups = {"contract", "daily"}) public void test12GetAccountHashCode() { String argStr = "\"" + Base58.encode58Check(contractExcAddress) + "\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "getAddressCodehash(address)", argStr, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "getAddressCodehash(address)", + argStr, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info(transactionExtention.toString()); - String trueRes = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + String trueRes = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); logger.info("0000000: " + trueRes); } - @Test(enabled = true, description = "get contract address hashcode ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "get contract address hashcode ", + groups = {"contract", "daily"}) public void test13GetContractAddressHashCode() { String argStr = "\"" + Base58.encode58Check(mapKeyContract) + "\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "getAddressCodehash(address)", argStr, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "getAddressCodehash(address)", + argStr, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); logger.info(transactionExtention.toString()); - String trueRes = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + String trueRes = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); logger.info("0000000: " + trueRes); } - @Test(enabled = true, description = "transfer trx to tx.origin address with payable", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "transfer trx to tx.origin address with payable", + groups = {"contract", "daily"}) public void test14TransferToTxoriginAddress() { Protocol.Account info = PublicMethod.queryAccount(mapKeyContract, blockingStubFull); - Long beforeBalance = info.getBalance(); + Long beforeBalance = info.getBalance(); logger.info("beforeBalance: " + beforeBalance); - String methodStr = "transferToTxorigin(uint64)"; - String triggerTxid = PublicMethod.triggerContract(mapKeyContract, methodStr, "1000000", false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String methodStr = "transferToTxorigin(uint64)"; + String triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + methodStr, + "1000000", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); info = PublicMethod.queryAccount(mapKeyContract, blockingStubFull); - Long afterBalance = info.getBalance(); + Long afterBalance = info.getBalance(); logger.info("afterBalance: " + afterBalance); Assert.assertTrue(beforeBalance == afterBalance + 1000000); } - @Test(enabled = true, description = "transfer trx to literal address with payable", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "transfer trx to literal address with payable", + groups = {"contract", "daily"}) public void test15TransferToLiteralAddress() { Protocol.Account info = PublicMethod.queryAccount(mapKeyContract, blockingStubFull); - Long beforeBalance = info.getBalance(); + Long beforeBalance = info.getBalance(); logger.info("beforeBalance: " + beforeBalance); - String methodStr = "transferToLiteralAddress(uint64)"; - String triggerTxid = PublicMethod.triggerContract(mapKeyContract, methodStr, "1000000", false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String methodStr = "transferToLiteralAddress(uint64)"; + String triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + methodStr, + "1000000", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); info = PublicMethod.queryAccount(mapKeyContract, blockingStubFull); - Long afterBalance = info.getBalance(); + Long afterBalance = info.getBalance(); logger.info("afterBalance: " + afterBalance); Assert.assertTrue(beforeBalance == afterBalance + 1000000); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0811.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0811.java index dc6226f5..9e0bfe6f 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0811.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0811.java @@ -12,126 +12,204 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class NewFeatureForSolc0811 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] mapKeyContract = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 300100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 300100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/NewFeature0811.sol"; - String contractName = "C"; + String filePath = "src/test/resources/soliditycode/NewFeature0811.sol"; + String contractName = "C"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - mapKeyContract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + mapKeyContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(mapKeyContract, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(mapKeyContract, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "Get enum.min or enum.max", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Get enum.min or enum.max", + groups = {"contract", "daily"}) public void test001GetEnumMinOrMax() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "getEnumMin()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "getEnumMin()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(0, result); - - transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "getEnumMax()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "getEnumMax()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(3, result); - } - - @Test(enabled = true,description = "User defined type of data", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "User defined type of data", + groups = {"contract", "daily"}) public void test002SupportUserDefinedTypeOfData() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "getUserDefinedValue()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "getUserDefinedValue()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(45, result); } - - @Test(enabled = true,description = "Get assembly address", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Get assembly address", + groups = {"contract", "daily"}) public void test003GetAssemblyAddress() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "testGetAddress()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "testGetAddress()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertTrue(ByteArray.toHexString(transactionExtention.getConstantResult(0) - .toByteArray()).contains(ByteArray.toHexString(mapKeyContract).substring(2))); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertTrue( + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()) + .contains(ByteArray.toHexString(mapKeyContract).substring(2))); } - - @Test(enabled = true,description = "Get assembly selector", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Get assembly selector", + groups = {"contract", "daily"}) public void test004GetAssemblySelector() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "testGetSelector()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "testGetSelector()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); long result = ByteArray.toLong(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(3781905051L, result); } - - @Test(enabled = true,description = "Get ABI-Encode calldata", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Get ABI-Encode calldata", + groups = {"contract", "daily"}) public void test005GetAbiEncodedCalldata() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "fSignatureFromLiteralCall()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "fSignatureFromLiteralCall()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("" + Assert.assertEquals( + "" + "0000000000000000000000000000000000000000000000000000000000000020" + "0000000000000000000000000000000000000000000000000000000000000084" + "33d8581000000000000000000000000000000000000000000000000000000000" @@ -142,60 +220,84 @@ public void test005GetAbiEncodedCalldata() { ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); } - - @Test(enabled = true,description = "Support constructor read immutable value", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Support constructor read immutable value", + groups = {"contract", "daily"}) public void test006SupportConstructorReadImmutableValue() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "readX()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "readX()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(33, result); - - transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "readI()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "readI()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(33, result); - - } - - @Test(enabled = true,description = "Fix immutable symbol bug", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Fix immutable symbol bug", + groups = {"contract", "daily"}) public void test007FixImmutableSymbol() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "fixBugTest()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "fixBugTest()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc", + Assert.assertEquals( + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0817.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0817.java index ce89bc11..2f64acd5 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0817.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0817.java @@ -1,5 +1,6 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.newGrammar; +import java.util.HashMap; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.testng.annotations.AfterClass; @@ -9,323 +10,545 @@ import org.tron.protos.Protocol; import org.tron.protos.contract.SmartContractOuterClass; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; - -import java.util.HashMap; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class NewFeatureForSolc0817 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] mapKeyContract = null; byte[] useForContract = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 300100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 300100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/NewFeature0817.sol"; - String contractName = "C"; + String filePath = "src/test/resources/soliditycode/NewFeature0817.sol"; + String contractName = "C"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - mapKeyContract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + mapKeyContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(mapKeyContract, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(mapKeyContract, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "test equality-comparison operators for external function types", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test equality-comparison operators for external function types", + groups = {"contract", "daily"}) public void test001EqualComparisonForFunction() { - String txid = PublicMethod.triggerContract(mapKeyContract, "comparison_operators_for_local_external_function_pointers()", "#", - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + mapKeyContract, + "comparison_operators_for_local_external_function_pointers()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, info.getResult()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); Assert.assertEquals(1, ByteArray.toInt(info.getContractResult(0).toByteArray())); - } - - @Test(enabled = true, description = "test ContractName.functionName for abi.encodeCall," - + " in addition to external function pointers", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "test ContractName.functionName for abi.encodeCall," + + " in addition to external function pointers", + groups = {"contract", "daily"}) public void test002SupportUserDefinedTypeOfData() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "test_function_name_for_abi_encodeCall()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "test_function_name_for_abi_encodeCall()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(11116, result); } - - @Test(enabled = true, description = "using M for Type; is allowed at file level free function", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "using M for Type; is allowed at file level free function", + groups = {"contract", "daily"}) public void test003UseForFreeFunction() { String filePath = "src/test/resources/soliditycode/NewFeature0817_1.sol"; - String contractName = "Lib"; + String contractName = "Lib"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] libAdd = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, contractExcAddress, - blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] libAdd = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath1 = "src/test/resources/soliditycode/NewFeature0817_2.sol"; - String contractName1 = "C"; + String filePath1 = "src/test/resources/soliditycode/NewFeature0817_2.sol"; + String contractName1 = "C"; HashMap retMap1 = PublicMethod.getBycodeAbiForLibrary(filePath1, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - String library = retMap1.get("library").toString(); - String libraryAddress = library + Base58.encode58Check(libAdd); - String compilerVersion = Configuration.getByPath("testng.conf") - .getString("defaultParameter.solidityCompilerVersion"); - useForContract = PublicMethod - .deployContractForLibrary(contractName1, abi1, code1, "", maxFeeLimit, - 0L, 100, libraryAddress, contractExcKey, contractExcAddress, - compilerVersion, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String library = retMap1.get("library").toString(); + String libraryAddress = library + Base58.encode58Check(libAdd); + String compilerVersion = + Configuration.getByPath("testng.conf") + .getString("defaultParameter.solidityCompilerVersion"); + useForContract = + PublicMethod.deployContractForLibrary( + contractName1, + abi1, + code1, + "", + maxFeeLimit, + 0L, + 100, + libraryAddress, + contractExcKey, + contractExcAddress, + compilerVersion, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(useForContract, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(useForContract, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(useForContract, - "g(uint256)", "3", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int result1 = ByteArray.toInt(transactionExtention - .getConstantResult(0).substring(0, 32).toByteArray()); - int result2 = ByteArray.toInt(transactionExtention - .getConstantResult(0).substring(32, 64).toByteArray()); - int result3 = ByteArray.toInt(transactionExtention - .getConstantResult(0).substring(64, 96).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + useForContract, + "g(uint256)", + "3", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int result1 = + ByteArray.toInt(transactionExtention.getConstantResult(0).substring(0, 32).toByteArray()); + int result2 = + ByteArray.toInt(transactionExtention.getConstantResult(0).substring(32, 64).toByteArray()); + int result3 = + ByteArray.toInt(transactionExtention.getConstantResult(0).substring(64, 96).toByteArray()); Assert.assertEquals(0, result1); Assert.assertEquals(3, result2); Assert.assertEquals(4, result3); } - @Test(enabled = true, description = "using M for Type; is allowed at file level lib function", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "using M for Type; is allowed at file level lib function", + groups = {"contract", "daily"}) public void test004UseForLibFunction() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(useForContract, - "f(uint256)", "3", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int result1 = ByteArray.toInt(transactionExtention - .getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + useForContract, + "f(uint256)", + "3", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int result1 = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(3, result1); } - - @Test(enabled = true, description = "using M for Type; is allowed at file level with global", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "using M for Type; is allowed at file level with global", + groups = {"contract", "daily"}) public void test005UseForGlobal() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(useForContract, - "glob()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int result1 = ByteArray.toInt(transactionExtention - .getConstantResult(0).substring(0, 32).toByteArray()); - int result2 = ByteArray.toInt(transactionExtention - .getConstantResult(0).substring(32, 64).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + useForContract, + "glob()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int result1 = + ByteArray.toInt(transactionExtention.getConstantResult(0).substring(0, 32).toByteArray()); + int result2 = + ByteArray.toInt(transactionExtention.getConstantResult(0).substring(32, 64).toByteArray()); System.out.println(result1 + " : " + result2); Assert.assertEquals(2, result1); Assert.assertEquals(1, result2); } - @Test(enabled = true, description = "test event.selector", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test event.selector", + groups = {"contract", "daily"}) public void test006EventSelector() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "eventSelector()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - String result1 = ByteArray.toHexString(transactionExtention - .getConstantResult(0).toByteArray()); - Assert.assertEquals("92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028", result1); - + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "eventSelector()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + String result1 = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + Assert.assertEquals( + "92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028", result1); } - @Test(enabled = true, description = "Support using library constants in initializers of other constants", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Support using library constants in initializers of other constants", + groups = {"contract", "daily"}) public void test007InitConstantsUseLibConstants() { String filePath = "src/test/resources/soliditycode/NewFeature0817_3.sol"; - String contractName = "C1"; + String contractName = "C1"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] consCon = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] consCon = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(mapKeyContract, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(mapKeyContract, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(consCon, - "LIMIT()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int result1 = ByteArray.toInt(transactionExtention - .getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + consCon, + "LIMIT()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int result1 = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); System.out.println(result1); Assert.assertEquals(100, result1); } - @Test(enabled = true, description = "Correctly encode literals used in ``abi.encodeCall`` in place of fixed bytes arguments", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Correctly encode literals used in ``abi.encodeCall`` in place of fixed bytes arguments", + groups = {"contract", "daily"}) public void test008BugFixAbiEncodeCall() { String filePath = "src/test/resources/soliditycode/NewFeature0817_4bugFix.sol"; - String contractName = "C"; + String contractName = "C"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] consCon = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] consCon = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(consCon, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(consCon, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(consCon, - "f()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - String result1 = ByteArray.toHexString(transactionExtention - .getConstantResult(0).toByteArray()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000020" - + "0000000000000000000000000000000000000000000000000000000000000060" - + "1234000000000000000000000000000000000000000000000000000000000000" - + "6162000000000000000000000000000000000000000000000000000000000000" - + "1234000000000000000000000000000000000000000000000000000000000000", result1); - - transactionExtention = PublicMethod - .triggerConstantContractForExtention(consCon, - "f2()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - - result1 = ByteArray.toHexString(transactionExtention - .getConstantResult(0).toByteArray()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000020" - + "0000000000000000000000000000000000000000000000000000000000000040" - + "0000000000000000000000000000000000000000000000000000000000001234" - + "0000000000000000000000000000000000000000000000000000000000001234", result1); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + consCon, + "f()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + String result1 = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000020" + + "0000000000000000000000000000000000000000000000000000000000000060" + + "1234000000000000000000000000000000000000000000000000000000000000" + + "6162000000000000000000000000000000000000000000000000000000000000" + + "1234000000000000000000000000000000000000000000000000000000000000", + result1); + + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + consCon, + "f2()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + + result1 = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000020" + + "0000000000000000000000000000000000000000000000000000000000000040" + + "0000000000000000000000000000000000000000000000000000000000001234" + + "0000000000000000000000000000000000000000000000000000000000001234", + result1); } - - @Test(enabled = true, description = "wallet-cli cannot process fixed lend array, so this case is disable", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "wallet-cli cannot process fixed lend array, so this case is disable", + groups = {"contract", "daily"}) public void test009BugFixStaticArray() { String filePath = "src/test/resources/soliditycode/NewFeature0817_4bugFix.sol"; - String contractName = "D"; + String contractName = "D"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] consCon = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] consCon = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(consCon, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(consCon, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(consCon, - "g(uint256[],uint256[1])", "[65535],[255]", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - String result1 = ByteArray.toHexString(transactionExtention - .getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + consCon, + "g(uint256[],uint256[1])", + "[65535],[255]", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + String result1 = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); System.out.println(result1); -// Assert.assertEquals("", result1); + // Assert.assertEquals("", result1); } - @Test(enabled = true, description = "", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "", + groups = {"contract", "daily"}) public void test010BugDirtyBytes() { String filePath = "src/test/resources/soliditycode/NewFeature0817_4bugFix.sol"; - String contractName = "E"; + String contractName = "E"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] consCon = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] consCon = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(consCon, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(consCon, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(consCon, - "h()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - String result1 = ByteArray.toHexString(transactionExtention - .getConstantResult(0).toByteArray()); -// System.out.println(result1); - Assert.assertEquals("000000000000000000000000000000000000000" - + "00000000000000000000000200000000000000000000000000000000000000000" - + "00000000000000000000004000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "00000000000000000000000", result1); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + consCon, + "h()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + String result1 = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + // System.out.println(result1); + Assert.assertEquals( + "000000000000000000000000000000000000000" + + "00000000000000000000000200000000000000000000000000000000000000000" + + "00000000000000000000004000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "00000000000000000000000", + result1); } - @Test(enabled = true, description = "", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "", + groups = {"contract", "daily"}) public void test011BugOverrideMemory2calldata() { String filePath = "src/test/resources/soliditycode/NewFeature0817_4bugFix.sol"; - String contractName = "M"; + String contractName = "M"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] consCon = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] consCon = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(consCon, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(consCon, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(consCon, - "g(uint256[])", "[9,8]", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - String result1 = ByteArray.toHexString(transactionExtention - .getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + consCon, + "g(uint256[])", + "[9,8]", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + String result1 = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); System.out.println(result1); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000020" - + "0000000000000000000000000000000000000000000000000000000000000002" - + "0000000000000000000000000000000000000000000000000000000000000009" - + "0000000000000000000000000000000000000000000000000000000000000008", result1); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000020" + + "0000000000000000000000000000000000000000000000000000000000000002" + + "0000000000000000000000000000000000000000000000000000000000000009" + + "0000000000000000000000000000000000000000000000000000000000000008", + result1); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0818.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0818.java index 88702654..204f12f4 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0818.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0818.java @@ -1,5 +1,6 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.newGrammar; +import java.util.HashMap; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.testng.annotations.AfterClass; @@ -9,97 +10,138 @@ import org.tron.protos.Protocol; import org.tron.protos.contract.SmartContractOuterClass; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; - -import java.util.HashMap; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class NewFeatureForSolc0818 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] mapKeyContract = null; byte[] useForContract = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 300100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 300100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/NewFeature0818.sol"; - String contractName = "C"; + String filePath = "src/test/resources/soliditycode/NewFeature0818.sol"; + String contractName = "C"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - mapKeyContract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + mapKeyContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(mapKeyContract, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(mapKeyContract, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "test named parameters in mapping types", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test named parameters in mapping types", + groups = {"contract", "daily"}) public void test001NamedParamsInMapping() { String temAdd = Base58.encode58Check(mapKeyContract); - String txid = PublicMethod.triggerContract(mapKeyContract, - "add(address,uint256)", "\"" + temAdd + "\",6", - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + mapKeyContract, + "add(address,uint256)", + "\"" + temAdd + "\",6", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info(info.toString()); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, info.getResult()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, info.getReceipt().getResult()); Assert.assertEquals(6, ByteArray.toInt(info.getContractResult(0).toByteArray())); - } - - @Test(enabled = true, description = "test block.prevrandao, this replaces block.difficulty ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test block.prevrandao, this replaces block.difficulty ", + groups = {"contract", "daily"}) public void test002blockPrevrandao() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "prevrandao()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "prevrandao()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(0, result); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "assemblyPrevrandao()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "assemblyPrevrandao()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(0, result); - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0820.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0820.java index eb299ddd..05174c02 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0820.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0820.java @@ -1,5 +1,8 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.newGrammar; +import java.io.BufferedReader; +import java.io.FileReader; +import java.util.HashMap; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.testng.annotations.AfterClass; @@ -9,18 +12,18 @@ import org.tron.protos.Protocol; import org.tron.protos.contract.SmartContractOuterClass; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; - -import java.io.BufferedReader; -import java.io.FileReader; -import java.util.HashMap; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class NewFeatureForSolc0820 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contract1 = null; byte[] contract2 = null; @@ -29,43 +32,76 @@ public class NewFeatureForSolc0820 extends TronBaseTest { ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 300100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 300100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/NewFeature0820_1.sol"; - String contractName = "C"; + String filePath = "src/test/resources/soliditycode/NewFeature0820_1.sol"; + String contractName = "C"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contract1 = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contract1 = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull); filePath = "src/test/resources/soliditycode/NewFeature0820_2.sol"; contractName = "D"; retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - contract2 = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contract2 = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); filePath = "src/test/resources/soliditycode/NewFeature0820_3.sol"; contractName = "L"; retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - lib = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + lib = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); filePath = "src/test/resources/soliditycode/NewFeature0820_3.sol"; @@ -73,18 +109,29 @@ public void beforeClass() { retMap = PublicMethod.getBycodeAbiForLibrary(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - String library = retMap.get("library").toString(); - String libraryAddress = library + Base58.encode58Check(lib); - String compilerVersion = Configuration.getByPath("testng.conf") - .getString("defaultParameter.solidityCompilerVersion"); - contract3 = PublicMethod - .deployContractForLibrary(contractName, abi, code, "", maxFeeLimit, - 0L, 100, libraryAddress, contractExcKey, contractExcAddress, - compilerVersion, blockingStubFull); + String library = retMap.get("library").toString(); + String libraryAddress = library + Base58.encode58Check(lib); + String compilerVersion = + Configuration.getByPath("testng.conf") + .getString("defaultParameter.solidityCompilerVersion"); + contract3 = + PublicMethod.deployContractForLibrary( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + libraryAddress, + contractExcKey, + contractExcAddress, + compilerVersion, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(contract1, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(contract1, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); smartContract = PublicMethod.getContract(contract2, blockingStubFull); @@ -94,105 +141,184 @@ public void beforeClass() { Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "test using for T global inside sol", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test using for T global inside sol", + groups = {"contract", "daily"}) public void test001UsingForInsideSol() { String args = "1,2"; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contract1,"pick(uint8,uint8)", args, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contract1, + "pick(uint8,uint8)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(1, result); } - @Test(enabled = true, description = "test using for T global beside sol", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test using for T global beside sol", + groups = {"contract", "daily"}) public void test002UsingForBesideSol() { String args = "3,2"; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contract2,"getFirstParam(uint8,uint8)", args, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contract2, + "getFirstParam(uint8,uint8)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(3, result); } - @Test(enabled = true, description = "test external library functions in ``using for``", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test external library functions in ``using for``", + groups = {"contract", "daily"}) public void test003ExternalLibFunctionInUsingFor() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contract3,"f()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contract3, + "f()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(1, result); } - @Test(enabled = true, description = "test public library functions in ``using for`` ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test public library functions in ``using for`` ", + groups = {"contract", "daily"}) public void test004PublicLibFunctionInUsingFor() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contract3,"g()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contract3, + "g()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(2, result); } - @Test(enabled = true, description = "test internal library functions in ``using for`` ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test internal library functions in ``using for`` ", + groups = {"contract", "daily"}) public void test005ExternalLibFunctionInUsingFor() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contract3,"h()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contract3, + "h()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(3, result); } - @Test(enabled = true, description = "emit event by a contract but defined outside of it.", groups = {"contract", "daily"}) - public void test006EventDefinedOutsideOfContract() throws Exception{ - String txid = PublicMethod - .triggerContract(contract3,"i()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + @Test( + enabled = true, + description = "emit event by a contract but defined outside of it.", + groups = {"contract", "daily"}) + public void test006EventDefinedOutsideOfContract() throws Exception { + String txid = + PublicMethod.triggerContract( + contract3, + "i()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); - String topic1 = ByteArray.toHexString(info.getLog(0).getTopics(0).toByteArray()); - String topic2 = ByteArray.toHexString(info.getLog(1).getTopics(0).toByteArray()); - Assert.assertEquals(topic1, "92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028"); //E() Keccak256 - Assert.assertEquals(topic2, "70a5d861ef9816388422765f41d618eb3abdf490acb37354b539729e37b09f0e"); //H() Keccak256 + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + String topic1 = ByteArray.toHexString(info.getLog(0).getTopics(0).toByteArray()); + String topic2 = ByteArray.toHexString(info.getLog(1).getTopics(0).toByteArray()); + Assert.assertEquals( + topic1, + "92bbf6e823a631f3c8e09b1c8df90f378fb56f7fbc9701827e1ff8aad7f6a028"); // E() Keccak256 + Assert.assertEquals( + topic2, + "70a5d861ef9816388422765f41d618eb3abdf490acb37354b539729e37b09f0e"); // H() Keccak256 - //ABI: Include events in the ABI that are emitted by a contract but defined outside of it. + // ABI: Include events in the ABI that are emitted by a contract but defined outside of it. String filePath = "src/test/resources/soliditycode/output/NewFeature0820_3/C.abi"; StringBuilder builder = readFile(filePath); Assert.assertTrue(builder.toString().contains("\"name\":\"E\"")); } - public StringBuilder readFile(String fileName) throws Exception{ + public StringBuilder readFile(String fileName) throws Exception { BufferedReader br = new BufferedReader(new FileReader(fileName)); StringBuilder builder = new StringBuilder(); - String str; - while((str = br.readLine())!=null){ + String str; + while ((str = br.readLine()) != null) { builder.append(str); } br.close(); return builder; } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0821.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0821.java index e0919bc0..ff71dbd6 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0821.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0821.java @@ -1,5 +1,7 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.newGrammar; +import java.util.HashMap; +import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.testng.annotations.AfterClass; @@ -12,17 +14,14 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - -import java.util.HashMap; -import java.util.Optional; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class NewFeatureForSolc0821 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractH = null; byte[] contractC = null; @@ -31,162 +30,281 @@ public class NewFeatureForSolc0821 extends TronBaseTest { ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 50100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 50100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/NewFeature0821_1.sol"; - String contractName = "H"; + String filePath = "src/test/resources/soliditycode/NewFeature0821_1.sol"; + String contractName = "H"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractH = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractH = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); contractName = "C"; retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - contractC = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - + contractC = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(contractH, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(contractH, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); smartContract = PublicMethod.getContract(contractC, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "expressions triggering selector can be executed correctly", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "expressions triggering selector can be executed correctly", + groups = {"contract", "daily"}) public void test001ExpressionsTriggerSelector() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractH,"f()", "", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractH, + "f()", + "", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(42, result); } - @Test(enabled = true, description = "Allow qualified access to events from other contracts.", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Allow qualified access to events from other contracts.", + groups = {"contract", "daily"}) public void test002AccessForeignEvent() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractC,"f()", "", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractC, + "f()", + "", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(4, transactionExtention.getLogsList().size()); - Assert.assertEquals(transactionExtention.getLogs(0).toString(), - transactionExtention.getLogs(1).toString()); - Assert.assertEquals(transactionExtention.getLogs(0).toString(), - transactionExtention.getLogs(2).toString()); - Assert.assertEquals(transactionExtention.getLogs(0).toString(), - transactionExtention.getLogs(3).toString()); - Assert.assertEquals("39cf8f4d81ddb7c9a936f0fa76190b3d8084a8c21c154d4b02236a58b3051ad9", - ByteArray.toHexString(transactionExtention.getLogs(1).getData().substring(0, 32).toByteArray())); - Assert.assertEquals(1, - ByteArray.toInt(transactionExtention.getLogs(1).getData().substring(32, 64).toByteArray())); - Assert.assertEquals(123, - ByteArray.toInt(transactionExtention.getLogs(1).getData().substring(64).toByteArray())); + Assert.assertEquals( + transactionExtention.getLogs(0).toString(), transactionExtention.getLogs(1).toString()); + Assert.assertEquals( + transactionExtention.getLogs(0).toString(), transactionExtention.getLogs(2).toString()); + Assert.assertEquals( + transactionExtention.getLogs(0).toString(), transactionExtention.getLogs(3).toString()); + Assert.assertEquals( + "39cf8f4d81ddb7c9a936f0fa76190b3d8084a8c21c154d4b02236a58b3051ad9", + ByteArray.toHexString( + transactionExtention.getLogs(1).getData().substring(0, 32).toByteArray())); + Assert.assertEquals( + 1, + ByteArray.toInt(transactionExtention.getLogs(1).getData().substring(32, 64).toByteArray())); + Assert.assertEquals( + 123, + ByteArray.toInt(transactionExtention.getLogs(1).getData().substring(64).toByteArray())); } - @Test(enabled = true, description = "immutable variable init in condition", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "immutable variable init in condition", + groups = {"contract", "daily"}) public void test003ImmutableInitInCondition() { - String filePath = "src/test/resources/soliditycode/NewFeature0821_1.sol";; - String contractName = "K"; + String filePath = "src/test/resources/soliditycode/NewFeature0821_1.sol"; + ; + String contractName = "K"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String constructorStr = "constructor(bool,uint256)"; - String argsStr = "true,2"; - String deplTxid = PublicMethod.deployContractWithConstantParame(contractName, abi, code, - constructorStr, argsStr, "", maxFeeLimit, 0L, 100,1000L, - "0", 0L, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String constructorStr = "constructor(bool,uint256)"; + String argsStr = "true,2"; + String deplTxid = + PublicMethod.deployContractWithConstantParame( + contractName, + abi, + code, + constructorStr, + argsStr, + "", + maxFeeLimit, + 0L, + 100, + 1000L, + "0", + 0L, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = PublicMethod - .getTransactionInfoById(deplTxid, blockingStubFull); + Optional info = + PublicMethod.getTransactionInfoById(deplTxid, blockingStubFull); Assert.assertTrue(info.get().getResultValue() == 0); contractK = info.get().getContractAddress().toByteArray(); - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractK,"x()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractK, + "x()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(42, result); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractK,"y()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractK, + "y()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(0, result); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractK,"z()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractK, + "z()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(42, result); } - @Test(enabled = true, description = "immutable variable init in try catch", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "immutable variable init in try catch", + groups = {"contract", "daily"}) public void test004ImmutableInitInTryCatch() { - String filePath = "src/test/resources/soliditycode/NewFeature0821_2.sol";; - String contractName = "A"; + String filePath = "src/test/resources/soliditycode/NewFeature0821_2.sol"; + ; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] contractA = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(contractA, + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractA = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethod.waitProduceNextBlock(blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(contractA, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); smartContract = PublicMethod.getContract(contractA, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractA,"variable()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractA, + "variable()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(5, result); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0822.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0822.java index 2fac1005..0af9aab7 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0822.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0822.java @@ -1,5 +1,6 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.newGrammar; +import java.util.HashMap; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.testng.annotations.AfterClass; @@ -11,16 +12,14 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - -import java.util.HashMap; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class NewFeatureForSolc0822 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractD = null; byte[] contractM = null; @@ -29,52 +28,95 @@ public class NewFeatureForSolc0822 extends TronBaseTest { ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 50100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 50100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/NewFeature0822_1.sol"; - String contractName = "D"; + String filePath = "src/test/resources/soliditycode/NewFeature0822_1.sol"; + String contractName = "D"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractD = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractD = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); contractName = "M"; retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - contractM = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractM = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); contractName = "A"; retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - contractA = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractA = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); contractName = "B"; retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - contractB = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractB = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(contractD, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(contractD, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); smartContract = PublicMethod.getContract(contractM, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); @@ -84,70 +126,122 @@ public void beforeClass() { Assert.assertNotNull(smartContract.getAbi()); } - - @Test(enabled = true, description = "event at file level", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "event at file level", + groups = {"contract", "daily"}) public void test001FileLevelEvent() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractD, "f()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractD, + "f()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); System.out.println(transactionExtention); - Assert.assertEquals(ByteArray.toHexString("abc".getBytes()), - ByteArray.toHexString(transactionExtention.getLogs(0).getData().substring(64).toByteArray()).substring(0,6)); - Assert.assertEquals(8, - ByteArray.toInt(transactionExtention.getLogs(1).getData().substring(0, 32).toByteArray())); + Assert.assertEquals( + ByteArray.toHexString("abc".getBytes()), + ByteArray.toHexString(transactionExtention.getLogs(0).getData().substring(64).toByteArray()) + .substring(0, 6)); + Assert.assertEquals( + 8, + ByteArray.toInt(transactionExtention.getLogs(1).getData().substring(0, 32).toByteArray())); Assert.assertEquals(2, transactionExtention.getLogs(1).getTopicsCount()); - Assert.assertEquals(6, - ByteArray.toInt(transactionExtention.getLogs(2).getData().toByteArray())); + Assert.assertEquals( + 6, ByteArray.toInt(transactionExtention.getLogs(2).getData().toByteArray())); } - @Test(enabled = true, description = "Fix internal error when requesting userdoc or devdoc for a contract " + - "that emits an event defined in a foreign contract or interface", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Fix internal error when requesting userdoc or devdoc for a contract " + + "that emits an event defined in a foreign contract or interface", + groups = {"contract", "daily"}) public void test002ImmutableInitInCondition() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractM, "emitEvent(uint256)", "8", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractM, + "emitEvent(uint256)", + "8", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); System.out.println(transactionExtention); Assert.assertEquals(2, transactionExtention.getLogs(0).getTopicsCount()); - Assert.assertEquals(ByteArray.toHexString(contractExcAddress).substring(2), - ByteArray.toHexString(transactionExtention.getLogs(0).getTopics(1).substring(12).toByteArray())); - Assert.assertEquals(8, - ByteArray.toInt(transactionExtention.getLogs(0).getData().toByteArray())); + Assert.assertEquals( + ByteArray.toHexString(contractExcAddress).substring(2), + ByteArray.toHexString( + transactionExtention.getLogs(0).getTopics(1).substring(12).toByteArray())); + Assert.assertEquals( + 8, ByteArray.toInt(transactionExtention.getLogs(0).getData().toByteArray())); } - @Test(enabled = true, description = "Remove redundant overflow checks of certain ``for`` loops when the counter variable cannot overflow.", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Remove redundant overflow checks of certain ``for`` loops when the counter variable cann" + + "ot overflow.", + groups = {"contract", "daily"}) public void test003UncheckForLoopsOverflow() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractA, "inc()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractA, + "inc()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); long incEnergy = transactionExtention.getEnergyUsed(); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractB, "inc()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractB, + "inc()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); long incUncheckEnergy = transactionExtention.getEnergyUsed(); logger.info("incEnergy: " + incEnergy + " incUncheckEnergy: " + incUncheckEnergy); Assert.assertEquals(incEnergy, incUncheckEnergy); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0825.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0825.java index 8f740f31..cdd4b1b5 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0825.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0825.java @@ -1,45 +1,43 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.newGrammar; -import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; +import java.util.HashMap; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.codec.binary.Hex; import org.junit.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.tron.api.GrpcAPI; import org.tron.protos.Protocol; import org.tron.protos.contract.SmartContractOuterClass; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; -import java.util.HashMap; @Slf4j public class NewFeatureForSolc0825 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractC = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - private Long maxFeeLimit = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.maxFeeLimit"); - /** - * constructor. - */ + private Long maxFeeLimit = + Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit"); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 11010_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 11010_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/NewFeature0825.sol"; String contractName = "C"; @@ -47,42 +45,79 @@ public void beforeClass() { String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); Assert.assertTrue(code.contains("5e")); - contractC = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractC = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(contractC, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(contractC, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "Code Generator: Use ``MCOPY`` instead of ``MLOAD``/``MSTORE`` loop " + - "when copying byte arrays.", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Code Generator: Use ``MCOPY`` instead of ``MLOAD``/``MSTORE`` loop " + + "when copying byte arrays.", + groups = {"contract", "daily"}) public void test001McopyCopyBytes() { - String txid = PublicMethod - .triggerContract(contractC,"copyBytes()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractC, + "copyBytes()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, info.getResult()); String out = ByteArray.toHexString(info.getContractResult(0).toByteArray()).substring(128); Assert.assertEquals("6161616161000000000000000000000000000000000000000000000000000000", out); } - @Test(enabled = true, description = "Code Generator: Use ``MCOPY`` instead of ``MLOAD``/``MSTORE`` loop " + - "when copying byte arrays.", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Code Generator: Use ``MCOPY`` instead of ``MLOAD``/``MSTORE`` loop " + + "when copying byte arrays.", + groups = {"contract", "daily"}) public void test002McopyCopyString() { - String txid = PublicMethod - .triggerContract(contractC, "copyString()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractC, + "copyString()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Protocol.TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Protocol.TransactionInfo info = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); Assert.assertEquals(Protocol.TransactionInfo.code.SUCESS, info.getResult()); String out = ByteArray.toHexString(info.getContractResult(0).toByteArray()).substring(128); Assert.assertEquals("72657475726e20737472696e6700000000000000000000000000000000000000", out); - } - } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0826.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0826.java index 67c8128c..c1668606 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0826.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc0826.java @@ -1,7 +1,6 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.newGrammar; -import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; +import java.util.HashMap; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.testng.annotations.BeforeClass; @@ -10,59 +9,87 @@ import org.tron.protos.contract.SmartContractOuterClass; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; -import java.util.HashMap; - @Slf4j public class NewFeatureForSolc0826 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); - private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); - byte[] contract = null; - ECKey ecKey = new ECKey(Utils.getRandom()); - byte[] contractExcAddress = ecKey.getAddress(); - String contractExcKey = ByteArray.toHexString(ecKey.getPrivKeyBytes()); - private Long maxFeeLimit = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.maxFeeLimit"); - /** - * constructor. - */ + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); + byte[] contract = null; + ECKey ecKey = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey.getPrivKeyBytes()); + private Long maxFeeLimit = + Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit"); + /** constructor. */ - @BeforeClass(enabled = true) - public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 11010_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/newFeature0826.sol"; - String contractName = "RequireErrorTest"; - HashMap retMap = PublicMethod.getBycodeAbiWithParam(filePath, contractName,"--experimental-via-ir"); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(contract, + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 11010_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/newFeature0826.sol"; + String contractName = "RequireErrorTest"; + HashMap retMap = + PublicMethod.getBycodeAbiWithParam(filePath, contractName, "--experimental-via-ir"); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, blockingStubFull); - Assert.assertNotNull(smartContract.getAbi()); - } + PublicMethod.waitProduceNextBlock(blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(contract, blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } - @Test(enabled = true, description = "test new feature for 0.8.26", groups = {"contract", "daily"}) - public void test01TestRequireError(){ - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contract, "double(uint256)", "0", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - String resultHex = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); - Assert.assertEquals(resultHex, "b5e403ec" + - "00000000000000000000000000000000000000000000000000000000000003e9" + - "0000000000000000000000000000000000000000000000000000000000000060" + - "0000000000000000000000000000000000000000000000000000000000000001" + - "0000000000000000000000000000000000000000000000000000000000000012" + - "78206d75737420626520706f7369746976650000000000000000000000000000"); - } + @Test( + enabled = true, + description = "test new feature for 0.8.26", + groups = {"contract", "daily"}) + public void test01TestRequireError() { + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contract, + "double(uint256)", + "0", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + String resultHex = + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + Assert.assertEquals( + resultHex, + "b5e403ec" + + "00000000000000000000000000000000000000000000000000000000000003e9" + + "0000000000000000000000000000000000000000000000000000000000000060" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "0000000000000000000000000000000000000000000000000000000000000012" + + "78206d75737420626520706f7369746976650000000000000000000000000000"); + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc086.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc086.java index 93d5de0f..a3a2df79 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc086.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc086.java @@ -11,14 +11,18 @@ import org.tron.protos.Protocol; import org.tron.protos.contract.SmartContractOuterClass; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.ProposalEnum; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class NewFeatureForSolc086 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] mapKeyContract = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -26,247 +30,421 @@ public class NewFeatureForSolc086 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private Long energyFee = 0L; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 300100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 300100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/NewFeature086.sol"; - String contractName = "C"; + String filePath = "src/test/resources/soliditycode/NewFeature086.sol"; + String contractName = "C"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - mapKeyContract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 500000000L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + mapKeyContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 500000000L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(mapKeyContract, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(mapKeyContract, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - energyFee = PublicMethod.getChainParametersValue( + energyFee = + PublicMethod.getChainParametersValue( ProposalEnum.GetEnergyFee.getProposalName(), blockingStubFull); - } - - @Test(enabled = true, description = "catch assert fail", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "catch assert fail", + groups = {"contract", "daily"}) public void test01TrtCatchAssertFail() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "catchAssertFail()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "catchAssertFail()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(1, trueRes); - } - @Test(enabled = true, description = "catch under flow", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "catch under flow", + groups = {"contract", "daily"}) public void test02CatchUnderFlow() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "catchUnderFlow()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "catchUnderFlow()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(17, trueRes); - } - @Test(enabled = true, description = "catch divide zero", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "catch divide zero", + groups = {"contract", "daily"}) public void test03CatchDivideZero() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "catchDivideZero()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "catchDivideZero()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(18, trueRes); } - @Test(enabled = true, description = "get address code length", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "get address code length", + groups = {"contract", "daily"}) public void test04GetAddressCodeLength() { - String triggerTxid = PublicMethod.triggerContract(mapKeyContract, "getAddressCodeLength()", - "#", false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + "getAddressCodeLength()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); Assert.assertTrue(transactionInfo.get().getFee() < 83880 * (energyFee / 280.0)); } - @Test(enabled = true, description = "fix kecca256 bug: differt length return same code", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "fix kecca256 bug: differt length return same code", + groups = {"contract", "daily"}) public void test05Kecca256BugFix() { String args = "\"abcd123\""; - String triggerTxid = PublicMethod.triggerContract(mapKeyContract, "keccak256Bug(string)", - args, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + "keccak256Bug(string)", + args, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); - Assert.assertEquals(0, - ByteArray.toInt(transactionInfo.get().getContractResult(0).toByteArray())); + Assert.assertEquals( + 0, ByteArray.toInt(transactionInfo.get().getContractResult(0).toByteArray())); logger.info(transactionInfo.toString()); } - @Test(enabled = true, description = "revert error type with params", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "revert error type with params", + groups = {"contract", "daily"}) public void test06RevertErrorType() { String args = "\"T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb\",1000000000"; - String triggerTxid = PublicMethod.triggerContract(mapKeyContract, "transfer(address,uint256)", - args, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + "transfer(address,uint256)", + args, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info(transactionInfo.toString()); Assert.assertEquals(1, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.REVERT, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.REVERT, transactionInfo.get().getReceipt().getResult()); - Assert.assertEquals("cf479181", - ByteArray.toHexString(transactionInfo.get() - .getContractResult(0).substring(0, 4).toByteArray())); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", - ByteArray.toHexString(transactionInfo.get().getContractResult(0) - .substring(4, 36).toByteArray())); - Assert.assertEquals("000000000000000000000000000000000000000000000000000000003b9aca00", - ByteArray.toHexString(transactionInfo.get().getContractResult(0) - .substring(36, 68).toByteArray())); - + Assert.assertEquals( + "cf479181", + ByteArray.toHexString( + transactionInfo.get().getContractResult(0).substring(0, 4).toByteArray())); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000000", + ByteArray.toHexString( + transactionInfo.get().getContractResult(0).substring(4, 36).toByteArray())); + Assert.assertEquals( + "000000000000000000000000000000000000000000000000000000003b9aca00", + ByteArray.toHexString( + transactionInfo.get().getContractResult(0).substring(36, 68).toByteArray())); } - @Test(enabled = true, description = "revert error type no params", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "revert error type no params", + groups = {"contract", "daily"}) public void test07RevertErrorType() { - String triggerTxid = PublicMethod.triggerContract(mapKeyContract, "withdraw()", "#", false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + "withdraw()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(1, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.REVERT, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.REVERT, transactionInfo.get().getReceipt().getResult()); - Assert.assertEquals("82b42900", - ByteArray.toHexString(transactionInfo.get().getContractResult(0) - .substring(0, 4).toByteArray())); + Assert.assertEquals( + "82b42900", + ByteArray.toHexString( + transactionInfo.get().getContractResult(0).substring(0, 4).toByteArray())); } - @Test(enabled = true, description = "test bytes concat", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test bytes concat", + groups = {"contract", "daily"}) public void test08bytesConcat() { String args = "\"0x1234\",\"p2\",\"0x48e2f56f2c57e3532146eef2587a2a72\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "bytesConcat(bytes,string,bytes16)", args, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "bytesConcat(bytes,string,bytes16)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(36, trueRes); } - @Test(enabled = true, description = "test emit event", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test emit event", + groups = {"contract", "daily"}) public void test09EmitEvent() { - String triggerTxid = PublicMethod.triggerContract(mapKeyContract, "testEmitEvent()", "#", false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + "testEmitEvent()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info(transactionInfo.toString()); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); - Assert.assertEquals(6, - ByteArray.toInt(transactionInfo.get().getLog(0).getData().toByteArray())); + Assert.assertEquals( + 6, ByteArray.toInt(transactionInfo.get().getLog(0).getData().toByteArray())); } - - @Test(enabled = true, description = "test bytes convert to byteN overflow", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test bytes convert to byteN overflow", + groups = {"contract", "daily"}) public void test10Bytes2ByteN() { String args = "\"0x12345678\""; - String triggerTxid = PublicMethod.triggerContract(mapKeyContract, "bytes2BytesN(bytes)", - args, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + "bytes2BytesN(bytes)", + args, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info(transactionInfo.toString()); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); - Assert.assertEquals("1234560000000000000000000000000000000000000000000000000000000000", + Assert.assertEquals( + "1234560000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "test bytes convert to byteN underflow", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test bytes convert to byteN underflow", + groups = {"contract", "daily"}) public void test11Bytes2ByteN() { String args = "\"0x1234\""; - String triggerTxid = PublicMethod.triggerContract(mapKeyContract, "bytes2BytesN(bytes)", - args, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + "bytes2BytesN(bytes)", + args, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info(transactionInfo.toString()); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); - Assert.assertEquals("1234000000000000000000000000000000000000000000000000000000000000", + Assert.assertEquals( + "1234000000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "get contract address by different function", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "get contract address by different function", + groups = {"contract", "daily"}) public void test12GetConcatAddress() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "getContractAddress()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "getContractAddress()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - String res1 = ByteArray.toHexString(transactionExtention.getConstantResult(0) - .substring(0, 32).toByteArray()); - String res2 = ByteArray.toHexString(transactionExtention.getConstantResult(0) - .substring(32, 64).toByteArray()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + String res1 = + ByteArray.toHexString( + transactionExtention.getConstantResult(0).substring(0, 32).toByteArray()); + String res2 = + ByteArray.toHexString( + transactionExtention.getConstantResult(0).substring(32, 64).toByteArray()); Assert.assertEquals(res1, res2); } - @Test(enabled = true, description = "test bytes concat with empty string", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test bytes concat with empty string", + groups = {"contract", "daily"}) public void test13bytesConcatWithEmptyStr() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "bytesConcatWithEmptyStr()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "bytesConcatWithEmptyStr()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc086WithVIAIR.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc086WithVIAIR.java index 572c4618..195141bc 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc086WithVIAIR.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolc086WithVIAIR.java @@ -1,268 +1,448 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.newGrammar; -import io.grpc.ManagedChannel; +import java.util.HashMap; +import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI; import org.tron.protos.Protocol; import org.tron.protos.contract.SmartContractOuterClass; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; - -import java.util.HashMap; -import java.util.Optional; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.ProposalEnum; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class NewFeatureForSolc086WithVIAIR extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] mapKeyContract = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - private Long maxFeeLimit = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.maxFeeLimit"); + private Long maxFeeLimit = + Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit"); private Long energyFee = 0L; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 300100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 300100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/NewFeature086.sol"; String contractName = "C"; - HashMap retMap = PublicMethod.getBycodeAbiWithParam(filePath, contractName,"--experimental-via-ir"); + HashMap retMap = + PublicMethod.getBycodeAbiWithParam(filePath, contractName, "--experimental-via-ir"); String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - mapKeyContract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 500000000L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + mapKeyContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 500000000L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(mapKeyContract, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(mapKeyContract, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - energyFee = PublicMethod.getChainParametersValue( + energyFee = + PublicMethod.getChainParametersValue( ProposalEnum.GetEnergyFee.getProposalName(), blockingStubFull); - } - @Test(enabled = true, description = "catch assert fail", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "catch assert fail", + groups = {"contract", "daily"}) public void test01TrtCatchAssertFail() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "catchAssertFail()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "catchAssertFail()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(1, trueRes); - } - @Test(enabled = true, description = "catch under flow", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "catch under flow", + groups = {"contract", "daily"}) public void test02CatchUnderFlow() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "catchUnderFlow()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "catchUnderFlow()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(17, trueRes); - } - @Test(enabled = true, description = "catch divide zero", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "catch divide zero", + groups = {"contract", "daily"}) public void test03CatchDivideZero() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "catchDivideZero()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "catchDivideZero()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(18, trueRes); } - @Test(enabled = true, description = "get address code length", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "get address code length", + groups = {"contract", "daily"}) public void test04GetAddressCodeLength() { - String triggerTxid = PublicMethod.triggerContract(mapKeyContract, "getAddressCodeLength()", - "#", false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + "getAddressCodeLength()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); - //as compile contract with --experimental-via-ir, trigger costs more energy than no via-ir + // as compile contract with --experimental-via-ir, trigger costs more energy than no via-ir Assert.assertEquals(401, transactionInfo.get().getReceipt().getEnergyUsageTotal()); } - @Test(enabled = true, description = "fix kecca256 bug: differt length return same code", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "fix kecca256 bug: differt length return same code", + groups = {"contract", "daily"}) public void test05Kecca256BugFix() { String args = "\"abcd123\""; - String triggerTxid = PublicMethod.triggerContract(mapKeyContract, "keccak256Bug(string)", - args, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + "keccak256Bug(string)", + args, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); - Assert.assertEquals(0, - ByteArray.toInt(transactionInfo.get().getContractResult(0).toByteArray())); + Assert.assertEquals( + 0, ByteArray.toInt(transactionInfo.get().getContractResult(0).toByteArray())); logger.info(transactionInfo.toString()); } - @Test(enabled = true, description = "revert error type with params", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "revert error type with params", + groups = {"contract", "daily"}) public void test06RevertErrorType() { String args = "\"T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb\",1000000000"; - String triggerTxid = PublicMethod.triggerContract(mapKeyContract, "transfer(address,uint256)", - args, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + "transfer(address,uint256)", + args, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info(transactionInfo.toString()); Assert.assertEquals(1, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.REVERT, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.REVERT, transactionInfo.get().getReceipt().getResult()); - Assert.assertEquals("cf479181", - ByteArray.toHexString(transactionInfo.get() - .getContractResult(0).substring(0, 4).toByteArray())); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", - ByteArray.toHexString(transactionInfo.get().getContractResult(0) - .substring(4, 36).toByteArray())); - Assert.assertEquals("000000000000000000000000000000000000000000000000000000003b9aca00", - ByteArray.toHexString(transactionInfo.get().getContractResult(0) - .substring(36, 68).toByteArray())); - + Assert.assertEquals( + "cf479181", + ByteArray.toHexString( + transactionInfo.get().getContractResult(0).substring(0, 4).toByteArray())); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000000", + ByteArray.toHexString( + transactionInfo.get().getContractResult(0).substring(4, 36).toByteArray())); + Assert.assertEquals( + "000000000000000000000000000000000000000000000000000000003b9aca00", + ByteArray.toHexString( + transactionInfo.get().getContractResult(0).substring(36, 68).toByteArray())); } - @Test(enabled = true, description = "revert error type no params", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "revert error type no params", + groups = {"contract", "daily"}) public void test07RevertErrorType() { - String triggerTxid = PublicMethod.triggerContract(mapKeyContract, "withdraw()", "#", false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + "withdraw()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(1, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.REVERT, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.REVERT, transactionInfo.get().getReceipt().getResult()); - Assert.assertEquals("82b42900", - ByteArray.toHexString(transactionInfo.get().getContractResult(0) - .substring(0, 4).toByteArray())); + Assert.assertEquals( + "82b42900", + ByteArray.toHexString( + transactionInfo.get().getContractResult(0).substring(0, 4).toByteArray())); } - @Test(enabled = true, description = "test bytes concat", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test bytes concat", + groups = {"contract", "daily"}) public void test08bytesConcat() { String args = "\"0x1234\",\"p2\",\"0x48e2f56f2c57e3532146eef2587a2a72\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "bytesConcat(bytes,string,bytes16)", args, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "bytesConcat(bytes,string,bytes16)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(36, trueRes); } - @Test(enabled = true, description = "test emit event", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test emit event", + groups = {"contract", "daily"}) public void test09EmitEvent() { - String triggerTxid = PublicMethod.triggerContract(mapKeyContract, "testEmitEvent()", "#", false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + "testEmitEvent()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info(transactionInfo.toString()); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); - Assert.assertEquals(6, - ByteArray.toInt(transactionInfo.get().getLog(0).getData().toByteArray())); + Assert.assertEquals( + 6, ByteArray.toInt(transactionInfo.get().getLog(0).getData().toByteArray())); } - @Test(enabled = true, description = "test bytes convert to byteN overflow", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test bytes convert to byteN overflow", + groups = {"contract", "daily"}) public void test10Bytes2ByteN() { String args = "\"0x12345678\""; - String triggerTxid = PublicMethod.triggerContract(mapKeyContract, "bytes2BytesN(bytes)", - args, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + "bytes2BytesN(bytes)", + args, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info(transactionInfo.toString()); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); - Assert.assertEquals("1234560000000000000000000000000000000000000000000000000000000000", + Assert.assertEquals( + "1234560000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "test bytes convert to byteN underflow", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test bytes convert to byteN underflow", + groups = {"contract", "daily"}) public void test11Bytes2ByteN() { String args = "\"0x1234\""; - String triggerTxid = PublicMethod.triggerContract(mapKeyContract, "bytes2BytesN(bytes)", - args, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + "bytes2BytesN(bytes)", + args, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info(transactionInfo.toString()); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); - Assert.assertEquals("1234000000000000000000000000000000000000000000000000000000000000", + Assert.assertEquals( + "1234000000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "get contract address by different function", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "get contract address by different function", + groups = {"contract", "daily"}) public void test12GetConcatAddress() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "getContractAddress()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "getContractAddress()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - String res1 = ByteArray.toHexString(transactionExtention.getConstantResult(0) - .substring(0, 32).toByteArray()); - String res2 = ByteArray.toHexString(transactionExtention.getConstantResult(0) - .substring(32, 64).toByteArray()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + String res1 = + ByteArray.toHexString( + transactionExtention.getConstantResult(0).substring(0, 32).toByteArray()); + String res2 = + ByteArray.toHexString( + transactionExtention.getConstantResult(0).substring(32, 64).toByteArray()); Assert.assertEquals(res1, res2); } - @Test(enabled = true, description = "test bytes concat with empty string", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test bytes concat with empty string", + groups = {"contract", "daily"}) public void test13bytesConcatWithEmptyStr() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "bytesConcatWithEmptyStr()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "bytesConcatWithEmptyStr()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); } - } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolidity062.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolidity062.java index 11ae055d..ea95b878 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolidity062.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/NewFeatureForSolidity062.java @@ -17,67 +17,111 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class NewFeatureForSolidity062 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] getSelectorContract = null; byte[] gasValueContract = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 300100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 300100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/ExternalSelector.sol"; - String contractName = "TestGasValue"; + String filePath = "src/test/resources/soliditycode/ExternalSelector.sol"; + String contractName = "TestGasValue"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - gasValueContract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 10000000L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + gasValueContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 10000000L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - - @Test(enabled = true, description = "get selector from contract or interface's external function", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "get selector from contract or interface's external function", + groups = {"contract", "daily"}) public void test01GetFunctionSelector() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(gasValueContract, - "getContractSelectorNoParam()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + gasValueContract, + "getContractSelectorNoParam()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - String truerRes = ByteArray.toHexString(transactionExtention - .getConstantResult(0).toByteArray()); + String truerRes = + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + truerRes + " message:" + transaction.getRet(0).getRet()); logger.info("transactionExtention: " + transactionExtention); Assert.assertTrue(truerRes.startsWith("6c4959fa")); - transactionExtention = PublicMethod.triggerConstantContractForExtention(gasValueContract, - "getContractSelectorWithParam()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + gasValueContract, + "getContractSelectorWithParam()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); transaction = transactionExtention.getTransaction(); truerRes = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + truerRes + " message:" + transaction.getRet(0).getRet()); logger.info("transactionExtention: " + transactionExtention); Assert.assertTrue(truerRes.startsWith("fbb94ff8")); - transactionExtention = PublicMethod.triggerConstantContractForExtention(gasValueContract, - "getInterfaceSelectorNoParam()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + gasValueContract, + "getInterfaceSelectorNoParam()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); transaction = transactionExtention.getTransaction(); truerRes = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + truerRes + " message:" + transaction.getRet(0).getRet()); @@ -85,190 +129,325 @@ public void test01GetFunctionSelector() { Assert.assertTrue(truerRes.startsWith("034899bc")); } - @Test(enabled = true, description = "call external function like " - + "c.f{gas: 0, value: 1}()", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "call external function like " + "c.f{gas: 0, value: 1}()", + groups = {"contract", "daily"}) public void test02Call0GasAnd1Value() { - String txid = PublicMethod.triggerContract(gasValueContract, - "callWithGasAndValue(uint256,uint256)", "0,1", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + gasValueContract, + "callWithGasAndValue(uint256,uint256)", + "0,1", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("txid: " + txid + "\n" + infoById.toString()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000159", + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000159", ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); - byte[] internalReceiver = infoById.get().getInternalTransactions(0) - .getTransferToAddress().toByteArray(); - - long balanceReceiver = PublicMethod.queryAccount(internalReceiver, blockingStubFull) - .getBalance(); - logger.info("transfer to address: " + Base58.encode58Check(internalReceiver) - + "\n balance:" + balanceReceiver); + byte[] internalReceiver = + infoById.get().getInternalTransactions(0).getTransferToAddress().toByteArray(); + + long balanceReceiver = + PublicMethod.queryAccount(internalReceiver, blockingStubFull).getBalance(); + logger.info( + "transfer to address: " + + Base58.encode58Check(internalReceiver) + + "\n balance:" + + balanceReceiver); Assert.assertEquals(1, balanceReceiver); } - @Test(enabled = true, description = "call external function like " - + "c.f{gas: 0, value: 0}()", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "call external function like " + "c.f{gas: 0, value: 0}()", + groups = {"contract", "daily"}) public void test03Call0GasAnd0Value() { - String txid = PublicMethod.triggerContract(gasValueContract, - "callWithGasAndValue(uint256,uint256)", "0,0", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + gasValueContract, + "callWithGasAndValue(uint256,uint256)", + "0,0", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("txid: " + txid + "\n" + infoById.toString()); Assert.assertEquals(FAILED, infoById.get().getResult()); - Assert.assertEquals("REVERT opcode executed", - infoById.get().getResMessage().toStringUtf8()); - + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); } - @Test(enabled = true, description = "inline assembly allow true and false", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "inline assembly allow true and false", + groups = {"contract", "daily"}) public void test04AssembleTrueFalse() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(gasValueContract, - "testAssemblyTrue()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + gasValueContract, + "testAssemblyTrue()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - int truerRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + int truerRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + truerRes + " message:" + transaction.getRet(0).getRet()); Assert.assertEquals(1, truerRes); - transactionExtention = PublicMethod.triggerConstantContractForExtention(gasValueContract, - "testAssemblyFalse()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + gasValueContract, + "testAssemblyFalse()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); transaction = transactionExtention.getTransaction(); - int falseRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + int falseRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info("res: " + falseRes + " message:" + transaction.getRet(0).getRet()); Assert.assertEquals(0, falseRes); - } - @Test(enabled = true, description = "test new create2", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test new create2", + groups = {"contract", "daily"}) public void test05NewCreate2() { - String txid = PublicMethod.triggerContract(gasValueContract, - "testCreate2()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + gasValueContract, + "testCreate2()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("txid: " + txid + "\n" + infoById.toString()); - byte[] internalReceiver = infoById.get() - .getInternalTransactions(0).getTransferToAddress().toByteArray(); - - long balanceReceiver = PublicMethod.queryAccount(internalReceiver, blockingStubFull) - .getBalance(); - logger.info("transfer to address: " + Base58.encode58Check(internalReceiver) - + "\n balance:" + balanceReceiver); + byte[] internalReceiver = + infoById.get().getInternalTransactions(0).getTransferToAddress().toByteArray(); + + long balanceReceiver = + PublicMethod.queryAccount(internalReceiver, blockingStubFull).getBalance(); + logger.info( + "transfer to address: " + + Base58.encode58Check(internalReceiver) + + "\n balance:" + + balanceReceiver); Assert.assertEquals(1000000, balanceReceiver); - } - @Test(enabled = true, description = "test Interface Succeed", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test Interface Succeed", + groups = {"contract", "daily"}) public void test06InterfaceSucceed() { String filePath = "src/test/resources/soliditycode/ExternalSelector.sol"; - String contractName = "implementContract"; + String contractName = "implementContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] implementContract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 10000000L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] implementContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 10000000L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(implementContract, - "getSelector()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + implementContract, + "getSelector()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - int truerRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + int truerRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + truerRes + " message:" + transaction.getRet(0).getRet()); Assert.assertEquals(66, truerRes); } - @Test(enabled = true, description = "call in contract external function like " - + "c.f{gas: 0, value: 1}()", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "call in contract external function like " + "c.f{gas: 0, value: 1}()", + groups = {"contract", "daily"}) public void test07CallThis0GasAnd1Value() { - String txid = PublicMethod.triggerContract(gasValueContract, - "callThisNoGasAnd1Value()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + gasValueContract, + "callThisNoGasAnd1Value()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("txid: " + txid + "\n" + infoById.toString()); Assert.assertEquals(FAILED, infoById.get().getResult()); - } - @Test(enabled = true, description = "call external function like " - + "c.f{gas: 440000, value: 0}()", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "call external function like " + "c.f{gas: 440000, value: 0}()", + groups = {"contract", "daily"}) public void test08CallWithGasAnd0Value() { - String txid = PublicMethod.triggerContract(gasValueContract, - "callWithGasAndValue(uint256,uint256)", "440000,0", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + gasValueContract, + "callWithGasAndValue(uint256,uint256)", + "440000,0", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("txid: " + txid + "\n" + infoById.toString()); Assert.assertEquals(SUCESS, infoById.get().getResult()); - } - @Test(enabled = true, description = "call external function like " - + "c.f{gas: 1, value: 0}()", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "call external function like " + "c.f{gas: 1, value: 0}()", + groups = {"contract", "daily"}) public void test09CallWith1GasAnd0Value() { - String txid = PublicMethod.triggerContract(gasValueContract, - "callWithGasAndValue(uint256,uint256)", "1,0", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + gasValueContract, + "callWithGasAndValue(uint256,uint256)", + "1,0", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("txid: " + txid + "\n" + infoById.toString()); Assert.assertEquals(FAILED, infoById.get().getResult()); - } - @Test(enabled = true, description = "call external function like " - + "c.f{gas: 0, value: > balance}()", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "call external function like " + "c.f{gas: 0, value: > balance}()", + groups = {"contract", "daily"}) public void test10CallWith0GasAndBigValue() { - String txid = PublicMethod.triggerContract(gasValueContract, - "callWithGasAndValue(uint256,uint256)", "0,9223372036854775800", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + gasValueContract, + "callWithGasAndValue(uint256,uint256)", + "0,9223372036854775800", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("txid: " + txid + "\n" + infoById.toString()); Assert.assertEquals(FAILED, infoById.get().getResult()); } - @Test(enabled = true, description = "call external function like " - + "c.f{gas: 9223372036854775800, value: 0}()", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "call external function like " + "c.f{gas: 9223372036854775800, value: 0}()", + groups = {"contract", "daily"}) public void test11CallWithBigGasAnd0Value() { - String txid = PublicMethod.triggerContract(gasValueContract, - "callWithGasAndValue(uint256,uint256)", "9223372036854775800,0", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + gasValueContract, + "callWithGasAndValue(uint256,uint256)", + "9223372036854775800,0", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("txid: " + txid + "\n" + infoById.toString()); Assert.assertEquals(SUCESS, infoById.get().getResult()); - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/Opcode.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/Opcode.java index 51f29750..9db79c6b 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/Opcode.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/Opcode.java @@ -15,446 +15,656 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class Opcode extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] mapKeyContract = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 300100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 300100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/opCode.sol"; - String contractName = "A"; + String filePath = "src/test/resources/soliditycode/opCode.sol"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbiNoOptimize(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - mapKeyContract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + mapKeyContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(mapKeyContract, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(mapKeyContract, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - } - - @Test(enabled = true, description = "test opcode smod, used for int", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test opcode smod, used for int", + groups = {"contract", "daily"}) public void test01Smod() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "sssmod()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "sssmod()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); Assert.assertEquals(1, trueRes); } - @Test(enabled = true, description = "test opcode extcodecopy return contract bytecode", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test opcode extcodecopy return contract bytecode", + groups = {"contract", "daily"}) public void test02Extcodecopy() { String base58 = Base58.encode58Check(mapKeyContract); - String txid = PublicMethod.triggerContract(mapKeyContract, - "eextcodecopy(address)", "\"" + base58 + "\"", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + mapKeyContract, + "eextcodecopy(address)", + "\"" + base58 + "\"", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("txid: " + txid + "\n" + infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - Assert.assertTrue(ByteArray.toHexString( - infoById.get().getContractResult(0).toByteArray()).length() > 0); - + Assert.assertTrue( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()).length() > 0); } - @Test(enabled = true, description = "test opcode coinbase," - + "block.coinbase is sr address which produced the block", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "test opcode coinbase," + "block.coinbase is sr address which produced the block", + groups = {"contract", "daily"}) public void test03Coinbase() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "cccoinbase()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "cccoinbase()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - String trueRes = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + String trueRes = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); Assert.assertEquals("SUCESS", transaction.getRet(0).getRet().toString()); - Assert.assertTrue(trueRes.startsWith("00000000000000000000000" - + "0bafb56091591790e00aa05eaddcc7dc1474b5d4b") - || trueRes.startsWith("0000000000000000000000000be88a918d74d0dfd71dc84bd4abf036d0562991") - || trueRes.startsWith("0000000000000000000000003ed7d77d2eb807375a34e1a0043c5ba7e8926265")); + Assert.assertTrue( + trueRes.startsWith("00000000000000000000000" + "0bafb56091591790e00aa05eaddcc7dc1474b5d4b") + || trueRes.startsWith( + "0000000000000000000000000be88a918d74d0dfd71dc84bd4abf036d0562991") + || trueRes.startsWith( + "0000000000000000000000003ed7d77d2eb807375a34e1a0043c5ba7e8926265")); } - @Test(enabled = false, description = "test opcode difficulty,block.difficulty is always 0," - + " Deprecate since 0.8.18", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = + "test opcode difficulty,block.difficulty is always 0," + " Deprecate since 0.8.18", + groups = {"contract", "daily"}) public void test04Difficulty() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "ddifficulty()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "ddifficulty()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); Assert.assertEquals("SUCESS", transaction.getRet(0).getRet().toString()); Assert.assertEquals(0, trueRes); - } - @Test(enabled = true, description = "test opcode gaslimit,block.gaslimit is always 0", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test opcode gaslimit,block.gaslimit is always 0", + groups = {"contract", "daily"}) public void test05Gaslimit() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "gggaslimit()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "gggaslimit()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); Assert.assertEquals("SUCESS", transaction.getRet(0).getRet().toString()); Assert.assertEquals(0, trueRes); - } - @Test(enabled = true, description = "test opcode pc,return current position, " - + "ppppc() can refer to opCode.sol", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test opcode pc,return current position, " + "ppppc() can refer to opCode.sol", + groups = {"contract", "daily"}) public void test06Pc() { - String code = "608060405260838060116000396000f3fe608060405234" - + "8015600f57600080fd5b506004361060285760003560e01c806" - + "36d3a027714602d575b600080fd5b60336045565b6040805191825251" - + "9081900360200190f35b60005890509056fea264697" - + "0667358221220fe03cbd3d2aae7454565f203b9abd76ce74cf0ac" - + "a079b151cf6b8e2bfda2d5c464736f6c634300060c0033"; - String abi = "[\n" - + "\t{\n" - + "\t\t\"inputs\": [],\n" - + "\t\t\"stateMutability\": \"payable\",\n" - + "\t\t\"type\": \"constructor\"\n" - + "\t},\n" - + "\t{\n" - + "\t\t\"inputs\": [],\n" - + "\t\t\"name\": \"ppppc\",\n" - + "\t\t\"outputs\": [\n" - + "\t\t\t{\n" - + "\t\t\t\t\"internalType\": \"uint256\",\n" - + "\t\t\t\t\"name\": \"a\",\n" - + "\t\t\t\t\"type\": \"uint256\"\n" - + "\t\t\t}\n" - + "\t\t],\n" - + "\t\t\"stateMutability\": \"nonpayable\",\n" - + "\t\t\"type\": \"function\"\n" - + "\t}\n" - + "]"; - byte[] temContract = PublicMethod.deployContract("A", abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = + "608060405260838060116000396000f3fe608060405234" + + "8015600f57600080fd5b506004361060285760003560e01c806" + + "36d3a027714602d575b600080fd5b60336045565b6040805191825251" + + "9081900360200190f35b60005890509056fea264697" + + "0667358221220fe03cbd3d2aae7454565f203b9abd76ce74cf0ac" + + "a079b151cf6b8e2bfda2d5c464736f6c634300060c0033"; + String abi = + "[\n" + + "\t{\n" + + "\t\t\"inputs\": [],\n" + + "\t\t\"stateMutability\": \"payable\",\n" + + "\t\t\"type\": \"constructor\"\n" + + "\t},\n" + + "\t{\n" + + "\t\t\"inputs\": [],\n" + + "\t\t\"name\": \"ppppc\",\n" + + "\t\t\"outputs\": [\n" + + "\t\t\t{\n" + + "\t\t\t\t\"internalType\": \"uint256\",\n" + + "\t\t\t\t\"name\": \"a\",\n" + + "\t\t\t\t\"type\": \"uint256\"\n" + + "\t\t\t}\n" + + "\t\t],\n" + + "\t\t\"stateMutability\": \"nonpayable\",\n" + + "\t\t\"type\": \"function\"\n" + + "\t}\n" + + "]"; + byte[] temContract = + PublicMethod.deployContract( + "A", + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(temContract, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(temContract, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(temContract, - "ppppc()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + temContract, + "ppppc()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); Assert.assertEquals("SUCESS", transaction.getRet(0).getRet().toString()); Assert.assertEquals(72, trueRes); - } - @Test(enabled = true, description = "test opcode msize,return size of memory, " - + "msize cannot be used if optimize is open, mmmsize() can refer to opCode.sol", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "test opcode msize,return size of memory, " + + "msize cannot be used if optimize is open, mmmsize() can refer to opCode.sol", + groups = {"contract", "daily"}) public void test07Msize() { - String code = "608060405260b5806100126000396000f3fe6080604052348015600f5760" - + "0080fd5b506004361060285760003560e01c8063bf1a725d14602d575b600080fd5b60" - + "336047565b604051603e9190605c565b60405180910390f35b600059905090565b6056" - + "816075565b82525050565b6000602082019050606f6000830184604f565b9291505056" - + "5b600081905091905056fea26469706673582212202252652aad4bca9a4aa9db179e03" - + "f7b3bf439f47152e31f45d8587b710bce79664736f6c63430008060033"; - String abi = "[\n" - + "\t{\n" - + "\t\t\"inputs\": [],\n" - + "\t\t\"stateMutability\": \"payable\",\n" - + "\t\t\"type\": \"constructor\"\n" - + "\t},\n" - + "\t{\n" - + "\t\t\"inputs\": [],\n" - + "\t\t\"name\": \"mmmsize\",\n" - + "\t\t\"outputs\": [\n" - + "\t\t\t{\n" - + "\t\t\t\t\"internalType\": \"uint256\",\n" - + "\t\t\t\t\"name\": \"a\",\n" - + "\t\t\t\t\"type\": \"uint256\"\n" - + "\t\t\t}\n" - + "\t\t],\n" - + "\t\t\"stateMutability\": \"nonpayable\",\n" - + "\t\t\"type\": \"function\"\n" - + "\t}\n" - + "]"; - byte[] temContract = PublicMethod.deployContract("A", abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = + "608060405260b5806100126000396000f3fe6080604052348015600f5760" + + "0080fd5b506004361060285760003560e01c8063bf1a725d14602d575b600080fd5b60" + + "336047565b604051603e9190605c565b60405180910390f35b600059905090565b6056" + + "816075565b82525050565b6000602082019050606f6000830184604f565b9291505056" + + "5b600081905091905056fea26469706673582212202252652aad4bca9a4aa9db179e03" + + "f7b3bf439f47152e31f45d8587b710bce79664736f6c63430008060033"; + String abi = + "[\n" + + "\t{\n" + + "\t\t\"inputs\": [],\n" + + "\t\t\"stateMutability\": \"payable\",\n" + + "\t\t\"type\": \"constructor\"\n" + + "\t},\n" + + "\t{\n" + + "\t\t\"inputs\": [],\n" + + "\t\t\"name\": \"mmmsize\",\n" + + "\t\t\"outputs\": [\n" + + "\t\t\t{\n" + + "\t\t\t\t\"internalType\": \"uint256\",\n" + + "\t\t\t\t\"name\": \"a\",\n" + + "\t\t\t\t\"type\": \"uint256\"\n" + + "\t\t\t}\n" + + "\t\t],\n" + + "\t\t\"stateMutability\": \"nonpayable\",\n" + + "\t\t\"type\": \"function\"\n" + + "\t}\n" + + "]"; + byte[] temContract = + PublicMethod.deployContract( + "A", + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(temContract, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(temContract, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(temContract, - "mmmsize()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + temContract, + "mmmsize()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); Assert.assertEquals("SUCESS", transaction.getRet(0).getRet().toString()); Assert.assertEquals(96, trueRes); - } - - @Test(enabled = true, description = "test opcode swap14-16,solidity cannot use optimize", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test opcode swap14-16,solidity cannot use optimize", + groups = {"contract", "daily"}) public void test08Swap() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "ssswap14()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - Protocol.Transaction transaction = transactionExtention.getTransaction(); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); - logger.info("truerRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); - Assert.assertEquals("SUCESS", transaction.getRet(0).getRet().toString()); - Assert.assertEquals(1, trueRes); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "ssswap15()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "ssswap14()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + Protocol.Transaction transaction = transactionExtention.getTransaction(); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + logger.info("truerRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); + Assert.assertEquals("SUCESS", transaction.getRet(0).getRet().toString()); + Assert.assertEquals(1, trueRes); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "ssswap15()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); transaction = transactionExtention.getTransaction(); trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); Assert.assertEquals("SUCESS", transaction.getRet(0).getRet().toString()); Assert.assertEquals(1, trueRes); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "ssswap16()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "ssswap16()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); transaction = transactionExtention.getTransaction(); trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); Assert.assertEquals("SUCESS", transaction.getRet(0).getRet().toString()); Assert.assertEquals(1, trueRes); - } - @Test(enabled = true, description = "test opcode push13-30 but exclude push20 and push29," - + "solidity cannot use optimize", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "test opcode push13-30 but exclude push20 and push29," + "solidity cannot use optimize", + groups = {"contract", "daily"}) public void test08Pushx() { GrpcAPI.TransactionExtention transactionExtention; - for(int i=13;i<31;i++){ - transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "pppushx(int8)", ""+i, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + for (int i = 13; i < 31; i++) { + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "pppushx(int8)", + "" + i, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - String trueRes = ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); + String trueRes = + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + trueRes + " message:" + transaction.getRet(0).getRet()); Assert.assertEquals("SUCESS", transaction.getRet(0).getRet().toString()); -// Assert.assertTrue(trueRes.contains("000000000000000000000000000000000000001" -// + "1223344556677889900112233")); + // Assert.assertTrue(trueRes.contains("000000000000000000000000000000000000001" + // + "1223344556677889900112233")); } } - @Test(enabled = true, description = "test opcode callcode,difference with delegatecall " - + "is caller and callvalue,the bytecode is compiled with solidity 0.4.22, " - + "can refer to opCode.sol for code", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "test opcode callcode,difference with delegatecall " + + "is caller and callvalue,the bytecode is compiled with solidity 0.4.22, " + + "can refer to opCode.sol for code", + groups = {"contract", "daily"}) public void test09Callcode() { - String code = "60806040526103b4806100136000396000f3006080604052600436106100565763" - + "ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416634" - + "cb335db811461005b578063ae02d91d14610081578063ea856db2146100a5575b600080fd5b61007f" - + "73ffffffffffffffffffffffffffffffffffffffff600435166024356100c9565b005b61007f73ffff" - + "ffffffffffffffffffffffffffffffffffff600435166024356101b6565b61007f73ffffffffffffff" - + "ffffffffffffffffffffffffff600435166024356102a3565b604080516024808201849052825180830" - + "39091018152604490910182526020810180517bffffffffffffffffffffffffffffffffffffffffffff" - + "ffffffffffff167f66c99139000000000000000000000000000000000000000000000000000000001781529" - + "151815173ffffffffffffffffffffffffffffffffffffffff861693600a93929182919080838360005b8" - + "3811015610170578181015183820152602001610158565b50505050905090810190601f16801561019d5" - + "780820380516001836020036101000a031916815260200191505b5091505060006040518083038185875" - + "af1505050505050565b60408051602480820184905282518083039091018152604490910182526020810" - + "180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f66c99139000000000" - + "000000000000000000000000000000000000000000000001781529151815173fffffffffffffffffffff" - + "fffffffffffffffffff861693600a93929182919080838360005b8381101561025d57818101518382015" - + "2602001610245565b50505050905090810190601f16801561028a5780820380516001836020036101000" - + "a031916815260200191505b5091505060006040518083038185875af2505050505050565b60408051602" - + "480820184905282518083039091018152604490910182526020810180517bfffffffffffffffffffffff" - + "fffffffffffffffffffffffffffffffff167f66c991390000000000000000000000000000000000000000" - + "00000000000000001781529151815173ffffffffffffffffffffffffffffffffffffffff8616938291808" - + "38360005b8381101561034457818101518382015260200161032c565b50505050905090810190601f1680" - + "156103715780820380516001836020036101000a031916815260200191505b50915050600060405180830" - + "381855af450505050505600a165627a7a72305820210d132d0c4006264ef113f342556c616d9e69acc20" - + "bfa80cf440a4eac170de80029"; - String abi = "[\n" - + "\t{\n" - + "\t\t\"constant\": false,\n" - + "\t\t\"inputs\": [\n" - + "\t\t\t{\n" - + "\t\t\t\t\"name\": \"callCAddress\",\n" - + "\t\t\t\t\"type\": \"address\"\n" - + "\t\t\t},\n" - + "\t\t\t{\n" - + "\t\t\t\t\"name\": \"amount\",\n" - + "\t\t\t\t\"type\": \"uint256\"\n" - + "\t\t\t}\n" - + "\t\t],\n" - + "\t\t\"name\": \"testInCall\",\n" - + "\t\t\"outputs\": [],\n" - + "\t\t\"payable\": true,\n" - + "\t\t\"stateMutability\": \"payable\",\n" - + "\t\t\"type\": \"function\"\n" - + "\t},\n" - + "\t{\n" - + "\t\t\"constant\": false,\n" - + "\t\t\"inputs\": [\n" - + "\t\t\t{\n" - + "\t\t\t\t\"name\": \"callCAddress\",\n" - + "\t\t\t\t\"type\": \"address\"\n" - + "\t\t\t},\n" - + "\t\t\t{\n" - + "\t\t\t\t\"name\": \"amount\",\n" - + "\t\t\t\t\"type\": \"uint256\"\n" - + "\t\t\t}\n" - + "\t\t],\n" - + "\t\t\"name\": \"testInCallcode\",\n" - + "\t\t\"outputs\": [],\n" - + "\t\t\"payable\": true,\n" - + "\t\t\"stateMutability\": \"payable\",\n" - + "\t\t\"type\": \"function\"\n" - + "\t},\n" - + "\t{\n" - + "\t\t\"constant\": false,\n" - + "\t\t\"inputs\": [\n" - + "\t\t\t{\n" - + "\t\t\t\t\"name\": \"callCAddress\",\n" - + "\t\t\t\t\"type\": \"address\"\n" - + "\t\t\t},\n" - + "\t\t\t{\n" - + "\t\t\t\t\"name\": \"amount\",\n" - + "\t\t\t\t\"type\": \"uint256\"\n" - + "\t\t\t}\n" - + "\t\t],\n" - + "\t\t\"name\": \"testIndelegateCall\",\n" - + "\t\t\"outputs\": [],\n" - + "\t\t\"payable\": true,\n" - + "\t\t\"stateMutability\": \"payable\",\n" - + "\t\t\"type\": \"function\"\n" - + "\t},\n" - + "\t{\n" - + "\t\t\"inputs\": [],\n" - + "\t\t\"payable\": true,\n" - + "\t\t\"stateMutability\": \"payable\",\n" - + "\t\t\"type\": \"constructor\"\n" - + "\t}\n" - + "]"; - byte[] contractA = PublicMethod.deployContract("A", abi, code, "", maxFeeLimit, - 1000000L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = + "60806040526103b4806100136000396000f3006080604052600436106100565763" + + "ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416634" + + "cb335db811461005b578063ae02d91d14610081578063ea856db2146100a5575b600080fd5b61007f" + + "73ffffffffffffffffffffffffffffffffffffffff600435166024356100c9565b005b61007f73ffff" + + "ffffffffffffffffffffffffffffffffffff600435166024356101b6565b61007f73ffffffffffffff" + + "ffffffffffffffffffffffffff600435166024356102a3565b604080516024808201849052825180830" + + "39091018152604490910182526020810180517bffffffffffffffffffffffffffffffffffffffffffff" + + "ffffffffffff167f66c99139000000000000000000000000000000000000000000000000000000001781" + + "529" + + "151815173ffffffffffffffffffffffffffffffffffffffff861693600a93929182919080838360005b8" + + "3811015610170578181015183820152602001610158565b50505050905090810190601f16801561019d5" + + "780820380516001836020036101000a031916815260200191505b5091505060006040518083038185875" + + "af1505050505050565b60408051602480820184905282518083039091018152604490910182526020810" + + "180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f66c99139000000000" + + "000000000000000000000000000000000000000000000001781529151815173fffffffffffffffffffff" + + "fffffffffffffffffff861693600a93929182919080838360005b8381101561025d57818101518382015" + + "2602001610245565b50505050905090810190601f16801561028a5780820380516001836020036101000" + + "a031916815260200191505b5091505060006040518083038185875af2505050505050565b60408051602" + + "480820184905282518083039091018152604490910182526020810180517bfffffffffffffffffffffff" + + "fffffffffffffffffffffffffffffffff167f66c99139000000000000000000000000000000000000000" + + "0" + + "00000000000000001781529151815173ffffffffffffffffffffffffffffffffffffffff861693829180" + + "8" + + "38360005b8381101561034457818101518382015260200161032c565b50505050905090810190601f168" + + "0" + + "156103715780820380516001836020036101000a031916815260200191505b5091505060006040518083" + + "0" + + "381855af450505050505600a165627a7a72305820210d132d0c4006264ef113f342556c616d9e69acc20" + + "bfa80cf440a4eac170de80029"; + String abi = + "[\n" + + "\t{\n" + + "\t\t\"constant\": false,\n" + + "\t\t\"inputs\": [\n" + + "\t\t\t{\n" + + "\t\t\t\t\"name\": \"callCAddress\",\n" + + "\t\t\t\t\"type\": \"address\"\n" + + "\t\t\t},\n" + + "\t\t\t{\n" + + "\t\t\t\t\"name\": \"amount\",\n" + + "\t\t\t\t\"type\": \"uint256\"\n" + + "\t\t\t}\n" + + "\t\t],\n" + + "\t\t\"name\": \"testInCall\",\n" + + "\t\t\"outputs\": [],\n" + + "\t\t\"payable\": true,\n" + + "\t\t\"stateMutability\": \"payable\",\n" + + "\t\t\"type\": \"function\"\n" + + "\t},\n" + + "\t{\n" + + "\t\t\"constant\": false,\n" + + "\t\t\"inputs\": [\n" + + "\t\t\t{\n" + + "\t\t\t\t\"name\": \"callCAddress\",\n" + + "\t\t\t\t\"type\": \"address\"\n" + + "\t\t\t},\n" + + "\t\t\t{\n" + + "\t\t\t\t\"name\": \"amount\",\n" + + "\t\t\t\t\"type\": \"uint256\"\n" + + "\t\t\t}\n" + + "\t\t],\n" + + "\t\t\"name\": \"testInCallcode\",\n" + + "\t\t\"outputs\": [],\n" + + "\t\t\"payable\": true,\n" + + "\t\t\"stateMutability\": \"payable\",\n" + + "\t\t\"type\": \"function\"\n" + + "\t},\n" + + "\t{\n" + + "\t\t\"constant\": false,\n" + + "\t\t\"inputs\": [\n" + + "\t\t\t{\n" + + "\t\t\t\t\"name\": \"callCAddress\",\n" + + "\t\t\t\t\"type\": \"address\"\n" + + "\t\t\t},\n" + + "\t\t\t{\n" + + "\t\t\t\t\"name\": \"amount\",\n" + + "\t\t\t\t\"type\": \"uint256\"\n" + + "\t\t\t}\n" + + "\t\t],\n" + + "\t\t\"name\": \"testIndelegateCall\",\n" + + "\t\t\"outputs\": [],\n" + + "\t\t\"payable\": true,\n" + + "\t\t\"stateMutability\": \"payable\",\n" + + "\t\t\"type\": \"function\"\n" + + "\t},\n" + + "\t{\n" + + "\t\t\"inputs\": [],\n" + + "\t\t\"payable\": true,\n" + + "\t\t\"stateMutability\": \"payable\",\n" + + "\t\t\"type\": \"constructor\"\n" + + "\t}\n" + + "]"; + byte[] contractA = + PublicMethod.deployContract( + "A", + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(contractA, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(contractA, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - code = "608060405260d2806100126000396000f300608060405260043610603e5763ffffffff7c0" - + "10000000000000000000000000000000000000000000000000000000060003504166366c99" - + "13981146043575b600080fd5b604c600435604e565b005b6040805173fffffffffffffffff" - + "fffffffffffffffffffffff3316815234602082015280820183905290517fac74fdf75f0e5" - + "a43f870f7135801b44f404be82b1dcad73423c542b840d1d64b9181900360600190a150560" - + "0a165627a7a72305820c460a35f70e363777be22b3a4ace5f95533de626073ab4e06d9bf3bbb2cffceb0029"; - abi = "[\n" - + "\t{\n" - + "\t\t\"constant\": false,\n" - + "\t\t\"inputs\": [\n" - + "\t\t\t{\n" - + "\t\t\t\t\"name\": \"amount\",\n" - + "\t\t\t\t\"type\": \"uint256\"\n" - + "\t\t\t}\n" - + "\t\t],\n" - + "\t\t\"name\": \"trans\",\n" - + "\t\t\"outputs\": [],\n" - + "\t\t\"payable\": true,\n" - + "\t\t\"stateMutability\": \"payable\",\n" - + "\t\t\"type\": \"function\"\n" - + "\t},\n" - + "\t{\n" - + "\t\t\"inputs\": [],\n" - + "\t\t\"payable\": true,\n" - + "\t\t\"stateMutability\": \"payable\",\n" - + "\t\t\"type\": \"constructor\"\n" - + "\t},\n" - + "\t{\n" - + "\t\t\"anonymous\": false,\n" - + "\t\t\"inputs\": [\n" - + "\t\t\t{\n" - + "\t\t\t\t\"indexed\": false,\n" - + "\t\t\t\t\"name\": \"\",\n" - + "\t\t\t\t\"type\": \"address\"\n" - + "\t\t\t},\n" - + "\t\t\t{\n" - + "\t\t\t\t\"indexed\": false,\n" - + "\t\t\t\t\"name\": \"\",\n" - + "\t\t\t\t\"type\": \"uint256\"\n" - + "\t\t\t},\n" - + "\t\t\t{\n" - + "\t\t\t\t\"indexed\": false,\n" - + "\t\t\t\t\"name\": \"\",\n" - + "\t\t\t\t\"type\": \"uint256\"\n" - + "\t\t\t}\n" - + "\t\t],\n" - + "\t\t\"name\": \"clog\",\n" - + "\t\t\"type\": \"event\"\n" - + "\t}\n" - + "]"; - byte[] contractC = PublicMethod.deployContract("C", abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + code = + "608060405260d2806100126000396000f300608060405260043610603e5763ffffffff7c0" + + "10000000000000000000000000000000000000000000000000000000060003504166366c99" + + "13981146043575b600080fd5b604c600435604e565b005b6040805173fffffffffffffffff" + + "fffffffffffffffffffffff3316815234602082015280820183905290517fac74fdf75f0e5" + + "a43f870f7135801b44f404be82b1dcad73423c542b840d1d64b9181900360600190a150560" + + "0a165627a7a72305820c460a35f70e363777be22b3a4ace5f95533de626073ab4e06d9bf3bbb2cffceb0" + + "029"; + abi = + "[\n" + + "\t{\n" + + "\t\t\"constant\": false,\n" + + "\t\t\"inputs\": [\n" + + "\t\t\t{\n" + + "\t\t\t\t\"name\": \"amount\",\n" + + "\t\t\t\t\"type\": \"uint256\"\n" + + "\t\t\t}\n" + + "\t\t],\n" + + "\t\t\"name\": \"trans\",\n" + + "\t\t\"outputs\": [],\n" + + "\t\t\"payable\": true,\n" + + "\t\t\"stateMutability\": \"payable\",\n" + + "\t\t\"type\": \"function\"\n" + + "\t},\n" + + "\t{\n" + + "\t\t\"inputs\": [],\n" + + "\t\t\"payable\": true,\n" + + "\t\t\"stateMutability\": \"payable\",\n" + + "\t\t\"type\": \"constructor\"\n" + + "\t},\n" + + "\t{\n" + + "\t\t\"anonymous\": false,\n" + + "\t\t\"inputs\": [\n" + + "\t\t\t{\n" + + "\t\t\t\t\"indexed\": false,\n" + + "\t\t\t\t\"name\": \"\",\n" + + "\t\t\t\t\"type\": \"address\"\n" + + "\t\t\t},\n" + + "\t\t\t{\n" + + "\t\t\t\t\"indexed\": false,\n" + + "\t\t\t\t\"name\": \"\",\n" + + "\t\t\t\t\"type\": \"uint256\"\n" + + "\t\t\t},\n" + + "\t\t\t{\n" + + "\t\t\t\t\"indexed\": false,\n" + + "\t\t\t\t\"name\": \"\",\n" + + "\t\t\t\t\"type\": \"uint256\"\n" + + "\t\t\t}\n" + + "\t\t],\n" + + "\t\t\"name\": \"clog\",\n" + + "\t\t\"type\": \"event\"\n" + + "\t}\n" + + "]"; + byte[] contractC = + PublicMethod.deployContract( + "C", + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - smartContract = PublicMethod.getContract(contractC, - blockingStubFull); + smartContract = PublicMethod.getContract(contractC, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - String base58C = Base58.encode58Check(contractC); - String txid = PublicMethod.triggerContract(contractA, - "testInCall(address,uint256)", "\"" + base58C + "\",1", false, - 1, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String base58C = Base58.encode58Check(contractC); + String txid = + PublicMethod.triggerContract( + contractA, + "testInCall(address,uint256)", + "\"" + base58C + "\",1", + false, + 1, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); - String logRes = ByteArray.toHexString(infoById.get().getLog(0).getData().toByteArray()); + String logRes = ByteArray.toHexString(infoById.get().getLog(0).getData().toByteArray()); System.out.println("000000: " + logRes); - String b = "41" + logRes.substring(24, 64); - String c = logRes.substring(64, 128); - String x = ByteArray.toHexString(contractA); + String b = "41" + logRes.substring(24, 64); + String c = logRes.substring(64, 128); + String x = ByteArray.toHexString(contractA); Assert.assertEquals(b, x); Assert.assertEquals("000000000000000000000000000000000000000000000000000000000000000a", c); - txid = PublicMethod.triggerContract(contractA, - "testIndelegateCall(address,uint256)", "\"" + base58C + "\",1", false, - 2, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractA, + "testIndelegateCall(address,uint256)", + "\"" + base58C + "\",1", + false, + 2, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("txid: " + txid + "\n" + infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); logRes = ByteArray.toHexString(infoById.get().getLog(0).getData().toByteArray()); @@ -465,13 +675,21 @@ public void test09Callcode() { Assert.assertEquals(b, x); Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000002", c); - - txid = PublicMethod.triggerContract(contractA, - "testInCallcode(address,uint256)", "\"" + base58C + "\",1", false, - 3, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractA, + "testInCallcode(address,uint256)", + "\"" + base58C + "\",1", + false, + 3, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("txid: " + txid + "\n" + infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); logRes = ByteArray.toHexString(infoById.get().getLog(0).getData().toByteArray()); @@ -483,15 +701,10 @@ public void test09Callcode() { Assert.assertEquals("000000000000000000000000000000000000000000000000000000000000000a", c); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/OverridePrivateFunction.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/OverridePrivateFunction.java index 21188576..1643fbf4 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/OverridePrivateFunction.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/OverridePrivateFunction.java @@ -12,66 +12,83 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class OverridePrivateFunction extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] gasValueContract = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); } - + PublicMethod.printAddress(contractExcKey); + } - @Test(enabled = false, description = "test override private function", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "test override private function", + groups = {"contract", "daily"}) public void test01OverridePrivateFunction() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/overridePrivateFunction.sol"; - String contractName = "B"; + String filePath = "src/test/resources/soliditycode/overridePrivateFunction.sol"; + String contractName = "B"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - gasValueContract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + gasValueContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(gasValueContract, - "testOverridePrivate()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + gasValueContract, + "testOverridePrivate()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Protocol.Transaction transaction = transactionExtention.getTransaction(); - int truerRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + int truerRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info("truerRes: " + truerRes + " message:" + transaction.getRet(0).getRet()); logger.info("transactionExtention: " + transactionExtention); Assert.assertEquals(2, truerRes); - - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/OverrideTest001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/OverrideTest001.java index 587538f1..48024186 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/OverrideTest001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/OverrideTest001.java @@ -13,408 +13,782 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class OverrideTest001 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] contractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 1000_000_000L, fromAddress, - testKey002, blockingStubFull)); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1000_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Deploy 0.5.15 about override(Base1,Base2)", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy 0.5.15 about override(Base1,Base2)", + groups = {"contract", "daily"}) public void test01OverrideContract515() { String contractName = "override001"; - String code = Configuration.getByPath("testng.conf") - .getString("code.code_override001"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_override001"); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = Configuration.getByPath("testng.conf").getString("code.code_override001"); + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_override001"); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod.getTransactionInfoById(txid, - blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - txid = PublicMethod.triggerContract(contractAddress, "setValue(uint256)", "5", false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "setValue(uint256)", + "5", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); - - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "x()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); + + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "x()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(0, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "y()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + Assert.assertEquals( + 0, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "y()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(5, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - + Assert.assertEquals( + 5, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); } - @Test(enabled = true, description = "Deploy 0.6.0 about not need override", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy 0.6.0 about not need override", + groups = {"contract", "daily"}) public void test02NotNeedOverride() { String filePath = "./src/test/resources/soliditycode/override002.sol"; - String contractName = "D"; + String contractName = "D"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod.getTransactionInfoById(txid, - blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - txid = PublicMethod.triggerContract(contractAddress, "setValue(uint256)", "5", false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "setValue(uint256)", + "5", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); - - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "x()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); + + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "x()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(5, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + 5, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); } - @Test(enabled = true, description = "Deploy 0.6.0 about override(Base1,Base2)", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy 0.6.0 about override(Base1,Base2)", + groups = {"contract", "daily"}) public void test03OverrideMultipleFunctionsWithTheSameName() { String filePath = "./src/test/resources/soliditycode/override003.sol"; - String contractName = "C"; + String contractName = "C"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod.getTransactionInfoById(txid, - blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - txid = PublicMethod.triggerContract(contractAddress, "setValue(uint256)", "5", false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "setValue(uint256)", + "5", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); - - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "x()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); + + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "x()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(5, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "y()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + Assert.assertEquals( + 5, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "y()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(0, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + 0, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); } - @Test(enabled = true, description = "Deploy 0.6.0 about override modifier", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy 0.6.0 about override modifier", + groups = {"contract", "daily"}) public void test04OverrideModifier060() { String filePath = "./src/test/resources/soliditycode/override004.sol"; - String contractName = "C"; + String contractName = "C"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod.getTransactionInfoById(txid, - blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - txid = PublicMethod.triggerContract(contractAddress, "setValue(uint256)", "7", false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "setValue(uint256)", + "7", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(1,infoById.get().getResultValue()); + Assert.assertEquals(1, infoById.get().getResultValue()); Assert.assertTrue(infoById.get().getContractResult(0).toStringUtf8().contains("x must >= 6")); - txid = PublicMethod.triggerContract(contractAddress, "setValue2(uint256)", "6", false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "setValue2(uint256)", + "6", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); - - txid = PublicMethod.triggerContract(contractAddress, "setValue(uint256)", "8", false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); + + txid = + PublicMethod.triggerContract( + contractAddress, + "setValue(uint256)", + "8", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); - - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "x()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); + + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "x()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(8, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + 8, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); } - @Test(enabled = true, description = "Deploy 0.5.15 about override modifier", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy 0.5.15 about override modifier", + groups = {"contract", "daily"}) public void test05OverrideModifier515() { String contractName = "C"; - String code = Configuration.getByPath("testng.conf") - .getString("code.code_override002"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_override002"); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = Configuration.getByPath("testng.conf").getString("code.code_override002"); + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_override002"); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod.getTransactionInfoById(txid, - blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - txid = PublicMethod.triggerContract(contractAddress, "setValue(uint256)", "7", false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "setValue(uint256)", + "7", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(1,infoById.get().getResultValue()); + Assert.assertEquals(1, infoById.get().getResultValue()); Assert.assertTrue(infoById.get().getContractResult(0).toStringUtf8().contains("x must >= 6")); - txid = PublicMethod.triggerContract(contractAddress, "setValue2(uint256)", "6", false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "setValue2(uint256)", + "6", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); - - txid = PublicMethod.triggerContract(contractAddress, "setValue(uint256)", "8", false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); + + txid = + PublicMethod.triggerContract( + contractAddress, + "setValue(uint256)", + "8", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); - - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "x()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); + + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "x()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(8, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + 8, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); } - @Test(enabled = true, description = "Deploy 0.6.0 public override external function", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy 0.6.0 public override external function", + groups = {"contract", "daily"}) public void test06PublicOverrideExternalFunction060() { String filePath = "./src/test/resources/soliditycode/override005.sol"; - String contractName = "Test"; + String contractName = "Test"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod.getTransactionInfoById(txid, - blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "stopped()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "stopped()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(0, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "i()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + Assert.assertEquals( + 0, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "i()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(32482989, ByteArray.toInt(transactionExtention.getConstantResult(0) - .toByteArray())); - - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "i2()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + Assert.assertEquals( + 32482989, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "i2()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(-32482989, ByteArray.toInt(transactionExtention.getConstantResult(0) - .toByteArray())); - - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "ui()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + Assert.assertEquals( + -32482989, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "ui()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(23487823, ByteArray.toInt(transactionExtention.getConstantResult(0) - .toByteArray())); - - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "origin()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + Assert.assertEquals( + 23487823, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "origin()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - byte[] tmpAddress = new byte[20]; - System - .arraycopy(transactionExtention.getConstantResult(0).toByteArray(), 12, tmpAddress, 0, 20); - Assert.assertEquals("TW63BNR5M7LuH1fjXS7Smyza3PZXfHAAs2", + byte[] tmpAddress = new byte[20]; + System.arraycopy( + transactionExtention.getConstantResult(0).toByteArray(), 12, tmpAddress, 0, 20); + Assert.assertEquals( + "TW63BNR5M7LuH1fjXS7Smyza3PZXfHAAs2", Base58.encode58Check(ByteArray.fromHexString("41" + ByteArray.toHexString(tmpAddress)))); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "b32()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "b32()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert.assertEquals("b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105c", + Assert.assertEquals( + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105c", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "choice()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "choice()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000003", + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000003", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); } - @Test(enabled = true, description = "Deploy 0.5.15 public override external function", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy 0.5.15 public override external function", + groups = {"contract", "daily"}) public void test07PublicOverrideExternalFunction515() { String contractName = "Test"; - String code = Configuration.getByPath("testng.conf") - .getString("code.code_override003"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_override003"); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = Configuration.getByPath("testng.conf").getString("code.code_override003"); + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_override003"); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod.getTransactionInfoById(txid, - blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "stopped()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "stopped()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(0, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "i()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + Assert.assertEquals( + 0, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "i()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(32482989, ByteArray.toInt(transactionExtention.getConstantResult(0) - .toByteArray())); - - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "i2()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + Assert.assertEquals( + 32482989, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "i2()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(-32482989, ByteArray.toInt(transactionExtention.getConstantResult(0) - .toByteArray())); - - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "ui()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + Assert.assertEquals( + -32482989, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "ui()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(23487823, ByteArray.toInt(transactionExtention.getConstantResult(0) - .toByteArray())); - - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "origin()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + Assert.assertEquals( + 23487823, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "origin()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - byte[] tmpAddress = new byte[20]; - System - .arraycopy(transactionExtention.getConstantResult(0).toByteArray(), 12, tmpAddress, 0, 20); - Assert.assertEquals("TW63BNR5M7LuH1fjXS7Smyza3PZXfHAAs2", + byte[] tmpAddress = new byte[20]; + System.arraycopy( + transactionExtention.getConstantResult(0).toByteArray(), 12, tmpAddress, 0, 20); + Assert.assertEquals( + "TW63BNR5M7LuH1fjXS7Smyza3PZXfHAAs2", Base58.encode58Check(ByteArray.fromHexString("41" + ByteArray.toHexString(tmpAddress)))); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "b32()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "b32()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert.assertEquals("b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105c", + Assert.assertEquals( + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105c", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "choice()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "choice()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000003", + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000003", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); } @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, - blockingStubFull); } + PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/PayableTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/PayableTest.java index 3b272bb6..fc85b074 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/PayableTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/PayableTest.java @@ -13,116 +13,172 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j public class PayableTest extends TronBaseTest { - private String testFoundationKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); - private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); + private String testFoundationKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); + private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey1.getAddress(); String testKey001 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private byte[] contractAddress; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(testKey001); PublicMethod - .sendcoin(testAddress001, 1000_000_000L, testFoundationAddress, testFoundationKey, - blockingStubFull); - String filePath = "src/test/resources/soliditycode/payable001.sol"; - String contractName = "PayableTest"; + PublicMethod.printAddress(testKey001); + PublicMethod.sendcoin( + testAddress001, 1000_000_000L, testFoundationAddress, testFoundationKey, blockingStubFull); + String filePath = "src/test/resources/soliditycode/payable001.sol"; + String contractName = "PayableTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 10000, 100, null, - testFoundationKey, testFoundationAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 10000, + 100, + null, + testFoundationKey, + testFoundationAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "payable(address) transfer", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "payable(address) transfer", + groups = {"contract", "daily"}) public void tryCatchTest001() { - Account account = PublicMethod - .queryAccount(PublicMethod.decode58Check( - "TBXSw8fM4jpQkGc6zZjsVABFpVN7UvXPdV"), blockingStubFull); - Long balanceBefore = account.getBalance(); - String methodStr = "receiveMoneyTransfer(address,uint256)"; - String argStr = "\"TBXSw8fM4jpQkGc6zZjsVABFpVN7UvXPdV\",3"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + Account account = + PublicMethod.queryAccount( + PublicMethod.decode58Check("TBXSw8fM4jpQkGc6zZjsVABFpVN7UvXPdV"), blockingStubFull); + Long balanceBefore = account.getBalance(); + String methodStr = "receiveMoneyTransfer(address,uint256)"; + String argStr = "\"TBXSw8fM4jpQkGc6zZjsVABFpVN7UvXPdV\",3"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); + Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); - Long balanceAfter = PublicMethod.queryAccount(PublicMethod.decode58Check( - "TBXSw8fM4jpQkGc6zZjsVABFpVN7UvXPdV"), blockingStubFull).getBalance(); - Assert.assertEquals(balanceBefore + 3,balanceAfter.longValue()); + Long balanceAfter = + PublicMethod.queryAccount( + PublicMethod.decode58Check("TBXSw8fM4jpQkGc6zZjsVABFpVN7UvXPdV"), blockingStubFull) + .getBalance(); + Assert.assertEquals(balanceBefore + 3, balanceAfter.longValue()); } - @Test(enabled = true, description = "payable(address) send", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "payable(address) send", + groups = {"contract", "daily"}) public void tryCatchTest002() { - Account account = PublicMethod - .queryAccount(PublicMethod.decode58Check( - "TBXSw8fM4jpQkGc6zZjsVABFpVN7UvXPdV"), blockingStubFull); - Long balanceBefore = account.getBalance(); - String methodStr = "receiveMoneySend(address,uint256)"; - String argStr = "\"TBXSw8fM4jpQkGc6zZjsVABFpVN7UvXPdV\",3"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + Account account = + PublicMethod.queryAccount( + PublicMethod.decode58Check("TBXSw8fM4jpQkGc6zZjsVABFpVN7UvXPdV"), blockingStubFull); + Long balanceBefore = account.getBalance(); + String methodStr = "receiveMoneySend(address,uint256)"; + String argStr = "\"TBXSw8fM4jpQkGc6zZjsVABFpVN7UvXPdV\",3"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); + Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); - Long balanceAfter = PublicMethod.queryAccount(PublicMethod.decode58Check( - "TBXSw8fM4jpQkGc6zZjsVABFpVN7UvXPdV"), blockingStubFull).getBalance(); - Assert.assertEquals(balanceBefore + 3,balanceAfter.longValue()); + Long balanceAfter = + PublicMethod.queryAccount( + PublicMethod.decode58Check("TBXSw8fM4jpQkGc6zZjsVABFpVN7UvXPdV"), blockingStubFull) + .getBalance(); + Assert.assertEquals(balanceBefore + 3, balanceAfter.longValue()); } - @Test(enabled = true, description = "payable(address(contract)) transfer", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "payable(address(contract)) transfer", + groups = {"contract", "daily"}) public void tryCatchTest003() { String filePath = "src/test/resources/soliditycode/payable001.sol"; - String contractName = "A"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] AContract = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0, 100, null, - testKey001, testAddress001, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] AContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - - Account account = PublicMethod - .queryAccount(AContract, blockingStubFull); - Long balanceBefore = account.getBalance(); - String methodStr = "receiveMoneyTransferWithContract(address,uint256)"; - String argStr = "\"" + Base58.encode58Check(AContract) + "\",3"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + Account account = PublicMethod.queryAccount(AContract, blockingStubFull); + Long balanceBefore = account.getBalance(); + String methodStr = "receiveMoneyTransferWithContract(address,uint256)"; + String argStr = "\"" + Base58.encode58Check(AContract) + "\",3"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); + Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); - Long balanceAfter = PublicMethod.queryAccount(AContract, blockingStubFull).getBalance(); - Assert.assertEquals(balanceBefore + 3,balanceAfter.longValue()); + Long balanceAfter = PublicMethod.queryAccount(AContract, blockingStubFull).getBalance(); + Assert.assertEquals(balanceBefore + 3, balanceAfter.longValue()); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/SelectorTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/SelectorTest.java index 17411a62..0c650541 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/SelectorTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/SelectorTest.java @@ -10,43 +10,55 @@ import org.tron.api.GrpcAPI.TransactionExtention; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class SelectorTest extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] contractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/selector.sol"; - String contractName = "A"; + String filePath = "./src/test/resources/soliditycode/selector.sol"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); - final String aContractAddress = ByteArray.toHexString(contractAddress); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); + final String aContractAddress = ByteArray.toHexString(contractAddress); contractName = "testSelector"; retMap = PublicMethod.getBycodeAbi(filePath, contractName); @@ -55,28 +67,58 @@ public class SelectorTest extends TronBaseTest { code = PublicMethod.replaceCode(code, aContractAddress.substring(1)); logger.info("code:" + code); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Get the selector of public or external library functions " - + "through member variables", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Get the selector of public or external library functions " + "through member variables", + groups = {"contract", "daily"}) public void test01GetSelector() { - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "getselector2()", "#", false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertThat(transactionExtention.getResult().getCode().toString(), - containsString("SUCCESS")); - logger.info("result: " + ByteArray - .toHexString(transactionExtention.getConstantResult(0).toByteArray())); - Assert.assertEquals("f8b2cb4f", PublicMethod.removeAll0sAtTheEndOfHexStr(ByteArray - .toHexString(transactionExtention.getConstantResult(0).toByteArray()).substring(0, 64))); - Assert.assertEquals("b4cef28d", PublicMethod.removeAll0sAtTheEndOfHexStr(ByteArray - .toHexString(transactionExtention.getConstantResult(0).toByteArray()).substring(64))); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getselector2()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), containsString("SUCCESS")); + logger.info( + "result: " + + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + "f8b2cb4f", + PublicMethod.removeAll0sAtTheEndOfHexStr( + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()) + .substring(0, 64))); + Assert.assertEquals( + "b4cef28d", + PublicMethod.removeAll0sAtTheEndOfHexStr( + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()) + .substring(64))); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/ShanghaiUpdate.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/ShanghaiUpdate.java index c3d7b8f4..2a8e50c7 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/ShanghaiUpdate.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/ShanghaiUpdate.java @@ -1,96 +1,126 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.newGrammar; +import java.util.HashMap; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI; -import org.tron.protos.Protocol; import org.tron.protos.contract.SmartContractOuterClass; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; - -import java.util.HashMap; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class ShanghaiUpdate extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] CContract = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 300100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 300100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/shanghaiUpdate.sol"; - String contractName = "Test"; + String filePath = "src/test/resources/soliditycode/shanghaiUpdate.sol"; + String contractName = "Test"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); -// String code = Configuration.getByPath("testng.conf") -// .getString("code.code_shanghai_update"); - //shanghaiUpdate.sol contract C -// String abi = Configuration.getByPath("testng.conf") -// .getString("abi.abi_shanghai_update"); - CContract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + // String code = Configuration.getByPath("testng.conf") + // .getString("code.code_shanghai_update"); + // shanghaiUpdate.sol contract C + // String abi = Configuration.getByPath("testng.conf") + // .getString("abi.abi_shanghai_update"); + CContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(CContract, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(CContract, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - - @Test(enabled = true, description = "test push0 using return 0", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test push0 using return 0", + groups = {"contract", "daily"}) public void test001Push0() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(CContract, - "zero()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + CContract, + "zero()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(0, result); - } - @Test(enabled = true, description = "test push0 is support", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test push0 is support", + groups = {"contract", "daily"}) public void test002Push0() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(CContract, - "isPush0Supported()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + CContract, + "isPush0Supported()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(1, result); - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/SlotAndOffsetNewGrammar.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/SlotAndOffsetNewGrammar.java index f9f456b0..425b8421 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/SlotAndOffsetNewGrammar.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/SlotAndOffsetNewGrammar.java @@ -11,11 +11,10 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; - +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class SlotAndOffsetNewGrammar extends TronBaseTest { @@ -25,97 +24,135 @@ public class SlotAndOffsetNewGrammar extends TronBaseTest { private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 1000_000_000L, fromAddress, - testKey002, blockingStubFull)); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1000_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - /** - * trigger contract and assert. - */ + /** trigger contract and assert. */ public void assertResult(byte[] contractAddress) { String txid = ""; - txid = PublicMethod.triggerContract(contractAddress, "getA()", "", false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "getA()", + "", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - String res = "0000000000000000000000000000000000000000000000000000000000000001" - + "0000000000000000000000000000000000000000000000000000000000000000"; + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + String res = + "0000000000000000000000000000000000000000000000000000000000000001" + + "0000000000000000000000000000000000000000000000000000000000000000"; System.out.println(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); - Assert.assertEquals(res, - ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); + Assert.assertEquals( + res, ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); - txid = PublicMethod.triggerContract(contractAddress, "getE()", "", false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "getE()", + "", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - res = "0000000000000000000000000000000000000000000000000000000000000004" - + "0000000000000000000000000000000000000000000000000000000000000000"; + res = + "0000000000000000000000000000000000000000000000000000000000000004" + + "0000000000000000000000000000000000000000000000000000000000000000"; System.out.println(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); - Assert.assertEquals(res, - ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); - + Assert.assertEquals( + res, ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "Deploy 0.6.x new grammer", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy 0.6.x new grammer", + groups = {"contract", "daily"}) public void testSlotAndOffsetOldVersion() { String contractName = "A"; - String code = Configuration.getByPath("testng.conf") - .getString("code.code_slotAndOffset_06x"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_slotAndOffset_06x"); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = Configuration.getByPath("testng.conf").getString("code.code_slotAndOffset_06x"); + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_slotAndOffset_06x"); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod.getTransactionInfoById(txid, - blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); assertResult(contractAddress); - } - @Test(enabled = true, description = "Deploy 0.7.0 new grammer", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy 0.7.0 new grammer", + groups = {"contract", "daily"}) public void testSlotAndOffsetNew() { String filePath = "./src/test/resources/soliditycode/slotAndOffsetNewGrammer.sol"; - String contractName = "A"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod.getTransactionInfoById(txid, - blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); assertResult(contractAddress); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); } + PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/StringSplitTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/StringSplitTest.java index f9433cff..be99072b 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/StringSplitTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/StringSplitTest.java @@ -10,136 +10,255 @@ import org.tron.api.GrpcAPI.TransactionExtention; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class StringSplitTest extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] contractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/stringSplit.sol"; - String contractName = "testStringSplit"; + String filePath = "./src/test/resources/soliditycode/stringSplit.sol"; + String contractName = "testStringSplit"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "get s1 n1", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "get s1 n1", + groups = {"contract", "daily"}) public void test01GetS1N1() { - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "getS1()", "#", false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertThat(transactionExtention.getResult().getCode().toString(), - containsString("SUCCESS")); - Assert.assertEquals("s12,./", - PublicMethod.hexStringToString(PublicMethod.removeAll0sAtTheEndOfHexStr( - ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())) - .substring(128))); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getS1()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), containsString("SUCCESS")); + Assert.assertEquals( + "s12,./", + PublicMethod.hexStringToString( + PublicMethod.removeAll0sAtTheEndOfHexStr( + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())) + .substring(128))); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "getS1N1()", "#", false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertThat(transactionExtention.getResult().getCode().toString(), - containsString("SUCCESS")); - Assert.assertEquals("s12,./", - PublicMethod.hexStringToString(PublicMethod.removeAll0sAtTheEndOfHexStr( - ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())) - .substring(128))); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getS1N1()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), containsString("SUCCESS")); + Assert.assertEquals( + "s12,./", + PublicMethod.hexStringToString( + PublicMethod.removeAll0sAtTheEndOfHexStr( + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())) + .substring(128))); } - @Test(enabled = true, description = "get s2 n2", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "get s2 n2", + groups = {"contract", "daily"}) public void test01GetS2N2() { - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "getS2()", "#", false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertThat(transactionExtention.getResult().getCode().toString(), - containsString("SUCCESS")); - Assert.assertEquals("s123?\\'.", - PublicMethod.hexStringToString(PublicMethod.removeAll0sAtTheEndOfHexStr( - ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())) - .substring(128))); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getS2()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), containsString("SUCCESS")); + Assert.assertEquals( + "s123?\\'.", + PublicMethod.hexStringToString( + PublicMethod.removeAll0sAtTheEndOfHexStr( + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())) + .substring(128))); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "getS2N2()", "#", false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertThat(transactionExtention.getResult().getCode().toString(), - containsString("SUCCESS")); - Assert.assertEquals("s123?\'.", - PublicMethod.hexStringToString(PublicMethod.removeAll0sAtTheEndOfHexStr( - ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())) - .substring(128))); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getS2N2()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), containsString("SUCCESS")); + Assert.assertEquals( + "s123?\'.", + PublicMethod.hexStringToString( + PublicMethod.removeAll0sAtTheEndOfHexStr( + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())) + .substring(128))); } - @Test(enabled = true, description = "get s3 n3", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "get s3 n3", + groups = {"contract", "daily"}) public void test01GetS3N3() { - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "getS3()", "#", false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertThat(transactionExtention.getResult().getCode().toString(), - containsString("SUCCESS")); - Assert.assertEquals("AB", - PublicMethod.hexStringToString(PublicMethod.removeAll0sAtTheEndOfHexStr( - ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())) - .substring(128))); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getS3()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), containsString("SUCCESS")); + Assert.assertEquals( + "AB", + PublicMethod.hexStringToString( + PublicMethod.removeAll0sAtTheEndOfHexStr( + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())) + .substring(128))); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "getS3N3()", "#", false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertThat(transactionExtention.getResult().getCode().toString(), - containsString("SUCCESS")); - Assert.assertEquals("AB", - PublicMethod.hexStringToString(PublicMethod.removeAll0sAtTheEndOfHexStr( - ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())) - .substring(128))); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getS3N3()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), containsString("SUCCESS")); + Assert.assertEquals( + "AB", + PublicMethod.hexStringToString( + PublicMethod.removeAll0sAtTheEndOfHexStr( + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())) + .substring(128))); } - @Test(enabled = true, description = "get s4 n4", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "get s4 n4", + groups = {"contract", "daily"}) public void test01GetS4N4() { - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "getS4()", "#", false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertThat(transactionExtention.getResult().getCode().toString(), - containsString("SUCCESS")); - Assert.assertEquals("AB", - PublicMethod.hexStringToString(PublicMethod.removeAll0sAtTheEndOfHexStr( - ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())) - .substring(128))); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getS4()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), containsString("SUCCESS")); + Assert.assertEquals( + "AB", + PublicMethod.hexStringToString( + PublicMethod.removeAll0sAtTheEndOfHexStr( + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())) + .substring(128))); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "getS4N4()", "#", false, 0, - 0, "0", 0, dev001Address, dev001Key, blockingStubFull); - Assert.assertThat(transactionExtention.getResult().getCode().toString(), - containsString("SUCCESS")); - Assert.assertEquals("AB", - PublicMethod.hexStringToString(PublicMethod.removeAll0sAtTheEndOfHexStr( - ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())) - .substring(128))); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "getS4N4()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), containsString("SUCCESS")); + Assert.assertEquals( + "AB", + PublicMethod.hexStringToString( + PublicMethod.removeAll0sAtTheEndOfHexStr( + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())) + .substring(128))); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/TvmVote.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/TvmVote.java index 835acea0..bccd3358 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/TvmVote.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/TvmVote.java @@ -5,7 +5,6 @@ import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; -import org.testng.SkipException; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -16,18 +15,19 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.Flaky; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -@Flaky(reason = "Requires specific SR voting state, sensitive to block timing", +@Flaky( + reason = "Requires specific SR voting state, sensitive to block timing", since = "2026-04-03") public class TvmVote extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] mapKeyContract = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -36,84 +36,128 @@ public class TvmVote extends TronBaseTest { int freezeCount = 100000000; int voteCount = 1; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() throws Exception { PublicMethod.printAddress(contractExcKey); -// if(PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { -// throw new SkipException("Skipping freezeV2 test case"); -// } + // if(PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + // throw new SkipException("Skipping freezeV2 test case"); + // } - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 300100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 300100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/tvmVote.sol"; - String contractName = "TestVote"; + String filePath = "src/test/resources/soliditycode/tvmVote.sol"; + String contractName = "TestVote"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - mapKeyContract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000000L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + mapKeyContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000000L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(mapKeyContract, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(mapKeyContract, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "query reward balance", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "query reward balance", + groups = {"contract", "daily"}) public void test01QueryRewardBalance() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "queryRewardBalance()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "queryRewardBalance()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); long trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info("result: " + trueRes); Assert.assertEquals(0, trueRes); - GrpcAPI.BytesMessage bytesMessage = GrpcAPI.BytesMessage.newBuilder().setValue(ByteString - .copyFrom(mapKeyContract)) - .build(); + GrpcAPI.BytesMessage bytesMessage = + GrpcAPI.BytesMessage.newBuilder().setValue(ByteString.copyFrom(mapKeyContract)).build(); long reward = blockingStubFull.getRewardInfo(bytesMessage).getNum(); org.testng.Assert.assertEquals(trueRes, reward); } - - @Test(enabled = true, description = "freeze balance and vote witness", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "freeze balance and vote witness", + groups = {"contract", "daily"}) public void test02VoteWitness() { String methodStr = "freezev2(uint256,uint256)"; - String receiverAdd = Base58.encode58Check(mapKeyContract); - String args = "" + freezeCount + ",1"; - String triggerTxid = PublicMethod.triggerContract(mapKeyContract, - methodStr, args, false, 0, maxFeeLimit, "0", 0, - contractExcAddress, contractExcKey, blockingStubFull); + String receiverAdd = Base58.encode58Check(mapKeyContract); + String args = "" + freezeCount + ",1"; + String triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + methodStr, + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); Protocol.InternalTransaction internal = transactionInfo.get().getInternalTransactions(0); - String note = internal.getNote().toStringUtf8(); + String note = internal.getNote().toStringUtf8(); Assert.assertEquals("freezeBalanceV2ForEnergy", note); Assert.assertEquals(freezeCount, internal.getCallValueInfo(0).getCallValue()); - String witness58Add = Base58.encode58Check(witnessAddress); + String witness58Add = Base58.encode58Check(witnessAddress); args = "[\"" + witness58Add + "\"],[" + voteCount + "]"; logger.info("vote args: " + args); methodStr = "voteWitness(address[],uint256[])"; - triggerTxid = PublicMethod.triggerContract(mapKeyContract, methodStr, args, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + methodStr, + args, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + transactionInfo = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); internal = transactionInfo.get().getInternalTransactions(0); note = internal.getNote().toStringUtf8(); @@ -121,112 +165,208 @@ public void test02VoteWitness() { Assert.assertTrue(internal.getExtra().length() > 1); Protocol.Account info = PublicMethod.queryAccount(mapKeyContract, blockingStubFull); - int voteCount = info.getVotesCount(); + int voteCount = info.getVotesCount(); logger.info("voteCount: " + voteCount); Assert.assertEquals(1, voteCount); } - @Test(enabled = true, description = "query contract address is Sr Candidate or not", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "query contract address is Sr Candidate or not", + groups = {"contract", "daily"}) public void test03IsSrCandidate() { String args = "\"" + Base58.encode58Check(mapKeyContract) + "\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "isWitness(address)", args, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "isWitness(address)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info(trueRes + ""); Assert.assertEquals(0, 0); } - @Test(enabled = true, description = "query sr address is Sr Candidate or not", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "query sr address is Sr Candidate or not", + groups = {"contract", "daily"}) public void test04IsSrCandidate() { String args = "\"" + Base58.encode58Check(witnessAddress) + "\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "isWitness(address)", args, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "isWitness(address)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info(trueRes + ""); Assert.assertEquals(1, 1); } - @Test(enabled = true, description = "query zero address is Sr Candidate or not", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "query zero address is Sr Candidate or not", + groups = {"contract", "daily"}) public void test05IsSrCandidate() { String args = "\"T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "isWitness(address)", args, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "isWitness(address)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info(trueRes + ""); Assert.assertEquals(0, 0); } - @Test(enabled = true, description = "query sr's total vote count", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "query sr's total vote count", + groups = {"contract", "daily"}) public void test06querySrTotalVoteCount() { String args = "\"" + Base58.encode58Check(witnessAddress) + "\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "queryTotalVoteCount(address)", args, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "queryTotalVoteCount(address)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info(trueRes + ""); Assert.assertEquals(0, trueRes); } - @Test(enabled = true, description = "query contract's total vote count", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "query contract's total vote count", + groups = {"contract", "daily"}) public void test07queryContractTotalVoteCount() { String args = "\"" + Base58.encode58Check(mapKeyContract) + "\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "queryTotalVoteCount(address)", args, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "queryTotalVoteCount(address)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info(trueRes + ""); Assert.assertEquals(freezeCount / 1000000, trueRes); } - @Test(enabled = true, description = "query vote count", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "query vote count", + groups = {"contract", "daily"}) public void test08queryVoteCount() { String from = Base58.encode58Check(mapKeyContract); - String to = Base58.encode58Check(witnessAddress); - String args = "\"" + from + "\",\"" + to + "\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "queryVoteCount(address,address)", args, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + String to = Base58.encode58Check(witnessAddress); + String args = "\"" + from + "\",\"" + to + "\""; + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "queryVoteCount(address,address)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info(trueRes + ""); Assert.assertEquals(voteCount, trueRes); } - @Test(enabled = true, description = "query contract used vote count", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "query contract used vote count", + groups = {"contract", "daily"}) public void test09queryUsedVoteCount() { String from = Base58.encode58Check(mapKeyContract); - String args = "\"" + from + "\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "queryUsedVoteCount(address)", args, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + String args = "\"" + from + "\""; + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "queryUsedVoteCount(address)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info(trueRes + ""); Assert.assertEquals(voteCount, trueRes); } - @Test(enabled = true, description = "query witnesses received vote count", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "query witnesses received vote count", + groups = {"contract", "daily"}) public void test10queryReceivedVoteCount() { String witness = Base58.encode58Check(witnessAddress); - String args = "\"" + witness + "\""; - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "queryReceivedVoteCount(address)", args, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + String args = "\"" + witness + "\""; + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "queryReceivedVoteCount(address)", + args, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int trueRes = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); logger.info(trueRes + ""); Assert.assertTrue(trueRes > 0); Optional list = PublicMethod.listWitnesses(blockingStubFull); long receiveCount = 0; - String temAdd; + String temAdd; for (int i = 0; i < list.get().getWitnessesCount(); i++) { temAdd = Base58.encode58Check(list.get().getWitnesses(i).getAddress().toByteArray()); if (witness.equals(temAdd)) { @@ -237,67 +377,101 @@ public void test10queryReceivedVoteCount() { Assert.assertEquals(trueRes, receiveCount); } - @Test(enabled = true, description = "withdraw reward", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "withdraw reward", + groups = {"contract", "daily"}) public void test11WithdrawReward() { String methodStr = "withdrawReward()"; - String triggerTxid = PublicMethod.triggerContract(mapKeyContract, methodStr, "#", false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + methodStr, + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); PublicMethod.waitProduceNextBlock(blockingStubFull); Protocol.InternalTransaction internal = transactionInfo.get().getInternalTransactions(0); - String note = internal.getNote().toStringUtf8(); + String note = internal.getNote().toStringUtf8(); Assert.assertEquals("withdrawReward", note); Assert.assertEquals(1, internal.getCallValueInfoCount()); Assert.assertEquals("", internal.getCallValueInfo(0).toString()); } - @Test(enabled = true, description = "unfreeze energy", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "unfreeze energy", + groups = {"contract", "daily"}) public void test12Unfreeze() { String methodStr = "unfreezev2(uint256,uint256)"; - String args = ""+freezeCount+",1"; - String triggerTxid = PublicMethod.triggerContract(mapKeyContract, methodStr, args, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String args = "" + freezeCount + ",1"; + String triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + methodStr, + args, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); Protocol.InternalTransaction internal = transactionInfo.get().getInternalTransactions(0); - String note = internal.getNote().toStringUtf8(); + String note = internal.getNote().toStringUtf8(); Assert.assertEquals("unfreezeBalanceV2ForEnergy", note); Assert.assertEquals(freezeCount, internal.getCallValueInfo(0).getCallValue()); } - @Test(enabled = true, description = "kill me", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "kill me", + groups = {"contract", "daily"}) public void test13Suicide() { String methodStr = "killme(address)"; - String args = "\"" + Base58.encode58Check(witnessAddress) + "\""; - String triggerTxid = PublicMethod.triggerContract(mapKeyContract, methodStr, args, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String args = "\"" + Base58.encode58Check(witnessAddress) + "\""; + String triggerTxid = + PublicMethod.triggerContract( + mapKeyContract, + methodStr, + args, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(1, transactionInfo.get().getResultValue()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.REVERT, + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.REVERT, transactionInfo.get().getReceipt().getResult()); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/UsdtTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/UsdtTest.java index cb3c7cd3..5fb5f112 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/UsdtTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/UsdtTest.java @@ -1,6 +1,7 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.newGrammar; import com.google.protobuf.ByteString; +import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.testng.annotations.AfterClass; @@ -10,14 +11,17 @@ import org.tron.protos.Protocol.TransactionInfo; import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; - -import java.util.Optional; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class UsdtTest extends TronBaseTest { private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); +public class UsdtTest extends TronBaseTest { + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); private byte[] usdtAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -28,221 +32,344 @@ public class UsdtTest extends TronBaseTest { private final String testNetAccoun byte[] callerddress = ecKey.getAddress(); String callerAddress58 = Base58.encode58Check(callerddress); String callerKey = ByteArray.toHexString(ecKey.getPrivKeyBytes()); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_usdt"); - String code = Configuration.getByPath("testng.conf") - .getString("code.code_usdt"); - + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_usdt"); + String code = Configuration.getByPath("testng.conf").getString("code.code_usdt"); @BeforeClass(enabled = true) - public void beforeClass() { Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 10000000000L, testNetAccountAddress, testNetAccountKey, + public void beforeClass() { + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); - PublicMethod.freezeBalanceV2(testNetAccountAddress, 1000000000L, 0, testNetAccountKey, blockingStubFull); + PublicMethod.freezeBalanceV2( + testNetAccountAddress, 1000000000L, 0, testNetAccountKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod.freezeBalanceForReceiver(testNetAccountAddress, 2000000000L, - 0, 1, ByteString.copyFrom(dev001Address), testNetAccountKey, blockingStubFull); + PublicMethod.freezeBalanceForReceiver( + testNetAccountAddress, + 2000000000L, + 0, + 1, + ByteString.copyFrom(dev001Address), + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName = "Usdt-test"; - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", 3000000000L, - 0, 70, 10000, "0", 0, null, dev001Key, dev001Address, + String contractName = "Usdt-test"; + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + 3000000000L, + 0, + 70, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, blockingStubFull); logger.info("txid: " + txid); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (txid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } usdtAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(usdtAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(usdtAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); logger.info(Base58.encode58Check(usdtAddress)); } - /** - * constructor. - */ - - @Test(enabled = true, description = "Test 4.7.1.1 hot fix of trigger " - + "has no balance and no energyLimit when transfer USDT", groups = {"contract", "daily"}) + /** constructor. */ + @Test( + enabled = true, + description = + "Test 4.7.1.1 hot fix of trigger " + + "has no balance and no energyLimit when transfer USDT", + groups = {"contract", "daily"}) public void test01() { - Assert.assertTrue(PublicMethod - .sendcoin(callerddress, 10000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + callerddress, 10000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod - .sendcoin(testNetAccountAddress, 10000000L, callerddress, callerKey, blockingStubFull)); - String methedStr = "transfer(address,uint256)"; - String argsStr = "\"" + callerAddress58 + "\",100"; - String txid = PublicMethod.triggerContract(usdtAddress, methedStr, argsStr, - false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + Assert.assertTrue( + PublicMethod.sendcoin( + testNetAccountAddress, 10000000L, callerddress, callerKey, blockingStubFull)); + String methedStr = "transfer(address,uint256)"; + String argsStr = "\"" + callerAddress58 + "\",100"; + String txid = + PublicMethod.triggerContract( + usdtAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, infoById.get().getReceipt().getResult()); - - long origin_window_size_before = PublicMethod.queryAccount(dev001Address,blockingStubFull) - .getAccountResource().getEnergyWindowSize(); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, + infoById.get().getReceipt().getResult()); + + long origin_window_size_before = + PublicMethod.queryAccount(dev001Address, blockingStubFull) + .getAccountResource() + .getEnergyWindowSize(); argsStr = "\"" + dev58 + "\",1"; - txid = PublicMethod.triggerContract(usdtAddress, methedStr, argsStr, - false, 0, maxFeeLimit, callerddress, callerKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + usdtAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + callerddress, + callerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - long origin_window_size_after = PublicMethod.queryAccount(dev001Address,blockingStubFull) - .getAccountResource().getEnergyWindowSize(); + long origin_window_size_after = + PublicMethod.queryAccount(dev001Address, blockingStubFull) + .getAccountResource() + .getEnergyWindowSize(); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("11111 infoById: " + infoById); logger.info("origin_window_size_before: " + origin_window_size_before); logger.info("origin_window_size_after: " + origin_window_size_after); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY, + infoById.get().getReceipt().getResult()); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() == 0); Assert.assertTrue(infoById.get().getReceipt().getOriginEnergyUsage() == 0); Assert.assertTrue(infoById.get().getReceipt().getNetUsage() > 0); - - } - /** - * constructor. - */ - - @Test(enabled = true, description = "Test 4.7.1.1 hot fix of trigger " - + "has balance, no energyLimit and feeLimit is 0 when transfer USDT", groups = {"contract", "daily"}) + /** constructor. */ + @Test( + enabled = true, + description = + "Test 4.7.1.1 hot fix of trigger " + + "has balance, no energyLimit and feeLimit is 0 when transfer USDT", + groups = {"contract", "daily"}) public void test02() { - Assert.assertTrue(PublicMethod - .sendcoin(callerddress, 10000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + callerddress, 10000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String methedStr = "transfer(address,uint256)"; - String argsStr = "\"" + dev58 + "\",1"; - long origin_window_size_before = PublicMethod.queryAccount(dev001Address,blockingStubFull) - .getAccountResource().getEnergyWindowSize(); - String txid = PublicMethod.triggerContract(usdtAddress, methedStr, argsStr, - false, 0, 0, callerddress, callerKey, blockingStubFull); + String methedStr = "transfer(address,uint256)"; + String argsStr = "\"" + dev58 + "\",1"; + long origin_window_size_before = + PublicMethod.queryAccount(dev001Address, blockingStubFull) + .getAccountResource() + .getEnergyWindowSize(); + String txid = + PublicMethod.triggerContract( + usdtAddress, + methedStr, + argsStr, + false, + 0, + 0, + callerddress, + callerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - long origin_window_size_after = PublicMethod.queryAccount(dev001Address,blockingStubFull) - .getAccountResource().getEnergyWindowSize(); + long origin_window_size_after = + PublicMethod.queryAccount(dev001Address, blockingStubFull) + .getAccountResource() + .getEnergyWindowSize(); - Optional infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("22222 infoById: " + infoById); logger.info("origin_window_size_before: " + origin_window_size_before); logger.info("origin_window_size_after: " + origin_window_size_after); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY, + infoById.get().getReceipt().getResult()); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() == 0); Assert.assertTrue(infoById.get().getReceipt().getOriginEnergyUsage() == 0); Assert.assertTrue(infoById.get().getReceipt().getNetUsage() > 0); - - } - @Test(enabled = true, description = "Test 4.7.1.1 hot fix of trigger has " - + "no balance,no energyLimit,feeLimit is 0 when transfer USDT", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Test 4.7.1.1 hot fix of trigger has " + + "no balance,no energyLimit,feeLimit is 0 when transfer USDT", + groups = {"contract", "daily"}) public void test03() { long balance = PublicMethod.queryAccount(callerddress, blockingStubFull).getBalance(); - PublicMethod.delegateResourceV2(testNetAccountAddress, 300000000L, 0, callerddress, testNetAccountKey, blockingStubFull); + PublicMethod.delegateResourceV2( + testNetAccountAddress, 300000000L, 0, callerddress, testNetAccountKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod - .sendcoin(testNetAccountAddress, balance, callerddress, callerKey, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testNetAccountAddress, balance, callerddress, callerKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String methedStr = "transfer(address,uint256)"; - String argsStr = "\"" + dev58 + "\",1"; - long origin_window_size_before = PublicMethod.queryAccount(dev001Address,blockingStubFull) - .getAccountResource().getEnergyWindowSize(); - String txid = PublicMethod.triggerContract(usdtAddress, methedStr, argsStr, - false, 0, 0, callerddress, callerKey, blockingStubFull); + String methedStr = "transfer(address,uint256)"; + String argsStr = "\"" + dev58 + "\",1"; + long origin_window_size_before = + PublicMethod.queryAccount(dev001Address, blockingStubFull) + .getAccountResource() + .getEnergyWindowSize(); + String txid = + PublicMethod.triggerContract( + usdtAddress, + methedStr, + argsStr, + false, + 0, + 0, + callerddress, + callerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - long origin_window_size_after = PublicMethod.queryAccount(dev001Address,blockingStubFull) - .getAccountResource().getEnergyWindowSize(); + long origin_window_size_after = + PublicMethod.queryAccount(dev001Address, blockingStubFull) + .getAccountResource() + .getEnergyWindowSize(); - Optional infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("22222 infoById: " + infoById); logger.info("origin_window_size_before: " + origin_window_size_before); logger.info("origin_window_size_after: " + origin_window_size_after); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY, + infoById.get().getReceipt().getResult()); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() == 0); Assert.assertTrue(infoById.get().getReceipt().getOriginEnergyUsage() == 0); Assert.assertTrue(infoById.get().getReceipt().getNetUsage() > 0); - } - @Test(enabled = true, description = "Test 4.7.1.1 hot fix of trigger has " - + "no balance, has energyLimit,feeLimit is 0 when transfer USDT", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Test 4.7.1.1 hot fix of trigger has " + + "no balance, has energyLimit,feeLimit is 0 when transfer USDT", + groups = {"contract", "daily"}) public void test04() { // no balance, has energyLimit,feeLimit is 0 long balance = PublicMethod.queryAccount(callerddress, blockingStubFull).getBalance(); - PublicMethod.delegateResourceV2(testNetAccountAddress, 600000000L, 1, callerddress, testNetAccountKey, blockingStubFull); + PublicMethod.delegateResourceV2( + testNetAccountAddress, 600000000L, 1, callerddress, testNetAccountKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); if (balance != 0) { - Assert.assertTrue(PublicMethod - .sendcoin(testNetAccountAddress, balance, callerddress, callerKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testNetAccountAddress, balance, callerddress, callerKey, blockingStubFull)); } PublicMethod.waitProduceNextBlock(blockingStubFull); - String methedStr = "transfer(address,uint256)"; - String argsStr = "\"" + dev58 + "\",1"; - long origin_window_size_before = PublicMethod.queryAccount(dev001Address,blockingStubFull) - .getAccountResource().getEnergyWindowSize(); - String txid = PublicMethod.triggerContract(usdtAddress, methedStr, argsStr, - false, 0, 0, callerddress, callerKey, blockingStubFull); + String methedStr = "transfer(address,uint256)"; + String argsStr = "\"" + dev58 + "\",1"; + long origin_window_size_before = + PublicMethod.queryAccount(dev001Address, blockingStubFull) + .getAccountResource() + .getEnergyWindowSize(); + String txid = + PublicMethod.triggerContract( + usdtAddress, + methedStr, + argsStr, + false, + 0, + 0, + callerddress, + callerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - long origin_window_size_after = PublicMethod.queryAccount(dev001Address,blockingStubFull) - .getAccountResource().getEnergyWindowSize(); + long origin_window_size_after = + PublicMethod.queryAccount(dev001Address, blockingStubFull) + .getAccountResource() + .getEnergyWindowSize(); - Optional infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("22222 infoById: " + infoById); logger.info("origin_window_size_before: " + origin_window_size_before); logger.info("origin_window_size_after: " + origin_window_size_after); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY, + infoById.get().getReceipt().getResult()); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() == 0); Assert.assertTrue(infoById.get().getReceipt().getOriginEnergyUsage() == 0); Assert.assertTrue(infoById.get().getReceipt().getNetUsage() > 0); - } - @Test(enabled = true, description = "Test 4.7.1.1 hot fix of trigger has " - + "has balance and energyLimit, feeLimit is 0 when transfer USDT", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Test 4.7.1.1 hot fix of trigger has " + + "has balance and energyLimit, feeLimit is 0 when transfer USDT", + groups = {"contract", "daily"}) public void test05() { // has balance, has energyLimit,feeLimit is 0 - Assert.assertTrue(PublicMethod - .sendcoin(callerddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + callerddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String methedStr = "transfer(address,uint256)"; - String argsStr = "\"" + dev58 + "\",1"; - long origin_window_size_before = PublicMethod.queryAccount(dev001Address,blockingStubFull) - .getAccountResource().getEnergyWindowSize(); - String txid = PublicMethod.triggerContract(usdtAddress, methedStr, argsStr, - false, 0, 0, callerddress, callerKey, blockingStubFull); + String methedStr = "transfer(address,uint256)"; + String argsStr = "\"" + dev58 + "\",1"; + long origin_window_size_before = + PublicMethod.queryAccount(dev001Address, blockingStubFull) + .getAccountResource() + .getEnergyWindowSize(); + String txid = + PublicMethod.triggerContract( + usdtAddress, + methedStr, + argsStr, + false, + 0, + 0, + callerddress, + callerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - long origin_window_size_after = PublicMethod.queryAccount(dev001Address,blockingStubFull) - .getAccountResource().getEnergyWindowSize(); + long origin_window_size_after = + PublicMethod.queryAccount(dev001Address, blockingStubFull) + .getAccountResource() + .getEnergyWindowSize(); - Optional infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("22222 infoById: " + infoById); logger.info("origin_window_size_before: " + origin_window_size_before); logger.info("origin_window_size_after: " + origin_window_size_after); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY, + infoById.get().getReceipt().getResult()); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() == 0); Assert.assertTrue(infoById.get().getReceipt().getOriginEnergyUsage() == 0); Assert.assertTrue(infoById.get().getReceipt().getNetUsage() > 0); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, testNetAccountAddress, blockingStubFull); PublicMethod.freeResource(callerddress, callerKey, testNetAccountAddress, blockingStubFull); - PublicMethod.unDelegateResourceV2(testNetAccountAddress, 1000000000L, 1, dev001Address, testNetAccountKey, blockingStubFull); - PublicMethod.unDelegateResourceV2(testNetAccountAddress, 300000000L, 0, callerddress, testNetAccountKey, blockingStubFull); } + PublicMethod.unDelegateResourceV2( + testNetAccountAddress, 1000000000L, 1, dev001Address, testNetAccountKey, blockingStubFull); + PublicMethod.unDelegateResourceV2( + testNetAccountAddress, 300000000L, 0, callerddress, testNetAccountKey, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/UsdtTest001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/UsdtTest001.java index f5a04760..8e507780 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/UsdtTest001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/UsdtTest001.java @@ -11,13 +11,18 @@ import org.tron.protos.Protocol.TransactionInfo; import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.ProposalEnum; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class UsdtTest001 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); private byte[] usdtAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -28,477 +33,794 @@ public class UsdtTest001 extends TronBaseTest { byte[] callerAddress = ecKey.getAddress(); String callerAddress58 = Base58.encode58Check(callerAddress); String callerKey = ByteArray.toHexString(ecKey.getPrivKeyBytes()); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_usdt"); - String code = Configuration.getByPath("testng.conf") - .getString("code.code_usdt"); + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_usdt"); + String code = Configuration.getByPath("testng.conf").getString("code.code_usdt"); Long energyPrice = 0L; - @BeforeClass(enabled = true) - public void beforeClass() { Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + public void beforeClass() { + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.freezeBalanceV2( - testNetAccountAddress, 1000000000L, 0, testNetAccountKey, blockingStubFull); + testNetAccountAddress, 1000000000L, 0, testNetAccountKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName = "Usdt-test"; - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", 3000000000L, - 0, 70, 10000, "0", 0, null, dev001Key, dev001Address, - blockingStubFull); + String contractName = "Usdt-test"; + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + 3000000000L, + 0, + 70, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); logger.info("txid: " + txid); PublicMethod.freezeBalanceForReceiver( - testNetAccountAddress, 10000000000L + PublicMethod.randomFreezeAmount.addAndGet(1), - 0, 1, ByteString.copyFrom(dev001Address), testNetAccountKey, blockingStubFull); + testNetAccountAddress, + 10000000000L + PublicMethod.randomFreezeAmount.addAndGet(1), + 0, + 1, + ByteString.copyFrom(dev001Address), + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (txid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } usdtAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(usdtAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(usdtAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); logger.info("usdtAddress:" + Base58.encode58Check(usdtAddress)); - energyPrice = PublicMethod.getChainParametersValue( - ProposalEnum.GetEnergyFee.getProposalName(), blockingStubFull); + energyPrice = + PublicMethod.getChainParametersValue( + ProposalEnum.GetEnergyFee.getProposalName(), blockingStubFull); } - /** - * constructor. - */ - @Test(enabled = true, description = "transfer when feeLimit = 0", groups = {"contract", "daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "transfer when feeLimit = 0", + groups = {"contract", "daily"}) public void test01TransferFeeLimitEqualZero() { String methedStr = "transfer(address,uint256)"; - String argsStr = "\"" + callerAddress58 + "\",100"; - PublicMethod.triggerContract(usdtAddress, methedStr, argsStr, - false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String argsStr = "\"" + callerAddress58 + "\",100"; + PublicMethod.triggerContract( + usdtAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.createAccount( - testNetAccountAddress, callerAddress, testNetAccountKey, blockingStubFull); + testNetAccountAddress, callerAddress, testNetAccountKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - //balance = 0 and energyLimit = 0 + // balance = 0 and energyLimit = 0 ECKey tempKey = new ECKey(Utils.getRandom()); argsStr = "\"" + Base58.encode58Check(tempKey.getAddress()) + "\",1"; - String txid = PublicMethod.triggerContract(usdtAddress, methedStr, argsStr, - false, 0, 0, callerAddress, callerKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + usdtAddress, + methedStr, + argsStr, + false, + 0, + 0, + callerAddress, + callerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo transactionInfo = PublicMethod.getTransactionInfoById( - txid, blockingStubFull).get(); - final Protocol.Transaction transaction = PublicMethod.getTransactionById( - txid, blockingStubFull).get(); + TransactionInfo transactionInfo = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + final Protocol.Transaction transaction = + PublicMethod.getTransactionById(txid, blockingStubFull).get(); logger.info("transactionInfo" + transactionInfo.toString()); Assert.assertEquals(transactionInfo.getResult(), TransactionInfo.code.FAILED); - Assert.assertEquals(transactionInfo.getReceipt().getResult(), - Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); + Assert.assertEquals( + transactionInfo.getReceipt().getResult(), + Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); Assert.assertEquals(transactionInfo.getReceipt().getEnergyUsageTotal(), 0L); - Assert.assertEquals(transaction.getRet(0).getContractRet(), - Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); + Assert.assertEquals( + transaction.getRet(0).getContractRet(), + Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); Assert.assertEquals(transaction.getRawData().getFeeLimit(), 0L); - //energy enough but feeLimit = 0 - PublicMethod.sendcoin(callerAddress, 2000000000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull); + // energy enough but feeLimit = 0 + PublicMethod.sendcoin( + callerAddress, 2000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.freezeBalanceV2(callerAddress, 300000000L, 0, callerKey, blockingStubFull); PublicMethod.freezeBalanceV2(callerAddress, 1000000000L, 1, callerKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid2 = PublicMethod.triggerContract(usdtAddress, methedStr, argsStr, - false, 0, 0, callerAddress, callerKey, blockingStubFull); + String txid2 = + PublicMethod.triggerContract( + usdtAddress, + methedStr, + argsStr, + false, + 0, + 0, + callerAddress, + callerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo transactionInfo2 = PublicMethod.getTransactionInfoById( - txid2, blockingStubFull).get(); - final Protocol.Transaction transaction2 = PublicMethod.getTransactionById( - txid2, blockingStubFull).get(); + TransactionInfo transactionInfo2 = + PublicMethod.getTransactionInfoById(txid2, blockingStubFull).get(); + final Protocol.Transaction transaction2 = + PublicMethod.getTransactionById(txid2, blockingStubFull).get(); logger.info("transactionInfo" + transactionInfo2.toString()); Assert.assertEquals(transactionInfo2.getResult(), TransactionInfo.code.FAILED); - Assert.assertEquals(transactionInfo2.getReceipt().getResult(), - Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); + Assert.assertEquals( + transactionInfo2.getReceipt().getResult(), + Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); Assert.assertEquals(transactionInfo2.getReceipt().getEnergyUsageTotal(), 0L); - Assert.assertEquals(transaction2.getRet(0).getContractRet(), - Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); + Assert.assertEquals( + transaction2.getRet(0).getContractRet(), + Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); Assert.assertEquals(transaction2.getRawData().getFeeLimit(), 0L); } - @Test(enabled = true, description = "transfer at FeeLimit boundary", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "transfer at FeeLimit boundary", + groups = {"contract", "daily"}) public void test02TransferFeeLimitBoundaryTest() { Long exceptEnergy = 29650L - 8895; // total - origin String methedStr = "transfer(address,uint256)"; - ECKey tempKey = new ECKey(Utils.getRandom()); - String argsStr = "\"" + Base58.encode58Check(tempKey.getAddress()) + "\",1"; - String txid = PublicMethod.triggerContract(usdtAddress, methedStr, argsStr, - false, 0, exceptEnergy * energyPrice, callerAddress, callerKey, blockingStubFull); + ECKey tempKey = new ECKey(Utils.getRandom()); + String argsStr = "\"" + Base58.encode58Check(tempKey.getAddress()) + "\",1"; + String txid = + PublicMethod.triggerContract( + usdtAddress, + methedStr, + argsStr, + false, + 0, + exceptEnergy * energyPrice, + callerAddress, + callerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo transactionInfo = PublicMethod.getTransactionInfoById( - txid, blockingStubFull).get(); - final Protocol.Transaction transaction = PublicMethod.getTransactionById( - txid, blockingStubFull).get(); + TransactionInfo transactionInfo = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + final Protocol.Transaction transaction = + PublicMethod.getTransactionById(txid, blockingStubFull).get(); logger.info("transactionInfo" + transactionInfo.toString()); Assert.assertEquals(transactionInfo.getResult(), TransactionInfo.code.SUCESS); - Assert.assertEquals(transactionInfo.getReceipt().getResult(), - Protocol.Transaction.Result.contractResult.SUCCESS); + Assert.assertEquals( + transactionInfo.getReceipt().getResult(), + Protocol.Transaction.Result.contractResult.SUCCESS); Assert.assertEquals(transactionInfo.getReceipt().getEnergyUsage(), exceptEnergy.longValue()); - Assert.assertEquals(transaction.getRet(0).getContractRet(), - Protocol.Transaction.Result.contractResult.SUCCESS); + Assert.assertEquals( + transaction.getRet(0).getContractRet(), Protocol.Transaction.Result.contractResult.SUCCESS); Assert.assertEquals(transaction.getRawData().getFeeLimit(), exceptEnergy * energyPrice); - //energy is different to the address which has already had Usdt - Long exceptEnergyOldAccount = 14650L - 4395; //total - origin - String txid2 = PublicMethod.triggerContract(usdtAddress, methedStr, argsStr, - false, 0, exceptEnergyOldAccount * energyPrice, callerAddress, callerKey, blockingStubFull); + // energy is different to the address which has already had Usdt + Long exceptEnergyOldAccount = 14650L - 4395; // total - origin + String txid2 = + PublicMethod.triggerContract( + usdtAddress, + methedStr, + argsStr, + false, + 0, + exceptEnergyOldAccount * energyPrice, + callerAddress, + callerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo transactionInfo2 = PublicMethod.getTransactionInfoById( - txid2, blockingStubFull).get(); - final Protocol.Transaction transaction2 = PublicMethod.getTransactionById( - txid2, blockingStubFull).get(); + TransactionInfo transactionInfo2 = + PublicMethod.getTransactionInfoById(txid2, blockingStubFull).get(); + final Protocol.Transaction transaction2 = + PublicMethod.getTransactionById(txid2, blockingStubFull).get(); logger.info("transactionInfo" + transactionInfo2.toString()); Assert.assertEquals(transactionInfo2.getResult(), TransactionInfo.code.SUCESS); - Assert.assertEquals(transactionInfo2.getReceipt().getResult(), - Protocol.Transaction.Result.contractResult.SUCCESS); - Assert.assertEquals(transactionInfo2.getReceipt().getEnergyUsage(), - exceptEnergyOldAccount.longValue()); - Assert.assertEquals(transaction2.getRet(0).getContractRet(), - Protocol.Transaction.Result.contractResult.SUCCESS); - Assert.assertEquals(transaction2.getRawData().getFeeLimit(), - exceptEnergyOldAccount * energyPrice); + Assert.assertEquals( + transactionInfo2.getReceipt().getResult(), + Protocol.Transaction.Result.contractResult.SUCCESS); + Assert.assertEquals( + transactionInfo2.getReceipt().getEnergyUsage(), exceptEnergyOldAccount.longValue()); + Assert.assertEquals( + transaction2.getRet(0).getContractRet(), + Protocol.Transaction.Result.contractResult.SUCCESS); + Assert.assertEquals( + transaction2.getRawData().getFeeLimit(), exceptEnergyOldAccount * energyPrice); } - @Test(enabled = true, description = "test black list when transfer and approve", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test black list when transfer and approve", + groups = {"contract", "daily"}) public void test03TransferWithBlackList() { ECKey tempKey = new ECKey(Utils.getRandom()); - ECKey spenderKey = new ECKey(Utils.getRandom()); - //add USDT balance to temp address + ECKey spenderKey = new ECKey(Utils.getRandom()); + // add USDT balance to temp address String methodStr = "transfer(address,uint256)"; - String argsStr = "\"" + Base58.encode58Check(tempKey.getAddress()) + "\",100"; - PublicMethod.triggerContract(usdtAddress, methodStr, argsStr, - false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); - PublicMethod.sendcoin(tempKey.getAddress(), 1000000000, - testNetAccountAddress, testNetAccountKey, blockingStubFull); - PublicMethod.sendcoin(spenderKey.getAddress(), 1000000000, - testNetAccountAddress, testNetAccountKey, blockingStubFull); + String argsStr = "\"" + Base58.encode58Check(tempKey.getAddress()) + "\",100"; + PublicMethod.triggerContract( + usdtAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); + PublicMethod.sendcoin( + tempKey.getAddress(), + 1000000000, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); + PublicMethod.sendcoin( + spenderKey.getAddress(), + 1000000000, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - //transfer success before add black list + // transfer success before add black list methodStr = "transfer(address,uint256)"; argsStr = "\"" + Base58.encode58Check(spenderKey.getAddress()) + "\",1"; - String txid1 = PublicMethod.triggerContract(usdtAddress, methodStr, argsStr, - false, 0, maxFeeLimit, tempKey.getAddress(), - ByteArray.toHexString(tempKey.getPrivKeyBytes()), blockingStubFull); + String txid1 = + PublicMethod.triggerContract( + usdtAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + tempKey.getAddress(), + ByteArray.toHexString(tempKey.getPrivKeyBytes()), + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo transactionInfo = PublicMethod.getTransactionInfoById( - txid1, blockingStubFull).get(); - Assert.assertEquals(transactionInfo.getReceipt().getResult(), - Protocol.Transaction.Result.contractResult.SUCCESS); - //add blackList + TransactionInfo transactionInfo = + PublicMethod.getTransactionInfoById(txid1, blockingStubFull).get(); + Assert.assertEquals( + transactionInfo.getReceipt().getResult(), + Protocol.Transaction.Result.contractResult.SUCCESS); + // add blackList Long addBlackListEnergyExcept = 21817L; methodStr = "addBlackList(address)"; argsStr = "\"" + Base58.encode58Check(tempKey.getAddress()) + "\""; - String txAddBlack = PublicMethod.triggerContract(usdtAddress, methodStr, argsStr, - false, 0, addBlackListEnergyExcept * energyPrice, - dev001Address, dev001Key, blockingStubFull); + String txAddBlack = + PublicMethod.triggerContract( + usdtAddress, + methodStr, + argsStr, + false, + 0, + addBlackListEnergyExcept * energyPrice, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("txAddBlack: " + txAddBlack); - TransactionInfo txAddBlackInfo = PublicMethod.getTransactionInfoById( - txAddBlack, blockingStubFull).get(); - Assert.assertEquals(txAddBlackInfo.getReceipt().getResult(), - Protocol.Transaction.Result.contractResult.SUCCESS); - Protocol.Transaction txAddBlackTx = PublicMethod.getTransactionById( - txAddBlack, blockingStubFull).get(); - Assert.assertEquals(txAddBlackTx.getRawData().getFeeLimit(), - energyPrice * addBlackListEnergyExcept); - //transfer revert after add black list + TransactionInfo txAddBlackInfo = + PublicMethod.getTransactionInfoById(txAddBlack, blockingStubFull).get(); + Assert.assertEquals( + txAddBlackInfo.getReceipt().getResult(), + Protocol.Transaction.Result.contractResult.SUCCESS); + Protocol.Transaction txAddBlackTx = + PublicMethod.getTransactionById(txAddBlack, blockingStubFull).get(); + Assert.assertEquals( + txAddBlackTx.getRawData().getFeeLimit(), energyPrice * addBlackListEnergyExcept); + // transfer revert after add black list methodStr = "transfer(address,uint256)"; argsStr = "\"" + Base58.encode58Check(spenderKey.getAddress()) + "\",1"; - String txid2 = PublicMethod.triggerContract(usdtAddress, methodStr, argsStr, - false, 0, maxFeeLimit, tempKey.getAddress(), - ByteArray.toHexString(tempKey.getPrivKeyBytes()), blockingStubFull); + String txid2 = + PublicMethod.triggerContract( + usdtAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + tempKey.getAddress(), + ByteArray.toHexString(tempKey.getPrivKeyBytes()), + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo transactionInfo2 = PublicMethod.getTransactionInfoById( - txid2, blockingStubFull).get(); - Assert.assertEquals(transactionInfo2.getReceipt().getResult(), - Protocol.Transaction.Result.contractResult.REVERT); - //approve token to another address + TransactionInfo transactionInfo2 = + PublicMethod.getTransactionInfoById(txid2, blockingStubFull).get(); + Assert.assertEquals( + transactionInfo2.getReceipt().getResult(), + Protocol.Transaction.Result.contractResult.REVERT); + // approve token to another address methodStr = "approve(address,uint256)"; argsStr = "\"" + Base58.encode58Check(spenderKey.getAddress()) + "\",20"; - PublicMethod.triggerContract(usdtAddress, methodStr, argsStr, - false, 0, maxFeeLimit, tempKey.getAddress(), - ByteArray.toHexString(tempKey.getPrivKeyBytes()), blockingStubFull); + PublicMethod.triggerContract( + usdtAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + tempKey.getAddress(), + ByteArray.toHexString(tempKey.getPrivKeyBytes()), + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - //transferFrom revert after add black list + // transferFrom revert after add black list methodStr = "transferFrom(address,address,uint256)"; - argsStr = "\"" + Base58.encode58Check(tempKey.getAddress()) + "\"" + ",\"" - + Base58.encode58Check(dev001Address) + "\",1"; - String txid3 = PublicMethod.triggerContract(usdtAddress, methodStr, argsStr, - false, 0, maxFeeLimit, spenderKey.getAddress(), - ByteArray.toHexString(spenderKey.getPrivKeyBytes()), blockingStubFull); + argsStr = + "\"" + + Base58.encode58Check(tempKey.getAddress()) + + "\"" + + ",\"" + + Base58.encode58Check(dev001Address) + + "\",1"; + String txid3 = + PublicMethod.triggerContract( + usdtAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + spenderKey.getAddress(), + ByteArray.toHexString(spenderKey.getPrivKeyBytes()), + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo transactionInfo3 = PublicMethod.getTransactionInfoById( - txid3, blockingStubFull).get(); - Assert.assertEquals(transactionInfo3.getReceipt().getResult(), - Protocol.Transaction.Result.contractResult.REVERT); - //remove BlackList + TransactionInfo transactionInfo3 = + PublicMethod.getTransactionInfoById(txid3, blockingStubFull).get(); + Assert.assertEquals( + transactionInfo3.getReceipt().getResult(), + Protocol.Transaction.Result.contractResult.REVERT); + // remove BlackList Long removeEnergyExcept = 7367L; methodStr = "removeBlackList(address)"; argsStr = "\"" + Base58.encode58Check(tempKey.getAddress()) + "\""; - String txRemoveBlackList = PublicMethod.triggerContract(usdtAddress, methodStr, argsStr, - false, 0, removeEnergyExcept * energyPrice, dev001Address, dev001Key, blockingStubFull); + String txRemoveBlackList = + PublicMethod.triggerContract( + usdtAddress, + methodStr, + argsStr, + false, + 0, + removeEnergyExcept * energyPrice, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("txRemoveBlackList: " + txRemoveBlackList); - TransactionInfo txRemoveBlackListInfo = PublicMethod.getTransactionInfoById( - txRemoveBlackList, blockingStubFull).get(); - Assert.assertEquals(txRemoveBlackListInfo.getReceipt().getResult(), - Protocol.Transaction.Result.contractResult.SUCCESS); - Protocol.Transaction txRemoveBlackListTx = PublicMethod.getTransactionById( - txRemoveBlackList, blockingStubFull).get(); - Assert.assertEquals(txRemoveBlackListTx.getRawData().getFeeLimit(), - energyPrice * removeEnergyExcept); - //transfer success after remove black list + TransactionInfo txRemoveBlackListInfo = + PublicMethod.getTransactionInfoById(txRemoveBlackList, blockingStubFull).get(); + Assert.assertEquals( + txRemoveBlackListInfo.getReceipt().getResult(), + Protocol.Transaction.Result.contractResult.SUCCESS); + Protocol.Transaction txRemoveBlackListTx = + PublicMethod.getTransactionById(txRemoveBlackList, blockingStubFull).get(); + Assert.assertEquals( + txRemoveBlackListTx.getRawData().getFeeLimit(), energyPrice * removeEnergyExcept); + // transfer success after remove black list methodStr = "transfer(address,uint256)"; argsStr = "\"" + Base58.encode58Check(spenderKey.getAddress()) + "\",1"; - String txid4 = PublicMethod.triggerContract(usdtAddress, methodStr, argsStr, - false, 0, maxFeeLimit, tempKey.getAddress(), - ByteArray.toHexString(tempKey.getPrivKeyBytes()), blockingStubFull); + String txid4 = + PublicMethod.triggerContract( + usdtAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + tempKey.getAddress(), + ByteArray.toHexString(tempKey.getPrivKeyBytes()), + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo transactionInfo4 = PublicMethod.getTransactionInfoById( - txid4, blockingStubFull).get(); - Assert.assertEquals(transactionInfo4.getReceipt().getResult(), - Protocol.Transaction.Result.contractResult.SUCCESS); - //transferFrom success after remove black list + TransactionInfo transactionInfo4 = + PublicMethod.getTransactionInfoById(txid4, blockingStubFull).get(); + Assert.assertEquals( + transactionInfo4.getReceipt().getResult(), + Protocol.Transaction.Result.contractResult.SUCCESS); + // transferFrom success after remove black list methodStr = "transferFrom(address,address,uint256)"; - argsStr = "\"" + Base58.encode58Check(tempKey.getAddress()) + "\"" - + ",\"" + Base58.encode58Check(dev001Address) + "\",1"; - String txid5 = PublicMethod.triggerContract(usdtAddress, methodStr, argsStr, - false, 0, maxFeeLimit, spenderKey.getAddress(), - ByteArray.toHexString(spenderKey.getPrivKeyBytes()), blockingStubFull); + argsStr = + "\"" + + Base58.encode58Check(tempKey.getAddress()) + + "\"" + + ",\"" + + Base58.encode58Check(dev001Address) + + "\",1"; + String txid5 = + PublicMethod.triggerContract( + usdtAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + spenderKey.getAddress(), + ByteArray.toHexString(spenderKey.getPrivKeyBytes()), + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo transactionInfo5 = PublicMethod.getTransactionInfoById( - txid5, blockingStubFull).get(); - Assert.assertEquals(transactionInfo5.getReceipt().getResult(), - Protocol.Transaction.Result.contractResult.SUCCESS); + TransactionInfo transactionInfo5 = + PublicMethod.getTransactionInfoById(txid5, blockingStubFull).get(); + Assert.assertEquals( + transactionInfo5.getReceipt().getResult(), + Protocol.Transaction.Result.contractResult.SUCCESS); } - @Test(enabled = true, description = "add and remove black list when feeLimit = 0", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "add and remove black list when feeLimit = 0", + groups = {"contract", "daily"}) public void test04BlackListFeeLimitEqualZero() { final Long addBlackListEnergyExcept = 21817L; - ECKey tempKey = new ECKey(Utils.getRandom()); - String methodStr = "addBlackList(address)"; - String argsStr = "\"" + Base58.encode58Check(tempKey.getAddress()) + "\""; - String txAddBlack = PublicMethod.triggerContract(usdtAddress, methodStr, argsStr, - false, 0, 0, dev001Address, dev001Key, blockingStubFull); + ECKey tempKey = new ECKey(Utils.getRandom()); + String methodStr = "addBlackList(address)"; + String argsStr = "\"" + Base58.encode58Check(tempKey.getAddress()) + "\""; + String txAddBlack = + PublicMethod.triggerContract( + usdtAddress, + methodStr, + argsStr, + false, + 0, + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("txAddBlack: " + txAddBlack); - TransactionInfo txAddBlackInfo = PublicMethod.getTransactionInfoById( - txAddBlack, blockingStubFull).get(); - Assert.assertEquals(txAddBlackInfo.getReceipt().getResult(), - Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); - Protocol.Transaction txAddBlackTx = PublicMethod.getTransactionById( - txAddBlack, blockingStubFull).get(); + TransactionInfo txAddBlackInfo = + PublicMethod.getTransactionInfoById(txAddBlack, blockingStubFull).get(); + Assert.assertEquals( + txAddBlackInfo.getReceipt().getResult(), + Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); + Protocol.Transaction txAddBlackTx = + PublicMethod.getTransactionById(txAddBlack, blockingStubFull).get(); Assert.assertEquals(txAddBlackTx.getRawData().getFeeLimit(), 0L); - String txAddBlack2 = PublicMethod.triggerContract(usdtAddress, methodStr, argsStr, - false, 0, addBlackListEnergyExcept * energyPrice + 1, - dev001Address, dev001Key, blockingStubFull); + String txAddBlack2 = + PublicMethod.triggerContract( + usdtAddress, + methodStr, + argsStr, + false, + 0, + addBlackListEnergyExcept * energyPrice + 1, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("txAddBlack2: " + txAddBlack2); - TransactionInfo txAddBlackInfo2 = PublicMethod.getTransactionInfoById( - txAddBlack2, blockingStubFull).get(); - Assert.assertEquals(txAddBlackInfo2.getReceipt().getResult(), - Protocol.Transaction.Result.contractResult.SUCCESS); - Protocol.Transaction txAddBlackTx2 = PublicMethod.getTransactionById( - txAddBlack2, blockingStubFull).get(); - Assert.assertEquals(txAddBlackTx2.getRawData().getFeeLimit(), - addBlackListEnergyExcept * energyPrice + 1); - final Long removeEnergyExcept = 7367L; + TransactionInfo txAddBlackInfo2 = + PublicMethod.getTransactionInfoById(txAddBlack2, blockingStubFull).get(); + Assert.assertEquals( + txAddBlackInfo2.getReceipt().getResult(), + Protocol.Transaction.Result.contractResult.SUCCESS); + Protocol.Transaction txAddBlackTx2 = + PublicMethod.getTransactionById(txAddBlack2, blockingStubFull).get(); + Assert.assertEquals( + txAddBlackTx2.getRawData().getFeeLimit(), addBlackListEnergyExcept * energyPrice + 1); + final Long removeEnergyExcept = 7367L; methodStr = "removeBlackList(address)"; argsStr = "\"" + Base58.encode58Check(tempKey.getAddress()) + "\""; - String txRemoveBlack = PublicMethod.triggerContract(usdtAddress, methodStr, argsStr, - false, 0, 0, dev001Address, dev001Key, blockingStubFull); + String txRemoveBlack = + PublicMethod.triggerContract( + usdtAddress, + methodStr, + argsStr, + false, + 0, + 0, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("txRemoveBlack: " + txRemoveBlack); - TransactionInfo txRemoveBlackInfo = PublicMethod.getTransactionInfoById( - txRemoveBlack, blockingStubFull).get(); - Assert.assertEquals(txRemoveBlackInfo.getReceipt().getResult(), - Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); - Protocol.Transaction txRemoveBlackTx = PublicMethod.getTransactionById( - txRemoveBlack, blockingStubFull).get(); + TransactionInfo txRemoveBlackInfo = + PublicMethod.getTransactionInfoById(txRemoveBlack, blockingStubFull).get(); + Assert.assertEquals( + txRemoveBlackInfo.getReceipt().getResult(), + Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); + Protocol.Transaction txRemoveBlackTx = + PublicMethod.getTransactionById(txRemoveBlack, blockingStubFull).get(); Assert.assertEquals(txRemoveBlackTx.getRawData().getFeeLimit(), 0L); - methodStr = "removeBlackList(address)"; argsStr = "\"" + Base58.encode58Check(tempKey.getAddress()) + "\""; - String txRemoveBlack2 = PublicMethod.triggerContract(usdtAddress, methodStr, argsStr, - false, 0, removeEnergyExcept * energyPrice, dev001Address, dev001Key, blockingStubFull); + String txRemoveBlack2 = + PublicMethod.triggerContract( + usdtAddress, + methodStr, + argsStr, + false, + 0, + removeEnergyExcept * energyPrice, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("txRemoveBlack2: " + txRemoveBlack2); - TransactionInfo txRemoveBlackInfo2 = PublicMethod.getTransactionInfoById( - txRemoveBlack2, blockingStubFull).get(); - Assert.assertEquals(txRemoveBlackInfo2.getReceipt().getResult(), - Protocol.Transaction.Result.contractResult.SUCCESS); - Protocol.Transaction txRemoveBlackTx2 = PublicMethod.getTransactionById( - txRemoveBlack2, blockingStubFull).get(); - Assert.assertEquals(txRemoveBlackTx2.getRawData().getFeeLimit(), - removeEnergyExcept * energyPrice); + TransactionInfo txRemoveBlackInfo2 = + PublicMethod.getTransactionInfoById(txRemoveBlack2, blockingStubFull).get(); + Assert.assertEquals( + txRemoveBlackInfo2.getReceipt().getResult(), + Protocol.Transaction.Result.contractResult.SUCCESS); + Protocol.Transaction txRemoveBlackTx2 = + PublicMethod.getTransactionById(txRemoveBlack2, blockingStubFull).get(); + Assert.assertEquals( + txRemoveBlackTx2.getRawData().getFeeLimit(), removeEnergyExcept * energyPrice); } - @Test(enabled = true, description = "approve when feeLimit = 0 and boundary + 1", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "approve when feeLimit = 0 and boundary + 1", + groups = {"contract", "daily"}) public void test05ApproveFeeLimitEqualZero() { - final ECKey spender = new ECKey(Utils.getRandom()); - final ECKey caller = new ECKey(Utils.getRandom()); - final byte[] callerAddress = caller.getAddress(); - final String callerKey = ByteArray.toHexString(caller.getPrivKeyBytes()); - String methodStr = "transfer(address,uint256)"; - String argsStr = "\"" + Base58.encode58Check(caller.getAddress()) + "\",100"; - PublicMethod.triggerContract(usdtAddress, methodStr, argsStr, - false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); - PublicMethod.sendcoin(caller.getAddress(), 1000000000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull); + final ECKey spender = new ECKey(Utils.getRandom()); + final ECKey caller = new ECKey(Utils.getRandom()); + final byte[] callerAddress = caller.getAddress(); + final String callerKey = ByteArray.toHexString(caller.getPrivKeyBytes()); + String methodStr = "transfer(address,uint256)"; + String argsStr = "\"" + Base58.encode58Check(caller.getAddress()) + "\",100"; + PublicMethod.triggerContract( + usdtAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); + PublicMethod.sendcoin( + caller.getAddress(), + 1000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - //approve token to another address + // approve token to another address methodStr = "approve(address,uint256)"; argsStr = "\"" + Base58.encode58Check(spender.getAddress()) + "\",20"; - String txid = PublicMethod.triggerContract(usdtAddress, methodStr, argsStr, - false, 0, 0, callerAddress, callerKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + usdtAddress, + methodStr, + argsStr, + false, + 0, + 0, + callerAddress, + callerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo transactionInfo = PublicMethod.getTransactionInfoById( - txid, blockingStubFull).get(); - final Protocol.Transaction transaction = PublicMethod.getTransactionById( - txid, blockingStubFull).get(); + TransactionInfo transactionInfo = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + final Protocol.Transaction transaction = + PublicMethod.getTransactionById(txid, blockingStubFull).get(); logger.info("transactionInfo" + transactionInfo.toString()); Assert.assertEquals(transactionInfo.getResult(), TransactionInfo.code.FAILED); - Assert.assertEquals(transactionInfo.getReceipt().getResult(), - Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); + Assert.assertEquals( + transactionInfo.getReceipt().getResult(), + Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); Assert.assertEquals(transactionInfo.getReceipt().getEnergyUsageTotal(), 0L); - Assert.assertEquals(transaction.getRet(0).getContractRet(), - Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); + Assert.assertEquals( + transaction.getRet(0).getContractRet(), + Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); Assert.assertEquals(transaction.getRawData().getFeeLimit(), 0L); - Long approveEnergyExcept = 22688L - 6806L; // total - origin - String txid2 = PublicMethod.triggerContract(usdtAddress, methodStr, argsStr, - false, 0, approveEnergyExcept * energyPrice, callerAddress, callerKey, blockingStubFull); + Long approveEnergyExcept = 22688L - 6806L; // total - origin + String txid2 = + PublicMethod.triggerContract( + usdtAddress, + methodStr, + argsStr, + false, + 0, + approveEnergyExcept * energyPrice, + callerAddress, + callerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo transactionInfo2 = PublicMethod.getTransactionInfoById( - txid2, blockingStubFull).get(); - final Protocol.Transaction transaction2 = PublicMethod.getTransactionById( - txid2, blockingStubFull).get(); + TransactionInfo transactionInfo2 = + PublicMethod.getTransactionInfoById(txid2, blockingStubFull).get(); + final Protocol.Transaction transaction2 = + PublicMethod.getTransactionById(txid2, blockingStubFull).get(); logger.info("transactionInfo" + transactionInfo2.toString()); Assert.assertEquals(transactionInfo2.getResult(), TransactionInfo.code.SUCESS); - Assert.assertEquals(transactionInfo2.getReceipt().getResult(), - Protocol.Transaction.Result.contractResult.SUCCESS); - Assert.assertEquals(transaction2.getRet(0).getContractRet(), - Protocol.Transaction.Result.contractResult.SUCCESS); + Assert.assertEquals( + transactionInfo2.getReceipt().getResult(), + Protocol.Transaction.Result.contractResult.SUCCESS); + Assert.assertEquals( + transaction2.getRet(0).getContractRet(), + Protocol.Transaction.Result.contractResult.SUCCESS); Assert.assertEquals(transaction2.getRawData().getFeeLimit(), energyPrice * approveEnergyExcept); } - - @Test(enabled = true, description = "approve when feeLimit = boundary - 1", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "approve when feeLimit = boundary - 1", + groups = {"contract", "daily"}) public void test06ApproveFeeLimitBoundary() { - final ECKey spender = new ECKey(Utils.getRandom()); - final ECKey caller = new ECKey(Utils.getRandom()); - final byte[] callerAddress = caller.getAddress(); - final String callerKey = ByteArray.toHexString(caller.getPrivKeyBytes()); - String methodStr = "transfer(address,uint256)"; - String argsStr = "\"" + Base58.encode58Check(caller.getAddress()) + "\",100"; - PublicMethod.triggerContract(usdtAddress, methodStr, argsStr, - false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); - PublicMethod.sendcoin(caller.getAddress(), 1000000000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull); + final ECKey spender = new ECKey(Utils.getRandom()); + final ECKey caller = new ECKey(Utils.getRandom()); + final byte[] callerAddress = caller.getAddress(); + final String callerKey = ByteArray.toHexString(caller.getPrivKeyBytes()); + String methodStr = "transfer(address,uint256)"; + String argsStr = "\"" + Base58.encode58Check(caller.getAddress()) + "\",100"; + PublicMethod.triggerContract( + usdtAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); + PublicMethod.sendcoin( + caller.getAddress(), + 1000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long approveEnergyExcept = 22677L - 6803L; // total - origin - //approve token to another address + Long approveEnergyExcept = 22677L - 6803L; // total - origin + // approve token to another address methodStr = "approve(address,uint256)"; argsStr = "\"" + Base58.encode58Check(spender.getAddress()) + "\",20"; - String txid = PublicMethod.triggerContract(usdtAddress, methodStr, argsStr, - false, 0, approveEnergyExcept * energyPrice - 1, - callerAddress, callerKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + usdtAddress, + methodStr, + argsStr, + false, + 0, + approveEnergyExcept * energyPrice - 1, + callerAddress, + callerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo transactionInfo = PublicMethod.getTransactionInfoById( - txid, blockingStubFull).get(); - final Protocol.Transaction transaction = PublicMethod.getTransactionById( - txid, blockingStubFull).get(); + TransactionInfo transactionInfo = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + final Protocol.Transaction transaction = + PublicMethod.getTransactionById(txid, blockingStubFull).get(); logger.info("transactionInfo" + transactionInfo.toString()); Assert.assertEquals(transactionInfo.getResult(), TransactionInfo.code.FAILED); - Assert.assertEquals(transactionInfo.getReceipt().getResult(), - Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); - Assert.assertEquals(transactionInfo.getReceipt().getEnergyUsageTotal(), - 22675L); - Assert.assertEquals(transaction.getRet(0).getContractRet(), - Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); - Assert.assertEquals(transaction.getRawData().getFeeLimit(), - approveEnergyExcept * energyPrice - 1); + Assert.assertEquals( + transactionInfo.getReceipt().getResult(), + Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); + Assert.assertEquals(transactionInfo.getReceipt().getEnergyUsageTotal(), 22675L); + Assert.assertEquals( + transaction.getRet(0).getContractRet(), + Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); + Assert.assertEquals( + transaction.getRawData().getFeeLimit(), approveEnergyExcept * energyPrice - 1); } - @Test(enabled = true, description = "add remove when feeLimit = boundary -1", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "add remove when feeLimit = boundary -1", + groups = {"contract", "daily"}) public void test07BlackListFeeLimitBoundary() { final Long addBlackListEnergyExcept = 21817L; - ECKey tempKey = new ECKey(Utils.getRandom()); - String methodStr = "addBlackList(address)"; - String argsStr = "\"" + Base58.encode58Check(tempKey.getAddress()) + "\""; - String txAddBlack = PublicMethod.triggerContract(usdtAddress, methodStr, argsStr, - false, 0, addBlackListEnergyExcept * energyPrice - 1, dev001Address, dev001Key, blockingStubFull); + ECKey tempKey = new ECKey(Utils.getRandom()); + String methodStr = "addBlackList(address)"; + String argsStr = "\"" + Base58.encode58Check(tempKey.getAddress()) + "\""; + String txAddBlack = + PublicMethod.triggerContract( + usdtAddress, + methodStr, + argsStr, + false, + 0, + addBlackListEnergyExcept * energyPrice - 1, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("txAddBlack: " + txAddBlack); - TransactionInfo txAddBlackInfo = PublicMethod.getTransactionInfoById( - txAddBlack, blockingStubFull).get(); - Assert.assertEquals(txAddBlackInfo.getReceipt().getResult(), - Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); - Protocol.Transaction txAddBlackTx = PublicMethod.getTransactionById( - txAddBlack, blockingStubFull).get(); - Assert.assertEquals(txAddBlackTx.getRawData().getFeeLimit(), addBlackListEnergyExcept * energyPrice -1); - String txAddBlack2 = PublicMethod.triggerContract(usdtAddress, methodStr, argsStr, - false, 0, addBlackListEnergyExcept * energyPrice, - dev001Address, dev001Key, blockingStubFull); + TransactionInfo txAddBlackInfo = + PublicMethod.getTransactionInfoById(txAddBlack, blockingStubFull).get(); + Assert.assertEquals( + txAddBlackInfo.getReceipt().getResult(), + Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); + Protocol.Transaction txAddBlackTx = + PublicMethod.getTransactionById(txAddBlack, blockingStubFull).get(); + Assert.assertEquals( + txAddBlackTx.getRawData().getFeeLimit(), addBlackListEnergyExcept * energyPrice - 1); + String txAddBlack2 = + PublicMethod.triggerContract( + usdtAddress, + methodStr, + argsStr, + false, + 0, + addBlackListEnergyExcept * energyPrice, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("txAddBlack2: " + txAddBlack2); - TransactionInfo txAddBlackInfo2 = PublicMethod.getTransactionInfoById( - txAddBlack2, blockingStubFull).get(); - Assert.assertEquals(txAddBlackInfo2.getReceipt().getResult(), - Protocol.Transaction.Result.contractResult.SUCCESS); - Protocol.Transaction txAddBlackTx2 = PublicMethod.getTransactionById( - txAddBlack2, blockingStubFull).get(); - Assert.assertEquals(txAddBlackTx2.getRawData().getFeeLimit(), - addBlackListEnergyExcept * energyPrice); - final Long removeEnergyExcept = 7367L; + TransactionInfo txAddBlackInfo2 = + PublicMethod.getTransactionInfoById(txAddBlack2, blockingStubFull).get(); + Assert.assertEquals( + txAddBlackInfo2.getReceipt().getResult(), + Protocol.Transaction.Result.contractResult.SUCCESS); + Protocol.Transaction txAddBlackTx2 = + PublicMethod.getTransactionById(txAddBlack2, blockingStubFull).get(); + Assert.assertEquals( + txAddBlackTx2.getRawData().getFeeLimit(), addBlackListEnergyExcept * energyPrice); + final Long removeEnergyExcept = 7367L; methodStr = "removeBlackList(address)"; argsStr = "\"" + Base58.encode58Check(tempKey.getAddress()) + "\""; - String txRemoveBlack = PublicMethod.triggerContract(usdtAddress, methodStr, argsStr, - false, 0, removeEnergyExcept * energyPrice - 1, dev001Address, dev001Key, blockingStubFull); + String txRemoveBlack = + PublicMethod.triggerContract( + usdtAddress, + methodStr, + argsStr, + false, + 0, + removeEnergyExcept * energyPrice - 1, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("txRemoveBlack: " + txRemoveBlack); - TransactionInfo txRemoveBlackInfo = PublicMethod.getTransactionInfoById( - txRemoveBlack, blockingStubFull).get(); - Assert.assertEquals(txRemoveBlackInfo.getReceipt().getResult(), - Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); - Protocol.Transaction txRemoveBlackTx = PublicMethod.getTransactionById( - txRemoveBlack, blockingStubFull).get(); - Assert.assertEquals(txRemoveBlackTx.getRawData().getFeeLimit(), removeEnergyExcept * energyPrice - 1); + TransactionInfo txRemoveBlackInfo = + PublicMethod.getTransactionInfoById(txRemoveBlack, blockingStubFull).get(); + Assert.assertEquals( + txRemoveBlackInfo.getReceipt().getResult(), + Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY); + Protocol.Transaction txRemoveBlackTx = + PublicMethod.getTransactionById(txRemoveBlack, blockingStubFull).get(); + Assert.assertEquals( + txRemoveBlackTx.getRawData().getFeeLimit(), removeEnergyExcept * energyPrice - 1); methodStr = "removeBlackList(address)"; argsStr = "\"" + Base58.encode58Check(tempKey.getAddress()) + "\""; - String txRemoveBlack2 = PublicMethod.triggerContract(usdtAddress, methodStr, argsStr, - false, 0, removeEnergyExcept * energyPrice + 1, dev001Address, dev001Key, blockingStubFull); + String txRemoveBlack2 = + PublicMethod.triggerContract( + usdtAddress, + methodStr, + argsStr, + false, + 0, + removeEnergyExcept * energyPrice + 1, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("txRemoveBlack2: " + txRemoveBlack2); - TransactionInfo txRemoveBlackInfo2 = PublicMethod.getTransactionInfoById( - txRemoveBlack2, blockingStubFull).get(); - Assert.assertEquals(txRemoveBlackInfo2.getReceipt().getResult(), - Protocol.Transaction.Result.contractResult.SUCCESS); - Protocol.Transaction txRemoveBlackTx2 = PublicMethod.getTransactionById( - txRemoveBlack2, blockingStubFull).get(); - Assert.assertEquals(txRemoveBlackTx2.getRawData().getFeeLimit(), - removeEnergyExcept * energyPrice + 1); + TransactionInfo txRemoveBlackInfo2 = + PublicMethod.getTransactionInfoById(txRemoveBlack2, blockingStubFull).get(); + Assert.assertEquals( + txRemoveBlackInfo2.getReceipt().getResult(), + Protocol.Transaction.Result.contractResult.SUCCESS); + Protocol.Transaction txRemoveBlackTx2 = + PublicMethod.getTransactionById(txRemoveBlack2, blockingStubFull).get(); + Assert.assertEquals( + txRemoveBlackTx2.getRawData().getFeeLimit(), removeEnergyExcept * energyPrice + 1); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { PublicMethod.freeResource(dev001Address, dev001Key, testNetAccountAddress, blockingStubFull); PublicMethod.freeResource(callerAddress, callerKey, testNetAccountAddress, blockingStubFull); - PublicMethod.unDelegateResourceV2(testNetAccountAddress, 8000000000L, - 1, dev001Address, testNetAccountKey, blockingStubFull); - PublicMethod.unDelegateResourceV2(testNetAccountAddress, 300000000L, - 0, callerAddress, testNetAccountKey, blockingStubFull); } + PublicMethod.unDelegateResourceV2( + testNetAccountAddress, 8000000000L, 1, dev001Address, testNetAccountKey, blockingStubFull); + PublicMethod.unDelegateResourceV2( + testNetAccountAddress, 300000000L, 0, callerAddress, testNetAccountKey, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/UsdtTest002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/UsdtTest002.java index 43d7cab9..7872fe9a 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/UsdtTest002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/UsdtTest002.java @@ -1,5 +1,6 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.newGrammar; +import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.testng.annotations.AfterClass; @@ -9,21 +10,24 @@ import org.tron.protos.Protocol.TransactionInfo; import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.*; - -import java.util.Optional; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.ByteArray; +import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.Flaky; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.ProposalEnum; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -@Flaky(reason = "Contract deployment timing, intermittent null results", - since = "2026-04-03") +@Flaky(reason = "Contract deployment timing, intermittent null results", since = "2026-04-03") @MultiNode -public class UsdtTest002 extends TronBaseTest { private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); +public class UsdtTest002 extends TronBaseTest { + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); private byte[] usdtAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,167 +41,264 @@ public class UsdtTest002 extends TronBaseTest { private String fullnodeLocal = byte[] callerddress = ecKey.getAddress(); String callerAddress58 = Base58.encode58Check(callerddress); String callerKey = ByteArray.toHexString(ecKey.getPrivKeyBytes()); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_usdt"); - String code = Configuration.getByPath("testng.conf") - .getString("code.code_usdt"); - + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_usdt"); + String code = Configuration.getByPath("testng.conf").getString("code.code_usdt"); @BeforeClass(enabled = true) - public void beforeClass() { Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 10000000000L, testNetAccountAddress, testNetAccountKey, + public void beforeClass() { + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); - String contractName = "Usdt-test"; - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", 1500000000L, - 0, consumeUserResourcePercent, 10000, "0", 0, - null, dev001Key, dev001Address, blockingStubFull); + String contractName = "Usdt-test"; + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + 1500000000L, + 0, + consumeUserResourcePercent, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); logger.info("deploy usdt txid: " + txid); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); if (txid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } usdtAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(usdtAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(usdtAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); logger.info(Base58.encode58Check(usdtAddress)); } - /** - * constructor. - */ - - @Test(enabled = true, description = "args feeLimit = need feeLimit - 1", groups = {"contract", "daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "args feeLimit = need feeLimit - 1", + groups = {"contract", "daily"}) public void test01() { - Assert.assertTrue(PublicMethod - .sendcoin(callerddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + callerddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //it cost more energy when transfer to an address which does not has usdt + // it cost more energy when transfer to an address which does not has usdt String methedStr = "transfer(address,uint256)"; - String argsStr = "\"" + callerAddress58 + "\",100"; - String txid = PublicMethod.triggerContract(usdtAddress, methedStr, argsStr, - false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String argsStr = "\"" + callerAddress58 + "\",100"; + String txid = + PublicMethod.triggerContract( + usdtAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, infoById.get().getReceipt().getResult()); - //transfer to callerAddress58 the second time to get feeLimit + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, + infoById.get().getReceipt().getResult()); + // transfer to callerAddress58 the second time to get feeLimit argsStr = "\"" + callerAddress58 + "\",1"; - txid = PublicMethod.triggerContract(usdtAddress, methedStr, argsStr, - false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + usdtAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, + infoById.get().getReceipt().getResult()); logger.info("test01 estimate feeLimit infoById: " + infoById.toString()); long energyTotal = infoById.get().getReceipt().getEnergyUsageTotal(); - energyFee = PublicMethod - .getChainParametersValue(ProposalEnum.GetEnergyFee.getProposalName(), blockingStubFull); + energyFee = + PublicMethod.getChainParametersValue( + ProposalEnum.GetEnergyFee.getProposalName(), blockingStubFull); rightFeeLimit = energyTotal * energyFee; long feeLimit = rightFeeLimit - 1; - //transfer to callerAddress58 the third time with feeLimit == needFeeLimit - 1 + // transfer to callerAddress58 the third time with feeLimit == needFeeLimit - 1 argsStr = "\"" + callerAddress58 + "\",1"; - txid = PublicMethod.triggerContract(usdtAddress, methedStr, argsStr, - false, 0, feeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + usdtAddress, + methedStr, + argsStr, + false, + 0, + feeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("need feeLimit - 1 infoById: " + infoById); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY, + infoById.get().getReceipt().getResult()); Assert.assertEquals(0, infoById.get().getReceipt().getOriginEnergyUsage()); Assert.assertEquals(0, infoById.get().getReceipt().getEnergyUsage()); Assert.assertEquals(0, infoById.get().getReceipt().getNetFee()); Assert.assertEquals(0, infoById.get().getReceipt().getEnergyPenaltyTotal()); - Assert.assertEquals(energyFee * infoById.get().getReceipt().getEnergyUsageTotal(), + Assert.assertEquals( + energyFee * infoById.get().getReceipt().getEnergyUsageTotal(), infoById.get().getReceipt().getEnergyFee()); Assert.assertEquals(infoById.get().getFee(), infoById.get().getReceipt().getEnergyFee()); Assert.assertTrue(infoById.get().getReceipt().getEnergyFee() < rightFeeLimit - 1); - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("Not enough energy for")); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("Not enough energy for")); - Protocol.Transaction transaction = PublicMethod.getTransactionById(txid, blockingStubFull).get(); + Protocol.Transaction transaction = + PublicMethod.getTransactionById(txid, blockingStubFull).get(); Assert.assertEquals(feeLimit, transaction.getRawData().getFeeLimit()); Assert.assertEquals("OUT_OF_ENERGY", transaction.getRet(0).getContractRet().toString()); - } - /** - * constructor. - */ - @Test(enabled = true, description = "transfer usdt, no energy, and trx balance = feeLimit", groups = {"contract", "daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "transfer usdt, no energy, and trx balance = feeLimit", + groups = {"contract", "daily"}) public void test02() { - Assert.assertTrue(PublicMethod.freezeBalanceV2(dev001Address, 100000000L, 0, dev001Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2(dev001Address, 100000000L, 0, dev001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long balance = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); long needSend = balance - rightFeeLimit; - Assert.assertTrue(PublicMethod.sendcoin(callerddress, needSend, dev001Address, dev001Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin(callerddress, needSend, dev001Address, dev001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String methedStr = "transfer(address,uint256)"; - String argsStr = "\"" + callerAddress58 + "\",1"; - String txid = PublicMethod.triggerContract(usdtAddress, methedStr, argsStr, - false, 0, rightFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methedStr = "transfer(address,uint256)"; + String argsStr = "\"" + callerAddress58 + "\",1"; + String txid = + PublicMethod.triggerContract( + usdtAddress, + methedStr, + argsStr, + false, + 0, + rightFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, infoById.getReceipt().getResult()); - Assert.assertEquals(energyFee * infoById.getReceipt().getEnergyUsageTotal(), infoById.getReceipt().getEnergyFee()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, infoById.getReceipt().getResult()); + Assert.assertEquals( + energyFee * infoById.getReceipt().getEnergyUsageTotal(), + infoById.getReceipt().getEnergyFee()); Assert.assertEquals(0, infoById.getReceipt().getOriginEnergyUsage()); Assert.assertEquals(388, infoById.getReceipt().getNetUsage()); Assert.assertEquals(0, infoById.getReceipt().getEnergyUsage()); Assert.assertEquals(0, infoById.getReceipt().getNetFee()); Assert.assertEquals(0, infoById.getReceipt().getEnergyPenaltyTotal()); - Protocol.Transaction transaction = PublicMethod.getTransactionById(txid, blockingStubFull).get(); + Protocol.Transaction transaction = + PublicMethod.getTransactionById(txid, blockingStubFull).get(); Assert.assertEquals(rightFeeLimit.longValue(), transaction.getRawData().getFeeLimit()); Assert.assertEquals("SUCCESS", transaction.getRet(0).getContractRet().toString()); - } - /** - * constructor. - */ - @Test(enabled = true, description = "transfer usdt, no energy, and trx balance = feeLimit - 1", groups = {"contract", "daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "transfer usdt, no energy, and trx balance = feeLimit - 1", + groups = {"contract", "daily"}) public void test03() { long balance = PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); long needSend = rightFeeLimit - balance - 1; - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, needSend, testNetAccountAddress, testNetAccountKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, needSend, testNetAccountAddress, testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String methedStr = "transfer(address,uint256)"; - String argsStr = "\"" + callerAddress58 + "\",1"; - String txid = PublicMethod.triggerContract(usdtAddress, methedStr, argsStr, - false, 0, rightFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methedStr = "transfer(address,uint256)"; + String argsStr = "\"" + callerAddress58 + "\",1"; + String txid = + PublicMethod.triggerContract( + usdtAddress, + methedStr, + argsStr, + false, + 0, + rightFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY, infoById.get().getReceipt().getResult()); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY, + infoById.get().getReceipt().getResult()); Assert.assertEquals(0, infoById.get().getReceipt().getOriginEnergyUsage()); Assert.assertEquals(0, infoById.get().getReceipt().getEnergyUsage()); Assert.assertEquals(0, infoById.get().getReceipt().getNetFee()); Assert.assertEquals(0, infoById.get().getReceipt().getEnergyPenaltyTotal()); Assert.assertEquals(infoById.get().getFee(), infoById.get().getReceipt().getEnergyFee()); Assert.assertTrue(infoById.get().getReceipt().getEnergyFee() < rightFeeLimit); - Assert.assertTrue(infoById.get().getResMessage().toStringUtf8().contains("Not enough energy for")); - Protocol.Transaction transaction = PublicMethod.getTransactionById(txid, blockingStubFull).get(); + Assert.assertTrue( + infoById.get().getResMessage().toStringUtf8().contains("Not enough energy for")); + Protocol.Transaction transaction = + PublicMethod.getTransactionById(txid, blockingStubFull).get(); Assert.assertEquals(rightFeeLimit.longValue(), transaction.getRawData().getFeeLimit()); Assert.assertEquals("OUT_OF_ENERGY", transaction.getRet(0).getContractRet().toString()); } - /** - * constructor. - */ - @Test(enabled = true, description = "originEnergy from 0 to enough", groups = {"contract", "daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "originEnergy from 0 to enough", + groups = {"contract", "daily"}) public void test04() { - //origin address has no frozen balance for energy + // origin address has no frozen balance for energy String methedStr = "transfer(address,uint256)"; - String argsStr = "\"" + dev58 + "\",1"; - String txid = PublicMethod.triggerContract(usdtAddress, methedStr, argsStr, - false, 0, maxFeeLimit, callerddress, callerKey, blockingStubFull); + String argsStr = "\"" + dev58 + "\",1"; + String txid = + PublicMethod.triggerContract( + usdtAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + callerddress, + callerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("test04 no originEnergy: " + infoById.get().toString()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, + infoById.get().getReceipt().getResult()); long originEnergyUsage = infoById.get().getReceipt().getOriginEnergyUsage(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); long netUsage = infoById.get().getReceipt().getNetUsage(); @@ -208,25 +309,41 @@ public void test04() { Assert.assertEquals(0, infoById.get().getReceipt().getEnergyUsage()); Assert.assertEquals(0, infoById.get().getReceipt().getNetFee()); Assert.assertEquals(0, infoById.get().getReceipt().getEnergyPenaltyTotal()); - Protocol.Transaction transaction = PublicMethod.getTransactionById(txid, blockingStubFull).get(); + Protocol.Transaction transaction = + PublicMethod.getTransactionById(txid, blockingStubFull).get(); Assert.assertEquals(maxFeeLimit, transaction.getRawData().getFeeLimit()); Assert.assertEquals("SUCCESS", transaction.getRet(0).getContractRet().toString()); - //origin address freeze balance to get energy - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 300000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceV2(dev001Address, 250000000L, 1, dev001Key, blockingStubFull)); + // origin address freeze balance to get energy + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 300000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceV2(dev001Address, 250000000L, 1, dev001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //origin address has enough frozen energy - txid = PublicMethod.triggerContract(usdtAddress, methedStr, argsStr, - false, 0, maxFeeLimit, callerddress, callerKey, blockingStubFull); + // origin address has enough frozen energy + txid = + PublicMethod.triggerContract( + usdtAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + callerddress, + callerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("test04 enough originEnergy: " + infoById.get().toString()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, + infoById.get().getReceipt().getResult()); originEnergyUsage = infoById.get().getReceipt().getOriginEnergyUsage(); energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); netUsage = infoById.get().getReceipt().getNetUsage(); energyFeeCost = infoById.get().getReceipt().getEnergyFee(); - Assert.assertEquals(Math.round(energyUsageTotal * (100 - consumeUserResourcePercent) / 100), originEnergyUsage); + Assert.assertEquals( + Math.round(energyUsageTotal * (100 - consumeUserResourcePercent) / 100), originEnergyUsage); Assert.assertEquals(389, netUsage); Assert.assertEquals(energyFee * (energyUsageTotal - originEnergyUsage), energyFeeCost); Assert.assertEquals(0, infoById.get().getReceipt().getNetFee()); @@ -236,47 +353,60 @@ public void test04() { Assert.assertEquals("SUCCESS", transaction.getRet(0).getContractRet().toString()); } - /** - * constructor. - */ - @Test(enabled = true, description = "change consumeUserResourcePercent from 70 to 80", groups = {"contract", "daily"}) + /** constructor. */ + @Test( + enabled = true, + description = "change consumeUserResourcePercent from 70 to 80", + groups = {"contract", "daily"}) public void test05() { consumeUserResourcePercent = 80; - Assert.assertTrue(PublicMethod.updateSetting(usdtAddress, consumeUserResourcePercent, dev001Key, dev001Address, blockingStubFull)); + Assert.assertTrue( + PublicMethod.updateSetting( + usdtAddress, consumeUserResourcePercent, dev001Key, dev001Address, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - long temPercent = PublicMethod.getContract(usdtAddress, blockingStubFull).getConsumeUserResourcePercent(); + long temPercent = + PublicMethod.getContract(usdtAddress, blockingStubFull).getConsumeUserResourcePercent(); Assert.assertEquals(consumeUserResourcePercent, temPercent); - String methedStr = "transfer(address,uint256)"; - String argsStr = "\"" + dev58 + "\",1"; - String txid = PublicMethod.triggerContract(usdtAddress, methedStr, argsStr, - false, 0, maxFeeLimit, callerddress, callerKey, blockingStubFull); + String methedStr = "transfer(address,uint256)"; + String argsStr = "\"" + dev58 + "\",1"; + String txid = + PublicMethod.triggerContract( + usdtAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + callerddress, + callerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); logger.info("test05 consumer Percent is 80 : " + infoById.toString()); - Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, infoById.getReceipt().getResult()); + Assert.assertEquals( + Protocol.Transaction.Result.contractResult.SUCCESS, infoById.getReceipt().getResult()); long originEnergyUsage = infoById.getReceipt().getOriginEnergyUsage(); long energyUsageTotal = infoById.getReceipt().getEnergyUsageTotal(); long netUsage = infoById.getReceipt().getNetUsage(); long energyFeeCost = infoById.getReceipt().getEnergyFee(); - Assert.assertEquals(Math.round(energyUsageTotal * (100 - consumeUserResourcePercent) / 100), originEnergyUsage); + Assert.assertEquals( + Math.round(energyUsageTotal * (100 - consumeUserResourcePercent) / 100), originEnergyUsage); Assert.assertEquals(389, netUsage); Assert.assertEquals(energyFee * (energyUsageTotal - originEnergyUsage), energyFeeCost); Assert.assertEquals(0, infoById.getReceipt().getNetFee()); Assert.assertEquals(0, infoById.getReceipt().getEnergyPenaltyTotal()); - Protocol.Transaction transaction = PublicMethod.getTransactionById(txid, blockingStubFull).get(); + Protocol.Transaction transaction = + PublicMethod.getTransactionById(txid, blockingStubFull).get(); Assert.assertEquals(maxFeeLimit, transaction.getRawData().getFeeLimit()); Assert.assertEquals("SUCCESS", transaction.getRet(0).getContractRet().toString()); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.unFreezeBalanceV2(dev001Address,dev001Key,50000000L,1, blockingStubFull); - PublicMethod.unFreezeBalanceV2(dev001Address,dev001Key,100000000L,0, blockingStubFull); + PublicMethod.unFreezeBalanceV2(dev001Address, dev001Key, 50000000L, 1, blockingStubFull); + PublicMethod.unFreezeBalanceV2(dev001Address, dev001Key, 100000000L, 0, blockingStubFull); PublicMethod.freeResource(dev001Address, dev001Key, testNetAccountAddress, blockingStubFull); - PublicMethod.freeResource(callerddress, callerKey, testNetAccountAddress, blockingStubFull); } + PublicMethod.freeResource(callerddress, callerKey, testNetAccountAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/VirtualTest001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/VirtualTest001.java index 9a5a4962..08cc0fdb 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/VirtualTest001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/VirtualTest001.java @@ -12,166 +12,303 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class VirtualTest001 extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] contractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 1000_000_000L, fromAddress, - testKey002, blockingStubFull)); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1000_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Deploy 0.5.15 about virtual", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy 0.5.15 about virtual", + groups = {"contract", "daily"}) public void test01OverrideContract515() { String contractName = "Z"; - String code = Configuration.getByPath("testng.conf") - .getString("code.code_virtual001"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_virtual001"); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = Configuration.getByPath("testng.conf").getString("code.code_virtual001"); + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_virtual001"); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod.getTransactionInfoById(txid, - blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - txid = PublicMethod.triggerContract(contractAddress, "setValue(uint256)", "5", false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "setValue(uint256)", + "5", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); + Assert.assertEquals(0, infoById.get().getResultValue()); - txid = PublicMethod.triggerContract(contractAddress, "setBool(bool)", "true", false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "setBool(bool)", + "true", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); + Assert.assertEquals(0, infoById.get().getResultValue()); - txid = PublicMethod.triggerContract(contractAddress, "setString(string)", "\"1q2w\"", false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "setString(string)", + "\"1q2w\"", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); + Assert.assertEquals(0, infoById.get().getResultValue()); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "x()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "x()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(5, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + 5, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "y()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "y()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + 1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "z()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "z()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals("0000000000000000000000000000000000000000000000000000000000000020" - + "0000000000000000000000000000000000000000000000000000000000000004" - + "3171327700000000000000000000000000000000000000000000000000000000", - ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000020" + + "0000000000000000000000000000000000000000000000000000000000000004" + + "3171327700000000000000000000000000000000000000000000000000000000", + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); } - @Test(enabled = true, description = "Deploy 0.6.0 about virtual", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy 0.6.0 about virtual", + groups = {"contract", "daily"}) public void test02OverrideContract060() { String filePath = "./src/test/resources/soliditycode/virtual001.sol"; - String contractName = "Z"; + String contractName = "Z"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod.getTransactionInfoById(txid, - blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - txid = PublicMethod.triggerContract(contractAddress, "setValue(uint256)", "5", false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "setValue(uint256)", + "5", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); + Assert.assertEquals(0, infoById.get().getResultValue()); - txid = PublicMethod.triggerContract(contractAddress, "setBool(bool)", "true", false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "setBool(bool)", + "true", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); + Assert.assertEquals(0, infoById.get().getResultValue()); - txid = PublicMethod.triggerContract(contractAddress, "setString(string)", "\"1q2w\"", false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "setString(string)", + "\"1q2w\"", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); + Assert.assertEquals(0, infoById.get().getResultValue()); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "x()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "x()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(5, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + 5, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "y()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "y()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals(1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + 1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "z()", "#", - false, 0, 0, "0", 0, dev001Address, dev001Key, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "z()", + "#", + false, + 0, + 0, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert - .assertEquals("0000000000000000000000000000000000000000000000000000000000000020" - + "0000000000000000000000000000000000000000000000000000000000000004" - + "3171327700000000000000000000000000000000000000000000000000000000", - ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000020" + + "0000000000000000000000000000000000000000000000000000000000000004" + + "3171327700000000000000000000000000000000000000000000000000000000", + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); } @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, - blockingStubFull); } + PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/assemblyTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/assemblyTest.java index 8ae5875b..9cdc0b50 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/assemblyTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/assemblyTest.java @@ -10,87 +10,141 @@ import org.tron.protos.Protocol.TransactionInfo; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class assemblyTest extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] contractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 100_000_000L, fromAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/assemblyTest.sol"; - String contractName = "assemblyTest"; + String filePath = "./src/test/resources/soliditycode/assemblyTest.sol"; + String contractName = "assemblyTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "get assembly references fuction number, type: uint", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "get assembly references fuction number, type: uint", + groups = {"contract", "daily"}) public void test01AssemblyReferencesUint() { String methodStr = "getZuint()"; - String argStr = ""; - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit,"0",0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals(1,ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + String argStr = ""; + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + 1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); methodStr = "getZuint2()"; - String txid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); - int ContractResult = ByteArray.toInt(infoById.get() - .getContractResult(0).toByteArray()); - Assert.assertEquals(1,ContractResult); - - + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); + int ContractResult = ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); + Assert.assertEquals(1, ContractResult); } - @Test(enabled = true, description = "get assembly references fuction number, type: boolen", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "get assembly references fuction number, type: boolen", + groups = {"contract", "daily"}) public void test02AssemblyReferencesBoolen() { String methodStr = "getZbool()"; - String argStr = ""; + String argStr = ""; - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit,"0",0, dev001Address, dev001Key, blockingStubFull); - Assert.assertEquals(1,ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + "0", + 0, + dev001Address, + dev001Key, + blockingStubFull); + Assert.assertEquals( + 1, ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray())); methodStr = "getZbool2()"; - String txid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0,infoById.get().getResultValue()); - int ContractResult = ByteArray.toInt(infoById.get() - .getContractResult(0).toByteArray()); - Assert.assertEquals(1,ContractResult); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); + int ContractResult = ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); + Assert.assertEquals(1, ContractResult); } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/calldataTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/calldataTest.java index 92dfc8bd..75a30fb4 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/calldataTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/calldataTest.java @@ -14,59 +14,81 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class calldataTest extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] contractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); } - @Test(enabled = true, description = "Deploy contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy contract", + groups = {"contract", "daily"}) public void test01DeployContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 1000_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 100_000_000L, - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1000_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 100_000_000L, + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(dev001Key, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = accountResource.getEnergyUsed(); - Long beforeNetUsed = accountResource.getNetUsed(); - Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = accountResource.getEnergyUsed(); + Long beforeNetUsed = accountResource.getNetUsed(); + Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String filePath = "./src/test/resources/soliditycode/calldata.sol"; - String contractName = "C"; + String filePath = "./src/test/resources/soliditycode/calldata.sol"; + String contractName = "C"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -81,13 +103,12 @@ public void test01DeployContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -96,13 +117,12 @@ public void test01DeployContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(dev001Key, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(dev001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -117,8 +137,6 @@ public void test01DeployContract() { @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, - blockingStubFull); } + PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/constructorDefaultsTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/constructorDefaultsTest.java index e784bb7d..7817b3fc 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/constructorDefaultsTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/constructorDefaultsTest.java @@ -10,64 +10,86 @@ import org.tron.api.GrpcAPI.AccountResourceMessage; import org.tron.protos.Protocol.TransactionInfo; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j -public class constructorDefaultsTest extends TronBaseTest { ECKey ecKey1 = new ECKey(Utils.getRandom()); +public class constructorDefaultsTest extends TronBaseTest { + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] dev001Address = ecKey1.getAddress(); - String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); /** - * constructor. - */ + String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(dev001Key); } + PublicMethod.printAddress(dev001Key); + } - @Test(enabled = true, description = "Constructor default test", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Constructor default test", + groups = {"contract", "daily"}) public void Test01ConstructorDefault() { - Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 200000000L, foundationAddress, foundationKey, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); - String filePath = "./src/test/resources/soliditycode/ConstructorDefaults.sol"; - String contractName = "testIsContract"; + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 200000000L, foundationAddress, foundationKey, blockingStubFull)); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + String filePath = "./src/test/resources/soliditycode/ConstructorDefaults.sol"; + String contractName = "testIsContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String constructorStr = "constructor(bool)"; - String data = "0"; - String txid = PublicMethod - .deployContractWithConstantParame(contractName, abi, code, constructorStr, data, "", - maxFeeLimit, 0L, 100, null, dev001Key, dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String constructorStr = "constructor(bool)"; + String data = "0"; + String txid = + PublicMethod.deployContractWithConstantParame( + contractName, + abi, + code, + constructorStr, + data, + "", + maxFeeLimit, + 0L, + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - byte[] contractaddress = null; - Optional info = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + byte[] contractaddress = null; + Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(info.toString()); Assert.assertTrue(info.get().getResultValue() == 0); data = "false"; - txid = PublicMethod - .deployContractWithConstantParame(contractName, abi, code, constructorStr, data, "", - maxFeeLimit, 0L, 100, null, dev001Key, dev001Address, blockingStubFull); + txid = + PublicMethod.deployContractWithConstantParame( + contractName, + abi, + code, + constructorStr, + data, + "", + maxFeeLimit, + 0L, + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - info = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(info.toString()); Assert.assertTrue(info.get().getResultValue() == 0); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - PublicMethod.sendcoin(foundationAddress, balance, dev001Address, dev001Key, - blockingStubFull); } + PublicMethod.sendcoin(foundationAddress, balance, dev001Address, dev001Key, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/enumAndStructTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/enumAndStructTest.java index 23c3a2c6..09aa78ec 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/enumAndStructTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/enumAndStructTest.java @@ -11,54 +11,72 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j public class enumAndStructTest extends TronBaseTest { - private String testFoundationKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); - private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); + private String testFoundationKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); + private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey1.getAddress(); String testKey001 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private byte[] contractAddress; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(testKey001); - String filePath = "src/test/resources/soliditycode/enumAndStruct.sol"; - String contractName = "enumAndStructTest"; + String filePath = "src/test/resources/soliditycode/enumAndStruct.sol"; + String contractName = "enumAndStructTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0, 100, null, - testFoundationKey, testFoundationAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0, + 100, + null, + testFoundationKey, + testFoundationAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "get Enum and Struct", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "get Enum and Struct", + groups = {"contract", "daily"}) public void EnumAndStructTest001() { - String methodStr = "getvalue()"; - String argStr = ""; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testFoundationAddress, testFoundationKey, blockingStubFull); + String argStr = ""; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); + Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); - Assert.assertEquals(1, - ByteArray.toInt(transactionInfo.get().getContractResult(0).toByteArray())); + Assert.assertEquals( + 1, ByteArray.toInt(transactionInfo.get().getContractResult(0).toByteArray())); } - - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/fallbackOldVersion.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/fallbackOldVersion.java index 4f84f083..dabc998b 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/fallbackOldVersion.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/fallbackOldVersion.java @@ -15,15 +15,16 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class fallbackOldVersion extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddressCall = null; byte[] contractAddressTest0 = null; @@ -32,96 +33,130 @@ public class fallbackOldVersion extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - PublicMethod - .sendcoin(contractExcAddress, 1000_000_000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + PublicMethod.sendcoin( + contractExcAddress, + 1000_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_fallbackOldVersionTest"); - String code = Configuration.getByPath("testng.conf") - .getString("code.code_fallbackOldVersionTest"); - String contractName = "Test0"; - contractAddressTest0 = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, - 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_fallbackOldversionCall"); - code = Configuration.getByPath("testng.conf") - .getString("code.code_fallbackOldVersionCall"); + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_fallbackOldVersionTest"); + String code = + Configuration.getByPath("testng.conf").getString("code.code_fallbackOldVersionTest"); + String contractName = "Test0"; + contractAddressTest0 = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); + abi = Configuration.getByPath("testng.conf").getString("abi.abi_fallbackOldversionCall"); + code = Configuration.getByPath("testng.conf").getString("code.code_fallbackOldVersionCall"); contractName = "Call"; - contractAddressCall = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, - 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractAddressCall = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "test fallback", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "test fallback", + groups = {"contract", "daily"}) public void test01FallbakTest() { Protocol.Account info; - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); + Long beforeBalance = info.getBalance(); logger.info("beforeBalance:" + beforeBalance); - String txid = ""; - String method = "call(address)"; + String txid = ""; + String method = "call(address)"; long value = 10000; - String para = "\"" + Base58.encode58Check(contractAddressTest0) + "\""; - txid = PublicMethod.triggerContract(contractAddressCall, method, para, false, value, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String para = "\"" + Base58.encode58Check(contractAddressTest0) + "\""; + txid = + PublicMethod.triggerContract( + contractAddressCall, + method, + para, + false, + value, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); + Long fee = infoById.get().getFee(); logger.info("fee:" + fee); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); logger.info("afterBalance:" + afterBalance); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertTrue(afterBalance + fee + value == beforeBalance); - txid = PublicMethod.triggerContract(contractAddressCall, method, para, false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddressCall, + method, + para, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); logger.info(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000001", + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000001", ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); } - //@AfterClass + // @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractAddressCall, contractExcKey, testNetAccountAddress, - blockingStubFull); - PublicMethod - .freeResource(contractAddressTest0, contractExcKey, testNetAccountAddress, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractAddressCall, contractExcKey, testNetAccountAddress, blockingStubFull); + PublicMethod.freeResource( + contractAddressTest0, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/fallbackReceive.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/fallbackReceive.java index 8cdacb24..32386e2d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/fallbackReceive.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/fallbackReceive.java @@ -18,17 +18,17 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class fallbackReceive extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddressCaller = null; byte[] contractAddressTest0 = null; @@ -40,81 +40,134 @@ public class fallbackReceive extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - PublicMethod - .sendcoin(contractExcAddress, 1000_000_000_000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + PublicMethod.sendcoin( + contractExcAddress, + 1000_000_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/fallbackUpgrade.sol"; - String contractName = "Caller"; + String filePath = "src/test/resources/soliditycode/fallbackUpgrade.sol"; + String contractName = "Caller"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddressCaller = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, - null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddressCaller = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); contractName = "Test0"; retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - contractAddressTest0 = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, - 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractAddressTest0 = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); contractName = "Test1"; retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - contractAddressTest1 = PublicMethod - .deployContractFallback(contractName, abi, code, "", maxFeeLimit, 0L, - 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractAddressTest1 = + PublicMethod.deployContractFallback( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); contractName = "Test2"; retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - contractAddressTest2 = PublicMethod - .deployContractFallback(contractName, abi, code, "", maxFeeLimit, 0L, - 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractAddressTest2 = + PublicMethod.deployContractFallback( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); contractName = "TestPayable"; retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - contractAddressTestPayable = PublicMethod - .deployContractFallback(contractName, abi, code, "", maxFeeLimit, 0L, - 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractAddressTestPayable = + PublicMethod.deployContractFallback( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "contract test0 has no fallback method", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "contract test0 has no fallback method", + groups = {"contract", "daily"}) public void test001NoFallback() { String txid = ""; - String method = "hello()"; - txid = PublicMethod.triggerContract(contractAddressTest0, - method, "#", false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String method = "hello()"; + txid = + PublicMethod.triggerContract( + contractAddressTest0, + method, + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -122,14 +175,25 @@ public void test001NoFallback() { Assert.assertEquals("FAILED", infoById.get().getResult().toString()); } - @Test(enabled = true, description = "contract test0 has no fallback method", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "contract test0 has no fallback method", + groups = {"contract", "daily"}) public void test002NoFallback() { String txid = ""; - String method = "callTest0(address)"; - String para = "\"" + Base58.encode58Check(contractAddressTest0) + "\""; - txid = PublicMethod.triggerContract(contractAddressCaller, - method, para, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String method = "callTest0(address)"; + String para = "\"" + Base58.encode58Check(contractAddressTest0) + "\""; + txid = + PublicMethod.triggerContract( + contractAddressCaller, + method, + para, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -137,14 +201,25 @@ public void test002NoFallback() { Assert.assertEquals("FAILED", infoById.get().getResult().toString()); } - @Test(enabled = true, description = "contract test01 has fallback method", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "contract test01 has fallback method", + groups = {"contract", "daily"}) public void test011Fallback() { String txid = ""; - String method = "callTest1(address)"; - String para = "\"" + Base58.encode58Check(contractAddressTest1) + "\""; - txid = PublicMethod.triggerContract(contractAddressCaller, - method, para, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String method = "callTest1(address)"; + String para = "\"" + Base58.encode58Check(contractAddressTest1) + "\""; + txid = + PublicMethod.triggerContract( + contractAddressCaller, + method, + para, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -153,21 +228,32 @@ public void test011Fallback() { List logList = infoById.get().getLogList(); if (!Objects.isNull(logList)) { for (Protocol.TransactionInfo.Log log : logList) { - //logger.info("LOG data info:" + tmp); - Assert.assertEquals("fallback", - PublicMethod.getContractStringMsg(log.getData().toByteArray())); + // logger.info("LOG data info:" + tmp); + Assert.assertEquals( + "fallback", PublicMethod.getContractStringMsg(log.getData().toByteArray())); } } } - @Test(enabled = true, description = "contract test01 has fallback method", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "contract test01 has fallback method", + groups = {"contract", "daily"}) public void test012Fallback() { String txid = ""; - String method = "callTest2(address)"; - String para = "\"" + Base58.encode58Check(contractAddressTest1) + "\""; - txid = PublicMethod.triggerContract(contractAddressCaller, - method, para, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String method = "callTest2(address)"; + String para = "\"" + Base58.encode58Check(contractAddressTest1) + "\""; + txid = + PublicMethod.triggerContract( + contractAddressCaller, + method, + para, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -175,56 +261,96 @@ public void test012Fallback() { Assert.assertEquals("REVERT", infoById.get().getReceipt().getResult().toString()); } - @Test(enabled = true, description = "contract test01 has fallback method", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "contract test01 has fallback method", + groups = {"contract", "daily"}) public void test013Fallback() { String txid = ""; - txid = PublicMethod.triggerContract(contractAddressTest1, - "hello()", "#", false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddressTest1, + "hello()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("getResult: " + infoById.get().getResultValue()); Assert.assertEquals("SUCESS", infoById.get().getResult().toString()); - txid = PublicMethod.triggerContract(contractAddressTest1, - "hello2()", "#", false, - 100000, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddressTest1, + "hello2()", + "#", + false, + 100000, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("result:" + infoById.get().getReceipt().getResult()); Assert.assertEquals("REVERT", infoById.get().getReceipt().getResult().toString()); } - @Test(enabled = true, description = "contract test02 has fallback payable method", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "contract test02 has fallback payable method", + groups = {"contract", "daily"}) public void test021FallbackPayable() { Protocol.Account info; - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); + Long beforeBalance = info.getBalance(); logger.info("beforeBalance:" + beforeBalance); - String txid = ""; + String txid = ""; long value = 10000; - txid = PublicMethod.triggerContract(contractAddressTest2, "hello()", "#", false, value, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddressTest2, + "hello()", + "#", + false, + value, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("result:" + infoById.get().getReceipt().getResult()); Assert.assertEquals("SUCESS", infoById.get().getResult().toString()); - Long fee = infoById.get().getFee(); + Long fee = infoById.get().getFee(); logger.info("fee:" + fee); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); logger.info("afterBalance:" + afterBalance); Assert.assertTrue(afterBalance + fee + value == beforeBalance); - String method = "callTest2(address)"; - String para = "\"" + Base58.encode58Check(contractAddressTest2) + "\""; - txid = PublicMethod.triggerContract(contractAddressCaller, method, para, false, value, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String method = "callTest2(address)"; + String para = "\"" + Base58.encode58Check(contractAddressTest2) + "\""; + txid = + PublicMethod.triggerContract( + contractAddressCaller, + method, + para, + false, + value, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("callTest2 result:" + infoById.get().getReceipt().getResult()); @@ -232,114 +358,154 @@ public void test021FallbackPayable() { fee = infoById.get().getFee(); logger.info("callTest2 fee:" + fee); infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance2 = infoafter.getBalance(); + resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance2 = infoafter.getBalance(); logger.info("callTest2 afterBalance:" + afterBalance); Assert.assertTrue(afterBalance2 + fee + value == afterBalance); } - @Test(enabled = true, description = "contract TestPayable has fallback and receive", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "contract TestPayable has fallback and receive", + groups = {"contract", "daily"}) public void test041FallbackReceive() { String txid = ""; - String method = "callTestPayable1(address)"; - String para = "\"" + Base58.encode58Check(contractAddressTestPayable) + "\""; - txid = PublicMethod.triggerContract(contractAddressCaller, - method, para, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String method = "callTestPayable1(address)"; + String para = "\"" + Base58.encode58Check(contractAddressTestPayable) + "\""; + txid = + PublicMethod.triggerContract( + contractAddressCaller, + method, + para, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("getResult: " + infoById.get().getResultValue()); Assert.assertEquals("SUCESS", infoById.get().getResult().toString()); - Assert.assertEquals("fallback", + Assert.assertEquals( + "fallback", PublicMethod.getContractStringMsg(infoById.get().getLog(0).getData().toByteArray())); - Assert.assertEquals("receive", + Assert.assertEquals( + "receive", PublicMethod.getContractStringMsg(infoById.get().getLog(1).getData().toByteArray())); } - @Test(enabled = true, description = "contract TestPayable has fallback and receive", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "contract TestPayable has fallback and receive", + groups = {"contract", "daily"}) public void test042FallbackReceive() { Protocol.Account info; - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - String txid = ""; - Long beforeBalance = info.getBalance(); + String txid = ""; + Long beforeBalance = info.getBalance(); logger.info("beforeBalance:" + beforeBalance); - String method = "callTest2(address)"; + String method = "callTest2(address)"; long value = 10000; - String para = "\"" + Base58.encode58Check(contractAddressTestPayable) + "\""; - txid = PublicMethod.triggerContract(contractAddressCaller, - method, para, false, - value, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String para = "\"" + Base58.encode58Check(contractAddressTestPayable) + "\""; + txid = + PublicMethod.triggerContract( + contractAddressCaller, + method, + para, + false, + value, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals("fallback", + Assert.assertEquals( + "fallback", PublicMethod.getContractStringMsg(infoById.get().getLog(0).getData().toByteArray())); - Long fee = infoById.get().getFee(); + Long fee = infoById.get().getFee(); logger.info("fee:" + fee); Protocol.Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); logger.info("afterBalance:" + afterBalance); Assert.assertTrue(afterBalance + fee + value == beforeBalance); } - @Test(enabled = true, description = "contract TestPayable has fallback and receive", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "contract TestPayable has fallback and receive", + groups = {"contract", "daily"}) public void test05FallbackReceive() { String txid = ""; long value = 10000; - txid = PublicMethod.triggerContract(contractAddressTestPayable, - "method()", "#", false, - value, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddressTestPayable, + "method()", + "#", + false, + value, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals("SUCESS", infoById.get().getResult().toString()); - Assert.assertEquals("fallback", + Assert.assertEquals( + "fallback", PublicMethod.getContractStringMsg(infoById.get().getLog(0).getData().toByteArray())); - Protocol.Account infoafter = PublicMethod - .queryAccount(contractAddressTestPayable, blockingStubFull); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractAddressTestPayable, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); + Protocol.Account infoafter = + PublicMethod.queryAccount(contractAddressTestPayable, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractAddressTestPayable, blockingStubFull); + Long afterBalance = infoafter.getBalance(); logger.info("contract balance:" + afterBalance.longValue()); Assert.assertEquals(11000, afterBalance.longValue()); - txid = PublicMethod.triggerContract(contractAddressTestPayable, - "#", "#", false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddressTestPayable, + "#", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.get().getResult().toString()); Assert.assertEquals("SUCESS", infoById.get().getResult().toString()); - Assert.assertEquals("receive", + Assert.assertEquals( + "receive", PublicMethod.getContractStringMsg(infoById.get().getLog(0).getData().toByteArray())); - } - //@AfterClass + // @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractAddressTest0, contractExcKey, testNetAccountAddress, - blockingStubFull); - PublicMethod - .freeResource(contractAddressTest1, contractExcKey, testNetAccountAddress, - blockingStubFull); - PublicMethod - .freeResource(contractAddressTest2, contractExcKey, testNetAccountAddress, - blockingStubFull); - PublicMethod - .freeResource(contractAddressTestPayable, contractExcKey, testNetAccountAddress, - blockingStubFull); - PublicMethod - .freeResource(contractAddressCaller, contractExcKey, testNetAccountAddress, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractAddressTest0, contractExcKey, testNetAccountAddress, blockingStubFull); + PublicMethod.freeResource( + contractAddressTest1, contractExcKey, testNetAccountAddress, blockingStubFull); + PublicMethod.freeResource( + contractAddressTest2, contractExcKey, testNetAccountAddress, blockingStubFull); + PublicMethod.freeResource( + contractAddressTestPayable, contractExcKey, testNetAccountAddress, blockingStubFull); + PublicMethod.freeResource( + contractAddressCaller, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } -} \ No newline at end of file + } + } +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/mappingGetterTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/mappingGetterTest.java index eb34fbe6..12e49570 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/mappingGetterTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/mappingGetterTest.java @@ -14,59 +14,81 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class mappingGetterTest extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] contractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); } - @Test(enabled = true, description = "Deploy contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy contract", + groups = {"contract", "daily"}) public void test01DeployContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 1000_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 100_000_000L, - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1000_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 100_000_000L, + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(dev001Key, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = accountResource.getEnergyUsed(); - Long beforeNetUsed = accountResource.getNetUsed(); - Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = accountResource.getEnergyUsed(); + Long beforeNetUsed = accountResource.getNetUsed(); + Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String filePath = "./src/test/resources/soliditycode/mappingGetter.sol"; - String contractName = "mappingGetter"; + String filePath = "./src/test/resources/soliditycode/mappingGetter.sol"; + String contractName = "mappingGetter"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -81,13 +103,12 @@ public void test01DeployContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -96,13 +117,12 @@ public void test01DeployContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(dev001Key, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(dev001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -114,14 +134,10 @@ public void test01DeployContract() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, - blockingStubFull); } + PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/stateVariableShadowing.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/stateVariableShadowing.java index 3237389d..1897eea4 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/stateVariableShadowing.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/stateVariableShadowing.java @@ -17,16 +17,16 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class stateVariableShadowing extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -34,65 +34,83 @@ public class stateVariableShadowing extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); PublicMethod.waitProduceNextBlock(blockingStubFull); - PublicMethod - .sendcoin(contractExcAddress, 1000_000_000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull); + PublicMethod.sendcoin( + contractExcAddress, + 1000_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/stateVariableShadowing.sol"; - String contractName = "stateVariableShadowing"; + String filePath = "src/test/resources/soliditycode/stateVariableShadowing.sol"; + String contractName = "stateVariableShadowing"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Verify that the compilation is successful", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Verify that the compilation is successful", + groups = {"contract", "daily"}) public void test01VerifyCompile() { Protocol.Account info; - GrpcAPI.AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + GrpcAPI.AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; + String txid = ""; ArrayList methods = new ArrayList(); methods.add("setValue2(uint256)"); methods.add("setValue3(uint256)"); for (String tmp : methods) { System.out.println(tmp); - txid = PublicMethod.triggerContract(contractAddress, - tmp, "100", false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + tmp, + "100", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -104,8 +122,10 @@ public void test01VerifyCompile() { @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/typeNameTest.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/typeNameTest.java index eafe8efc..c48e9455 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/typeNameTest.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/typeNameTest.java @@ -15,59 +15,81 @@ import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.ECKey; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j @MultiNode public class typeNameTest extends TronBaseTest { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] contractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); } - @Test(enabled = true, description = "Deploy contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy contract", + groups = {"contract", "daily"}) public void test01DeployContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 1000_000_000L, fromAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 100_000_000L, - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1000_000_000L, fromAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 100_000_000L, + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(dev001Key, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = accountResource.getEnergyUsed(); - Long beforeNetUsed = accountResource.getNetUsed(); - Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = accountResource.getEnergyUsed(); + Long beforeNetUsed = accountResource.getNetUsed(); + Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String filePath = "./src/test/resources/soliditycode/typeName.sol"; - String contractName = "TypeName"; + String filePath = "./src/test/resources/soliditycode/typeName.sol"; + String contractName = "TypeName"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -82,13 +104,12 @@ public void test01DeployContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -97,13 +118,12 @@ public void test01DeployContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(dev001Key, blockingStubFull); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(dev001Address, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -115,29 +135,34 @@ public void test01DeployContract() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - - @Test(enabled = true, description = "Trigger testTypeName function", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger testTypeName function", + groups = {"contract", "daily"}) public void test02TriggerTestTypeNameFunction() { - final String txid = PublicMethod.triggerContract(contractAddress, - "testTypeName()", "#", false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + final String txid = + PublicMethod.triggerContract( + contractAddress, + "testTypeName()", + "#", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); logger.info("infoById:" + infoById.get()); - Assert.assertTrue(infoById.get().getContractResult(0).toStringUtf8() - .contains("TypeName")); + Assert.assertTrue(infoById.get().getContractResult(0).toStringUtf8().contains("TypeName")); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, - blockingStubFull); } + PublicMethod.sendcoin(fromAddress, balance, dev001Address, dev001Key, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand001.java index 9b864eee..131a5cc5 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand001.java @@ -17,17 +17,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class ShiftCommand001 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -35,72 +35,90 @@ public class ShiftCommand001 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } - + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = true, description = "Trigger old ShiftLeft ShiftRight", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger old ShiftLeft ShiftRight", + groups = {"contract", "daily"}) public void test1OldInstruction() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TvmOldCommand001.sol"; - String contractName = "binaryRightContract"; + String filePath = "src/test/resources/soliditycode/TvmOldCommand001.sol"; + String contractName = "binaryRightContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - String num = "1"; - txid = PublicMethod.triggerContract(contractAddress, - "binaryMoveR(uint256)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "1"; + txid = + PublicMethod.triggerContract( + contractAddress, + "binaryMoveR(uint256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -109,12 +127,12 @@ public void test1OldInstruction() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -125,55 +143,82 @@ public void test1OldInstruction() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - txid = PublicMethod.triggerContract(contractAddress, - "binaryLiftR(uint256)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "binaryLiftR(uint256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - - } - @Test(enabled = true, description = "Trigger new ShiftLeft ShiftRight ShiftRightSigned", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger new ShiftLeft ShiftRight ShiftRightSigned", + groups = {"contract", "daily"}) public void test2NewInstruction() { String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; - String contractName = "TestBitwiseShift"; + String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - String num = "1" + "," + "5"; + String txid = ""; + String num = "1" + "," + "5"; - txid = PublicMethod.triggerContract(contractAddress, - "sarTest(uint256,uint256)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "sarTest(uint256,uint256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -183,12 +228,12 @@ public void test2NewInstruction() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -199,31 +244,45 @@ public void test2NewInstruction() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - txid = PublicMethod.triggerContract(contractAddress, - "shlTest(uint256,uint256)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "shlTest(uint256,uint256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertEquals(10, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - txid = PublicMethod.triggerContract(contractAddress, - "shrTest(uint256,uint256)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "shrTest(uint256,uint256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertEquals(2, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand002.java index a1e9f27e..30ca30c7 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand002.java @@ -17,16 +17,16 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class ShiftCommand002 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -34,81 +34,106 @@ public class ShiftCommand002 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); - blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } - + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + } - @Test(enabled = true, description = "OLd compiler compile shift instruction", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "OLd compiler compile shift instruction", + groups = {"contract", "daily"}) public void test1Oldcompile() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName = "TestBitwiseShift"; - String code = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a5" - + "7600080fd5b506101478061003a6000396000f3006080604052600436106100565763ffffffff7c0100" - + "000000000000000000000000000000000000000000000000000000600035041663614eb4da811461005" - + "b578063b5675d6d146100a2578063baf27c0c146100d7575b600080fd5b34801561006757600080fd5b" - + "50d3801561007457600080fd5b50d2801561008157600080fd5b5061009060043560243561010c565b6" - + "0408051918252519081900360200190f35b3480156100ae57600080fd5b50d380156100bb57600080fd" - + "5b50d280156100c857600080fd5b50610090600435602435610111565b3480156100e357600080fd5b5" - + "0d380156100f057600080fd5b50d280156100fd57600080fd5b50610090600435602435610116565b90" - + "1b90565b901d90565b901c905600a165627a7a723058200d5cc53ffdc6db62c4d7414d8b7d95c98218e" - + "50b4c1ea5961d527de1439733450029"; - String abi = "[{\"constant\":false,\"inputs\":[{\"name\":\"num\",\"type\":\"uint256\"}," - + "{\"name\":\"input\",\"type\":\"uint256\"}],\"name\":\"shlTest\",\"outputs\":" - + "[{\"name\":\"out\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":" - + "\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":" - + "\"num\",\"type\":\"uint256\"},{\"name\":\"input\",\"type\":\"uint256\"}],\"name" - + "\":\"sarTest\",\"outputs\":[{\"name\":\"out\",\"type\":\"bytes32\"}],\"payable" - + "\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant" - + "\":false,\"inputs\":[{\"name\":\"num\",\"type\":\"uint256\"},{\"name\":\"input\"" - + ",\"type\":\"uint256\"}],\"name\":\"shrTest\",\"outputs\":[{\"name\":\"out\",\"" - + "type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"" - + "type\":\"function\"}]"; - - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String contractName = "TestBitwiseShift"; + String code = + "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a5" + + "7600080fd5b506101478061003a6000396000f3006080604052600436106100565763ffffffff7c0100" + + "000000000000000000000000000000000000000000000000000000600035041663614eb4da811461005" + + "b578063b5675d6d146100a2578063baf27c0c146100d7575b600080fd5b34801561006757600080fd5b" + + "50d3801561007457600080fd5b50d2801561008157600080fd5b5061009060043560243561010c565b6" + + "0408051918252519081900360200190f35b3480156100ae57600080fd5b50d380156100bb57600080fd" + + "5b50d280156100c857600080fd5b50610090600435602435610111565b3480156100e357600080fd5b5" + + "0d380156100f057600080fd5b50d280156100fd57600080fd5b50610090600435602435610116565b90" + + "1b90565b901d90565b901c905600a165627a7a723058200d5cc53ffdc6db62c4d7414d8b7d95c98218e" + + "50b4c1ea5961d527de1439733450029"; + String abi = + "[{\"constant\":false,\"inputs\":[{\"name\":\"num\",\"type\":\"uint256\"}," + + "{\"name\":\"input\",\"type\":\"uint256\"}],\"name\":\"shlTest\",\"outputs\":" + + "[{\"name\":\"out\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":" + + "\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":" + + "\"num\",\"type\":\"uint256\"},{\"name\":\"input\",\"type\":\"uint256\"}],\"name" + + "\":\"sarTest\",\"outputs\":[{\"name\":\"out\",\"type\":\"bytes32\"}],\"payable" + + "\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant" + + "\":false,\"inputs\":[{\"name\":\"num\",\"type\":\"uint256\"},{\"name\":\"input\"" + + ",\"type\":\"uint256\"}],\"name\":\"shrTest\",\"outputs\":[{\"name\":\"out\",\"" + + "type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"" + + "type\":\"function\"}]"; + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - String num = "1" + "," + "5"; + String txid = ""; + String num = "1" + "," + "5"; - txid = PublicMethod - .triggerContract(contractAddress, "sarTest(uint256,uint256)", num, false, 0, maxFeeLimit, - contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "sarTest(uint256,uint256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -118,12 +143,12 @@ public void test1Oldcompile() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -134,59 +159,99 @@ public void test1Oldcompile() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - txid = PublicMethod - .triggerContract(contractAddress, "shlTest(uint256,uint256)", num, false, 0, maxFeeLimit, - contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "shlTest(uint256,uint256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - txid = PublicMethod - .triggerContract(contractAddress, "shrTest(uint256,uint256)", num, false, 0, maxFeeLimit, - contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "shrTest(uint256,uint256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - } - @Test(enabled = true, description = "New compiler compile shift instruction", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "New compiler compile shift instruction", + groups = {"contract", "daily"}) public void test2Newcompile() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); - String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; - String contractName = "TestBitwiseShift"; + String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; + String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - String num = "1" + "," + "5"; + String txid = ""; + String num = "1" + "," + "5"; - txid = PublicMethod - .triggerContract(contractAddress, "sarTest(uint256,uint256)", num, false, 0, maxFeeLimit, - contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "sarTest(uint256,uint256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -196,12 +261,12 @@ public void test2Newcompile() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -212,28 +277,41 @@ public void test2Newcompile() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - txid = PublicMethod - .triggerContract(contractAddress, "shlTest(uint256,uint256)", num, false, 0, maxFeeLimit, - contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "shlTest(uint256,uint256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - txid = PublicMethod - .triggerContract(contractAddress, "shrTest(uint256,uint256)", num, false, 0, maxFeeLimit, - contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "shrTest(uint256,uint256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand003.java index 6fcf7d76..013ec51d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand003.java @@ -19,16 +19,16 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.DataWord; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class ShiftCommand003 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -36,79 +36,98 @@ public class ShiftCommand003 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = true, description = "Trigger new ShiftLeft with displacement number too short ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger new ShiftLeft with displacement number too short ", + groups = {"contract", "daily"}) public void test1ShiftLeft() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; - String contractName = "TestBitwiseShift"; + String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; + String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x01")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); + String param = Hex.toHexString(paramBytes); logger.info("param:" + param); - String txid = ""; - txid = PublicMethod.triggerContract(contractAddress, - "shlTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + txid = + PublicMethod.triggerContract( + contractAddress, + "shlTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -118,12 +137,12 @@ public void test1ShiftLeft() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -134,53 +153,65 @@ public void test1ShiftLeft() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - - @Test(enabled = true, description = "Trigger new ShiftRight with displacement number too short ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger new ShiftRight with displacement number too short ", + groups = {"contract", "daily"}) public void test2ShiftRight() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x01")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); + String param = Hex.toHexString(paramBytes); logger.info("param:" + param); - String txid = ""; - txid = PublicMethod.triggerContract(contractAddress, - "shrTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + txid = + PublicMethod.triggerContract( + contractAddress, + "shrTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -190,12 +221,12 @@ public void test2ShiftRight() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -206,54 +237,65 @@ public void test2ShiftRight() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("00007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "00007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - - @Test(enabled = true, description = "Trigger new ShiftRightSigned " - + "with displacement number too short ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger new ShiftRightSigned " + "with displacement number too short ", + groups = {"contract", "daily"}) public void test3ShiftRightSigned() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x01")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); + String param = Hex.toHexString(paramBytes); logger.info("param:" + param); - String txid = ""; - txid = PublicMethod.triggerContract(contractAddress, - "sarTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + txid = + PublicMethod.triggerContract( + contractAddress, + "sarTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -263,12 +305,12 @@ public void test3ShiftRightSigned() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -279,25 +321,25 @@ public void test3ShiftRightSigned() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("00007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "00007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand004.java index 0cd73e9e..7a763e92 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand004.java @@ -19,17 +19,17 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.DataWord; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class ShiftCommand004 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,81 +37,102 @@ public class ShiftCommand004 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = true, description = "Trigger new ShiftLeft,value is " - + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" - + "is 0x00", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftLeft,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacemen" + + "t number" + + "is 0x00", + groups = {"contract", "daily"}) public void test1ShiftLeft() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; - String contractName = "TestBitwiseShift"; + String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; + String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x00")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000001")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x00")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "shlTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "shlTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -121,12 +142,12 @@ public void test1ShiftLeft() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -137,58 +158,71 @@ public void test1ShiftLeft() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000001")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftLeft,value is " - + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" - + "is 0x01", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftLeft,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacemen" + + "t number" + + "is 0x01", + groups = {"contract", "daily"}) public void test2ShiftLeft() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray - .fromHexString("0x01")) - .getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000001")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "shlTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "shlTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -198,12 +232,12 @@ public void test2ShiftLeft() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -214,59 +248,71 @@ public void test2ShiftLeft() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000002")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000002")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - - @Test(enabled = true, description = "Trigger new ShiftLeft,value is " - + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" - + "is 0xff", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftLeft,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacemen" + + "t number" + + "is 0xff", + groups = {"contract", "daily"}) public void test3ShiftLeft() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray - .fromHexString("0xff")) - .getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000001")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0xff")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "shlTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "shlTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -276,12 +322,12 @@ public void test3ShiftLeft() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -292,56 +338,70 @@ public void test3ShiftLeft() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x8000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - - @Test(enabled = true, description = "Trigger new ShiftLeft,value is " - + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" - + "is 0x0100", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftLeft,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacemen" + + "t number" + + "is 0x0100", + groups = {"contract", "daily"}) public void test4ShiftLeft() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x0100")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000001")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x0100")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - txid = PublicMethod.triggerContract(contractAddress, - "shlTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + txid = + PublicMethod.triggerContract( + contractAddress, + "shlTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -351,12 +411,12 @@ public void test4ShiftLeft() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -367,53 +427,68 @@ public void test4ShiftLeft() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftLeft,value is " - + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" - + "is 0x0101", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftLeft,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacemen" + + "t number" + + "is 0x0101", + groups = {"contract", "daily"}) public void test5ShiftLeft() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x0101")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000001")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x0101")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - txid = PublicMethod.triggerContract(contractAddress, - "shlTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + txid = + PublicMethod.triggerContract( + contractAddress, + "shlTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -423,12 +498,12 @@ public void test5ShiftLeft() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -439,53 +514,68 @@ public void test5ShiftLeft() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftLeft,value is " - + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" - + "is 0x00", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftLeft,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacemen" + + "t number" + + "is 0x00", + groups = {"contract", "daily"}) public void test6ShiftLeft() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x00")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x00")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - txid = PublicMethod.triggerContract(contractAddress, - "shlTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + txid = + PublicMethod.triggerContract( + contractAddress, + "shlTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -495,12 +585,12 @@ public void test6ShiftLeft() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -511,65 +601,90 @@ public void test6ShiftLeft() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftLeft,value is " - + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" - + "is 0x01", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftLeft,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacemen" + + "t number" + + "is 0x01", + groups = {"contract", "daily"}) public void test7ShiftLeft() { String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; - String contractName = "TestBitwiseShift"; + String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x01")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "shlTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "shlTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -579,12 +694,12 @@ public void test7ShiftLeft() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -595,57 +710,71 @@ public void test7ShiftLeft() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - - @Test(enabled = true, description = "Trigger new ShiftLeft,value is " - + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" - + "is 0xff", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftLeft,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacemen" + + "t number" + + "is 0xff", + groups = {"contract", "daily"}) public void test8ShiftLeft() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0xff")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0xff")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "shlTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "shlTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -655,12 +784,12 @@ public void test8ShiftLeft() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -671,56 +800,70 @@ public void test8ShiftLeft() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x8000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - - @Test(enabled = true, description = "Trigger new ShiftLeft,value is " - + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" - + "is 0x0100", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftLeft,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacemen" + + "t number" + + "is 0x0100", + groups = {"contract", "daily"}) public void test9ShiftLeft() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x0100")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x0100")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "shlTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "shlTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -730,12 +873,12 @@ public void test9ShiftLeft() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -746,56 +889,70 @@ public void test9ShiftLeft() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - - @Test(enabled = true, description = "Trigger new ShiftLeft,value is " - + "0x0000000000000000000000000000000000000000000000000000000000000000 and Displacement number" - + "is 0x01", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftLeft,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000000 and Displacemen" + + "t number" + + "is 0x01", + groups = {"contract", "daily"}) public void testShiftLeft10() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x01")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000000")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "shlTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "shlTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -805,12 +962,12 @@ public void testShiftLeft10() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -821,56 +978,71 @@ public void testShiftLeft10() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftLeft,value is " - + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" - + "is 0x01", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftLeft,value is " + + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacemen" + + "t number" + + "is 0x01", + groups = {"contract", "daily"}) public void testShiftLeft11() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x01")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "shlTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "shlTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -880,12 +1052,12 @@ public void testShiftLeft11() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -896,66 +1068,91 @@ public void testShiftLeft11() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftLeft,value is " - + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" - + "is 0x0101", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftLeft,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacemen" + + "t number" + + "is 0x0101", + groups = {"contract", "daily"}) public void testShiftLeft12() { String filePath = "src/test/resources/soliditycode/TvmNewCommand043.sol"; - String contractName = "TestBitwiseShift"; + String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x0101")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x0101")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "shlTest(int256,int256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "shlTest(int256,int256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -965,12 +1162,12 @@ public void testShiftLeft12() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -981,26 +1178,25 @@ public void testShiftLeft12() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand005.java index ab5afc7e..27bf06c3 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand005.java @@ -19,17 +19,17 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.DataWord; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class ShiftCommand005 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,81 +37,102 @@ public class ShiftCommand005 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = true, description = "Trigger new ShiftRight,value is " - + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" - + "is 0x00", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRight,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacemen" + + "t number" + + "is 0x00", + groups = {"contract", "daily"}) public void test1ShiftRight() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 100000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; - String contractName = "TestBitwiseShift"; + String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; + String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x00")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000001")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x00")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "shrTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "shrTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -121,12 +142,12 @@ public void test1ShiftRight() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -137,58 +158,75 @@ public void test1ShiftRight() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber14 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + Long returnnumber14 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000001")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftRight,value is " - + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" - + "is 0x01", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRight,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacemen" + + "t number" + + "is 0x01", + groups = {"contract", "daily"}) public void test2ShiftRight() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x01")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000001")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "shrTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "shrTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -198,12 +236,12 @@ public void test2ShiftRight() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -214,54 +252,71 @@ public void test2ShiftRight() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftRight,value is " - + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" - + "is 0x01", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRight,value is " + + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacemen" + + "t number" + + "is 0x01", + groups = {"contract", "daily"}) public void test3ShiftRight() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - String originNumber = String.valueOf(ByteArray.toLong(ByteArray - .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000"))); - String valueNumber = String.valueOf(ByteArray.toLong((ByteArray - .fromHexString("0x01")))); - String num = valueNumber + "," + originNumber; + String txid = ""; + String originNumber = + String.valueOf( + ByteArray.toLong( + ByteArray.fromHexString( + "0x8000000000000000000000000000000000000000000000000000000000000000"))); + String valueNumber = String.valueOf(ByteArray.toLong((ByteArray.fromHexString("0x01")))); + String num = valueNumber + "," + originNumber; logger.info("returnnumber:" + originNumber); logger.info("returnnumber1:" + valueNumber); - txid = PublicMethod.triggerContract(contractAddress, - "shrTest(uint256,uint256)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "shrTest(uint256,uint256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -271,12 +326,12 @@ public void test3ShiftRight() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -287,57 +342,70 @@ public void test3ShiftRight() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x4000000000000000000000000000000000000000000000000000000000000000")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x4000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftRight,value is " - + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" - + "is 0xff", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRight,value is " + + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacemen" + + "t number" + + "is 0xff", + groups = {"contract", "daily"}) public void test4ShiftRight() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray - .fromHexString("0xff")) - .getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x8000000000000000000000000000000000000000000000000000000000000000")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0xff")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - txid = PublicMethod.triggerContract(contractAddress, - "shrTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + txid = + PublicMethod.triggerContract( + contractAddress, + "shrTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -347,12 +415,12 @@ public void test4ShiftRight() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -363,59 +431,75 @@ public void test4ShiftRight() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber14 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + Long returnnumber14 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000001")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - - @Test(enabled = true, description = "Trigger new ShiftRight,value is " - + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" - + "is 0x0100", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRight,value is " + + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacemen" + + "t number" + + "is 0x0100", + groups = {"contract", "daily"}) public void test5ShiftRight() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x0100")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x8000000000000000000000000000000000000000000000000000000000000000")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x0100")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "shrTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "shrTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -425,12 +509,12 @@ public void test5ShiftRight() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -441,56 +525,71 @@ public void test5ShiftRight() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftRight,value is " - + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" - + "is 0x0101", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRight,value is " + + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacemen" + + "t number" + + "is 0x0101", + groups = {"contract", "daily"}) public void test6ShiftRight() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x0101")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x8000000000000000000000000000000000000000000000000000000000000000")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x0101")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "shrTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "shrTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -500,12 +599,12 @@ public void test6ShiftRight() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -516,56 +615,71 @@ public void test6ShiftRight() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftRight,value is " - + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" - + "is 0x00", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRight,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacemen" + + "t number" + + "is 0x00", + groups = {"contract", "daily"}) public void test7ShiftRight() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x00")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x00")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "shrTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "shrTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -575,12 +689,12 @@ public void test7ShiftRight() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -591,56 +705,71 @@ public void test7ShiftRight() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftRight,value is " - + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" - + "is 0x01", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRight,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacemen" + + "t number" + + "is 0x01", + groups = {"contract", "daily"}) public void test8ShiftRight() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x01")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "shrTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "shrTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -650,12 +779,12 @@ public void test8ShiftRight() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -666,58 +795,75 @@ public void test8ShiftRight() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber14 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + Long returnnumber14 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftRight,value is " - + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" - + "is 0xff", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRight,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacemen" + + "t number" + + "is 0xff", + groups = {"contract", "daily"}) public void test9ShiftRight() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0xff")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0xff")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "shrTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "shrTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -727,12 +873,12 @@ public void test9ShiftRight() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -743,58 +889,75 @@ public void test9ShiftRight() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber14 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + Long returnnumber14 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000001")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftRight,value is " - + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" - + "is 0x0100", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRight,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacemen" + + "t number" + + "is 0x0100", + groups = {"contract", "daily"}) public void testShiftRight10() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x0100")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x0100")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "shrTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "shrTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -804,12 +967,12 @@ public void testShiftRight10() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -820,66 +983,91 @@ public void testShiftRight10() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftRight,value is " - + "0x0000000000000000000000000000000000000000000000000000000000000000 and Displacement number" - + "is 0x01", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRight,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000000 and Displacemen" + + "t number" + + "is 0x01", + groups = {"contract", "daily"}) public void testShiftRight11() { String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; - String contractName = "TestBitwiseShift"; + String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x01")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000000")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "shrTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "shrTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -889,12 +1077,12 @@ public void testShiftRight11() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -905,67 +1093,91 @@ public void testShiftRight11() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - - @Test(enabled = true, description = "Trigger new ShiftRight,value is " - + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" - + "is 0x0101", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRight,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacemen" + + "t number" + + "is 0x0101", + groups = {"contract", "daily"}) public void testShiftRight12() { String filePath = "src/test/resources/soliditycode/TvmNewCommand043.sol"; - String contractName = "TestBitwiseShift"; + String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x0101")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x0101")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "shrTest(int256,int256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "shrTest(int256,int256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -975,12 +1187,12 @@ public void testShiftRight12() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -991,25 +1203,25 @@ public void testShiftRight12() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand006.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand006.java index fadc74cb..920e94e2 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand006.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand006.java @@ -19,17 +19,17 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.DataWord; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class ShiftCommand006 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,81 +37,102 @@ public class ShiftCommand006 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " - + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" - + "is 0x00", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRightSigned,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacemen" + + "t number" + + "is 0x00", + groups = {"contract", "daily"}) public void test1ShiftRightSigned() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 100000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; - String contractName = "TestBitwiseShift"; + String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; + String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x00")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000001")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x00")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "sarTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "sarTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -121,12 +142,12 @@ public void test1ShiftRightSigned() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -137,56 +158,71 @@ public void test1ShiftRightSigned() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000001")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " - + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" - + "is 0x01", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRightSigned,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacemen" + + "t number" + + "is 0x01", + groups = {"contract", "daily"}) public void test2ShiftRightSigned() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x01")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000001")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "sarTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "sarTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -196,12 +232,12 @@ public void test2ShiftRightSigned() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -212,57 +248,74 @@ public void test2ShiftRightSigned() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber14 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + Long returnnumber14 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " - + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" - + "is 0x01", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRightSigned,value is " + + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacemen" + + "t number" + + "is 0x01", + groups = {"contract", "daily"}) public void test3ShiftRightSigned() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x01")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x8000000000000000000000000000000000000000000000000000000000000000")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "sarTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "sarTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -272,12 +325,12 @@ public void test3ShiftRightSigned() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -288,58 +341,71 @@ public void test3ShiftRightSigned() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0xc000000000000000000000000000000000000000000000000000000000000000")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0xc000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " - + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" - + "is 0xff", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRightSigned,value is " + + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacemen" + + "t number" + + "is 0xff", + groups = {"contract", "daily"}) public void test4ShiftRightSigned() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray - .fromHexString("0xff")) - .getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x8000000000000000000000000000000000000000000000000000000000000000")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0xff")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "sarTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "sarTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -349,12 +415,12 @@ public void test4ShiftRightSigned() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -365,57 +431,74 @@ public void test4ShiftRightSigned() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber14 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + Long returnnumber14 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " - + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" - + "is 0x0100", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRightSigned,value is " + + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacemen" + + "t number" + + "is 0x0100", + groups = {"contract", "daily"}) public void test5ShiftRightSigned() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x0100")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x8000000000000000000000000000000000000000000000000000000000000000")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x0100")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - txid = PublicMethod.triggerContract(contractAddress, - "sarTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + txid = + PublicMethod.triggerContract( + contractAddress, + "sarTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -425,12 +508,12 @@ public void test5ShiftRightSigned() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -441,57 +524,74 @@ public void test5ShiftRightSigned() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber14 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + Long returnnumber14 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " - + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" - + "is 0x0101", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRightSigned,value is " + + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacemen" + + "t number" + + "is 0x0101", + groups = {"contract", "daily"}) public void test6ShiftRightSigned() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x0101")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x8000000000000000000000000000000000000000000000000000000000000000")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x0101")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - txid = PublicMethod.triggerContract(contractAddress, - "sarTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + txid = + PublicMethod.triggerContract( + contractAddress, + "sarTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -501,12 +601,12 @@ public void test6ShiftRightSigned() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -517,60 +617,75 @@ public void test6ShiftRightSigned() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber14 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + Long returnnumber14 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " - + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" - + "is 0x00", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRightSigned,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacemen" + + "t number" + + "is 0x00", + groups = {"contract", "daily"}) public void test7ShiftRightSigned() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray - .fromHexString("0x00")) - .getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x00")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "sarTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "sarTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -580,12 +695,12 @@ public void test7ShiftRightSigned() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -596,61 +711,75 @@ public void test7ShiftRightSigned() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber14 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + Long returnnumber14 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); - } - @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " - + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" - + "is 0x01", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRightSigned,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacemen" + + "t number" + + "is 0x01", + groups = {"contract", "daily"}) public void test8ShiftRightSigned() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray - .fromHexString("0x01")) - .getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "sarTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "sarTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -660,12 +789,12 @@ public void test8ShiftRightSigned() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -676,59 +805,74 @@ public void test8ShiftRightSigned() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber14 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + Long returnnumber14 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " - + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" - + "is 0xff", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRightSigned,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacemen" + + "t number" + + "is 0xff", + groups = {"contract", "daily"}) public void test9ShiftRightSigned() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray - .fromHexString("0xff")) - .getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0xff")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - txid = PublicMethod.triggerContract(contractAddress, - "sarTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + txid = + PublicMethod.triggerContract( + contractAddress, + "sarTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -738,12 +882,12 @@ public void test9ShiftRightSigned() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -754,61 +898,75 @@ public void test9ShiftRightSigned() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber14 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + Long returnnumber14 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - - @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " - + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" - + "is 0x0100", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRightSigned,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacemen" + + "t number" + + "is 0x0100", + groups = {"contract", "daily"}) public void testShiftRightSigned10() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray - .fromHexString("0x0100")) - .getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x0100")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "sarTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "sarTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -818,12 +976,12 @@ public void testShiftRightSigned10() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -834,61 +992,75 @@ public void testShiftRightSigned10() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber14 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + Long returnnumber14 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - - @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " - + "0x0000000000000000000000000000000000000000000000000000000000000000 and Displacement number" - + "is 0x01", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRightSigned,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000000 and Displacemen" + + "t number" + + "is 0x01", + groups = {"contract", "daily"}) public void testShiftRightSigned11() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray - .fromHexString("0x01")) - .getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000000")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "sarTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "sarTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -898,12 +1070,12 @@ public void testShiftRightSigned11() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -914,61 +1086,75 @@ public void testShiftRightSigned11() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber14 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + Long returnnumber14 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - - @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " - + "0x4000000000000000000000000000000000000000000000000000000000000000 and Displacement number" - + "is 0xfe", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRightSigned,value is " + + "0x4000000000000000000000000000000000000000000000000000000000000000 and Displacemen" + + "t number" + + "is 0xfe", + groups = {"contract", "daily"}) public void testShiftRightSigned12() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x4000000000000000000000000000000000000000000000000000000000000000")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray - .fromHexString("0xfe")) - .getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x4000000000000000000000000000000000000000000000000000000000000000")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0xfe")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "sarTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "sarTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -978,12 +1164,12 @@ public void testShiftRightSigned12() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -994,60 +1180,75 @@ public void testShiftRightSigned12() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber14 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + Long returnnumber14 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000001")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " - + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" - + "is 0xf8", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRightSigned,value is " + + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacemen" + + "t number" + + "is 0xf8", + groups = {"contract", "daily"}) public void testShiftRightSigned13() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray - .fromHexString("0xf8")) - .getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0xf8")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "sarTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "sarTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -1057,12 +1258,12 @@ public void testShiftRightSigned13() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -1073,58 +1274,74 @@ public void testShiftRightSigned13() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber14 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + Long returnnumber14 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x000000000000000000000000000000000000000000000000000000000000007f")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x000000000000000000000000000000000000000000000000000000000000007f")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - - @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " - + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" - + "is 0xfe", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRightSigned,value is " + + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacemen" + + "t number" + + "is 0xfe", + groups = {"contract", "daily"}) public void testShiftRightSigned14() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0xfe")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0xfe")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - txid = PublicMethod.triggerContract(contractAddress, - "sarTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + txid = + PublicMethod.triggerContract( + contractAddress, + "sarTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -1134,12 +1351,12 @@ public void testShiftRightSigned14() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -1150,57 +1367,74 @@ public void testShiftRightSigned14() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber14 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + Long returnnumber14 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000001")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " - + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" - + "is 0xff", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRightSigned,value is " + + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacemen" + + "t number" + + "is 0xff", + groups = {"contract", "daily"}) public void testShiftRightSigned15() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0xff")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0xff")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - txid = PublicMethod.triggerContract(contractAddress, - "sarTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + txid = + PublicMethod.triggerContract( + contractAddress, + "sarTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -1210,12 +1444,12 @@ public void testShiftRightSigned15() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -1226,58 +1460,74 @@ public void testShiftRightSigned15() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber14 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + Long returnnumber14 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - - @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " - + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" - + "is 0x0100", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRightSigned,value is " + + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacemen" + + "t number" + + "is 0x0100", + groups = {"contract", "daily"}) public void testShiftRightSigned16() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x0100")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x0100")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - txid = PublicMethod.triggerContract(contractAddress, - "sarTest(uint256,uint256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + txid = + PublicMethod.triggerContract( + contractAddress, + "sarTest(uint256,uint256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -1287,12 +1537,12 @@ public void testShiftRightSigned16() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -1303,70 +1553,95 @@ public void testShiftRightSigned16() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber14 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + Long returnnumber14 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " - + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" - + "is 0x0101", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRightSigned,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacemen" + + "t number" + + "is 0x0101", + groups = {"contract", "daily"}) public void testShiftRightSigned17() { String filePath = "src/test/resources/soliditycode/TvmNewCommand043.sol"; - String contractName = "TestBitwiseShift"; + String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray - .fromHexString("0x0101")) - .getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x0101")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - - txid = PublicMethod.triggerContract(contractAddress, - "sarTest(int256,int256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + + txid = + PublicMethod.triggerContract( + contractAddress, + "sarTest(int256,int256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -1376,12 +1651,12 @@ public void testShiftRightSigned17() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -1392,67 +1667,94 @@ public void testShiftRightSigned17() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber14 = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + Long returnnumber14 = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " - + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" - + "is 0x0101", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Trigger new ShiftRightSigned,value is " + + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacemen" + + "t number" + + "is 0x0101", + groups = {"contract", "daily"}) public void testShiftRightSigned18() { String filePath = "src/test/resources/soliditycode/TvmNewCommand043.sol"; - String contractName = "TestBitwiseShift"; + String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - byte[] originNumber = new DataWord( - ByteArray - .fromHexString("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) - .getData(); - byte[] valueNumber = new DataWord( - ByteArray.fromHexString("0x0101")).getData(); - byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + String txid = ""; + byte[] originNumber = + new DataWord( + ByteArray.fromHexString( + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord(ByteArray.fromHexString("0x0101")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); - String param = Hex.toHexString(paramBytes); - txid = PublicMethod.triggerContract(contractAddress, - "sarTest(int256,int256)", param, true, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String param = Hex.toHexString(paramBytes); + txid = + PublicMethod.triggerContract( + contractAddress, + "sarTest(int256,int256)", + param, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -1462,12 +1764,12 @@ public void testShiftRightSigned18() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -1478,25 +1780,25 @@ public void testShiftRightSigned18() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - String returnString = (ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray())); + String returnString = + (ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); - Assert.assertEquals(ByteArray.toLong(ByteArray - .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), - ByteArray.toLong(ByteArray - .fromHexString( + Assert.assertEquals( + ByteArray.toLong( + ByteArray.fromHexString( + "0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong( + ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/ContractTestSendCoin001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/ContractTestSendCoin001.java index d6e6963d..61f3950c 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/ContractTestSendCoin001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/ContractTestSendCoin001.java @@ -1,8 +1,6 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.transferfailed; -import static org.hamcrest.core.StringContains.containsString; import static org.tron.api.GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR; -import static org.tron.protos.Protocol.Transaction.Result.contractResult.SUCCESS_VALUE; import com.google.protobuf.ByteString; import java.util.HashMap; @@ -16,8 +14,6 @@ import org.tron.api.GrpcAPI.Return; import org.tron.api.GrpcAPI.TransactionExtention; import org.tron.protos.Protocol.Account; -import org.tron.protos.Protocol.Transaction; -import org.tron.protos.Protocol.Transaction.Result.contractResult; import org.tron.protos.Protocol.TransactionInfo; import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import stest.tron.wallet.common.client.Configuration; @@ -26,9 +22,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; -import stest.tron.wallet.common.client.utils.ProposalEnum; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class ContractTestSendCoin001 extends TronBaseTest { @@ -38,10 +33,10 @@ public class ContractTestSendCoin001 extends TronBaseTest { private static String tokenName = "testAssetIssue_" + Long.toString(now); private static ByteString assetAccountId = null; private byte[] transferTokenContractAddress = null; - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -49,36 +44,66 @@ public class ContractTestSendCoin001 extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); } - @Test(enabled = true, description = "Sendcoin and transferAsset to contractAddresss ," - + "then selfdestruct", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Sendcoin and transferAsset to contractAddresss ," + "then selfdestruct", + groups = {"contract", "daily"}) public void testSendCoinAndTransferAssetContract001() { - Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 3100_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 3100_000_000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 130000L, blockingStubFull), 0, - 1, ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), 0, 0, - ByteString.copyFrom(dev001Address), foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount(dev001Address, dev001Key, 130000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(dev001Address), + foundationKey, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 10_000_000L + PublicMethod.randomFreezeAmount.getAndAdd(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod - .createAssetIssue(dev001Address, tokenName, TotalSupply, 1, 10000, start, end, 1, - description, url, 100000L, 100000L, 1L, 1L, dev001Key, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + dev001Address, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + dev001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -86,31 +111,46 @@ public void testSendCoinAndTransferAssetContract001() { logger.info("The token name: " + tokenName); logger.info("The token ID: " + assetAccountId.toStringUtf8()); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod - .getAccountResource(dev001Address, blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountBefore: " - + devAssetCountBefore); - String filePath = "src/test/resources/soliditycode/contractTrcToken031.sol"; - String contractName = "token"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "src/test/resources/soliditycode/contractTrcToken031.sol"; + String contractName = "token"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String tokenId = assetAccountId.toStringUtf8(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String tokenId = assetAccountId.toStringUtf8(); long tokenValue = 100; long callValue = 5; - final String deployContractTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callValue, 0, 10000, tokenId, tokenValue, null, dev001Key, dev001Address, + final String deployContractTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callValue, + 0, + 10000, + tokenId, + tokenValue, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -119,136 +159,198 @@ public void testSendCoinAndTransferAssetContract001() { energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); long balanceAfter = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("after energyLimit is " + Long.toString(energyLimit)); logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountAfter: " - + devAssetCountAfter); - - Optional infoById = PublicMethod - .getTransactionInfoById(deployContractTxid, blockingStubFull); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + + Optional infoById = + PublicMethod.getTransactionInfoById(deployContractTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (deployContractTxid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(transferTokenContractAddress, blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(transferTokenContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - Return ret = PublicMethod - .transferAssetForReturn(transferTokenContractAddress, assetAccountId.toByteArray(), 100L, - dev001Address, dev001Key, blockingStubFull); + Return ret = + PublicMethod.transferAssetForReturn( + transferTokenContractAddress, + assetAccountId.toByteArray(), + 100L, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, ret.getCode()); - Assert.assertEquals("Contract validate error : Cannot transfer asset to smartContract.", + Assert.assertEquals( + "Contract validate error : Cannot transfer asset to smartContract.", ret.getMessage().toStringUtf8()); - Long contractAssetCount = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); + Long contractAssetCount = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); Assert.assertEquals(Long.valueOf(tokenValue), contractAssetCount); - Return ret1 = PublicMethod - .sendcoinForReturn(transferTokenContractAddress, 1_000_000L, fromAddress, foundationKey, - blockingStubFull); + Return ret1 = + PublicMethod.sendcoinForReturn( + transferTokenContractAddress, 1_000_000L, fromAddress, foundationKey, blockingStubFull); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, ret1.getCode()); - Assert.assertEquals("Contract validate error : Cannot transfer TRX to a smartContract.", + Assert.assertEquals( + "Contract validate error : Cannot transfer TRX to a smartContract.", ret1.getMessage().toStringUtf8()); - String num = "\"" + Base58.encode58Check(dev001Address) + "\""; - String txid = PublicMethod - .triggerContract(transferTokenContractAddress, "kill(address)", num, false, 0, maxFeeLimit, - dev001Address, dev001Key, blockingStubFull); + String num = "\"" + Base58.encode58Check(dev001Address) + "\""; + String txid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "kill(address)", + num, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - long contractAssetCountBefore = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - long contractBefore = PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull) - .getBalance(); + long contractAssetCountBefore = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + long contractBefore = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { - Assert.assertFalse(PublicMethod - .transferAsset(transferTokenContractAddress, assetAccountId.toByteArray(), 100L, - dev001Address, dev001Key, blockingStubFull)); - Assert.assertFalse(PublicMethod - .sendcoin(transferTokenContractAddress, 1_000_000L, fromAddress, foundationKey, - blockingStubFull)); + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + Assert.assertFalse( + PublicMethod.transferAsset( + transferTokenContractAddress, + assetAccountId.toByteArray(), + 100L, + dev001Address, + dev001Key, + blockingStubFull)); + Assert.assertFalse( + PublicMethod.sendcoin( + transferTokenContractAddress, + 1_000_000L, + fromAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); - long contractAssetCountAfter = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - long contractAfetr = PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull) - .getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + long contractAssetCountAfter = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + long contractAfetr = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); Assert.assertEquals(contractAssetCountBefore, contractAssetCountAfter); Assert.assertEquals(contractBefore, contractAfetr); - }else { - Assert.assertTrue(PublicMethod - .transferAsset(transferTokenContractAddress, assetAccountId.toByteArray(), 100L, - dev001Address, dev001Key, blockingStubFull)); - Assert.assertTrue(PublicMethod - .sendcoin(transferTokenContractAddress, 1_000_000L, fromAddress, foundationKey, - blockingStubFull)); + } else { + Assert.assertTrue( + PublicMethod.transferAsset( + transferTokenContractAddress, + assetAccountId.toByteArray(), + 100L, + dev001Address, + dev001Key, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + transferTokenContractAddress, + 1_000_000L, + fromAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); - long contractAssetCountAfter = PublicMethod - .getAssetIssueValue(transferTokenContractAddress, assetAccountId, blockingStubFull); - long contractAfetr = PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull) - .getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + long contractAssetCountAfter = + PublicMethod.getAssetIssueValue( + transferTokenContractAddress, assetAccountId, blockingStubFull); + long contractAfetr = + PublicMethod.queryAccount(transferTokenContractAddress, blockingStubFull).getBalance(); Assert.assertEquals((contractAssetCountBefore + 100L), contractAssetCountAfter); Assert.assertEquals((contractBefore + 1_000_000L), contractAfetr); } } - - @Test(enabled = true, description = "Use create to generate a contract address " - + "Sendcoin and transferAsset to contractAddresss ,then selfdestruct,", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Use create to generate a contract address " + + "Sendcoin and transferAsset to contractAddresss ,then selfdestruct,", + groups = {"contract", "daily"}) public void testSendCoinAndTransferAssetContract002() { assetAccountId = PublicMethod.queryAccount(dev001Address, blockingStubFull).getAssetIssuedID(); logger.info("The token name: " + tokenName); logger.info("The token ID: " + assetAccountId.toStringUtf8()); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod - .getAccountResource(dev001Address, blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountBefore = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountBefore = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - logger.info("before AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountBefore: " - + devAssetCountBefore); - String filePath = "src/test/resources/soliditycode/contractTransferToken001.sol"; - String contractName = "A"; + logger.info( + "before AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountBefore: " + + devAssetCountBefore); + String filePath = "src/test/resources/soliditycode/contractTransferToken001.sol"; + String contractName = "A"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String tokenId = assetAccountId.toStringUtf8(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String tokenId = assetAccountId.toStringUtf8(); long tokenValue = 100; long callValue = 5; - final String deployContractTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callValue, 0, 10000, tokenId, tokenValue, null, dev001Key, dev001Address, + final String deployContractTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callValue, + 0, + 10000, + tokenId, + tokenValue, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(deployContractTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(deployContractTxid, blockingStubFull); transferTokenContractAddress = infoById.get().getContractAddress().toByteArray(); @@ -256,25 +358,36 @@ public void testSendCoinAndTransferAssetContract002() { energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); long balanceAfter = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); - Long devAssetCountAfter = PublicMethod - .getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); + Long devAssetCountAfter = + PublicMethod.getAssetIssueValue(dev001Address, assetAccountId, blockingStubFull); logger.info("after energyLimit is " + Long.toString(energyLimit)); logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - logger.info("after AssetId: " + assetAccountId.toStringUtf8() + ", devAssetCountAfter: " - + devAssetCountAfter); - String txid = PublicMethod - .triggerContract(transferTokenContractAddress, "newB()", "#", false, 0, maxFeeLimit, - dev001Address, dev001Key, blockingStubFull); + logger.info( + "after AssetId: " + + assetAccountId.toStringUtf8() + + ", devAssetCountAfter: " + + devAssetCountAfter); + String txid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "newB()", + "#", + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - byte[] a = infoById.get().getContractResult(0).toByteArray(); - byte[] b = subByte(a, 11, 1); - byte[] c = subByte(a, 0, 11); - byte[] e = "41".getBytes(); - byte[] d = subByte(a, 12, 20); + byte[] a = infoById.get().getContractResult(0).toByteArray(); + byte[] b = subByte(a, 11, 1); + byte[] c = subByte(a, 0, 11); + byte[] e = "41".getBytes(); + byte[] d = subByte(a, 12, 20); logger.info("a:" + ByteArray.toHexString(a)); @@ -284,132 +397,186 @@ public void testSendCoinAndTransferAssetContract002() { logger.info("d:" + ByteArray.toHexString(d)); logger.info("41" + ByteArray.toHexString(d)); - String exceptedResult = "41" + ByteArray.toHexString(d); - String realResult = ByteArray.toHexString(b); + String exceptedResult = "41" + ByteArray.toHexString(d); + String realResult = ByteArray.toHexString(b); Assert.assertEquals(realResult, "00"); Assert.assertNotEquals(realResult, "41"); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(exceptedResult)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(exceptedResult)); logger.info("create Address : " + addressFinal); - byte[] testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); - - Return ret = PublicMethod - .transferAssetForReturn(testContractAddress, assetAccountId.toByteArray(), 100L, - dev001Address, dev001Key, blockingStubFull); + byte[] testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + Return ret = + PublicMethod.transferAssetForReturn( + testContractAddress, + assetAccountId.toByteArray(), + 100L, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, ret.getCode()); - Assert.assertEquals("Contract validate error : Cannot transfer asset to smartContract.", + Assert.assertEquals( + "Contract validate error : Cannot transfer asset to smartContract.", ret.getMessage().toStringUtf8()); - Long contractAssetCount = PublicMethod - .getAssetIssueValue(testContractAddress, assetAccountId, blockingStubFull); - logger.info("Contract has AssetId: " + assetAccountId.toStringUtf8() + ", Count: " - + contractAssetCount); + Long contractAssetCount = + PublicMethod.getAssetIssueValue(testContractAddress, assetAccountId, blockingStubFull); + logger.info( + "Contract has AssetId: " + + assetAccountId.toStringUtf8() + + ", Count: " + + contractAssetCount); Assert.assertEquals(Long.valueOf(0L), contractAssetCount); - Return ret1 = PublicMethod - .sendcoinForReturn(testContractAddress, 1_000_000L, fromAddress, foundationKey, - blockingStubFull); + Return ret1 = + PublicMethod.sendcoinForReturn( + testContractAddress, 1_000_000L, fromAddress, foundationKey, blockingStubFull); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, ret1.getCode()); - Assert.assertEquals("Contract validate error : Cannot transfer TRX to a smartContract.", + Assert.assertEquals( + "Contract validate error : Cannot transfer TRX to a smartContract.", ret1.getMessage().toStringUtf8()); - String num = "\"" + Base58.encode58Check(dev001Address) + "\""; - - txid = PublicMethod - .triggerContract(testContractAddress, "kill(address)", num, false, 0, maxFeeLimit, - dev001Address, dev001Key, blockingStubFull); + String num = "\"" + Base58.encode58Check(dev001Address) + "\""; + + txid = + PublicMethod.triggerContract( + testContractAddress, + "kill(address)", + num, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull); - long contractAssetCountBefore = PublicMethod - .getAssetIssueValue(testContractAddress, assetAccountId, blockingStubFull); - long contractBefore = PublicMethod.queryAccount(testContractAddress, blockingStubFull) - .getBalance(); + long contractAssetCountBefore = + PublicMethod.getAssetIssueValue(testContractAddress, assetAccountId, blockingStubFull); + long contractBefore = + PublicMethod.queryAccount(testContractAddress, blockingStubFull).getBalance(); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { - Assert.assertFalse(PublicMethod - .transferAsset(testContractAddress, assetAccountId.toByteArray(), 100L, dev001Address, - dev001Key, blockingStubFull)); - Assert.assertFalse(PublicMethod - .sendcoin(testContractAddress, 1_000_000L, fromAddress, foundationKey, blockingStubFull)); + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + Assert.assertFalse( + PublicMethod.transferAsset( + testContractAddress, + assetAccountId.toByteArray(), + 100L, + dev001Address, + dev001Key, + blockingStubFull)); + Assert.assertFalse( + PublicMethod.sendcoin( + testContractAddress, 1_000_000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); - long contractAssetCountAfter = PublicMethod - .getAssetIssueValue(testContractAddress, assetAccountId, blockingStubFull); - long contractAfetr = PublicMethod.queryAccount(testContractAddress, blockingStubFull) - .getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + long contractAssetCountAfter = + PublicMethod.getAssetIssueValue(testContractAddress, assetAccountId, blockingStubFull); + long contractAfetr = + PublicMethod.queryAccount(testContractAddress, blockingStubFull).getBalance(); Assert.assertEquals(contractAssetCountBefore, contractAssetCountAfter); Assert.assertEquals(contractBefore, contractAfetr); - }else { - Assert.assertTrue(PublicMethod - .transferAsset(testContractAddress, assetAccountId.toByteArray(), 100L, dev001Address, - dev001Key, blockingStubFull)); - Assert.assertTrue(PublicMethod - .sendcoin(testContractAddress, 1_000_000L, fromAddress, foundationKey, blockingStubFull)); + } else { + Assert.assertTrue( + PublicMethod.transferAsset( + testContractAddress, + assetAccountId.toByteArray(), + 100L, + dev001Address, + dev001Key, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testContractAddress, 1_000_000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); - long contractAssetCountAfter = PublicMethod - .getAssetIssueValue(testContractAddress, assetAccountId, blockingStubFull); - long contractAfetr = PublicMethod.queryAccount(testContractAddress, blockingStubFull) - .getBalance(); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + long contractAssetCountAfter = + PublicMethod.getAssetIssueValue(testContractAddress, assetAccountId, blockingStubFull); + long contractAfetr = + PublicMethod.queryAccount(testContractAddress, blockingStubFull).getBalance(); Assert.assertEquals(contractAssetCountBefore + 100L, contractAssetCountAfter); - Assert.assertEquals(contractBefore + 1_000_000L, contractAfetr); + Assert.assertEquals(contractBefore + 1_000_000L, contractAfetr); } } - - @Test(enabled = true, description = "Use create2 to generate a contract address " - + "Sendcoin and transferAsset to contractAddresss ,then selfdestruct", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "Use create2 to generate a contract address " + + "Sendcoin and transferAsset to contractAddresss ,then selfdestruct", + groups = {"contract", "daily"}) public void testSendCoinAndTransferAssetContract003() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] contractExcAddress = ecKey1.getAddress(); - String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 2000000000L, fromAddress, foundationKey, blockingStubFull)); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, 2000000000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/create2contractn2.sol"; - String contractName = "Factory"; + String filePath = "src/test/resources/soliditycode/create2contractn2.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String contractName1 = "TestConstract"; + String contractName1 = "TestConstract"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - String txid = ""; - String num = "\"" + code1 + "\"" + "," + 1; - txid = PublicMethod - .triggerContract(contractAddress, "deploy(bytes,uint256)", num, false, 0, maxFeeLimit, "0", - 0, contractExcAddress, contractExcKey, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + "," + 1; + txid = + PublicMethod.triggerContract( + contractAddress, + "deploy(bytes,uint256)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -419,12 +586,12 @@ public void testSendCoinAndTransferAssetContract003() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -435,37 +602,59 @@ public void testSendCoinAndTransferAssetContract003() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() - .toByteArray(); - String returnAddress = Base58.encode58Check(returnAddressBytes); + byte[] returnAddressBytes = + infoById.get().getInternalTransactions(0).getTransferToAddress().toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); - Return ret = PublicMethod - .transferAssetForReturn(returnAddressBytes, assetAccountId.toByteArray(), 100L, - dev001Address, dev001Key, blockingStubFull); + Return ret = + PublicMethod.transferAssetForReturn( + returnAddressBytes, + assetAccountId.toByteArray(), + 100L, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, ret.getCode()); - Assert.assertEquals("Contract validate error : Cannot transfer asset to smartContract.", + Assert.assertEquals( + "Contract validate error : Cannot transfer asset to smartContract.", ret.getMessage().toStringUtf8()); - Return ret1 = PublicMethod - .transferAssetForReturn(returnAddressBytes, assetAccountId.toByteArray(), 100L, - dev001Address, dev001Key, blockingStubFull); + Return ret1 = + PublicMethod.transferAssetForReturn( + returnAddressBytes, + assetAccountId.toByteArray(), + 100L, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, ret1.getCode()); - Assert.assertEquals("Contract validate error : Cannot transfer asset to smartContract.", + Assert.assertEquals( + "Contract validate error : Cannot transfer asset to smartContract.", ret1.getMessage().toStringUtf8()); - txid = PublicMethod - .triggerContract(returnAddressBytes, "i()", "#", false, 0, maxFeeLimit, "0", 0, - contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + returnAddressBytes, + "i()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee1 = infoById1.get().getFee(); - Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); - Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); - Long netFee1 = infoById1.get().getReceipt().getNetFee(); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); logger.info("fee1:" + fee1); @@ -475,12 +664,12 @@ public void testSendCoinAndTransferAssetContract003() { logger.info("energyUsageTotal1:" + energyUsageTotal1); Account infoafter1 = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter1 = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); - Long afterBalance1 = infoafter1.getBalance(); - Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); - Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); - Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter1 = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance1); logger.info("afterEnergyUsed:" + afterEnergyUsed1); logger.info("afterNetUsed:" + afterNetUsed1); @@ -489,144 +678,270 @@ public void testSendCoinAndTransferAssetContract003() { Assert.assertTrue(infoById1.get().getResultValue() == 0); Assert.assertTrue(afterBalance1 + fee1 == afterBalance); Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); - txid = PublicMethod - .triggerContract(returnAddressBytes, "set()", "#", false, 0, maxFeeLimit, "0", 0, - contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + returnAddressBytes, + "set()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - txid = PublicMethod - .triggerContract(returnAddressBytes, "i()", "#", false, 0, maxFeeLimit, "0", 0, - contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + returnAddressBytes, + "i()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById1 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(5 == returnnumber); - String param1 = "\"" + Base58.encode58Check(returnAddressBytes) + "\""; - - //if the receiver is the contract, it will do nothing, contract is still alive - txid = PublicMethod - .triggerContract(returnAddressBytes, "testSuicideNonexistentTarget(address)", param1, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String param1 = "\"" + Base58.encode58Check(returnAddressBytes) + "\""; + + // if the receiver is the contract, it will do nothing, contract is still alive + txid = + PublicMethod.triggerContract( + returnAddressBytes, + "testSuicideNonexistentTarget(address)", + param1, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById2 = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById2 = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals("suicide", + Assert.assertEquals( + "suicide", ByteArray.toStr(infoById2.get().getInternalTransactions(0).getNote().toByteArray())); - TransactionExtention transactionExtention = PublicMethod - .triggerContractForExtention(returnAddressBytes, "i()", "#", false, 0, maxFeeLimit, "0", 0, - contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerContractForExtention( + returnAddressBytes, + "i()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { Assert.assertEquals("SUCCESS", transactionExtention.getResult().getCode().toString()); - Assert.assertFalse(PublicMethod - .transferAsset(returnAddressBytes, assetAccountId.toByteArray(), 100L, dev001Address, - dev001Key, blockingStubFull)); - Assert.assertFalse(PublicMethod - .sendcoin(returnAddressBytes, 1_000_000L, fromAddress, foundationKey, blockingStubFull)); - txid = PublicMethod - .triggerContract(contractAddress, "deploy(bytes,uint256)", num, false, 0, maxFeeLimit, "0", - 0, contractExcAddress, contractExcKey, blockingStubFull); + Assert.assertFalse( + PublicMethod.transferAsset( + returnAddressBytes, + assetAccountId.toByteArray(), + 100L, + dev001Address, + dev001Key, + blockingStubFull)); + Assert.assertFalse( + PublicMethod.sendcoin( + returnAddressBytes, 1_000_000L, fromAddress, foundationKey, blockingStubFull)); + txid = + PublicMethod.triggerContract( + contractAddress, + "deploy(bytes,uint256)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById3 = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById3 = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(TransactionInfo.code.FAILED, infoById3.get().getResult()); - txid = PublicMethod - .triggerContract(returnAddressBytes, "i()", "#", false, 0, maxFeeLimit, "0", 0, - contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + returnAddressBytes, + "i()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById1 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(5 == returnnumber); - ret = PublicMethod - .transferAssetForReturn(returnAddressBytes, assetAccountId.toByteArray(), 100L, - dev001Address, dev001Key, blockingStubFull); + ret = + PublicMethod.transferAssetForReturn( + returnAddressBytes, + assetAccountId.toByteArray(), + 100L, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, ret.getCode()); - Assert.assertEquals("Contract validate error : Cannot transfer asset to smartContract.", - ret.getMessage().toStringUtf8()); - - ret1 = PublicMethod - .transferAssetForReturn(returnAddressBytes, assetAccountId.toByteArray(), 100L, - dev001Address, dev001Key, blockingStubFull); + Assert.assertEquals( + "Contract validate error : Cannot transfer asset to smartContract.", + ret.getMessage().toStringUtf8()); + + ret1 = + PublicMethod.transferAssetForReturn( + returnAddressBytes, + assetAccountId.toByteArray(), + 100L, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, ret1.getCode()); - Assert.assertEquals("Contract validate error : Cannot transfer asset to smartContract.", - ret1.getMessage().toStringUtf8()); - }else { - Assert.assertTrue(transactionExtention.getResult().getCode().toString().contains("CONTRACT_VALIDATE_ERROR")); - Assert.assertTrue(transactionExtention.getResult().getMessage().toStringUtf8() + Assert.assertEquals( + "Contract validate error : Cannot transfer asset to smartContract.", + ret1.getMessage().toStringUtf8()); + } else { + Assert.assertTrue( + transactionExtention + .getResult() + .getCode() + .toString() + .contains("CONTRACT_VALIDATE_ERROR")); + Assert.assertTrue( + transactionExtention + .getResult() + .getMessage() + .toStringUtf8() .contains("Contract validate error : No contract or not a valid smart contract")); - Assert.assertTrue(PublicMethod - .transferAsset(returnAddressBytes, assetAccountId.toByteArray(), 100L, dev001Address, - dev001Key, blockingStubFull)); - Assert.assertTrue(PublicMethod - .sendcoin(returnAddressBytes, 1_000_000L, fromAddress, foundationKey, blockingStubFull)); - txid = PublicMethod - .triggerContract(contractAddress, "deploy(bytes,uint256)", num, false, 0, maxFeeLimit, "0", - 0, contractExcAddress, contractExcKey, blockingStubFull); + Assert.assertTrue( + PublicMethod.transferAsset( + returnAddressBytes, + assetAccountId.toByteArray(), + 100L, + dev001Address, + dev001Key, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + returnAddressBytes, 1_000_000L, fromAddress, foundationKey, blockingStubFull)); + txid = + PublicMethod.triggerContract( + contractAddress, + "deploy(bytes,uint256)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById3 = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - byte[] returnAddressBytes1 = infoById3.get().getInternalTransactions(0).getTransferToAddress() - .toByteArray(); + Optional infoById3 = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + byte[] returnAddressBytes1 = + infoById3.get().getInternalTransactions(0).getTransferToAddress().toByteArray(); String returnAddress1 = Base58.encode58Check(returnAddressBytes1); Assert.assertEquals(returnAddress1, returnAddress); - txid = PublicMethod - .triggerContract(returnAddressBytes1, "i()", "#", false, 0, maxFeeLimit, "0", 0, - contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + returnAddressBytes1, + "i()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById1 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); - ret = PublicMethod - .transferAssetForReturn(returnAddressBytes1, assetAccountId.toByteArray(), 100L, - dev001Address, dev001Key, blockingStubFull); + ret = + PublicMethod.transferAssetForReturn( + returnAddressBytes1, + assetAccountId.toByteArray(), + 100L, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, ret.getCode()); - Assert.assertEquals("Contract validate error : Cannot transfer asset to smartContract.", - ret.getMessage().toStringUtf8()); - - ret1 = PublicMethod - .transferAssetForReturn(returnAddressBytes1, assetAccountId.toByteArray(), 100L, - dev001Address, dev001Key, blockingStubFull); + Assert.assertEquals( + "Contract validate error : Cannot transfer asset to smartContract.", + ret.getMessage().toStringUtf8()); + + ret1 = + PublicMethod.transferAssetForReturn( + returnAddressBytes1, + assetAccountId.toByteArray(), + 100L, + dev001Address, + dev001Key, + blockingStubFull); Assert.assertEquals(CONTRACT_VALIDATE_ERROR, ret1.getCode()); - Assert.assertEquals("Contract validate error : Cannot transfer asset to smartContract.", - ret1.getMessage().toStringUtf8()); + Assert.assertEquals( + "Contract validate error : Cannot transfer asset to smartContract.", + ret1.getMessage().toStringUtf8()); } - - - } - public byte[] subByte(byte[] b, int off, int length) { byte[] b1 = new byte[length]; System.arraycopy(b, off, b1, 0, length); return b1; - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); } + PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TestResourceReceiver.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TestResourceReceiver.java index aeac0386..dde917fb 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TestResourceReceiver.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TestResourceReceiver.java @@ -19,17 +19,17 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TestResourceReceiver extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,83 +37,107 @@ public class TestResourceReceiver extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = false) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } - + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "Suicide existent Target", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Suicide existent Target", + groups = {"contract", "daily"}) public void test1SuicideExistentTarget() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod - .sendcoin(contractAddress, 3000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractAddress, 3000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + testNetAccountAddress, + 1000000, + 0, + 1, + ByteString.copyFrom(contractAddress), + testNetAccountKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(testNetAccountAddress, - 1000000, 0, 1, - ByteString.copyFrom(contractAddress), testNetAccountKey, blockingStubFull)); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - ECKey ecKey2 = new ECKey(Utils.getRandom()); - byte[] existentAddress = ecKey2.getAddress(); - Assert.assertTrue(PublicMethod - .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] existentAddress = ecKey2.getAddress(); + Assert.assertTrue( + PublicMethod.sendcoin( + contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = ""; - String num = "\"" + Base58.encode58Check(contractAddress) + "\""; - txid = PublicMethod.triggerContract(contractAddress, - "testSuicideNonexistentTarget(address)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "\"" + Base58.encode58Check(contractAddress) + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testSuicideNonexistentTarget(address)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -122,12 +146,12 @@ public void test1SuicideExistentTarget() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -136,29 +160,32 @@ public void test1SuicideExistentTarget() { long contractBalance = contractafter.getBalance(); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertEquals(contractBalance, 0); - txid = PublicMethod.triggerContract(contractAddress, - "testSuicideNonexistentTarget(address)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "testSuicideNonexistentTarget(address)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertNull(txid); Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - PublicMethod.unFreezeBalance(testNetAccountAddress, testNetAccountKey, 1, - contractAddress, blockingStubFull); - - + PublicMethod.unFreezeBalance( + testNetAccountAddress, testNetAccountKey, 1, contractAddress, blockingStubFull); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java index cf92bd98..c90392ce 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java @@ -24,17 +24,17 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.EnergyCost; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TransferFailed001 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -42,70 +42,89 @@ public class TransferFailed001 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = true, description = "Transfer trx insufficient balance", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Transfer trx insufficient balance", + groups = {"contract", "daily"}) public void test001TransferTrxInsufficientBalance() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 2000000L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 2000000L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - String num = "2000001"; - txid = PublicMethod.triggerContract(contractAddress, - "testTransferTrxInsufficientBalance(uint256)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "2000001"; + txid = + PublicMethod.triggerContract( + contractAddress, + "testTransferTrxInsufficientBalance(uint256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -114,12 +133,12 @@ public void test001TransferTrxInsufficientBalance() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -128,50 +147,57 @@ public void test001TransferTrxInsufficientBalance() { Assert.assertTrue(infoById.get().getResultValue() == 1); Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); Assert.assertEquals( - "REVERT opcode executed", - ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + "REVERT opcode executed", ByteArray.toStr(infoById.get().getResMessage().toByteArray())); Assert.assertTrue(afterBalance + fee == beforeBalance); Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Assert.assertNotEquals(10000000, energyUsageTotal); - - } - - @Test(enabled = true, description = "Transfer balance enough", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Transfer balance enough", + groups = {"contract", "daily"}) public void test002TransferEnough() { - //Assert.assertTrue(PublicMethod + // Assert.assertTrue(PublicMethod // .sendcoin(contractAddress, 3000000L, testNetAccountAddress, testNetAccountKey, // blockingStubFull)); - //PublicMethod.waitProduceNextBlock(blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - String num = "1"; - txid = PublicMethod.triggerContract(contractAddress, - "testTransferTrxInsufficientBalance(uint256)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "1"; + txid = + PublicMethod.triggerContract( + contractAddress, + "testTransferTrxInsufficientBalance(uint256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -180,12 +206,12 @@ public void test002TransferEnough() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -197,47 +223,55 @@ public void test002TransferEnough() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - - } - - @Test(enabled = true, description = "Transfer trx nonexistent target", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Transfer trx nonexistent target", + groups = {"contract", "daily"}) public void test003TransferTrxNonexistentTarget() { - //Assert.assertTrue(PublicMethod + // Assert.assertTrue(PublicMethod // .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, // blockingStubFull)); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - ECKey ecKey2 = new ECKey(Utils.getRandom()); - byte[] nonexistentAddress = ecKey2.getAddress(); - String txid = ""; - String num = "1" + ",\"" + Base58.encode58Check(nonexistentAddress) + "\""; - - txid = PublicMethod.triggerContract(contractAddress, - "testTransferTrxNonexistentTarget(uint256,address)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] nonexistentAddress = ecKey2.getAddress(); + String txid = ""; + String num = "1" + ",\"" + Base58.encode58Check(nonexistentAddress) + "\""; + + txid = + PublicMethod.triggerContract( + contractAddress, + "testTransferTrxNonexistentTarget(uint256,address)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -246,19 +280,19 @@ public void test003TransferTrxNonexistentTarget() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); - Account nonexistentAddressAccount = PublicMethod - .queryAccount(nonexistentAddress, blockingStubFull1); + Account nonexistentAddressAccount = + PublicMethod.queryAccount(nonexistentAddress, blockingStubFull1); Assert.assertEquals(1, nonexistentAddressAccount.getBalance()); Assert.assertEquals(0, infoById.get().getResultValue()); @@ -268,9 +302,17 @@ public void test003TransferTrxNonexistentTarget() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Assert.assertNotEquals(10000000, energyUsageTotal); - txid = PublicMethod.triggerContract(contractAddress, - "testTransferTrxNonexistentTarget(uint256,address)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "testTransferTrxNonexistentTarget(uint256,address)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -288,8 +330,7 @@ public void test003TransferTrxNonexistentTarget() { logger.info("energyUsageTotal:" + energyUsageTotal2); infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); + resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); afterBalance = infoafter.getBalance(); afterEnergyUsed = resourceInfoafter.getEnergyUsed(); afterNetUsed = resourceInfoafter.getNetUsed(); @@ -299,47 +340,54 @@ public void test003TransferTrxNonexistentTarget() { logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); - nonexistentAddressAccount = PublicMethod - .queryAccount(nonexistentAddress, blockingStubFull1); + nonexistentAddressAccount = PublicMethod.queryAccount(nonexistentAddress, blockingStubFull1); Assert.assertEquals(2, nonexistentAddressAccount.getBalance()); Assert.assertEquals(0, infoById.get().getResultValue()); - Assert.assertEquals(energyUsageTotal2 + EnergyCost.getNewAcctCall(), - energyUsageTotal); - + Assert.assertEquals(energyUsageTotal2 + EnergyCost.getNewAcctCall(), energyUsageTotal); } - - @Test(enabled = true, description = "Transfer trx to myself", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Transfer trx to myself", + groups = {"contract", "daily"}) public void test004TransferTrxSelf() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - String num = "1"; - - txid = PublicMethod.triggerContract(contractAddress, - "testTransferTrxSelf(uint256)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "1"; + + txid = + PublicMethod.triggerContract( + contractAddress, + "testTransferTrxSelf(uint256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -348,12 +396,12 @@ public void test004TransferTrxSelf() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -361,7 +409,8 @@ public void test004TransferTrxSelf() { Assert.assertTrue(infoById.get().getResultValue() == 1); Assert.assertEquals(contractResult.TRANSFER_FAILED, infoById.get().getReceipt().getResult()); - Assert.assertEquals("transfer trx failed: Cannot transfer TRX to yourself.", + Assert.assertEquals( + "transfer trx failed: Cannot transfer TRX to yourself.", ByteArray.toStr(infoById.get().getResMessage().toByteArray())); Assert.assertTrue(afterBalance + fee == beforeBalance); @@ -369,43 +418,51 @@ public void test004TransferTrxSelf() { Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Assert.assertNotEquals(10000000, energyUsageTotal); - - } - - @Test(enabled = true, description = "Transfer trx nonexistent target and insufficient balance", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Transfer trx nonexistent target and insufficient balance", + groups = {"contract", "daily"}) public void test005TransferTrxNonexistentTarget() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - ECKey ecKey2 = new ECKey(Utils.getRandom()); - byte[] nonexistentAddress = ecKey2.getAddress(); - String txid = ""; - String num = "10000000" + ",\"" + Base58.encode58Check(nonexistentAddress) + "\""; - - txid = PublicMethod.triggerContract(contractAddress, - "testTransferTrxNonexistentTarget(uint256,address)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] nonexistentAddress = ecKey2.getAddress(); + String txid = ""; + String num = "10000000" + ",\"" + Base58.encode58Check(nonexistentAddress) + "\""; + + txid = + PublicMethod.triggerContract( + contractAddress, + "testTransferTrxNonexistentTarget(uint256,address)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -414,12 +471,12 @@ public void test005TransferTrxNonexistentTarget() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -428,50 +485,57 @@ public void test005TransferTrxNonexistentTarget() { Assert.assertTrue(infoById.get().getResultValue() == 1); Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); Assert.assertEquals( - "REVERT opcode executed", - ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + "REVERT opcode executed", ByteArray.toStr(infoById.get().getResMessage().toByteArray())); Assert.assertTrue(afterBalance + fee == beforeBalance); Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Assert.assertNotEquals(10000000, energyUsageTotal); - - } - - @Test(enabled = true, description = "Transfer trx to myself and insufficient balance", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Transfer trx to myself and insufficient balance", + groups = {"contract", "daily"}) public void test006TransferTrxSelf() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - ECKey ecKey2 = new ECKey(Utils.getRandom()); - String txid = ""; - String num = "1000000000"; - - txid = PublicMethod.triggerContract(contractAddress, - "testTransferTrxSelf(uint256)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + String txid = ""; + String num = "1000000000"; + + txid = + PublicMethod.triggerContract( + contractAddress, + "testTransferTrxSelf(uint256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -480,12 +544,12 @@ public void test006TransferTrxSelf() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -494,49 +558,57 @@ public void test006TransferTrxSelf() { Assert.assertTrue(infoById.get().getResultValue() == 1); Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); Assert.assertEquals( - "REVERT opcode executed", - ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + "REVERT opcode executed", ByteArray.toStr(infoById.get().getResMessage().toByteArray())); Assert.assertTrue(afterBalance + fee == beforeBalance); Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Assert.assertNotEquals(10000000, energyUsageTotal); - - } - @Test(enabled = true, description = "PreCompiled transfertoken with value," - + " long.max < value or long.min > value", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "PreCompiled transfertoken with value," + " long.max < value or long.min > value", + groups = {"contract", "daily"}) public void test007TransferTrckenPreCompiled() { - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - String num = "1"; - - txid = PublicMethod.triggerContract(contractAddress, - "testTransferTokenCompiledLongMax1()", "#", false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "1"; + + txid = + PublicMethod.triggerContract( + contractAddress, + "testTransferTokenCompiledLongMax1()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -544,8 +616,7 @@ public void test007TransferTrckenPreCompiled() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); - resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + resourceInfo = PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); beforeBalance = info.getBalance(); beforeEnergyUsed = resourceInfo.getEnergyUsed(); @@ -560,9 +631,17 @@ public void test007TransferTrckenPreCompiled() { Assert.assertTrue(energyUsageTotal < maxFeeLimit / 10); Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); - txid = PublicMethod.triggerContract(contractAddress, - "testTransferTokenCompiledLongMin1()", "#", false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "testTransferTokenCompiledLongMin1()", + "#", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -579,8 +658,7 @@ public void test007TransferTrckenPreCompiled() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); - resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + resourceInfo = PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); beforeBalance = info.getBalance(); beforeEnergyUsed = resourceInfo.getEnergyUsed(); @@ -594,86 +672,132 @@ public void test007TransferTrckenPreCompiled() { Assert.assertEquals(FAILED, infoById.get().getResult()); Assert.assertTrue(energyUsageTotal < maxFeeLimit / 10); Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); - } - @Test(enabled = false, description = "PreCompiled tokenbalance", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "PreCompiled tokenbalance", + groups = {"contract", "daily"}) public void test008TransferTrctoken() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000_000_000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000_000_000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ByteString assetAccountId = null; - final long TotalSupply = 10000000L; + final long TotalSupply = 10000000L; long now = System.currentTimeMillis(); - String tokenName = "testAssetIssue_" + Long.toString(now); - //Create a new AssetIssue success. - Assert - .assertTrue(PublicMethod.createAssetIssue(contractExcAddress, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, - 100000L, 1L, 1L, contractExcKey, blockingStubFull)); + String tokenName = "testAssetIssue_" + Long.toString(now); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + contractExcAddress, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + contractExcKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - assetAccountId = PublicMethod.queryAccount(contractExcAddress, blockingStubFull) - .getAssetIssuedID(); - String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; + assetAccountId = + PublicMethod.queryAccount(contractExcAddress, blockingStubFull).getAssetIssuedID(); + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.transferAsset(contractAddress, - assetAccountId.toByteArray(), 100L, contractExcAddress, contractExcKey, - blockingStubFull)); - Long returnAddressBytesAccountCountBefore = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Assert.assertTrue( + PublicMethod.transferAsset( + contractAddress, + assetAccountId.toByteArray(), + 100L, + contractExcAddress, + contractExcKey, + blockingStubFull)); + Long returnAddressBytesAccountCountBefore = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("returnAddressBytesAccountCountBefore : " + returnAddressBytesAccountCountBefore); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long testNetAccountCountBefore = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountBefore = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); logger.info("contractAccountCountBefore:" + contractAccountCountBefore); - String txid = ""; - String num = - "\"" + Base58.encode58Check(contractAddress) + "\"," + "\"" + assetAccountId.toStringUtf8() + String txid = ""; + String num = + "\"" + + Base58.encode58Check(contractAddress) + + "\"," + + "\"" + + assetAccountId.toStringUtf8() + "\""; - //String num = "\""+Base58.encode58Check(contractAddress) +"\","+ "\"" + -1 + "\""; - txid = PublicMethod.triggerContract(contractAddress, - "testTransferTokenTest(address,uint256)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + // String num = "\""+Base58.encode58Check(contractAddress) +"\","+ "\"" + -1 + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testTransferTokenTest(address,uint256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -682,16 +806,16 @@ public void test008TransferTrctoken() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long testNetAccountCountAfter = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountAfter = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long testNetAccountCountAfter = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -703,81 +827,108 @@ public void test008TransferTrctoken() { Assert.assertTrue(afterBalance + fee == beforeBalance); Assert.assertTrue(energyUsageTotal < maxFeeLimit / 10); Assert.assertEquals(100, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - - } - @Test(enabled = true, description = "PreCompiled address(0x1) query tokenbalance", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "PreCompiled address(0x1) query tokenbalance", + groups = {"contract", "daily"}) public void test009TransferTrctoken() { - //address: 410000000000000000000000000000000000000001 + // address: 410000000000000000000000000000000000000001 String addressx = "T9yD14Nj9j7xAB4dbGeiX9h8unkKLxmGkn"; - byte[] addressxx = WalletClient.decodeFromBase58Check(addressx); + byte[] addressxx = WalletClient.decodeFromBase58Check(addressx); - Assert.assertTrue(PublicMethod - .sendcoin(addressxx, 1000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + addressxx, 1000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ByteString assetAccountId = null; - final long TotalSupply = 10000000L; + final long TotalSupply = 10000000L; long now = System.currentTimeMillis(); - String tokenName = "testAssetIssue_" + Long.toString(now); - //Create a new AssetIssue success. - Assert - .assertTrue(PublicMethod.createAssetIssue(contractExcAddress, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, - 100000L, 1L, 1L, contractExcKey, blockingStubFull)); + String tokenName = "testAssetIssue_" + Long.toString(now); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + contractExcAddress, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + contractExcKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - assetAccountId = PublicMethod.queryAccount(contractExcAddress, blockingStubFull) - .getAssetIssuedID(); - - Assert.assertTrue(PublicMethod.transferAsset(addressxx, - assetAccountId.toByteArray(), 100L, contractExcAddress, contractExcKey, - blockingStubFull)); + assetAccountId = + PublicMethod.queryAccount(contractExcAddress, blockingStubFull).getAssetIssuedID(); + + Assert.assertTrue( + PublicMethod.transferAsset( + addressxx, + assetAccountId.toByteArray(), + 100L, + contractExcAddress, + contractExcKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long returnAddressBytesAccountCountBefore = PublicMethod - .getAssetIssueValue(addressxx, assetAccountId, blockingStubFull); + Long returnAddressBytesAccountCountBefore = + PublicMethod.getAssetIssueValue(addressxx, assetAccountId, blockingStubFull); logger.info("returnAddressBytesAccountCountBefore : " + returnAddressBytesAccountCountBefore); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long testNetAccountCountBefore = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountBefore = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); logger.info("contractAccountCountBefore:" + contractAccountCountBefore); - String txid = ""; - //String num = "\""+Base58.encode58Check(contractAddress) + String txid = ""; + // String num = "\""+Base58.encode58Check(contractAddress) // +"\","+ "\"" + assetAccountId.toStringUtf8() + "\""; - String num = "\"" + assetAccountId.toStringUtf8() + "\""; - //String num = "\""+Base58.encode58Check(contractAddress) +"\","+ "\"" + -1 + "\""; - txid = PublicMethod.triggerContract(contractAddress, - "testTransferTokenCompiledTokenId(uint256)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String num = "\"" + assetAccountId.toStringUtf8() + "\""; + // String num = "\""+Base58.encode58Check(contractAddress) +"\","+ "\"" + -1 + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testTransferTokenCompiledTokenId(uint256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -786,16 +937,16 @@ public void test009TransferTrctoken() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long testNetAccountCountAfter = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountAfter = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long testNetAccountCountAfter = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -809,38 +960,49 @@ public void test009TransferTrctoken() { Assert.assertEquals(100, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "transferTrx to nonexistent target ,but revert", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "transferTrx to nonexistent target ,but revert", + groups = {"contract", "daily"}) public void test010TransferRevert() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - ECKey ecKey2 = new ECKey(Utils.getRandom()); - byte[] nonexistentAddress = ecKey2.getAddress(); - String txid = ""; - String num = "1" + ",\"" + Base58.encode58Check(nonexistentAddress) + "\""; - - txid = PublicMethod.triggerContract(contractAddress, - "testTransferTrxrevert(uint256,address)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] nonexistentAddress = ecKey2.getAddress(); + String txid = ""; + String num = "1" + ",\"" + Base58.encode58Check(nonexistentAddress) + "\""; + + txid = + PublicMethod.triggerContract( + contractAddress, + "testTransferTrxrevert(uint256,address)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -849,19 +1011,19 @@ public void test010TransferRevert() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); - Account nonexistentAddressAccount = PublicMethod - .queryAccount(nonexistentAddress, blockingStubFull1); + Account nonexistentAddressAccount = + PublicMethod.queryAccount(nonexistentAddress, blockingStubFull1); Assert.assertEquals(0, nonexistentAddressAccount.getBalance()); Assert.assertEquals(1, infoById.get().getResultValue()); @@ -872,15 +1034,13 @@ public void test010TransferRevert() { Assert.assertTrue(energyUsageTotal > EnergyCost.getNewAcctCall()); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed002.java index b51a8393..38b3e952 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed002.java @@ -20,17 +20,17 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.EnergyCost; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TransferFailed002 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -38,63 +38,87 @@ public class TransferFailed002 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); - blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + } - @Test(enabled = true, description = "Send balance not enough", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Send balance not enough", + groups = {"contract", "daily"}) public void test1SendNotEnough() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 3000000L, 100, null, - contractExcKey, contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 3000000L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - String num = "3000001"; - txid = PublicMethod - .triggerContract(contractAddress, "testSendTrxInsufficientBalance(uint256)", num, false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "3000001"; + txid = + PublicMethod.triggerContract( + contractAddress, + "testSendTrxInsufficientBalance(uint256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -103,12 +127,12 @@ public void test1SendNotEnough() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -121,41 +145,50 @@ public void test1SendNotEnough() { Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Assert.assertNotEquals(10000000, energyUsageTotal); - - } - @Test(enabled = true, description = "Send balance enough", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Send balance enough", + groups = {"contract", "daily"}) public void test2SendEnough() { - //Assert.assertTrue(PublicMethod + // Assert.assertTrue(PublicMethod // .sendcoin(contractAddress, 3000000L, testNetAccountAddress, testNetAccountKey, // blockingStubFull)); - //PublicMethod.waitProduceNextBlock(blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - String num = "1"; - txid = PublicMethod - .triggerContract(contractAddress, "testSendTrxInsufficientBalance(uint256)", num, false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "1"; + txid = + PublicMethod.triggerContract( + contractAddress, + "testSendTrxInsufficientBalance(uint256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -164,12 +197,12 @@ public void test2SendEnough() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -181,42 +214,51 @@ public void test2SendEnough() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - } - - @Test(enabled = true, description = "Send trx nonexistent target", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Send trx nonexistent target", + groups = {"contract", "daily"}) public void test3SendTrxNonexistentTarget() { Account info; - AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - ECKey ecKey2 = new ECKey(Utils.getRandom()); - byte[] nonexistentAddress = ecKey2.getAddress(); - String txid = ""; - String num = "1" + ",\"" + Base58.encode58Check(nonexistentAddress) + "\""; - - txid = PublicMethod - .triggerContract(contractAddress, "testSendTrxNonexistentTarget(uint256,address)", num, - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] nonexistentAddress = ecKey2.getAddress(); + String txid = ""; + String num = "1" + ",\"" + Base58.encode58Check(nonexistentAddress) + "\""; + + txid = + PublicMethod.triggerContract( + contractAddress, + "testSendTrxNonexistentTarget(uint256,address)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -225,12 +267,12 @@ public void test3SendTrxNonexistentTarget() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -244,13 +286,21 @@ public void test3SendTrxNonexistentTarget() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Assert.assertNotEquals(10000000, energyUsageTotal); - Account nonexistentAddressAccount = PublicMethod - .queryAccount(nonexistentAddress, blockingStubFull1); + Account nonexistentAddressAccount = + PublicMethod.queryAccount(nonexistentAddress, blockingStubFull1); Assert.assertEquals(1, nonexistentAddressAccount.getBalance()); - txid = PublicMethod - .triggerContract(contractAddress, "testSendTrxNonexistentTarget(uint256,address)", num, - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "testSendTrxNonexistentTarget(uint256,address)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -280,43 +330,51 @@ public void test3SendTrxNonexistentTarget() { Assert.assertEquals(0, infoById.get().getResultValue()); - Assert.assertNotEquals(energyUsageTotal2, - energyUsageTotal + EnergyCost.getNewAcctCall()); + Assert.assertNotEquals(energyUsageTotal2, energyUsageTotal + EnergyCost.getNewAcctCall()); nonexistentAddressAccount = PublicMethod.queryAccount(nonexistentAddress, blockingStubFull1); Assert.assertEquals(2, nonexistentAddressAccount.getBalance()); - } - - @Test(enabled = true, description = "Send trx self", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Send trx self", + groups = {"contract", "daily"}) public void test4SendTrxSelf() { Account info; - AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - String num = "1"; - txid = PublicMethod - .triggerContract(contractAddress, "testSendTrxSelf(uint256)", num, false, 0, maxFeeLimit, - contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "1"; + txid = + PublicMethod.triggerContract( + contractAddress, + "testSendTrxSelf(uint256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -325,12 +383,12 @@ public void test4SendTrxSelf() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -338,7 +396,8 @@ public void test4SendTrxSelf() { Assert.assertTrue(infoById.get().getResultValue() == 1); Assert.assertEquals(contractResult.TRANSFER_FAILED, infoById.get().getReceipt().getResult()); - Assert.assertEquals("transfer trx failed: Cannot transfer TRX to yourself.", + Assert.assertEquals( + "transfer trx failed: Cannot transfer TRX to yourself.", ByteArray.toStr(infoById.get().getResMessage().toByteArray())); Assert.assertTrue(afterBalance + fee == beforeBalance); @@ -347,42 +406,50 @@ public void test4SendTrxSelf() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Assert.assertNotEquals(10000000, energyUsageTotal); Assert.assertNotEquals(10000000, energyUsageTotal); - - } - - @Test(enabled = true, description = "Send trx nonexistent target and balance not enough", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Send trx nonexistent target and balance not enough", + groups = {"contract", "daily"}) public void test5SendTrxNonexistentTarget() { Account info; - AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - ECKey ecKey2 = new ECKey(Utils.getRandom()); - byte[] nonexistentAddress = ecKey2.getAddress(); - String txid = ""; - String num = "100000000" + ",\"" + Base58.encode58Check(contractExcAddress) + "\""; - - txid = PublicMethod - .triggerContract(contractAddress, "testSendTrxNonexistentTarget(uint256,address)", num, - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] nonexistentAddress = ecKey2.getAddress(); + String txid = ""; + String num = "100000000" + ",\"" + Base58.encode58Check(contractExcAddress) + "\""; + + txid = + PublicMethod.triggerContract( + contractAddress, + "testSendTrxNonexistentTarget(uint256,address)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -391,12 +458,12 @@ public void test5SendTrxNonexistentTarget() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -408,40 +475,49 @@ public void test5SendTrxNonexistentTarget() { Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Assert.assertNotEquals(10000000, energyUsageTotal); - } - - @Test(enabled = true, description = "Send trx self and balance not enough", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Send trx self and balance not enough", + groups = {"contract", "daily"}) public void test6SendTrxSelf() { Account info; - AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - ECKey ecKey2 = new ECKey(Utils.getRandom()); - String txid = ""; - String num = "1000000000"; - - txid = PublicMethod - .triggerContract(contractAddress, "testSendTrxSelf(uint256)", num, false, 0, maxFeeLimit, - contractExcAddress, contractExcKey, blockingStubFull); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + String txid = ""; + String num = "1000000000"; + + txid = + PublicMethod.triggerContract( + contractAddress, + "testSendTrxSelf(uint256)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -450,12 +526,12 @@ public void test6SendTrxSelf() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -467,42 +543,51 @@ public void test6SendTrxSelf() { Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Assert.assertNotEquals(10000000, energyUsageTotal); - - } - @Test(enabled = true, description = "Send trx nonexistent target, but revert", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Send trx nonexistent target, but revert", + groups = {"contract", "daily"}) public void test7SendTrxNonexistentTargetRevert() { Account info; - AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - ECKey ecKey2 = new ECKey(Utils.getRandom()); - byte[] nonexistentAddress = ecKey2.getAddress(); - String txid = ""; - String num = "1" + ",\"" + Base58.encode58Check(nonexistentAddress) + "\""; - - txid = PublicMethod - .triggerContract(contractAddress, "testSendTrxRevert(uint256,address)", num, false, 0, - maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] nonexistentAddress = ecKey2.getAddress(); + String txid = ""; + String num = "1" + ",\"" + Base58.encode58Check(nonexistentAddress) + "\""; + + txid = + PublicMethod.triggerContract( + contractAddress, + "testSendTrxRevert(uint256,address)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -511,19 +596,19 @@ public void test7SendTrxNonexistentTargetRevert() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); - Account nonexistentAddressAccount = PublicMethod - .queryAccount(nonexistentAddress, blockingStubFull1); + Account nonexistentAddressAccount = + PublicMethod.queryAccount(nonexistentAddress, blockingStubFull1); Assert.assertEquals(0, nonexistentAddressAccount.getBalance()); Assert.assertEquals(1, infoById.get().getResultValue()); @@ -532,19 +617,15 @@ public void test7SendTrxNonexistentTargetRevert() { Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Assert.assertTrue(energyUsageTotal > EnergyCost.getNewAcctCall()); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java index 67be0e20..bd54bbf3 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java @@ -21,10 +21,10 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.EnergyCost; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode @@ -34,106 +34,139 @@ public class TransferFailed003 extends TronBaseTest { private static final long TotalSupply = 10000000L; private static ByteString assetAccountId = null; private static String tokenName = "testAssetIssue_" + Long.toString(now); - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } - + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = true, description = "TransferToken enough tokenBalance", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken enough tokenBalance", + groups = {"contract", "daily"}) public void test1TransferTokenEnough() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000_000_000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000_000_000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert - .assertTrue(PublicMethod.createAssetIssue(contractExcAddress, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, - 100000L, 1L, 1L, contractExcKey, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + contractExcAddress, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + contractExcKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - assetAccountId = PublicMethod.queryAccount(contractExcAddress, blockingStubFull) - .getAssetIssuedID(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, 1000000000L, - assetAccountId.toStringUtf8(), 100L, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + assetAccountId = + PublicMethod.queryAccount(contractExcAddress, blockingStubFull).getAssetIssuedID(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + 1000000000L, + assetAccountId.toStringUtf8(), + 100L, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Assert.assertTrue(PublicMethod.transferAsset(contractAddress, + // Assert.assertTrue(PublicMethod.transferAsset(contractAddress, // assetAccountId.toByteArray(), 100L, contractExcAddress, contractExcKey, // blockingStubFull)); - //PublicMethod.waitProduceNextBlock(blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long testNetAccountCountBefore = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountBefore = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); logger.info("contractAccountCountBefore:" + contractAccountCountBefore); - String txid = ""; - String num = "1" + ",\"" + assetAccountId.toStringUtf8() + "\""; - txid = PublicMethod.triggerContract(contractAddress, - "testTransferTokenInsufficientBalance(uint256,trcToken)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "1" + ",\"" + assetAccountId.toStringUtf8() + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testTransferTokenInsufficientBalance(uint256,trcToken)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -142,16 +175,16 @@ public void test1TransferTokenEnough() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long testNetAccountCountAfter = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountAfter = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long testNetAccountCountAfter = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -167,44 +200,53 @@ public void test1TransferTokenEnough() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - - } - @Test(enabled = true, description = "TransferToken insufficient tokenBalance", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken insufficient tokenBalance", + groups = {"contract", "daily"}) public void test2TransferTokenNotEnough() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long testNetAccountCountBefore = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountBefore = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); logger.info("contractAccountCountBefore:" + contractAccountCountBefore); - String txid = ""; - String num = "1000" + ",\"" + assetAccountId.toStringUtf8() + "\""; - txid = PublicMethod.triggerContract(contractAddress, - "testTransferTokenInsufficientBalance(uint256,trcToken)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "1000" + ",\"" + assetAccountId.toStringUtf8() + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testTransferTokenInsufficientBalance(uint256,trcToken)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -213,16 +255,16 @@ public void test2TransferTokenNotEnough() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long testNetAccountCountAfter = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountAfter = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long testNetAccountCountAfter = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -233,8 +275,7 @@ public void test2TransferTokenNotEnough() { Assert.assertTrue(infoById.get().getResultValue() == 1); Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); Assert.assertEquals( - "REVERT opcode executed", - ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + "REVERT opcode executed", ByteArray.toStr(infoById.get().getResMessage().toByteArray())); Assert.assertTrue(afterBalance + fee == beforeBalance); Assert.assertEquals(testNetAccountCountBefore, testNetAccountCountAfter); Assert.assertEquals(contractAccountCountBefore, contractAccountCountAfter); @@ -243,49 +284,62 @@ public void test2TransferTokenNotEnough() { Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Assert.assertNotEquals(10000000, energyUsageTotal); - } - - @Test(enabled = true, description = "TransferToken to nonexistent target", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken to nonexistent target", + groups = {"contract", "daily"}) public void test3TransferTokenNonexistentTarget() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long testNetAccountCountBefore = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountBefore = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); logger.info("contractAccountCountBefore:" + contractAccountCountBefore); - String txid = ""; - ECKey ecKey2 = new ECKey(Utils.getRandom()); - byte[] nonexistentAddress = ecKey2.getAddress(); - String num = - "\"1" + "\",\"" + Base58.encode58Check(nonexistentAddress) + "\",\"" + assetAccountId - .toStringUtf8() + "\""; - txid = PublicMethod.triggerContract(contractAddress, - "testTransferTokenNonexistentTarget(uint256,address,trcToken)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] nonexistentAddress = ecKey2.getAddress(); + String num = + "\"1" + + "\",\"" + + Base58.encode58Check(nonexistentAddress) + + "\",\"" + + assetAccountId.toStringUtf8() + + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testTransferTokenNonexistentTarget(uint256,address,trcToken)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById:" + infoById); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -294,16 +348,16 @@ public void test3TransferTokenNonexistentTarget() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long testNetAccountCountAfter = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountAfter = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long testNetAccountCountAfter = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -321,13 +375,21 @@ public void test3TransferTokenNonexistentTarget() { Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Assert.assertNotEquals(10000000, energyUsageTotal); - Long nonexistentAddressAccount = PublicMethod - .getAssetIssueValue(nonexistentAddress, assetAccountId, blockingStubFull1); + Long nonexistentAddressAccount = + PublicMethod.getAssetIssueValue(nonexistentAddress, assetAccountId, blockingStubFull1); Assert.assertEquals(1L, nonexistentAddressAccount.longValue()); - txid = PublicMethod.triggerContract(contractAddress, - "testTransferTokenNonexistentTarget(uint256,address,trcToken)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "testTransferTokenNonexistentTarget(uint256,address,trcToken)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); @@ -344,16 +406,15 @@ public void test3TransferTokenNonexistentTarget() { logger.info("energyUsageTotal:" + energyUsageTotal2); infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); + resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); afterBalance = infoafter.getBalance(); afterEnergyUsed = resourceInfoafter.getEnergyUsed(); afterNetUsed = resourceInfoafter.getNetUsed(); afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - testNetAccountCountAfter = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - contractAccountCountAfter = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + testNetAccountCountAfter = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + contractAccountCountAfter = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -366,50 +427,59 @@ public void test3TransferTokenNonexistentTarget() { Assert.assertEquals(testNetAccountCountBefore, testNetAccountCountAfter); Assert.assertEquals(contractAccountCountBefore - 2, contractAccountCountAfter.longValue()); - Assert.assertEquals(energyUsageTotal, - energyUsageTotal2 + EnergyCost.getNewAcctCall()); + Assert.assertEquals(energyUsageTotal, energyUsageTotal2 + EnergyCost.getNewAcctCall()); - nonexistentAddressAccount = PublicMethod - .getAssetIssueValue(nonexistentAddress, assetAccountId, blockingStubFull1); + nonexistentAddressAccount = + PublicMethod.getAssetIssueValue(nonexistentAddress, assetAccountId, blockingStubFull1); Assert.assertEquals(2L, nonexistentAddressAccount.longValue()); } - - @Test(enabled = true, description = "TransferToken to myself", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken to myself", + groups = {"contract", "daily"}) public void test4TransferTokenSelf() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long testNetAccountCountBefore = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountBefore = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); logger.info("contractAccountCountBefore:" + contractAccountCountBefore); - String txid = ""; - String num = "1" + ",\"" + assetAccountId.toStringUtf8() + "\""; - txid = PublicMethod.triggerContract(contractAddress, - "testTransferTokenSelf(uint256,trcToken)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "1" + ",\"" + assetAccountId.toStringUtf8() + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testTransferTokenSelf(uint256,trcToken)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById:" + infoById); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -418,16 +488,16 @@ public void test4TransferTokenSelf() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long testNetAccountCountAfter = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountAfter = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long testNetAccountCountAfter = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -448,47 +518,55 @@ public void test4TransferTokenSelf() { Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Assert.assertNotEquals(10000000, energyUsageTotal); - - } - - @Test(enabled = true, description = "TransferToken notexist tokenID ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken notexist tokenID ", + groups = {"contract", "daily"}) public void test5TransferTokenNotexist() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long testNetAccountCountBefore = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountBefore = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); logger.info("contractAccountCountBefore:" + contractAccountCountBefore); - String txid = ""; - String fakeassetAccountId = Long.toString(0L); - String num = "1" + ",\"" + fakeassetAccountId + "\""; - txid = PublicMethod.triggerContract(contractAddress, - "testTransferTokenInsufficientBalance(uint256,trcToken)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String fakeassetAccountId = Long.toString(0L); + String num = "1" + ",\"" + fakeassetAccountId + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testTransferTokenInsufficientBalance(uint256,trcToken)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById:" + infoById); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -497,16 +575,16 @@ public void test5TransferTokenNotexist() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long testNetAccountCountAfter = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountAfter = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long testNetAccountCountAfter = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -517,8 +595,7 @@ public void test5TransferTokenNotexist() { Assert.assertTrue(infoById.get().getResultValue() == 1); Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); Assert.assertEquals( - "REVERT opcode executed", - ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + "REVERT opcode executed", ByteArray.toStr(infoById.get().getResMessage().toByteArray())); Assert.assertTrue(afterBalance + fee == beforeBalance); Assert.assertEquals(testNetAccountCountBefore, testNetAccountCountAfter); Assert.assertEquals(contractAccountCountBefore, contractAccountCountAfter); @@ -526,52 +603,62 @@ public void test5TransferTokenNotexist() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - - } - - @Test(enabled = true, description = "TransferToken to nonexistent target and " - + "insufficient tokenBalance", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken to nonexistent target and " + "insufficient tokenBalance", + groups = {"contract", "daily"}) public void test7TransferTokenNonexistentTarget() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long testNetAccountCountBefore = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountBefore = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); logger.info("contractAccountCountBefore:" + contractAccountCountBefore); - String txid = ""; - ECKey ecKey2 = new ECKey(Utils.getRandom()); - byte[] nonexistentAddress = ecKey2.getAddress(); - String num = - "\"100000000000" + "\",\"" + Base58.encode58Check(nonexistentAddress) + "\",\"" - + assetAccountId - .toStringUtf8() + "\""; - txid = PublicMethod.triggerContract(contractAddress, - "testTransferTokenNonexistentTarget(uint256,address,trcToken)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] nonexistentAddress = ecKey2.getAddress(); + String num = + "\"100000000000" + + "\",\"" + + Base58.encode58Check(nonexistentAddress) + + "\",\"" + + assetAccountId.toStringUtf8() + + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testTransferTokenNonexistentTarget(uint256,address,trcToken)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById:" + infoById); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -580,16 +667,16 @@ public void test7TransferTokenNonexistentTarget() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long testNetAccountCountAfter = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountAfter = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long testNetAccountCountAfter = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -600,8 +687,7 @@ public void test7TransferTokenNonexistentTarget() { Assert.assertTrue(infoById.get().getResultValue() == 1); Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); Assert.assertEquals( - "REVERT opcode executed", - ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + "REVERT opcode executed", ByteArray.toStr(infoById.get().getResMessage().toByteArray())); Assert.assertEquals(afterBalance + fee, beforeBalance.longValue()); Assert.assertEquals(testNetAccountCountBefore, testNetAccountCountAfter); Assert.assertEquals(contractAccountCountBefore, contractAccountCountAfter); @@ -610,49 +696,57 @@ public void test7TransferTokenNonexistentTarget() { Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Assert.assertNotEquals(10000000, energyUsageTotal); - Long nonexistentAddressAccount = PublicMethod - .getAssetIssueValue(nonexistentAddress, assetAccountId, blockingStubFull1); + Long nonexistentAddressAccount = + PublicMethod.getAssetIssueValue(nonexistentAddress, assetAccountId, blockingStubFull1); Assert.assertEquals(0L, nonexistentAddressAccount.longValue()); - - } - - @Test(enabled = true, description = "TransferToken to myself and insufficient tokenBalance", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken to myself and insufficient tokenBalance", + groups = {"contract", "daily"}) public void test8TransferTokenSelf() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long testNetAccountCountBefore = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountBefore = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); logger.info("contractAccountCountBefore:" + contractAccountCountBefore); - String txid = ""; - String num = "1000000000000000" + ",\"" + assetAccountId.toStringUtf8() + "\""; - txid = PublicMethod.triggerContract(contractAddress, - "testTransferTokenSelf(uint256,trcToken)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "1000000000000000" + ",\"" + assetAccountId.toStringUtf8() + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testTransferTokenSelf(uint256,trcToken)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById:" + infoById); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -661,16 +755,16 @@ public void test8TransferTokenSelf() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long testNetAccountCountAfter = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountAfter = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long testNetAccountCountAfter = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -681,8 +775,7 @@ public void test8TransferTokenSelf() { Assert.assertTrue(infoById.get().getResultValue() == 1); Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); Assert.assertEquals( - "REVERT opcode executed", - ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + "REVERT opcode executed", ByteArray.toStr(infoById.get().getResMessage().toByteArray())); Assert.assertTrue(afterBalance + fee == beforeBalance); Assert.assertEquals(testNetAccountCountBefore, testNetAccountCountAfter); Assert.assertEquals(contractAccountCountBefore, contractAccountCountAfter); @@ -692,47 +785,61 @@ public void test8TransferTokenSelf() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Assert.assertNotEquals(10000000, energyUsageTotal); - } - @Test(enabled = true, description = "TransferToken to nonexistent target, but revert", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken to nonexistent target, but revert", + groups = {"contract", "daily"}) public void test9TransferTokenNonexistentTargetRevert() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long testNetAccountCountBefore = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountBefore = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); logger.info("contractAccountCountBefore:" + contractAccountCountBefore); - String txid = ""; - ECKey ecKey2 = new ECKey(Utils.getRandom()); - byte[] nonexistentAddress = ecKey2.getAddress(); - String num = - "\"1" + "\",\"" + Base58.encode58Check(nonexistentAddress) + "\",\"" + assetAccountId - .toStringUtf8() + "\""; - txid = PublicMethod.triggerContract(contractAddress, - "testTransferTokenRevert(uint256,address,trcToken)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] nonexistentAddress = ecKey2.getAddress(); + String num = + "\"1" + + "\",\"" + + Base58.encode58Check(nonexistentAddress) + + "\",\"" + + assetAccountId.toStringUtf8() + + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testTransferTokenRevert(uint256,address,trcToken)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById:" + infoById); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -741,16 +848,16 @@ public void test9TransferTokenNonexistentTargetRevert() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long testNetAccountCountAfter = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountAfter = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long testNetAccountCountAfter = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -768,20 +875,18 @@ public void test9TransferTokenNonexistentTargetRevert() { Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Assert.assertTrue(energyUsageTotal > EnergyCost.getNewAcctCall()); - Long nonexistentAddressAccount = PublicMethod - .getAssetIssueValue(nonexistentAddress, assetAccountId, blockingStubFull1); + Long nonexistentAddressAccount = + PublicMethod.getAssetIssueValue(nonexistentAddress, assetAccountId, blockingStubFull1); Assert.assertEquals(0L, nonexistentAddressAccount.longValue()); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed004.java index 48aed93e..081e12c3 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed004.java @@ -20,18 +20,17 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; -import stest.tron.wallet.common.client.utils.ProposalEnum; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TransferFailed004 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; byte[] contractAddress2 = null; @@ -41,10 +40,9 @@ public class TransferFailed004 extends TronBaseTest { private static ByteString assetAccountId = null; private static ByteString assetAccountId2 = null; private static String tokenName = "testAssetIssue_" + Long.toString(now); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -57,99 +55,138 @@ public class TransferFailed004 extends TronBaseTest { long energyUsageTotal2 = 0; private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert - .assertTrue(PublicMethod.createAssetIssue(contractExcAddress, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, - 100000L, 1L, 1L, contractExcKey, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + contractExcAddress, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + contractExcKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - assetAccountId = PublicMethod.queryAccount(contractExcAddress, blockingStubFull) - .getAssetIssuedID(); - + assetAccountId = + PublicMethod.queryAccount(contractExcAddress, blockingStubFull).getAssetIssuedID(); } - @Test(enabled = true, description = "Suicide nonexistent target", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Suicide nonexistent target", + groups = {"contract", "daily"}) public void test1SuicideNonexistentTarget() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContractFallbackReceive(contractName, abi, code, "", - maxFeeLimit, 1000000L, 100,1000L, assetAccountId.toStringUtf8(), 1000L, - null, contractExcKey, contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContractFallbackReceive( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + 1000L, + assetAccountId.toStringUtf8(), + 1000L, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long testNetAccountCountBefore = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountBefore = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); logger.info("contractAccountCountBefore:" + contractAccountCountBefore); - String txid = ""; - String num = "\"" + Base58.encode58Check(nonexistentAddress) + "\""; - - txid = PublicMethod.triggerContract(contractAddress, - "testSuicideNonexistentTarget(address)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "\"" + Base58.encode58Check(nonexistentAddress) + "\""; + + txid = + PublicMethod.triggerContract( + contractAddress, + "testSuicideNonexistentTarget(address)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - final Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - final Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + final Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + final Long netFee = infoById.get().getReceipt().getNetFee(); energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); - Long testNetAccountCountAfter = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountAfter = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long testNetAccountCountAfter = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("energyUsed:" + energyUsed); @@ -159,12 +196,12 @@ public void test1SuicideNonexistentTarget() { logger.info("contractAccountCountAfter:" + contractAccountCountAfter); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -179,47 +216,69 @@ public void test1SuicideNonexistentTarget() { Assert.assertEquals(testNetAccountCountBefore, testNetAccountCountAfter); Assert.assertEquals(0L, contractAccountCountAfter.longValue()); Assert.assertNotEquals(10000000, energyUsageTotal); - String assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetIssuedID().toStringUtf8(); + String assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); Assert.assertEquals(0, assetIssueId.length()); - Account nonexistentAddressAccountTrxBalance = PublicMethod - .queryAccount(nonexistentAddress, blockingStubFull1); + Account nonexistentAddressAccountTrxBalance = + PublicMethod.queryAccount(nonexistentAddress, blockingStubFull1); Assert.assertEquals(1000000L, nonexistentAddressAccountTrxBalance.getBalance()); - Long nonexistentAddressAccountTokenBalance = PublicMethod - .getAssetIssueValue(nonexistentAddress, assetAccountId, blockingStubFull1); + Long nonexistentAddressAccountTokenBalance = + PublicMethod.getAssetIssueValue(nonexistentAddress, assetAccountId, blockingStubFull1); Assert.assertEquals(1000L, nonexistentAddressAccountTokenBalance.longValue()); } - @Test(enabled = true, description = "Suicide existent target", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Suicide existent target", + groups = {"contract", "daily"}) public void test2SuicideExistentTarget() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); - String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress2 = PublicMethod.deployContractFallbackReceive(contractName, abi, code, "", - maxFeeLimit, 1000000L, 100,1000L, assetAccountId.toStringUtf8(), - 1000L,null, contractExcKey, contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress2 = + PublicMethod.deployContractFallbackReceive( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + 1000L, + assetAccountId.toStringUtf8(), + 1000L, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long testNetAccountCountBefore = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountBefore = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); @@ -227,27 +286,39 @@ public void test2SuicideExistentTarget() { logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); logger.info("contractAccountCountBefore:" + contractAccountCountBefore); - Assert.assertTrue(PublicMethod - .sendcoin(nonexistentAddress, 1000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + nonexistentAddress, + 1000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = ""; - String num = "\"" + Base58.encode58Check(nonexistentAddress) + "\""; - txid = PublicMethod.triggerContract(contractAddress2, - "testSuicideNonexistentTarget(address)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "\"" + Base58.encode58Check(nonexistentAddress) + "\""; + txid = + PublicMethod.triggerContract( + contractAddress2, + "testSuicideNonexistentTarget(address)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - final Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - final Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + final Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + final Long netFee = infoById.get().getReceipt().getNetFee(); energyUsageTotal2 = infoById.get().getReceipt().getEnergyUsageTotal(); - Long testNetAccountCountAfter = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountAfter = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long testNetAccountCountAfter = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("energyUsed:" + energyUsed); @@ -257,12 +328,12 @@ public void test2SuicideExistentTarget() { logger.info("contractAccountCountAfter:" + contractAccountCountAfter); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -279,63 +350,87 @@ public void test2SuicideExistentTarget() { Assert.assertEquals(0L, contractAccountCountAfter.longValue()); Assert.assertEquals(energyUsageTotal, energyUsageTotal2 + 25000); - Account nonexistentAddressAccountTrxBalance = PublicMethod - .queryAccount(nonexistentAddress, blockingStubFull1); + Account nonexistentAddressAccountTrxBalance = + PublicMethod.queryAccount(nonexistentAddress, blockingStubFull1); Assert.assertEquals(3000000L, nonexistentAddressAccountTrxBalance.getBalance()); - Long nonexistentAddressAccountTokenBalance = PublicMethod - .getAssetIssueValue(nonexistentAddress, assetAccountId, blockingStubFull1); + Long nonexistentAddressAccountTokenBalance = + PublicMethod.getAssetIssueValue(nonexistentAddress, assetAccountId, blockingStubFull1); Assert.assertEquals(2000L, nonexistentAddressAccountTokenBalance.longValue()); - } - @Test(enabled = true, description = "Suicide nonexistent target, but revert", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Suicide nonexistent target, but revert", + groups = {"contract", "daily"}) public void test3SuicideNonexistentTargetRevert() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); - String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress3 = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000000L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress3 = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Assert.assertTrue(PublicMethod - //.sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, + // Assert.assertTrue(PublicMethod + // .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, // blockingStubFull)); - //PublicMethod.waitProduceNextBlock(blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - ECKey ecKey2 = new ECKey(Utils.getRandom()); - byte[] nonexistentAddress1 = ecKey2.getAddress(); - String txid = ""; - String num = "\"" + Base58.encode58Check(nonexistentAddress1) + "\""; - - txid = PublicMethod.triggerContract(contractAddress3, - "testSuicideRevert(address)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] nonexistentAddress1 = ecKey2.getAddress(); + String txid = ""; + String num = "\"" + Base58.encode58Check(nonexistentAddress1) + "\""; + + txid = + PublicMethod.triggerContract( + contractAddress3, + "testSuicideRevert(address)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - final Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - final Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + final Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + final Long netFee = infoById.get().getReceipt().getNetFee(); energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -344,12 +439,12 @@ public void test3SuicideNonexistentTargetRevert() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -363,51 +458,78 @@ public void test3SuicideNonexistentTargetRevert() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Assert.assertTrue(energyUsageTotal < 1000000000L); - Account nonexistentAddressAccount = PublicMethod - .queryAccount(nonexistentAddress1, blockingStubFull1); + Account nonexistentAddressAccount = + PublicMethod.queryAccount(nonexistentAddress1, blockingStubFull1); Assert.assertEquals(1000000L, nonexistentAddressAccount.getBalance()); } - @Test(enabled = true, description = "transfer to a suicide contract address same token", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "transfer to a suicide contract address same token", + groups = {"contract", "daily"}) public void test4transferToSuicideContractSameToken() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); - String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final byte[] contractAddress4 = PublicMethod.deployContract(contractName, abi, code, "", - maxFeeLimit, 1000000L, 100, 1000000000L, - assetAccountId.toStringUtf8(), 1000L,null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final byte[] contractAddress4 = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + 1000000000L, + assetAccountId.toStringUtf8(), + 1000L, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); Account info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - String num = "1" + ",\"" + Base58.encode58Check(contractAddress) + "\""; - - txid = PublicMethod.triggerContract(contractAddress4, - "testTransferTrxNonexistentTarget(uint256,address)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "1" + ",\"" + Base58.encode58Check(contractAddress) + "\""; + + txid = + PublicMethod.triggerContract( + contractAddress4, + "testTransferTrxNonexistentTarget(uint256,address)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -416,37 +538,49 @@ public void test4transferToSuicideContractSameToken() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); logger.info("infoById:" + infoById); - if(PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { + if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); - Account nonexistentAddressAccount = PublicMethod - .queryAccount(contractAddress, blockingStubFull1); + Account nonexistentAddressAccount = + PublicMethod.queryAccount(contractAddress, blockingStubFull1); Assert.assertEquals(0L, nonexistentAddressAccount.getBalance()); num = - "\"1" + "\",\"" + Base58.encode58Check(contractAddress) + "\",\"" + assetAccountId - .toStringUtf8() + "\""; - txid = PublicMethod.triggerContract(contractAddress4, - "testTransferTokenNonexistentTarget(uint256,address,trcToken)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + "\"1" + + "\",\"" + + Base58.encode58Check(contractAddress) + + "\",\"" + + assetAccountId.toStringUtf8() + + "\""; + txid = + PublicMethod.triggerContract( + contractAddress4, + "testTransferTokenNonexistentTarget(uint256,address,trcToken)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); - Long contractAccountCountAfter = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); Assert.assertEquals(0L, contractAccountCountAfter.longValue()); - }else { + } else { Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals(contractResult.SUCCESS, infoById.get().getReceipt().getResult()); @@ -456,139 +590,213 @@ public void test4transferToSuicideContractSameToken() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Assert.assertNotEquals(10000000, energyUsageTotal); - Account nonexistentAddressAccount = PublicMethod - .queryAccount(contractAddress, blockingStubFull1); + Account nonexistentAddressAccount = + PublicMethod.queryAccount(contractAddress, blockingStubFull1); Assert.assertEquals(1L, nonexistentAddressAccount.getBalance()); num = - "\"1" + "\",\"" + Base58.encode58Check(contractAddress) + "\",\"" + assetAccountId - .toStringUtf8() + "\""; - txid = PublicMethod.triggerContract(contractAddress4, - "testTransferTokenNonexistentTarget(uint256,address,trcToken)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + "\"1" + + "\",\"" + + Base58.encode58Check(contractAddress) + + "\",\"" + + assetAccountId.toStringUtf8() + + "\""; + txid = + PublicMethod.triggerContract( + contractAddress4, + "testTransferTokenNonexistentTarget(uint256,address,trcToken)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); - Long contractAccountCountAfter = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); Assert.assertEquals(1L, contractAccountCountAfter.longValue()); } } - @Test(enabled = true, description = "transfer to a suicide contract address different token", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "transfer to a suicide contract address different token", + groups = {"contract", "daily"}) public void test5transferToSuicideContractDifferentToken() { // create different token - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress3, 10000_000_000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress3, + 10000_000_000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert - .assertTrue(PublicMethod.createAssetIssue(contractExcAddress3, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, - 100000L, 1L, 1L, contractExcKey3, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + contractExcAddress3, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + contractExcKey3, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - assetAccountId2 = PublicMethod.queryAccount(contractExcAddress3, blockingStubFull) - .getAssetIssuedID(); - - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress3, 10000000000L, testNetAccountAddress, testNetAccountKey, + assetAccountId2 = + PublicMethod.queryAccount(contractExcAddress3, blockingStubFull).getAssetIssuedID(); + + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress3, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); - String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final byte[] contractAddress4 = PublicMethod.deployContract(contractName, abi, code, "", - maxFeeLimit, 1000000L, 100, 1000000000L, - assetAccountId2.toStringUtf8(), 1000L,null, contractExcKey3, - contractExcAddress3, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final byte[] contractAddress4 = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000L, + 100, + 1000000000L, + assetAccountId2.toStringUtf8(), + 1000L, + null, + contractExcKey3, + contractExcAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress3, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress3, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey3, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); if (PublicMethod.allowTvmSelfdestructRestrictionIsActive(blockingStubFull)) { - Account nonexistentAddressAccount = PublicMethod - .queryAccount(contractAddress, blockingStubFull1); + Account nonexistentAddressAccount = + PublicMethod.queryAccount(contractAddress, blockingStubFull1); Assert.assertEquals(0L, nonexistentAddressAccount.getBalance()); String num = - "\"1" + "\",\"" + Base58.encode58Check(contractAddress) + "\",\"" + assetAccountId2 - .toStringUtf8() + "\""; - String txid = PublicMethod.triggerContract(contractAddress4, - "testTransferTokenNonexistentTarget(uint256,address,trcToken)", num, false, - 0, maxFeeLimit, contractExcAddress3, contractExcKey3, blockingStubFull); + "\"1" + + "\",\"" + + Base58.encode58Check(contractAddress) + + "\",\"" + + assetAccountId2.toStringUtf8() + + "\""; + String txid = + PublicMethod.triggerContract( + contractAddress4, + "testTransferTokenNonexistentTarget(uint256,address,trcToken)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress3, + contractExcKey3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); - Long contractAccountCountTokenBalance = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long contractAccountCountTokenBalance = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); Assert.assertEquals(0L, contractAccountCountTokenBalance.longValue()); - Long contractAccountCountTokenBalance2 = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId2, blockingStubFull); + Long contractAccountCountTokenBalance2 = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId2, blockingStubFull); Assert.assertEquals(0L, contractAccountCountTokenBalance2.longValue()); - String assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetIssuedID().toStringUtf8(); + String assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); Assert.assertEquals(0, assetIssueId.length()); - }else { - Account nonexistentAddressAccount = PublicMethod - .queryAccount(contractAddress, blockingStubFull1); + } else { + Account nonexistentAddressAccount = + PublicMethod.queryAccount(contractAddress, blockingStubFull1); Assert.assertEquals(1L, nonexistentAddressAccount.getBalance()); String num = - "\"1" + "\",\"" + Base58.encode58Check(contractAddress) + "\",\"" + assetAccountId2 - .toStringUtf8() + "\""; - String txid = PublicMethod.triggerContract(contractAddress4, - "testTransferTokenNonexistentTarget(uint256,address,trcToken)", num, false, - 0, maxFeeLimit, contractExcAddress3, contractExcKey3, blockingStubFull); + "\"1" + + "\",\"" + + Base58.encode58Check(contractAddress) + + "\",\"" + + assetAccountId2.toStringUtf8() + + "\""; + String txid = + PublicMethod.triggerContract( + contractAddress4, + "testTransferTokenNonexistentTarget(uint256,address,trcToken)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress3, + contractExcKey3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); - Long contractAccountCountTokenBalance = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long contractAccountCountTokenBalance = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); Assert.assertEquals(1L, contractAccountCountTokenBalance.longValue()); - Long contractAccountCountTokenBalance2 = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId2, blockingStubFull); + Long contractAccountCountTokenBalance2 = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId2, blockingStubFull); Assert.assertEquals(1L, contractAccountCountTokenBalance2.longValue()); - String assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetIssuedID().toStringUtf8(); + String assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); Assert.assertEquals(0, assetIssueId.length()); } } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java index bd6994c6..f115f1b0 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java @@ -20,10 +20,10 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode @@ -36,31 +36,44 @@ public class TransferFailed005 extends TronBaseTest { String accountExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(accountExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + PublicMethod.printAddress(accountExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); { - Assert.assertTrue(PublicMethod - .sendcoin(accountExcAddress, 10000_000_000L, foundationAddress, foundationKey, + Assert.assertTrue( + PublicMethod.sendcoin( + accountExcAddress, + 10000_000_000L, + foundationAddress, + foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TransferFailed005.sol"; - String contractName = "EnergyOfTransferFailedTest"; + String filePath = "src/test/resources/soliditycode/TransferFailed005.sol"; + String contractName = "EnergyOfTransferFailedTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 100L, 100L, null, accountExcKey, - accountExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 100L, + 100L, + null, + accountExcKey, + accountExcAddress, + blockingStubFull); filePath = "src/test/resources/soliditycode/TransferFailed005.sol"; contractName = "Caller"; @@ -68,32 +81,65 @@ public void beforeClass() { code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - contractAddress1 = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100L, null, accountExcKey, - accountExcAddress, blockingStubFull); + contractAddress1 = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100L, + null, + accountExcKey, + accountExcAddress, + blockingStubFull); } } - @Test(enabled = false, description = "Deploy contract for trigger", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Deploy contract for trigger", + groups = {"contract", "daily"}) public void deployContract() { - Assert.assertTrue(PublicMethod - .sendcoin(accountExcAddress, 10000_000_000L, foundationAddress, foundationKey, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + accountExcAddress, 10000_000_000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TransferFailed005.sol"; - String contractName = "EnergyOfTransferFailedTest"; + String filePath = "src/test/resources/soliditycode/TransferFailed005.sol"; + String contractName = "EnergyOfTransferFailedTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100L, null, accountExcKey, - accountExcAddress, blockingStubFull); - String txid1 = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100L, - null, accountExcKey, accountExcAddress, blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid1, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100L, + null, + accountExcKey, + accountExcAddress, + blockingStubFull); + String txid1 = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100L, + null, + accountExcKey, + accountExcAddress, + blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid1, blockingStubFull); contractAddress = infoById.get().getContractAddress().toByteArray(); Assert.assertEquals(0, infoById.get().getResultValue()); @@ -103,116 +149,174 @@ public void deployContract() { code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - contractAddress1 = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100L, null, accountExcKey, - accountExcAddress, blockingStubFull); - txid1 = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100L, - null, accountExcKey, accountExcAddress, blockingStubFull); + contractAddress1 = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100L, + null, + accountExcKey, + accountExcAddress, + blockingStubFull); + txid1 = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100L, + null, + accountExcKey, + accountExcAddress, + blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); contractAddress1 = infoById.get().getContractAddress().toByteArray(); logger.info("caller address : " + Base58.encode58Check(contractAddress1)); Assert.assertEquals(0, infoById.get().getResultValue()); } - @Test(enabled = true, description = "TransferFailed for function call_value ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferFailed for function call_value ", + groups = {"contract", "daily"}) public void triggerContract01() { Account info = null; - AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(accountExcAddress, blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(accountExcAddress, blockingStubFull); info = PublicMethod.queryAccount(accountExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - //Assert.assertTrue(PublicMethod + // Assert.assertTrue(PublicMethod // .sendcoin(contractAddress, 1000100L, accountExcAddress, accountExcKey, blockingStubFull)); - //Assert.assertTrue(PublicMethod + // Assert.assertTrue(PublicMethod // .sendcoin(contractAddress1, 1, accountExcAddress, accountExcKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - logger.info("contractAddress balance before: " + PublicMethod - .queryAccount(contractAddress, blockingStubFull).getBalance()); - logger.info("callerAddress balance before: " + PublicMethod - .queryAccount(contractAddress1, blockingStubFull).getBalance()); + logger.info( + "contractAddress balance before: " + + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); + logger.info( + "callerAddress balance before: " + + PublicMethod.queryAccount(contractAddress1, blockingStubFull).getBalance()); long paramValue = 1; - // transfer trx to self`s account + // transfer trx to self`s account String param = "\"" + paramValue + "\",\"" + Base58.encode58Check(contractAddress) + "\""; - String triggerTxid = PublicMethod - .triggerContract(contractAddress, "testCallTrxInsufficientBalance(uint256,address)", param, - false, 0L, maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + contractAddress, + "testCallTrxInsufficientBalance(uint256,address)", + param, + false, + 0L, + maxFeeLimit, + accountExcAddress, + accountExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(infoById.get().getResultValue(), 1); Assert.assertEquals("FAILED", infoById.get().getResult().toString()); Assert.assertEquals("TRANSFER_FAILED", infoById.get().getReceipt().getResult().toString()); - Assert.assertEquals("transfer trx failed: Cannot transfer TRX to yourself.", + Assert.assertEquals( + "transfer trx failed: Cannot transfer TRX to yourself.", infoById.get().getResMessage().toStringUtf8()); - Assert.assertEquals(100L, - PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); - Assert.assertEquals(0L, - PublicMethod.queryAccount(contractAddress1, blockingStubFull).getBalance()); + Assert.assertEquals( + 100L, PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); + Assert.assertEquals( + 0L, PublicMethod.queryAccount(contractAddress1, blockingStubFull).getBalance()); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); - // transfer trx to unactivate account + // transfer trx to unactivate account ECKey ecKey2 = new ECKey(Utils.getRandom()); - byte[] accountExcAddress2 = ecKey2.getAddress(); + byte[] accountExcAddress2 = ecKey2.getAddress(); param = "\"" + paramValue + "\",\"" + Base58.encode58Check(accountExcAddress2) + "\""; - triggerTxid = PublicMethod - .triggerContract(contractAddress, "testCallTrxInsufficientBalance(uint256,address)", param, - false, 0L, maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + contractAddress, + "testCallTrxInsufficientBalance(uint256,address)", + param, + false, + 0L, + maxFeeLimit, + accountExcAddress, + accountExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertEquals(infoById.get().getResultValue(), 0); Assert.assertEquals("SUCESS", infoById.get().getResult().toString()); - Assert.assertEquals(99L, - PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); - Assert.assertEquals(0L, - PublicMethod.queryAccount(contractAddress1, blockingStubFull).getBalance()); + Assert.assertEquals( + 99L, PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); + Assert.assertEquals( + 0L, PublicMethod.queryAccount(contractAddress1, blockingStubFull).getBalance()); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); - // transfer trx to caller, value enough , function success contractResult(call_value) successed + // transfer trx to caller, value enough , function success contractResult(call_value) successed param = "\"" + paramValue + "\",\"" + Base58.encode58Check(contractAddress1) + "\""; - triggerTxid = PublicMethod - .triggerContract(contractAddress, "testCallTrxInsufficientBalance(uint256,address)", param, - false, 0L, maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + contractAddress, + "testCallTrxInsufficientBalance(uint256,address)", + param, + false, + 0L, + maxFeeLimit, + accountExcAddress, + accountExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info(infoById.get().getReceipt().getResult() + ""); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("energyUsed:" + energyUsed); logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); - int contractResult = ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); + int contractResult = ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); Assert.assertEquals(1, contractResult); Assert.assertEquals(infoById.get().getResultValue(), 0); Assert.assertEquals(infoById.get().getResult().toString(), "SUCESS"); - Assert.assertEquals(98L, - PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); - Assert.assertEquals(1L, - PublicMethod.queryAccount(contractAddress1, blockingStubFull).getBalance()); + Assert.assertEquals( + 98L, PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); + Assert.assertEquals( + 1L, PublicMethod.queryAccount(contractAddress1, blockingStubFull).getBalance()); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); - // transfer trx to caller, value not enough, function success + // transfer trx to caller, value not enough, function success // but contractResult(call_value) failed param = "\"" + 100 + "\",\"" + Base58.encode58Check(contractAddress1) + "\""; - triggerTxid = PublicMethod - .triggerContract(contractAddress, "testCallTrxInsufficientBalance(uint256,address)", param, - false, 0L, maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + contractAddress, + "testCallTrxInsufficientBalance(uint256,address)", + param, + false, + 0L, + maxFeeLimit, + accountExcAddress, + accountExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); @@ -226,61 +330,72 @@ public void triggerContract01() { logger.info("energyUsed:" + energyUsed); logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); - //contractResult`s first boolean value + // contractResult`s first boolean value contractResult = ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); Assert.assertEquals(0, contractResult); Assert.assertEquals(infoById.get().getResultValue(), 0); Assert.assertEquals(infoById.get().getResult().toString(), "SUCESS"); - Assert.assertEquals(98L, - PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); - Assert.assertEquals(1L, - PublicMethod.queryAccount(contractAddress1, blockingStubFull).getBalance()); + Assert.assertEquals( + 98L, PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); + Assert.assertEquals( + 1L, PublicMethod.queryAccount(contractAddress1, blockingStubFull).getBalance()); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); - - } - @Test(enabled = true, description = "TransferFailed for create", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferFailed for create", + groups = {"contract", "daily"}) public void triggerContract02() { - final Long contractBalance = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + final Long contractBalance = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Account info = null; - AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(accountExcAddress, blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(accountExcAddress, blockingStubFull); info = PublicMethod.queryAccount(accountExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - //Assert.assertTrue(PublicMethod + // Assert.assertTrue(PublicMethod // .sendcoin(contractAddress, 1000100L, accountExcAddress, accountExcKey, blockingStubFull)); - //Assert.assertTrue(PublicMethod + // Assert.assertTrue(PublicMethod // .sendcoin(contractAddress1, 1, accountExcAddress, accountExcKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - logger.info("contractAddress balance before: " + PublicMethod - .queryAccount(contractAddress, blockingStubFull).getBalance()); - logger.info("callerAddress balance before: " + PublicMethod - .queryAccount(contractAddress1, blockingStubFull).getBalance()); + logger.info( + "contractAddress balance before: " + + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); + logger.info( + "callerAddress balance before: " + + PublicMethod.queryAccount(contractAddress1, blockingStubFull).getBalance()); long paramValue = 1; - String param = "\"" + paramValue + "\""; - String triggerTxid = PublicMethod - .triggerContract(contractAddress, "testCreateTrxInsufficientBalance(uint256)", param, false, - 0L, maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + String param = "\"" + paramValue + "\""; + String triggerTxid = + PublicMethod.triggerContract( + contractAddress, + "testCreateTrxInsufficientBalance(uint256)", + param, + false, + 0L, + maxFeeLimit, + accountExcAddress, + accountExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info(infoById.get().getReceipt().getResult() + ""); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -288,20 +403,31 @@ public void triggerContract02() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); - logger.info("contractAddress balance before: " + PublicMethod - .queryAccount(contractAddress, blockingStubFull).getBalance()); - logger.info("callerAddress balance before: " + PublicMethod - .queryAccount(contractAddress1, blockingStubFull).getBalance()); + logger.info( + "contractAddress balance before: " + + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); + logger.info( + "callerAddress balance before: " + + PublicMethod.queryAccount(contractAddress1, blockingStubFull).getBalance()); Assert.assertEquals(infoById.get().getResultValue(), 0); Assert.assertFalse(infoById.get().getInternalTransactions(0).getRejected()); - Assert.assertEquals(contractBalance - 1, + Assert.assertEquals( + contractBalance - 1, PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); param = "\"" + (contractBalance + 1) + "\""; - triggerTxid = PublicMethod - .triggerContract(contractAddress, "testCreateTrxInsufficientBalance(uint256)", param, false, - 0L, maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + contractAddress, + "testCreateTrxInsufficientBalance(uint256)", + param, + false, + 0L, + maxFeeLimit, + accountExcAddress, + accountExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); @@ -316,78 +442,100 @@ public void triggerContract02() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); - logger.info("contractAddress balance before: " + PublicMethod - .queryAccount(contractAddress, blockingStubFull).getBalance()); - logger.info("callerAddress balance before: " + PublicMethod - .queryAccount(contractAddress1, blockingStubFull).getBalance()); + logger.info( + "contractAddress balance before: " + + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); + logger.info( + "callerAddress balance before: " + + PublicMethod.queryAccount(contractAddress1, blockingStubFull).getBalance()); Assert.assertEquals(infoById.get().getResultValue(), 1); Assert.assertEquals(infoById.get().getResMessage().toStringUtf8(), "REVERT opcode executed"); - Assert.assertEquals(contractBalance - 1, + Assert.assertEquals( + contractBalance - 1, PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); - - } - @Test(enabled = true, description = "TransferFailed for create2", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferFailed for create2", + groups = {"contract", "daily"}) public void triggerContract03() { - final Long contractBalance = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + final Long contractBalance = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Account info; - AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(accountExcAddress, blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(accountExcAddress, blockingStubFull); info = PublicMethod.queryAccount(accountExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - //Assert.assertTrue(PublicMethod + // Assert.assertTrue(PublicMethod // .sendcoin(contractAddress, 15L, accountExcAddress, accountExcKey, blockingStubFull)); - logger.info("contractAddress balance before: " + PublicMethod - .queryAccount(contractAddress, blockingStubFull).getBalance()); - String filePath = "./src/test/resources/soliditycode/TransferFailed007.sol"; - String contractName = "Caller"; + logger.info( + "contractAddress balance before: " + + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); + String filePath = "./src/test/resources/soliditycode/TransferFailed007.sol"; + String contractName = "Caller"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - String triggerTxid = PublicMethod - .triggerContract(contractAddress, "deploy(bytes,uint256)", param, false, 0L, maxFeeLimit, - accountExcAddress, accountExcKey, blockingStubFull); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + String triggerTxid = + PublicMethod.triggerContract( + contractAddress, + "deploy(bytes,uint256)", + param, + false, + 0L, + maxFeeLimit, + accountExcAddress, + accountExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("energyUsed:" + energyUsed); logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); - Long afterBalance = 0L; + Long afterBalance = 0L; afterBalance = PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); - logger.info("contractAddress balance after : " + PublicMethod - .queryAccount(contractAddress, blockingStubFull).getBalance()); + logger.info( + "contractAddress balance after : " + + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals("SUCESS", infoById.get().getResult().toString()); Assert.assertEquals(contractBalance - 10L, afterBalance.longValue()); Assert.assertFalse(infoById.get().getInternalTransactions(0).getRejected()); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); - triggerTxid = PublicMethod - .triggerContract(contractAddress, "deploy2(bytes,uint256)", param, false, 0L, maxFeeLimit, - accountExcAddress, accountExcKey, blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + contractAddress, + "deploy2(bytes,uint256)", + param, + false, + 0L, + maxFeeLimit, + accountExcAddress, + accountExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); @@ -403,31 +551,44 @@ public void triggerContract03() { logger.info("energyUsageTotal:" + energyUsageTotal); afterBalance = PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); - logger.info("contractAddress balance after : " + PublicMethod - .queryAccount(contractAddress, blockingStubFull).getBalance()); + logger.info( + "contractAddress balance after : " + + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); Assert.assertEquals(1, infoById.get().getResultValue()); Assert.assertEquals("FAILED", infoById.get().getResult().toString()); Assert.assertEquals(contractBalance - 10L, afterBalance.longValue()); Assert.assertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); - } - @Test(enabled = true, description = "Triggerconstant a transfer function", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Triggerconstant a transfer function", + groups = {"contract", "daily"}) public void triggerContract04() { Account account = PublicMethod.queryAccount(accountExcAddress, blockingStubFull); Account contractAccount = PublicMethod.queryAccount(contractAddress, blockingStubFull); - final Long AccountBeforeBalance = account.getBalance(); - final Long contractAccountBalance = contractAccount.getBalance(); - - TransactionExtention return1 = PublicMethod.triggerConstantContractForExtention(contractAddress, - "testTransferTrxInsufficientBalance(uint256)", "1", false, 0L, 1000000000, "0", 0L, - accountExcAddress, accountExcKey, blockingStubFull); + final Long AccountBeforeBalance = account.getBalance(); + final Long contractAccountBalance = contractAccount.getBalance(); + + TransactionExtention return1 = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testTransferTrxInsufficientBalance(uint256)", + "1", + false, + 0L, + 1000000000, + "0", + 0L, + accountExcAddress, + accountExcKey, + blockingStubFull); Assert.assertEquals(response_code.SUCCESS, return1.getResult().getCode()); /*Assert.assertEquals( - "class org.tron.core.vm.program.Program$StaticCallModificationException " - + ": Attempt to call a state modifying opcode inside STATICCALL", - return1.getResult().getMessage().toStringUtf8());*/ + "class org.tron.core.vm.program.Program$StaticCallModificationException " + + ": Attempt to call a state modifying opcode inside STATICCALL", + return1.getResult().getMessage().toStringUtf8());*/ logger.info("return1: " + return1); @@ -438,14 +599,13 @@ public void triggerContract04() { Assert.assertEquals(contractAccountBalance.longValue(), contractAccount.getBalance()); } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(accountExcAddress, accountExcKey, foundationAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + accountExcAddress, accountExcKey, foundationAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed006.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed006.java index 3af22468..3b984b13 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed006.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed006.java @@ -18,10 +18,10 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode @@ -34,38 +34,47 @@ public class TransferFailed006 extends TronBaseTest { String accountExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(accountExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(accountExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - } - @Test(enabled = false, description = "Deploy contract for trigger", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Deploy contract for trigger", + groups = {"contract", "daily"}) public void deployContract() { - Assert.assertTrue(PublicMethod - .sendcoin(accountExcAddress, 10000000000L, foundationAddress, foundationKey, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + accountExcAddress, 10000000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TransferFailed006.sol"; - String contractName = "EnergyOfTransferFailedTest"; + String filePath = "src/test/resources/soliditycode/TransferFailed006.sol"; + String contractName = "EnergyOfTransferFailedTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid1 = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100L, - null, accountExcKey, accountExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid1 = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100L, + null, + accountExcKey, + accountExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid1, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid1, blockingStubFull); contractAddress = infoById.get().getContractAddress().toByteArray(); Assert.assertEquals(0, infoById.get().getResultValue()); @@ -75,61 +84,81 @@ public void deployContract() { code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - txid1 = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100L, - null, accountExcKey, accountExcAddress, blockingStubFull); + txid1 = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100L, + null, + accountExcKey, + accountExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid1, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); contractAddress1 = infoById.get().getContractAddress().toByteArray(); logger.info("caller address : " + Base58.encode58Check(contractAddress1)); Assert.assertEquals(0, infoById.get().getResultValue()); } - @Test(enabled = false, description = "TransferFailed for create", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TransferFailed for create", + groups = {"contract", "daily"}) public void triggerContract() { Account info = null; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(accountExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(accountExcAddress, blockingStubFull); info = PublicMethod.queryAccount(accountExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - Assert.assertTrue(PublicMethod - .sendcoin(contractAddress, 1000100L, accountExcAddress, accountExcKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .sendcoin(contractAddress1, 1, accountExcAddress, accountExcKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + contractAddress, 1000100L, accountExcAddress, accountExcKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + contractAddress1, 1, accountExcAddress, accountExcKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info( - "contractAddress balance before: " + PublicMethod - .queryAccount(contractAddress, blockingStubFull) - .getBalance()); + "contractAddress balance before: " + + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); logger.info( - "callerAddress balance before: " + PublicMethod - .queryAccount(contractAddress1, blockingStubFull) - .getBalance()); + "callerAddress balance before: " + + PublicMethod.queryAccount(contractAddress1, blockingStubFull).getBalance()); long paramValue = 1000000; - String param = "\"" + paramValue + "\""; - String triggerTxid = PublicMethod.triggerContract(contractAddress, - "testCreateTrxInsufficientBalance(uint256)", param, false, 0L, - maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + String param = "\"" + paramValue + "\""; + String triggerTxid = + PublicMethod.triggerContract( + contractAddress, + "testCreateTrxInsufficientBalance(uint256)", + param, + false, + 0L, + maxFeeLimit, + accountExcAddress, + accountExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); logger.info(infoById.get().getReceipt().getResult() + ""); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -138,22 +167,28 @@ public void triggerContract() { logger.info("energyUsageTotal:" + energyUsageTotal); logger.info( - "contractAddress balance before: " + PublicMethod - .queryAccount(contractAddress, blockingStubFull) - .getBalance()); + "contractAddress balance before: " + + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); logger.info( - "callerAddress balance before: " + PublicMethod - .queryAccount(contractAddress1, blockingStubFull) - .getBalance()); + "callerAddress balance before: " + + PublicMethod.queryAccount(contractAddress1, blockingStubFull).getBalance()); Assert.assertEquals(infoById.get().getResultValue(), 0); Assert.assertFalse(infoById.get().getInternalTransactions(0).getRejected()); - Assert.assertEquals(100L, - PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); + Assert.assertEquals( + 100L, PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); - triggerTxid = PublicMethod.triggerContract(contractAddress, - "testCreateTrxInsufficientBalance(uint256)", param, false, 0L, - maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + contractAddress, + "testCreateTrxInsufficientBalance(uint256)", + param, + false, + 0L, + maxFeeLimit, + accountExcAddress, + accountExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); @@ -169,33 +204,28 @@ public void triggerContract() { logger.info("energyUsageTotal:" + energyUsageTotal); logger.info( - "contractAddress balance before: " + PublicMethod - .queryAccount(contractAddress, blockingStubFull) - .getBalance()); + "contractAddress balance before: " + + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); logger.info( - "callerAddress balance before: " + PublicMethod - .queryAccount(contractAddress1, blockingStubFull) - .getBalance()); + "callerAddress balance before: " + + PublicMethod.queryAccount(contractAddress1, blockingStubFull).getBalance()); Assert.assertEquals(infoById.get().getResultValue(), 1); Assert.assertEquals(infoById.get().getResMessage().toStringUtf8(), "REVERT opcode executed"); - Assert.assertEquals(100L, - PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); - Assert.assertEquals(1L, - PublicMethod.queryAccount(contractAddress1, blockingStubFull).getBalance()); + Assert.assertEquals( + 100L, PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); + Assert.assertEquals( + 1L, PublicMethod.queryAccount(contractAddress1, blockingStubFull).getBalance()); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); - - } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(accountExcAddress, accountExcKey, foundationAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + accountExcAddress, accountExcKey, foundationAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed007.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed007.java index 77810401..ff2baeba 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed007.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed007.java @@ -17,10 +17,10 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode @@ -33,80 +33,100 @@ public class TransferFailed007 extends TronBaseTest { String accountExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(accountExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(accountExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - } - @Test(enabled = false, description = "Deploy contract for trigger", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Deploy contract for trigger", + groups = {"contract", "daily"}) public void deployContract() { - Assert.assertTrue(PublicMethod - .sendcoin(accountExcAddress, 10000000000L, foundationAddress, foundationKey, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + accountExcAddress, 10000000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TransferFailed007.sol"; - String contractName = "EnergyOfTransferFailedTest"; + String filePath = "src/test/resources/soliditycode/TransferFailed007.sol"; + String contractName = "EnergyOfTransferFailedTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid1 = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100L, - null, accountExcKey, accountExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid1 = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100L, + null, + accountExcKey, + accountExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid1, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid1, blockingStubFull); contractAddress = infoById.get().getContractAddress().toByteArray(); Assert.assertEquals(0, infoById.get().getResultValue()); } - @Test(enabled = false, description = "TransferFailed for create2", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TransferFailed for create2", + groups = {"contract", "daily"}) public void triggerContract() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(accountExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(accountExcAddress, blockingStubFull); info = PublicMethod.queryAccount(accountExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - Assert.assertTrue(PublicMethod - .sendcoin(contractAddress, 15L, accountExcAddress, accountExcKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + contractAddress, 15L, accountExcAddress, accountExcKey, blockingStubFull)); logger.info( - "contractAddress balance before: " + PublicMethod - .queryAccount(contractAddress, blockingStubFull) - .getBalance()); - String filePath = "./src/test/resources/soliditycode/TransferFailed007.sol"; - String contractName = "Caller"; + "contractAddress balance before: " + + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); + String filePath = "./src/test/resources/soliditycode/TransferFailed007.sol"; + String contractName = "Caller"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; - String param = "\"" + testContractCode + "\"," + salt; - String triggerTxid = PublicMethod.triggerContract(contractAddress, - "deploy(bytes,uint256)", param, false, 0L, - maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); - - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + String param = "\"" + testContractCode + "\"," + salt; + String triggerTxid = + PublicMethod.triggerContract( + contractAddress, + "deploy(bytes,uint256)", + param, + false, + 0L, + maxFeeLimit, + accountExcAddress, + accountExcKey, + blockingStubFull); + + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -115,24 +135,29 @@ public void triggerContract() { logger.info("energyUsageTotal:" + energyUsageTotal); long afterBalance = 0L; - afterBalance = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + afterBalance = PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); logger.info( - "contractAddress balance after : " + PublicMethod - .queryAccount(contractAddress, blockingStubFull) - .getBalance()); + "contractAddress balance after : " + + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals("SUCESS", infoById.get().getResult().toString()); Assert.assertEquals(5L, afterBalance); Assert.assertFalse(infoById.get().getInternalTransactions(0).getRejected()); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); - triggerTxid = PublicMethod.triggerContract(contractAddress, - "deploy(bytes,uint256)", param, false, 0L, - maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + contractAddress, + "deploy(bytes,uint256)", + param, + false, + 0L, + maxFeeLimit, + accountExcAddress, + accountExcKey, + blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); fee = infoById.get().getFee(); netUsed = infoById.get().getReceipt().getNetUsage(); @@ -147,25 +172,22 @@ public void triggerContract() { afterBalance = PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); logger.info( - "contractAddress balance after : " + PublicMethod - .queryAccount(contractAddress, blockingStubFull) - .getBalance()); + "contractAddress balance after : " + + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance()); Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals("SUCESS", infoById.get().getResult().toString()); Assert.assertEquals(5L, afterBalance); Assert.assertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(accountExcAddress, accountExcKey, foundationAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + accountExcAddress, accountExcKey, foundationAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed008.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed008.java index 1e49d227..fd27b603 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed008.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed008.java @@ -19,10 +19,10 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode @@ -33,13 +33,12 @@ public class TransferFailed008 extends TronBaseTest { private static ByteString assetAccountId = null; private static ByteString assetAccountId2 = null; private static String tokenName = "testAssetIssue_" + Long.toString(now); - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); byte[] contractAddress = null; byte[] contractAddress2 = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -52,105 +51,138 @@ public class TransferFailed008 extends TronBaseTest { byte[] nonexistentAddress = ecKey2.getAddress(); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000_000_000L, testNetAccountAddress, testNetAccountKey, + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000_000_000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert - .assertTrue(PublicMethod.createAssetIssue(contractExcAddress, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, - 100000L, 1L, 1L, contractExcKey, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + contractExcAddress, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + contractExcKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - assetAccountId = PublicMethod.queryAccount(contractExcAddress, blockingStubFull) - .getAssetIssuedID(); + assetAccountId = + PublicMethod.queryAccount(contractExcAddress, blockingStubFull).getAssetIssuedID(); System.out.println("assetAccountId:" + assetAccountId.toStringUtf8()); - Long testNetAccountCountBefore = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long testNetAccountCountBefore = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); } - - @Test(enabled = false, description = "TransferToken to old contractAddress", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TransferToken to old contractAddress", + groups = {"contract", "daily"}) public void test1TransferToOldContractAddress() { String filePath = "src/test/resources/soliditycode/accountAssert.sol"; - String contractName = "transferTokenTestB"; + String contractName = "transferTokenTestB"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, 1000000000L, - assetAccountId.toStringUtf8(), 1000L, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + 1000000000L, + assetAccountId.toStringUtf8(), + 1000L, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long contractAccountTokenBalance = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long contractAccountTokenBalance = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); Assert.assertEquals(1000L, contractAccountTokenBalance.longValue()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long testNetAccountCountBefore = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountBefore = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); logger.info("contractAccountCountBefore:" + contractAccountCountBefore); - String txid = ""; - // TUtbvvfggwQLrDZCNqYpfieCvCaKgKk5k9 selfdestruct contractAddress + String txid = ""; + // TUtbvvfggwQLrDZCNqYpfieCvCaKgKk5k9 selfdestruct contractAddress // TQ1sSomxqmgqKiGqL3Lt8iybHt28FvUTwN exist accountAddress have token // TWvKUjxH37F9BoeBrdD1hhWf7Es4CDTsRP exist contractAddress haven't token // TKK8PhmACsJVX9T7Jkwr2QuWmhB8LjvwUW exist accountAddress haven't token // v4.1.2 contract address ----Manual input String oldContractAddress = "TV1ExzvFmSTMj67sxnzHrkZmjpsG5QWSne"; - String num = - "\"" + oldContractAddress + "\",\"1\",\"" + assetAccountId.toStringUtf8() + "\""; - txid = PublicMethod.triggerContract(contractAddress, - "transferTokenTest(address,uint256,trcToken)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String num = "\"" + oldContractAddress + "\",\"1\",\"" + assetAccountId.toStringUtf8() + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "transferTokenTest(address,uint256,trcToken)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById:" + infoById); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -159,16 +191,16 @@ public void test1TransferToOldContractAddress() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long testNetAccountCountAfter = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountAfter = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long testNetAccountCountAfter = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -186,60 +218,84 @@ public void test1TransferToOldContractAddress() { Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Assert.assertNotEquals(10000000, energyUsageTotal); - Long oldContractAddressAccount = PublicMethod.getAssetIssueValue( - PublicMethod.decode58Check(oldContractAddress), assetAccountId, blockingStubFull1); + Long oldContractAddressAccount = + PublicMethod.getAssetIssueValue( + PublicMethod.decode58Check(oldContractAddress), assetAccountId, blockingStubFull1); Assert.assertEquals(1L, oldContractAddressAccount.longValue()); } - @Test(enabled = true, description = "TransferToken to new contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken to new contract", + groups = {"contract", "daily"}) public void test1TransferToNewContract() { String filePath = "src/test/resources/soliditycode/accountAssert.sol"; - String contractName = "transferTokenTestB"; + String contractName = "transferTokenTestB"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, 1000000000L, - assetAccountId.toStringUtf8(), 1000L, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + 1000000000L, + assetAccountId.toStringUtf8(), + 1000L, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long contractAccountTokenBalance = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long contractAccountTokenBalance = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); Assert.assertEquals(1000L, contractAccountTokenBalance.longValue()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - Long testNetAccountCountBefore = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountBefore = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); logger.info("contractAccountCountBefore:" + contractAccountCountBefore); - String txid = ""; - String num = "\"1" + "\",\"" + assetAccountId.toStringUtf8() + "\""; - txid = PublicMethod.triggerContract(contractAddress, - "createContractTest(uint256,trcToken)", num, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + String num = "\"1" + "\",\"" + assetAccountId.toStringUtf8() + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + "createContractTest(uint256,trcToken)", + num, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); Optional infoById = null; PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById:" + infoById); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -248,16 +304,16 @@ public void test1TransferToNewContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull1); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull1); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - Long testNetAccountCountAfter = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountAfter = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long testNetAccountCountAfter = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -275,171 +331,258 @@ public void test1TransferToNewContract() { Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Assert.assertNotEquals(10000000, energyUsageTotal); - String addressHex = - "41" + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()) - .substring(24); + String addressHex = + "41" + + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()) + .substring(24); logger.info("address_hex: " + addressHex); - byte[] contractAddressA = ByteArray.fromHexString(addressHex); + byte[] contractAddressA = ByteArray.fromHexString(addressHex); logger.info("contractAddressA: " + Base58.encode58Check(contractAddressA)); - Long nonexistentAddressAccount = PublicMethod - .getAssetIssueValue(contractAddressA, assetAccountId, blockingStubFull1); + Long nonexistentAddressAccount = + PublicMethod.getAssetIssueValue(contractAddressA, assetAccountId, blockingStubFull1); Assert.assertEquals(1L, nonexistentAddressAccount.longValue()); } - @Test(enabled = true, description = "TransferToken nonexistent target in constructor", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken nonexistent target in constructor", + groups = {"contract", "daily"}) public void test2TransferToNonexistentTargetInConstructor() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long testNetAccountCountBefore = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountBefore = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long testNetAccountCountBefore = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); logger.info("contractAccountCountBefore:" + contractAccountCountBefore); - String filePath = "src/test/resources/soliditycode/accountAssert.sol"; - String contractName = "transferTokenTestA"; + String filePath = "src/test/resources/soliditycode/accountAssert.sol"; + String contractName = "transferTokenTestA"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String constructorStr = "constructor(address,uint256,trcToken)"; - String argsStr = - "\"" + Base58.encode58Check(nonexistentAddress) + "\",\"1\",\"" + assetAccountId - .toStringUtf8() + "\""; - String deplTxid = PublicMethod.deployContractWithConstantParame(contractName, abi, code, - constructorStr, argsStr, "", maxFeeLimit, 1000000L, 100,1000L, - assetAccountId.toStringUtf8(), 1000L, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String constructorStr = "constructor(address,uint256,trcToken)"; + String argsStr = + "\"" + + Base58.encode58Check(nonexistentAddress) + + "\",\"1\",\"" + + assetAccountId.toStringUtf8() + + "\""; + String deplTxid = + PublicMethod.deployContractWithConstantParame( + contractName, + abi, + code, + constructorStr, + argsStr, + "", + maxFeeLimit, + 1000000L, + 100, + 1000L, + assetAccountId.toStringUtf8(), + 1000L, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = PublicMethod - .getTransactionInfoById(deplTxid, blockingStubFull); + Optional info = + PublicMethod.getTransactionInfoById(deplTxid, blockingStubFull); Assert.assertTrue(info.get().getResultValue() == 0); contractAddress = info.get().getContractAddress().toByteArray(); - Long testNetAccountCountAfter = PublicMethod - .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); - Long contractAccountCountAfter = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long testNetAccountCountAfter = + PublicMethod.getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("testNetAccountCountAfter:" + testNetAccountCountAfter); logger.info("contractAccountCountAfter:" + contractAccountCountAfter); - Assert.assertEquals(testNetAccountCountBefore.longValue() - 1000L, - testNetAccountCountAfter.longValue()); + Assert.assertEquals( + testNetAccountCountBefore.longValue() - 1000L, testNetAccountCountAfter.longValue()); Assert.assertEquals(999L, contractAccountCountAfter.longValue()); - Account nonexistentAddressAccountTrxBalance = PublicMethod - .queryAccount(nonexistentAddress, blockingStubFull1); + Account nonexistentAddressAccountTrxBalance = + PublicMethod.queryAccount(nonexistentAddress, blockingStubFull1); Assert.assertEquals(0L, nonexistentAddressAccountTrxBalance.getBalance()); - Long nonexistentAddressAccountTokenBalance = PublicMethod - .getAssetIssueValue(nonexistentAddress, assetAccountId, blockingStubFull1); + Long nonexistentAddressAccountTokenBalance = + PublicMethod.getAssetIssueValue(nonexistentAddress, assetAccountId, blockingStubFull1); Assert.assertEquals(1L, nonexistentAddressAccountTokenBalance.longValue()); } - @Test(enabled = true, description = "TransferToken existent target in constructor", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken existent target in constructor", + groups = {"contract", "daily"}) public void test3TransferToExistentTargetInConstructor() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress3, 10000_000_000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress3, + 10000_000_000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; - //Create a new AssetIssue success. - Assert - .assertTrue(PublicMethod.createAssetIssue(contractExcAddress3, tokenName, TotalSupply, 1, - 10000, start, end, 1, description, url, 100000L, - 100000L, 1L, 1L, contractExcKey3, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + contractExcAddress3, + tokenName, + TotalSupply, + 1, + 10000, + start, + end, + 1, + description, + url, + 100000L, + 100000L, + 1L, + 1L, + contractExcKey3, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - assetAccountId2 = PublicMethod.queryAccount(contractExcAddress3, blockingStubFull) - .getAssetIssuedID(); - - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress3, 10000000000L, testNetAccountAddress, testNetAccountKey, + assetAccountId2 = + PublicMethod.queryAccount(contractExcAddress3, blockingStubFull).getAssetIssuedID(); + + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress3, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long testNetAccountCountBefore = PublicMethod - .getAssetIssueValue(contractExcAddress3, assetAccountId2, blockingStubFull); - Long contractAccountCountBefore = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId2, blockingStubFull); + Long testNetAccountCountBefore = + PublicMethod.getAssetIssueValue(contractExcAddress3, assetAccountId2, blockingStubFull); + Long contractAccountCountBefore = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId2, blockingStubFull); logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); logger.info("contractAccountCountBefore:" + contractAccountCountBefore); - String filePath = "src/test/resources/soliditycode/accountAssert.sol"; - String contractName = "transferTokenTestA"; + String filePath = "src/test/resources/soliditycode/accountAssert.sol"; + String contractName = "transferTokenTestA"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String constructorStr = "constructor(address,uint256,trcToken)"; - String argsStr = - "\"" + Base58.encode58Check(nonexistentAddress) + "\",\"1\",\"" + assetAccountId2 - .toStringUtf8() + "\""; - String deplTxid = PublicMethod.deployContractWithConstantParame(contractName, abi, code, - constructorStr, argsStr, "", maxFeeLimit, 1000000L, 100, - 1000L, assetAccountId2.toStringUtf8(), 1000L, null, contractExcKey3, - contractExcAddress3, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String constructorStr = "constructor(address,uint256,trcToken)"; + String argsStr = + "\"" + + Base58.encode58Check(nonexistentAddress) + + "\",\"1\",\"" + + assetAccountId2.toStringUtf8() + + "\""; + String deplTxid = + PublicMethod.deployContractWithConstantParame( + contractName, + abi, + code, + constructorStr, + argsStr, + "", + maxFeeLimit, + 1000000L, + 100, + 1000L, + assetAccountId2.toStringUtf8(), + 1000L, + null, + contractExcKey3, + contractExcAddress3, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = PublicMethod - .getTransactionInfoById(deplTxid, blockingStubFull); + Optional info = + PublicMethod.getTransactionInfoById(deplTxid, blockingStubFull); Assert.assertTrue(info.get().getResultValue() == 0); contractAddress = info.get().getContractAddress().toByteArray(); - Long testNetAccountCountAfter = PublicMethod - .getAssetIssueValue(contractExcAddress3, assetAccountId2, blockingStubFull); - Long contractAccountCountAfter = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId2, blockingStubFull); + Long testNetAccountCountAfter = + PublicMethod.getAssetIssueValue(contractExcAddress3, assetAccountId2, blockingStubFull); + Long contractAccountCountAfter = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId2, blockingStubFull); logger.info("testNetAccountCountAfter:" + testNetAccountCountAfter); logger.info("contractAccountCountAfter:" + contractAccountCountAfter); - Assert.assertEquals(testNetAccountCountBefore.longValue() - 1000L, - testNetAccountCountAfter.longValue()); + Assert.assertEquals( + testNetAccountCountBefore.longValue() - 1000L, testNetAccountCountAfter.longValue()); Assert.assertEquals(999L, contractAccountCountAfter.longValue()); - Account nonexistentAddressAccountTrxBalance = PublicMethod - .queryAccount(nonexistentAddress, blockingStubFull1); + Account nonexistentAddressAccountTrxBalance = + PublicMethod.queryAccount(nonexistentAddress, blockingStubFull1); Assert.assertEquals(0L, nonexistentAddressAccountTrxBalance.getBalance()); - Long nonexistentAddressAccountTokenBalance = PublicMethod - .getAssetIssueValue(nonexistentAddress, assetAccountId, blockingStubFull1); + Long nonexistentAddressAccountTokenBalance = + PublicMethod.getAssetIssueValue(nonexistentAddress, assetAccountId, blockingStubFull1); Assert.assertEquals(1L, nonexistentAddressAccountTokenBalance.longValue()); - Long nonexistentAddressAccountTokenBalance2 = PublicMethod - .getAssetIssueValue(nonexistentAddress, assetAccountId2, blockingStubFull1); + Long nonexistentAddressAccountTokenBalance2 = + PublicMethod.getAssetIssueValue(nonexistentAddress, assetAccountId2, blockingStubFull1); Assert.assertEquals(1L, nonexistentAddressAccountTokenBalance2.longValue()); } - @Test(enabled = true, description = "TransferToken existent target in constructor", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TransferToken existent target in constructor", + groups = {"contract", "daily"}) public void test4GetTokenBalanceInConstructor() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/accountAssert.sol"; - String contractName = "transferTokenTestC"; + String filePath = "src/test/resources/soliditycode/accountAssert.sol"; + String contractName = "transferTokenTestC"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String constructorStr = "constructor(trcToken)"; - String argsStr = "\"" + assetAccountId.toStringUtf8() + "\""; - String deplTxid = PublicMethod.deployContractWithConstantParame(contractName, abi, code, - constructorStr, argsStr, "", maxFeeLimit, 1000000L, 100,1000L, - "0", 0L, null, contractExcKey, contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String constructorStr = "constructor(trcToken)"; + String argsStr = "\"" + assetAccountId.toStringUtf8() + "\""; + String deplTxid = + PublicMethod.deployContractWithConstantParame( + contractName, + abi, + code, + constructorStr, + argsStr, + "", + maxFeeLimit, + 1000000L, + 100, + 1000L, + "0", + 0L, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = PublicMethod - .getTransactionInfoById(deplTxid, blockingStubFull); + Optional info = + PublicMethod.getTransactionInfoById(deplTxid, blockingStubFull); Assert.assertTrue(info.get().getResultValue() == 0); contractAddress = info.get().getContractAddress().toByteArray(); - Long contractAccountCountAfter = PublicMethod - .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = + PublicMethod.getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); logger.info("contractAccountCountAfter:" + contractAccountCountAfter); Assert.assertEquals(0L, contractAccountCountAfter.longValue()); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java index 9119d671..4e69a3e7 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java @@ -6,11 +6,9 @@ import io.grpc.ManagedChannelBuilder; import java.util.HashMap; import java.util.Optional; -import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; import org.bouncycastle.util.encoders.Hex; import org.junit.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.AccountResourceMessage; @@ -24,10 +22,10 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode @@ -56,9 +54,10 @@ public class TriggerConstant001 extends TronBaseTest { @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); - blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); channelRealSolidity = - ManagedChannelBuilder.forTarget(realSoliditynode).usePlaintext().build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + channelRealSolidity = ManagedChannelBuilder.forTarget(realSoliditynode).usePlaintext().build(); blockingStubRealSolidity = WalletSolidityGrpc.newBlockingStub(channelRealSolidity); { @@ -70,11 +69,11 @@ public void beforeClass() { testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant001.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/TriggerConstant001.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - final String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + final String abi = retMap.get("abI").toString(); contractAddressNoAbi = PublicMethod.deployContract( @@ -121,7 +120,10 @@ public void beforeClass() { } } - @Test(enabled = true, description = "TriggerConstantContract a payable function without ABI", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerConstantContract a payable function without ABI", + groups = {"contract", "daily"}) public void test01TriggerConstantContract() { String txid = ""; @@ -172,7 +174,8 @@ public void test01TriggerConstantContract() { @Test( enabled = true, - description = "TriggerConstantContract a payable function" + " without ABI on solidity", groups = {"contract", "daily"}) + description = "TriggerConstantContract a payable function" + " without ABI on solidity", + groups = {"contract", "daily"}) public void test01TriggerConstantContractOnSolidity() { TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtentionOnSolidity( @@ -200,7 +203,8 @@ public void test01TriggerConstantContractOnSolidity() { @Test( enabled = true, - description = "TriggerConstantContract a payable function" + " without ABI on real solidity", groups = {"contract", "daily"}) + description = "TriggerConstantContract a payable function" + " without ABI on real solidity", + groups = {"contract", "daily"}) public void test01TriggerConstantContractOnRealSolidity() { TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtentionOnSolidity( @@ -228,7 +232,8 @@ public void test01TriggerConstantContractOnRealSolidity() { @Test( enabled = true, - description = "TriggerConstantContract a non-payable function" + " without ABI", groups = {"contract", "daily"}) + description = "TriggerConstantContract a non-payable function" + " without ABI", + groups = {"contract", "daily"}) public void test02TriggerConstantContract() { TransactionExtention transactionExtention = @@ -257,7 +262,8 @@ public void test02TriggerConstantContract() { @Test( enabled = true, - description = "TriggerConstantContract a non-payable function" + " without ABI on solidity", groups = {"contract", "daily"}) + description = "TriggerConstantContract a non-payable function" + " without ABI on solidity", + groups = {"contract", "daily"}) public void test02TriggerConstantContractOnSolidity() { TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtentionOnSolidity( @@ -286,7 +292,8 @@ public void test02TriggerConstantContractOnSolidity() { @Test( enabled = true, description = - "TriggerConstantContract a non-payable function" + " without ABI on real solidity", groups = {"contract", "daily"}) + "TriggerConstantContract a non-payable function" + " without ABI on real solidity", + groups = {"contract", "daily"}) public void test02TriggerConstantContractOnRealSolidity() { TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtentionOnSolidity( @@ -312,7 +319,10 @@ public void test02TriggerConstantContractOnRealSolidity() { containsString("Attempt to call a state modifying opcode inside STATICCALL"));*/ } - @Test(enabled = true, description = "TriggerConstantContract a view function without ABI", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerConstantContract a view function without ABI", + groups = {"contract", "daily"}) public void test03TriggerConstantContract() { TransactionExtention transactionExtention = @@ -330,7 +340,7 @@ public void test03TriggerConstantContract() { blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -341,7 +351,8 @@ public void test03TriggerConstantContract() { @Test( enabled = true, - description = "TriggerConstantContract a view function" + " without ABI on solidity", groups = {"contract", "daily"}) + description = "TriggerConstantContract a view function" + " without ABI on solidity", + groups = {"contract", "daily"}) public void test03TriggerConstantContractOnSolidity() { TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtentionOnSolidity( @@ -358,7 +369,7 @@ public void test03TriggerConstantContractOnSolidity() { blockingStubSolidity); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -369,7 +380,8 @@ public void test03TriggerConstantContractOnSolidity() { @Test( enabled = true, - description = "TriggerConstantContract a view function" + " without ABI on real solidity", groups = {"contract", "daily"}) + description = "TriggerConstantContract a view function" + " without ABI on real solidity", + groups = {"contract", "daily"}) public void test03TriggerConstantContractOnRealSolidity() { TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtentionOnSolidity( @@ -386,7 +398,7 @@ public void test03TriggerConstantContractOnRealSolidity() { blockingStubRealSolidity); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -395,7 +407,10 @@ public void test03TriggerConstantContractOnRealSolidity() { Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); } - @Test(enabled = true, description = "TriggerConstantContract a pure function without ABI", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerConstantContract a pure function without ABI", + groups = {"contract", "daily"}) public void test04TriggerConstantContract() { TransactionExtention transactionExtention = @@ -413,7 +428,7 @@ public void test04TriggerConstantContract() { blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -424,7 +439,8 @@ public void test04TriggerConstantContract() { @Test( enabled = true, - description = "TriggerConstantContract a pure function" + " without ABI on solidity", groups = {"contract", "daily"}) + description = "TriggerConstantContract a pure function" + " without ABI on solidity", + groups = {"contract", "daily"}) public void test04TriggerConstantContractOnSolidity() { TransactionExtention transactionExtention = @@ -442,7 +458,7 @@ public void test04TriggerConstantContractOnSolidity() { blockingStubSolidity); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -453,7 +469,8 @@ public void test04TriggerConstantContractOnSolidity() { @Test( enabled = true, - description = "TriggerConstantContract a pure function" + " without ABI on real solidity", groups = {"contract", "daily"}) + description = "TriggerConstantContract a pure function" + " without ABI on real solidity", + groups = {"contract", "daily"}) public void test04TriggerConstantContractOnRealSolidity() { TransactionExtention transactionExtention = @@ -471,7 +488,7 @@ public void test04TriggerConstantContractOnRealSolidity() { blockingStubRealSolidity); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -480,7 +497,10 @@ public void test04TriggerConstantContractOnRealSolidity() { Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); } - @Test(enabled = true, description = "TriggerConstantContract a payable function with ABI", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerConstantContract a payable function with ABI", + groups = {"contract", "daily"}) public void test05TriggerConstantContract() { TransactionExtention transactionExtention = @@ -510,7 +530,8 @@ public void test05TriggerConstantContract() { @Test( enabled = true, - description = "TriggerConstantContract a payable function" + " with ABI on solidity", groups = {"contract", "daily"}) + description = "TriggerConstantContract a payable function" + " with ABI on solidity", + groups = {"contract", "daily"}) public void test05TriggerConstantContractOnSolidity() { TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtentionOnSolidity( @@ -539,7 +560,8 @@ public void test05TriggerConstantContractOnSolidity() { @Test( enabled = true, - description = "TriggerConstantContract a payable function" + " with ABI on real solidity", groups = {"contract", "daily"}) + description = "TriggerConstantContract a payable function" + " with ABI on real solidity", + groups = {"contract", "daily"}) public void test05TriggerConstantContractOnRealSolidity() { TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtentionOnSolidity( @@ -566,7 +588,10 @@ public void test05TriggerConstantContractOnRealSolidity() { PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "TriggerConstantContract a non-payable function with ABI", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerConstantContract a non-payable function with ABI", + groups = {"contract", "daily"}) public void test06TriggerConstantContract() { TransactionExtention transactionExtention = @@ -596,7 +621,8 @@ public void test06TriggerConstantContract() { @Test( enabled = true, - description = "TriggerConstantContract a non-payable function" + " with ABI on solidity", groups = {"contract", "daily"}) + description = "TriggerConstantContract a non-payable function" + " with ABI on solidity", + groups = {"contract", "daily"}) public void test06TriggerConstantContractOnSolidity() { TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtentionOnSolidity( @@ -625,7 +651,8 @@ public void test06TriggerConstantContractOnSolidity() { @Test( enabled = true, - description = "TriggerConstantContract a non-payable function" + " with ABI on real solidity", groups = {"contract", "daily"}) + description = "TriggerConstantContract a non-payable function" + " with ABI on real solidity", + groups = {"contract", "daily"}) public void test06TriggerConstantContractOnRealSolidity() { TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtentionOnSolidity( @@ -652,7 +679,10 @@ public void test06TriggerConstantContractOnRealSolidity() { PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "TriggerConstantContract a view function with ABI", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerConstantContract a view function with ABI", + groups = {"contract", "daily"}) public void test07TriggerConstantContract() { TransactionExtention transactionExtention = @@ -670,7 +700,7 @@ public void test07TriggerConstantContract() { blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -681,7 +711,8 @@ public void test07TriggerConstantContract() { @Test( enabled = true, - description = "TriggerConstantContract a view function" + " with ABI on solidity", groups = {"contract", "daily"}) + description = "TriggerConstantContract a view function" + " with ABI on solidity", + groups = {"contract", "daily"}) public void test07TriggerConstantContractOnSolidity() { TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtentionOnSolidity( @@ -698,7 +729,7 @@ public void test07TriggerConstantContractOnSolidity() { blockingStubSolidity); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -709,7 +740,8 @@ public void test07TriggerConstantContractOnSolidity() { @Test( enabled = true, - description = "TriggerConstantContract a view function" + " with ABI on real solidity", groups = {"contract", "daily"}) + description = "TriggerConstantContract a view function" + " with ABI on real solidity", + groups = {"contract", "daily"}) public void test07TriggerConstantContractOnRealSolidity() { TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtentionOnSolidity( @@ -726,7 +758,7 @@ public void test07TriggerConstantContractOnRealSolidity() { blockingStubRealSolidity); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -735,7 +767,10 @@ public void test07TriggerConstantContractOnRealSolidity() { Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); } - @Test(enabled = true, description = "TriggerConstantContract a pure function with ABI", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerConstantContract a pure function with ABI", + groups = {"contract", "daily"}) public void test08TriggerConstantContract() { TransactionExtention transactionExtention = @@ -753,7 +788,7 @@ public void test08TriggerConstantContract() { blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -764,7 +799,8 @@ public void test08TriggerConstantContract() { @Test( enabled = true, - description = "TriggerConstantContract a pure function" + " with ABI on solidity", groups = {"contract", "daily"}) + description = "TriggerConstantContract a pure function" + " with ABI on solidity", + groups = {"contract", "daily"}) public void test08TriggerConstantContractOnSolidity() { TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtentionOnSolidity( @@ -781,7 +817,7 @@ public void test08TriggerConstantContractOnSolidity() { blockingStubSolidity); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -792,7 +828,8 @@ public void test08TriggerConstantContractOnSolidity() { @Test( enabled = true, - description = "TriggerConstantContract a pure function" + " with ABI on real solidity", groups = {"contract", "daily"}) + description = "TriggerConstantContract a pure function" + " with ABI on real solidity", + groups = {"contract", "daily"}) public void test08TriggerConstantContractOnRealSolidity() { TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtentionOnSolidity( @@ -809,7 +846,7 @@ public void test08TriggerConstantContractOnRealSolidity() { blockingStubRealSolidity); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -818,22 +855,25 @@ public void test08TriggerConstantContractOnRealSolidity() { Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); } - @Test(enabled = true, description = "TriggerContract a payable function without ABI", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerContract a payable function without ABI", + groups = {"contract", "daily"}) public void test09TriggerContract() { Account info; AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; + String txid = ""; txid = PublicMethod.triggerContract( @@ -852,10 +892,10 @@ public void test09TriggerContract() { PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -867,10 +907,10 @@ public void test09TriggerContract() { Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -881,29 +921,32 @@ public void test09TriggerContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber = + Long returnnumber = ByteArray.toLong( ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); } - @Test(enabled = true, description = "TriggerContract a non-payable function without ABI", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerContract a non-payable function without ABI", + groups = {"contract", "daily"}) public void test10TriggerContract() { Account info; AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; + String txid = ""; txid = PublicMethod.triggerContract( @@ -922,10 +965,10 @@ public void test10TriggerContract() { PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -937,10 +980,10 @@ public void test10TriggerContract() { Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -951,14 +994,17 @@ public void test10TriggerContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber = + Long returnnumber = ByteArray.toLong( ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); } - @Test(enabled = true, description = "TriggerContract a view function without ABI", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerContract a view function without ABI", + groups = {"contract", "daily"}) public void test11TriggerContract() { Account info; @@ -966,15 +1012,15 @@ public void test11TriggerContract() { AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; + String txid = ""; txid = PublicMethod.triggerContract( @@ -993,10 +1039,10 @@ public void test11TriggerContract() { PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -1008,10 +1054,10 @@ public void test11TriggerContract() { Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -1022,14 +1068,17 @@ public void test11TriggerContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber = + Long returnnumber = ByteArray.toLong( ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); } - @Test(enabled = true, description = "TriggerContract a pure function without ABI", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerContract a pure function without ABI", + groups = {"contract", "daily"}) public void test12TriggerContract() { Account info; @@ -1037,15 +1086,15 @@ public void test12TriggerContract() { AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; + String txid = ""; txid = PublicMethod.triggerContract( @@ -1064,10 +1113,10 @@ public void test12TriggerContract() { PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -1079,10 +1128,10 @@ public void test12TriggerContract() { Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -1093,14 +1142,17 @@ public void test12TriggerContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber = + Long returnnumber = ByteArray.toLong( ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); } - @Test(enabled = true, description = "TriggerContract a pure function with ABI", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerContract a pure function with ABI", + groups = {"contract", "daily"}) public void test18TriggerContract() { TransactionExtention transactionExtention = @@ -1118,7 +1170,7 @@ public void test18TriggerContract() { blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -1127,7 +1179,10 @@ public void test18TriggerContract() { Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); } - @Test(enabled = true, description = "TriggerContract a payable function with ABI", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerContract a payable function with ABI", + groups = {"contract", "daily"}) public void test19TriggerContract() { Account info; @@ -1135,15 +1190,15 @@ public void test19TriggerContract() { AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; + String txid = ""; txid = PublicMethod.triggerContract( contractAddressWithAbi, @@ -1161,10 +1216,10 @@ public void test19TriggerContract() { PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -1176,10 +1231,10 @@ public void test19TriggerContract() { Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -1190,29 +1245,32 @@ public void test19TriggerContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber = + Long returnnumber = ByteArray.toLong( ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); } - @Test(enabled = true, description = "TriggerContract a non-payable function with ABI", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerContract a non-payable function with ABI", + groups = {"contract", "daily"}) public void test20TriggerContract() { Account info; AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; + String txid = ""; txid = PublicMethod.triggerContract( contractAddressNoAbi, @@ -1230,10 +1288,10 @@ public void test20TriggerContract() { PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -1245,10 +1303,10 @@ public void test20TriggerContract() { Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -1259,14 +1317,17 @@ public void test20TriggerContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber = + Long returnnumber = ByteArray.toLong( ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); } - @Test(enabled = true, description = "TriggerContract a view function with ABI", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerContract a view function with ABI", + groups = {"contract", "daily"}) public void test21TriggerConstantContract() { TransactionExtention transactionExtention = @@ -1284,7 +1345,7 @@ public void test21TriggerConstantContract() { blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -1293,7 +1354,10 @@ public void test21TriggerConstantContract() { Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); } - @Test(enabled = true, description = "TriggerContract a view function with ABI on solidity", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerContract a view function with ABI on solidity", + groups = {"contract", "daily"}) public void test21TriggerConstantContractOnSolidity() { TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtentionOnSolidity( @@ -1310,7 +1374,7 @@ public void test21TriggerConstantContractOnSolidity() { blockingStubSolidity); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -1319,7 +1383,10 @@ public void test21TriggerConstantContractOnSolidity() { Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); } - @Test(enabled = true, description = "TriggerContract a view function with ABI on real solidity", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerContract a view function with ABI on real solidity", + groups = {"contract", "daily"}) public void test21TriggerConstantContractOnRealSolidity() { TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtentionOnSolidity( @@ -1336,7 +1403,7 @@ public void test21TriggerConstantContractOnRealSolidity() { blockingStubRealSolidity); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -1347,7 +1414,8 @@ public void test21TriggerConstantContractOnRealSolidity() { @Test( enabled = true, - description = "TriggerConstantContract a view method with ABI ,method has " + "revert()", groups = {"contract", "daily"}) + description = "TriggerConstantContract a view method with ABI ,method has " + "revert()", + groups = {"contract", "daily"}) public void test24TriggerConstantContract() { TransactionExtention transactionExtention = @@ -1365,7 +1433,7 @@ public void test24TriggerConstantContract() { blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -1379,7 +1447,8 @@ public void test24TriggerConstantContract() { @Test( enabled = true, description = - "TriggerConstantContract a view method with ABI ,method has " + "revert() on solidity", groups = {"contract", "daily"}) + "TriggerConstantContract a view method with ABI ,method has " + "revert() on solidity", + groups = {"contract", "daily"}) public void test24TriggerConstantContractOnSolidity() { TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtentionOnSolidity( @@ -1396,7 +1465,7 @@ public void test24TriggerConstantContractOnSolidity() { blockingStubSolidity); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -1411,7 +1480,8 @@ public void test24TriggerConstantContractOnSolidity() { enabled = true, description = "TriggerConstantContract a view method with ABI ,method has " - + "revert() on real solidity", groups = {"contract", "daily"}) + + "revert() on real solidity", + groups = {"contract", "daily"}) public void test24TriggerConstantContractOnRealSolidity() { TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtentionOnSolidity( @@ -1428,7 +1498,7 @@ public void test24TriggerConstantContractOnRealSolidity() { blockingStubRealSolidity); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -1441,7 +1511,8 @@ public void test24TriggerConstantContractOnRealSolidity() { @Test( enabled = true, - description = "TriggerContract a view method with ABI ,method has " + "revert()", groups = {"contract", "daily"}) + description = "TriggerContract a view method with ABI ,method has " + "revert()", + groups = {"contract", "daily"}) public void test25TriggerConstantContract() { TransactionExtention transactionExtention = @@ -1459,7 +1530,7 @@ public void test25TriggerConstantContract() { blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -1472,7 +1543,8 @@ public void test25TriggerConstantContract() { @Test( enabled = true, - description = "TriggerContract a view method with ABI ,method has " + "revert() on solidity", groups = {"contract", "daily"}) + description = "TriggerContract a view method with ABI ,method has " + "revert() on solidity", + groups = {"contract", "daily"}) public void test25TriggerConstantContractOnSolidity() { TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtentionOnSolidity( @@ -1489,7 +1561,7 @@ public void test25TriggerConstantContractOnSolidity() { blockingStubSolidity); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -1503,7 +1575,8 @@ public void test25TriggerConstantContractOnSolidity() { @Test( enabled = true, description = - "TriggerContract a view method with ABI ,method has " + "revert() on real solidity", groups = {"contract", "daily"}) + "TriggerContract a view method with ABI ,method has " + "revert() on real solidity", + groups = {"contract", "daily"}) public void test25TriggerConstantContractOnRealSolidity() { TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtentionOnSolidity( @@ -1520,7 +1593,7 @@ public void test25TriggerConstantContractOnRealSolidity() { blockingStubRealSolidity); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -1533,7 +1606,8 @@ public void test25TriggerConstantContractOnRealSolidity() { @Test( enabled = true, - description = "TriggerConstantContract a view method without ABI,method has" + "revert()", groups = {"contract", "daily"}) + description = "TriggerConstantContract a view method without ABI,method has" + "revert()", + groups = {"contract", "daily"}) public void testTriggerConstantContract() { TransactionExtention transactionExtention = @@ -1551,7 +1625,7 @@ public void testTriggerConstantContract() { blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -1566,7 +1640,8 @@ public void testTriggerConstantContract() { @Test( enabled = true, description = - "TriggerConstantContract a view method without ABI,method has" + "revert() on solidity", groups = {"contract", "daily"}) + "TriggerConstantContract a view method without ABI,method has" + "revert() on solidity", + groups = {"contract", "daily"}) public void testTriggerConstantContractOnSolidity() { TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtentionOnSolidity( @@ -1583,7 +1658,7 @@ public void testTriggerConstantContractOnSolidity() { blockingStubSolidity); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); @@ -1599,7 +1674,8 @@ public void testTriggerConstantContractOnSolidity() { enabled = true, description = "TriggerConstantContract a view method without ABI,method has" - + "revert() on real solidity", groups = {"contract", "daily"}) + + "revert() on real solidity", + groups = {"contract", "daily"}) public void testTriggerConstantContractOnRealSolidity() { TransactionExtention transactionExtention = PublicMethod.triggerConstantContractForExtentionOnSolidity( @@ -1616,7 +1692,7 @@ public void testTriggerConstantContractOnRealSolidity() { blockingStubRealSolidity); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant002.java index 11578e41..cf2ce8ac 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant002.java @@ -19,17 +19,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant002 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,43 +37,54 @@ public class TriggerConstant002 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerConstantContract a non-payable function without ABI", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerConstantContract a non-payable function without ABI", + groups = {"contract", "daily"}) public void testTriggerConstantContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, "[]", code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + "[]", + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); @@ -81,46 +92,49 @@ public void testTriggerConstantContract() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "testNoPayable()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testNoPayable()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); System.out.println("Code = " + transactionExtention.getResult().getCode()); - System.out - .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); - - Assert - .assertThat(transactionExtention.getResult().getCode().toString(), - containsString("CONTRACT_EXE_ERROR")); - Assert - .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), - containsString("Attempt to call a state modifying opcode inside STATICCALL")); - - + System.out.println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_EXE_ERROR")); + Assert.assertThat( + transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Attempt to call a state modifying opcode inside STATICCALL")); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant003.java index 72ff81c4..116c00e1 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant003.java @@ -19,17 +19,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant003 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,178 +37,218 @@ public class TriggerConstant003 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant003.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/TriggerConstant003.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, "[]", code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + "[]", + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - } - @Test(enabled = true, description = "TriggerConstantContract a view function without ABI", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerConstantContract a view function without ABI", + groups = {"contract", "daily"}) public void test001TriggerConstantContract() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "testView()", "#", false, - 0, 1000000000, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testView()", + "#", + false, + 0, + 1000000000, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); - System.out.println(":" + ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println( + ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); System.out.println("Result:" + Hex.toHexString(result)); - Assert.assertEquals(1, ByteArray.toLong(ByteArray - .fromHexString(Hex - .toHexString(result)))); + Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); } - @Test(enabled = true, description = "TriggerConstantContract a pure function without ABI", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerConstantContract a pure function without ABI", + groups = {"contract", "daily"}) public void test002TriggerConstantContract() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "testPure()", "#", false, - 0, 1000000000, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure()", + "#", + false, + 0, + 1000000000, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); - System.out.println(":" + ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println( + ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); System.out.println("Result:" + Hex.toHexString(result)); - Assert.assertEquals(1, ByteArray.toLong(ByteArray - .fromHexString(Hex - .toHexString(result)))); + Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); } - @Test(enabled = true, description = "TriggerConstantContract a payable function without ABI", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerConstantContract a payable function without ABI", + groups = {"contract", "daily"}) public void test003TriggerConstantContract() { Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "testPayable()", "#", false, - 0, 1000000000, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPayable()", + "#", + false, + 0, + 1000000000, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); - System.out.println(":" + ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println( + ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); System.out.println("Result:" + Hex.toHexString(result)); Assert.assertEquals("SUCESS", transaction.getRet(0).getRet().toString()); - Assert.assertEquals(1, ByteArray.toLong(ByteArray - .fromHexString(Hex - .toHexString(result)))); - - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "testPayable()", "#", false, - 1L, 1000000000, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); + + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPayable()", + "#", + false, + 1L, + 1000000000, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); transaction = transactionExtention.getTransaction(); System.out.println(transactionExtention.toString()); result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); - System.out.println(":" + ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println( + ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); System.out.println("Result:" + Hex.toHexString(result)); - Assert.assertEquals(1, ByteArray.toLong(ByteArray - .fromHexString(Hex - .toHexString(result)))); + Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); Assert.assertEquals("SUCESS", transaction.getRet(0).getRet().toString()); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant004.java index d4367c22..279a2873 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant004.java @@ -19,17 +19,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant004 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,43 +37,54 @@ public class TriggerConstant004 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerConstantContract a pure function without ABI", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerConstantContract a pure function without ABI", + groups = {"contract", "daily"}) public void testTriggerConstantContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, "[]", code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + "[]", + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); @@ -81,47 +92,49 @@ public void testTriggerConstantContract() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "testPure()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); - System.out.println(":" + ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println( + ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); System.out.println("Result:" + Hex.toHexString(result)); - Assert.assertEquals(1, ByteArray.toLong(ByteArray - .fromHexString(Hex - .toHexString(result)))); - - + Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java index 7a81edb7..a892394d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java @@ -19,17 +19,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant005 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,36 +37,52 @@ public class TriggerConstant005 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); - blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + } - @Test(enabled = false, description = "TriggerConstantContract a payable function with ABI", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerConstantContract a payable function with ABI", + groups = {"contract", "daily"}) public void testTriggerConstantContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant001.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/TriggerConstant001.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); @@ -74,42 +90,49 @@ public void testTriggerConstantContract() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, "testPayable()", "#", false, 0, 0, - "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPayable()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); System.out.println("Code = " + transactionExtention.getResult().getCode()); System.out.println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); - Assert.assertThat(transactionExtention.getResult().getCode().toString(), - containsString("SUCCESS")); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), containsString("SUCCESS")); /*Assert.assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), - containsString("Attempt to call a state modifying opcode inside STATICCALL"));*/ + containsString("Attempt to call a state modifying opcode inside STATICCALL"));*/ } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant006.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant006.java index b8dfbbbe..54857f07 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant006.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant006.java @@ -19,17 +19,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant006 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,43 +37,54 @@ public class TriggerConstant006 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerConstantContract a non-payable function with ABI", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerConstantContract a non-payable function with ABI", + groups = {"contract", "daily"}) public void testTriggerConstantContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); @@ -81,45 +92,50 @@ public void testTriggerConstantContract() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "testNoPayable()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testNoPayable()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); System.out.println("Code = " + transactionExtention.getResult().getCode()); - System.out - .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + System.out.println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); - Assert.assertThat(transactionExtention.getResult().getCode().toString(), + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), containsString("CONTRACT_EXE_ERROR")); - Assert.assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + Assert.assertThat( + transactionExtention.getResult().getMessage().toStringUtf8(), containsString("Attempt to call a state modifying opcode inside STATICCALL")); PublicMethod.waitProduceNextBlock(blockingStubFull); - - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant007.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant007.java index 4cf1a68c..26059e56 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant007.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant007.java @@ -19,17 +19,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant007 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,43 +37,54 @@ public class TriggerConstant007 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerConstantContract a view function with ABI", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerConstantContract a view function with ABI", + groups = {"contract", "daily"}) public void testTriggerConstantContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant003.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/TriggerConstant003.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); @@ -81,47 +92,49 @@ public void testTriggerConstantContract() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "testView()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testView()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); - System.out.println(":" + ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println( + ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); System.out.println("Result:" + Hex.toHexString(result)); - Assert.assertEquals(1, ByteArray.toLong(ByteArray - .fromHexString(Hex - .toHexString(result)))); - - + Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant008.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant008.java index 1750dca8..97127225 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant008.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant008.java @@ -19,17 +19,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant008 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,43 +37,54 @@ public class TriggerConstant008 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerConstantContract a pure function with ABI", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerConstantContract a pure function with ABI", + groups = {"contract", "daily"}) public void testTriggerConstantContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); @@ -81,47 +92,49 @@ public void testTriggerConstantContract() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "testPure()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPure()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); - System.out.println(":" + ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println( + ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); System.out.println("Result:" + Hex.toHexString(result)); - Assert.assertEquals(1, ByteArray.toLong(ByteArray - .fromHexString(Hex - .toHexString(result)))); - - + Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant009.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant009.java index c169bb96..5fa99eb0 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant009.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant009.java @@ -18,17 +18,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant009 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -36,43 +36,54 @@ public class TriggerConstant009 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerContract a payable function without ABI", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerContract a payable function without ABI", + groups = {"contract", "daily"}) public void testTriggerContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant001.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/TriggerConstant001.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, "[]", code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + "[]", + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); @@ -80,31 +91,40 @@ public void testTriggerContract() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - - txid = PublicMethod - .triggerContract(contractAddress, - "testPayable()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + + txid = + PublicMethod.triggerContract( + contractAddress, + "testPayable()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -114,12 +134,12 @@ public void testTriggerContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -130,23 +150,20 @@ public void testTriggerContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); - - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant010.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant010.java index b67a9d62..464b9c27 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant010.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant010.java @@ -18,17 +18,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant010 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -36,43 +36,54 @@ public class TriggerConstant010 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerContract a non-payable function without ABI", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerContract a non-payable function without ABI", + groups = {"contract", "daily"}) public void testTriggerContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, "[]", code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + "[]", + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); @@ -80,31 +91,40 @@ public void testTriggerContract() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - - txid = PublicMethod - .triggerContract(contractAddress, - "testNoPayable()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + + txid = + PublicMethod.triggerContract( + contractAddress, + "testNoPayable()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -114,12 +134,12 @@ public void testTriggerContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -130,23 +150,20 @@ public void testTriggerContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); - - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant011.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant011.java index b0783d70..8cb306d0 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant011.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant011.java @@ -18,17 +18,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant011 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -36,43 +36,54 @@ public class TriggerConstant011 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerContract a view function without ABI", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerContract a view function without ABI", + groups = {"contract", "daily"}) public void testTriggerContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant003.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/TriggerConstant003.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, "[]", code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + "[]", + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); @@ -80,31 +91,40 @@ public void testTriggerContract() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - - txid = PublicMethod - .triggerContract(contractAddress, - "testView()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + + txid = + PublicMethod.triggerContract( + contractAddress, + "testView()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -114,12 +134,12 @@ public void testTriggerContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -130,23 +150,20 @@ public void testTriggerContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); - - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant012.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant012.java index eac12d47..257bad58 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant012.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant012.java @@ -18,17 +18,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant012 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -36,43 +36,54 @@ public class TriggerConstant012 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerContract a pure function without ABI", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerContract a pure function without ABI", + groups = {"contract", "daily"}) public void testTriggerContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, "[]", code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + "[]", + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); @@ -80,31 +91,40 @@ public void testTriggerContract() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - - txid = PublicMethod - .triggerContract(contractAddress, - "testPure()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + + txid = + PublicMethod.triggerContract( + contractAddress, + "testPure()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -114,12 +134,12 @@ public void testTriggerContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -130,23 +150,20 @@ public void testTriggerContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); - - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant013.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant013.java index 748c09b2..7cfba96e 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant013.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant013.java @@ -23,17 +23,17 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant013 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; byte[] returnAddressBytes = null; @@ -44,87 +44,103 @@ public class TriggerConstant013 extends TronBaseTest { private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; private ManagedChannel channelRealSolidity = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubRealSolidity = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - private String realSoliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1); - private String soliInPbft = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(2); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + private String realSoliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); + private String soliInPbft = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(2); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initPbftChannel(); initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - channelRealSolidity = ManagedChannelBuilder.forTarget(realSoliditynode) - .usePlaintext() - .build(); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + channelRealSolidity = ManagedChannelBuilder.forTarget(realSoliditynode).usePlaintext().build(); blockingStubRealSolidity = WalletSolidityGrpc.newBlockingStub(channelRealSolidity); - channelPbft = ManagedChannelBuilder.forTarget(soliInPbft) - .usePlaintext() - .build(); - } + channelPbft = ManagedChannelBuilder.forTarget(soliInPbft).usePlaintext().build(); + } - @Test(enabled = true, description = "triggerContract a constant function created by create2", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "triggerContract a constant function created by create2", + groups = {"contract", "daily"}) public void test01TriggerContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant015.sol"; - String contractName = "Factory"; + String filePath = "src/test/resources/soliditycode/TriggerConstant015.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String contractName1 = "TestConstract"; + String contractName1 = "TestConstract"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - String txid = ""; - String num = "\"" + code1 + "\"" + "," + 1; - txid = PublicMethod - .triggerContract(contractAddress, - "deploy(bytes,uint256)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + "," + 1; + txid = + PublicMethod.triggerContract( + contractAddress, + "deploy(bytes,uint256)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -134,12 +150,12 @@ public void test01TriggerContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -150,21 +166,30 @@ public void test01TriggerContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() - .toByteArray(); - String returnAddress = Base58.encode58Check(returnAddressBytes); + returnAddressBytes = + infoById.get().getInternalTransactions(0).getTransferToAddress().toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); - txid = PublicMethod - .triggerContract(returnAddressBytes, - "plusOne()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + returnAddressBytes, + "plusOne()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee1 = infoById1.get().getFee(); - Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); - Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); - Long netFee1 = infoById1.get().getReceipt().getNetFee(); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); logger.info("fee1:" + fee1); @@ -174,12 +199,12 @@ public void test01TriggerContract() { logger.info("energyUsageTotal1:" + energyUsageTotal1); Account infoafter1 = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter1 = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance1 = infoafter1.getBalance(); - Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); - Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); - Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter1 = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance1); logger.info("afterEnergyUsed:" + afterEnergyUsed1); logger.info("afterNetUsed:" + afterNetUsed1); @@ -188,119 +213,155 @@ public void test01TriggerContract() { Assert.assertTrue(infoById1.get().getResultValue() == 0); Assert.assertTrue(afterBalance1 + fee1 == afterBalance); Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); - } - - @Test(enabled = true, description = "TriggerConstantContract a constant function " - + "created by create2", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerConstantContract a constant function " + "created by create2", + groups = {"contract", "daily"}) public void test15TriggerConstantContract() { SmartContract smartContract = PublicMethod.getContract(returnAddressBytes, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - String returnAddress = Base58.encode58Check(returnAddressBytes); + String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(returnAddressBytes, - "plusOne()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + returnAddressBytes, + "plusOne()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); - System.out.println(":" + ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println( + ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); System.out.println("Result:" + Hex.toHexString(result)); - Assert.assertEquals(1, ByteArray.toLong(ByteArray - .fromHexString(Hex - .toHexString(result)))); + Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); } - @Test(enabled = true, description = "TriggerConstantContract a constant function " - + "created by create2 on solidity", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "TriggerConstantContract a constant function " + "created by create2 on solidity", + groups = {"contract", "daily"}) public void test16TriggerConstantContractOnSolidity() { SmartContract smartContract = PublicMethod.getContract(returnAddressBytes, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - String returnAddress = Base58.encode58Check(returnAddressBytes); + String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtentionOnSolidity(returnAddressBytes, - "plusOne()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubSolidity); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtentionOnSolidity( + returnAddressBytes, + "plusOne()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubSolidity); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); - System.out.println(":" + ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println( + ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); System.out.println("Result:" + Hex.toHexString(result)); - Assert.assertEquals(1, ByteArray.toLong(ByteArray - .fromHexString(Hex - .toHexString(result)))); + Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); } - @Test(enabled = true, description = "TriggerConstantContract a constant function " - + "created by create2 on real solidity", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "TriggerConstantContract a constant function " + "created by create2 on real solidity", + groups = {"contract", "daily"}) public void test17TriggerConstantContractOnRealSolidity() { SmartContract smartContract = PublicMethod.getContract(returnAddressBytes, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - String returnAddress = Base58.encode58Check(returnAddressBytes); + String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtentionOnSolidity(returnAddressBytes, - "plusOne()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubRealSolidity); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtentionOnSolidity( + returnAddressBytes, + "plusOne()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubRealSolidity); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); - System.out.println(":" + ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println( + ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); System.out.println("Result:" + Hex.toHexString(result)); - Assert.assertEquals(1, ByteArray.toLong(ByteArray - .fromHexString(Hex - .toHexString(result)))); + Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); } - @Test(enabled = true, description = "TriggerConstantContract a constant function " - + "created by create2 on pbft", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerConstantContract a constant function " + "created by create2 on pbft", + groups = {"contract", "daily"}) public void test18TriggerConstantContractOnPbft() { SmartContract smartContract = PublicMethod.getContract(returnAddressBytes, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - String returnAddress = Base58.encode58Check(returnAddressBytes); + String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtentionOnSolidity(returnAddressBytes, - "plusOne()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubPbft); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtentionOnSolidity( + returnAddressBytes, + "plusOne()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubPbft); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); - System.out.println(":" + ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println( + ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); System.out.println("Result:" + Hex.toHexString(result)); - Assert.assertEquals(1, ByteArray.toLong(ByteArray - .fromHexString(Hex - .toHexString(result)))); + Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant014.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant014.java index 074f7f00..2f4b107a 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant014.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant014.java @@ -23,17 +23,17 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant014 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; byte[] returnAddressBytes = null; @@ -44,74 +44,99 @@ public class TriggerConstant014 extends TronBaseTest { private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; private ManagedChannel channelRealSolidity = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubRealSolidity = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - private String realSoliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + private String realSoliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); - blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); channelRealSolidity = ManagedChannelBuilder.forTarget(realSoliditynode).usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + channelRealSolidity = ManagedChannelBuilder.forTarget(realSoliditynode).usePlaintext().build(); blockingStubRealSolidity = WalletSolidityGrpc.newBlockingStub(channelRealSolidity); } - @Test(enabled = true, description = "TriggerContract a non-constant function created by create2", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerContract a non-constant function created by create2", + groups = {"contract", "daily"}) public void test01TriggerContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/ClearAbi005.sol"; - String contractName = "Factory"; + String filePath = "src/test/resources/soliditycode/ClearAbi005.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String contractName1 = "TestConstract"; + String contractName1 = "TestConstract"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - String txid = ""; - String num = "\"" + code1 + "\"" + "," + 1; - txid = PublicMethod - .triggerContract(contractAddress, "deploy(bytes,uint256)", num, false, 0, maxFeeLimit, "0", - 0, contractExcAddress, contractExcKey, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + "," + 1; + txid = + PublicMethod.triggerContract( + contractAddress, + "deploy(bytes,uint256)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -121,12 +146,12 @@ public void test01TriggerContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -137,20 +162,30 @@ public void test01TriggerContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() - .toByteArray(); - String returnAddress = Base58.encode58Check(returnAddressBytes); + returnAddressBytes = + infoById.get().getInternalTransactions(0).getTransferToAddress().toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); - txid = PublicMethod - .triggerContract(returnAddressBytes, "plusOne()", "#", false, 0, maxFeeLimit, "0", 0, - contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + returnAddressBytes, + "plusOne()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; infoById1 = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee1 = infoById1.get().getFee(); - Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); - Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); - Long netFee1 = infoById1.get().getReceipt().getNetFee(); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); logger.info("fee1:" + fee1); @@ -160,12 +195,12 @@ public void test01TriggerContract() { logger.info("energyUsageTotal1:" + energyUsageTotal1); Account infoafter1 = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter1 = PublicMethod - .getAccountResource(contractExcAddress, blockingStubFull); - Long afterBalance1 = infoafter1.getBalance(); - Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); - Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); - Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter1 = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance1); logger.info("afterEnergyUsed:" + afterEnergyUsed1); logger.info("afterNetUsed:" + afterNetUsed1); @@ -174,78 +209,114 @@ public void test01TriggerContract() { Assert.assertTrue(infoById1.get().getResultValue() == 0); Assert.assertTrue(afterBalance1 + fee1 == afterBalance); Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); } - @Test(enabled = true, description = "TriggerConstantContract a non-constant function " - + "created by create2", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "TriggerConstantContract a non-constant function " + "created by create2", + groups = {"contract", "daily"}) public void test16TriggerConstantContract() { String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(returnAddressBytes, "plusOne()", "#", false, 0, - maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + returnAddressBytes, + "plusOne()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); System.out.println("Code = " + transactionExtention.getResult().getCode()); System.out.println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); - Assert - .assertThat(transactionExtention.getResult().getCode().toString(), - containsString("SUCCESS")); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), containsString("SUCCESS")); /*Assert - .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), - containsString("Attempt to call a state modifying opcode inside STATICCALL"));*/ + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Attempt to call a state modifying opcode inside STATICCALL"));*/ } - @Test(enabled = true, description = "TriggerConstantContract a non-constant function " - + "created by create2 on solidity", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "TriggerConstantContract a non-constant function " + "created by create2 on solidity", + groups = {"contract", "daily"}) public void test16TriggerConstantContractOnSolidity() { String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtentionOnSolidity(returnAddressBytes, "plusOne()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubSolidity); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtentionOnSolidity( + returnAddressBytes, + "plusOne()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubSolidity); System.out.println("Code = " + transactionExtention.getResult().getCode()); System.out.println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); - Assert - .assertThat(transactionExtention.getResult().getCode().toString(), - containsString("SUCCESS")); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), containsString("SUCCESS")); /*Assert - .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), - containsString("Attempt to call a state modifying opcode inside STATICCALL"));*/ + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Attempt to call a state modifying opcode inside STATICCALL"));*/ } - @Test(enabled = true, description = "TriggerConstantContract a non-constant function " - + "created by create2 on real solidity", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "TriggerConstantContract a non-constant function " + + "created by create2 on real solidity", + groups = {"contract", "daily"}) public void test16TriggerConstantContractOnRealSolidity() { String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtentionOnSolidity(returnAddressBytes, "plusOne()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubRealSolidity); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtentionOnSolidity( + returnAddressBytes, + "plusOne()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubRealSolidity); System.out.println("Code = " + transactionExtention.getResult().getCode()); System.out.println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); - Assert - .assertThat(transactionExtention.getResult().getCode().toString(), - containsString("SUCCESS")); + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), containsString("SUCCESS")); /*Assert - .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), - containsString("Attempt to call a state modifying opcode inside STATICCALL"));*/ + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Attempt to call a state modifying opcode inside STATICCALL"));*/ } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant015.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant015.java index 1c16a9b4..64f88278 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant015.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant015.java @@ -22,17 +22,17 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant015 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -40,77 +40,96 @@ public class TriggerConstant015 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerConstantContract a constant function " - + "created by create2", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerConstantContract a constant function " + "created by create2", + groups = {"contract", "daily"}) public void testTriggerConstantContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant015.sol"; - String contractName = "Factory"; + String filePath = "src/test/resources/soliditycode/TriggerConstant015.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String contractName1 = "TestConstract"; + String contractName1 = "TestConstract"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - String txid = ""; - String num = "\"" + code1 + "\"" + "," + 1; - txid = PublicMethod - .triggerContract(contractAddress, - "deploy(bytes,uint256)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + "," + 1; + txid = + PublicMethod.triggerContract( + contractAddress, + "deploy(bytes,uint256)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -120,12 +139,12 @@ public void testTriggerConstantContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -136,39 +155,43 @@ public void testTriggerConstantContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() - .toByteArray(); + byte[] returnAddressBytes = + infoById.get().getInternalTransactions(0).getTransferToAddress().toByteArray(); SmartContract smartContract = PublicMethod.getContract(returnAddressBytes, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - String returnAddress = Base58.encode58Check(returnAddressBytes); + String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(returnAddressBytes, - "plusOne()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + returnAddressBytes, + "plusOne()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); - System.out.println(":" + ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println( + ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); System.out.println("Result:" + Hex.toHexString(result)); - Assert.assertEquals(1, ByteArray.toLong(ByteArray - .fromHexString(Hex - .toHexString(result)))); + Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant016.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant016.java index 2ec1ef00..5e8a55c3 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant016.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant016.java @@ -21,17 +21,17 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant016 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -39,77 +39,96 @@ public class TriggerConstant016 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerConstantContract a non-constant function " - + "created by create2", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerConstantContract a non-constant function " + "created by create2", + groups = {"contract", "daily"}) public void testTriggerConstantContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/ClearAbi005.sol"; - String contractName = "Factory"; + String filePath = "src/test/resources/soliditycode/ClearAbi005.sol"; + String contractName = "Factory"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String contractName1 = "TestConstract"; + String contractName1 = "TestConstract"; HashMap retMap1 = PublicMethod.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - String txid = ""; - String num = "\"" + code1 + "\"" + "," + 1; - txid = PublicMethod - .triggerContract(contractAddress, - "deploy(bytes,uint256)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + "," + 1; + txid = + PublicMethod.triggerContract( + contractAddress, + "deploy(bytes,uint256)", + num, + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -119,12 +138,12 @@ public void testTriggerConstantContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -135,36 +154,41 @@ public void testTriggerConstantContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() - .toByteArray(); - String returnAddress = Base58.encode58Check(returnAddressBytes); + byte[] returnAddressBytes = + infoById.get().getInternalTransactions(0).getTransferToAddress().toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(returnAddressBytes, - "plusOne()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + returnAddressBytes, + "plusOne()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); System.out.println("Code = " + transactionExtention.getResult().getCode()); - System.out - .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); - - Assert - .assertThat(transactionExtention.getResult().getCode().toString(), - containsString("CONTRACT_EXE_ERROR")); - Assert - .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), - containsString("Attempt to call a state modifying opcode inside STATICCALL")); + System.out.println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_EXE_ERROR")); + Assert.assertThat( + transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Attempt to call a state modifying opcode inside STATICCALL")); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant017.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant017.java index 79c0dae8..71b2cd25 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant017.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant017.java @@ -21,17 +21,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant017 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -39,75 +39,95 @@ public class TriggerConstant017 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = true, description = "TriggerConstantContract a constant function which is " - + "deployed with ABI, but cleared ABI later", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = + "TriggerConstantContract a constant function which is " + + "deployed with ABI, but cleared ABI later", + groups = {"contract", "daily"}) public void testTriggerConstantContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 100000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "testPayable()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPayable()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); - System.out.println(":" + ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println( + ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); System.out.println("Result:" + Hex.toHexString(result)); - Assert.assertEquals(1, ByteArray.toLong(ByteArray - .fromHexString(Hex - .toHexString(result)))); - String txid = ""; - txid = PublicMethod - .clearContractAbi(contractAddress, contractExcAddress, contractExcKey, blockingStubFull); + Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); + String txid = ""; + txid = + PublicMethod.clearContractAbi( + contractAddress, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); @@ -117,32 +137,36 @@ public void testTriggerConstantContract() { Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - TransactionExtention transactionExtention1 = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "testPayable()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention1 = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testPayable()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Transaction transaction1 = transactionExtention1.getTransaction(); - byte[] result1 = transactionExtention1.getConstantResult(0).toByteArray(); + byte[] result1 = transactionExtention1.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction1.getRet(0).getRet()); - System.out.println(":" + ByteArray - .toStr(transactionExtention1.getResult().getMessage().toByteArray())); + System.out.println( + ":" + ByteArray.toStr(transactionExtention1.getResult().getMessage().toByteArray())); System.out.println("Result:" + Hex.toHexString(result1)); - Assert.assertEquals(1, ByteArray.toLong(ByteArray - .fromHexString(Hex - .toHexString(result1)))); + Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result1)))); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant018.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant018.java index 6a7edcbb..698422c2 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant018.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant018.java @@ -19,17 +19,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant018 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,43 +37,54 @@ public class TriggerConstant018 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerContract a pure function with ABI", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerContract a pure function with ABI", + groups = {"contract", "daily"}) public void testTriggerContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); @@ -81,45 +92,48 @@ public void testTriggerContract() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerContractForExtention(contractAddress, - "testPure()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerContractForExtention( + contractAddress, + "testPure()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); - System.out.println(":" + ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println( + ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); System.out.println("Result:" + Hex.toHexString(result)); - Assert.assertEquals(1, ByteArray.toLong(ByteArray - .fromHexString(Hex - .toHexString(result)))); - + Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant019.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant019.java index 229fcc88..48cde2d3 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant019.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant019.java @@ -18,17 +18,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant019 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -36,43 +36,54 @@ public class TriggerConstant019 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerContract a payable function with ABI", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerContract a payable function with ABI", + groups = {"contract", "daily"}) public void testTriggerContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant001.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/TriggerConstant001.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); @@ -80,30 +91,39 @@ public void testTriggerContract() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - txid = PublicMethod - .triggerContract(contractAddress, - "testPayable()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testPayable()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -113,12 +133,12 @@ public void testTriggerContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -129,22 +149,20 @@ public void testTriggerContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant020.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant020.java index f8f69960..5eeb63a1 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant020.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant020.java @@ -18,17 +18,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant020 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -36,43 +36,54 @@ public class TriggerConstant020 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerContract a non-payable function with ABI", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerContract a non-payable function with ABI", + groups = {"contract", "daily"}) public void testTriggerContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); @@ -80,30 +91,39 @@ public void testTriggerContract() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; - txid = PublicMethod - .triggerContract(contractAddress, - "testNoPayable()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + String txid = ""; + txid = + PublicMethod.triggerContract( + contractAddress, + "testNoPayable()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); @@ -113,12 +133,12 @@ public void testTriggerContract() { logger.info("energyUsageTotal:" + energyUsageTotal); Account infoafter = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -129,22 +149,20 @@ public void testTriggerContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Long returnnumber = + ByteArray.toLong( + ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant021.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant021.java index 69610df9..ba98255d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant021.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant021.java @@ -19,17 +19,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant021 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,43 +37,54 @@ public class TriggerConstant021 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerContract a view function with ABI", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerContract a view function with ABI", + groups = {"contract", "daily"}) public void testTriggerContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant003.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/TriggerConstant003.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); @@ -81,45 +92,48 @@ public void testTriggerContract() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerContractForExtention(contractAddress, - "testView()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerContractForExtention( + contractAddress, + "testView()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); - System.out.println(":" + ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println( + ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); System.out.println("Result:" + Hex.toHexString(result)); - Assert.assertEquals(1, ByteArray.toLong(ByteArray - .fromHexString(Hex - .toHexString(result)))); - + Assert.assertEquals(1, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant022.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant022.java index 04a9e410..2c98bf80 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant022.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant022.java @@ -19,17 +19,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant022 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,48 +37,61 @@ public class TriggerConstant022 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerContract a non-payable function " - + "with ABI(constant ABI)", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerContract a non-payable function " + "with ABI(constant ABI)", + groups = {"contract", "daily"}) public void testTriggerContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = "[{\"constant\":true,\"inputs\":[],\"name\":\"testNoPayable\",\"outputs\":[{\"" - + "name\":\"z\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable" - + "\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"i\",\"outputs\":" - + "[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\"," - + "\"type\":\"function\"}]"; - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = + "[{\"constant\":true,\"inputs\":[],\"name\":\"testNoPayable\"," + + "\"outputs\":[{\"name\":\"z\",\"type\":\"uint256\"}]," + + "\"payable\":false,\"stateMutability\":\"nonpayable\"," + + "\"type\":\"function\"},{\"constant\":true,\"inputs\":[]," + + "\"name\":\"i\",\"outputs\":[{\"name\":\"\"," + + "\"type\":\"uint256\"}],\"payable\":false," + + "\"stateMutability\":\"view\",\"type\":\"function\"}]"; + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); @@ -86,44 +99,48 @@ public void testTriggerContract() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerContractForExtention(contractAddress, - "testNoPayable()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerContractForExtention( + contractAddress, + "testNoPayable()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); System.out.println("Code = " + transactionExtention.getResult().getCode()); - System.out - .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); - - Assert - .assertThat(transactionExtention.getResult().getCode().toString(), - containsString("CONTRACT_EXE_ERROR")); - Assert - .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), - containsString("Attempt to call a state modifying opcode inside STATICCALL")); - + System.out.println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_EXE_ERROR")); + Assert.assertThat( + transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Attempt to call a state modifying opcode inside STATICCALL")); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant023.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant023.java index 6eedb0d1..9dc2ff4b 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant023.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant023.java @@ -19,17 +19,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant023 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -37,48 +37,61 @@ public class TriggerConstant023 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerConstantContract a non-payable function with" - + " ABI(constant ABI )", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerConstantContract a non-payable function with" + " ABI(constant ABI )", + groups = {"contract", "daily"}) public void testTriggerConstantContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = "[{\"constant\":true,\"inputs\":[],\"name\":\"testNoPayable\",\"outputs\":[{\"name" - + "\":\"z\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"" - + "type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"i\",\"outputs\":[{\"na" - + "me\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\"" - + ":\"function\"}]"; - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = + "[{\"constant\":true,\"inputs\":[],\"name\":\"testNoPayable\"," + + "\"outputs\":[{\"name\":\"z\",\"type\":\"uint256\"}]," + + "\"payable\":false,\"stateMutability\":\"nonpayable\"," + + "\"type\":\"function\"},{\"constant\":true,\"inputs\":[]," + + "\"name\":\"i\",\"outputs\":[{\"name\":\"\"," + + "\"type\":\"uint256\"}],\"payable\":false," + + "\"stateMutability\":\"view\",\"type\":\"function\"}]"; + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); @@ -86,44 +99,48 @@ public void testTriggerConstantContract() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "testNoPayable()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testNoPayable()", + "#", + false, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); System.out.println("Code = " + transactionExtention.getResult().getCode()); - System.out - .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); - - Assert - .assertThat(transactionExtention.getResult().getCode().toString(), - containsString("CONTRACT_EXE_ERROR")); - Assert - .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), - containsString("Attempt to call a state modifying opcode inside STATICCALL")); - + System.out.println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + + Assert.assertThat( + transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_EXE_ERROR")); + Assert.assertThat( + transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Attempt to call a state modifying opcode inside STATICCALL")); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant024.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant024.java index fa83f05f..e0a3f40e 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant024.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant024.java @@ -20,17 +20,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant024 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -38,44 +38,54 @@ public class TriggerConstant024 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerConstantContract a view method with ABI ,method has " - + "revert()", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerConstantContract a view method with ABI ,method has " + "revert()", + groups = {"contract", "daily"}) public void testTriggerConstantContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant024.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/TriggerConstant024.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); @@ -83,50 +93,51 @@ public void testTriggerConstantContract() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "testView()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testView()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); - System.out.println(":" + ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray())); - - Assert - .assertThat(transaction.getRet(0).getRet().toString(), - containsString("FAILED")); - Assert - .assertThat(ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray()), - containsString("REVERT opcode executed")); - + System.out.println( + ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); + Assert.assertThat(transaction.getRet(0).getRet().toString(), containsString("FAILED")); + Assert.assertThat( + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray()), + containsString("REVERT opcode executed")); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant025.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant025.java index b8517614..228e342b 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant025.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant025.java @@ -20,17 +20,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant025 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -38,44 +38,54 @@ public class TriggerConstant025 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerContract a view method with ABI ,method has " - + "revert()", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerContract a view method with ABI ,method has " + "revert()", + groups = {"contract", "daily"}) public void testTriggerContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant024.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/TriggerConstant024.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); @@ -83,47 +93,51 @@ public void testTriggerContract() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerContractForExtention(contractAddress, - "testView()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerContractForExtention( + contractAddress, + "testView()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); - System.out.println(":" + ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println( + ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); - Assert.assertThat(transaction.getRet(0).getRet().toString(), - containsString("FAILED")); - Assert.assertThat(ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray()), + Assert.assertThat(transaction.getRet(0).getRet().toString(), containsString("FAILED")); + Assert.assertThat( + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray()), containsString("REVERT opcode executed")); - - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java index aa1867a3..68bd36a9 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java @@ -21,17 +21,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant026 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -39,44 +39,54 @@ public class TriggerConstant026 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerConstantContract a view method without ABI," - + "method has revert()", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerConstantContract a view method without ABI," + "method has revert()", + groups = {"contract", "daily"}) public void testTriggerConstantContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, "[]", code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + "[]", + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); @@ -84,50 +94,52 @@ public void testTriggerConstantContract() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "testView()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testView()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); - System.out.println(":" + ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println( + ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); System.out.println("Result:" + Hex.toHexString(result)); - Assert - .assertThat(transaction.getRet(0).getRet().toString(), - containsString("FAILED")); - Assert - .assertThat(ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray()), - containsString("REVERT opcode executed")); - - + Assert.assertThat(transaction.getRet(0).getRet().toString(), containsString("FAILED")); + Assert.assertThat( + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray()), + containsString("REVERT opcode executed")); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant027.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant027.java index 67cf502b..ba7819ba 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant027.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant027.java @@ -21,17 +21,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TriggerConstant027 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -39,44 +39,54 @@ public class TriggerConstant027 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - } + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + } - @Test(enabled = false, description = "TriggerConstantContract a view method without ABI," - + "method has revert()", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "TriggerConstantContract a view method without ABI," + "method has revert()", + groups = {"contract", "daily"}) public void testTriggerConstantContract() { - Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 1000000000L, + testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; - String contractName = "testConstantContract"; + String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; + String contractName = "testConstantContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethod.deployContract(contractName, "[]", code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = + PublicMethod.deployContract( + contractName, + "[]", + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); @@ -84,50 +94,52 @@ public void testTriggerConstantContract() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); Account info; - AccountResourceMessage resourceInfo = PublicMethod.getAccountResource(contractExcAddress, - blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethod.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, - "testView()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + "testView()", + "#", + false, + 0, + 0, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); - System.out.println(":" + ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println( + ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); System.out.println("Result:" + Hex.toHexString(result)); - Assert - .assertThat(transaction.getRet(0).getRet().toString(), - containsString("FAILED")); - Assert - .assertThat(ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray()), - containsString("REVERT opcode executed")); - - + Assert.assertThat(transaction.getRet(0).getRet().toString(), containsString("FAILED")); + Assert.assertThat( + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray()), + containsString("REVERT opcode executed")); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod - .freeResource(contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); if (channelFull1 != null) { + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } - - + } + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tryCatch/tryCatchTest001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tryCatch/tryCatchTest001.java index b228bccd..4d274de9 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tryCatch/tryCatchTest001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tryCatch/tryCatchTest001.java @@ -13,216 +13,339 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class tryCatchTest001 extends TronBaseTest { - private String testFoundationKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); - private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); + private String testFoundationKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); + private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey1.getAddress(); String testKey001 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private byte[] contractAddress; private byte[] errorContractAddress; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(testKey001); PublicMethod - .sendcoin(testAddress001, 10000_000_000L, testFoundationAddress, testFoundationKey, - blockingStubFull); + PublicMethod.printAddress(testKey001); + PublicMethod.sendcoin( + testAddress001, 10000_000_000L, testFoundationAddress, testFoundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/tryCatch001.sol"; - String contractName = "tryTest"; + String filePath = "src/test/resources/soliditycode/tryCatch001.sol"; + String contractName = "tryTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0, 100, null, - testFoundationKey, testFoundationAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0, + 100, + null, + testFoundationKey, + testFoundationAddress, + blockingStubFull); contractName = "errorContract"; retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - errorContractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0, 100, null, - testFoundationKey, testFoundationAddress, blockingStubFull); + errorContractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0, + 100, + null, + testFoundationKey, + testFoundationAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - } - - @Test(enabled = true, description = "try catch revert no msg", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "try catch revert no msg", + groups = {"contract", "daily"}) public void tryCatchTest001() { String methodStr = "getErrorSwitch(address,uint256)"; - String argStr = "\"" + Base58.encode58Check(errorContractAddress) + "\",0"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = "\"" + Base58.encode58Check(errorContractAddress) + "\",0"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); - Assert.assertEquals("NoErrorMsg", PublicMethod - .getContractStringMsg(transactionInfo.get().getContractResult(0).toByteArray())); - - + Assert.assertEquals( + "NoErrorMsg", + PublicMethod.getContractStringMsg( + transactionInfo.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "try catch revert msg", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "try catch revert msg", + groups = {"contract", "daily"}) public void tryCatchTest002() { String methodStr = "getErrorSwitch(address,uint256)"; - String argStr = "\"" + Base58.encode58Check(errorContractAddress) + "\",1"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = "\"" + Base58.encode58Check(errorContractAddress) + "\",1"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); - Assert.assertEquals("Revert Msg.", PublicMethod - .getContractStringMsg(transactionInfo.get().getContractResult(0).toByteArray())); + Assert.assertEquals( + "Revert Msg.", + PublicMethod.getContractStringMsg( + transactionInfo.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "try catch Require no msg", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "try catch Require no msg", + groups = {"contract", "daily"}) public void tryCatchTest003() { String methodStr = "getErrorSwitch(address,uint256)"; - String argStr = "\"" + Base58.encode58Check(errorContractAddress) + "\",2"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = "\"" + Base58.encode58Check(errorContractAddress) + "\",2"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); - Assert.assertEquals("NoErrorMsg", PublicMethod - .getContractStringMsg(transactionInfo.get().getContractResult(0).toByteArray())); - + Assert.assertEquals( + "NoErrorMsg", + PublicMethod.getContractStringMsg( + transactionInfo.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "try catch Require msg", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "try catch Require msg", + groups = {"contract", "daily"}) public void tryCatchTest004() { String methodStr = "getErrorSwitch(address,uint256)"; - String argStr = "\"" + Base58.encode58Check(errorContractAddress) + "\",3"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = "\"" + Base58.encode58Check(errorContractAddress) + "\",3"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); - Assert.assertEquals("Require Msg.", PublicMethod - .getContractStringMsg(transactionInfo.get().getContractResult(0).toByteArray())); + Assert.assertEquals( + "Require Msg.", + PublicMethod.getContractStringMsg( + transactionInfo.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "try catch assert", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "try catch assert", + groups = {"contract", "daily"}) public void tryCatchTest005() { String methodStr = "getErrorSwitch(address,uint256)"; - String argStr = "\"" + Base58.encode58Check(errorContractAddress) + "\",4"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = "\"" + Base58.encode58Check(errorContractAddress) + "\",4"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(contractResult.SUCCESS, - transactionInfo.get().getReceipt().getResult()); - + Assert.assertEquals(contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); } - @Test(enabled = true, description = "try catch transfer fail", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "try catch transfer fail", + groups = {"contract", "daily"}) public void tryCatchTest006() { String methodStr = "getErrorSwitch(address,uint256)"; - String argStr = "\"" + Base58.encode58Check(errorContractAddress) + "\",5"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = "\"" + Base58.encode58Check(errorContractAddress) + "\",5"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); - Assert.assertEquals("NoErrorMsg", PublicMethod - .getContractStringMsg(transactionInfo.get().getContractResult(0).toByteArray())); - + Assert.assertEquals( + "NoErrorMsg", + PublicMethod.getContractStringMsg( + transactionInfo.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "try catch Send_Error", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "try catch Send_Error", + groups = {"contract", "daily"}) public void tryCatchTest007() { String methodStr = "getErrorSwitch(address,uint256)"; - String argStr = "\"" + Base58.encode58Check(errorContractAddress) + "\",6"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = "\"" + Base58.encode58Check(errorContractAddress) + "\",6"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); - Assert.assertEquals("success", PublicMethod - .getContractStringMsg(transactionInfo.get().getContractResult(0).toByteArray())); - + Assert.assertEquals( + "success", + PublicMethod.getContractStringMsg( + transactionInfo.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "try catch Math_Error", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "try catch Math_Error", + groups = {"contract", "daily"}) public void tryCatchTest008() { String methodStr = "getErrorSwitch(address,uint256)"; - String argStr = "\"" + Base58.encode58Check(errorContractAddress) + "\",7"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = "\"" + Base58.encode58Check(errorContractAddress) + "\",7"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(contractResult.SUCCESS, - transactionInfo.get().getReceipt().getResult()); - + Assert.assertEquals(contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); } - @Test(enabled = true, description = "try catch ArrayOverFlow_Error", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "try catch ArrayOverFlow_Error", + groups = {"contract", "daily"}) public void tryCatchTest009() { String methodStr = "getErrorSwitch(address,uint256)"; - String argStr = "\"" + Base58.encode58Check(errorContractAddress) + "\",8"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = "\"" + Base58.encode58Check(errorContractAddress) + "\",8"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); Assert.assertEquals(0, transactionInfo.get().getResultValue()); - Assert.assertEquals(contractResult.SUCCESS, - transactionInfo.get().getReceipt().getResult()); - + Assert.assertEquals(contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); } - } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tryCatch/tryCatchTest002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tryCatch/tryCatchTest002.java index ac11d3d4..d0ffc758 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tryCatch/tryCatchTest002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tryCatch/tryCatchTest002.java @@ -12,218 +12,322 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class tryCatchTest002 extends TronBaseTest { - private String testFoundationKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); - private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); + private String testFoundationKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); + private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey1.getAddress(); String testKey001 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private byte[] contractAddress; private byte[] errorContractAddress; - /** - * miraculous.wong. - */ - + /** miraculous.wong. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(testKey001); PublicMethod - .sendcoin(testAddress001, 10000_000_000L, testFoundationAddress, testFoundationKey, - blockingStubFull); + PublicMethod.printAddress(testKey001); + PublicMethod.sendcoin( + testAddress001, 10000_000_000L, testFoundationAddress, testFoundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/tryCatch001.sol"; - String contractName = "tryTest"; + String filePath = "src/test/resources/soliditycode/tryCatch001.sol"; + String contractName = "tryTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0, 100, null, - testFoundationKey, testFoundationAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0, + 100, + null, + testFoundationKey, + testFoundationAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - - } - - @Test(enabled = true, description = "try catch [new] revert no msg", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "try catch [new] revert no msg", + groups = {"contract", "daily"}) public void tryCatchTest001() { String methodStr = "catchNewErrorSwitch(uint256)"; - String argStr = "0"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = "0"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); + Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); Assert.assertEquals( "0000000000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "try catch [new] revert msg", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "try catch [new] revert msg", + groups = {"contract", "daily"}) public void tryCatchTest002() { String methodStr = "catchNewErrorSwitch(uint256)"; - String argStr = "1"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = "1"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); + Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); Assert.assertEquals( "0000000000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "try catch [new] Require no msg", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "try catch [new] Require no msg", + groups = {"contract", "daily"}) public void tryCatchTest003() { String methodStr = "catchNewErrorSwitch(uint256)"; - String argStr = "2"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = "2"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); + Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); Assert.assertEquals( "0000000000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); - } - @Test(enabled = true, description = "try catch [new] Require msg", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "try catch [new] Require msg", + groups = {"contract", "daily"}) public void tryCatchTest004() { String methodStr = "catchNewErrorSwitch(uint256)"; - String argStr = "3"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = "3"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); + Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); Assert.assertEquals( "0000000000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "try catch [new] assert", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "try catch [new] assert", + groups = {"contract", "daily"}) public void tryCatchTest005() { String methodStr = "catchNewErrorSwitch(uint256)"; - String argStr = "4"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = "4"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); - Assert.assertEquals(contractResult.SUCCESS, - transactionInfo.get().getReceipt().getResult()); + Assert.assertEquals(0, transactionInfo.get().getResultValue()); + Assert.assertEquals(contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); Assert.assertEquals( "0000000000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "try catch [new] transfer fail", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "try catch [new] transfer fail", + groups = {"contract", "daily"}) public void tryCatchTest006() { String methodStr = "catchNewErrorSwitch(uint256)"; - String argStr = "5"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = "5"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); + Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); Assert.assertEquals( "0000000000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); - } - @Test(enabled = true, description = "try catch [new] Send_Error", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "try catch [new] Send_Error", + groups = {"contract", "daily"}) public void tryCatchTest007() { String methodStr = "catchNewErrorSwitch(uint256)"; - String argStr = "6"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = "6"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); + Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); Assert.assertNotEquals( "0000000000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(transactionInfo.get().getContractResult(0).toByteArray())); - } - @Test(enabled = true, description = "try catch [new] Math_Error", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "try catch [new] Math_Error", + groups = {"contract", "daily"}) public void tryCatchTest008() { String methodStr = "catchNewErrorSwitch(uint256)"; - String argStr = "7"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = "7"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); + Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); - Assert.assertEquals(contractResult.SUCCESS, - transactionInfo.get().getReceipt().getResult()); - + Assert.assertEquals(contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); } - @Test(enabled = true, description = "try catch [new] ArrayOverFlow_Error", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "try catch [new] ArrayOverFlow_Error", + groups = {"contract", "daily"}) public void tryCatchTest009() { String methodStr = "catchNewErrorSwitch(uint256)"; - String argStr = "8"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, argStr, false, - 0, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String argStr = "8"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional transactionInfo = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional transactionInfo = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("transactionInfo: " + transactionInfo.get()); - Assert.assertEquals(0,transactionInfo.get().getResultValue()); + Assert.assertEquals(0, transactionInfo.get().getResultValue()); Assert.assertTrue(transactionInfo.get().getFee() < maxFeeLimit); - Assert.assertEquals(contractResult.SUCCESS, - transactionInfo.get().getReceipt().getResult()); - + Assert.assertEquals(contractResult.SUCCESS, transactionInfo.get().getReceipt().getResult()); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmFreeze/FreezeContractTest001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmFreeze/FreezeContractTest001.java index 2942e97d..98261305 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmFreeze/FreezeContractTest001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmFreeze/FreezeContractTest001.java @@ -17,15 +17,16 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class FreezeContractTest001 extends TronBaseTest { - private String testFoundationKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); - private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); + private String testFoundationKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); + private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey1.getAddress(); String testKey001 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private byte[] contractAddress; @@ -39,333 +40,501 @@ public class FreezeContractTest001 extends TronBaseTest { private byte[] create2Address; private final long freezeCount = 1000_123456L; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() throws Exception { if(PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { throw new SkipException("Skipping freezeV2 test case"); + public void beforeClass() throws Exception { + if (PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + throw new SkipException("Skipping freezeV2 test case"); } - Assert.assertTrue(PublicMethod.sendcoin(testAddress001,2000_000000L, - testFoundationAddress,testFoundationKey,blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(testAddress002,10_000000L, - testFoundationAddress,testFoundationKey,blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(testAddress003,12000_000000L, - testFoundationAddress,testFoundationKey,blockingStubFull)); - String filePath = "src/test/resources/soliditycode/freezeContract001.sol"; - String contractName = "TestFreeze"; + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress001, + 2000_000000L, + testFoundationAddress, + testFoundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress002, + 10_000000L, + testFoundationAddress, + testFoundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress003, + 12000_000000L, + testFoundationAddress, + testFoundationKey, + blockingStubFull)); + String filePath = "src/test/resources/soliditycode/freezeContract001.sol"; + String contractName = "TestFreeze"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 10000_000000L, - 100, null, testFoundationKey, - testFoundationAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 10000_000000L, + 100, + null, + testFoundationKey, + testFoundationAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - - @Test(description = "contract freeze to account", groups = {"contract", "daily"}) + @Test( + description = "contract freeze to account", + groups = {"contract", "daily"}) void FreezeContractTest001() { - AccountResourceMessage account002_before = PublicMethod - .getAccountResource(testAddress002,blockingStubFull); - Account contractAccount_before = PublicMethod.queryAccount(contractAddress,blockingStubFull); - // freeze(address payable receiver, uint amount, uint res) + AccountResourceMessage account002_before = + PublicMethod.getAccountResource(testAddress002, blockingStubFull); + Account contractAccount_before = PublicMethod.queryAccount(contractAddress, blockingStubFull); + // freeze(address payable receiver, uint amount, uint res) String methedStr = "freeze(address,uint256,uint256)"; - String argsStr = "\"" + Base58.encode58Check(testAddress002) + "\"," + freezeCount + "," + "1"; - String txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + String argsStr = "\"" + Base58.encode58Check(testAddress002) + "\"," + freezeCount + "," + "1"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage account002_after = PublicMethod - .getAccountResource(testAddress002,blockingStubFull); + AccountResourceMessage account002_after = + PublicMethod.getAccountResource(testAddress002, blockingStubFull); Account contractAccount_after = PublicMethod.queryAccount(contractAddress, blockingStubFull); logger.info("account002_before.getEnergyLimit : " + account002_before.getEnergyLimit()); logger.info("account002_after.getEnergyLimit : " + account002_after.getEnergyLimit()); Assert.assertTrue(account002_before.getEnergyLimit() < account002_after.getEnergyLimit()); - Assert.assertEquals(contractAccount_before.getAccountResource() - .getDelegatedFrozenBalanceForEnergy() + freezeCount, + Assert.assertEquals( + contractAccount_before.getAccountResource().getDelegatedFrozenBalanceForEnergy() + + freezeCount, contractAccount_after.getAccountResource().getDelegatedFrozenBalanceForEnergy()); - Assert.assertEquals(contractAccount_before.getBalance() - freezeCount, - contractAccount_after.getBalance()); + Assert.assertEquals( + contractAccount_before.getBalance() - freezeCount, contractAccount_after.getBalance()); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); freezeEnergyUseage = info.getReceipt().getEnergyUsageTotal(); - - } - @Test(description = "contract freeze to self", groups = {"contract", "daily"}) + @Test( + description = "contract freeze to self", + groups = {"contract", "daily"}) void FreezeContractTest002() { - AccountResourceMessage contractResource_before = PublicMethod - .getAccountResource(contractAddress,blockingStubFull); - Account contractAccount_before = PublicMethod.queryAccount(contractAddress,blockingStubFull); - // freeze(address payable receiver, uint amount, uint res) + AccountResourceMessage contractResource_before = + PublicMethod.getAccountResource(contractAddress, blockingStubFull); + Account contractAccount_before = PublicMethod.queryAccount(contractAddress, blockingStubFull); + // freeze(address payable receiver, uint amount, uint res) String methedStr = "freeze(address,uint256,uint256)"; - String argsStr = "\"" + Base58.encode58Check(contractAddress) + "\"," + freezeCount + "," + "1"; - String txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + String argsStr = "\"" + Base58.encode58Check(contractAddress) + "\"," + freezeCount + "," + "1"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage contractResource_after = PublicMethod - .getAccountResource(contractAddress,blockingStubFull); + AccountResourceMessage contractResource_after = + PublicMethod.getAccountResource(contractAddress, blockingStubFull); Account contractAccount_after = PublicMethod.queryAccount(contractAddress, blockingStubFull); logger.info("account002_before.getEnergyLimit : " + contractResource_before.getEnergyLimit()); logger.info("account002_after.getEnergyLimit : " + contractResource_after.getEnergyLimit()); Assert.assertTrue( contractResource_before.getEnergyLimit() < contractResource_after.getEnergyLimit()); - Assert.assertEquals(contractAccount_before.getAccountResource() - .getFrozenBalanceForEnergy().getFrozenBalance() + freezeCount, + Assert.assertEquals( + contractAccount_before.getAccountResource().getFrozenBalanceForEnergy().getFrozenBalance() + + freezeCount, contractAccount_after.getAccountResource().getFrozenBalanceForEnergy().getFrozenBalance()); - } - @Test(description = "contract freeze to other contract", groups = {"contract", "daily"}) + @Test( + description = "contract freeze to other contract", + groups = {"contract", "daily"}) void FreezeContractTest003() { String filePath = "src/test/resources/soliditycode/freezeContract001.sol"; - String contractName = "TestFreeze"; + String contractName = "TestFreeze"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] newContract = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 100_000000L, - 100, null, testFoundationKey, - testFoundationAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] newContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 100_000000L, + 100, + null, + testFoundationKey, + testFoundationAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - - Account contractAccount_before = PublicMethod.queryAccount(contractAddress,blockingStubFull); - // freeze(address payable receiver, uint amount, uint res) + Account contractAccount_before = PublicMethod.queryAccount(contractAddress, blockingStubFull); + // freeze(address payable receiver, uint amount, uint res) String methedStr = "freeze(address,uint256,uint256)"; - String argsStr = "\"" + Base58.encode58Check(newContract) + "\"," + freezeCount + "," + "1"; - String txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + String argsStr = "\"" + Base58.encode58Check(newContract) + "\"," + freezeCount + "," + "1"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); - Assert.assertEquals(TransactionInfo.code.FAILED,info.getResult()); + Assert.assertEquals(TransactionInfo.code.FAILED, info.getResult()); - AccountResourceMessage contractResource_after = PublicMethod - .getAccountResource(newContract,blockingStubFull); + AccountResourceMessage contractResource_after = + PublicMethod.getAccountResource(newContract, blockingStubFull); Account contractAccount_after = PublicMethod.queryAccount(contractAddress, blockingStubFull); logger.info("account002_after.getEnergyLimit : " + contractResource_after.getEnergyLimit()); - Assert.assertEquals(contractResource_after.getEnergyLimit(),0); - Assert.assertEquals(contractAccount_before.getAccountResource() - .getDelegatedFrozenBalanceForEnergy(), + Assert.assertEquals(contractResource_after.getEnergyLimit(), 0); + Assert.assertEquals( + contractAccount_before.getAccountResource().getDelegatedFrozenBalanceForEnergy(), contractAccount_after.getAccountResource().getDelegatedFrozenBalanceForEnergy()); - Assert.assertEquals(contractAccount_before.getBalance(),contractAccount_after.getBalance()); - + Assert.assertEquals(contractAccount_before.getBalance(), contractAccount_after.getBalance()); } - @Test(description = "contract freeze to unactive account", - dependsOnMethods = "FreezeContractTest001", groups = {"contract", "daily"}) + @Test( + description = "contract freeze to unactive account", + dependsOnMethods = "FreezeContractTest001", + groups = {"contract", "daily"}) void FreezeContractTest004() { ECKey ecKey = new ECKey(Utils.getRandom()); - byte[] testAddress = ecKey.getAddress(); - String testKey = ByteArray.toHexString(ecKey.getPrivKeyBytes()); + byte[] testAddress = ecKey.getAddress(); + String testKey = ByteArray.toHexString(ecKey.getPrivKeyBytes()); - Account contractAccount_before = PublicMethod.queryAccount(contractAddress,blockingStubFull); - // freeze(address payable receiver, uint amount, uint res) + Account contractAccount_before = PublicMethod.queryAccount(contractAddress, blockingStubFull); + // freeze(address payable receiver, uint amount, uint res) String methedStr = "freeze(address,uint256,uint256)"; - String argsStr = "\"" + Base58.encode58Check(testAddress) + "\"," + freezeCount + "," + "1"; + String argsStr = "\"" + Base58.encode58Check(testAddress) + "\"," + freezeCount + "," + "1"; logger.info("argsStr: " + argsStr); - String txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage account002_after = PublicMethod - .getAccountResource(testAddress,blockingStubFull); + AccountResourceMessage account002_after = + PublicMethod.getAccountResource(testAddress, blockingStubFull); Account contractAccount_after = PublicMethod.queryAccount(contractAddress, blockingStubFull); logger.info("account002_after.getEnergyLimit : " + account002_after.getEnergyLimit()); Assert.assertTrue(account002_after.getEnergyLimit() > 0); - Assert.assertEquals(contractAccount_before.getAccountResource() - .getDelegatedFrozenBalanceForEnergy() + freezeCount, + Assert.assertEquals( + contractAccount_before.getAccountResource().getDelegatedFrozenBalanceForEnergy() + + freezeCount, contractAccount_after.getAccountResource().getDelegatedFrozenBalanceForEnergy()); - Assert.assertEquals(contractAccount_before.getBalance() - freezeCount, - contractAccount_after.getBalance()); - // check active account status - Account testAccount = PublicMethod.queryAccount(testAddress,blockingStubFull); + Assert.assertEquals( + contractAccount_before.getBalance() - freezeCount, contractAccount_after.getBalance()); + // check active account status + Account testAccount = PublicMethod.queryAccount(testAddress, blockingStubFull); Assert.assertTrue(testAccount.getCreateTime() > 0); Assert.assertNotNull(testAccount.getOwnerPermission()); Assert.assertNotNull(testAccount.getActivePermissionList()); - - TransactionInfo info = PublicMethod.getTransactionInfoById(txid,blockingStubFull).get(); + TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); Assert.assertEquals(freezeEnergyUseage + 25000L, info.getReceipt().getEnergyUsageTotal()); - - } - @Test(description = "contract freeze to pre create2 address, and UnFreeze", - dependsOnMethods = "FreezeContractTest001", groups = {"contract", "daily"}) + @Test( + description = "contract freeze to pre create2 address, and UnFreeze", + dependsOnMethods = "FreezeContractTest001", + groups = {"contract", "daily"}) void FreezeContractTest005() { String create2ArgsStr = "1"; - String create2MethedStr = "deploy(uint256)"; - TransactionExtention exten = PublicMethod.triggerConstantContractForExtention( - contractAddress, create2MethedStr, create2ArgsStr, false, 0, maxFeeLimit, - "#", 0, testAddress001, testKey001, blockingStubFull); - String addressHex = - "41" + ByteArray.toHexString(exten.getConstantResult(0).toByteArray()) - .substring(24); + String create2MethedStr = "deploy(uint256)"; + TransactionExtention exten = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + create2MethedStr, + create2ArgsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testAddress001, + testKey001, + blockingStubFull); + String addressHex = + "41" + ByteArray.toHexString(exten.getConstantResult(0).toByteArray()).substring(24); logger.info("address_hex: " + addressHex); create2Address = ByteArray.fromHexString(addressHex); logger.info("create2Address: " + Base58.encode58Check(create2Address)); - - Account contractAccount_before = PublicMethod.queryAccount(contractAddress,blockingStubFull); - // freeze(address payable receiver, uint amount, uint res) + Account contractAccount_before = PublicMethod.queryAccount(contractAddress, blockingStubFull); + // freeze(address payable receiver, uint amount, uint res) String methedStr = "freeze(address,uint256,uint256)"; - String argsStr = "\"" + Base58.encode58Check(create2Address) + "\"," + freezeCount + "," + "1"; + String argsStr = "\"" + Base58.encode58Check(create2Address) + "\"," + freezeCount + "," + "1"; logger.info("argsStr: " + argsStr); - String txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage account002_after = PublicMethod - .getAccountResource(create2Address,blockingStubFull); + AccountResourceMessage account002_after = + PublicMethod.getAccountResource(create2Address, blockingStubFull); Account contractAccount_after = PublicMethod.queryAccount(contractAddress, blockingStubFull); logger.info("account002_after.getEnergyLimit : " + account002_after.getEnergyLimit()); Assert.assertTrue(account002_after.getEnergyLimit() > 0); - Assert.assertEquals(contractAccount_before.getAccountResource() - .getDelegatedFrozenBalanceForEnergy() + freezeCount, + Assert.assertEquals( + contractAccount_before.getAccountResource().getDelegatedFrozenBalanceForEnergy() + + freezeCount, contractAccount_after.getAccountResource().getDelegatedFrozenBalanceForEnergy()); - Assert.assertEquals(contractAccount_before.getBalance() - freezeCount, - contractAccount_after.getBalance()); + Assert.assertEquals( + contractAccount_before.getBalance() - freezeCount, contractAccount_after.getBalance()); - TransactionInfo info = PublicMethod.getTransactionInfoById(txid,blockingStubFull).get(); + TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); Assert.assertEquals(freezeEnergyUseage + 25000L, info.getReceipt().getEnergyUsageTotal()); - txid = PublicMethod.triggerContract(contractAddress,create2MethedStr, - create2ArgsStr,false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + create2MethedStr, + create2ArgsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - - contractAccount_before = PublicMethod.queryAccount(contractAddress,blockingStubFull); - // freeze(address payable receiver, uint amount, uint res) + contractAccount_before = PublicMethod.queryAccount(contractAddress, blockingStubFull); + // freeze(address payable receiver, uint amount, uint res) methedStr = "getExpireTime(address,uint256)"; argsStr = "\"" + Base58.encode58Check(create2Address) + "\"" + ",1"; - TransactionExtention extention = PublicMethod - .triggerConstantContractForExtention(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,"#",0, testAddress001,testKey001,blockingStubFull); - Long ExpireTime = ByteArray.toLong(extention.getConstantResult(0).toByteArray()); + TransactionExtention extention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testAddress001, + testKey001, + blockingStubFull); + Long ExpireTime = ByteArray.toLong(extention.getConstantResult(0).toByteArray()); logger.info("ExpireTime: " + ExpireTime); Assert.assertTrue(ExpireTime > 0); methedStr = "unfreeze(address,uint256)"; - txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); contractAccount_after = PublicMethod.queryAccount(contractAddress, blockingStubFull); - Assert.assertEquals(contractAccount_before.getAccountResource() - .getDelegatedFrozenBalanceForEnergy() - freezeCount, + Assert.assertEquals( + contractAccount_before.getAccountResource().getDelegatedFrozenBalanceForEnergy() + - freezeCount, contractAccount_after.getAccountResource().getDelegatedFrozenBalanceForEnergy()); - Assert.assertEquals(contractAccount_before.getBalance() + freezeCount, - contractAccount_after.getBalance()); - + Assert.assertEquals( + contractAccount_before.getBalance() + freezeCount, contractAccount_after.getBalance()); } - @Test(description = "Unfreeze when freeze to account", - dependsOnMethods = "FreezeContractTest001", groups = {"contract", "daily"}) + @Test( + description = "Unfreeze when freeze to account", + dependsOnMethods = "FreezeContractTest001", + groups = {"contract", "daily"}) void UnFreezeContractTest001() { - AccountResourceMessage account002_before = PublicMethod - .getAccountResource(testAddress002,blockingStubFull); - Account contractAccount_before = PublicMethod.queryAccount(contractAddress,blockingStubFull); - // freeze(address payable receiver, uint amount, uint res) + AccountResourceMessage account002_before = + PublicMethod.getAccountResource(testAddress002, blockingStubFull); + Account contractAccount_before = PublicMethod.queryAccount(contractAddress, blockingStubFull); + // freeze(address payable receiver, uint amount, uint res) String methedStr = "getExpireTime(address,uint256)"; - String argsStr = "\"" + Base58.encode58Check(testAddress002) + "\"" + ",1"; - TransactionExtention extention = PublicMethod - .triggerConstantContractForExtention(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,"#",0, testAddress001,testKey001,blockingStubFull); - Long ExpireTime = ByteArray.toLong(extention.getConstantResult(0).toByteArray()); + String argsStr = "\"" + Base58.encode58Check(testAddress002) + "\"" + ",1"; + TransactionExtention extention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testAddress001, + testKey001, + blockingStubFull); + Long ExpireTime = ByteArray.toLong(extention.getConstantResult(0).toByteArray()); logger.info("ExpireTime: " + ExpireTime); Assert.assertTrue(ExpireTime > 0); methedStr = "unfreeze(address,uint256)"; - String txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage account002_after = PublicMethod - .getAccountResource(testAddress002,blockingStubFull); + AccountResourceMessage account002_after = + PublicMethod.getAccountResource(testAddress002, blockingStubFull); Account contractAccount_after = PublicMethod.queryAccount(contractAddress, blockingStubFull); logger.info("account002_before.getEnergyLimit : " + account002_before.getEnergyLimit()); logger.info("account002_after.getEnergyLimit : " + account002_after.getEnergyLimit()); - Assert.assertEquals(contractAccount_before.getAccountResource() - .getDelegatedFrozenBalanceForEnergy() - freezeCount, + Assert.assertEquals( + contractAccount_before.getAccountResource().getDelegatedFrozenBalanceForEnergy() + - freezeCount, contractAccount_after.getAccountResource().getDelegatedFrozenBalanceForEnergy()); Assert.assertTrue(account002_before.getEnergyLimit() > account002_after.getEnergyLimit()); - } - @Test(description = "Unfreeze when freeze to contract self", - dependsOnMethods = "FreezeContractTest002", groups = {"contract", "daily"}) + @Test( + description = "Unfreeze when freeze to contract self", + dependsOnMethods = "FreezeContractTest002", + groups = {"contract", "daily"}) void UnFreezeContractTest002() { - Account contractAccount_before = PublicMethod.queryAccount(contractAddress,blockingStubFull); - // freeze(address payable receiver, uint amount, uint res) + Account contractAccount_before = PublicMethod.queryAccount(contractAddress, blockingStubFull); + // freeze(address payable receiver, uint amount, uint res) String methedStr = "getExpireTime(address,uint256)"; - String argsStr = "\"" + Base58.encode58Check(contractAddress) + "\"" + ",1"; - TransactionExtention extention = PublicMethod - .triggerConstantContractForExtention(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,"#",0, testAddress001,testKey001,blockingStubFull); - Long ExpireTime = ByteArray.toLong(extention.getConstantResult(0).toByteArray()); + String argsStr = "\"" + Base58.encode58Check(contractAddress) + "\"" + ",1"; + TransactionExtention extention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testAddress001, + testKey001, + blockingStubFull); + Long ExpireTime = ByteArray.toLong(extention.getConstantResult(0).toByteArray()); logger.info("ExpireTime: " + ExpireTime); Assert.assertTrue(ExpireTime > 0); methedStr = "unfreeze(address,uint256)"; - String txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage account002_after = PublicMethod - .getAccountResource(testAddress002,blockingStubFull); + AccountResourceMessage account002_after = + PublicMethod.getAccountResource(testAddress002, blockingStubFull); Account contractAccount_after = PublicMethod.queryAccount(contractAddress, blockingStubFull); logger.info("account002_after.getEnergyLimit : " + account002_after.getEnergyLimit()); - Assert.assertEquals(contractAccount_before.getAccountResource() - .getFrozenBalanceForEnergy().getFrozenBalance() - freezeCount, + Assert.assertEquals( + contractAccount_before.getAccountResource().getFrozenBalanceForEnergy().getFrozenBalance() + - freezeCount, contractAccount_after.getAccountResource().getFrozenBalanceForEnergy().getFrozenBalance()); - - } - @Test(description = "energy caulate after transaction end", groups = {"contract", "daily"}) + @Test( + description = "energy caulate after transaction end", + groups = {"contract", "daily"}) public void freezeEnergyCaulate() { String methedStr = "freeze(address,uint256,uint256)"; - String argsStr = "\"" + Base58.encode58Check(testAddress001) + "\"," + freezeCount + "," + "1"; - String txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + String argsStr = "\"" + Base58.encode58Check(testAddress001) + "\"," + freezeCount + "," + "1"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo info = PublicMethod.getTransactionInfoById(txid,blockingStubFull).get(); - AccountResourceMessage testAccount001 = PublicMethod - .getAccountResource(testAddress001,blockingStubFull); - + TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + AccountResourceMessage testAccount001 = + PublicMethod.getAccountResource(testAddress001, blockingStubFull); Assert.assertTrue(testAccount001.getEnergyLimit() > 0); Assert.assertTrue(info.getReceipt().getEnergyFee() > 0); @@ -373,91 +542,149 @@ public void freezeEnergyCaulate() { methedStr = "unfreeze(address,uint256)"; argsStr = "\"" + Base58.encode58Check(testAddress001) + "\",1"; - txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - info = PublicMethod.getTransactionInfoById(txid,blockingStubFull).get(); - testAccount001 = PublicMethod.getAccountResource(testAddress001,blockingStubFull); - - Assert.assertEquals(code.SUCESS,info.getResult()); - Assert.assertEquals(contractResult.SUCCESS,info.getReceipt().getResult()); + info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + testAccount001 = PublicMethod.getAccountResource(testAddress001, blockingStubFull); + Assert.assertEquals(code.SUCESS, info.getResult()); + Assert.assertEquals(contractResult.SUCCESS, info.getReceipt().getResult()); Assert.assertEquals(0, info.getReceipt().getEnergyFee()); Assert.assertEquals(0, testAccount001.getEnergyLimit()); Assert.assertTrue(testAccount001.getEnergyUsed() > 0); } - @Test(description = "Get Zero Address ExpireTime,used to be that freeze to contract self", - dependsOnMethods = "FreezeContractTest002", groups = {"contract", "daily"}) + @Test( + description = "Get Zero Address ExpireTime,used to be that freeze to contract self", + dependsOnMethods = "FreezeContractTest002", + groups = {"contract", "daily"}) public void getZeroExpireTimeTest() { long startTime = System.currentTimeMillis() - 6 * 1000; - String ExpireTimeMethedStr = "getExpireTime(address,uint256)"; - String ExpireTimeArgsStr = "\"T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb\"" + ",0"; - TransactionExtention extention = PublicMethod - .triggerConstantContractForExtention(contractAddress,ExpireTimeMethedStr,ExpireTimeArgsStr, - false,0,maxFeeLimit,"#",0, testAddress001,testKey001,blockingStubFull); - Long ExpireTime1 = ByteArray.toLong(extention.getConstantResult(0).toByteArray()); + String ExpireTimeMethedStr = "getExpireTime(address,uint256)"; + String ExpireTimeArgsStr = "\"T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb\"" + ",0"; + TransactionExtention extention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + ExpireTimeMethedStr, + ExpireTimeArgsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testAddress001, + testKey001, + blockingStubFull); + Long ExpireTime1 = ByteArray.toLong(extention.getConstantResult(0).toByteArray()); logger.info("ExpireTime1: " + ExpireTime1); - Assert.assertEquals(0,ExpireTime1.longValue()); + Assert.assertEquals(0, ExpireTime1.longValue()); ExpireTimeArgsStr = "\"T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb\"" + ",1"; - extention = PublicMethod - .triggerConstantContractForExtention(contractAddress,ExpireTimeMethedStr,ExpireTimeArgsStr, - false,0,maxFeeLimit,"#",0, testAddress001,testKey001,blockingStubFull); - Long ExpireTime2 = ByteArray.toLong(extention.getConstantResult(0).toByteArray()); + extention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + ExpireTimeMethedStr, + ExpireTimeArgsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testAddress001, + testKey001, + blockingStubFull); + Long ExpireTime2 = ByteArray.toLong(extention.getConstantResult(0).toByteArray()); logger.info("ExpireTime2: " + ExpireTime2); - Assert.assertEquals(0,ExpireTime2.longValue()); - // freeze(address payable receiver, uint amount, uint res) + Assert.assertEquals(0, ExpireTime2.longValue()); + // freeze(address payable receiver, uint amount, uint res) String methedStr = "freeze(address,uint256,uint256)"; - String argsStr = "\"" + "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb" + "\"," + freezeCount + "," + "1"; - String txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + String argsStr = "\"" + "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb" + "\"," + freezeCount + "," + "1"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); - Assert.assertEquals(code.SUCESS,info.getResult()); - Assert.assertEquals(contractResult.SUCCESS,info.getReceipt().getResult()); - - extention = PublicMethod - .triggerConstantContractForExtention(contractAddress,ExpireTimeMethedStr,ExpireTimeArgsStr, - false,0,maxFeeLimit,"#",0, testAddress001,testKey001,blockingStubFull); - Long ExpireTime = ByteArray.toLong(extention.getConstantResult(0).toByteArray()); + Assert.assertEquals(code.SUCESS, info.getResult()); + Assert.assertEquals(contractResult.SUCCESS, info.getReceipt().getResult()); + + extention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + ExpireTimeMethedStr, + ExpireTimeArgsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testAddress001, + testKey001, + blockingStubFull); + Long ExpireTime = ByteArray.toLong(extention.getConstantResult(0).toByteArray()); logger.info("ExpireTime: " + ExpireTime + " nextBlockTimeStamp: " + info.getBlockTimeStamp()); Assert.assertTrue(ExpireTime * 1000 <= info.getBlockTimeStamp()); Assert.assertTrue(ExpireTime * 1000 > startTime); - } - @Test(description = "freeze in constructor", groups = {"contract", "daily"}) + @Test( + description = "freeze in constructor", + groups = {"contract", "daily"}) public void FreezeContractTest006() { - AccountResourceMessage account003_before = PublicMethod - .getAccountResource(testAddress003,blockingStubFull); - String filePath = "src/test/resources/soliditycode/freezeContract001.sol"; - String contractName = "D"; + AccountResourceMessage account003_before = + PublicMethod.getAccountResource(testAddress003, blockingStubFull); + String filePath = "src/test/resources/soliditycode/freezeContract001.sol"; + String contractName = "D"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); long callValue = 10000_000000L; - byte[] contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, callValue, - 100, null, testKey003, - testAddress003, blockingStubFull); + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + callValue, + 100, + null, + testKey003, + testAddress003, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage account003_after = PublicMethod - .getAccountResource(testAddress003,blockingStubFull); + AccountResourceMessage account003_after = + PublicMethod.getAccountResource(testAddress003, blockingStubFull); Account contractAccount_after = PublicMethod.queryAccount(contractAddress, blockingStubFull); logger.info("account002_before.getEnergyLimit : " + account003_before.getEnergyLimit()); logger.info("account002_after.getEnergyLimit : " + account003_after.getEnergyLimit()); Assert.assertTrue(account003_before.getEnergyLimit() < account003_after.getEnergyLimit()); - Assert.assertEquals(callValue, - contractAccount_after.getAccountResource().getDelegatedFrozenBalanceForEnergy()); + Assert.assertEquals( + callValue, contractAccount_after.getAccountResource().getDelegatedFrozenBalanceForEnergy()); Assert.assertEquals(0, contractAccount_after.getBalance()); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmFreeze/FreezeContractTest002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmFreeze/FreezeContractTest002.java index cd305639..1d541e85 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmFreeze/FreezeContractTest002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmFreeze/FreezeContractTest002.java @@ -17,15 +17,16 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class FreezeContractTest002 extends TronBaseTest { - private String testFoundationKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); - private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); + private String testFoundationKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); + private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey1.getAddress(); String testKey001 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private byte[] contractAddress; @@ -34,84 +35,121 @@ public class FreezeContractTest002 extends TronBaseTest { String testKey002 = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); private long freezeEnergyUseage; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() throws Exception { if(PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { throw new SkipException("Skipping freezeV2 test case"); + public void beforeClass() throws Exception { + if (PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + throw new SkipException("Skipping freezeV2 test case"); } - - Assert.assertTrue(PublicMethod.sendcoin(testAddress001,2000_000000L, - testFoundationAddress,testFoundationKey,blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(testAddress002,10_000000L, - testFoundationAddress,testFoundationKey,blockingStubFull)); - String filePath = "src/test/resources/soliditycode/freezeContract001.sol"; - String contractName = "TestFreeze"; + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress001, + 2000_000000L, + testFoundationAddress, + testFoundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress002, + 10_000000L, + testFoundationAddress, + testFoundationKey, + blockingStubFull)); + String filePath = "src/test/resources/soliditycode/freezeContract001.sol"; + String contractName = "TestFreeze"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 100_000000L, - 100, null, testFoundationKey, - testFoundationAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 100_000000L, + 100, + null, + testFoundationKey, + testFoundationAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "contract freeze over balance", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "contract freeze over balance", + groups = {"contract", "daily"}) void FreezeContract001() { - AccountResourceMessage account002_before = PublicMethod - .getAccountResource(testAddress002,blockingStubFull); - Account contractAccount_before = PublicMethod.queryAccount(contractAddress,blockingStubFull); - // freeze(address payable receiver, uint amount, uint res) + AccountResourceMessage account002_before = + PublicMethod.getAccountResource(testAddress002, blockingStubFull); + Account contractAccount_before = PublicMethod.queryAccount(contractAddress, blockingStubFull); + // freeze(address payable receiver, uint amount, uint res) Long freezeCount = contractAccount_before.getBalance() + 1; - String methedStr = "freeze(address,uint256,uint256)"; - String argsStr = "\"" + Base58.encode58Check(testAddress002) + "\"," + freezeCount + "," + "1"; - String txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + String methedStr = "freeze(address,uint256,uint256)"; + String argsStr = "\"" + Base58.encode58Check(testAddress002) + "\"," + freezeCount + "," + "1"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage account002_after = PublicMethod - .getAccountResource(testAddress002,blockingStubFull); + AccountResourceMessage account002_after = + PublicMethod.getAccountResource(testAddress002, blockingStubFull); Account contractAccount_after = PublicMethod.queryAccount(contractAddress, blockingStubFull); logger.info("account002_before.getEnergyLimit : " + account002_before.getEnergyLimit()); logger.info("account002_after.getEnergyLimit : " + account002_after.getEnergyLimit()); Assert.assertEquals(account002_before.getEnergyLimit(), account002_after.getEnergyLimit()); - Assert.assertEquals(contractAccount_before.getAccountResource() - .getDelegatedFrozenBalanceForEnergy(), + Assert.assertEquals( + contractAccount_before.getAccountResource().getDelegatedFrozenBalanceForEnergy(), contractAccount_after.getAccountResource().getDelegatedFrozenBalanceForEnergy()); - Assert.assertEquals(contractAccount_before.getBalance(), - contractAccount_after.getBalance()); + Assert.assertEquals(contractAccount_before.getBalance(), contractAccount_after.getBalance()); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); freezeEnergyUseage = info.getReceipt().getEnergyUsageTotal(); - Assert.assertEquals(code.FAILED,info.getResult()); - Assert.assertEquals(contractResult.REVERT,info.getReceipt().getResult()); - + Assert.assertEquals(code.FAILED, info.getResult()); + Assert.assertEquals(contractResult.REVERT, info.getReceipt().getResult()); } - @Test(enabled = true, description = "contract freeze amount < 1 TRX", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "contract freeze amount < 1 TRX", + groups = {"contract", "daily"}) void FreezeContract002() { - Account account002_before = PublicMethod - .queryAccount(testAddress002,blockingStubFull); - Account contractAccount_before = PublicMethod.queryAccount(contractAddress,blockingStubFull); - // freeze(address payable receiver, uint amount, uint res) + Account account002_before = PublicMethod.queryAccount(testAddress002, blockingStubFull); + Account contractAccount_before = PublicMethod.queryAccount(contractAddress, blockingStubFull); + // freeze(address payable receiver, uint amount, uint res) Long freezeCount = 999999L; - String methedStr = "freeze(address,uint256,uint256)"; - String argsStr = "\"" + Base58.encode58Check(testAddress002) + "\"," + freezeCount + "," + "1"; - String txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + String methedStr = "freeze(address,uint256,uint256)"; + String argsStr = "\"" + Base58.encode58Check(testAddress002) + "\"," + freezeCount + "," + "1"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Account account002_after = PublicMethod - .queryAccount(testAddress002,blockingStubFull); + Account account002_after = PublicMethod.queryAccount(testAddress002, blockingStubFull); Account contractAccount_after = PublicMethod.queryAccount(contractAddress, blockingStubFull); logger.info("account002_before.getAccountResource : " + account002_before.getAccountResource()); logger.info("account002_after.getAccountResource : " + account002_after.getAccountResource()); @@ -119,121 +157,180 @@ void FreezeContract002() { Assert.assertEquals( account002_before.getAccountResource().getAcquiredDelegatedFrozenBalanceForEnergy(), account002_after.getAccountResource().getAcquiredDelegatedFrozenBalanceForEnergy()); - Assert.assertEquals(contractAccount_before.getAccountResource() - .getDelegatedFrozenBalanceForEnergy(), + Assert.assertEquals( + contractAccount_before.getAccountResource().getDelegatedFrozenBalanceForEnergy(), contractAccount_after.getAccountResource().getDelegatedFrozenBalanceForEnergy()); - Assert.assertEquals(contractAccount_before.getBalance(), - contractAccount_after.getBalance()); - + Assert.assertEquals(contractAccount_before.getBalance(), contractAccount_after.getBalance()); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); freezeEnergyUseage = info.getReceipt().getEnergyUsageTotal(); - Assert.assertEquals(code.FAILED,info.getResult()); - Assert.assertEquals(contractResult.REVERT,info.getReceipt().getResult()); - + Assert.assertEquals(code.FAILED, info.getResult()); + Assert.assertEquals(contractResult.REVERT, info.getReceipt().getResult()); } - @Test(enabled = true, description = "contract transfer all balance, then freeze", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "contract transfer all balance, then freeze", + groups = {"contract", "daily"}) void FreezeContract003() { - AccountResourceMessage account002_before = PublicMethod - .getAccountResource(testAddress002,blockingStubFull); - Account contractAccount_before = PublicMethod.queryAccount(contractAddress,blockingStubFull); - // freeze(address payable receiver, uint amount, uint res) + AccountResourceMessage account002_before = + PublicMethod.getAccountResource(testAddress002, blockingStubFull); + Account contractAccount_before = PublicMethod.queryAccount(contractAddress, blockingStubFull); + // freeze(address payable receiver, uint amount, uint res) Long freezeCount = contractAccount_before.getBalance(); - String methedStr = "freezeAndSend(address,uint256,uint256)"; - String argsStr = "\"" + Base58.encode58Check(testAddress002) + "\"," + freezeCount + "," + "1"; - String txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + String methedStr = "freezeAndSend(address,uint256,uint256)"; + String argsStr = "\"" + Base58.encode58Check(testAddress002) + "\"," + freezeCount + "," + "1"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage account002_after = PublicMethod - .getAccountResource(testAddress002,blockingStubFull); + AccountResourceMessage account002_after = + PublicMethod.getAccountResource(testAddress002, blockingStubFull); Account contractAccount_after = PublicMethod.queryAccount(contractAddress, blockingStubFull); logger.info("account002_before.getEnergyLimit : " + account002_before.getEnergyLimit()); logger.info("account002_after.getEnergyLimit : " + account002_after.getEnergyLimit()); Assert.assertEquals(account002_before.getEnergyLimit(), account002_after.getEnergyLimit()); - Assert.assertEquals(contractAccount_before.getAccountResource() - .getDelegatedFrozenBalanceForEnergy(), + Assert.assertEquals( + contractAccount_before.getAccountResource().getDelegatedFrozenBalanceForEnergy(), contractAccount_after.getAccountResource().getDelegatedFrozenBalanceForEnergy()); - Assert.assertEquals(contractAccount_before.getBalance(), - contractAccount_after.getBalance()); + Assert.assertEquals(contractAccount_before.getBalance(), contractAccount_after.getBalance()); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); freezeEnergyUseage = info.getReceipt().getEnergyUsageTotal(); - Assert.assertEquals(code.FAILED,info.getResult()); - Assert.assertEquals(contractResult.REVERT,info.getReceipt().getResult()); + Assert.assertEquals(code.FAILED, info.getResult()); + Assert.assertEquals(contractResult.REVERT, info.getReceipt().getResult()); } - @Test(enabled = true, description = "contract freeze to ger Net", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "contract freeze to ger Net", + groups = {"contract", "daily"}) void FreezeContract004() { - AccountResourceMessage account002_before = PublicMethod - .getAccountResource(testAddress002,blockingStubFull); - Account contractAccount_before = PublicMethod.queryAccount(contractAddress,blockingStubFull); - // freeze(address payable receiver, uint amount, uint res) + AccountResourceMessage account002_before = + PublicMethod.getAccountResource(testAddress002, blockingStubFull); + Account contractAccount_before = PublicMethod.queryAccount(contractAddress, blockingStubFull); + // freeze(address payable receiver, uint amount, uint res) Long freezeCount = 1_000000L; - String methedStr = "freeze(address,uint256,uint256)"; - String argsStr = "\"" + Base58.encode58Check(testAddress002) + "\"," + freezeCount + "," + "0"; - String txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + String methedStr = "freeze(address,uint256,uint256)"; + String argsStr = "\"" + Base58.encode58Check(testAddress002) + "\"," + freezeCount + "," + "0"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage account002_after = PublicMethod - .getAccountResource(testAddress002,blockingStubFull); + AccountResourceMessage account002_after = + PublicMethod.getAccountResource(testAddress002, blockingStubFull); Account contractAccount_after = PublicMethod.queryAccount(contractAddress, blockingStubFull); logger.info("account002_before.getNetLimit : " + account002_before.getNetLimit()); logger.info("account002_after.getNetLimit : " + account002_after.getNetLimit()); Assert.assertTrue(account002_before.getNetLimit() < account002_after.getNetLimit()); - Assert.assertEquals(contractAccount_before - .getDelegatedFrozenBalanceForBandwidth() + freezeCount, + Assert.assertEquals( + contractAccount_before.getDelegatedFrozenBalanceForBandwidth() + freezeCount, contractAccount_after.getDelegatedFrozenBalanceForBandwidth()); - Assert.assertEquals(contractAccount_before.getBalance() - freezeCount, - contractAccount_after.getBalance()); + Assert.assertEquals( + contractAccount_before.getBalance() - freezeCount, contractAccount_after.getBalance()); } - @Test(enabled = true, description = "contract freeze to ger Net", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "contract freeze to ger Net", + groups = {"contract", "daily"}) void FreezeContract005() { long startTime = System.currentTimeMillis() - 6 * 1000; - // freeze(address payable receiver, uint amount, uint res) + // freeze(address payable receiver, uint amount, uint res) Long freezeCount = 1000000L; - String methedStr = "freeze(address,uint256,uint256)"; - String argsStr = "\"" + Base58.encode58Check(testAddress001) + "\"," + freezeCount + "," + "1"; - String txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + String methedStr = "freeze(address,uint256,uint256)"; + String argsStr = "\"" + Base58.encode58Check(testAddress001) + "\"," + freezeCount + "," + "1"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - // freeze(address payable receiver, uint amount, uint res) + // freeze(address payable receiver, uint amount, uint res) String ExpireTimeMethedStr = "getExpireTime(address,uint256)"; - String ExpireTimeArgsStr = "\"" + Base58.encode58Check(testAddress001) + "\"" + ",1"; - TransactionExtention extention = PublicMethod - .triggerConstantContractForExtention(contractAddress,ExpireTimeMethedStr,ExpireTimeArgsStr, - false,0,maxFeeLimit,"#",0, testAddress001,testKey001,blockingStubFull); - Long ExpireTime1 = ByteArray.toLong(extention.getConstantResult(0).toByteArray()); + String ExpireTimeArgsStr = "\"" + Base58.encode58Check(testAddress001) + "\"" + ",1"; + TransactionExtention extention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + ExpireTimeMethedStr, + ExpireTimeArgsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testAddress001, + testKey001, + blockingStubFull); + Long ExpireTime1 = ByteArray.toLong(extention.getConstantResult(0).toByteArray()); logger.info("ExpireTime1: " + ExpireTime1); - txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); freezeEnergyUseage = info.getReceipt().getEnergyUsageTotal(); - Assert.assertEquals(code.SUCESS,info.getResult()); - Assert.assertEquals(contractResult.SUCCESS,info.getReceipt().getResult()); - - extention = PublicMethod - .triggerConstantContractForExtention(contractAddress,ExpireTimeMethedStr,ExpireTimeArgsStr, - false,0,maxFeeLimit,"#",0, testAddress001, testKey001, blockingStubFull); - Long ExpireTime2 = ByteArray.toLong(extention.getConstantResult(0).toByteArray()); + Assert.assertEquals(code.SUCESS, info.getResult()); + Assert.assertEquals(contractResult.SUCCESS, info.getReceipt().getResult()); + + extention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + ExpireTimeMethedStr, + ExpireTimeArgsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testAddress001, + testKey001, + blockingStubFull); + Long ExpireTime2 = ByteArray.toLong(extention.getConstantResult(0).toByteArray()); logger.info("ExpireTime2: " + ExpireTime2); Assert.assertTrue(ExpireTime2 * 1000 <= info.getBlockTimeStamp()); Assert.assertTrue(ExpireTime2 * 1000 > startTime); } - - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmFreeze/FreezeSuicideTest001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmFreeze/FreezeSuicideTest001.java index 22f38bff..6d526ced 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmFreeze/FreezeSuicideTest001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmFreeze/FreezeSuicideTest001.java @@ -17,15 +17,16 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class FreezeSuicideTest001 extends TronBaseTest { - private String testFoundationKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); - private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); + private String testFoundationKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); + private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey1.getAddress(); String testKey001 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private byte[] contractAddress; @@ -37,213 +38,350 @@ public class FreezeSuicideTest001 extends TronBaseTest { private byte[] create2Address; private final Long freezeCount = 1000_000000L; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() throws Exception{ if(PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { throw new SkipException("Skipping freezeV2 test case"); + public void beforeClass() throws Exception { + if (PublicMethod.freezeV2ProposalIsOpen(blockingStubFull)) { + throw new SkipException("Skipping freezeV2 test case"); } - Assert.assertTrue(PublicMethod.sendcoin(testAddress001,2000_000000L, - testFoundationAddress,testFoundationKey,blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(testAddress002,200_0000_000000L, - testFoundationAddress,testFoundationKey,blockingStubFull)); - String filePath = "src/test/resources/soliditycode/freezeContract001.sol"; - String contractName = "TestFreeze"; + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress001, + 2000_000000L, + testFoundationAddress, + testFoundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress002, + 200_0000_000000L, + testFoundationAddress, + testFoundationKey, + blockingStubFull)); + String filePath = "src/test/resources/soliditycode/freezeContract001.sol"; + String contractName = "TestFreeze"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); callValue = 50000_000000L; - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, callValue, - 100, null, testFoundationKey, - testFoundationAddress, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + callValue, + 100, + null, + testFoundationKey, + testFoundationAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(testAddress002, - 100_0000_000000L,0,0,testKey002,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + testAddress002, 100_0000_000000L, 0, 0, testKey002, blockingStubFull)); } - @Test(enabled = true, description = "when delegate freeze, cannot suicide", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "when delegate freeze, cannot suicide", + groups = {"contract", "daily"}) public void FreezeSuicideTest001() { - Account contractAccount_before = PublicMethod.queryAccount(contractAddress,blockingStubFull); - // freeze(address payable receiver, uint amount, uint res) + Account contractAccount_before = PublicMethod.queryAccount(contractAddress, blockingStubFull); + // freeze(address payable receiver, uint amount, uint res) String methedStr = "freeze(address,uint256,uint256)"; - String argsStr = "\"" + Base58.encode58Check(testAddress002) + "\"," + freezeCount + "," + "1"; - String txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + String argsStr = "\"" + Base58.encode58Check(testAddress002) + "\"," + freezeCount + "," + "1"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account contractAccount_after = PublicMethod.queryAccount(contractAddress, blockingStubFull); - Assert.assertEquals(contractAccount_before.getAccountResource() - .getDelegatedFrozenBalanceForEnergy() + freezeCount, + Assert.assertEquals( + contractAccount_before.getAccountResource().getDelegatedFrozenBalanceForEnergy() + + freezeCount, contractAccount_after.getAccountResource().getDelegatedFrozenBalanceForEnergy()); - Assert.assertEquals(contractAccount_before.getBalance() - freezeCount, - contractAccount_after.getBalance()); + Assert.assertEquals( + contractAccount_before.getBalance() - freezeCount, contractAccount_after.getBalance()); methedStr = "destroy(address)"; argsStr = "\"" + Base58.encode58Check(testAddress002) + "\""; - txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo info = PublicMethod.getTransactionInfoById(txid,blockingStubFull).get(); - Assert.assertEquals(code.FAILED,info.getResult()); - Assert.assertEquals(contractResult.REVERT,info.getReceipt().getResult()); - + TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Assert.assertEquals(code.FAILED, info.getResult()); + Assert.assertEquals(contractResult.REVERT, info.getReceipt().getResult()); methedStr = "unfreeze(address,uint256)"; argsStr = "\"" + Base58.encode58Check(testAddress002) + "\"," + "1"; - PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); } - @Test(enabled = true, description = "when delegate freeze to self, then suicide", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "when delegate freeze to self, then suicide", + groups = {"contract", "daily"}) public void FreezeSuicideTest002() { - Account contractAccount_before = PublicMethod.queryAccount(contractAddress,blockingStubFull); - AccountResourceMessage freezeAccount_before = PublicMethod - .getAccountResource(testAddress002,blockingStubFull); - // freeze(address payable receiver, uint amount, uint res) + Account contractAccount_before = PublicMethod.queryAccount(contractAddress, blockingStubFull); + AccountResourceMessage freezeAccount_before = + PublicMethod.getAccountResource(testAddress002, blockingStubFull); + // freeze(address payable receiver, uint amount, uint res) String methedStr = "freeze(address,uint256,uint256)"; - String argsStr = "\"" + Base58.encode58Check(contractAddress) + "\"," + freezeCount + "," + "0"; - String txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + String argsStr = "\"" + Base58.encode58Check(contractAddress) + "\"," + freezeCount + "," + "0"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - AccountResourceMessage freezeAccount_after = PublicMethod - .getAccountResource(testAddress002,blockingStubFull); + AccountResourceMessage freezeAccount_after = + PublicMethod.getAccountResource(testAddress002, blockingStubFull); Account contractAccount_after = PublicMethod.queryAccount(contractAddress, blockingStubFull); - Assert.assertEquals(freezeCount.longValue(), - contractAccount_after.getFrozen(0).getFrozenBalance()); - Assert.assertEquals(contractAccount_before.getBalance() - freezeCount, - contractAccount_after.getBalance()); + Assert.assertEquals( + freezeCount.longValue(), contractAccount_after.getFrozen(0).getFrozenBalance()); + Assert.assertEquals( + contractAccount_before.getBalance() - freezeCount, contractAccount_after.getBalance()); logger.info("freezeAccount_before.getNetLimit : " + freezeAccount_before.getNetLimit()); logger.info("freezeAccount_after.getNetLimit : " + freezeAccount_after.getNetLimit()); Assert.assertTrue(freezeAccount_after.getNetLimit() < freezeAccount_before.getNetLimit()); - Long beforeBalance = PublicMethod.queryAccount(testAddress002,blockingStubFull).getBalance(); + Long beforeBalance = PublicMethod.queryAccount(testAddress002, blockingStubFull).getBalance(); methedStr = "destroy(address)"; argsStr = "\"" + Base58.encode58Check(testAddress002) + "\""; - txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo info = PublicMethod.getTransactionInfoById(txid,blockingStubFull).get(); - Assert.assertEquals(code.SUCESS,info.getResult()); - Assert.assertEquals(contractResult.SUCCESS,info.getReceipt().getResult()); + TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Assert.assertEquals(code.SUCESS, info.getResult()); + Assert.assertEquals(contractResult.SUCCESS, info.getReceipt().getResult()); - freezeAccount_after = PublicMethod - .getAccountResource(testAddress002,blockingStubFull); - Assert.assertEquals(freezeAccount_before.getNetLimit(), - freezeAccount_after.getNetLimit()); - Long AfterBalance = PublicMethod.queryAccount(testAddress002,blockingStubFull).getBalance(); + freezeAccount_after = PublicMethod.getAccountResource(testAddress002, blockingStubFull); + Assert.assertEquals(freezeAccount_before.getNetLimit(), freezeAccount_after.getNetLimit()); + Long AfterBalance = PublicMethod.queryAccount(testAddress002, blockingStubFull).getBalance(); Assert.assertEquals(beforeBalance + callValue, AfterBalance.longValue()); - - } - @Test(enabled = true, description = "suicide、freeze、unfreeze、getExpireTime " - + "with suicided create2 address", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "suicide、freeze、unfreeze、getExpireTime " + "with suicided create2 address", + groups = {"contract", "daily"}) public void FreezeSuicideTest003() { String filePath = "src/test/resources/soliditycode/freezeContract001.sol"; - String contractName = "TestFreeze"; + String contractName = "TestFreeze"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String bytecode = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String bytecode = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); callValue = 10000_000000L; - contractAddress = PublicMethod - .deployContract(contractName, abi, bytecode, "", maxFeeLimit, callValue, - 100, null, testFoundationKey, - testFoundationAddress, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + bytecode, + "", + maxFeeLimit, + callValue, + 100, + null, + testFoundationKey, + testFoundationAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - // triggerconstant create2 function, and get create2 Address + // triggerconstant create2 function, and get create2 Address String create2ArgsStr = "1"; - String create2MethedStr = "deploy(uint256)"; - TransactionExtention exten = PublicMethod.triggerConstantContractForExtention( - contractAddress, create2MethedStr, create2ArgsStr, false, 0, maxFeeLimit, - "#", 0, testAddress001, testKey001, blockingStubFull); - String addressHex = - "41" + ByteArray.toHexString(exten.getConstantResult(0).toByteArray()) - .substring(24); + String create2MethedStr = "deploy(uint256)"; + TransactionExtention exten = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + create2MethedStr, + create2ArgsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testAddress001, + testKey001, + blockingStubFull); + String addressHex = + "41" + ByteArray.toHexString(exten.getConstantResult(0).toByteArray()).substring(24); logger.info("address_hex: " + addressHex); create2Address = ByteArray.fromHexString(addressHex); logger.info("create2Address: " + Base58.encode58Check(create2Address)); - // freeze to create2 Address, active create2 address + // freeze to create2 Address, active create2 address String methedStr = "freeze(address,uint256,uint256)"; - String argsStr = "\"" + Base58.encode58Check(create2Address) + "\"," + freezeCount + "," + "1"; + String argsStr = "\"" + Base58.encode58Check(create2Address) + "\"," + freezeCount + "," + "1"; logger.info("argsStr: " + argsStr); - String txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - TransactionInfo info = PublicMethod.getTransactionInfoById(txid,blockingStubFull).get(); - Assert.assertEquals(code.SUCESS,info.getResult()); - Assert.assertEquals(contractResult.SUCCESS,info.getReceipt().getResult()); - // create2 contract Address, turn create2 address to contract type - txid = PublicMethod.triggerContract(contractAddress,create2MethedStr, - create2ArgsStr,false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + TransactionInfo info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Assert.assertEquals(code.SUCESS, info.getResult()); + Assert.assertEquals(contractResult.SUCCESS, info.getReceipt().getResult()); + // create2 contract Address, turn create2 address to contract type + txid = + PublicMethod.triggerContract( + contractAddress, + create2MethedStr, + create2ArgsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - info = PublicMethod.getTransactionInfoById(txid,blockingStubFull).get(); - Assert.assertEquals(code.SUCESS,info.getResult()); - Assert.assertEquals(contractResult.SUCCESS,info.getReceipt().getResult()); - // create2 contract suicide + info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Assert.assertEquals(code.SUCESS, info.getResult()); + Assert.assertEquals(contractResult.SUCCESS, info.getReceipt().getResult()); + // create2 contract suicide methedStr = "destroy(address)"; argsStr = "\"" + Base58.encode58Check(testAddress002) + "\""; - txid = PublicMethod.triggerContract(create2Address,methedStr,argsStr,false,0, - maxFeeLimit,testAddress001,testKey001,blockingStubFull); + txid = + PublicMethod.triggerContract( + create2Address, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - info = PublicMethod.getTransactionInfoById(txid,blockingStubFull).get(); - Assert.assertEquals(code.SUCESS,info.getResult()); - Assert.assertEquals(contractResult.SUCCESS,info.getReceipt().getResult()); - // get create2 account ExpireTime + info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Assert.assertEquals(code.SUCESS, info.getResult()); + Assert.assertEquals(contractResult.SUCCESS, info.getReceipt().getResult()); + // get create2 account ExpireTime methedStr = "getExpireTime(address,uint256)"; argsStr = "\"" + Base58.encode58Check(create2Address) + "\"" + ",1"; - TransactionExtention extention = PublicMethod - .triggerConstantContractForExtention(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,"#",0, testAddress001,testKey001,blockingStubFull); - Long ExpireTime = ByteArray.toLong(extention.getConstantResult(0).toByteArray()); + TransactionExtention extention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + "#", + 0, + testAddress001, + testKey001, + blockingStubFull); + Long ExpireTime = ByteArray.toLong(extention.getConstantResult(0).toByteArray()); logger.info("ExpireTime: " + ExpireTime); Assert.assertTrue(ExpireTime > 0); - // suicide FreezeTest contract, and should be failed + // suicide FreezeTest contract, and should be failed methedStr = "destroy(address)"; argsStr = "\"" + Base58.encode58Check(testAddress002) + "\""; - txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr,false,0, - maxFeeLimit,testAddress001,testKey001,blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - info = PublicMethod.getTransactionInfoById(txid,blockingStubFull).get(); - Assert.assertEquals(code.FAILED,info.getResult()); - Assert.assertEquals(contractResult.REVERT,info.getReceipt().getResult()); + info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Assert.assertEquals(code.FAILED, info.getResult()); + Assert.assertEquals(contractResult.REVERT, info.getReceipt().getResult()); - Account contract_before = PublicMethod.queryAccount(contractAddress,blockingStubFull); - // unfreeze suicide create2 account + Account contract_before = PublicMethod.queryAccount(contractAddress, blockingStubFull); + // unfreeze suicide create2 account methedStr = "unfreeze(address,uint256)"; argsStr = "\"" + Base58.encode58Check(create2Address) + "\"," + "1"; - txid = PublicMethod.triggerContract(contractAddress,methedStr,argsStr, - false,0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - info = PublicMethod.getTransactionInfoById(txid,blockingStubFull).get(); - Assert.assertEquals(code.SUCESS,info.getResult()); - Assert.assertEquals(contractResult.SUCCESS,info.getReceipt().getResult()); + info = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + Assert.assertEquals(code.SUCESS, info.getResult()); + Assert.assertEquals(contractResult.SUCCESS, info.getReceipt().getResult()); - Account contract_after = PublicMethod.queryAccount(contractAddress,blockingStubFull); + Account contract_after = PublicMethod.queryAccount(contractAddress, blockingStubFull); Assert.assertEquals(contract_before.getBalance() + freezeCount, contract_after.getBalance()); - Assert.assertEquals(contract_after.getAccountResource().getDelegatedFrozenBalanceForEnergy(), + Assert.assertEquals( + contract_after.getAccountResource().getDelegatedFrozenBalanceForEnergy(), contract_before.getAccountResource().getDelegatedFrozenBalanceForEnergy() - freezeCount); - - } - - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmassetissue/TvmAssetIssue001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmassetissue/TvmAssetIssue001.java index 76a68055..d910cab5 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmassetissue/TvmAssetIssue001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmassetissue/TvmAssetIssue001.java @@ -19,8 +19,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class TvmAssetIssue001 extends TronBaseTest { @@ -39,98 +39,127 @@ public class TvmAssetIssue001 extends TronBaseTest { private byte[] dev002Address = ecKey2.getAddress(); private String dev002Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = false) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(dev002Key); } - @Test(enabled = false, description = "tokenIssue normal", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "tokenIssue normal", + groups = {"contract", "daily"}) public void tokenIssueNormal() { - Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 3100_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 3100_000_000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/tvmAssetIssue001.sol"; - String contractName = "tvmAssetIssue001"; + String filePath = "./src/test/resources/soliditycode/tvmAssetIssue001.sol"; + String contractName = "tvmAssetIssue001"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); long callvalue = 1050000000L; - final String deployTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callvalue, 0, 10000, "0", 0L, null, dev001Key, dev001Address, + final String deployTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callvalue, + 0, + 10000, + "0", + 0L, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(deployTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(deployTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (deployTxid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(contractAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - long contractAddressBalance = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + long contractAddressBalance = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(callvalue, contractAddressBalance); - AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(dev001Address, blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); Account info = PublicMethod.queryAccount(dev001Address, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); /*String param = "0000000000000000000000000000000000007465737441737365744973737565" - + "0000000000000000000074657374417373657431353938333439363637393631" - + "0000000000000000000000000000000000000000000000000000000000989680" - + "0000000000000000000000000000000000000000000000000000000000000001";*/ + + "0000000000000000000074657374417373657431353938333439363637393631" + + "0000000000000000000000000000000000000000000000000000000000989680" + + "0000000000000000000000000000000000000000000000000000000000000001";*/ String tokenName = PublicMethod.stringToHexString(name); - String tokenAbbr = PublicMethod.stringToHexString(abbr); - String param = - "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; + String tokenAbbr = PublicMethod.stringToHexString(abbr); + String param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; logger.info("param: " + param); - String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; - String txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); long returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); logger.info("returnAssetId: " + returnAssetId); Assert.assertEquals(returnAssetId, Long.parseLong(assetIssueId)); - logger.info("getAssetV2Map(): " + PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map()); - long assetIssueValue = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map().get(assetIssueId); + logger.info( + "getAssetV2Map(): " + + PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetV2Map()); + long assetIssueValue = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); Assert.assertEquals(totalSupply, assetIssueValue); - AssetIssueContract assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + AssetIssueContract assetIssueById = + PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); Assert.assertEquals(totalSupply, assetIssueById.getTotalSupply()); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -138,12 +167,12 @@ public void tokenIssueNormal() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(dev001Address, blockingStubFull); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(dev001Address, blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -152,71 +181,97 @@ public void tokenIssueNormal() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - long contractAddressBalance2 = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + long contractAddressBalance2 = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(contractAddressBalance - 1024000000L, contractAddressBalance2); param = "\"" + Base58.encode58Check(dev002Address) + "\"," + 100 + ",\"" + assetIssueId + "\""; - String methodTransferToken = "transferToken(address,uint256,trcToken)"; - txid = PublicMethod.triggerContract(contractAddress, methodTransferToken, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodTransferToken = "transferToken(address,uint256,trcToken)"; + txid = + PublicMethod.triggerContract( + contractAddress, + methodTransferToken, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - long assetIssueValueAfter = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map().get(assetIssueId); - long dev002AssetValue = PublicMethod - .getAssetIssueValue(dev002Address, ByteString.copyFrom(assetIssueId.getBytes()), - blockingStubFull); + long assetIssueValueAfter = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); + long dev002AssetValue = + PublicMethod.getAssetIssueValue( + dev002Address, ByteString.copyFrom(assetIssueId.getBytes()), blockingStubFull); Assert.assertEquals(assetIssueValue - 100L, assetIssueValueAfter); Assert.assertEquals(100L, dev002AssetValue); } - @Test(enabled = false, description = "updateAsset normal", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "updateAsset normal", + groups = {"contract", "daily"}) public void updateAssetNormal() { - AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(dev001Address, blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); Account info = PublicMethod.queryAccount(dev001Address, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String param = "\"" + assetIssueId + "\",\"" + url + "\",\"" + description + "\""; + String param = "\"" + assetIssueId + "\",\"" + url + "\",\"" + description + "\""; logger.info("param: " + param); - String methodUpdateAsset = "updateAsset(trcToken,string,string)"; - String txid = PublicMethod.triggerContract(contractAddress, methodUpdateAsset, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodUpdateAsset = "updateAsset(trcToken,string,string)"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodUpdateAsset, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); long returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(1, returnAssetId); - assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); - AssetIssueContract assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + AssetIssueContract assetIssueById = + PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); - Assert - .assertEquals(description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); + Assert.assertEquals( + description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); Assert.assertEquals(url, ByteArray.toStr(assetIssueById.getUrl().toByteArray())); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -224,12 +279,12 @@ public void updateAssetNormal() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(dev001Address, blockingStubFull); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(dev001Address, blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -240,10 +295,9 @@ public void updateAssetNormal() { Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); } + PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmassetissue/TvmAssetIssue002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmassetissue/TvmAssetIssue002.java index 8c658fca..3c7b72f6 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmassetissue/TvmAssetIssue002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmassetissue/TvmAssetIssue002.java @@ -20,8 +20,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class TvmAssetIssue002 extends TronBaseTest { @@ -40,70 +40,92 @@ public class TvmAssetIssue002 extends TronBaseTest { private byte[] dev002Address = ecKey2.getAddress(); private String dev002Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = false) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(dev002Key); } - @Test(enabled = false, description = "tokenIssue illegal parameter verification", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "tokenIssue illegal parameter verification", + groups = {"contract", "daily"}) public void tokenIssue001IllegalParameterVerification() { - Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 3100_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 3100_000_000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/tvmAssetIssue001.sol"; - String contractName = "tvmAssetIssue001"; + String filePath = "./src/test/resources/soliditycode/tvmAssetIssue001.sol"; + String contractName = "tvmAssetIssue001"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); long callvalue = 2050000000L; - final String deployTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callvalue, 0, 10000, "0", 0L, null, dev001Key, dev001Address, + final String deployTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callvalue, + 0, + 10000, + "0", + 0L, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(deployTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(deployTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (deployTxid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(contractAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - long contractAddressBalance = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + long contractAddressBalance = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(callvalue, contractAddressBalance); /*String param = "0000000000000000000000000000000000007465737441737365744973737565" - + "0000000000000000000074657374417373657431353938333439363637393631" - + "0000000000000000000000000000000000000000000000000000000000989680" - + "0000000000000000000000000000000000000000000000000000000000000001";*/ + + "0000000000000000000074657374417373657431353938333439363637393631" + + "0000000000000000000000000000000000000000000000000000000000989680" + + "0000000000000000000000000000000000000000000000000000000000000001";*/ // assetName is trx String tokenName = PublicMethod.stringToHexString("trx"); - String tokenAbbr = PublicMethod.stringToHexString(abbr); - String param = - "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; + String tokenAbbr = PublicMethod.stringToHexString(abbr); + String param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; logger.info("param: " + param); - String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; - String txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); long returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(0, returnAssetId); - Map assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map(); + Map assetV2Map = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetV2Map(); Assert.assertEquals(0, assetV2Map.size()); - // assetName.length > 32 compile fail + // assetName.length > 32 compile fail /*tokenName = PublicMethod.stringToHexString("testAssetIssue_testAssetIssue_tes"); tokenAbbr = PublicMethod.stringToHexString(abbr); param = @@ -124,109 +146,148 @@ public void tokenIssue001IllegalParameterVerification() { // assetName is "" tokenName = PublicMethod.stringToHexString(""); tokenAbbr = PublicMethod.stringToHexString(abbr); - param = - "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; + param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; logger.info("param: " + param); methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; - txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(0, returnAssetId); - assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map(); + assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetV2Map(); Assert.assertEquals(0, assetV2Map.size()); - // assetName is chinese + // assetName is chinese tokenName = PublicMethod.stringToHexString("名字"); tokenAbbr = PublicMethod.stringToHexString(abbr); - param = - "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; + param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; logger.info("param: " + param); methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; - txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(0, returnAssetId); - assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map(); + assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetV2Map(); Assert.assertEquals(0, assetV2Map.size()); - // assetAbbr is null + // assetAbbr is null tokenName = PublicMethod.stringToHexString(name); tokenAbbr = PublicMethod.stringToHexString(""); - param = - "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; + param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; logger.info("param: " + param); methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; - txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(0, returnAssetId); - assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map(); + assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetV2Map(); Assert.assertEquals(0, assetV2Map.size()); - // assetAbbr is chinese + // assetAbbr is chinese tokenName = PublicMethod.stringToHexString(name); tokenAbbr = PublicMethod.stringToHexString("简称"); - param = - "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; + param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; logger.info("param: " + param); methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; - txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(0, returnAssetId); - assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map(); + assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetV2Map(); Assert.assertEquals(0, assetV2Map.size()); - // totalSupply is Long.MAX_VALUE+1 - param = "a8547918" - + "74657374417373657449737375655f3136303034333636393333333600000000" - + "7472780000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000008000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000006"; + // totalSupply is Long.MAX_VALUE+1 + param = + "a8547918" + + "74657374417373657449737375655f3136303034333636393333333600000000" + + "7472780000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000008000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000006"; logger.info("param: " + param); - txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, true, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + true, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(0, returnAssetId); - assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map(); + assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetV2Map(); Assert.assertEquals(0, assetV2Map.size()); - // totalSupply is -1 + // totalSupply is -1 tokenName = PublicMethod.stringToHexString(name); tokenAbbr = PublicMethod.stringToHexString("trx"); - param = - "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + -1 + "," + 6; + param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + -1 + "," + 6; logger.info("param: " + param); - txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); logger.info("totalSupply is -1"); Assert.assertEquals(0, infoById.get().getResultValue()); @@ -234,20 +295,26 @@ public void tokenIssue001IllegalParameterVerification() { Assert.assertTrue(infoById.get().getFee() < 1000000000); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(0, returnAssetId); - assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map(); + assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetV2Map(); Assert.assertEquals(0, assetV2Map.size()); - // totalSupply is 0 + // totalSupply is 0 tokenName = PublicMethod.stringToHexString(name); tokenAbbr = PublicMethod.stringToHexString("trx"); - param = - "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + 0 + "," + 6; + param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + 0 + "," + 6; logger.info("param: " + param); - txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); logger.info("totalSupply is 0"); Assert.assertEquals(0, infoById.get().getResultValue()); @@ -255,177 +322,254 @@ public void tokenIssue001IllegalParameterVerification() { Assert.assertTrue(infoById.get().getFee() < 1000000000); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(0, returnAssetId); - assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map(); + assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetV2Map(); Assert.assertEquals(0, assetV2Map.size()); - // precision is 7 + // precision is 7 tokenName = PublicMethod.stringToHexString(name); tokenAbbr = PublicMethod.stringToHexString(abbr); - param = - "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 7; + param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 7; logger.info("param: " + param); - txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(0, returnAssetId); - assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map(); + assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetV2Map(); Assert.assertEquals(0, assetV2Map.size()); - // precision is -1 + // precision is -1 tokenName = PublicMethod.stringToHexString(name); tokenAbbr = PublicMethod.stringToHexString(abbr); - param = - "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + -1; + param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + -1; logger.info("param: " + param); - txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(0, returnAssetId); - assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map(); + assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetV2Map(); Assert.assertEquals(0, assetV2Map.size()); - // assetAbbr is trx will success + // assetAbbr is trx will success tokenName = PublicMethod.stringToHexString(name); tokenAbbr = PublicMethod.stringToHexString("trx"); param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; logger.info("param: " + param); - txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(returnAssetId, Long.parseLong(assetIssueId)); - AssetIssueContract assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + AssetIssueContract assetIssueById = + PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals("trx", ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); - assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map(); + assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetV2Map(); Assert.assertEquals(1, assetV2Map.size()); - // created multiple times will fail - txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + // created multiple times will fail + txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(0, returnAssetId); - assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map(); + assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetV2Map(); Assert.assertEquals(1, assetV2Map.size()); - String assetIssueId1 = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetIssuedID() - .toStringUtf8(); + String assetIssueId1 = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); Assert.assertEquals(assetIssueId, assetIssueId1); } - @Test(enabled = false, description = "tokenIssue trx balance insufficient", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "tokenIssue trx balance insufficient", + groups = {"contract", "daily"}) public void tokenIssue002TrxBalanceInsufficient() { - Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 3100_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 3100_000_000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/tvmAssetIssue001.sol"; - String contractName = "tvmAssetIssue001"; + String filePath = "./src/test/resources/soliditycode/tvmAssetIssue001.sol"; + String contractName = "tvmAssetIssue001"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); long callvalue = 1023999999L; - final String deployTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callvalue, 0, 10000, "0", 0L, null, dev001Key, dev001Address, + final String deployTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callvalue, + 0, + 10000, + "0", + 0L, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(deployTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(deployTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (deployTxid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(contractAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - long contractAddressBalance = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + long contractAddressBalance = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(callvalue, contractAddressBalance); - // trx balance insufficient + // trx balance insufficient String tokenName = PublicMethod.stringToHexString(name); - String tokenAbbr = PublicMethod.stringToHexString(abbr); - String param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; + String tokenAbbr = PublicMethod.stringToHexString(abbr); + String param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; logger.info("param: " + param); - String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; - String txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); long returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(0, returnAssetId); - Map assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map(); + Map assetV2Map = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetV2Map(); Assert.assertEquals(0, assetV2Map.size()); } - @Test(enabled = false, description = "tokenIssue called multiple times in one contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "tokenIssue called multiple times in one contract", + groups = {"contract", "daily"}) public void tokenIssue003CalledMultipleTimesInOneContract() { - Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 3100_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 3100_000_000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/tvmAssetIssue002.sol"; - String contractName = "tvmAssetIssue002"; + String filePath = "./src/test/resources/soliditycode/tvmAssetIssue002.sol"; + String contractName = "tvmAssetIssue002"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); long callvalue = 1024000000L; - final String deployTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callvalue, 0, 10000, "0", 0L, null, dev001Key, dev001Address, + final String deployTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callvalue, + 0, + 10000, + "0", + 0L, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(deployTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(deployTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (deployTxid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(contractAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - long contractAddressBalance = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + long contractAddressBalance = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(callvalue, contractAddressBalance); - String tokenName = PublicMethod.stringToHexString(name); - String tokenAbbr = PublicMethod.stringToHexString(abbr); - String param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 5; + String tokenName = PublicMethod.stringToHexString(name); + String tokenAbbr = PublicMethod.stringToHexString(abbr); + String param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 5; logger.info("param: " + param); - String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; - String txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); @@ -433,217 +577,311 @@ public void tokenIssue003CalledMultipleTimesInOneContract() { long returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(0, returnAssetId); - Map assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map(); + Map assetV2Map = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetV2Map(); Assert.assertEquals(1, assetV2Map.size()); - assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); - long assetIssueValue = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map().get(assetIssueId); + long assetIssueValue = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); Assert.assertEquals(totalSupply, assetIssueValue); - AssetIssueContract assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + AssetIssueContract assetIssueById = + PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); Assert.assertEquals(totalSupply, assetIssueById.getTotalSupply()); Assert.assertEquals(5, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); } - @Test(enabled = false, description = "tokenIssue revert", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "tokenIssue revert", + groups = {"contract", "daily"}) public void tokenIssue004Revert() { - Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 3100_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 3100_000_000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/tvmAssetIssue003.sol"; - String contractName = "tvmAssetIssue003"; + String filePath = "./src/test/resources/soliditycode/tvmAssetIssue003.sol"; + String contractName = "tvmAssetIssue003"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); long callvalue = 2500000000L; - final String deployTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callvalue, 0, 10000, "0", 0L, null, dev001Key, dev001Address, + final String deployTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callvalue, + 0, + 10000, + "0", + 0L, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(deployTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(deployTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (deployTxid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(contractAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - long contractAddressBalance = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + long contractAddressBalance = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(callvalue, contractAddressBalance); - String tokenName = PublicMethod.stringToHexString(name); - String tokenAbbr = PublicMethod.stringToHexString(abbr); - String param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 4; + String tokenName = PublicMethod.stringToHexString(name); + String tokenAbbr = PublicMethod.stringToHexString(abbr); + String param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 4; logger.info("param: " + param); - String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; - String txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - Map assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map(); + Map assetV2Map = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetV2Map(); Assert.assertEquals(1, assetV2Map.size()); - assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); long returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(returnAssetId, Long.parseLong(assetIssueId)); - long assetIssueValue = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map().get(assetIssueId); + long assetIssueValue = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); Assert.assertEquals(totalSupply, assetIssueValue); - AssetIssueContract assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + AssetIssueContract assetIssueById = + PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); Assert.assertEquals(totalSupply, assetIssueById.getTotalSupply()); Assert.assertEquals(4, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); - String tokenName1 = PublicMethod.stringToHexString(name + "_rev"); - String tokenAbbr1 = PublicMethod.stringToHexString(abbr + "_rev"); + String tokenName1 = PublicMethod.stringToHexString(name + "_rev"); + String tokenAbbr1 = PublicMethod.stringToHexString(abbr + "_rev"); param = - "\"" + tokenName1 + "\",\"" + tokenAbbr1 + "\",\"" + 1000000 + "\",\"" + 3 + "\",\"" - + Base58.encode58Check(dev002Address) + "\""; + "\"" + + tokenName1 + + "\",\"" + + tokenAbbr1 + + "\",\"" + + 1000000 + + "\",\"" + + 3 + + "\",\"" + + Base58.encode58Check(dev002Address) + + "\""; logger.info("param: " + param); - String methodTokenIssueRevert = "tokenIssueAndTransfer(bytes32,bytes32,uint64,uint8,address)"; - txid = PublicMethod.triggerContract(contractAddress, methodTokenIssueRevert, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodTokenIssueRevert = "tokenIssueAndTransfer(bytes32,bytes32,uint64,uint8,address)"; + txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssueRevert, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map(); + assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetV2Map(); Assert.assertEquals(1, assetV2Map.size()); - String assetIssueId1 = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetIssuedID() - .toStringUtf8(); + String assetIssueId1 = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId1: " + assetIssueId1); Assert.assertEquals(assetIssueId, assetIssueId1); - assetIssueValue = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map().get(assetIssueId); + assetIssueValue = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); Assert.assertEquals(totalSupply, assetIssueValue); - assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + assetIssueById = PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); Assert.assertEquals(totalSupply, assetIssueById.getTotalSupply()); Assert.assertEquals(4, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); long balance = PublicMethod.queryAccount(dev002Address, blockingStubFull).getBalance(); Assert.assertEquals(200000000L, balance); } - @Test(enabled = false, description = "tokenIssue call another contract in one contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "tokenIssue call another contract in one contract", + groups = {"contract", "daily"}) public void tokenIssue005CallAnotherInOneContract() { - Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 3100_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 3100_000_000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/tvmAssetIssue004.sol"; - String contractName = "tvmAssetIssue004"; + String filePath = "./src/test/resources/soliditycode/tvmAssetIssue004.sol"; + String contractName = "tvmAssetIssue004"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); long callvalue = 1030000000L; - String deployTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callvalue, 0, 10000, "0", 0L, null, dev001Key, dev001Address, + String deployTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callvalue, + 0, + 10000, + "0", + 0L, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(deployTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(deployTxid, blockingStubFull); if (deployTxid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(contractAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); callvalue = 1024000000L; - String txid = PublicMethod.triggerContract(contractAddress, "getContractAddress()", "#", false, - callvalue, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + "getContractAddress()", + "#", + false, + callvalue, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - String addressHex = - "41" + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()) - .substring(24); + String addressHex = + "41" + + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()) + .substring(24); logger.info("address_hex: " + addressHex); - byte[] contractAddressA = ByteArray.fromHexString(addressHex); + byte[] contractAddressA = ByteArray.fromHexString(addressHex); logger.info("contractAddressA: " + Base58.encode58Check(contractAddressA)); - contractAddressBalance = PublicMethod.queryAccount(contractAddressA, blockingStubFull) - .getBalance(); + contractAddressBalance = + PublicMethod.queryAccount(contractAddressA, blockingStubFull).getBalance(); Assert.assertEquals(callvalue, contractAddressBalance); - AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(dev001Address, blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); Account info = PublicMethod.queryAccount(dev001Address, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String tokenName = PublicMethod.stringToHexString(name); - String tokenAbbr = PublicMethod.stringToHexString(abbr); - String param = - "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 2; + String tokenName = PublicMethod.stringToHexString(name); + String tokenAbbr = PublicMethod.stringToHexString(abbr); + String param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 2; logger.info("param: " + param); - String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; - txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; + txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - assetIssueId = PublicMethod.queryAccount(contractAddressA, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddressA, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); long returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); logger.info("returnAssetId: " + returnAssetId); Assert.assertEquals(returnAssetId, Long.parseLong(assetIssueId)); - Map assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map(); + Map assetV2Map = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetV2Map(); Assert.assertEquals(0, assetV2Map.size()); - long assetIssueValue = PublicMethod.queryAccount(contractAddressA, blockingStubFull) - .getAssetV2Map().get(assetIssueId); + long assetIssueValue = + PublicMethod.queryAccount(contractAddressA, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); Assert.assertEquals(totalSupply, assetIssueValue); - AssetIssueContract assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + AssetIssueContract assetIssueById = + PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); Assert.assertEquals(totalSupply, assetIssueById.getTotalSupply()); Assert.assertEquals(2, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddressA), + Assert.assertEquals( + Base58.encode58Check(contractAddressA), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -651,12 +889,12 @@ public void tokenIssue005CallAnotherInOneContract() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(dev001Address, blockingStubFull); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(dev001Address, blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -665,32 +903,42 @@ public void tokenIssue005CallAnotherInOneContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - long contractAddressBalance2 = PublicMethod.queryAccount(contractAddressA, blockingStubFull) - .getBalance(); + long contractAddressBalance2 = + PublicMethod.queryAccount(contractAddressA, blockingStubFull).getBalance(); Assert.assertEquals(contractAddressBalance - 1024000000L, contractAddressBalance2); param = "\"" + Base58.encode58Check(dev002Address) + "\"," + 100 + ",\"" + assetIssueId + "\""; - String methodTransferToken = "transferToken(address,uint256,trcToken)"; - txid = PublicMethod.triggerContract(contractAddressA, methodTransferToken, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodTransferToken = "transferToken(address,uint256,trcToken)"; + txid = + PublicMethod.triggerContract( + contractAddressA, + methodTransferToken, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - long assetIssueValueAfter = PublicMethod.queryAccount(contractAddressA, blockingStubFull) - .getAssetV2Map().get(assetIssueId); - long dev002AssetValue = PublicMethod - .getAssetIssueValue(dev002Address, ByteString.copyFrom(assetIssueId.getBytes()), - blockingStubFull); + long assetIssueValueAfter = + PublicMethod.queryAccount(contractAddressA, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); + long dev002AssetValue = + PublicMethod.getAssetIssueValue( + dev002Address, ByteString.copyFrom(assetIssueId.getBytes()), blockingStubFull); Assert.assertEquals(assetIssueValue - 100L, assetIssueValueAfter); Assert.assertEquals(100L, dev002AssetValue); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); } + PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmassetissue/TvmAssetIssue003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmassetissue/TvmAssetIssue003.java index d11a9e99..f4f0f2dc 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmassetissue/TvmAssetIssue003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmassetissue/TvmAssetIssue003.java @@ -19,8 +19,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class TvmAssetIssue003 extends TronBaseTest { @@ -40,108 +40,146 @@ public class TvmAssetIssue003 extends TronBaseTest { private byte[] dev002Address = ecKey2.getAddress(); private String dev002Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = false) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(dev002Key); } - @Test(enabled = false, description = "updateAsset illegal parameter verification", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "updateAsset illegal parameter verification", + groups = {"contract", "daily"}) public void updateAsset001IllegalParameterVerification() { - Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 1100_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1100_000_000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/tvmAssetIssue001.sol"; - String contractName = "tvmAssetIssue001"; + String filePath = "./src/test/resources/soliditycode/tvmAssetIssue001.sol"; + String contractName = "tvmAssetIssue001"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); long callvalue = 1024000000L; - final String deployTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callvalue, 0, 10000, "0", 0L, null, dev001Key, dev001Address, + final String deployTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callvalue, + 0, + 10000, + "0", + 0L, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(deployTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(deployTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (deployTxid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(contractAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - long contractAddressBalance = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + long contractAddressBalance = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(callvalue, contractAddressBalance); - String tokenName = PublicMethod.stringToHexString(name); - String tokenAbbr = PublicMethod.stringToHexString(abbr); - String param = - "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; + String tokenName = PublicMethod.stringToHexString(name); + String tokenAbbr = PublicMethod.stringToHexString(abbr); + String param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; logger.info("param: " + param); - String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; - String txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); long returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); logger.info("returnAssetId: " + returnAssetId); Assert.assertEquals(returnAssetId, Long.parseLong(assetIssueId)); - long assetIssueValue = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map().get(assetIssueId); + long assetIssueValue = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); Assert.assertEquals(totalSupply, assetIssueValue); - AssetIssueContract assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + AssetIssueContract assetIssueById = + PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); Assert.assertEquals(totalSupply, assetIssueById.getTotalSupply()); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); - long contractAddressBalance2 = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + long contractAddressBalance2 = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(contractAddressBalance - 1024000000L, contractAddressBalance2); - // desc and url is trx, will success + // desc and url is trx, will success url = "trx"; description = "trx"; param = "\"" + assetIssueId + "\",\"" + url + "\",\"" + description + "\""; logger.info("param: " + param); - String methodUpdateAsset = "updateAsset(trcToken,string,string)"; - txid = PublicMethod.triggerContract(contractAddress, methodUpdateAsset, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodUpdateAsset = "updateAsset(trcToken,string,string)"; + txid = + PublicMethod.triggerContract( + contractAddress, + methodUpdateAsset, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(1, returnAssetId); - assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); - assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + assetIssueById = PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); - Assert - .assertEquals(description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); + Assert.assertEquals( + description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); Assert.assertEquals(url, ByteArray.toStr(assetIssueById.getUrl().toByteArray())); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); - // desc.length is 201, will fail + // desc.length is 201, will fail String descriptions = "desc_1234567890desc_1234567890desc_1234567890desc_1234567890desc_1234567890" + "desc_1234567890desc_1234567890desc_1234567890desc_1234567890desc_1234567890desc" @@ -149,82 +187,112 @@ public void updateAsset001IllegalParameterVerification() { + "desc_1234567890desc_1234567890desc_1"; param = "\"" + assetIssueId + "\",\"" + url + "\",\"" + descriptions + "\""; logger.info("param: " + param); - txid = PublicMethod.triggerContract(contractAddress, methodUpdateAsset, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodUpdateAsset, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(0, returnAssetId); - assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); - assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + assetIssueById = PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); - Assert - .assertEquals(description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); + Assert.assertEquals( + description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); Assert.assertEquals(url, ByteArray.toStr(assetIssueById.getUrl().toByteArray())); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); - // desc.length is "", will success + // desc.length is "", will success param = "\"" + assetIssueId + "\",\"" + url + "\",\"\""; logger.info("param: " + param); - txid = PublicMethod.triggerContract(contractAddress, methodUpdateAsset, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodUpdateAsset, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(1, returnAssetId); - assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); - assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + assetIssueById = PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); Assert.assertEquals(0, assetIssueById.getDescription().size()); Assert.assertEquals(url, ByteArray.toStr(assetIssueById.getUrl().toByteArray())); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); - // desc.length is chinese, will success + // desc.length is chinese, will success description = "token说明"; param = "\"" + assetIssueId + "\",\"" + url + "\",\"" + description + "\""; logger.info("param: " + param); - txid = PublicMethod.triggerContract(contractAddress, methodUpdateAsset, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodUpdateAsset, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(1, returnAssetId); - assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); - assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + assetIssueById = PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); - Assert - .assertEquals(description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); + Assert.assertEquals( + description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); Assert.assertEquals(url, ByteArray.toStr(assetIssueById.getUrl().toByteArray())); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); - // url.length is 257, will fail + // url.length is 257, will fail String urls = "url_12345678901url_12345678901url_12345678901url_12345678901url_12345678901url_12345678901" + "url_12345678901url_12345678901url_12345678901url_12345678901url_12345678901url" @@ -232,123 +300,177 @@ public void updateAsset001IllegalParameterVerification() { + "url_12345678901url_12345678901url_12345678901url_12345678901url_12345678901ur"; param = "\"" + assetIssueId + "\",\"" + urls + "\",\"" + description + "\""; logger.info("param: " + param); - txid = PublicMethod.triggerContract(contractAddress, methodUpdateAsset, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodUpdateAsset, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(0, returnAssetId); - assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); - assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + assetIssueById = PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); - Assert - .assertEquals(description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); + Assert.assertEquals( + description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); Assert.assertEquals(url, ByteArray.toStr(assetIssueById.getUrl().toByteArray())); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); - // url.length is "", will fail + // url.length is "", will fail param = "\"" + assetIssueId + "\",\"\",\"" + description + "\""; logger.info("param: " + param); - txid = PublicMethod.triggerContract(contractAddress, methodUpdateAsset, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodUpdateAsset, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(0, returnAssetId); - assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); - assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + assetIssueById = PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); - Assert - .assertEquals(description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); + Assert.assertEquals( + description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); Assert.assertEquals(url, ByteArray.toStr(assetIssueById.getUrl().toByteArray())); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); - // url.length is chinese, will success + // url.length is chinese, will success url = "官网"; param = "\"" + assetIssueId + "\",\"" + url + "\",\"" + description + "\""; logger.info("param: " + param); - txid = PublicMethod.triggerContract(contractAddress, methodUpdateAsset, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodUpdateAsset, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(1, returnAssetId); - assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); - assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + assetIssueById = PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); - Assert - .assertEquals(description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); + Assert.assertEquals( + description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); Assert.assertEquals(url, ByteArray.toStr(assetIssueById.getUrl().toByteArray())); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); } - @Test(enabled = false, description = "updateAsset called multiple times in one contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "updateAsset called multiple times in one contract", + groups = {"contract", "daily"}) public void updateAsset002CalledMultipleTimesInOneContract() { - Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 1100_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1100_000_000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/tvmAssetIssue002.sol"; - String contractName = "tvmAssetIssue002"; + String filePath = "./src/test/resources/soliditycode/tvmAssetIssue002.sol"; + String contractName = "tvmAssetIssue002"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); long callvalue = 1024000000L; - final String deployTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callvalue, 0, 10000, "0", 0L, null, dev001Key, dev001Address, + final String deployTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callvalue, + 0, + 10000, + "0", + 0L, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(deployTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(deployTxid, blockingStubFull); logger.info("infoById: " + infoById.get().getReceipt().getEnergyUsageTotal()); if (deployTxid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(contractAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - long contractAddressBalance = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + long contractAddressBalance = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(callvalue, contractAddressBalance); - String tokenName = PublicMethod.stringToHexString(name); - String tokenAbbr = PublicMethod.stringToHexString(abbr); - String param = - "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; + String tokenName = PublicMethod.stringToHexString(name); + String tokenAbbr = PublicMethod.stringToHexString(abbr); + String param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; logger.info("param: " + param); - String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; - String txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); @@ -356,251 +478,362 @@ public void updateAsset002CalledMultipleTimesInOneContract() { long returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(0, returnAssetId); - assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); - long assetIssueValue = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map().get(assetIssueId); + long assetIssueValue = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); Assert.assertEquals(totalSupply, assetIssueValue); - AssetIssueContract assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + AssetIssueContract assetIssueById = + PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); Assert.assertEquals(totalSupply, assetIssueById.getTotalSupply()); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); - long contractAddressBalance2 = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + long contractAddressBalance2 = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(contractAddressBalance - 1024000000L, contractAddressBalance2); - // updateAsset + // updateAsset description = "desc1_" + Long.toString(now); url = "url1_" + Long.toString(now); - String description2 = "desc2_" + Long.toString(now); - String url2 = "url2_" + Long.toString(now); - param = "\"" + assetIssueId + "\",\"" + url + "\",\"" + description + "\",\"" + url2 + "\",\"" - + description2 + "\""; + String description2 = "desc2_" + Long.toString(now); + String url2 = "url2_" + Long.toString(now); + param = + "\"" + + assetIssueId + + "\",\"" + + url + + "\",\"" + + description + + "\",\"" + + url2 + + "\",\"" + + description2 + + "\""; logger.info("param: " + param); - String methodUpdateAsset = "updateAsset(trcToken,string,string,string,string)"; - txid = PublicMethod.triggerContract(contractAddress, methodUpdateAsset, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodUpdateAsset = "updateAsset(trcToken,string,string,string,string)"; + txid = + PublicMethod.triggerContract( + contractAddress, + methodUpdateAsset, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(1, returnAssetId); - assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); - assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + assetIssueById = PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); - Assert - .assertEquals(description2, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); + Assert.assertEquals( + description2, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); Assert.assertEquals(url2, ByteArray.toStr(assetIssueById.getUrl().toByteArray())); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); } - @Test(enabled = false, description = "updateAsset revert", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "updateAsset revert", + groups = {"contract", "daily"}) public void updateAsset003Revert() { - Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 1500_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1500_000_000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/tvmAssetIssue003.sol"; - String contractName = "tvmAssetIssue003"; + String filePath = "./src/test/resources/soliditycode/tvmAssetIssue003.sol"; + String contractName = "tvmAssetIssue003"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); long callvalue = 1225000000L; - final String deployTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callvalue, 0, 10000, "0", 0L, null, dev001Key, dev001Address, + final String deployTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callvalue, + 0, + 10000, + "0", + 0L, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(deployTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(deployTxid, blockingStubFull); logger.info("infoById: " + infoById.get().getReceipt().getEnergyUsageTotal()); if (deployTxid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(contractAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - long contractAddressBalance = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + long contractAddressBalance = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(callvalue, contractAddressBalance); - String tokenName = PublicMethod.stringToHexString(name); - String tokenAbbr = PublicMethod.stringToHexString(abbr); - String param = - "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; + String tokenName = PublicMethod.stringToHexString(name); + String tokenAbbr = PublicMethod.stringToHexString(abbr); + String param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; logger.info("param: " + param); - String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; - String txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); long returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(returnAssetId, Long.parseLong(assetIssueId)); - long assetIssueValue = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map().get(assetIssueId); + long assetIssueValue = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); Assert.assertEquals(totalSupply, assetIssueValue); - AssetIssueContract assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + AssetIssueContract assetIssueById = + PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); Assert.assertEquals(totalSupply, assetIssueById.getTotalSupply()); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); - long contractAddressBalance2 = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + long contractAddressBalance2 = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(contractAddressBalance - 1024000000L, contractAddressBalance2); - // updateAsset + // updateAsset String description1 = "desc_1234567890desc_1234567890desc_1234567890desc_1234567890desc_1234567890" + "desc_1234567890desc_1234567890desc_1234567890desc_1234567890desc_1234567890desc" + "_1234567890" + "desc_1234567890desc_1234567890desc_1"; - String url1 = "url1_" + Long.toString(now); - param = "\"" + assetIssueId + "\",\"" + url1 + "\",\"" + description1 + "\",\"" + Base58 - .encode58Check(dev002Address) + "\""; + String url1 = "url1_" + Long.toString(now); + param = + "\"" + + assetIssueId + + "\",\"" + + url1 + + "\",\"" + + description1 + + "\",\"" + + Base58.encode58Check(dev002Address) + + "\""; logger.info("param: " + param); - String methodUpdateAsset = "updateAssetAndTransfer(trcToken,string,string,address)"; - txid = PublicMethod.triggerContract(contractAddress, methodUpdateAsset, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodUpdateAsset = "updateAssetAndTransfer(trcToken,string,string,address)"; + txid = + PublicMethod.triggerContract( + contractAddress, + methodUpdateAsset, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(0, returnAssetId); - assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); - assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + assetIssueById = PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); logger.info("assetIssueById: " + assetIssueById); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); Assert.assertEquals(0, assetIssueById.getDescription().size()); Assert.assertEquals(0, assetIssueById.getUrl().size()); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); long balance = PublicMethod.queryAccount(dev002Address, blockingStubFull).getBalance(); Assert.assertEquals(200000000L, balance); } - @Test(enabled = false, description = "updateAsset call another contract in one contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "updateAsset call another contract in one contract", + groups = {"contract", "daily"}) public void updateAsset004CallAnotherInOneContract() { - Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 3100_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 3100_000_000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/tvmAssetIssue004.sol"; - String contractName = "tvmAssetIssue004"; + String filePath = "./src/test/resources/soliditycode/tvmAssetIssue004.sol"; + String contractName = "tvmAssetIssue004"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); long callvalue = 1030000000L; - String deployTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callvalue, 0, 10000, "0", 0L, null, dev001Key, dev001Address, + String deployTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callvalue, + 0, + 10000, + "0", + 0L, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(deployTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(deployTxid, blockingStubFull); if (deployTxid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(contractAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); callvalue = 1024000000L; - String txid = PublicMethod.triggerContract(contractAddress, "getContractAddress()", "#", false, - callvalue, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + "getContractAddress()", + "#", + false, + callvalue, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - String addressHex = - "41" + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()) - .substring(24); + String addressHex = + "41" + + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()) + .substring(24); logger.info("address_hex: " + addressHex); - byte[] contractAddressA = ByteArray.fromHexString(addressHex); + byte[] contractAddressA = ByteArray.fromHexString(addressHex); logger.info("contractAddressA: " + Base58.encode58Check(contractAddressA)); - long contractAddressBalance = PublicMethod.queryAccount(contractAddressA, blockingStubFull) - .getBalance(); + long contractAddressBalance = + PublicMethod.queryAccount(contractAddressA, blockingStubFull).getBalance(); Assert.assertEquals(callvalue, contractAddressBalance); - AccountResourceMessage resourceInfo = PublicMethod - .getAccountResource(dev001Address, blockingStubFull); + AccountResourceMessage resourceInfo = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); Account info = PublicMethod.queryAccount(dev001Address, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String tokenName = PublicMethod.stringToHexString(name); - String tokenAbbr = PublicMethod.stringToHexString(abbr); - String param = - "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 2; + String tokenName = PublicMethod.stringToHexString(name); + String tokenAbbr = PublicMethod.stringToHexString(abbr); + String param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 2; logger.info("param: " + param); - String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; - txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; + txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - assetIssueId = PublicMethod.queryAccount(contractAddressA, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddressA, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); long returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); logger.info("returnAssetId: " + returnAssetId); Assert.assertEquals(returnAssetId, Long.parseLong(assetIssueId)); - Map assetV2Map = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map(); + Map assetV2Map = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetV2Map(); Assert.assertEquals(0, assetV2Map.size()); - long assetIssueValue = PublicMethod.queryAccount(contractAddressA, blockingStubFull) - .getAssetV2Map().get(assetIssueId); + long assetIssueValue = + PublicMethod.queryAccount(contractAddressA, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); Assert.assertEquals(totalSupply, assetIssueValue); - AssetIssueContract assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + AssetIssueContract assetIssueById = + PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); Assert.assertEquals(totalSupply, assetIssueById.getTotalSupply()); Assert.assertEquals(2, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddressA), + Assert.assertEquals( + Base58.encode58Check(contractAddressA), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); @@ -608,12 +841,12 @@ public void updateAsset004CallAnotherInOneContract() { logger.info("netFee:" + netFee); logger.info("energyUsageTotal:" + energyUsageTotal); Protocol.Account infoafter = PublicMethod.queryAccount(dev001Address, blockingStubFull); - GrpcAPI.AccountResourceMessage resourceInfoafter = PublicMethod - .getAccountResource(dev001Address, blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + GrpcAPI.AccountResourceMessage resourceInfoafter = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); @@ -622,15 +855,24 @@ public void updateAsset004CallAnotherInOneContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - long contractAddressBalance2 = PublicMethod.queryAccount(contractAddressA, blockingStubFull) - .getBalance(); + long contractAddressBalance2 = + PublicMethod.queryAccount(contractAddressA, blockingStubFull).getBalance(); Assert.assertEquals(contractAddressBalance - 1024000000L, contractAddressBalance2); - // updateAsset + // updateAsset param = "\"" + assetIssueId + "\",\"" + url + "\",\"" + description + "\""; logger.info("param: " + param); - String methodUpdateAsset = "updateAsset(trcToken,string,string)"; - txid = PublicMethod.triggerContract(contractAddress, methodUpdateAsset, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodUpdateAsset = "updateAsset(trcToken,string,string)"; + txid = + PublicMethod.triggerContract( + contractAddress, + methodUpdateAsset, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); @@ -638,163 +880,222 @@ public void updateAsset004CallAnotherInOneContract() { returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(1, returnAssetId); - assetIssueId = PublicMethod.queryAccount(contractAddressA, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddressA, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); - assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + assetIssueById = PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); - Assert - .assertEquals(description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); + Assert.assertEquals( + description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); Assert.assertEquals(url, ByteArray.toStr(assetIssueById.getUrl().toByteArray())); Assert.assertEquals(2, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddressA), + Assert.assertEquals( + Base58.encode58Check(contractAddressA), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); } - @Test(enabled = false, description = "updateAsset verify token", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "updateAsset verify token", + groups = {"contract", "daily"}) public void updateAsset005VerifyTokenId() { - Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 1100_000_000L, fromAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .sendcoin(dev002Address, 50_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1100_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev002Address, 50_000_000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/tvmAssetIssue001.sol"; - String contractName = "tvmAssetIssue001"; + String filePath = "./src/test/resources/soliditycode/tvmAssetIssue001.sol"; + String contractName = "tvmAssetIssue001"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); long callvalue = 1024000000L; - final String deployTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callvalue, 0, 10000, "0", 0L, null, dev001Key, dev001Address, + final String deployTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callvalue, + 0, + 10000, + "0", + 0L, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(deployTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(deployTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (deployTxid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(contractAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - long contractAddressBalance = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + long contractAddressBalance = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(callvalue, contractAddressBalance); - String tokenName = PublicMethod.stringToHexString(name); - String tokenAbbr = PublicMethod.stringToHexString(abbr); - String param = - "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; + String tokenName = PublicMethod.stringToHexString(name); + String tokenAbbr = PublicMethod.stringToHexString(abbr); + String param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; logger.info("param: " + param); - String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; - String txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); long returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); logger.info("returnAssetId: " + returnAssetId); Assert.assertEquals(returnAssetId, Long.parseLong(assetIssueId)); - long assetIssueValue = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map().get(assetIssueId); + long assetIssueValue = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); Assert.assertEquals(totalSupply, assetIssueValue); - AssetIssueContract assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + AssetIssueContract assetIssueById = + PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); Assert.assertEquals(totalSupply, assetIssueById.getTotalSupply()); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); - long contractAddressBalance2 = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + long contractAddressBalance2 = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(contractAddressBalance - 1024000000L, contractAddressBalance2); - // token id does not exist, will update myself + // token id does not exist, will update myself url = "trx"; description = "trx"; param = "\"1119125\",\"" + url + "\",\"" + description + "\""; logger.info("param: " + param); - String methodUpdateAsset = "updateAsset(trcToken,string,string)"; - txid = PublicMethod.triggerContract(contractAddress, methodUpdateAsset, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodUpdateAsset = "updateAsset(trcToken,string,string)"; + txid = + PublicMethod.triggerContract( + contractAddress, + methodUpdateAsset, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(1, returnAssetId); - assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); - assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + assetIssueById = PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); logger.info("assetIssueById: " + assetIssueById); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); - Assert - .assertEquals(description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); + Assert.assertEquals( + description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); Assert.assertEquals(url, ByteArray.toStr(assetIssueById.getUrl().toByteArray())); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); - // not owner's asset, will update myself - AssetIssueContract assetIssueByIdBefore = PublicMethod - .getAssetIssueById("1000004", blockingStubFull); - final String nameBefore = ByteArray.toStr(assetIssueByIdBefore.getName().toByteArray()); - final String abbrBefore = ByteArray.toStr(assetIssueByIdBefore.getAbbr().toByteArray()); - final String descBefore = assetIssueByIdBefore.getDescription().size() == 0 ? "" - : ByteArray.toStr(assetIssueByIdBefore.getDescription().toByteArray()); - final String urlBefore = assetIssueByIdBefore.getUrl().size() == 0 ? "" - : ByteArray.toStr(assetIssueByIdBefore.getUrl().toByteArray()); - final long precisionBefore = assetIssueByIdBefore.getPrecision(); + // not owner's asset, will update myself + AssetIssueContract assetIssueByIdBefore = + PublicMethod.getAssetIssueById("1000004", blockingStubFull); + final String nameBefore = ByteArray.toStr(assetIssueByIdBefore.getName().toByteArray()); + final String abbrBefore = ByteArray.toStr(assetIssueByIdBefore.getAbbr().toByteArray()); + final String descBefore = + assetIssueByIdBefore.getDescription().size() == 0 + ? "" + : ByteArray.toStr(assetIssueByIdBefore.getDescription().toByteArray()); + final String urlBefore = + assetIssueByIdBefore.getUrl().size() == 0 + ? "" + : ByteArray.toStr(assetIssueByIdBefore.getUrl().toByteArray()); + final long precisionBefore = assetIssueByIdBefore.getPrecision(); url = url + "123456"; description = description + "123"; param = "\"" + url + "\",\"" + description + "\""; logger.info("param: " + param); - txid = PublicMethod - .triggerContract(contractAddress, "updateOtherAccountAsset(string,string)", param, false, - 0, maxFeeLimit, dev002Address, dev002Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "updateOtherAccountAsset(string,string)", + param, + false, + 0, + maxFeeLimit, + dev002Address, + dev002Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(1, returnAssetId); - assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); - assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + assetIssueById = PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); logger.info("assetIssueById: " + assetIssueById); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); - Assert - .assertEquals(description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); + Assert.assertEquals( + description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); Assert.assertEquals(url, ByteArray.toStr(assetIssueById.getUrl().toByteArray())); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); - AssetIssueContract assetIssueByIdAfter = PublicMethod - .getAssetIssueById("1000004", blockingStubFull); - String descAfter = assetIssueByIdBefore.getDescription().size() == 0 ? "" - : ByteArray.toStr(assetIssueByIdAfter.getDescription().toByteArray()); - String urlAfter = assetIssueByIdBefore.getUrl().size() == 0 ? "" - : ByteArray.toStr(assetIssueByIdAfter.getUrl().toByteArray()); + AssetIssueContract assetIssueByIdAfter = + PublicMethod.getAssetIssueById("1000004", blockingStubFull); + String descAfter = + assetIssueByIdBefore.getDescription().size() == 0 + ? "" + : ByteArray.toStr(assetIssueByIdAfter.getDescription().toByteArray()); + String urlAfter = + assetIssueByIdBefore.getUrl().size() == 0 + ? "" + : ByteArray.toStr(assetIssueByIdAfter.getUrl().toByteArray()); Assert.assertEquals(nameBefore, ByteArray.toStr(assetIssueByIdAfter.getName().toByteArray())); Assert.assertEquals(abbrBefore, ByteArray.toStr(assetIssueByIdAfter.getAbbr().toByteArray())); Assert.assertEquals(descBefore, descAfter); @@ -802,10 +1103,9 @@ public void updateAsset005VerifyTokenId() { Assert.assertEquals(precisionBefore, assetIssueByIdAfter.getPrecision()); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); } + PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmassetissue/TvmAssetIssue004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmassetissue/TvmAssetIssue004.java index c12bffcc..8ff3aa78 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmassetissue/TvmAssetIssue004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmassetissue/TvmAssetIssue004.java @@ -15,8 +15,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class TvmAssetIssue004 extends TronBaseTest { @@ -39,135 +39,186 @@ public class TvmAssetIssue004 extends TronBaseTest { private byte[] dev003Address = ecKey3.getAddress(); private String dev003Key = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = false) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(dev002Key); PublicMethod.printAddress(dev003Key); } - @Test(enabled = false, description = "tokenIssue and transfer to account", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "tokenIssue and transfer to account", + groups = {"contract", "daily"}) public void tokenIssueAndTransferToAccount() { - Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 3100_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 3100_000_000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/tvmAssetIssue001.sol"; - String contractName = "tvmAssetIssue001"; + String filePath = "./src/test/resources/soliditycode/tvmAssetIssue001.sol"; + String contractName = "tvmAssetIssue001"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); long callvalue = 1050000000L; - final String deployTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callvalue, 0, 10000, "0", 0L, null, dev001Key, dev001Address, + final String deployTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callvalue, + 0, + 10000, + "0", + 0L, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(deployTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(deployTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (deployTxid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(contractAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - long contractAddressBalance = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + long contractAddressBalance = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(callvalue, contractAddressBalance); - String tokenName = PublicMethod.stringToHexString(name); - String tokenAbbr = PublicMethod.stringToHexString(abbr); - String param = - "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; + String tokenName = PublicMethod.stringToHexString(name); + String tokenAbbr = PublicMethod.stringToHexString(abbr); + String param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; logger.info("param: " + param); - String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; - String txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); long returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); logger.info("returnAssetId: " + returnAssetId); Assert.assertEquals(returnAssetId, Long.parseLong(assetIssueId)); - logger.info("getAssetV2Map(): " + PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map()); - long assetIssueValue = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map().get(assetIssueId); + logger.info( + "getAssetV2Map(): " + + PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetV2Map()); + long assetIssueValue = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); Assert.assertEquals(totalSupply, assetIssueValue); - AssetIssueContract assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + AssetIssueContract assetIssueById = + PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); Assert.assertEquals(totalSupply, assetIssueById.getTotalSupply()); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); - long contractAddressBalance2 = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + long contractAddressBalance2 = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(contractAddressBalance - 1024000000L, contractAddressBalance2); - // transfer token to create exist account - Assert.assertTrue(PublicMethod - .sendcoin(dev003Address, 10_000_000L, dev001Address, dev001Key, blockingStubFull)); + // transfer token to create exist account + Assert.assertTrue( + PublicMethod.sendcoin( + dev003Address, 10_000_000L, dev001Address, dev001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - long dev001AddressBalanceBefore = PublicMethod.queryAccount(dev001Address, blockingStubFull) - .getBalance(); + long dev001AddressBalanceBefore = + PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); logger.info("dev001AddressBalanceBefore: " + dev001AddressBalanceBefore); param = "\"" + Base58.encode58Check(dev003Address) + "\"," + 100 + ",\"" + assetIssueId + "\""; - String methodTransferToken = "transferToken(address,uint256,trcToken)"; - txid = PublicMethod.triggerContract(contractAddress, methodTransferToken, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String methodTransferToken = "transferToken(address,uint256,trcToken)"; + txid = + PublicMethod.triggerContract( + contractAddress, + methodTransferToken, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - long dev001AddressBalanceAfter = PublicMethod.queryAccount(dev001Address, blockingStubFull) - .getBalance(); + long dev001AddressBalanceAfter = + PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); logger.info("dev001AddressBalanceAfter: " + dev001AddressBalanceAfter); - long assetIssueValueAfter = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map().get(assetIssueId); - long dev003AssetValue = PublicMethod - .getAssetIssueValue(dev003Address, ByteString.copyFrom(assetIssueId.getBytes()), - blockingStubFull); + long assetIssueValueAfter = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); + long dev003AssetValue = + PublicMethod.getAssetIssueValue( + dev003Address, ByteString.copyFrom(assetIssueId.getBytes()), blockingStubFull); Assert.assertEquals(assetIssueValue - 100L, assetIssueValueAfter); Assert.assertEquals(100L, dev003AssetValue); - // transfer token to create new account - long dev001AddressBalanceBefore1 = PublicMethod.queryAccount(dev001Address, blockingStubFull) - .getBalance(); + // transfer token to create new account + long dev001AddressBalanceBefore1 = + PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); logger.info("dev001AddressBalanceBefore1: " + dev001AddressBalanceBefore1); param = "\"" + Base58.encode58Check(dev002Address) + "\"," + 100 + ",\"" + assetIssueId + "\""; - txid = PublicMethod.triggerContract(contractAddress, methodTransferToken, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodTransferToken, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() > 30000); - long dev001AddressBalanceAfter2 = PublicMethod.queryAccount(dev001Address, blockingStubFull) - .getBalance(); + long dev001AddressBalanceAfter2 = + PublicMethod.queryAccount(dev001Address, blockingStubFull).getBalance(); logger.info("dev001AddressBalanceAfter2: " + dev001AddressBalanceAfter2); - long assetIssueValueAfter1 = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map().get(assetIssueId); - long dev002AssetValue = PublicMethod - .getAssetIssueValue(dev002Address, ByteString.copyFrom(assetIssueId.getBytes()), - blockingStubFull); + long assetIssueValueAfter1 = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); + long dev002AssetValue = + PublicMethod.getAssetIssueValue( + dev002Address, ByteString.copyFrom(assetIssueId.getBytes()), blockingStubFull); Assert.assertEquals(assetIssueValueAfter - 100L, assetIssueValueAfter1); Assert.assertEquals(100L, dev002AssetValue); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); } + PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmassetissue/TvmAssetIssue005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmassetissue/TvmAssetIssue005.java index bd5fe36d..bdf37bf2 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmassetissue/TvmAssetIssue005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmassetissue/TvmAssetIssue005.java @@ -17,8 +17,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class TvmAssetIssue005 extends TronBaseTest { @@ -43,615 +43,870 @@ public class TvmAssetIssue005 extends TronBaseTest { private byte[] dev004Address = ecKey4.getAddress(); private String dev004Key = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = false) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(dev002Key); PublicMethod.printAddress(dev003Key); PublicMethod.printAddress(dev004Key); - Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 7000_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 7000_000_000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = false, description = "tokenIssue and updateAsset with suicide to account", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "tokenIssue and updateAsset with suicide to account", + groups = {"contract", "daily"}) public void tokenIssue001AndSuicideToAccount() { String filePath = "./src/test/resources/soliditycode/tvmAssetIssue005.sol"; - String contractName = "tvmAssetIssue005"; + String contractName = "tvmAssetIssue005"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); long callvalue = 1050000000L; - // deploy - final String deployTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callvalue, 0, 10000, "0", 0L, null, dev001Key, dev001Address, + // deploy + final String deployTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callvalue, + 0, + 10000, + "0", + 0L, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(deployTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(deployTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (deployTxid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(contractAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - contractAddressBalance = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + contractAddressBalance = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(callvalue, contractAddressBalance); - // tokenIssue + // tokenIssue name = "testAssetIssu1_" + Long.toString(now); abbr = "testAsse1_" + Long.toString(now); - String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; - String tokenName = PublicMethod.stringToHexString(name); - String tokenAbbr = PublicMethod.stringToHexString(abbr); - String param = - "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; + String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; + String tokenName = PublicMethod.stringToHexString(name); + String tokenAbbr = PublicMethod.stringToHexString(abbr); + String param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; logger.info("param: " + param); - String txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - String assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetIssuedID().toStringUtf8(); + String assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); long returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); logger.info("returnAssetId: " + returnAssetId); Assert.assertEquals(returnAssetId, Long.parseLong(assetIssueId)); - logger.info("getAssetV2Map(): " + PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map()); - long assetIssueValue = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map().get(assetIssueId); + logger.info( + "getAssetV2Map(): " + + PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetV2Map()); + long assetIssueValue = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); Assert.assertEquals(totalSupply, assetIssueValue); - AssetIssueContract assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + AssetIssueContract assetIssueById = + PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); Assert.assertEquals(totalSupply, assetIssueById.getTotalSupply()); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); AssetIssueContract assetIssueByName = PublicMethod.getAssetIssueByName(name, blockingStubFull); - AssetIssueContract assetIssueByAccount = PublicMethod - .getAssetIssueByAccount(contractAddress, blockingStubFull).get().getAssetIssue(0); - AssetIssueContract assetIssueListByName = PublicMethod - .getAssetIssueListByName(name, blockingStubFull) - .get().getAssetIssue(0); + AssetIssueContract assetIssueByAccount = + PublicMethod.getAssetIssueByAccount(contractAddress, blockingStubFull) + .get() + .getAssetIssue(0); + AssetIssueContract assetIssueListByName = + PublicMethod.getAssetIssueListByName(name, blockingStubFull).get().getAssetIssue(0); Assert.assertEquals(assetIssueId, assetIssueByName.getId()); Assert.assertEquals(name, ByteArray.toStr(assetIssueByAccount.getName().toByteArray())); Assert.assertEquals(assetIssueId, assetIssueListByName.getId()); - long contractAddressBalance2 = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + long contractAddressBalance2 = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(contractAddressBalance - 1024000000L, contractAddressBalance2); - // transferToken + // transferToken String methodTransferToken = "transferToken(address,uint256,trcToken)"; param = "\"" + Base58.encode58Check(dev002Address) + "\"," + 100 + ",\"" + assetIssueId + "\""; - txid = PublicMethod.triggerContract(contractAddress, methodTransferToken, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodTransferToken, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - long assetIssueValueAfter = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map().get(assetIssueId); - long dev002AssetValue = PublicMethod - .getAssetIssueValue(dev002Address, ByteString.copyFrom(assetIssueId.getBytes()), - blockingStubFull); + long assetIssueValueAfter = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); + long dev002AssetValue = + PublicMethod.getAssetIssueValue( + dev002Address, ByteString.copyFrom(assetIssueId.getBytes()), blockingStubFull); Assert.assertEquals(assetIssueValue - 100L, assetIssueValueAfter); Assert.assertEquals(100L, dev002AssetValue); - // updateAsset + // updateAsset String methodUpdateAsset = "updateAsset(trcToken,string,string)"; param = "\"" + assetIssueId + "\",\"" + url + "\",\"" + description + "\""; logger.info("param: " + param); - txid = PublicMethod.triggerContract(contractAddress, methodUpdateAsset, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodUpdateAsset, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); long returnId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(1, returnId); - assetIssueId = PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID() - .toStringUtf8(); + assetIssueId = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); - assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + assetIssueById = PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); - Assert - .assertEquals(description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); + Assert.assertEquals( + description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); Assert.assertEquals(url, ByteArray.toStr(assetIssueById.getUrl().toByteArray())); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); - // selfdestruct + // selfdestruct String methodSuicide = "SelfdestructTest(address)"; param = "\"" + Base58.encode58Check(dev003Address) + "\""; logger.info("param: " + param); - txid = PublicMethod.triggerContract(contractAddress, methodSuicide, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodSuicide, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - Assert.assertEquals(0, - PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID().size()); - Assert.assertEquals(0, - PublicMethod.getAssetIssueByAccount(dev003Address, blockingStubFull).get() + Assert.assertEquals( + 0, PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID().size()); + Assert.assertEquals( + 0, + PublicMethod.getAssetIssueByAccount(dev003Address, blockingStubFull) + .get() .getAssetIssueCount()); - Assert.assertEquals(0, - PublicMethod.queryAccount(dev003Address, blockingStubFull).getAssetIssuedID().size()); - long contractAssetCountDev003 = PublicMethod - .getAssetIssueValue(dev003Address, ByteString.copyFrom(assetIssueId.getBytes()), - blockingStubFull); + Assert.assertEquals( + 0, PublicMethod.queryAccount(dev003Address, blockingStubFull).getAssetIssuedID().size()); + long contractAssetCountDev003 = + PublicMethod.getAssetIssueValue( + dev003Address, ByteString.copyFrom(assetIssueId.getBytes()), blockingStubFull); Assert.assertEquals(assetIssueValueAfter, contractAssetCountDev003); - assetIssueValue = PublicMethod.queryAccount(dev003Address, blockingStubFull) - .getAssetV2Map().get(assetIssueId); + assetIssueValue = + PublicMethod.queryAccount(dev003Address, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); Assert.assertEquals(assetIssueValueAfter, assetIssueValue); - assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + assetIssueById = PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); Assert.assertEquals(totalSupply, assetIssueById.getTotalSupply()); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); assetIssueByName = PublicMethod.getAssetIssueByName(name, blockingStubFull); - assetIssueByAccount = PublicMethod - .getAssetIssueByAccount(contractAddress, blockingStubFull).get().getAssetIssue(0); - assetIssueListByName = PublicMethod - .getAssetIssueListByName(name, blockingStubFull) - .get().getAssetIssue(0); + assetIssueByAccount = + PublicMethod.getAssetIssueByAccount(contractAddress, blockingStubFull) + .get() + .getAssetIssue(0); + assetIssueListByName = + PublicMethod.getAssetIssueListByName(name, blockingStubFull).get().getAssetIssue(0); Assert.assertEquals(assetIssueId, assetIssueByName.getId()); Assert.assertEquals(name, ByteArray.toStr(assetIssueByAccount.getName().toByteArray())); Assert.assertEquals(assetIssueId, assetIssueListByName.getId()); - dev002AssetValue = PublicMethod - .getAssetIssueValue(dev002Address, ByteString.copyFrom(assetIssueId.getBytes()), - blockingStubFull); + dev002AssetValue = + PublicMethod.getAssetIssueValue( + dev002Address, ByteString.copyFrom(assetIssueId.getBytes()), blockingStubFull); Assert.assertEquals(100L, dev002AssetValue); - Assert.assertTrue(PublicMethod - .sendcoin(dev002Address, 100_000_000L, fromAddress, foundationKey, blockingStubFull)); - PublicMethod.waitProduceNextBlock(blockingStubFull); - // transferAsset,success - Assert.assertTrue(PublicMethod.transferAsset(dev002Address, assetIssueId.getBytes(), 100L, - dev003Address, dev003Key, blockingStubFull)); - PublicMethod.waitProduceNextBlock(blockingStubFull); - long assetIssueValueDev002 = PublicMethod - .getAssetIssueValue(dev002Address, ByteString.copyFrom(assetIssueId.getBytes()), - blockingStubFull); - long assetIssueValueDev003 = PublicMethod - .getAssetIssueValue(dev003Address, ByteString.copyFrom(assetIssueId.getBytes()), - blockingStubFull); + Assert.assertTrue( + PublicMethod.sendcoin( + dev002Address, 100_000_000L, fromAddress, foundationKey, blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + // transferAsset,success + Assert.assertTrue( + PublicMethod.transferAsset( + dev002Address, + assetIssueId.getBytes(), + 100L, + dev003Address, + dev003Key, + blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + long assetIssueValueDev002 = + PublicMethod.getAssetIssueValue( + dev002Address, ByteString.copyFrom(assetIssueId.getBytes()), blockingStubFull); + long assetIssueValueDev003 = + PublicMethod.getAssetIssueValue( + dev003Address, ByteString.copyFrom(assetIssueId.getBytes()), blockingStubFull); Assert.assertEquals(200L, assetIssueValueDev002); Assert.assertEquals(assetIssueValue - 100L, assetIssueValueDev003); - Assert.assertTrue(PublicMethod.transferAsset(dev004Address, assetIssueId.getBytes(), 102L, - dev002Address, dev002Key, blockingStubFull)); - PublicMethod.waitProduceNextBlock(blockingStubFull); - long assetIssueValueDev002After = PublicMethod - .getAssetIssueValue(dev002Address, ByteString.copyFrom(assetIssueId.getBytes()), - blockingStubFull); - long assetIssueValueDev004 = PublicMethod - .getAssetIssueValue(dev004Address, ByteString.copyFrom(assetIssueId.getBytes()), - blockingStubFull); + Assert.assertTrue( + PublicMethod.transferAsset( + dev004Address, + assetIssueId.getBytes(), + 102L, + dev002Address, + dev002Key, + blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + long assetIssueValueDev002After = + PublicMethod.getAssetIssueValue( + dev002Address, ByteString.copyFrom(assetIssueId.getBytes()), blockingStubFull); + long assetIssueValueDev004 = + PublicMethod.getAssetIssueValue( + dev004Address, ByteString.copyFrom(assetIssueId.getBytes()), blockingStubFull); Assert.assertEquals(102L, assetIssueValueDev004); Assert.assertEquals(assetIssueValueDev002 - 102L, assetIssueValueDev002After); - // updateAsset,will fail - Assert.assertFalse(PublicMethod - .updateAsset(dev003Address, "updateDesc1".getBytes(), "updateURL1".getBytes(), 1L, 2L, - dev003Key, blockingStubFull)); - PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertFalse(PublicMethod - .updateAsset(contractAddress, "updateDesc2".getBytes(), "updateURL2".getBytes(), 3L, 4L, - dev003Key, blockingStubFull)); - PublicMethod.waitProduceNextBlock(blockingStubFull); - assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); - Assert - .assertEquals(description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); + // updateAsset,will fail + Assert.assertFalse( + PublicMethod.updateAsset( + dev003Address, + "updateDesc1".getBytes(), + "updateURL1".getBytes(), + 1L, + 2L, + dev003Key, + blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + Assert.assertFalse( + PublicMethod.updateAsset( + contractAddress, + "updateDesc2".getBytes(), + "updateURL2".getBytes(), + 3L, + 4L, + dev003Key, + blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + assetIssueById = PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); + Assert.assertEquals( + description, ByteArray.toStr(assetIssueById.getDescription().toByteArray())); Assert.assertEquals(url, ByteArray.toStr(assetIssueById.getUrl().toByteArray())); - Assert.assertEquals(Base58.encode58Check(contractAddress), + Assert.assertEquals( + Base58.encode58Check(contractAddress), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); } - @Test(enabled = false, description = "tokenIssue and updateAsset with suicide to contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "tokenIssue and updateAsset with suicide to contract", + groups = {"contract", "daily"}) public void tokenIssue002AndSuicideToContract() { String filePath = "./src/test/resources/soliditycode/tvmAssetIssue005.sol"; - String contractName = "tvmAssetIssue005"; + String contractName = "tvmAssetIssue005"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); long callvalue = 1050000000L; - // deploy - String deployTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callvalue, 0, 10000, "0", 0L, null, dev001Key, dev001Address, + // deploy + String deployTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callvalue, + 0, + 10000, + "0", + 0L, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(deployTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(deployTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (deployTxid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } byte[] contractAddress2 = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(contractAddress2, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress2, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - long contractAddressBalance2 = PublicMethod.queryAccount(contractAddress2, blockingStubFull) - .getBalance(); + long contractAddressBalance2 = + PublicMethod.queryAccount(contractAddress2, blockingStubFull).getBalance(); Assert.assertEquals(callvalue, contractAddressBalance2); - deployTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - callvalue, 0, 10000, "0", 0L, null, dev001Key, dev001Address, + deployTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + callvalue, + 0, + 10000, + "0", + 0L, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(deployTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(deployTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (deployTxid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } contractAddress = infoById.get().getContractAddress().toByteArray(); - smartContract = PublicMethod - .getContract(contractAddress, blockingStubFull); + smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - contractAddressBalance = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + contractAddressBalance = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(callvalue, contractAddressBalance); - // tokenIssue + // tokenIssue name = "testAssetIssu2_" + Long.toString(now); abbr = "testAsse2_" + Long.toString(now); - String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; - String tokenName = PublicMethod.stringToHexString(name); - String tokenAbbr = PublicMethod.stringToHexString(abbr); - String param = - "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; + String methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; + String tokenName = PublicMethod.stringToHexString(name); + String tokenAbbr = PublicMethod.stringToHexString(abbr); + String param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; logger.info("param: " + param); - String txid = PublicMethod.triggerContract(contractAddress2, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress2, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - String assetIssueId = PublicMethod.queryAccount(contractAddress2, blockingStubFull) - .getAssetIssuedID() - .toStringUtf8(); + String assetIssueId = + PublicMethod.queryAccount(contractAddress2, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); long returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); logger.info("returnAssetId: " + returnAssetId); Assert.assertEquals(returnAssetId, Long.parseLong(assetIssueId)); - logger.info("getAssetV2Map(): " + PublicMethod.queryAccount(contractAddress2, blockingStubFull) - .getAssetV2Map()); - long assetIssueValue = PublicMethod.queryAccount(contractAddress2, blockingStubFull) - .getAssetV2Map().get(assetIssueId); + logger.info( + "getAssetV2Map(): " + + PublicMethod.queryAccount(contractAddress2, blockingStubFull).getAssetV2Map()); + long assetIssueValue = + PublicMethod.queryAccount(contractAddress2, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); Assert.assertEquals(totalSupply, assetIssueValue); - AssetIssueContract assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + AssetIssueContract assetIssueById = + PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); Assert.assertEquals(totalSupply, assetIssueById.getTotalSupply()); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress2), + Assert.assertEquals( + Base58.encode58Check(contractAddress2), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); AssetIssueContract assetIssueByName = PublicMethod.getAssetIssueByName(name, blockingStubFull); - AssetIssueContract assetIssueByAccount = PublicMethod - .getAssetIssueByAccount(contractAddress2, blockingStubFull).get().getAssetIssue(0); - AssetIssueContract assetIssueListByName = PublicMethod - .getAssetIssueListByName(name, blockingStubFull) - .get().getAssetIssue(0); + AssetIssueContract assetIssueByAccount = + PublicMethod.getAssetIssueByAccount(contractAddress2, blockingStubFull) + .get() + .getAssetIssue(0); + AssetIssueContract assetIssueListByName = + PublicMethod.getAssetIssueListByName(name, blockingStubFull).get().getAssetIssue(0); Assert.assertEquals(assetIssueId, assetIssueByName.getId()); Assert.assertEquals(name, ByteArray.toStr(assetIssueByAccount.getName().toByteArray())); Assert.assertEquals(assetIssueId, assetIssueListByName.getId()); - long contractAddressBalanceAfter2 = PublicMethod - .queryAccount(contractAddress2, blockingStubFull) - .getBalance(); + long contractAddressBalanceAfter2 = + PublicMethod.queryAccount(contractAddress2, blockingStubFull).getBalance(); Assert.assertEquals(contractAddressBalance2 - 1024000000L, contractAddressBalanceAfter2); - // transferToken + // transferToken String methodTransferToken = "transferToken(address,uint256,trcToken)"; param = "\"" + Base58.encode58Check(dev002Address) + "\"," + 100 + ",\"" + assetIssueId + "\""; - txid = PublicMethod.triggerContract(contractAddress2, methodTransferToken, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress2, + methodTransferToken, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - long assetIssueValueAfter = PublicMethod.queryAccount(contractAddress2, blockingStubFull) - .getAssetV2Map().get(assetIssueId); - long dev002AssetValue = PublicMethod - .getAssetIssueValue(dev002Address, ByteString.copyFrom(assetIssueId.getBytes()), - blockingStubFull); + long assetIssueValueAfter = + PublicMethod.queryAccount(contractAddress2, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); + long dev002AssetValue = + PublicMethod.getAssetIssueValue( + dev002Address, ByteString.copyFrom(assetIssueId.getBytes()), blockingStubFull); Assert.assertEquals(assetIssueValue - 100L, assetIssueValueAfter); Assert.assertEquals(100L, dev002AssetValue); - param = - "\"" + Base58.encode58Check(contractAddress) + "\"," + 50 + ",\"" + assetIssueId + "\""; - txid = PublicMethod.triggerContract(contractAddress2, methodTransferToken, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + param = "\"" + Base58.encode58Check(contractAddress) + "\"," + 50 + ",\"" + assetIssueId + "\""; + txid = + PublicMethod.triggerContract( + contractAddress2, + methodTransferToken, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - long assetIssueValueAfter2 = PublicMethod.queryAccount(contractAddress2, blockingStubFull) - .getAssetV2Map().get(assetIssueId); - long contractAssetValue = PublicMethod - .getAssetIssueValue(contractAddress, ByteString.copyFrom(assetIssueId.getBytes()), - blockingStubFull); + long assetIssueValueAfter2 = + PublicMethod.queryAccount(contractAddress2, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); + long contractAssetValue = + PublicMethod.getAssetIssueValue( + contractAddress, ByteString.copyFrom(assetIssueId.getBytes()), blockingStubFull); Assert.assertEquals(assetIssueValueAfter - 50L, assetIssueValueAfter2); Assert.assertEquals(50L, contractAssetValue); - // selfdestruct + // selfdestruct String methodSuicide = "SelfdestructTest(address)"; param = "\"" + Base58.encode58Check(contractAddress) + "\""; logger.info("param: " + param); - txid = PublicMethod.triggerContract(contractAddress2, methodSuicide, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress2, + methodSuicide, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - Assert.assertEquals(0, - PublicMethod.queryAccount(contractAddress2, blockingStubFull).getAssetIssuedID().size()); - Assert.assertEquals(0, - PublicMethod.getAssetIssueByAccount(contractAddress, blockingStubFull).get() + Assert.assertEquals( + 0, PublicMethod.queryAccount(contractAddress2, blockingStubFull).getAssetIssuedID().size()); + Assert.assertEquals( + 0, + PublicMethod.getAssetIssueByAccount(contractAddress, blockingStubFull) + .get() .getAssetIssueCount()); - Assert.assertEquals(0, - PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID().size()); - assetIssueValue = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map().get(assetIssueId); + Assert.assertEquals( + 0, PublicMethod.queryAccount(contractAddress, blockingStubFull).getAssetIssuedID().size()); + assetIssueValue = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); Assert.assertEquals(assetIssueValueAfter2 + 50L, assetIssueValue); - assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + assetIssueById = PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(assetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(assetIssueById.getAbbr().toByteArray())); Assert.assertEquals(totalSupply, assetIssueById.getTotalSupply()); Assert.assertEquals(6, assetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(contractAddress2), + Assert.assertEquals( + Base58.encode58Check(contractAddress2), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); assetIssueByName = PublicMethod.getAssetIssueByName(name, blockingStubFull); - assetIssueByAccount = PublicMethod - .getAssetIssueByAccount(contractAddress2, blockingStubFull).get().getAssetIssue(0); - assetIssueListByName = PublicMethod - .getAssetIssueListByName(name, blockingStubFull) - .get().getAssetIssue(0); + assetIssueByAccount = + PublicMethod.getAssetIssueByAccount(contractAddress2, blockingStubFull) + .get() + .getAssetIssue(0); + assetIssueListByName = + PublicMethod.getAssetIssueListByName(name, blockingStubFull).get().getAssetIssue(0); Assert.assertEquals(assetIssueId, assetIssueByName.getId()); Assert.assertEquals(name, ByteArray.toStr(assetIssueByAccount.getName().toByteArray())); Assert.assertEquals(assetIssueId, assetIssueListByName.getId()); - // transferToken,success + // transferToken,success methodTransferToken = "transferToken(address,uint256,trcToken)"; param = "\"" + Base58.encode58Check(dev002Address) + "\"," + 100 + ",\"" + assetIssueId + "\""; - txid = PublicMethod.triggerContract(contractAddress, methodTransferToken, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodTransferToken, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - assetIssueValueAfter = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getAssetV2Map().get(assetIssueId); - dev002AssetValue = PublicMethod - .getAssetIssueValue(dev002Address, ByteString.copyFrom(assetIssueId.getBytes()), - blockingStubFull); + assetIssueValueAfter = + PublicMethod.queryAccount(contractAddress, blockingStubFull) + .getAssetV2Map() + .get(assetIssueId); + dev002AssetValue = + PublicMethod.getAssetIssueValue( + dev002Address, ByteString.copyFrom(assetIssueId.getBytes()), blockingStubFull); Assert.assertEquals(assetIssueValue - 100L, assetIssueValueAfter); Assert.assertEquals(200L, dev002AssetValue); - Assert.assertTrue(PublicMethod.transferAsset(dev004Address, assetIssueId.getBytes(), 12L, - dev002Address, dev002Key, blockingStubFull)); - PublicMethod.waitProduceNextBlock(blockingStubFull); - long assetIssueValueDev002After = PublicMethod - .getAssetIssueValue(dev002Address, ByteString.copyFrom(assetIssueId.getBytes()), - blockingStubFull); - long assetIssueValueDev004 = PublicMethod - .getAssetIssueValue(dev004Address, ByteString.copyFrom(assetIssueId.getBytes()), - blockingStubFull); + Assert.assertTrue( + PublicMethod.transferAsset( + dev004Address, + assetIssueId.getBytes(), + 12L, + dev002Address, + dev002Key, + blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + long assetIssueValueDev002After = + PublicMethod.getAssetIssueValue( + dev002Address, ByteString.copyFrom(assetIssueId.getBytes()), blockingStubFull); + long assetIssueValueDev004 = + PublicMethod.getAssetIssueValue( + dev004Address, ByteString.copyFrom(assetIssueId.getBytes()), blockingStubFull); Assert.assertEquals(12L, assetIssueValueDev004); Assert.assertEquals(dev002AssetValue - 12L, assetIssueValueDev002After); - // updateAsset,will fail + // updateAsset,will fail String methodUpdateAsset = "updateAsset(trcToken,string,string)"; param = "\"" + assetIssueId + "\",\"updateUrl\",\"updateDesc\""; logger.info("param: " + param); - txid = PublicMethod.triggerContract(contractAddress, methodUpdateAsset, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodUpdateAsset, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); long returnId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(0, returnId); - assetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + assetIssueById = PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(0, assetIssueById.getDescription().size()); Assert.assertEquals(0, assetIssueById.getUrl().size()); - Assert.assertEquals(Base58.encode58Check(contractAddress2), + Assert.assertEquals( + Base58.encode58Check(contractAddress2), Base58.encode58Check(assetIssueById.getOwnerAddress().toByteArray())); } - @Test(enabled = false, description = "tokenIssue and updateAsset suicide with create2", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "tokenIssue and updateAsset suicide with create2", + groups = {"contract", "daily"}) public void tokenIssue003AndSuicideWithCreate2() { String filePath = "./src/test/resources/soliditycode/tvmAssetIssue005.sol"; - String contractName = "B"; + String contractName = "B"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String deployTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, - 0, 0, 10000, "0", 0L, null, dev001Key, dev001Address, + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String deployTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0, + 0, + 10000, + "0", + 0L, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(deployTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(deployTxid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); if (deployTxid == null || infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod - .getContract(contractAddress, blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - String methodTokenIssue = "deploy(uint256)"; - String param = "" + 6; + String methodTokenIssue = "deploy(uint256)"; + String param = "" + 6; logger.info("param: " + param); - String txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info( - "the value: " + PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - List retList = PublicMethod - .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + "the value: " + + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + List retList = + PublicMethod.getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); logger.info("actualSalt: " + actualSalt); - byte[] tmpAddress = new byte[20]; - System.arraycopy(ByteArray.fromHexString(retList.get(0)), - 12, tmpAddress, 0, 20); - String addressHex = "41" + ByteArray.toHexString(tmpAddress); + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); logger.info("address_hex: " + addressHex); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); - byte[] callContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + byte[] callContractAddress = WalletClient.decodeFromBase58Check(addressFinal); - Assert.assertTrue(PublicMethod - .sendcoin(callContractAddress, 1500_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + callContractAddress, 1500_000_000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); name = "testAssetIssu3_" + Long.toString(now); abbr = "testAsse3_" + Long.toString(now); methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; - String tokenName = PublicMethod.stringToHexString(name); - String tokenAbbr = PublicMethod.stringToHexString(abbr); - param = - "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; + String tokenName = PublicMethod.stringToHexString(name); + String tokenAbbr = PublicMethod.stringToHexString(abbr); + param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; logger.info("param: " + param); - txid = PublicMethod.triggerContract(callContractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + callContractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - String assetIssueId = PublicMethod.queryAccount(callContractAddress, blockingStubFull) - .getAssetIssuedID().toStringUtf8(); + String assetIssueId = + PublicMethod.queryAccount(callContractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId: " + assetIssueId); long returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); logger.info("returnAssetId: " + returnAssetId); Assert.assertEquals(returnAssetId, Long.parseLong(assetIssueId)); - String methodSuicide = "SelfdestructTest(address)"; + String methodSuicide = "SelfdestructTest(address)"; param = "\"" + Base58.encode58Check(dev003Address) + "\"," + 10000000; logger.info("param: " + param); - txid = PublicMethod.triggerContract(callContractAddress, methodSuicide, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + callContractAddress, + methodSuicide, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); methodTokenIssue = "deploy(uint256)"; param = "" + 6; logger.info("param: " + param); - txid = PublicMethod.triggerContract(contractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod - .sendcoin(callContractAddress, 1500_000_000L, fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + callContractAddress, 1500_000_000L, fromAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); methodTokenIssue = "tokenIssue(bytes32,bytes32,uint64,uint8)"; tokenName = PublicMethod.stringToHexString("testAssetIssue_11111"); tokenAbbr = PublicMethod.stringToHexString("testAssetIssue_22222"); - param = - "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; + param = "\"" + tokenName + "\",\"" + tokenAbbr + "\"," + totalSupply + "," + 6; logger.info("param: " + param); - txid = PublicMethod.triggerContract(callContractAddress, methodTokenIssue, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + callContractAddress, + methodTokenIssue, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - String assetIssueId2 = PublicMethod.queryAccount(callContractAddress, blockingStubFull) - .getAssetIssuedID().toStringUtf8(); + String assetIssueId2 = + PublicMethod.queryAccount(callContractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("assetIssueId2: " + assetIssueId2); returnAssetId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); logger.info("returnAssetId: " + returnAssetId); Assert.assertEquals(returnAssetId, Long.parseLong(assetIssueId2)); Assert.assertEquals(Long.parseLong(assetIssueId) + 1, Long.parseLong(assetIssueId2)); - Assert.assertEquals(2, - PublicMethod.getAssetIssueByAccount(callContractAddress, blockingStubFull).get() + Assert.assertEquals( + 2, + PublicMethod.getAssetIssueByAccount(callContractAddress, blockingStubFull) + .get() .getAssetIssueCount()); - // updateAsset + // updateAsset String methodUpdateAsset = "updateAsset(trcToken,string,string)"; param = "\"123\",\"updateURLURL\",\"updateDESCDESC\""; logger.info("param: " + param); - txid = PublicMethod.triggerContract(callContractAddress, methodUpdateAsset, param, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + txid = + PublicMethod.triggerContract( + callContractAddress, + methodUpdateAsset, + param, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); long returnId = ByteArray.toLong((infoById.get().getContractResult(0).toByteArray())); Assert.assertEquals(1, returnId); - String newAssetIssueId = PublicMethod.queryAccount(callContractAddress, blockingStubFull) - .getAssetIssuedID() - .toStringUtf8(); + String newAssetIssueId = + PublicMethod.queryAccount(callContractAddress, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8(); logger.info("newAssetIssueId: " + newAssetIssueId); - AssetIssueContract newAssetIssueById = PublicMethod - .getAssetIssueById(newAssetIssueId, blockingStubFull); - Assert.assertEquals("testAssetIssue_11111", - ByteArray.toStr(newAssetIssueById.getName().toByteArray())); - Assert.assertEquals("testAssetIssue_22222", - ByteArray.toStr(newAssetIssueById.getAbbr().toByteArray())); - Assert - .assertEquals("updateDESCDESC", - ByteArray.toStr(newAssetIssueById.getDescription().toByteArray())); + AssetIssueContract newAssetIssueById = + PublicMethod.getAssetIssueById(newAssetIssueId, blockingStubFull); + Assert.assertEquals( + "testAssetIssue_11111", ByteArray.toStr(newAssetIssueById.getName().toByteArray())); + Assert.assertEquals( + "testAssetIssue_22222", ByteArray.toStr(newAssetIssueById.getAbbr().toByteArray())); + Assert.assertEquals( + "updateDESCDESC", ByteArray.toStr(newAssetIssueById.getDescription().toByteArray())); Assert.assertEquals("updateURLURL", ByteArray.toStr(newAssetIssueById.getUrl().toByteArray())); Assert.assertEquals(6, newAssetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(callContractAddress), + Assert.assertEquals( + Base58.encode58Check(callContractAddress), Base58.encode58Check(newAssetIssueById.getOwnerAddress().toByteArray())); - AssetIssueContract oldAssetIssueById = PublicMethod - .getAssetIssueById(assetIssueId, blockingStubFull); + AssetIssueContract oldAssetIssueById = + PublicMethod.getAssetIssueById(assetIssueId, blockingStubFull); Assert.assertEquals(name, ByteArray.toStr(oldAssetIssueById.getName().toByteArray())); Assert.assertEquals(abbr, ByteArray.toStr(oldAssetIssueById.getAbbr().toByteArray())); Assert.assertEquals(0, oldAssetIssueById.getDescription().size()); Assert.assertEquals(0, oldAssetIssueById.getUrl().size()); Assert.assertEquals(6, oldAssetIssueById.getPrecision()); - Assert.assertEquals(Base58.encode58Check(callContractAddress), + Assert.assertEquals( + Base58.encode58Check(callContractAddress), Base58.encode58Check(oldAssetIssueById.getOwnerAddress().toByteArray())); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); } + PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/ContractRewardTest001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/ContractRewardTest001.java index a8e4b115..9aa94d93 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/ContractRewardTest001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/ContractRewardTest001.java @@ -4,7 +4,6 @@ import java.util.HashMap; import lombok.extern.slf4j.Slf4j; import org.testng.Assert; -import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.BytesMessage; import org.tron.api.GrpcAPI.Return.response_code; @@ -16,192 +15,327 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class ContractRewardTest001 extends TronBaseTest { - private String testFoundationKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private String testFoundationKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); private String witnessAddress = PublicMethod.getAddressString(witnessKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey1.getAddress(); String testKey001 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private byte[] contractAddress; - //= Base58.decode58Check("TQYK8QPAFtxjmse1dShHWYXEMsF836jxxe"); + // = Base58.decode58Check("TQYK8QPAFtxjmse1dShHWYXEMsF836jxxe"); // @BeforeSuite(enabled = false, description = "stake beforeSuite delete") -// public void beforeSuite() { -// -// PublicMethod.printAddress(testKey001); -////// -// PublicMethod -// .sendcoin(testAddress001, 1000_000_000L, testFoundationAddress, testFoundationKey, -// blockingStubFull); -// -// String filePath = "src/test/resources/soliditycode/stackContract001.sol"; -// String contractName = "B"; -// HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); -// String code = retMap.get("byteCode").toString(); -// String abi = retMap.get("abI").toString(); -// contractAddress = PublicMethod -// .deployContract(contractName, abi, code, "", maxFeeLimit, 100_000_000L, 100, null, -// testFoundationKey, testFoundationAddress, blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); -// -// PublicMethod.triggerContract(contractAddress,"Stake(address,uint256)", -// "\"" + witnessAddress + "\",10000000",false,0,maxFeeLimit, -// testFoundationAddress, testFoundationKey,blockingStubFull); -// } - - @Test(enabled = false,description = "querry SR account, reward should equal to gerRewardInfo", groups = {"contract", "daily"}) + // public void beforeSuite() { + // + // PublicMethod.printAddress(testKey001); + ////// + // PublicMethod + // .sendcoin(testAddress001, 1000_000_000L, testFoundationAddress, testFoundationKey, + // blockingStubFull); + // + // String filePath = "src/test/resources/soliditycode/stackContract001.sol"; + // String contractName = "B"; + // HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); + // String code = retMap.get("byteCode").toString(); + // String abi = retMap.get("abI").toString(); + // contractAddress = PublicMethod + // .deployContract(contractName, abi, code, "", maxFeeLimit, 100_000_000L, 100, null, + // testFoundationKey, testFoundationAddress, blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + // + // PublicMethod.triggerContract(contractAddress,"Stake(address,uint256)", + // "\"" + witnessAddress + "\",10000000",false,0,maxFeeLimit, + // testFoundationAddress, testFoundationKey,blockingStubFull); + // } + + @Test( + enabled = false, + description = "querry SR account, reward should equal to gerRewardInfo", + groups = {"contract", "daily"}) void rewardbalanceTest001() { - BytesMessage bytesMessage = BytesMessage.newBuilder().setValue(ByteString - .copyFrom(PublicMethod.getFinalAddress(witnessKey))) - .build(); + BytesMessage bytesMessage = + BytesMessage.newBuilder() + .setValue(ByteString.copyFrom(PublicMethod.getFinalAddress(witnessKey))) + .build(); long reward = blockingStubFull.getRewardInfo(bytesMessage).getNum(); - String methedStr = "rewardBalance(address)"; - String argStr = "\"" + witnessAddress + "\""; - TransactionExtention txen = PublicMethod.triggerConstantContractForExtention(contractAddress, - methedStr,argStr,false,0,maxFeeLimit,"0",0,testAddress001,testKey001,blockingStubFull); + String methedStr = "rewardBalance(address)"; + String argStr = "\"" + witnessAddress + "\""; + TransactionExtention txen = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress001, + testKey001, + blockingStubFull); System.out.println(txen); long rewardBalance = ByteArray.toLong(txen.getConstantResult(0).toByteArray()); Assert.assertEquals(txen.getResult().getCode(), response_code.SUCCESS); - Assert.assertEquals(reward,rewardBalance); + Assert.assertEquals(reward, rewardBalance); } - @Test(enabled = false,description = "querry 0x00, reward should be 0", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "querry 0x00, reward should be 0", + groups = {"contract", "daily"}) void rewardbalanceTest002() { String methedStr = "nullAddressTest()"; - String argStr = ""; - TransactionExtention txen = PublicMethod.triggerConstantContractForExtention(contractAddress, - methedStr,argStr,false,0,maxFeeLimit,"0",0,testAddress001,testKey001,blockingStubFull); + String argStr = ""; + TransactionExtention txen = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress001, + testKey001, + blockingStubFull); long rewardBalance = ByteArray.toLong(txen.getConstantResult(0).toByteArray()); Assert.assertEquals(txen.getResult().getCode(), response_code.SUCCESS); - Assert.assertEquals(rewardBalance,0); + Assert.assertEquals(rewardBalance, 0); } - @Test(enabled = false,description = "querry UnActive account , reward should be 0", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "querry UnActive account , reward should be 0", + groups = {"contract", "daily"}) void rewardbalanceTest003() { ECKey ecKey2 = new ECKey(Utils.getRandom()); - String key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - String methedStr = "rewardBalance(address)"; - String argStr = "\"" + PublicMethod.getAddressString(key) + "\""; - TransactionExtention txen = PublicMethod.triggerConstantContractForExtention(contractAddress, - methedStr,argStr,false,0,maxFeeLimit,"0",0,testAddress001,testKey001,blockingStubFull); + String key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + String methedStr = "rewardBalance(address)"; + String argStr = "\"" + PublicMethod.getAddressString(key) + "\""; + TransactionExtention txen = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress001, + testKey001, + blockingStubFull); long rewardBalance = ByteArray.toLong(txen.getConstantResult(0).toByteArray()); Assert.assertEquals(txen.getResult().getCode(), response_code.SUCCESS); - Assert.assertEquals(rewardBalance,0); + Assert.assertEquals(rewardBalance, 0); } - @Test(enabled = false,description = "querry contract account,reward should equal to " - + "gerRewardInfo", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "querry contract account,reward should equal to " + "gerRewardInfo", + groups = {"contract", "daily"}) void rewardbalanceTest004() { - BytesMessage bytesMessage = BytesMessage.newBuilder().setValue(ByteString - .copyFrom(contractAddress)) - .build(); + BytesMessage bytesMessage = + BytesMessage.newBuilder().setValue(ByteString.copyFrom(contractAddress)).build(); long reward = blockingStubFull.getRewardInfo(bytesMessage).getNum(); - String methedStr = "rewardBalance(address)"; - String argStr = "\"" + Base58.encode58Check(contractAddress) + "\""; - TransactionExtention txen = PublicMethod.triggerConstantContractForExtention(contractAddress, - methedStr,argStr,false,0,maxFeeLimit,"0",0,testAddress001,testKey001,blockingStubFull); + String methedStr = "rewardBalance(address)"; + String argStr = "\"" + Base58.encode58Check(contractAddress) + "\""; + TransactionExtention txen = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress001, + testKey001, + blockingStubFull); long rewardBalance = ByteArray.toLong(txen.getConstantResult(0).toByteArray()); logger.info("rewardBalance: " + rewardBalance); logger.info("reward: " + reward); Assert.assertEquals(txen.getResult().getCode(), response_code.SUCCESS); - Assert.assertEquals(rewardBalance,reward); + Assert.assertEquals(rewardBalance, reward); } - @Test(enabled = false,description = "querry ZeroReward account, reward should be 0", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "querry ZeroReward account, reward should be 0", + groups = {"contract", "daily"}) void rewardbalanceTest005() { - BytesMessage bytesMessage = BytesMessage.newBuilder().setValue(ByteString - .copyFrom(PublicMethod.getFinalAddress(testFoundationKey))) - .build(); + BytesMessage bytesMessage = + BytesMessage.newBuilder() + .setValue(ByteString.copyFrom(PublicMethod.getFinalAddress(testFoundationKey))) + .build(); long reward = blockingStubFull.getRewardInfo(bytesMessage).getNum(); - String methedStr = "rewardBalance(address)"; - String argStr = "\"" + PublicMethod.getAddressString(testFoundationKey) + "\""; - TransactionExtention txen = PublicMethod.triggerConstantContractForExtention(contractAddress, - methedStr,argStr,false,0,maxFeeLimit,"0",0,testAddress001,testKey001,blockingStubFull); + String methedStr = "rewardBalance(address)"; + String argStr = "\"" + PublicMethod.getAddressString(testFoundationKey) + "\""; + TransactionExtention txen = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress001, + testKey001, + blockingStubFull); long rewardBalance = ByteArray.toLong(txen.getConstantResult(0).toByteArray()); Assert.assertEquals(txen.getResult().getCode(), response_code.SUCCESS); - Assert.assertEquals(reward,rewardBalance,0); + Assert.assertEquals(reward, rewardBalance, 0); } - @Test(enabled = false,description = "withdrawBalance", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "withdrawBalance", + groups = {"contract", "daily"}) void withdrawBalanceTest006() { - //contractAddress = Base58.decode58Check("TBsf2FCSht83CEA8CSZ1ReQTRDByNB7FCe"); - String methedStr = "withdrawRewardTest()"; - String argStr = ""; - String txid = PublicMethod.triggerContract(contractAddress, - methedStr,argStr,false,0,maxFeeLimit,"0",0,testAddress001,testKey001,blockingStubFull); + // contractAddress = Base58.decode58Check("TBsf2FCSht83CEA8CSZ1ReQTRDByNB7FCe"); + String methedStr = "withdrawRewardTest()"; + String argStr = ""; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo ext = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); - int result = ByteArray.toInt(ext.getContractResult(0).toByteArray()); - Assert.assertEquals(result,0); + int result = ByteArray.toInt(ext.getContractResult(0).toByteArray()); + Assert.assertEquals(result, 0); Assert.assertEquals(ext.getResult(), code.SUCESS); } - @Test(enabled = false,description = "withdrawBalance twice", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "withdrawBalance twice", + groups = {"contract", "daily"}) void withdrawBalanceTest007() { String methedStr = "withdrawRewardTest()"; - String argStr = ""; - String txid = PublicMethod.triggerContract(contractAddress, - methedStr,argStr,false,0,maxFeeLimit,"0",0,testAddress001,testKey001,blockingStubFull); + String argStr = ""; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo ext = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); - int result = ByteArray.toInt(ext.getContractResult(0).toByteArray()); - Assert.assertEquals(result,0); + int result = ByteArray.toInt(ext.getContractResult(0).toByteArray()); + Assert.assertEquals(result, 0); Assert.assertEquals(ext.getResult(), code.SUCESS); } - @Test(enabled = false,description = "withdrawBalance other contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "withdrawBalance other contract", + groups = {"contract", "daily"}) void withdrawBalanceTest008() { String filePath = "src/test/resources/soliditycode/stackContract001.sol"; - String contractName = "B"; + String contractName = "B"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - byte[] otherContract = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 100_000_000L, 100, null, - testFoundationKey, testFoundationAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] otherContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 100_000_000L, + 100, + null, + testFoundationKey, + testFoundationAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String methedStr = "contractBWithdrawRewardTest(address)"; - String argStr = "\"" + Base58.encode58Check(otherContract) + "\""; - String txid = PublicMethod.triggerContract(contractAddress, - methedStr,argStr,false,0,maxFeeLimit,"0",0,testAddress001,testKey001,blockingStubFull); + String methedStr = "contractBWithdrawRewardTest(address)"; + String argStr = "\"" + Base58.encode58Check(otherContract) + "\""; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo ext = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); - int result = ByteArray.toInt(ext.getContractResult(0).toByteArray()); - Assert.assertEquals(result,0); + int result = ByteArray.toInt(ext.getContractResult(0).toByteArray()); + Assert.assertEquals(result, 0); Assert.assertEquals(ext.getResult(), TransactionInfo.code.SUCESS); } - @Test(enabled = false,description = "new withdrawBalance constructor", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "new withdrawBalance constructor", + groups = {"contract", "daily"}) void withdrawBalanceTest009() { String methedStr = "createA()"; - String argStr = ""; - String txid = PublicMethod.triggerContract(contractAddress, - methedStr,argStr,false,0,maxFeeLimit,"0",0,testAddress001,testKey001,blockingStubFull); + String argStr = ""; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + "0", + 0, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); TransactionInfo ext = PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); - int result = ByteArray.toInt(ext.getLog(0).getData().toByteArray()); - Assert.assertEquals(result,0); - int result2 = ByteArray.toInt(ext.getLog(1).getData().toByteArray()); - Assert.assertEquals(result2,0); + int result = ByteArray.toInt(ext.getLog(0).getData().toByteArray()); + Assert.assertEquals(result, 0); + int result2 = ByteArray.toInt(ext.getLog(1).getData().toByteArray()); + Assert.assertEquals(result2, 0); Assert.assertEquals(ext.getResult(), code.SUCESS); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/IsSrCandidateTest001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/IsSrCandidateTest001.java index 0314d39a..33ca8dee 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/IsSrCandidateTest001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/IsSrCandidateTest001.java @@ -10,83 +10,142 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - public class IsSrCandidateTest001 extends TronBaseTest { - private String testFoundationKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); +import stest.tron.wallet.common.client.utils.Utils; + +public class IsSrCandidateTest001 extends TronBaseTest { + private String testFoundationKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey1.getAddress(); String testKey001 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private byte[] contractAddress; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = false) public void beforeClass() { - PublicMethod.printAddress(testKey001); PublicMethod - .sendcoin(testAddress001, 1000_000_000L, testFoundationAddress, testFoundationKey, - blockingStubFull); + PublicMethod.printAddress(testKey001); + PublicMethod.sendcoin( + testAddress001, 1000_000_000L, testFoundationAddress, testFoundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/isSRCandidate.sol"; - String contractName = "TestIsSRCandidate"; + String filePath = "src/test/resources/soliditycode/isSRCandidate.sol"; + String contractName = "TestIsSRCandidate"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, testKey001, - testAddress001, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); } - @Test(enabled = false, description = "Witness Address should be true", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Witness Address should be true", + groups = {"contract", "daily"}) void tvmStakeTest001() { String methodStr = "isSRCandidateTest(address)"; - String argsStr = "\"" + PublicMethod.getAddressString(witnessKey) + "\""; - TransactionExtention returns = PublicMethod - .triggerConstantContractForExtention(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, "", 0, testAddress001, testKey001, blockingStubFull); - int isSR = ByteArray.toInt(returns.getConstantResult(0).toByteArray()); + String argsStr = "\"" + PublicMethod.getAddressString(witnessKey) + "\""; + TransactionExtention returns = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + "", + 0, + testAddress001, + testKey001, + blockingStubFull); + int isSR = ByteArray.toInt(returns.getConstantResult(0).toByteArray()); - Assert.assertEquals(isSR,1); + Assert.assertEquals(isSR, 1); } - @Test(enabled = false, description = "Account Address should be false", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Account Address should be false", + groups = {"contract", "daily"}) void tvmStakeTest002() { String methodStr = "isSRCandidateTest(address)"; - String argsStr = "\"" + Base58.encode58Check(testAddress001) + "\""; - TransactionExtention returns = PublicMethod - .triggerConstantContractForExtention(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, "", 0, testAddress001, testKey001, blockingStubFull); - int isSR = ByteArray.toInt(returns.getConstantResult(0).toByteArray()); + String argsStr = "\"" + Base58.encode58Check(testAddress001) + "\""; + TransactionExtention returns = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + "", + 0, + testAddress001, + testKey001, + blockingStubFull); + int isSR = ByteArray.toInt(returns.getConstantResult(0).toByteArray()); - Assert.assertEquals(isSR,0); + Assert.assertEquals(isSR, 0); } - @Test(enabled = false, description = "zero Address(0x00) should be false", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "zero Address(0x00) should be false", + groups = {"contract", "daily"}) void tvmStakeTest003() { String methodStr = "zeroAddressTest()"; - String argsStr = ""; - TransactionExtention returns = PublicMethod - .triggerConstantContractForExtention(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, "", 0, testAddress001, testKey001, blockingStubFull); - int isSR = ByteArray.toInt(returns.getConstantResult(0).toByteArray()); + String argsStr = ""; + TransactionExtention returns = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + "", + 0, + testAddress001, + testKey001, + blockingStubFull); + int isSR = ByteArray.toInt(returns.getConstantResult(0).toByteArray()); - Assert.assertEquals(isSR,0); + Assert.assertEquals(isSR, 0); } - @Test(enabled = false, description = "Contract Address should be false", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Contract Address should be false", + groups = {"contract", "daily"}) void tvmStakeTest004() { String methodStr = "localContractAddrTest()"; - String argsStr = ""; - TransactionExtention returns = PublicMethod - .triggerConstantContractForExtention(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, "", 0, testAddress001, testKey001, blockingStubFull); - int isSR = ByteArray.toInt(returns.getConstantResult(0).toByteArray()); + String argsStr = ""; + TransactionExtention returns = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + "", + 0, + testAddress001, + testKey001, + blockingStubFull); + int isSR = ByteArray.toInt(returns.getConstantResult(0).toByteArray()); - Assert.assertEquals(isSR,0); + Assert.assertEquals(isSR, 0); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StackSuicideTest001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StackSuicideTest001.java index 4c35692c..0f9ab68e 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StackSuicideTest001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StackSuicideTest001.java @@ -15,192 +15,341 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class StackSuicideTest001 extends TronBaseTest { - private String testFoundationKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private String testFoundationKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); - private String testWitnessAddress = PublicMethod.getAddressString(witnessKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); + private String testWitnessAddress = PublicMethod.getAddressString(witnessKey); + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey1.getAddress(); String testKey001 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private byte[] contractAddress; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = false) public void beforeClass() { - PublicMethod.printAddress(testKey001); PublicMethod - .sendcoin(testAddress001, 1000_000_000L, testFoundationAddress, testFoundationKey, - blockingStubFull); + PublicMethod.printAddress(testKey001); + PublicMethod.sendcoin( + testAddress001, 1000_000_000L, testFoundationAddress, testFoundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - } - @Test(enabled = false, description = "targetAddress no TRX, and no frozen", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "targetAddress no TRX, and no frozen", + groups = {"contract", "daily"}) public void stackSuicideTest001() { String filePath = "src/test/resources/soliditycode/stackSuicide001.sol"; - String contractName = "testStakeSuicide"; + String contractName = "testStakeSuicide"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 10000000L, 100, null, testKey001, - testAddress001, blockingStubFull); - final byte[] targetAddress = PublicMethod.deployContract(contractName, abi, code, "", - maxFeeLimit, 0, 100, null, testKey001, testAddress001, blockingStubFull); - String txid = PublicMethod.triggerContract(contractAddress,"Stake(address,uint256)", - "\"" + testWitnessAddress + "\",10000000",false,0,maxFeeLimit, - testFoundationAddress, testFoundationKey,blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 10000000L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); + final byte[] targetAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + "Stake(address,uint256)", + "\"" + testWitnessAddress + "\",10000000", + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional ex = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()),1); - - Account ownerAccount = PublicMethod.queryAccount(contractAddress,blockingStubFull); - final Frozen ownerFrozen = ownerAccount.getFrozen(0); - String methedStr = "SelfdestructTest(address)"; - String argStr = "\"" + Base58.encode58Check(targetAddress) + "\""; - txid = PublicMethod.triggerContract(contractAddress,methedStr,argStr,false, - 0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()), 1); + + Account ownerAccount = PublicMethod.queryAccount(contractAddress, blockingStubFull); + final Frozen ownerFrozen = ownerAccount.getFrozen(0); + String methedStr = "SelfdestructTest(address)"; + String argStr = "\"" + Base58.encode58Check(targetAddress) + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - ex = PublicMethod.getTransactionInfoById(txid,blockingStubFull); + ex = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Account targetAccount = PublicMethod.queryAccount(targetAddress,blockingStubFull); + Account targetAccount = PublicMethod.queryAccount(targetAddress, blockingStubFull); Frozen targetFrozen = targetAccount.getFrozen(0); - Assert.assertEquals(ownerFrozen.getExpireTime(),targetFrozen.getExpireTime()); - Assert.assertEquals(ownerFrozen.getFrozenBalance(),targetFrozen.getFrozenBalance()); - + Assert.assertEquals(ownerFrozen.getExpireTime(), targetFrozen.getExpireTime()); + Assert.assertEquals(ownerFrozen.getFrozenBalance(), targetFrozen.getFrozenBalance()); } - @Test(enabled = false, description = "targetAddress has TRX, but no frozen", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "targetAddress has TRX, but no frozen", + groups = {"contract", "daily"}) public void stackSuicideTest002() { String filePath = "src/test/resources/soliditycode/stackSuicide001.sol"; - String contractName = "testStakeSuicide"; + String contractName = "testStakeSuicide"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 10000000L, 100, null, testKey001, - testAddress001, blockingStubFull); - Long targetBalance = 10_000_000L; - final byte[] targetAddress = PublicMethod.deployContract(contractName, abi, code, "", - maxFeeLimit, targetBalance, 100, null, testKey001, testAddress001, blockingStubFull); - String methedStr = "Stake(address,uint256)"; - String argStr = "\"" + testWitnessAddress + "\",10000000"; - String txid = PublicMethod.triggerContract(contractAddress,methedStr, - argStr,false,0,maxFeeLimit, - testFoundationAddress, testFoundationKey,blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 10000000L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); + Long targetBalance = 10_000_000L; + final byte[] targetAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + targetBalance, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); + String methedStr = "Stake(address,uint256)"; + String argStr = "\"" + testWitnessAddress + "\",10000000"; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional ex = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()),1); + Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()), 1); - Account ownerAccount = PublicMethod.queryAccount(contractAddress,blockingStubFull); - final Frozen ownerFrozen = ownerAccount.getFrozen(0); + Account ownerAccount = PublicMethod.queryAccount(contractAddress, blockingStubFull); + final Frozen ownerFrozen = ownerAccount.getFrozen(0); methedStr = "SelfdestructTest(address)"; argStr = "\"" + Base58.encode58Check(targetAddress) + "\""; - txid = PublicMethod.triggerContract(contractAddress,methedStr,argStr,false, - 0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - ex = PublicMethod.getTransactionInfoById(txid,blockingStubFull); + ex = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Account targetAccount = PublicMethod.queryAccount(targetAddress,blockingStubFull); + Account targetAccount = PublicMethod.queryAccount(targetAddress, blockingStubFull); Frozen targetFrozen = targetAccount.getFrozen(0); - Assert.assertEquals(ownerFrozen.getExpireTime(),targetFrozen.getExpireTime()); - Assert.assertEquals(ownerFrozen.getFrozenBalance(),targetFrozen.getFrozenBalance()); + Assert.assertEquals(ownerFrozen.getExpireTime(), targetFrozen.getExpireTime()); + Assert.assertEquals(ownerFrozen.getFrozenBalance(), targetFrozen.getFrozenBalance()); methedStr = "transfer(address,uint256)"; argStr = "\"" + Base58.encode58Check(testAddress001) + "\"," + targetBalance; - txid = PublicMethod.triggerContract(targetAddress,methedStr,argStr,false,0, - maxFeeLimit,testAddress001,testKey001,blockingStubFull); + txid = + PublicMethod.triggerContract( + targetAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(0,PublicMethod.queryAccount(targetAddress,blockingStubFull).getBalance()); + Assert.assertEquals(0, PublicMethod.queryAccount(targetAddress, blockingStubFull).getBalance()); } - @Test(enabled = false, description = "targetAddress has TRX, and has frozen", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "targetAddress has TRX, and has frozen", + groups = {"contract", "daily"}) public void stackSuicideTest003() { Long targetBalance = 10_000_000L; - String filePath = "src/test/resources/soliditycode/stackSuicide001.sol"; - String contractName = "testStakeSuicide"; + String filePath = "src/test/resources/soliditycode/stackSuicide001.sol"; + String contractName = "testStakeSuicide"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, targetBalance, 100, - null, testKey001, testAddress001, blockingStubFull); - final byte[] targetAddress = PublicMethod.deployContract(contractName, abi, code, "", - maxFeeLimit, 12_345_678L, 100, null, testKey001, testAddress001, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + targetBalance, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); + final byte[] targetAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 12_345_678L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String methedStr = "Stake(address,uint256)"; - String argStr = "\"" + testWitnessAddress + "\"," + targetBalance; - String txid = PublicMethod.triggerContract(contractAddress,methedStr, - argStr,false,0,maxFeeLimit, testFoundationAddress, testFoundationKey,blockingStubFull); + String methedStr = "Stake(address,uint256)"; + String argStr = "\"" + testWitnessAddress + "\"," + targetBalance; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional ex = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()),1); + Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()), 1); argStr = "\"" + testWitnessAddress + "\"," + 12_000_000L; - String txid2 = PublicMethod.triggerContract(targetAddress,methedStr,argStr,false, - 0,maxFeeLimit,testFoundationAddress,testFoundationKey,blockingStubFull); + String txid2 = + PublicMethod.triggerContract( + targetAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - ex = PublicMethod.getTransactionInfoById(txid2,blockingStubFull); + ex = PublicMethod.getTransactionInfoById(txid2, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()),1); + Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()), 1); - Account ownerAccount = PublicMethod.queryAccount(contractAddress,blockingStubFull); - final Frozen ownerFrozen = ownerAccount.getFrozen(0); + Account ownerAccount = PublicMethod.queryAccount(contractAddress, blockingStubFull); + final Frozen ownerFrozen = ownerAccount.getFrozen(0); - Account targetAccount = PublicMethod.queryAccount(targetAddress,blockingStubFull); - final Frozen targetFrozen = targetAccount.getFrozen(0); + Account targetAccount = PublicMethod.queryAccount(targetAddress, blockingStubFull); + final Frozen targetFrozen = targetAccount.getFrozen(0); methedStr = "SelfdestructTest(address)"; argStr = "\"" + Base58.encode58Check(targetAddress) + "\""; - txid = PublicMethod.triggerContract(contractAddress,methedStr,argStr,false, - 0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - ex = PublicMethod.getTransactionInfoById(txid,blockingStubFull); + ex = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - targetAccount = PublicMethod.queryAccount(targetAddress,blockingStubFull); + targetAccount = PublicMethod.queryAccount(targetAddress, blockingStubFull); Frozen targetFrozenAfter = targetAccount.getFrozen(0); BigInteger expected = BigInteger.valueOf(ownerFrozen.getExpireTime()) - .multiply(BigInteger.valueOf(ownerFrozen.getFrozenBalance())) - .add(BigInteger.valueOf(targetFrozen.getExpireTime()) - .multiply(BigInteger.valueOf(targetFrozen.getFrozenBalance()))) - .divide(BigInteger.valueOf(ownerFrozen.getFrozenBalance()) - .add(BigInteger.valueOf(targetFrozen.getFrozenBalance()))); + .multiply(BigInteger.valueOf(ownerFrozen.getFrozenBalance())) + .add( + BigInteger.valueOf(targetFrozen.getExpireTime()) + .multiply(BigInteger.valueOf(targetFrozen.getFrozenBalance()))) + .divide( + BigInteger.valueOf(ownerFrozen.getFrozenBalance()) + .add(BigInteger.valueOf(targetFrozen.getFrozenBalance()))); Assert.assertEquals(expected.longValue(), targetFrozenAfter.getExpireTime()); - Assert.assertEquals(targetFrozenAfter.getFrozenBalance(), + Assert.assertEquals( + targetFrozenAfter.getFrozenBalance(), ownerFrozen.getFrozenBalance() + targetFrozen.getFrozenBalance()); methedStr = "transfer(address,uint256)"; argStr = "\"" + Base58.encode58Check(testAddress001) + "\"," + 345678; - txid = PublicMethod.triggerContract(targetAddress,methedStr,argStr,false,0, - maxFeeLimit,testAddress001,testKey001,blockingStubFull); + txid = + PublicMethod.triggerContract( + targetAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(0,PublicMethod.queryAccount(targetAddress,blockingStubFull).getBalance()); + Assert.assertEquals(0, PublicMethod.queryAccount(targetAddress, blockingStubFull).getBalance()); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StakeSuicideTest002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StakeSuicideTest002.java index 0d684de0..9525141e 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StakeSuicideTest002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StakeSuicideTest002.java @@ -14,144 +14,217 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class StakeSuicideTest002 extends TronBaseTest { - private String testFoundationKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private String testFoundationKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); private String testWitnessAddress = PublicMethod.getAddressString(witnessKey); private byte[] contractAddress; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = false) - public void beforeClass() { String filePath = "src/test/resources/soliditycode/stackSuicide001.sol"; - String contractName = "B"; + public void beforeClass() { + String filePath = "src/test/resources/soliditycode/stackSuicide001.sol"; + String contractName = "B"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 10000000L, - 100, null, testFoundationKey, - testFoundationAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 10000000L, + 100, + null, + testFoundationKey, + testFoundationAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = false, description = "create2 -> stake -> suicide -> create2 the same Address", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "create2 -> stake -> suicide -> create2 the same Address", + groups = {"contract", "daily"}) public void stackSuicideAndCreate2Test001() { String filePath = "src/test/resources/soliditycode/stackSuicide001.sol"; - String contractName = "testStakeSuicide"; + String contractName = "testStakeSuicide"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String methedStr = "deploy(bytes,uint256)"; - String argStr = "\"" + code + "\"," + 1; - String txid = PublicMethod.triggerContract(contractAddress,methedStr,argStr,false, - 0,maxFeeLimit,testFoundationAddress,testFoundationKey,blockingStubFull); + String code = retMap.get("byteCode").toString(); + String methedStr = "deploy(bytes,uint256)"; + String argStr = "\"" + code + "\"," + 1; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional ex = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - String hex = "41" + ByteArray.toHexString(ex.get().getContractResult(0).toByteArray()) - .substring(24); + String hex = + "41" + ByteArray.toHexString(ex.get().getContractResult(0).toByteArray()).substring(24); logger.info("Deploy Address : " + Base58.encode58Check(ByteArray.fromHexString(hex))); - byte[] ownerAddress = ByteArray.fromHexString(hex); + byte[] ownerAddress = ByteArray.fromHexString(hex); methedStr = "Stake(address,uint256)"; argStr = "\"" + testWitnessAddress + "\"," + 10_000_000; - txid = PublicMethod.triggerContract(ownerAddress,methedStr, - argStr,false,10_000_000,maxFeeLimit, - testFoundationAddress, testFoundationKey,blockingStubFull); + txid = + PublicMethod.triggerContract( + ownerAddress, + methedStr, + argStr, + false, + 10_000_000, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - ex = PublicMethod.getTransactionInfoById(txid,blockingStubFull); + ex = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Account ownerAccount = PublicMethod.queryAccount(ownerAddress,blockingStubFull); - final Frozen ownerFrozen = ownerAccount.getFrozen(0); + Account ownerAccount = PublicMethod.queryAccount(ownerAddress, blockingStubFull); + final Frozen ownerFrozen = ownerAccount.getFrozen(0); methedStr = "SelfdestructTest(address)"; argStr = "\"" + Base58.encode58Check(contractAddress) + "\""; - txid = PublicMethod.triggerContract(ownerAddress,methedStr,argStr,false, - 0,maxFeeLimit,testFoundationAddress,testFoundationKey,blockingStubFull); + txid = + PublicMethod.triggerContract( + ownerAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); methedStr = "deploy(bytes,uint256)"; argStr = "\"" + code + "\"," + 1; - txid = PublicMethod.triggerContract(contractAddress,methedStr,argStr,false, - 0,maxFeeLimit,testFoundationAddress,testFoundationKey,blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - ownerAccount = PublicMethod.queryAccount(ownerAddress,blockingStubFull); - Assert.assertEquals(ownerAccount.getBalance(),0); - Assert.assertEquals(ownerAccount.getFrozenCount(),0); - Assert.assertEquals(ownerAccount.getVotesCount(),0); + ownerAccount = PublicMethod.queryAccount(ownerAddress, blockingStubFull); + Assert.assertEquals(ownerAccount.getBalance(), 0); + Assert.assertEquals(ownerAccount.getFrozenCount(), 0); + Assert.assertEquals(ownerAccount.getVotesCount(), 0); - Account targetAccount = PublicMethod.queryAccount(contractAddress,blockingStubFull); + Account targetAccount = PublicMethod.queryAccount(contractAddress, blockingStubFull); Frozen targetFrozen = targetAccount.getFrozen(0); - Assert.assertEquals(ownerFrozen.getExpireTime(),targetFrozen.getExpireTime()); - Assert.assertEquals(ownerFrozen.getFrozenBalance(),targetFrozen.getFrozenBalance()); - + Assert.assertEquals(ownerFrozen.getExpireTime(), targetFrozen.getExpireTime()); + Assert.assertEquals(ownerFrozen.getFrozenBalance(), targetFrozen.getFrozenBalance()); } - @Test(enabled = false, description = "create2 -> stake -> suicide -> sendcoin to create2 Address", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "create2 -> stake -> suicide -> sendcoin to create2 Address", + groups = {"contract", "daily"}) public void stackSuicideAndCreate2Test002() { String filePath = "src/test/resources/soliditycode/stackSuicide001.sol"; - String contractName = "testStakeSuicide"; + String contractName = "testStakeSuicide"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String methedStr = "deploy(bytes,uint256)"; - String argStr = "\"" + code + "\"," + 2; - String txid = PublicMethod.triggerContract(contractAddress,methedStr,argStr,false, - 0,maxFeeLimit,testFoundationAddress,testFoundationKey,blockingStubFull); + String code = retMap.get("byteCode").toString(); + String methedStr = "deploy(bytes,uint256)"; + String argStr = "\"" + code + "\"," + 2; + String txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional ex = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - String hex = "41" + ByteArray.toHexString(ex.get().getContractResult(0).toByteArray()) - .substring(24); + String hex = + "41" + ByteArray.toHexString(ex.get().getContractResult(0).toByteArray()).substring(24); logger.info("Deploy Address : " + Base58.encode58Check(ByteArray.fromHexString(hex))); - byte[] ownerAddress = ByteArray.fromHexString(hex); + byte[] ownerAddress = ByteArray.fromHexString(hex); methedStr = "Stake(address,uint256)"; argStr = "\"" + testWitnessAddress + "\"," + 10_000_000; - txid = PublicMethod.triggerContract(ownerAddress,methedStr, - argStr,false,10_000_000,maxFeeLimit, - testFoundationAddress, testFoundationKey,blockingStubFull); + txid = + PublicMethod.triggerContract( + ownerAddress, + methedStr, + argStr, + false, + 10_000_000, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - ex = PublicMethod.getTransactionInfoById(txid,blockingStubFull); + ex = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Account ownerAccount = PublicMethod.queryAccount(ownerAddress,blockingStubFull); - final Frozen ownerFrozen = ownerAccount.getFrozen(0); - ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] testAddress001 = ecKey1.getAddress(); + Account ownerAccount = PublicMethod.queryAccount(ownerAddress, blockingStubFull); + final Frozen ownerFrozen = ownerAccount.getFrozen(0); + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] testAddress001 = ecKey1.getAddress(); methedStr = "SelfdestructTest(address)"; argStr = "\"" + Base58.encode58Check(testAddress001) + "\""; - txid = PublicMethod.triggerContract(ownerAddress,methedStr,argStr,false, - 0,maxFeeLimit,testFoundationAddress,testFoundationKey,blockingStubFull); + txid = + PublicMethod.triggerContract( + ownerAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); long sendcoin = 1; - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress,sendcoin,testFoundationAddress, - testFoundationKey,blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, sendcoin, testFoundationAddress, testFoundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - ownerAccount = PublicMethod.queryAccount(ownerAddress,blockingStubFull); - Assert.assertEquals(ownerAccount.getBalance(),sendcoin); - Assert.assertEquals(ownerAccount.getFrozenCount(),0); - Assert.assertEquals(ownerAccount.getVotesCount(),0); + ownerAccount = PublicMethod.queryAccount(ownerAddress, blockingStubFull); + Assert.assertEquals(ownerAccount.getBalance(), sendcoin); + Assert.assertEquals(ownerAccount.getFrozenCount(), 0); + Assert.assertEquals(ownerAccount.getVotesCount(), 0); - Account targetAccount = PublicMethod.queryAccount(testAddress001,blockingStubFull); + Account targetAccount = PublicMethod.queryAccount(testAddress001, blockingStubFull); Frozen targetFrozen = targetAccount.getFrozen(0); - Assert.assertEquals(ownerFrozen.getExpireTime(),targetFrozen.getExpireTime()); - Assert.assertEquals(ownerFrozen.getFrozenBalance(),targetFrozen.getFrozenBalance()); + Assert.assertEquals(ownerFrozen.getExpireTime(), targetFrozen.getExpireTime()); + Assert.assertEquals(ownerFrozen.getFrozenBalance(), targetFrozen.getFrozenBalance()); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StakeSuicideTest003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StakeSuicideTest003.java index d02245ee..8a0afac2 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StakeSuicideTest003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StakeSuicideTest003.java @@ -13,149 +13,233 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - public class StakeSuicideTest003 extends TronBaseTest { +import stest.tron.wallet.common.client.utils.Utils; - private String testFoundationKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); +public class StakeSuicideTest003 extends TronBaseTest { + + private String testFoundationKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); - private String testWitnessAddress = PublicMethod.getAddressString(witnessKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); + private String testWitnessAddress = PublicMethod.getAddressString(witnessKey); + ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey1.getAddress(); String testKey001 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private byte[] contractAddress; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = false) - public void beforeClass() { PublicMethod.sendcoin(testAddress001,10000000,testFoundationAddress, - testFoundationKey,blockingStubFull); + public void beforeClass() { + PublicMethod.sendcoin( + testAddress001, 10000000, testFoundationAddress, testFoundationKey, blockingStubFull); } - @Test(enabled = false, description = "suicide target Address is owner Address", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "suicide target Address is owner Address", + groups = {"contract", "daily"}) public void stakeSuicideTest001() { String filePath = "src/test/resources/soliditycode/stackSuicide001.sol"; - String contractName = "testStakeSuicide"; + String contractName = "testStakeSuicide"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 10000000L, - 100, null, testFoundationKey, - testFoundationAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 10000000L, + 100, + null, + testFoundationKey, + testFoundationAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = PublicMethod.triggerContract(contractAddress,"Stake(address,uint256)", - "\"" + testWitnessAddress + "\",10000000",false,0,maxFeeLimit, - testFoundationAddress, testFoundationKey,blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + "Stake(address,uint256)", + "\"" + testWitnessAddress + "\",10000000", + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional ex = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()),1); + Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()), 1); - Account ownerAccount = PublicMethod.queryAccount(contractAddress,blockingStubFull); + Account ownerAccount = PublicMethod.queryAccount(contractAddress, blockingStubFull); Frozen ownerFrozen = ownerAccount.getFrozen(0); - String methedStr = "SelfdestructTest(address)"; - String argStr = "\"" + Base58.encode58Check(contractAddress) + "\""; - txid = PublicMethod.triggerContract(contractAddress,methedStr,argStr,false, - 0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); + String methedStr = "SelfdestructTest(address)"; + String argStr = "\"" + Base58.encode58Check(contractAddress) + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - ex = PublicMethod.getTransactionInfoById(txid,blockingStubFull); + ex = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Account account = PublicMethod.queryAccount(contractAddress,blockingStubFull); - Assert.assertEquals(account.getFrozenCount(),0); - + Account account = PublicMethod.queryAccount(contractAddress, blockingStubFull); + Assert.assertEquals(account.getFrozenCount(), 0); } - @Test(enabled = false, description = "suicide target Address is BlackHoleAddress Address", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "suicide target Address is BlackHoleAddress Address", + groups = {"contract", "daily"}) public void stakeSuicideTest002() { String filePath = "src/test/resources/soliditycode/stackSuicide001.sol"; - String contractName = "testStakeSuicide"; + String contractName = "testStakeSuicide"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 10000000L, - 100, null, testFoundationKey, - testFoundationAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 10000000L, + 100, + null, + testFoundationKey, + testFoundationAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = PublicMethod.triggerContract(contractAddress,"Stake(address,uint256)", - "\"" + testWitnessAddress + "\",10000000",false,0,maxFeeLimit, - testFoundationAddress, testFoundationKey,blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + "Stake(address,uint256)", + "\"" + testWitnessAddress + "\",10000000", + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional ex = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()),1); + Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()), 1); - Account ownerAccount = PublicMethod.queryAccount(contractAddress,blockingStubFull); + Account ownerAccount = PublicMethod.queryAccount(contractAddress, blockingStubFull); Frozen ownerFrozen = ownerAccount.getFrozen(0); - String blackHoleAddress = "TLsV52sRDL79HXGGm9yzwKibb6BeruhUzy"; - final Account accountBefore = PublicMethod - .queryAccount(PublicMethod.decode58Check(blackHoleAddress), + String blackHoleAddress = "TLsV52sRDL79HXGGm9yzwKibb6BeruhUzy"; + final Account accountBefore = + PublicMethod.queryAccount(PublicMethod.decode58Check(blackHoleAddress), blockingStubFull); + String methedStr = "SelfdestructTest(address)"; + String argStr = "\"" + blackHoleAddress + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, blockingStubFull); - String methedStr = "SelfdestructTest(address)"; - String argStr = "\"" + blackHoleAddress + "\""; - txid = PublicMethod.triggerContract(contractAddress,methedStr,argStr,false, - 0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - ex = PublicMethod.getTransactionInfoById(txid,blockingStubFull); + ex = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Account account = PublicMethod.queryAccount(contractAddress,blockingStubFull); - Assert.assertEquals(account.getFrozenCount(),0); + Account account = PublicMethod.queryAccount(contractAddress, blockingStubFull); + Assert.assertEquals(account.getFrozenCount(), 0); - Account accountAfter = PublicMethod - .queryAccount(PublicMethod.decode58Check(blackHoleAddress), - blockingStubFull); - Assert.assertEquals(accountBefore.getBalance() + ex.get().getReceipt().getEnergyFee() - + 10000000, accountAfter.getBalance()); + Account accountAfter = + PublicMethod.queryAccount(PublicMethod.decode58Check(blackHoleAddress), blockingStubFull); + Assert.assertEquals( + accountBefore.getBalance() + ex.get().getReceipt().getEnergyFee() + 10000000, + accountAfter.getBalance()); } - @Test(enabled = false, description = "suicide target Address is BlackHoleAddress Address", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "suicide target Address is BlackHoleAddress Address", + groups = {"contract", "daily"}) public void stakeSuicideTest003() { String filePath = "src/test/resources/soliditycode/stackSuicide001.sol"; - String contractName = "testStakeSuicide"; + String contractName = "testStakeSuicide"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 10000000L, - 100, null, testFoundationKey, - testFoundationAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 10000000L, + 100, + null, + testFoundationKey, + testFoundationAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String txid = PublicMethod.triggerContract(contractAddress,"Stake(address,uint256)", - "\"" + testWitnessAddress + "\",10000000",false,0,maxFeeLimit, - testFoundationAddress, testFoundationKey,blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + "Stake(address,uint256)", + "\"" + testWitnessAddress + "\",10000000", + false, + 0, + maxFeeLimit, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional ex = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()),1); + Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()), 1); - Account ownerAccount = PublicMethod.queryAccount(contractAddress,blockingStubFull); + Account ownerAccount = PublicMethod.queryAccount(contractAddress, blockingStubFull); Frozen ownerFrozen = ownerAccount.getFrozen(0); - final Account accountBefore = PublicMethod - .queryAccount(PublicMethod.decode58Check("T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb"), + final Account accountBefore = + PublicMethod.queryAccount( + PublicMethod.decode58Check("T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb"), blockingStubFull); + String methedStr = "SelfdestructTest(address)"; + String argStr = "\"" + "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb" + "\""; + txid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, blockingStubFull); - String methedStr = "SelfdestructTest(address)"; - String argStr = "\"" + "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb" + "\""; - txid = PublicMethod.triggerContract(contractAddress,methedStr,argStr,false, - 0,maxFeeLimit,testAddress001,testKey001,blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - ex = PublicMethod.getTransactionInfoById(txid,blockingStubFull); + ex = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Account account = PublicMethod.queryAccount(contractAddress,blockingStubFull); - Assert.assertEquals(account.getFrozenCount(),0); + Account account = PublicMethod.queryAccount(contractAddress, blockingStubFull); + Assert.assertEquals(account.getFrozenCount(), 0); - Account accountAfter = PublicMethod - .queryAccount(PublicMethod.decode58Check("T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb"), - blockingStubFull); + Account accountAfter = + PublicMethod.queryAccount( + PublicMethod.decode58Check("T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb"), blockingStubFull); Assert.assertEquals(accountBefore.getBalance() + 10000000, accountAfter.getBalance()); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StakeSuicideTest004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StakeSuicideTest004.java index 3c1dda08..3d9f7b90 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StakeSuicideTest004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StakeSuicideTest004.java @@ -10,14 +10,14 @@ import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.Account.Frozen; import org.tron.protos.Protocol.TransactionInfo; -import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - public class StakeSuicideTest004 extends TronBaseTest { +import stest.tron.wallet.common.client.utils.Utils; + +public class StakeSuicideTest004 extends TronBaseTest { private byte[] testWitnessAddress = PublicMethod.getFinalAddress(witnessKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey1.getAddress(); @@ -31,312 +31,476 @@ public class StakeSuicideTest004 extends TronBaseTest { String code = ""; String abi = ""; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = false) public void beforeClass() { System.out.println(testKey001); - PublicMethod.printAddress(testKey001); PublicMethod - .sendcoin(testAddress001, 1000_000_00000L, foundationAddress, foundationKey, - blockingStubFull); + PublicMethod.printAddress(testKey001); + PublicMethod.sendcoin( + testAddress001, 1000_000_00000L, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 1000_000000L, 100, - null, testKey001, testAddress001, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000_000000L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = false, description = "targetAddress has frozen 1,suicide contract stake 1", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "targetAddress has frozen 1,suicide contract stake 1", + groups = {"contract", "daily"}) void tvmStakeSuicideTest001() { ECKey ecKeyTargetAddress = new ECKey(Utils.getRandom()); - byte[] targetAddress = ecKeyTargetAddress.getAddress(); - String testKeyTargetAddress = ByteArray.toHexString(ecKeyTargetAddress.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod - .sendcoin(targetAddress, 10_000000L, foundationAddress, foundationKey, - blockingStubFull)); + byte[] targetAddress = ecKeyTargetAddress.getAddress(); + String testKeyTargetAddress = ByteArray.toHexString(ecKeyTargetAddress.getPrivKeyBytes()); + Assert.assertTrue( + PublicMethod.sendcoin( + targetAddress, 10_000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalance(targetAddress,1_000000L,3,testKeyTargetAddress,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance( + targetAddress, 1_000000L, 3, testKeyTargetAddress, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Account targetAccount = PublicMethod.queryAccount(targetAddress,blockingStubFull); - final Frozen targetFrozenBefore = targetAccount.getFrozen(0); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000_000000L, 100, null, testKey001, testAddress001, blockingStubFull); + Account targetAccount = PublicMethod.queryAccount(targetAddress, blockingStubFull); + final Frozen targetFrozenBefore = targetAccount.getFrozen(0); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000_000000L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String methodStr = "Stake(address,uint256)"; - String argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + 1000000; - String txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + String methodStr = "Stake(address,uint256)"; + String argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + 1000000; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional ex = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()),1); - - Account ownerAccount = PublicMethod.queryAccount(contractAddress,blockingStubFull); - final Frozen ownerFrozen = ownerAccount.getFrozen(0); - Long ownerBalance = ownerAccount.getBalance(); - String methodStrSuicide = "SelfdestructTest(address)"; - String argsStrSuicide = "\"" + Base58.encode58Check(targetAddress) + "\""; - String txidSuicide = PublicMethod - .triggerContract(contractAddress, methodStrSuicide, argsStrSuicide, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()), 1); + + Account ownerAccount = PublicMethod.queryAccount(contractAddress, blockingStubFull); + final Frozen ownerFrozen = ownerAccount.getFrozen(0); + Long ownerBalance = ownerAccount.getBalance(); + String methodStrSuicide = "SelfdestructTest(address)"; + String argsStrSuicide = "\"" + Base58.encode58Check(targetAddress) + "\""; + String txidSuicide = + PublicMethod.triggerContract( + contractAddress, + methodStrSuicide, + argsStrSuicide, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); ex = PublicMethod.getTransactionInfoById(txidSuicide, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Account targetAccountAfter = PublicMethod.queryAccount(targetAddress,blockingStubFull); + Account targetAccountAfter = PublicMethod.queryAccount(targetAddress, blockingStubFull); Frozen targetFrozenAfter = targetAccountAfter.getFrozen(0); BigInteger expected = BigInteger.valueOf(ownerFrozen.getExpireTime()) .multiply(BigInteger.valueOf(ownerFrozen.getFrozenBalance())) - .add(BigInteger.valueOf(targetFrozenBefore.getExpireTime()) - .multiply(BigInteger.valueOf(targetFrozenBefore.getFrozenBalance()))) - .divide(BigInteger.valueOf(ownerFrozen.getFrozenBalance()) - .add(BigInteger.valueOf(targetFrozenBefore.getFrozenBalance()))); + .add( + BigInteger.valueOf(targetFrozenBefore.getExpireTime()) + .multiply(BigInteger.valueOf(targetFrozenBefore.getFrozenBalance()))) + .divide( + BigInteger.valueOf(ownerFrozen.getFrozenBalance()) + .add(BigInteger.valueOf(targetFrozenBefore.getFrozenBalance()))); Assert.assertEquals(expected.longValue(), targetFrozenAfter.getExpireTime()); - Assert.assertEquals(targetFrozenAfter.getFrozenBalance(), + Assert.assertEquals( + targetFrozenAfter.getFrozenBalance(), ownerFrozen.getFrozenBalance() + targetFrozenBefore.getFrozenBalance()); - } - @Test(enabled = false, description = "targetAddress has frozen 1,suicide contract stake all", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "targetAddress has frozen 1,suicide contract stake all", + groups = {"contract", "daily"}) void tvmStakeSuicideTest002() { ECKey ecKeyTargetAddress = new ECKey(Utils.getRandom()); - byte[] targetAddress = ecKeyTargetAddress.getAddress(); - String testKeyTargetAddress = ByteArray.toHexString(ecKeyTargetAddress.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod - .sendcoin(targetAddress, 10_000000L, foundationAddress, foundationKey, - blockingStubFull)); + byte[] targetAddress = ecKeyTargetAddress.getAddress(); + String testKeyTargetAddress = ByteArray.toHexString(ecKeyTargetAddress.getPrivKeyBytes()); + Assert.assertTrue( + PublicMethod.sendcoin( + targetAddress, 10_000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalance(targetAddress,1_000000L,3,testKeyTargetAddress,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance( + targetAddress, 1_000000L, 3, testKeyTargetAddress, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Account targetAccount = PublicMethod.queryAccount(targetAddress,blockingStubFull); - final Frozen targetFrozenBefore = targetAccount.getFrozen(0); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 100_000000L, 100, null, testKey001, testAddress001, blockingStubFull); + Account targetAccount = PublicMethod.queryAccount(targetAddress, blockingStubFull); + final Frozen targetFrozenBefore = targetAccount.getFrozen(0); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 100_000000L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String methodStr = "Stake(address,uint256)"; - String argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + 100_000000L; - String txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + String methodStr = "Stake(address,uint256)"; + String argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + 100_000000L; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional ex = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()),1); - - Account ownerAccount = PublicMethod.queryAccount(contractAddress,blockingStubFull); - final Frozen ownerFrozen = ownerAccount.getFrozen(0); - Long ownerBalance = ownerAccount.getBalance(); - String methodStrSuicide = "SelfdestructTest(address)"; - String argsStrSuicide = "\"" + Base58.encode58Check(targetAddress) + "\""; - String txidSuicide = PublicMethod - .triggerContract(contractAddress, methodStrSuicide, argsStrSuicide, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()), 1); + + Account ownerAccount = PublicMethod.queryAccount(contractAddress, blockingStubFull); + final Frozen ownerFrozen = ownerAccount.getFrozen(0); + Long ownerBalance = ownerAccount.getBalance(); + String methodStrSuicide = "SelfdestructTest(address)"; + String argsStrSuicide = "\"" + Base58.encode58Check(targetAddress) + "\""; + String txidSuicide = + PublicMethod.triggerContract( + contractAddress, + methodStrSuicide, + argsStrSuicide, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); ex = PublicMethod.getTransactionInfoById(txidSuicide, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Account targetAccountAfter = PublicMethod.queryAccount(targetAddress,blockingStubFull); + Account targetAccountAfter = PublicMethod.queryAccount(targetAddress, blockingStubFull); Frozen targetFrozenAfter = targetAccountAfter.getFrozen(0); BigInteger expected = BigInteger.valueOf(ownerFrozen.getExpireTime()) .multiply(BigInteger.valueOf(ownerFrozen.getFrozenBalance())) - .add(BigInteger.valueOf(targetFrozenBefore.getExpireTime()) - .multiply(BigInteger.valueOf(targetFrozenBefore.getFrozenBalance()))) - .divide(BigInteger.valueOf(ownerFrozen.getFrozenBalance()) - .add(BigInteger.valueOf(targetFrozenBefore.getFrozenBalance()))); + .add( + BigInteger.valueOf(targetFrozenBefore.getExpireTime()) + .multiply(BigInteger.valueOf(targetFrozenBefore.getFrozenBalance()))) + .divide( + BigInteger.valueOf(ownerFrozen.getFrozenBalance()) + .add(BigInteger.valueOf(targetFrozenBefore.getFrozenBalance()))); Assert.assertEquals(expected.longValue(), targetFrozenAfter.getExpireTime()); - Assert.assertEquals(targetFrozenAfter.getFrozenBalance(), + Assert.assertEquals( + targetFrozenAfter.getFrozenBalance(), ownerFrozen.getFrozenBalance() + targetFrozenBefore.getFrozenBalance()); - } - @Test(enabled = false, description = "targetAddress has frozen all,suicide contract stake all", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "targetAddress has frozen all,suicide contract stake all", + groups = {"contract", "daily"}) void tvmStakeSuicideTest003() { ECKey ecKeyTargetAddress = new ECKey(Utils.getRandom()); - byte[] targetAddress = ecKeyTargetAddress.getAddress(); - String testKeyTargetAddress = ByteArray.toHexString(ecKeyTargetAddress.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod - .sendcoin(targetAddress, 20_000000L, foundationAddress, foundationKey, - blockingStubFull)); + byte[] targetAddress = ecKeyTargetAddress.getAddress(); + String testKeyTargetAddress = ByteArray.toHexString(ecKeyTargetAddress.getPrivKeyBytes()); + Assert.assertTrue( + PublicMethod.sendcoin( + targetAddress, 20_000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(targetAddress,5_000000L, - 3,1, ByteString.copyFrom(testAddress001),testKeyTargetAddress,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + targetAddress, + 5_000000L, + 3, + 1, + ByteString.copyFrom(testAddress001), + testKeyTargetAddress, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalance(targetAddress,10_000000L,3,testKeyTargetAddress,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance( + targetAddress, 10_000000L, 3, testKeyTargetAddress, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Account targetAccount = PublicMethod.queryAccount(targetAddress,blockingStubFull); - final Frozen targetFrozenBefore = targetAccount.getFrozen(0); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 100_000000L, 100, null, testKey001, testAddress001, blockingStubFull); + Account targetAccount = PublicMethod.queryAccount(targetAddress, blockingStubFull); + final Frozen targetFrozenBefore = targetAccount.getFrozen(0); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 100_000000L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String methodStr = "Stake(address,uint256)"; - String argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + 100_000000L; - String txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + String methodStr = "Stake(address,uint256)"; + String argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + 100_000000L; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional ex = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()),1); - - Account ownerAccount = PublicMethod.queryAccount(contractAddress,blockingStubFull); - final Frozen ownerFrozen = ownerAccount.getFrozen(0); - Long ownerBalance = ownerAccount.getBalance(); - String methodStrSuicide = "SelfdestructTest(address)"; - String argsStrSuicide = "\"" + Base58.encode58Check(targetAddress) + "\""; - String txidSuicide = PublicMethod - .triggerContract(contractAddress, methodStrSuicide, argsStrSuicide, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()), 1); + + Account ownerAccount = PublicMethod.queryAccount(contractAddress, blockingStubFull); + final Frozen ownerFrozen = ownerAccount.getFrozen(0); + Long ownerBalance = ownerAccount.getBalance(); + String methodStrSuicide = "SelfdestructTest(address)"; + String argsStrSuicide = "\"" + Base58.encode58Check(targetAddress) + "\""; + String txidSuicide = + PublicMethod.triggerContract( + contractAddress, + methodStrSuicide, + argsStrSuicide, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); ex = PublicMethod.getTransactionInfoById(txidSuicide, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Account targetAccountAfter = PublicMethod.queryAccount(targetAddress,blockingStubFull); + Account targetAccountAfter = PublicMethod.queryAccount(targetAddress, blockingStubFull); Frozen targetFrozenAfter = targetAccountAfter.getFrozen(0); BigInteger expected = BigInteger.valueOf(ownerFrozen.getExpireTime()) .multiply(BigInteger.valueOf(ownerFrozen.getFrozenBalance())) - .add(BigInteger.valueOf(targetFrozenBefore.getExpireTime()) - .multiply(BigInteger.valueOf(targetFrozenBefore.getFrozenBalance()))) - .divide(BigInteger.valueOf(ownerFrozen.getFrozenBalance()) - .add(BigInteger.valueOf(targetFrozenBefore.getFrozenBalance()))); + .add( + BigInteger.valueOf(targetFrozenBefore.getExpireTime()) + .multiply(BigInteger.valueOf(targetFrozenBefore.getFrozenBalance()))) + .divide( + BigInteger.valueOf(ownerFrozen.getFrozenBalance()) + .add(BigInteger.valueOf(targetFrozenBefore.getFrozenBalance()))); Assert.assertEquals(expected.longValue(), targetFrozenAfter.getExpireTime()); - Assert.assertEquals(targetFrozenAfter.getFrozenBalance(), + Assert.assertEquals( + targetFrozenAfter.getFrozenBalance(), ownerFrozen.getFrozenBalance() + targetFrozenBefore.getFrozenBalance()); - } - @Test(enabled = false, description = "targetAddress is new account ,suicide contract stake all", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "targetAddress is new account ,suicide contract stake all", + groups = {"contract", "daily"}) void tvmStakeSuicideTest004() { ECKey ecKeyTargetAddress = new ECKey(Utils.getRandom()); - byte[] targetAddress = ecKeyTargetAddress.getAddress(); - String testKeyTargetAddress = ByteArray.toHexString(ecKeyTargetAddress.getPrivKeyBytes()); + byte[] targetAddress = ecKeyTargetAddress.getAddress(); + String testKeyTargetAddress = ByteArray.toHexString(ecKeyTargetAddress.getPrivKeyBytes()); System.out.println(Base58.encode58Check(targetAddress)); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 100_000000L, 100, null, testKey001, testAddress001, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 100_000000L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String methodStr = "Stake(address,uint256)"; - String argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + 100_000000L; - String txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + String methodStr = "Stake(address,uint256)"; + String argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + 100_000000L; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional ex = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()),1); - - Account ownerAccount = PublicMethod.queryAccount(contractAddress,blockingStubFull); - final Frozen ownerFrozen = ownerAccount.getFrozen(0); - Long ownerBalance = ownerAccount.getBalance(); - String methodStrSuicide = "SelfdestructTest(address)"; - String argsStrSuicide = "\"" + Base58.encode58Check(targetAddress) + "\""; - String txidSuicide = PublicMethod - .triggerContract(contractAddress, methodStrSuicide, argsStrSuicide, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()), 1); + + Account ownerAccount = PublicMethod.queryAccount(contractAddress, blockingStubFull); + final Frozen ownerFrozen = ownerAccount.getFrozen(0); + Long ownerBalance = ownerAccount.getBalance(); + String methodStrSuicide = "SelfdestructTest(address)"; + String argsStrSuicide = "\"" + Base58.encode58Check(targetAddress) + "\""; + String txidSuicide = + PublicMethod.triggerContract( + contractAddress, + methodStrSuicide, + argsStrSuicide, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); ex = PublicMethod.getTransactionInfoById(txidSuicide, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Account targetAccountAfter = PublicMethod.queryAccount(targetAddress,blockingStubFull); + Account targetAccountAfter = PublicMethod.queryAccount(targetAddress, blockingStubFull); Frozen targetFrozenAfter = targetAccountAfter.getFrozen(0); Assert.assertEquals(ownerFrozen.getExpireTime(), targetFrozenAfter.getExpireTime()); - Assert.assertEquals(targetFrozenAfter.getFrozenBalance(), - ownerFrozen.getFrozenBalance()); - + Assert.assertEquals(targetFrozenAfter.getFrozenBalance(), ownerFrozen.getFrozenBalance()); } - @Test(enabled = false, description = "targetAddress frozen to other address ,suicide contract " - + "stake all", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "targetAddress frozen to other address ,suicide contract " + "stake all", + groups = {"contract", "daily"}) void tvmStakeSuicideTest005() { ECKey ecKeyTargetAddress = new ECKey(Utils.getRandom()); - byte[] targetAddress = ecKeyTargetAddress.getAddress(); - ECKey ecKey = new ECKey(Utils.getRandom()); - byte[] address = ecKey.getAddress(); - String testKeyTargetAddress = ByteArray.toHexString(ecKeyTargetAddress.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod - .sendcoin(targetAddress, 10_000000L, foundationAddress, foundationKey, - blockingStubFull)); + byte[] targetAddress = ecKeyTargetAddress.getAddress(); + ECKey ecKey = new ECKey(Utils.getRandom()); + byte[] address = ecKey.getAddress(); + String testKeyTargetAddress = ByteArray.toHexString(ecKeyTargetAddress.getPrivKeyBytes()); + Assert.assertTrue( + PublicMethod.sendcoin( + targetAddress, 10_000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(targetAddress,5_000000L, - 3,1, ByteString.copyFrom(testAddress001),testKeyTargetAddress,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + targetAddress, + 5_000000L, + 3, + 1, + ByteString.copyFrom(testAddress001), + testKeyTargetAddress, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); System.out.println("aaaa" + Base58.encode58Check(targetAddress)); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 100_000000L, 100, null, testKey001, testAddress001, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 100_000000L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String methodStr = "Stake(address,uint256)"; - String argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + 100_000000L; - String txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + String methodStr = "Stake(address,uint256)"; + String argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + 100_000000L; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional ex = PublicMethod.getTransactionInfoById(txid, blockingStubFull); System.out.println("aaaaa" + Base58.encode58Check(contractAddress)); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()),1); - - Account ownerAccount = PublicMethod.queryAccount(contractAddress,blockingStubFull); - final Frozen ownerFrozen = ownerAccount.getFrozen(0); - Long ownerBalance = ownerAccount.getBalance(); - String methodStrSuicide = "SelfdestructTest(address)"; - String argsStrSuicide = "\"" + Base58.encode58Check(targetAddress) + "\""; - String txidSuicide = PublicMethod - .triggerContract(contractAddress, methodStrSuicide, argsStrSuicide, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + Assert.assertEquals(ByteArray.toInt(ex.get().getContractResult(0).toByteArray()), 1); + + Account ownerAccount = PublicMethod.queryAccount(contractAddress, blockingStubFull); + final Frozen ownerFrozen = ownerAccount.getFrozen(0); + Long ownerBalance = ownerAccount.getBalance(); + String methodStrSuicide = "SelfdestructTest(address)"; + String argsStrSuicide = "\"" + Base58.encode58Check(targetAddress) + "\""; + String txidSuicide = + PublicMethod.triggerContract( + contractAddress, + methodStrSuicide, + argsStrSuicide, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Account targetAccount = PublicMethod.queryAccount(targetAddress,blockingStubFull); - final Frozen targetFrozenAfter = targetAccount.getFrozen(0); + Account targetAccount = PublicMethod.queryAccount(targetAddress, blockingStubFull); + final Frozen targetFrozenAfter = targetAccount.getFrozen(0); ex = PublicMethod.getTransactionInfoById(txidSuicide, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertEquals(ownerFrozen.getExpireTime(), targetFrozenAfter.getExpireTime()); - Assert.assertEquals(targetFrozenAfter.getFrozenBalance(), - ownerFrozen.getFrozenBalance()); - + Assert.assertEquals(targetFrozenAfter.getFrozenBalance(), ownerFrozen.getFrozenBalance()); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StakeSuicideTest005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StakeSuicideTest005.java index 8735149d..38ec4928 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StakeSuicideTest005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StakeSuicideTest005.java @@ -8,14 +8,14 @@ import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.Account.Frozen; import org.tron.protos.Protocol.TransactionInfo; -import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - public class StakeSuicideTest005 extends TronBaseTest { +import stest.tron.wallet.common.client.utils.Utils; + +public class StakeSuicideTest005 extends TronBaseTest { private byte[] testWitnessAddress = PublicMethod.getFinalAddress(witnessKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -33,134 +33,203 @@ public class StakeSuicideTest005 extends TronBaseTest { @BeforeClass(enabled = false) public void beforeClass() { System.out.println(testKey001); - PublicMethod.printAddress(testKey001); PublicMethod - .sendcoin(testAddress001, 1000_000_00000L, foundationAddress, foundationKey, - blockingStubFull); + PublicMethod.printAddress(testKey001); + PublicMethod.sendcoin( + testAddress001, 1000_000_00000L, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000_000000L, 100, null, testKey001, testAddress001, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000_000000L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = false, description = "targetAddress is account no TRX, and no frozen", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "targetAddress is account no TRX, and no frozen", + groups = {"contract", "daily"}) void tvmStakeSuicideTest001() { ECKey ecKeyTargetAddress = new ECKey(Utils.getRandom()); - byte[] targetAddress = ecKeyTargetAddress.getAddress(); - String testKeyTargetAddress = ByteArray.toHexString(ecKeyTargetAddress.getPrivKeyBytes()); - - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 1000_000000L, 100, - null, testKey001, testAddress001, blockingStubFull); - - Account ownerAccount = PublicMethod.queryAccount(contractAddress,blockingStubFull); - final Long ownerBalance = ownerAccount.getBalance(); - String methodStrSuicide = "SelfdestructTest(address)"; - String argsStrSuicide = "\"" + Base58.encode58Check(targetAddress) + "\""; - String txidSuicide = PublicMethod - .triggerContract(contractAddress, methodStrSuicide, argsStrSuicide, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + byte[] targetAddress = ecKeyTargetAddress.getAddress(); + String testKeyTargetAddress = ByteArray.toHexString(ecKeyTargetAddress.getPrivKeyBytes()); + + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000_000000L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); + + Account ownerAccount = PublicMethod.queryAccount(contractAddress, blockingStubFull); + final Long ownerBalance = ownerAccount.getBalance(); + String methodStrSuicide = "SelfdestructTest(address)"; + String argsStrSuicide = "\"" + Base58.encode58Check(targetAddress) + "\""; + String txidSuicide = + PublicMethod.triggerContract( + contractAddress, + methodStrSuicide, + argsStrSuicide, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional ex = PublicMethod.getTransactionInfoById(txidSuicide, - blockingStubFull); - ex = PublicMethod.getTransactionInfoById(txidSuicide,blockingStubFull); + Optional ex = + PublicMethod.getTransactionInfoById(txidSuicide, blockingStubFull); + ex = PublicMethod.getTransactionInfoById(txidSuicide, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Account targetAccount = PublicMethod.queryAccount(targetAddress,blockingStubFull); - Long targetBalance = targetAccount.getBalance(); + Account targetAccount = PublicMethod.queryAccount(targetAddress, blockingStubFull); + Long targetBalance = targetAccount.getBalance(); System.out.println(targetBalance); - Assert.assertEquals(ownerBalance,targetBalance); - + Assert.assertEquals(ownerBalance, targetBalance); } - @Test(enabled = false, description = "targetAddress is account 1 TRX, and no frozen", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "targetAddress is account 1 TRX, and no frozen", + groups = {"contract", "daily"}) void tvmStakeSuicideTest002() { ECKey ecKeyTargetAddress = new ECKey(Utils.getRandom()); - byte[] targetAddress = ecKeyTargetAddress.getAddress(); - final String testKeyTargetAddress = ByteArray.toHexString(ecKeyTargetAddress.getPrivKeyBytes()); + byte[] targetAddress = ecKeyTargetAddress.getAddress(); + final String testKeyTargetAddress = ByteArray.toHexString(ecKeyTargetAddress.getPrivKeyBytes()); - PublicMethod - .sendcoin(targetAddress, 1_000000L, foundationAddress, foundationKey, - blockingStubFull); + PublicMethod.sendcoin( + targetAddress, 1_000000L, foundationAddress, foundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000_000000L, 100, null, testKey001, testAddress001, blockingStubFull); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000_000000L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); - Account ownerAccount = PublicMethod.queryAccount(contractAddress,blockingStubFull); - final Long ownerBalance = ownerAccount.getBalance(); - String methodStrSuicide = "SelfdestructTest(address)"; - String argsStrSuicide = "\"" + Base58.encode58Check(targetAddress) + "\""; - String txidSuicide = PublicMethod - .triggerContract(contractAddress, methodStrSuicide, argsStrSuicide, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + Account ownerAccount = PublicMethod.queryAccount(contractAddress, blockingStubFull); + final Long ownerBalance = ownerAccount.getBalance(); + String methodStrSuicide = "SelfdestructTest(address)"; + String argsStrSuicide = "\"" + Base58.encode58Check(targetAddress) + "\""; + String txidSuicide = + PublicMethod.triggerContract( + contractAddress, + methodStrSuicide, + argsStrSuicide, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional ex = PublicMethod.getTransactionInfoById(txidSuicide, - blockingStubFull); - ex = PublicMethod.getTransactionInfoById(txidSuicide,blockingStubFull); + Optional ex = + PublicMethod.getTransactionInfoById(txidSuicide, blockingStubFull); + ex = PublicMethod.getTransactionInfoById(txidSuicide, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); - Account targetAccount = PublicMethod.queryAccount(targetAddress,blockingStubFull); - Long targetBalance = targetAccount.getBalance() - 1_000000L; + Account targetAccount = PublicMethod.queryAccount(targetAddress, blockingStubFull); + Long targetBalance = targetAccount.getBalance() - 1_000000L; - Assert.assertEquals(ownerBalance,targetBalance); + Assert.assertEquals(ownerBalance, targetBalance); - Assert.assertTrue(PublicMethod - .freezeBalance(targetAddress,1_000000L,3,testKeyTargetAddress,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance( + targetAddress, 1_000000L, 3, testKeyTargetAddress, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - } - @Test(enabled = false, description = "targetAddress is account 1 TRX, and 1 frozen", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "targetAddress is account 1 TRX, and 1 frozen", + groups = {"contract", "daily"}) void tvmStakeSuicideTest003() { ECKey ecKeyTargetAddress = new ECKey(Utils.getRandom()); - byte[] targetAddress = ecKeyTargetAddress.getAddress(); - String testKeyTargetAddress = ByteArray.toHexString(ecKeyTargetAddress.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod - .sendcoin(targetAddress, 10_000000L, foundationAddress, foundationKey, - blockingStubFull)); + byte[] targetAddress = ecKeyTargetAddress.getAddress(); + String testKeyTargetAddress = ByteArray.toHexString(ecKeyTargetAddress.getPrivKeyBytes()); + Assert.assertTrue( + PublicMethod.sendcoin( + targetAddress, 10_000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod - .freezeBalance(targetAddress,1_000000L,3,testKeyTargetAddress,blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance( + targetAddress, 1_000000L, 3, testKeyTargetAddress, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Account targetAccount = PublicMethod.queryAccount(targetAddress,blockingStubFull); - final Frozen targetFrozenBefore = targetAccount.getFrozen(0); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000_000000L, 100, null, testKey001, testAddress001, blockingStubFull); + Account targetAccount = PublicMethod.queryAccount(targetAddress, blockingStubFull); + final Frozen targetFrozenBefore = targetAccount.getFrozen(0); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000_000000L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Account ownerAccount = PublicMethod.queryAccount(contractAddress,blockingStubFull); - final Long ownerBalance = ownerAccount.getBalance(); - String methodStrSuicide = "SelfdestructTest(address)"; - String argsStrSuicide = "\"" + Base58.encode58Check(targetAddress) + "\""; - String txidSuicide = PublicMethod - .triggerContract(contractAddress, methodStrSuicide, argsStrSuicide, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + Account ownerAccount = PublicMethod.queryAccount(contractAddress, blockingStubFull); + final Long ownerBalance = ownerAccount.getBalance(); + String methodStrSuicide = "SelfdestructTest(address)"; + String argsStrSuicide = "\"" + Base58.encode58Check(targetAddress) + "\""; + String txidSuicide = + PublicMethod.triggerContract( + contractAddress, + methodStrSuicide, + argsStrSuicide, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional ex = PublicMethod.getTransactionInfoById(txidSuicide, - blockingStubFull); + Optional ex = + PublicMethod.getTransactionInfoById(txidSuicide, blockingStubFull); Assert.assertEquals(ex.get().getResult(), TransactionInfo.code.SUCESS); PublicMethod.waitProduceNextBlock(blockingStubFull); - Account targetAccountAfter = PublicMethod.queryAccount(targetAddress,blockingStubFull); + Account targetAccountAfter = PublicMethod.queryAccount(targetAddress, blockingStubFull); Frozen targetFrozenAfter = targetAccountAfter.getFrozen(0); - Long targetBalance = targetAccountAfter.getBalance() - 9_000000L; - Assert.assertEquals(targetFrozenBefore,targetFrozenAfter); - Assert.assertEquals(ownerBalance,targetBalance); - + Long targetBalance = targetAccountAfter.getBalance() - 9_000000L; + Assert.assertEquals(targetFrozenBefore, targetFrozenAfter); + Assert.assertEquals(ownerBalance, targetBalance); } - } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StakeTest001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StakeTest001.java index c80d931e..3f89a483 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StakeTest001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/StakeTest001.java @@ -14,13 +14,13 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class StakeTest001 extends TronBaseTest { - private String testFoundationKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private String testFoundationKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); private byte[] testWitnessAddress = PublicMethod.getFinalAddress(witnessKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -28,244 +28,367 @@ public class StakeTest001 extends TronBaseTest { String testKey001 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private byte[] contractAddress; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = false) public void beforeClass() { - PublicMethod.printAddress(testKey001); PublicMethod - .sendcoin(testAddress001, 1000_000_00000L, testFoundationAddress, testFoundationKey, - blockingStubFull); + PublicMethod.printAddress(testKey001); + PublicMethod.sendcoin( + testAddress001, + 1000_000_00000L, + testFoundationAddress, + testFoundationKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/testStakeSuicide.sol"; - String contractName = "testStakeSuicide"; + String filePath = "src/test/resources/soliditycode/testStakeSuicide.sol"; + String contractName = "testStakeSuicide"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 1000_000_0000L, 100, null, testKey001, testAddress001, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000_000_0000L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = false, description = "Vote for witness", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Vote for witness", + groups = {"contract", "daily"}) void tvmStakeTest001() { long balanceBefore = PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); - String methodStr = "Stake(address,uint256)"; - String argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + 1000000; - String txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + String methodStr = "Stake(address,uint256)"; + String argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + 1000000; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = PublicMethod.getTransactionInfoById(txid,blockingStubFull); - int contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); - Assert.assertEquals(contractResult,1); + Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); + int contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); + Assert.assertEquals(contractResult, 1); Account request = Account.newBuilder().setAddress(ByteString.copyFrom(contractAddress)).build(); long balanceAfter = PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); - Assert.assertEquals(balanceAfter,balanceBefore - 1000000); - byte[] voteAddress = (blockingStubFull.getAccount(request).getVotesList().get(0) - .getVoteAddress().toByteArray()); - Assert.assertEquals(testWitnessAddress,voteAddress); - Assert.assertEquals(1,blockingStubFull.getAccount(request).getVotes(0).getVoteCount()); - + Assert.assertEquals(balanceAfter, balanceBefore - 1000000); + byte[] voteAddress = + (blockingStubFull.getAccount(request).getVotesList().get(0).getVoteAddress().toByteArray()); + Assert.assertEquals(testWitnessAddress, voteAddress); + Assert.assertEquals(1, blockingStubFull.getAccount(request).getVotes(0).getVoteCount()); } - @Test(enabled = false, description = "Non-witness account", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Non-witness account", + groups = {"contract", "daily"}) void tvmStakeTest002() { - //account address + // account address String methodStr = "Stake(address,uint256)"; - String argsStr = "\"" + Base58.encode58Check(testAddress001) + "\"," + 1000000; - String txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + String argsStr = "\"" + Base58.encode58Check(testAddress001) + "\"," + 1000000; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = PublicMethod.getTransactionInfoById(txid,blockingStubFull); - int contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); - Assert.assertEquals(contractResult,0); - //contract address + Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); + int contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); + Assert.assertEquals(contractResult, 0); + // contract address methodStr = "Stake(address,uint256)"; - argsStr = "\"" + Base58.encode58Check(contractAddress) + "\"," + 1000000; - txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + argsStr = "\"" + Base58.encode58Check(contractAddress) + "\"," + 1000000; + txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - info = PublicMethod.getTransactionInfoById(txid,blockingStubFull); + info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); - Assert.assertEquals(contractResult,0); - + Assert.assertEquals(contractResult, 0); } - @Test(enabled = false, description = "Number of votes over balance", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Number of votes over balance", + groups = {"contract", "daily"}) void tvmStakeTest003() { String methodStr = "Stake(address,uint256)"; - String argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + Long.MAX_VALUE; - String txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + String argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + Long.MAX_VALUE; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = PublicMethod.getTransactionInfoById(txid,blockingStubFull); - int contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); - - Assert.assertEquals(contractResult,0); + Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); + int contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); + Assert.assertEquals(contractResult, 0); } - @Test(enabled = false, description = "Enough votes for a second ballot", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Enough votes for a second ballot", + groups = {"contract", "daily"}) void tvmStakeTest004() { PublicMethod.waitProduceNextBlock(blockingStubFull); - String methodStr = "Stake(address,uint256)"; - String argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + 21000000; - String txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + String methodStr = "Stake(address,uint256)"; + String argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + 21000000; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = PublicMethod.getTransactionInfoById(txid,blockingStubFull); - int contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); - Assert.assertEquals(contractResult,1); + Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); + int contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); + Assert.assertEquals(contractResult, 1); Account request = Account.newBuilder().setAddress(ByteString.copyFrom(contractAddress)).build(); - byte[] voteAddress = (blockingStubFull.getAccount(request).getVotesList().get(0) - .getVoteAddress().toByteArray()); - Assert.assertEquals(testWitnessAddress,voteAddress); + byte[] voteAddress = + (blockingStubFull.getAccount(request).getVotesList().get(0).getVoteAddress().toByteArray()); + Assert.assertEquals(testWitnessAddress, voteAddress); System.out.println(blockingStubFull.getAccount(request).getVotesCount()); - Assert.assertEquals(21,blockingStubFull.getAccount(request).getVotes(0).getVoteCount()); + Assert.assertEquals(21, blockingStubFull.getAccount(request).getVotes(0).getVoteCount()); - argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + 11000000; - txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + 11000000; + txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - info = PublicMethod.getTransactionInfoById(txid,blockingStubFull); + info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); - Assert.assertEquals(contractResult,1); + Assert.assertEquals(contractResult, 1); request = Account.newBuilder().setAddress(ByteString.copyFrom(contractAddress)).build(); - voteAddress = (blockingStubFull.getAccount(request).getVotesList().get(0).getVoteAddress() - .toByteArray()); - Assert.assertEquals(testWitnessAddress,voteAddress); - Assert.assertEquals(11,blockingStubFull.getAccount(request).getVotes(0).getVoteCount()); - + voteAddress = + (blockingStubFull.getAccount(request).getVotesList().get(0).getVoteAddress().toByteArray()); + Assert.assertEquals(testWitnessAddress, voteAddress); + Assert.assertEquals(11, blockingStubFull.getAccount(request).getVotes(0).getVoteCount()); } - @Test(enabled = false, description = "Revert test", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Revert test", + groups = {"contract", "daily"}) void tvmStakeTest005() { PublicMethod.waitProduceNextBlock(blockingStubFull); - String methodStr = "revertTest1(address,uint256,address)"; - String argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + 1000000 + ",\"" - + Base58.encode58Check(testAddress001) + "\""; - String txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + String methodStr = "revertTest1(address,uint256,address)"; + String argsStr = + "\"" + + Base58.encode58Check(testWitnessAddress) + + "\"," + + 1000000 + + ",\"" + + Base58.encode58Check(testAddress001) + + "\""; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = PublicMethod.getTransactionInfoById(txid,blockingStubFull); - int contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); - - Assert.assertEquals(contractResult,0); + Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); + int contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); + Assert.assertEquals(contractResult, 0); } - @Test(enabled = false, description = "Contract Call Contract stake", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Contract Call Contract stake", + groups = {"contract", "daily"}) void tvmStakeTest006() { String methodStr = "deployB()"; - String argsStr = ""; - String txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + String argsStr = ""; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("txid:" + txid); methodStr = "BStake(address,uint256)"; - argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + 1000000; - txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + 1000000; + txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); long callvalue = 1000000000L; - txid = PublicMethod.triggerContract(contractAddress, "deployB()", "#", false, - callvalue, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "deployB()", + "#", + false, + callvalue, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); - String addressHex = - "41" + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()) - .substring(24); - byte[] contractAddressB = ByteArray.fromHexString(addressHex); - long contractAddressBBalance = PublicMethod.queryAccount(contractAddressB, blockingStubFull) - .getBalance(); + String addressHex = + "41" + + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()) + .substring(24); + byte[] contractAddressB = ByteArray.fromHexString(addressHex); + long contractAddressBBalance = + PublicMethod.queryAccount(contractAddressB, blockingStubFull).getBalance(); Assert.assertEquals(callvalue, contractAddressBBalance); methodStr = "BStake(address,uint256)"; argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + 10000000; - txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - int contractResult = ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); + int contractResult = ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); Assert.assertEquals(contractResult, 1); Account account = PublicMethod.queryAccount(contractAddressB, blockingStubFull); long frozenBalance = account.getFrozen(0).getFrozenBalance(); - byte[] voteAddress = account.getVotes(0).getVoteAddress().toByteArray(); + byte[] voteAddress = account.getVotes(0).getVoteAddress().toByteArray(); long voteCount = account.getVotes(0).getVoteCount(); long balanceAfter = account.getBalance(); Assert.assertEquals(voteCount, 10); Assert.assertEquals(voteAddress, testWitnessAddress); Assert.assertEquals(frozenBalance, 10000000); Assert.assertEquals(balanceAfter, contractAddressBBalance - 10000000); - } - @Test(enabled = false, description = "Vote for the first witness and then vote for the second " - + "witness.", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "Vote for the first witness and then vote for the second " + "witness.", + groups = {"contract", "daily"}) void tvmStakeTest007() { PublicMethod.waitProduceNextBlock(blockingStubFull); - String methodStr = "Stake(address,uint256)"; - String argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + 21000000; - String txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + String methodStr = "Stake(address,uint256)"; + String argsStr = "\"" + Base58.encode58Check(testWitnessAddress) + "\"," + 21000000; + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = PublicMethod.getTransactionInfoById(txid,blockingStubFull); - int contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); - Assert.assertEquals(contractResult,1); + Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); + int contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); + Assert.assertEquals(contractResult, 1); Account request = Account.newBuilder().setAddress(ByteString.copyFrom(contractAddress)).build(); - byte[] voteAddress = (blockingStubFull.getAccount(request).getVotesList().get(0) - .getVoteAddress().toByteArray()); - Assert.assertEquals(testWitnessAddress,voteAddress); + byte[] voteAddress = + (blockingStubFull.getAccount(request).getVotesList().get(0).getVoteAddress().toByteArray()); + Assert.assertEquals(testWitnessAddress, voteAddress); System.out.println(blockingStubFull.getAccount(request).getVotesCount()); - Assert.assertEquals(21,blockingStubFull.getAccount(request).getVotes(0).getVoteCount()); + Assert.assertEquals(21, blockingStubFull.getAccount(request).getVotes(0).getVoteCount()); - argsStr = "\"" + Base58.encode58Check(witnessAddress3) + "\"," + 11000000; - txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + argsStr = "\"" + Base58.encode58Check(witnessAddress3) + "\"," + 11000000; + txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - info = PublicMethod.getTransactionInfoById(txid,blockingStubFull); + info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); - Assert.assertEquals(contractResult,1); + Assert.assertEquals(contractResult, 1); request = Account.newBuilder().setAddress(ByteString.copyFrom(contractAddress)).build(); - voteAddress = (blockingStubFull.getAccount(request).getVotesList().get(0).getVoteAddress() - .toByteArray()); - Assert.assertEquals(witnessAddress3,voteAddress); - Assert.assertEquals(11,blockingStubFull.getAccount(request).getVotes(0).getVoteCount()); - + voteAddress = + (blockingStubFull.getAccount(request).getVotesList().get(0).getVoteAddress().toByteArray()); + Assert.assertEquals(witnessAddress3, voteAddress); + Assert.assertEquals(11, blockingStubFull.getAccount(request).getVotes(0).getVoteCount()); } - } - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/UnStakeTest001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/UnStakeTest001.java index 8b981785..278b02d1 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/UnStakeTest001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/tvmstake/UnStakeTest001.java @@ -17,14 +17,14 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class UnStakeTest001 extends TronBaseTest { - private String testFoundationKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private String testFoundationKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private byte[] testFoundationAddress = PublicMethod.getFinalAddress(testFoundationKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] testAddress001 = ecKey1.getAddress(); @@ -34,189 +34,280 @@ public class UnStakeTest001 extends TronBaseTest { private String testKey002 = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); private byte[] contractAddress; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = false) public void beforeClass() { - PublicMethod.printAddress(testKey001); } + PublicMethod.printAddress(testKey001); + } - @Test(enabled = false, description = "unstake normal", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "unstake normal", + groups = {"contract", "daily"}) public void tvmStakeTest001Normal() { - PublicMethod - .sendcoin(testAddress001, 1120_000_000L, testFoundationAddress, testFoundationKey, - blockingStubFull); + PublicMethod.sendcoin( + testAddress001, 1120_000_000L, testFoundationAddress, testFoundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/unStake001.sol"; - String contractName = "unStakeTest"; + String filePath = "./src/test/resources/soliditycode/unStake001.sol"; + String contractName = "unStakeTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 1000000000L, 100, null, - testKey001, testAddress001, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000000L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String methodStr = "Stake(address,uint256)"; - String argsStr = "\"" + Base58.encode58Check(witnessAddress4) + "\"," + 10000000; + String methodStr = "Stake(address,uint256)"; + String argsStr = "\"" + Base58.encode58Check(witnessAddress4) + "\"," + 10000000; long balanceBefore = PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); - String txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - int contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); + int contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); Assert.assertEquals(contractResult, 1); Account account = PublicMethod.queryAccount(contractAddress, blockingStubFull); long balanceAfter = account.getBalance(); Assert.assertEquals(balanceAfter, balanceBefore - 10000000); long frozenBalance = account.getFrozen(0).getFrozenBalance(); - byte[] voteAddress = account.getVotes(0).getVoteAddress().toByteArray(); + byte[] voteAddress = account.getVotes(0).getVoteAddress().toByteArray(); long voteCount = account.getVotes(0).getVoteCount(); Assert.assertEquals(voteCount, 10); Assert.assertEquals(voteAddress, witnessAddress4); Assert.assertEquals(frozenBalance, 10000000); methodStr = "unStake()"; - txid = PublicMethod - .triggerContract(contractAddress, methodStr, "#", false, 0, maxFeeLimit, testAddress001, - testKey001, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + "#", + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); contractResult = ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); Assert.assertEquals(contractResult, 1); account = PublicMethod.queryAccount(contractAddress, blockingStubFull); - int frozenCount = account.getFrozenCount(); - int votesCount = account.getVotesCount(); + int frozenCount = account.getFrozenCount(); + int votesCount = account.getVotesCount(); Assert.assertEquals(0, frozenCount); Assert.assertEquals(0, votesCount); Assert.assertEquals(account.getBalance(), balanceBefore); } - @Test(enabled = false, description = "unstake when no stake", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "unstake when no stake", + groups = {"contract", "daily"}) public void tvmUnstakeTest002NoStake() { - PublicMethod - .sendcoin(testAddress001, 1120_000_000L, testFoundationAddress, testFoundationKey, - blockingStubFull); + PublicMethod.sendcoin( + testAddress001, 1120_000_000L, testFoundationAddress, testFoundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/unStake001.sol"; - String contractName = "unStakeTest"; + String filePath = "./src/test/resources/soliditycode/unStake001.sol"; + String contractName = "unStakeTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 1000000000L, 100, null, - testKey001, testAddress001, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000000L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String methodStr = "unStake()"; + String methodStr = "unStake()"; long balanceBefore = PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); - String txid = PublicMethod - .triggerContract(contractAddress, methodStr, "", false, 0, maxFeeLimit, testAddress001, - testKey001, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + "", + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); Account account = PublicMethod.queryAccount(contractAddress, blockingStubFull); Assert.assertEquals(account.getBalance(), balanceBefore); - int contractResult = ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); + int contractResult = ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); Assert.assertEquals(contractResult, 0); - int frozenCount = account.getFrozenCount(); - int votesCount = account.getVotesCount(); + int frozenCount = account.getFrozenCount(); + int votesCount = account.getVotesCount(); Assert.assertEquals(0, frozenCount); Assert.assertEquals(0, votesCount); } - @Test(enabled = false, description = "unstake twice", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "unstake twice", + groups = {"contract", "daily"}) public void tvmUnstakeTest003UnstakeTwice() { - PublicMethod - .sendcoin(testAddress001, 1120_000_000L, testFoundationAddress, testFoundationKey, - blockingStubFull); + PublicMethod.sendcoin( + testAddress001, 1120_000_000L, testFoundationAddress, testFoundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/unStake001.sol"; - String contractName = "unStakeTest"; + String filePath = "./src/test/resources/soliditycode/unStake001.sol"; + String contractName = "unStakeTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 1000000000L, 100, null, - testKey001, testAddress001, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000000L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String methodStr = "Stake(address,uint256)"; - String argsStr = "\"" + Base58.encode58Check(witnessAddress4) + "\"," + 10000000; + String methodStr = "Stake(address,uint256)"; + String argsStr = "\"" + Base58.encode58Check(witnessAddress4) + "\"," + 10000000; long balanceBefore = PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); - String txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - int contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); + int contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); Assert.assertEquals(contractResult, 1); Account account = PublicMethod.queryAccount(contractAddress, blockingStubFull); long balanceAfter = account.getBalance(); Assert.assertEquals(balanceAfter, balanceBefore - 10000000); long frozenBalance = account.getFrozen(0).getFrozenBalance(); - byte[] voteAddress = account.getVotes(0).getVoteAddress().toByteArray(); + byte[] voteAddress = account.getVotes(0).getVoteAddress().toByteArray(); long voteCount = account.getVotes(0).getVoteCount(); Assert.assertEquals(voteCount, 10); Assert.assertEquals(voteAddress, witnessAddress4); Assert.assertEquals(frozenBalance, 10000000); methodStr = "unStake2()"; - txid = PublicMethod - .triggerContract(contractAddress, methodStr, "", false, 0, maxFeeLimit, testAddress001, - testKey001, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + "", + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); contractResult = ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); Assert.assertEquals(contractResult, 0); account = PublicMethod.queryAccount(contractAddress, blockingStubFull); - int frozenCount = account.getFrozenCount(); - int votesCount = account.getVotesCount(); + int frozenCount = account.getFrozenCount(); + int votesCount = account.getVotesCount(); Assert.assertEquals(0, frozenCount); Assert.assertEquals(0, votesCount); Assert.assertEquals(account.getBalance(), balanceBefore); } - @Test(enabled = false, description = "unstake revert", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "unstake revert", + groups = {"contract", "daily"}) public void tvmUnstakeTest004Revert() { - PublicMethod - .sendcoin(testAddress001, 1120_000_000L, testFoundationAddress, testFoundationKey, - blockingStubFull); + PublicMethod.sendcoin( + testAddress001, 1120_000_000L, testFoundationAddress, testFoundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/unStake001.sol"; - String contractName = "unStakeTest"; + String filePath = "./src/test/resources/soliditycode/unStake001.sol"; + String contractName = "unStakeTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 1000000000L, 100, null, - testKey001, testAddress001, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000000L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String methodStr = "Stake(address,uint256)"; - String argsStr = "\"" + Base58.encode58Check(witnessAddress4) + "\"," + 10000000; + String methodStr = "Stake(address,uint256)"; + String argsStr = "\"" + Base58.encode58Check(witnessAddress4) + "\"," + 10000000; long balanceBefore = PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); - String txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - int contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); + int contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); Assert.assertEquals(contractResult, 1); Account account = PublicMethod.queryAccount(contractAddress, blockingStubFull); long balanceAfter = account.getBalance(); Assert.assertEquals(balanceAfter, balanceBefore - 10000000); long frozenBalance = account.getFrozen(0).getFrozenBalance(); - byte[] voteAddress = account.getVotes(0).getVoteAddress().toByteArray(); + byte[] voteAddress = account.getVotes(0).getVoteAddress().toByteArray(); long voteCount = account.getVotes(0).getVoteCount(); Assert.assertEquals(voteCount, 10); Assert.assertEquals(voteAddress, witnessAddress4); @@ -224,19 +315,27 @@ public void tvmUnstakeTest004Revert() { methodStr = "revertTest2(address)"; argsStr = "\"" + Base58.encode58Check(testAddress002) + "\""; - txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, false, 0, maxFeeLimit, testAddress001, - testKey001, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); contractResult = ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); Assert.assertEquals(contractResult, 0); account = PublicMethod.queryAccount(contractAddress, blockingStubFull); - int frozenCount = account.getFrozenCount(); - int votesCount = account.getVotesCount(); + int frozenCount = account.getFrozenCount(); + int votesCount = account.getVotesCount(); Assert.assertEquals(0, frozenCount); Assert.assertEquals(0, votesCount); Assert.assertEquals(account.getBalance(), 993000000L); @@ -244,115 +343,170 @@ public void tvmUnstakeTest004Revert() { Assert.assertEquals(7000000L, balance); } - @Test(enabled = false, description = "unstake call another contract in one contract", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "unstake call another contract in one contract", + groups = {"contract", "daily"}) public void tvmUnstakeTest005CallAnotherInOneContract() { - PublicMethod - .sendcoin(testAddress001, 2120_000_000L, testFoundationAddress, testFoundationKey, - blockingStubFull); + PublicMethod.sendcoin( + testAddress001, 2120_000_000L, testFoundationAddress, testFoundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/unStake001.sol"; - String contractName = "unStakeTest"; + String filePath = "./src/test/resources/soliditycode/unStake001.sol"; + String contractName = "unStakeTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 1000000000L, 100, null, - testKey001, testAddress001, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000000L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); long callvalue = 1000000000L; - String txid = PublicMethod.triggerContract(contractAddress, "deployB()", "#", false, - callvalue, maxFeeLimit, testAddress001, testKey001, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + "deployB()", + "#", + false, + callvalue, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); - String addressHex = - "41" + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()) - .substring(24); + String addressHex = + "41" + + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()) + .substring(24); logger.info("address_hex: " + addressHex); - byte[] contractAddressB = ByteArray.fromHexString(addressHex); + byte[] contractAddressB = ByteArray.fromHexString(addressHex); logger.info("contractAddressB: " + Base58.encode58Check(contractAddressB)); - long contractAddressBBalance = PublicMethod.queryAccount(contractAddressB, blockingStubFull) - .getBalance(); + long contractAddressBBalance = + PublicMethod.queryAccount(contractAddressB, blockingStubFull).getBalance(); Assert.assertEquals(callvalue, contractAddressBBalance); - String methodStr = "BStake(address,uint256)"; - String argsStr = "\"" + Base58.encode58Check(witnessAddress4) + "\"," + 10000000; - txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + String methodStr = "BStake(address,uint256)"; + String argsStr = "\"" + Base58.encode58Check(witnessAddress4) + "\"," + 10000000; + txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - int contractResult = ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); + int contractResult = ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); Assert.assertEquals(contractResult, 1); Account account = PublicMethod.queryAccount(contractAddressB, blockingStubFull); long frozenBalance = account.getFrozen(0).getFrozenBalance(); - byte[] voteAddress = account.getVotes(0).getVoteAddress().toByteArray(); + byte[] voteAddress = account.getVotes(0).getVoteAddress().toByteArray(); long voteCount = account.getVotes(0).getVoteCount(); long balanceAfter = account.getBalance(); Assert.assertEquals(voteCount, 10); Assert.assertEquals(voteAddress, witnessAddress4); Assert.assertEquals(frozenBalance, 10000000); Assert.assertEquals(balanceAfter, contractAddressBBalance - 10000000); - long contractAddressBalance = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + long contractAddressBalance = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(contractAddressBalance, 1000000000); methodStr = "BUnStake()"; - txid = PublicMethod - .triggerContract(contractAddress, methodStr, "", false, 0, maxFeeLimit, testAddress001, - testKey001, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + "", + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); contractResult = ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); Assert.assertEquals(contractResult, 1); account = PublicMethod.queryAccount(contractAddressB, blockingStubFull); - int frozenCount = account.getFrozenCount(); - int votesCount = account.getVotesCount(); + int frozenCount = account.getFrozenCount(); + int votesCount = account.getVotesCount(); Assert.assertEquals(0, frozenCount); Assert.assertEquals(0, votesCount); Assert.assertEquals(account.getBalance(), contractAddressBBalance); - contractAddressBalance = PublicMethod.queryAccount(contractAddress, blockingStubFull) - .getBalance(); + contractAddressBalance = + PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); Assert.assertEquals(contractAddressBalance, 1000000000); } - @Test(enabled = false, description = "unstake with reward balance", groups = {"contract", "daily"}) + @Test( + enabled = false, + description = "unstake with reward balance", + groups = {"contract", "daily"}) public void tvmUnstakeTest006WithRewardBalance() { - PublicMethod - .sendcoin(testAddress001, 1120_000_000L, testFoundationAddress, testFoundationKey, - blockingStubFull); + PublicMethod.sendcoin( + testAddress001, 1120_000_000L, testFoundationAddress, testFoundationKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/unStake001.sol"; - String contractName = "unStakeTest"; + String filePath = "./src/test/resources/soliditycode/unStake001.sol"; + String contractName = "unStakeTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 1000000000L, 100, null, - testKey001, testAddress001, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000000L, + 100, + null, + testKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String methodStr = "Stake(address,uint256)"; - String argsStr = "\"" + Base58.encode58Check(witnessAddress4) + "\"," + 10000000; + String methodStr = "Stake(address,uint256)"; + String argsStr = "\"" + Base58.encode58Check(witnessAddress4) + "\"," + 10000000; long balanceBefore = PublicMethod.queryAccount(contractAddress, blockingStubFull).getBalance(); - String txid = PublicMethod - .triggerContract(contractAddress, methodStr, argsStr, - false, 0, maxFeeLimit, - testAddress001, testKey001, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - int contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); + int contractResult = ByteArray.toInt(info.get().getContractResult(0).toByteArray()); Assert.assertEquals(contractResult, 1); Account account = PublicMethod.queryAccount(contractAddress, blockingStubFull); long balanceAfter = account.getBalance(); Assert.assertEquals(balanceAfter, balanceBefore - 10000000); long frozenBalance = account.getFrozen(0).getFrozenBalance(); - byte[] voteAddress = account.getVotes(0).getVoteAddress().toByteArray(); + byte[] voteAddress = account.getVotes(0).getVoteAddress().toByteArray(); long voteCount = account.getVotes(0).getVoteCount(); Assert.assertEquals(voteCount, 10); Assert.assertEquals(voteAddress, witnessAddress4); @@ -362,26 +516,43 @@ public void tvmUnstakeTest006WithRewardBalance() { methodStr = "rewardBalance(address)"; argsStr = "\"" + Base58.encode58Check(contractAddress) + "\""; - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, methodStr, argsStr, false, 0, 0, "0", - 0, testAddress001, testKey001, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methodStr, + argsStr, + false, + 0, + 0, + "0", + 0, + testAddress001, + testKey001, + blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); System.out.println("Result:" + Hex.toHexString(result)); - org.junit.Assert.assertEquals(0, ByteArray.toLong(ByteArray - .fromHexString(Hex - .toHexString(result)))); + org.junit.Assert.assertEquals( + 0, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); methodStr = "withdrawReward()"; - txid = PublicMethod - .triggerContract(contractAddress, methodStr, "", false, 0, maxFeeLimit, testAddress001, - testKey001, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + "", + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); contractResult = ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); @@ -391,44 +562,58 @@ public void tvmUnstakeTest006WithRewardBalance() { Assert.assertEquals(balanceAfter, balanceAfter2); methodStr = "unStake2()"; - txid = PublicMethod - .triggerContract(contractAddress, methodStr, "", false, 0, maxFeeLimit, testAddress001, - testKey001, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + "", + false, + 0, + maxFeeLimit, + testAddress001, + testKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(infoById.toString()); Assert.assertEquals(0, infoById.get().getResultValue()); contractResult = ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); Assert.assertEquals(contractResult, 0); account = PublicMethod.queryAccount(contractAddress, blockingStubFull); - int frozenCount = account.getFrozenCount(); - int votesCount = account.getVotesCount(); + int frozenCount = account.getFrozenCount(); + int votesCount = account.getVotesCount(); Assert.assertEquals(0, frozenCount); Assert.assertEquals(0, votesCount); Assert.assertEquals(account.getBalance(), balanceBefore); methodStr = "rewardBalance(address)"; argsStr = "\"" + Base58.encode58Check(contractAddress) + "\""; - transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddress, methodStr, argsStr, false, 0, 0, "0", - 0, testAddress001, testKey001, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddress, + methodStr, + argsStr, + false, + 0, + 0, + "0", + 0, + testAddress001, + testKey001, + blockingStubFull); transaction = transactionExtention.getTransaction(); result = transactionExtention.getConstantResult(0).toByteArray(); System.out.println("message:" + transaction.getRet(0).getRet()); System.out.println( ":" + ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray())); System.out.println("Result:" + Hex.toHexString(result)); - org.junit.Assert.assertEquals(0, ByteArray.toLong(ByteArray - .fromHexString(Hex - .toHexString(result)))); + org.junit.Assert.assertEquals( + 0, ByteArray.toLong(ByteArray.fromHexString(Hex.toHexString(result)))); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(testAddress001, testKey001, testFoundationAddress, blockingStubFull); } - + PublicMethod.freeResource(testAddress001, testKey001, testFoundationAddress, blockingStubFull); + } } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/validatemultisign/TestValidatemultisign001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/validatemultisign/TestValidatemultisign001.java index c0130ec5..749dc923 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/validatemultisign/TestValidatemultisign001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/validatemultisign/TestValidatemultisign001.java @@ -22,13 +22,13 @@ import stest.tron.wallet.common.client.utils.ByteUtil; import stest.tron.wallet.common.client.utils.CommonParameter; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; import stest.tron.wallet.common.client.utils.Sha256Hash; import stest.tron.wallet.common.client.utils.TransactionUtils; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode @@ -50,53 +50,74 @@ public class TestValidatemultisign001 extends TronBaseTest { ECKey ecKey004 = new ECKey(Utils.getRandom()); byte[] participateAddress = ecKey004.getAddress(); String participateKey = ByteArray.toHexString(ecKey004.getPrivKeyBytes()); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private byte[] contractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); } - @Test(enabled = true, description = "Deploy validatemultisign contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy validatemultisign contract", + groups = {"contract", "daily"}) public void test001DeployContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 1000_000_000L, foundationAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(foundationAddress, 100_000_000L, - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1000_000_000L, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100_000_000L, + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(dev001Key, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = accountResource.getEnergyUsed(); - Long beforeNetUsed = accountResource.getNetUsed(); - Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = accountResource.getEnergyUsed(); + Long beforeNetUsed = accountResource.getNetUsed(); + Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String filePath = "./src/test/resources/soliditycode/validatemultisign001.sol"; - String contractName = "validatemultisignTest"; + String filePath = "./src/test/resources/soliditycode/validatemultisign001.sol"; + String contractName = "validatemultisignTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -104,18 +125,17 @@ public void test001DeployContract() { infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); PublicMethod.printAddress(ownerKey); long needCoin = updateAccountPermissionFee * 1 + multiSignFee * 3; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, needCoin + 2048000000L, foundationAddress, testKey002, - blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, needCoin + 2048000000L, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -124,48 +144,70 @@ public void test001DeployContract() { ownerKeyString[1] = manager1Key; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Trigger validatemultisign contract with " - + "Permission(address) case", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger validatemultisign contract with " + "Permission(address) case", + groups = {"contract", "daily"}) public void test002validatemultisign() { List signatures = new ArrayList<>(); ownerKeyString[0] = ownerKey; ownerKeyString[1] = manager1Key; - Transaction transaction = PublicMethodForMultiSign.sendcoinGetTransaction( - foundationAddress, 1L, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); - byte[] hash = Sha256Hash.of(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()).getBytes(); - byte[] merged = ByteUtil.merge(ownerAddress, ByteArray.fromInt(0), hash); - byte[] tosign = Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), merged); + Transaction transaction = + PublicMethodForMultiSign.sendcoinGetTransaction( + foundationAddress, 1L, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); + byte[] hash = + Sha256Hash.of( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()) + .getBytes(); + byte[] merged = ByteUtil.merge(ownerAddress, ByteArray.fromInt(0), hash); + byte[] tosign = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), merged); signatures.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray())); - // Trigger with correct Permission address - List parameters = Arrays.asList(WalletClient.encode58Check(ownerAddress), - 0, "0x" + Hex.toHexString(hash), signatures); - String input = PublicMethod.parametersString(parameters); - String methodStr = "testmulti(address,uint256,bytes32,bytes[])"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, input, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + // Trigger with correct Permission address + List parameters = + Arrays.asList( + WalletClient.encode58Check(ownerAddress), 0, "0x" + Hex.toHexString(hash), signatures); + String input = PublicMethod.parametersString(parameters); + String methodStr = "testmulti(address,uint256,bytes32,bytes[])"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + input, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -174,84 +216,126 @@ public void test002validatemultisign() { Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals(1, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - // Trigger with wrong Permission address + // Trigger with wrong Permission address merged = ByteUtil.merge(dev001Address, ByteArray.fromInt(0), hash); - tosign = Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), merged); + tosign = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), merged); signatures.clear(); signatures.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray())); - parameters = Arrays.asList(WalletClient.encode58Check(dev001Address), - 0, "0x" + Hex.toHexString(hash), signatures); + parameters = + Arrays.asList( + WalletClient.encode58Check(dev001Address), 0, "0x" + Hex.toHexString(hash), signatures); input = PublicMethod.parametersString(parameters); - TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, input, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + input, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("infoById" + infoById); Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - // Trigger with address that have not permission + // Trigger with address that have not permission merged = ByteUtil.merge(foundationAddress, ByteArray.fromInt(0), hash); - tosign = Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), merged); + tosign = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), merged); signatures.clear(); signatures.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray())); - parameters = Arrays.asList(WalletClient.encode58Check(foundationAddress), - 0, "0x" + Hex.toHexString(hash), signatures); + parameters = + Arrays.asList( + WalletClient.encode58Check(foundationAddress), + 0, + "0x" + Hex.toHexString(hash), + signatures); input = PublicMethod.parametersString(parameters); - TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, input, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + input, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("infoById" + infoById); Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - // Trigger with not exist address + // Trigger with not exist address merged = ByteUtil.merge(manager1Address, ByteArray.fromInt(0), hash); - tosign = Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), merged); + tosign = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), merged); signatures.clear(); signatures.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray())); - parameters = Arrays.asList(WalletClient.encode58Check(manager1Address), - 0, "0x" + Hex.toHexString(hash), signatures); + parameters = + Arrays.asList( + WalletClient.encode58Check(manager1Address), + 0, + "0x" + Hex.toHexString(hash), + signatures); input = PublicMethod.parametersString(parameters); - TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, input, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + input, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("infoById" + infoById); Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - // Trigger with error format address + // Trigger with error format address merged = ByteUtil.merge(manager1Address, ByteArray.fromInt(0), hash); - tosign = Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), merged); + tosign = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), merged); signatures.clear(); signatures.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray())); - parameters = Arrays.asList("TVgXWwGWE9huXiE4FuzDuGnCPUowsbZ8VZ", - 0, "0x" + Hex.toHexString(hash), signatures); + parameters = + Arrays.asList( + "TVgXWwGWE9huXiE4FuzDuGnCPUowsbZ8VZ", 0, "0x" + Hex.toHexString(hash), signatures); input = PublicMethod.parametersString(parameters); - TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, input, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + input, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("infoById" + infoById); @@ -260,33 +344,51 @@ public void test002validatemultisign() { Assert.assertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "Trigger validatemultisign contract with " - + "Permission(permissionId) case", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger validatemultisign contract with " + "Permission(permissionId) case", + groups = {"contract", "daily"}) public void test003validatemultisign() { List signatures = new ArrayList<>(); ownerKeyString[0] = ownerKey; ownerKeyString[1] = manager1Key; - Transaction transaction = PublicMethodForMultiSign.sendcoinGetTransaction( - foundationAddress, 1L, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); - byte[] hash = Sha256Hash.of(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()).getBytes(); - // Trigger with wrong PermissionID + Transaction transaction = + PublicMethodForMultiSign.sendcoinGetTransaction( + foundationAddress, 1L, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); + byte[] hash = + Sha256Hash.of( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()) + .getBytes(); + // Trigger with wrong PermissionID long permissionId = 2; - byte[] merged = ByteUtil.merge(ownerAddress, ByteArray.fromLong(permissionId), hash); - byte[] tosign = Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), merged); + byte[] merged = ByteUtil.merge(ownerAddress, ByteArray.fromLong(permissionId), hash); + byte[] tosign = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), merged); signatures.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray())); - List parameters = Arrays.asList(WalletClient.encode58Check(ownerAddress), - permissionId, "0x" + Hex.toHexString(hash), signatures); - String input = PublicMethod.parametersString(parameters); - String methodStr = "testmulti(address,uint256,bytes32,bytes[])"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, input, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + List parameters = + Arrays.asList( + WalletClient.encode58Check(ownerAddress), + permissionId, + "0x" + Hex.toHexString(hash), + signatures); + String input = PublicMethod.parametersString(parameters); + String methodStr = "testmulti(address,uint256,bytes32,bytes[])"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + input, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -295,66 +397,102 @@ public void test003validatemultisign() { Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - // Trigger with error format PermissionID + // Trigger with error format PermissionID permissionId = 100; merged = ByteUtil.merge(ownerAddress, ByteArray.fromLong(permissionId), hash); - tosign = Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), merged); + tosign = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), merged); signatures.clear(); signatures.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray())); - parameters = Arrays.asList(WalletClient.encode58Check(ownerAddress), - permissionId, "0x" + Hex.toHexString(hash), signatures); + parameters = + Arrays.asList( + WalletClient.encode58Check(ownerAddress), + permissionId, + "0x" + Hex.toHexString(hash), + signatures); input = PublicMethod.parametersString(parameters); - TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, input, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + input, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("infoById" + infoById); Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - // Trigger with Long.MAX_VALUE + 1 PermissionID + // Trigger with Long.MAX_VALUE + 1 PermissionID permissionId = Long.MAX_VALUE + 1; merged = ByteUtil.merge(ownerAddress, ByteArray.fromLong(permissionId), hash); - tosign = Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), merged); + tosign = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), merged); signatures.clear(); signatures.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray())); - parameters = Arrays.asList(WalletClient.encode58Check(ownerAddress), - permissionId, "0x" + Hex.toHexString(hash), signatures); + parameters = + Arrays.asList( + WalletClient.encode58Check(ownerAddress), + permissionId, + "0x" + Hex.toHexString(hash), + signatures); input = PublicMethod.parametersString(parameters); - TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, input, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + input, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("infoById" + infoById); Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - // Trigger with Long.MIN_VALUE - 1 PermissionID + // Trigger with Long.MIN_VALUE - 1 PermissionID permissionId = Long.MIN_VALUE - 1; merged = ByteUtil.merge(ownerAddress, ByteArray.fromLong(permissionId), hash); - tosign = Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), merged); + tosign = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), merged); signatures.clear(); signatures.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray())); - parameters = Arrays.asList(WalletClient.encode58Check(ownerAddress), - permissionId, "0x" + Hex.toHexString(hash), signatures); + parameters = + Arrays.asList( + WalletClient.encode58Check(ownerAddress), + permissionId, + "0x" + Hex.toHexString(hash), + signatures); input = PublicMethod.parametersString(parameters); - TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, input, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + input, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("infoById" + infoById); @@ -363,32 +501,47 @@ public void test003validatemultisign() { Assert.assertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "Trigger validatemultisign contract with " - + "Permission(hash) case", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger validatemultisign contract with " + "Permission(hash) case", + groups = {"contract", "daily"}) public void test004validatemultisign() { List signatures = new ArrayList<>(); ownerKeyString[0] = ownerKey; ownerKeyString[1] = manager1Key; - Transaction transaction = PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( - foundationAddress, 1L, ownerAddress, 0, ownerKey, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, ownerAddress, 0, ownerKey, blockingStubFull); transaction = TransactionUtils.setTimestamp(transaction); - byte[] hash = Sha256Hash.of(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()).getBytes(); - byte[] merged = ByteUtil.merge(ownerAddress, ByteArray.fromInt(0), hash); - byte[] tosign = Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), merged); + byte[] hash = + Sha256Hash.of( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()) + .getBytes(); + byte[] merged = ByteUtil.merge(ownerAddress, ByteArray.fromInt(0), hash); + byte[] tosign = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), merged); signatures.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray())); - // Trigger with no sign hash - List parameters = Arrays.asList(WalletClient.encode58Check(ownerAddress), - 0, "0x" + Hex.toHexString(hash), signatures); - String input = PublicMethod.parametersString(parameters); - String methodStr = "testmulti(address,uint256,bytes32,bytes[])"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, input, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + // Trigger with no sign hash + List parameters = + Arrays.asList( + WalletClient.encode58Check(ownerAddress), 0, "0x" + Hex.toHexString(hash), signatures); + String input = PublicMethod.parametersString(parameters); + String methodStr = "testmulti(address,uint256,bytes32,bytes[])"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + input, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -397,33 +550,53 @@ public void test004validatemultisign() { Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals(1, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - // Trigger with wrong hash - transaction = PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( - foundationAddress, 1L, ownerAddress, 0, ownerKey, blockingStubFull); - logger.info("hash: {}", Sha256Hash.of(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()).getBytes()); - - hash = Sha256Hash.of(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()).getBytes(); + // Trigger with wrong hash + transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, ownerAddress, 0, ownerKey, blockingStubFull); + logger.info( + "hash: {}", + Sha256Hash.of( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()) + .getBytes()); + + hash = + Sha256Hash.of( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()) + .getBytes(); merged = ByteUtil.merge(ownerAddress, ByteArray.fromInt(0), hash); - tosign = Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), merged); + tosign = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), merged); signatures.clear(); signatures.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray())); transaction = TransactionUtils.setTimestamp(transaction); - hash = Sha256Hash.of(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()).getBytes(); - - parameters = Arrays.asList(WalletClient.encode58Check(ownerAddress), - 0, "0x" + Hex.toHexString(hash), signatures); + hash = + Sha256Hash.of( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()) + .getBytes(); + + parameters = + Arrays.asList( + WalletClient.encode58Check(ownerAddress), 0, "0x" + Hex.toHexString(hash), signatures); input = PublicMethod.parametersString(parameters); - TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, input, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + input, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); @@ -431,29 +604,42 @@ public void test004validatemultisign() { Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - // 1) address B create transaction_1, but address A`s permission address sign + // 1) address B create transaction_1, but address A`s permission address sign // 2) user address A verify transaction_1 that created by B - transaction = PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( - foundationAddress, 1L, dev001Address, 0, dev001Key, blockingStubFull); + transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, dev001Address, 0, dev001Key, blockingStubFull); transaction = TransactionUtils.setTimestamp(transaction); - hash = Sha256Hash.of(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()).getBytes(); + hash = + Sha256Hash.of( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()) + .getBytes(); merged = ByteUtil.merge(ownerAddress, ByteArray.fromInt(0), hash); - tosign = Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), merged); + tosign = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), merged); signatures.clear(); signatures.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray())); - parameters = Arrays.asList(WalletClient.encode58Check(ownerAddress), - 0, "0x" + Hex.toHexString(hash), signatures); + parameters = + Arrays.asList( + WalletClient.encode58Check(ownerAddress), 0, "0x" + Hex.toHexString(hash), signatures); input = PublicMethod.parametersString(parameters); - TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, input, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + input, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); @@ -462,5 +648,4 @@ public void test004validatemultisign() { Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals(1, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/validatemultisign/TestValidatemultisign002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/validatemultisign/TestValidatemultisign002.java index f9b65fa4..fd210cf1 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/validatemultisign/TestValidatemultisign002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/validatemultisign/TestValidatemultisign002.java @@ -22,13 +22,13 @@ import stest.tron.wallet.common.client.utils.ByteUtil; import stest.tron.wallet.common.client.utils.CommonParameter; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; import stest.tron.wallet.common.client.utils.Sha256Hash; import stest.tron.wallet.common.client.utils.TransactionUtils; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode @@ -56,53 +56,74 @@ public class TestValidatemultisign002 extends TronBaseTest { ECKey ecKey006 = new ECKey(Utils.getRandom()); byte[] manager6Address = ecKey006.getAddress(); String manager6Key = ByteArray.toHexString(ecKey006.getPrivKeyBytes()); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private byte[] contractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); } - @Test(enabled = true, description = "Deploy validatemultisign contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy validatemultisign contract", + groups = {"contract", "daily"}) public void test001DeployContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 1000_000_000L, foundationAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(foundationAddress, 100_000_000L, - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1000_000_000L, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100_000_000L, + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(dev001Key, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = accountResource.getEnergyUsed(); - Long beforeNetUsed = accountResource.getNetUsed(); - Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = accountResource.getEnergyUsed(); + Long beforeNetUsed = accountResource.getNetUsed(); + Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String filePath = "./src/test/resources/soliditycode/validatemultisign001.sol"; - String contractName = "validatemultisignTest"; + String filePath = "./src/test/resources/soliditycode/validatemultisign001.sol"; + String contractName = "validatemultisignTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -110,18 +131,17 @@ public void test001DeployContract() { infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); PublicMethod.printAddress(ownerKey); long needCoin = updateAccountPermissionFee * 1 + multiSignFee * 3; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, needCoin + 2048000000L, foundationAddress, testKey002, - blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, needCoin + 2048000000L, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -130,49 +150,81 @@ public void test001DeployContract() { ownerKeyString[1] = manager1Key; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":3," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":2}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":3}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager4Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager5Key) + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":2}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":3}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager4Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager5Key) + + "\",\"weight\":1}," + "]}]}"; logger.info(accountPermissionJson); - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Trigger validatemultisign with signatures num", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger validatemultisign with signatures num", + groups = {"contract", "daily"}) public void test002validatemultisign() { List signatures = new ArrayList<>(); - int permissionId = 2; + int permissionId = 2; ownerKeyString[0] = ownerKey; ownerKeyString[1] = manager1Key; - Transaction transaction = PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( - foundationAddress, 1L, ownerAddress, permissionId, ownerKey, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, ownerAddress, permissionId, ownerKey, blockingStubFull); transaction = TransactionUtils.setTimestamp(transaction); - byte[] hash = Sha256Hash.of(CommonParameter.getInstance().isECKeyCryptoEngine(), - transaction.getRawData().toByteArray()).getBytes(); - byte[] merged = ByteUtil.merge(ownerAddress, ByteArray.fromInt(permissionId), hash); - byte[] tosign = Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), merged); + byte[] hash = + Sha256Hash.of( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()) + .getBytes(); + byte[] merged = ByteUtil.merge(ownerAddress, ByteArray.fromInt(permissionId), hash); + byte[] tosign = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), merged); signatures.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray())); - // Trigger with one signature - List parameters = Arrays.asList(WalletClient.encode58Check(ownerAddress), - permissionId, "0x" + Hex.toHexString(hash), signatures); - String input = PublicMethod.parametersString(parameters); - String methodStr = "testmulti(address,uint256,bytes32,bytes[])"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, input, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + // Trigger with one signature + List parameters = + Arrays.asList( + WalletClient.encode58Check(ownerAddress), + permissionId, + "0x" + Hex.toHexString(hash), + signatures); + String input = PublicMethod.parametersString(parameters); + String methodStr = "testmulti(address,uint256,bytes32,bytes[])"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + input, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -181,7 +233,7 @@ public void test002validatemultisign() { Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals(1, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - // Trigger with five signature + // Trigger with five signature signatures.clear(); signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey002.sign(tosign).toByteArray())); @@ -189,19 +241,32 @@ public void test002validatemultisign() { signatures.add(Hex.toHexString(ecKey004.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey005.sign(tosign).toByteArray())); - parameters = Arrays.asList(WalletClient.encode58Check(ownerAddress), - permissionId, "0x" + Hex.toHexString(hash), signatures); + parameters = + Arrays.asList( + WalletClient.encode58Check(ownerAddress), + permissionId, + "0x" + Hex.toHexString(hash), + signatures); input = PublicMethod.parametersString(parameters); - TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, input, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + input, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("infoById" + infoById); Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals(1, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - // Trigger with six signature + // Trigger with six signature signatures.clear(); signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey002.sign(tosign).toByteArray())); @@ -210,48 +275,79 @@ public void test002validatemultisign() { signatures.add(Hex.toHexString(ecKey005.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey006.sign(tosign).toByteArray())); - parameters = Arrays.asList(WalletClient.encode58Check(ownerAddress), - permissionId, "0x" + Hex.toHexString(hash), signatures); + parameters = + Arrays.asList( + WalletClient.encode58Check(ownerAddress), + permissionId, + "0x" + Hex.toHexString(hash), + signatures); input = PublicMethod.parametersString(parameters); - TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, input, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + input, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("infoById" + infoById); Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - } - @Test(enabled = true, description = "Trigger validatemultisign with Duplicate signatures", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger validatemultisign with Duplicate signatures", + groups = {"contract", "daily"}) public void test003validatemultisign() { List signatures = new ArrayList<>(); - int permissionId = 2; + int permissionId = 2; ownerKeyString[0] = ownerKey; ownerKeyString[1] = manager1Key; - Transaction transaction = PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( - foundationAddress, 1L, ownerAddress, permissionId, ownerKey, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, ownerAddress, permissionId, ownerKey, blockingStubFull); transaction = TransactionUtils.setTimestamp(transaction); - byte[] hash = Sha256Hash.of(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()).getBytes(); - byte[] merged = ByteUtil.merge(ownerAddress, ByteArray.fromInt(permissionId), hash); - byte[] tosign = Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), merged); - // signatures with Duplicate signatures but weight enough + byte[] hash = + Sha256Hash.of( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()) + .getBytes(); + byte[] merged = ByteUtil.merge(ownerAddress, ByteArray.fromInt(permissionId), hash); + byte[] tosign = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), merged); + // signatures with Duplicate signatures but weight enough signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey002.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey004.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey004.sign(tosign).toByteArray())); - List parameters = Arrays.asList(WalletClient.encode58Check(ownerAddress), - permissionId, "0x" + Hex.toHexString(hash), signatures); - String input = PublicMethod.parametersString(parameters); - String methodStr = "testmulti(address,uint256,bytes32,bytes[])"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, input, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + List parameters = + Arrays.asList( + WalletClient.encode58Check(ownerAddress), + permissionId, + "0x" + Hex.toHexString(hash), + signatures); + String input = PublicMethod.parametersString(parameters); + String methodStr = "testmulti(address,uint256,bytes32,bytes[])"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + input, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -260,26 +356,39 @@ public void test003validatemultisign() { Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals(1, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - // Trigger with Duplicate signatures and weight not enough + // Trigger with Duplicate signatures and weight not enough signatures.clear(); signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey004.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey004.sign(tosign).toByteArray())); - parameters = Arrays.asList(WalletClient.encode58Check(ownerAddress), - permissionId, "0x" + Hex.toHexString(hash), signatures); + parameters = + Arrays.asList( + WalletClient.encode58Check(ownerAddress), + permissionId, + "0x" + Hex.toHexString(hash), + signatures); input = PublicMethod.parametersString(parameters); - TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, input, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + input, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("infoById" + infoById); Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - // Trigger with Duplicate signatures and fix signatures + // Trigger with Duplicate signatures and fix signatures signatures.clear(); signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey004.sign(tosign).toByteArray())); @@ -288,46 +397,77 @@ public void test003validatemultisign() { signatures.add(Hex.toHexString(ecKey005.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey005.sign(tosign).toByteArray())); - parameters = Arrays.asList(WalletClient.encode58Check(ownerAddress), - permissionId, "0x" + Hex.toHexString(hash), signatures); + parameters = + Arrays.asList( + WalletClient.encode58Check(ownerAddress), + permissionId, + "0x" + Hex.toHexString(hash), + signatures); input = PublicMethod.parametersString(parameters); - TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, input, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + input, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("infoById" + infoById); Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - } - @Test(enabled = true, description = "Trigger validatemultisign with weight", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger validatemultisign with weight", + groups = {"contract", "daily"}) public void test004validatemultisign() { List signatures = new ArrayList<>(); - int permissionId = 2; + int permissionId = 2; ownerKeyString[0] = ownerKey; ownerKeyString[1] = manager1Key; - Transaction transaction = PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( - foundationAddress, 1L, ownerAddress, permissionId, ownerKey, blockingStubFull); + Transaction transaction = + PublicMethodForMultiSign.sendcoinWithPermissionIdNotSign( + foundationAddress, 1L, ownerAddress, permissionId, ownerKey, blockingStubFull); transaction = TransactionUtils.setTimestamp(transaction); - byte[] hash = Sha256Hash.of(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()).getBytes(); - byte[] merged = ByteUtil.merge(ownerAddress, ByteArray.fromInt(permissionId), hash); - byte[] tosign = Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), merged); - // signatures with weight not enough + byte[] hash = + Sha256Hash.of( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()) + .getBytes(); + byte[] merged = ByteUtil.merge(ownerAddress, ByteArray.fromInt(permissionId), hash); + byte[] tosign = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), merged); + // signatures with weight not enough signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey004.sign(tosign).toByteArray())); - List parameters = Arrays.asList(WalletClient.encode58Check(ownerAddress), - permissionId, "0x" + Hex.toHexString(hash), signatures); - String input = PublicMethod.parametersString(parameters); - String methodStr = "testmulti(address,uint256,bytes32,bytes[])"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, input, false, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + List parameters = + Arrays.asList( + WalletClient.encode58Check(ownerAddress), + permissionId, + "0x" + Hex.toHexString(hash), + signatures); + String input = PublicMethod.parametersString(parameters); + String methodStr = "testmulti(address,uint256,bytes32,bytes[])"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + input, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -336,8 +476,5 @@ public void test004validatemultisign() { Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - } - - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/validatemultisign/TestValidatemultisign003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/validatemultisign/TestValidatemultisign003.java index a8f2f006..8aa15139 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/validatemultisign/TestValidatemultisign003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/validatemultisign/TestValidatemultisign003.java @@ -23,12 +23,12 @@ import stest.tron.wallet.common.client.utils.ByteUtil; import stest.tron.wallet.common.client.utils.CommonParameter; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; import stest.tron.wallet.common.client.utils.Sha256Hash; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode @@ -47,53 +47,74 @@ public class TestValidatemultisign003 extends TronBaseTest { ECKey ecKey003 = new ECKey(Utils.getRandom()); byte[] ownerAddress = ecKey003.getAddress(); String ownerKey = ByteArray.toHexString(ecKey003.getPrivKeyBytes()); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); private byte[] contractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); } - @Test(enabled = true, description = "Deploy validatemultisign contract", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy validatemultisign contract", + groups = {"contract", "daily"}) public void test001DeployContract() { - Assert.assertTrue(PublicMethod.sendcoin(dev001Address, 1000_000_000L, foundationAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(foundationAddress, 100_000_000L + PublicMethod.randomFreezeAmount.addAndGet(1), - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 1000_000_000L, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 100_000_000L + PublicMethod.randomFreezeAmount.addAndGet(1), + 0, + 0, + ByteString.copyFrom(dev001Address), + testKey002, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(dev001Key, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = accountResource.getEnergyUsed(); - Long beforeNetUsed = accountResource.getNetUsed(); - Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = accountResource.getEnergyUsed(); + Long beforeNetUsed = accountResource.getNetUsed(); + Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String filePath = "./src/test/resources/soliditycode/validatemultisign001.sol"; - String contractName = "validatemultisignTest"; + String filePath = "./src/test/resources/soliditycode/validatemultisign001.sol"; + String contractName = "validatemultisignTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -101,18 +122,17 @@ public void test001DeployContract() { infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); PublicMethod.printAddress(ownerKey); long needCoin = updateAccountPermissionFee * 1 + multiSignFee * 3; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, needCoin + 2048000000L, foundationAddress, testKey002, - blockingStubFull)); + PublicMethod.sendcoin( + ownerAddress, needCoin + 2048000000L, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -121,51 +141,74 @@ public void test001DeployContract() { ownerKeyString[1] = manager1Key; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Trigger validatemultisign precompiled contract, " - + "with wrong hash bytes", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger validatemultisign precompiled contract, " + "with wrong hash bytes", + groups = {"contract", "daily"}) public void test002validatemultisign() { List signatures = new ArrayList<>(); ownerKeyString[0] = ownerKey; ownerKeyString[1] = manager1Key; - Transaction transaction = PublicMethodForMultiSign.sendcoinGetTransaction( - foundationAddress, 1L, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); - byte[] hash = Sha256Hash.of(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()).getBytes(); - byte[] merged = ByteUtil.merge(ownerAddress, ByteArray.fromInt(0), hash); - byte[] tosign = Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), merged); + Transaction transaction = + PublicMethodForMultiSign.sendcoinGetTransaction( + foundationAddress, 1L, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); + byte[] hash = + Sha256Hash.of( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()) + .getBytes(); + byte[] merged = ByteUtil.merge(ownerAddress, ByteArray.fromInt(0), hash); + byte[] tosign = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), merged); signatures.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray())); - List parameters = Arrays.asList(WalletClient.encode58Check(ownerAddress), - 0, "0x" + Hex.toHexString(hash), signatures); - String argsStr = PublicMethod.parametersString(parameters); - byte[] inputBytesArray = Hex.decode(AbiUtil.parseMethod( - "validatemultisign(address,uint256,bytes32,bytes[])", argsStr, false)); - String input = ByteArray.toHexString(inputBytesArray); - String methodStr = "testMultiPrecompileContract(bytes)"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, - AbiUtil.parseParameters(methodStr, Arrays.asList(input)), true, - 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + List parameters = + Arrays.asList( + WalletClient.encode58Check(ownerAddress), 0, "0x" + Hex.toHexString(hash), signatures); + String argsStr = PublicMethod.parametersString(parameters); + byte[] inputBytesArray = + Hex.decode( + AbiUtil.parseMethod( + "validatemultisign(address,uint256,bytes32,bytes[])", argsStr, false)); + String input = ByteArray.toHexString(inputBytesArray); + String methodStr = "testMultiPrecompileContract(bytes)"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + AbiUtil.parseParameters(methodStr, Arrays.asList(input)), + true, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -175,34 +218,48 @@ public void test002validatemultisign() { Assert.assertEquals(1, infoById.get().getResultValue()); } - @Test(enabled = true, description = "Trigger validatemultisign precompiled contract, " - + "with correct hash bytes", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Trigger validatemultisign precompiled contract, " + "with correct hash bytes", + groups = {"contract", "daily"}) public void test003validatemultisign() { List signatures = new ArrayList<>(); ownerKeyString[0] = ownerKey; ownerKeyString[1] = manager1Key; - Transaction transaction = PublicMethodForMultiSign.sendcoinGetTransaction( - foundationAddress, 1L, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); - byte[] hash = Sha256Hash.of(CommonParameter.getInstance() - .isECKeyCryptoEngine(), transaction.getRawData().toByteArray()).getBytes(); - byte[] merged = ByteUtil.merge(ownerAddress, ByteArray.fromInt(0), hash); - byte[] tosign = Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), merged); + Transaction transaction = + PublicMethodForMultiSign.sendcoinGetTransaction( + foundationAddress, 1L, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); + byte[] hash = + Sha256Hash.of( + CommonParameter.getInstance().isECKeyCryptoEngine(), + transaction.getRawData().toByteArray()) + .getBytes(); + byte[] merged = ByteUtil.merge(ownerAddress, ByteArray.fromInt(0), hash); + byte[] tosign = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), merged); signatures.add(Hex.toHexString(ecKey003.sign(tosign).toByteArray())); signatures.add(Hex.toHexString(ecKey001.sign(tosign).toByteArray())); - List parameters = Arrays.asList(WalletClient.encode58Check(ownerAddress), - 0, "0x" + Hex.toHexString(hash), signatures); - String argsStr = PublicMethod.parametersString(parameters); - String input = AbiUtil.parseParameters( - "validatemultisign(address,uint256,bytes32,bytes[])", argsStr); - String methodStr = "testMultiPrecompileContract(bytes)"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methodStr, - AbiUtil.parseParameters(methodStr, Arrays.asList(input)), true, - 0, 100000000, dev001Address, dev001Key, blockingStubFull); + List parameters = + Arrays.asList( + WalletClient.encode58Check(ownerAddress), 0, "0x" + Hex.toHexString(hash), signatures); + String argsStr = PublicMethod.parametersString(parameters); + String input = + AbiUtil.parseParameters("validatemultisign(address,uint256,bytes32,bytes[])", argsStr); + String methodStr = "testMultiPrecompileContract(bytes)"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methodStr, + AbiUtil.parseParameters(methodStr, Arrays.asList(input)), + true, + 0, + 100000000, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -210,7 +267,5 @@ public void test003validatemultisign() { logger.info("infoById" + infoById); Assert.assertEquals(1, infoById.get().getResultValue()); - } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/zenProofCommand/PedersenHash001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/zenProofCommand/PedersenHash001.java index c5ac7ba5..1bab9b0d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/zenProofCommand/PedersenHash001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/zenProofCommand/PedersenHash001.java @@ -15,17 +15,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class PedersenHash001 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; String txid; @@ -34,112 +34,172 @@ public class PedersenHash001 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - txid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 10000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); + txid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/pedersenHash001.sol"; - String contractName = "pedersenHashTest"; + String filePath = "src/test/resources/soliditycode/pedersenHash001.sol"; + String contractName = "pedersenHashTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "data is empty", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "data is empty", + groups = {"contract", "daily"}) public void test01DataIsEmpty() { String method = "test1()"; - txid = PublicMethod - .triggerContract(contractAddress, method, "", false, 0, maxFeeLimit, contractExcAddress, - contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + method, + "", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals("SUCESS", infoById.get().getResult().toString()); - byte[] result = infoById.get().getContractResult(0).toByteArray(); - String boolResult = ByteArray.toHexString(ByteArray.subArray(result, 0, 32)); + byte[] result = infoById.get().getContractResult(0).toByteArray(); + String boolResult = ByteArray.toHexString(ByteArray.subArray(result, 0, 32)); System.out.println("boolResult: " + boolResult); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", - boolResult); - + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000000", boolResult); } - @Test(enabled = true, description = "data length limit", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "data length limit", + groups = {"contract", "daily"}) public void test02DataLengthLimit() { String method = "test2(bytes)"; - // length:64 - String argsStr1 = "\"0000000000000000000000000000000000000000000000000000000000000001" - + "0000000000000000000000000000000000000000000000000000000000000002\""; + // length:64 + String argsStr1 = + "\"0000000000000000000000000000000000000000000000000000000000000001" + + "0000000000000000000000000000000000000000000000000000000000000002\""; Optional infoById = null; - txid = PublicMethod.triggerContract(contractAddress, method, argsStr1, false, 0, maxFeeLimit, - contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + method, + argsStr1, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertEquals("SUCESS", infoById.get().getResult().toString()); - int boolResult = ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); + int boolResult = ByteArray.toInt(infoById.get().getContractResult(0).toByteArray()); Assert.assertFalse(Boolean.valueOf(String.valueOf(boolResult))); Assert.assertTrue(maxFeeLimit > infoById.get().getFee()); - // length:128 - String argsStr2 = "\"0000000000000000000000000000000000000000000000000000000000000001" - + "0000000000000000000000000000000000000000000000000000000000000001" - + "0000000000000000000000000000000000000000000000000000000000000002" - + "0000000000000000000000000000000000000000000000000000000000000002\""; - txid = PublicMethod.triggerContract(contractAddress, method, argsStr2, false, 0, maxFeeLimit, - contractExcAddress, contractExcKey, blockingStubFull); + // length:128 + String argsStr2 = + "\"0000000000000000000000000000000000000000000000000000000000000001" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "0000000000000000000000000000000000000000000000000000000000000002" + + "0000000000000000000000000000000000000000000000000000000000000002\""; + txid = + PublicMethod.triggerContract( + contractAddress, + method, + argsStr2, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000001" + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000040" + "0000000000000000000000000000000000000000000000000000000000000020" + "7d6b910840eb7b47f76492aca4a3344888b8fa5aab77a49e9445cda718d75040", ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "normal", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "normal", + groups = {"contract", "daily"}) public void test02Normal() { String method = "test3(uint32,bytes32,bytes32)"; - String argsStr1 = "0000000000000000000000000000000000000000000000000000000000000001" - + "0000000000000000000000000000000000000000000000000000000000000001" - + "0000000000000000000000000000000000000000000000000000000000000002"; + String argsStr1 = + "0000000000000000000000000000000000000000000000000000000000000001" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "0000000000000000000000000000000000000000000000000000000000000002"; Optional infoById = null; - txid = PublicMethod.triggerContract(contractAddress, method, argsStr1, true, 0, maxFeeLimit, - contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + method, + argsStr1, + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); - Assert.assertEquals("7d6b910840eb7b47f76492aca4a3344888b8fa5aab77a49e9445cda718d75040", + Assert.assertEquals( + "7d6b910840eb7b47f76492aca4a3344888b8fa5aab77a49e9445cda718d75040", ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); } @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(contractExcKey, blockingStubFull).getBalance(); - PublicMethod - .sendcoin(testNetAccountAddress, balance - 1000000, contractExcAddress, contractExcKey, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.sendcoin( + testNetAccountAddress, + balance - 1000000, + contractExcAddress, + contractExcKey, + blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/zenProofCommand/PedersenHash002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/zenProofCommand/PedersenHash002.java index 834f0bb7..57791258 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/zenProofCommand/PedersenHash002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/zenProofCommand/PedersenHash002.java @@ -34,20 +34,20 @@ import stest.tron.wallet.common.client.utils.HttpMethod; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.ShieldedAddressInfo; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.exception.ZksnarkException; import stest.tron.wallet.common.client.utils.zen.address.DiversifierT; @Slf4j public class PedersenHash002 extends TronBaseTest { - public static final String zenTrc20TokenOwnerKey = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTrc20TokenOwnerKey"); - public static final byte[] zenTrc20TokenOwnerAddress = PublicMethod - .getFinalAddress(zenTrc20TokenOwnerKey); - public static final String zenTrc20TokenOwnerAddressString = PublicMethod - .getAddressString(zenTrc20TokenOwnerKey); + public static final String zenTrc20TokenOwnerKey = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTrc20TokenOwnerKey"); + public static final byte[] zenTrc20TokenOwnerAddress = + PublicMethod.getFinalAddress(zenTrc20TokenOwnerKey); + public static final String zenTrc20TokenOwnerAddressString = + PublicMethod.getAddressString(zenTrc20TokenOwnerKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -70,35 +70,48 @@ public class PedersenHash002 extends TronBaseTest { public static Integer scalingFactorLogarithm = 0; public static Long totalSupply = 1000000000000L; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true, description = "Deploy shield trc20 depend contract") - public void deployShieldTrc20DependContract() { Assert.assertTrue(PublicMethod.sendcoin(contractExcAddress, 10000000000000L, - foundationAddress, foundationKey, blockingStubFull)); + public void deployShieldTrc20DependContract() { + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 10000000000000L, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String contractName = "shieldTrc20Token"; - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_shieldTrc20Token"); - String code = Configuration.getByPath("testng.conf") - .getString("code.code_shieldTrc20Token"); - String constructorStr = "constructor(uint256,string,string)"; - String data = totalSupply.toString() + "," + "\"TokenTRC20\"" + "," + "\"zen20\""; + String contractName = "shieldTrc20Token"; + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_shieldTrc20Token"); + String code = Configuration.getByPath("testng.conf").getString("code.code_shieldTrc20Token"); + String constructorStr = "constructor(uint256,string,string)"; + String data = totalSupply.toString() + "," + "\"TokenTRC20\"" + "," + "\"zen20\""; logger.info("data:" + data); - deployShieldTrc20Txid = PublicMethod - .deployContractWithConstantParame(contractName, abi, code, constructorStr, data, "", - maxFeeLimit, 0L, 100, null, - contractExcKey, contractExcAddress, blockingStubFull); + deployShieldTrc20Txid = + PublicMethod.deployContractWithConstantParame( + contractName, + abi, + code, + constructorStr, + data, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info(deployShieldTrc20Txid); - Optional infoById = PublicMethod - .getTransactionInfoById(deployShieldTrc20Txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(deployShieldTrc20Txid, blockingStubFull); contractAddressByteString = infoById.get().getContractAddress(); contractAddressByte = infoById.get().getContractAddress().toByteArray(); contractAddress = Base58.encode58Check(contractAddressByte); logger.info(contractAddress); - String filePath = "src/test/resources/soliditycode/pedersenHash002.sol"; + String filePath = "src/test/resources/soliditycode/pedersenHash002.sol"; contractName = "ShieldedTRC20"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); @@ -106,10 +119,21 @@ public void deployShieldTrc20DependContract() { Assert.assertTrue(PublicMetho abi = retMap.get("abI").toString(); data = "\"" + contractAddress + "\"" + "," + scalingFactorLogarithm; constructorStr = "constructor(address,uint256)"; - deployShieldTxid = PublicMethod - .deployContractWithConstantParame(contractName, abi, code, constructorStr, data, "", - maxFeeLimit, 0L, 100, null, - contractExcKey, contractExcAddress, blockingStubFull); + deployShieldTxid = + PublicMethod.deployContractWithConstantParame( + contractName, + abi, + code, + constructorStr, + data, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info(deployShieldTxid); infoById = PublicMethod.getTransactionInfoById(deployShieldTxid, blockingStubFull); @@ -119,74 +143,107 @@ public void deployShieldTrc20DependContract() { Assert.assertTrue(PublicMetho logger.info(shieldAddress); data = "\"" + shieldAddress + "\"" + "," + totalSupply.toString(); - String txid = PublicMethod.triggerContract(contractAddressByte, - "approve(address,uint256)", data, false, - 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + contractAddressByte, + "approve(address,uint256)", + data, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("approve:" + txid); Assert.assertTrue(infoById.get().getReceipt().getResultValue() == 1); publicFromAmount = getRandomAmount(); } - - @Test(enabled = true, description = "left and right value is 0", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "left and right value is 0", + groups = {"contract", "daily"}) public void test01LeftAndRightValueIsZero() throws Exception { - //Query account before mint balance -// final Long beforeMintAccountBalance = getBalanceOfShieldTrc20(zenTrc20TokenOwnerAddressString, -// zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); - //Query contract before mint balance -// final Long beforeMintShieldAccountBalance = getBalanceOfShieldTrc20(shieldAddress, -// zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); - //Generate new shiled account and set note memo + // Query account before mint balance + // final Long beforeMintAccountBalance = + // getBalanceOfShieldTrc20(zenTrc20TokenOwnerAddressString, + // zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); + // Query contract before mint balance + // final Long beforeMintShieldAccountBalance = getBalanceOfShieldTrc20(shieldAddress, + // zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); + // Generate new shiled account and set note memo receiverShieldAddressInfo = getNewShieldedAddress(blockingStubFull); - String memo = "Shield trc20 from T account to shield account in" + System.currentTimeMillis(); - String receiverShieldAddress = receiverShieldAddressInfo.get().getAddress(); + String memo = "Shield trc20 from T account to shield account in" + System.currentTimeMillis(); + String receiverShieldAddress = receiverShieldAddressInfo.get().getAddress(); shieldOutList.clear(); - shieldOutList = addShieldTrc20OutputList(shieldOutList, receiverShieldAddress, - "" + publicFromAmount, memo, blockingStubFull); - //Create shiled trc20 parameters - GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters - = createShieldedTrc20Parameters("ByValueIsZero", publicFromAmount, - null, null, shieldOutList, "", 0L, - blockingStubFull, blockingStubSolidity); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, receiverShieldAddress, "" + publicFromAmount, memo, blockingStubFull); + // Create shiled trc20 parameters + GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters = + createShieldedTrc20Parameters( + "ByValueIsZero", + publicFromAmount, + null, + null, + shieldOutList, + "", + 0L, + blockingStubFull, + blockingStubSolidity); Assert.assertEquals(shieldedTrc20Parameters.getParameterType(), "mint"); - Assert.assertTrue(shieldedTrc20Parameters.getReceiveDescription(0).getZkproof().toByteArray().length > 190); + Assert.assertTrue( + shieldedTrc20Parameters.getReceiveDescription(0).getZkproof().toByteArray().length > 190); } - - @Test(enabled = true, description = "Should not cause exception: CreateShieldedContractParameters in fullnode ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Should not cause exception: CreateShieldedContractParameters in fullnode ", + groups = {"contract", "daily"}) public void test02TriggerUnexistMethod() throws Exception { - //Generate new shiled account and set note memo + // Generate new shiled account and set note memo receiverShieldAddressInfo = getNewShieldedAddress(blockingStubFull); - String memo = "Shield trc20 from T account to shield account in" + System.currentTimeMillis(); - String receiverShieldAddress = receiverShieldAddressInfo.get().getAddress(); + String memo = "Shield trc20 from T account to shield account in" + System.currentTimeMillis(); + String receiverShieldAddress = receiverShieldAddressInfo.get().getAddress(); shieldOutList.clear(); - shieldOutList = addShieldTrc20OutputList(shieldOutList, receiverShieldAddress, - "" + publicFromAmount, memo, blockingStubFull); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, receiverShieldAddress, "" + publicFromAmount, memo, blockingStubFull); shieldAddressByte = contractAddressByte; - // verify error(for log level changed from info to error) - //ERROR [rpc-full-executor-1] [API](RpcApiService.java:2484) createShieldedContractParameters: - createShieldedTrc20Parameters("ByValueIsZero", publicFromAmount, - null, null, shieldOutList, "", 0L, - blockingStubFull, blockingStubSolidity); + // verify error(for log level changed from info to error) + // ERROR [rpc-full-executor-1] [API](RpcApiService.java:2484) createShieldedContractParameters: + createShieldedTrc20Parameters( + "ByValueIsZero", + publicFromAmount, + null, + null, + shieldOutList, + "", + 0L, + blockingStubFull, + blockingStubSolidity); } - /** - * constructor. - */ - public GrpcAPI.ShieldedTRC20Parameters createShieldedTrc20Parameters(String methodSuffix, - BigInteger publicFromAmount, GrpcAPI.DecryptNotesTRC20 inputNoteList, - List shieldedAddressInfoList, List outputNoteList, - String publicToAddress, Long pubicToAmount, WalletGrpc.WalletBlockingStub blockingStubFull, - WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity) throws ZksnarkException { - - GrpcAPI.PrivateShieldedTRC20Parameters.Builder builder - = GrpcAPI.PrivateShieldedTRC20Parameters.newBuilder(); - //Mint type should set public from amount to parameter + /** constructor. */ + public GrpcAPI.ShieldedTRC20Parameters createShieldedTrc20Parameters( + String methodSuffix, + BigInteger publicFromAmount, + GrpcAPI.DecryptNotesTRC20 inputNoteList, + List shieldedAddressInfoList, + List outputNoteList, + String publicToAddress, + Long pubicToAmount, + WalletGrpc.WalletBlockingStub blockingStubFull, + WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity) + throws ZksnarkException { + + GrpcAPI.PrivateShieldedTRC20Parameters.Builder builder = + GrpcAPI.PrivateShieldedTRC20Parameters.newBuilder(); + // Mint type should set public from amount to parameter if (publicFromAmount.compareTo(BigInteger.ZERO) > 0) { builder.setFromAmount(publicFromAmount.toString()); } @@ -215,12 +272,14 @@ public GrpcAPI.ShieldedTRC20Parameters createShieldedTrc20Parameters(String meth for (int i = 0; i < inputNoteList.getNoteTxsCount(); ++i) { if (i == 0) { String shieldedAddress = inputNoteList.getNoteTxs(i).getNote().getPaymentAddress(); - String spendingKey = ByteArray.toHexString(shieldedAddressInfoList.get(0).getSk()); - BytesMessage sk = BytesMessage.newBuilder() - .setValue(ByteString.copyFrom(ByteArray.fromHexString(spendingKey))).build(); - Optional esk = Optional - .of(blockingStubFull.getExpandedSpendingKey(sk)); - //ExpandedSpendingKey expandedSpendingKey = spendingKey.expandedSpendingKey(); + String spendingKey = ByteArray.toHexString(shieldedAddressInfoList.get(0).getSk()); + BytesMessage sk = + BytesMessage.newBuilder() + .setValue(ByteString.copyFrom(ByteArray.fromHexString(spendingKey))) + .build(); + Optional esk = + Optional.of(blockingStubFull.getExpandedSpendingKey(sk)); + // ExpandedSpendingKey expandedSpendingKey = spendingKey.expandedSpendingKey(); builder.setAsk(esk.get().getAsk()); builder.setNsk(esk.get().getNsk()); builder.setOvk(esk.get().getOvk()); @@ -230,23 +289,27 @@ public GrpcAPI.ShieldedTRC20Parameters createShieldedTrc20Parameters(String meth noteBuild.setValue(inputNoteList.getNoteTxs(i).getNote().getValue()); noteBuild.setRcm(inputNoteList.getNoteTxs(i).getNote().getRcm()); noteBuild.setMemo(inputNoteList.getNoteTxs(i).getNote().getMemo()); - byte[] eachRootAndPath = ByteArray.fromHexString(rootAndPath.get(i)); - byte[] root = Arrays.copyOfRange(eachRootAndPath, 0, 32); - byte[] path = Arrays.copyOfRange(eachRootAndPath, 32, 1056); + byte[] eachRootAndPath = ByteArray.fromHexString(rootAndPath.get(i)); + byte[] root = Arrays.copyOfRange(eachRootAndPath, 0, 32); + byte[] path = Arrays.copyOfRange(eachRootAndPath, 32, 1056); GrpcAPI.SpendNoteTRC20.Builder spendTRC20NoteBuilder = GrpcAPI.SpendNoteTRC20.newBuilder(); spendTRC20NoteBuilder.setNote(noteBuild.build()); - spendTRC20NoteBuilder.setAlpha(ByteString.copyFrom(blockingStubFull.getRcm( - EmptyMessage.newBuilder().build()).getValue().toByteArray())); + spendTRC20NoteBuilder.setAlpha( + ByteString.copyFrom( + blockingStubFull + .getRcm(EmptyMessage.newBuilder().build()) + .getValue() + .toByteArray())); spendTRC20NoteBuilder.setRoot(ByteString.copyFrom(root)); spendTRC20NoteBuilder.setPath(ByteString.copyFrom(path)); spendTRC20NoteBuilder.setPos(inputNoteList.getNoteTxs(i).getPosition()); - valueBalance = Math - .addExact(valueBalance, inputNoteList.getNoteTxs(i).getNote().getValue()); + valueBalance = + Math.addExact(valueBalance, inputNoteList.getNoteTxs(i).getNote().getValue()); builder.addShieldedSpends(spendTRC20NoteBuilder.build()); } } else { - //@TODO remove randomOvk by sha256.of(privateKey) + // @TODO remove randomOvk by sha256.of(privateKey) byte[] ovk = getRandomOvk(); if (ovk != null) { builder.setOvk(ByteString.copyFrom(ovk)); @@ -260,8 +323,7 @@ public GrpcAPI.ShieldedTRC20Parameters createShieldedTrc20Parameters(String meth for (int i = 0; i < outputNoteList.size(); i++) { Note note = outputNoteList.get(i); valueBalance = Math.subtractExact(valueBalance, note.getValue()); - builder.addShieldedReceives( - GrpcAPI.ReceiveNote.newBuilder().setNote(note).build()); + builder.addShieldedReceives(GrpcAPI.ReceiveNote.newBuilder().setNote(note).build()); } } @@ -278,30 +340,38 @@ public GrpcAPI.ShieldedTRC20Parameters createShieldedTrc20Parameters(String meth return blockingStubFull.createShieldedContractParameters(builder.build()); } catch (Exception e) { Status status = Status.fromThrowable(e); - System.out.println("createShieldedContractParameters failed,error " - + status.getDescription()); + System.out.println( + "createShieldedContractParameters failed,error " + status.getDescription()); } return null; } - public String getRootAndPath(String methodSuffix, long position, - WalletSolidityGrpc.WalletSolidityBlockingStub - blockingStubSolidity) { + public String getRootAndPath( + String methodSuffix, + long position, + WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity) { String methodStr = "getPath" + methodSuffix + "(uint256)"; - byte[] indexBytes = ByteArray.fromLong(position); - String argsStr = ByteArray.toHexString(indexBytes); + byte[] indexBytes = ByteArray.fromLong(position); + String argsStr = ByteArray.toHexString(indexBytes); argsStr = "000000000000000000000000000000000000000000000000" + argsStr; - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtentionOnSolidity(shieldAddressByte, methodStr, argsStr, true, - 0, 1000000000L, "0", 0, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubSolidity); - byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtentionOnSolidity( + shieldAddressByte, + methodStr, + argsStr, + true, + 0, + 1000000000L, + "0", + 0, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubSolidity); + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); return ByteArray.toHexString(result); } - /** - * constructor. - */ + /** constructor. */ public static HttpResponse getNewShieldedAddress(String httpNode) { try { String requestUrl = "http://" + httpNode + "/wallet/getnewshieldedaddress"; @@ -314,22 +384,19 @@ public static HttpResponse getNewShieldedAddress(String httpNode) { return response; } - /** - * constructor. - */ - public Optional getNewShieldedAddress(WalletGrpc.WalletBlockingStub - blockingStubFull) { + /** constructor. */ + public Optional getNewShieldedAddress( + WalletGrpc.WalletBlockingStub blockingStubFull) { ShieldedAddressInfo addressInfo = new ShieldedAddressInfo(); try { - Optional sk = Optional.of(blockingStubFull - .getSpendingKey(EmptyMessage.newBuilder().build())); - final Optional d = Optional.of(blockingStubFull.getDiversifier( - EmptyMessage.newBuilder().build())); + Optional sk = + Optional.of(blockingStubFull.getSpendingKey(EmptyMessage.newBuilder().build())); + final Optional d = + Optional.of(blockingStubFull.getDiversifier(EmptyMessage.newBuilder().build())); - Optional expandedSpendingKeyMessage - = Optional.of(blockingStubFull - .getExpandedSpendingKey(sk.get())); + Optional expandedSpendingKeyMessage = + Optional.of(blockingStubFull.getExpandedSpendingKey(sk.get())); BytesMessage.Builder askBuilder = BytesMessage.newBuilder(); askBuilder.setValue(expandedSpendingKeyMessage.get().getAsk()); @@ -342,16 +409,15 @@ public Optional getNewShieldedAddress(WalletGrpc.WalletBloc GrpcAPI.ViewingKeyMessage.Builder viewBuilder = GrpcAPI.ViewingKeyMessage.newBuilder(); viewBuilder.setAk(ak.get().getValue()); viewBuilder.setNk(nk.get().getValue()); - Optional ivk = Optional.of(blockingStubFull - .getIncomingViewingKey(viewBuilder.build())); + Optional ivk = + Optional.of(blockingStubFull.getIncomingViewingKey(viewBuilder.build())); - GrpcAPI.IncomingViewingKeyDiversifierMessage.Builder builder - = GrpcAPI.IncomingViewingKeyDiversifierMessage - .newBuilder(); + GrpcAPI.IncomingViewingKeyDiversifierMessage.Builder builder = + GrpcAPI.IncomingViewingKeyDiversifierMessage.newBuilder(); builder.setD(d.get()); builder.setIvk(ivk.get()); - Optional addressMessage = Optional.of(blockingStubFull - .getZenPaymentAddress(builder.build())); + Optional addressMessage = + Optional.of(blockingStubFull.getZenPaymentAddress(builder.build())); addressInfo.setSk(sk.get().getValue().toByteArray()); addressInfo.setD(new DiversifierT(d.get().getD().toByteArray())); addressInfo.setIvk(ivk.get().getIvk().toByteArray()); @@ -367,14 +433,15 @@ public Optional getNewShieldedAddress(WalletGrpc.WalletBloc return Optional.empty(); } - /** - * constructor. - */ - public static List addShieldTrc20OutputList(List shieldOutList, - String shieldToAddress, String toAmountString, String menoString, + /** constructor. */ + public static List addShieldTrc20OutputList( + List shieldOutList, + String shieldToAddress, + String toAmountString, + String menoString, WalletGrpc.WalletBlockingStub blockingStubFull) { String shieldAddress = shieldToAddress; - String amountString = toAmountString; + String amountString = toAmountString; if (menoString.equals("null")) { menoString = ""; } @@ -385,27 +452,37 @@ public static List addShieldTrc20OutputList(List shieldOutList, Note.Builder noteBuild = Note.newBuilder(); noteBuild.setPaymentAddress(shieldAddress); - //noteBuild.setPaymentAddress(shieldAddress); + // noteBuild.setPaymentAddress(shieldAddress); noteBuild.setValue(shieldAmount); - noteBuild.setRcm(ByteString.copyFrom(blockingStubFull.getRcm(EmptyMessage.newBuilder().build()) - .getValue().toByteArray())); + noteBuild.setRcm( + ByteString.copyFrom( + blockingStubFull.getRcm(EmptyMessage.newBuilder().build()).getValue().toByteArray())); noteBuild.setMemo(ByteString.copyFrom(menoString.getBytes())); shieldOutList.add(noteBuild.build()); return shieldOutList; } - /** - * constructor. - */ - public Long getBalanceOfShieldTrc20(String queryAddress, byte[] ownerAddress, - String ownerKey, WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public Long getBalanceOfShieldTrc20( + String queryAddress, + byte[] ownerAddress, + String ownerKey, + WalletGrpc.WalletBlockingStub blockingStubFull) { String paramStr = "\"" + queryAddress + "\""; - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(contractAddressByte, "balanceOf(address)", - paramStr, false, 0, 0, "0", 0, - ownerAddress, ownerKey, blockingStubFull); - String hexBalance = Hex.toHexString(transactionExtention - .getConstantResult(0).toByteArray()); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + contractAddressByte, + "balanceOf(address)", + paramStr, + false, + 0, + 0, + "0", + 0, + ownerAddress, + ownerKey, + blockingStubFull); + String hexBalance = Hex.toHexString(transactionExtention.getConstantResult(0).toByteArray()); for (int i = 0; i < hexBalance.length(); i++) { if (hexBalance.charAt(i) != '0') { hexBalance = hexBalance.substring(i); @@ -416,16 +493,13 @@ public Long getBalanceOfShieldTrc20(String queryAddress, byte[] ownerAddress, return Long.parseLong(hexBalance, 16); } - /** - * constructor. - */ + /** constructor. */ public byte[] getRandomOvk() { try { - Optional sk = Optional.of(blockingStubFull - .getSpendingKey(EmptyMessage.newBuilder().build())); - Optional expandedSpendingKeyMessage - = Optional.of(blockingStubFull - .getExpandedSpendingKey(sk.get())); + Optional sk = + Optional.of(blockingStubFull.getSpendingKey(EmptyMessage.newBuilder().build())); + Optional expandedSpendingKeyMessage = + Optional.of(blockingStubFull.getExpandedSpendingKey(sk.get())); return expandedSpendingKeyMessage.get().getOvk().toByteArray(); } catch (Exception e) { e.printStackTrace(); @@ -433,25 +507,20 @@ public byte[] getRandomOvk() { return null; } - /** - * constructor. - */ + /** constructor. */ public BigInteger getRandomAmount() { Random random = new Random(); - int x = random.nextInt(100000) + 100; + int x = random.nextInt(100000) + 100; return BigInteger.valueOf(x); } public byte[] longTo32Bytes(long value) { byte[] longBytes = ByteArray.fromLong(value); - byte[] zeroBytes = new byte[24]; + byte[] zeroBytes = new byte[24]; return ByteUtil.merge(zeroBytes, longBytes); } - - /** - * constructor. - */ + /** constructor. */ public static String getRcm(String httpNode) { try { String requestUrl = "http://" + httpNode + "/wallet/getrcm"; @@ -463,5 +532,4 @@ public static String getRcm(String httpNode) { } return HttpMethod.parseResponseContent(response).getString("value"); } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/zenProofCommand/VerifyBurnProof001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/zenProofCommand/VerifyBurnProof001.java index c47f5552..e4d978d3 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/zenProofCommand/VerifyBurnProof001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/zenProofCommand/VerifyBurnProof001.java @@ -10,12 +10,11 @@ import org.tron.protos.Protocol; import org.tron.protos.Protocol.TransactionInfo; import org.tron.protos.contract.SmartContractOuterClass.SmartContract; -import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class VerifyBurnProof001 extends TronBaseTest { @@ -25,41 +24,55 @@ public class VerifyBurnProof001 extends TronBaseTest { private byte[] testAddress001 = ecKey1.getAddress(); private String testPriKey001 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(testPriKey001); - Assert.assertTrue(PublicMethod.sendcoin(testAddress001, 1000_000_000L, foundationAddress, - foundationKey, blockingStubFull)); + public void beforeClass() { + PublicMethod.printAddress(testPriKey001); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress001, 1000_000_000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Deploy VerfyMintProof contract ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy VerfyMintProof contract ", + groups = {"contract", "daily"}) public void verifyBurnProof001() { - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(testAddress001, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(testAddress001, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(testPriKey001, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = accountResource.getEnergyUsed(); - Long beforeNetUsed = accountResource.getNetUsed(); - Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = accountResource.getEnergyUsed(); + Long beforeNetUsed = accountResource.getNetUsed(); + Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String filePath = "./src/test/resources/soliditycode/VerifyBurnProof001.sol"; - String contractName = "VerifyBurnProof001Test"; + String filePath = "./src/test/resources/soliditycode/VerifyBurnProof001.sol"; + String contractName = "VerifyBurnProof001Test"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, testPriKey001, - testAddress001, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + testPriKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -69,222 +82,268 @@ public void verifyBurnProof001() { Assert.assertEquals(0, infoById.get().getResultValue()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - } - @Test(enabled = true, description = "data length != 512", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "data length != 512", + groups = {"contract", "daily"}) public void verifyBurnProofTest002() { - String argsStr = "\"" - + "c9cf924134dd8fbd11d3b245b00adf4797b48c42e001673e7c566ce229b8fdf6" - + "24097774778540c2c4d5acbeffe333e1f595a1b731cbe10848e3d3a527ba4d1b" - + "a079c66e70cae2225cd702a7c0977635755ad104a87f435634d4e5382ac2afc8" - + "1c47919273d4861ad815855ba1b4db5f90cc7e922b65c930c291eddc6d49a6c4" - + "90771325afc8e6e4a506f9dca0889dff75bcb4c46030702a33899b4d1e81122a" - + "a236433cf4c8ff426c66446de2f375b08575c4a18802e19a5fa5500922f7d570" - + "aac680208d05f9f2a9beaef0d9adede10e4a0242a3d1e048dd2a65034ef3f348" - + "0c108652d93da2ed13a0720fce9dce3a01a25cfa898bbaa8730f3fa8bba4b8a9" - + "7a609fd9f4d008a9334dea39acc838298c989ae0f31cbaa08e4b00342ba2c0b1" - + "ba37ac7be8084e0aeb01045f121e87e9cc942ecdc3b5e52933b79aad6f005d8e" - - + "dfc2aabf584106dfb2f6d3eb7f4584f5f2d9cba8340b0f73ba5fab4a4a024db2" - + "d00c5f0b3aba1f98cba6d1c9750591628daca165bac2de6fd694df833110ee01" - - + "0000000000000000000000000000000000000000000000000000000000000064" - - + "19389f87908cb5f1ede2a9fe0c3047d2ad5fce424d133bacb655ae1179a81084" - + "102ce5ad22d815a64374da9e2207d722b1c9a3099b292eaea0862edc886ff70d" - - + "b85285dd55258a2fbd04cc6ef365677b286d728f73db42c06ecc0a5822a6334a" - /// add more 32bytes - + "0000000000000000000000000000000000000000000000000000000000000064\""; - //argsStr = argsStr + "0000000000000000000000000000000000000000000000000000000000000064"; - String methedStr = "VerifyBurnProofSize002(bytes)"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, false, - 0, maxFeeLimit, testAddress001, testPriKey001, blockingStubFull); + String argsStr = + "\"" + + "c9cf924134dd8fbd11d3b245b00adf4797b48c42e001673e7c566ce229b8fdf6" + + "24097774778540c2c4d5acbeffe333e1f595a1b731cbe10848e3d3a527ba4d1b" + + "a079c66e70cae2225cd702a7c0977635755ad104a87f435634d4e5382ac2afc8" + + "1c47919273d4861ad815855ba1b4db5f90cc7e922b65c930c291eddc6d49a6c4" + + "90771325afc8e6e4a506f9dca0889dff75bcb4c46030702a33899b4d1e81122a" + + "a236433cf4c8ff426c66446de2f375b08575c4a18802e19a5fa5500922f7d570" + + "aac680208d05f9f2a9beaef0d9adede10e4a0242a3d1e048dd2a65034ef3f348" + + "0c108652d93da2ed13a0720fce9dce3a01a25cfa898bbaa8730f3fa8bba4b8a9" + + "7a609fd9f4d008a9334dea39acc838298c989ae0f31cbaa08e4b00342ba2c0b1" + + "ba37ac7be8084e0aeb01045f121e87e9cc942ecdc3b5e52933b79aad6f005d8e" + + "dfc2aabf584106dfb2f6d3eb7f4584f5f2d9cba8340b0f73ba5fab4a4a024db2" + + "d00c5f0b3aba1f98cba6d1c9750591628daca165bac2de6fd694df833110ee01" + + "0000000000000000000000000000000000000000000000000000000000000064" + + "19389f87908cb5f1ede2a9fe0c3047d2ad5fce424d133bacb655ae1179a81084" + + "102ce5ad22d815a64374da9e2207d722b1c9a3099b292eaea0862edc886ff70d" + + "b85285dd55258a2fbd04cc6ef365677b286d728f73db42c06ecc0a5822a6334a" + /// add more 32bytes + + "0000000000000000000000000000000000000000000000000000000000000064\""; + // argsStr = argsStr + "0000000000000000000000000000000000000000000000000000000000000064"; + String methedStr = "VerifyBurnProofSize002(bytes)"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testPriKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("TriggerTxid: " + TriggerTxid); - Optional infoById = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("infoById : " + infoById); Assert.assertEquals(0, infoById.get().getResultValue()); - String contractResult = ByteArray.toHexString( - infoById.get().getContractResult(0).toByteArray()); - - Assert.assertEquals("" - + "0000000000000000000000000000000000000000000000000000000000000001" // 1 : true - + "0000000000000000000000000000000000000000000000000000000000000040" - + "0000000000000000000000000000000000000000000000000000000000000020" - + "0000000000000000000000000000000000000000000000000000000000000000", contractResult); - - + String contractResult = + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); + + Assert.assertEquals( + "" + + "0000000000000000000000000000000000000000000000000000000000000001" // 1 : true + + "0000000000000000000000000000000000000000000000000000000000000040" + + "0000000000000000000000000000000000000000000000000000000000000020" + + "0000000000000000000000000000000000000000000000000000000000000000", + contractResult); } - @Test(enabled = true, description = "data is empty", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "data is empty", + groups = {"contract", "daily"}) public void verifyBurnProofTest003() { String methedStr = "VerifyBurnProofSize003()"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methedStr, "", false, - 0, maxFeeLimit, testAddress001, testPriKey001, blockingStubFull); + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + "", + false, + 0, + maxFeeLimit, + testAddress001, + testPriKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("TriggerTxid: " + TriggerTxid); - Optional infoById = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("infoById : " + infoById); Assert.assertEquals(0, infoById.get().getResultValue()); - String contractResult = ByteArray.toHexString( - infoById.get().getContractResult(0).toByteArray()); - - Assert.assertEquals("" - + "0000000000000000000000000000000000000000000000000000000000000001" // 1 : true - + "0000000000000000000000000000000000000000000000000000000000000040" - + "0000000000000000000000000000000000000000000000000000000000000020" - + "0000000000000000000000000000000000000000000000000000000000000000", contractResult); - - + String contractResult = + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); + + Assert.assertEquals( + "" + + "0000000000000000000000000000000000000000000000000000000000000001" // 1 : true + + "0000000000000000000000000000000000000000000000000000000000000040" + + "0000000000000000000000000000000000000000000000000000000000000020" + + "0000000000000000000000000000000000000000000000000000000000000000", + contractResult); } - @Test(enabled = true, description = "value greate than Long.MAX_VALUE", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "value greate than Long.MAX_VALUE", + groups = {"contract", "daily"}) public void verifyBurnProofTest004() { - //String methedStr = "VerifyBurnProofSize002(bytes)"; - String methedStr = "VerifyBurnProofSize001(bytes32[10],bytes32[2],uint64,bytes32[2],bytes32)"; - String argsStr = "" - + "c9cf924134dd8fbd11d3b245b00adf4797b48c42e001673e7c566ce229b8fdf6" - + "24097774778540c2c4d5acbeffe333e1f595a1b731cbe10848e3d3a527ba4d1b" - + "a079c66e70cae2225cd702a7c0977635755ad104a87f435634d4e5382ac2afc8" - + "1c47919273d4861ad815855ba1b4db5f90cc7e922b65c930c291eddc6d49a6c4" - + "90771325afc8e6e4a506f9dca0889dff75bcb4c46030702a33899b4d1e81122a" - + "a236433cf4c8ff426c66446de2f375b08575c4a18802e19a5fa5500922f7d570" - + "aac680208d05f9f2a9beaef0d9adede10e4a0242a3d1e048dd2a65034ef3f348" - + "0c108652d93da2ed13a0720fce9dce3a01a25cfa898bbaa8730f3fa8bba4b8a9" - + "7a609fd9f4d008a9334dea39acc838298c989ae0f31cbaa08e4b00342ba2c0b1" - + "ba37ac7be8084e0aeb01045f121e87e9cc942ecdc3b5e52933b79aad6f005d8e" - - + "dfc2aabf584106dfb2f6d3eb7f4584f5f2d9cba8340b0f73ba5fab4a4a024db2" - + "d00c5f0b3aba1f98cba6d1c9750591628daca165bac2de6fd694df833110ee01" - - + "0000000000000000000000000000000000000000000000000fffffffffffffff" - - + "19389f87908cb5f1ede2a9fe0c3047d2ad5fce424d133bacb655ae1179a81084" - + "102ce5ad22d815a64374da9e2207d722b1c9a3099b292eaea0862edc886ff70d" - - + "b85285dd55258a2fbd04cc6ef365677b286d728f73db42c06ecc0a5822a6334a"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, true, - 0, maxFeeLimit, testAddress001, testPriKey001, blockingStubFull); + // String methedStr = "VerifyBurnProofSize002(bytes)"; + String methedStr = "VerifyBurnProofSize001(bytes32[10],bytes32[2],uint64,bytes32[2],bytes32)"; + String argsStr = + "" + + "c9cf924134dd8fbd11d3b245b00adf4797b48c42e001673e7c566ce229b8fdf6" + + "24097774778540c2c4d5acbeffe333e1f595a1b731cbe10848e3d3a527ba4d1b" + + "a079c66e70cae2225cd702a7c0977635755ad104a87f435634d4e5382ac2afc8" + + "1c47919273d4861ad815855ba1b4db5f90cc7e922b65c930c291eddc6d49a6c4" + + "90771325afc8e6e4a506f9dca0889dff75bcb4c46030702a33899b4d1e81122a" + + "a236433cf4c8ff426c66446de2f375b08575c4a18802e19a5fa5500922f7d570" + + "aac680208d05f9f2a9beaef0d9adede10e4a0242a3d1e048dd2a65034ef3f348" + + "0c108652d93da2ed13a0720fce9dce3a01a25cfa898bbaa8730f3fa8bba4b8a9" + + "7a609fd9f4d008a9334dea39acc838298c989ae0f31cbaa08e4b00342ba2c0b1" + + "ba37ac7be8084e0aeb01045f121e87e9cc942ecdc3b5e52933b79aad6f005d8e" + + "dfc2aabf584106dfb2f6d3eb7f4584f5f2d9cba8340b0f73ba5fab4a4a024db2" + + "d00c5f0b3aba1f98cba6d1c9750591628daca165bac2de6fd694df833110ee01" + + "0000000000000000000000000000000000000000000000000fffffffffffffff" + + "19389f87908cb5f1ede2a9fe0c3047d2ad5fce424d133bacb655ae1179a81084" + + "102ce5ad22d815a64374da9e2207d722b1c9a3099b292eaea0862edc886ff70d" + + "b85285dd55258a2fbd04cc6ef365677b286d728f73db42c06ecc0a5822a6334a"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + true, + 0, + maxFeeLimit, + testAddress001, + testPriKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("TriggerTxid: " + TriggerTxid); - Optional infoById = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("infoById : " + infoById); Assert.assertEquals(0, infoById.get().getResultValue()); - String contractResult = ByteArray.toHexString( - infoById.get().getContractResult(0).toByteArray()); - // parseLong will return Long.MAX_VALUE and checkResult false + String contractResult = + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); + // parseLong will return Long.MAX_VALUE and checkResult false - Assert.assertEquals("" - + "0000000000000000000000000000000000000000000000000000000000000000", contractResult); + Assert.assertEquals( + "" + "0000000000000000000000000000000000000000000000000000000000000000", contractResult); } - @Test(enabled = true, description = "verify success with address call", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "verify success with address call", + groups = {"contract", "daily"}) public void verifyBurnProofTest005() { - String argsStr = "\"" - + "c9cf924134dd8fbd11d3b245b00adf4797b48c42e001673e7c566ce229b8fdf6" - + "24097774778540c2c4d5acbeffe333e1f595a1b731cbe10848e3d3a527ba4d1b" - + "a079c66e70cae2225cd702a7c0977635755ad104a87f435634d4e5382ac2afc8" - + "1c47919273d4861ad815855ba1b4db5f90cc7e922b65c930c291eddc6d49a6c4" - + "90771325afc8e6e4a506f9dca0889dff75bcb4c46030702a33899b4d1e81122a" - + "a236433cf4c8ff426c66446de2f375b08575c4a18802e19a5fa5500922f7d570" - + "aac680208d05f9f2a9beaef0d9adede10e4a0242a3d1e048dd2a65034ef3f348" - + "0c108652d93da2ed13a0720fce9dce3a01a25cfa898bbaa8730f3fa8bba4b8a9" - + "7a609fd9f4d008a9334dea39acc838298c989ae0f31cbaa08e4b00342ba2c0b1" - + "ba37ac7be8084e0aeb01045f121e87e9cc942ecdc3b5e52933b79aad6f005d8e" - - + "dfc2aabf584106dfb2f6d3eb7f4584f5f2d9cba8340b0f73ba5fab4a4a024db2" - + "d00c5f0b3aba1f98cba6d1c9750591628daca165bac2de6fd694df833110ee01" - - + "0000000000000000000000000000000000000000000000000000000000000064" - - + "19389f87908cb5f1ede2a9fe0c3047d2ad5fce424d133bacb655ae1179a81084" - + "102ce5ad22d815a64374da9e2207d722b1c9a3099b292eaea0862edc886ff70d" - - + "b85285dd55258a2fbd04cc6ef365677b286d728f73db42c06ecc0a5822a6334a" - + "\""; - String methedStr = "VerifyBurnProofSize002(bytes)"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, false, - 0, maxFeeLimit, testAddress001, testPriKey001, blockingStubFull); + String argsStr = + "\"" + + "c9cf924134dd8fbd11d3b245b00adf4797b48c42e001673e7c566ce229b8fdf6" + + "24097774778540c2c4d5acbeffe333e1f595a1b731cbe10848e3d3a527ba4d1b" + + "a079c66e70cae2225cd702a7c0977635755ad104a87f435634d4e5382ac2afc8" + + "1c47919273d4861ad815855ba1b4db5f90cc7e922b65c930c291eddc6d49a6c4" + + "90771325afc8e6e4a506f9dca0889dff75bcb4c46030702a33899b4d1e81122a" + + "a236433cf4c8ff426c66446de2f375b08575c4a18802e19a5fa5500922f7d570" + + "aac680208d05f9f2a9beaef0d9adede10e4a0242a3d1e048dd2a65034ef3f348" + + "0c108652d93da2ed13a0720fce9dce3a01a25cfa898bbaa8730f3fa8bba4b8a9" + + "7a609fd9f4d008a9334dea39acc838298c989ae0f31cbaa08e4b00342ba2c0b1" + + "ba37ac7be8084e0aeb01045f121e87e9cc942ecdc3b5e52933b79aad6f005d8e" + + "dfc2aabf584106dfb2f6d3eb7f4584f5f2d9cba8340b0f73ba5fab4a4a024db2" + + "d00c5f0b3aba1f98cba6d1c9750591628daca165bac2de6fd694df833110ee01" + + "0000000000000000000000000000000000000000000000000000000000000064" + + "19389f87908cb5f1ede2a9fe0c3047d2ad5fce424d133bacb655ae1179a81084" + + "102ce5ad22d815a64374da9e2207d722b1c9a3099b292eaea0862edc886ff70d" + + "b85285dd55258a2fbd04cc6ef365677b286d728f73db42c06ecc0a5822a6334a" + + "\""; + String methedStr = "VerifyBurnProofSize002(bytes)"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testPriKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("TriggerTxid: " + TriggerTxid); - Optional infoById = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("infoById : " + infoById); Assert.assertEquals(0, infoById.get().getResultValue()); - String contractResult = ByteArray.toHexString( - infoById.get().getContractResult(0).toByteArray()); - - Assert.assertEquals("" - + "0000000000000000000000000000000000000000000000000000000000000001" // 1 : true - + "0000000000000000000000000000000000000000000000000000000000000040" - + "0000000000000000000000000000000000000000000000000000000000000020" - + "0000000000000000000000000000000000000000000000000000000000000001", contractResult); + String contractResult = + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); + + Assert.assertEquals( + "" + + "0000000000000000000000000000000000000000000000000000000000000001" // 1 : true + + "0000000000000000000000000000000000000000000000000000000000000040" + + "0000000000000000000000000000000000000000000000000000000000000020" + + "0000000000000000000000000000000000000000000000000000000000000001", + contractResult); } - @Test(enabled = true, description = "verify success with fuction call", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "verify success with fuction call", + groups = {"contract", "daily"}) public void verifyBurnProofTest006() { - String argsStr = "" - + "c9cf924134dd8fbd11d3b245b00adf4797b48c42e001673e7c566ce229b8fdf6" - + "24097774778540c2c4d5acbeffe333e1f595a1b731cbe10848e3d3a527ba4d1b" - + "a079c66e70cae2225cd702a7c0977635755ad104a87f435634d4e5382ac2afc8" - + "1c47919273d4861ad815855ba1b4db5f90cc7e922b65c930c291eddc6d49a6c4" - + "90771325afc8e6e4a506f9dca0889dff75bcb4c46030702a33899b4d1e81122a" - + "a236433cf4c8ff426c66446de2f375b08575c4a18802e19a5fa5500922f7d570" - + "aac680208d05f9f2a9beaef0d9adede10e4a0242a3d1e048dd2a65034ef3f348" - + "0c108652d93da2ed13a0720fce9dce3a01a25cfa898bbaa8730f3fa8bba4b8a9" - + "7a609fd9f4d008a9334dea39acc838298c989ae0f31cbaa08e4b00342ba2c0b1" - + "ba37ac7be8084e0aeb01045f121e87e9cc942ecdc3b5e52933b79aad6f005d8e" - - + "dfc2aabf584106dfb2f6d3eb7f4584f5f2d9cba8340b0f73ba5fab4a4a024db2" - + "d00c5f0b3aba1f98cba6d1c9750591628daca165bac2de6fd694df833110ee01" - - + "0000000000000000000000000000000000000000000000000000000000000064" - - + "19389f87908cb5f1ede2a9fe0c3047d2ad5fce424d133bacb655ae1179a81084" - + "102ce5ad22d815a64374da9e2207d722b1c9a3099b292eaea0862edc886ff70d" - - + "b85285dd55258a2fbd04cc6ef365677b286d728f73db42c06ecc0a5822a6334a"; - String methedStr = "VerifyBurnProofSize001(bytes32[10],bytes32[2],uint64,bytes32[2],bytes32)"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, true, - 0, maxFeeLimit, testAddress001, testPriKey001, blockingStubFull); + String argsStr = + "" + + "c9cf924134dd8fbd11d3b245b00adf4797b48c42e001673e7c566ce229b8fdf6" + + "24097774778540c2c4d5acbeffe333e1f595a1b731cbe10848e3d3a527ba4d1b" + + "a079c66e70cae2225cd702a7c0977635755ad104a87f435634d4e5382ac2afc8" + + "1c47919273d4861ad815855ba1b4db5f90cc7e922b65c930c291eddc6d49a6c4" + + "90771325afc8e6e4a506f9dca0889dff75bcb4c46030702a33899b4d1e81122a" + + "a236433cf4c8ff426c66446de2f375b08575c4a18802e19a5fa5500922f7d570" + + "aac680208d05f9f2a9beaef0d9adede10e4a0242a3d1e048dd2a65034ef3f348" + + "0c108652d93da2ed13a0720fce9dce3a01a25cfa898bbaa8730f3fa8bba4b8a9" + + "7a609fd9f4d008a9334dea39acc838298c989ae0f31cbaa08e4b00342ba2c0b1" + + "ba37ac7be8084e0aeb01045f121e87e9cc942ecdc3b5e52933b79aad6f005d8e" + + "dfc2aabf584106dfb2f6d3eb7f4584f5f2d9cba8340b0f73ba5fab4a4a024db2" + + "d00c5f0b3aba1f98cba6d1c9750591628daca165bac2de6fd694df833110ee01" + + "0000000000000000000000000000000000000000000000000000000000000064" + + "19389f87908cb5f1ede2a9fe0c3047d2ad5fce424d133bacb655ae1179a81084" + + "102ce5ad22d815a64374da9e2207d722b1c9a3099b292eaea0862edc886ff70d" + + "b85285dd55258a2fbd04cc6ef365677b286d728f73db42c06ecc0a5822a6334a"; + String methedStr = "VerifyBurnProofSize001(bytes32[10],bytes32[2],uint64,bytes32[2],bytes32)"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + true, + 0, + maxFeeLimit, + testAddress001, + testPriKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("TriggerTxid: " + TriggerTxid); - Optional infoById = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("infoById : " + infoById); Assert.assertEquals(0, infoById.get().getResultValue()); - String contractResult = ByteArray.toHexString( - infoById.get().getContractResult(0).toByteArray()); + String contractResult = + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); - Assert.assertEquals("" - + "0000000000000000000000000000000000000000000000000000000000000001", contractResult); + Assert.assertEquals( + "" + "0000000000000000000000000000000000000000000000000000000000000001", contractResult); } - - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/zenProofCommand/VerifyMintProof001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/zenProofCommand/VerifyMintProof001.java index 8f74ade7..2a42b367 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/zenProofCommand/VerifyMintProof001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/zenProofCommand/VerifyMintProof001.java @@ -10,12 +10,11 @@ import org.tron.protos.Protocol; import org.tron.protos.Protocol.TransactionInfo; import org.tron.protos.contract.SmartContractOuterClass.SmartContract; -import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class VerifyMintProof001 extends TronBaseTest { @@ -25,41 +24,55 @@ public class VerifyMintProof001 extends TronBaseTest { private byte[] testAddress001 = ecKey1.getAddress(); private String testPriKey001 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(testPriKey001); - Assert.assertTrue(PublicMethod.sendcoin(testAddress001, 1000_000_000L, foundationAddress, - foundationKey, blockingStubFull)); + public void beforeClass() { + PublicMethod.printAddress(testPriKey001); + Assert.assertTrue( + PublicMethod.sendcoin( + testAddress001, 1000_000_000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Deploy VerfyMintProof contract ", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "Deploy VerfyMintProof contract ", + groups = {"contract", "daily"}) public void verifyMintProofTest001() { - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(testAddress001, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(testAddress001, blockingStubFull); Protocol.Account info = PublicMethod.queryAccount(testPriKey001, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = accountResource.getEnergyUsed(); - Long beforeNetUsed = accountResource.getNetUsed(); - Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = accountResource.getEnergyUsed(); + Long beforeNetUsed = accountResource.getNetUsed(); + Long beforeFreeNetUsed = accountResource.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String filePath = "./src/test/resources/soliditycode/VerifyMintProof001.sol"; - String contractName = "VerifyMintProof001Test"; + String filePath = "./src/test/resources/soliditycode/VerifyMintProof001.sol"; + String contractName = "VerifyMintProof001Test"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - String txid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, testPriKey001, - testAddress001, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + testPriKey001, + testAddress001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -69,201 +82,233 @@ public void verifyMintProofTest001() { Assert.assertEquals(0, infoById.get().getResultValue()); contractAddress = infoById.get().getContractAddress().toByteArray(); - SmartContract smartContract = PublicMethod.getContract(contractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); - } - @Test(enabled = true, description = "data length != 1504", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "data length != 1504", + groups = {"contract", "daily"}) public void verifyMintProofTest002() { - String argsStr = "\"" - + "a634da705bbacb108a276ce26470568873d573e6f1f00d3a2b2e93b93f4b1a0c" - + "2eb2b8ae07c858dafd7d99f4487a779878b1f87fb632c7fccff14d44c0b23e56" - + "61ba88273d52c44cf4e1939ce6e76b97ef2611ce4cf472c5e8a61e66463f948d" - + "8ffed5e9e6125a292dcb2f2855a753893467176b19ed366b3fc7c182e5b62cc1" - + "d01bb22cba6ca8a514f36c5f24e6dcaf953f77db33c5e6db4f2a756b2e4793b7" - + "be6e29b29309c37b9a1a5fe1e6ad42b1ed17c6d84d0fb4ed39772dceb5af6d23" - + "01ed5d94ce6b69efc2bbe863f7798d871ae5bfc3db4eb36073fd9b8eb08d6c0c" - + "52439f429ee437454cd59b8068ec9350b611f9b41cf5fa840c911227a2db3546" - + "f0d190023a929d821aaf0529066bd81eac321ad0c9cf98c4a39060d636140a99" - - + "2ac86687e4c5284a8272390684e557d9a70bcd8dbaec6b8c8cb6114b13e01f22" - + "c1dd79631dc9bd508f87d77bae4bebf31917c981d1ed1f8d8d9e637a7e56db0b" - - + "0000000000000000000000000000000000000000000000000000000000000064" - - + "33e4e8db7e8d3c127620de9901e7c6e65ca675b1c69455784a98aa7e4ed31a91" - - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - - + "0000000000000000000000000000000000000000000000000000000000000000" - // add more bytes32 - + "0000000000000000000000000000000000000000000000000000000000000064" - + "\""; - String methedStr = "VerifyMintProofSize002(bytes)"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, false, - 0, maxFeeLimit, testAddress001, testPriKey001, blockingStubFull); + String argsStr = + "\"" + + "a634da705bbacb108a276ce26470568873d573e6f1f00d3a2b2e93b93f4b1a0c" + + "2eb2b8ae07c858dafd7d99f4487a779878b1f87fb632c7fccff14d44c0b23e56" + + "61ba88273d52c44cf4e1939ce6e76b97ef2611ce4cf472c5e8a61e66463f948d" + + "8ffed5e9e6125a292dcb2f2855a753893467176b19ed366b3fc7c182e5b62cc1" + + "d01bb22cba6ca8a514f36c5f24e6dcaf953f77db33c5e6db4f2a756b2e4793b7" + + "be6e29b29309c37b9a1a5fe1e6ad42b1ed17c6d84d0fb4ed39772dceb5af6d23" + + "01ed5d94ce6b69efc2bbe863f7798d871ae5bfc3db4eb36073fd9b8eb08d6c0c" + + "52439f429ee437454cd59b8068ec9350b611f9b41cf5fa840c911227a2db3546" + + "f0d190023a929d821aaf0529066bd81eac321ad0c9cf98c4a39060d636140a99" + + "2ac86687e4c5284a8272390684e557d9a70bcd8dbaec6b8c8cb6114b13e01f22" + + "c1dd79631dc9bd508f87d77bae4bebf31917c981d1ed1f8d8d9e637a7e56db0b" + + "0000000000000000000000000000000000000000000000000000000000000064" + + "33e4e8db7e8d3c127620de9901e7c6e65ca675b1c69455784a98aa7e4ed31a91" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + // add more bytes32 + + "0000000000000000000000000000000000000000000000000000000000000064" + + "\""; + String methedStr = "VerifyMintProofSize002(bytes)"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testPriKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("TriggerTxid: " + TriggerTxid); - Optional infoById = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("infoById : " + infoById); Assert.assertEquals(0, infoById.get().getResultValue()); - String contractResult = ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray()); - - Assert.assertEquals("" - + "0000000000000000000000000000000000000000000000000000000000000001" // 1 : true - + "0000000000000000000000000000000000000000000000000000000000000040" - + "0000000000000000000000000000000000000000000000000000000000000020" - + "0000000000000000000000000000000000000000000000000000000000000000", contractResult); - - + String contractResult = + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); + + Assert.assertEquals( + "" + + "0000000000000000000000000000000000000000000000000000000000000001" // 1 : true + + "0000000000000000000000000000000000000000000000000000000000000040" + + "0000000000000000000000000000000000000000000000000000000000000020" + + "0000000000000000000000000000000000000000000000000000000000000000", + contractResult); } - @Test(enabled = true, description = "data is empty", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "data is empty", + groups = {"contract", "daily"}) public void verifyMintProofTest003() { String methedStr = "VerifyMintProofSize003()"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methedStr, "", false, - 0, maxFeeLimit, testAddress001, testPriKey001, blockingStubFull); + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + "", + false, + 0, + maxFeeLimit, + testAddress001, + testPriKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("TriggerTxid: " + TriggerTxid); - Optional infoById = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("infoById : " + infoById); Assert.assertEquals(0, infoById.get().getResultValue()); - String contractResult = ByteArray - .toHexString(infoById.get().getContractResult(0).toByteArray()); - - Assert.assertEquals("" - + "0000000000000000000000000000000000000000000000000000000000000001" // 1 : true - + "0000000000000000000000000000000000000000000000000000000000000040" - + "0000000000000000000000000000000000000000000000000000000000000020" - + "0000000000000000000000000000000000000000000000000000000000000000", contractResult); - + String contractResult = + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); + + Assert.assertEquals( + "" + + "0000000000000000000000000000000000000000000000000000000000000001" // 1 : true + + "0000000000000000000000000000000000000000000000000000000000000040" + + "0000000000000000000000000000000000000000000000000000000000000020" + + "0000000000000000000000000000000000000000000000000000000000000000", + contractResult); } - @Test(enabled = true, description = "leafCount greate than 2^32-1", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "leafCount greate than 2^32-1", + groups = {"contract", "daily"}) public void verifyMintProofTest004() { String methedStr = "VerifyMintProofSize002(bytes)"; - String argsStr = "\"" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - - + "000000000000000000000000000000000000000000000000000000000000000a" - - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" - - + "0000000000000000000000000000000000000000000000000000000100000002" - + "\""; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, false, - 0, maxFeeLimit, testAddress001, testPriKey001, blockingStubFull); + String argsStr = + "\"" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "000000000000000000000000000000000000000000000000000000000000000a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "b55a21aaee0ce8f1c8ffaa0dbd23105cb55a21aaee0ce8f1c8ffaa0dbd23105a" + + "0000000000000000000000000000000000000000000000000000000100000002" + + "\""; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testPriKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("TriggerTxid: " + TriggerTxid); - Optional infoById = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("infoById : " + infoById); Assert.assertEquals(0, infoById.get().getResultValue()); - String contractResult = ByteArray.toHexString(infoById.get() - .getContractResult(0).toByteArray()); - - Assert.assertEquals("" - + "" // 1 : true - + "0000000000000000000000000000000000000000000000000000000000000001" - + "0000000000000000000000000000000000000000000000000000000000000040" - + "0000000000000000000000000000000000000000000000000000000000000020" - + "0000000000000000000000000000000000000000000000000000000000000000", contractResult); + String contractResult = + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); + + Assert.assertEquals( + "" + + "" // 1 : true + + "0000000000000000000000000000000000000000000000000000000000000001" + + "0000000000000000000000000000000000000000000000000000000000000040" + + "0000000000000000000000000000000000000000000000000000000000000020" + + "0000000000000000000000000000000000000000000000000000000000000000", + contractResult); } - @Test(enabled = true, description = "verify success with address call", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "verify success with address call", + groups = {"contract", "daily"}) public void verifyMintProofTest005() { String argsStr = "\"a634da705bbacb108a276ce26470568873d573e6f1f00d3a2b2e93b93f4b1a0c" @@ -275,14 +320,10 @@ public void verifyMintProofTest005() { + "01ed5d94ce6b69efc2bbe863f7798d871ae5bfc3db4eb36073fd9b8eb08d6c0c" + "52439f429ee437454cd59b8068ec9350b611f9b41cf5fa840c911227a2db3546" + "f0d190023a929d821aaf0529066bd81eac321ad0c9cf98c4a39060d636140a99" - + "2ac86687e4c5284a8272390684e557d9a70bcd8dbaec6b8c8cb6114b13e01f22" + "c1dd79631dc9bd508f87d77bae4bebf31917c981d1ed1f8d8d9e637a7e56db0b" - + "0000000000000000000000000000000000000000000000000000000000000064" - + "33e4e8db7e8d3c127620de9901e7c6e65ca675b1c69455784a98aa7e4ed31a91" - + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" @@ -316,34 +357,46 @@ public void verifyMintProofTest005() { + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000\""; - String methedStr = "VerifyMintProofSize002(bytes)"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, false, - 0, maxFeeLimit, testAddress001, testPriKey001, blockingStubFull); + String methedStr = "VerifyMintProofSize002(bytes)"; + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + testAddress001, + testPriKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("TriggerTxid: " + TriggerTxid); - Optional infoById = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("infoById : " + infoById); Assert.assertEquals(0, infoById.get().getResultValue()); - String contractResult = ByteArray.toHexString(infoById.get() - .getContractResult(0).toByteArray()); - - Assert.assertEquals("" - + "0000000000000000000000000000000000000000000000000000000000000001" // 1 : true - + "0000000000000000000000000000000000000000000000000000000000000040" - + "0000000000000000000000000000000000000000000000000000000000000060" - + "0000000000000000000000000000000000000000000000000000000000000001" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "39e261b362110781a20878cc19f480cb50df5e6b896ed9a1fea8b8a9a4239a17", contractResult); - + String contractResult = + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); + + Assert.assertEquals( + "" + + "0000000000000000000000000000000000000000000000000000000000000001" // 1 : true + + "0000000000000000000000000000000000000000000000000000000000000040" + + "0000000000000000000000000000000000000000000000000000000000000060" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "39e261b362110781a20878cc19f480cb50df5e6b896ed9a1fea8b8a9a4239a17", + contractResult); } - @Test(enabled = true, description = "verify success with fuction call", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "verify success with fuction call", + groups = {"contract", "daily"}) public void verifyMintProofTest006() { String argsStr = "a634da705bbacb108a276ce26470568873d573e6f1f00d3a2b2e93b93f4b1a0c" @@ -355,14 +408,10 @@ public void verifyMintProofTest006() { + "01ed5d94ce6b69efc2bbe863f7798d871ae5bfc3db4eb36073fd9b8eb08d6c0c" + "52439f429ee437454cd59b8068ec9350b611f9b41cf5fa840c911227a2db3546" + "f0d190023a929d821aaf0529066bd81eac321ad0c9cf98c4a39060d636140a99" - + "2ac86687e4c5284a8272390684e557d9a70bcd8dbaec6b8c8cb6114b13e01f22" + "c1dd79631dc9bd508f87d77bae4bebf31917c981d1ed1f8d8d9e637a7e56db0b" - + "0000000000000000000000000000000000000000000000000000000000000064" - + "33e4e8db7e8d3c127620de9901e7c6e65ca675b1c69455784a98aa7e4ed31a91" - + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" @@ -396,37 +445,43 @@ public void verifyMintProofTest006() { + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000"; - String methedStr = + String methedStr = "VerifyMintProofSize001(bytes32[9],bytes32[2],uint64,bytes32,bytes32[33],uint256)"; - String TriggerTxid = PublicMethod.triggerContract(contractAddress, methedStr, argsStr, true, - 0, maxFeeLimit, testAddress001, testPriKey001, blockingStubFull); + String TriggerTxid = + PublicMethod.triggerContract( + contractAddress, + methedStr, + argsStr, + true, + 0, + maxFeeLimit, + testAddress001, + testPriKey001, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info("TriggerTxid: " + TriggerTxid); - Optional infoById = PublicMethod - .getTransactionInfoById(TriggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(TriggerTxid, blockingStubFull); logger.info("infoById : " + infoById); Assert.assertEquals(0, infoById.get().getResultValue()); - String contractResult = ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); - -// Assert.assertTrue(contractResult.length() > 1000); - String offset = contractResult.substring(0,64); - String length = contractResult.substring(64,128); - //data1: 1:success - String data1 = contractResult.substring(128,192); - String data2 = contractResult.substring(192,256); - String data3 = contractResult.substring(256,320); + String contractResult = + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); + + // Assert.assertTrue(contractResult.length() > 1000); + String offset = contractResult.substring(0, 64); + String length = contractResult.substring(64, 128); + // data1: 1:success + String data1 = contractResult.substring(128, 192); + String data2 = contractResult.substring(192, 256); + String data3 = contractResult.substring(256, 320); Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000020", offset); Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000003", length); Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000001", data1); Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", data2); Assert.assertEquals("39e261b362110781a20878cc19f480cb50df5e6b896ed9a1fea8b8a9a4239a17", data3); - } - - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/zenProofCommand/verifyTransferProof001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/zenProofCommand/verifyTransferProof001.java index 6781ae19..f96c8f77 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/zenProofCommand/verifyTransferProof001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/zenProofCommand/verifyTransferProof001.java @@ -15,17 +15,17 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class verifyTransferProof001 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] contractAddress = null; String txid; @@ -34,231 +34,82 @@ public class verifyTransferProof001 extends TronBaseTest { String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractExcKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + PublicMethod.printAddress(contractExcKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - txid = PublicMethod - .sendcoinGetTransactionId(contractExcAddress, 10000000000L, testNetAccountAddress, - testNetAccountKey, blockingStubFull); + txid = + PublicMethod.sendcoinGetTransactionId( + contractExcAddress, + 10000000000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/verifyTransferProof001.sol"; - String contractName = "verifyTransferProofTest"; + String filePath = "src/test/resources/soliditycode/verifyTransferProof001.sol"; + String contractName = "verifyTransferProofTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "data is empty", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "data is empty", + groups = {"contract", "daily"}) public void test01DataIsEmpty() { String method = "test1()"; - txid = PublicMethod - .triggerContract(contractAddress, method, "", false, 0, maxFeeLimit, contractExcAddress, - contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + method, + "", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000001" + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000040" + "0000000000000000000000000000000000000000000000000000000000000020" + "0000000000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "data length limit", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "data length limit", + groups = {"contract", "daily"}) public void test02DataLengthLimit() { String method = "test2(bytes)"; Optional infoById = null; - // length:2048 - String argsStr1 = "\"0000000000000000000000000000000000000000000000000000000000000520" - + "0000000000000000000000000000000000000000000000000000000000000680" - + "00000000000000000000000000000000000000000000000000000000000006e0" - + "f3e912b1f0d8e6a6654c1e9ff16d9eb5c2895b35490a5fa825d275d842efb5e5" - + "45ae827a6fb105d6fc6d125c2a8c1253f753b4973a6505b671b0c01b6ef3ac06" - + "4f4aca9fdf2a460e95df34315749ac432cd5154ad42217b7296b3b5bd81dd00b" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "363f4cb9b6605bbd39b3ccf4fdc834721afc8d38cd25becc7830dab5cacf1852" - + "32431ad6d4cfa89730b413b4ca2f744623a0b4b8315fc5e307ed62a043fa4064" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000003" - + "0000000000000000000000000000000000000000000000000000000000000001" - + "66b02f76abecb4de13adc2b9b48edf60edf7e243dba5930276655936b53019ee" - + "626327f3509cadc915c8df9d9f97e17f244c828f3ad82b19f6701ae09dc0e22e" - + "659d5386266aef0a8434fe2ac728a655071f4688ad6cd1dae6e58e4767e1a36a" - + "d2614240434f15b189c8f235e35b281454988d72518df3068d8f512fe992e564" - + "a27d2c53207376e3f179aed8f415acbe1bca1a9ec60188f6fea1d1fd99f80db2" - + "c70271638ea0aa5d99e49fca76157e7692c856f4056b7857ed5ce852e69c713f" - + "42dd888295906c9988cc7fdd6715ea2dac745e97fa8ffd63653ee8e17b8a2ada" - + "1148bed585f91c1ab2f38f77e78a4dacd86587ac899961665e0a6f34d7cf0a41" - + "0f1032d3c26d0ab381ba3fd45f1cbb36b04f889584c1868fdc448eaab9bb8592" - + "d91a58c9e735862cdd346201fb9ab75999c6a57a6a474f2248f71c631375f0a8" - + "0000000000000000000000000000000000000000000000000000000000000001" - + "8dcbff6a27f4e6b39c6e19aab7deb9427368bc8dc1082f0dfe57edc94fbb8c3e" - + "1eb36d9f48c5243dad16ab511dcea3c8489ba0dd774befb12fc58f1ae50e7504" - + "0000000000000000000000000000000000000000000000000000000000000001" - + "9fa6ed64a910bee735eafdb80636852367f6a487f6aec0598708ad80cad8ed09" - + "7aa9686c3cc957f88703e1eea87c5412baba2044c78e9161a7b2ac2b21bfef9b" - + "83ca769ba273d3fe1d4cc0d5d0d1ab8a6540f220c1db981fc8885ee34b51263f" - + "90f31816d21895f518bbb893c62ce296ee8416486c37b9dba9d0cb3cdd5f58c5" - + "7e175a69dbf443509bc060f354862d9787490de120ae665cbcba894854eb8aaf" - + "b811e676c506f7c4f2038afa09fc56b66c0c9cefcc00d780d152f1633d1c90af" - + "058355203f7737de6184b08bbf84248f118c3b540a7dc8f5518676fe0ebb2b35" - + "e4c3ec5f6b2f93138c7e7aa4a9b631dc9786b6df2d317208f220055d3fcab328\""; - txid = PublicMethod.triggerContract(contractAddress, method, argsStr1, false, 0, maxFeeLimit, - contractExcAddress, contractExcKey, blockingStubFull); - PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0, infoById.get().getResultValue()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000001" - + "0000000000000000000000000000000000000000000000000000000000000040" - + "0000000000000000000000000000000000000000000000000000000000000020" - + "0000000000000000000000000000000000000000000000000000000000000000", - ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); - // length:2784 - String argsStr2 = "\"0000000000000000000000000000000000000000000000000000000000000520" - + "00000000000000000000000000000000000000000000000000000000000007c0" - + "0000000000000000000000000000000000000000000000000000000000000860" - + "898bb618ff2874a2b706e000d663c8e7ff7095ca404e131ce712583d7a3bf717" - + "b7b6ec3705a0823d09524e13c81bd4f44e6c796e63b197ffcdb6ec7bb44ff505" - + "2487fbd8a96638187266aa9c54795e0c14aabcd72d45b6d13ba304b539cbc7ed" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "82f70d55b1d9131cd3d41b7491636291a5ac41ed3372e4fe502d1c4a911cce4b" - + "49c6eaf2968c27437831622072b8f8cfa18791084189e7c4764c104a360bbe70" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000002" - + "0000000000000000000000000000000000000000000000000000000000000002" - + "7c62133e78f43c71c49e8b85b145377c51c7d4dfd7c44656d62363144f243575" - + "1f2b46d412955c11a51cd81f6499bd0e9cf9c5a3fa12befe26b1e992e41cfd4c" - + "f1243c6008688639d9dffa4670b74546f66be60209a9c5664a9de7dcca856f6a" - + "fdfb2e8cf0083a20dbf2899042baa469949f7993f7b0f3606d70f443486ebf46" - + "9232a4e7a899e52a7479d9ca981ee7fe96250e4ef8d6899d89e8c33be62ac65c" - + "a97e4cd3d9a58033d35f9a7c45375f0b8866db6db15fcbd185e6c254cd0300b9" - + "364a3c2d9499e474bf207ce2f2b67427df0796d2c221efb28b7fccea210b58ba" - + "01f5a9b4a12eb295ab0fecbe97f01bf4841002e94e1334a513755403f6832ce3" - + "0ab328b11e8772aa922dc7c84768c887b38b35e39df177e3fc4f760051209e1a" - + "9dfef66affba94f21d5a28c39a893419af506faee2217f0c605830427173a7d5" - + "521c7b5bf3ff99421c69c861af0fc30b565332ff1aad344afd9dd7b40e3da769" - + "67ecbac59d221641a28b19134e599c1d20c5cc55ac45217a68b0b9106872b92a" - + "8d55ca2e65e84ccd45a21d88a0eec096d98525d7e6751d4dbc4ddcb6aaec334b" - + "c7061b48ba27b89f193ad9e9f4d9c98aa1316b08f018222a3d92c1da7e8b7611" - + "806764eeb09ac490eea1f01d16ba8378e0c64396a0c06a707ed6027eae76938e" - + "74fa404d1ed9a955c7fe85eabc07b76eb58287d749a8dd304e810f94f680120b" - + "6e792117717f8b5b7f9f01416205900d962ffb69540e85562688604c26db4987" - + "0de0658d072aeb649809bf6f21714975f87e75df545e583c77bd6f786b3cc5c6" - + "08051b7885a732ac9bd49271d7ae9caea7d995d2ce5b18740f2b5b0de32d1337" - + "46f30ae9eb6d1f54ea1e4e228b6a22849a99f0a2decd09c806d8bd7cad6810de" - + "0000000000000000000000000000000000000000000000000000000000000002" - + "c68b0fa0e76ffae969421ef87a0e27e4ad5a94b5bf2b5237c0a0e57259f20e60" - + "60525cfbc22ff838b067110121840a6885bff4516a5dc21eedce04f79b04b403" - + "10e640233b876885329599a78ce1cdc5dff83a29216f7fe58f225338963ec9b4" - + "9811e7479ef258776289394525c1070b70d3aeacb6d9d4a9065024ca21d8ed08" - + "0000000000000000000000000000000000000000000000000000000000000002" - + "73238d94e2ad7575eb6067b1e5889a8445ef29dc377bdba0807f716b0b75b13e" - + "00ef0b6303b098a8af5e2deb8d506aaa710a58805325aa2097c19a63b876e5b4" - + "26e055e92683f24fab7c79b7d8825928fc3dc356d496c09069b8fd0d01df275b" - + "b0a57952d3adc1f31570d3626d2011a725f9caaf857e253b4e4791adfb7babe7" - + "27c0b4791f16050dfdb1a4763f75fd0f970ca19ee66c36462e43dff2899c5d62" - + "3e363389f3dedb855c09e051f20f3f27ee52d2d267ae1f1bf024c2f63068b682" - + "0b578b39aebb57b8fc055a7d13d25574dfcde58656beec84dde4ba439b0bbb5d" - + "0b5b24a2cf71f6b68b56c5ef1bac89888b5b6827bca8cd8b47fc394cf89a6c23" - + "468f7857b566cddf39f06eed6ac079f20044b42381fb0ca969c4f425ed04e166" - + "09e582987c6af094c8afbfeb52e14b0e4e342c82dc784405631f4a985c826e51" - + "4a9b50b6ad41db1a403b0ced0f5f1e4a9ae2964237b6874056c8044233b331e1" - + "a8bcf84d0584c12dc42ebd27cca972b31c475a644450afcfd40c36c739740566" - + "8b377c8ed99dcca1a5ec03ca990d6c4cb846ad561dd204c66c834fc024030b75" - + "106bdca9e57e8d68d19e4183a349bc488b9c3d666f59f9bdca8e92457dbbacf5" - + "1a0e074d5cb64b54e533aef3d1da2b673b7a87cae612c7faed50563a20970a9b" - + "07539d7ea4d57a83defeaefa024832fe6ec1db4c3a4ef6badcc4d95e0d22f4ec" - + "e4f272a22dcfaa2326bc301f2dfac22fa35bd0c9a40262caf424e2e62b3e0a45" - + "c2fa591c482e923a2d6b3c4ba0819df430f4d548105071f7cb561749459f15d2" - + "c2fa591c482e923a2d6b3c4ba0819df430f4d548105071f7cb561749459f15d2\""; - txid = PublicMethod.triggerContract(contractAddress, method, argsStr2, false, 0, maxFeeLimit, - contractExcAddress, contractExcKey, blockingStubFull); - PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - Assert.assertEquals(0, infoById.get().getResultValue()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000001" - + "0000000000000000000000000000000000000000000000000000000000000040" - + "0000000000000000000000000000000000000000000000000000000000000020" - + "0000000000000000000000000000000000000000000000000000000000000000", - ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); - } - - @Test(enabled = true, description = "tree width limit", groups = {"contract", "daily"}) - public void test03TreeWidthLimit() { - String method = "test2(bytes)"; - txid = PublicMethod.triggerContract(contractAddress, method, + // length:2048 + String argsStr1 = "\"0000000000000000000000000000000000000000000000000000000000000520" + "0000000000000000000000000000000000000000000000000000000000000680" + "00000000000000000000000000000000000000000000000000000000000006e0" @@ -299,7 +150,7 @@ public void test03TreeWidthLimit() { + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" - + "00000000000000000000000000000000000000000000000000000000ffffffff" + + "0000000000000000000000000000000000000000000000000000000000000003" + "0000000000000000000000000000000000000000000000000000000000000001" + "66b02f76abecb4de13adc2b9b48edf60edf7e243dba5930276655936b53019ee" + "626327f3509cadc915c8df9d9f97e17f244c828f3ad82b19f6701ae09dc0e22e" @@ -322,35 +173,38 @@ public void test03TreeWidthLimit() { + "7e175a69dbf443509bc060f354862d9787490de120ae665cbcba894854eb8aaf" + "b811e676c506f7c4f2038afa09fc56b66c0c9cefcc00d780d152f1633d1c90af" + "058355203f7737de6184b08bbf84248f118c3b540a7dc8f5518676fe0ebb2b35" - + "e4c3ec5f6b2f93138c7e7aa4a9b631dc9786b6df2d317208f220055d3fcab328" - + "d50b3131146a9b97443fca616d401b0f5e7c51b3c71b91c3637df35cf4b91864\"", - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + + "e4c3ec5f6b2f93138c7e7aa4a9b631dc9786b6df2d317208f220055d3fcab328\""; + txid = + PublicMethod.triggerContract( + contractAddress, + method, + argsStr1, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000001" + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000040" + "0000000000000000000000000000000000000000000000000000000000000020" + "0000000000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); - } - - @Test(enabled = true, description = "spend count greater than 2", groups = {"contract", "daily"}) - public void test04SpendCountGreaterThan2() { - String method = "test2(bytes)"; - txid = PublicMethod.triggerContract(contractAddress, method, - "\"0000000000000000000000000000000000000000000000000000000000000521" - + "0000000000000000000000000000000000000000000000000000000000000680" - + "00000000000000000000000000000000000000000000000000000000000006e0" - + "e5ae9d43a82fc3bc74272dbe20dcf99d2d37ff4ae1689c3f9b53d40113cf5fa8" - + "77e4f78bef9e692985e3a7cd08b92a8380aa0aaec623b7cf3aae5c5a13b41602" - + "9b40cc7690e15b1437f1d88aaf3b44649e23cbd4013b4b41da1efdf31b774779" + // length:2784 + String argsStr2 = + "\"0000000000000000000000000000000000000000000000000000000000000520" + + "00000000000000000000000000000000000000000000000000000000000007c0" + + "0000000000000000000000000000000000000000000000000000000000000860" + + "898bb618ff2874a2b706e000d663c8e7ff7095ca404e131ce712583d7a3bf717" + + "b7b6ec3705a0823d09524e13c81bd4f44e6c796e63b197ffcdb6ec7bb44ff505" + + "2487fbd8a96638187266aa9c54795e0c14aabcd72d45b6d13ba304b539cbc7ed" + "0000000000000000000000000000000000000000000000000000000000000000" - + "22389ba23e8f871b2a2e71d87c67f03eaace9849e59e8cfd54d5ca783c9b8923" - + "2108740b5326d2802e5a09a263a2668f987425af3f76d61a5d3fa98896ea2a52" - + "db286eec8ac754634b2e099f661b194b79d99c4fc33f9eef975b1b2862f72866" - + "60b225e4f8a010864d82e87cbec9d1fab63a6ae57f04a03f0ced73fb7ba73a71" + + "82f70d55b1d9131cd3d41b7491636291a5ac41ed3372e4fe502d1c4a911cce4b" + + "49c6eaf2968c27437831622072b8f8cfa18791084189e7c4764c104a360bbe70" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" @@ -380,400 +234,669 @@ public void test04SpendCountGreaterThan2() { + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" - + "000000000000000000000000000000000000000000000000000000000000000d" - + "0000000000000000000000000000000000000000000000000000000000000001" - + "fa05291a6d8af85cf9dc46f04687c31c12a4de8b2e9b51a55f2b777fb0220ddb" - + "c11bbb1f5025494923823c12fe864d290958384d5bc5e4d920e2bd9db70d005b" - + "b609c343bf7a9b3275ef9419ec1c5dfca574b9e17d67a782b745d2a4c830346d" - + "c77bfd763dfab3fa57596693a828cba2dbbd43fa0daa454136cd61f303e66d72" - + "b91efc162b5a4474b71f9b688af8513bc0e19fbcc834223c02c942f504c4286a" - + "359462bc8993d7b41aead7ac25a25c64b5ae662cea2370ff912e2b2a6ef76bbe" - + "f5ae2a40d920ee79197c99b9ba92df929d445bbd4a0384ce3e637d59939086dc" - + "06042ef2abbb6ea7a599acac186d8fce957c1632d1dc64c9cc04a4a597d42923" - + "491440cfa5bf9c0d387ef77902921343929900044165384c73b30b38c466e4f6" - + "d71f6c1e1b6af43ce2ec0572cd3a28e7c1d5caab600cb001effd07e4182e89be" - + "0000000000000000000000000000000000000000000000000000000000000001" - + "3f153ababa83e18ff39b3149b893d90aebd440521b670b10e8268f7a98f42f06" - + "64efcf611c6c0e11f9edfeca53af7e8fc758f92b713fb4c104df4f6868eb6807" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000002" + + "0000000000000000000000000000000000000000000000000000000000000002" + + "7c62133e78f43c71c49e8b85b145377c51c7d4dfd7c44656d62363144f243575" + + "1f2b46d412955c11a51cd81f6499bd0e9cf9c5a3fa12befe26b1e992e41cfd4c" + + "f1243c6008688639d9dffa4670b74546f66be60209a9c5664a9de7dcca856f6a" + + "fdfb2e8cf0083a20dbf2899042baa469949f7993f7b0f3606d70f443486ebf46" + + "9232a4e7a899e52a7479d9ca981ee7fe96250e4ef8d6899d89e8c33be62ac65c" + + "a97e4cd3d9a58033d35f9a7c45375f0b8866db6db15fcbd185e6c254cd0300b9" + + "364a3c2d9499e474bf207ce2f2b67427df0796d2c221efb28b7fccea210b58ba" + + "01f5a9b4a12eb295ab0fecbe97f01bf4841002e94e1334a513755403f6832ce3" + + "0ab328b11e8772aa922dc7c84768c887b38b35e39df177e3fc4f760051209e1a" + + "9dfef66affba94f21d5a28c39a893419af506faee2217f0c605830427173a7d5" + + "521c7b5bf3ff99421c69c861af0fc30b565332ff1aad344afd9dd7b40e3da769" + + "67ecbac59d221641a28b19134e599c1d20c5cc55ac45217a68b0b9106872b92a" + + "8d55ca2e65e84ccd45a21d88a0eec096d98525d7e6751d4dbc4ddcb6aaec334b" + + "c7061b48ba27b89f193ad9e9f4d9c98aa1316b08f018222a3d92c1da7e8b7611" + + "806764eeb09ac490eea1f01d16ba8378e0c64396a0c06a707ed6027eae76938e" + + "74fa404d1ed9a955c7fe85eabc07b76eb58287d749a8dd304e810f94f680120b" + + "6e792117717f8b5b7f9f01416205900d962ffb69540e85562688604c26db4987" + + "0de0658d072aeb649809bf6f21714975f87e75df545e583c77bd6f786b3cc5c6" + + "08051b7885a732ac9bd49271d7ae9caea7d995d2ce5b18740f2b5b0de32d1337" + + "46f30ae9eb6d1f54ea1e4e228b6a22849a99f0a2decd09c806d8bd7cad6810de" + "0000000000000000000000000000000000000000000000000000000000000002" - + "4fd0c6e8ed03c4e7797c4da435e5da8b7ecf63c765c8f5817fe29aa4f54e6057" - + "fc5dda67c0109f8ce48344c9c55fb8081a79ad549bd7d162b3f334a9219f8169" - + "a2f5c0f129ac81ab9f93b13a09ec25b40356420dbfe9aa21d367af61415a6a45" - + "82b5efd3f827c7ca99371b1a029e1781156f068e000fdb26ea1b078ce24ae4e1" - + "571001515de0d6d55d2eb7ed4371397b993b2fe4df3addd53248e3adfc24c6fe" - + "81e7b3679ba49fb7e5ef8c13661e7d442210cac48e93398f6d731b3770fcb23e" - + "01c0d34d139df0c31c1dbdf8b08fe0d6029845b1abc990986408191905d04e76" - + "44dd0fc25446d753e94638ee48bb5e088f4483ce9e648093e654ba762ea516df" - + "5bb29cb95cfe347fc2f109ff86d5596bdb89c116b4805b9c6bdc019049b597f3" - + "ee52b22ececc9c7bc4d2c4dd61f9e16bc9feb07a5575f28e577a2d67c1eb3d24" - + "d6583d39f9ea3fe2de10132de6303217cca345201a194ecde8ad098f49d3f63b" - + "2f1f12c99a24d5779e7b4d1e6aa4fc3e1f0bd671701f42e43f3530501e7e2c00" - + "b47f9f2c332b75a849eb94a260a9d2a846212562ec57e927e071962ddc5dda5c" - + "dd9d38d346666659216b4897492ee991b359f9d3adf8bb576720f3b1d49be957" - + "a5c39e894b98bea2538645b434d47e4e7c71fdf765aeae264dd916ff41542eee" - + "063bbed2ff1e40ee1a2a949d5bd197e5936709cdb68151108221b8478fa15d86" - + "d8aff952d21265677a1a363cf7f492de8c0715cb95960d149842e3cee99bdb32\"", - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + + "c68b0fa0e76ffae969421ef87a0e27e4ad5a94b5bf2b5237c0a0e57259f20e60" + + "60525cfbc22ff838b067110121840a6885bff4516a5dc21eedce04f79b04b403" + + "10e640233b876885329599a78ce1cdc5dff83a29216f7fe58f225338963ec9b4" + + "9811e7479ef258776289394525c1070b70d3aeacb6d9d4a9065024ca21d8ed08" + + "0000000000000000000000000000000000000000000000000000000000000002" + + "73238d94e2ad7575eb6067b1e5889a8445ef29dc377bdba0807f716b0b75b13e" + + "00ef0b6303b098a8af5e2deb8d506aaa710a58805325aa2097c19a63b876e5b4" + + "26e055e92683f24fab7c79b7d8825928fc3dc356d496c09069b8fd0d01df275b" + + "b0a57952d3adc1f31570d3626d2011a725f9caaf857e253b4e4791adfb7babe7" + + "27c0b4791f16050dfdb1a4763f75fd0f970ca19ee66c36462e43dff2899c5d62" + + "3e363389f3dedb855c09e051f20f3f27ee52d2d267ae1f1bf024c2f63068b682" + + "0b578b39aebb57b8fc055a7d13d25574dfcde58656beec84dde4ba439b0bbb5d" + + "0b5b24a2cf71f6b68b56c5ef1bac89888b5b6827bca8cd8b47fc394cf89a6c23" + + "468f7857b566cddf39f06eed6ac079f20044b42381fb0ca969c4f425ed04e166" + + "09e582987c6af094c8afbfeb52e14b0e4e342c82dc784405631f4a985c826e51" + + "4a9b50b6ad41db1a403b0ced0f5f1e4a9ae2964237b6874056c8044233b331e1" + + "a8bcf84d0584c12dc42ebd27cca972b31c475a644450afcfd40c36c739740566" + + "8b377c8ed99dcca1a5ec03ca990d6c4cb846ad561dd204c66c834fc024030b75" + + "106bdca9e57e8d68d19e4183a349bc488b9c3d666f59f9bdca8e92457dbbacf5" + + "1a0e074d5cb64b54e533aef3d1da2b673b7a87cae612c7faed50563a20970a9b" + + "07539d7ea4d57a83defeaefa024832fe6ec1db4c3a4ef6badcc4d95e0d22f4ec" + + "e4f272a22dcfaa2326bc301f2dfac22fa35bd0c9a40262caf424e2e62b3e0a45" + + "c2fa591c482e923a2d6b3c4ba0819df430f4d548105071f7cb561749459f15d2" + + "c2fa591c482e923a2d6b3c4ba0819df430f4d548105071f7cb561749459f15d2\""; + txid = + PublicMethod.triggerContract( + contractAddress, + method, + argsStr2, + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000001" + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000040" + "0000000000000000000000000000000000000000000000000000000000000020" + "0000000000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "duplicate nullifiers", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "tree width limit", + groups = {"contract", "daily"}) + public void test03TreeWidthLimit() { + String method = "test2(bytes)"; + txid = + PublicMethod.triggerContract( + contractAddress, + method, + "\"0000000000000000000000000000000000000000000000000000000000000520" + + "0000000000000000000000000000000000000000000000000000000000000680" + + "00000000000000000000000000000000000000000000000000000000000006e0" + + "f3e912b1f0d8e6a6654c1e9ff16d9eb5c2895b35490a5fa825d275d842efb5e5" + + "45ae827a6fb105d6fc6d125c2a8c1253f753b4973a6505b671b0c01b6ef3ac06" + + "4f4aca9fdf2a460e95df34315749ac432cd5154ad42217b7296b3b5bd81dd00b" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "363f4cb9b6605bbd39b3ccf4fdc834721afc8d38cd25becc7830dab5cacf1852" + + "32431ad6d4cfa89730b413b4ca2f744623a0b4b8315fc5e307ed62a043fa4064" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "00000000000000000000000000000000000000000000000000000000ffffffff" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "66b02f76abecb4de13adc2b9b48edf60edf7e243dba5930276655936b53019ee" + + "626327f3509cadc915c8df9d9f97e17f244c828f3ad82b19f6701ae09dc0e22e" + + "659d5386266aef0a8434fe2ac728a655071f4688ad6cd1dae6e58e4767e1a36a" + + "d2614240434f15b189c8f235e35b281454988d72518df3068d8f512fe992e564" + + "a27d2c53207376e3f179aed8f415acbe1bca1a9ec60188f6fea1d1fd99f80db2" + + "c70271638ea0aa5d99e49fca76157e7692c856f4056b7857ed5ce852e69c713f" + + "42dd888295906c9988cc7fdd6715ea2dac745e97fa8ffd63653ee8e17b8a2ada" + + "1148bed585f91c1ab2f38f77e78a4dacd86587ac899961665e0a6f34d7cf0a41" + + "0f1032d3c26d0ab381ba3fd45f1cbb36b04f889584c1868fdc448eaab9bb8592" + + "d91a58c9e735862cdd346201fb9ab75999c6a57a6a474f2248f71c631375f0a8" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "8dcbff6a27f4e6b39c6e19aab7deb9427368bc8dc1082f0dfe57edc94fbb8c3e" + + "1eb36d9f48c5243dad16ab511dcea3c8489ba0dd774befb12fc58f1ae50e7504" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "9fa6ed64a910bee735eafdb80636852367f6a487f6aec0598708ad80cad8ed09" + + "7aa9686c3cc957f88703e1eea87c5412baba2044c78e9161a7b2ac2b21bfef9b" + + "83ca769ba273d3fe1d4cc0d5d0d1ab8a6540f220c1db981fc8885ee34b51263f" + + "90f31816d21895f518bbb893c62ce296ee8416486c37b9dba9d0cb3cdd5f58c5" + + "7e175a69dbf443509bc060f354862d9787490de120ae665cbcba894854eb8aaf" + + "b811e676c506f7c4f2038afa09fc56b66c0c9cefcc00d780d152f1633d1c90af" + + "058355203f7737de6184b08bbf84248f118c3b540a7dc8f5518676fe0ebb2b35" + + "e4c3ec5f6b2f93138c7e7aa4a9b631dc9786b6df2d317208f220055d3fcab328" + + "d50b3131146a9b97443fca616d401b0f5e7c51b3c71b91c3637df35cf4b91864\"", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); + PublicMethod.waitProduceNextBlock(blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000001" + + "0000000000000000000000000000000000000000000000000000000000000040" + + "0000000000000000000000000000000000000000000000000000000000000020" + + "0000000000000000000000000000000000000000000000000000000000000000", + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); + } + + @Test( + enabled = true, + description = "spend count greater than 2", + groups = {"contract", "daily"}) + public void test04SpendCountGreaterThan2() { + String method = "test2(bytes)"; + txid = + PublicMethod.triggerContract( + contractAddress, + method, + "\"0000000000000000000000000000000000000000000000000000000000000521" + + "0000000000000000000000000000000000000000000000000000000000000680" + + "00000000000000000000000000000000000000000000000000000000000006e0" + + "e5ae9d43a82fc3bc74272dbe20dcf99d2d37ff4ae1689c3f9b53d40113cf5fa8" + + "77e4f78bef9e692985e3a7cd08b92a8380aa0aaec623b7cf3aae5c5a13b41602" + + "9b40cc7690e15b1437f1d88aaf3b44649e23cbd4013b4b41da1efdf31b774779" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "22389ba23e8f871b2a2e71d87c67f03eaace9849e59e8cfd54d5ca783c9b8923" + + "2108740b5326d2802e5a09a263a2668f987425af3f76d61a5d3fa98896ea2a52" + + "db286eec8ac754634b2e099f661b194b79d99c4fc33f9eef975b1b2862f72866" + + "60b225e4f8a010864d82e87cbec9d1fab63a6ae57f04a03f0ced73fb7ba73a71" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "000000000000000000000000000000000000000000000000000000000000000d" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "fa05291a6d8af85cf9dc46f04687c31c12a4de8b2e9b51a55f2b777fb0220ddb" + + "c11bbb1f5025494923823c12fe864d290958384d5bc5e4d920e2bd9db70d005b" + + "b609c343bf7a9b3275ef9419ec1c5dfca574b9e17d67a782b745d2a4c830346d" + + "c77bfd763dfab3fa57596693a828cba2dbbd43fa0daa454136cd61f303e66d72" + + "b91efc162b5a4474b71f9b688af8513bc0e19fbcc834223c02c942f504c4286a" + + "359462bc8993d7b41aead7ac25a25c64b5ae662cea2370ff912e2b2a6ef76bbe" + + "f5ae2a40d920ee79197c99b9ba92df929d445bbd4a0384ce3e637d59939086dc" + + "06042ef2abbb6ea7a599acac186d8fce957c1632d1dc64c9cc04a4a597d42923" + + "491440cfa5bf9c0d387ef77902921343929900044165384c73b30b38c466e4f6" + + "d71f6c1e1b6af43ce2ec0572cd3a28e7c1d5caab600cb001effd07e4182e89be" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "3f153ababa83e18ff39b3149b893d90aebd440521b670b10e8268f7a98f42f06" + + "64efcf611c6c0e11f9edfeca53af7e8fc758f92b713fb4c104df4f6868eb6807" + + "0000000000000000000000000000000000000000000000000000000000000002" + + "4fd0c6e8ed03c4e7797c4da435e5da8b7ecf63c765c8f5817fe29aa4f54e6057" + + "fc5dda67c0109f8ce48344c9c55fb8081a79ad549bd7d162b3f334a9219f8169" + + "a2f5c0f129ac81ab9f93b13a09ec25b40356420dbfe9aa21d367af61415a6a45" + + "82b5efd3f827c7ca99371b1a029e1781156f068e000fdb26ea1b078ce24ae4e1" + + "571001515de0d6d55d2eb7ed4371397b993b2fe4df3addd53248e3adfc24c6fe" + + "81e7b3679ba49fb7e5ef8c13661e7d442210cac48e93398f6d731b3770fcb23e" + + "01c0d34d139df0c31c1dbdf8b08fe0d6029845b1abc990986408191905d04e76" + + "44dd0fc25446d753e94638ee48bb5e088f4483ce9e648093e654ba762ea516df" + + "5bb29cb95cfe347fc2f109ff86d5596bdb89c116b4805b9c6bdc019049b597f3" + + "ee52b22ececc9c7bc4d2c4dd61f9e16bc9feb07a5575f28e577a2d67c1eb3d24" + + "d6583d39f9ea3fe2de10132de6303217cca345201a194ecde8ad098f49d3f63b" + + "2f1f12c99a24d5779e7b4d1e6aa4fc3e1f0bd671701f42e43f3530501e7e2c00" + + "b47f9f2c332b75a849eb94a260a9d2a846212562ec57e927e071962ddc5dda5c" + + "dd9d38d346666659216b4897492ee991b359f9d3adf8bb576720f3b1d49be957" + + "a5c39e894b98bea2538645b434d47e4e7c71fdf765aeae264dd916ff41542eee" + + "063bbed2ff1e40ee1a2a949d5bd197e5936709cdb68151108221b8478fa15d86" + + "d8aff952d21265677a1a363cf7f492de8c0715cb95960d149842e3cee99bdb32\"", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); + PublicMethod.waitProduceNextBlock(blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals(0, infoById.get().getResultValue()); + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000001" + + "0000000000000000000000000000000000000000000000000000000000000040" + + "0000000000000000000000000000000000000000000000000000000000000020" + + "0000000000000000000000000000000000000000000000000000000000000000", + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); + } + + @Test( + enabled = true, + description = "duplicate nullifiers", + groups = {"contract", "daily"}) public void test05DuplicateNullifiers() { String method = "test2(bytes)"; - txid = PublicMethod.triggerContract(contractAddress, method, - "\"0000000000000000000000000000000000000000000000000000000000000520" - + "00000000000000000000000000000000000000000000000000000000000007c0" - + "0000000000000000000000000000000000000000000000000000000000000860" - + "f95c0de8b0b573b6a302be34f42cab92fb84ad87be4c9e7c5016ccf4e5692552" - + "79279550d90ed369e0c60b07bc0ace565391941aff977ea101b221c26c14490d" - + "43b5d1b2f29511ff3425e353eb022493f3771203daff96e326477afbe34f7357" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0d9a42f99c055f6218415145bdd3b18496273ccd579c9370cbb312505e65ac2f" - + "88a987bdf381b7a6c41f5683334f9becdec01ab10fa4976a9b15191b9e33fc5c" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000002" - + "0000000000000000000000000000000000000000000000000000000000000002" - + "0a43f2568d0aca1a589ff1b76a5147123e1b2c76634970378d742088d68187d7" - + "ed942fe6a584633ab56c66b5824fa24e1380d371abf8aedbcae1b45927fcc236" - + "216f0eafbbdee5f09a136f5dedd86ac5a1ebe7317942bc1999cd0b0b1c11b707" - + "295f566ff309ea8510919d2507b558d7f88151746aab05866a8708d1d70acf42" - + "80f40957fe79d81223cbe9f4eef86be1d4ab19fd3f26f6e08aa27477a8b2160f" - + "44de6d5ce257eccdf91ab3de59461420b20ee95a75bd031f117796e9d1995e85" - + "0c8900a176dd7fc60694716ef82d6ba5d72698f5580503575cecf09a912574d0" - + "02d9761fef0f283242404cbadaa10a70270dae33899c626f27cc626e2c7737d7" - + "5cf62af8190938d92f04d9cb4fcab07d98482843c9b062d5a3c48b1d6259f94c" - + "fa6961c578ecd8b87052edd19b7dc9fa168349cc125ed8e9beddb04450e0558b" - + "0a43f2568d0aca1a589ff1b76a5147123e1b2c76634970378d742088d68187d7" - + "ad182389453f849cf316d7d8c1c8b0da2675c404d09a8a7efb6ab4f81e5d253e" - + "2ab630a209d6dbd4446cc274859a4a97175cac7fc9d20544f5df8d5e6cc37856" - + "a305d5f20688846a81e57dd6141049691495e48ad37cf38183408b4e7ff9a250" - + "b449788c9ef60787fa698915b959979713e800c36966dc737032ab5455374854" - + "e31eebc49b73fc73e709962c69da79e4a3eb55c7311d245e671c83213562da8f" - + "751483514e1c9fead10186b95783a29b880f1c443fcb0c12fad1c8f4f1f1f8b2" - + "10792470322970e28ff0f1cff37531a594a164a4af755fa0d7bb9f24c2d4d7df" - + "2ebe0ff20d7a8a01bbc19ea13f92fe1ea3a8676cdb81efaee30ed4a0e15de0e4" - + "7ce1f4304ad9b824b08f26d655c2c04cdb1e1bf69f8796d5360af32193cceb26" - + "0000000000000000000000000000000000000000000000000000000000000002" - + "36ecefb9a2264d4515ef9c1dc23bd8de87930c2434c3426df4b12afc17ccde46" - + "8e6a99a43572ea6c6110db239cd60627e927d339dfad1920bb88ce2335d91e07" - + "eb6968339a770e46c2c7acbedfdcf93678493f2d3ea03c4a78a2f28925e0e5b4" - + "632d959daaa129e79901713f5b8e3a233219371473b5c8f494dc28bceb399508" - + "0000000000000000000000000000000000000000000000000000000000000001" - + "14c1d485df7f471413cf90be5bae3909ccb5812fbee683f91e1fc5b7178d8852" - + "51a559f6632e3beb24ed1e781de05d6fbb2a4600dd9b2195cdf378a18e2a31ed" - + "49936339e06e29754fe00956cde97338c627806596d681de95db6653d110a7a3" - + "95617c958e1c4d81d4baa99b295bddd6c3da2d4fb9dddc886d31461224ed423a" - + "68c4b504cbed65a19a43efe8c7f721cc9406d8251ca03bbdc6217f6f02077b45" - + "02a1db7de8fab00edc14df913fd7369c4e28294086bd2cb86bd1559133f211b6" - + "1382886e7feb401fdb9fc6ac186dd133d456a7a220615bb410ad79da8b0fb7b7" - + "c404341cf42246820f2afb70466b08658d55b24d3a53707ed88b82827e1358d0" - + "2fe7e8c746f6f7124d2dd3d1717d2859e8390f8f76147e1c767831924058ce70\"", - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + method, + "\"0000000000000000000000000000000000000000000000000000000000000520" + + "00000000000000000000000000000000000000000000000000000000000007c0" + + "0000000000000000000000000000000000000000000000000000000000000860" + + "f95c0de8b0b573b6a302be34f42cab92fb84ad87be4c9e7c5016ccf4e5692552" + + "79279550d90ed369e0c60b07bc0ace565391941aff977ea101b221c26c14490d" + + "43b5d1b2f29511ff3425e353eb022493f3771203daff96e326477afbe34f7357" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0d9a42f99c055f6218415145bdd3b18496273ccd579c9370cbb312505e65ac2f" + + "88a987bdf381b7a6c41f5683334f9becdec01ab10fa4976a9b15191b9e33fc5c" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000002" + + "0000000000000000000000000000000000000000000000000000000000000002" + + "0a43f2568d0aca1a589ff1b76a5147123e1b2c76634970378d742088d68187d7" + + "ed942fe6a584633ab56c66b5824fa24e1380d371abf8aedbcae1b45927fcc236" + + "216f0eafbbdee5f09a136f5dedd86ac5a1ebe7317942bc1999cd0b0b1c11b707" + + "295f566ff309ea8510919d2507b558d7f88151746aab05866a8708d1d70acf42" + + "80f40957fe79d81223cbe9f4eef86be1d4ab19fd3f26f6e08aa27477a8b2160f" + + "44de6d5ce257eccdf91ab3de59461420b20ee95a75bd031f117796e9d1995e85" + + "0c8900a176dd7fc60694716ef82d6ba5d72698f5580503575cecf09a912574d0" + + "02d9761fef0f283242404cbadaa10a70270dae33899c626f27cc626e2c7737d7" + + "5cf62af8190938d92f04d9cb4fcab07d98482843c9b062d5a3c48b1d6259f94c" + + "fa6961c578ecd8b87052edd19b7dc9fa168349cc125ed8e9beddb04450e0558b" + + "0a43f2568d0aca1a589ff1b76a5147123e1b2c76634970378d742088d68187d7" + + "ad182389453f849cf316d7d8c1c8b0da2675c404d09a8a7efb6ab4f81e5d253e" + + "2ab630a209d6dbd4446cc274859a4a97175cac7fc9d20544f5df8d5e6cc37856" + + "a305d5f20688846a81e57dd6141049691495e48ad37cf38183408b4e7ff9a250" + + "b449788c9ef60787fa698915b959979713e800c36966dc737032ab5455374854" + + "e31eebc49b73fc73e709962c69da79e4a3eb55c7311d245e671c83213562da8f" + + "751483514e1c9fead10186b95783a29b880f1c443fcb0c12fad1c8f4f1f1f8b2" + + "10792470322970e28ff0f1cff37531a594a164a4af755fa0d7bb9f24c2d4d7df" + + "2ebe0ff20d7a8a01bbc19ea13f92fe1ea3a8676cdb81efaee30ed4a0e15de0e4" + + "7ce1f4304ad9b824b08f26d655c2c04cdb1e1bf69f8796d5360af32193cceb26" + + "0000000000000000000000000000000000000000000000000000000000000002" + + "36ecefb9a2264d4515ef9c1dc23bd8de87930c2434c3426df4b12afc17ccde46" + + "8e6a99a43572ea6c6110db239cd60627e927d339dfad1920bb88ce2335d91e07" + + "eb6968339a770e46c2c7acbedfdcf93678493f2d3ea03c4a78a2f28925e0e5b4" + + "632d959daaa129e79901713f5b8e3a233219371473b5c8f494dc28bceb399508" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "14c1d485df7f471413cf90be5bae3909ccb5812fbee683f91e1fc5b7178d8852" + + "51a559f6632e3beb24ed1e781de05d6fbb2a4600dd9b2195cdf378a18e2a31ed" + + "49936339e06e29754fe00956cde97338c627806596d681de95db6653d110a7a3" + + "95617c958e1c4d81d4baa99b295bddd6c3da2d4fb9dddc886d31461224ed423a" + + "68c4b504cbed65a19a43efe8c7f721cc9406d8251ca03bbdc6217f6f02077b45" + + "02a1db7de8fab00edc14df913fd7369c4e28294086bd2cb86bd1559133f211b6" + + "1382886e7feb401fdb9fc6ac186dd133d456a7a220615bb410ad79da8b0fb7b7" + + "c404341cf42246820f2afb70466b08658d55b24d3a53707ed88b82827e1358d0" + + "2fe7e8c746f6f7124d2dd3d1717d2859e8390f8f76147e1c767831924058ce70\"", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000001" + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000040" + "0000000000000000000000000000000000000000000000000000000000000020" + "0000000000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "duplicate output note", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "duplicate output note", + groups = {"contract", "daily"}) public void test06DuplicateOutputNote() { String method = "test2(bytes)"; - txid = PublicMethod.triggerContract(contractAddress, method, - "\"0000000000000000000000000000000000000000000000000000000000000520" - + "0000000000000000000000000000000000000000000000000000000000000680" - + "00000000000000000000000000000000000000000000000000000000000006e0" - + "9144cda061b41702bbf641dc3864fa94bc934511895058f01b7bfbdbdb301f8c" - + "d43a44ccd4b131e6b37bd673f8ac6e554eb5b4ab599b6d2b66bc294b7767f506" - + "24614ac147e95287ff8351ed22aa43f2b3e82460dc79b57952e8a39bf4027c47" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "73792777f50b3c5cf7fcf88c7d24baf975c0b4132f2affa898df03874b3e8163" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000001" - + "0000000000000000000000000000000000000000000000000000000000000001" - + "92a3ddb4b05a3903fd1d9693e047c7136ac048fd12a7384bfd569e57a265b1f9" - + "2e96a076fcd5722ff4e04bc31cec8aeb2fa5ee3006104a3046c28c4a1584293f" - + "d02e3f11e3ca072628d2fa4755699958223e3467ef7c2039ff699fd9616a5921" - + "0624e9ba16fc55a77d6d872854c638a1c3b6570267130cb43770661793fa9fda" - + "9406c39d8388060ece340e133238f9452e990d1adcc2a91a0bfe46403489043b" - + "51ac2c88e5f0f4fe74b65eb30ec50400a5334a59f3f7f425073edf66bc3ca8cf" - + "f599d1f6742d1ebf0e40dce32d81a4a5cafb1c0ec078a692b95c97265cce277c" - + "11bf7216ff5df3d0d916359abe8b1a5dedf30e5bd5ccf24e6659adc9a4db9558" - + "6369477f2a15447a56249fa1703f31b7b3800aff0cf67772d132bd74cf888ee5" - + "4f45236c6687ac59c89a6157e001bd5190fadba40d515f739636a7dbd77b5108" - + "0000000000000000000000000000000000000000000000000000000000000001" - + "59eca5d4562a891db660355de4de8c14afa64332a8c58afc44108798fc070cba" - + "e90d708016a0f09278a895325c538a0773a011aa9f132dce77e073f39b864606" - + "0000000000000000000000000000000000000000000000000000000000000002" - + "23540e10b3989fc8efdcadda1bcb840cce8580b45718082d5ace9fc4a6f4d45b" - + "d3ad992cbf4a32ece6a7911992c82b94a54705f7fbe680b5250c9b05cb1a31ca" - + "0d26babfd7f9614d5b3cbe84c7006f4aebcea2977d31c9761c5f7ef9c4b0a8eb" - + "98c35f51cd4ed7eef014a56ae50b4efb6555d497991ff7b282183d82f19282d5" - + "5ce8b8f286f6bdeae73981db2a615c7cb9c4fdaa7618502480945647aa1e98eb" - + "4dab59853f9bb3327f7ecbfd92fde4e2f49968562b468ca060447f1036172075" - + "163840bd0f1dca2495392228e23bf49b0934e14a145be29a9e42fb8477925c9f" - + "5a18093e51748a2494ee9191e16511bbae6d8c71d188c46286dd6dc5213b1d7f" - + "95eab6bade1ee763656b06c95d8e907dd8f3310722024cb9322d17724757f686" - + "23540e10b3989fc8efdcadda1bcb840cce8580b45718082d5ace9fc4a6f4d45b" - + "77b1609896bde81495ab555869c6ddbc5c7aac7274830f505486682093284fb6" - + "6f4aeab08e6417ab85026d97aeedfa26407b867227639653ec7a2fb529eb3e9f" - + "a207cb75c8eeb1c77fc3fc9949fc9c95e4b98806a9c6d7558f1f4e8f2a87df47" - + "375dc915db5332f6abbd87967796875ea8922e70e9ba135cdeabd171273884a9" - + "107992ee1a521f648c499620299a45031821e0639abadeec464a3ec3f439a823" - + "15bfe031aaaba0e3bc80fc359d7c7722e448e1e671447c41592cc0f27d35e1bc" - + "b5a4dd42ac75418f70f1a23f0de47fb6a2985ff86958816e52067612df232aa6" - + "9b5cedeab709b800eacc4b2d81582e4bb4f0a0e51571a5b03816126b39e1c9ab\"", - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + method, + "\"0000000000000000000000000000000000000000000000000000000000000520" + + "0000000000000000000000000000000000000000000000000000000000000680" + + "00000000000000000000000000000000000000000000000000000000000006e0" + + "9144cda061b41702bbf641dc3864fa94bc934511895058f01b7bfbdbdb301f8c" + + "d43a44ccd4b131e6b37bd673f8ac6e554eb5b4ab599b6d2b66bc294b7767f506" + + "24614ac147e95287ff8351ed22aa43f2b3e82460dc79b57952e8a39bf4027c47" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "73792777f50b3c5cf7fcf88c7d24baf975c0b4132f2affa898df03874b3e8163" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "92a3ddb4b05a3903fd1d9693e047c7136ac048fd12a7384bfd569e57a265b1f9" + + "2e96a076fcd5722ff4e04bc31cec8aeb2fa5ee3006104a3046c28c4a1584293f" + + "d02e3f11e3ca072628d2fa4755699958223e3467ef7c2039ff699fd9616a5921" + + "0624e9ba16fc55a77d6d872854c638a1c3b6570267130cb43770661793fa9fda" + + "9406c39d8388060ece340e133238f9452e990d1adcc2a91a0bfe46403489043b" + + "51ac2c88e5f0f4fe74b65eb30ec50400a5334a59f3f7f425073edf66bc3ca8cf" + + "f599d1f6742d1ebf0e40dce32d81a4a5cafb1c0ec078a692b95c97265cce277c" + + "11bf7216ff5df3d0d916359abe8b1a5dedf30e5bd5ccf24e6659adc9a4db9558" + + "6369477f2a15447a56249fa1703f31b7b3800aff0cf67772d132bd74cf888ee5" + + "4f45236c6687ac59c89a6157e001bd5190fadba40d515f739636a7dbd77b5108" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "59eca5d4562a891db660355de4de8c14afa64332a8c58afc44108798fc070cba" + + "e90d708016a0f09278a895325c538a0773a011aa9f132dce77e073f39b864606" + + "0000000000000000000000000000000000000000000000000000000000000002" + + "23540e10b3989fc8efdcadda1bcb840cce8580b45718082d5ace9fc4a6f4d45b" + + "d3ad992cbf4a32ece6a7911992c82b94a54705f7fbe680b5250c9b05cb1a31ca" + + "0d26babfd7f9614d5b3cbe84c7006f4aebcea2977d31c9761c5f7ef9c4b0a8eb" + + "98c35f51cd4ed7eef014a56ae50b4efb6555d497991ff7b282183d82f19282d5" + + "5ce8b8f286f6bdeae73981db2a615c7cb9c4fdaa7618502480945647aa1e98eb" + + "4dab59853f9bb3327f7ecbfd92fde4e2f49968562b468ca060447f1036172075" + + "163840bd0f1dca2495392228e23bf49b0934e14a145be29a9e42fb8477925c9f" + + "5a18093e51748a2494ee9191e16511bbae6d8c71d188c46286dd6dc5213b1d7f" + + "95eab6bade1ee763656b06c95d8e907dd8f3310722024cb9322d17724757f686" + + "23540e10b3989fc8efdcadda1bcb840cce8580b45718082d5ace9fc4a6f4d45b" + + "77b1609896bde81495ab555869c6ddbc5c7aac7274830f505486682093284fb6" + + "6f4aeab08e6417ab85026d97aeedfa26407b867227639653ec7a2fb529eb3e9f" + + "a207cb75c8eeb1c77fc3fc9949fc9c95e4b98806a9c6d7558f1f4e8f2a87df47" + + "375dc915db5332f6abbd87967796875ea8922e70e9ba135cdeabd171273884a9" + + "107992ee1a521f648c499620299a45031821e0639abadeec464a3ec3f439a823" + + "15bfe031aaaba0e3bc80fc359d7c7722e448e1e671447c41592cc0f27d35e1bc" + + "b5a4dd42ac75418f70f1a23f0de47fb6a2985ff86958816e52067612df232aa6" + + "9b5cedeab709b800eacc4b2d81582e4bb4f0a0e51571a5b03816126b39e1c9ab\"", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000001" + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000040" + "0000000000000000000000000000000000000000000000000000000000000020" + "0000000000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "checkResult is false", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "checkResult is false", + groups = {"contract", "daily"}) public void test07CheckResultIsFalse() { String method = "test2(bytes)"; - txid = PublicMethod.triggerContract(contractAddress, method, - "\"0000000000000000000000000000000000000000000000000000000000000520" - + "0000000000000000000000000000000000000000000000000000000000000680" - + "00000000000000000000000000000000000000000000000000000000000006e0" - + "f3e912b1f0d8e6a6654c1e9ff16d9eb5c2895b35490a5fa825d275d842efb5e5" - + "45ae827a6fb105d6fc6d125c2a8c1253f753b4973a6505b671b0c86b6ef8ac86" - + "4f4aca9fdf2a460e95df34315749ac432cd5154ad42217b7296b3b5bd81dd00b" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "363f4cb9b6605bbd39b3ccf4fdc834721afc8d38cd25becc7830dab5cacf1852" - + "32431ad6d4cfa89730b413b4ca2f744623a0b4b8315fc5e307ed62a043fa4064" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000003" - + "0000000000000000000000000000000000000000000000000000000000000001" - + "66b02f76abecb4de13adc2b9b48edf60edf7e243dba5930276655936b53019ee" - + "626327f3509cadc915c8df9d9f97e17f244c828f3ad82b19f6701ae09dc0e22e" - + "659d5386266aef0a8434fe2ac728a655071f4688ad6cd1dae6e58e4767e1a36a" - + "d2614240434f15b189c8f235e35b281454988d72518df3068d8f512fe992e564" - + "a27d2c53207376e3f179aed8f415acbe1bca1a9ec60188f6fea1d1fd99f80db2" - + "c70271638ea0aa5d99e49fca76157e7692c856f4056b7857ed5ce852e69c713f" - + "42dd888295906c9988cc7fdd6715ea2dac745e97fa8ffd63653ee8e17b8a2ada" - + "1148bed585f91c1ab2f38f77e78a4dacd86587ac899961665e0a6f34d7cf0a41" - + "0f1032d3c26d0ab381ba3fd45f1cbb36b04f889584c1868fdc448eaab9bb8592" - + "d91a58c9e735862cdd346201fb9ab75999c6a57a6a474f2248f71c631375f0a8" - + "0000000000000000000000000000000000000000000000000000000000000001" - + "8dcbff6a27f4e6b39c6e19aab7deb9427368bc8dc1082f0dfe57edc94fbb8c3e" - + "1eb36d9f48c5243dad16ab511dcea3c8489ba0dd774befb12fc58f1ae50e7504" - + "0000000000000000000000000000000000000000000000000000000000000001" - + "9fa6ed64a910bee735eafdb80636852367f6a487f6aec0598708ad80cad8ed09" - + "7aa9686c3cc957f88703e1eea87c5412baba2044c78e9161a7b2ac2b21bfef9b" - + "83ca769ba273d3fe1d4cc0d5d0d1ab8a6540f220c1db981fc8885ee34b51263f" - + "90f31816d21895f518bbb893c62ce296ee8416486c37b9dba9d0cb3cdd5f58c5" - + "7e175a69dbf443509bc060f354862d9787490de120ae665cbcba894854eb8aaf" - + "b811e676c506f7c4f2038afa09fc56b66c0c9cefcc00d780d152f1633d1c90af" - + "058355203f7737de6184b08bbf84248f118c3b540a7dc8f5518676fe0ebb2b35" - + "e4c3ec5f6b2f93138c7e7aa4a9b631dc9786b6df2d317208f220055d3fcab328" - + "d50b3131146a9b97443fca616d401b0f5e7c51b3c71b91c3637df35cf4b91864\"", - false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + method, + "\"0000000000000000000000000000000000000000000000000000000000000520" + + "0000000000000000000000000000000000000000000000000000000000000680" + + "00000000000000000000000000000000000000000000000000000000000006e0" + + "f3e912b1f0d8e6a6654c1e9ff16d9eb5c2895b35490a5fa825d275d842efb5e5" + + "45ae827a6fb105d6fc6d125c2a8c1253f753b4973a6505b671b0c86b6ef8ac86" + + "4f4aca9fdf2a460e95df34315749ac432cd5154ad42217b7296b3b5bd81dd00b" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "363f4cb9b6605bbd39b3ccf4fdc834721afc8d38cd25becc7830dab5cacf1852" + + "32431ad6d4cfa89730b413b4ca2f744623a0b4b8315fc5e307ed62a043fa4064" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000003" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "66b02f76abecb4de13adc2b9b48edf60edf7e243dba5930276655936b53019ee" + + "626327f3509cadc915c8df9d9f97e17f244c828f3ad82b19f6701ae09dc0e22e" + + "659d5386266aef0a8434fe2ac728a655071f4688ad6cd1dae6e58e4767e1a36a" + + "d2614240434f15b189c8f235e35b281454988d72518df3068d8f512fe992e564" + + "a27d2c53207376e3f179aed8f415acbe1bca1a9ec60188f6fea1d1fd99f80db2" + + "c70271638ea0aa5d99e49fca76157e7692c856f4056b7857ed5ce852e69c713f" + + "42dd888295906c9988cc7fdd6715ea2dac745e97fa8ffd63653ee8e17b8a2ada" + + "1148bed585f91c1ab2f38f77e78a4dacd86587ac899961665e0a6f34d7cf0a41" + + "0f1032d3c26d0ab381ba3fd45f1cbb36b04f889584c1868fdc448eaab9bb8592" + + "d91a58c9e735862cdd346201fb9ab75999c6a57a6a474f2248f71c631375f0a8" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "8dcbff6a27f4e6b39c6e19aab7deb9427368bc8dc1082f0dfe57edc94fbb8c3e" + + "1eb36d9f48c5243dad16ab511dcea3c8489ba0dd774befb12fc58f1ae50e7504" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "9fa6ed64a910bee735eafdb80636852367f6a487f6aec0598708ad80cad8ed09" + + "7aa9686c3cc957f88703e1eea87c5412baba2044c78e9161a7b2ac2b21bfef9b" + + "83ca769ba273d3fe1d4cc0d5d0d1ab8a6540f220c1db981fc8885ee34b51263f" + + "90f31816d21895f518bbb893c62ce296ee8416486c37b9dba9d0cb3cdd5f58c5" + + "7e175a69dbf443509bc060f354862d9787490de120ae665cbcba894854eb8aaf" + + "b811e676c506f7c4f2038afa09fc56b66c0c9cefcc00d780d152f1633d1c90af" + + "058355203f7737de6184b08bbf84248f118c3b540a7dc8f5518676fe0ebb2b35" + + "e4c3ec5f6b2f93138c7e7aa4a9b631dc9786b6df2d317208f220055d3fcab328" + + "d50b3131146a9b97443fca616d401b0f5e7c51b3c71b91c3637df35cf4b91864\"", + false, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); - Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000001" + Assert.assertEquals( + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000040" + "0000000000000000000000000000000000000000000000000000000000000020" + "0000000000000000000000000000000000000000000000000000000000000000", ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())); } - @Test(enabled = true, description = "normal", groups = {"contract", "daily"}) + @Test( + enabled = true, + description = "normal", + groups = {"contract", "daily"}) public void test08Normal() { - String method = "test3(bytes32[10][],bytes32[2][],bytes32[9][]" - + ",bytes32[2],bytes32,uint64,bytes32[33],uint256)"; - txid = PublicMethod.triggerContract(contractAddress, method, - "0000000000000000000000000000000000000000000000000000000000000520" - + "0000000000000000000000000000000000000000000000000000000000000680" - + "00000000000000000000000000000000000000000000000000000000000006e0" - + "f3e912b1f0d8e6a6654c1e9ff16d9eb5c2895b35490a5fa825d275d842efb5e5" - + "45ae827a6fb105d6fc6d125c2a8c1253f753b4973a6505b671b0c01b6ef3ac06" - + "4f4aca9fdf2a460e95df34315749ac432cd5154ad42217b7296b3b5bd81dd00b" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "363f4cb9b6605bbd39b3ccf4fdc834721afc8d38cd25becc7830dab5cacf1852" - + "32431ad6d4cfa89730b413b4ca2f744623a0b4b8315fc5e307ed62a043fa4064" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000003" - + "0000000000000000000000000000000000000000000000000000000000000001" - + "66b02f76abecb4de13adc2b9b48edf60edf7e243dba5930276655936b53019ee" - + "626327f3509cadc915c8df9d9f97e17f244c828f3ad82b19f6701ae09dc0e22e" - + "659d5386266aef0a8434fe2ac728a655071f4688ad6cd1dae6e58e4767e1a36a" - + "d2614240434f15b189c8f235e35b281454988d72518df3068d8f512fe992e564" - + "a27d2c53207376e3f179aed8f415acbe1bca1a9ec60188f6fea1d1fd99f80db2" - + "c70271638ea0aa5d99e49fca76157e7692c856f4056b7857ed5ce852e69c713f" - + "42dd888295906c9988cc7fdd6715ea2dac745e97fa8ffd63653ee8e17b8a2ada" - + "1148bed585f91c1ab2f38f77e78a4dacd86587ac899961665e0a6f34d7cf0a41" - + "0f1032d3c26d0ab381ba3fd45f1cbb36b04f889584c1868fdc448eaab9bb8592" - + "d91a58c9e735862cdd346201fb9ab75999c6a57a6a474f2248f71c631375f0a8" - + "0000000000000000000000000000000000000000000000000000000000000001" - + "8dcbff6a27f4e6b39c6e19aab7deb9427368bc8dc1082f0dfe57edc94fbb8c3e" - + "1eb36d9f48c5243dad16ab511dcea3c8489ba0dd774befb12fc58f1ae50e7504" - + "0000000000000000000000000000000000000000000000000000000000000001" - + "9fa6ed64a910bee735eafdb80636852367f6a487f6aec0598708ad80cad8ed09" - + "7aa9686c3cc957f88703e1eea87c5412baba2044c78e9161a7b2ac2b21bfef9b" - + "83ca769ba273d3fe1d4cc0d5d0d1ab8a6540f220c1db981fc8885ee34b51263f" - + "90f31816d21895f518bbb893c62ce296ee8416486c37b9dba9d0cb3cdd5f58c5" - + "7e175a69dbf443509bc060f354862d9787490de120ae665cbcba894854eb8aaf" - + "b811e676c506f7c4f2038afa09fc56b66c0c9cefcc00d780d152f1633d1c90af" - + "058355203f7737de6184b08bbf84248f118c3b540a7dc8f5518676fe0ebb2b35" - + "e4c3ec5f6b2f93138c7e7aa4a9b631dc9786b6df2d317208f220055d3fcab328" - + "d50b3131146a9b97443fca616d401b0f5e7c51b3c71b91c3637df35cf4b91864", - true, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + String method = + "test3(bytes32[10][],bytes32[2][],bytes32[9][]" + + ",bytes32[2],bytes32,uint64,bytes32[33],uint256)"; + txid = + PublicMethod.triggerContract( + contractAddress, + method, + "0000000000000000000000000000000000000000000000000000000000000520" + + "0000000000000000000000000000000000000000000000000000000000000680" + + "00000000000000000000000000000000000000000000000000000000000006e0" + + "f3e912b1f0d8e6a6654c1e9ff16d9eb5c2895b35490a5fa825d275d842efb5e5" + + "45ae827a6fb105d6fc6d125c2a8c1253f753b4973a6505b671b0c01b6ef3ac06" + + "4f4aca9fdf2a460e95df34315749ac432cd5154ad42217b7296b3b5bd81dd00b" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "363f4cb9b6605bbd39b3ccf4fdc834721afc8d38cd25becc7830dab5cacf1852" + + "32431ad6d4cfa89730b413b4ca2f744623a0b4b8315fc5e307ed62a043fa4064" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000003" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "66b02f76abecb4de13adc2b9b48edf60edf7e243dba5930276655936b53019ee" + + "626327f3509cadc915c8df9d9f97e17f244c828f3ad82b19f6701ae09dc0e22e" + + "659d5386266aef0a8434fe2ac728a655071f4688ad6cd1dae6e58e4767e1a36a" + + "d2614240434f15b189c8f235e35b281454988d72518df3068d8f512fe992e564" + + "a27d2c53207376e3f179aed8f415acbe1bca1a9ec60188f6fea1d1fd99f80db2" + + "c70271638ea0aa5d99e49fca76157e7692c856f4056b7857ed5ce852e69c713f" + + "42dd888295906c9988cc7fdd6715ea2dac745e97fa8ffd63653ee8e17b8a2ada" + + "1148bed585f91c1ab2f38f77e78a4dacd86587ac899961665e0a6f34d7cf0a41" + + "0f1032d3c26d0ab381ba3fd45f1cbb36b04f889584c1868fdc448eaab9bb8592" + + "d91a58c9e735862cdd346201fb9ab75999c6a57a6a474f2248f71c631375f0a8" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "8dcbff6a27f4e6b39c6e19aab7deb9427368bc8dc1082f0dfe57edc94fbb8c3e" + + "1eb36d9f48c5243dad16ab511dcea3c8489ba0dd774befb12fc58f1ae50e7504" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "9fa6ed64a910bee735eafdb80636852367f6a487f6aec0598708ad80cad8ed09" + + "7aa9686c3cc957f88703e1eea87c5412baba2044c78e9161a7b2ac2b21bfef9b" + + "83ca769ba273d3fe1d4cc0d5d0d1ab8a6540f220c1db981fc8885ee34b51263f" + + "90f31816d21895f518bbb893c62ce296ee8416486c37b9dba9d0cb3cdd5f58c5" + + "7e175a69dbf443509bc060f354862d9787490de120ae665cbcba894854eb8aaf" + + "b811e676c506f7c4f2038afa09fc56b66c0c9cefcc00d780d152f1633d1c90af" + + "058355203f7737de6184b08bbf84248f118c3b540a7dc8f5518676fe0ebb2b35" + + "e4c3ec5f6b2f93138c7e7aa4a9b631dc9786b6df2d317208f220055d3fcab328" + + "d50b3131146a9b97443fca616d401b0f5e7c51b3c71b91c3637df35cf4b91864", + true, + 0, + maxFeeLimit, + contractExcAddress, + contractExcKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0, infoById.get().getResultValue()); -// Assert.assertTrue( -// ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()).length() > 10000); + // Assert.assertTrue( + // ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()).length() > + // 10000); String result = ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()); - String offset = result.substring(0,64); - String length = result.substring(64,128); - String data1 = result.substring(128,192); - String data2 = result.substring(192,256); - String data3 = result.substring(256,320); - String data4 = result.substring(320,384); - String data5 = result.substring(384,448); + String offset = result.substring(0, 64); + String length = result.substring(64, 128); + String data1 = result.substring(128, 192); + String data2 = result.substring(192, 256); + String data3 = result.substring(256, 320); + String data4 = result.substring(320, 384); + String data5 = result.substring(384, 448); Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000020", offset); Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000005", length); Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000001", data1); @@ -781,17 +904,19 @@ public void test08Normal() { Assert.assertEquals("83a36b13f04fa5302213ae219b2bc77dd58deece0c2aa6311bce815a761c3f3b", data3); Assert.assertEquals("94d22bf13665a04532f94d9822f79317670ade963b70feb2053755c5f36e1450", data4); Assert.assertEquals("ae12ac48beebcaccbb395d4f532944cfead09a4c0ee09c1cb49742b7b6188669", data5); - } @AfterClass public void shutdown() throws InterruptedException { long balance = PublicMethod.queryAccount(contractExcKey, blockingStubFull).getBalance(); - PublicMethod - .sendcoin(testNetAccountAddress, balance - 1000000, contractExcAddress, contractExcKey, - blockingStubFull); if (channelFull1 != null) { + PublicMethod.sendcoin( + testNetAccountAddress, + balance - 1000000, + contractExcAddress, + contractExcKey, + blockingStubFull); + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/votereward/VoteRewardTest001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/votereward/VoteRewardTest001.java index 0a683f29..07f6f45b 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/votereward/VoteRewardTest001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/votereward/VoteRewardTest001.java @@ -13,7 +13,6 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.RetryUtil; import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.TronConstants; import stest.tron.wallet.common.client.utils.Utils; @@ -21,8 +20,8 @@ /** * TIP-271: Vote reward distribution tests. * - *

Tests the SR reward mechanism: voters receive rewards proportional to - * their vote weight, minus the SR brokerage fee. + *

Tests the SR reward mechanism: voters receive rewards proportional to their vote weight, minus + * the SR brokerage fee. */ @Slf4j public class VoteRewardTest001 extends TronBaseTest { @@ -34,45 +33,61 @@ public class VoteRewardTest001 extends TronBaseTest { @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(voterKey); - Assert.assertTrue(PublicMethod.sendcoin(voterAddress, TronConstants.TEN_THOUSAND_TRX, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + voterAddress, + TronConstants.TEN_THOUSAND_TRX, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = true, description = "Query reward info for witness account", + @Test( + enabled = true, + description = "Query reward info for witness account", groups = {"daily"}) public void test01QueryWitnessRewardInfo() { - BytesMessage bytesMessage = BytesMessage.newBuilder() - .setValue(ByteString.copyFrom(witnessAddress)).build(); + BytesMessage bytesMessage = + BytesMessage.newBuilder().setValue(ByteString.copyFrom(witnessAddress)).build(); NumberMessage reward = blockingStubFull.getRewardInfo(bytesMessage); logger.info("Witness reward: {}", reward.getNum()); Assert.assertTrue(reward.getNum() >= 0, "Witness reward should be non-negative"); } - @Test(enabled = true, description = "Query brokerage for witness", + @Test( + enabled = true, + description = "Query brokerage for witness", groups = {"daily"}) public void test02QueryWitnessBrokerage() { long brokerage = PublicMethod.getBrokerage(witnessAddress, blockingStubFull); logger.info("Witness brokerage: {}%", brokerage); - Assert.assertTrue(brokerage >= 0 && brokerage <= 100, - "Brokerage should be between 0 and 100"); + Assert.assertTrue(brokerage >= 0 && brokerage <= 100, "Brokerage should be between 0 and 100"); } - @Test(enabled = true, description = "Freeze TRX, vote for witness, and verify vote count", + @Test( + enabled = true, + description = "Freeze TRX, vote for witness, and verify vote count", groups = {"daily"}) public void test03FreezeAndVote() { // Freeze for voting power (Tron Power) - Assert.assertTrue(PublicMethod.freezeBalanceGetTronPower( - voterAddress, TronConstants.THOUSAND_TRX, 0, - TronConstants.FREEZE_TRON_POWER, null, voterKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetTronPower( + voterAddress, + TronConstants.THOUSAND_TRX, + 0, + TronConstants.FREEZE_TRON_POWER, + null, + voterKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); // Vote for witness HashMap witnessMap = new HashMap<>(); long voteCount = TronConstants.THOUSAND_TRX / TronConstants.ONE_TRX; witnessMap.put(witnessAddress, voteCount); - Assert.assertTrue(PublicMethod.voteWitness(voterAddress, voterKey, - witnessMap, blockingStubFull)); + Assert.assertTrue( + PublicMethod.voteWitness(voterAddress, voterKey, witnessMap, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); // Verify vote was recorded @@ -81,43 +96,54 @@ public void test03FreezeAndVote() { logger.info("Vote count: {}", voterAccount.getVotes(0).getVoteCount()); } - @Test(enabled = true, description = "Query voter reward after voting", + @Test( + enabled = true, + description = "Query voter reward after voting", groups = {"daily"}) public void test04QueryVoterReward() { - BytesMessage bytesMessage = BytesMessage.newBuilder() - .setValue(ByteString.copyFrom(voterAddress)).build(); + BytesMessage bytesMessage = + BytesMessage.newBuilder().setValue(ByteString.copyFrom(voterAddress)).build(); NumberMessage reward = blockingStubFull.getRewardInfo(bytesMessage); logger.info("Voter reward after voting: {}", reward.getNum()); // Reward may be 0 if not enough maintenance cycles have passed Assert.assertTrue(reward.getNum() >= 0, "Voter reward should be non-negative"); } - @Test(enabled = true, description = "Vote with zero TronPower should fail", + @Test( + enabled = true, + description = "Vote with zero TronPower should fail", groups = {"daily"}) public void test05VoteWithoutTronPower() { ECKey noFreezeKey = new ECKey(Utils.getRandom()); byte[] noFreezeAddr = noFreezeKey.getAddress(); String noFreezeKeyStr = ByteArray.toHexString(noFreezeKey.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(noFreezeAddr, TronConstants.TEN_TRX, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + noFreezeAddr, + TronConstants.TEN_TRX, + foundationAddress, + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); HashMap witnessMap = new HashMap<>(); witnessMap.put(witnessAddress, 1L); - Assert.assertFalse(PublicMethod.voteWitness(noFreezeAddr, noFreezeKeyStr, - witnessMap, blockingStubFull), + Assert.assertFalse( + PublicMethod.voteWitness(noFreezeAddr, noFreezeKeyStr, witnessMap, blockingStubFull), "Voting without frozen TronPower should fail"); } - @Test(enabled = true, description = "Vote exceeding TronPower limit should fail", + @Test( + enabled = true, + description = "Vote exceeding TronPower limit should fail", groups = {"daily"}) public void test06VoteExceedingLimit() { long tronPowerLimit = TronConstants.THOUSAND_TRX / TronConstants.ONE_TRX; HashMap witnessMap = new HashMap<>(); witnessMap.put(witnessAddress, tronPowerLimit + 1); - Assert.assertFalse(PublicMethod.voteWitness(voterAddress, voterKey, - witnessMap, blockingStubFull), + Assert.assertFalse( + PublicMethod.voteWitness(voterAddress, voterKey, witnessMap, blockingStubFull), "Voting more than available TronPower should fail"); } diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken001.java index 4df3010c..55b90064 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken001.java @@ -1,6 +1,7 @@ package stest.tron.wallet.dailybuild.zentoken; import com.google.protobuf.ByteString; +import io.grpc.ManagedChannelBuilder; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -13,19 +14,19 @@ import org.tron.api.GrpcAPI.DecryptNotes; import org.tron.api.GrpcAPI.Note; import org.tron.api.GrpcAPI.SpendResult; +import org.tron.api.WalletGrpc; import org.tron.protos.Protocol.Account; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.ShieldAddressInfo; -import stest.tron.wallet.common.client.utils.Utils; -import io.grpc.ManagedChannelBuilder; -import org.tron.api.WalletGrpc; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class WalletTestZenToken001 extends TronBaseTest { Optional shieldAddressInfo; +public class WalletTestZenToken001 extends TronBaseTest { + Optional shieldAddressInfo; String shieldAddress; List shieldOutList = new ArrayList<>(); List shieldInputList = new ArrayList<>(); @@ -35,38 +36,54 @@ public class WalletTestZenToken001 extends TronBaseTest { Optional sendShieldAddressInfo; + private static ByteString assetAccountId = null; + Optional sendShieldAddressInfo; Optional receiverShieldAddressInfo; String sendShieldAddress; String receiverShieldAddress; @@ -46,80 +46,90 @@ public class WalletTestZenToken002 extends TronBaseTest { String zenTokenOwnerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelSolidity1 = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity1 = null; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - private String soliditynode1 = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1); - private String soliInPbft = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(2); - private String foundationZenTokenKey = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenOwnerKey"); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + private String soliditynode1 = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); + private String soliInPbft = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(2); + private String foundationZenTokenKey = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenOwnerKey"); byte[] foundationZenTokenAddress = PublicMethod.getFinalAddress(foundationZenTokenKey); - private String zenTokenId = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenId"); + private String zenTokenId = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenId"); private byte[] tokenId = zenTokenId.getBytes(); - private Long zenTokenFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.zenTokenFee"); + private Long zenTokenFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.zenTokenFee"); private Long costTokenAmount = 10 * zenTokenFee; private Long sendTokenAmount = 8 * zenTokenFee; - /** - * constructor. - */ + /** constructor. */ - - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initPbftChannel(); initSolidityChannel(); PublicMethod.printAddress(foundationZenTokenKey); - PublicMethod.printAddress(zenTokenOwnerKey); channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - channelSolidity1 = ManagedChannelBuilder.forTarget(soliditynode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(zenTokenOwnerKey); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + channelSolidity1 = ManagedChannelBuilder.forTarget(soliditynode1).usePlaintext().build(); blockingStubSolidity1 = WalletSolidityGrpc.newBlockingStub(channelSolidity1); - channelPbft = ManagedChannelBuilder.forTarget(soliInPbft) - .usePlaintext() - .build(); - Assert.assertTrue(PublicMethod.transferAsset(zenTokenOwnerAddress, tokenId, - costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull)); + channelPbft = ManagedChannelBuilder.forTarget(soliInPbft).usePlaintext().build(); + Assert.assertTrue( + PublicMethod.transferAsset( + zenTokenOwnerAddress, + tokenId, + costTokenAmount, + foundationZenTokenAddress, + foundationZenTokenKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Args.setFullNodeAllowShieldedTransaction(true); + // Args.setFullNodeAllowShieldedTransaction(true); sendShieldAddressInfo = PublicMethod.generateShieldAddress(); sendShieldAddress = sendShieldAddressInfo.get().getAddress(); logger.info("sendShieldAddressInfo:" + sendShieldAddressInfo); memo = "Shield memo in" + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress, - "" + (sendTokenAmount - zenTokenFee), memo); - Assert.assertTrue(PublicMethod.sendShieldCoin(zenTokenOwnerAddress, sendTokenAmount, null, - null, shieldOutList, null, 0, zenTokenOwnerKey, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, sendShieldAddress, "" + (sendTokenAmount - zenTokenFee), memo); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + zenTokenOwnerAddress, + sendTokenAmount, + null, + null, + shieldOutList, + null, + 0, + zenTokenOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); notes = PublicMethod.listShieldNote(sendShieldAddressInfo, blockingStubFull); sendNote = notes.getNoteTxs(0).getNote(); } - @Test(enabled = false, description = "Get merkle tree voucher info", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "Get merkle tree voucher info", + groups = {"daily", "shield"}) public void test01GetMerkleTreeVoucherInfo() { notes = PublicMethod.listShieldNote(sendShieldAddressInfo, blockingStubFull); sendNote = notes.getNoteTxs(0).getNote(); OutputPointInfo.Builder request = OutputPointInfo.newBuilder(); - //ShieldNoteInfo noteInfo = shieldWrapper.getUtxoMapNote().get(shieldInputList.get(i)); + // ShieldNoteInfo noteInfo = shieldWrapper.getUtxoMapNote().get(shieldInputList.get(i)); OutputPoint.Builder outPointBuild = OutputPoint.newBuilder(); outPointBuild.setHash(ByteString.copyFrom(notes.getNoteTxs(0).getTxid().toByteArray())); outPointBuild.setIndex(notes.getNoteTxs(0).getIndex()); request.addOutPoints(outPointBuild.build()); - firstMerkleVoucherInfo = blockingStubFull - .getMerkleTreeVoucherInfo(request.build()); + firstMerkleVoucherInfo = blockingStubFull.getMerkleTreeVoucherInfo(request.build()); } - - @Test(enabled = false, description = "Shield to shield transaction", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "Shield to shield transaction", + groups = {"daily", "shield"}) public void test02Shield2ShieldTransaction() { receiverShieldAddressInfo = PublicMethod.generateShieldAddress(); receiverShieldAddress = receiverShieldAddressInfo.get().getAddress(); @@ -127,239 +137,303 @@ public void test02Shield2ShieldTransaction() { shieldOutList.clear(); ; memo = "Send shield to receiver shield memo in" + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, receiverShieldAddress, - "" + (sendNote.getValue() - zenTokenFee), memo); - Assert.assertTrue(PublicMethod.sendShieldCoin( - null, 0, - sendShieldAddressInfo.get(), notes.getNoteTxs(0), - shieldOutList, - null, 0, - zenTokenOwnerKey, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, receiverShieldAddress, "" + (sendNote.getValue() - zenTokenFee), memo); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + null, + 0, + sendShieldAddressInfo.get(), + notes.getNoteTxs(0), + shieldOutList, + null, + 0, + zenTokenOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); notes = PublicMethod.listShieldNote(receiverShieldAddressInfo, blockingStubFull); receiverNote = notes.getNoteTxs(0).getNote(); logger.info("Receiver note:" + receiverNote.toString()); Assert.assertTrue(receiverNote.getValue() == sendNote.getValue() - zenTokenFee); - } - /** - * constructor. - */ - @Test(enabled = false, description = "Scan note by ivk and scan not by ivk on FullNode", groups = {"daily", "shield"}) + /** constructor. */ + @Test( + enabled = false, + description = "Scan note by ivk and scan not by ivk on FullNode", + groups = {"daily", "shield"}) public void test03ScanNoteByIvkAndOvk() { - //Scan sender note by ovk equals scan receiver note by ivk on FullNode - Note scanNoteByIvk = PublicMethod - .getShieldNotesByIvk(receiverShieldAddressInfo, blockingStubFull).getNoteTxs(0).getNote(); - Note scanNoteByOvk = PublicMethod - .getShieldNotesByOvk(sendShieldAddressInfo, blockingStubFull).getNoteTxs(0).getNote(); + // Scan sender note by ovk equals scan receiver note by ivk on FullNode + Note scanNoteByIvk = + PublicMethod.getShieldNotesByIvk(receiverShieldAddressInfo, blockingStubFull) + .getNoteTxs(0) + .getNote(); + Note scanNoteByOvk = + PublicMethod.getShieldNotesByOvk(sendShieldAddressInfo, blockingStubFull) + .getNoteTxs(0) + .getNote(); Assert.assertEquals(scanNoteByIvk.getValue(), scanNoteByOvk.getValue()); Assert.assertEquals(scanNoteByIvk.getMemo(), scanNoteByOvk.getMemo()); Assert.assertEquals(scanNoteByIvk.getRcm(), scanNoteByOvk.getRcm()); Assert.assertEquals(scanNoteByIvk.getPaymentAddress(), scanNoteByOvk.getPaymentAddress()); } - /** - * constructor. - */ - @Test(enabled = false, description = "Scan note by ivk and scan not by ivk on solidity", groups = {"daily", "shield"}) + /** constructor. */ + @Test( + enabled = false, + description = "Scan note by ivk and scan not by ivk on solidity", + groups = {"daily", "shield"}) public void test04ScanNoteByIvkAndOvkOnSolidityServer() { - //Scan sender note by ovk equals scan receiver note by ivk in Solidity + // Scan sender note by ovk equals scan receiver note by ivk in Solidity PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); - Note scanNoteByIvk = PublicMethod - .getShieldNotesByIvkOnSolidity(receiverShieldAddressInfo, blockingStubSolidity) - .getNoteTxs(0).getNote(); - Note scanNoteByOvk = PublicMethod - .getShieldNotesByOvkOnSolidity(sendShieldAddressInfo, blockingStubSolidity) - .getNoteTxs(0).getNote(); + Note scanNoteByIvk = + PublicMethod.getShieldNotesByIvkOnSolidity(receiverShieldAddressInfo, blockingStubSolidity) + .getNoteTxs(0) + .getNote(); + Note scanNoteByOvk = + PublicMethod.getShieldNotesByOvkOnSolidity(sendShieldAddressInfo, blockingStubSolidity) + .getNoteTxs(0) + .getNote(); Assert.assertEquals(scanNoteByIvk.getValue(), scanNoteByOvk.getValue()); Assert.assertEquals(scanNoteByIvk.getMemo(), scanNoteByOvk.getMemo()); Assert.assertEquals(scanNoteByIvk.getRcm(), scanNoteByOvk.getRcm()); Assert.assertEquals(scanNoteByIvk.getPaymentAddress(), scanNoteByOvk.getPaymentAddress()); } - /** - * constructor. - */ - @Test(enabled = false, description = "Scan note by ivk and scan not by ivk on Pbft", groups = {"daily", "shield"}) + /** constructor. */ + @Test( + enabled = false, + description = "Scan note by ivk and scan not by ivk on Pbft", + groups = {"daily", "shield"}) public void test05ScanNoteByIvkAndOvkOnPbftServer() { - //Scan sender note by ovk equals scan receiver note by ivk in Solidity + // Scan sender note by ovk equals scan receiver note by ivk in Solidity PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); - Note scanNoteByIvk = PublicMethod - .getShieldNotesByIvkOnSolidity(receiverShieldAddressInfo, blockingStubPbft) - .getNoteTxs(0).getNote(); - Note scanNoteByOvk = PublicMethod - .getShieldNotesByOvkOnSolidity(sendShieldAddressInfo, blockingStubPbft) - .getNoteTxs(0).getNote(); + Note scanNoteByIvk = + PublicMethod.getShieldNotesByIvkOnSolidity(receiverShieldAddressInfo, blockingStubPbft) + .getNoteTxs(0) + .getNote(); + Note scanNoteByOvk = + PublicMethod.getShieldNotesByOvkOnSolidity(sendShieldAddressInfo, blockingStubPbft) + .getNoteTxs(0) + .getNote(); Assert.assertEquals(scanNoteByIvk.getValue(), scanNoteByOvk.getValue()); Assert.assertEquals(scanNoteByIvk.getMemo(), scanNoteByOvk.getMemo()); Assert.assertEquals(scanNoteByIvk.getRcm(), scanNoteByOvk.getRcm()); Assert.assertEquals(scanNoteByIvk.getPaymentAddress(), scanNoteByOvk.getPaymentAddress()); } - - /** - * constructor. - */ - @Test(enabled = false, description = "Scan note by ivk and scan not by ivk on solidity", groups = {"daily", "shield"}) + /** constructor. */ + @Test( + enabled = false, + description = "Scan note by ivk and scan not by ivk on solidity", + groups = {"daily", "shield"}) public void test06ScanNoteByIvkAndOvkOnSolidityServer() { - //Scan sender note by ovk equals scan receiver note by ivk in Solidity + // Scan sender note by ovk equals scan receiver note by ivk in Solidity PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity1); - Note scanNoteByIvk = PublicMethod - .getShieldNotesByIvkOnSolidity(receiverShieldAddressInfo, blockingStubSolidity1) - .getNoteTxs(0).getNote(); - Note scanNoteByOvk = PublicMethod - .getShieldNotesByOvkOnSolidity(sendShieldAddressInfo, blockingStubSolidity1) - - .getNoteTxs(0).getNote(); + Note scanNoteByIvk = + PublicMethod.getShieldNotesByIvkOnSolidity(receiverShieldAddressInfo, blockingStubSolidity1) + .getNoteTxs(0) + .getNote(); + Note scanNoteByOvk = + PublicMethod.getShieldNotesByOvkOnSolidity(sendShieldAddressInfo, blockingStubSolidity1) + .getNoteTxs(0) + .getNote(); Assert.assertEquals(scanNoteByIvk.getValue(), scanNoteByOvk.getValue()); Assert.assertEquals(scanNoteByIvk.getMemo(), scanNoteByOvk.getMemo()); Assert.assertEquals(scanNoteByIvk.getRcm(), scanNoteByOvk.getRcm()); Assert.assertEquals(scanNoteByIvk.getPaymentAddress(), scanNoteByOvk.getPaymentAddress()); } - /** - * constructor. - */ - @Test(enabled = false, description = "Query whether note is spend on solidity", groups = {"daily", "shield"}) + /** constructor. */ + @Test( + enabled = false, + description = "Query whether note is spend on solidity", + groups = {"daily", "shield"}) public void test07QueryNoteIsSpendOnSolidity() { notes = PublicMethod.listShieldNote(sendShieldAddressInfo, blockingStubFull); - //Scan sender note by ovk equals scan receiver note by ivk in Solidity - Assert.assertTrue(PublicMethod.getSpendResult(sendShieldAddressInfo.get(), - notes.getNoteTxs(0), blockingStubFull).getResult()); - Assert.assertTrue(PublicMethod.getSpendResultOnSolidity(sendShieldAddressInfo.get(), - notes.getNoteTxs(0), blockingStubSolidity).getResult()); - Assert.assertTrue(PublicMethod.getSpendResultOnSolidity(sendShieldAddressInfo.get(), - notes.getNoteTxs(0), blockingStubSolidity1).getResult()); + // Scan sender note by ovk equals scan receiver note by ivk in Solidity + Assert.assertTrue( + PublicMethod.getSpendResult( + sendShieldAddressInfo.get(), notes.getNoteTxs(0), blockingStubFull) + .getResult()); + Assert.assertTrue( + PublicMethod.getSpendResultOnSolidity( + sendShieldAddressInfo.get(), notes.getNoteTxs(0), blockingStubSolidity) + .getResult()); + Assert.assertTrue( + PublicMethod.getSpendResultOnSolidity( + sendShieldAddressInfo.get(), notes.getNoteTxs(0), blockingStubSolidity1) + .getResult()); } - /** - * constructor. - */ - @Test(enabled = false, description = "Query whether note is spend on PBFT", groups = {"daily", "shield"}) + /** constructor. */ + @Test( + enabled = false, + description = "Query whether note is spend on PBFT", + groups = {"daily", "shield"}) public void test08QueryNoteIsSpendOnPbft() { notes = PublicMethod.listShieldNote(sendShieldAddressInfo, blockingStubFull); - //Scan sender note by ovk equals scan receiver note by ivk in Solidity - Assert.assertTrue(PublicMethod.getSpendResult(sendShieldAddressInfo.get(), - notes.getNoteTxs(0), blockingStubFull).getResult()); - Assert.assertTrue(PublicMethod.getSpendResultOnSolidity(sendShieldAddressInfo.get(), - notes.getNoteTxs(0), blockingStubPbft).getResult()); + // Scan sender note by ovk equals scan receiver note by ivk in Solidity + Assert.assertTrue( + PublicMethod.getSpendResult( + sendShieldAddressInfo.get(), notes.getNoteTxs(0), blockingStubFull) + .getResult()); + Assert.assertTrue( + PublicMethod.getSpendResultOnSolidity( + sendShieldAddressInfo.get(), notes.getNoteTxs(0), blockingStubPbft) + .getResult()); } - - /** - * constructor. - */ - @Test(enabled = false, description = "Query note and spend status on fullnode and solidity", groups = {"daily", "shield"}) + /** constructor. */ + @Test( + enabled = false, + description = "Query note and spend status on fullnode and solidity", + groups = {"daily", "shield"}) public void test09QueryNoteAndSpendStatusOnFullnode() { Assert.assertFalse( PublicMethod.getShieldNotesAndMarkByIvk(receiverShieldAddressInfo, blockingStubFull) - .getNoteTxs(0).getIsSpend()); - Note scanNoteByIvk = PublicMethod - .getShieldNotesByIvk(receiverShieldAddressInfo, blockingStubFull) - .getNoteTxs(0).getNote(); - Assert.assertEquals(scanNoteByIvk, + .getNoteTxs(0) + .getIsSpend()); + Note scanNoteByIvk = + PublicMethod.getShieldNotesByIvk(receiverShieldAddressInfo, blockingStubFull) + .getNoteTxs(0) + .getNote(); + Assert.assertEquals( + scanNoteByIvk, PublicMethod.getShieldNotesAndMarkByIvk(receiverShieldAddressInfo, blockingStubFull) - .getNoteTxs(0).getNote()); + .getNoteTxs(0) + .getNote()); - Assert.assertFalse(PublicMethod - .getShieldNotesAndMarkByIvkOnSolidity(receiverShieldAddressInfo, blockingStubSolidity) - .getNoteTxs(0).getIsSpend()); - scanNoteByIvk = PublicMethod - .getShieldNotesByIvkOnSolidity(receiverShieldAddressInfo, blockingStubSolidity) - .getNoteTxs(0).getNote(); - Assert.assertEquals(scanNoteByIvk, PublicMethod - .getShieldNotesAndMarkByIvkOnSolidity(receiverShieldAddressInfo, blockingStubSolidity) - .getNoteTxs(0).getNote()); - Assert.assertEquals(scanNoteByIvk, PublicMethod - .getShieldNotesAndMarkByIvkOnSolidity(receiverShieldAddressInfo, blockingStubPbft) - .getNoteTxs(0).getNote()); + Assert.assertFalse( + PublicMethod.getShieldNotesAndMarkByIvkOnSolidity( + receiverShieldAddressInfo, blockingStubSolidity) + .getNoteTxs(0) + .getIsSpend()); + scanNoteByIvk = + PublicMethod.getShieldNotesByIvkOnSolidity(receiverShieldAddressInfo, blockingStubSolidity) + .getNoteTxs(0) + .getNote(); + Assert.assertEquals( + scanNoteByIvk, + PublicMethod.getShieldNotesAndMarkByIvkOnSolidity( + receiverShieldAddressInfo, blockingStubSolidity) + .getNoteTxs(0) + .getNote()); + Assert.assertEquals( + scanNoteByIvk, + PublicMethod.getShieldNotesAndMarkByIvkOnSolidity( + receiverShieldAddressInfo, blockingStubPbft) + .getNoteTxs(0) + .getNote()); shieldOutList.clear(); memo = "Query note and spend status on fullnode " + System.currentTimeMillis(); notes = PublicMethod.listShieldNote(receiverShieldAddressInfo, blockingStubFull); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress, - "" + (notes.getNoteTxs(0).getNote().getValue() - zenTokenFee), memo); - Assert.assertTrue(PublicMethod.sendShieldCoin( - null, 0, - receiverShieldAddressInfo.get(), notes.getNoteTxs(0), - shieldOutList, - null, 0, - zenTokenOwnerKey, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, + sendShieldAddress, + "" + (notes.getNoteTxs(0).getNote().getValue() - zenTokenFee), + memo); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + null, + 0, + receiverShieldAddressInfo.get(), + notes.getNoteTxs(0), + shieldOutList, + null, + 0, + zenTokenOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); Assert.assertTrue( PublicMethod.getShieldNotesAndMarkByIvk(receiverShieldAddressInfo, blockingStubFull) - .getNoteTxs(0).getIsSpend()); + .getNoteTxs(0) + .getIsSpend()); - Assert.assertTrue(PublicMethod - .getShieldNotesAndMarkByIvkOnSolidity(receiverShieldAddressInfo, blockingStubSolidity) - .getNoteTxs(0).getIsSpend()); + Assert.assertTrue( + PublicMethod.getShieldNotesAndMarkByIvkOnSolidity( + receiverShieldAddressInfo, blockingStubSolidity) + .getNoteTxs(0) + .getIsSpend()); } - @Test(enabled = false, description = "Get merkle tree voucher info", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "Get merkle tree voucher info", + groups = {"daily", "shield"}) public void test10GetMerkleTreeVoucherInfo() { notes = PublicMethod.listShieldNote(sendShieldAddressInfo, blockingStubFull); sendNote = notes.getNoteTxs(0).getNote(); OutputPointInfo.Builder request = OutputPointInfo.newBuilder(); - //ShieldNoteInfo noteInfo = shieldWrapper.getUtxoMapNote().get(shieldInputList.get(i)); + // ShieldNoteInfo noteInfo = shieldWrapper.getUtxoMapNote().get(shieldInputList.get(i)); OutputPoint.Builder outPointBuild = OutputPoint.newBuilder(); outPointBuild.setHash(ByteString.copyFrom(notes.getNoteTxs(0).getTxid().toByteArray())); outPointBuild.setIndex(notes.getNoteTxs(0).getIndex()); request.addOutPoints(outPointBuild.build()); - secondMerkleVoucherInfo = blockingStubFull - .getMerkleTreeVoucherInfo(request.build()); + secondMerkleVoucherInfo = blockingStubFull.getMerkleTreeVoucherInfo(request.build()); Assert.assertEquals(firstMerkleVoucherInfo, secondMerkleVoucherInfo); } - @Test(enabled = false, description = "Get merkle tree voucher info from Solidity", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "Get merkle tree voucher info from Solidity", + groups = {"daily", "shield"}) public void test11GetMerkleTreeVoucherInfoFromSolidity() { notes = PublicMethod.listShieldNote(sendShieldAddressInfo, blockingStubFull); sendNote = notes.getNoteTxs(0).getNote(); OutputPointInfo.Builder request = OutputPointInfo.newBuilder(); - //ShieldNoteInfo noteInfo = shieldWrapper.getUtxoMapNote().get(shieldInputList.get(i)); + // ShieldNoteInfo noteInfo = shieldWrapper.getUtxoMapNote().get(shieldInputList.get(i)); OutputPoint.Builder outPointBuild = OutputPoint.newBuilder(); outPointBuild.setHash(ByteString.copyFrom(notes.getNoteTxs(0).getTxid().toByteArray())); outPointBuild.setIndex(notes.getNoteTxs(0).getIndex()); request.addOutPoints(outPointBuild.build()); - secondMerkleVoucherInfo = blockingStubSolidity - .getMerkleTreeVoucherInfo(request.build()); + secondMerkleVoucherInfo = blockingStubSolidity.getMerkleTreeVoucherInfo(request.build()); Assert.assertEquals(firstMerkleVoucherInfo, secondMerkleVoucherInfo); } - @Test(enabled = false, description = "Get merkle tree voucher info from Pbft", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "Get merkle tree voucher info from Pbft", + groups = {"daily", "shield"}) public void test12GetMerkleTreeVoucherInfoFromPbft() { notes = PublicMethod.listShieldNote(sendShieldAddressInfo, blockingStubFull); sendNote = notes.getNoteTxs(0).getNote(); OutputPointInfo.Builder request = OutputPointInfo.newBuilder(); - //ShieldNoteInfo noteInfo = shieldWrapper.getUtxoMapNote().get(shieldInputList.get(i)); + // ShieldNoteInfo noteInfo = shieldWrapper.getUtxoMapNote().get(shieldInputList.get(i)); OutputPoint.Builder outPointBuild = OutputPoint.newBuilder(); outPointBuild.setHash(ByteString.copyFrom(notes.getNoteTxs(0).getTxid().toByteArray())); outPointBuild.setIndex(notes.getNoteTxs(0).getIndex()); request.addOutPoints(outPointBuild.build()); - secondMerkleVoucherInfo = blockingStubPbft - .getMerkleTreeVoucherInfo(request.build()); + secondMerkleVoucherInfo = blockingStubPbft.getMerkleTreeVoucherInfo(request.build()); Assert.assertEquals(firstMerkleVoucherInfo, secondMerkleVoucherInfo); } - - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - PublicMethod.transferAsset(foundationZenTokenAddress, tokenId, - PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, + PublicMethod.transferAsset( + foundationZenTokenAddress, + tokenId, + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull), zenTokenOwnerAddress, zenTokenOwnerKey, blockingStubFull); if (channelSolidity1 != null) { + blockingStubFull), + zenTokenOwnerAddress, + zenTokenOwnerKey, + blockingStubFull); + if (channelSolidity1 != null) { channelSolidity1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } } -} \ No newline at end of file + } + } +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken003.java index fd6c9e52..798e08f9 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken003.java @@ -18,11 +18,12 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.ShieldAddressInfo; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class WalletTestZenToken003 extends TronBaseTest { List shieldOutList = new ArrayList<>(); +public class WalletTestZenToken003 extends TronBaseTest { + List shieldOutList = new ArrayList<>(); DecryptNotes notes; Note note; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -31,84 +32,99 @@ public class WalletTestZenToken003 extends TronBaseTest { List shieldOutL ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] receiverPublicAddress = ecKey2.getAddress(); String receiverPublicKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - private String foundationZenTokenKey = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenOwnerKey"); + private String foundationZenTokenKey = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenOwnerKey"); byte[] foundationZenTokenAddress = PublicMethod.getFinalAddress(foundationZenTokenKey); - private String zenTokenId = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenId"); + private String zenTokenId = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenId"); private byte[] tokenId = zenTokenId.getBytes(); - private Long zenTokenFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.zenTokenFee"); - private Long zenTokenWhenCreateNewAddress = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.zenTokenWhenCreateNewAddress"); + private Long zenTokenFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.zenTokenFee"); + private Long zenTokenWhenCreateNewAddress = + Configuration.getByPath("testng.conf") + .getLong("defaultParameter.zenTokenWhenCreateNewAddress"); private Long costTokenAmount = 20 * zenTokenFee; private String txid; private Optional infoById; private Optional byId; - /** - * constructor. - */ + /** constructor. */ - - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(foundationZenTokenKey); - PublicMethod.printAddress(zenTokenOwnerKey); Assert.assertTrue(PublicMethod.transferAsset(zenTokenOwnerAddress, tokenId, - costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull)); + PublicMethod.printAddress(zenTokenOwnerKey); + Assert.assertTrue( + PublicMethod.transferAsset( + zenTokenOwnerAddress, + tokenId, + costTokenAmount, + foundationZenTokenAddress, + foundationZenTokenKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Args.setFullNodeAllowShieldedTransaction(true); + // Args.setFullNodeAllowShieldedTransaction(true); } - @Test(enabled = false, - description = "Public to two shield transaction", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "Public to two shield transaction", + groups = {"daily", "shield"}) public void test1Public2ShieldTransaction() { Optional shieldAddressInfo1 = PublicMethod.generateShieldAddress(); - String shieldAddress1 = shieldAddressInfo1.get().getAddress(); + String shieldAddress1 = shieldAddressInfo1.get().getAddress(); Optional shieldAddressInfo2 = PublicMethod.generateShieldAddress(); - String shieldAddress2 = shieldAddressInfo2.get().getAddress(); + String shieldAddress2 = shieldAddressInfo2.get().getAddress(); logger.info("shieldAddress1:" + shieldAddress1); logger.info("shieldAddress2:" + shieldAddress2); - final Long beforeAssetBalance = PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, - PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull); - final Long beforeNetUsed = PublicMethod - .getAccountResource(zenTokenOwnerAddress, blockingStubFull).getFreeNetUsed(); - Long sendToShiledAddress1Amount = 3 * zenTokenFee; - Long sendToShiledAddress2Amount = costTokenAmount - sendToShiledAddress1Amount - zenTokenFee; - String memo1 = "Public to shield address1 transaction"; - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress1, - "" + sendToShiledAddress1Amount, memo1); - String memo2 = "Public to shield address2 transaction"; - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress2, - "" + sendToShiledAddress2Amount, memo2); - txid = PublicMethod.sendShieldCoinGetTxid( - zenTokenOwnerAddress, costTokenAmount, - null, null, - shieldOutList, - null, 0, - zenTokenOwnerKey, blockingStubFull); + final Long beforeAssetBalance = + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, + PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), + blockingStubFull); + final Long beforeNetUsed = + PublicMethod.getAccountResource(zenTokenOwnerAddress, blockingStubFull).getFreeNetUsed(); + Long sendToShiledAddress1Amount = 3 * zenTokenFee; + Long sendToShiledAddress2Amount = costTokenAmount - sendToShiledAddress1Amount - zenTokenFee; + String memo1 = "Public to shield address1 transaction"; + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress1, "" + sendToShiledAddress1Amount, memo1); + String memo2 = "Public to shield address2 transaction"; + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress2, "" + sendToShiledAddress2Amount, memo2); + txid = + PublicMethod.sendShieldCoinGetTxid( + zenTokenOwnerAddress, + costTokenAmount, + null, + null, + shieldOutList, + null, + 0, + zenTokenOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getShieldedTransactionFee() == zenTokenFee); byId = PublicMethod.getTransactionById(txid, blockingStubFull); Assert.assertTrue(byId.get().getSignatureCount() == 1); - Long afterAssetBalance = PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, - PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull); - final Long afterNetUsed = PublicMethod - .getAccountResource(zenTokenOwnerAddress, blockingStubFull) - .getFreeNetUsed(); + Long afterAssetBalance = + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, + PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), + blockingStubFull); + final Long afterNetUsed = + PublicMethod.getAccountResource(zenTokenOwnerAddress, blockingStubFull).getFreeNetUsed(); logger.info("beforeAssetBalance:" + beforeAssetBalance); logger.info("afterAssetBalance:" + afterAssetBalance); Assert.assertTrue(beforeAssetBalance - afterAssetBalance == costTokenAmount); Assert.assertTrue(beforeNetUsed == afterNetUsed); notes = PublicMethod.listShieldNote(shieldAddressInfo1, blockingStubFull); note = notes.getNoteTxs(0).getNote(); - Long receiverShieldTokenAmount1 = note.getValue(); + Long receiverShieldTokenAmount1 = note.getValue(); logger.info("receiverShieldTokenAmount1:" + receiverShieldTokenAmount1); logger.info("sendToShiledAddress1Amount:" + sendToShiledAddress1Amount); Assert.assertEquals(receiverShieldTokenAmount1, sendToShiledAddress1Amount); @@ -116,61 +132,77 @@ public void test1Public2ShieldTransaction() { notes = PublicMethod.listShieldNote(shieldAddressInfo2, blockingStubFull); note = notes.getNoteTxs(0).getNote(); - Long receiverShieldTokenAmount2 = note.getValue(); + Long receiverShieldTokenAmount2 = note.getValue(); Assert.assertEquals(receiverShieldTokenAmount2, sendToShiledAddress2Amount); Assert.assertEquals(memo2, PublicMethod.getMemo(note)); - } - @Test(enabled = false, - description = "Public to one public and one shield transaction", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "Public to one public and one shield transaction", + groups = {"daily", "shield"}) public void test2Public2OneShieldAndOnePublicTransaction() { - Assert.assertTrue(PublicMethod.transferAsset(zenTokenOwnerAddress, tokenId, - costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + zenTokenOwnerAddress, + tokenId, + costTokenAmount, + foundationZenTokenAddress, + foundationZenTokenKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional shieldAddressInfo1 = PublicMethod.generateShieldAddress(); - String shieldAddress1 = shieldAddressInfo1.get().getAddress(); + String shieldAddress1 = shieldAddressInfo1.get().getAddress(); logger.info("shieldAddress1:" + shieldAddress1); - final Long beforeAssetBalance = PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, - PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull); - final Long beforeNetUsed = PublicMethod - .getAccountResource(zenTokenOwnerAddress, blockingStubFull).getFreeNetUsed(); - final Long beforeBalance = PublicMethod - .queryAccount(receiverPublicAddress, blockingStubFull).getBalance(); - Long sendToShiledAddress1Amount = 1 * zenTokenFee; - //When receiver public address don't active,the fee is 1000000 - Long sendToPublicAddressAmount = costTokenAmount - - sendToShiledAddress1Amount - zenTokenWhenCreateNewAddress; + final Long beforeAssetBalance = + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, + PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), + blockingStubFull); + final Long beforeNetUsed = + PublicMethod.getAccountResource(zenTokenOwnerAddress, blockingStubFull).getFreeNetUsed(); + final Long beforeBalance = + PublicMethod.queryAccount(receiverPublicAddress, blockingStubFull).getBalance(); + Long sendToShiledAddress1Amount = 1 * zenTokenFee; + // When receiver public address don't active,the fee is 1000000 + Long sendToPublicAddressAmount = + costTokenAmount - sendToShiledAddress1Amount - zenTokenWhenCreateNewAddress; logger.info("costTokenAmount " + costTokenAmount); logger.info("sendToShiledAddress1Amount " + sendToShiledAddress1Amount); logger.info("sendToPublicAddressAmount " + sendToPublicAddressAmount); shieldOutList.clear(); - String memo1 = "Public to shield address1 transaction"; - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress1, - "" + sendToShiledAddress1Amount, memo1); + String memo1 = "Public to shield address1 transaction"; + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress1, "" + sendToShiledAddress1Amount, memo1); - txid = PublicMethod.sendShieldCoinGetTxid( - zenTokenOwnerAddress, costTokenAmount, - null, null, - shieldOutList, - receiverPublicAddress, sendToPublicAddressAmount, - zenTokenOwnerKey, blockingStubFull); + txid = + PublicMethod.sendShieldCoinGetTxid( + zenTokenOwnerAddress, + costTokenAmount, + null, + null, + shieldOutList, + receiverPublicAddress, + sendToPublicAddressAmount, + zenTokenOwnerKey, + blockingStubFull); logger.info("txid:" + txid); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getShieldedTransactionFee() == zenTokenWhenCreateNewAddress); byId = PublicMethod.getTransactionById(txid, blockingStubFull); Assert.assertTrue(byId.get().getSignatureCount() == 1); - Long afterAssetBalance = PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, - PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull); - final Long afterNetUsed = PublicMethod - .getAccountResource(zenTokenOwnerAddress, blockingStubFull) - .getFreeNetUsed(); - final Long afterBalance = PublicMethod - .queryAccount(receiverPublicAddress, blockingStubFull).getBalance(); + Long afterAssetBalance = + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, + PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), + blockingStubFull); + final Long afterNetUsed = + PublicMethod.getAccountResource(zenTokenOwnerAddress, blockingStubFull).getFreeNetUsed(); + final Long afterBalance = + PublicMethod.queryAccount(receiverPublicAddress, blockingStubFull).getBalance(); logger.info("beforeAssetBalance:" + beforeAssetBalance); logger.info("afterAssetBalance:" + afterAssetBalance); Assert.assertTrue(beforeAssetBalance - afterAssetBalance == costTokenAmount); @@ -179,68 +211,89 @@ public void test2Public2OneShieldAndOnePublicTransaction() { notes = PublicMethod.listShieldNote(shieldAddressInfo1, blockingStubFull); note = notes.getNoteTxs(0).getNote(); - Long receiverShieldTokenAmount1 = note.getValue(); + Long receiverShieldTokenAmount1 = note.getValue(); logger.info("receiverShieldTokenAmount1:" + receiverShieldTokenAmount1); logger.info("sendToShiledAddress1Amount:" + sendToShiledAddress1Amount); Assert.assertEquals(receiverShieldTokenAmount1, sendToShiledAddress1Amount); Assert.assertEquals(memo1, PublicMethod.getMemo(note)); - Long afterReceiverPublicAssetBalance = PublicMethod.getAssetIssueValue(receiverPublicAddress, - PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull); + Long afterReceiverPublicAssetBalance = + PublicMethod.getAssetIssueValue( + receiverPublicAddress, + PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), + blockingStubFull); Assert.assertEquals(afterReceiverPublicAssetBalance, sendToPublicAddressAmount); } - @Test(enabled = false, - description = "Public to one public and two shield transaction", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "Public to one public and two shield transaction", + groups = {"daily", "shield"}) public void test3Public2OneShieldAndOnePublicTransaction() { - Assert.assertTrue(PublicMethod.transferAsset(zenTokenOwnerAddress, tokenId, - costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + zenTokenOwnerAddress, + tokenId, + costTokenAmount, + foundationZenTokenAddress, + foundationZenTokenKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional shieldAddressInfo1 = PublicMethod.generateShieldAddress(); - String shieldAddress1 = shieldAddressInfo1.get().getAddress(); + String shieldAddress1 = shieldAddressInfo1.get().getAddress(); Optional shieldAddressInfo2 = PublicMethod.generateShieldAddress(); - String shieldAddress2 = shieldAddressInfo2.get().getAddress(); + String shieldAddress2 = shieldAddressInfo2.get().getAddress(); logger.info("shieldAddress1:" + shieldAddress1); logger.info("shieldAddress2:" + shieldAddress2); - final Long beforeAssetBalance = PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, - PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull); - final Long beforeNetUsed = PublicMethod - .getAccountResource(zenTokenOwnerAddress, blockingStubFull).getFreeNetUsed(); - Long sendToShiledAddress1Amount = 1 * zenTokenFee; - Long sendToShiledAddress2Amount = 2 * zenTokenFee; - final Long sendToPublicAddressAmount = costTokenAmount - sendToShiledAddress1Amount - - sendToShiledAddress2Amount - zenTokenFee; + final Long beforeAssetBalance = + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, + PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), + blockingStubFull); + final Long beforeNetUsed = + PublicMethod.getAccountResource(zenTokenOwnerAddress, blockingStubFull).getFreeNetUsed(); + Long sendToShiledAddress1Amount = 1 * zenTokenFee; + Long sendToShiledAddress2Amount = 2 * zenTokenFee; + final Long sendToPublicAddressAmount = + costTokenAmount - sendToShiledAddress1Amount - sendToShiledAddress2Amount - zenTokenFee; shieldOutList.clear(); - String memo1 = "Public to shield address1 transaction"; - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress1, - "" + sendToShiledAddress1Amount, memo1); - String memo2 = "Public to shield address2 transaction"; - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress2, - "" + sendToShiledAddress2Amount, memo2); - final Long beforeReceiverPublicAssetBalance = PublicMethod - .getAssetIssueValue(receiverPublicAddress, + String memo1 = "Public to shield address1 transaction"; + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress1, "" + sendToShiledAddress1Amount, memo1); + String memo2 = "Public to shield address2 transaction"; + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress2, "" + sendToShiledAddress2Amount, memo2); + final Long beforeReceiverPublicAssetBalance = + PublicMethod.getAssetIssueValue( + receiverPublicAddress, PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), blockingStubFull); - txid = PublicMethod.sendShieldCoinGetTxid( - zenTokenOwnerAddress, costTokenAmount, - null, null, - shieldOutList, - receiverPublicAddress, sendToPublicAddressAmount, - zenTokenOwnerKey, blockingStubFull); + txid = + PublicMethod.sendShieldCoinGetTxid( + zenTokenOwnerAddress, + costTokenAmount, + null, + null, + shieldOutList, + receiverPublicAddress, + sendToPublicAddressAmount, + zenTokenOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getShieldedTransactionFee() == zenTokenFee); byId = PublicMethod.getTransactionById(txid, blockingStubFull); Assert.assertTrue(byId.get().getSignatureCount() == 1); - Long afterAssetBalance = PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, - PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull); - final Long afterNetUsed = PublicMethod - .getAccountResource(zenTokenOwnerAddress, blockingStubFull) - .getFreeNetUsed(); + Long afterAssetBalance = + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, + PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), + blockingStubFull); + final Long afterNetUsed = + PublicMethod.getAccountResource(zenTokenOwnerAddress, blockingStubFull).getFreeNetUsed(); logger.info("beforeAssetBalance:" + beforeAssetBalance); logger.info("afterAssetBalance:" + afterAssetBalance); Assert.assertTrue(beforeAssetBalance - afterAssetBalance == costTokenAmount); @@ -248,92 +301,131 @@ public void test3Public2OneShieldAndOnePublicTransaction() { notes = PublicMethod.listShieldNote(shieldAddressInfo1, blockingStubFull); note = notes.getNoteTxs(0).getNote(); - Long receiverShieldTokenAmount1 = note.getValue(); + Long receiverShieldTokenAmount1 = note.getValue(); Assert.assertEquals(receiverShieldTokenAmount1, sendToShiledAddress1Amount); Assert.assertEquals(memo1, PublicMethod.getMemo(note)); notes = PublicMethod.listShieldNote(shieldAddressInfo2, blockingStubFull); note = notes.getNoteTxs(0).getNote(); - Long receiverShieldTokenAmount2 = note.getValue(); + Long receiverShieldTokenAmount2 = note.getValue(); Assert.assertEquals(receiverShieldTokenAmount2, sendToShiledAddress2Amount); Assert.assertEquals(memo2, PublicMethod.getMemo(note)); - Long afterReceiverPublicAssetBalance = PublicMethod.getAssetIssueValue(receiverPublicAddress, - PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull); - Assert.assertTrue(afterReceiverPublicAssetBalance - - beforeReceiverPublicAssetBalance == sendToPublicAddressAmount); + Long afterReceiverPublicAssetBalance = + PublicMethod.getAssetIssueValue( + receiverPublicAddress, + PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), + blockingStubFull); + Assert.assertTrue( + afterReceiverPublicAssetBalance - beforeReceiverPublicAssetBalance + == sendToPublicAddressAmount); } - @Test(enabled = false, - description = "Public to one smart contract and one shield transaction", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "Public to one smart contract and one shield transaction", + groups = {"daily", "shield"}) public void test4Public2OneShieldAndOneSmartContractAddressTransaction() { - Assert.assertTrue(PublicMethod.transferAsset(zenTokenOwnerAddress, tokenId, - costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + zenTokenOwnerAddress, + tokenId, + costTokenAmount, + foundationZenTokenAddress, + foundationZenTokenKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional shieldAddressInfo1 = PublicMethod.generateShieldAddress(); - String shieldAddress1 = shieldAddressInfo1.get().getAddress(); + String shieldAddress1 = shieldAddressInfo1.get().getAddress(); logger.info("shieldAddress1:" + shieldAddress1); - final Long beforeAssetBalance = PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, - PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull); - final Long beforeNetUsed = PublicMethod - .getAccountResource(zenTokenOwnerAddress, blockingStubFull).getFreeNetUsed(); - final Long beforeBalance = PublicMethod - .queryAccount(receiverPublicAddress, blockingStubFull).getBalance(); - Long sendToShiledAddress1Amount = 1 * zenTokenFee; + final Long beforeAssetBalance = + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, + PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), + blockingStubFull); + final Long beforeNetUsed = + PublicMethod.getAccountResource(zenTokenOwnerAddress, blockingStubFull).getFreeNetUsed(); + final Long beforeBalance = + PublicMethod.queryAccount(receiverPublicAddress, blockingStubFull).getBalance(); + Long sendToShiledAddress1Amount = 1 * zenTokenFee; shieldOutList.clear(); - String memo1 = "Public to shield address1 transaction"; - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress1, - "" + sendToShiledAddress1Amount, memo1); - String contractName = "tokenBalanceContract"; - String code = "608060405260ff806100126000396000f30060806040526" - + "004361060485763ffffffff7c010000000000000" - + "0000000000000000000000000000000000000000000600035041663a730416e8114604d578063b69ef8a8146" - + "081575b600080fd5b606f73ffffffffffffffffffffffffffffffffffffffff6004351660243560ab565b604" - + "08051918252519081900360200190f35b348015608c57600080fd5b50d38015609857600080fd5b50d280156" - + "0a457600080fd5b50606f60cd565b73ffffffffffffffffffffffffffffffffffffffff90911690d16000908" - + "15590565b600054815600a165627a7a723058202b6235122df66c062c2e723ad58a9fea93346f3bc19898971" - + "8f211aa1dbd2d7a0029"; - String abi = "[{\"constant\":false,\"inputs\":[{\"name\":\"toAddress\",\"type\":\"address\"}," - + "{\"name\":\"tokenId\",\"type\":\"trcToken\"}],\"name\":\"getTokenBalnce\",\"outputs\":" - + "[{\"name\":\"b\",\"type\":\"uint256\"}],\"payable\":true,\"stateMutability\":" - + "\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":" - + "\"balance\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false," - + "\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"payable\":true," - + "\"stateMutability\":\"payable\",\"type\":\"constructor\"}]"; - txid = PublicMethod.deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 100, null, foundationKey, foundationAddress, blockingStubFull); + String memo1 = "Public to shield address1 transaction"; + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress1, "" + sendToShiledAddress1Amount, memo1); + String contractName = "tokenBalanceContract"; + String code = + "608060405260ff806100126000396000f30060806040526" + + "004361060485763ffffffff7c010000000000000" + + "0000000000000000000000000000000000000000000600035041663a730416e8114604d578063b69ef8a" + + "8146" + + "081575b600080fd5b606f73ffffffffffffffffffffffffffffffffffffffff6004351660243560ab565" + + "b604" + + "08051918252519081900360200190f35b348015608c57600080fd5b50d38015609857600080fd5b50d28" + + "0156" + + "0a457600080fd5b50606f60cd565b73ffffffffffffffffffffffffffffffffffffffff90911690d1600" + + "0908" + + "15590565b600054815600a165627a7a723058202b6235122df66c062c2e723ad58a9fea93346f3bc1989" + + "8971" + + "8f211aa1dbd2d7a0029"; + String abi = + "[{\"constant\":false,\"inputs\":[{\"name\":\"toAddress\"," + + "\"type\":\"address\"},{\"name\":\"tokenId\"," + + "\"type\":\"trcToken\"}],\"name\":\"getTokenBalnce\"," + + "\"outputs\":[{\"name\":\"b\",\"type\":\"uint256\"}]," + + "\"payable\":true,\"stateMutability\":" + + "\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":" + + "\"balance\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false," + + "\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"payable\":true," + + "\"stateMutability\":\"payable\",\"type\":\"constructor\"}]"; + txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + foundationKey, + foundationAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); logger.info(txid); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); com.google.protobuf.ByteString contractAddress = infoById.get().getContractAddress(); - SmartContract smartContract = PublicMethod - .getContract(contractAddress.toByteArray(), blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(contractAddress.toByteArray(), blockingStubFull); org.junit.Assert.assertTrue(smartContract.getAbi() != null); - Long sendToPublicAddressAmount = costTokenAmount - sendToShiledAddress1Amount - zenTokenFee; - txid = PublicMethod.sendShieldCoinGetTxid( - zenTokenOwnerAddress, costTokenAmount, - null, null, - shieldOutList, - contractAddress.toByteArray(), sendToPublicAddressAmount, - zenTokenOwnerKey, blockingStubFull); + Long sendToPublicAddressAmount = costTokenAmount - sendToShiledAddress1Amount - zenTokenFee; + txid = + PublicMethod.sendShieldCoinGetTxid( + zenTokenOwnerAddress, + costTokenAmount, + null, + null, + shieldOutList, + contractAddress.toByteArray(), + sendToPublicAddressAmount, + zenTokenOwnerKey, + blockingStubFull); logger.info("txid:" + txid); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getShieldedTransactionFee() == zenTokenFee); byId = PublicMethod.getTransactionById(txid, blockingStubFull); Assert.assertTrue(byId.get().getSignatureCount() == 1); - Long afterAssetBalance = PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, - PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull); - final Long afterNetUsed = PublicMethod - .getAccountResource(zenTokenOwnerAddress, blockingStubFull) - .getFreeNetUsed(); - final Long afterBalance = PublicMethod - .queryAccount(receiverPublicAddress, blockingStubFull).getBalance(); + Long afterAssetBalance = + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, + PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), + blockingStubFull); + final Long afterNetUsed = + PublicMethod.getAccountResource(zenTokenOwnerAddress, blockingStubFull).getFreeNetUsed(); + final Long afterBalance = + PublicMethod.queryAccount(receiverPublicAddress, blockingStubFull).getBalance(); logger.info("beforeAssetBalance:" + beforeAssetBalance); logger.info("afterAssetBalance:" + afterAssetBalance); Assert.assertTrue(beforeAssetBalance - afterAssetBalance == costTokenAmount); @@ -342,60 +434,79 @@ public void test4Public2OneShieldAndOneSmartContractAddressTransaction() { notes = PublicMethod.listShieldNote(shieldAddressInfo1, blockingStubFull); note = notes.getNoteTxs(0).getNote(); - Long receiverShieldTokenAmount1 = note.getValue(); + Long receiverShieldTokenAmount1 = note.getValue(); logger.info("receiverShieldTokenAmount1:" + receiverShieldTokenAmount1); logger.info("sendToShiledAddress1Amount:" + sendToShiledAddress1Amount); Assert.assertEquals(receiverShieldTokenAmount1, sendToShiledAddress1Amount); Assert.assertEquals(memo1, PublicMethod.getMemo(note)); - Long afterReceiverPublicAssetBalance = PublicMethod - .getAssetIssueValue(contractAddress.toByteArray(), + Long afterReceiverPublicAssetBalance = + PublicMethod.getAssetIssueValue( + contractAddress.toByteArray(), PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), blockingStubFull); Assert.assertEquals(afterReceiverPublicAssetBalance, sendToPublicAddressAmount); } - @Test(enabled = false, - description = "Public to two same shield address", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "Public to two same shield address", + groups = {"daily", "shield"}) public void test5Public2TwoSameShieldAddress() { - Assert.assertTrue(PublicMethod.transferAsset(zenTokenOwnerAddress, tokenId, - costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + zenTokenOwnerAddress, + tokenId, + costTokenAmount, + foundationZenTokenAddress, + foundationZenTokenKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional shieldAddressInfo1 = PublicMethod.generateShieldAddress(); - String shieldAddress1 = shieldAddressInfo1.get().getAddress(); + String shieldAddress1 = shieldAddressInfo1.get().getAddress(); logger.info("shieldAddress1:" + shieldAddress1); - final Long beforeAssetBalance = PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, - PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull); - final Long beforeNetUsed = PublicMethod - .getAccountResource(zenTokenOwnerAddress, blockingStubFull).getFreeNetUsed(); - Long sendToShiledAddress1Amount = 3 * zenTokenFee; - Long sendToShiledAddress2Amount = costTokenAmount - sendToShiledAddress1Amount - zenTokenFee; + final Long beforeAssetBalance = + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, + PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), + blockingStubFull); + final Long beforeNetUsed = + PublicMethod.getAccountResource(zenTokenOwnerAddress, blockingStubFull).getFreeNetUsed(); + Long sendToShiledAddress1Amount = 3 * zenTokenFee; + Long sendToShiledAddress2Amount = costTokenAmount - sendToShiledAddress1Amount - zenTokenFee; shieldOutList.clear(); - String memo1 = "First public to shield same address transaction"; - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress1, - "" + sendToShiledAddress1Amount, memo1); - String memo2 = "Second public to shield same address transaction"; - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress1, - "" + sendToShiledAddress2Amount, memo2); - txid = PublicMethod.sendShieldCoinGetTxid( - zenTokenOwnerAddress, costTokenAmount, - null, null, - shieldOutList, - null, 0, - zenTokenOwnerKey, blockingStubFull); + String memo1 = "First public to shield same address transaction"; + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress1, "" + sendToShiledAddress1Amount, memo1); + String memo2 = "Second public to shield same address transaction"; + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress1, "" + sendToShiledAddress2Amount, memo2); + txid = + PublicMethod.sendShieldCoinGetTxid( + zenTokenOwnerAddress, + costTokenAmount, + null, + null, + shieldOutList, + null, + 0, + zenTokenOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getShieldedTransactionFee() == zenTokenFee); byId = PublicMethod.getTransactionById(txid, blockingStubFull); Assert.assertTrue(byId.get().getSignatureCount() == 1); - Long afterAssetBalance = PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, - PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull); - final Long afterNetUsed = PublicMethod - .getAccountResource(zenTokenOwnerAddress, blockingStubFull) - .getFreeNetUsed(); + Long afterAssetBalance = + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, + PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), + blockingStubFull); + final Long afterNetUsed = + PublicMethod.getAccountResource(zenTokenOwnerAddress, blockingStubFull).getFreeNetUsed(); logger.info("beforeAssetBalance:" + beforeAssetBalance); logger.info("afterAssetBalance:" + afterAssetBalance); Assert.assertTrue(beforeAssetBalance - afterAssetBalance == costTokenAmount); @@ -403,28 +514,30 @@ public void test5Public2TwoSameShieldAddress() { notes = PublicMethod.getShieldNotesByIvk(shieldAddressInfo1, blockingStubFull); Assert.assertTrue(notes.getNoteTxsCount() == 2); note = notes.getNoteTxs(0).getNote(); - Long receiverShieldTokenAmount1 = note.getValue(); + Long receiverShieldTokenAmount1 = note.getValue(); logger.info("receiverShieldTokenAmount1:" + receiverShieldTokenAmount1); logger.info("sendToShiledAddress1Amount:" + sendToShiledAddress1Amount); Assert.assertEquals(receiverShieldTokenAmount1, sendToShiledAddress1Amount); Assert.assertEquals(memo1, PublicMethod.getMemo(note)); note = notes.getNoteTxs(1).getNote(); - Long receiverShieldTokenAmount2 = note.getValue(); + Long receiverShieldTokenAmount2 = note.getValue(); Assert.assertEquals(receiverShieldTokenAmount2, sendToShiledAddress2Amount); Assert.assertEquals(memo2, PublicMethod.getMemo(note)); - } - - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - PublicMethod.transferAsset(foundationZenTokenAddress, tokenId, - PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, + PublicMethod.transferAsset( + foundationZenTokenAddress, + tokenId, + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull), zenTokenOwnerAddress, zenTokenOwnerKey, blockingStubFull); } -} \ No newline at end of file + blockingStubFull), + zenTokenOwnerAddress, + zenTokenOwnerKey, + blockingStubFull); + } +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken004.java index c0f70918..87c93555 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken004.java @@ -15,11 +15,12 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.ShieldAddressInfo; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class WalletTestZenToken004 extends TronBaseTest { List shieldOutList = new ArrayList<>(); +public class WalletTestZenToken004 extends TronBaseTest { + List shieldOutList = new ArrayList<>(); DecryptNotes notes; Note note; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -30,83 +31,98 @@ public class WalletTestZenToken004 extends TronBaseTest { List shieldOutL String receiverPublicKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); Optional sendShieldAddressInfo; String sendshieldAddress; - private String foundationZenTokenKey = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenOwnerKey"); + private String foundationZenTokenKey = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenOwnerKey"); byte[] foundationZenTokenAddress = PublicMethod.getFinalAddress(foundationZenTokenKey); - private String zenTokenId = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenId"); + private String zenTokenId = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenId"); private byte[] tokenId = zenTokenId.getBytes(); - private Long zenTokenFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.zenTokenFee"); + private Long zenTokenFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.zenTokenFee"); private Long costTokenAmount = 20 * zenTokenFee; - private Long zenTokenWhenCreateNewAddress = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.zenTokenWhenCreateNewAddress"); + private Long zenTokenWhenCreateNewAddress = + Configuration.getByPath("testng.conf") + .getLong("defaultParameter.zenTokenWhenCreateNewAddress"); - /** - * constructor. - */ - + /** constructor. */ - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(foundationZenTokenKey); PublicMethod.printAddress(zenTokenOwnerKey); - //Args.setFullNodeAllowShieldedTransaction(true); - Assert.assertTrue(PublicMethod.sendcoin(receiverPublicAddress, 1000000L, - foundationAddress, foundationKey, blockingStubFull)); + // Args.setFullNodeAllowShieldedTransaction(true); + Assert.assertTrue( + PublicMethod.sendcoin( + receiverPublicAddress, 1000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } - @Test(enabled = false, description = "Shield to two shield transaction", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "Shield to two shield transaction", + groups = {"daily", "shield"}) public void test1Shield2TwoShieldTransaction() { sendShieldAddressInfo = PublicMethod.generateShieldAddress(); sendshieldAddress = sendShieldAddressInfo.get().getAddress(); - String memo = "Use to TestZenToken004 shield address"; - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendshieldAddress, - "" + costTokenAmount, memo); - Assert.assertTrue(PublicMethod.sendShieldCoin( - foundationZenTokenAddress, costTokenAmount + zenTokenFee, - null, null, - shieldOutList, - null, 0, - foundationZenTokenKey, blockingStubFull)); + String memo = "Use to TestZenToken004 shield address"; + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, sendshieldAddress, "" + costTokenAmount, memo); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + foundationZenTokenAddress, + costTokenAmount + zenTokenFee, + null, + null, + shieldOutList, + null, + 0, + foundationZenTokenKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); notes = PublicMethod.listShieldNote(sendShieldAddressInfo, blockingStubFull); Optional shieldAddressInfo1 = PublicMethod.generateShieldAddress(); - String shieldAddress1 = shieldAddressInfo1.get().getAddress(); + String shieldAddress1 = shieldAddressInfo1.get().getAddress(); Optional shieldAddressInfo2 = PublicMethod.generateShieldAddress(); - String shieldAddress2 = shieldAddressInfo2.get().getAddress(); + String shieldAddress2 = shieldAddressInfo2.get().getAddress(); logger.info("shieldAddress1:" + shieldAddress1); logger.info("shieldAddress2:" + shieldAddress2); - Long sendToShiledAddress1Amount = 3 * zenTokenFee; - Long sendToShiledAddress2Amount = costTokenAmount - sendToShiledAddress1Amount - zenTokenFee; - String memo1 = "Shield to shield address1 transaction"; + Long sendToShiledAddress1Amount = 3 * zenTokenFee; + Long sendToShiledAddress2Amount = costTokenAmount - sendToShiledAddress1Amount - zenTokenFee; + String memo1 = "Shield to shield address1 transaction"; shieldOutList.clear(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress1, - "" + sendToShiledAddress1Amount, memo1); - String memo2 = "Shield to shield address2 transaction"; - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress2, - "" + sendToShiledAddress2Amount, memo2); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress1, "" + sendToShiledAddress1Amount, memo1); + String memo2 = "Shield to shield address2 transaction"; + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress2, "" + sendToShiledAddress2Amount, memo2); - Assert.assertTrue(PublicMethod.sendShieldCoin( - null, 0, - sendShieldAddressInfo.get(), notes.getNoteTxs(0), - shieldOutList, - null, 0, - zenTokenOwnerKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + null, + 0, + sendShieldAddressInfo.get(), + notes.getNoteTxs(0), + shieldOutList, + null, + 0, + zenTokenOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); notes = PublicMethod.listShieldNote(sendShieldAddressInfo, blockingStubFull); - Assert.assertTrue(PublicMethod.getSpendResult(sendShieldAddressInfo.get(), - notes.getNoteTxs(0), blockingStubFull).getResult()); + Assert.assertTrue( + PublicMethod.getSpendResult( + sendShieldAddressInfo.get(), notes.getNoteTxs(0), blockingStubFull) + .getResult()); notes = PublicMethod.listShieldNote(shieldAddressInfo1, blockingStubFull); note = notes.getNoteTxs(0).getNote(); - Long receiverShieldTokenAmount1 = note.getValue(); + Long receiverShieldTokenAmount1 = note.getValue(); logger.info("receiverShieldTokenAmount1:" + receiverShieldTokenAmount1); logger.info("sendToShiledAddress1Amount:" + sendToShiledAddress1Amount); Assert.assertEquals(receiverShieldTokenAmount1, sendToShiledAddress1Amount); @@ -114,129 +130,167 @@ public void test1Shield2TwoShieldTransaction() { notes = PublicMethod.listShieldNote(shieldAddressInfo2, blockingStubFull); note = notes.getNoteTxs(0).getNote(); - Long receiverShieldTokenAmount2 = note.getValue(); + Long receiverShieldTokenAmount2 = note.getValue(); Assert.assertEquals(receiverShieldTokenAmount2, sendToShiledAddress2Amount); Assert.assertEquals(memo2, PublicMethod.getMemo(note)); - } - @Test(enabled = false, - description = "Shield to one public and one shield transaction", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "Shield to one public and one shield transaction", + groups = {"daily", "shield"}) public void test2Shield2OneShieldAndOnePublicTransaction() { sendShieldAddressInfo = PublicMethod.generateShieldAddress(); sendshieldAddress = sendShieldAddressInfo.get().getAddress(); - String memo = "Use to TestZenToken004 shield address"; + String memo = "Use to TestZenToken004 shield address"; shieldOutList.clear(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendshieldAddress, - "" + costTokenAmount, memo); - Assert.assertTrue(PublicMethod.sendShieldCoin( - foundationZenTokenAddress, costTokenAmount + zenTokenFee, - null, null, - shieldOutList, - null, 0, - foundationZenTokenKey, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, sendshieldAddress, "" + costTokenAmount, memo); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + foundationZenTokenAddress, + costTokenAmount + zenTokenFee, + null, + null, + shieldOutList, + null, + 0, + foundationZenTokenKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); notes = PublicMethod.listShieldNote(sendShieldAddressInfo, blockingStubFull); Optional shieldAddressInfo1 = PublicMethod.generateShieldAddress(); - String shieldAddress1 = shieldAddressInfo1.get().getAddress(); + String shieldAddress1 = shieldAddressInfo1.get().getAddress(); logger.info("shieldAddress1:" + shieldAddress1); - Long sendToShiledAddress1Amount = 1 * zenTokenFee; - Long sendToPublicAddressAmount = costTokenAmount - sendToShiledAddress1Amount - zenTokenFee; + Long sendToShiledAddress1Amount = 1 * zenTokenFee; + Long sendToPublicAddressAmount = costTokenAmount - sendToShiledAddress1Amount - zenTokenFee; shieldOutList.clear(); - String memo1 = "Shield to shield address1 transaction"; - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress1, - "" + sendToShiledAddress1Amount, memo1); + String memo1 = "Shield to shield address1 transaction"; + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress1, "" + sendToShiledAddress1Amount, memo1); - Assert.assertTrue(PublicMethod.sendShieldCoin( - null, 0, - sendShieldAddressInfo.get(), notes.getNoteTxs(0), - shieldOutList, - receiverPublicAddress, sendToPublicAddressAmount, - zenTokenOwnerKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + null, + 0, + sendShieldAddressInfo.get(), + notes.getNoteTxs(0), + shieldOutList, + receiverPublicAddress, + sendToPublicAddressAmount, + zenTokenOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); notes = PublicMethod.listShieldNote(sendShieldAddressInfo, blockingStubFull); - Assert.assertTrue(PublicMethod.getSpendResult(sendShieldAddressInfo.get(), - notes.getNoteTxs(0), blockingStubFull).getResult()); + Assert.assertTrue( + PublicMethod.getSpendResult( + sendShieldAddressInfo.get(), notes.getNoteTxs(0), blockingStubFull) + .getResult()); notes = PublicMethod.listShieldNote(shieldAddressInfo1, blockingStubFull); note = notes.getNoteTxs(0).getNote(); - Long receiverShieldTokenAmount1 = note.getValue(); + Long receiverShieldTokenAmount1 = note.getValue(); logger.info("receiverShieldTokenAmount1:" + receiverShieldTokenAmount1); logger.info("sendToShiledAddress1Amount:" + sendToShiledAddress1Amount); Assert.assertEquals(receiverShieldTokenAmount1, sendToShiledAddress1Amount); Assert.assertEquals(memo1, PublicMethod.getMemo(note)); - Long afterReceiverPublicAssetBalance = PublicMethod.getAssetIssueValue(receiverPublicAddress, - PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull); + Long afterReceiverPublicAssetBalance = + PublicMethod.getAssetIssueValue( + receiverPublicAddress, + PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), + blockingStubFull); Assert.assertEquals(afterReceiverPublicAssetBalance, sendToPublicAddressAmount); } - @Test(enabled = false, - description = "Shield to one public and two shield transaction", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "Shield to one public and two shield transaction", + groups = {"daily", "shield"}) public void test3Public2OneShieldAndOnePublicTransaction() { sendShieldAddressInfo = PublicMethod.generateShieldAddress(); sendshieldAddress = sendShieldAddressInfo.get().getAddress(); - String memo = "Use to TestZenToken004 shield address"; + String memo = "Use to TestZenToken004 shield address"; shieldOutList.clear(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendshieldAddress, - "" + costTokenAmount, memo); - Assert.assertTrue(PublicMethod.sendShieldCoin( - foundationZenTokenAddress, costTokenAmount + zenTokenFee, - null, null, - shieldOutList, - null, 0, - foundationZenTokenKey, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, sendshieldAddress, "" + costTokenAmount, memo); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + foundationZenTokenAddress, + costTokenAmount + zenTokenFee, + null, + null, + shieldOutList, + null, + 0, + foundationZenTokenKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); notes = PublicMethod.listShieldNote(sendShieldAddressInfo, blockingStubFull); Optional shieldAddressInfo1 = PublicMethod.generateShieldAddress(); - String shieldAddress1 = shieldAddressInfo1.get().getAddress(); + String shieldAddress1 = shieldAddressInfo1.get().getAddress(); Optional shieldAddressInfo2 = PublicMethod.generateShieldAddress(); - String shieldAddress2 = shieldAddressInfo2.get().getAddress(); + String shieldAddress2 = shieldAddressInfo2.get().getAddress(); logger.info("shieldAddress1:" + shieldAddress1); logger.info("shieldAddress2:" + shieldAddress2); - Long sendToShiledAddress1Amount = 3 * zenTokenFee; - Long sendToShiledAddress2Amount = 4 * zenTokenFee; - final Long sendToPublicAddressAmount = costTokenAmount - sendToShiledAddress1Amount - - sendToShiledAddress2Amount - zenTokenWhenCreateNewAddress; + Long sendToShiledAddress1Amount = 3 * zenTokenFee; + Long sendToShiledAddress2Amount = 4 * zenTokenFee; + final Long sendToPublicAddressAmount = + costTokenAmount + - sendToShiledAddress1Amount + - sendToShiledAddress2Amount + - zenTokenWhenCreateNewAddress; shieldOutList.clear(); - String memo1 = "Shield to shield address1 transaction"; - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress1, - "" + sendToShiledAddress1Amount, memo1); - String memo2 = "Shield to shield address2 transaction"; - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress2, - "" + sendToShiledAddress2Amount, memo2); - //When receiver public address don't active,the fee is 1000000 + String memo1 = "Shield to shield address1 transaction"; + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress1, "" + sendToShiledAddress1Amount, memo1); + String memo2 = "Shield to shield address2 transaction"; + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress2, "" + sendToShiledAddress2Amount, memo2); + // When receiver public address don't active,the fee is 1000000 ECKey ecKey3 = new ECKey(Utils.getRandom()); - byte[] notActivePublicAddress = ecKey3.getAddress(); + byte[] notActivePublicAddress = ecKey3.getAddress(); - Assert.assertTrue(PublicMethod.sendShieldCoin( - null, 0, - sendShieldAddressInfo.get(), notes.getNoteTxs(0), - shieldOutList, - notActivePublicAddress, sendToPublicAddressAmount, - zenTokenOwnerKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + null, + 0, + sendShieldAddressInfo.get(), + notes.getNoteTxs(0), + shieldOutList, + notActivePublicAddress, + sendToPublicAddressAmount, + zenTokenOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); notes = PublicMethod.listShieldNote(sendShieldAddressInfo, blockingStubFull); - Assert.assertTrue(PublicMethod.getSpendResult(sendShieldAddressInfo.get(), - notes.getNoteTxs(0), blockingStubFull).getResult()); + Assert.assertTrue( + PublicMethod.getSpendResult( + sendShieldAddressInfo.get(), notes.getNoteTxs(0), blockingStubFull) + .getResult()); notes = PublicMethod.listShieldNote(shieldAddressInfo1, blockingStubFull); note = notes.getNoteTxs(0).getNote(); - Long receiverShieldTokenAmount1 = note.getValue(); + Long receiverShieldTokenAmount1 = note.getValue(); Assert.assertEquals(receiverShieldTokenAmount1, sendToShiledAddress1Amount); Assert.assertEquals(memo1, PublicMethod.getMemo(note)); notes = PublicMethod.listShieldNote(shieldAddressInfo2, blockingStubFull); note = notes.getNoteTxs(0).getNote(); - Long receiverShieldTokenAmount2 = note.getValue(); + Long receiverShieldTokenAmount2 = note.getValue(); Assert.assertEquals(receiverShieldTokenAmount2, sendToShiledAddress2Amount); Assert.assertEquals(memo2, PublicMethod.getMemo(note)); - final Long afterNotActivePublicAssetBalance = PublicMethod - .getAssetIssueValue(notActivePublicAddress, + final Long afterNotActivePublicAssetBalance = + PublicMethod.getAssetIssueValue( + notActivePublicAddress, PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), blockingStubFull); logger.info("afterNotActivePublicAssetBalance:" + afterNotActivePublicAssetBalance); @@ -244,14 +298,18 @@ public void test3Public2OneShieldAndOnePublicTransaction() { Assert.assertEquals(afterNotActivePublicAssetBalance, sendToPublicAddressAmount); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - PublicMethod.transferAsset(foundationZenTokenAddress, tokenId, - PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, + PublicMethod.transferAsset( + foundationZenTokenAddress, + tokenId, + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull), zenTokenOwnerAddress, zenTokenOwnerKey, blockingStubFull); } -} \ No newline at end of file + blockingStubFull), + zenTokenOwnerAddress, + zenTokenOwnerKey, + blockingStubFull); + } +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken005.java index ea9202f7..50c1b121 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken005.java @@ -15,11 +15,12 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.ShieldAddressInfo; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class WalletTestZenToken005 extends TronBaseTest { List shieldOutList = new ArrayList<>(); +public class WalletTestZenToken005 extends TronBaseTest { + List shieldOutList = new ArrayList<>(); DecryptNotes notes; Note note; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -28,159 +29,218 @@ public class WalletTestZenToken005 extends TronBaseTest { List shieldOutL ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] receiverPublicAddress = ecKey2.getAddress(); String receiverPublicKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - private String foundationZenTokenKey = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenOwnerKey"); + private String foundationZenTokenKey = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenOwnerKey"); byte[] foundationZenTokenAddress = PublicMethod.getFinalAddress(foundationZenTokenKey); - private String zenTokenId = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenId"); + private String zenTokenId = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenId"); private byte[] tokenId = zenTokenId.getBytes(); - private Long zenTokenFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.zenTokenFee"); + private Long zenTokenFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.zenTokenFee"); private Long costTokenAmount = 10 * zenTokenFee; - /** - * constructor. - */ - + /** constructor. */ - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(foundationZenTokenKey); - PublicMethod.printAddress(zenTokenOwnerKey); Assert.assertTrue(PublicMethod.transferAsset(zenTokenOwnerAddress, tokenId, - costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(receiverPublicAddress, 1000000L, - foundationAddress, foundationKey, blockingStubFull)); + PublicMethod.printAddress(zenTokenOwnerKey); + Assert.assertTrue( + PublicMethod.transferAsset( + zenTokenOwnerAddress, + tokenId, + costTokenAmount, + foundationZenTokenAddress, + foundationZenTokenKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + receiverPublicAddress, 1000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Args.setFullNodeAllowShieldedTransaction(true); + // Args.setFullNodeAllowShieldedTransaction(true); } - @Test(enabled = false, - description = "The receiver shield address can't more then 2", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "The receiver shield address can't more then 2", + groups = {"daily", "shield"}) public void test1ReceiverShieldAddressCanNotMoreThenTwo() { Optional shieldAddressInfo1 = PublicMethod.generateShieldAddress(); - String shieldAddress1 = shieldAddressInfo1.get().getAddress(); + String shieldAddress1 = shieldAddressInfo1.get().getAddress(); Optional shieldAddressInfo2 = PublicMethod.generateShieldAddress(); - String shieldAddress2 = shieldAddressInfo2.get().getAddress(); + String shieldAddress2 = shieldAddressInfo2.get().getAddress(); Optional shieldAddressInfo3 = PublicMethod.generateShieldAddress(); - String shieldAddress3 = shieldAddressInfo3.get().getAddress(); + String shieldAddress3 = shieldAddressInfo3.get().getAddress(); logger.info("shieldAddress1:" + shieldAddress1); logger.info("shieldAddress2:" + shieldAddress2); logger.info("shieldAddress3:" + shieldAddress3); - Long sendToShiledAddress1Amount = 3 * zenTokenFee; - Long sendToShiledAddress2Amount = 2 * zenTokenFee; - Long sendToShiledAddress3Amount = costTokenAmount - sendToShiledAddress1Amount - - sendToShiledAddress2Amount - zenTokenFee; - String memo1 = "Shield to shield address1 transaction"; - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress1, - "" + sendToShiledAddress1Amount, memo1); - String memo2 = "Shield to shield address2 transaction"; - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress2, - "" + sendToShiledAddress2Amount, memo2); - String memo3 = "Shield to shield address3 transaction"; - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress3, - "" + sendToShiledAddress3Amount, memo3); + Long sendToShiledAddress1Amount = 3 * zenTokenFee; + Long sendToShiledAddress2Amount = 2 * zenTokenFee; + Long sendToShiledAddress3Amount = + costTokenAmount - sendToShiledAddress1Amount - sendToShiledAddress2Amount - zenTokenFee; + String memo1 = "Shield to shield address1 transaction"; + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress1, "" + sendToShiledAddress1Amount, memo1); + String memo2 = "Shield to shield address2 transaction"; + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress2, "" + sendToShiledAddress2Amount, memo2); + String memo3 = "Shield to shield address3 transaction"; + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress3, "" + sendToShiledAddress3Amount, memo3); - Assert.assertFalse(PublicMethod.sendShieldCoin( - zenTokenOwnerAddress, costTokenAmount, - null, null, - shieldOutList, - null, 0, - zenTokenOwnerKey, blockingStubFull)); + Assert.assertFalse( + PublicMethod.sendShieldCoin( + zenTokenOwnerAddress, + costTokenAmount, + null, + null, + shieldOutList, + null, + 0, + zenTokenOwnerKey, + blockingStubFull)); } - @Test(enabled = false, - description = "The receiver can't only one public address", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "The receiver can't only one public address", + groups = {"daily", "shield"}) public void test2ReceiverPublicCanNotOnlyOnePublic() { - Assert.assertTrue(PublicMethod.transferAsset(zenTokenOwnerAddress, tokenId, - costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + zenTokenOwnerAddress, + tokenId, + costTokenAmount, + foundationZenTokenAddress, + foundationZenTokenKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); shieldOutList.clear(); - Assert.assertFalse(PublicMethod.sendShieldCoin( - zenTokenOwnerAddress, costTokenAmount, - null, null, - shieldOutList, - receiverPublicAddress, costTokenAmount - zenTokenFee, - zenTokenOwnerKey, blockingStubFull)); + Assert.assertFalse( + PublicMethod.sendShieldCoin( + zenTokenOwnerAddress, + costTokenAmount, + null, + null, + shieldOutList, + receiverPublicAddress, + costTokenAmount - zenTokenFee, + zenTokenOwnerKey, + blockingStubFull)); } - @Test(enabled = false, - description = "Public send amount must equal receiver amount + shieldFee", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "Public send amount must equal receiver amount + shieldFee", + groups = {"daily", "shield"}) public void test3SendAmountMustEqualReceiverAmountPlusShieldFee() { - Assert.assertTrue(PublicMethod.transferAsset(zenTokenOwnerAddress, tokenId, - costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + zenTokenOwnerAddress, + tokenId, + costTokenAmount, + foundationZenTokenAddress, + foundationZenTokenKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Optional shieldAddressInfo1 = PublicMethod.generateShieldAddress(); - String shieldAddress1 = shieldAddressInfo1.get().getAddress(); + String shieldAddress1 = shieldAddressInfo1.get().getAddress(); Optional shieldAddressInfo2 = PublicMethod.generateShieldAddress(); - String shieldAddress2 = shieldAddressInfo2.get().getAddress(); + String shieldAddress2 = shieldAddressInfo2.get().getAddress(); logger.info("shieldAddress1:" + shieldAddress1); logger.info("shieldAddress2:" + shieldAddress2); - Long sendToShiledAddress1Amount = 1 * zenTokenFee; - Long sendToShiledAddress2Amount = 2 * zenTokenFee; + Long sendToShiledAddress1Amount = 1 * zenTokenFee; + Long sendToShiledAddress2Amount = 2 * zenTokenFee; shieldOutList.clear(); - String memo1 = "Public to shield address1 transaction"; - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress1, - "" + sendToShiledAddress1Amount, memo1); - String memo2 = "Public to shield address2 transaction"; - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress2, - "" + sendToShiledAddress2Amount, memo2); - //Public receiver amount is wrong - Long sendToPublicAddressAmount = costTokenAmount - sendToShiledAddress1Amount - - sendToShiledAddress2Amount - zenTokenFee; - Assert.assertFalse(PublicMethod.sendShieldCoin( - zenTokenOwnerAddress, costTokenAmount, - null, null, - shieldOutList, - receiverPublicAddress, sendToPublicAddressAmount - 1, - zenTokenOwnerKey, blockingStubFull)); - //Shield receiver amount is wrong + String memo1 = "Public to shield address1 transaction"; + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress1, "" + sendToShiledAddress1Amount, memo1); + String memo2 = "Public to shield address2 transaction"; + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress2, "" + sendToShiledAddress2Amount, memo2); + // Public receiver amount is wrong + Long sendToPublicAddressAmount = + costTokenAmount - sendToShiledAddress1Amount - sendToShiledAddress2Amount - zenTokenFee; + Assert.assertFalse( + PublicMethod.sendShieldCoin( + zenTokenOwnerAddress, + costTokenAmount, + null, + null, + shieldOutList, + receiverPublicAddress, + sendToPublicAddressAmount - 1, + zenTokenOwnerKey, + blockingStubFull)); + // Shield receiver amount is wrong sendToShiledAddress1Amount = 1 * zenTokenFee; sendToShiledAddress2Amount = 2 * zenTokenFee; - sendToPublicAddressAmount = costTokenAmount - sendToShiledAddress1Amount - - sendToShiledAddress2Amount - zenTokenFee; + sendToPublicAddressAmount = + costTokenAmount - sendToShiledAddress1Amount - sendToShiledAddress2Amount - zenTokenFee; shieldOutList.clear(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress1, - "" + (sendToShiledAddress1Amount - 1), memo1); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress2, - "" + sendToShiledAddress2Amount, memo2); - Assert.assertFalse(PublicMethod.sendShieldCoin( - zenTokenOwnerAddress, costTokenAmount, - null, null, - shieldOutList, - receiverPublicAddress, sendToPublicAddressAmount, - zenTokenOwnerKey, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress1, "" + (sendToShiledAddress1Amount - 1), memo1); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress2, "" + sendToShiledAddress2Amount, memo2); + Assert.assertFalse( + PublicMethod.sendShieldCoin( + zenTokenOwnerAddress, + costTokenAmount, + null, + null, + shieldOutList, + receiverPublicAddress, + sendToPublicAddressAmount, + zenTokenOwnerKey, + blockingStubFull)); sendToShiledAddress1Amount = 1 * zenTokenFee; sendToShiledAddress2Amount = 2 * zenTokenFee; - sendToPublicAddressAmount = costTokenAmount - sendToShiledAddress1Amount - - sendToShiledAddress2Amount - zenTokenFee; + sendToPublicAddressAmount = + costTokenAmount - sendToShiledAddress1Amount - sendToShiledAddress2Amount - zenTokenFee; shieldOutList.clear(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress1, - "" + sendToShiledAddress1Amount, memo1); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress2, - "" + sendToShiledAddress2Amount, memo2); - Assert.assertTrue(PublicMethod.sendShieldCoin( - zenTokenOwnerAddress, costTokenAmount, - null, null, - shieldOutList, - receiverPublicAddress, sendToPublicAddressAmount, - zenTokenOwnerKey, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress1, "" + sendToShiledAddress1Amount, memo1); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress2, "" + sendToShiledAddress2Amount, memo2); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + zenTokenOwnerAddress, + costTokenAmount, + null, + null, + shieldOutList, + receiverPublicAddress, + sendToPublicAddressAmount, + zenTokenOwnerKey, + blockingStubFull)); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - PublicMethod.transferAsset(foundationZenTokenAddress, tokenId, - PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, + PublicMethod.transferAsset( + foundationZenTokenAddress, + tokenId, + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull), zenTokenOwnerAddress, zenTokenOwnerKey, blockingStubFull); } -} \ No newline at end of file + blockingStubFull), + zenTokenOwnerAddress, + zenTokenOwnerKey, + blockingStubFull); + } +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken006.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken006.java index ce6faa17..95f50c74 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken006.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken006.java @@ -15,11 +15,12 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.ShieldAddressInfo; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class WalletTestZenToken006 extends TronBaseTest { Optional shieldAddressInfo; +public class WalletTestZenToken006 extends TronBaseTest { + Optional shieldAddressInfo; String shieldAddress; List shieldOutList = new ArrayList<>(); List shieldInputList = new ArrayList<>(); @@ -29,208 +30,262 @@ public class WalletTestZenToken006 extends TronBaseTest { Optional\\001\\262B%\\371\\'\\005w\\354\\200\"\n" - + "}"; + memo = + "{\n" + + " note {\n" + + " value: 49957\n" + + " payment_address: \"ztron1f42n7h0l3p8mlaq0d0rxdkhq" + + "n6xuq49xhvj593wfduy24kn3xrmxfpqt8lnmh9ysnu5nzt3zgzx\"\n" + + " rcm: \"\\210x\\256\\211\\256v\\0344\\267\\240\\375\\377xs\\3" + + "50\\3558^Y\\200i0$S\\312KK\\326l\\234J\\b\"\n" + + " memo: \"System.exit(1);\"\n" + + " }\n" + + " txid: \"\\215\\332\\304\\241\\362\\vbt\\250\\364\\353\\30" + + "7\\'o\\275\\313ya*)\\320>\\001\\262B%\\371\\'\\005w\\354\\200\"\n" + + "}"; shieldOutList.clear(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress, - "" + zenTokenFee, memo); - Assert.assertTrue(PublicMethod.sendShieldCoin( - zenTokenOwnerAddress, 2 * zenTokenFee, - null, null, - shieldOutList, - null, 0, - zenTokenOwnerKey, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList(shieldOutList, shieldAddress, "" + zenTokenFee, memo); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + zenTokenOwnerAddress, + 2 * zenTokenFee, + null, + null, + shieldOutList, + null, + 0, + zenTokenOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); notes = PublicMethod.listShieldNote(shieldAddressInfo, blockingStubFull); note = notes.getNoteTxs(0).getNote(); - Long receiverShieldTokenAmount = note.getValue(); + Long receiverShieldTokenAmount = note.getValue(); Assert.assertEquals(receiverShieldTokenAmount, zenTokenFee); Assert.assertEquals(memo, PublicMethod.getMemo(note)); - - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - PublicMethod.transferAsset(foundationZenTokenAddress, tokenId, - PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, + PublicMethod.transferAsset( + foundationZenTokenAddress, + tokenId, + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull), zenTokenOwnerAddress, zenTokenOwnerKey, blockingStubFull); } -} \ No newline at end of file + blockingStubFull), + zenTokenOwnerAddress, + zenTokenOwnerKey, + blockingStubFull); + } +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken007.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken007.java index bfb34814..176f8632 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken007.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken007.java @@ -28,14 +28,15 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.ShieldAddressInfo; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.zen.address.DiversifierT; @Slf4j public class WalletTestZenToken007 extends TronBaseTest { - private static ByteString assetAccountId = null; Optional sendShieldAddressInfo1; + private static ByteString assetAccountId = null; + Optional sendShieldAddressInfo1; Optional sendShieldAddressInfo2; Optional sendShieldAddressInfo3; Optional receiverShieldAddressInfo; @@ -84,29 +85,24 @@ public class WalletTestZenToken007 extends TronBaseTest { String zenTokenOwnerKey4 = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); private ManagedChannel channelSolidity1 = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity1 = null; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - private String soliditynode1 = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1); - private String foundationZenTokenKey = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenOwnerKey"); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + private String soliditynode1 = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); + private String foundationZenTokenKey = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenOwnerKey"); byte[] foundationZenTokenAddress = PublicMethod.getFinalAddress(foundationZenTokenKey); - private String zenTokenId = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenId"); + private String zenTokenId = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenId"); private byte[] tokenId = zenTokenId.getBytes(); - private Long zenTokenFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.zenTokenFee"); + private Long zenTokenFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.zenTokenFee"); private Long costTokenAmount = 10 * zenTokenFee; private Long sendTokenAmount = 8 * zenTokenFee; - /** - * constructor. - */ - + /** constructor. */ - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); @@ -114,24 +110,45 @@ public void beforeClass() { PublicMethod.printAddress(zenTokenOwnerKey1); PublicMethod.printAddress(zenTokenOwnerKey2); PublicMethod.printAddress(zenTokenOwnerKey3); - PublicMethod.printAddress(zenTokenOwnerKey4); channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - channelSolidity1 = ManagedChannelBuilder.forTarget(soliditynode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(zenTokenOwnerKey4); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + channelSolidity1 = ManagedChannelBuilder.forTarget(soliditynode1).usePlaintext().build(); blockingStubSolidity1 = WalletSolidityGrpc.newBlockingStub(channelSolidity1); - Assert.assertTrue(PublicMethod.transferAsset(zenTokenOwnerAddress1, tokenId, - costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.transferAsset(zenTokenOwnerAddress2, tokenId, - costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.transferAsset(zenTokenOwnerAddress3, tokenId, - costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.transferAsset(zenTokenOwnerAddress4, tokenId, - costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + zenTokenOwnerAddress1, + tokenId, + costTokenAmount, + foundationZenTokenAddress, + foundationZenTokenKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + zenTokenOwnerAddress2, + tokenId, + costTokenAmount, + foundationZenTokenAddress, + foundationZenTokenKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + zenTokenOwnerAddress3, + tokenId, + costTokenAmount, + foundationZenTokenAddress, + foundationZenTokenKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + zenTokenOwnerAddress4, + tokenId, + costTokenAmount, + foundationZenTokenAddress, + foundationZenTokenKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Args.setFullNodeAllowShieldedTransaction(true); + // Args.setFullNodeAllowShieldedTransaction(true); sendShieldAddressInfo1 = PublicMethod.generateShieldAddress(); sendShieldAddressInfo2 = PublicMethod.generateShieldAddress(); sendShieldAddressInfo3 = PublicMethod.generateShieldAddress(); @@ -144,22 +161,52 @@ public void beforeClass() { memo1 = "Shield memo1 in " + System.currentTimeMillis(); memo2 = "Shield memo2 in " + System.currentTimeMillis(); memo3 = "Shield memo3 in " + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress1, - "" + (sendTokenAmount - zenTokenFee), memo1); - Assert.assertTrue(PublicMethod.sendShieldCoin(zenTokenOwnerAddress1, sendTokenAmount, null, - null, shieldOutList, null, 0, zenTokenOwnerKey1, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, sendShieldAddress1, "" + (sendTokenAmount - zenTokenFee), memo1); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + zenTokenOwnerAddress1, + sendTokenAmount, + null, + null, + shieldOutList, + null, + 0, + zenTokenOwnerKey1, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); shieldOutList.clear(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress2, - "" + (sendTokenAmount - zenTokenFee), memo2); - Assert.assertTrue(PublicMethod.sendShieldCoin(zenTokenOwnerAddress2, sendTokenAmount, null, - null, shieldOutList, null, 0, zenTokenOwnerKey2, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, sendShieldAddress2, "" + (sendTokenAmount - zenTokenFee), memo2); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + zenTokenOwnerAddress2, + sendTokenAmount, + null, + null, + shieldOutList, + null, + 0, + zenTokenOwnerKey2, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); shieldOutList.clear(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress3, - "" + (sendTokenAmount - zenTokenFee), memo3); - Assert.assertTrue(PublicMethod.sendShieldCoin(zenTokenOwnerAddress3, sendTokenAmount, null, - null, shieldOutList, null, 0, zenTokenOwnerKey3, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, sendShieldAddress3, "" + (sendTokenAmount - zenTokenFee), memo3); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + zenTokenOwnerAddress3, + sendTokenAmount, + null, + null, + shieldOutList, + null, + 0, + zenTokenOwnerKey3, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); notes = PublicMethod.listShieldNote(sendShieldAddressInfo1, blockingStubFull); sendNote1 = notes.getNoteTxs(0).getNote(); @@ -167,23 +214,23 @@ public void beforeClass() { sendNote2 = notes.getNoteTxs(0).getNote(); notes = PublicMethod.listShieldNote(sendShieldAddressInfo3, blockingStubFull); sendNote3 = notes.getNoteTxs(0).getNote(); - } - /** - * constructor. - */ - @Test(enabled = false, description = "Get spending key", groups = {"daily", "shield"}) + /** constructor. */ + @Test( + enabled = false, + description = "Get spending key", + groups = {"daily", "shield"}) public void test01GetSpendingKey() { sk = blockingStubFull.getSpendingKey(EmptyMessage.newBuilder().build()); logger.info("sk: " + ByteArray.toHexString(sk.getValue().toByteArray())); - } - /** - * constructor. - */ - @Test(enabled = false, description = "Get diversifier", groups = {"daily", "shield"}) + /** constructor. */ + @Test( + enabled = false, + description = "Get diversifier", + groups = {"daily", "shield"}) public void test02GetDiversifier() { diversifierMessage1 = blockingStubFull.getDiversifier(EmptyMessage.newBuilder().build()); logger.info("d1: " + ByteArray.toHexString(diversifierMessage1.getD().toByteArray())); @@ -191,25 +238,25 @@ public void test02GetDiversifier() { logger.info("d2: " + ByteArray.toHexString(diversifierMessage2.getD().toByteArray())); diversifierMessage3 = blockingStubFull.getDiversifier(EmptyMessage.newBuilder().build()); logger.info("d3: " + ByteArray.toHexString(diversifierMessage3.getD().toByteArray())); - } - /** - * constructor. - */ - @Test(enabled = false, description = "Get expanded spending key", groups = {"daily", "shield"}) + /** constructor. */ + @Test( + enabled = false, + description = "Get expanded spending key", + groups = {"daily", "shield"}) public void test03GetExpandedSpendingKey() { expandedSpendingKeyMessage = blockingStubFull.getExpandedSpendingKey(sk); logger.info("ask: " + ByteArray.toHexString(expandedSpendingKeyMessage.getAsk().toByteArray())); logger.info("nsk: " + ByteArray.toHexString(expandedSpendingKeyMessage.getNsk().toByteArray())); logger.info("ovk: " + ByteArray.toHexString(expandedSpendingKeyMessage.getOvk().toByteArray())); - } - /** - * constructor. - */ - @Test(enabled = false, description = "Get AK from ASK", groups = {"daily", "shield"}) + /** constructor. */ + @Test( + enabled = false, + description = "Get AK from ASK", + groups = {"daily", "shield"}) public void test04GetAkFromAsk() { BytesMessage.Builder askBuilder = BytesMessage.newBuilder(); askBuilder.setValue(expandedSpendingKeyMessage.getAsk()); @@ -217,10 +264,11 @@ public void test04GetAkFromAsk() { logger.info("ak: " + ByteArray.toHexString(ak.getValue().toByteArray())); } - /** - * constructor. - */ - @Test(enabled = false, description = "Get Nk from Nsk", groups = {"daily", "shield"}) + /** constructor. */ + @Test( + enabled = false, + description = "Get Nk from Nsk", + groups = {"daily", "shield"}) public void test05GetNkFromNsk() { BytesMessage.Builder nskBuilder = BytesMessage.newBuilder(); nskBuilder.setValue(expandedSpendingKeyMessage.getNsk()); @@ -228,10 +276,11 @@ public void test05GetNkFromNsk() { logger.info("nk: " + ByteArray.toHexString(nk.getValue().toByteArray())); } - /** - * constructor. - */ - @Test(enabled = false, description = "Get incoming viewing Key", groups = {"daily", "shield"}) + /** constructor. */ + @Test( + enabled = false, + description = "Get incoming viewing Key", + groups = {"daily", "shield"}) public void test06GetIncomingViewingKey() { ViewingKeyMessage.Builder viewBuilder = ViewingKeyMessage.newBuilder(); viewBuilder.setAk(ak.getValue()); @@ -240,10 +289,11 @@ public void test06GetIncomingViewingKey() { logger.info("ivk: " + ByteArray.toHexString(ivk.getIvk().toByteArray())); } - /** - * constructor. - */ - @Test(enabled = false, description = "Get Zen Payment Address", groups = {"daily", "shield"}) + /** constructor. */ + @Test( + enabled = false, + description = "Get Zen Payment Address", + groups = {"daily", "shield"}) public void test07GetZenPaymentAddress() { IncomingViewingKeyDiversifierMessage.Builder builder = IncomingViewingKeyDiversifierMessage.newBuilder(); @@ -286,58 +336,86 @@ public void test07GetZenPaymentAddress() { addressInfo3.setOvk(expandedSpendingKeyMessage.getOvk().toByteArray()); addressInfo3.setPkD(addressMessage.getPkD().toByteArray()); receiverAddressInfo3 = Optional.of(addressInfo3); - - } - @Test(enabled = false, description = "Shield to shield transaction", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "Shield to shield transaction", + groups = {"daily", "shield"}) public void test08Shield2ShieldTransaction() { - //S to S address1 + // S to S address1 receiverShieldAddress1 = receiverAddressInfo1.get().getAddress(); shieldOutList.clear(); ; memo1 = "Send shield to receiver1 shield memo in" + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, receiverShieldAddress1, - "" + (sendNote1.getValue() - zenTokenFee), memo1); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, + receiverShieldAddress1, + "" + (sendNote1.getValue() - zenTokenFee), + memo1); notes = PublicMethod.listShieldNote(sendShieldAddressInfo1, blockingStubFull); - Assert.assertTrue(PublicMethod.sendShieldCoin( - null, 0, - sendShieldAddressInfo1.get(), notes.getNoteTxs(0), - shieldOutList, - null, 0, - zenTokenOwnerKey1, blockingStubFull)); - //S to S address2 + Assert.assertTrue( + PublicMethod.sendShieldCoin( + null, + 0, + sendShieldAddressInfo1.get(), + notes.getNoteTxs(0), + shieldOutList, + null, + 0, + zenTokenOwnerKey1, + blockingStubFull)); + // S to S address2 receiverShieldAddress2 = receiverAddressInfo2.get().getAddress(); shieldOutList.clear(); ; memo2 = "Send shield2 to receiver shield memo in" + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, receiverShieldAddress2, - "" + (sendNote2.getValue() - zenTokenFee), memo2); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, + receiverShieldAddress2, + "" + (sendNote2.getValue() - zenTokenFee), + memo2); notes = PublicMethod.listShieldNote(sendShieldAddressInfo2, blockingStubFull); - Assert.assertTrue(PublicMethod.sendShieldCoin( - null, 0, - sendShieldAddressInfo2.get(), notes.getNoteTxs(0), - shieldOutList, - null, 0, - zenTokenOwnerKey2, blockingStubFull)); - //S to S address3 + Assert.assertTrue( + PublicMethod.sendShieldCoin( + null, + 0, + sendShieldAddressInfo2.get(), + notes.getNoteTxs(0), + shieldOutList, + null, + 0, + zenTokenOwnerKey2, + blockingStubFull)); + // S to S address3 receiverShieldAddress3 = receiverAddressInfo3.get().getAddress(); shieldOutList.clear(); ; memo3 = "Send shield3 to receiver shield memo in" + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, receiverShieldAddress3, - "" + (sendNote3.getValue() - zenTokenFee), memo3); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, + receiverShieldAddress3, + "" + (sendNote3.getValue() - zenTokenFee), + memo3); notes = PublicMethod.listShieldNote(sendShieldAddressInfo3, blockingStubFull); - Assert.assertTrue(PublicMethod.sendShieldCoin( - null, 0, - sendShieldAddressInfo3.get(), notes.getNoteTxs(0), - shieldOutList, - null, 0, - zenTokenOwnerKey3, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + null, + 0, + sendShieldAddressInfo3.get(), + notes.getNoteTxs(0), + shieldOutList, + null, + 0, + zenTokenOwnerKey3, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Same sk and different d can produce different + // Same sk and different d can produce different // shield address,the notes can scan out by same ivk. notes = PublicMethod.getShieldNotesByIvk(receiverAddressInfo1, blockingStubFull); Assert.assertTrue(notes.getNoteTxsCount() == 3); @@ -353,10 +431,12 @@ public void test08Shield2ShieldTransaction() { Assert.assertTrue(receiverNote3.getValue() == sendNote3.getValue() - zenTokenFee); } - @Test(enabled = false, - description = "Shield to shield transaction without ask", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "Shield to shield transaction without ask", + groups = {"daily", "shield"}) public void test09Shield2ShieldTransactionWithoutAsk() { - //Same sk and different d can produce different shield address, + // Same sk and different d can produce different shield address, // the notes can use by scan from same ovk. sendShieldAddressInfo1 = PublicMethod.generateShieldAddress(); sendShieldAddress1 = sendShieldAddressInfo1.get().getAddress(); @@ -372,39 +452,66 @@ public void test09Shield2ShieldTransactionWithoutAsk() { shieldOutList.clear(); ; memo1 = "Send shield address 1 without ask" + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress1, - "" + (receiverNote1.getValue() - zenTokenFee), memo1); - - Assert.assertTrue(PublicMethod.sendShieldCoinWithoutAsk( - null, 0, - receiverAddressInfo1.get(), notes.getNoteTxs(0), - shieldOutList, - null, 0, - zenTokenOwnerKey1, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, + sendShieldAddress1, + "" + (receiverNote1.getValue() - zenTokenFee), + memo1); + + Assert.assertTrue( + PublicMethod.sendShieldCoinWithoutAsk( + null, + 0, + receiverAddressInfo1.get(), + notes.getNoteTxs(0), + shieldOutList, + null, + 0, + zenTokenOwnerKey1, + blockingStubFull)); shieldOutList.clear(); ; memo2 = "Send shield address 2 without ask" + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress2, - "" + (receiverNote2.getValue() - zenTokenFee), memo2); - Assert.assertTrue(PublicMethod.sendShieldCoinWithoutAsk( - null, 0, - receiverAddressInfo2.get(), notes.getNoteTxs(1), - shieldOutList, - null, 0, - zenTokenOwnerKey2, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, + sendShieldAddress2, + "" + (receiverNote2.getValue() - zenTokenFee), + memo2); + Assert.assertTrue( + PublicMethod.sendShieldCoinWithoutAsk( + null, + 0, + receiverAddressInfo2.get(), + notes.getNoteTxs(1), + shieldOutList, + null, + 0, + zenTokenOwnerKey2, + blockingStubFull)); shieldOutList.clear(); ; memo3 = "Send shield address 3 without ask" + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress3, - "" + (receiverNote3.getValue() - zenTokenFee), memo3); - Assert.assertTrue(PublicMethod.sendShieldCoin( - null, 0, - receiverAddressInfo3.get(), notes.getNoteTxs(2), - shieldOutList, - null, 0, - zenTokenOwnerKey3, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, + sendShieldAddress3, + "" + (receiverNote3.getValue() - zenTokenFee), + memo3); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + null, + 0, + receiverAddressInfo3.get(), + notes.getNoteTxs(2), + shieldOutList, + null, + 0, + zenTokenOwnerKey3, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -428,68 +535,107 @@ public void test09Shield2ShieldTransactionWithoutAsk() { Assert.assertEquals(memo3, PublicMethod.getMemo(sendNote3)); } - @Test(enabled = false, description = "Get shield Nulltifier", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "Get shield Nulltifier", + groups = {"daily", "shield"}) public void test10GetShieldNulltifier() { notes = PublicMethod.listShieldNote(sendShieldAddressInfo1, blockingStubFull); - Assert.assertEquals(PublicMethod.getShieldNullifier(sendShieldAddressInfo1.get(), - notes.getNoteTxs(0), blockingStubFull).length(), 64); + Assert.assertEquals( + PublicMethod.getShieldNullifier( + sendShieldAddressInfo1.get(), notes.getNoteTxs(0), blockingStubFull) + .length(), + 64); notes = PublicMethod.listShieldNote(receiverAddressInfo1, blockingStubFull); - Assert.assertEquals(PublicMethod.getShieldNullifier(receiverAddressInfo1.get(), - notes.getNoteTxs(0), blockingStubFull).length(), 64); - - Assert.assertTrue(PublicMethod.getSpendResult(receiverAddressInfo1.get(), - notes.getNoteTxs(0), blockingStubFull).getResult()); + Assert.assertEquals( + PublicMethod.getShieldNullifier( + receiverAddressInfo1.get(), notes.getNoteTxs(0), blockingStubFull) + .length(), + 64); + + Assert.assertTrue( + PublicMethod.getSpendResult( + receiverAddressInfo1.get(), notes.getNoteTxs(0), blockingStubFull) + .getResult()); } - @Test(enabled = false, - description = "Same sk transfer shield address note is spent", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "Same sk transfer shield address note is spent", + groups = {"daily", "shield"}) public void test11SameSkTransferShieldAddressNoteCanSpent() { notes = PublicMethod.getShieldNotesByIvk(receiverAddressInfo2, blockingStubFull); receiverNote1 = notes.getNoteTxs(0).getNote(); shieldOutList.clear(); memo1 = "Send shield address 1 without ask" + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress1, - "" + (receiverNote1.getValue() - zenTokenFee), memo1); - Assert.assertFalse(PublicMethod.sendShieldCoinWithoutAsk( - null, 0, - receiverAddressInfo1.get(), notes.getNoteTxs(0), - shieldOutList, - null, 0, - zenTokenOwnerKey1, blockingStubFull)); - - Assert.assertTrue(PublicMethod.getSpendResult(receiverAddressInfo1.get(), - notes.getNoteTxs(0), blockingStubFull).getResult()); - Assert.assertTrue(PublicMethod.getSpendResult(receiverAddressInfo2.get(), - notes.getNoteTxs(1), blockingStubFull).getResult()); - Assert.assertTrue(PublicMethod.getSpendResult(receiverAddressInfo3.get(), - notes.getNoteTxs(2), blockingStubFull).getResult()); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, + sendShieldAddress1, + "" + (receiverNote1.getValue() - zenTokenFee), + memo1); + Assert.assertFalse( + PublicMethod.sendShieldCoinWithoutAsk( + null, + 0, + receiverAddressInfo1.get(), + notes.getNoteTxs(0), + shieldOutList, + null, + 0, + zenTokenOwnerKey1, + blockingStubFull)); + + Assert.assertTrue( + PublicMethod.getSpendResult( + receiverAddressInfo1.get(), notes.getNoteTxs(0), blockingStubFull) + .getResult()); + Assert.assertTrue( + PublicMethod.getSpendResult( + receiverAddressInfo2.get(), notes.getNoteTxs(1), blockingStubFull) + .getResult()); + Assert.assertTrue( + PublicMethod.getSpendResult( + receiverAddressInfo3.get(), notes.getNoteTxs(2), blockingStubFull) + .getResult()); } - @Test(enabled = false, description = "Same sk transfer two shield address," - + "in one transaction send to these shield transaction", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = + "Same sk transfer two shield address," + + "in one transaction send to these shield transaction", + groups = {"daily", "shield"}) public void test12SameSkTransferTwoShieldAddressInOneTransaction() { shieldOutList.clear(); memo1 = "Send to first shield address " + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, receiverShieldAddress1, - "" + zenTokenFee, memo1); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, receiverShieldAddress1, "" + zenTokenFee, memo1); memo2 = "Send to second shield address " + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, receiverShieldAddress2, - "" + (costTokenAmount - 2 * zenTokenFee), memo2); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, receiverShieldAddress2, "" + (costTokenAmount - 2 * zenTokenFee), memo2); logger.info("address1 receiver amount:" + zenTokenFee); logger.info("address2 receiver amount:" + (costTokenAmount - 2 * zenTokenFee)); - Assert.assertTrue(PublicMethod.sendShieldCoinWithoutAsk( - zenTokenOwnerAddress4, costTokenAmount, - null, null, - shieldOutList, - null, 0, - zenTokenOwnerKey4, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendShieldCoinWithoutAsk( + zenTokenOwnerAddress4, + costTokenAmount, + null, + null, + shieldOutList, + null, + 0, + zenTokenOwnerKey4, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); notes = PublicMethod.getShieldNotesByIvk(receiverAddressInfo2, blockingStubFull); Assert.assertTrue(notes.getNoteTxsCount() == 5); Assert.assertTrue(notes.getNoteTxs(3).getNote().getValue() == zenTokenFee); - Assert.assertTrue(notes.getNoteTxs(4).getNote().getValue() - == (costTokenAmount - 2 * zenTokenFee)); + Assert.assertTrue( + notes.getNoteTxs(4).getNote().getValue() == (costTokenAmount - 2 * zenTokenFee)); Assert.assertEquals(PublicMethod.getMemo(notes.getNoteTxs(3).getNote()), memo1); Assert.assertEquals(PublicMethod.getMemo(notes.getNoteTxs(4).getNote()), memo2); @@ -498,26 +644,44 @@ public void test12SameSkTransferTwoShieldAddressInOneTransaction() { receiverNote1 = notes.getNoteTxs(3).getNote(); receiverNote2 = notes.getNoteTxs(4).getNote(); memo1 = "Send shield address 1 without ask" + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress1, - "" + (receiverNote1.getValue() - zenTokenFee), memo1); - Assert.assertTrue(PublicMethod.sendShieldCoinWithoutAsk( - null, 0, - receiverAddressInfo1.get(), notes.getNoteTxs(3), - shieldOutList, - null, 0, - zenTokenOwnerKey1, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, + sendShieldAddress1, + "" + (receiverNote1.getValue() - zenTokenFee), + memo1); + Assert.assertTrue( + PublicMethod.sendShieldCoinWithoutAsk( + null, + 0, + receiverAddressInfo1.get(), + notes.getNoteTxs(3), + shieldOutList, + null, + 0, + zenTokenOwnerKey1, + blockingStubFull)); shieldOutList.clear(); ; memo2 = "Send shield address 2 without ask" + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress2, - "" + (receiverNote2.getValue() - zenTokenFee), memo2); - Assert.assertTrue(PublicMethod.sendShieldCoinWithoutAsk( - null, 0, - receiverAddressInfo2.get(), notes.getNoteTxs(4), - shieldOutList, - null, 0, - zenTokenOwnerKey2, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, + sendShieldAddress2, + "" + (receiverNote2.getValue() - zenTokenFee), + memo2); + Assert.assertTrue( + PublicMethod.sendShieldCoinWithoutAsk( + null, + 0, + receiverAddressInfo2.get(), + notes.getNoteTxs(4), + shieldOutList, + null, + 0, + zenTokenOwnerKey2, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -525,84 +689,131 @@ public void test12SameSkTransferTwoShieldAddressInOneTransaction() { sendNote1 = notes.getNoteTxs(0).getNote(); shieldOutList.clear(); memo2 = "Send receiver a note and spend it" + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress2, - "" + (sendNote1.getValue() - zenTokenFee), memo2); - Assert.assertTrue(PublicMethod.sendShieldCoinWithoutAsk( - null, 0, - sendShieldAddressInfo1.get(), notes.getNoteTxs(0), - shieldOutList, - null, 0, - zenTokenOwnerKey2, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, sendShieldAddress2, "" + (sendNote1.getValue() - zenTokenFee), memo2); + Assert.assertTrue( + PublicMethod.sendShieldCoinWithoutAsk( + null, + 0, + sendShieldAddressInfo1.get(), + notes.getNoteTxs(0), + shieldOutList, + null, + 0, + zenTokenOwnerKey2, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); notes = PublicMethod.getShieldNotesByIvk(receiverAddressInfo2, blockingStubFull); - Assert.assertTrue(PublicMethod.getSpendResult(receiverAddressInfo1.get(), - notes.getNoteTxs(3), blockingStubFull).getResult()); - Assert.assertTrue(PublicMethod.getSpendResult(receiverAddressInfo2.get(), - notes.getNoteTxs(4), blockingStubFull).getResult()); + Assert.assertTrue( + PublicMethod.getSpendResult( + receiverAddressInfo1.get(), notes.getNoteTxs(3), blockingStubFull) + .getResult()); + Assert.assertTrue( + PublicMethod.getSpendResult( + receiverAddressInfo2.get(), notes.getNoteTxs(4), blockingStubFull) + .getResult()); notes = PublicMethod.getShieldNotesByOvk(receiverAddressInfo1, blockingStubFull); - Assert.assertTrue(PublicMethod.getSpendResult(sendShieldAddressInfo1.get(), - notes.getNoteTxs(0), blockingStubFull).getResult()); - Assert.assertFalse(PublicMethod.getSpendResult(receiverAddressInfo2.get(), - notes.getNoteTxs(1), blockingStubFull).getResult()); - Assert.assertFalse(PublicMethod.getSpendResult(receiverAddressInfo3.get(), - notes.getNoteTxs(2), blockingStubFull).getResult()); - Assert.assertFalse(PublicMethod.getSpendResult(receiverAddressInfo1.get(), - notes.getNoteTxs(3), blockingStubFull).getResult()); - Assert.assertFalse(PublicMethod.getSpendResult(receiverAddressInfo2.get(), - notes.getNoteTxs(4), blockingStubFull).getResult()); - //Send shield coin without ask when there is no output shield address + Assert.assertTrue( + PublicMethod.getSpendResult( + sendShieldAddressInfo1.get(), notes.getNoteTxs(0), blockingStubFull) + .getResult()); + Assert.assertFalse( + PublicMethod.getSpendResult( + receiverAddressInfo2.get(), notes.getNoteTxs(1), blockingStubFull) + .getResult()); + Assert.assertFalse( + PublicMethod.getSpendResult( + receiverAddressInfo3.get(), notes.getNoteTxs(2), blockingStubFull) + .getResult()); + Assert.assertFalse( + PublicMethod.getSpendResult( + receiverAddressInfo1.get(), notes.getNoteTxs(3), blockingStubFull) + .getResult()); + Assert.assertFalse( + PublicMethod.getSpendResult( + receiverAddressInfo2.get(), notes.getNoteTxs(4), blockingStubFull) + .getResult()); + // Send shield coin without ask when there is no output shield address shieldOutList.clear(); memo2 = "Send receiver a note and spend it" + System.currentTimeMillis(); - Assert.assertTrue(PublicMethod.sendShieldCoinWithoutAsk( - null, 0, - sendShieldAddressInfo2.get(), notes.getNoteTxs(1), - shieldOutList, - zenTokenOwnerAddress1, notes.getNoteTxs(1).getNote().getValue() - zenTokenFee, - zenTokenOwnerKey2, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendShieldCoinWithoutAsk( + null, + 0, + sendShieldAddressInfo2.get(), + notes.getNoteTxs(1), + shieldOutList, + zenTokenOwnerAddress1, + notes.getNoteTxs(1).getNote().getValue() - zenTokenFee, + zenTokenOwnerKey2, + blockingStubFull)); shieldOutList.clear(); memo2 = "Send receiver a note and spend it" + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress2, - "0", memo2); - Assert.assertTrue(PublicMethod.sendShieldCoinWithoutAsk( - null, 0, - sendShieldAddressInfo3.get(), notes.getNoteTxs(2), - shieldOutList, - zenTokenOwnerAddress1, notes.getNoteTxs(2).getNote().getValue() - zenTokenFee, - zenTokenOwnerKey2, blockingStubFull)); + shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress2, "0", memo2); + Assert.assertTrue( + PublicMethod.sendShieldCoinWithoutAsk( + null, + 0, + sendShieldAddressInfo3.get(), + notes.getNoteTxs(2), + shieldOutList, + zenTokenOwnerAddress1, + notes.getNoteTxs(2).getNote().getValue() - zenTokenFee, + zenTokenOwnerKey2, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); notes = PublicMethod.getShieldNotesByIvk(receiverAddressInfo2, blockingStubFull); - Assert.assertTrue(PublicMethod.getSpendResult(receiverAddressInfo2.get(), - notes.getNoteTxs(1), blockingStubFull).getResult()); - Assert.assertTrue(PublicMethod.getSpendResult(receiverAddressInfo3.get(), - notes.getNoteTxs(2), blockingStubFull).getResult()); - - + Assert.assertTrue( + PublicMethod.getSpendResult( + receiverAddressInfo2.get(), notes.getNoteTxs(1), blockingStubFull) + .getResult()); + Assert.assertTrue( + PublicMethod.getSpendResult( + receiverAddressInfo3.get(), notes.getNoteTxs(2), blockingStubFull) + .getResult()); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - PublicMethod.transferAsset(foundationZenTokenAddress, tokenId, - PublicMethod.getAssetIssueValue(zenTokenOwnerAddress1, + PublicMethod.transferAsset( + foundationZenTokenAddress, + tokenId, + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress1, PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull), zenTokenOwnerAddress1, zenTokenOwnerKey1, blockingStubFull); - PublicMethod.transferAsset(foundationZenTokenAddress, tokenId, - PublicMethod.getAssetIssueValue(zenTokenOwnerAddress2, + blockingStubFull), + zenTokenOwnerAddress1, + zenTokenOwnerKey1, + blockingStubFull); + PublicMethod.transferAsset( + foundationZenTokenAddress, + tokenId, + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress2, PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull), zenTokenOwnerAddress2, zenTokenOwnerKey2, blockingStubFull); - PublicMethod.transferAsset(foundationZenTokenAddress, tokenId, - PublicMethod.getAssetIssueValue(zenTokenOwnerAddress3, + blockingStubFull), + zenTokenOwnerAddress2, + zenTokenOwnerKey2, + blockingStubFull); + PublicMethod.transferAsset( + foundationZenTokenAddress, + tokenId, + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress3, PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull), zenTokenOwnerAddress3, zenTokenOwnerKey3, blockingStubFull); if (channelSolidity1 != null) { + blockingStubFull), + zenTokenOwnerAddress3, + zenTokenOwnerKey3, + blockingStubFull); + if (channelSolidity1 != null) { channelSolidity1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken008.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken008.java index cb6ded0f..2bcbcc1d 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken008.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken008.java @@ -20,14 +20,14 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.ShieldAddressInfo; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestZenToken008 extends TronBaseTest { - private static ByteString assetAccountId = null; Optional sendShieldAddressInfo; + private static ByteString assetAccountId = null; + Optional sendShieldAddressInfo; Optional receiverShieldAddressInfo; String sendShieldAddress; String receiverShieldAddress; @@ -41,78 +41,103 @@ public class WalletTestZenToken008 extends TronBaseTest { String zenTokenOwnerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelSolidity1 = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity1 = null; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - private String soliditynode1 = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1); - private String foundationZenTokenKey = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenOwnerKey"); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + private String soliditynode1 = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); + private String foundationZenTokenKey = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenOwnerKey"); byte[] foundationZenTokenAddress = PublicMethod.getFinalAddress(foundationZenTokenKey); - private String zenTokenId = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenId"); + private String zenTokenId = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenId"); private byte[] tokenId = zenTokenId.getBytes(); - private Long zenTokenFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.zenTokenFee"); + private Long zenTokenFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.zenTokenFee"); private Long costTokenAmount = 1 * zenTokenFee + 1; private Long sendTokenAmount = 1 * zenTokenFee; - /** - * constructor. - */ + /** constructor. */ - - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); PublicMethod.printAddress(foundationZenTokenKey); - PublicMethod.printAddress(zenTokenOwnerKey); channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - channelSolidity1 = ManagedChannelBuilder.forTarget(soliditynode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(zenTokenOwnerKey); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + channelSolidity1 = ManagedChannelBuilder.forTarget(soliditynode1).usePlaintext().build(); blockingStubSolidity1 = WalletSolidityGrpc.newBlockingStub(channelSolidity1); - Assert.assertTrue(PublicMethod.transferAsset(zenTokenOwnerAddress, tokenId, - costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + zenTokenOwnerAddress, + tokenId, + costTokenAmount, + foundationZenTokenAddress, + foundationZenTokenKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Args.setFullNodeAllowShieldedTransaction(true); - + // Args.setFullNodeAllowShieldedTransaction(true); } - @Test(enabled = false, - description = "Public send 1 token to shield transaction", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "Public send 1 token to shield transaction", + groups = {"daily", "shield"}) public void test1Shield2ShieldTransaction() { sendShieldAddressInfo = PublicMethod.generateShieldAddress(); sendShieldAddress = sendShieldAddressInfo.get().getAddress(); logger.info("sendShieldAddressInfo:" + sendShieldAddressInfo); memo = "Shield 1 token memo in " + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress, - "1", memo); - Assert.assertFalse(PublicMethod.sendShieldCoin(zenTokenOwnerAddress, sendTokenAmount, null, - null, shieldOutList, null, 0, zenTokenOwnerKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendShieldCoin(zenTokenOwnerAddress, costTokenAmount, null, - null, shieldOutList, null, 0, zenTokenOwnerKey, blockingStubFull)); + shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress, "1", memo); + Assert.assertFalse( + PublicMethod.sendShieldCoin( + zenTokenOwnerAddress, + sendTokenAmount, + null, + null, + shieldOutList, + null, + 0, + zenTokenOwnerKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + zenTokenOwnerAddress, + costTokenAmount, + null, + null, + shieldOutList, + null, + 0, + zenTokenOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); notes = PublicMethod.listShieldNote(sendShieldAddressInfo, blockingStubFull); sendNote = notes.getNoteTxs(0).getNote(); Assert.assertTrue(sendNote.getValue() == 1); - } - @Test(enabled = false, - description = "Shield send 0 token to shield transaction", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "Shield send 0 token to shield transaction", + groups = {"daily", "shield"}) public void test2Shield2ShieldTransaction() { - Assert.assertTrue(PublicMethod.transferAsset(zenTokenOwnerAddress, tokenId, - zenTokenFee * 2, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + zenTokenOwnerAddress, + tokenId, + zenTokenFee * 2, + foundationZenTokenAddress, + foundationZenTokenKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long afterAssetBalance = PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, - PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull); + Long afterAssetBalance = + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, + PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), + blockingStubFull); logger.info("token balance is " + afterAssetBalance); sendShieldAddressInfo = PublicMethod.generateShieldAddress(); @@ -120,48 +145,72 @@ public void test2Shield2ShieldTransaction() { logger.info("sendShieldAddressInfo:" + sendShieldAddressInfo); memo = "Shield costFee token memo in " + System.currentTimeMillis(); shieldOutList.clear(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress, - "" + zenTokenFee, memo); - //logger.info(); - Assert.assertTrue(PublicMethod.sendShieldCoin(zenTokenOwnerAddress, zenTokenFee * 2, null, - null, shieldOutList, null, 0, zenTokenOwnerKey, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress, "" + zenTokenFee, memo); + // logger.info(); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + zenTokenOwnerAddress, + zenTokenFee * 2, + null, + null, + shieldOutList, + null, + 0, + zenTokenOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); receiverShieldAddressInfo = PublicMethod.generateShieldAddress(); receiverShieldAddress = receiverShieldAddressInfo.get().getAddress(); shieldOutList.clear(); memo = "Send shield to receiver shield memo in" + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, receiverShieldAddress, - "0", memo); - //Wrong proof - Assert.assertFalse(PublicMethod.sendShieldCoin( - null, 0, - sendShieldAddressInfo.get(), notes.getNoteTxs(0), - shieldOutList, - null, 0, - zenTokenOwnerKey, blockingStubFull)); - //Amount is -1 + shieldOutList = + PublicMethod.addShieldOutputList(shieldOutList, receiverShieldAddress, "0", memo); + // Wrong proof + Assert.assertFalse( + PublicMethod.sendShieldCoin( + null, + 0, + sendShieldAddressInfo.get(), + notes.getNoteTxs(0), + shieldOutList, + null, + 0, + zenTokenOwnerKey, + blockingStubFull)); + // Amount is -1 notes = PublicMethod.listShieldNote(sendShieldAddressInfo, blockingStubFull); shieldOutList.clear(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, receiverShieldAddress, - "-1", memo); - Assert.assertFalse(PublicMethod.sendShieldCoin( - null, 0, - sendShieldAddressInfo.get(), notes.getNoteTxs(0), - shieldOutList, - null, 0, - zenTokenOwnerKey, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList(shieldOutList, receiverShieldAddress, "-1", memo); + Assert.assertFalse( + PublicMethod.sendShieldCoin( + null, + 0, + sendShieldAddressInfo.get(), + notes.getNoteTxs(0), + shieldOutList, + null, + 0, + zenTokenOwnerKey, + blockingStubFull)); notes = PublicMethod.listShieldNote(sendShieldAddressInfo, blockingStubFull); shieldOutList.clear(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, receiverShieldAddress, - "0", memo); - Assert.assertTrue(PublicMethod.sendShieldCoin( - null, 0, - sendShieldAddressInfo.get(), notes.getNoteTxs(0), - shieldOutList, - null, 0, - zenTokenOwnerKey, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList(shieldOutList, receiverShieldAddress, "0", memo); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + null, + 0, + sendShieldAddressInfo.get(), + notes.getNoteTxs(0), + shieldOutList, + null, + 0, + zenTokenOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); notes = PublicMethod.listShieldNote(receiverShieldAddressInfo, blockingStubFull); @@ -170,16 +219,21 @@ public void test2Shield2ShieldTransaction() { Assert.assertTrue(receiverNote.getValue() == 0); } - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - PublicMethod.transferAsset(foundationZenTokenAddress, tokenId, - PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, + PublicMethod.transferAsset( + foundationZenTokenAddress, + tokenId, + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull), zenTokenOwnerAddress, zenTokenOwnerKey, blockingStubFull); if (channelSolidity1 != null) { + blockingStubFull), + zenTokenOwnerAddress, + zenTokenOwnerKey, + blockingStubFull); + if (channelSolidity1 != null) { channelSolidity1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken009.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken009.java index faac53fa..82b55f8f 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken009.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken009.java @@ -16,11 +16,12 @@ import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; import stest.tron.wallet.common.client.utils.ShieldAddressInfo; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class WalletTestZenToken009 extends TronBaseTest { Optional shieldAddressInfo; +public class WalletTestZenToken009 extends TronBaseTest { + Optional shieldAddressInfo; String shieldAddress; Optional receiverAddressInfo; String receiverAddress; @@ -44,35 +45,35 @@ public class WalletTestZenToken009 extends TronBaseTest { Optional sendShieldAddressInfo; + private static ByteString assetAccountId = null; + Optional sendShieldAddressInfo; Optional receiverShieldAddressInfo; String sendShieldAddress; String receiverShieldAddress; @@ -43,106 +43,137 @@ public class WalletTestZenToken010 extends TronBaseTest { String zenTokenOwnerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelSolidity1 = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity1 = null; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - private String soliditynode1 = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1); - private String foundationZenTokenKey = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenOwnerKey"); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + private String soliditynode1 = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); + private String foundationZenTokenKey = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenOwnerKey"); byte[] foundationZenTokenAddress = PublicMethod.getFinalAddress(foundationZenTokenKey); - private String zenTokenId = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenId"); + private String zenTokenId = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenId"); private byte[] tokenId = zenTokenId.getBytes(); - private Long zenTokenFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.zenTokenFee"); + private Long zenTokenFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.zenTokenFee"); private Long costTokenAmount = 10 * zenTokenFee; private Long sendTokenAmount = 8 * zenTokenFee; private String txid; private Optional infoById; private Optional byId; - /** - * constructor. - */ + /** constructor. */ - - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); PublicMethod.printAddress(foundationZenTokenKey); - PublicMethod.printAddress(zenTokenOwnerKey); channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - channelSolidity1 = ManagedChannelBuilder.forTarget(soliditynode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(zenTokenOwnerKey); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + channelSolidity1 = ManagedChannelBuilder.forTarget(soliditynode1).usePlaintext().build(); blockingStubSolidity1 = WalletSolidityGrpc.newBlockingStub(channelSolidity1); - Assert.assertTrue(PublicMethod.transferAsset(zenTokenOwnerAddress, tokenId, - costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + zenTokenOwnerAddress, + tokenId, + costTokenAmount, + foundationZenTokenAddress, + foundationZenTokenKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Args.setFullNodeAllowShieldedTransaction(true); + // Args.setFullNodeAllowShieldedTransaction(true); sendShieldAddressInfo = PublicMethod.generateShieldAddress(); sendShieldAddress = sendShieldAddressInfo.get().getAddress(); logger.info("sendShieldAddressInfo:" + sendShieldAddressInfo); memo = "Shield memo in" + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress, - "" + (sendTokenAmount - zenTokenFee), memo); - Assert.assertTrue(PublicMethod.sendShieldCoin(zenTokenOwnerAddress, sendTokenAmount, null, - null, shieldOutList, null, 0, zenTokenOwnerKey, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, sendShieldAddress, "" + (sendTokenAmount - zenTokenFee), memo); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + zenTokenOwnerAddress, + sendTokenAmount, + null, + null, + shieldOutList, + null, + 0, + zenTokenOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); notes = PublicMethod.listShieldNote(sendShieldAddressInfo, blockingStubFull); sendNote = notes.getNoteTxs(0).getNote(); - } - @Test(enabled = false, description = "Shield to itself transaction", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "Shield to itself transaction", + groups = {"daily", "shield"}) public void test1Shield2ShieldTransaction() { shieldOutList.clear(); memo = "Send shield to itself memo1 in " + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress, - "" + zenTokenFee, memo); + shieldOutList = + PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress, "" + zenTokenFee, memo); memo = "Send shield to itself memo2 in " + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress, - "" + (sendNote.getValue() - 2 * zenTokenFee), memo); - Assert.assertTrue(PublicMethod.sendShieldCoin( - null, 0, - sendShieldAddressInfo.get(), notes.getNoteTxs(0), - shieldOutList, - null, 0, - zenTokenOwnerKey, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, sendShieldAddress, "" + (sendNote.getValue() - 2 * zenTokenFee), memo); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + null, + 0, + sendShieldAddressInfo.get(), + notes.getNoteTxs(0), + shieldOutList, + null, + 0, + zenTokenOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); notes = PublicMethod.getShieldNotesByIvk(sendShieldAddressInfo, blockingStubFull); Assert.assertTrue(notes.getNoteTxsCount() == 3); Assert.assertTrue(notes.getNoteTxs(1).getNote().getValue() == zenTokenFee); - Assert.assertTrue(notes.getNoteTxs(2).getNote().getValue() - == sendNote.getValue() - 2 * zenTokenFee); - Assert.assertEquals(notes.getNoteTxs(1).getNote().getPaymentAddress(), + Assert.assertTrue( + notes.getNoteTxs(2).getNote().getValue() == sendNote.getValue() - 2 * zenTokenFee); + Assert.assertEquals( + notes.getNoteTxs(1).getNote().getPaymentAddress(), notes.getNoteTxs(2).getNote().getPaymentAddress()); Assert.assertEquals(notes.getNoteTxs(1).getTxid(), notes.getNoteTxs(2).getTxid()); - Assert.assertTrue(PublicMethod.getSpendResult(sendShieldAddressInfo.get(), - notes.getNoteTxs(0), blockingStubFull).getResult()); + Assert.assertTrue( + PublicMethod.getSpendResult( + sendShieldAddressInfo.get(), notes.getNoteTxs(0), blockingStubFull) + .getResult()); notes = PublicMethod.getShieldNotesByOvk(sendShieldAddressInfo, blockingStubFull); Assert.assertTrue(notes.getNoteTxsCount() == 2); } - @Test(enabled = false, description = "From shield only have one zenToken fee", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "From shield only have one zenToken fee", + groups = {"daily", "shield"}) public void test2Shield2ShieldTransaction() { sendShieldAddressInfo = PublicMethod.generateShieldAddress(); sendShieldAddress = sendShieldAddressInfo.get().getAddress(); logger.info("sendShieldAddressInfo:" + sendShieldAddressInfo); memo = "Shield memo in" + System.currentTimeMillis(); shieldOutList.clear(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress, - "" + zenTokenFee, memo); - Assert.assertTrue(PublicMethod.sendShieldCoin(zenTokenOwnerAddress, 2 * zenTokenFee, null, - null, shieldOutList, null, 0, zenTokenOwnerKey, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress, "" + zenTokenFee, memo); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + zenTokenOwnerAddress, + 2 * zenTokenFee, + null, + null, + shieldOutList, + null, + 0, + zenTokenOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); notes = PublicMethod.listShieldNote(sendShieldAddressInfo, blockingStubFull); sendNote = notes.getNoteTxs(0).getNote(); @@ -151,18 +182,21 @@ public void test2Shield2ShieldTransaction() { shieldOutList.clear(); memo = "Send shield to itself memo1 in " + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress, - "0", memo); + shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress, "0", memo); memo = "Send shield to itself memo2 in " + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress, - "0", memo); - Assert.assertTrue(PublicMethod.sendShieldCoin( - null, 0, - sendShieldAddressInfo.get(), notes.getNoteTxs(0), - shieldOutList, - null, 0, - zenTokenOwnerKey, blockingStubFull)); + shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress, "0", memo); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + null, + 0, + sendShieldAddressInfo.get(), + notes.getNoteTxs(0), + shieldOutList, + null, + 0, + zenTokenOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -173,12 +207,16 @@ public void test2Shield2ShieldTransaction() { logger.info("index 2:" + notes.getNoteTxs(2).getNote().getValue()); Assert.assertTrue(notes.getNoteTxs(1).getNote().getValue() == 0); Assert.assertTrue(notes.getNoteTxs(2).getNote().getValue() == 0); - Assert.assertEquals(notes.getNoteTxs(1).getNote().getPaymentAddress(), + Assert.assertEquals( + notes.getNoteTxs(1).getNote().getPaymentAddress(), notes.getNoteTxs(2).getNote().getPaymentAddress()); Assert.assertEquals(notes.getNoteTxs(1).getTxid(), notes.getNoteTxs(2).getTxid()); } - @Test(enabled = false, description = "From public and to public is same one", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "From public and to public is same one", + groups = {"daily", "shield"}) public void test3Public2ShieldAndPublicItselfTransaction() { sendShieldAddressInfo = PublicMethod.generateShieldAddress(); sendShieldAddress = sendShieldAddressInfo.get().getAddress(); @@ -186,47 +224,68 @@ public void test3Public2ShieldAndPublicItselfTransaction() { ecKey1 = new ECKey(Utils.getRandom()); zenTokenOwnerAddress = ecKey1.getAddress(); zenTokenOwnerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.transferAsset(zenTokenOwnerAddress, tokenId, - costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull)); - final Long beforeAssetBalance = PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, - PublicMethod.queryAccount(foundationZenTokenAddress, blockingStubFull).getAccountId(), - blockingStubFull); - final Long beforeBalance = PublicMethod.queryAccount(zenTokenOwnerAddress, blockingStubFull) - .getBalance(); + Assert.assertTrue( + PublicMethod.transferAsset( + zenTokenOwnerAddress, + tokenId, + costTokenAmount, + foundationZenTokenAddress, + foundationZenTokenKey, + blockingStubFull)); + final Long beforeAssetBalance = + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, + PublicMethod.queryAccount(foundationZenTokenAddress, blockingStubFull).getAccountId(), + blockingStubFull); + final Long beforeBalance = + PublicMethod.queryAccount(zenTokenOwnerAddress, blockingStubFull).getBalance(); shieldOutList.clear(); memo = "From public and to public is same one memo in " + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress, - "" + 2 * zenTokenFee, memo); - - Assert.assertFalse(PublicMethod - .sendShieldCoin(zenTokenOwnerAddress, costTokenAmount, null, null, shieldOutList, - zenTokenOwnerAddress, 7 * zenTokenFee, zenTokenOwnerKey, blockingStubFull)); - Long afterAssetBalance = PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, - PublicMethod.queryAccount(foundationZenTokenAddress, blockingStubFull).getAccountId(), - blockingStubFull); - Long afterBalance = PublicMethod.queryAccount(zenTokenOwnerAddress, blockingStubFull) - .getBalance(); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, sendShieldAddress, "" + 2 * zenTokenFee, memo); + + Assert.assertFalse( + PublicMethod.sendShieldCoin( + zenTokenOwnerAddress, + costTokenAmount, + null, + null, + shieldOutList, + zenTokenOwnerAddress, + 7 * zenTokenFee, + zenTokenOwnerKey, + blockingStubFull)); + Long afterAssetBalance = + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, + PublicMethod.queryAccount(foundationZenTokenAddress, blockingStubFull).getAccountId(), + blockingStubFull); + Long afterBalance = + PublicMethod.queryAccount(zenTokenOwnerAddress, blockingStubFull).getBalance(); Assert.assertEquals(beforeAssetBalance, afterAssetBalance); Assert.assertEquals(beforeBalance, afterBalance); notes = PublicMethod.getShieldNotesByIvk(sendShieldAddressInfo, blockingStubFull); Assert.assertTrue(notes.getNoteTxsCount() == 0); - - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - PublicMethod.transferAsset(foundationZenTokenAddress, tokenId, - PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, + PublicMethod.transferAsset( + foundationZenTokenAddress, + tokenId, + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull), zenTokenOwnerAddress, zenTokenOwnerKey, blockingStubFull); if (channelSolidity1 != null) { + blockingStubFull), + zenTokenOwnerAddress, + zenTokenOwnerKey, + blockingStubFull); + if (channelSolidity1 != null) { channelSolidity1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken011.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken011.java index ed26fb11..b3c9c044 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken011.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentoken/WalletTestZenToken011.java @@ -23,14 +23,14 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.ShieldAddressInfo; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestZenToken011 extends TronBaseTest { - private static ByteString assetAccountId = null; Optional sendShieldAddressInfo; + private static ByteString assetAccountId = null; + Optional sendShieldAddressInfo; Optional receiverShieldAddressInfo; String sendShieldAddress; String receiverShieldAddress; @@ -44,74 +44,90 @@ public class WalletTestZenToken011 extends TronBaseTest { String zenTokenOwnerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelSolidity1 = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity1 = null; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - private String soliditynode1 = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1); - private String foundationZenTokenKey = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenOwnerKey"); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + private String soliditynode1 = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); + private String foundationZenTokenKey = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenOwnerKey"); byte[] foundationZenTokenAddress = PublicMethod.getFinalAddress(foundationZenTokenKey); - private String zenTokenId = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenId"); + private String zenTokenId = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenId"); private byte[] tokenId = zenTokenId.getBytes(); - private Long zenTokenFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.zenTokenFee"); + private Long zenTokenFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.zenTokenFee"); private Long costTokenAmount = 10 * zenTokenFee; private Long sendTokenAmount = 8 * zenTokenFee; private String txid; private Optional infoById; private Optional byId; - /** - * constructor. - */ + /** constructor. */ - - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); PublicMethod.printAddress(foundationZenTokenKey); - PublicMethod.printAddress(zenTokenOwnerKey); channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - channelSolidity1 = ManagedChannelBuilder.forTarget(soliditynode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(zenTokenOwnerKey); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + channelSolidity1 = ManagedChannelBuilder.forTarget(soliditynode1).usePlaintext().build(); blockingStubSolidity1 = WalletSolidityGrpc.newBlockingStub(channelSolidity1); - Assert.assertTrue(PublicMethod.transferAsset(zenTokenOwnerAddress, tokenId, - costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + zenTokenOwnerAddress, + tokenId, + costTokenAmount, + foundationZenTokenAddress, + foundationZenTokenKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Args.setFullNodeAllowShieldedTransaction(true); - + // Args.setFullNodeAllowShieldedTransaction(true); } - @Test(enabled = false, description = "Test get new shield address ", groups = {"daily", "shield"}) + @Test( + enabled = false, + description = "Test get new shield address ", + groups = {"daily", "shield"}) public void test1Shield2ShieldTransaction() { - sendShieldAddress = blockingStubFull.getNewShieldedAddress(GrpcAPI.EmptyMessage.newBuilder() - .build()).getPaymentAddress(); + sendShieldAddress = + blockingStubFull + .getNewShieldedAddress(GrpcAPI.EmptyMessage.newBuilder().build()) + .getPaymentAddress(); memo = "Shield memo in" + System.currentTimeMillis(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress, - "" + (sendTokenAmount - zenTokenFee), memo); - Assert.assertTrue(PublicMethod.sendShieldCoin(zenTokenOwnerAddress, sendTokenAmount, null, - null, shieldOutList, null, 0, zenTokenOwnerKey, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, sendShieldAddress, "" + (sendTokenAmount - zenTokenFee), memo); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + zenTokenOwnerAddress, + sendTokenAmount, + null, + null, + shieldOutList, + null, + 0, + zenTokenOwnerKey, + blockingStubFull)); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - PublicMethod.transferAsset(foundationZenTokenAddress, tokenId, - PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, + PublicMethod.transferAsset( + foundationZenTokenAddress, + tokenId, + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull), zenTokenOwnerAddress, zenTokenOwnerKey, blockingStubFull); if (channelSolidity1 != null) { + blockingStubFull), + zenTokenOwnerAddress, + zenTokenOwnerKey, + blockingStubFull); + if (channelSolidity1 != null) { channelSolidity1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token001.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token001.java index 20c41303..7a24f1e0 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token001.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token001.java @@ -18,61 +18,74 @@ @Slf4j public class ShieldTrc20Token001 extends ZenTrc20Base { - private String fullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(0); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String fullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext() - .build(); + channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); blockingStubFull = WalletGrpc.newBlockingStub(channelFull); } - @Test(enabled = true, description = "Check shield contract deploy success", groups = {"daily", "serial", "shield"}) + @Test( + enabled = true, + description = "Check shield contract deploy success", + groups = {"daily", "serial", "shield"}) public void test01checkShieldContractDeploySuccess() { - Optional infoById = PublicMethod - .getTransactionInfoById(deployShieldTrc20Txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(deployShieldTrc20Txid, blockingStubFull); Assert.assertTrue(infoById.get().getReceipt().getResultValue() == 1); - infoById = PublicMethod - .getTransactionInfoById(deployShieldTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(deployShieldTxid, blockingStubFull); Assert.assertTrue(infoById.get().getReceipt().getResultValue() == 1); - //scalingFactor() + // scalingFactor() } - @Test(enabled = true, description = "View scaling factor test", groups = {"daily", "serial", "shield"}) + @Test( + enabled = true, + description = "View scaling factor test", + groups = {"daily", "serial", "shield"}) public void test02ViewScalingFactor() { - String txid = PublicMethod.triggerContract(shieldAddressByte, - "scalingFactor()", "", false, - 0, maxFeeLimit, zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + String txid = + PublicMethod.triggerContract( + shieldAddressByte, + "scalingFactor()", + "", + false, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(txid); logger.info(Integer.toString(infoById.get().getResultValue())); - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(shieldAddressByte, "scalingFactor()", - "", false, 0, 0, "0", 0, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + shieldAddressByte, + "scalingFactor()", + "", + false, + 0, + 0, + "0", + 0, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); logger.info("transactionExtention:" + transactionExtention); - String scalingFactor = PublicMethod - .bytes32ToString(transactionExtention.getConstantResult(0).toByteArray()); - Assert.assertEquals("00000000000000000000000000000001", - scalingFactor); - + String scalingFactor = + PublicMethod.bytes32ToString(transactionExtention.getConstantResult(0).toByteArray()); + Assert.assertEquals("00000000000000000000000000000001", scalingFactor); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { if (channelFull != null) { @@ -80,5 +93,3 @@ public void shutdown() throws InterruptedException { } } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token002.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token002.java index a897d1e6..4abfc5ce 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token002.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token002.java @@ -18,111 +18,129 @@ import org.tron.api.WalletSolidityGrpc; import org.tron.protos.Protocol.TransactionInfo; import stest.tron.wallet.common.client.Configuration; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.ShieldedAddressInfo; import stest.tron.wallet.common.client.utils.ZenTrc20Base; -import stest.tron.wallet.common.client.utils.MultiNode; @Slf4j @MultiNode public class ShieldTrc20Token002 extends ZenTrc20Base { - private String fullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(0); - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String fullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0); + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); Optional receiverShieldAddressInfo; private BigInteger publicFromAmount; List shieldOutList = new ArrayList<>(); - - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext() - .build(); + channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); blockingStubFull = WalletGrpc.newBlockingStub(channelFull); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); publicFromAmount = getRandomAmount(); } - /** - * constructor. - */ - @Test(enabled = true, description = "Send shield trc20 from T account to shield account", groups = {"daily", "serial", "shield"}) + /** constructor. */ + @Test( + enabled = true, + description = "Send shield trc20 from T account to shield account", + groups = {"daily", "serial", "shield"}) public void test01ShieldTrc20TransactionByTypeMint() throws Exception { - //Query account before mint balance - final Long beforeMintAccountBalance = getBalanceOfShieldTrc20(zenTrc20TokenOwnerAddressString, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); - //Query contract before mint balance - final Long beforeMintShieldAccountBalance = getBalanceOfShieldTrc20(shieldAddress, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); - //Generate new shiled account and set note memo + // Query account before mint balance + final Long beforeMintAccountBalance = + getBalanceOfShieldTrc20( + zenTrc20TokenOwnerAddressString, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); + // Query contract before mint balance + final Long beforeMintShieldAccountBalance = + getBalanceOfShieldTrc20( + shieldAddress, zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); + // Generate new shiled account and set note memo receiverShieldAddressInfo = getNewShieldedAddress(blockingStubFull); String memo = "Shield trc20 from T account to shield account in" + System.currentTimeMillis(); String receiverShieldAddress = receiverShieldAddressInfo.get().getAddress(); shieldOutList.clear(); - shieldOutList = addShieldTrc20OutputList(shieldOutList, receiverShieldAddress, - "" + publicFromAmount, memo, blockingStubFull); - - //Create shiled trc20 parameters - GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters - = createShieldedTrc20Parameters(publicFromAmount, - null, null, shieldOutList, "", 0L, - blockingStubFull, blockingStubSolidity - ); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, receiverShieldAddress, "" + publicFromAmount, memo, blockingStubFull); + + // Create shiled trc20 parameters + GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters = + createShieldedTrc20Parameters( + publicFromAmount, + null, + null, + shieldOutList, + "", + 0L, + blockingStubFull, + blockingStubSolidity); String data = encodeMintParamsToHexString(shieldedTrc20Parameters, publicFromAmount); - //Do mint transaction type - String txid = PublicMethod.triggerContract(shieldAddressByte, - mint, data, true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); + // Do mint transaction type + String txid = + PublicMethod.triggerContract( + shieldAddressByte, + mint, + data, + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info(mint + ":" + txid); logger.info(mint + infoById.get().getReceipt().getEnergyUsageTotal()); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() > 250000); Assert.assertTrue(infoById.get().getReceipt().getResultValue() == 1); - //Query account after mint balance - Long afterMintAccountBalance = getBalanceOfShieldTrc20(zenTrc20TokenOwnerAddressString, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); - //Query contract after mint balance - Long afterMintShieldAccountBalance = getBalanceOfShieldTrc20(shieldAddress, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); - - Assert.assertEquals(BigInteger.valueOf(beforeMintAccountBalance - afterMintAccountBalance), + // Query account after mint balance + Long afterMintAccountBalance = + getBalanceOfShieldTrc20( + zenTrc20TokenOwnerAddressString, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); + // Query contract after mint balance + Long afterMintShieldAccountBalance = + getBalanceOfShieldTrc20( + shieldAddress, zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); + + Assert.assertEquals( + BigInteger.valueOf(beforeMintAccountBalance - afterMintAccountBalance), publicFromAmount); + Assert.assertEquals( + BigInteger.valueOf(afterMintShieldAccountBalance - beforeMintShieldAccountBalance), publicFromAmount); - Assert.assertEquals(BigInteger.valueOf(afterMintShieldAccountBalance - - beforeMintShieldAccountBalance), publicFromAmount); - GrpcAPI.DecryptNotesTRC20 note = scanShieldedTrc20NoteByIvk(receiverShieldAddressInfo.get(), - blockingStubFull); + GrpcAPI.DecryptNotesTRC20 note = + scanShieldedTrc20NoteByIvk(receiverShieldAddressInfo.get(), blockingStubFull); logger.info("" + note); Assert.assertEquals(note.getNoteTxs(0).getNote().getValue(), publicFromAmount.longValue()); - Assert.assertEquals(note.getNoteTxs(0).getNote().getPaymentAddress(), + Assert.assertEquals( + note.getNoteTxs(0).getNote().getPaymentAddress(), receiverShieldAddressInfo.get().getAddress()); Assert.assertEquals(note.getNoteTxs(0).getNote().getMemo(), ByteString.copyFromUtf8(memo)); Assert.assertEquals(note.getNoteTxs(0).getTxid(), infoById.get().getId()); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { if (channelFull != null) { @@ -130,5 +148,3 @@ public void shutdown() throws InterruptedException { } } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token003.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token003.java index 422f006e..0e28ad9a 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token003.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token003.java @@ -25,10 +25,10 @@ @Slf4j public class ShieldTrc20Token003 extends ZenTrc20Base { - private String fullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(0); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String fullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); Optional senderShieldAddressInfo; Optional receiverShieldAddressInfo; private BigInteger publicFromAmount; @@ -38,173 +38,215 @@ public class ShieldTrc20Token003 extends ZenTrc20Base { GrpcAPI.DecryptNotesTRC20 receiverNote; long senderPosition; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() throws Exception { - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext() - .build(); + channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); blockingStubFull = WalletGrpc.newBlockingStub(channelFull); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); publicFromAmount = getRandomAmount(); - //Generate new shiled account for sender and receiver + // Generate new shiled account for sender and receiver senderShieldAddressInfo = getNewShieldedAddress(blockingStubFull); receiverShieldAddressInfo = getNewShieldedAddress(blockingStubFull); String memo = "Create a note for transfer test " + System.currentTimeMillis(); String sendShieldAddress = senderShieldAddressInfo.get().getAddress(); shieldOutList.clear(); - shieldOutList = addShieldTrc20OutputList(shieldOutList, sendShieldAddress, - "" + publicFromAmount, memo, blockingStubFull); - //Create mint parameters - GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters - = createShieldedTrc20Parameters(publicFromAmount, - null, null, shieldOutList, "", 0L, - blockingStubFull, blockingStubSolidity); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, sendShieldAddress, "" + publicFromAmount, memo, blockingStubFull); + // Create mint parameters + GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters = + createShieldedTrc20Parameters( + publicFromAmount, + null, + null, + shieldOutList, + "", + 0L, + blockingStubFull, + blockingStubSolidity); String data = encodeMintParamsToHexString(shieldedTrc20Parameters, publicFromAmount); - //Do mint transaction type - String txid = PublicMethod.triggerContract(shieldAddressByte, - mint, data, true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); + // Do mint transaction type + String txid = + PublicMethod.triggerContract( + shieldAddressByte, + mint, + data, + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getReceipt().getResultValue() == 1); - //Scan sender note - senderNote = scanShieldedTrc20NoteByIvk(senderShieldAddressInfo.get(), - blockingStubFull); + // Scan sender note + senderNote = scanShieldedTrc20NoteByIvk(senderShieldAddressInfo.get(), blockingStubFull); Assert.assertEquals(senderNote.getNoteTxs(0).getIsSpent(), false); logger.info("" + senderNote); senderPosition = senderNote.getNoteTxs(0).getPosition(); - Assert.assertEquals(senderNote.getNoteTxs(0).getNote().getValue(), - publicFromAmount.longValue()); - - + Assert.assertEquals( + senderNote.getNoteTxs(0).getNote().getValue(), publicFromAmount.longValue()); } - /** - * constructor. - */ - @Test(enabled = true, description = "Shield TRC20 transaction with type transfer", groups = {"daily", "serial", "shield"}) + /** constructor. */ + @Test( + enabled = true, + description = "Shield TRC20 transaction with type transfer", + groups = {"daily", "serial", "shield"}) public void test01ShieldTrc20TransactionWithTypeTransfer() throws Exception { - final Long beforeMintShieldContractBalance = getBalanceOfShieldTrc20(shieldAddress, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); + final Long beforeMintShieldContractBalance = + getBalanceOfShieldTrc20( + shieldAddress, zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); String transferMemo = "Transfer type test " + System.currentTimeMillis(); String receiverShieldAddress = receiverShieldAddressInfo.get().getAddress(); shieldOutList.clear(); - shieldOutList = addShieldTrc20OutputList(shieldOutList, receiverShieldAddress, - "" + publicFromAmount, transferMemo, blockingStubFull); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, + receiverShieldAddress, + "" + publicFromAmount, + transferMemo, + blockingStubFull); inputShieldAddressList.add(senderShieldAddressInfo.get()); - //inputNoteList.add(senderNote); - //Create transfer parameters - GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters - = createShieldedTrc20Parameters(BigInteger.valueOf(0), - senderNote, inputShieldAddressList, shieldOutList, "", 0L, - blockingStubFull, blockingStubSolidity); + // inputNoteList.add(senderNote); + // Create transfer parameters + GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters = + createShieldedTrc20Parameters( + BigInteger.valueOf(0), + senderNote, + inputShieldAddressList, + shieldOutList, + "", + 0L, + blockingStubFull, + blockingStubSolidity); String data = encodeTransferParamsToHexString(shieldedTrc20Parameters); - //String data = shieldedTrc20Parameters.getTriggerContractInput(); - String txid = PublicMethod.triggerContract(shieldAddressByte, - transfer, data, true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); + // String data = shieldedTrc20Parameters.getTriggerContractInput(); + String txid = + PublicMethod.triggerContract( + shieldAddressByte, + transfer, + data, + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); -// PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + // PublicMethod.waitProduceNextBlock(blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getReceipt().getResultValue() == 1); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() > 300000); - //Scan sender note - receiverNote = scanShieldedTrc20NoteByIvk(receiverShieldAddressInfo.get(), - blockingStubFull); + // Scan sender note + receiverNote = scanShieldedTrc20NoteByIvk(receiverShieldAddressInfo.get(), blockingStubFull); logger.info("" + receiverNote); Assert.assertEquals(receiverNote.getNoteTxs(0).getTxid(), infoById.get().getId()); - Assert.assertEquals(receiverNote.getNoteTxs(0).getNote().getMemo(), - ByteString.copyFromUtf8(transferMemo)); - Assert.assertEquals(receiverNote.getNoteTxs(0).getNote().getValue(), - publicFromAmount.longValue()); - Assert.assertEquals(receiverNote.getNoteTxs(0).getNote().getPaymentAddress(), + Assert.assertEquals( + receiverNote.getNoteTxs(0).getNote().getMemo(), ByteString.copyFromUtf8(transferMemo)); + Assert.assertEquals( + receiverNote.getNoteTxs(0).getNote().getValue(), publicFromAmount.longValue()); + Assert.assertEquals( + receiverNote.getNoteTxs(0).getNote().getPaymentAddress(), receiverShieldAddressInfo.get().getAddress()); logger.info("scanShieldedTrc20NoteByIvk + senderNote:" + senderNote); - senderNote = scanShieldedTrc20NoteByIvk(senderShieldAddressInfo.get(), - blockingStubFull); + senderNote = scanShieldedTrc20NoteByIvk(senderShieldAddressInfo.get(), blockingStubFull); Assert.assertEquals(senderNote.getNoteTxs(0).getIsSpent(), true); - senderNote = scanShieldedTrc20NoteByOvk(senderShieldAddressInfo.get(), - blockingStubFull); + senderNote = scanShieldedTrc20NoteByOvk(senderShieldAddressInfo.get(), blockingStubFull); logger.info("scanShieldedTrc20NoteByOvk + senderNote:" + senderNote); - final Long afterMintShieldContractBalance = getBalanceOfShieldTrc20(shieldAddress, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); + final Long afterMintShieldContractBalance = + getBalanceOfShieldTrc20( + shieldAddress, zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); Assert.assertEquals(beforeMintShieldContractBalance, afterMintShieldContractBalance); } - /** - * constructor. - */ - @Test(enabled = true, description = "Shield TRC20 transaction with type transfer without ask", groups = {"daily", "serial", "shield"}) + /** constructor. */ + @Test( + enabled = true, + description = "Shield TRC20 transaction with type transfer without ask", + groups = {"daily", "serial", "shield"}) public void test02ShieldTrc20TransactionWithTypeTransferWithoutAsk() throws Exception { PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); - //Scan receiver note prepare for without type of transfer - receiverNote = scanShieldedTrc20NoteByIvk(receiverShieldAddressInfo.get(), - blockingStubFull); + // Scan receiver note prepare for without type of transfer + receiverNote = scanShieldedTrc20NoteByIvk(receiverShieldAddressInfo.get(), blockingStubFull); String transferMemo = "Transfer type without ask test " + System.currentTimeMillis(); shieldOutList.clear(); - shieldOutList = addShieldTrc20OutputList(shieldOutList, senderShieldAddressInfo.get() - .getAddress(), - "" + publicFromAmount, transferMemo, blockingStubFull); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, + senderShieldAddressInfo.get().getAddress(), + "" + publicFromAmount, + transferMemo, + blockingStubFull); inputShieldAddressList.clear(); inputShieldAddressList.add(receiverShieldAddressInfo.get()); - //Create transfer parameters - GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters - = createShieldedTrc20ParametersWithoutAsk(BigInteger.valueOf(0), - receiverNote, inputShieldAddressList, shieldOutList, "", null, 0L, - blockingStubFull, blockingStubSolidity); + // Create transfer parameters + GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters = + createShieldedTrc20ParametersWithoutAsk( + BigInteger.valueOf(0), + receiverNote, + inputShieldAddressList, + shieldOutList, + "", + null, + 0L, + blockingStubFull, + blockingStubSolidity); String data = encodeTransferParamsToHexString(shieldedTrc20Parameters); - String txid = PublicMethod.triggerContract(shieldAddressByte, - transfer, data, true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + shieldAddressByte, + transfer, + data, + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getReceipt().getResultValue() == 1); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() > 300000); - senderNote = scanShieldedTrc20NoteByIvk(senderShieldAddressInfo.get(), - blockingStubFull); + senderNote = scanShieldedTrc20NoteByIvk(senderShieldAddressInfo.get(), blockingStubFull); logger.info("" + senderNote); Assert.assertEquals(senderNote.getNoteTxs(1).getTxid(), infoById.get().getId()); - Assert.assertEquals(senderNote.getNoteTxs(1).getNote().getMemo(), - ByteString.copyFromUtf8(transferMemo)); - Assert.assertEquals(senderNote.getNoteTxs(1).getNote().getValue(), - publicFromAmount.longValue()); - Assert.assertEquals(senderNote.getNoteTxs(1).getNote().getPaymentAddress(), + Assert.assertEquals( + senderNote.getNoteTxs(1).getNote().getMemo(), ByteString.copyFromUtf8(transferMemo)); + Assert.assertEquals( + senderNote.getNoteTxs(1).getNote().getValue(), publicFromAmount.longValue()); + Assert.assertEquals( + senderNote.getNoteTxs(1).getNote().getPaymentAddress(), senderShieldAddressInfo.get().getAddress()); - //logger.info("scanShieldedTrc20NoteByIvk + senderNote:" + senderNote); - receiverNote = scanShieldedTrc20NoteByIvk(receiverShieldAddressInfo.get(), - blockingStubFull); + // logger.info("scanShieldedTrc20NoteByIvk + senderNote:" + senderNote); + receiverNote = scanShieldedTrc20NoteByIvk(receiverShieldAddressInfo.get(), blockingStubFull); Assert.assertEquals(receiverNote.getNoteTxs(0).getIsSpent(), true); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { if (channelFull != null) { @@ -212,5 +254,3 @@ public void shutdown() throws InterruptedException { } } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token004.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token004.java index d99f865d..4c0e19a3 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token004.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token004.java @@ -27,10 +27,10 @@ @Slf4j public class ShieldTrc20Token004 extends ZenTrc20Base { - private String fullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(0); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String fullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); Optional senderShieldAddressInfo; Optional secondSenderShieldAddressInfo; Optional receiverShieldAddressInfo; @@ -42,179 +42,227 @@ public class ShieldTrc20Token004 extends ZenTrc20Base { GrpcAPI.DecryptNotesTRC20 secondSenderNote; long senderPosition; - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] receiverAddressbyte = ecKey1.getAddress(); String receiverKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); String receiverAddressString = PublicMethod.getAddressString(receiverKey); - - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() throws Exception { - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext() - .build(); + channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); blockingStubFull = WalletGrpc.newBlockingStub(channelFull); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); publicFromAmount = getRandomAmount(); - //Generate new shiled account for sender and receiver + // Generate new shiled account for sender and receiver senderShieldAddressInfo = getNewShieldedAddress(blockingStubFull); receiverShieldAddressInfo = getNewShieldedAddress(blockingStubFull); String memo = "Create a note for burn test " + System.currentTimeMillis(); String sendShieldAddress = senderShieldAddressInfo.get().getAddress(); shieldOutList.clear(); - shieldOutList = addShieldTrc20OutputList(shieldOutList, sendShieldAddress, - "" + publicFromAmount, memo, blockingStubFull); - //Create mint parameters - GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters - = createShieldedTrc20Parameters(publicFromAmount, - null, null, shieldOutList, "", 0L, - blockingStubFull, blockingStubSolidity); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, sendShieldAddress, "" + publicFromAmount, memo, blockingStubFull); + // Create mint parameters + GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters = + createShieldedTrc20Parameters( + publicFromAmount, + null, + null, + shieldOutList, + "", + 0L, + blockingStubFull, + blockingStubSolidity); String data = encodeMintParamsToHexString(shieldedTrc20Parameters, publicFromAmount); - //Do mint transaction type - String txid = PublicMethod.triggerContract(shieldAddressByte, - mint, data, true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); + // Do mint transaction type + String txid = + PublicMethod.triggerContract( + shieldAddressByte, + mint, + data, + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getReceipt().getResultValue() == 1); - //Scan sender note - senderNote = scanShieldedTrc20NoteByIvk(senderShieldAddressInfo.get(), - blockingStubFull); + // Scan sender note + senderNote = scanShieldedTrc20NoteByIvk(senderShieldAddressInfo.get(), blockingStubFull); Assert.assertEquals(senderNote.getNoteTxs(0).getIsSpent(), false); logger.info("" + senderNote); senderPosition = senderNote.getNoteTxs(0).getPosition(); - Assert.assertEquals(senderNote.getNoteTxs(0).getNote().getValue(), - publicFromAmount.longValue()); + Assert.assertEquals( + senderNote.getNoteTxs(0).getNote().getValue(), publicFromAmount.longValue()); - //Generate new shiled account for burn to one public and one shield + // Generate new shiled account for burn to one public and one shield secondSenderShieldAddressInfo = getNewShieldedAddress(blockingStubFull); - memo = "Create a note for burn to one public and one shield test " - + System.currentTimeMillis(); + memo = + "Create a note for burn to one public and one shield test " + System.currentTimeMillis(); sendShieldAddress = secondSenderShieldAddressInfo.get().getAddress(); shieldOutList.clear(); - shieldOutList = addShieldTrc20OutputList(shieldOutList, sendShieldAddress, - "" + publicFromAmount, memo, blockingStubFull); - //Create mint parameters - shieldedTrc20Parameters - = createShieldedTrc20Parameters(publicFromAmount, - null, null, shieldOutList, "", 0L, - blockingStubFull, blockingStubSolidity); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, sendShieldAddress, "" + publicFromAmount, memo, blockingStubFull); + // Create mint parameters + shieldedTrc20Parameters = + createShieldedTrc20Parameters( + publicFromAmount, + null, + null, + shieldOutList, + "", + 0L, + blockingStubFull, + blockingStubSolidity); data = encodeMintParamsToHexString(shieldedTrc20Parameters, publicFromAmount); - //Do mint transaction type - txid = PublicMethod.triggerContract(shieldAddressByte, - mint, data, true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); + // Do mint transaction type + txid = + PublicMethod.triggerContract( + shieldAddressByte, + mint, + data, + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getReceipt().getResultValue() == 1); - //Scan sender note - secondSenderNote = scanShieldedTrc20NoteByIvk(secondSenderShieldAddressInfo.get(), - blockingStubFull); + // Scan sender note + secondSenderNote = + scanShieldedTrc20NoteByIvk(secondSenderShieldAddressInfo.get(), blockingStubFull); Assert.assertEquals(secondSenderNote.getNoteTxs(0).getIsSpent(), false); logger.info("" + secondSenderNote); senderPosition = secondSenderNote.getNoteTxs(0).getPosition(); - Assert.assertEquals(secondSenderNote.getNoteTxs(0).getNote().getValue(), - publicFromAmount.longValue()); + Assert.assertEquals( + secondSenderNote.getNoteTxs(0).getNote().getValue(), publicFromAmount.longValue()); } - /** - * constructor. - */ - @Test(enabled = true, description = "Shield TRC20 transaction with type burn", groups = {"daily", "serial", "shield"}) + /** constructor. */ + @Test( + enabled = true, + description = "Shield TRC20 transaction with type burn", + groups = {"daily", "serial", "shield"}) public void test01ShieldTrc20TransactionWithTypeBurn() throws Exception { PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); - //Query account before mint balance - final Long beforeBurnAccountBalance = getBalanceOfShieldTrc20(receiverAddressString, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); - //Query contract before mint balance - final Long beforeBurnShieldAccountBalance = getBalanceOfShieldTrc20(shieldAddress, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); - - //String burnMemo = "Burn type test " + System.currentTimeMillis(); + // Query account before mint balance + final Long beforeBurnAccountBalance = + getBalanceOfShieldTrc20( + receiverAddressString, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); + // Query contract before mint balance + final Long beforeBurnShieldAccountBalance = + getBalanceOfShieldTrc20( + shieldAddress, zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); + + // String burnMemo = "Burn type test " + System.currentTimeMillis(); inputShieldAddressList.add(senderShieldAddressInfo.get()); BigInteger receiveAmount = publicFromAmount; - //Create transfer parameters - GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters - = createShieldedTrc20Parameters(BigInteger.valueOf(0), - senderNote, inputShieldAddressList, null, receiverAddressString, - receiveAmount.longValue(), blockingStubFull, blockingStubSolidity); + // Create transfer parameters + GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters = + createShieldedTrc20Parameters( + BigInteger.valueOf(0), + senderNote, + inputShieldAddressList, + null, + receiverAddressString, + receiveAmount.longValue(), + blockingStubFull, + blockingStubSolidity); String data = shieldedTrc20Parameters.getTriggerContractInput(); - String txid = PublicMethod.triggerContract(shieldAddressByte, - burn, data, true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + shieldAddressByte, + burn, + data, + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getReceipt().getResultValue() == 1); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() > 180000); logger.info("scanShieldedTrc20NoteByIvk + senderNote:" + senderNote); - senderNote = scanShieldedTrc20NoteByIvk(senderShieldAddressInfo.get(), - blockingStubFull); + senderNote = scanShieldedTrc20NoteByIvk(senderShieldAddressInfo.get(), blockingStubFull); Assert.assertEquals(senderNote.getNoteTxs(0).getIsSpent(), true); - final Long afterBurnAccountBalance = getBalanceOfShieldTrc20(receiverAddressString, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); - //Query contract before mint balance - final Long afterBurnShieldAccountBalance = getBalanceOfShieldTrc20(shieldAddress, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); + final Long afterBurnAccountBalance = + getBalanceOfShieldTrc20( + receiverAddressString, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); + // Query contract before mint balance + final Long afterBurnShieldAccountBalance = + getBalanceOfShieldTrc20( + shieldAddress, zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); logger.info("afterBurnAccountBalance :" + afterBurnAccountBalance); logger.info("beforeBurnAccountBalance :" + beforeBurnAccountBalance); logger.info("beforeBurnShieldAccountBalance:" + beforeBurnShieldAccountBalance); logger.info("afterBurnShieldAccountBalance :" + afterBurnShieldAccountBalance); - Assert.assertEquals(BigInteger.valueOf(afterBurnAccountBalance - beforeBurnAccountBalance), + Assert.assertEquals( + BigInteger.valueOf(afterBurnAccountBalance - beforeBurnAccountBalance), receiveAmount); + Assert.assertEquals( + BigInteger.valueOf(beforeBurnShieldAccountBalance - afterBurnShieldAccountBalance), receiveAmount); - Assert.assertEquals(BigInteger.valueOf(beforeBurnShieldAccountBalance - - afterBurnShieldAccountBalance), receiveAmount); - senderNote = scanShieldedTrc20NoteByOvk(senderShieldAddressInfo.get(), - blockingStubFull); - Assert.assertEquals(ByteArray.toHexString(senderNote.getNoteTxs(0) - .getTxid().toByteArray()), txid); + senderNote = scanShieldedTrc20NoteByOvk(senderShieldAddressInfo.get(), blockingStubFull); + Assert.assertEquals( + ByteArray.toHexString(senderNote.getNoteTxs(0).getTxid().toByteArray()), txid); Assert.assertEquals(senderNote.getNoteTxs(0).getToAmount(), publicFromAmount.toString()); - String toAddress = ByteArray.toHexString(senderNote.getNoteTxs(0) - .getTransparentToAddress().toByteArray()); + String toAddress = + ByteArray.toHexString(senderNote.getNoteTxs(0).getTransparentToAddress().toByteArray()); String receiverHexString = ByteArray.toHexString(PublicMethod.getFinalAddress(receiverKey)); Assert.assertEquals(toAddress, receiverHexString); - - } - - /** - * constructor. - */ - @Test(enabled = true, description = "Shield TRC20 transaction to one T and one S with type burn", groups = {"daily", "serial", "shield"}) + /** constructor. */ + @Test( + enabled = true, + description = "Shield TRC20 transaction to one T and one S with type burn", + groups = {"daily", "serial", "shield"}) public void test02ShieldTrc20TransactionWithTypeBurnToOnePublicAndOneShield() throws Exception { - secondSenderNote = scanShieldedTrc20NoteByIvk(secondSenderShieldAddressInfo.get(), - blockingStubFull); - - //Query account before mint balance - final Long beforeBurnAccountBalance = getBalanceOfShieldTrc20(receiverAddressString, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); - //Query contract before mint balance - final Long beforeBurnShieldAccountBalance = getBalanceOfShieldTrc20(shieldAddress, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); + secondSenderNote = + scanShieldedTrc20NoteByIvk(secondSenderShieldAddressInfo.get(), blockingStubFull); + + // Query account before mint balance + final Long beforeBurnAccountBalance = + getBalanceOfShieldTrc20( + receiverAddressString, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); + // Query contract before mint balance + final Long beforeBurnShieldAccountBalance = + getBalanceOfShieldTrc20( + shieldAddress, zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); inputShieldAddressList.clear(); inputShieldAddressList.add(secondSenderShieldAddressInfo.get()); @@ -225,77 +273,92 @@ public void test02ShieldTrc20TransactionWithTypeBurnToOnePublicAndOneShield() th String receiverShieldAddress = receiverShieldAddressInfo.getAddress(); String memo = "Burn to one shield and one public test " + System.currentTimeMillis(); shieldOutList.clear(); - shieldOutList = addShieldTrc20OutputList(shieldOutList, receiverShieldAddress, - "" + shieldReceiveAmount, memo, blockingStubFull); - - //Create transfer parameters - GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters - = createShieldedTrc20Parameters(BigInteger.valueOf(0), - secondSenderNote, inputShieldAddressList, shieldOutList, receiverAddressString, - receiveAmount.longValue(), blockingStubFull, blockingStubSolidity); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, receiverShieldAddress, "" + shieldReceiveAmount, memo, blockingStubFull); + + // Create transfer parameters + GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters = + createShieldedTrc20Parameters( + BigInteger.valueOf(0), + secondSenderNote, + inputShieldAddressList, + shieldOutList, + receiverAddressString, + receiveAmount.longValue(), + blockingStubFull, + blockingStubSolidity); String data = shieldedTrc20Parameters.getTriggerContractInput(); - String txid = PublicMethod.triggerContract(shieldAddressByte, - burn, data, true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + shieldAddressByte, + burn, + data, + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getReceipt().getResultValue() == 1); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() > 180000); logger.info("scanShieldedTrc20NoteByIvk + senderNote:" + senderNote); - senderNote = scanShieldedTrc20NoteByIvk(senderShieldAddressInfo.get(), - blockingStubFull); + senderNote = scanShieldedTrc20NoteByIvk(senderShieldAddressInfo.get(), blockingStubFull); Assert.assertEquals(senderNote.getNoteTxs(0).getIsSpent(), true); - final Long afterBurnAccountBalance = getBalanceOfShieldTrc20(receiverAddressString, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); - //Query contract before mint balance - final Long afterBurnShieldAccountBalance = getBalanceOfShieldTrc20(shieldAddress, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); + final Long afterBurnAccountBalance = + getBalanceOfShieldTrc20( + receiverAddressString, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); + // Query contract before mint balance + final Long afterBurnShieldAccountBalance = + getBalanceOfShieldTrc20( + shieldAddress, zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); logger.info("afterBurnAccountBalance :" + afterBurnAccountBalance); logger.info("beforeBurnAccountBalance :" + beforeBurnAccountBalance); logger.info("beforeBurnShieldAccountBalance:" + beforeBurnShieldAccountBalance); logger.info("afterBurnShieldAccountBalance :" + afterBurnShieldAccountBalance); - Assert.assertEquals(BigInteger.valueOf(afterBurnAccountBalance - beforeBurnAccountBalance), + Assert.assertEquals( + BigInteger.valueOf(afterBurnAccountBalance - beforeBurnAccountBalance), receiveAmount); + Assert.assertEquals( + BigInteger.valueOf(beforeBurnShieldAccountBalance - afterBurnShieldAccountBalance), receiveAmount); - Assert.assertEquals(BigInteger.valueOf(beforeBurnShieldAccountBalance - - afterBurnShieldAccountBalance), receiveAmount); - secondSenderNote = scanShieldedTrc20NoteByOvk(secondSenderShieldAddressInfo.get(), - blockingStubFull); + secondSenderNote = + scanShieldedTrc20NoteByOvk(secondSenderShieldAddressInfo.get(), blockingStubFull); logger.info(secondSenderNote.toString()); - Assert.assertEquals(secondSenderNote.getNoteTxs(0).getNote().getValue(), - shieldReceiveAmount.longValue()); + Assert.assertEquals( + secondSenderNote.getNoteTxs(0).getNote().getValue(), shieldReceiveAmount.longValue()); - Assert.assertEquals(ByteArray.toHexString(secondSenderNote.getNoteTxs(1) - .getTxid().toByteArray()), txid); + Assert.assertEquals( + ByteArray.toHexString(secondSenderNote.getNoteTxs(1).getTxid().toByteArray()), txid); Assert.assertEquals(secondSenderNote.getNoteTxs(1).getToAmount(), receiveAmount.toString()); - String toAddress = ByteArray.toHexString(secondSenderNote.getNoteTxs(1) - .getTransparentToAddress().toByteArray()); + String toAddress = + ByteArray.toHexString( + secondSenderNote.getNoteTxs(1).getTransparentToAddress().toByteArray()); String receiverHexString = ByteArray.toHexString(PublicMethod.getFinalAddress(receiverKey)); Assert.assertEquals(toAddress, receiverHexString); - GrpcAPI.DecryptNotesTRC20 receiverSenderNote - = scanShieldedTrc20NoteByIvk(receiverShieldAddressInfo, - blockingStubFull); - Assert.assertEquals(receiverSenderNote.getNoteTxs(0) - .getIsSpent(), false); - Assert.assertEquals(receiverSenderNote.getNoteTxs(0) - .getNote().getValue(), shieldReceiveAmount.longValue()); - Assert.assertEquals(ByteArray.toHexString(receiverSenderNote - .getNoteTxs(0).getTxid().toByteArray()), txid); - - + GrpcAPI.DecryptNotesTRC20 receiverSenderNote = + scanShieldedTrc20NoteByIvk(receiverShieldAddressInfo, blockingStubFull); + Assert.assertEquals(receiverSenderNote.getNoteTxs(0).getIsSpent(), false); + Assert.assertEquals( + receiverSenderNote.getNoteTxs(0).getNote().getValue(), shieldReceiveAmount.longValue()); + Assert.assertEquals( + ByteArray.toHexString(receiverSenderNote.getNoteTxs(0).getTxid().toByteArray()), txid); } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { if (channelFull != null) { @@ -303,5 +366,3 @@ public void shutdown() throws InterruptedException { } } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token005.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token005.java index 2043b572..65499abc 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token005.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token005.java @@ -27,10 +27,10 @@ @Slf4j public class ShieldTrc20Token005 extends ZenTrc20Base { - private String fullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(0); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String fullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); Optional senderShieldAddressInfo; Optional secondSenderShieldAddressInfo; private BigInteger publicFromAmount; @@ -42,155 +42,206 @@ public class ShieldTrc20Token005 extends ZenTrc20Base { GrpcAPI.DecryptNotesTRC20 receiverSenderNote; long senderPosition; - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] receiverAddressbyte = ecKey1.getAddress(); String receiverKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); String receiverAddressString = PublicMethod.getAddressString(receiverKey); - - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() throws Exception { - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext() - .build(); + channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); blockingStubFull = WalletGrpc.newBlockingStub(channelFull); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); publicFromAmount = getRandomAmount(); - //Generate new shiled account for sender and receiver + // Generate new shiled account for sender and receiver senderShieldAddressInfo = getNewShieldedAddress(blockingStubFull); String memo = "Create a note for burn withoutask test " + System.currentTimeMillis(); String sendShieldAddress = senderShieldAddressInfo.get().getAddress(); shieldOutList.clear(); - shieldOutList = addShieldTrc20OutputList(shieldOutList, sendShieldAddress, - "" + publicFromAmount, memo, blockingStubFull); - //Create mint parameters - GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters - = createShieldedTrc20Parameters(publicFromAmount, - null, null, shieldOutList, "", 0L, - blockingStubFull, blockingStubSolidity); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, sendShieldAddress, "" + publicFromAmount, memo, blockingStubFull); + // Create mint parameters + GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters = + createShieldedTrc20Parameters( + publicFromAmount, + null, + null, + shieldOutList, + "", + 0L, + blockingStubFull, + blockingStubSolidity); String data = encodeMintParamsToHexString(shieldedTrc20Parameters, publicFromAmount); - //Do mint transaction type - String txid = PublicMethod.triggerContract(shieldAddressByte, - mint, data, true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); + // Do mint transaction type + String txid = + PublicMethod.triggerContract( + shieldAddressByte, + mint, + data, + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getReceipt().getResultValue() == 1); - //Create second mint parameters - memo = "Create a note for burn to one public and one shield withoutask test " - + System.currentTimeMillis(); + // Create second mint parameters + memo = + "Create a note for burn to one public and one shield withoutask test " + + System.currentTimeMillis(); secondSenderShieldAddressInfo = getNewShieldedAddress(blockingStubFull); String sesendShieldAddress = secondSenderShieldAddressInfo.get().getAddress(); shieldOutList.clear(); - shieldOutList = addShieldTrc20OutputList(shieldOutList, sesendShieldAddress, - "" + publicFromAmount, memo, blockingStubFull); - - shieldedTrc20Parameters - = createShieldedTrc20Parameters(publicFromAmount, - null, null, shieldOutList, "", 0L, - blockingStubFull, blockingStubSolidity); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, sesendShieldAddress, "" + publicFromAmount, memo, blockingStubFull); + + shieldedTrc20Parameters = + createShieldedTrc20Parameters( + publicFromAmount, + null, + null, + shieldOutList, + "", + 0L, + blockingStubFull, + blockingStubSolidity); data = encodeMintParamsToHexString(shieldedTrc20Parameters, publicFromAmount); - //Do mint transaction type - txid = PublicMethod.triggerContract(shieldAddressByte, - mint, data, true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); + // Do mint transaction type + txid = + PublicMethod.triggerContract( + shieldAddressByte, + mint, + data, + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getReceipt().getResultValue() == 1); - //Scan sender note - senderNote = scanShieldedTrc20NoteByIvk(senderShieldAddressInfo.get(), - blockingStubFull); + // Scan sender note + senderNote = scanShieldedTrc20NoteByIvk(senderShieldAddressInfo.get(), blockingStubFull); Assert.assertEquals(senderNote.getNoteTxs(0).getIsSpent(), false); logger.info("" + senderNote); senderPosition = senderNote.getNoteTxs(0).getPosition(); - Assert.assertEquals(senderNote.getNoteTxs(0).getNote().getValue(), - publicFromAmount.longValue()); - - + Assert.assertEquals( + senderNote.getNoteTxs(0).getNote().getValue(), publicFromAmount.longValue()); } - /** - * constructor. - */ - @Test(enabled = true, description = "Shield TRC20 transaction with type burn and without ask", groups = {"daily", "serial", "shield"}) + /** constructor. */ + @Test( + enabled = true, + description = "Shield TRC20 transaction with type burn and without ask", + groups = {"daily", "serial", "shield"}) public void test01ShieldTrc20TransactionWithTypeBurnWithoutAsk() throws Exception { PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); - //Query account before mint balance - final Long beforeBurnAccountBalance = getBalanceOfShieldTrc20(receiverAddressString, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); - //Query contract before mint balance - final Long beforeBurnShieldAccountBalance = getBalanceOfShieldTrc20(shieldAddress, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); + // Query account before mint balance + final Long beforeBurnAccountBalance = + getBalanceOfShieldTrc20( + receiverAddressString, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); + // Query contract before mint balance + final Long beforeBurnShieldAccountBalance = + getBalanceOfShieldTrc20( + shieldAddress, zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); inputShieldAddressList.add(senderShieldAddressInfo.get()); BigInteger receiveAmount = publicFromAmount; - //Create burn parameters - GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters - = createShieldedTrc20ParametersWithoutAsk(BigInteger.valueOf(0), - senderNote, inputShieldAddressList, null, receiverAddressString, receiverAddressbyte, - receiveAmount.longValue(), blockingStubFull, blockingStubSolidity); + // Create burn parameters + GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters = + createShieldedTrc20ParametersWithoutAsk( + BigInteger.valueOf(0), + senderNote, + inputShieldAddressList, + null, + receiverAddressString, + receiverAddressbyte, + receiveAmount.longValue(), + blockingStubFull, + blockingStubSolidity); String data = shieldedTrc20Parameters.getTriggerContractInput(); - String txid = PublicMethod.triggerContract(shieldAddressByte, - burn, data, true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + shieldAddressByte, + burn, + data, + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getReceipt().getResultValue() == 1); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() > 180000); logger.info("scanShieldedTrc20NoteByIvk + senderNote:" + senderNote); - senderNote = scanShieldedTrc20NoteByIvk(senderShieldAddressInfo.get(), - blockingStubFull); + senderNote = scanShieldedTrc20NoteByIvk(senderShieldAddressInfo.get(), blockingStubFull); Assert.assertEquals(senderNote.getNoteTxs(0).getIsSpent(), true); - final Long afterBurnAccountBalance = getBalanceOfShieldTrc20(receiverAddressString, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); - //Query contract before mint balance - final Long afterBurnShieldAccountBalance = getBalanceOfShieldTrc20(shieldAddress, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); + final Long afterBurnAccountBalance = + getBalanceOfShieldTrc20( + receiverAddressString, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); + // Query contract before mint balance + final Long afterBurnShieldAccountBalance = + getBalanceOfShieldTrc20( + shieldAddress, zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); logger.info("afterBurnAccountBalance :" + afterBurnAccountBalance); logger.info("beforeBurnAccountBalance :" + beforeBurnAccountBalance); logger.info("beforeBurnShieldAccountBalance:" + beforeBurnShieldAccountBalance); logger.info("afterBurnShieldAccountBalance :" + afterBurnShieldAccountBalance); - Assert.assertEquals(BigInteger.valueOf(afterBurnAccountBalance - beforeBurnAccountBalance), - receiveAmount); - Assert.assertEquals(BigInteger.valueOf(beforeBurnShieldAccountBalance - - afterBurnShieldAccountBalance), + Assert.assertEquals( + BigInteger.valueOf(afterBurnAccountBalance - beforeBurnAccountBalance), receiveAmount); + Assert.assertEquals( + BigInteger.valueOf(beforeBurnShieldAccountBalance - afterBurnShieldAccountBalance), receiveAmount); } - /** - * constructor. - */ - @Test(enabled = true, description = "Shield TRC20 transaction with type burn to one " - + "T and one Z address and without ask", groups = {"daily", "serial", "shield"}) + /** constructor. */ + @Test( + enabled = true, + description = + "Shield TRC20 transaction with type burn to one " + "T and one Z address and without ask", + groups = {"daily", "serial", "shield"}) public void test02ShieldTrc20TransactionWithTypeBurnWithoutAsk() throws Exception { - //Scan sender note - secondSenderNote = scanShieldedTrc20NoteByIvk(secondSenderShieldAddressInfo.get(), - blockingStubFull); - //Query account before mint balance - final Long beforeBurnAccountBalance = getBalanceOfShieldTrc20(receiverAddressString, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); - //Query contract before mint balance - final Long beforeBurnShieldAccountBalance = getBalanceOfShieldTrc20(shieldAddress, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); + // Scan sender note + secondSenderNote = + scanShieldedTrc20NoteByIvk(secondSenderShieldAddressInfo.get(), blockingStubFull); + // Query account before mint balance + final Long beforeBurnAccountBalance = + getBalanceOfShieldTrc20( + receiverAddressString, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); + // Query contract before mint balance + final Long beforeBurnShieldAccountBalance = + getBalanceOfShieldTrc20( + shieldAddress, zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); inputShieldAddressList.clear(); inputShieldAddressList.add(secondSenderShieldAddressInfo.get()); @@ -201,70 +252,84 @@ public void test02ShieldTrc20TransactionWithTypeBurnWithoutAsk() throws Exceptio String receiverShieldAddress = receiverShieldAddressInfo.getAddress(); String memo = "Burn to one shield and one public test " + System.currentTimeMillis(); shieldOutList.clear(); - shieldOutList = addShieldTrc20OutputList(shieldOutList, receiverShieldAddress, - "" + shieldReceiveAmount, memo, blockingStubFull); - - //Create burn parameters - GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters - = createShieldedTrc20ParametersWithoutAsk(BigInteger.valueOf(0), - secondSenderNote, inputShieldAddressList, shieldOutList, receiverAddressString, - receiverAddressbyte, - receiveAmount.longValue(), blockingStubFull, blockingStubSolidity); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, receiverShieldAddress, "" + shieldReceiveAmount, memo, blockingStubFull); + + // Create burn parameters + GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters = + createShieldedTrc20ParametersWithoutAsk( + BigInteger.valueOf(0), + secondSenderNote, + inputShieldAddressList, + shieldOutList, + receiverAddressString, + receiverAddressbyte, + receiveAmount.longValue(), + blockingStubFull, + blockingStubSolidity); String data = shieldedTrc20Parameters.getTriggerContractInput(); - String txid = PublicMethod.triggerContract(shieldAddressByte, - burn, data, true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + shieldAddressByte, + burn, + data, + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getReceipt().getResultValue() == 1); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() > 180000); logger.info("scanShieldedTrc20NoteByIvk + senderNote:" + senderNote); - secondSenderNote = scanShieldedTrc20NoteByIvk(secondSenderShieldAddressInfo.get(), - blockingStubFull); + secondSenderNote = + scanShieldedTrc20NoteByIvk(secondSenderShieldAddressInfo.get(), blockingStubFull); Assert.assertEquals(secondSenderNote.getNoteTxs(0).getIsSpent(), true); - final Long afterBurnAccountBalance = getBalanceOfShieldTrc20(receiverAddressString, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); - //Query contract before mint balance - final Long afterBurnShieldAccountBalance = getBalanceOfShieldTrc20(shieldAddress, - zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); + final Long afterBurnAccountBalance = + getBalanceOfShieldTrc20( + receiverAddressString, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); + // Query contract before mint balance + final Long afterBurnShieldAccountBalance = + getBalanceOfShieldTrc20( + shieldAddress, zenTrc20TokenOwnerAddress, zenTrc20TokenOwnerKey, blockingStubFull); logger.info("afterBurnAccountBalance :" + afterBurnAccountBalance); logger.info("beforeBurnAccountBalance :" + beforeBurnAccountBalance); logger.info("beforeBurnShieldAccountBalance:" + beforeBurnShieldAccountBalance); logger.info("afterBurnShieldAccountBalance :" + afterBurnShieldAccountBalance); - Assert.assertEquals(BigInteger.valueOf(afterBurnAccountBalance - beforeBurnAccountBalance), - receiveAmount); - Assert.assertEquals(BigInteger.valueOf(beforeBurnShieldAccountBalance - - afterBurnShieldAccountBalance), + Assert.assertEquals( + BigInteger.valueOf(afterBurnAccountBalance - beforeBurnAccountBalance), receiveAmount); + Assert.assertEquals( + BigInteger.valueOf(beforeBurnShieldAccountBalance - afterBurnShieldAccountBalance), receiveAmount); - receiverSenderNote = scanShieldedTrc20NoteByIvk(receiverShieldAddressInfo, - blockingStubFull); + receiverSenderNote = scanShieldedTrc20NoteByIvk(receiverShieldAddressInfo, blockingStubFull); Assert.assertEquals(receiverSenderNote.getNoteTxs(0).getIsSpent(), false); - Assert.assertEquals(receiverSenderNote.getNoteTxs(0).getNote() - .getValue(), shieldReceiveAmount.longValue()); - Assert.assertEquals(ByteArray.toHexString(receiverSenderNote.getNoteTxs(0) - .getTxid().toByteArray()), txid); + Assert.assertEquals( + receiverSenderNote.getNoteTxs(0).getNote().getValue(), shieldReceiveAmount.longValue()); + Assert.assertEquals( + ByteArray.toHexString(receiverSenderNote.getNoteTxs(0).getTxid().toByteArray()), txid); - secondSenderNote = scanShieldedTrc20NoteByOvk(secondSenderShieldAddressInfo.get(), - blockingStubFull); + secondSenderNote = + scanShieldedTrc20NoteByOvk(secondSenderShieldAddressInfo.get(), blockingStubFull); logger.info(secondSenderNote.toString()); - Assert.assertEquals(secondSenderNote.getNoteTxs(0).getNote().getValue(), - shieldReceiveAmount.longValue()); - - + Assert.assertEquals( + secondSenderNote.getNoteTxs(0).getNote().getValue(), shieldReceiveAmount.longValue()); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { if (channelFull != null) { @@ -272,5 +337,3 @@ public void shutdown() throws InterruptedException { } } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token006.java b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token006.java index c9c01049..0c0d5e63 100644 --- a/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token006.java +++ b/testcase/src/test/java/stest/tron/wallet/dailybuild/zentrc20token/ShieldTrc20Token006.java @@ -25,12 +25,12 @@ @Slf4j public class ShieldTrc20Token006 extends ZenTrc20Base { - private String fullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(0); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - private String soliInPbft = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(2); + private String fullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + private String soliInPbft = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(2); Optional shieldAddressInfo1; Optional shieldAddressInfo2; String shieldAddress1; @@ -47,72 +47,76 @@ public class ShieldTrc20Token006 extends ZenTrc20Base { GrpcAPI.DecryptNotesTRC20 shield2Note; long senderPosition; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() throws Exception { - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext() - .build(); + channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); blockingStubFull = WalletGrpc.newBlockingStub(channelFull); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - channelPbft = ManagedChannelBuilder.forTarget(soliInPbft) - .usePlaintext() - .build(); + channelPbft = ManagedChannelBuilder.forTarget(soliInPbft).usePlaintext().build(); blockingStubPbft = WalletSolidityGrpc.newBlockingStub(channelPbft); publicFromAmount = getRandomAmount(); - //Generate new shiled account for sender and receiver + // Generate new shiled account for sender and receiver shieldAddressInfo1 = getNewShieldedAddress(blockingStubFull); shieldAddressInfo2 = getNewShieldedAddress(blockingStubFull); String memo = "Create a note for transfer test " + System.currentTimeMillis(); shieldAddress1 = shieldAddressInfo1.get().getAddress(); shieldOutList.clear(); - shieldOutList = addShieldTrc20OutputList(shieldOutList, shieldAddress1, - "" + publicFromAmount, memo, blockingStubFull); - //Create mint parameters - GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters - = createShieldedTrc20Parameters(publicFromAmount, - null, null, shieldOutList, "", 0L, - blockingStubFull, blockingStubSolidity - ); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, shieldAddress1, "" + publicFromAmount, memo, blockingStubFull); + // Create mint parameters + GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters = + createShieldedTrc20Parameters( + publicFromAmount, + null, + null, + shieldOutList, + "", + 0L, + blockingStubFull, + blockingStubSolidity); String data = encodeMintParamsToHexString(shieldedTrc20Parameters, publicFromAmount); - //Do mint transaction type - String txid = PublicMethod.triggerContract(shieldAddressByte, - mint, data, true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); + // Do mint transaction type + String txid = + PublicMethod.triggerContract( + shieldAddressByte, + mint, + data, + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getReceipt().getResultValue() == 1); - //Scan sender note - shield1Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo1.get(), - blockingStubFull); + // Scan sender note + shield1Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo1.get(), blockingStubFull); Assert.assertEquals(shield1Note.getNoteTxs(0).getIsSpent(), false); logger.info("" + shield1Note); senderPosition = shield1Note.getNoteTxs(0).getPosition(); - Assert.assertEquals(shield1Note.getNoteTxs(0).getNote().getValue(), - publicFromAmount.longValue()); - - + Assert.assertEquals( + shield1Note.getNoteTxs(0).getNote().getValue(), publicFromAmount.longValue()); } - /** - * constructor. - */ - @Test(enabled = true, description = "Shield TRC20 transfer with type 1 to 2", groups = {"daily", "serial", "shield"}) + /** constructor. */ + @Test( + enabled = true, + description = "Shield TRC20 transfer with type 1 to 2", + groups = {"daily", "serial", "shield"}) public void test01ShieldTrc20TransferWith1To2() throws Exception { PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); - //Prepare parameters + // Prepare parameters final String transferMemo1 = "1 to 2 for shieldAddressInfo1 " + System.currentTimeMillis(); final String transferMemo2 = "1 to 2 for shieldAddressInfo2 " + System.currentTimeMillis(); shieldAddress1 = shieldAddressInfo1.get().getAddress(); @@ -120,400 +124,496 @@ public void test01ShieldTrc20TransferWith1To2() throws Exception { shield1ReceiveAmountFor1to2 = BigInteger.valueOf(30); shield2ReceiveAmountFor1to2 = publicFromAmount.subtract(shield1ReceiveAmountFor1to2); shieldOutList.clear(); - shieldOutList = addShieldTrc20OutputList(shieldOutList, shieldAddress1, - "" + shield1ReceiveAmountFor1to2, transferMemo1, blockingStubFull); - shieldOutList = addShieldTrc20OutputList(shieldOutList, shieldAddress2, - "" + shield2ReceiveAmountFor1to2, transferMemo2, blockingStubFull); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, + shieldAddress1, + "" + shield1ReceiveAmountFor1to2, + transferMemo1, + blockingStubFull); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, + shieldAddress2, + "" + shield2ReceiveAmountFor1to2, + transferMemo2, + blockingStubFull); inputShieldAddressList.clear(); inputShieldAddressList.add(shieldAddressInfo1.get()); - //Create transfer parameters - GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters - = createShieldedTrc20Parameters(BigInteger.valueOf(0), - shield1Note, inputShieldAddressList, shieldOutList, "", 0L, - blockingStubFull, blockingStubSolidity - ); - - //Create transfer transaction + // Create transfer parameters + GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters = + createShieldedTrc20Parameters( + BigInteger.valueOf(0), + shield1Note, + inputShieldAddressList, + shieldOutList, + "", + 0L, + blockingStubFull, + blockingStubSolidity); + + // Create transfer transaction String data = encodeTransferParamsToHexString(shieldedTrc20Parameters); - String txid = PublicMethod.triggerContract(shieldAddressByte, - transfer, data, true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + shieldAddressByte, + transfer, + data, + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getReceipt().getResultValue() == 1); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() > 300000); - //Scan 1 to 2 ivk note - shield1Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo1.get(), - blockingStubFull); - shield2Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo2.get(), - blockingStubFull); + // Scan 1 to 2 ivk note + shield1Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo1.get(), blockingStubFull); + shield2Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo2.get(), blockingStubFull); logger.info("" + shield1Note); logger.info("" + shield2Note); Assert.assertEquals(shield1Note.getNoteTxs(1).getTxid(), infoById.get().getId()); - Assert.assertEquals(shield1Note.getNoteTxs(1).getNote().getMemo(), - ByteString.copyFromUtf8(transferMemo1)); - Assert.assertEquals(shield1Note.getNoteTxs(1).getNote().getValue(), - shield1ReceiveAmountFor1to2.longValue()); - Assert.assertEquals(shield1Note.getNoteTxs(1).getNote().getPaymentAddress(), + Assert.assertEquals( + shield1Note.getNoteTxs(1).getNote().getMemo(), ByteString.copyFromUtf8(transferMemo1)); + Assert.assertEquals( + shield1Note.getNoteTxs(1).getNote().getValue(), shield1ReceiveAmountFor1to2.longValue()); + Assert.assertEquals( + shield1Note.getNoteTxs(1).getNote().getPaymentAddress(), shieldAddressInfo1.get().getAddress()); Assert.assertEquals(shield2Note.getNoteTxs(0).getTxid(), infoById.get().getId()); - Assert.assertEquals(shield2Note.getNoteTxs(0).getNote().getMemo(), - ByteString.copyFromUtf8(transferMemo2)); - Assert.assertEquals(shield2Note.getNoteTxs(0).getNote().getValue(), - shield2ReceiveAmountFor1to2.longValue()); - Assert.assertEquals(shield2Note.getNoteTxs(0).getNote().getPaymentAddress(), + Assert.assertEquals( + shield2Note.getNoteTxs(0).getNote().getMemo(), ByteString.copyFromUtf8(transferMemo2)); + Assert.assertEquals( + shield2Note.getNoteTxs(0).getNote().getValue(), shield2ReceiveAmountFor1to2.longValue()); + Assert.assertEquals( + shield2Note.getNoteTxs(0).getNote().getPaymentAddress(), shieldAddressInfo2.get().getAddress()); Assert.assertEquals(shield1Note.getNoteTxs(0).getIsSpent(), true); - //Scan 1 to 2 ovk note - shield1Note = scanShieldedTrc20NoteByOvk(shieldAddressInfo1.get(), - blockingStubFull); + // Scan 1 to 2 ovk note + shield1Note = scanShieldedTrc20NoteByOvk(shieldAddressInfo1.get(), blockingStubFull); logger.info("scanShieldedTrc20NoteByOvk + shield1Note:" + shield1Note); Assert.assertEquals(shield1Note.getNoteTxsCount(), 2); Assert.assertEquals(shield1Note.getNoteTxs(0).getTxid(), infoById.get().getId()); - Assert.assertEquals(shield1Note.getNoteTxs(0).getNote().getMemo(), - ByteString.copyFromUtf8(transferMemo1)); - Assert.assertEquals(shield1Note.getNoteTxs(0).getNote().getValue(), - shield1ReceiveAmountFor1to2.longValue()); - Assert.assertEquals(shield1Note.getNoteTxs(0).getNote().getPaymentAddress(), + Assert.assertEquals( + shield1Note.getNoteTxs(0).getNote().getMemo(), ByteString.copyFromUtf8(transferMemo1)); + Assert.assertEquals( + shield1Note.getNoteTxs(0).getNote().getValue(), shield1ReceiveAmountFor1to2.longValue()); + Assert.assertEquals( + shield1Note.getNoteTxs(0).getNote().getPaymentAddress(), shieldAddressInfo1.get().getAddress()); Assert.assertEquals(shield1Note.getNoteTxs(1).getTxid(), infoById.get().getId()); - Assert.assertEquals(shield1Note.getNoteTxs(1).getNote().getMemo(), - ByteString.copyFromUtf8(transferMemo2)); - Assert.assertEquals(shield1Note.getNoteTxs(1).getNote().getValue(), - shield2ReceiveAmountFor1to2.longValue()); - Assert.assertEquals(shield1Note.getNoteTxs(1).getNote().getPaymentAddress(), + Assert.assertEquals( + shield1Note.getNoteTxs(1).getNote().getMemo(), ByteString.copyFromUtf8(transferMemo2)); + Assert.assertEquals( + shield1Note.getNoteTxs(1).getNote().getValue(), shield2ReceiveAmountFor1to2.longValue()); + Assert.assertEquals( + shield1Note.getNoteTxs(1).getNote().getPaymentAddress(), shieldAddressInfo2.get().getAddress()); } - - /** - * constructor. - */ - @Test(enabled = true, description = "Shield TRC20 transfer with type 2 to 2", groups = {"daily", "serial", "shield"}) + /** constructor. */ + @Test( + enabled = true, + description = "Shield TRC20 transfer with type 2 to 2", + groups = {"daily", "serial", "shield"}) public void test02ShieldTrc20TransferWith2To2() throws Exception { - //Create a new note for 2 to 2 + // Create a new note for 2 to 2 String memo = "Create a new note for transfer test " + System.currentTimeMillis(); shieldAddress1 = shieldAddressInfo1.get().getAddress(); shieldOutList.clear(); - shieldOutList = addShieldTrc20OutputList(shieldOutList, shieldAddress1, - "" + publicFromAmount, memo, blockingStubFull); - //Create mint parameters - GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters - = createShieldedTrc20Parameters(publicFromAmount, - null, null, shieldOutList, "", 0L, - blockingStubFull, blockingStubSolidity - ); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, shieldAddress1, "" + publicFromAmount, memo, blockingStubFull); + // Create mint parameters + GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters = + createShieldedTrc20Parameters( + publicFromAmount, + null, + null, + shieldOutList, + "", + 0L, + blockingStubFull, + blockingStubSolidity); String data = encodeMintParamsToHexString(shieldedTrc20Parameters, publicFromAmount); - //Do mint transaction type - String txid = PublicMethod.triggerContract(shieldAddressByte, - mint, data, true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); + // Do mint transaction type + String txid = + PublicMethod.triggerContract( + shieldAddressByte, + mint, + data, + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getReceipt().getResultValue() == 1); - shield1Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo1.get(), - blockingStubFull); + shield1Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo1.get(), blockingStubFull); - final GrpcAPI.DecryptNotesTRC20 inputNoteFor2to2 = GrpcAPI.DecryptNotesTRC20.newBuilder() - .addNoteTxs(shield1Note.getNoteTxs(1)) - .addNoteTxs(shield1Note.getNoteTxs(2)).build(); + final GrpcAPI.DecryptNotesTRC20 inputNoteFor2to2 = + GrpcAPI.DecryptNotesTRC20.newBuilder() + .addNoteTxs(shield1Note.getNoteTxs(1)) + .addNoteTxs(shield1Note.getNoteTxs(2)) + .build(); - //Prepare parameters + // Prepare parameters final String transferMemo1 = "2 to 2 for shieldAddressInfo1 " + System.currentTimeMillis(); final String transferMemo2 = "2 to 2 for shieldAddressInfo2 " + System.currentTimeMillis(); shieldAddress1 = shieldAddressInfo1.get().getAddress(); shieldAddress2 = shieldAddressInfo2.get().getAddress(); shield1ReceiveAmountFor2to2 = BigInteger.valueOf(5); - shield2ReceiveAmountFor2to2 = publicFromAmount.add(shield1ReceiveAmountFor1to2) - .subtract(shield1ReceiveAmountFor2to2); + shield2ReceiveAmountFor2to2 = + publicFromAmount.add(shield1ReceiveAmountFor1to2).subtract(shield1ReceiveAmountFor2to2); shieldOutList.clear(); - shieldOutList = addShieldTrc20OutputList(shieldOutList, shieldAddress1, - "" + shield1ReceiveAmountFor2to2, transferMemo1, blockingStubFull); - shieldOutList = addShieldTrc20OutputList(shieldOutList, shieldAddress2, - "" + shield2ReceiveAmountFor2to2, transferMemo2, blockingStubFull); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, + shieldAddress1, + "" + shield1ReceiveAmountFor2to2, + transferMemo1, + blockingStubFull); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, + shieldAddress2, + "" + shield2ReceiveAmountFor2to2, + transferMemo2, + blockingStubFull); inputShieldAddressList.clear(); inputShieldAddressList.add(shieldAddressInfo1.get()); inputShieldAddressList.add(shieldAddressInfo1.get()); - //Create transfer parameters - shieldedTrc20Parameters - = createShieldedTrc20Parameters(BigInteger.valueOf(0), - inputNoteFor2to2, inputShieldAddressList, shieldOutList, "", 0L, - blockingStubFull, blockingStubSolidity - ); - - //Create transfer transaction + // Create transfer parameters + shieldedTrc20Parameters = + createShieldedTrc20Parameters( + BigInteger.valueOf(0), + inputNoteFor2to2, + inputShieldAddressList, + shieldOutList, + "", + 0L, + blockingStubFull, + blockingStubSolidity); + + // Create transfer transaction data = encodeTransferParamsToHexString(shieldedTrc20Parameters); - txid = PublicMethod.triggerContract(shieldAddressByte, - transfer, data, true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + shieldAddressByte, + transfer, + data, + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getReceipt().getResultValue() == 1); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() > 300000); - //Scan 2 to 2 ivk note - shield1Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo1.get(), - blockingStubFull); - shield2Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo2.get(), - blockingStubFull); + // Scan 2 to 2 ivk note + shield1Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo1.get(), blockingStubFull); + shield2Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo2.get(), blockingStubFull); logger.info("" + shield1Note); logger.info("" + shield2Note); Assert.assertEquals(shield1Note.getNoteTxs(3).getTxid(), infoById.get().getId()); - Assert.assertEquals(shield1Note.getNoteTxs(3).getNote().getMemo(), - ByteString.copyFromUtf8(transferMemo1)); - Assert.assertEquals(shield1Note.getNoteTxs(3).getNote().getValue(), - shield1ReceiveAmountFor2to2.longValue()); - Assert.assertEquals(shield1Note.getNoteTxs(3).getNote().getPaymentAddress(), + Assert.assertEquals( + shield1Note.getNoteTxs(3).getNote().getMemo(), ByteString.copyFromUtf8(transferMemo1)); + Assert.assertEquals( + shield1Note.getNoteTxs(3).getNote().getValue(), shield1ReceiveAmountFor2to2.longValue()); + Assert.assertEquals( + shield1Note.getNoteTxs(3).getNote().getPaymentAddress(), shieldAddressInfo1.get().getAddress()); Assert.assertEquals(shield2Note.getNoteTxs(1).getTxid(), infoById.get().getId()); - Assert.assertEquals(shield2Note.getNoteTxs(1).getNote().getMemo(), - ByteString.copyFromUtf8(transferMemo2)); - Assert.assertEquals(shield2Note.getNoteTxs(1).getNote().getValue(), - shield2ReceiveAmountFor2to2.longValue()); - Assert.assertEquals(shield2Note.getNoteTxs(1).getNote().getPaymentAddress(), + Assert.assertEquals( + shield2Note.getNoteTxs(1).getNote().getMemo(), ByteString.copyFromUtf8(transferMemo2)); + Assert.assertEquals( + shield2Note.getNoteTxs(1).getNote().getValue(), shield2ReceiveAmountFor2to2.longValue()); + Assert.assertEquals( + shield2Note.getNoteTxs(1).getNote().getPaymentAddress(), shieldAddressInfo2.get().getAddress()); Assert.assertEquals(shield1Note.getNoteTxs(1).getIsSpent(), true); Assert.assertEquals(shield1Note.getNoteTxs(2).getIsSpent(), true); - //Scan 2 to 2 ovk note - shield1Note = scanShieldedTrc20NoteByOvk(shieldAddressInfo1.get(), - blockingStubFull); + // Scan 2 to 2 ovk note + shield1Note = scanShieldedTrc20NoteByOvk(shieldAddressInfo1.get(), blockingStubFull); logger.info("scanShieldedTrc20NoteByOvk + shield1Note:" + shield1Note); Assert.assertEquals(shield1Note.getNoteTxsCount(), 4); Assert.assertEquals(shield1Note.getNoteTxs(2).getTxid(), infoById.get().getId()); - Assert.assertEquals(shield1Note.getNoteTxs(2).getNote().getMemo(), - ByteString.copyFromUtf8(transferMemo1)); - Assert.assertEquals(shield1Note.getNoteTxs(2).getNote().getValue(), - shield1ReceiveAmountFor2to2.longValue()); - Assert.assertEquals(shield1Note.getNoteTxs(2).getNote().getPaymentAddress(), + Assert.assertEquals( + shield1Note.getNoteTxs(2).getNote().getMemo(), ByteString.copyFromUtf8(transferMemo1)); + Assert.assertEquals( + shield1Note.getNoteTxs(2).getNote().getValue(), shield1ReceiveAmountFor2to2.longValue()); + Assert.assertEquals( + shield1Note.getNoteTxs(2).getNote().getPaymentAddress(), shieldAddressInfo1.get().getAddress()); Assert.assertEquals(shield1Note.getNoteTxs(3).getTxid(), infoById.get().getId()); - Assert.assertEquals(shield1Note.getNoteTxs(3).getNote().getMemo(), - ByteString.copyFromUtf8(transferMemo2)); - Assert.assertEquals(shield1Note.getNoteTxs(3).getNote().getValue(), - shield2ReceiveAmountFor2to2.longValue()); - Assert.assertEquals(shield1Note.getNoteTxs(3).getNote().getPaymentAddress(), + Assert.assertEquals( + shield1Note.getNoteTxs(3).getNote().getMemo(), ByteString.copyFromUtf8(transferMemo2)); + Assert.assertEquals( + shield1Note.getNoteTxs(3).getNote().getValue(), shield2ReceiveAmountFor2to2.longValue()); + Assert.assertEquals( + shield1Note.getNoteTxs(3).getNote().getPaymentAddress(), shieldAddressInfo2.get().getAddress()); } - /** - * constructor. - */ - @Test(enabled = true, description = "Shield TRC20 transfer with type 2 to 1", groups = {"daily", "serial", "shield"}) + /** constructor. */ + @Test( + enabled = true, + description = "Shield TRC20 transfer with type 2 to 1", + groups = {"daily", "serial", "shield"}) public void test03ShieldTrc20TransferWith2To1() throws Exception { PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); - shield2Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo2.get(), - blockingStubFull); + shield2Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo2.get(), blockingStubFull); - //Prepare parameters + // Prepare parameters final String transferMemo1 = "2 to 1 for shieldAddressInfo1 " + System.currentTimeMillis(); shieldAddress1 = shieldAddressInfo1.get().getAddress(); - shield1ReceiveAmountFor2to1 = BigInteger.valueOf(shield2Note.getNoteTxs(0) - .getNote().getValue() + shield2Note.getNoteTxs(1).getNote().getValue()); + shield1ReceiveAmountFor2to1 = + BigInteger.valueOf( + shield2Note.getNoteTxs(0).getNote().getValue() + + shield2Note.getNoteTxs(1).getNote().getValue()); shieldOutList.clear(); - shieldOutList = addShieldTrc20OutputList(shieldOutList, shieldAddress1, - "" + shield1ReceiveAmountFor2to1, transferMemo1, blockingStubFull); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, + shieldAddress1, + "" + shield1ReceiveAmountFor2to1, + transferMemo1, + blockingStubFull); inputShieldAddressList.clear(); inputShieldAddressList.add(shieldAddressInfo2.get()); inputShieldAddressList.add(shieldAddressInfo2.get()); - //Create transfer parameters - GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters - = createShieldedTrc20Parameters(BigInteger.valueOf(0), - shield2Note, inputShieldAddressList, shieldOutList, "", 0L, - blockingStubFull, blockingStubSolidity - ); - - //Create transfer transaction + // Create transfer parameters + GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters = + createShieldedTrc20Parameters( + BigInteger.valueOf(0), + shield2Note, + inputShieldAddressList, + shieldOutList, + "", + 0L, + blockingStubFull, + blockingStubSolidity); + + // Create transfer transaction String data = encodeTransferParamsToHexString(shieldedTrc20Parameters); - String txid = PublicMethod.triggerContract(shieldAddressByte, - transfer, data, true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + shieldAddressByte, + transfer, + data, + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getReceipt().getResultValue() == 1); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() > 300000); - //Scan 2 to 1 ivk note - shield1Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo1.get(), - blockingStubFull); - shield2Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo2.get(), - blockingStubFull); + // Scan 2 to 1 ivk note + shield1Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo1.get(), blockingStubFull); + shield2Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo2.get(), blockingStubFull); logger.info("" + shield1Note); logger.info("" + shield2Note); Assert.assertEquals(shield1Note.getNoteTxs(4).getTxid(), infoById.get().getId()); - Assert.assertEquals(shield1Note.getNoteTxs(4).getNote().getMemo(), - ByteString.copyFromUtf8(transferMemo1)); - Assert.assertEquals(shield1Note.getNoteTxs(4).getNote().getValue(), - shield1ReceiveAmountFor2to1.longValue()); - Assert.assertEquals(shield1Note.getNoteTxs(4).getNote().getPaymentAddress(), + Assert.assertEquals( + shield1Note.getNoteTxs(4).getNote().getMemo(), ByteString.copyFromUtf8(transferMemo1)); + Assert.assertEquals( + shield1Note.getNoteTxs(4).getNote().getValue(), shield1ReceiveAmountFor2to1.longValue()); + Assert.assertEquals( + shield1Note.getNoteTxs(4).getNote().getPaymentAddress(), shieldAddressInfo1.get().getAddress()); Assert.assertEquals(shield2Note.getNoteTxs(0).getIsSpent(), true); Assert.assertEquals(shield2Note.getNoteTxs(1).getIsSpent(), true); - //Scan 2 to 1 ovk note - shield2Note = scanShieldedTrc20NoteByOvk(shieldAddressInfo2.get(), - blockingStubFull); + // Scan 2 to 1 ovk note + shield2Note = scanShieldedTrc20NoteByOvk(shieldAddressInfo2.get(), blockingStubFull); logger.info("scanShieldedTrc20NoteByOvk + shield1Note:" + shield2Note); Assert.assertEquals(shield2Note.getNoteTxsCount(), 1); Assert.assertEquals(shield2Note.getNoteTxs(0).getTxid(), infoById.get().getId()); - Assert.assertEquals(shield2Note.getNoteTxs(0).getNote().getValue(), - shield1ReceiveAmountFor2to1.longValue()); - Assert.assertEquals(shield2Note.getNoteTxs(0).getNote().getPaymentAddress(), + Assert.assertEquals( + shield2Note.getNoteTxs(0).getNote().getValue(), shield1ReceiveAmountFor2to1.longValue()); + Assert.assertEquals( + shield2Note.getNoteTxs(0).getNote().getPaymentAddress(), shieldAddressInfo1.get().getAddress()); - } - /** - * constructor. - */ - @Test(enabled = true, description = "Scan shield trc20 note by ivk and ovk on solidity", groups = {"daily", "serial", "shield"}) + /** constructor. */ + @Test( + enabled = true, + description = "Scan shield trc20 note by ivk and ovk on solidity", + groups = {"daily", "serial", "shield"}) public void test04ScanShieldTrc20NoteByIvkAndOvkOnSolidity() throws Exception { PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); - shield1Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo1.get(), - blockingStubFull); - GrpcAPI.DecryptNotesTRC20 shield1NoteOnSolidity - = scanShieldedTrc20NoteByIvk(shieldAddressInfo1.get(), - blockingStubFull, blockingStubSolidity); + shield1Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo1.get(), blockingStubFull); + GrpcAPI.DecryptNotesTRC20 shield1NoteOnSolidity = + scanShieldedTrc20NoteByIvk( + shieldAddressInfo1.get(), blockingStubFull, blockingStubSolidity); Assert.assertEquals(shield1Note, shield1NoteOnSolidity); - shield2Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo2.get(), - blockingStubFull); - GrpcAPI.DecryptNotesTRC20 shield2NoteOnSolidity - = scanShieldedTrc20NoteByIvk(shieldAddressInfo2.get(), - blockingStubFull, blockingStubSolidity); + shield2Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo2.get(), blockingStubFull); + GrpcAPI.DecryptNotesTRC20 shield2NoteOnSolidity = + scanShieldedTrc20NoteByIvk( + shieldAddressInfo2.get(), blockingStubFull, blockingStubSolidity); Assert.assertEquals(shield2Note, shield2NoteOnSolidity); - shield1Note = scanShieldedTrc20NoteByOvk(shieldAddressInfo1.get(), - blockingStubFull); - shield1NoteOnSolidity - = scanShieldedTrc20NoteByOvk(shieldAddressInfo1.get(), - blockingStubFull, blockingStubSolidity); + shield1Note = scanShieldedTrc20NoteByOvk(shieldAddressInfo1.get(), blockingStubFull); + shield1NoteOnSolidity = + scanShieldedTrc20NoteByOvk( + shieldAddressInfo1.get(), blockingStubFull, blockingStubSolidity); Assert.assertEquals(shield1Note, shield1NoteOnSolidity); - shield2Note = scanShieldedTrc20NoteByOvk(shieldAddressInfo2.get(), - blockingStubFull); - shield2NoteOnSolidity - = scanShieldedTrc20NoteByOvk(shieldAddressInfo2.get(), - blockingStubFull, blockingStubSolidity); + shield2Note = scanShieldedTrc20NoteByOvk(shieldAddressInfo2.get(), blockingStubFull); + shield2NoteOnSolidity = + scanShieldedTrc20NoteByOvk( + shieldAddressInfo2.get(), blockingStubFull, blockingStubSolidity); Assert.assertEquals(shield2Note, shield2NoteOnSolidity); } - /** - * constructor. - */ - @Test(enabled = true, description = "Scan shield trc20 note by ivk and ovk on pbft", groups = {"daily", "serial", "shield"}) + /** constructor. */ + @Test( + enabled = true, + description = "Scan shield trc20 note by ivk and ovk on pbft", + groups = {"daily", "serial", "shield"}) public void test04ScanShieldTrc20NoteByIvkAndOvkOnPbft() throws Exception { PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); - shield1Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo1.get(), - blockingStubFull); - GrpcAPI.DecryptNotesTRC20 shield1NoteOnPbft - = scanShieldedTrc20NoteByIvk(shieldAddressInfo1.get(), - blockingStubFull, blockingStubPbft); + shield1Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo1.get(), blockingStubFull); + GrpcAPI.DecryptNotesTRC20 shield1NoteOnPbft = + scanShieldedTrc20NoteByIvk(shieldAddressInfo1.get(), blockingStubFull, blockingStubPbft); Assert.assertEquals(shield1Note, shield1NoteOnPbft); - shield2Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo2.get(), - blockingStubFull); - GrpcAPI.DecryptNotesTRC20 shield2NoteOnPbft - = scanShieldedTrc20NoteByIvk(shieldAddressInfo2.get(), - blockingStubFull, blockingStubPbft); + shield2Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo2.get(), blockingStubFull); + GrpcAPI.DecryptNotesTRC20 shield2NoteOnPbft = + scanShieldedTrc20NoteByIvk(shieldAddressInfo2.get(), blockingStubFull, blockingStubPbft); Assert.assertEquals(shield2Note, shield2NoteOnPbft); - shield1Note = scanShieldedTrc20NoteByOvk(shieldAddressInfo1.get(), - blockingStubFull); - shield1NoteOnPbft - = scanShieldedTrc20NoteByOvk(shieldAddressInfo1.get(), - blockingStubFull, blockingStubPbft); + shield1Note = scanShieldedTrc20NoteByOvk(shieldAddressInfo1.get(), blockingStubFull); + shield1NoteOnPbft = + scanShieldedTrc20NoteByOvk(shieldAddressInfo1.get(), blockingStubFull, blockingStubPbft); Assert.assertEquals(shield1Note, shield1NoteOnPbft); - shield2Note = scanShieldedTrc20NoteByOvk(shieldAddressInfo2.get(), - blockingStubFull); - shield2NoteOnPbft - = scanShieldedTrc20NoteByOvk(shieldAddressInfo2.get(), - blockingStubFull, blockingStubPbft); + shield2Note = scanShieldedTrc20NoteByOvk(shieldAddressInfo2.get(), blockingStubFull); + shield2NoteOnPbft = + scanShieldedTrc20NoteByOvk(shieldAddressInfo2.get(), blockingStubFull, blockingStubPbft); Assert.assertEquals(shield2Note, shield2NoteOnPbft); } - - /** - * constructor. - */ - @Test(enabled = true, description = "Query is shield trc20 note spend on solidity and pbft", groups = {"daily", "serial", "shield"}) + /** constructor. */ + @Test( + enabled = true, + description = "Query is shield trc20 note spend on solidity and pbft", + groups = {"daily", "serial", "shield"}) public void test05IsShieldTrc20NoteSpendOnSolidityAndPbft() throws Exception { - shield1Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo1.get(), - blockingStubFull); - shield2Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo2.get(), - blockingStubFull); - - Assert.assertEquals(getTrc20SpendResult(shieldAddressInfo1.get(), - shield1Note.getNoteTxs(0), blockingStubFull), true); - - Assert.assertEquals(getTrc20SpendResult(shieldAddressInfo1.get(), - shield1Note.getNoteTxs(0), blockingStubFull), - getTrc20SpendResult(shieldAddressInfo1.get(), - shield1Note.getNoteTxs(0), blockingStubFull, blockingStubSolidity)); - - Assert.assertTrue(getTrc20SpendResult(shieldAddressInfo1.get(), - shield1Note.getNoteTxs(0), blockingStubFull, blockingStubPbft)); - - boolean spend = getTrc20SpendResult(shieldAddressInfo1.get(),shield1Note.getNoteTxs(1), - blockingStubFull); - - Assert.assertEquals(spend, - getTrc20SpendResult(shieldAddressInfo1.get(), shield1Note.getNoteTxs(1), - blockingStubFull, blockingStubSolidity)); - Assert.assertEquals(spend, - getTrc20SpendResult(shieldAddressInfo1.get(), shield1Note.getNoteTxs(1), - blockingStubFull, blockingStubPbft)); - - spend = getTrc20SpendResult(shieldAddressInfo2.get(),shield2Note.getNoteTxs(0), - blockingStubFull); - Assert.assertEquals(spend, - getTrc20SpendResult(shieldAddressInfo2.get(), shield2Note.getNoteTxs(0), - blockingStubFull, blockingStubSolidity)); - Assert.assertEquals(spend, - getTrc20SpendResult(shieldAddressInfo2.get(), shield2Note.getNoteTxs(0), - blockingStubFull, blockingStubPbft)); - - spend = getTrc20SpendResult(shieldAddressInfo2.get(),shield2Note.getNoteTxs(1), - blockingStubFull); - Assert.assertEquals(spend, - getTrc20SpendResult(shieldAddressInfo2.get(), shield2Note.getNoteTxs(1), - blockingStubFull, blockingStubSolidity)); - Assert.assertEquals(spend, - getTrc20SpendResult(shieldAddressInfo2.get(), shield2Note.getNoteTxs(1), - blockingStubFull, blockingStubPbft)); - + shield1Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo1.get(), blockingStubFull); + shield2Note = scanShieldedTrc20NoteByIvk(shieldAddressInfo2.get(), blockingStubFull); + + Assert.assertEquals( + getTrc20SpendResult(shieldAddressInfo1.get(), shield1Note.getNoteTxs(0), blockingStubFull), + true); + + Assert.assertEquals( + getTrc20SpendResult(shieldAddressInfo1.get(), shield1Note.getNoteTxs(0), blockingStubFull), + getTrc20SpendResult( + shieldAddressInfo1.get(), + shield1Note.getNoteTxs(0), + blockingStubFull, + blockingStubSolidity)); + + Assert.assertTrue( + getTrc20SpendResult( + shieldAddressInfo1.get(), + shield1Note.getNoteTxs(0), + blockingStubFull, + blockingStubPbft)); + + boolean spend = + getTrc20SpendResult(shieldAddressInfo1.get(), shield1Note.getNoteTxs(1), blockingStubFull); + + Assert.assertEquals( + spend, + getTrc20SpendResult( + shieldAddressInfo1.get(), + shield1Note.getNoteTxs(1), + blockingStubFull, + blockingStubSolidity)); + Assert.assertEquals( + spend, + getTrc20SpendResult( + shieldAddressInfo1.get(), + shield1Note.getNoteTxs(1), + blockingStubFull, + blockingStubPbft)); + + spend = + getTrc20SpendResult(shieldAddressInfo2.get(), shield2Note.getNoteTxs(0), blockingStubFull); + Assert.assertEquals( + spend, + getTrc20SpendResult( + shieldAddressInfo2.get(), + shield2Note.getNoteTxs(0), + blockingStubFull, + blockingStubSolidity)); + Assert.assertEquals( + spend, + getTrc20SpendResult( + shieldAddressInfo2.get(), + shield2Note.getNoteTxs(0), + blockingStubFull, + blockingStubPbft)); + + spend = + getTrc20SpendResult(shieldAddressInfo2.get(), shield2Note.getNoteTxs(1), blockingStubFull); + Assert.assertEquals( + spend, + getTrc20SpendResult( + shieldAddressInfo2.get(), + shield2Note.getNoteTxs(1), + blockingStubFull, + blockingStubSolidity)); + Assert.assertEquals( + spend, + getTrc20SpendResult( + shieldAddressInfo2.get(), + shield2Note.getNoteTxs(1), + blockingStubFull, + blockingStubPbft)); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { if (channelFull != null) { @@ -521,5 +621,3 @@ public void shutdown() throws InterruptedException { } } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/fulltest/AttackSendcoin.java b/testcase/src/test/java/stest/tron/wallet/fulltest/AttackSendcoin.java index 80c942e1..bf6fda0d 100644 --- a/testcase/src/test/java/stest/tron/wallet/fulltest/AttackSendcoin.java +++ b/testcase/src/test/java/stest/tron/wallet/fulltest/AttackSendcoin.java @@ -43,27 +43,27 @@ public class AttackSendcoin extends TronBaseTest { private static long afterNormal3Balance; private static long afterNormal4Balance; private static long afterAttackBalance; - //testng001、testng002、testng003、testng004 + // testng001、testng002、testng003、testng004 // all keys below are just for test!!!!! - //Devaccount + // Devaccount private final String testKey001 = "8CB4480194192F30907E14B52498F594BD046E21D7C4D8FE866563A6760AC891"; - //Zion + // Zion private final String testKey002 = "FC8BF0238748587B9617EB6D15D47A66C0E07C1A1959033CF249C6532DC29FE6"; - //Sun + // Sun private final String testKey003 = "6815B367FDDE637E53E9ADC8E69424E07724333C9A2B973CFA469975E20753FC"; - //Normal1 + // Normal1 private final String normalKey001 = "36c0710378a34634e6baba0d3a79d7439a81183030147e7f4a0dd43bfed1a32f"; - //Normal2 + // Normal2 private final String normalKey002 = "a6bfbcf98bbe07770bf79bc6b2970bae0992771c1dcbf24cc063a3f033f17fbf"; - //Normal3 + // Normal3 private final String normalKey003 = "8273f6b26202526cbffb77569b830c1ba8a920040e77f6f26062a67315580ed7"; - //Normal4 + // Normal4 private final String normalKey004 = "271c824fcb55f04a9f86f768424a80edeb26ab79cf12aa56643b595f689c008a"; private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); @@ -78,16 +78,18 @@ public class AttackSendcoin extends TronBaseTest { private final Long sendNromal4Amount = 4L; private final Long attackAmount = 5L; - /** - * constructor. - */ - public static Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDuration, - String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public static Boolean freezeBalance( + byte[] addRess, + long freezeBalance, + long freezeDuration, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address = addRess; long frozenBalance = freezeBalance; long frozenDuration = freezeDuration; - //String priKey = testKey002; - ECKey temKey = null; + // String priKey = testKey002; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -95,17 +97,19 @@ public static Boolean freezeBalance(byte[] addRess, long freezeBalance, long fre ex.printStackTrace(); } final ECKey ecKey = temKey; - Protocol.Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI - .EmptyMessage.newBuilder().build()); - final Long beforeBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); - Long beforeFrozenBalance = 0L; - //Long beforeBandwidth = beforeFronzen.getBandwidth(); - - BalanceContract.FreezeBalanceContract.Builder builder = BalanceContract.FreezeBalanceContract - .newBuilder(); + Protocol.Block currentBlock = + blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); + final Long beforeBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); + Long beforeFrozenBalance = 0L; + // Long beforeBandwidth = beforeFronzen.getBandwidth(); + + BalanceContract.FreezeBalanceContract.Builder builder = + BalanceContract.FreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess).setFrozenBalance(frozenBalance) + builder + .setOwnerAddress(byteAddreess) + .setFrozenBalance(frozenBalance) .setFrozenDuration(frozenDuration); BalanceContract.FreezeBalanceContract contract = builder.build(); @@ -128,26 +132,22 @@ public static Boolean freezeBalance(byte[] addRess, long freezeBalance, long fre Long afterBlockNum = 0L; while (afterBlockNum < beforeBlockNum) { - Protocol.Block currentBlock1 = blockingStubFull.getNowBlock(GrpcAPI - .EmptyMessage.newBuilder().build()); + Protocol.Block currentBlock1 = + blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); afterBlockNum = currentBlock1.getBlockHeader().getRawData().getNumber(); } return true; } - - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { final Account fromInfo = PublicMethod.queryAccount(testKey002, blockingStubFull); - final Account attackInfo = PublicMethod.queryAccount(testKey001, blockingStubFull); - final Account normal1Info = PublicMethod.queryAccount(normalKey001, blockingStubFull); - final Account normal2Info = PublicMethod.queryAccount(normalKey002, blockingStubFull); - final Account normal3Info = PublicMethod.queryAccount(normalKey003, blockingStubFull); - final Account normal4Info = PublicMethod.queryAccount(normalKey004, blockingStubFull); + public void beforeClass() { + final Account fromInfo = PublicMethod.queryAccount(testKey002, blockingStubFull); + final Account attackInfo = PublicMethod.queryAccount(testKey001, blockingStubFull); + final Account normal1Info = PublicMethod.queryAccount(normalKey001, blockingStubFull); + final Account normal2Info = PublicMethod.queryAccount(normalKey002, blockingStubFull); + final Account normal3Info = PublicMethod.queryAccount(normalKey003, blockingStubFull); + final Account normal4Info = PublicMethod.queryAccount(normalKey004, blockingStubFull); beforeFromBalance = fromInfo.getBalance(); beforeNormal1Balance = normal1Info.getBalance(); beforeNormal2Balance = normal2Info.getBalance(); @@ -157,8 +157,12 @@ public static Boolean freezeBalance(byte[] addRess, long freezeBalance, long fre start = System.currentTimeMillis(); } - //@Test(enabled = true, groups = {"full"}) - @Test(enabled = false, threadPoolSize = 200, invocationCount = 200, groups = {"full"}) + // @Test(enabled = true, groups = {"full"}) + @Test( + enabled = false, + threadPoolSize = 200, + invocationCount = 200, + groups = {"full"}) public void freezeAndSendcoin() throws InterruptedException { Integer i = 0; @@ -169,12 +173,13 @@ public void freezeAndSendcoin() throws InterruptedException { while (i < 20) { randNum = i % 4; i++; - fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list") - .get(randNum); if (randNum == 3) { - PublicMethod.sendcoin(attackAddress, attackAmount, foundationAddress, testKey002, - blockingStubFull); - PublicMethod.sendcoin(attackAddress, attackAmount, foundationAddress, testKey002, - blockingStubFull); + fullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(randNum); + if (randNum == 3) { + PublicMethod.sendcoin( + attackAddress, attackAmount, foundationAddress, testKey002, blockingStubFull); + PublicMethod.sendcoin( + attackAddress, attackAmount, foundationAddress, testKey002, blockingStubFull); /* PublicMethod.sendcoin(attackAddress, attackAmount, foundationAddress, testKey002, blockingStubFull); PublicMethod.sendcoin(attackAddress, attackAmount, foundationAddress, testKey002, @@ -190,44 +195,41 @@ public void freezeAndSendcoin() throws InterruptedException { } if (randNum == 0) { - PublicMethod.sendcoin(normal1Address, sendNromal1Amount, foundationAddress, - testKey002, blockingStubFull); + PublicMethod.sendcoin( + normal1Address, sendNromal1Amount, foundationAddress, testKey002, blockingStubFull); continue; } if (randNum == 1) { - PublicMethod.sendcoin(normal2Address, sendNromal2Amount, foundationAddress, - testKey002, blockingStubFull); + PublicMethod.sendcoin( + normal2Address, sendNromal2Amount, foundationAddress, testKey002, blockingStubFull); continue; } if (randNum == 2) { - PublicMethod.sendcoin(normal3Address, sendNromal3Amount, foundationAddress, - testKey002, blockingStubFull); + PublicMethod.sendcoin( + normal3Address, sendNromal3Amount, foundationAddress, testKey002, blockingStubFull); continue; } if (randNum == 3) { - PublicMethod.sendcoin(normal4Address, sendNromal4Amount, foundationAddress, - testKey002, blockingStubFull); + PublicMethod.sendcoin( + normal4Address, sendNromal4Amount, foundationAddress, testKey002, blockingStubFull); continue; } } } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - //Print the duration. + // Print the duration. end = System.currentTimeMillis(); logger.info("The time is " + Long.toString(end - start)); - //Print 6 account balance information. + // Print 6 account balance information. final Account fromInfo = PublicMethod.queryAccount(testKey002, blockingStubFull); - final Account attackInfo = PublicMethod.queryAccount(testKey001, blockingStubFull); - final Account normal1Info = PublicMethod.queryAccount(normalKey001, blockingStubFull); - final Account normal2Info = PublicMethod.queryAccount(normalKey002, blockingStubFull); - final Account normal3Info = PublicMethod.queryAccount(normalKey003, blockingStubFull); - final Account normal4Info = PublicMethod.queryAccount(normalKey004, blockingStubFull); + final Account attackInfo = PublicMethod.queryAccount(testKey001, blockingStubFull); + final Account normal1Info = PublicMethod.queryAccount(normalKey001, blockingStubFull); + final Account normal2Info = PublicMethod.queryAccount(normalKey002, blockingStubFull); + final Account normal3Info = PublicMethod.queryAccount(normalKey003, blockingStubFull); + final Account normal4Info = PublicMethod.queryAccount(normalKey004, blockingStubFull); afterFromBalance = fromInfo.getBalance(); afterNormal1Balance = normal1Info.getBalance(); @@ -236,26 +238,33 @@ public void shutdown() throws InterruptedException { afterNormal4Balance = normal4Info.getBalance(); afterAttackBalance = attackInfo.getBalance(); - logger.info("attack transaction success num is " - + (afterAttackBalance - beforeAttackBalance) / attackAmount); - logger.info("Normal 1 transaction success num is " - + (afterNormal1Balance - beforeNormal1Balance) / sendNromal1Amount); - logger.info("Normal 2 transaction success num is " - + (afterNormal2Balance - beforeNormal2Balance) / sendNromal2Amount); - logger.info("Normal 3 transaction success num is " - + (afterNormal3Balance - beforeNormal3Balance) / sendNromal3Amount); - logger.info("Normal 4 transaction success num is " - + (afterNormal4Balance - beforeNormal4Balance) / sendNromal4Amount); - Long totalSuccessNum = (afterAttackBalance - beforeAttackBalance) / attackAmount - + (afterNormal1Balance - beforeNormal1Balance) / sendNromal1Amount - + (afterNormal3Balance - beforeNormal3Balance) / sendNromal3Amount - + (afterNormal4Balance - beforeNormal4Balance) / sendNromal4Amount - + (afterNormal2Balance - beforeNormal2Balance) / sendNromal2Amount; + logger.info( + "attack transaction success num is " + + (afterAttackBalance - beforeAttackBalance) / attackAmount); + logger.info( + "Normal 1 transaction success num is " + + (afterNormal1Balance - beforeNormal1Balance) / sendNromal1Amount); + logger.info( + "Normal 2 transaction success num is " + + (afterNormal2Balance - beforeNormal2Balance) / sendNromal2Amount); + logger.info( + "Normal 3 transaction success num is " + + (afterNormal3Balance - beforeNormal3Balance) / sendNromal3Amount); + logger.info( + "Normal 4 transaction success num is " + + (afterNormal4Balance - beforeNormal4Balance) / sendNromal4Amount); + Long totalSuccessNum = + (afterAttackBalance - beforeAttackBalance) / attackAmount + + (afterNormal1Balance - beforeNormal1Balance) / sendNromal1Amount + + (afterNormal3Balance - beforeNormal3Balance) / sendNromal3Amount + + (afterNormal4Balance - beforeNormal4Balance) / sendNromal4Amount + + (afterNormal2Balance - beforeNormal2Balance) / sendNromal2Amount; logger.info("Total success transaction is " + Long.toString(totalSuccessNum)); - Long normaltotalSuccessNum = (afterNormal1Balance - beforeNormal1Balance) / sendNromal1Amount - + (afterNormal3Balance - beforeNormal3Balance) / sendNromal3Amount - + (afterNormal4Balance - beforeNormal4Balance) / sendNromal4Amount - + (afterNormal2Balance - beforeNormal2Balance) / sendNromal2Amount; + Long normaltotalSuccessNum = + (afterNormal1Balance - beforeNormal1Balance) / sendNromal1Amount + + (afterNormal3Balance - beforeNormal3Balance) / sendNromal3Amount + + (afterNormal4Balance - beforeNormal4Balance) / sendNromal4Amount + + (afterNormal2Balance - beforeNormal2Balance) / sendNromal2Amount; logger.info("Total normal success transaction is " + Long.toString(normaltotalSuccessNum)); Integer blockTimes = 0; @@ -263,12 +272,15 @@ public void shutdown() throws InterruptedException { while (blockTimes < 5) { blockTimes++; - //Print the current block transaction num. + // Print the current block transaction num. Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - Long currentNum = currentBlock.getBlockHeader().getRawData().getNumber(); - logger.info("The block num " + Long.toString(currentNum) - + "total transaction is " + Long.toString(currentBlock.getTransactionsCount())); - //logger.info(Integer.toString(currentBlock.getTransactionsList() + Long currentNum = currentBlock.getBlockHeader().getRawData().getNumber(); + logger.info( + "The block num " + + Long.toString(currentNum) + + "total transaction is " + + Long.toString(currentBlock.getTransactionsCount())); + // logger.info(Integer.toString(currentBlock.getTransactionsList() // .get(0).getRawData().getContract(0).getTypeValue())); Integer normal1Num = 0; @@ -276,11 +288,17 @@ public void shutdown() throws InterruptedException { Integer normal3Num = 0; Integer normal4Num = 0; Integer attackNum = 0; - Long temp = 0L; + Long temp = 0L; for (Integer m = 0; m < currentBlock.getTransactionsCount(); m++) { try { - temp = currentBlock.getTransactions(m).getRawData().getContract(0).getParameter() - .unpack(TransferContract.class).getAmount(); + temp = + currentBlock + .getTransactions(m) + .getRawData() + .getContract(0) + .getParameter() + .unpack(TransferContract.class) + .getAmount(); } catch (InvalidProtocolBufferException e) { e.printStackTrace(); } @@ -300,16 +318,31 @@ public void shutdown() throws InterruptedException { attackNum++; } } - logger.info("Block num " + Long.toString(currentNum) + ", Attack num is " - + Integer.toString(attackNum)); - logger.info("Block num " + Long.toString(currentNum) + ", normal 1 num is " - + Integer.toString(normal1Num)); - logger.info("Block num " + Long.toString(currentNum) + ", normal 2 num is " - + Integer.toString(normal2Num)); - logger.info("Block num " + Long.toString(currentNum) + ", normal 3 num is " - + Integer.toString(normal3Num)); - logger.info("Block num " + Long.toString(currentNum) + ", normal 4 num is " - + Integer.toString(normal4Num)); + logger.info( + "Block num " + + Long.toString(currentNum) + + ", Attack num is " + + Integer.toString(attackNum)); + logger.info( + "Block num " + + Long.toString(currentNum) + + ", normal 1 num is " + + Integer.toString(normal1Num)); + logger.info( + "Block num " + + Long.toString(currentNum) + + ", normal 2 num is " + + Integer.toString(normal2Num)); + logger.info( + "Block num " + + Long.toString(currentNum) + + ", normal 3 num is " + + Integer.toString(normal3Num)); + logger.info( + "Block num " + + Long.toString(currentNum) + + ", normal 4 num is " + + Integer.toString(normal4Num)); blockTransNum = blockTransNum + currentBlock.getTransactionsCount(); try { Thread.sleep(3000); @@ -318,16 +351,12 @@ public void shutdown() throws InterruptedException { } } logger.info("Total block record num is " + Integer.toString(blockTransNum)); - - } - /** - * constructor. - */ + /** constructor. */ public boolean unFreezeBalance(byte[] addRess, String priKey) { byte[] address = addRess; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -335,10 +364,9 @@ public boolean unFreezeBalance(byte[] addRess, String priKey) { ex.printStackTrace(); } final ECKey ecKey = temKey; - // Account search = queryAccount(ecKey, blockingStubFull); + // Account search = queryAccount(ecKey, blockingStubFull); - UnfreezeBalanceContract.Builder builder = UnfreezeBalanceContract - .newBuilder(); + UnfreezeBalanceContract.Builder builder = UnfreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddreess); @@ -360,9 +388,7 @@ public boolean unFreezeBalance(byte[] addRess, String priKey) { } } - /** - * constructor. - */ + /** constructor. */ public boolean withdrawBalance(byte[] address, String priKey) { ECKey temKey = null; try { @@ -374,8 +400,7 @@ public boolean withdrawBalance(byte[] address, String priKey) { ECKey ecKey = temKey; BalanceContract.WithdrawBalanceContract.Builder builder = - BalanceContract.WithdrawBalanceContract - .newBuilder(); + BalanceContract.WithdrawBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddreess); BalanceContract.WithdrawBalanceContract contract = builder.build(); @@ -391,7 +416,6 @@ public boolean withdrawBalance(byte[] address, String priKey) { } logger.info("test withdraw" + priKey); return true; - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -402,7 +426,4 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { transaction = TransactionUtils.setTimestamp(transaction); return TransactionUtils.sign(transaction, ecKey); } - } - - diff --git a/testcase/src/test/java/stest/tron/wallet/fulltest/ContinueVote.java b/testcase/src/test/java/stest/tron/wallet/fulltest/ContinueVote.java index 07063ac8..59f5d8f6 100644 --- a/testcase/src/test/java/stest/tron/wallet/fulltest/ContinueVote.java +++ b/testcase/src/test/java/stest/tron/wallet/fulltest/ContinueVote.java @@ -31,51 +31,49 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; @Slf4j @MultiNode public class ContinueVote extends TronBaseTest { - //testng001、testng002、testng003、testng004 only for test, do not worry + // testng001、testng002、testng003、testng004 only for test, do not worry private final String testKey002 = "FC8BF0238748587B9617EB6D15D47A66C0E07C1A1959033CF249C6532DC29FE6"; - /* //testng001、testng002、testng003、testng004 private static final byte[] fromAddress = Base58 .decodeFromBase58Check("THph9K2M2nLvkianrMGswRhz5hjSA9fuH7");*/ private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); private ManagedChannel searchChannelFull = null; private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; - private String searchFullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String searchFullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass public void beforeClass() { WalletClient.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); - logger.info("Pre fix byte ===== " + WalletClient.getAddressPreFixByte()); searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode) - .usePlaintext() - .build(); + logger.info("Pre fix byte ===== " + WalletClient.getAddressPreFixByte()); + searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode).usePlaintext().build(); searchBlockingStubFull = WalletGrpc.newBlockingStub(searchChannelFull); } - @Test(enabled = false, threadPoolSize = 30, invocationCount = 30, groups = {"full"}) + @Test( + enabled = false, + threadPoolSize = 30, + invocationCount = 30, + groups = {"full"}) public void testVoteWitness() { ByteString addressBs = ByteString.copyFrom(fromAddress); Account request = Account.newBuilder().setAddress(addressBs).build(); @@ -84,7 +82,7 @@ public void testVoteWitness() { Integer randNum = rand.nextInt(30) + 1; Base58.encode58Check(fromAddress); logger.info(Base58.encode58Check(fromAddress)); - String voteStr = "TB4B1RMhoPeivkj4Hebm6tttHjRY9yQFes"; + String voteStr = "TB4B1RMhoPeivkj4Hebm6tttHjRY9yQFes"; HashMap smallVoteMap = new HashMap(); smallVoteMap.put(voteStr, "1"); Account fromInfo = PublicMethod.queryAccount(testKey002, blockingStubFull); @@ -102,31 +100,25 @@ public void testVoteWitness() { ret = voteWitness(smallVoteMap, fromAddress, testKey002); if (ret) { logger.info("This vote num is " + Integer.toString(randNum)); - logger.info("Now the fromaddress vote is " + Long.toString(fromInfo - .getVotes(0).getVoteCount())); + logger.info( + "Now the fromaddress vote is " + Long.toString(fromInfo.getVotes(0).getVoteCount())); logger.info(Integer.toString(i++)); } fromInfo = PublicMethod.queryAccount(testKey002, blockingStubFull); accountNetMessage = blockingStubFull.getAccountNet(request); logger.info("Now the from net used is " + Long.toString(accountNetMessage.getNetUsed())); - } - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { if (searchChannelFull != null) { + public void shutdown() throws InterruptedException { + if (searchChannelFull != null) { searchChannelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - /** - * constructor. - */ + /** constructor. */ public Boolean voteWitness(HashMap witness, byte[] addRess, String priKey) { ECKey temKey = null; @@ -138,21 +130,20 @@ public Boolean voteWitness(HashMap witness, byte[] addRess, Stri } ECKey ecKey = temKey; Account beforeVote = queryAccount(ecKey, blockingStubFull); - Long beforeVoteNum = 0L; + Long beforeVoteNum = 0L; if (beforeVote.getVotesCount() != 0) { beforeVoteNum = beforeVote.getVotes(0).getVoteCount(); } - WitnessContract.VoteWitnessContract.Builder builder = WitnessContract.VoteWitnessContract - .newBuilder(); + WitnessContract.VoteWitnessContract.Builder builder = + WitnessContract.VoteWitnessContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(addRess)); for (String addressBase58 : witness.keySet()) { String value = witness.get(addressBase58); - final long count = Long.parseLong(value); + final long count = Long.parseLong(value); WitnessContract.VoteWitnessContract.Vote.Builder voteBuilder = - WitnessContract.VoteWitnessContract.Vote - .newBuilder(); - byte[] address = WalletClient.decodeFromBase58Check(addressBase58); + WitnessContract.VoteWitnessContract.Vote.newBuilder(); + byte[] address = WalletClient.decodeFromBase58Check(addressBase58); logger.info("address ====== " + ByteArray.toHexString(address)); if (address == null) { continue; @@ -181,7 +172,7 @@ public Boolean voteWitness(HashMap witness, byte[] addRess, Stri e.printStackTrace(); } Account afterVote = queryAccount(ecKey, searchBlockingStubFull); - //Long afterVoteNum = afterVote.getVotes(0).getVoteCount(); + // Long afterVoteNum = afterVote.getVotes(0).getVoteCount(); for (String key : witness.keySet()) { for (int j = 0; j < afterVote.getVotesCount(); j++) { logger.info(Long.toString(Long.parseLong(witness.get(key)))); @@ -190,25 +181,22 @@ public Boolean voteWitness(HashMap witness, byte[] addRess, Stri logger.info("catch it"); logger.info(Long.toString(afterVote.getVotes(j).getVoteCount())); logger.info(Long.toString(Long.parseLong(witness.get(key)))); - //Assert.assertTrue(afterVote.getVotes(j).getVoteCount() == Long + // Assert.assertTrue(afterVote.getVotes(j).getVoteCount() == Long // .parseLong(witness.get(key))); } - } } return true; } - /** - * constructor. - */ - public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDuration, - String priKey) { + /** constructor. */ + public Boolean freezeBalance( + byte[] addRess, long freezeBalance, long freezeDuration, String priKey) { byte[] address = addRess; long frozenBalance = freezeBalance; long frozenDuration = freezeDuration; - //String priKey = testKey002; - ECKey temKey = null; + // String priKey = testKey002; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -217,19 +205,21 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura } ECKey ecKey = temKey; Account beforeFronzen = queryAccount(ecKey, blockingStubFull); - Long beforeFrozenBalance = 0L; - //Long beforeBandwidth = beforeFronzen.getBandwidth(); + Long beforeFrozenBalance = 0L; + // Long beforeBandwidth = beforeFronzen.getBandwidth(); if (beforeFronzen.getFrozenCount() != 0) { beforeFrozenBalance = beforeFronzen.getFrozen(0).getFrozenBalance(); - //beforeBandwidth = beforeFronzen.getBandwidth(); - //logger.info(Long.toString(beforeFronzen.getBandwidth())); + // beforeBandwidth = beforeFronzen.getBandwidth(); + // logger.info(Long.toString(beforeFronzen.getBandwidth())); logger.info(Long.toString(beforeFronzen.getFrozen(0).getFrozenBalance())); } FreezeBalanceContract.Builder builder = FreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess).setFrozenBalance(frozenBalance) + builder + .setOwnerAddress(byteAddreess) + .setFrozenBalance(frozenBalance) .setFrozenDuration(frozenDuration); FreezeBalanceContract contract = builder.build(); @@ -248,19 +238,20 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura } Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - Block searchCurrentBlock = searchBlockingStubFull.getNowBlock(GrpcAPI - .EmptyMessage.newBuilder().build()); + Block searchCurrentBlock = + searchBlockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); Integer wait = 0; while (searchCurrentBlock.getBlockHeader().getRawData().getNumber() - < currentBlock.getBlockHeader().getRawData().getNumber() + 1 && wait < 30) { + < currentBlock.getBlockHeader().getRawData().getNumber() + 1 + && wait < 30) { try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } logger.info("Another fullnode didn't syn the first fullnode data"); - searchCurrentBlock = searchBlockingStubFull.getNowBlock(GrpcAPI - .EmptyMessage.newBuilder().build()); + searchCurrentBlock = + searchBlockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); wait++; if (wait == 9) { logger.info("Didn't syn,skip to next case."); @@ -268,34 +259,34 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura } Account afterFronzen = queryAccount(ecKey, searchBlockingStubFull); - Long afterFrozenBalance = afterFronzen.getFrozen(0).getFrozenBalance(); - //Long afterBandwidth = afterFronzen.getBandwidth(); - //logger.info(Long.toString(afterFronzen.getBandwidth())); - //logger.info(Long.toString(afterFronzen.getFrozen(0).getFrozenBalance())); - //logger.info(Integer.toString(search.getFrozenCount())); + Long afterFrozenBalance = afterFronzen.getFrozen(0).getFrozenBalance(); + // Long afterBandwidth = afterFronzen.getBandwidth(); + // logger.info(Long.toString(afterFronzen.getBandwidth())); + // logger.info(Long.toString(afterFronzen.getFrozen(0).getFrozenBalance())); + // logger.info(Integer.toString(search.getFrozenCount())); logger.info( - "afterfrozenbalance =" + Long.toString(afterFrozenBalance) + "beforefrozenbalance = " - + beforeFrozenBalance + "freezebalance = " + Long.toString(freezeBalance)); - //logger.info("afterbandwidth = " + Long.toString(afterBandwidth) + " beforebandwidth = + "afterfrozenbalance =" + + Long.toString(afterFrozenBalance) + + "beforefrozenbalance = " + + beforeFrozenBalance + + "freezebalance = " + + Long.toString(freezeBalance)); + // logger.info("afterbandwidth = " + Long.toString(afterBandwidth) + " beforebandwidth = // " + Long.toString(beforeBandwidth)); - //if ((afterFrozenBalance - beforeFrozenBalance != freezeBalance) || + // if ((afterFrozenBalance - beforeFrozenBalance != freezeBalance) || // (freezeBalance * frozen_duration -(afterBandwidth - beforeBandwidth) !=0)){ // logger.info("After 20 second, two node still not synchronous"); - // } + // } Assert.assertTrue(afterFrozenBalance - beforeFrozenBalance == freezeBalance); - //Assert.assertTrue(freezeBalance * frozen_duration - (afterBandwidth - + // Assert.assertTrue(freezeBalance * frozen_duration - (afterBandwidth - // beforeBandwidth) <= 1000000); return true; - - } - /** - * constructor. - */ + /** constructor. */ public boolean unFreezeBalance(byte[] addRess, String priKey) { byte[] address = addRess; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -305,8 +296,7 @@ public boolean unFreezeBalance(byte[] addRess, String priKey) { ECKey ecKey = temKey; Account search = queryAccount(ecKey, blockingStubFull); - UnfreezeBalanceContract.Builder builder = UnfreezeBalanceContract - .newBuilder(); + UnfreezeBalanceContract.Builder builder = UnfreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddreess); @@ -328,19 +318,17 @@ public boolean unFreezeBalance(byte[] addRess, String priKey) { } } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -350,23 +338,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -378,5 +361,3 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/fulltest/CreateAddressAndKey.java b/testcase/src/test/java/stest/tron/wallet/fulltest/CreateAddressAndKey.java index e4c74d2c..5817b23b 100644 --- a/testcase/src/test/java/stest/tron/wallet/fulltest/CreateAddressAndKey.java +++ b/testcase/src/test/java/stest/tron/wallet/fulltest/CreateAddressAndKey.java @@ -29,7 +29,7 @@ public class CreateAddressAndKey { private static String path = "/Users/wangzihe/Documents/"; private static String filename = "/Users/wangzihe/Sites/postmanUsedKeyandAddress"; private static String filenameTemp; - //testng001、testng002、testng003、testng004 only for test + // testng001、testng002、testng003、testng004 only for test private final String testKey002 = "FC8BF0238748587B9617EB6D15D47A66C0E07C1A1959033CF249C6532DC29FE6"; private final String testKey003 = @@ -37,37 +37,31 @@ public class CreateAddressAndKey { private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); - /** - * constructor. - */ + /** constructor. */ public static boolean createFile(String fileName, String filecontent) { Boolean bool = false; - filenameTemp = fileName;//文件路径+名称+文件类型 + filenameTemp = fileName; // 文件路径+名称+文件类型 File file = new File(filenameTemp); try { - //如果文件不存在,则创建新的文件 + // 如果文件不存在,则创建新的文件 if (!file.exists()) { file.createNewFile(); bool = true; System.out.println("success create file,the file is " + filenameTemp); - //创建文件成功后,写入内容到文件里 + // 创建文件成功后,写入内容到文件里 writeFileContent(filenameTemp, filecontent); } else { clearInfoForFile(filenameTemp); writeFileContent(filenameTemp, filecontent); - } } catch (Exception e) { e.printStackTrace(); - } return bool; } - /** - * constructor. - */ + /** constructor. */ public static void clearInfoForFile(String fileName) { File file = new File(fileName); try { @@ -83,9 +77,7 @@ public static void clearInfoForFile(String fileName) { } } - /** - * constructor. - */ + /** constructor. */ public static boolean writeFileContent(String filepath, String newstr) throws IOException { Boolean bool = false; String filein = newstr + "\r\n"; @@ -137,10 +129,7 @@ public static boolean writeFileContent(String filepath, String newstr) throws IO return bool; } - /** - * constructor. - */ - + /** constructor. */ public static boolean delFile(String fileName) { Boolean bool = false; filenameTemp = path + fileName + ".txt"; @@ -156,17 +145,13 @@ public static boolean delFile(String fileName) { return bool; } - - - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = false) - public void beforeClass() { + public void beforeClass() {} - } - - @Test(enabled = false, groups = {"full"}) + @Test( + enabled = false, + groups = {"full"}) public void createAddressesAndKeys() { Integer i = 0; String accountIndex; @@ -186,18 +171,19 @@ public void createAddressesAndKeys() { JsonObject userBaseObj2 = new JsonObject(); userBaseObj2.addProperty("address", addressString); userBaseObj2.addProperty("key", keyString); - //userBaseObj2.addProperty("address",ByteArray.toStr(Base64.encode(address))); - //userBaseObj2.addProperty("key", ByteArray.toStr(Base64.encode(key))); + // userBaseObj2.addProperty("address",ByteArray.toStr(Base64.encode(address))); + // userBaseObj2.addProperty("key", ByteArray.toStr(Base64.encode(key))); jsonarray.add(userBaseObj2); } Gson gson = new Gson(); String jsonMap = gson.toJson(addressAndKey); - //createFile(filename,jsonobject.toString()); + // createFile(filename,jsonobject.toString()); createFile(filename, jsonarray.toString()); - } - @Test(enabled = true, groups = {"full"}) + @Test( + enabled = true, + groups = {"full"}) public void create() { Integer i = 0; String accountIndex; @@ -219,13 +205,10 @@ public void create() { } Gson gson = new Gson(); String jsonMap = gson.toJson(addressAndKey); - //createFile(filename,jsonobject.toString()); + // createFile(filename,jsonobject.toString()); createFile(filename, jsonarray.toString()); - } @AfterClass(enabled = false) - public void shutdown() throws InterruptedException { - } + public void shutdown() throws InterruptedException {} } - diff --git a/testcase/src/test/java/stest/tron/wallet/fulltest/CreateAsset.java b/testcase/src/test/java/stest/tron/wallet/fulltest/CreateAsset.java index a8614370..b7c56a1a 100644 --- a/testcase/src/test/java/stest/tron/wallet/fulltest/CreateAsset.java +++ b/testcase/src/test/java/stest/tron/wallet/fulltest/CreateAsset.java @@ -10,8 +10,8 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class CreateAsset extends TronBaseTest { @@ -29,7 +29,7 @@ public class CreateAsset extends TronBaseTest { private static final long sendAmount = 1025000000L; private static final long netCostMeasure = 200L; private static String name = "c_" + Long.toString(now); - //testng001、testng002、testng003、testng004 only for test, do not worry + // testng001、testng002、testng003、testng004 only for test, do not worry private final String testKey002 = "FC8BF0238748587B9617EB6D15D47A66C0E07C1A1959033CF249C6532DC29FE6"; private final String testKey003 = @@ -40,7 +40,7 @@ public class CreateAsset extends TronBaseTest { Long publicFreeAssetNetLimit = 30000L; String description = "f"; String url = "h"; - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] asset016Address = ecKey1.getAddress(); String testKeyForAssetIssue016 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -48,30 +48,32 @@ public class CreateAsset extends TronBaseTest { byte[] transferAssetAddress = ecKey2.getAddress(); String transferAssetCreateKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = false) public void beforeClass() { logger.info(testKeyForAssetIssue016); - logger.info(transferAssetCreateKey); } + logger.info(transferAssetCreateKey); + } - //@Test(enabled = false, groups = {"full"}) - @Test(enabled = false, threadPoolSize = 20, invocationCount = 20, groups = {"full"}) + // @Test(enabled = false, groups = {"full"}) + @Test( + enabled = false, + threadPoolSize = 20, + invocationCount = 20, + groups = {"full"}) public void createAssetissue() throws InterruptedException { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] asset016Address = ecKey1.getAddress(); - String testKeyForAssetIssue016 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + byte[] asset016Address = ecKey1.getAddress(); + String testKeyForAssetIssue016 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); Account fromAccountInfo = PublicMethod.queryAccount(testKey002, blockingStubFull); - //Assert.assertTrue(PublicMethod.freezeBalance(foundationAddress,100000000, 3, testKey002, + // Assert.assertTrue(PublicMethod.freezeBalance(foundationAddress,100000000, 3, testKey002, // blockingStubFull)); Integer i = 0; - //GrpcAPI.AssetIssueList assetIssueList = blockingStubFull + // GrpcAPI.AssetIssueList assetIssueList = blockingStubFull // .getAssetIssueList(GrpcAPI.EmptyMessage.newBuilder().build()); - //logger.info(Integer.toString(assetIssueList.getAssetIssueCount())); + // logger.info(Integer.toString(assetIssueList.getAssetIssueCount())); Boolean ret = false; Boolean transRet = false; Boolean updateRet = false; @@ -80,42 +82,70 @@ public void createAssetissue() throws InterruptedException { Integer randNum; while (fromAccountInfo.getBalance() > 1025000000) { - randNum = rand.nextInt(4); fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list") - .get(randNum); PublicMethod - .sendcoin(asset016Address, sendAmount, foundationAddress, testKey002, blockingStubFull); - Long start = System.currentTimeMillis() + 2000; - Long end = System.currentTimeMillis() + 1000000000; + randNum = rand.nextInt(4); + fullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(randNum); + PublicMethod.sendcoin( + asset016Address, sendAmount, foundationAddress, testKey002, blockingStubFull); + Long start = System.currentTimeMillis() + 2000; + Long end = System.currentTimeMillis() + 1000000000; name = "c_" + Long.toString(System.currentTimeMillis()); totalSupply = now; - ret = PublicMethod - .createAssetIssue(asset016Address, name, totalSupply, 1, 1, start, end, 1, description, - url, freeAssetNetLimit, publicFreeAssetNetLimit, 1L, 1L, testKeyForAssetIssue016, + ret = + PublicMethod.createAssetIssue( + asset016Address, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + freeAssetNetLimit, + publicFreeAssetNetLimit, + 1L, + 1L, + testKeyForAssetIssue016, blockingStubFull); if (ret) { - updateRet = PublicMethod - .updateAsset(asset016Address, tooLongDescription.getBytes(), tooLongUrl.getBytes(), - 4000L, 4000L, - testKeyForAssetIssue016, blockingStubFull); + updateRet = + PublicMethod.updateAsset( + asset016Address, + tooLongDescription.getBytes(), + tooLongUrl.getBytes(), + 4000L, + 4000L, + testKeyForAssetIssue016, + blockingStubFull); if (updateRet) { logger.info("update succesfully"); } logger.info(Integer.toString(i++)); - //assetIssueList = blockingStubFull + // assetIssueList = blockingStubFull // .getAssetIssueList(GrpcAPI.EmptyMessage.newBuilder().build()); - //logger.info("assetissue num is " + Integer.toString(assetIssueList.getAssetIssueCount())); + // logger.info("assetissue num is " + + // Integer.toString(assetIssueList.getAssetIssueCount())); try { randNum = rand.nextInt(10000) + 3000; Thread.sleep(randNum); } catch (InterruptedException e) { e.printStackTrace(); } - transRet = PublicMethod.transferAsset(toAddress, name.getBytes(), - 1L, asset016Address, testKeyForAssetIssue016, blockingStubFull); - participateRet = PublicMethod - .participateAssetIssue(asset016Address, name.getBytes(), 1L, toAddress, testKey003, + transRet = + PublicMethod.transferAsset( + toAddress, + name.getBytes(), + 1L, + asset016Address, + testKeyForAssetIssue016, blockingStubFull); + participateRet = + PublicMethod.participateAssetIssue( + asset016Address, name.getBytes(), 1L, toAddress, testKey003, blockingStubFull); if (participateRet) { logger.info("participate success"); } @@ -123,7 +153,6 @@ public void createAssetissue() throws InterruptedException { if (transRet) { logger.info("transfer success"); } - } ecKey1 = new ECKey(Utils.getRandom()); asset016Address = ecKey1.getAddress(); @@ -132,27 +161,20 @@ public void createAssetissue() throws InterruptedException { ret = false; updateRet = false; participateRet = false; - if (channelFull != null) { try { - //randNum = rand.nextInt(10000) + 3000; + if (channelFull != null) { + try { + // randNum = rand.nextInt(10000) + 3000; Thread.sleep(6000); } catch (InterruptedException e) { e.printStackTrace(); } - } - - } } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = false) public void shutdown() throws InterruptedException { /* if (channelFull != null) { }*/ } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/fulltest/FreezeAndSendcoin.java b/testcase/src/test/java/stest/tron/wallet/fulltest/FreezeAndSendcoin.java index e0068ff7..a93765a5 100644 --- a/testcase/src/test/java/stest/tron/wallet/fulltest/FreezeAndSendcoin.java +++ b/testcase/src/test/java/stest/tron/wallet/fulltest/FreezeAndSendcoin.java @@ -21,21 +21,21 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class FreezeAndSendcoin extends TronBaseTest { private static final long now = System.currentTimeMillis(); - //testng001、testng002、testng003、testng004 only for test, do not worry + // testng001、testng002、testng003、testng004 only for test, do not worry private final String testKey002 = "FC8BF0238748587B9617EB6D15D47A66C0E07C1A1959033CF249C6532DC29FE6"; private final String testKey003 = "6815B367FDDE637E53E9ADC8E69424E07724333C9A2B973CFA469975E20753FC"; private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); private final Long sendAmount = 10000000L; - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] freezeAddress = ecKey1.getAddress(); String testKeyForFreeze = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -43,16 +43,18 @@ public class FreezeAndSendcoin extends TronBaseTest { byte[] transferAssetAddress = ecKey2.getAddress(); String transferAssetCreateKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ - public static Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDuration, - String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public static Boolean freezeBalance( + byte[] addRess, + long freezeBalance, + long freezeDuration, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address = addRess; long frozenBalance = freezeBalance; long frozenDuration = freezeDuration; - //String priKey = testKey002; - ECKey temKey = null; + // String priKey = testKey002; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -60,17 +62,19 @@ public static Boolean freezeBalance(byte[] addRess, long freezeBalance, long fre ex.printStackTrace(); } final ECKey ecKey = temKey; - Protocol.Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI - .EmptyMessage.newBuilder().build()); - final Long beforeBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); - Long beforeFrozenBalance = 0L; - //Long beforeBandwidth = beforeFronzen.getBandwidth(); - - BalanceContract.FreezeBalanceContract.Builder builder = BalanceContract.FreezeBalanceContract - .newBuilder(); + Protocol.Block currentBlock = + blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); + final Long beforeBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); + Long beforeFrozenBalance = 0L; + // Long beforeBandwidth = beforeFronzen.getBandwidth(); + + BalanceContract.FreezeBalanceContract.Builder builder = + BalanceContract.FreezeBalanceContract.newBuilder(); ByteString byteAddress = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddress).setFrozenBalance(frozenBalance) + builder + .setOwnerAddress(byteAddress) + .setFrozenBalance(frozenBalance) .setFrozenDuration(frozenDuration); BalanceContract.FreezeBalanceContract contract = builder.build(); @@ -93,21 +97,16 @@ public static Boolean freezeBalance(byte[] addRess, long freezeBalance, long fre Long afterBlockNum = 0L; while (afterBlockNum < beforeBlockNum) { - Protocol.Block currentBlock1 = blockingStubFull.getNowBlock(GrpcAPI - .EmptyMessage.newBuilder().build()); + Protocol.Block currentBlock1 = + blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); afterBlockNum = currentBlock1.getBlockHeader().getRawData().getNumber(); } return true; } - - - //@Test(enabled = false, groups = {"full"}) - - /** - * constructor. - */ + // @Test(enabled = false, groups = {"full"}) + /** constructor. */ @BeforeClass(enabled = false) public void beforeClass() { /* Random rand = new Random(); @@ -121,14 +120,19 @@ public void beforeClass() { }*/ logger.info(testKeyForFreeze); - logger.info(transferAssetCreateKey); } + logger.info(transferAssetCreateKey); + } - @Test(enabled = false, threadPoolSize = 500, invocationCount = 1000, groups = {"full"}) + @Test( + enabled = false, + threadPoolSize = 500, + invocationCount = 1000, + groups = {"full"}) public void freezeAndSendcoin() throws InterruptedException { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] freezeAddress = ecKey1.getAddress(); - String testKeyForFreeze = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + byte[] freezeAddress = ecKey1.getAddress(); + String testKeyForFreeze = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); Account toAccountInfo = PublicMethod.queryAccount(testKey003, blockingStubFull); Account freezeAccountInfo = PublicMethod.queryAccount(testKeyForFreeze, blockingStubFull); @@ -141,10 +145,11 @@ public void freezeAndSendcoin() throws InterruptedException { Integer randNum = rand.nextInt(30) + 1; while (toAccountInfo.getBalance() > 10000009L) { - randNum = rand.nextInt(3); fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list") - .get(randNum); freezeBalance(freezeAddress, 3000000L, 3L, testKeyForFreeze, blockingStubFull); - PublicMethod - .sendcoin(freezeAddress, sendAmount, toAddress, testKey003, blockingStubFull); + randNum = rand.nextInt(3); + fullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(randNum); + freezeBalance(freezeAddress, 3000000L, 3L, testKeyForFreeze, blockingStubFull); + PublicMethod.sendcoin(freezeAddress, sendAmount, toAddress, testKey003, blockingStubFull); ret = freezeBalance(freezeAddress, 1000000L, 3L, testKeyForFreeze, blockingStubFull); freezeBalance(freezeAddress, 1000000L, 3L, testKeyForFreeze, blockingStubFull); @@ -152,16 +157,15 @@ public void freezeAndSendcoin() throws InterruptedException { if (ret) { logger.info("New account freeze success " + Integer.toString(i)); - sendRet = PublicMethod.sendcoin(toAddress, 6000000L, freezeAddress, - testKeyForFreeze, blockingStubFull); + sendRet = + PublicMethod.sendcoin( + toAddress, 6000000L, freezeAddress, testKeyForFreeze, blockingStubFull); if (sendRet) { logger.info("This account transfer coin back. " + Integer.toString(i)); freezeAccountInfo = PublicMethod.queryAccount(testKeyForFreeze, blockingStubFull); - logger.info("This account now has balance is " + Long - .toString(freezeAccountInfo.getBalance())); - + logger.info( + "This account now has balance is " + Long.toString(freezeAccountInfo.getBalance())); } - } unFreezeBalance(freezeAddress, testKeyForFreeze); @@ -172,8 +176,8 @@ public void freezeAndSendcoin() throws InterruptedException { testKeyForFreeze = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); toAccountInfo = PublicMethod.queryAccount(testKey003, blockingStubFull); logger.info("Now the toaddress balance is " + Long.toString(toAccountInfo.getBalance())); - NumberMessage beforeGetTotalTransaction = blockingStubFull - .totalTransaction(GrpcAPI.EmptyMessage.newBuilder().build()); + NumberMessage beforeGetTotalTransaction = + blockingStubFull.totalTransaction(GrpcAPI.EmptyMessage.newBuilder().build()); logger.info("Now total transaction is " + Long.toString(beforeGetTotalTransaction.getNum())); ret = false; sendRet = false; @@ -191,19 +195,14 @@ public void freezeAndSendcoin() throws InterruptedException { } } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = false) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ + /** constructor. */ public boolean unFreezeBalance(byte[] addRess, String priKey) { byte[] address = addRess; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -211,10 +210,9 @@ public boolean unFreezeBalance(byte[] addRess, String priKey) { ex.printStackTrace(); } final ECKey ecKey = temKey; - // Account search = queryAccount(ecKey, blockingStubFull); + // Account search = queryAccount(ecKey, blockingStubFull); - UnfreezeBalanceContract.Builder builder = UnfreezeBalanceContract - .newBuilder(); + UnfreezeBalanceContract.Builder builder = UnfreezeBalanceContract.newBuilder(); ByteString byteAddress = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddress); @@ -236,9 +234,7 @@ public boolean unFreezeBalance(byte[] addRess, String priKey) { } } - /** - * constructor. - */ + /** constructor. */ public boolean withdrawBalance(byte[] address, String priKey) { ECKey temKey = null; try { @@ -250,8 +246,7 @@ public boolean withdrawBalance(byte[] address, String priKey) { ECKey ecKey = temKey; BalanceContract.WithdrawBalanceContract.Builder builder = - BalanceContract.WithdrawBalanceContract - .newBuilder(); + BalanceContract.WithdrawBalanceContract.newBuilder(); ByteString byteAddress = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddress); BalanceContract.WithdrawBalanceContract contract = builder.build(); @@ -267,7 +262,6 @@ public boolean withdrawBalance(byte[] address, String priKey) { } logger.info("test withdraw" + priKey); return true; - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -278,7 +272,4 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { transaction = TransactionUtils.setTimestamp(transaction); return TransactionUtils.sign(transaction, ecKey); } - } - - diff --git a/testcase/src/test/java/stest/tron/wallet/fulltest/Fuzzytest.java b/testcase/src/test/java/stest/tron/wallet/fulltest/Fuzzytest.java index ec26e659..9b035a70 100644 --- a/testcase/src/test/java/stest/tron/wallet/fulltest/Fuzzytest.java +++ b/testcase/src/test/java/stest/tron/wallet/fulltest/Fuzzytest.java @@ -1,7 +1,6 @@ package stest.tron.wallet.fulltest; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.math.BigInteger; import lombok.extern.slf4j.Slf4j; @@ -21,8 +20,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class Fuzzytest extends TronBaseTest { @@ -34,7 +33,7 @@ public class Fuzzytest extends TronBaseTest { private static long now = System.currentTimeMillis(); private static String name = "AssetIssue016_" + Long.toString(now); private static long totalSupply = now; - //testng001、testng002、testng003、testng004 all keys are for test + // testng001、testng002、testng003、testng004 all keys are for test private final String testKey002 = "FC8BF0238748587B9617EB6D15D47A66C0E07C1A1959033CF249C6532DC29FE6"; private final String testKey003 = @@ -44,21 +43,31 @@ public class Fuzzytest extends TronBaseTest { Long publicFreeAssetNetLimit = 30000L; String description = "for case assetissue016"; String url = "https://stest.assetissue016.url"; - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] asset017Address = ecKey1.getAddress(); String testKeyForAssetIssue017 = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private WalletExtensionGrpc.WalletExtensionBlockingStub blockingStubExtension = null; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ - public static Boolean createAssetIssue(byte[] address, String name, Long totalSupply, - Integer trxNum, Integer icoNum, Long startTime, Long endTime, Integer voteScore, - String description, String url, Long freeAssetNetLimit, Long publicFreeAssetNetLimit, - Long fronzenAmount, Long frozenDay, String priKey, + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + + /** constructor. */ + public static Boolean createAssetIssue( + byte[] address, + String name, + Long totalSupply, + Integer trxNum, + Integer icoNum, + Long startTime, + Long endTime, + Integer voteScore, + String description, + String url, + Long freeAssetNetLimit, + Long publicFreeAssetNetLimit, + Long fronzenAmount, + Long frozenDay, + String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { @@ -68,11 +77,10 @@ public static Boolean createAssetIssue(byte[] address, String name, Long totalSu ex.printStackTrace(); } ECKey ecKey = temKey; - //Protocol.Account search = queryAccount(ecKey, blockingStubFull); + // Protocol.Account search = queryAccount(ecKey, blockingStubFull); try { AssetIssueContractOuterClass.AssetIssueContract.Builder builder = - AssetIssueContractOuterClass.AssetIssueContract - .newBuilder(); + AssetIssueContractOuterClass.AssetIssueContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(address)); builder.setName(ByteString.copyFrom(name.getBytes())); builder.setTotalSupply(totalSupply); @@ -111,50 +119,59 @@ public static Boolean createAssetIssue(byte[] address, String name, Long totalSu } } - /** - * constructor. - */ - public static Protocol.Transaction signTransaction(ECKey ecKey, - Protocol.Transaction transaction) { + /** constructor. */ + public static Protocol.Transaction signTransaction( + ECKey ecKey, Protocol.Transaction transaction) { if (ecKey == null || ecKey.getPrivKey() == null) { - //logger.warn("Warning: Can't sign,there is no private key !!"); + // logger.warn("Warning: Can't sign,there is no private key !!"); return null; } transaction = TransactionUtils.setTimestamp(transaction); return TransactionUtils.sign(transaction, ecKey); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = false) - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); blockingStubExtension = WalletExtensionGrpc.newBlockingStub(channelSolidity); - AssetIssueList assetIssueList = blockingStubFull - .getAssetIssueList(GrpcAPI.EmptyMessage.newBuilder().build()); - Assert.assertTrue(PublicMethod.freezeBalance(foundationAddress, 10000000, 3, testKey002, - blockingStubFull)); + AssetIssueList assetIssueList = + blockingStubFull.getAssetIssueList(GrpcAPI.EmptyMessage.newBuilder().build()); + Assert.assertTrue( + PublicMethod.freezeBalance(foundationAddress, 10000000, 3, testKey002, blockingStubFull)); while (assetIssueList.getAssetIssueCount() <= 1) { - //Sendcoin to this account - Assert.assertTrue(PublicMethod - .sendcoin(asset017Address, sendAmount, foundationAddress, testKey002, blockingStubFull)); + // Sendcoin to this account + Assert.assertTrue( + PublicMethod.sendcoin( + asset017Address, sendAmount, foundationAddress, testKey002, blockingStubFull)); start = System.currentTimeMillis() + 2000; end = System.currentTimeMillis() + 1000000000; now = System.currentTimeMillis(); name = "AssetIssue017_" + Long.toString(now); totalSupply = now; - Assert.assertTrue(createAssetIssue(asset017Address, name, totalSupply, 1, 1, - start, end, 1, description, url, freeAssetNetLimit, publicFreeAssetNetLimit, 1L, - 1L, testKeyForAssetIssue017, blockingStubFull)); - - assetIssueList = blockingStubFull - .getAssetIssueList(GrpcAPI.EmptyMessage.newBuilder().build()); + Assert.assertTrue( + createAssetIssue( + asset017Address, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + freeAssetNetLimit, + publicFreeAssetNetLimit, + 1L, + 1L, + testKeyForAssetIssue017, + blockingStubFull)); + + assetIssueList = + blockingStubFull.getAssetIssueList(GrpcAPI.EmptyMessage.newBuilder().build()); ecKey1 = new ECKey(Utils.getRandom()); asset017Address = ecKey1.getAddress(); @@ -162,24 +179,23 @@ public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget } } - @Test(enabled = false, threadPoolSize = 5, invocationCount = 5, groups = {"full"}) + @Test( + enabled = false, + threadPoolSize = 5, + invocationCount = 5, + groups = {"full"}) public void tooManyChannelFull() { Integer i = 0; - while (i++ < 20000) { GrpcAPI.NodeList nodeList = blockingStubFull - .listNodes(GrpcAPI.EmptyMessage.newBuilder().build()); + while (i++ < 20000) { + GrpcAPI.NodeList nodeList = + blockingStubFull.listNodes(GrpcAPI.EmptyMessage.newBuilder().build()); if (i % 100 == 0) { logger.info(Integer.toString(i)); } - } - - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = false) public void shutdown() throws InterruptedException { /* if (channelSolidity != null) { @@ -187,5 +203,3 @@ public void shutdown() throws InterruptedException { }*/ } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/fulltest/ParticipateAssetIssue.java b/testcase/src/test/java/stest/tron/wallet/fulltest/ParticipateAssetIssue.java index 5e7d042b..e7449c61 100644 --- a/testcase/src/test/java/stest/tron/wallet/fulltest/ParticipateAssetIssue.java +++ b/testcase/src/test/java/stest/tron/wallet/fulltest/ParticipateAssetIssue.java @@ -20,8 +20,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class ParticipateAssetIssue extends TronBaseTest { @@ -34,7 +34,7 @@ public class ParticipateAssetIssue extends TronBaseTest { private static long afterParticipateAssetIssueBalance; private static long start1; private static long end1; - //testng001、testng002、testng003、testng004 only for test + // testng001、testng002、testng003、testng004 only for test private final String testKey002 = "FC8BF0238748587B9617EB6D15D47A66C0E07C1A1959033CF249C6532DC29FE6"; private final String testKey003 = @@ -45,7 +45,7 @@ public class ParticipateAssetIssue extends TronBaseTest { Long publicFreeAssetNetLimit = 300000000L; String description = "f"; String url = "h"; - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] createAddress = ecKey1.getAddress(); String testKeyForCreate = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -53,11 +53,14 @@ public class ParticipateAssetIssue extends TronBaseTest { byte[] participateAssetAddress = ecKey2.getAddress(); String testKeyForParticipate = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ - public static boolean participateAssetIssue(byte[] to, byte[] assertName, long amount, - byte[] from, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public static boolean participateAssetIssue( + byte[] to, + byte[] assertName, + long amount, + byte[] from, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -68,8 +71,7 @@ public static boolean participateAssetIssue(byte[] to, byte[] assertName, long a final ECKey ecKey = temKey; AssetIssueContractOuterClass.ParticipateAssetIssueContract.Builder builder = - AssetIssueContractOuterClass.ParticipateAssetIssueContract - .newBuilder(); + AssetIssueContractOuterClass.ParticipateAssetIssueContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); ByteString bsName = ByteString.copyFrom(assertName); ByteString bsOwner = ByteString.copyFrom(from); @@ -88,24 +90,25 @@ public static boolean participateAssetIssue(byte[] to, byte[] assertName, long a } } - /** - * constructor. - */ - public static Protocol.Transaction signTransaction(ECKey ecKey, - Protocol.Transaction transaction) { + /** constructor. */ + public static Protocol.Transaction signTransaction( + ECKey ecKey, Protocol.Transaction transaction) { if (ecKey == null || ecKey.getPrivKey() == null) { - //logger.warn("Warning: Can't sign,there is no private key !!"); + // logger.warn("Warning: Can't sign,there is no private key !!"); return null; } transaction = TransactionUtils.setTimestamp(transaction); return TransactionUtils.sign(transaction, ecKey); } - /** - * constructor. - */ - public static boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] address, - String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public static boolean transferAsset( + byte[] to, + byte[] assertName, + long amount, + byte[] address, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -116,8 +119,7 @@ public static boolean transferAsset(byte[] to, byte[] assertName, long amount, b final ECKey ecKey = temKey; AssetIssueContractOuterClass.TransferAssetContract.Builder builder = - AssetIssueContractOuterClass.TransferAssetContract - .newBuilder(); + AssetIssueContractOuterClass.TransferAssetContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); ByteString bsName = ByteString.copyFrom(assertName); ByteString bsOwner = ByteString.copyFrom(address); @@ -130,57 +132,71 @@ public static boolean transferAsset(byte[] to, byte[] assertName, long amount, b Protocol.Transaction transaction = blockingStubFull.transferAsset(contract); if (transaction == null || transaction.getRawData().getContractCount() == 0) { if (transaction == null) { - //logger.info("transaction == null"); + // logger.info("transaction == null"); } else { - //logger.info("transaction.getRawData().getContractCount() == 0"); + // logger.info("transaction.getRawData().getContractCount() == 0"); } return false; } transaction = signTransaction(ecKey, transaction); GrpcAPI.Return response = blockingStubFull.broadcastTransaction(transaction); if (response.getResult() == false) { - //logger.info(ByteArray.toStr(response.getMessage().toByteArray())); + // logger.info(ByteArray.toStr(response.getMessage().toByteArray())); return false; } else { - //Protocol.Account search = queryAccount(ecKey, blockingStubFull); + // Protocol.Account search = queryAccount(ecKey, blockingStubFull); return true; } } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = false) public void beforeClass() { logger.info(testKeyForCreate); logger.info(testKeyForParticipate); - //Send coin to 2 account. - Assert.assertTrue(PublicMethod.sendcoin(createAddress, sendAmount, foundationAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(participateAssetAddress, sendAmount, - foundationAddress, testKey002, blockingStubFull)); - //Participate account freeze balance to get bandwidth. - Assert.assertTrue(PublicMethod.freezeBalance(participateAssetAddress, - 10000000L, 3, testKeyForParticipate, blockingStubFull)); - //Create an asset issue. + // Send coin to 2 account. + Assert.assertTrue( + PublicMethod.sendcoin( + createAddress, sendAmount, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + participateAssetAddress, sendAmount, foundationAddress, testKey002, blockingStubFull)); + // Participate account freeze balance to get bandwidth. + Assert.assertTrue( + PublicMethod.freezeBalance( + participateAssetAddress, 10000000L, 3, testKeyForParticipate, blockingStubFull)); + // Create an asset issue. Long start = System.currentTimeMillis() + 2000; - Long end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod.createAssetIssue(createAddress, name, totalSupply, 1, 1, - start, end, 1, description, url, freeAssetNetLimit, publicFreeAssetNetLimit, - 10L, 10L, testKeyForCreate, blockingStubFull)); + Long end = System.currentTimeMillis() + 1000000000; + Assert.assertTrue( + PublicMethod.createAssetIssue( + createAddress, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + freeAssetNetLimit, + publicFreeAssetNetLimit, + 10L, + 10L, + testKeyForCreate, + blockingStubFull)); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } final Account createInfo = PublicMethod.queryAccount(testKeyForCreate, blockingStubFull); - final Account participateInfo = PublicMethod.queryAccount(testKeyForParticipate, - blockingStubFull); + final Account participateInfo = + PublicMethod.queryAccount(testKeyForParticipate, blockingStubFull); Map assetIssueMap = new HashMap(); - Long temp = 0L; + Long temp = 0L; assetIssueMap = createInfo.getAssetMap(); for (String key : assetIssueMap.keySet()) { @@ -194,8 +210,12 @@ public void beforeClass() { start1 = System.currentTimeMillis(); } - //@Test(enabled = false, groups = {"full"}) - @Test(enabled = false, threadPoolSize = 250, invocationCount = 250, groups = {"full"}) + // @Test(enabled = false, groups = {"full"}) + @Test( + enabled = false, + threadPoolSize = 250, + invocationCount = 250, + groups = {"full"}) public void testParticipateAssetIssue() throws InterruptedException { Integer i = 0; Integer randNum; @@ -203,26 +223,29 @@ public void testParticipateAssetIssue() throws InterruptedException { while (i < 20) { randNum = i % 4; i++; - fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list") - .get(randNum); participateAssetIssue(createAddress, name.getBytes(), - 1, participateAssetAddress, testKeyForParticipate, blockingStubFull); + fullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(randNum); + participateAssetIssue( + createAddress, + name.getBytes(), + 1, + participateAssetAddress, + testKeyForParticipate, + blockingStubFull); } } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = false) public void shutdown() throws InterruptedException { - //Print the duration. + // Print the duration. end1 = System.currentTimeMillis(); logger.info("The time is " + Long.toString(end1 - start1)); Account createInfo = PublicMethod.queryAccount(testKeyForCreate, blockingStubFull); Map createAssetIssueMap = new HashMap(); - Long temp = 0L; + Long temp = 0L; createAssetIssueMap = createInfo.getAssetMap(); for (String key : createAssetIssueMap.keySet()) { @@ -244,25 +267,34 @@ public void shutdown() throws InterruptedException { } afterParticipateAssetIssueBalance = temp; - logger.info("Create account has balance " + Long.toString(beforeCreateAssetIssueBalance) - + " at the beginning"); - logger.info("Create account has balance " + Long.toString(afterCreateAssetIssueBalance) - + " at the end"); - logger.info("Create account reduce balance " + Long.toString(beforeCreateAssetIssueBalance - - afterCreateAssetIssueBalance)); - logger.info("Participate account total success transaction is " - + Long.toString(afterParticipateAssetIssueBalance)); + logger.info( + "Create account has balance " + + Long.toString(beforeCreateAssetIssueBalance) + + " at the beginning"); + logger.info( + "Create account has balance " + + Long.toString(afterCreateAssetIssueBalance) + + " at the end"); + logger.info( + "Create account reduce balance " + + Long.toString(beforeCreateAssetIssueBalance - afterCreateAssetIssueBalance)); + logger.info( + "Participate account total success transaction is " + + Long.toString(afterParticipateAssetIssueBalance)); Integer blockTimes = 0; Integer blockTransParticipateNum = 0; while (blockTimes < 5) { blockTimes++; - //Print the current block transaction num. + // Print the current block transaction num. Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - Long currentNum = currentBlock.getBlockHeader().getRawData().getNumber(); - logger.info("The block num " + Long.toString(currentNum) - + " total transaction is " + Long.toString(currentBlock.getTransactionsCount())); + Long currentNum = currentBlock.getBlockHeader().getRawData().getNumber(); + logger.info( + "The block num " + + Long.toString(currentNum) + + " total transaction is " + + Long.toString(currentBlock.getTransactionsCount())); try { Thread.sleep(3000); } catch (InterruptedException e) { @@ -295,13 +327,14 @@ public void shutdown() throws InterruptedException { } afterParticipateAssetIssueBalance = temp; - logger.info("Create account has balance " + Long.toString(beforeCreateAssetIssueBalance) - + "at the beginning"); - logger.info("Create account has balance " + Long.toString(afterCreateAssetIssueBalance) - + "at the end"); - logger.info("Participate account total success transaction is " - + Long.toString(afterParticipateAssetIssueBalance)); } - + logger.info( + "Create account has balance " + + Long.toString(beforeCreateAssetIssueBalance) + + "at the beginning"); + logger.info( + "Create account has balance " + Long.toString(afterCreateAssetIssueBalance) + "at the end"); + logger.info( + "Participate account total success transaction is " + + Long.toString(afterParticipateAssetIssueBalance)); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/fulltest/SuperWitnessAllowance.java b/testcase/src/test/java/stest/tron/wallet/fulltest/SuperWitnessAllowance.java index 966f5490..adbcd50c 100644 --- a/testcase/src/test/java/stest/tron/wallet/fulltest/SuperWitnessAllowance.java +++ b/testcase/src/test/java/stest/tron/wallet/fulltest/SuperWitnessAllowance.java @@ -28,9 +28,10 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - //import stest.tron.wallet.common.client.AccountComparator; +import stest.tron.wallet.common.client.utils.Utils; + +// import stest.tron.wallet.common.client.AccountComparator; @Slf4j public class SuperWitnessAllowance extends TronBaseTest { @@ -38,10 +39,10 @@ public class SuperWitnessAllowance extends TronBaseTest { /* //testng001、testng002、testng003、testng004 private static final byte[] foundationAddress = Base58 .decodeFromBase58Check("THph9K2M2nLvkianrMGswRhz5hjSA9fuH7");*/ - private static final byte[] INVAILD_ADDRESS = Base58 - .decodeFromBase58Check("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48"); + private static final byte[] INVAILD_ADDRESS = + Base58.decodeFromBase58Check("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48"); private static final Long costForCreateWitness = 10009000000L; - //testng001、testng002、testng003、testng004 only for test + // testng001、testng002、testng003、testng004 only for test private final String testKey002 = "FC8BF0238748587B9617EB6D15D47A66C0E07C1A1959033CF249C6532DC29FE6"; String createWitnessUrl = "http://www.createwitnessurl.com"; @@ -52,66 +53,65 @@ public class SuperWitnessAllowance extends TronBaseTest { byte[] updateUrl = updateWitnessUrl.getBytes(); byte[] wrongUrl = nullUrl.getBytes(); byte[] updateSpaceUrl = spaceUrl.getBytes(); - //get account + // get account ECKey ecKey = new ECKey(Utils.getRandom()); byte[] lowBalAddress = ecKey.getAddress(); String lowBalTest = ByteArray.toHexString(ecKey.getPrivKeyBytes()); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass public void beforeClass() { logger.info(lowBalTest); logger.info(ByteArray.toHexString(PublicMethod.getFinalAddress(lowBalTest))); - logger.info(Base58.encode58Check(PublicMethod.getFinalAddress(lowBalTest))); } + logger.info(Base58.encode58Check(PublicMethod.getFinalAddress(lowBalTest))); + } @Test(groups = {"full"}) public void testInvaildToApplyBecomeWitness() { Assert.assertFalse(createWitness(INVAILD_ADDRESS, createUrl, testKey002)); } - //@Test(enabled = true,threadPoolSize = 10, invocationCount = 10, groups = {"full"}) - @Test(enabled = false, groups = {"full"}) + // @Test(enabled = true,threadPoolSize = 10, invocationCount = 10, groups = {"full"}) + @Test( + enabled = false, + groups = {"full"}) public void testCreate130Witness() { - WitnessList witnesslist = blockingStubFull - .listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build()); + WitnessList witnesslist = + blockingStubFull.listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build()); Optional result = Optional.ofNullable(witnesslist); WitnessList witnessList = result.get(); while (witnessList.getWitnessesCount() < 130) { ECKey ecKey = new ECKey(Utils.getRandom()); - byte[] lowBalAddress = ecKey.getAddress(); - String lowBalTest = ByteArray.toHexString(ecKey.getPrivKeyBytes()); + byte[] lowBalAddress = ecKey.getAddress(); + String lowBalTest = ByteArray.toHexString(ecKey.getPrivKeyBytes()); logger.info(lowBalTest); - Assert.assertTrue(sendcoin(lowBalAddress, costForCreateWitness, foundationAddress, testKey002)); - Assert.assertTrue(PublicMethod.freezeBalance(lowBalAddress, 1000000, - 3, lowBalTest, blockingStubFull)); + Assert.assertTrue( + sendcoin(lowBalAddress, costForCreateWitness, foundationAddress, testKey002)); + Assert.assertTrue( + PublicMethod.freezeBalance(lowBalAddress, 1000000, 3, lowBalTest, blockingStubFull)); Assert.assertTrue(createWitness(lowBalAddress, createUrl, lowBalTest)); - String voteStr = Base58.encode58Check(PublicMethod.getFinalAddress(lowBalTest)); + String voteStr = Base58.encode58Check(PublicMethod.getFinalAddress(lowBalTest)); HashMap smallVoteMap = new HashMap(); smallVoteMap.put(voteStr, "1"); Assert.assertTrue(voteWitness(smallVoteMap, lowBalAddress, lowBalTest)); - witnesslist = blockingStubFull - .listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build()); + witnesslist = blockingStubFull.listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build()); result = Optional.ofNullable(witnesslist); witnessList = result.get(); - } - } - //@Test(enabled = true,threadPoolSize = 10, invocationCount = 10, groups = {"full"}) - @Test(enabled = false, groups = {"full"}) + // @Test(enabled = true,threadPoolSize = 10, invocationCount = 10, groups = {"full"}) + @Test( + enabled = false, + groups = {"full"}) public void testQueryAllowance() { - WitnessList witnesslist = blockingStubFull - .listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build()); + WitnessList witnesslist = + blockingStubFull.listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build()); Optional result = Optional.ofNullable(witnesslist); WitnessList witnessList = result.get(); Integer allowanceNum = 0; @@ -122,29 +122,24 @@ public void testQueryAllowance() { witnessList.getWitnesses(i).getAddress();*/ ByteString addressBs = witnessList.getWitnesses(i).getAddress(); Account request = Account.newBuilder().setAddress(addressBs).build(); - request = blockingStubFull.getAccount(request); + request = blockingStubFull.getAccount(request); if (request.getAllowance() > 0) { allowanceNum++; } - logger.info("Account " + Integer.toString(i) + " allowance is " + Long.toString(request - .getAllowance())); - + logger.info( + "Account " + + Integer.toString(i) + + " allowance is " + + Long.toString(request.getAllowance())); } logger.info("Allowance num is " + Integer.toString(allowanceNum)); - - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ + /** constructor. */ public Boolean createWitness(byte[] owner, byte[] url, String priKey) { ECKey temKey = null; try { @@ -155,8 +150,8 @@ public Boolean createWitness(byte[] owner, byte[] url, String priKey) { } final ECKey ecKey = temKey; - WitnessContract.WitnessCreateContract.Builder builder = WitnessContract.WitnessCreateContract - .newBuilder(); + WitnessContract.WitnessCreateContract.Builder builder = + WitnessContract.WitnessCreateContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(owner)); builder.setUrl(ByteString.copyFrom(url)); WitnessContract.WitnessCreateContract contract = builder.build(); @@ -167,12 +162,9 @@ public Boolean createWitness(byte[] owner, byte[] url, String priKey) { transaction = signTransaction(ecKey, transaction); GrpcAPI.Return response = blockingStubFull.broadcastTransaction(transaction); return response.getResult(); - } - /** - * constructor. - */ + /** constructor. */ public Boolean updateWitness(byte[] owner, byte[] url, String priKey) { ECKey temKey = null; try { @@ -183,8 +175,8 @@ public Boolean updateWitness(byte[] owner, byte[] url, String priKey) { } final ECKey ecKey = temKey; - WitnessContract.WitnessUpdateContract.Builder builder = WitnessContract.WitnessUpdateContract - .newBuilder(); + WitnessContract.WitnessUpdateContract.Builder builder = + WitnessContract.WitnessUpdateContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(owner)); builder.setUpdateUrl(ByteString.copyFrom(url)); WitnessContract.WitnessUpdateContract contract = builder.build(); @@ -202,16 +194,13 @@ public Boolean updateWitness(byte[] owner, byte[] url, String priKey) { } else { return true; } - } - /** - * constructor. - */ + /** constructor. */ public Boolean sendcoin(byte[] to, long amount, byte[] owner, String priKey) { - //String priKey = testKey002; - ECKey temKey = null; + // String priKey = testKey002; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -220,8 +209,8 @@ public Boolean sendcoin(byte[] to, long amount, byte[] owner, String priKey) { } final ECKey ecKey = temKey; - BalanceContract.TransferContract.Builder builder = BalanceContract.TransferContract - .newBuilder(); + BalanceContract.TransferContract.Builder builder = + BalanceContract.TransferContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); ByteString bsOwner = ByteString.copyFrom(owner); builder.setToAddress(bsTo); @@ -243,12 +232,10 @@ public Boolean sendcoin(byte[] to, long amount, byte[] owner, String priKey) { } } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -257,13 +244,13 @@ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockin } ECKey ecKey = temKey; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -273,23 +260,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Protocol.Transaction signTransaction(ECKey ecKey, Protocol.Transaction transaction) { @@ -301,9 +283,7 @@ private Protocol.Transaction signTransaction(ECKey ecKey, Protocol.Transaction t return TransactionUtils.sign(transaction, ecKey); } - /** - * constructor. - */ + /** constructor. */ public Boolean voteWitness(HashMap witness, byte[] addRess, String priKey) { ECKey temKey = null; @@ -315,22 +295,21 @@ public Boolean voteWitness(HashMap witness, byte[] addRess, Stri } final ECKey ecKey = temKey; Account beforeVote = PublicMethod.queryAccount(priKey, blockingStubFull); - //Account beforeVote = queryAccount(ecKey, blockingStubFull); - Long beforeVoteNum = 0L; + // Account beforeVote = queryAccount(ecKey, blockingStubFull); + Long beforeVoteNum = 0L; if (beforeVote.getVotesCount() != 0) { beforeVoteNum = beforeVote.getVotes(0).getVoteCount(); } - WitnessContract.VoteWitnessContract.Builder builder = WitnessContract.VoteWitnessContract - .newBuilder(); + WitnessContract.VoteWitnessContract.Builder builder = + WitnessContract.VoteWitnessContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(addRess)); for (String addressBase58 : witness.keySet()) { String value = witness.get(addressBase58); - final long count = Long.parseLong(value); + final long count = Long.parseLong(value); WitnessContract.VoteWitnessContract.Vote.Builder voteBuilder = - WitnessContract.VoteWitnessContract.Vote - .newBuilder(); - byte[] address = WalletClient.decodeFromBase58Check(addressBase58); + WitnessContract.VoteWitnessContract.Vote.newBuilder(); + byte[] address = WalletClient.decodeFromBase58Check(addressBase58); logger.info("address ====== " + ByteArray.toHexString(address)); if (address == null) { continue; @@ -358,9 +337,7 @@ public Boolean voteWitness(HashMap witness, byte[] addRess, Stri } catch (InterruptedException e) { e.printStackTrace(); } - //Long afterVoteNum = afterVote.getVotes(0).getVoteCount(); + // Long afterVoteNum = afterVote.getVotes(0).getVoteCount(); return true; } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/fulltest/TransferAssetIssue.java b/testcase/src/test/java/stest/tron/wallet/fulltest/TransferAssetIssue.java index 9900ae35..1befa978 100644 --- a/testcase/src/test/java/stest/tron/wallet/fulltest/TransferAssetIssue.java +++ b/testcase/src/test/java/stest/tron/wallet/fulltest/TransferAssetIssue.java @@ -25,9 +25,8 @@ import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.Sha256Hash; import stest.tron.wallet.common.client.utils.TransactionUtils; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class TransferAssetIssue extends TronBaseTest { @@ -40,7 +39,7 @@ public class TransferAssetIssue extends TronBaseTest { private static long afterParticipateAssetIssueBalance; private static long start1; private static long end1; - //testng001、testng002、testng003、testng004 only for test + // testng001、testng002、testng003、testng004 only for test private final String testKey002 = "FC8BF0238748587B9617EB6D15D47A66C0E07C1A1959033CF249C6532DC29FE6"; private final String testKey003 = @@ -51,7 +50,7 @@ public class TransferAssetIssue extends TronBaseTest { Long publicFreeAssetNetLimit = 300000000L; String description = "f"; String url = "h"; - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] createAddress = ecKey1.getAddress(); String testKeyForCreate = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -59,11 +58,14 @@ public class TransferAssetIssue extends TronBaseTest { byte[] participateAssetAddress = ecKey2.getAddress(); String testKeyForParticipate = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ - public static boolean participateAssetIssue(byte[] to, byte[] assertName, long amount, - byte[] from, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public static boolean participateAssetIssue( + byte[] to, + byte[] assertName, + long amount, + byte[] from, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -74,8 +76,7 @@ public static boolean participateAssetIssue(byte[] to, byte[] assertName, long a final ECKey ecKey = temKey; AssetIssueContractOuterClass.ParticipateAssetIssueContract.Builder builder = - AssetIssueContractOuterClass.ParticipateAssetIssueContract - .newBuilder(); + AssetIssueContractOuterClass.ParticipateAssetIssueContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); ByteString bsName = ByteString.copyFrom(assertName); ByteString bsOwner = ByteString.copyFrom(from); @@ -94,24 +95,25 @@ public static boolean participateAssetIssue(byte[] to, byte[] assertName, long a } } - /** - * constructor. - */ - public static Protocol.Transaction signTransaction(ECKey ecKey, - Protocol.Transaction transaction) { + /** constructor. */ + public static Protocol.Transaction signTransaction( + ECKey ecKey, Protocol.Transaction transaction) { if (ecKey == null || ecKey.getPrivKey() == null) { - //logger.warn("Warning: Can't sign,there is no private key !!"); + // logger.warn("Warning: Can't sign,there is no private key !!"); return null; } transaction = TransactionUtils.setTimestamp(transaction); return TransactionUtils.sign(transaction, ecKey); } - /** - * constructor. - */ - public static boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] address, - String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public static boolean transferAsset( + byte[] to, + byte[] assertName, + long amount, + byte[] address, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -122,8 +124,7 @@ public static boolean transferAsset(byte[] to, byte[] assertName, long amount, b final ECKey ecKey = temKey; AssetIssueContractOuterClass.TransferAssetContract.Builder builder = - AssetIssueContractOuterClass.TransferAssetContract - .newBuilder(); + AssetIssueContractOuterClass.TransferAssetContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); ByteString bsName = ByteString.copyFrom(assertName); ByteString bsOwner = ByteString.copyFrom(address); @@ -136,58 +137,71 @@ public static boolean transferAsset(byte[] to, byte[] assertName, long amount, b Protocol.Transaction transaction = blockingStubFull.transferAsset(contract); if (transaction == null || transaction.getRawData().getContractCount() == 0) { if (transaction == null) { - //logger.info("transaction == null"); + // logger.info("transaction == null"); } else { - //logger.info("transaction.getRawData().getContractCount() == 0"); + // logger.info("transaction.getRawData().getContractCount() == 0"); } return false; } transaction = signTransaction(ecKey, transaction); GrpcAPI.Return response = blockingStubFull.broadcastTransaction(transaction); if (response.getResult() == false) { - //logger.info(ByteArray.toStr(response.getMessage().toByteArray())); + // logger.info(ByteArray.toStr(response.getMessage().toByteArray())); return false; } else { - //Protocol.Account search = queryAccount(ecKey, blockingStubFull); + // Protocol.Account search = queryAccount(ecKey, blockingStubFull); return true; } } - - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = false) public void beforeClass() { logger.info(testKeyForCreate); logger.info(testKeyForParticipate); - //Send coin to 2 account. - Assert.assertTrue(PublicMethod.sendcoin(createAddress, sendAmount, - foundationAddress, testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(participateAssetAddress, - sendAmount, foundationAddress, testKey002, blockingStubFull)); - //Participate account freeze balance to get bandwidth. - Assert.assertTrue(PublicMethod.freezeBalance(participateAssetAddress, 10000000L, 3, - testKeyForParticipate, blockingStubFull)); - //Create an asset issue. + // Send coin to 2 account. + Assert.assertTrue( + PublicMethod.sendcoin( + createAddress, sendAmount, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + participateAssetAddress, sendAmount, foundationAddress, testKey002, blockingStubFull)); + // Participate account freeze balance to get bandwidth. + Assert.assertTrue( + PublicMethod.freezeBalance( + participateAssetAddress, 10000000L, 3, testKeyForParticipate, blockingStubFull)); + // Create an asset issue. Long start = System.currentTimeMillis() + 2000; - Long end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod.createAssetIssue(createAddress, name, totalSupply, 1, 1, - start, end, 1, description, url, freeAssetNetLimit, publicFreeAssetNetLimit, - 10L, 10L, testKeyForCreate, blockingStubFull)); + Long end = System.currentTimeMillis() + 1000000000; + Assert.assertTrue( + PublicMethod.createAssetIssue( + createAddress, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + freeAssetNetLimit, + publicFreeAssetNetLimit, + 10L, + 10L, + testKeyForCreate, + blockingStubFull)); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } final Account createInfo = PublicMethod.queryAccount(testKeyForCreate, blockingStubFull); - final Account participateInfo = PublicMethod.queryAccount(testKeyForParticipate, - blockingStubFull); + final Account participateInfo = + PublicMethod.queryAccount(testKeyForParticipate, blockingStubFull); Map assetIssueMap = new HashMap(); - Long temp = 0L; + Long temp = 0L; assetIssueMap = createInfo.getAssetMap(); for (String key : assetIssueMap.keySet()) { @@ -201,8 +215,12 @@ public void beforeClass() { start1 = System.currentTimeMillis(); } - //@Test(enabled = false, groups = {"full"}) - @Test(enabled = false, threadPoolSize = 200, invocationCount = 200, groups = {"full"}) + // @Test(enabled = false, groups = {"full"}) + @Test( + enabled = false, + threadPoolSize = 200, + invocationCount = 200, + groups = {"full"}) public void transferAssetIssue() throws InterruptedException { Integer i = 0; Integer randNum; @@ -210,25 +228,27 @@ public void transferAssetIssue() throws InterruptedException { while (i < 20) { randNum = i % 4; i++; - fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list") - .get(randNum); transferAsset(participateAssetAddress, name.getBytes(), 1, - createAddress, testKeyForCreate, blockingStubFull); + fullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(randNum); + transferAsset( + participateAssetAddress, + name.getBytes(), + 1, + createAddress, + testKeyForCreate, + blockingStubFull); } } - /** - * constructor. - */ - - + /** constructor. */ @AfterClass(enabled = false) public void shutdown() throws InterruptedException { - //Print the duration. + // Print the duration. end1 = System.currentTimeMillis(); logger.info("The time is " + Long.toString(end1 - start1)); Map createAssetIssueMap = new HashMap(); - Long temp = 0L; + Long temp = 0L; Account createInfo = PublicMethod.queryAccount(testKeyForCreate, blockingStubFull); createAssetIssueMap = createInfo.getAssetMap(); for (String key : createAssetIssueMap.keySet()) { @@ -251,14 +271,20 @@ public void shutdown() throws InterruptedException { } afterParticipateAssetIssueBalance = temp; - logger.info("Create account has balance " + Long.toString(beforeCreateAssetIssueBalance) - + " at the beginning"); - logger.info("Create account has balance " + Long.toString(afterCreateAssetIssueBalance) - + " at the end"); - logger.info("Create account reduce balance " + Long.toString(beforeCreateAssetIssueBalance - - afterCreateAssetIssueBalance)); - logger.info("Transfer account total success transaction is " - + Long.toString(afterParticipateAssetIssueBalance)); + logger.info( + "Create account has balance " + + Long.toString(beforeCreateAssetIssueBalance) + + " at the beginning"); + logger.info( + "Create account has balance " + + Long.toString(afterCreateAssetIssueBalance) + + " at the end"); + logger.info( + "Create account reduce balance " + + Long.toString(beforeCreateAssetIssueBalance - afterCreateAssetIssueBalance)); + logger.info( + "Transfer account total success transaction is " + + Long.toString(afterParticipateAssetIssueBalance)); Integer blockTimes = 0; Integer blockTransParticipateNum = 0; @@ -267,17 +293,19 @@ public void shutdown() throws InterruptedException { while (blockTimes < 5) { blockTimes++; - //Print the current block transaction num. + // Print the current block transaction num. Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - Long currentNum = currentBlock.getBlockHeader().getRawData().getNumber(); + Long currentNum = currentBlock.getBlockHeader().getRawData().getNumber(); for (Integer m = 0; m < currentBlock.getTransactionsCount(); m++) { logger.info(currentBlock.getTransactions(m).getRetList().toString()); - String txId = ByteArray.toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), currentBlock.getTransactions(m) - .getRawData().toByteArray())); + String txId = + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + currentBlock.getTransactions(m).getRawData().toByteArray())); ByteString bsTxid = ByteString.copyFrom(ByteArray.fromHexString(txId)); BytesMessage request = BytesMessage.newBuilder().setValue(bsTxid).build(); - Transaction transaction = blockingStubFull.getTransactionById(request); + Transaction transaction = blockingStubFull.getTransactionById(request); Optional getTransactionById = Optional.ofNullable(transaction); if (getTransactionById.get().getRet(0).getFee() > 0) { logger.info(Long.toString(getTransactionById.get().getRet(0).getFee())); @@ -288,8 +316,11 @@ public void shutdown() throws InterruptedException { } } - logger.info("The block num " + Long.toString(currentNum) - + " total transaction is " + Long.toString(currentBlock.getTransactionsCount())); + logger.info( + "The block num " + + Long.toString(currentNum) + + " total transaction is " + + Long.toString(currentBlock.getTransactionsCount())); try { Thread.sleep(3000); } catch (InterruptedException e) { @@ -325,13 +356,14 @@ public void shutdown() throws InterruptedException { } afterParticipateAssetIssueBalance = temp; - logger.info("Create account has balance " + Long.toString(beforeCreateAssetIssueBalance) - + "at the beginning"); - logger.info("Create account has balance " + Long.toString(afterCreateAssetIssueBalance) - + "at the end"); - logger.info("Participate account total success transaction is " - + Long.toString(afterParticipateAssetIssueBalance)); } - + logger.info( + "Create account has balance " + + Long.toString(beforeCreateAssetIssueBalance) + + "at the beginning"); + logger.info( + "Create account has balance " + Long.toString(afterCreateAssetIssueBalance) + "at the end"); + logger.info( + "Participate account total success transaction is " + + Long.toString(afterParticipateAssetIssueBalance)); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/fulltest/TronDice.java b/testcase/src/test/java/stest/tron/wallet/fulltest/TronDice.java index 4229c845..cc130059 100644 --- a/testcase/src/test/java/stest/tron/wallet/fulltest/TronDice.java +++ b/testcase/src/test/java/stest/tron/wallet/fulltest/TronDice.java @@ -13,48 +13,60 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode -public class TronDice extends TronBaseTest { byte[] contractAddress; +public class TronDice extends TronBaseTest { + byte[] contractAddress; Long maxFeeLimit = 1000000000L; Optional infoById = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contract008Address = ecKey1.getAddress(); String contract008Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); ArrayList txidList = new ArrayList(); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - /** - * constructor. - */ + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contract008Key); PublicMethod.printAddress(foundationKey); - AccountResourceMessage accountResource = PublicMethod.getAccountResource(contract008Address, - blockingStubFull); + PublicMethod.printAddress(contract008Key); + PublicMethod.printAddress(foundationKey); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(contract008Address, blockingStubFull); } - @Test(enabled = true, threadPoolSize = 30, invocationCount = 30, groups = {"full"}) + @Test( + enabled = true, + threadPoolSize = 30, + invocationCount = 30, + groups = {"full"}) public void tronDice() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] tronDiceAddress = ecKey1.getAddress(); - String tronDiceKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - PublicMethod - .sendcoin(tronDiceAddress, 100000000000L, foundationAddress, foundationKey, blockingStubFull); - String contractName = "TronDice"; - String code = Configuration.getByPath("testng.conf") - .getString("code.code_TronDice_tronDice"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_TronDice_tronDice"); - byte[] contractAddress = PublicMethod.deployContract(contractName, abi, code, "", - maxFeeLimit, 1000000000L, 100, null, tronDiceKey, tronDiceAddress, blockingStubFull); + byte[] tronDiceAddress = ecKey1.getAddress(); + String tronDiceKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + PublicMethod.sendcoin( + tronDiceAddress, 100000000000L, foundationAddress, foundationKey, blockingStubFull); + String contractName = "TronDice"; + String code = Configuration.getByPath("testng.conf").getString("code.code_TronDice_tronDice"); + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_TronDice_tronDice"); + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 1000000000L, + 100, + null, + tronDiceKey, + tronDiceAddress, + blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); try { Thread.sleep(10000); @@ -63,13 +75,21 @@ public void tronDice() { } Assert.assertTrue(smartContract.getAbi() != null); - String txid; + String txid; for (Integer i = 0; i < 100; i++) { String initParmes = "\"" + "10" + "\""; - txid = PublicMethod.triggerContract(contractAddress, - "rollDice(uint256)", initParmes, false, - 1000000, maxFeeLimit, tronDiceAddress, tronDiceKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "rollDice(uint256)", + initParmes, + false, + 1000000, + maxFeeLimit, + tronDiceAddress, + tronDiceKey, + blockingStubFull); logger.info(txid); txidList.add(txid); @@ -78,15 +98,10 @@ public void tronDice() { } catch (InterruptedException e) { e.printStackTrace(); } - } - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { try { @@ -110,7 +125,6 @@ public void shutdown() throws InterruptedException { logger.info("Total times is " + totalTimes.toString()); logger.info("success times is " + successTimes.toString()); logger.info("failed times is " + failedTimes.toString()); - logger.info("success percent is " + successTimes / totalTimes); } + logger.info("success percent is " + successTimes / totalTimes); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/fulltest/TvmContract.java b/testcase/src/test/java/stest/tron/wallet/fulltest/TvmContract.java index 9931686e..7938aff6 100644 --- a/testcase/src/test/java/stest/tron/wallet/fulltest/TvmContract.java +++ b/testcase/src/test/java/stest/tron/wallet/fulltest/TvmContract.java @@ -11,76 +11,91 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class TvmContract extends TronBaseTest { - //testng001、testng002、testng003、testng004 only for test, do not worry ! + // testng001、testng002、testng003、testng004 only for test, do not worry ! private final String testKey002 = "FC8BF0238748587B9617EB6D15D47A66C0E07C1A1959033CF249C6532DC29FE6"; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contract008Address = ecKey1.getAddress(); String contract008Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = false) public void beforeClass() { - PublicMethod.printAddress(contract008Key); Assert.assertTrue(PublicMethod.sendcoin(contract008Address, 500000000L, foundationAddress, - testKey002, blockingStubFull)); - logger.info(Long.toString(PublicMethod.queryAccount(contract008Key, blockingStubFull) - .getBalance())); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(contract008Address, 1000000L, - 3, 1, contract008Key, blockingStubFull)); - Assert.assertTrue(PublicMethod.buyStorage(50000000L, contract008Address, contract008Key, - blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalance(contract008Address, 5000000L, - 3, contract008Key, blockingStubFull)); - + PublicMethod.printAddress(contract008Key); + Assert.assertTrue( + PublicMethod.sendcoin( + contract008Address, 500000000L, foundationAddress, testKey002, blockingStubFull)); + logger.info( + Long.toString(PublicMethod.queryAccount(contract008Key, blockingStubFull).getBalance())); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + contract008Address, 1000000L, 3, 1, contract008Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.buyStorage(50000000L, contract008Address, contract008Key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance( + contract008Address, 5000000L, 3, contract008Key, blockingStubFull)); } - @Test(enabled = false, groups = {"full"}) + @Test( + enabled = false, + groups = {"full"}) public void deployErc721CryptoKitties() { - AccountResourceMessage accountResource = PublicMethod.getAccountResource(contract008Address, - blockingStubFull); - Long energyLimit = accountResource.getEnergyLimit(); - Long storageLimit = accountResource.getStorageLimit(); - Long energyUsage = accountResource.getEnergyUsed(); - Long storageUsage = accountResource.getStorageUsed(); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(contract008Address, blockingStubFull); + Long energyLimit = accountResource.getEnergyLimit(); + Long storageLimit = accountResource.getStorageLimit(); + Long energyUsage = accountResource.getEnergyUsed(); + Long storageUsage = accountResource.getStorageUsed(); logger.info("before energy limit is " + Long.toString(energyLimit)); logger.info("before energy usage is " + Long.toString(energyUsage)); logger.info("before storage limit is " + Long.toString(storageLimit)); logger.info("before storage usaged is " + Long.toString(storageUsage)); - Long maxFeeLimit = 50000000L; - String contractName = "ERC721"; - String code = Configuration.getByPath("testng.conf") - .getString("code.code_TvmContract_deployErc721CryptoKitties"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_TvmContract_deployErc721CryptoKitties"); - Long m = 0L; - Long freeNet; + Long maxFeeLimit = 50000000L; + String contractName = "ERC721"; + String code = + Configuration.getByPath("testng.conf") + .getString("code.code_TvmContract_deployErc721CryptoKitties"); + String abi = + Configuration.getByPath("testng.conf") + .getString("abi.abi_TvmContract_deployErc721CryptoKitties"); + Long m = 0L; + Long freeNet; accountResource = PublicMethod.getAccountResource(contract008Address, blockingStubFull); - Long net = accountResource.getFreeNetUsed(); + Long net = accountResource.getFreeNetUsed(); Account account = PublicMethod.queryAccount(contract008Key, blockingStubFull); - Long netUsed = account.getNetUsage(); + Long netUsed = account.getNetUsage(); logger.info("before net used is " + Long.toString(netUsed)); logger.info("before balance is " + account.getBalance()); for (Integer i = 0; i < 1; i++) { - byte[] contractAddress = PublicMethod.deployContract("1", abi, code, "", - 30000000L, 0L, 1, null, contract008Key, contract008Address, blockingStubFull); + byte[] contractAddress = + PublicMethod.deployContract( + "1", + abi, + code, + "", + 30000000L, + 0L, + 1, + null, + contract008Key, + contract008Address, + blockingStubFull); accountResource = PublicMethod.getAccountResource(contract008Address, blockingStubFull); freeNet = accountResource.getFreeNetUsed(); energyUsage = accountResource.getEnergyUsed(); logger.info( "Time " + Integer.toString(i) + ": energy usage is " + Long.toString(energyUsage - m)); - logger.info("Time " + Integer.toString(i) + ": free net used is " + Long - .toString(freeNet - net)); + logger.info( + "Time " + Integer.toString(i) + ": free net used is " + Long.toString(freeNet - net)); account = PublicMethod.queryAccount(contract008Key, blockingStubFull); logger.info("after balance is " + account.getBalance()); netUsed = account.getNetUsage(); @@ -92,23 +107,22 @@ public void deployErc721CryptoKitties() { } catch (InterruptedException e) { e.printStackTrace(); } - } - //SmartContract smartContract = PublicMethod.getContract(contractAddress,blockingStubFull); - //Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); - //Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); - //Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - //logger.info(smartContract.getName()); - //logger.info(smartContract.getAbi().toString()); + // SmartContract smartContract = PublicMethod.getContract(contractAddress,blockingStubFull); + // Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + // Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + // Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + // logger.info(smartContract.getName()); + // logger.info(smartContract.getAbi().toString()); accountResource = PublicMethod.getAccountResource(contract008Address, blockingStubFull); energyLimit = accountResource.getEnergyLimit(); storageLimit = accountResource.getStorageLimit(); energyUsage = accountResource.getEnergyUsed(); storageUsage = accountResource.getStorageUsed(); - //Assert.assertTrue(storageUsage > 0); - //Assert.assertTrue(storageLimit > 0); - //Assert.assertTrue(energyLimit > 0); - //Assert.assertTrue(energyUsage > 0); + // Assert.assertTrue(storageUsage > 0); + // Assert.assertTrue(storageLimit > 0); + // Assert.assertTrue(energyLimit > 0); + // Assert.assertTrue(energyUsage > 0); logger.info("after energy limit is " + Long.toString(energyLimit)); logger.info("after energy usage is " + Long.toString(energyUsage)); @@ -116,12 +130,7 @@ public void deployErc721CryptoKitties() { logger.info("after storage usaged is " + Long.toString(storageUsage)); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/fuzz/AddressValidationPropertyTest.java b/testcase/src/test/java/stest/tron/wallet/fuzz/AddressValidationPropertyTest.java index 2e8bb1e9..d333e71e 100644 --- a/testcase/src/test/java/stest/tron/wallet/fuzz/AddressValidationPropertyTest.java +++ b/testcase/src/test/java/stest/tron/wallet/fuzz/AddressValidationPropertyTest.java @@ -1,8 +1,12 @@ package stest.tron.wallet.fuzz; -import net.jqwik.api.*; -import net.jqwik.api.constraints.*; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import net.jqwik.api.Assume; +import net.jqwik.api.ForAll; +import net.jqwik.api.Property; +import net.jqwik.api.constraints.Size; import stest.tron.wallet.common.client.utils.Base58; class AddressValidationPropertyTest { diff --git a/testcase/src/test/java/stest/tron/wallet/fuzz/AmountBoundaryPropertyTest.java b/testcase/src/test/java/stest/tron/wallet/fuzz/AmountBoundaryPropertyTest.java index 9e5bed2e..a084514b 100644 --- a/testcase/src/test/java/stest/tron/wallet/fuzz/AmountBoundaryPropertyTest.java +++ b/testcase/src/test/java/stest/tron/wallet/fuzz/AmountBoundaryPropertyTest.java @@ -1,8 +1,11 @@ package stest.tron.wallet.fuzz; -import net.jqwik.api.*; -import net.jqwik.api.constraints.*; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import net.jqwik.api.ForAll; +import net.jqwik.api.Property; +import net.jqwik.api.constraints.LongRange; +import net.jqwik.api.constraints.Size; import stest.tron.wallet.common.client.utils.ByteArray; class AmountBoundaryPropertyTest { @@ -24,7 +27,8 @@ void intToByteArrayAndBack(@ForAll int value) { } @Property(tries = 1000) - void trxAmountsPreserved(@ForAll @LongRange(min = 0, max = 100_000_000_000_000_000L) long sunAmount) { + void trxAmountsPreserved( + @ForAll @LongRange(min = 0, max = 100_000_000_000_000_000L) long sunAmount) { byte[] bytes = ByteArray.fromLong(sunAmount); long recovered = ByteArray.toLong(bytes); assertEquals(sunAmount, recovered, "TRX amount in sun should roundtrip"); diff --git a/testcase/src/test/java/stest/tron/wallet/fuzz/Base58PropertyTest.java b/testcase/src/test/java/stest/tron/wallet/fuzz/Base58PropertyTest.java index e0e568a1..6176f0a8 100644 --- a/testcase/src/test/java/stest/tron/wallet/fuzz/Base58PropertyTest.java +++ b/testcase/src/test/java/stest/tron/wallet/fuzz/Base58PropertyTest.java @@ -1,7 +1,10 @@ package stest.tron.wallet.fuzz; -import net.jqwik.api.*; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import net.jqwik.api.ForAll; +import net.jqwik.api.Property; import stest.tron.wallet.common.client.utils.Base58; class Base58PropertyTest { @@ -18,8 +21,7 @@ void encodedStringContainsOnlyBase58Chars(@ForAll byte[] input) { String encoded = Base58.encode(input); String alphabet = new String(Base58.ALPHABET); for (char c : encoded.toCharArray()) { - assertTrue(alphabet.indexOf(c) >= 0, - "Encoded string contains non-Base58 character: " + c); + assertTrue(alphabet.indexOf(c) >= 0, "Encoded string contains non-Base58 character: " + c); } } diff --git a/testcase/src/test/java/stest/tron/wallet/fuzz/ByteArrayPropertyTest.java b/testcase/src/test/java/stest/tron/wallet/fuzz/ByteArrayPropertyTest.java index 7e5fbc69..a2ec18bf 100644 --- a/testcase/src/test/java/stest/tron/wallet/fuzz/ByteArrayPropertyTest.java +++ b/testcase/src/test/java/stest/tron/wallet/fuzz/ByteArrayPropertyTest.java @@ -1,8 +1,12 @@ package stest.tron.wallet.fuzz; -import net.jqwik.api.*; -import net.jqwik.api.constraints.*; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import net.jqwik.api.ForAll; +import net.jqwik.api.Property; +import net.jqwik.api.constraints.IntRange; +import net.jqwik.api.constraints.LongRange; import stest.tron.wallet.common.client.utils.ByteArray; class ByteArrayPropertyTest { diff --git a/testcase/src/test/java/stest/tron/wallet/fuzz/ContractBytecodeFuzzTest.java b/testcase/src/test/java/stest/tron/wallet/fuzz/ContractBytecodeFuzzTest.java index f75127a0..2f6f7020 100644 --- a/testcase/src/test/java/stest/tron/wallet/fuzz/ContractBytecodeFuzzTest.java +++ b/testcase/src/test/java/stest/tron/wallet/fuzz/ContractBytecodeFuzzTest.java @@ -1,9 +1,14 @@ package stest.tron.wallet.fuzz; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + import com.google.protobuf.ByteString; -import net.jqwik.api.*; -import net.jqwik.api.constraints.*; -import static org.junit.jupiter.api.Assertions.*; +import net.jqwik.api.ForAll; +import net.jqwik.api.Property; +import net.jqwik.api.constraints.IntRange; +import net.jqwik.api.constraints.Size; +import net.jqwik.api.constraints.StringLength; import org.tron.protos.contract.SmartContractOuterClass.CreateSmartContract; import org.tron.protos.contract.SmartContractOuterClass.SmartContract; import org.tron.protos.contract.SmartContractOuterClass.SmartContract.ABI; @@ -12,8 +17,8 @@ /** * Fuzz testing for smart contract bytecode. * - *

Generates random bytecode sequences and verifies that the protobuf - * message construction handles arbitrary data without crashing. + *

Generates random bytecode sequences and verifies that the protobuf message construction + * handles arbitrary data without crashing. */ class ContractBytecodeFuzzTest { @@ -21,16 +26,18 @@ class ContractBytecodeFuzzTest { void randomBytecodeCanBePackaged(@ForAll @Size(max = 24576) byte[] bytecode) { ECKey owner = new ECKey(); - SmartContract.Builder contractBuilder = SmartContract.newBuilder() - .setOriginAddress(ByteString.copyFrom(owner.getAddress())) - .setBytecode(ByteString.copyFrom(bytecode)) - .setName("FuzzContract") - .setConsumeUserResourcePercent(100); + SmartContract.Builder contractBuilder = + SmartContract.newBuilder() + .setOriginAddress(ByteString.copyFrom(owner.getAddress())) + .setBytecode(ByteString.copyFrom(bytecode)) + .setName("FuzzContract") + .setConsumeUserResourcePercent(100); - CreateSmartContract createContract = CreateSmartContract.newBuilder() - .setOwnerAddress(ByteString.copyFrom(owner.getAddress())) - .setNewContract(contractBuilder.build()) - .build(); + CreateSmartContract createContract = + CreateSmartContract.newBuilder() + .setOwnerAddress(ByteString.copyFrom(owner.getAddress())) + .setNewContract(contractBuilder.build()) + .build(); // Should not throw; protobuf accepts any bytes as bytecode assertNotNull(createContract); @@ -41,11 +48,12 @@ void randomBytecodeCanBePackaged(@ForAll @Size(max = 24576) byte[] bytecode) { void emptyBytecodeIsAcceptedByProtobuf() { ECKey owner = new ECKey(); - SmartContract contract = SmartContract.newBuilder() - .setOriginAddress(ByteString.copyFrom(owner.getAddress())) - .setBytecode(ByteString.EMPTY) - .setName("EmptyContract") - .build(); + SmartContract contract = + SmartContract.newBuilder() + .setOriginAddress(ByteString.copyFrom(owner.getAddress())) + .setBytecode(ByteString.EMPTY) + .setName("EmptyContract") + .build(); assertEquals(0, contract.getBytecode().size()); } @@ -54,11 +62,12 @@ void emptyBytecodeIsAcceptedByProtobuf() { void contractNameWithSpecialChars(@ForAll @StringLength(max = 256) String name) { ECKey owner = new ECKey(); - SmartContract contract = SmartContract.newBuilder() - .setOriginAddress(ByteString.copyFrom(owner.getAddress())) - .setBytecode(ByteString.copyFrom(new byte[]{0x60, 0x00})) - .setName(name) - .build(); + SmartContract contract = + SmartContract.newBuilder() + .setOriginAddress(ByteString.copyFrom(owner.getAddress())) + .setBytecode(ByteString.copyFrom(new byte[] {0x60, 0x00})) + .setName(name) + .build(); assertEquals(name, contract.getName()); } @@ -67,10 +76,8 @@ void contractNameWithSpecialChars(@ForAll @StringLength(max = 256) String name) void abiWithRandomEntryCount(@ForAll @IntRange(min = 0, max = 50) int entryCount) { ABI.Builder abiBuilder = ABI.newBuilder(); for (int i = 0; i < entryCount; i++) { - abiBuilder.addEntrys(ABI.Entry.newBuilder() - .setName("func" + i) - .setType(ABI.Entry.EntryType.Function) - .build()); + abiBuilder.addEntrys( + ABI.Entry.newBuilder().setName("func" + i).setType(ABI.Entry.EntryType.Function).build()); } ABI abi = abiBuilder.build(); diff --git a/testcase/src/test/java/stest/tron/wallet/fuzz/ECKeyPropertyTest.java b/testcase/src/test/java/stest/tron/wallet/fuzz/ECKeyPropertyTest.java index 5a5119f2..3b09d443 100644 --- a/testcase/src/test/java/stest/tron/wallet/fuzz/ECKeyPropertyTest.java +++ b/testcase/src/test/java/stest/tron/wallet/fuzz/ECKeyPropertyTest.java @@ -1,7 +1,13 @@ package stest.tron.wallet.fuzz; -import net.jqwik.api.*; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import net.jqwik.api.Assume; +import net.jqwik.api.ForAll; +import net.jqwik.api.Property; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.Sha256Hash; @@ -14,8 +20,7 @@ void signAndRecoverPublicKey(@ForAll byte[] message) { ECKey key = new ECKey(); ECKey.ECDSASignature sig = key.sign(messageHash); - byte[] recoveredPubKey = ECKey.recoverPubBytesFromSignature( - sig.v - 27, sig, messageHash); + byte[] recoveredPubKey = ECKey.recoverPubBytesFromSignature(sig.v - 27, sig, messageHash); assertNotNull(recoveredPubKey); assertArrayEquals(key.getPubKey(), recoveredPubKey); } diff --git a/testcase/src/test/java/stest/tron/wallet/fuzz/GrpcMessageFuzzTest.java b/testcase/src/test/java/stest/tron/wallet/fuzz/GrpcMessageFuzzTest.java index a7241536..2bb425a0 100644 --- a/testcase/src/test/java/stest/tron/wallet/fuzz/GrpcMessageFuzzTest.java +++ b/testcase/src/test/java/stest/tron/wallet/fuzz/GrpcMessageFuzzTest.java @@ -1,10 +1,15 @@ package stest.tron.wallet.fuzz; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; + import com.google.protobuf.ByteString; import com.google.protobuf.InvalidProtocolBufferException; -import net.jqwik.api.*; -import net.jqwik.api.constraints.*; -import static org.junit.jupiter.api.Assertions.*; +import net.jqwik.api.ForAll; +import net.jqwik.api.Property; +import net.jqwik.api.constraints.Size; import org.tron.api.GrpcAPI.BytesMessage; import org.tron.api.GrpcAPI.NumberMessage; import org.tron.protos.Protocol.Transaction; @@ -12,8 +17,8 @@ /** * Fuzz testing for gRPC/protobuf message parsing. * - *

Feeds random bytes into protobuf parsers to verify they handle - * malformed input gracefully (throw exceptions, not crash). + *

Feeds random bytes into protobuf parsers to verify they handle malformed input gracefully + * (throw exceptions, not crash). */ class GrpcMessageFuzzTest { @@ -50,14 +55,12 @@ void randomBytesAsNumberMessageShouldNotCrash(@ForAll byte[] randomBytes) { @Property(tries = 1000) void bytesMessageRoundTrip(@ForAll @Size(max = 1024) byte[] data) { - BytesMessage original = BytesMessage.newBuilder() - .setValue(ByteString.copyFrom(data)) - .build(); + BytesMessage original = BytesMessage.newBuilder().setValue(ByteString.copyFrom(data)).build(); try { BytesMessage parsed = BytesMessage.parseFrom(original.toByteArray()); - assertArrayEquals(data, parsed.getValue().toByteArray(), - "BytesMessage should roundtrip correctly"); + assertArrayEquals( + data, parsed.getValue().toByteArray(), "BytesMessage should roundtrip correctly"); } catch (InvalidProtocolBufferException e) { fail("Valid BytesMessage should always parse: " + e.getMessage()); } @@ -65,14 +68,11 @@ void bytesMessageRoundTrip(@ForAll @Size(max = 1024) byte[] data) { @Property(tries = 1000) void numberMessageRoundTrip(@ForAll long number) { - NumberMessage original = NumberMessage.newBuilder() - .setNum(number) - .build(); + NumberMessage original = NumberMessage.newBuilder().setNum(number).build(); try { NumberMessage parsed = NumberMessage.parseFrom(original.toByteArray()); - assertEquals(number, parsed.getNum(), - "NumberMessage should roundtrip correctly"); + assertEquals(number, parsed.getNum(), "NumberMessage should roundtrip correctly"); } catch (InvalidProtocolBufferException e) { fail("Valid NumberMessage should always parse: " + e.getMessage()); } diff --git a/testcase/src/test/java/stest/tron/wallet/fuzz/Sha256PropertyTest.java b/testcase/src/test/java/stest/tron/wallet/fuzz/Sha256PropertyTest.java index b6213842..c6f55915 100644 --- a/testcase/src/test/java/stest/tron/wallet/fuzz/Sha256PropertyTest.java +++ b/testcase/src/test/java/stest/tron/wallet/fuzz/Sha256PropertyTest.java @@ -1,8 +1,13 @@ package stest.tron.wallet.fuzz; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; + import java.util.Arrays; -import net.jqwik.api.*; -import static org.junit.jupiter.api.Assertions.*; +import net.jqwik.api.Assume; +import net.jqwik.api.ForAll; +import net.jqwik.api.Property; import stest.tron.wallet.common.client.utils.Sha256Hash; class Sha256PropertyTest { diff --git a/testcase/src/test/java/stest/tron/wallet/fuzz/TransactionFuzzTest.java b/testcase/src/test/java/stest/tron/wallet/fuzz/TransactionFuzzTest.java index 75215a75..226b6a8d 100644 --- a/testcase/src/test/java/stest/tron/wallet/fuzz/TransactionFuzzTest.java +++ b/testcase/src/test/java/stest/tron/wallet/fuzz/TransactionFuzzTest.java @@ -1,9 +1,14 @@ package stest.tron.wallet.fuzz; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import com.google.protobuf.ByteString; -import net.jqwik.api.*; -import net.jqwik.api.constraints.*; -import static org.junit.jupiter.api.Assertions.*; +import net.jqwik.api.ForAll; +import net.jqwik.api.Property; +import net.jqwik.api.constraints.LongRange; import org.tron.protos.Protocol.Transaction; import org.tron.protos.contract.BalanceContract.TransferContract; import stest.tron.wallet.common.client.utils.ECKey; @@ -13,28 +18,33 @@ /** * Fuzz testing for transaction fields. * - *

Generates random/boundary values for transaction parameters to verify - * that invalid transactions are properly rejected and valid ones can be signed. + *

Generates random/boundary values for transaction parameters to verify that invalid + * transactions are properly rejected and valid ones can be signed. */ class TransactionFuzzTest { @Property(tries = 500) - void randomAmountTransactionCanBeSigned(@ForAll @LongRange(min = 0, max = Long.MAX_VALUE) long amount) { + void randomAmountTransactionCanBeSigned( + @ForAll @LongRange(min = 0, max = Long.MAX_VALUE) long amount) { ECKey sender = new ECKey(); ECKey receiver = new ECKey(); - TransferContract.Builder transferBuilder = TransferContract.newBuilder() - .setOwnerAddress(ByteString.copyFrom(sender.getAddress())) - .setToAddress(ByteString.copyFrom(receiver.getAddress())) - .setAmount(amount); + TransferContract.Builder transferBuilder = + TransferContract.newBuilder() + .setOwnerAddress(ByteString.copyFrom(sender.getAddress())) + .setToAddress(ByteString.copyFrom(receiver.getAddress())) + .setAmount(amount); - Transaction.raw.Builder rawBuilder = Transaction.raw.newBuilder() - .setTimestamp(System.currentTimeMillis()) - .setExpiration(System.currentTimeMillis() + 60_000); + Transaction.raw.Builder rawBuilder = + Transaction.raw + .newBuilder() + .setTimestamp(System.currentTimeMillis()) + .setExpiration(System.currentTimeMillis() + 60_000); - Transaction.Contract.Builder contractBuilder = Transaction.Contract.newBuilder() - .setType(Transaction.Contract.ContractType.TransferContract) - .setParameter(com.google.protobuf.Any.pack(transferBuilder.build())); + Transaction.Contract.Builder contractBuilder = + Transaction.Contract.newBuilder() + .setType(Transaction.Contract.ContractType.TransferContract) + .setParameter(com.google.protobuf.Any.pack(transferBuilder.build())); rawBuilder.addContract(contractBuilder.build()); Transaction tx = Transaction.newBuilder().setRawData(rawBuilder.build()).build(); @@ -46,15 +56,17 @@ void randomAmountTransactionCanBeSigned(@ForAll @LongRange(min = 0, max = Long.M } @Property(tries = 500) - void negativeAmountProducesInvalidTransfer(@ForAll @LongRange(min = Long.MIN_VALUE, max = -1) long amount) { + void negativeAmountProducesInvalidTransfer( + @ForAll @LongRange(min = Long.MIN_VALUE, max = -1) long amount) { ECKey sender = new ECKey(); ECKey receiver = new ECKey(); - TransferContract contract = TransferContract.newBuilder() - .setOwnerAddress(ByteString.copyFrom(sender.getAddress())) - .setToAddress(ByteString.copyFrom(receiver.getAddress())) - .setAmount(amount) - .build(); + TransferContract contract = + TransferContract.newBuilder() + .setOwnerAddress(ByteString.copyFrom(sender.getAddress())) + .setToAddress(ByteString.copyFrom(receiver.getAddress())) + .setAmount(amount) + .build(); // Negative amounts should still serialize (validation is on-chain) assertTrue(contract.getAmount() < 0, "Negative amount should be preserved in protobuf"); @@ -64,11 +76,12 @@ void negativeAmountProducesInvalidTransfer(@ForAll @LongRange(min = Long.MIN_VAL void randomBytesAsAddressInTransfer(@ForAll byte[] randomAddr) { ECKey sender = new ECKey(); - TransferContract contract = TransferContract.newBuilder() - .setOwnerAddress(ByteString.copyFrom(sender.getAddress())) - .setToAddress(ByteString.copyFrom(randomAddr)) - .setAmount(1000000L) - .build(); + TransferContract contract = + TransferContract.newBuilder() + .setOwnerAddress(ByteString.copyFrom(sender.getAddress())) + .setToAddress(ByteString.copyFrom(randomAddr)) + .setAmount(1000000L) + .build(); // Protobuf accepts any bytes; on-chain validation rejects bad addresses assertEquals(randomAddr.length, contract.getToAddress().size()); @@ -88,13 +101,15 @@ void tamperedSignatureInvalidatesTransaction() { // Tampered signature should not recover the original public key try { - byte[] recovered = ECKey.recoverPubBytesFromSignature( - sig.v - 27, - ECKey.ECDSASignature.fromComponents(sigBytes, sigBytes, (byte) sig.v), - message); + byte[] recovered = + ECKey.recoverPubBytesFromSignature( + sig.v - 27, + ECKey.ECDSASignature.fromComponents(sigBytes, sigBytes, (byte) sig.v), + message); // If recovery succeeds, it should be a different key if (recovered != null) { - assertFalse(java.util.Arrays.equals(key.getPubKey(), recovered), + assertFalse( + java.util.Arrays.equals(key.getPubKey(), recovered), "Tampered signature should not recover original key"); } } catch (Exception e) { diff --git a/testcase/src/test/java/stest/tron/wallet/leveldb/TestLeveldb001.java b/testcase/src/test/java/stest/tron/wallet/leveldb/TestLeveldb001.java index 4ec6b8b2..f6c88bb9 100644 --- a/testcase/src/test/java/stest/tron/wallet/leveldb/TestLeveldb001.java +++ b/testcase/src/test/java/stest/tron/wallet/leveldb/TestLeveldb001.java @@ -9,23 +9,17 @@ public class TestLeveldb001 extends LeveldbBase { public void test01() { try { - //System.out.println(getAccountFromDb("TAsimLx1ZWc6epr5FjitmktrDqhJY2AZ5R").toString()); - //System.out.println(getAddressBalance("TAsimLx1ZWc6epr5FjitmktrDqhJY2AZ5R")); - //System.out.println(getAddressAssetCount("TAsimLx1ZWc6epr5FjitmktrDqhJY2AZ5R", "1000005")); - //System.out.println(getAssetIssueById("1000005")); - //String txid = "cdc321bba1856982f5d90b7a2adb0ed19a847003cc670840e8c35d13c2210515"; - //System.out.println(getTransactionById(txid).toString()); - //System.out.println(getTransactionInfoById(txid).toString()); - //System.out.println(getBlockByNumber(311).toString()); - //System.out.println(getNowBlock().toString()); + // System.out.println(getAccountFromDb("TAsimLx1ZWc6epr5FjitmktrDqhJY2AZ5R").toString()); + // System.out.println(getAddressBalance("TAsimLx1ZWc6epr5FjitmktrDqhJY2AZ5R")); + // System.out.println(getAddressAssetCount("TAsimLx1ZWc6epr5FjitmktrDqhJY2AZ5R", "1000005")); + // System.out.println(getAssetIssueById("1000005")); + // String txid = "cdc321bba1856982f5d90b7a2adb0ed19a847003cc670840e8c35d13c2210515"; + // System.out.println(getTransactionById(txid).toString()); + // System.out.println(getTransactionInfoById(txid).toString()); + // System.out.println(getBlockByNumber(311).toString()); + // System.out.println(getNowBlock().toString()); } catch (Exception e) { e.printStackTrace(); } } - - - - - - } diff --git a/testcase/src/test/java/stest/tron/wallet/multisign/WalletTestMultiSign001.java b/testcase/src/test/java/stest/tron/wallet/multisign/WalletTestMultiSign001.java index 57bffb17..135e5ccb 100644 --- a/testcase/src/test/java/stest/tron/wallet/multisign/WalletTestMultiSign001.java +++ b/testcase/src/test/java/stest/tron/wallet/multisign/WalletTestMultiSign001.java @@ -14,8 +14,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestMultiSign001 extends TronBaseTest { @@ -23,10 +23,9 @@ public class WalletTestMultiSign001 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final long totalSupply = now; private static String name = "MultiSign001_" + Long.toString(now); - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); ByteString assetAccountId1; String[] permissionKeyString = new String[2]; String[] ownerKeyString = new String[2]; @@ -43,19 +42,18 @@ public class WalletTestMultiSign001 extends TronBaseTest { ECKey ecKey4 = new ECKey(Utils.getRandom()); byte[] participateAddress = ecKey4.getAddress(); String participateKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - - /** - * constructor. - */ + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, groups = {"multisig", "smoke"}) + @Test( + enabled = true, + groups = {"multisig", "smoke"}) public void testMultiSign1CreateAssetissue() { ecKey1 = new ECKey(Utils.getRandom()); manager1Address = ecKey1.getAddress(); @@ -73,10 +71,14 @@ public void testMultiSign1CreateAssetissue() { long needCoin = updateAccountPermissionFee * 1 + multiSignFee * 3; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, needCoin + 2048000000L, foundationAddress, foundationKey, + PublicMethod.sendcoin( + ownerAddress, + needCoin + 2048000000L, + foundationAddress, + foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -85,24 +87,31 @@ public void testMultiSign1CreateAssetissue() { ownerKeyString[1] = manager1Key; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - String txid = PublicMethodForMultiSign - .accountPermissionUpdateForTransactionId(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerKeyString); + String txid = + PublicMethodForMultiSign.accountPermissionUpdateForTransactionId( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); long energyFee = infoById.get().getReceipt().getEnergyFee(); @@ -118,20 +127,34 @@ public void testMultiSign1CreateAssetissue() { Assert.assertEquals(fee, energyFee + netFee + updateAccountPermissionFee); balanceBefore = balanceAfter; - Long start = System.currentTimeMillis() + 5000; - Long end = System.currentTimeMillis() + 1000000000; + Long start = System.currentTimeMillis() + 5000; + Long end = System.currentTimeMillis() + 1000000000; logger.info("try create asset issue"); - txid = PublicMethodForMultiSign - .createAssetIssueForTransactionId(ownerAddress, name, totalSupply, 1, - 1, start, end, 1, description, url, 2000L, 2000L, - 1L, 1L, ownerKey, blockingStubFull, ownerKeyString); + txid = + PublicMethodForMultiSign.createAssetIssueForTransactionId( + ownerAddress, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + ownerKey, + blockingStubFull, + ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); energyFee = infoById.get().getReceipt().getEnergyFee(); netFee = infoById.get().getReceipt().getNetFee(); @@ -148,29 +171,34 @@ public void testMultiSign1CreateAssetissue() { logger.info(" create asset end"); } - /** - * constructor. - */ - - @Test(enabled = true, groups = {"multisig", "smoke"}) + /** constructor. */ + @Test( + enabled = true, + groups = {"multisig", "smoke"}) public void testMultiSign2TransferAssetissue() { PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.printAddress(manager1Key); Account getAssetIdFromOwnerAccount; getAssetIdFromOwnerAccount = PublicMethod.queryAccount(ownerAddress, blockingStubFull); assetAccountId1 = getAssetIdFromOwnerAccount.getAssetIssuedID(); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); - String txid = PublicMethodForMultiSign.transferAssetForTransactionId(manager1Address, - assetAccountId1.toByteArray(), 10, ownerAddress, ownerKey, blockingStubFull, - ownerKeyString); + String txid = + PublicMethodForMultiSign.transferAssetForTransactionId( + manager1Address, + assetAccountId1.toByteArray(), + 10, + ownerAddress, + ownerKey, + blockingStubFull, + ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); long energyFee = infoById.get().getReceipt().getEnergyFee(); long netFee = infoById.get().getReceipt().getNetFee(); @@ -185,11 +213,10 @@ public void testMultiSign2TransferAssetissue() { Assert.assertEquals(fee, energyFee + netFee + multiSignFee); } - /** - * constructor. - */ - - @Test(enabled = true, groups = {"multisig", "smoke"}) + /** constructor. */ + @Test( + enabled = true, + groups = {"multisig", "smoke"}) public void testMultiSign3ParticipateAssetissue() { ecKey4 = new ECKey(Utils.getRandom()); participateAddress = ecKey4.getAddress(); @@ -198,39 +225,54 @@ public void testMultiSign3ParticipateAssetissue() { long needCoin = updateAccountPermissionFee * 1 + multiSignFee * 2; Assert.assertTrue( - PublicMethod.sendcoin(participateAddress, needCoin + 2048000000L, foundationAddress, foundationKey, + PublicMethod.sendcoin( + participateAddress, + needCoin + 2048000000L, + foundationAddress, + foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(participateAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = + PublicMethod.queryAccount(participateAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); ownerKeyString[0] = participateKey; ownerKeyString[1] = manager1Key; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(participateKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(participateKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - String txid = PublicMethodForMultiSign - .accountPermissionUpdateForTransactionId(accountPermissionJson, participateAddress, - participateKey, blockingStubFull, ownerKeyString); + String txid = + PublicMethodForMultiSign.accountPermissionUpdateForTransactionId( + accountPermissionJson, + participateAddress, + participateKey, + blockingStubFull, + ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - long balanceAfter = PublicMethod.queryAccount(participateAddress, blockingStubFull) - .getBalance(); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); + long balanceAfter = + PublicMethod.queryAccount(participateAddress, blockingStubFull).getBalance(); long energyFee = infoById.get().getReceipt().getEnergyFee(); long netFee = infoById.get().getReceipt().getNetFee(); long fee = infoById.get().getFee(); @@ -245,17 +287,22 @@ public void testMultiSign3ParticipateAssetissue() { balanceBefore = balanceAfter; - txid = PublicMethodForMultiSign.participateAssetIssueForTransactionId(ownerAddress, - assetAccountId1.toByteArray(), 10, participateAddress, participateKey, 0, - blockingStubFull, ownerKeyString); + txid = + PublicMethodForMultiSign.participateAssetIssueForTransactionId( + ownerAddress, + assetAccountId1.toByteArray(), + 10, + participateAddress, + participateKey, + 0, + blockingStubFull, + ownerKeyString); Assert.assertNotNull(txid); PublicMethod.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); - balanceAfter = PublicMethod.queryAccount(participateAddress, blockingStubFull) - .getBalance(); + infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); + balanceAfter = PublicMethod.queryAccount(participateAddress, blockingStubFull).getBalance(); energyFee = infoById.get().getReceipt().getEnergyFee(); netFee = infoById.get().getReceipt().getNetFee(); fee = infoById.get().getFee(); @@ -269,26 +316,33 @@ public void testMultiSign3ParticipateAssetissue() { Assert.assertEquals(fee, energyFee + netFee + multiSignFee); } - /** - * constructor. - */ - - @Test(enabled = true, groups = {"multisig", "smoke"}) + /** constructor. */ + @Test( + enabled = true, + groups = {"multisig", "smoke"}) public void testMultiSign4updateAssetissue() { url = "MultiSign001_update_url" + Long.toString(now); ownerKeyString[0] = ownerKey; description = "MultiSign001_update_description" + Long.toString(now); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); - String txid = PublicMethodForMultiSign - .updateAssetForTransactionId(ownerAddress, description.getBytes(), url.getBytes(), 100L, - 100L, ownerKey, 2, blockingStubFull, permissionKeyString); + String txid = + PublicMethodForMultiSign.updateAssetForTransactionId( + ownerAddress, + description.getBytes(), + url.getBytes(), + 100L, + 100L, + ownerKey, + 2, + blockingStubFull, + permissionKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); long energyFee = infoById.get().getReceipt().getEnergyFee(); long netFee = infoById.get().getReceipt().getNetFee(); @@ -303,12 +357,7 @@ public void testMultiSign4updateAssetissue() { Assert.assertEquals(fee, energyFee + netFee + multiSignFee); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/multisign/WalletTestMultiSign003.java b/testcase/src/test/java/stest/tron/wallet/multisign/WalletTestMultiSign003.java index b7965fe3..3bd8c09c 100644 --- a/testcase/src/test/java/stest/tron/wallet/multisign/WalletTestMultiSign003.java +++ b/testcase/src/test/java/stest/tron/wallet/multisign/WalletTestMultiSign003.java @@ -15,11 +15,12 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class WalletTestMultiSign003 extends TronBaseTest { ByteString assetAccountId1; +public class WalletTestMultiSign003 extends TronBaseTest { + ByteString assetAccountId1; String[] permissionKeyString = new String[2]; String[] ownerKeyString = new String[3]; String accountPermissionJson = ""; @@ -35,19 +36,18 @@ public class WalletTestMultiSign003 extends TronBaseTest { ByteString assetAcco ECKey ecKey4 = new ECKey(Utils.getRandom()); byte[] newAddress = ecKey4.getAddress(); String newKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - - /** - * constructor. - */ + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, groups = {"multisig", "smoke"}) + @Test( + enabled = true, + groups = {"multisig", "smoke"}) public void testMultiSignForAccount() { ecKey1 = new ECKey(Utils.getRandom()); manager1Address = ecKey1.getAddress(); @@ -69,16 +69,25 @@ public void testMultiSignForAccount() { long needCoin = updateAccountPermissionFee * 1 + multiSignFee * 9; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, needCoin + 100000000L, foundationAddress, foundationKey, + PublicMethod.sendcoin( + ownerAddress, + needCoin + 100000000L, + foundationAddress, + foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(foundationAddress, 1000000000, 0, 0, ByteString.copyFrom(ownerAddress), - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + 1000000000, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -88,26 +97,35 @@ public void testMultiSignForAccount() { ownerKeyString[2] = manager2Key; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":3,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - String txid = PublicMethodForMultiSign - .accountPermissionUpdateForTransactionId(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerKeyString); - final String updateName = Long.toString(System.currentTimeMillis()); + String txid = + PublicMethodForMultiSign.accountPermissionUpdateForTransactionId( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); + final String updateName = Long.toString(System.currentTimeMillis()); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertNotNull(txid); - Optional infoById = PublicMethod - .getTransactionInfoById(txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(txid, blockingStubFull); long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); long energyFee = infoById.get().getReceipt().getEnergyFee(); long netFee = infoById.get().getReceipt().getNetFee(); @@ -123,29 +141,44 @@ public void testMultiSignForAccount() { balanceBefore = balanceAfter; - Assert.assertTrue(PublicMethodForMultiSign.createAccount( - ownerAddress, newAddress, ownerKey, blockingStubFull, ownerKeyString)); - - Assert.assertTrue(PublicMethodForMultiSign.sendcoinWithPermissionId( - newAddress, 100L, ownerAddress, 2, ownerKey, blockingStubFull, permissionKeyString)); - Assert.assertTrue(PublicMethodForMultiSign.freezeBalanceWithPermissionId( - ownerAddress, 1000000L, 0, 0, ownerKey, blockingStubFull, ownerKeyString)); - Assert.assertTrue(PublicMethodForMultiSign.freezeBalanceGetEnergy( - ownerAddress, 1000000L, 0, 2, ownerKey, blockingStubFull, ownerKeyString)); - Assert.assertTrue(PublicMethodForMultiSign.freezeBalanceForReceiver( - ownerAddress, 1000000L, 0, 0, ByteString.copyFrom(newAddress), - ownerKey, blockingStubFull, ownerKeyString)); - Assert.assertTrue(PublicMethodForMultiSign.unFreezeBalance( - ownerAddress, ownerKey, 0, null, blockingStubFull, ownerKeyString)); - Assert.assertTrue(PublicMethodForMultiSign.unFreezeBalanceWithPermissionId( - ownerAddress, ownerKey, 0, newAddress, 2, blockingStubFull, permissionKeyString)); - Assert.assertTrue(PublicMethodForMultiSign.updateAccount( - ownerAddress, updateName.getBytes(), ownerKey, blockingStubFull, ownerKeyString)); - String voteStr = Base58.encode58Check(witnessAddress); + Assert.assertTrue( + PublicMethodForMultiSign.createAccount( + ownerAddress, newAddress, ownerKey, blockingStubFull, ownerKeyString)); + + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + newAddress, 100L, ownerAddress, 2, ownerKey, blockingStubFull, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.freezeBalanceWithPermissionId( + ownerAddress, 1000000L, 0, 0, ownerKey, blockingStubFull, ownerKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.freezeBalanceGetEnergy( + ownerAddress, 1000000L, 0, 2, ownerKey, blockingStubFull, ownerKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.freezeBalanceForReceiver( + ownerAddress, + 1000000L, + 0, + 0, + ByteString.copyFrom(newAddress), + ownerKey, + blockingStubFull, + ownerKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.unFreezeBalance( + ownerAddress, ownerKey, 0, null, blockingStubFull, ownerKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.unFreezeBalanceWithPermissionId( + ownerAddress, ownerKey, 0, newAddress, 2, blockingStubFull, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.updateAccount( + ownerAddress, updateName.getBytes(), ownerKey, blockingStubFull, ownerKeyString)); + String voteStr = Base58.encode58Check(witnessAddress); HashMap smallVoteMap = new HashMap(); smallVoteMap.put(voteStr, "1"); - Assert.assertTrue(PublicMethodForMultiSign.voteWitness( - smallVoteMap, ownerAddress, ownerKey, blockingStubFull, ownerKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.voteWitness( + smallVoteMap, ownerAddress, ownerKey, blockingStubFull, ownerKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); @@ -154,15 +187,11 @@ public void testMultiSignForAccount() { Assert.assertEquals(balanceBefore - balanceAfter, multiSignFee * 9 + 1000000 + 100); Assert.assertTrue( - PublicMethod.unFreezeBalance(foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull)); - + PublicMethod.unFreezeBalance( + foundationAddress, foundationKey, 0, ownerAddress, blockingStubFull)); } - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/multisign/WalletTestMultiSign004.java b/testcase/src/test/java/stest/tron/wallet/multisign/WalletTestMultiSign004.java index a8631c62..64745d13 100644 --- a/testcase/src/test/java/stest/tron/wallet/multisign/WalletTestMultiSign004.java +++ b/testcase/src/test/java/stest/tron/wallet/multisign/WalletTestMultiSign004.java @@ -9,7 +9,6 @@ import java.util.Random; import lombok.extern.slf4j.Slf4j; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.WalletGrpc; @@ -19,15 +18,16 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; +import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; -import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; @Slf4j @MultiNode -public class WalletTestMultiSign004 extends TronBaseTest { ArrayList txidList = new ArrayList(); +public class WalletTestMultiSign004 extends TronBaseTest { + ArrayList txidList = new ArrayList(); Optional infoById = null; Long beforeTime; Long afterTime; @@ -47,23 +47,20 @@ public class WalletTestMultiSign004 extends TronBaseTest { ArrayList tx ECKey ecKey3 = new ECKey(Utils.getRandom()); byte[] ownerAddress = ecKey3.getAddress(); String ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); private ManagedChannel channelFull1 = null; - private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - - - /** - * constructor. - */ - + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + public void beforeClass() { + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } @Test(enabled = true, threadPoolSize = 1, invocationCount = 1) @@ -84,19 +81,32 @@ public void testMultiSignForSmartContract() { long needcoin = updateAccountPermissionFee + multiSignFee * 3; Assert.assertTrue( - PublicMethod.sendcoin(ownerAddress, needcoin + 100000000L, fromAddress, foundationKey2, - blockingStubFull)); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(fromAddress, 1000000000, 0, 0, ByteString.copyFrom(ownerAddress), - foundationKey2, blockingStubFull)); - Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(fromAddress, 1000000000, 0, 1, ByteString.copyFrom(ownerAddress), + PublicMethod.sendcoin( + ownerAddress, needcoin + 100000000L, foundationAddress2, foundationKey2, blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress2, + 1000000000, + 0, + 0, + ByteString.copyFrom(ownerAddress), + foundationKey2, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress2, + 1000000000, + 0, + 1, + ByteString.copyFrom(ownerAddress), + foundationKey2, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull) - .getBalance(); + Long balanceBefore = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; @@ -106,51 +116,78 @@ public void testMultiSignForSmartContract() { ownerKeyString[1] = manager1Key; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerKeyString); + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); Random rand = new Random(); Integer randNum = rand.nextInt(30) + 1; randNum = rand.nextInt(4000); Long maxFeeLimit = 1000000000L; - //String contractName = "StorageAndCpu" + Integer.toString(randNum); + // String contractName = "StorageAndCpu" + Integer.toString(randNum); String filePath = "./src/test/resources/soliditycode/walletTestMultiSign004.sol"; String contractName = "timeoutTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - byte[] contractAddress = PublicMethodForMultiSign.deployContract(contractName, abi, code, - "", maxFeeLimit, - 0L, 100, null, ownerKey, ownerAddress, blockingStubFull, ownerKeyString); + byte[] contractAddress = + PublicMethodForMultiSign.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + ownerKey, + ownerAddress, + blockingStubFull, + ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString() != null); String txid; String initParmes = "\"" + "930" + "\""; - txid = PublicMethodForMultiSign.triggerContract(contractAddress, - "testUseCpu(uint256)", initParmes, false, - 0, maxFeeLimit, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); + txid = + PublicMethodForMultiSign.triggerContract( + contractAddress, + "testUseCpu(uint256)", + initParmes, + false, + 0, + maxFeeLimit, + ownerAddress, + ownerKey, + blockingStubFull, + ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); logger.info("Txid is " + txid); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); Assert.assertTrue(infoById.get().getBlockNumber() > 0); - PublicMethodForMultiSign.updateSettingWithPermissionId(contractAddress, 50, ownerKey, - ownerAddress, 0, blockingStubFull, ownerKeyString); + PublicMethodForMultiSign.updateSettingWithPermissionId( + contractAddress, 50, ownerKey, ownerAddress, 0, blockingStubFull, ownerKeyString); PublicMethod.waitProduceNextBlock(blockingStubFull); long balanceAfter = PublicMethod.queryAccount(ownerAddress, blockingStubFull).getBalance(); @@ -159,8 +196,10 @@ public void testMultiSignForSmartContract() { Assert.assertEquals(balanceBefore - balanceAfter, needcoin); Assert.assertTrue( - PublicMethod.unFreezeBalance(fromAddress, foundationKey2, 0, ownerAddress, blockingStubFull)); + PublicMethod.unFreezeBalance( + fromAddress, foundationKey2, 0, ownerAddress, blockingStubFull)); Assert.assertTrue( - PublicMethod.unFreezeBalance(fromAddress, foundationKey2, 1, ownerAddress, blockingStubFull)); + PublicMethod.unFreezeBalance( + fromAddress, foundationKey2, 1, ownerAddress, blockingStubFull)); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/multisign/WalletTestMultiSign005.java b/testcase/src/test/java/stest/tron/wallet/multisign/WalletTestMultiSign005.java index 7a2c06cb..0f8d49e2 100644 --- a/testcase/src/test/java/stest/tron/wallet/multisign/WalletTestMultiSign005.java +++ b/testcase/src/test/java/stest/tron/wallet/multisign/WalletTestMultiSign005.java @@ -1,6 +1,5 @@ package stest.tron.wallet.multisign; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.HashMap; import java.util.Map; @@ -19,9 +18,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class WalletTestMultiSign005 extends TronBaseTest { @@ -37,30 +35,33 @@ public class WalletTestMultiSign005 extends TronBaseTest { ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] manager2Address = ecKey2.getAddress(); String manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); - private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.updateAccountPermissionFee"); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ - + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.updateAccountPermissionFee"); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + + /** constructor. */ @BeforeClass - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, groups = {"multisig", "smoke"}) + @Test( + enabled = true, + groups = {"multisig", "smoke"}) public void testMultiSignForProposal() { long needcoin = updateAccountPermissionFee + multiSignFee * 3; - Assert.assertTrue(PublicMethod.sendcoin(witness001Address, needcoin + 10000000L, - foundationAddress, foundationKey, blockingStubFull)); - + Assert.assertTrue( + PublicMethod.sendcoin( + witness001Address, + needcoin + 10000000L, + foundationAddress, + foundationKey, + blockingStubFull)); + PublicMethod.waitProduceNextBlock(blockingStubFull); ecKey1 = new ECKey(Utils.getRandom()); manager1Address = ecKey1.getAddress(); manager1Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -69,45 +70,49 @@ public void testMultiSignForProposal() { manager2Address = ecKey2.getAddress(); manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceBefore = PublicMethod.queryAccount(witness001Address, blockingStubFull) - .getBalance(); + Long balanceBefore = + PublicMethod.queryAccount(witness001Address, blockingStubFull).getBalance(); logger.info("balanceBefore: " + balanceBefore); permissionKeyString[0] = manager1Key; permissionKeyString[1] = manager2Key; - PublicMethod.waitProduceNextBlock(blockingStubFull); ownerKeyString[0] = witnessKey; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":2}]}," + "\"witness_permission\":{\"type\":1,\"permission_name\":\"owner\",\"threshold\":1,\"" - + "keys\":[{\"address\":\"" + PublicMethod.getAddressString(witnessKey) + + "keys\":[{\"address\":\"" + + PublicMethod.getAddressString(witnessKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); PublicMethodForMultiSign.accountPermissionUpdate( - accountPermissionJson, witness001Address, witnessKey, - blockingStubFull, ownerKeyString); - //Create a proposal - Long proposalValue = 819699L; + accountPermissionJson, witness001Address, witnessKey, blockingStubFull, ownerKeyString); + // Create a proposal + PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); HashMap proposalMap = new HashMap(); + Long proposalValue = 819699L; proposalMap.put(0L, proposalValue); Assert.assertTrue( - PublicMethodForMultiSign.createProposalWithPermissionId(witness001Address, witnessKey, - proposalMap, 2, blockingStubFull, permissionKeyString)); + PublicMethodForMultiSign.createProposalWithPermissionId( + witness001Address, witnessKey, proposalMap, 2, blockingStubFull, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Get proposal list + // Get proposal list ProposalList proposalList = blockingStubFull.listProposals(EmptyMessage.newBuilder().build()); Optional listProposals = Optional.ofNullable(proposalList); - Integer proposalId = 0; + Integer proposalId = -1; for (Proposal proposal : listProposals.get().getProposalsList()) { for (Map.Entry entry : proposal.getParametersMap().entrySet()) { if (entry.getValue() == proposalValue) { @@ -115,32 +120,37 @@ public void testMultiSignForProposal() { break; } } + if (proposalId != -1) { + break; + } } final Integer finalProposalId = proposalId; - logger.info(Integer.toString(proposalId)); + logger.info(Integer.toString(finalProposalId)); - Assert.assertTrue(PublicMethodForMultiSign.approveProposalWithPermission( - witness001Address, witnessKey, proposalId, - true, 2, blockingStubFull, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.approveProposalWithPermission( + witness001Address, + witnessKey, + finalProposalId, + true, + 2, + blockingStubFull, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Delete proposal list after approve - Assert.assertTrue(PublicMethodForMultiSign.deleteProposalWithPermissionId( - witness001Address, witnessKey, proposalId, 2, blockingStubFull, permissionKeyString)); + // Delete proposal list after approve + Assert.assertTrue( + PublicMethodForMultiSign.deleteProposalWithPermissionId( + witness001Address, witnessKey, finalProposalId, 2, + blockingStubFull, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Long balanceAfter = PublicMethod.queryAccount(witness001Address, blockingStubFull) - .getBalance(); + Long balanceAfter = PublicMethod.queryAccount(witness001Address, blockingStubFull).getBalance(); logger.info("balanceAfter: " + balanceAfter); Assert.assertTrue(balanceBefore - balanceAfter >= needcoin); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/CreateAccount2Test.java b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/CreateAccount2Test.java index 6552b732..d668dc29 100644 --- a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/CreateAccount2Test.java +++ b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/CreateAccount2Test.java @@ -1,18 +1,16 @@ package stest.tron.wallet.newaddinterface2; -import io.grpc.ManagedChannel; import lombok.extern.slf4j.Slf4j; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI; import org.tron.api.GrpcAPI.AccountNetMessage; import org.tron.protos.Protocol.Account; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; @Slf4j @@ -24,65 +22,64 @@ public class CreateAccount2Test extends TronBaseTest { private static final long FREENETLIMIT = 5000L; private static final long BASELINE = 4800L; private static String name = "AssetIssue012_" + Long.toString(now); - //owner account + // owner account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] account007Address = ecKey1.getAddress(); String account007Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - //Wait to be create account + // Wait to be create account ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] newAccountAddress = ecKey2.getAddress(); String newAccountKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - logger.info(account007Key); Assert.assertTrue(PublicMethod.sendcoin(account007Address, 10000000, - fromAddress, foundationKey, blockingStubFull)); + logger.info(account007Key); + Assert.assertTrue( + PublicMethod.sendcoin( + account007Address, 10000000, fromAddress, foundationKey, blockingStubFull)); } @Test(enabled = true) public void testCreateAccount2() { Account accountInfo = PublicMethod.queryAccount(account007Key, blockingStubFull); final Long beforeBalance = accountInfo.getBalance(); - AccountNetMessage accountNetInfo = PublicMethod.getAccountNet(account007Address, - blockingStubFull); + AccountNetMessage accountNetInfo = + PublicMethod.getAccountNet(account007Address, blockingStubFull); final Long beforeFreeNet = accountNetInfo.getFreeNetUsed(); - GrpcAPI.Return ret1 = PublicMethod.createAccount2(account007Address, newAccountAddress, - account007Key, blockingStubFull); + GrpcAPI.Return ret1 = + PublicMethod.createAccount2( + account007Address, newAccountAddress, account007Key, blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); accountInfo = PublicMethod.queryAccount(account007Key, blockingStubFull); Long afterBalance = accountInfo.getBalance(); - accountNetInfo = PublicMethod.getAccountNet(account007Address, - blockingStubFull); + accountNetInfo = PublicMethod.getAccountNet(account007Address, blockingStubFull); Long afterFreeNet = accountNetInfo.getFreeNetUsed(); logger.info(Long.toString(beforeBalance)); logger.info(Long.toString(afterBalance)); - //When creator has no bandwidth, he can't use the free net. + // When creator has no bandwidth, he can't use the free net. Assert.assertTrue(afterFreeNet == beforeFreeNet); - //When the creator has no bandwidth, create a new account should spend 0.1TRX. + // When the creator has no bandwidth, create a new account should spend 0.1TRX. Assert.assertTrue(beforeBalance - afterBalance == 100000); } @Test(enabled = true) public void testExceptionCreateAccount2() { - //Try to create an exist account - GrpcAPI.Return ret1 = PublicMethod - .createAccount2(account007Address, account007Address, account007Key, - blockingStubFull); + // Try to create an exist account + GrpcAPI.Return ret1 = + PublicMethod.createAccount2( + account007Address, account007Address, account007Key, blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : Account has existed"); - //Try to create an invalid account + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Account has existed"); + // Try to create an invalid account byte[] wrongAddress = "wrongAddress".getBytes(); - ret1 = PublicMethod.createAccount2(account007Address, wrongAddress, account007Key, - blockingStubFull); + ret1 = + PublicMethod.createAccount2( + account007Address, wrongAddress, account007Key, blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : Invalid account address"); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Invalid account address"); } - - } - +} diff --git a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/CreateAssetIssue2Test.java b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/CreateAssetIssue2Test.java index 634264f2..8d04c411 100644 --- a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/CreateAssetIssue2Test.java +++ b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/CreateAssetIssue2Test.java @@ -1,14 +1,12 @@ package stest.tron.wallet.newaddinterface2; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import java.math.BigInteger; import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.bouncycastle.util.encoders.Hex; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI; @@ -24,57 +22,71 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; +import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class CreateAssetIssue2Test extends TronBaseTest { - private static final byte[] INVAILD_ADDRESS = Base58 - .decodeFromBase58Check("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48"); + private static final byte[] INVAILD_ADDRESS = + Base58.decodeFromBase58Check("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48"); private static final long now = System.currentTimeMillis(); private static final long totalSupply = now; private static String name = "testAssetIssue001_" + Long.toString(now); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); String description = "just-test-assetissue-001"; String url = "https://github.com/tronprotocol/wallet-cli/assetissue001"; - //get account + // get account ECKey ecKey = new ECKey(Utils.getRandom()); byte[] noBandwitchAddress = ecKey.getAddress(); String noBandwitch = ByteArray.toHexString(ecKey.getPrivKeyBytes()); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - logger.info(ByteArray.toHexString(ecKey.getPrivKeyBytes())); } + logger.info(ByteArray.toHexString(ecKey.getPrivKeyBytes())); + } @Test() public void testTransferAssetBandwitchDecreaseWithin10Second2() { ByteString addressBS1 = ByteString.copyFrom(noBandwitchAddress); Account request1 = Account.newBuilder().setAddress(addressBS1).build(); - GrpcAPI.AssetIssueList assetIssueList1 = blockingStubFull - .getAssetIssueByAccount(request1); + GrpcAPI.AssetIssueList assetIssueList1 = blockingStubFull.getAssetIssueByAccount(request1); Optional queryAssetByAccount = Optional.ofNullable(assetIssueList1); if (queryAssetByAccount.get().getAssetIssueCount() == 0) { - Assert.assertTrue(PublicMethod.sendcoin(noBandwitchAddress, 2048000000, - fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + noBandwitchAddress, 2048000000, fromAddress, foundationKey, blockingStubFull)); Long start = System.currentTimeMillis() + 2000000; Long end = System.currentTimeMillis() + 1000000000; - GrpcAPI.Return ret1 = PublicMethod.createAssetIssue2(noBandwitchAddress, name, totalSupply, 1, - 100, start, end, 1, description, url, 10000L, 10000L, - 1L, 1L, noBandwitch, blockingStubFull); + GrpcAPI.Return ret1 = + PublicMethod.createAssetIssue2( + noBandwitchAddress, + name, + totalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + noBandwitch, + blockingStubFull); Assert.assertEquals(ret1.getCode(), Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); } else { @@ -85,61 +97,66 @@ public void testTransferAssetBandwitchDecreaseWithin10Second2() { Assert.assertTrue( transferAsset(toAddress, name.getBytes(), 100L, noBandwitchAddress, noBandwitch)); - //Transfer Asset failed when transfer to yourself - //Assert.assertFalse(transferAsset2(toAddress, name.getBytes(), 100L, toAddress, testKey003)); + // Transfer Asset failed when transfer to yourself + // Assert.assertFalse(transferAsset2(toAddress, name.getBytes(), 100L, toAddress, testKey003)); Return ret1 = transferAsset2(toAddress, name.getBytes(), 100L, toAddress, testKey003); Assert.assertEquals(ret1.getCode(), Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "contract validate error : Cannot transfer asset to yourself."); - //Transfer Asset failed when the transfer amount is large than the asset balance you have. + // Transfer Asset failed when the transfer amount is large than the asset balance you have. ret1 = transferAsset2(fromAddress, name.getBytes(), 9100000000000000000L, toAddress, testKey003); Assert.assertEquals(ret1.getCode(), Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "contract validate error : assetBalance is not sufficient."); - //Transfer Asset failed when the transfer amount is 0 + // Transfer Asset failed when the transfer amount is 0 ret1 = transferAsset2(fromAddress, name.getBytes(), 0L, toAddress, testKey003); Assert.assertEquals(ret1.getCode(), Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "contract validate error : Amount must greater than 0."); - //Transfer Asset failed when the transfer amount is -1 + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "contract validate error : Amount must greater than 0."); + // Transfer Asset failed when the transfer amount is -1 ret1 = transferAsset2(fromAddress, name.getBytes(), -1L, toAddress, testKey003); Assert.assertEquals(ret1.getCode(), Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "contract validate error : Amount must greater than 0."); - //Transfer failed when you want to transfer to an invalid address - ret1 = transferAsset2(INVAILD_ADDRESS, name.getBytes(), - 1L, toAddress, testKey003); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "contract validate error : Amount must greater than 0."); + // Transfer failed when you want to transfer to an invalid address + ret1 = transferAsset2(INVAILD_ADDRESS, name.getBytes(), 1L, toAddress, testKey003); Assert.assertEquals(ret1.getCode(), Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "contract validate error : Invalid toAddress"); - //Transfer failed when the asset issue name is not correct. - ret1 = - transferAsset2(fromAddress, (name + "wrong").getBytes(), 1L, toAddress, testKey003); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "contract validate error : Invalid toAddress"); + // Transfer failed when the asset issue name is not correct. + ret1 = transferAsset2(fromAddress, (name + "wrong").getBytes(), 1L, toAddress, testKey003); Assert.assertEquals(ret1.getCode(), Return.response_code.CONTRACT_VALIDATE_ERROR); Assert.assertEquals(ret1.getMessage().toStringUtf8(), "contract validate error : No asset !"); - //Transfer success. + // Transfer success. ret1 = transferAsset2(fromAddress, name.getBytes(), 1L, toAddress, testKey003); Assert.assertEquals(ret1.getCode(), Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); - //No freeze asset, try to unfreeze asset failed. + // No freeze asset, try to unfreeze asset failed. Assert.assertFalse(unFreezeAsset(noBandwitchAddress, noBandwitch)); logger.info("Test no asset frozen balance, try to unfreeze asset, no exception. Test OK!!!"); - //Not create asset, try to unfreeze asset failed.No exception. + // Not create asset, try to unfreeze asset failed.No exception. Assert.assertFalse(unFreezeAsset(toAddress, testKey003)); logger.info("Test not create asset issue, try to unfreeze asset, no exception. Test OK!!!"); - } - /** - * constructor. - */ - - public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, Integer trxNum, - Integer icoNum, Long startTime, Long endTime, - Integer voteScore, String description, String url, String priKey) { + /** constructor. */ + public Boolean createAssetIssue( + byte[] address, + String name, + Long totalSupply, + Integer trxNum, + Integer icoNum, + Long startTime, + Long endTime, + Integer voteScore, + String description, + String url, + String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -183,14 +200,11 @@ public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, I } } - /** - * constructor. - */ - + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; @@ -206,20 +220,14 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ - + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ - + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); @@ -235,12 +243,9 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } - /** - * constructor. - */ - - public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] address, - String priKey) { + /** constructor. */ + public boolean transferAsset( + byte[] to, byte[] assertName, long amount, byte[] address, String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -272,15 +277,11 @@ public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] a Account search = queryAccount(ecKey, blockingStubFull); return true; } - } - /** - * constructor. - */ - - public Return transferAsset2(byte[] to, byte[] assertName, long amount, byte[] address, - String priKey) { + /** constructor. */ + public Return transferAsset2( + byte[] to, byte[] assertName, long amount, byte[] address, String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -325,15 +326,12 @@ public Return transferAsset2(byte[] to, byte[] assertName, long amount, byte[] a return response; } else { Account search = queryAccount(ecKey, blockingStubFull); - //return true; + // return true; } return ret; } - /** - * constructor. - */ - + /** constructor. */ public boolean unFreezeAsset(byte[] addRess, String priKey) { byte[] address = addRess; ECKey temKey = null; @@ -344,8 +342,7 @@ public boolean unFreezeAsset(byte[] addRess, String priKey) { ex.printStackTrace(); } final ECKey ecKey = temKey; - UnfreezeAssetContract.Builder builder = UnfreezeAssetContract - .newBuilder(); + UnfreezeAssetContract.Builder builder = UnfreezeAssetContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddreess); UnfreezeAssetContract contract = builder.build(); @@ -364,4 +361,3 @@ public boolean unFreezeAsset(byte[] addRess, String priKey) { } } } - diff --git a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/CreateTransaction2Test.java b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/CreateTransaction2Test.java index 9dad3326..ff11c897 100644 --- a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/CreateTransaction2Test.java +++ b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/CreateTransaction2Test.java @@ -24,12 +24,12 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; +import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; -import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; @Slf4j @MultiNode public class CreateTransaction2Test extends TronBaseTest { @@ -37,19 +37,24 @@ public class CreateTransaction2Test extends TronBaseTest { { fullnode = config.getStringList("fullnode.ip.list").get(1); } - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); /* //testng001、testng002、testng003、testng004 private static final byte[] fromAddress = Base58 .decodeFromBase58Check("THph9K2M2nLvkianrMGswRhz5hjSA9fuH7"); private static final byte[] toAddress = Base58 - .decodeFromBase58Check("TV75jZpdmP2juMe1dRwGrwpV6AMU6mr1EU");*/ private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); - //receipt account + .decodeFromBase58Check("TV75jZpdmP2juMe1dRwGrwpV6AMU6mr1EU");*/ + private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); + // receipt account ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] receiptAccountAddress = ecKey2.getAddress(); - String receiptAccountKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); private ManagedChannel searchChannelFull = null; private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; private String searchFullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + String receiptAccountKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + private ManagedChannel searchChannelFull = null; + private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; + private String searchFullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] sendAccountAddress = ecKey1.getAddress(); String sendAccountKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -59,22 +64,18 @@ public static String loadPubKey() { return String.valueOf(buf, 32, 130); } - /** - * constructor. - */ - + /** constructor. */ @BeforeClass - public void beforeClass() { searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode) - .usePlaintext() - .build(); + public void beforeClass() { + searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode).usePlaintext().build(); searchBlockingStubFull = WalletGrpc.newBlockingStub(searchChannelFull); - } @Test public void testSendCoin2() { - Assert.assertTrue(PublicMethod.sendcoin(sendAccountAddress, 90000000000L, - fromAddress, foundationKey2, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + sendAccountAddress, 90000000000L, fromAddress, foundationKey2, blockingStubFull)); logger.info(receiptAccountKey); Account sendAccount = PublicMethod.queryAccount(sendAccountKey, blockingStubFull); @@ -83,9 +84,14 @@ public void testSendCoin2() { Account receiptAccount = PublicMethod.queryAccount(receiptAccountKey, blockingStubFull); Long receiptAccountBeforeBalance = receiptAccount.getBalance(); Assert.assertTrue(receiptAccountBeforeBalance == 0); - //normal sendcoin2 - Return ret1 = PublicMethod.sendcoin2(receiptAccountAddress, 49880000000L, - sendAccountAddress, sendAccountKey, blockingStubFull); + // normal sendcoin2 + Return ret1 = + PublicMethod.sendcoin2( + receiptAccountAddress, + 49880000000L, + sendAccountAddress, + sendAccountKey, + blockingStubFull); Assert.assertEquals(ret1.getCode(), Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); @@ -97,36 +103,51 @@ public void testSendCoin2() { receiptAccount = PublicMethod.queryAccount(receiptAccountKey, blockingStubFull); Long receiptAccountAfterBalance = receiptAccount.getBalance(); Assert.assertTrue(receiptAccountAfterBalance == 49880000000L); - //Send coin failed due to no enough balance. - ret1 = PublicMethod - .sendcoin2(receiptAccountAddress, 9199999999999999999L, sendAccountAddress, sendAccountKey, + // Send coin failed due to no enough balance. + ret1 = + PublicMethod.sendcoin2( + receiptAccountAddress, + 9199999999999999999L, + sendAccountAddress, + sendAccountKey, blockingStubFull); Assert.assertEquals(ret1.getCode(), Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Validate TransferContract error, balance is not sufficient."); - //Send coin failed due to the amount is 0. - ret1 = PublicMethod - .sendcoin2(receiptAccountAddress, 0L, sendAccountAddress, sendAccountKey, blockingStubFull); + // Send coin failed due to the amount is 0. + ret1 = + PublicMethod.sendcoin2( + receiptAccountAddress, 0L, sendAccountAddress, sendAccountKey, blockingStubFull); Assert.assertEquals(ret1.getCode(), Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Amount must be greater than 0."); - //Send coin failed due to the amount is -1Trx. - ret1 = PublicMethod - .sendcoin2(receiptAccountAddress, -1000000L, sendAccountAddress, sendAccountKey, - blockingStubFull); + // Send coin failed due to the amount is -1Trx. + ret1 = + PublicMethod.sendcoin2( + receiptAccountAddress, -1000000L, sendAccountAddress, sendAccountKey, blockingStubFull); Assert.assertEquals(ret1.getCode(), Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Amount must be greater than 0.."); - //Send coin to yourself - ret1 = PublicMethod.sendcoin2(sendAccountAddress, 1000000L, sendAccountAddress, sendAccountKey, - blockingStubFull); + // Send coin to yourself + ret1 = + PublicMethod.sendcoin2( + sendAccountAddress, 1000000L, sendAccountAddress, sendAccountKey, blockingStubFull); Assert.assertEquals(ret1.getCode(), Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Cannot transfer trx to yourself."); - //transfer all balance - ret1 = PublicMethod.sendcoin2(receiptAccountAddress, 40119900000L, - sendAccountAddress, sendAccountKey, blockingStubFull); + // transfer all balance + ret1 = + PublicMethod.sendcoin2( + receiptAccountAddress, + 40119900000L, + sendAccountAddress, + sendAccountKey, + blockingStubFull); Assert.assertEquals(ret1.getCode(), Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); @@ -142,10 +163,7 @@ public void testSendCoin2() { Assert.assertTrue(receiptAccountAfterBalance1 == 49880000000L + 40119900000L); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { if (channelFull != null) { @@ -156,17 +174,14 @@ public void shutdown() throws InterruptedException { } } - /** - * constructor. - */ - - public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDuration, - String priKey) { + /** constructor. */ + public Boolean freezeBalance( + byte[] addRess, long freezeBalance, long freezeDuration, String priKey) { byte[] address = addRess; long frozenBalance = freezeBalance; long frozenDuration = freezeDuration; - //String priKey = foundationKey2; + // String priKey = foundationKey2; ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -179,18 +194,20 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura final Long beforeBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Account beforeFronzen = queryAccount(ecKey, blockingStubFull); Long beforeFrozenBalance = 0L; - //Long beforeBandwidth = beforeFronzen.getBandwidth(); + // Long beforeBandwidth = beforeFronzen.getBandwidth(); if (beforeFronzen.getFrozenCount() != 0) { beforeFrozenBalance = beforeFronzen.getFrozen(0).getFrozenBalance(); - //beforeBandwidth = beforeFronzen.getBandwidth(); - //logger.info(Long.toString(beforeFronzen.getBandwidth())); + // beforeBandwidth = beforeFronzen.getBandwidth(); + // logger.info(Long.toString(beforeFronzen.getBandwidth())); logger.info(Long.toString(beforeFronzen.getFrozen(0).getFrozenBalance())); } FreezeBalanceContract.Builder builder = FreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess).setFrozenBalance(frozenBalance) + builder + .setOwnerAddress(byteAddreess) + .setFrozenBalance(frozenBalance) .setFrozenDuration(frozenDuration); FreezeBalanceContract contract = builder.build(); @@ -213,8 +230,8 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura Long afterBlockNum = 0L; Integer wait = 0; while (afterBlockNum < beforeBlockNum + 1 && wait < 10) { - Block currentBlock1 = searchBlockingStubFull - .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); + Block currentBlock1 = + searchBlockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); afterBlockNum = currentBlock1.getBlockHeader().getRawData().getNumber(); wait++; try { @@ -227,26 +244,24 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura Account afterFronzen = queryAccount(ecKey, searchBlockingStubFull); Long afterFrozenBalance = afterFronzen.getFrozen(0).getFrozenBalance(); - //Long afterBandwidth = afterFronzen.getBandwidth(); - //logger.info(Long.toString(afterFronzen.getBandwidth())); + // Long afterBandwidth = afterFronzen.getBandwidth(); + // logger.info(Long.toString(afterFronzen.getBandwidth())); logger.info(Long.toString(afterFronzen.getFrozen(0).getFrozenBalance())); - //logger.info(Integer.toString(search.getFrozenCount())); + // logger.info(Integer.toString(search.getFrozenCount())); logger.info( - "beforefronen" + beforeFrozenBalance.toString() + " afterfronzen" + afterFrozenBalance - .toString()); + "beforefronen" + + beforeFrozenBalance.toString() + + " afterfronzen" + + afterFrozenBalance.toString()); Assert.assertTrue(afterFrozenBalance - beforeFrozenBalance == freezeBalance); - //Assert.assertTrue(afterBandwidth - beforeBandwidth == freezeBalance * frozen_duration); + // Assert.assertTrue(afterBandwidth - beforeBandwidth == freezeBalance * frozen_duration); return true; - } - /** - * constructor. - */ - + /** constructor. */ public Boolean sendcoin(byte[] to, long amount, byte[] owner, String priKey) { - //String priKey = foundationKey2; + // String priKey = foundationKey2; ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -278,14 +293,11 @@ public Boolean sendcoin(byte[] to, long amount, byte[] owner, String priKey) { } } - /** - * constructor. - */ - + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; @@ -301,25 +313,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ - + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ - + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -331,4 +336,3 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } } - diff --git a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/CreateaAndUpdateWitness2Test.java b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/CreateaAndUpdateWitness2Test.java index e4cb9ec8..e301bd0f 100644 --- a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/CreateaAndUpdateWitness2Test.java +++ b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/CreateaAndUpdateWitness2Test.java @@ -24,15 +24,16 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - //import stest.tron.wallet.common.client.AccountComparator; +import stest.tron.wallet.common.client.utils.Utils; + +// import stest.tron.wallet.common.client.AccountComparator; @Slf4j public class CreateaAndUpdateWitness2Test extends TronBaseTest { - private static final byte[] INVAILD_ADDRESS = Base58 - .decodeFromBase58Check("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48"); + private static final byte[] INVAILD_ADDRESS = + Base58.decodeFromBase58Check("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48"); private static final Long costForCreateWitness = 9999000000L; String createWitnessUrl = "http://www.createwitnessurl.com"; String updateWitnessUrl = "http://www.updatewitnessurl.com"; @@ -42,80 +43,84 @@ public class CreateaAndUpdateWitness2Test extends TronBaseTest { byte[] updateUrl = updateWitnessUrl.getBytes(); byte[] wrongUrl = nullUrl.getBytes(); byte[] updateSpaceUrl = spaceUrl.getBytes(); - //get account + // get account ECKey ecKey = new ECKey(Utils.getRandom()); byte[] lowBalAddress = ecKey.getAddress(); String lowBalTest = ByteArray.toHexString(ecKey.getPrivKeyBytes()); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass public void beforeClass() { logger.info(lowBalTest); logger.info(ByteArray.toHexString(PublicMethod.getFinalAddress(lowBalTest))); - logger.info(Base58.encode58Check(PublicMethod.getFinalAddress(lowBalTest))); } + logger.info(Base58.encode58Check(PublicMethod.getFinalAddress(lowBalTest))); + } @Test(groups = {"smoke"}) public void testInvaildToApplyBecomeWitness2() { GrpcAPI.Return ret1 = createWitness2(INVAILD_ADDRESS, createUrl, foundationKey); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : Invalid address"); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Invalid address"); } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void testCreateWitness2() { - //If you are already is witness, apply failed + // If you are already is witness, apply failed createWitness(foundationAddress, createUrl, foundationKey); GrpcAPI.Return ret1 = createWitness2(foundationAddress, createUrl, foundationKey); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Witness[415624c12e308b03a1a6b21d9b86e3942fac1ab92b] " + "has existed"); - //balance is not enouhg,try to create witness. + // balance is not enouhg,try to create witness. Assert.assertTrue(sendcoin(lowBalAddress, 1000000L, foundationAddress, foundationKey)); ret1 = createWitness2(lowBalAddress, createUrl, lowBalTest); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : balance < AccountUpgradeCost"); - //Send enough coin to the apply account to make that account + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : balance < AccountUpgradeCost"); + // Send enough coin to the apply account to make that account // has ability to apply become witness. - WitnessList witnesslist = blockingStubFull - .listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build()); + WitnessList witnesslist = + blockingStubFull.listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build()); Optional result = Optional.ofNullable(witnesslist); WitnessList witnessList = result.get(); if (result.get().getWitnessesCount() < 6) { - Assert.assertTrue(sendcoin(lowBalAddress, costForCreateWitness, foundationAddress, foundationKey)); + Assert.assertTrue( + sendcoin(lowBalAddress, costForCreateWitness, foundationAddress, foundationKey)); ret1 = createWitness2(lowBalAddress, createUrl, lowBalTest); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); } } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void testUpdateWitness2() { - WitnessList witnesslist = blockingStubFull - .listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build()); + WitnessList witnesslist = + blockingStubFull.listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build()); Optional result = Optional.ofNullable(witnesslist); WitnessList witnessList = result.get(); if (result.get().getWitnessesCount() < 6) { - //null url, update failed + // null url, update failed GrpcAPI.Return ret1 = updateWitness2(lowBalAddress, wrongUrl, lowBalTest); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : Invalid url"); - //Content space and special char, update success + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Invalid url"); + // Content space and special char, update success ret1 = updateWitness2(lowBalAddress, updateSpaceUrl, lowBalTest); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); - //update success + // update success ret1 = updateWitness2(lowBalAddress, updateUrl, lowBalTest); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); @@ -124,16 +129,11 @@ public void testUpdateWitness2() { } } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ + /** constructor. */ public Boolean createWitness(byte[] owner, byte[] url, String priKey) { ECKey temKey = null; try { @@ -144,8 +144,8 @@ public Boolean createWitness(byte[] owner, byte[] url, String priKey) { } final ECKey ecKey = temKey; - WitnessContract.WitnessCreateContract.Builder builder = WitnessContract.WitnessCreateContract - .newBuilder(); + WitnessContract.WitnessCreateContract.Builder builder = + WitnessContract.WitnessCreateContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(owner)); builder.setUrl(ByteString.copyFrom(url)); WitnessContract.WitnessCreateContract contract = builder.build(); @@ -160,12 +160,9 @@ public Boolean createWitness(byte[] owner, byte[] url, String priKey) { } else { return true; } - } - /** - * constructor. - */ + /** constructor. */ public GrpcAPI.Return createWitness2(byte[] owner, byte[] url, String priKey) { ECKey temKey = null; try { @@ -176,8 +173,8 @@ public GrpcAPI.Return createWitness2(byte[] owner, byte[] url, String priKey) { } final ECKey ecKey = temKey; - WitnessContract.WitnessCreateContract.Builder builder = WitnessContract.WitnessCreateContract - .newBuilder(); + WitnessContract.WitnessCreateContract.Builder builder = + WitnessContract.WitnessCreateContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(owner)); builder.setUrl(ByteString.copyFrom(url)); WitnessContract.WitnessCreateContract contract = builder.build(); @@ -209,12 +206,9 @@ public GrpcAPI.Return createWitness2(byte[] owner, byte[] url, String priKey) { return response; } return ret; - } - /** - * constructor. - */ + /** constructor. */ public Boolean updateWitness(byte[] owner, byte[] url, String priKey) { ECKey temKey = null; try { @@ -225,8 +219,8 @@ public Boolean updateWitness(byte[] owner, byte[] url, String priKey) { } final ECKey ecKey = temKey; - WitnessContract.WitnessUpdateContract.Builder builder = WitnessContract.WitnessUpdateContract - .newBuilder(); + WitnessContract.WitnessUpdateContract.Builder builder = + WitnessContract.WitnessUpdateContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(owner)); builder.setUpdateUrl(ByteString.copyFrom(url)); WitnessContract.WitnessUpdateContract contract = builder.build(); @@ -244,12 +238,9 @@ public Boolean updateWitness(byte[] owner, byte[] url, String priKey) { } else { return true; } - } - /** - * constructor. - */ + /** constructor. */ public GrpcAPI.Return updateWitness2(byte[] owner, byte[] url, String priKey) { ECKey temKey = null; try { @@ -260,8 +251,8 @@ public GrpcAPI.Return updateWitness2(byte[] owner, byte[] url, String priKey) { } final ECKey ecKey = temKey; - WitnessContract.WitnessUpdateContract.Builder builder = WitnessContract.WitnessUpdateContract - .newBuilder(); + WitnessContract.WitnessUpdateContract.Builder builder = + WitnessContract.WitnessUpdateContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(owner)); builder.setUpdateUrl(ByteString.copyFrom(url)); WitnessContract.WitnessUpdateContract contract = builder.build(); @@ -296,13 +287,11 @@ public GrpcAPI.Return updateWitness2(byte[] owner, byte[] url, String priKey) { return ret; } - /** - * constructor. - */ + /** constructor. */ public Boolean sendcoin(byte[] to, long amount, byte[] owner, String priKey) { - //String priKey = foundationKey; - ECKey temKey = null; + // String priKey = foundationKey; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -311,8 +300,8 @@ public Boolean sendcoin(byte[] to, long amount, byte[] owner, String priKey) { } final ECKey ecKey = temKey; - BalanceContract.TransferContract.Builder builder = BalanceContract.TransferContract - .newBuilder(); + BalanceContract.TransferContract.Builder builder = + BalanceContract.TransferContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); ByteString bsOwner = ByteString.copyFrom(owner); builder.setToAddress(bsTo); @@ -334,12 +323,10 @@ public Boolean sendcoin(byte[] to, long amount, byte[] owner, String priKey) { } } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -348,13 +335,13 @@ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockin } ECKey ecKey = temKey; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -364,23 +351,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Protocol.Transaction signTransaction(ECKey ecKey, Protocol.Transaction transaction) { @@ -392,5 +374,3 @@ private Protocol.Transaction signTransaction(ECKey ecKey, Protocol.Transaction t return TransactionUtils.sign(transaction, ecKey); } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/FreezeBalance2Test.java b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/FreezeBalance2Test.java index cba324ba..3a32476c 100644 --- a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/FreezeBalance2Test.java +++ b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/FreezeBalance2Test.java @@ -25,11 +25,11 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; - import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; + @Slf4j @MultiNode public class FreezeBalance2Test extends TronBaseTest { @@ -38,68 +38,75 @@ public class FreezeBalance2Test extends TronBaseTest { fullnode = config.getStringList("fullnode.ip.list").get(1); } - //only for test, do not worry + // only for test, do not worry private final String noFrozenBalanceTestKey = - "8CB4480194192F30907E14B52498F594BD046E21D7C4D8FE866563A6760AC891"; private final byte[] noFrozenAddress = PublicMethod.getFinalAddress(noFrozenBalanceTestKey); private ManagedChannel searchChannelFull = null; private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; private String searchFullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + "8CB4480194192F30907E14B52498F594BD046E21D7C4D8FE866563A6760AC891"; + private final byte[] noFrozenAddress = PublicMethod.getFinalAddress(noFrozenBalanceTestKey); + private ManagedChannel searchChannelFull = null; + private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; + private String searchFullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - /** - * constructor. - */ - + /** constructor. */ @BeforeClass - public void beforeClass() { searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode) - .usePlaintext() - .build(); + public void beforeClass() { + searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode).usePlaintext().build(); searchBlockingStubFull = WalletGrpc.newBlockingStub(searchChannelFull); } @Test(enabled = true) public void testFreezeBalance2() { - //Freeze failed when freeze amount is large than currently balance. + // Freeze failed when freeze amount is large than currently balance. Return ret1 = freezeBalance2(fromAddress, 9000000000000000000L, 3L, foundationKey2); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : frozenBalance must be less than accountBalance"); - //Freeze failed when freeze amount less than 1Trx + // Freeze failed when freeze amount less than 1Trx ret1 = freezeBalance2(fromAddress, 999999L, 3L, foundationKey2); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : frozenBalance must be more than 1TRX"); - //Freeze failed when freeze duration isn't 3 days. + // Freeze failed when freeze duration isn't 3 days. ret1 = freezeBalance2(fromAddress, 1000000L, 2L, foundationKey2); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : frozenDuration must be less than 3 days and more than 3 days"); - //Unfreeze balance failed when 3 days hasn't come. + // Unfreeze balance failed when 3 days hasn't come. ret1 = unFreezeBalance2(fromAddress, foundationKey2); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : It's not time to unfreeze."); - //Freeze failed when freeze amount is 0. + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : It's not time to unfreeze."); + // Freeze failed when freeze amount is 0. ret1 = freezeBalance2(fromAddress, 0L, 3L, foundationKey2); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : frozenBalance must be positive"); - //Freeze failed when freeze amount is -1. + // Freeze failed when freeze amount is -1. ret1 = freezeBalance2(fromAddress, -1L, 3L, foundationKey2); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : frozenBalance must be positive"); - //Freeze failed when freeze duration is -1. + // Freeze failed when freeze duration is -1. ret1 = freezeBalance2(fromAddress, 1000000L, -1L, foundationKey2); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : frozenDuration must be less than 3 days and more than 3 days"); - //Freeze failed when freeze duration is 0. + // Freeze failed when freeze duration is 0. ret1 = freezeBalance2(fromAddress, 1000000L, 0L, foundationKey2); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : frozenDuration must be less than 3 days and more than 3 days"); try { @@ -107,7 +114,7 @@ public void testFreezeBalance2() { } catch (InterruptedException e) { e.printStackTrace(); } - //Freeze balance success. + // Freeze balance success. ret1 = PublicMethod.freezeBalance2(fromAddress, 1000000L, 3L, foundationKey2, blockingStubFull); Assert.assertEquals(ret1.getCode(), Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); @@ -115,18 +122,15 @@ public void testFreezeBalance2() { @Test(enabled = true) public void testUnFreezeBalance2() { - //Unfreeze failed when there is no freeze balance. + // Unfreeze failed when there is no freeze balance. Return ret1 = unFreezeBalance2(noFrozenAddress, noFrozenBalanceTestKey); logger.info("Test unfreezebalance"); Assert.assertEquals(ret1.getCode(), Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : no frozenBalance(BANDWIDTH)"); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : no frozenBalance(BANDWIDTH)"); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { if (channelFull != null) { @@ -137,17 +141,14 @@ public void shutdown() throws InterruptedException { } } - /** - * constructor. - */ - - public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDuration, - String priKey) { + /** constructor. */ + public Boolean freezeBalance( + byte[] addRess, long freezeBalance, long freezeDuration, String priKey) { byte[] address = addRess; long frozenBalance = freezeBalance; long frozenDuration = freezeDuration; - //String priKey = foundationKey2; + // String priKey = foundationKey2; ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -160,18 +161,20 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura final Long beforeBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Account beforeFronzen = queryAccount(ecKey, blockingStubFull); Long beforeFrozenBalance = 0L; - //Long beforeBandwidth = beforeFronzen.getBandwidth(); + // Long beforeBandwidth = beforeFronzen.getBandwidth(); if (beforeFronzen.getFrozenCount() != 0) { beforeFrozenBalance = beforeFronzen.getFrozen(0).getFrozenBalance(); - //beforeBandwidth = beforeFronzen.getBandwidth(); - //logger.info(Long.toString(beforeFronzen.getBandwidth())); + // beforeBandwidth = beforeFronzen.getBandwidth(); + // logger.info(Long.toString(beforeFronzen.getBandwidth())); logger.info(Long.toString(beforeFronzen.getFrozen(0).getFrozenBalance())); } FreezeBalanceContract.Builder builder = FreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess).setFrozenBalance(frozenBalance) + builder + .setOwnerAddress(byteAddreess) + .setFrozenBalance(frozenBalance) .setFrozenDuration(frozenDuration); FreezeBalanceContract contract = builder.build(); @@ -205,30 +208,28 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura Account afterFronzen = queryAccount(ecKey, searchBlockingStubFull); Long afterFrozenBalance = afterFronzen.getFrozen(0).getFrozenBalance(); - //Long afterBandwidth = afterFronzen.getBandwidth(); - //logger.info(Long.toString(afterFronzen.getBandwidth())); + // Long afterBandwidth = afterFronzen.getBandwidth(); + // logger.info(Long.toString(afterFronzen.getBandwidth())); logger.info(Long.toString(afterFronzen.getFrozen(0).getFrozenBalance())); - //logger.info(Integer.toString(search.getFrozenCount())); + // logger.info(Integer.toString(search.getFrozenCount())); logger.info( - "beforefronen" + beforeFrozenBalance.toString() + " afterfronzen" + afterFrozenBalance - .toString()); + "beforefronen" + + beforeFrozenBalance.toString() + + " afterfronzen" + + afterFrozenBalance.toString()); Assert.assertTrue(afterFrozenBalance - beforeFrozenBalance == freezeBalance); - //Assert.assertTrue(afterBandwidth - beforeBandwidth == freezeBalance * frozen_duration); + // Assert.assertTrue(afterBandwidth - beforeBandwidth == freezeBalance * frozen_duration); return true; - } - /** - * constructor. - */ - - public Return freezeBalance2(byte[] addRess, long freezeBalance, long freezeDuration, - String priKey) { + /** constructor. */ + public Return freezeBalance2( + byte[] addRess, long freezeBalance, long freezeDuration, String priKey) { byte[] address = addRess; long frozenBalance = freezeBalance; long frozenDuration = freezeDuration; - //String priKey = foundationKey2; + // String priKey = foundationKey2; ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -241,18 +242,20 @@ public Return freezeBalance2(byte[] addRess, long freezeBalance, long freezeDura final Long beforeBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Account beforeFronzen = queryAccount(ecKey, blockingStubFull); Long beforeFrozenBalance = 0L; - //Long beforeBandwidth = beforeFronzen.getBandwidth(); + // Long beforeBandwidth = beforeFronzen.getBandwidth(); if (beforeFronzen.getFrozenCount() != 0) { beforeFrozenBalance = beforeFronzen.getFrozen(0).getFrozenBalance(); - //beforeBandwidth = beforeFronzen.getBandwidth(); - //logger.info(Long.toString(beforeFronzen.getBandwidth())); + // beforeBandwidth = beforeFronzen.getBandwidth(); + // logger.info(Long.toString(beforeFronzen.getBandwidth())); logger.info(Long.toString(beforeFronzen.getFrozen(0).getFrozenBalance())); } FreezeBalanceContract.Builder builder = FreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess).setFrozenBalance(frozenBalance) + builder + .setOwnerAddress(byteAddreess) + .setFrozenBalance(frozenBalance) .setFrozenDuration(frozenDuration); FreezeBalanceContract contract = builder.build(); @@ -302,23 +305,21 @@ public Return freezeBalance2(byte[] addRess, long freezeBalance, long freezeDura Account afterFronzen = queryAccount(ecKey, searchBlockingStubFull); Long afterFrozenBalance = afterFronzen.getFrozen(0).getFrozenBalance(); - //Long afterBandwidth = afterFronzen.getBandwidth(); - //logger.info(Long.toString(afterFronzen.getBandwidth())); + // Long afterBandwidth = afterFronzen.getBandwidth(); + // logger.info(Long.toString(afterFronzen.getBandwidth())); logger.info(Long.toString(afterFronzen.getFrozen(0).getFrozenBalance())); - //logger.info(Integer.toString(search.getFrozenCount())); + // logger.info(Integer.toString(search.getFrozenCount())); logger.info( - "beforefronen" + beforeFrozenBalance.toString() + " afterfronzen" + afterFrozenBalance - .toString()); + "beforefronen" + + beforeFrozenBalance.toString() + + " afterfronzen" + + afterFrozenBalance.toString()); Assert.assertTrue(afterFrozenBalance - beforeFrozenBalance == freezeBalance); - //Assert.assertTrue(afterBandwidth - beforeBandwidth == freezeBalance * frozen_duration); + // Assert.assertTrue(afterBandwidth - beforeBandwidth == freezeBalance * frozen_duration); return ret; - } - /** - * constructor. - */ - + /** constructor. */ public boolean unFreezeBalance(byte[] addRess, String priKey) { byte[] address = addRess; @@ -332,8 +333,7 @@ public boolean unFreezeBalance(byte[] addRess, String priKey) { ECKey ecKey = temKey; Account search = queryAccount(ecKey, blockingStubFull); - UnfreezeBalanceContract.Builder builder = UnfreezeBalanceContract - .newBuilder(); + UnfreezeBalanceContract.Builder builder = UnfreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddreess); @@ -356,10 +356,7 @@ public boolean unFreezeBalance(byte[] addRess, String priKey) { } } - /** - * constructor. - */ - + /** constructor. */ public Return unFreezeBalance2(byte[] addRess, String priKey) { byte[] address = addRess; @@ -373,8 +370,7 @@ public Return unFreezeBalance2(byte[] addRess, String priKey) { ECKey ecKey = temKey; Account search = queryAccount(ecKey, blockingStubFull); - UnfreezeBalanceContract.Builder builder = UnfreezeBalanceContract - .newBuilder(); + UnfreezeBalanceContract.Builder builder = UnfreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddreess); @@ -411,14 +407,11 @@ public Return unFreezeBalance2(byte[] addRess, String priKey) { return ret; } - /** - * constructor. - */ - + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; @@ -434,25 +427,17 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ - + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ - + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } } - diff --git a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetBlockByLatestNum2Test.java b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetBlockByLatestNum2Test.java index be0cd481..0b9141de 100644 --- a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetBlockByLatestNum2Test.java +++ b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetBlockByLatestNum2Test.java @@ -19,25 +19,24 @@ import stest.tron.wallet.common.client.utils.TronBaseTest; @Slf4j -public class GetBlockByLatestNum2Test extends TronBaseTest { public static String loadPubKey() { +public class GetBlockByLatestNum2Test extends TronBaseTest { + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void testGetBlockByLatestNum2() { // - GrpcAPI.BlockExtention currentBlock = blockingStubFull - .getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); - Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); + GrpcAPI.BlockExtention currentBlock = + blockingStubFull.getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); + Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Assert.assertFalse(currentBlockNum < 0); while (currentBlockNum <= 5) { logger.info("Now the block num is " + Long.toString(currentBlockNum) + " Please wait"); @@ -53,7 +52,12 @@ public void testGetBlockByLatestNum2() { Assert.assertTrue( getBlockByLatestNum.get().getBlock(1).getBlockHeader().getRawData().getNumber() > 0); Assert.assertFalse( - getBlockByLatestNum.get().getBlock(2).getBlockHeader().getRawData().getParentHash() + getBlockByLatestNum + .get() + .getBlock(2) + .getBlockHeader() + .getRawData() + .getParentHash() .isEmpty()); logger.info("TestGetBlockByLatestNum ok!!!"); Assert.assertFalse(getBlockByLatestNum.get().getBlock(0).getBlockid().isEmpty()); @@ -61,11 +65,13 @@ public void testGetBlockByLatestNum2() { Assert.assertFalse(getBlockByLatestNum.get().getBlock(2).getBlockid().isEmpty()); } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void testGetBlockByExceptionNum2() { - GrpcAPI.BlockExtention currentBlock = blockingStubFull - .getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); - Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); + GrpcAPI.BlockExtention currentBlock = + blockingStubFull.getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); + Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Assert.assertFalse(currentBlockNum < 0); while (currentBlockNum <= 5) { logger.info("Now the block num is " + Long.toString(currentBlockNum) + " Please wait"); @@ -76,35 +82,30 @@ public void testGetBlockByExceptionNum2() { GrpcAPI.BlockListExtention blockList = blockingStubFull.getBlockByLatestNum2(numberMessage); Optional getBlockByLatestNum = Optional.ofNullable(blockList); Assert.assertTrue(getBlockByLatestNum.get().getBlockCount() == 0); - //Assert.assertTrue(getBlockByLatestNum.get().getBlock(1).getBlockid().isEmpty()); + // Assert.assertTrue(getBlockByLatestNum.get().getBlock(1).getBlockid().isEmpty()); numberMessage = NumberMessage.newBuilder().setNum(0).build(); blockList = blockingStubFull.getBlockByLatestNum2(numberMessage); getBlockByLatestNum = Optional.ofNullable(blockList); Assert.assertTrue(getBlockByLatestNum.get().getBlockCount() == 0); - //Assert.assertTrue(getBlockByLatestNum.get().getBlock(1).getBlockid().isEmpty()); + // Assert.assertTrue(getBlockByLatestNum.get().getBlock(1).getBlockid().isEmpty()); numberMessage = NumberMessage.newBuilder().setNum(100).build(); blockList = blockingStubFull.getBlockByLatestNum2(numberMessage); getBlockByLatestNum = Optional.ofNullable(blockList); Assert.assertTrue(getBlockByLatestNum.get().getBlockCount() == 0); - //Assert.assertTrue(getBlockByLatestNum.get().getBlock(10).getBlockid().isEmpty()); + // Assert.assertTrue(getBlockByLatestNum.get().getBlock(10).getBlockid().isEmpty()); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -113,13 +114,13 @@ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockin } ECKey ecKey = temKey; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -129,24 +130,17 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetBlockByLimitNext2.java b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetBlockByLimitNext2.java index c9802771..e02aa786 100644 --- a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetBlockByLimitNext2.java +++ b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetBlockByLimitNext2.java @@ -19,25 +19,24 @@ import stest.tron.wallet.common.client.utils.TronBaseTest; @Slf4j -public class GetBlockByLimitNext2 extends TronBaseTest { public static String loadPubKey() { +public class GetBlockByLimitNext2 extends TronBaseTest { + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void testGetBlockByLimitNext2() { // - GrpcAPI.BlockExtention currentBlock = blockingStubFull - .getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); - Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); + GrpcAPI.BlockExtention currentBlock = + blockingStubFull.getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); + Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Assert.assertFalse(currentBlockNum < 0); while (currentBlockNum <= 5) { logger.info("Now has very little block, Please wait"); @@ -51,10 +50,12 @@ public void testGetBlockByLimitNext2() { Optional getBlockByLimitNext = Optional.ofNullable(blockList); Assert.assertTrue(getBlockByLimitNext.isPresent()); Assert.assertTrue(getBlockByLimitNext.get().getBlockCount() == 2); - logger.info(Long.toString( - getBlockByLimitNext.get().getBlock(0).getBlockHeader().getRawData().getNumber())); - logger.info(Long.toString( - getBlockByLimitNext.get().getBlock(1).getBlockHeader().getRawData().getNumber())); + logger.info( + Long.toString( + getBlockByLimitNext.get().getBlock(0).getBlockHeader().getRawData().getNumber())); + logger.info( + Long.toString( + getBlockByLimitNext.get().getBlock(1).getBlockHeader().getRawData().getNumber())); Assert.assertTrue( getBlockByLimitNext.get().getBlock(0).getBlockHeader().getRawData().getNumber() < 4); Assert.assertTrue( @@ -62,20 +63,32 @@ public void testGetBlockByLimitNext2() { Assert.assertTrue(getBlockByLimitNext.get().getBlock(0).hasBlockHeader()); Assert.assertTrue(getBlockByLimitNext.get().getBlock(1).hasBlockHeader()); Assert.assertFalse( - getBlockByLimitNext.get().getBlock(0).getBlockHeader().getRawData().getParentHash() + getBlockByLimitNext + .get() + .getBlock(0) + .getBlockHeader() + .getRawData() + .getParentHash() .isEmpty()); Assert.assertFalse( - getBlockByLimitNext.get().getBlock(1).getBlockHeader().getRawData().getParentHash() + getBlockByLimitNext + .get() + .getBlock(1) + .getBlockHeader() + .getRawData() + .getParentHash() .isEmpty()); Assert.assertFalse(getBlockByLimitNext.get().getBlock(0).getBlockid().isEmpty()); Assert.assertFalse(getBlockByLimitNext.get().getBlock(1).getBlockid().isEmpty()); } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void testGetBlockByExceptionLimitNext2() { - GrpcAPI.BlockExtention currentBlock = blockingStubFull - .getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); - Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); + GrpcAPI.BlockExtention currentBlock = + blockingStubFull.getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); + Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Assert.assertFalse(currentBlockNum < 0); while (currentBlockNum <= 5) { logger.info("Now has very little block, Please wait"); @@ -83,54 +96,49 @@ public void testGetBlockByExceptionLimitNext2() { currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); } - //From -1 to 1 + // From -1 to 1 GrpcAPI.BlockLimit.Builder builder = GrpcAPI.BlockLimit.newBuilder(); builder.setStartNum(-1); builder.setEndNum(1); GrpcAPI.BlockListExtention blockList = blockingStubFull.getBlockByLimitNext2(builder.build()); Optional getBlockByLimitNext = Optional.ofNullable(blockList); Assert.assertTrue(getBlockByLimitNext.get().getBlockCount() == 0); - //check o block is empty - //Assert.assertTrue(getBlockByLimitNext.get().getBlock(1).getBlockid().isEmpty()); - //From 3 to 3 + // check o block is empty + // Assert.assertTrue(getBlockByLimitNext.get().getBlock(1).getBlockid().isEmpty()); + // From 3 to 3 builder = GrpcAPI.BlockLimit.newBuilder(); builder.setStartNum(3); builder.setEndNum(3); blockList = blockingStubFull.getBlockByLimitNext2(builder.build()); getBlockByLimitNext = Optional.ofNullable(blockList); Assert.assertTrue(getBlockByLimitNext.get().getBlockCount() == 0); - //check the third block is empty - //Assert.assertTrue(getBlockByLimitNext.get().getBlock(3).getBlockid().isEmpty()); - //From 4 to 2 + // check the third block is empty + // Assert.assertTrue(getBlockByLimitNext.get().getBlock(3).getBlockid().isEmpty()); + // From 4 to 2 builder = GrpcAPI.BlockLimit.newBuilder(); builder.setStartNum(4); builder.setEndNum(2); blockList = blockingStubFull.getBlockByLimitNext2(builder.build()); getBlockByLimitNext = Optional.ofNullable(blockList); Assert.assertTrue(getBlockByLimitNext.get().getBlockCount() == 0); - //Assert.assertTrue(getBlockByLimitNext.get().getBlock(4).getBlockid().isEmpty()); + // Assert.assertTrue(getBlockByLimitNext.get().getBlock(4).getBlockid().isEmpty()); builder = GrpcAPI.BlockLimit.newBuilder(); builder.setStartNum(999999990); builder.setEndNum(999999999); blockList = blockingStubFull.getBlockByLimitNext2(builder.build()); getBlockByLimitNext = Optional.ofNullable(blockList); Assert.assertTrue(getBlockByLimitNext.get().getBlockCount() == 0); - //Assert.assertTrue(getBlockByLimitNext.get().getBlock(999999990).getBlockid().isEmpty()); + // Assert.assertTrue(getBlockByLimitNext.get().getBlock(999999990).getBlockid().isEmpty()); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -139,13 +147,13 @@ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockin } ECKey ecKey = temKey; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -155,24 +163,17 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetBlockByNum2Test.java b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetBlockByNum2Test.java index 16c83d49..e2928ca5 100644 --- a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetBlockByNum2Test.java +++ b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetBlockByNum2Test.java @@ -7,7 +7,6 @@ import org.apache.commons.lang3.StringUtils; import org.bouncycastle.util.encoders.Hex; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI; @@ -17,26 +16,27 @@ import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.Block; import stest.tron.wallet.common.client.utils.ECKey; - import stest.tron.wallet.common.client.utils.TronBaseTest; + @Slf4j -public class GetBlockByNum2Test extends TronBaseTest { private ManagedChannel channelSolidity = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; public static String loadPubKey() { +public class GetBlockByNum2Test extends TronBaseTest { + private ManagedChannel channelSolidity = null; + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - /** - * constructor. - */ - + /** constructor. */ @BeforeClass - public void beforeClass() { } + public void beforeClass() {} @Test(enabled = true) public void testGetBlockByNum2() { initSolidityChannel(); - GrpcAPI.BlockExtention currentBlock = blockingStubFull - .getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); + GrpcAPI.BlockExtention currentBlock = + blockingStubFull.getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Assert.assertFalse(currentBlockNum < 0); if (currentBlockNum == 1) { @@ -44,14 +44,14 @@ public void testGetBlockByNum2() { Assert.assertTrue(currentBlockNum == 1); } - //The number is large than the currently number, there is no exception when query this number. + // The number is large than the currently number, there is no exception when query this number. /* Long outOfCurrentBlockNum = currentBlockNum + 10000L; NumberMessage.Builder builder1 = NumberMessage.newBuilder(); builder1.setNum(outOfCurrentBlockNum); Block outOfCurrentBlock = blockingStubFull.getBlockByNum(builder1.build()); Assert.assertFalse(outOfCurrentBlock.hasBlockHeader());*/ - //Query the first block + // Query the first block NumberMessage.Builder builder2 = NumberMessage.newBuilder(); builder2.setNum(1); GrpcAPI.BlockExtention firstBlock = blockingStubFull.getBlockByNum2(builder2.build()); @@ -64,7 +64,7 @@ public void testGetBlockByNum2() { Assert.assertTrue(firstBlock.getBlockHeader().getRawData().getWitnessId() >= 0); Assert.assertFalse(firstBlock.getBlockid().isEmpty()); - //Query the zero block + // Query the zero block NumberMessage.Builder builder21 = NumberMessage.newBuilder(); builder2.setNum(0); GrpcAPI.BlockExtention zeroBlock = blockingStubFull.getBlockByNum2(builder21.build()); @@ -77,7 +77,7 @@ public void testGetBlockByNum2() { Assert.assertTrue(zeroBlock.getBlockHeader().getRawData().getWitnessId() >= 0); Assert.assertFalse(zeroBlock.getBlockid().isEmpty()); - //Query the -1 block + // Query the -1 block NumberMessage.Builder builder22 = NumberMessage.newBuilder(); builder2.setNum(-1); GrpcAPI.BlockExtention nagtiveBlock = blockingStubFull.getBlockByNum2(builder22.build()); @@ -90,7 +90,7 @@ public void testGetBlockByNum2() { Assert.assertTrue(nagtiveBlock.getBlockHeader().getRawData().getWitnessId() >= 0); Assert.assertFalse(nagtiveBlock.getBlockid().isEmpty()); - //Query the second latest block. + // Query the second latest block. NumberMessage.Builder builder3 = NumberMessage.newBuilder(); builder3.setNum(currentBlockNum - 1); GrpcAPI.BlockExtention lastSecondBlock = blockingStubFull.getBlockByNum2(builder3.build()); @@ -107,8 +107,8 @@ public void testGetBlockByNum2() { @Test(enabled = true) public void testGetBlockByNumFromSolidity2() { - GrpcAPI.BlockExtention currentBlock = blockingStubSolidity - .getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); + GrpcAPI.BlockExtention currentBlock = + blockingStubSolidity.getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); Long currentBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Assert.assertFalse(currentBlockNum < 0); if (currentBlockNum == 1) { @@ -116,7 +116,7 @@ public void testGetBlockByNumFromSolidity2() { Assert.assertTrue(currentBlockNum == 1); } - //Query the first block. + // Query the first block. NumberMessage.Builder builder2 = NumberMessage.newBuilder(); builder2.setNum(1); GrpcAPI.BlockExtention firstBlock = blockingStubSolidity.getBlockByNum2(builder2.build()); @@ -130,7 +130,7 @@ public void testGetBlockByNumFromSolidity2() { logger.info("firstblock test from solidity succesfully"); Assert.assertFalse(firstBlock.getBlockid().isEmpty()); - //Query the second latest block. + // Query the second latest block. NumberMessage.Builder builder3 = NumberMessage.newBuilder(); builder3.setNum(currentBlockNum - 1); GrpcAPI.BlockExtention lastSecondBlock = blockingStubSolidity.getBlockByNum2(builder3.build()); @@ -148,8 +148,8 @@ public void testGetBlockByNumFromSolidity2() { @Test(enabled = true) public void testGetBlockById2() { - GrpcAPI.BlockExtention currentBlock = blockingStubFull - .getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); + GrpcAPI.BlockExtention currentBlock = + blockingStubFull.getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); ByteString currentHash = currentBlock.getBlockHeader().getRawData().getParentHash(); GrpcAPI.BytesMessage request = GrpcAPI.BytesMessage.newBuilder().setValue(currentHash).build(); Block setIdOfBlock = blockingStubFull.getBlockById(request); @@ -160,15 +160,13 @@ public void testGetBlockById2() { logger.info(Long.toString(setIdOfBlock.getBlockHeader().getRawData().getNumber())); logger.info(Long.toString(currentBlock.getBlockHeader().getRawData().getNumber())); Assert.assertTrue( - setIdOfBlock.getBlockHeader().getRawData().getNumber() + 1 == currentBlock.getBlockHeader() - .getRawData().getNumber()); + setIdOfBlock.getBlockHeader().getRawData().getNumber() + 1 + == currentBlock.getBlockHeader().getRawData().getNumber()); Assert.assertFalse(setIdOfBlock.getBlockHeader().getRawData().getParentHash().isEmpty()); Assert.assertTrue(setIdOfBlock.getBlockHeader().getRawData().getWitnessId() >= 0); logger.info("By ID test succesfully"); } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; @@ -181,7 +179,7 @@ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockin } ECKey ecKey = temKey; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; @@ -197,26 +195,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ - + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ - - public GrpcAPI.BlockExtention getBlock2(long blockNum, - WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public GrpcAPI.BlockExtention getBlock2( + long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum2(builder.build()); - } } - diff --git a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetNowBlock2Test.java b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetNowBlock2Test.java index 7611b4f3..0059d991 100644 --- a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetNowBlock2Test.java +++ b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetNowBlock2Test.java @@ -7,7 +7,6 @@ import org.apache.commons.lang3.StringUtils; import org.bouncycastle.util.encoders.Hex; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI; @@ -17,29 +16,28 @@ import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.Block; import stest.tron.wallet.common.client.utils.ECKey; - -//import stest.tron.wallet.common.client.AccountComparator; - import stest.tron.wallet.common.client.utils.TronBaseTest; + @Slf4j -public class GetNowBlock2Test extends TronBaseTest { private ManagedChannel channelSolidity = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; public static String loadPubKey() { +public class GetNowBlock2Test extends TronBaseTest { + private ManagedChannel channelSolidity = null; + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - /** - * constructor. - */ - + /** constructor. */ @BeforeClass - public void beforeClass() { } + public void beforeClass() {} @Test public void testCurrentBlock2() { initSolidityChannel(); - //Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - GrpcAPI.BlockExtention currentBlock = blockingStubFull - .getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); + // Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); + GrpcAPI.BlockExtention currentBlock = + blockingStubFull.getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); Assert.assertTrue(currentBlock.hasBlockHeader()); Assert.assertFalse(currentBlock.getBlockHeader().getWitnessSignature().isEmpty()); Assert.assertTrue(currentBlock.getBlockHeader().getRawData().getTimestamp() > 0); @@ -47,15 +45,16 @@ public void testCurrentBlock2() { Assert.assertTrue(currentBlock.getBlockHeader().getRawData().getNumber() > 0); Assert.assertFalse(currentBlock.getBlockHeader().getRawData().getParentHash().isEmpty()); Assert.assertTrue(currentBlock.getBlockHeader().getRawData().getWitnessId() >= 0); - logger.info("test getcurrentblock is " + Long - .toString(currentBlock.getBlockHeader().getRawData().getNumber())); + logger.info( + "test getcurrentblock is " + + Long.toString(currentBlock.getBlockHeader().getRawData().getNumber())); Assert.assertFalse(currentBlock.getBlockid().isEmpty()); - //Improve coverage. + // Improve coverage. currentBlock.equals(currentBlock); - //Block newBlock = blockingStubFull.getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); - GrpcAPI.BlockExtention newBlock = blockingStubFull - .getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); + // Block newBlock = blockingStubFull.getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); + GrpcAPI.BlockExtention newBlock = + blockingStubFull.getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); newBlock.equals(currentBlock); newBlock.hashCode(); newBlock.getSerializedSize(); @@ -66,8 +65,8 @@ public void testCurrentBlock2() { @Test public void testCurrentBlockFromSolidity2() { - GrpcAPI.BlockExtention currentBlock = blockingStubSolidity - .getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); + GrpcAPI.BlockExtention currentBlock = + blockingStubSolidity.getNowBlock2(GrpcAPI.EmptyMessage.newBuilder().build()); Assert.assertTrue(currentBlock.hasBlockHeader()); Assert.assertFalse(currentBlock.getBlockHeader().getWitnessSignature().isEmpty()); Assert.assertTrue(currentBlock.getBlockHeader().getRawData().getTimestamp() > 0); @@ -75,12 +74,11 @@ public void testCurrentBlockFromSolidity2() { Assert.assertTrue(currentBlock.getBlockHeader().getRawData().getNumber() > 0); Assert.assertFalse(currentBlock.getBlockHeader().getRawData().getParentHash().isEmpty()); Assert.assertTrue(currentBlock.getBlockHeader().getRawData().getWitnessId() >= 0); - logger.info("test getcurrentblock in soliditynode is " + Long - .toString(currentBlock.getBlockHeader().getRawData().getNumber())); + logger.info( + "test getcurrentblock in soliditynode is " + + Long.toString(currentBlock.getBlockHeader().getRawData().getNumber())); } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; @@ -93,7 +91,7 @@ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockin } ECKey ecKey = temKey; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; @@ -109,25 +107,17 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ - + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ - + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } } - diff --git a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetTransactionsFromThis2Test.java b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetTransactionsFromThis2Test.java index 25a66c71..1092e0cc 100644 --- a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetTransactionsFromThis2Test.java +++ b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetTransactionsFromThis2Test.java @@ -1,7 +1,6 @@ package stest.tron.wallet.newaddinterface2; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.Optional; import lombok.extern.slf4j.Slf4j; @@ -27,59 +26,57 @@ import stest.tron.wallet.common.client.utils.TransactionUtils; import stest.tron.wallet.common.client.utils.TronBaseTest; - @Slf4j public class GetTransactionsFromThis2Test extends TronBaseTest { private static final byte[] INVAILD_ADDRESS = Base58.decodeFromBase58Check("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48"); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); - //the key is only for test + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); + // the key is only for test private final String notexist01 = "DCB620820121A866E4E25905DC37F5025BFA5420B781C69E1BC6E1D83038C88A"; private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); private WalletExtensionGrpc.WalletExtensionBlockingStub blockingStubExtension = null; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); blockingStubExtension = WalletExtensionGrpc.newBlockingStub(channelSolidity); - } - @Test(enabled = false, groups = {"smoke"}) + @Test( + enabled = false, + groups = {"smoke"}) public void testgetTransactionsFromThis2() { - //Create a transfer. - Assert.assertTrue(PublicMethod.sendcoin(toAddress, 1000000, foundationAddress, - foundationKey, blockingStubFull)); + // Create a transfer. + Assert.assertTrue( + PublicMethod.sendcoin( + toAddress, 1000000, foundationAddress, foundationKey, blockingStubFull)); ByteString addressBs = ByteString.copyFrom(foundationAddress); Account account = Account.newBuilder().setAddress(addressBs).build(); AccountPaginated.Builder accountPaginated = AccountPaginated.newBuilder().setAccount(account); accountPaginated.setOffset(1000); accountPaginated.setLimit(0); - GrpcAPI.TransactionListExtention transactionListExtention = blockingStubExtension - .getTransactionsFromThis2(accountPaginated.build()); - Optional gettransactionsfromthis2 = Optional - .ofNullable(transactionListExtention); + GrpcAPI.TransactionListExtention transactionListExtention = + blockingStubExtension.getTransactionsFromThis2(accountPaginated.build()); + Optional gettransactionsfromthis2 = + Optional.ofNullable(transactionListExtention); if (gettransactionsfromthis2.get().getTransactionCount() == 0) { - Assert.assertTrue(PublicMethod.sendcoin(toAddress, 1000000L, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + toAddress, 1000000L, foundationAddress, foundationKey, blockingStubFull)); } Assert.assertTrue(gettransactionsfromthis2.isPresent()); @@ -87,68 +84,68 @@ public void testgetTransactionsFromThis2() { logger.info(Integer.toString(beforecount)); for (Integer j = 0; j < beforecount; j++) { Assert.assertFalse( - gettransactionsfromthis2.get().getTransaction(j).getTransaction().getRawData() - .getContractList().isEmpty()); + gettransactionsfromthis2 + .get() + .getTransaction(j) + .getTransaction() + .getRawData() + .getContractList() + .isEmpty()); } } - @Test(enabled = false, groups = {"smoke"}) + @Test( + enabled = false, + groups = {"smoke"}) public void testgetTransactionsFromThisByInvaildAddress2() { - //Invaild address. + // Invaild address. ByteString addressBs = ByteString.copyFrom(INVAILD_ADDRESS); Account account = Account.newBuilder().setAddress(addressBs).build(); AccountPaginated.Builder accountPaginated = AccountPaginated.newBuilder().setAccount(account); accountPaginated.setOffset(1000); accountPaginated.setLimit(0); - GrpcAPI.TransactionListExtention transactionListExtention = blockingStubExtension - .getTransactionsFromThis2(accountPaginated.build()); - Optional gettransactionsfromthisByInvaildAddress = Optional - .ofNullable(transactionListExtention); + GrpcAPI.TransactionListExtention transactionListExtention = + blockingStubExtension.getTransactionsFromThis2(accountPaginated.build()); + Optional gettransactionsfromthisByInvaildAddress = + Optional.ofNullable(transactionListExtention); Assert.assertTrue(gettransactionsfromthisByInvaildAddress.get().getTransactionCount() == 0); - //Limit is -1 + // Limit is -1 addressBs = ByteString.copyFrom(INVAILD_ADDRESS); account = Account.newBuilder().setAddress(addressBs).build(); accountPaginated = AccountPaginated.newBuilder().setAccount(account); accountPaginated.setOffset(1000); accountPaginated.setLimit(-1); - transactionListExtention = blockingStubExtension - .getTransactionsFromThis2(accountPaginated.build()); - gettransactionsfromthisByInvaildAddress = Optional - .ofNullable(transactionListExtention); + transactionListExtention = + blockingStubExtension.getTransactionsFromThis2(accountPaginated.build()); + gettransactionsfromthisByInvaildAddress = Optional.ofNullable(transactionListExtention); Assert.assertTrue(gettransactionsfromthisByInvaildAddress.get().getTransactionCount() == 0); - //offset is -1 + // offset is -1 addressBs = ByteString.copyFrom(INVAILD_ADDRESS); account = Account.newBuilder().setAddress(addressBs).build(); accountPaginated = AccountPaginated.newBuilder().setAccount(account); accountPaginated.setOffset(-1); accountPaginated.setLimit(100); - transactionListExtention = blockingStubExtension - .getTransactionsFromThis2(accountPaginated.build()); - gettransactionsfromthisByInvaildAddress = Optional - .ofNullable(transactionListExtention); + transactionListExtention = + blockingStubExtension.getTransactionsFromThis2(accountPaginated.build()); + gettransactionsfromthisByInvaildAddress = Optional.ofNullable(transactionListExtention); Assert.assertTrue(gettransactionsfromthisByInvaildAddress.get().getTransactionCount() == 0); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -158,18 +155,14 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); @@ -185,5 +178,3 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetTransactionsToThis2.java b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetTransactionsToThis2.java index d8cc5260..bd914e2f 100644 --- a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetTransactionsToThis2.java +++ b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/GetTransactionsToThis2.java @@ -7,7 +7,6 @@ import org.apache.commons.lang3.StringUtils; import org.bouncycastle.util.encoders.Hex; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI; @@ -23,8 +22,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; - import stest.tron.wallet.common.client.utils.TronBaseTest; + @Slf4j public class GetTransactionsToThis2 extends TronBaseTest { @@ -36,43 +35,46 @@ public class GetTransactionsToThis2 extends TronBaseTest { Base58.decodeFromBase58Check("TV75jZpdmP2juMe1dRwGrwpV6AMU6mr1EU");*/ private static final byte[] INVAILD_ADDRESS = Base58.decodeFromBase58Check("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48"); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final String notexist01 = - "DCB620820121A866E4E25905DC37F5025BFA5420B781C69E1BC6E1D83038C88A"; private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); private ManagedChannel channelSolidity = null; private WalletExtensionGrpc.WalletExtensionBlockingStub blockingStubExtension = null; public static String loadPubKey() { + "DCB620820121A866E4E25905DC37F5025BFA5420B781C69E1BC6E1D83038C88A"; + private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); + private ManagedChannel channelSolidity = null; + private WalletExtensionGrpc.WalletExtensionBlockingStub blockingStubExtension = null; + + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - /** - * constructor. - */ - + /** constructor. */ @BeforeClass - public void beforeClass() { blockingStubExtension = WalletExtensionGrpc.newBlockingStub(channelSolidity); - + public void beforeClass() { + blockingStubExtension = WalletExtensionGrpc.newBlockingStub(channelSolidity); } @Test(enabled = true) public void testgetTransactionsToThis2() { - //Create a transfer. - Assert.assertTrue(PublicMethod.sendcoin(toAddress, 1000000, fromAddress, - foundationKey2, blockingStubFull)); + // Create a transfer. + Assert.assertTrue( + PublicMethod.sendcoin(toAddress, 1000000, fromAddress, foundationKey2, blockingStubFull)); ByteString addressBs = ByteString.copyFrom(toAddress); Account account = Account.newBuilder().setAddress(addressBs).build(); AccountPaginated.Builder accountPaginated = AccountPaginated.newBuilder().setAccount(account); accountPaginated.setOffset(1000); accountPaginated.setLimit(0); - GrpcAPI.TransactionListExtention transactionListExtention = blockingStubExtension - .getTransactionsToThis2(accountPaginated.build()); + GrpcAPI.TransactionListExtention transactionListExtention = + blockingStubExtension.getTransactionsToThis2(accountPaginated.build()); - Optional gettransactionstothis2 = Optional - .ofNullable(transactionListExtention); + Optional gettransactionstothis2 = + Optional.ofNullable(transactionListExtention); if (gettransactionstothis2.get().getTransactionCount() == 0) { - Assert.assertTrue(PublicMethod.sendcoin(toAddress, 1000000L, fromAddress, foundationKey2, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + toAddress, 1000000L, fromAddress, foundationKey2, blockingStubFull)); } Assert.assertTrue(gettransactionstothis2.isPresent()); @@ -80,61 +82,61 @@ public void testgetTransactionsToThis2() { logger.info(Integer.toString(beforecount)); for (Integer j = 0; j < beforecount; j++) { Assert.assertFalse( - gettransactionstothis2.get().getTransaction(j).getTransaction().getRawData() - .getContractList().isEmpty()); + gettransactionstothis2 + .get() + .getTransaction(j) + .getTransaction() + .getRawData() + .getContractList() + .isEmpty()); } } @Test(enabled = true) public void testgetTransactionsToThisByInvaildAddress2() { - //Invaild address. + // Invaild address. ByteString addressBs = ByteString.copyFrom(INVAILD_ADDRESS); Account account = Account.newBuilder().setAddress(addressBs).build(); AccountPaginated.Builder accountPaginated = AccountPaginated.newBuilder().setAccount(account); accountPaginated.setOffset(1000); accountPaginated.setLimit(0); - GrpcAPI.TransactionListExtention transactionListExtention = blockingStubExtension - .getTransactionsToThis2(accountPaginated.build()); - Optional gettransactionstothisByInvaildAddress = Optional - .ofNullable(transactionListExtention); + GrpcAPI.TransactionListExtention transactionListExtention = + blockingStubExtension.getTransactionsToThis2(accountPaginated.build()); + Optional gettransactionstothisByInvaildAddress = + Optional.ofNullable(transactionListExtention); Assert.assertTrue(gettransactionstothisByInvaildAddress.get().getTransactionCount() == 0); - //Limit is -1 + // Limit is -1 addressBs = ByteString.copyFrom(INVAILD_ADDRESS); account = Account.newBuilder().setAddress(addressBs).build(); accountPaginated = AccountPaginated.newBuilder().setAccount(account); accountPaginated.setOffset(1000); accountPaginated.setLimit(-1); - transactionListExtention = blockingStubExtension - .getTransactionsToThis2(accountPaginated.build()); - gettransactionstothisByInvaildAddress = Optional - .ofNullable(transactionListExtention); + transactionListExtention = + blockingStubExtension.getTransactionsToThis2(accountPaginated.build()); + gettransactionstothisByInvaildAddress = Optional.ofNullable(transactionListExtention); Assert.assertTrue(gettransactionstothisByInvaildAddress.get().getTransactionCount() == 0); - //offset is -1 + // offset is -1 addressBs = ByteString.copyFrom(INVAILD_ADDRESS); account = Account.newBuilder().setAddress(addressBs).build(); accountPaginated = AccountPaginated.newBuilder().setAccount(account); accountPaginated.setOffset(-1); accountPaginated.setLimit(100); - transactionListExtention = blockingStubExtension - .getTransactionsToThis2(accountPaginated.build()); - gettransactionstothisByInvaildAddress = Optional - .ofNullable(transactionListExtention); + transactionListExtention = + blockingStubExtension.getTransactionsToThis2(accountPaginated.build()); + gettransactionstothisByInvaildAddress = Optional.ofNullable(transactionListExtention); Assert.assertTrue(gettransactionstothisByInvaildAddress.get().getTransactionCount() == 0); - } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; @@ -150,20 +152,14 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ - + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ - + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); @@ -179,4 +175,3 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } } - diff --git a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/ParticipateAssetIssue2Test.java b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/ParticipateAssetIssue2Test.java index 7edec2e6..4ade77af 100644 --- a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/ParticipateAssetIssue2Test.java +++ b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/ParticipateAssetIssue2Test.java @@ -25,8 +25,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class ParticipateAssetIssue2Test extends TronBaseTest { @@ -34,57 +34,71 @@ public class ParticipateAssetIssue2Test extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final long totalSupply = now; private static String name = "testAssetIssue002_" + Long.toString(now); - //testng001、testng002、testng003、testng004 - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + // testng001、testng002、testng003、testng004 + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); String description = "just-test"; String url = "https://github.com/tronprotocol/wallet-cli/"; - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] participateAccountAddress = ecKey1.getAddress(); String participateAccountKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] assetIssueAccount002 = ecKey2.getAddress(); - String testKeyForAssetIssueAccount002 = ByteArray.toHexString(ecKey2 - .getPrivKeyBytes()); + String testKeyForAssetIssueAccount002 = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void testParticipateAssetissue2() { ByteString addressBS1 = ByteString.copyFrom(participateAccountAddress); Account request1 = Account.newBuilder().setAddress(addressBS1).build(); - GrpcAPI.AssetIssueList assetIssueList1 = blockingStubFull - .getAssetIssueByAccount(request1); + GrpcAPI.AssetIssueList assetIssueList1 = blockingStubFull.getAssetIssueByAccount(request1); Optional queryAssetByAccount = Optional.ofNullable(assetIssueList1); if (queryAssetByAccount.get().getAssetIssueCount() == 0) { Long start = System.currentTimeMillis() + 2000; - Long end = System.currentTimeMillis() + 1000000000; - //send coin to the new account - Assert.assertTrue(PublicMethod.sendcoin(participateAccountAddress, 2048000000, foundationAddress, - foundationKey, blockingStubFull)); - //Create a new Asset Issue - Assert.assertTrue(PublicMethod.createAssetIssue(participateAccountAddress, - name, totalSupply, 1, 1, System.currentTimeMillis() + 2000, - System.currentTimeMillis() + 1000000000, 1, description, url, - 2000L, 2000L, 1L, 1L, - participateAccountKey, blockingStubFull)); + Long end = System.currentTimeMillis() + 1000000000; + // send coin to the new account + Assert.assertTrue( + PublicMethod.sendcoin( + participateAccountAddress, + 2048000000, + foundationAddress, + foundationKey, + blockingStubFull)); + // Create a new Asset Issue + Assert.assertTrue( + PublicMethod.createAssetIssue( + participateAccountAddress, + name, + totalSupply, + 1, + 1, + System.currentTimeMillis() + 2000, + System.currentTimeMillis() + 1000000000, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + participateAccountKey, + blockingStubFull)); } else { logger.info("This account already create an assetisue"); Optional queryAssetByAccount1 = Optional.ofNullable(assetIssueList1); name = ByteArray.toStr(queryAssetByAccount1.get().getAssetIssue(0).getName().toByteArray()); - } try { @@ -92,51 +106,71 @@ public void testParticipateAssetissue2() { } catch (InterruptedException e) { e.printStackTrace(); } - //Participate AssetIssue success + // Participate AssetIssue success logger.info(name); - //Freeze amount to get bandwitch. - Assert.assertTrue(PublicMethod.freezeBalance(toAddress, 10000000, 3, testKey003, - blockingStubFull)); - //The amount is large than the total supply, participate failed. - Return ret1 = PublicMethod.participateAssetIssue2(participateAccountAddress, - name.getBytes(), 9100000000000000000L, toAddress, testKey003, blockingStubFull); + // Freeze amount to get bandwitch. + Assert.assertTrue( + PublicMethod.freezeBalance(toAddress, 10000000, 3, testKey003, blockingStubFull)); + // The amount is large than the total supply, participate failed. + Return ret1 = + PublicMethod.participateAssetIssue2( + participateAccountAddress, + name.getBytes(), + 9100000000000000000L, + toAddress, + testKey003, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : No enough balance !"); - //The asset issue name is not correct, participate failed. - ret1 = PublicMethod.participateAssetIssue2(participateAccountAddress, - (name + "wrong").getBytes(), 100L, toAddress, testKey003, blockingStubFull); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : No enough balance !"); + // The asset issue name is not correct, participate failed. + ret1 = + PublicMethod.participateAssetIssue2( + participateAccountAddress, + (name + "wrong").getBytes(), + 100L, + toAddress, + testKey003, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - //The amount is 0, participate asset issue failed. - ret1 = PublicMethod.participateAssetIssue2(participateAccountAddress, - name.getBytes(), 0L, toAddress, testKey003, blockingStubFull); + // The amount is 0, participate asset issue failed. + ret1 = + PublicMethod.participateAssetIssue2( + participateAccountAddress, + name.getBytes(), + 0L, + toAddress, + testKey003, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : Amount must greater than 0!"); - //The amount is -1, participate asset issue failed. - ret1 = PublicMethod.participateAssetIssue2(participateAccountAddress, - name.getBytes(), -1L, toAddress, testKey003, blockingStubFull); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Amount must greater than 0!"); + // The amount is -1, participate asset issue failed. + ret1 = + PublicMethod.participateAssetIssue2( + participateAccountAddress, + name.getBytes(), + -1L, + toAddress, + testKey003, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : Amount must greater than 0!"); - //The asset issue owner address is not correct, participate asset issue failed. - ret1 = PublicMethod.participateAssetIssue2(foundationAddress, name.getBytes(), 100L, - toAddress, testKey003, blockingStubFull); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Amount must greater than 0!"); + // The asset issue owner address is not correct, participate asset issue failed. + ret1 = + PublicMethod.participateAssetIssue2( + foundationAddress, name.getBytes(), 100L, toAddress, testKey003, blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ - public boolean participateAssetIssue(byte[] to, byte[] assertName, long amount, byte[] from, - String priKey) { + /** constructor. */ + public boolean participateAssetIssue( + byte[] to, byte[] assertName, long amount, byte[] from, String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -146,8 +180,7 @@ public boolean participateAssetIssue(byte[] to, byte[] assertName, long amount, } final ECKey ecKey = temKey; - ParticipateAssetIssueContract.Builder builder = ParticipateAssetIssueContract - .newBuilder(); + ParticipateAssetIssueContract.Builder builder = ParticipateAssetIssueContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); ByteString bsName = ByteString.copyFrom(assertName); ByteString bsOwner = ByteString.copyFrom(from); @@ -168,12 +201,20 @@ public boolean participateAssetIssue(byte[] to, byte[] assertName, long amount, } } - /** - * constructor. - */ - public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, Integer trxNum, - Integer icoNum, Long startTime, Long endTime, - Integer voteScore, String description, String url, Long fronzenAmount, Long frozenDay, + /** constructor. */ + public Boolean createAssetIssue( + byte[] address, + String name, + Long totalSupply, + Integer trxNum, + Integer icoNum, + Long startTime, + Long endTime, + Integer voteScore, + String description, + String url, + Long fronzenAmount, + Long frozenDay, String priKey) { ECKey temKey = null; try { @@ -222,12 +263,10 @@ public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, I } } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -236,13 +275,13 @@ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockin } ECKey ecKey = temKey; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -252,23 +291,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -280,11 +314,9 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } - /** - * constructor. - */ - public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] address, - String priKey) { + /** constructor. */ + public boolean transferAsset( + byte[] to, byte[] assertName, long amount, byte[] address, String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -315,11 +347,8 @@ public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] a logger.info(ByteArray.toStr(response.getMessage().toByteArray())); return false; } else { - //Account search = queryAccount(ecKey, blockingStubFull); + // Account search = queryAccount(ecKey, blockingStubFull); return true; } - } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/TransferAsset2Test.java b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/TransferAsset2Test.java index aefd9d9f..82167659 100644 --- a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/TransferAsset2Test.java +++ b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/TransferAsset2Test.java @@ -1,14 +1,12 @@ package stest.tron.wallet.newaddinterface2; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import java.math.BigInteger; import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.bouncycastle.util.encoders.Hex; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI; @@ -23,10 +21,10 @@ import org.tron.protos.contract.AssetIssueContractOuterClass.UnfreezeAssetContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; +import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; @Slf4j @@ -35,100 +33,120 @@ public class TransferAsset2Test extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final long totalSupply = now; private static String name = "testAssetIssue001_" + Long.toString(now); - //testng001、testng002、testng003、testng004 - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + // testng001、testng002、testng003、testng004 + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); String description = "just-test-assetissue-001"; String url = "https://github.com/tronprotocol/wallet-cli/assetissue001"; - //get account + // get account ECKey ecKey = new ECKey(Utils.getRandom()); byte[] noBandwitchAddress = ecKey.getAddress(); String noBandwitch = ByteArray.toHexString(ecKey.getPrivKeyBytes()); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - logger.info(ByteArray.toHexString(ecKey.getPrivKeyBytes())); } + logger.info(ByteArray.toHexString(ecKey.getPrivKeyBytes())); + } @Test() public void testTransferAssetBandwitchDecreaseWithin10Second2() { ByteString addressBS1 = ByteString.copyFrom(noBandwitchAddress); Account request1 = Account.newBuilder().setAddress(addressBS1).build(); - GrpcAPI.AssetIssueList assetIssueList1 = blockingStubFull - .getAssetIssueByAccount(request1); + GrpcAPI.AssetIssueList assetIssueList1 = blockingStubFull.getAssetIssueByAccount(request1); Optional queryAssetByAccount = Optional.ofNullable(assetIssueList1); if (queryAssetByAccount.get().getAssetIssueCount() == 0) { - Assert.assertTrue(PublicMethod.sendcoin(noBandwitchAddress, 2048000000, - fromAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + noBandwitchAddress, 2048000000, fromAddress, foundationKey, blockingStubFull)); Long start = System.currentTimeMillis() + 2000; Long end = System.currentTimeMillis() + 1000000000; - Return ret1 = PublicMethod.createAssetIssue2(noBandwitchAddress, name, totalSupply, 1, - 100, start, end, 1, description, url, 10000L, 10000L, - 1L, 1L, noBandwitch, blockingStubFull); + Return ret1 = + PublicMethod.createAssetIssue2( + noBandwitchAddress, + name, + totalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + noBandwitch, + blockingStubFull); } else { logger.info("This account already create an assetisue"); Optional queryAssetByAccount1 = Optional.ofNullable(assetIssueList1); name = ByteArray.toStr(queryAssetByAccount1.get().getAssetIssue(0).getName().toByteArray()); - } Return ret1 = transferAsset2(toAddress, name.getBytes(), 100L, noBandwitchAddress, noBandwitch); Assert.assertEquals(ret1.getCode(), Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); - //Transfer Asset failed when transfer to yourself + // Transfer Asset failed when transfer to yourself ret1 = transferAsset2(toAddress, name.getBytes(), 100L, toAddress, testKey003); Assert.assertEquals(ret1.getCode(), Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Cannot transfer asset to yourself."); - //Transfer Asset failed when the transfer amount is large than the asset balance you have. + // Transfer Asset failed when the transfer amount is large than the asset balance you have. ret1 = transferAsset2(fromAddress, name.getBytes(), 9100000000000000000L, toAddress, testKey003); Assert.assertEquals(ret1.getCode(), Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : assetBalance is not sufficient."); - //Transfer Asset failed when the transfer amount is 0 + // Transfer Asset failed when the transfer amount is 0 ret1 = transferAsset2(fromAddress, name.getBytes(), 0L, toAddress, testKey003); Assert.assertEquals(ret1.getCode(), Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : Amount must greater than 0."); - //Transfer Asset failed when the transfer amount is -1 + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Amount must greater than 0."); + // Transfer Asset failed when the transfer amount is -1 ret1 = transferAsset2(fromAddress, name.getBytes(), -1L, toAddress, testKey003); Assert.assertEquals(ret1.getCode(), Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : Amount must greater than 0."); - ret1 = - transferAsset2(fromAddress, (name + "wrong").getBytes(), 1L, toAddress, testKey003); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Amount must greater than 0."); + ret1 = transferAsset2(fromAddress, (name + "wrong").getBytes(), 1L, toAddress, testKey003); Assert.assertEquals(ret1.getCode(), Return.response_code.CONTRACT_VALIDATE_ERROR); Assert.assertEquals(ret1.getMessage().toStringUtf8(), "Contract validate error : No asset !"); - //Transfer success. + // Transfer success. ret1 = transferAsset2(fromAddress, name.getBytes(), 1L, toAddress, testKey003); Assert.assertEquals(ret1.getCode(), Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); - //No freeze asset, try to unfreeze asset failed. + // No freeze asset, try to unfreeze asset failed. Assert.assertFalse(unFreezeAsset(noBandwitchAddress, noBandwitch)); logger.info("Test no asset frozen balance, try to unfreeze asset, no exception. Test OK!!!"); - //Not create asset, try to unfreeze asset failed.No exception. + // Not create asset, try to unfreeze asset failed.No exception. Assert.assertFalse(unFreezeAsset(toAddress, testKey003)); logger.info("Test not create asset issue, try to unfreeze asset, no exception. Test OK!!!"); } - /** - * constructor. - */ - - public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, Integer trxNum, - Integer icoNum, Long startTime, Long endTime, - Integer voteScore, String description, String url, String priKey) { + /** constructor. */ + public Boolean createAssetIssue( + byte[] address, + String name, + Long totalSupply, + Integer trxNum, + Integer icoNum, + Long startTime, + Long endTime, + Integer voteScore, + String description, + String url, + String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -172,14 +190,11 @@ public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, I } } - /** - * constructor. - */ - + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; @@ -195,25 +210,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ - + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ - + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -225,12 +233,9 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } - /** - * constructor. - */ - - public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] address, - String priKey) { + /** constructor. */ + public boolean transferAsset( + byte[] to, byte[] assertName, long amount, byte[] address, String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -264,15 +269,11 @@ public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] a Account search = queryAccount(ecKey, blockingStubFull); return true; } - } - /** - * constructor. - */ - - public Return transferAsset2(byte[] to, byte[] assertName, long amount, byte[] address, - String priKey) { + /** constructor. */ + public Return transferAsset2( + byte[] to, byte[] assertName, long amount, byte[] address, String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -325,10 +326,7 @@ public Return transferAsset2(byte[] to, byte[] assertName, long amount, byte[] a return ret; } - /** - * constructor. - */ - + /** constructor. */ public boolean unFreezeAsset(byte[] addRess, String priKey) { byte[] address = addRess; @@ -341,8 +339,7 @@ public boolean unFreezeAsset(byte[] addRess, String priKey) { } final ECKey ecKey = temKey; - UnfreezeAssetContract.Builder builder = UnfreezeAssetContract - .newBuilder(); + UnfreezeAssetContract.Builder builder = UnfreezeAssetContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddreess); @@ -366,4 +363,3 @@ public boolean unFreezeAsset(byte[] addRess, String priKey) { } } } - diff --git a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/UnfreezeAsset2Test.java b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/UnfreezeAsset2Test.java index 95033d45..f12f0ae1 100644 --- a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/UnfreezeAsset2Test.java +++ b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/UnfreezeAsset2Test.java @@ -1,14 +1,12 @@ package stest.tron.wallet.newaddinterface2; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import java.math.BigInteger; import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.bouncycastle.util.encoders.Hex; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI; @@ -24,10 +22,10 @@ import org.tron.protos.contract.AssetIssueContractOuterClass.UnfreezeAssetContract; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; +import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; @Slf4j @@ -54,41 +52,41 @@ public class UnfreezeAsset2Test extends TronBaseTest { + "vqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqaz" + "xswedcvqazxswedcvqazxswedcvqazxswedcv"; private static final long totalSupply = now; - //testng001、testng002、testng003、testng004 - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + // testng001、testng002、testng003、testng004 + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); - //get account + // get account ECKey ecKey = new ECKey(Utils.getRandom()); byte[] lowBalAddress = ecKey.getAddress(); String lowBalTest = ByteArray.toHexString(ecKey.getPrivKeyBytes()); - //get account + // get account ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] lowBalAddress2 = ecKey2.getAddress(); String lowBalTest2 = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); String description = "just-test"; String url = "https://github.com/tronprotocol/wallet-cli/"; + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} @Test(enabled = true) public void testGetAllAssetIssue2() { - Return ret1 = PublicMethod.sendcoin2(lowBalAddress, 2124500000L, - fromAddress, foundationKey, blockingStubFull); + Return ret1 = + PublicMethod.sendcoin2( + lowBalAddress, 2124500000L, fromAddress, foundationKey, blockingStubFull); Assert.assertEquals(ret1.getCode(), Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); - ret1 = PublicMethod.sendcoin2(lowBalAddress2, 21240500000L, - fromAddress, foundationKey, blockingStubFull); + ret1 = + PublicMethod.sendcoin2( + lowBalAddress2, 21240500000L, fromAddress, foundationKey, blockingStubFull); Assert.assertEquals(ret1.getCode(), Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); ByteString addressBS1 = ByteString.copyFrom(fromAddress); @@ -96,169 +94,513 @@ public void testGetAllAssetIssue2() { GrpcAPI.AssetIssueList assetIssueList1 = blockingStubFull.getAssetIssueByAccount(request1); Optional queryAssetByAccount = Optional.ofNullable(assetIssueList1); - //if (queryAssetByAccount.get().getAssetIssueCount() == 0) { + // if (queryAssetByAccount.get().getAssetIssueCount() == 0) { Long start = System.currentTimeMillis() + 100000; Long end = System.currentTimeMillis() + 1000000000; - //Freeze amount is large than total supply, create asset issue failed. - ret1 = PublicMethod.createAssetIssue2(lowBalAddress, name, totalSupply, 1, 10, - start, end, 2, description, url, 10000L, 10000L, - 9000000000000000000L, 1L, lowBalTest, blockingStubFull); + // Freeze amount is large than total supply, create asset issue failed. + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + name, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 9000000000000000000L, + 1L, + lowBalTest, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Frozen supply cannot exceed total supply"); - //Freeze day is 0, create failed - ret1 = PublicMethod.createAssetIssue2(lowBalAddress, name, totalSupply, 1, 10, - start, end, 2, description, url, 10000L, 10000L, - 100L, 0L, lowBalTest, blockingStubFull); + // Freeze day is 0, create failed + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + name, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 100L, + 0L, + lowBalTest, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), "Contract validate error : " - + "frozenDuration must be less than 3652 days and more than 1 days"); - //Freeze amount is 0, create failed - ret1 = PublicMethod.createAssetIssue2(lowBalAddress, name, totalSupply, 1, 10, - start, end, 2, description, url, 10000L, 10000L, - 0L, 1L, lowBalTest, blockingStubFull); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), + "Contract validate error : " + + "frozenDuration must be less than 3652 days and more than 1 days"); + // Freeze amount is 0, create failed + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + name, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 0L, + 1L, + lowBalTest, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Frozen supply must be greater than 0!"); - //Freeze day is -1, create failed - ret1 = PublicMethod.createAssetIssue2(lowBalAddress, name, totalSupply, 1, 10, - start, end, 2, description, url, 1000L, 1000L, - 1000L, -1L, lowBalTest, blockingStubFull); + // Freeze day is -1, create failed + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + name, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 1000L, + 1000L, + 1000L, + -1L, + lowBalTest, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), "Contract validate error : " - + "frozenDuration must be less than 3652 days and more than 1 days"); - //Freeze amount is -1, create failed - ret1 = PublicMethod.createAssetIssue2(lowBalAddress, name, totalSupply, 1, 10, - start, end, 2, description, url, 10000L, 10000L, - -1L, 1L, lowBalTest, blockingStubFull); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), + "Contract validate error : " + + "frozenDuration must be less than 3652 days and more than 1 days"); + // Freeze amount is -1, create failed + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + name, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + -1L, + 1L, + lowBalTest, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Frozen supply must be greater than 0!"); - //Freeze day is 3653(10 years + 1 day), create failed - ret1 = PublicMethod.createAssetIssue2(lowBalAddress, name, totalSupply, 1, 10, - start, end, 2, description, url, 10000L, 10000L, - 1L, 3653L, lowBalTest, blockingStubFull); + // Freeze day is 3653(10 years + 1 day), create failed + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + name, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3653L, + lowBalTest, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), "Contract validate error : " - + "frozenDuration must be less than 3652 days and more than 1 days"); - //Start time is late than end time. - ret1 = PublicMethod.createAssetIssue2(lowBalAddress, name, totalSupply, 1, 10, - end, start, 2, description, url, 10000L, 10000L, - 1L, 2L, lowBalTest, blockingStubFull); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), + "Contract validate error : " + + "frozenDuration must be less than 3652 days and more than 1 days"); + // Start time is late than end time. + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + name, + totalSupply, + 1, + 10, + end, + start, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 2L, + lowBalTest, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : End time should be greater than start time"); - //Start time is early than currently time. - ret1 = PublicMethod.createAssetIssue2(lowBalAddress, name, totalSupply, 1, 10, - start - 1000000L, end, 2, description, url, 10000L, - 10000L, 1L, 2L, lowBalTest, blockingStubFull); + // Start time is early than currently time. + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + name, + totalSupply, + 1, + 10, + start - 1000000L, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 2L, + lowBalTest, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Start time should be greater than HeadBlockTime"); - //totalSupply is zero. - ret1 = PublicMethod.createAssetIssue2(lowBalAddress, name, 0L, 1, 10, - start, end, 2, description, url, 10000L, 10000L, - 1L, 3652L, lowBalTest, blockingStubFull); + // totalSupply is zero. + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + name, + 0L, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + lowBalTest, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : TotalSupply must greater than 0!"); - //Totalsupply is -1. - ret1 = PublicMethod.createAssetIssue2(lowBalAddress, name, -1L, 1, 10, - start, end, 2, description, url, 10000L, 10000L, - 1L, 3652L, lowBalTest, blockingStubFull); + // Totalsupply is -1. + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + name, + -1L, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + lowBalTest, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : TotalSupply must greater than 0!"); - //TrxNum is zero. - ret1 = PublicMethod.createAssetIssue2(lowBalAddress, name, totalSupply, 0, 10, - start, end, 2, description, url, 10000L, 10000L, - 1L, 3652L, lowBalTest, blockingStubFull); + // TrxNum is zero. + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + name, + totalSupply, + 0, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + lowBalTest, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : TrxNum must greater than 0!"); - //TrxNum is -1. - ret1 = PublicMethod.createAssetIssue2(lowBalAddress, name, totalSupply, -1, 10, - start, end, 2, description, url, 10000L, 10000L, - 1L, 3652L, lowBalTest, blockingStubFull); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : TrxNum must greater than 0!"); + // TrxNum is -1. + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + name, + totalSupply, + -1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + lowBalTest, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : TrxNum must greater than 0!"); - //IcoNum is 0. - ret1 = PublicMethod.createAssetIssue2(lowBalAddress, name, totalSupply, 1, 0, - start, end, 2, description, url, 10000L, 10000L, - 1L, 3652L, foundationKey, blockingStubFull); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : TrxNum must greater than 0!"); + // IcoNum is 0. + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + name, + totalSupply, + 1, + 0, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + foundationKey, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : Num must greater than 0!"); - //IcoNum is -1. - ret1 = PublicMethod.createAssetIssue2(lowBalAddress, name, totalSupply, 1, -1, - start, end, 2, description, url, 10000L, 10000L, - 1L, 3652L, lowBalTest, blockingStubFull); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Num must greater than 0!"); + // IcoNum is -1. + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + name, + totalSupply, + 1, + -1, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + lowBalTest, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : Num must greater than 0!"); - //The asset issue name is null. - ret1 = PublicMethod.createAssetIssue2(lowBalAddress, "", totalSupply, 1, 10, - start, end, 2, description, url, 10000L, 10000L, - 1L, 3652L, lowBalTest, blockingStubFull); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Num must greater than 0!"); + // The asset issue name is null. + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + "", + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + lowBalTest, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : Invalid assetName"); - //The asset issue name is large than 33 char. - ret1 = PublicMethod.createAssetIssue2(lowBalAddress, tooLongName, totalSupply, 1, 10, - start, end, 2, description, url, 10000L, 10000L, - 1L, 3652L, lowBalTest, blockingStubFull); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Invalid assetName"); + // The asset issue name is large than 33 char. + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + tooLongName, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + lowBalTest, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : Invalid assetName"); - //The asset issue name is chinese name. - ret1 = PublicMethod.createAssetIssue2(lowBalAddress, chineseAssetIssuename, totalSupply, 1, - 10, start, end, 2, description, url, 10000L, - 10000L, 1L, 3652L, lowBalTest, blockingStubFull); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Invalid assetName"); + // The asset issue name is chinese name. + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + chineseAssetIssuename, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + lowBalTest, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : Invalid assetName"); - //The URL is null. - ret1 = PublicMethod.createAssetIssue2(lowBalAddress, name, totalSupply, 1, 10, - start, end, 2, description, "", 10000L, 10000L, - 1L, 3652L, lowBalTest, blockingStubFull); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Invalid assetName"); + // The URL is null. + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + name, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + "", + 10000L, + 10000L, + 1L, + 3652L, + lowBalTest, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); Assert.assertEquals(ret1.getMessage().toStringUtf8(), "Contract validate error : Invalid url"); - //The URL is too long. - ret1 = PublicMethod.createAssetIssue2(lowBalAddress, name, totalSupply, 1, 10, - start, end, 2, description, tooLongUrl, 10000L, 10000L, - 1L, 3652L, lowBalTest, blockingStubFull); + // The URL is too long. + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + name, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + tooLongUrl, + 10000L, + 10000L, + 1L, + 3652L, + lowBalTest, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); Assert.assertEquals(ret1.getMessage().toStringUtf8(), "Contract validate error : Invalid url"); - //The description is too long, create failed. - ret1 = PublicMethod.createAssetIssue2(lowBalAddress, name, totalSupply, 1, 10, - start, end, 2, tooLongDescription, url, 10000L, - 10000L, 1L, 3652L, lowBalTest, blockingStubFull); + // The description is too long, create failed. + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + name, + totalSupply, + 1, + 10, + start, + end, + 2, + tooLongDescription, + url, + 10000L, + 10000L, + 1L, + 3652L, + lowBalTest, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : Invalid description"); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Invalid description"); - //FreezeBalance - Assert.assertTrue(PublicMethod.freezeBalance(lowBalAddress, 10000000L, 3, lowBalTest, - blockingStubFull)); - //Create success + // FreezeBalance + Assert.assertTrue( + PublicMethod.freezeBalance(lowBalAddress, 10000000L, 3, lowBalTest, blockingStubFull)); + // Create success start = System.currentTimeMillis() + 6000; end = System.currentTimeMillis() + 1000000000; - ret1 = PublicMethod.createAssetIssue2(lowBalAddress, name, totalSupply, 1, 10, - start, end, 2, description, url, 10000L, 10000L, - 1L, 3652L, lowBalTest, blockingStubFull); + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + name, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + lowBalTest, + blockingStubFull); Assert.assertEquals(ret1.getCode(), Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); - //Test not in the duration time, participate failed. - ret1 = PublicMethod.participateAssetIssue2(lowBalAddress, name.getBytes(), 1L, - toAddress, lowBalTest, blockingStubFull); + // Test not in the duration time, participate failed. + ret1 = + PublicMethod.participateAssetIssue2( + lowBalAddress, name.getBytes(), 1L, toAddress, lowBalTest, blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : No longer valid period!"); - //Test another address try to create the same name asset issue, create failed. - ret1 = PublicMethod.createAssetIssue2(lowBalAddress2, name, totalSupply, 1, 10, - start, end, 2, description, url, 10000L, 10000L, - 1L, 3652L, lowBalTest2, blockingStubFull); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : No longer valid period!"); + // Test another address try to create the same name asset issue, create failed. + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress2, + name, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + lowBalTest2, + blockingStubFull); Assert.assertEquals(ret1.getCode(), Return.response_code.CONTRACT_VALIDATE_ERROR); Assert.assertEquals(ret1.getMessage().toStringUtf8(), "contract validate error : Token exists"); @@ -268,27 +610,42 @@ public void testGetAllAssetIssue2() { e.printStackTrace(); } - GrpcAPI.AssetIssueList assetIssueList = blockingStubFull - .getAssetIssueList(GrpcAPI.EmptyMessage.newBuilder().build()); + GrpcAPI.AssetIssueList assetIssueList = + blockingStubFull.getAssetIssueList(GrpcAPI.EmptyMessage.newBuilder().build()); logger.info(Integer.toString(assetIssueList.getAssetIssue(0).getFrozenSupplyCount())); Assert.assertTrue(assetIssueList.getAssetIssue(0).getFrozenSupplyCount() == 1); - //Assert.assertTrue(assetIssueList.getAssetIssue(j).getFrozenSupplyCount() > 0); + // Assert.assertTrue(assetIssueList.getAssetIssue(j).getFrozenSupplyCount() > 0); Assert.assertTrue(assetIssueList.getAssetIssue(0).getFrozenSupply(0).getFrozenAmount() > 0); Assert.assertTrue(assetIssueList.getAssetIssue(0).getFrozenSupply(0).getFrozenDays() > 0); - //Test one account only can create one asset issue. + // Test one account only can create one asset issue. start = System.currentTimeMillis() + 3000; end = System.currentTimeMillis() + 1000000000; - ret1 = PublicMethod.createAssetIssue2(lowBalAddress, shortname, totalSupply, 1, 10, - start, end, 2, description, url, 10000L, 10000L, - 1L, 3652L, foundationKey, blockingStubFull); + ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + shortname, + totalSupply, + 1, + 10, + start, + end, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 3652L, + foundationKey, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : An account can only issue one asset"); logger.info("FROM ADDRESS create asset issue in this case!!!"); - assetIssueList = blockingStubFull - .getAssetIssueList(GrpcAPI.EmptyMessage.newBuilder().build()); + assetIssueList = blockingStubFull.getAssetIssueList(GrpcAPI.EmptyMessage.newBuilder().build()); Assert.assertTrue(assetIssueList.getAssetIssueCount() >= 1); for (Integer j = 0; j < assetIssueList.getAssetIssueCount(); j++) { Assert.assertFalse(assetIssueList.getAssetIssue(j).getOwnerAddress().isEmpty()); @@ -298,24 +655,30 @@ public void testGetAllAssetIssue2() { logger.info("test get all assetissue"); } - //Improve coverage. + // Improve coverage. assetIssueList.equals(assetIssueList); assetIssueList.equals(null); - GrpcAPI.AssetIssueList newAssetIssueList = blockingStubFull - .getAssetIssueList(GrpcAPI.EmptyMessage.newBuilder().build()); + GrpcAPI.AssetIssueList newAssetIssueList = + blockingStubFull.getAssetIssueList(GrpcAPI.EmptyMessage.newBuilder().build()); assetIssueList.equals(newAssetIssueList); assetIssueList.hashCode(); assetIssueList.getSerializedSize(); - } - /** - * constructor. - */ - - public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, Integer trxNum, - Integer icoNum, Long startTime, Long endTime, - Integer voteScore, String description, String url, Long fronzenAmount, Long frozenDay, + /** constructor. */ + public Boolean createAssetIssue( + byte[] address, + String name, + Long totalSupply, + Integer trxNum, + Integer icoNum, + Long startTime, + Long endTime, + Integer voteScore, + String description, + String url, + Long fronzenAmount, + Long frozenDay, String priKey) { ECKey temKey = null; try { @@ -342,8 +705,7 @@ public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, I builder.setPublicFreeAssetNetLimit(10000); builder.setUrl(ByteString.copyFrom(url.getBytes())); AssetIssueContract.FrozenSupply.Builder frozenBuilder = - AssetIssueContract.FrozenSupply - .newBuilder(); + AssetIssueContract.FrozenSupply.newBuilder(); frozenBuilder.setFrozenAmount(fronzenAmount); frozenBuilder.setFrozenDays(frozenDay); builder.addFrozenSupply(0, frozenBuilder); @@ -368,14 +730,11 @@ public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, I } } - /** - * constructor. - */ - + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; @@ -391,25 +750,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ - + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ - + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -421,12 +773,9 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } - /** - * constructor. - */ - - public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] address, - String priKey) { + /** constructor. */ + public boolean transferAsset( + byte[] to, byte[] assertName, long amount, byte[] address, String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -458,13 +807,9 @@ public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] a Account search = queryAccount(ecKey, blockingStubFull); return true; } - } - /** - * constructor. - */ - + /** constructor. */ public boolean unFreezeAsset(byte[] addRess, String priKey) { byte[] address = addRess; @@ -477,8 +822,7 @@ public boolean unFreezeAsset(byte[] addRess, String priKey) { } final ECKey ecKey = temKey; - UnfreezeAssetContract.Builder builder = UnfreezeAssetContract - .newBuilder(); + UnfreezeAssetContract.Builder builder = UnfreezeAssetContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddreess); @@ -502,10 +846,7 @@ public boolean unFreezeAsset(byte[] addRess, String priKey) { } } - /** - * constructor. - */ - + /** constructor. */ public boolean unFreezeAsset2(byte[] addRess, String priKey) { byte[] address = addRess; @@ -518,8 +859,7 @@ public boolean unFreezeAsset2(byte[] addRess, String priKey) { } final ECKey ecKey = temKey; - UnfreezeAssetContract.Builder builder = UnfreezeAssetContract - .newBuilder(); + UnfreezeAssetContract.Builder builder = UnfreezeAssetContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddreess); @@ -555,12 +895,9 @@ public boolean unFreezeAsset2(byte[] addRess, String priKey) { } } - /** - * constructor. - */ - - public boolean participateAssetIssue(byte[] to, byte[] assertName, long amount, byte[] from, - String priKey) { + /** constructor. */ + public boolean participateAssetIssue( + byte[] to, byte[] assertName, long amount, byte[] from, String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -570,8 +907,7 @@ public boolean participateAssetIssue(byte[] to, byte[] assertName, long amount, } final ECKey ecKey = temKey; - ParticipateAssetIssueContract.Builder builder = ParticipateAssetIssueContract - .newBuilder(); + ParticipateAssetIssueContract.Builder builder = ParticipateAssetIssueContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); ByteString bsName = ByteString.copyFrom(assertName); ByteString bsOwner = ByteString.copyFrom(from); @@ -592,6 +928,4 @@ public boolean participateAssetIssue(byte[] to, byte[] assertName, long amount, return true; } } - } - diff --git a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/UpdateAccount2Test.java b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/UpdateAccount2Test.java index 284a4350..84395e29 100644 --- a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/UpdateAccount2Test.java +++ b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/UpdateAccount2Test.java @@ -1,7 +1,6 @@ package stest.tron.wallet.newaddinterface2; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import java.math.BigInteger; import java.util.Comparator; import java.util.HashMap; @@ -10,7 +9,6 @@ import org.apache.commons.lang3.StringUtils; import org.bouncycastle.util.encoders.Hex; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI; @@ -28,13 +26,13 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; +import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; -//import stest.tron.wallet.common.client.AccountComparator; +// import stest.tron.wallet.common.client.AccountComparator; @Slf4j public class UpdateAccount2Test extends TronBaseTest { @@ -42,59 +40,60 @@ public class UpdateAccount2Test extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final String name = "testAssetIssue_" + Long.toString(now); private static final long TotalSupply = now; - //testng001、testng002、testng003、testng004 - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + // testng001、testng002、testng003、testng004 + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); - String mostLongNamePlusOneChar = "1abcdeabcdefabcdefg1abcdefg10o0og1abcdefg10o0oabcd" - + "efabcdefg1abcdefg10o0og1abcdefg10o0oabcdefabcdefg1abcdefg10o0og1abcdefg10o0oab" - + "cdefabcdefg1abcdefg10o0og1abcdefg10o0ofabcdefg1abcdefg10o0og1abcdefg10o0o"; - String mostLongName = "abcdeabcdefabcdefg1abcdefg10o0og1abcdefg10o0oabcd" - + "efabcdefg1abcdefg10o0og1abcdefg10o0oabcdefabcdefg1abcdefg10o0og1abcdefg10o0oab" - + "cdefabcdefg1abcdefg10o0og1abcdefg10o0ofabcdefg1abcdefg10o0og1abcdefg10o0o"; + String mostLongNamePlusOneChar = + "1abcdeabcdefabcdefg1abcdefg10o0og1abcdefg10o0oabcd" + + "efabcdefg1abcdefg10o0og1abcdefg10o0oabcdefabcdefg1abcdefg10o0og1abcdefg10o0oab" + + "cdefabcdefg1abcdefg10o0og1abcdefg10o0ofabcdefg1abcdefg10o0og1abcdefg10o0o"; + String mostLongName = + "abcdeabcdefabcdefg1abcdefg10o0og1abcdefg10o0oabcd" + + "efabcdefg1abcdefg10o0og1abcdefg10o0oabcdefabcdefg1abcdefg10o0og1abcdefg10o0oab" + + "cdefabcdefg1abcdefg10o0og1abcdefg10o0ofabcdefg1abcdefg10o0og1abcdefg10o0o"; String description = "just-test"; String url = "https://github.com/tronprotocol/wallet-cli/"; - //get account + // get account ECKey ecKey = new ECKey(Utils.getRandom()); byte[] lowBalAddress = ecKey.getAddress(); String lowBalTest = ByteArray.toHexString(ecKey.getPrivKeyBytes()); - //System.out.println(); - //get account + // System.out.println(); + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] noBandwitchAddress = ecKey1.getAddress(); String noBandwitch = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - /** - * constructor. - */ - + /** constructor. */ @BeforeClass public void beforeClass() { - PublicMethod.printAddress(lowBalTest); } + PublicMethod.printAddress(lowBalTest); + } @Test public void testCreateAccount2() { Account noCreateAccount = queryAccount(lowBalTest, blockingStubFull); if (noCreateAccount.getAccountName().isEmpty()) { - Assert.assertTrue(PublicMethod.freezeBalance(fromAddress, 10000000, 3, foundationKey, - blockingStubFull)); - //Assert.assertTrue(sendCoin2(lowBalAddress, 1L, fromAddress, foundationKey)); + Assert.assertTrue( + PublicMethod.freezeBalance(fromAddress, 10000000, 3, foundationKey, blockingStubFull)); + // Assert.assertTrue(sendCoin2(lowBalAddress, 1L, fromAddress, foundationKey)); GrpcAPI.Return ret1 = sendCoin2(lowBalAddress, 1000000L, fromAddress, foundationKey); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); - //Assert.assertTrue(Sendcoin(Low_Bal_ADDRESS, 1000000L, fromAddress, foundationKey)); + // Assert.assertTrue(Sendcoin(Low_Bal_ADDRESS, 1000000L, fromAddress, foundationKey)); noCreateAccount = queryAccount(lowBalTest, blockingStubFull); logger.info(Long.toString(noCreateAccount.getBalance())); - //Assert.assertTrue(noCreateAccount.getBalance() == 1); + // Assert.assertTrue(noCreateAccount.getBalance() == 1); - //TestVoteToNonWitnessAccount + // TestVoteToNonWitnessAccount String voteStr = Base58.encode58Check(lowBalAddress); HashMap voteToNonWitnessAccount = new HashMap(); @@ -103,16 +102,17 @@ public void testCreateAccount2() { HashMap voteToInvaildAddress = new HashMap(); voteToInvaildAddress.put("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48SS", "4"); - //TQkJsN2Q2sZV9H2dQ5x2rSneKNyLQgegVv + // TQkJsN2Q2sZV9H2dQ5x2rSneKNyLQgegVv ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] lowBalAddress2 = ecKey2.getAddress(); - ret1 = PublicMethod.sendcoin2(lowBalAddress2, 21245000000L, - fromAddress, foundationKey, blockingStubFull); + ret1 = + PublicMethod.sendcoin2( + lowBalAddress2, 21245000000L, fromAddress, foundationKey, blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.SUCCESS); - WitnessList witnesslist = blockingStubFull - .listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build()); + WitnessList witnesslist = + blockingStubFull.listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build()); Optional result = Optional.ofNullable(witnesslist); WitnessList witnessList = result.get(); if (result.get().getWitnessesCount() < 6) { @@ -129,22 +129,23 @@ public void testCreateAccount2() { ret1 = voteWitness2(voteToWitAddress, fromAddress, foundationKey); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); - //logger.info("vote to non witness account ok!!!"); + // logger.info("vote to non witness account ok!!!"); } - //normal freezeBalance - //Assert.assertTrue(freezeBalance2(fromAddress, 10000000L, 3L, foundationKey)) + // normal freezeBalance + // Assert.assertTrue(freezeBalance2(fromAddress, 10000000L, 3L, foundationKey)) ret1 = freezeBalance2(fromAddress, 100000000L, 3L, foundationKey); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); - //vote To NonWitnessAccount + // vote To NonWitnessAccount ret1 = voteWitness2(voteToNonWitnessAccount, fromAddress, foundationKey); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - //vote to InvaildAddress + // vote to InvaildAddress ret1 = voteWitness2(voteToInvaildAddress, fromAddress, foundationKey); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : VoteNumber must more than 0"); } else { @@ -157,28 +158,27 @@ public void testCreateAccount2() { public void testUpdateAccount2() { Account tryToUpdateAccount = queryAccount(lowBalTest, blockingStubFull); if (tryToUpdateAccount.getAccountName().isEmpty()) { - GrpcAPI.Return ret1 = updateAccount2(lowBalAddress, mostLongNamePlusOneChar.getBytes(), - lowBalTest); + GrpcAPI.Return ret1 = + updateAccount2(lowBalAddress, mostLongNamePlusOneChar.getBytes(), lowBalTest); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : Invalid accountName"); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Invalid accountName"); ret1 = updateAccount2(lowBalAddress, "".getBytes(), lowBalTest); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : This name is existed"); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : This name is existed"); System.out.println("dingwei2:"); ret1 = updateAccount2(lowBalAddress, mostLongName.getBytes(), lowBalTest); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : This name is existed"); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : This name is existed"); ret1 = updateAccount2(lowBalAddress, "secondUpdateName".getBytes(), lowBalTest); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : This name is existed"); - + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : This name is existed"); } } @@ -190,51 +190,63 @@ public void testNoBalanceCreateAssetIssue2() { } System.out.println("1111112222"); - GrpcAPI.Return ret1 = PublicMethod.createAssetIssue2(lowBalAddress, name, TotalSupply, 1, 1, - now + 100000000L, now + 10000000000L, 2, description, url, 10000L, - 10000L, 1L, 1L, lowBalTest, blockingStubFull); + GrpcAPI.Return ret1 = + PublicMethod.createAssetIssue2( + lowBalAddress, + name, + TotalSupply, + 1, + 1, + now + 100000000L, + now + 10000000000L, + 2, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + lowBalTest, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : No enough balance for fee!"); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : No enough balance for fee!"); logger.info("nobalancecreateassetissue"); } @Test(enabled = true) public void testNoBalanceTransferTrx2() { - //Send Coin failed when there is no enough balance. + // Send Coin failed when there is no enough balance. Assert.assertFalse(sendCoin(toAddress, 100000000000000000L, lowBalAddress, lowBalTest)); } @Test(enabled = true) public void testNoBalanceCreateWitness2() { - //Apply to be super witness failed when no enough balance. - //Assert.assertFalse(createWitness2(lowBalAddress, fromAddress, lowBalTest)); + // Apply to be super witness failed when no enough balance. + // Assert.assertFalse(createWitness2(lowBalAddress, fromAddress, lowBalTest)); System.out.println("1111222333:" + lowBalAddress); GrpcAPI.Return ret1 = createWitness2(lowBalAddress, fromAddress, lowBalTest); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : balance < AccountUpgradeCost"); - + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : balance < AccountUpgradeCost"); } @Test(enabled = true) public void testNoFreezeBalanceToUnfreezeBalance2() { - //Unfreeze account failed when no freeze balance + // Unfreeze account failed when no freeze balance Account noFreezeAccount = queryAccount(lowBalTest, blockingStubFull); if (noFreezeAccount.getFrozenCount() == 0) { GrpcAPI.Return ret1 = unFreezeBalance2(lowBalAddress, lowBalTest); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : no frozenBalance(BANDWIDTH)"); } else { logger.info("This account has freeze balance, please test this case for manual"); } } - /** - * constructor. - */ - + /** constructor. */ public Boolean createWitness(byte[] owner, byte[] url, String priKey) { ECKey temKey = null; try { @@ -245,8 +257,8 @@ public Boolean createWitness(byte[] owner, byte[] url, String priKey) { } final ECKey ecKey = temKey; - WitnessContract.WitnessCreateContract.Builder builder = WitnessContract.WitnessCreateContract - .newBuilder(); + WitnessContract.WitnessCreateContract.Builder builder = + WitnessContract.WitnessCreateContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(owner)); builder.setUrl(ByteString.copyFrom(url)); WitnessContract.WitnessCreateContract contract = builder.build(); @@ -259,10 +271,7 @@ public Boolean createWitness(byte[] owner, byte[] url, String priKey) { return response.getResult(); } - /** - * constructor. - */ - + /** constructor. */ public GrpcAPI.Return createWitness2(byte[] owner, byte[] url, String priKey) { ECKey temKey = null; try { @@ -273,8 +282,8 @@ public GrpcAPI.Return createWitness2(byte[] owner, byte[] url, String priKey) { } final ECKey ecKey = temKey; - WitnessContract.WitnessCreateContract.Builder builder = WitnessContract.WitnessCreateContract - .newBuilder(); + WitnessContract.WitnessCreateContract.Builder builder = + WitnessContract.WitnessCreateContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(owner)); builder.setUrl(ByteString.copyFrom(url)); WitnessContract.WitnessCreateContract contract = builder.build(); @@ -307,12 +316,9 @@ public GrpcAPI.Return createWitness2(byte[] owner, byte[] url, String priKey) { return ret; } - /** - * constructor. - */ - + /** constructor. */ public Boolean sendCoin(byte[] to, long amount, byte[] owner, String priKey) { - //String priKey = foundationKey; + // String priKey = foundationKey; ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -322,8 +328,8 @@ public Boolean sendCoin(byte[] to, long amount, byte[] owner, String priKey) { } final ECKey ecKey = temKey; - BalanceContract.TransferContract.Builder builder = BalanceContract.TransferContract - .newBuilder(); + BalanceContract.TransferContract.Builder builder = + BalanceContract.TransferContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); ByteString bsOwner = ByteString.copyFrom(owner); builder.setToAddress(bsTo); @@ -344,12 +350,9 @@ public Boolean sendCoin(byte[] to, long amount, byte[] owner, String priKey) { return response.getResult(); } - /** - * constructor. - */ - + /** constructor. */ public GrpcAPI.Return sendCoin2(byte[] to, long amount, byte[] owner, String priKey) { - //String priKey = foundationKey; + // String priKey = foundationKey; ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -359,8 +362,8 @@ public GrpcAPI.Return sendCoin2(byte[] to, long amount, byte[] owner, String pri } final ECKey ecKey = temKey; - BalanceContract.TransferContract.Builder builder = BalanceContract.TransferContract - .newBuilder(); + BalanceContract.TransferContract.Builder builder = + BalanceContract.TransferContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); ByteString bsOwner = ByteString.copyFrom(owner); builder.setToAddress(bsTo); @@ -368,8 +371,8 @@ public GrpcAPI.Return sendCoin2(byte[] to, long amount, byte[] owner, String pri builder.setAmount(amount); BalanceContract.TransferContract contract = builder.build(); - GrpcAPI.TransactionExtention transactionExtention = blockingStubFull - .createTransaction2(contract); + GrpcAPI.TransactionExtention transactionExtention = + blockingStubFull.createTransaction2(contract); if (transactionExtention == null) { return transactionExtention.getResult(); } @@ -400,13 +403,19 @@ public GrpcAPI.Return sendCoin2(byte[] to, long amount, byte[] owner, String pri return ret; } - /** - * constructor. - */ - - public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, Integer trxNum, - Integer icoNum, Long startTime, Long endTime, - Integer voteScore, String description, String url, String priKey) { + /** constructor. */ + public Boolean createAssetIssue( + byte[] address, + String name, + Long totalSupply, + Integer trxNum, + Integer icoNum, + Long startTime, + Long endTime, + Integer voteScore, + String description, + String url, + String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -418,8 +427,7 @@ public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, I try { AssetIssueContractOuterClass.AssetIssueContract.Builder builder = - AssetIssueContractOuterClass.AssetIssueContract - .newBuilder(); + AssetIssueContractOuterClass.AssetIssueContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(address)); builder.setName(ByteString.copyFrom(name.getBytes())); builder.setTotalSupply(TotalSupply); @@ -451,10 +459,7 @@ public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, I } } - /** - * constructor. - */ - + /** constructor. */ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; ECKey temKey = null; @@ -466,7 +471,7 @@ public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockin } ECKey ecKey = temKey; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; @@ -482,25 +487,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ - + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ - + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Protocol.Transaction signTransaction(ECKey ecKey, Protocol.Transaction transaction) { @@ -512,10 +510,7 @@ private Protocol.Transaction signTransaction(ECKey ecKey, Protocol.Transaction t return TransactionUtils.sign(transaction, ecKey); } - /** - * constructor. - */ - + /** constructor. */ public boolean updateAccount(byte[] addressBytes, byte[] accountNameBytes, String priKey) { ECKey temKey = null; try { @@ -552,12 +547,9 @@ public boolean updateAccount(byte[] addressBytes, byte[] accountNameBytes, Strin } } - /** - * constructor. - */ - - public GrpcAPI.Return updateAccount2(byte[] addressBytes, byte[] accountNameBytes, - String priKey) { + /** constructor. */ + public GrpcAPI.Return updateAccount2( + byte[] addressBytes, byte[] accountNameBytes, String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -609,10 +601,7 @@ public GrpcAPI.Return updateAccount2(byte[] addressBytes, byte[] accountNameByte } } - /** - * constructor. - */ - + /** constructor. */ public boolean unFreezeBalance(byte[] address, String priKey) { ECKey temKey = null; try { @@ -623,8 +612,7 @@ public boolean unFreezeBalance(byte[] address, String priKey) { } final ECKey ecKey = temKey; BalanceContract.UnfreezeBalanceContract.Builder builder = - BalanceContract.UnfreezeBalanceContract - .newBuilder(); + BalanceContract.UnfreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddreess); @@ -647,12 +635,9 @@ public boolean unFreezeBalance(byte[] address, String priKey) { } } - /** - * constructor. - */ - + /** constructor. */ public GrpcAPI.Return unFreezeBalance2(byte[] address, String priKey) { - //byte[] address = address; + // byte[] address = address; ECKey temKey = null; try { @@ -663,8 +648,7 @@ public GrpcAPI.Return unFreezeBalance2(byte[] address, String priKey) { } final ECKey ecKey = temKey; BalanceContract.UnfreezeBalanceContract.Builder builder = - BalanceContract.UnfreezeBalanceContract - .newBuilder(); + BalanceContract.UnfreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddreess); @@ -700,10 +684,7 @@ public GrpcAPI.Return unFreezeBalance2(byte[] address, String priKey) { return ret; } - /** - * constructor. - */ - + /** constructor. */ public Boolean voteWitness(HashMap witness, byte[] address, String priKey) { ECKey temKey = null; @@ -714,15 +695,14 @@ public Boolean voteWitness(HashMap witness, byte[] address, Stri ex.printStackTrace(); } final ECKey ecKey = temKey; - WitnessContract.VoteWitnessContract.Builder builder = WitnessContract.VoteWitnessContract - .newBuilder(); + WitnessContract.VoteWitnessContract.Builder builder = + WitnessContract.VoteWitnessContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(address)); for (String addressBase58 : witness.keySet()) { String value = witness.get(addressBase58); long count = Long.parseLong(value); WitnessContract.VoteWitnessContract.Vote.Builder voteBuilder = - WitnessContract.VoteWitnessContract.Vote - .newBuilder(); + WitnessContract.VoteWitnessContract.Vote.newBuilder(); byte[] addRess = WalletClient.decodeFromBase58Check(addressBase58); if (addRess == null) { return false; @@ -749,12 +729,9 @@ public Boolean voteWitness(HashMap witness, byte[] address, Stri return true; } - /** - * constructor. - */ - - public GrpcAPI.Return voteWitness2(HashMap witness, byte[] address, - String priKey) { + /** constructor. */ + public GrpcAPI.Return voteWitness2( + HashMap witness, byte[] address, String priKey) { ECKey temKey = null; try { @@ -764,15 +741,14 @@ public GrpcAPI.Return voteWitness2(HashMap witness, byte[] addre ex.printStackTrace(); } final ECKey ecKey = temKey; - WitnessContract.VoteWitnessContract.Builder builder = WitnessContract.VoteWitnessContract - .newBuilder(); + WitnessContract.VoteWitnessContract.Builder builder = + WitnessContract.VoteWitnessContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(address)); for (String addressBase58 : witness.keySet()) { String value = witness.get(addressBase58); long count = Long.parseLong(value); WitnessContract.VoteWitnessContract.Vote.Builder voteBuilder = - WitnessContract.VoteWitnessContract.Vote - .newBuilder(); + WitnessContract.VoteWitnessContract.Vote.newBuilder(); byte[] addRess = WalletClient.decodeFromBase58Check(addressBase58); if (addRess == null) { continue; @@ -784,8 +760,8 @@ public GrpcAPI.Return voteWitness2(HashMap witness, byte[] addre WitnessContract.VoteWitnessContract contract = builder.build(); - GrpcAPI.TransactionExtention transactionExtention = blockingStubFull - .voteWitnessAccount2(contract); + GrpcAPI.TransactionExtention transactionExtention = + blockingStubFull.voteWitnessAccount2(contract); if (transactionExtention == null) { return transactionExtention.getResult(); } @@ -816,12 +792,9 @@ public GrpcAPI.Return voteWitness2(HashMap witness, byte[] addre return ret; } - /** - * constructor. - */ - - public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDuration, - String priKey) { + /** constructor. */ + public Boolean freezeBalance( + byte[] addRess, long freezeBalance, long freezeDuration, String priKey) { byte[] address = addRess; long frozenBalance = freezeBalance; long frozenDuration = freezeDuration; @@ -835,11 +808,13 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura } final ECKey ecKey = temKey; - BalanceContract.FreezeBalanceContract.Builder builder = BalanceContract.FreezeBalanceContract - .newBuilder(); + BalanceContract.FreezeBalanceContract.Builder builder = + BalanceContract.FreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess).setFrozenBalance(frozenBalance) + builder + .setOwnerAddress(byteAddreess) + .setFrozenBalance(frozenBalance) .setFrozenDuration(frozenDuration); BalanceContract.FreezeBalanceContract contract = builder.build(); @@ -854,20 +829,16 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura GrpcAPI.Return response = blockingStubFull.broadcastTransaction(transaction); return response.getResult(); - } - /** - * constructor. - */ - - public GrpcAPI.Return freezeBalance2(byte[] addRess, long freezeBalance, long freezeDuration, - String priKey) { + /** constructor. */ + public GrpcAPI.Return freezeBalance2( + byte[] addRess, long freezeBalance, long freezeDuration, String priKey) { byte[] address = addRess; long frozenBalance = freezeBalance; long frozenDuration = freezeDuration; - //String priKey = foundationKey; + // String priKey = foundationKey; ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -877,11 +848,13 @@ public GrpcAPI.Return freezeBalance2(byte[] addRess, long freezeBalance, long fr } final ECKey ecKey = temKey; - BalanceContract.FreezeBalanceContract.Builder builder = BalanceContract.FreezeBalanceContract - .newBuilder(); + BalanceContract.FreezeBalanceContract.Builder builder = + BalanceContract.FreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess).setFrozenBalance(frozenBalance) + builder + .setOwnerAddress(byteAddreess) + .setFrozenBalance(frozenBalance) .setFrozenDuration(frozenDuration); BalanceContract.FreezeBalanceContract contract = builder.build(); @@ -922,6 +895,4 @@ public int compare(Object o1, Object o2) { return Long.compare(((Account) o2).getBalance(), ((Account) o1).getBalance()); } } - } - diff --git a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/UpdateAsset2Test.java b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/UpdateAsset2Test.java index 84d312e0..a6f58af9 100644 --- a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/UpdateAsset2Test.java +++ b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/UpdateAsset2Test.java @@ -22,8 +22,8 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class UpdateAsset2Test extends TronBaseTest { @@ -35,10 +35,11 @@ public class UpdateAsset2Test extends TronBaseTest { "1qazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcv" + "qazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswe" + "dcvqazxswedcvqazxswedcvqazxswedcvqazxswedcv"; - private static final String tooLongUrl = "qaswqaswqaswqaswqaswqaswqaswqaswqaswqaswqaswqas" - + "wqaswqasw1qazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazx" - + "swedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedc" - + "vqazxswedcvqazxswedcvqazxswedcvqazxswedcv"; + private static final String tooLongUrl = + "qaswqaswqaswqaswqaswqaswqaswqaswqaswqaswqaswqas" + + "wqaswqasw1qazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazx" + + "swedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedcvqazxswedc" + + "vqazxswedcvqazxswedcvqazxswedcvqazxswedcv"; private static String name = "testAssetIssue010_" + Long.toString(now); String description = "just-test"; String url = "https://github.com/tronprotocol/wallet-cli/"; @@ -48,72 +49,97 @@ public class UpdateAsset2Test extends TronBaseTest { Long publicFreeAssetNetLimit = 1000L; Long updateFreeAssetNetLimit = 10001L; Long updatePublicFreeAssetNetLimit = 10001L; - //get account + // get account ECKey ecKey = new ECKey(Utils.getRandom()); byte[] asset010Address = ecKey.getAddress(); String testKeyForAssetIssue010 = ByteArray.toHexString(ecKey.getPrivKeyBytes()); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void testUpdateAssetIssue2() { - //Sendcoin to this account + // Sendcoin to this account ByteString addressBS1 = ByteString.copyFrom(asset010Address); Account request1 = Account.newBuilder().setAddress(addressBS1).build(); - GrpcAPI.AssetIssueList assetIssueList1 = blockingStubFull - .getAssetIssueByAccount(request1); + GrpcAPI.AssetIssueList assetIssueList1 = blockingStubFull.getAssetIssueByAccount(request1); Optional queryAssetByAccount = Optional.ofNullable(assetIssueList1); if (queryAssetByAccount.get().getAssetIssueCount() == 0) { - //Assert.assertTrue(PublicMethod.freezeBalance(foundationAddress,10000000L,3, + // Assert.assertTrue(PublicMethod.freezeBalance(foundationAddress,10000000L,3, // foundationKey,blockingStubFull)); - Assert.assertTrue(PublicMethod - .sendcoin(asset010Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod - .freezeBalance(asset010Address, 200000000L, 3, testKeyForAssetIssue010, + Assert.assertTrue( + PublicMethod.sendcoin( + asset010Address, sendAmount, foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalance( + asset010Address, 200000000L, 3, testKeyForAssetIssue010, blockingStubFull)); + Long start = System.currentTimeMillis() + 2000; + Long end = System.currentTimeMillis() + 1000000000; + Assert.assertTrue( + PublicMethod.createAssetIssue( + asset010Address, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + freeAssetNetLimit, + publicFreeAssetNetLimit, + 1L, + 1L, + testKeyForAssetIssue010, blockingStubFull)); - Long start = System.currentTimeMillis() + 2000; - Long end = System.currentTimeMillis() + 1000000000; - Assert.assertTrue(PublicMethod.createAssetIssue(asset010Address, name, totalSupply, 1, 1, - start, end, 1, description, url, freeAssetNetLimit, publicFreeAssetNetLimit, - 1L, 1L, testKeyForAssetIssue010, blockingStubFull)); } else { logger.info("This account already create an assetisue"); Optional queryAssetByAccount1 = Optional.ofNullable(assetIssueList1); name = ByteArray.toStr(queryAssetByAccount1.get().getAssetIssue(0).getName().toByteArray()); - Assert.assertTrue(PublicMethod - .updateAsset(asset010Address, description.getBytes(), url.getBytes(), freeAssetNetLimit, - publicFreeAssetNetLimit, testKeyForAssetIssue010, blockingStubFull)); + Assert.assertTrue( + PublicMethod.updateAsset( + asset010Address, + description.getBytes(), + url.getBytes(), + freeAssetNetLimit, + publicFreeAssetNetLimit, + testKeyForAssetIssue010, + blockingStubFull)); } - //Query the description and url,freeAssetNetLimit and publicFreeAssetNetLimit + // Query the description and url,freeAssetNetLimit and publicFreeAssetNetLimit ByteString assetNameBs = ByteString.copyFrom(name.getBytes()); GrpcAPI.BytesMessage request = GrpcAPI.BytesMessage.newBuilder().setValue(assetNameBs).build(); - AssetIssueContractOuterClass.AssetIssueContract assetIssueByName = blockingStubFull - .getAssetIssueByName(request); + AssetIssueContractOuterClass.AssetIssueContract assetIssueByName = + blockingStubFull.getAssetIssueByName(request); Assert.assertTrue( ByteArray.toStr(assetIssueByName.getDescription().toByteArray()).equals(description)); Assert.assertTrue(ByteArray.toStr(assetIssueByName.getUrl().toByteArray()).equals(url)); Assert.assertTrue(assetIssueByName.getFreeAssetNetLimit() == freeAssetNetLimit); Assert.assertTrue(assetIssueByName.getPublicFreeAssetNetLimit() == publicFreeAssetNetLimit); - //Test update asset issue - Return ret1 = PublicMethod - .updateAsset2(asset010Address, updateDescription.getBytes(), updateUrl.getBytes(), + // Test update asset issue + Return ret1 = + PublicMethod.updateAsset2( + asset010Address, + updateDescription.getBytes(), + updateUrl.getBytes(), updateFreeAssetNetLimit, - updatePublicFreeAssetNetLimit, testKeyForAssetIssue010, blockingStubFull); + updatePublicFreeAssetNetLimit, + testKeyForAssetIssue010, + blockingStubFull); Assert.assertEquals(ret1.getCode(), Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); - //After update asset issue ,query the description and url, + // After update asset issue ,query the description and url, // freeAssetNetLimit and publicFreeAssetNetLimit assetNameBs = ByteString.copyFrom(name.getBytes()); request = GrpcAPI.BytesMessage.newBuilder().setValue(assetNameBs).build(); @@ -123,88 +149,147 @@ public void testUpdateAssetIssue2() { ByteArray.toStr(assetIssueByName.getDescription().toByteArray()).equals(updateDescription)); Assert.assertTrue(ByteArray.toStr(assetIssueByName.getUrl().toByteArray()).equals(updateUrl)); Assert.assertTrue(assetIssueByName.getFreeAssetNetLimit() == updateFreeAssetNetLimit); - Assert - .assertTrue(assetIssueByName.getPublicFreeAssetNetLimit() == updatePublicFreeAssetNetLimit); + Assert.assertTrue( + assetIssueByName.getPublicFreeAssetNetLimit() == updatePublicFreeAssetNetLimit); } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void testUpdateAssetIssueExcption2() { - //Test update asset issue for wrong parameter - //publicFreeAssetNetLimit is -1 - Return ret1 = PublicMethod - .updateAsset2(asset010Address, updateDescription.getBytes(), updateUrl.getBytes(), + // Test update asset issue for wrong parameter + // publicFreeAssetNetLimit is -1 + Return ret1 = + PublicMethod.updateAsset2( + asset010Address, + updateDescription.getBytes(), + updateUrl.getBytes(), updateFreeAssetNetLimit, - -1L, testKeyForAssetIssue010, blockingStubFull); + -1L, + testKeyForAssetIssue010, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Invalid PublicFreeAssetNetLimit"); - //publicFreeAssetNetLimit is 0 - ret1 = PublicMethod - .updateAsset2(asset010Address, updateDescription.getBytes(), updateUrl.getBytes(), + // publicFreeAssetNetLimit is 0 + ret1 = + PublicMethod.updateAsset2( + asset010Address, + updateDescription.getBytes(), + updateUrl.getBytes(), updateFreeAssetNetLimit, - 0, testKeyForAssetIssue010, blockingStubFull); + 0, + testKeyForAssetIssue010, + blockingStubFull); Assert.assertEquals(ret1.getCode(), Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); - //FreeAssetNetLimit is -1 - ret1 = PublicMethod - .updateAsset2(asset010Address, updateDescription.getBytes(), updateUrl.getBytes(), -1, - publicFreeAssetNetLimit, testKeyForAssetIssue010, blockingStubFull); + // FreeAssetNetLimit is -1 + ret1 = + PublicMethod.updateAsset2( + asset010Address, + updateDescription.getBytes(), + updateUrl.getBytes(), + -1, + publicFreeAssetNetLimit, + testKeyForAssetIssue010, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : Invalid FreeAssetNetLimit"); - //FreeAssetNetLimit is 0 - ret1 = PublicMethod - .updateAsset2(asset010Address, updateDescription.getBytes(), updateUrl.getBytes(), 0, - publicFreeAssetNetLimit, testKeyForAssetIssue010, blockingStubFull); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Invalid FreeAssetNetLimit"); + // FreeAssetNetLimit is 0 + ret1 = + PublicMethod.updateAsset2( + asset010Address, + updateDescription.getBytes(), + updateUrl.getBytes(), + 0, + publicFreeAssetNetLimit, + testKeyForAssetIssue010, + blockingStubFull); Assert.assertEquals(ret1.getCode(), Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); - //Description is null - ret1 = PublicMethod - .updateAsset2(asset010Address, "".getBytes(), updateUrl.getBytes(), freeAssetNetLimit, - publicFreeAssetNetLimit, testKeyForAssetIssue010, blockingStubFull); + // Description is null + ret1 = + PublicMethod.updateAsset2( + asset010Address, + "".getBytes(), + updateUrl.getBytes(), + freeAssetNetLimit, + publicFreeAssetNetLimit, + testKeyForAssetIssue010, + blockingStubFull); Assert.assertEquals(ret1.getCode(), Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); - //Url is null - ret1 = PublicMethod - .updateAsset2(asset010Address, description.getBytes(), "".getBytes(), freeAssetNetLimit, - publicFreeAssetNetLimit, testKeyForAssetIssue010, blockingStubFull); + // Url is null + ret1 = + PublicMethod.updateAsset2( + asset010Address, + description.getBytes(), + "".getBytes(), + freeAssetNetLimit, + publicFreeAssetNetLimit, + testKeyForAssetIssue010, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); Assert.assertEquals(ret1.getMessage().toStringUtf8(), "Contract validate error : Invalid url"); - //Too long discription - ret1 = PublicMethod - .updateAsset2(asset010Address, tooLongDescription.getBytes(), url.getBytes(), + // Too long discription + ret1 = + PublicMethod.updateAsset2( + asset010Address, + tooLongDescription.getBytes(), + url.getBytes(), freeAssetNetLimit, - publicFreeAssetNetLimit, testKeyForAssetIssue010, blockingStubFull); + publicFreeAssetNetLimit, + testKeyForAssetIssue010, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), - "Contract validate error : Invalid description"); - //Too long URL - ret1 = PublicMethod - .updateAsset2(asset010Address, description.getBytes(), tooLongUrl.getBytes(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : Invalid description"); + // Too long URL + ret1 = + PublicMethod.updateAsset2( + asset010Address, + description.getBytes(), + tooLongUrl.getBytes(), freeAssetNetLimit, - publicFreeAssetNetLimit, testKeyForAssetIssue010, blockingStubFull); + publicFreeAssetNetLimit, + testKeyForAssetIssue010, + blockingStubFull); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); Assert.assertEquals(ret1.getMessage().toStringUtf8(), "Contract validate error : Invalid url"); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - Return ret1 = PublicMethod - .updateAsset2(asset010Address, description.getBytes(), url.getBytes(), 1999999999, - 199, testKeyForAssetIssue010, blockingStubFull); + Return ret1 = + PublicMethod.updateAsset2( + asset010Address, + description.getBytes(), + url.getBytes(), + 1999999999, + 199, + testKeyForAssetIssue010, + blockingStubFull); Assert.assertEquals(ret1.getCode(), Return.response_code.SUCCESS); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); } + Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); + } - /** - * constructor. - */ - public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, Integer trxNum, - Integer icoNum, Long startTime, Long endTime, - Integer voteScore, String description, String url, Long fronzenAmount, Long frozenDay, + /** constructor. */ + public Boolean createAssetIssue( + byte[] address, + String name, + Long totalSupply, + Integer trxNum, + Integer icoNum, + Long startTime, + Long endTime, + Integer voteScore, + String description, + String url, + Long fronzenAmount, + Long frozenDay, String priKey) { ECKey temKey = null; try { @@ -218,8 +303,7 @@ public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, I try { AssetIssueContractOuterClass.AssetIssueContract.Builder builder = - AssetIssueContractOuterClass.AssetIssueContract - .newBuilder(); + AssetIssueContractOuterClass.AssetIssueContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(address)); builder.setName(ByteString.copyFrom(name.getBytes())); builder.setTotalSupply(totalSupply); @@ -231,8 +315,7 @@ public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, I builder.setDescription(ByteString.copyFrom(description.getBytes())); builder.setUrl(ByteString.copyFrom(url.getBytes())); AssetIssueContractOuterClass.AssetIssueContract.FrozenSupply.Builder frozenBuilder = - AssetIssueContractOuterClass.AssetIssueContract.FrozenSupply - .newBuilder(); + AssetIssueContractOuterClass.AssetIssueContract.FrozenSupply.newBuilder(); frozenBuilder.setFrozenAmount(fronzenAmount); frozenBuilder.setFrozenDays(frozenDay); builder.addFrozenSupply(0, frozenBuilder); @@ -257,19 +340,17 @@ public Boolean createAssetIssue(byte[] address, String name, Long totalSupply, I } } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -279,23 +360,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -307,11 +383,9 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } - /** - * constructor. - */ - public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] address, - String priKey) { + /** constructor. */ + public boolean transferAsset( + byte[] to, byte[] assertName, long amount, byte[] address, String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -322,8 +396,7 @@ public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] a final ECKey ecKey = temKey; AssetIssueContractOuterClass.TransferAssetContract.Builder builder = - AssetIssueContractOuterClass.TransferAssetContract - .newBuilder(); + AssetIssueContractOuterClass.TransferAssetContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); ByteString bsName = ByteString.copyFrom(assertName); ByteString bsOwner = ByteString.copyFrom(address); @@ -345,15 +418,12 @@ public boolean transferAsset(byte[] to, byte[] assertName, long amount, byte[] a Account search = queryAccount(ecKey, blockingStubFull); return true; } - } - /** - * constructor. - */ + /** constructor. */ public boolean unFreezeAsset(byte[] addRess, String priKey) { byte[] address = addRess; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -363,8 +433,7 @@ public boolean unFreezeAsset(byte[] addRess, String priKey) { final ECKey ecKey = temKey; AssetIssueContractOuterClass.UnfreezeAssetContract.Builder builder = - AssetIssueContractOuterClass.UnfreezeAssetContract - .newBuilder(); + AssetIssueContractOuterClass.UnfreezeAssetContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddreess); @@ -387,11 +456,9 @@ public boolean unFreezeAsset(byte[] addRess, String priKey) { } } - /** - * constructor. - */ - public boolean participateAssetIssue(byte[] to, byte[] assertName, long amount, byte[] from, - String priKey) { + /** constructor. */ + public boolean participateAssetIssue( + byte[] to, byte[] assertName, long amount, byte[] from, String priKey) { ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -402,8 +469,7 @@ public boolean participateAssetIssue(byte[] to, byte[] assertName, long amount, final ECKey ecKey = temKey; AssetIssueContractOuterClass.ParticipateAssetIssueContract.Builder builder = - AssetIssueContractOuterClass.ParticipateAssetIssueContract - .newBuilder(); + AssetIssueContractOuterClass.ParticipateAssetIssueContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); ByteString bsName = ByteString.copyFrom(assertName); ByteString bsOwner = ByteString.copyFrom(from); @@ -423,7 +489,4 @@ public boolean participateAssetIssue(byte[] to, byte[] assertName, long amount, return true; } } - } - - diff --git a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/VoteWitnessAccount2Test.java b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/VoteWitnessAccount2Test.java index bc9cecbd..0bff826f 100644 --- a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/VoteWitnessAccount2Test.java +++ b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/VoteWitnessAccount2Test.java @@ -30,60 +30,61 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; +import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; -import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; @Slf4j @MultiNode public class VoteWitnessAccount2Test extends TronBaseTest { { fullnode = config.getStringList("fullnode.ip.list").get(1); - } private ManagedChannel searchChannelFull = null; private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; private String searchFullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + } + + private ManagedChannel searchChannelFull = null; + private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; + private String searchFullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - /** - * constructor. - */ - + /** constructor. */ @BeforeClass public void beforeClass() { WalletClient.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); - logger.info("Pre fix byte ===== " + WalletClient.getAddressPreFixByte()); searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode) - .usePlaintext() - .build(); + logger.info("Pre fix byte ===== " + WalletClient.getAddressPreFixByte()); + searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode).usePlaintext().build(); searchBlockingStubFull = WalletGrpc.newBlockingStub(searchChannelFull); - } @Test(enabled = true) public void testVoteWitness2() { - //get account + // get account ECKey ecKey = new ECKey(Utils.getRandom()); byte[] lowBalAddress = ecKey.getAddress(); ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] lowBalAddress2 = ecKey2.getAddress(); String lowBalTest2 = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - //sendcoin - Return ret1 = PublicMethod.sendcoin2(lowBalAddress, 21245000000L, - fromAddress, foundationKey2, blockingStubFull); + // sendcoin + Return ret1 = + PublicMethod.sendcoin2( + lowBalAddress, 21245000000L, fromAddress, foundationKey2, blockingStubFull); Assert.assertEquals(ret1.getCode(), Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); - ret1 = PublicMethod.sendcoin2(lowBalAddress2, 21245000000L, - fromAddress, foundationKey2, blockingStubFull); + ret1 = + PublicMethod.sendcoin2( + lowBalAddress2, 21245000000L, fromAddress, foundationKey2, blockingStubFull); Assert.assertEquals(ret1.getCode(), Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); - //assetissue + // assetissue String createUrl1 = "adfafds"; byte[] createUrl = createUrl1.getBytes(); String lowBalTest = ByteArray.toHexString(ecKey.getPrivKeyBytes()); @@ -93,8 +94,8 @@ public void testVoteWitness2() { String voteStr1 = Base58.encode58Check(lowBalAddress); - //Base58.encode58Check(getFinalAddress(key); - //String voteStr = "TB4B1RMhoPeivkj4Hebm6tttHjRY9yQFes"; + // Base58.encode58Check(getFinalAddress(key); + // String voteStr = "TB4B1RMhoPeivkj4Hebm6tttHjRY9yQFes"; String voteStr = voteStr1; HashMap smallVoteMap = new HashMap(); smallVoteMap.put(voteStr, "1"); @@ -108,42 +109,42 @@ public void testVoteWitness2() { HashMap wrongDropMap = new HashMap(); wrongDropMap.put(voteStr, "10000000000000000"); - //Vote failed due to no freeze balance. - //Assert.assertFalse(VoteWitness(smallVoteMap, NO_FROZEN_ADDRESS, no_frozen_balance_testKey)); + // Vote failed due to no freeze balance. + // Assert.assertFalse(VoteWitness(smallVoteMap, NO_FROZEN_ADDRESS, no_frozen_balance_testKey)); - //Freeze balance to get vote ability. - ret1 = PublicMethod.freezeBalance2(fromAddress, 10000000L, 3L, foundationKey2, blockingStubFull); + // Freeze balance to get vote ability. + ret1 = + PublicMethod.freezeBalance2(fromAddress, 10000000L, 3L, foundationKey2, blockingStubFull); Assert.assertEquals(ret1.getCode(), Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); - //Vote failed when the vote is large than the freeze balance. + // Vote failed when the vote is large than the freeze balance. ret1 = voteWitness2(veryLargeMap, fromAddress, foundationKey2); Assert.assertEquals(ret1.getCode(), Return.response_code.CONTRACT_VALIDATE_ERROR); - //Vote failed due to 0 vote. + // Vote failed due to 0 vote. ret1 = voteWitness2(zeroVoteMap, fromAddress, foundationKey2); Assert.assertEquals(ret1.getCode(), Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : vote count must be greater than 0"); ret1 = voteWitness2(wrongVoteMap, fromAddress, foundationKey2); Assert.assertEquals(ret1.getCode(), Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : vote count must be greater than 0"); ret1 = voteWitness2(wrongDropMap, fromAddress, foundationKey2); Assert.assertEquals(ret1.getCode(), Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), "Contract validate error : overflow: checkedMultiply(10000000000000000, 1000000)"); ret1 = voteWitness2(smallVoteMap, fromAddress, foundationKey2); Assert.assertEquals(ret1.getCode(), Return.response_code.SUCCESS); Assert.assertEquals(ret1.getMessage().toStringUtf8(), ""); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { if (channelFull != null) { @@ -154,10 +155,7 @@ public void shutdown() throws InterruptedException { } } - /** - * constructor. - */ - + /** constructor. */ public Boolean voteWitness(HashMap witness, byte[] addRess, String priKey) { ECKey temKey = null; @@ -174,14 +172,13 @@ public Boolean voteWitness(HashMap witness, byte[] addRess, Stri beforeVoteNum = beforeVote.getVotes(0).getVoteCount(); } - WitnessContract.VoteWitnessContract.Builder builder = WitnessContract.VoteWitnessContract - .newBuilder(); + WitnessContract.VoteWitnessContract.Builder builder = + WitnessContract.VoteWitnessContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(addRess)); for (String addressBase58 : witness.keySet()) { WitnessContract.VoteWitnessContract.Vote.Builder voteBuilder = - WitnessContract.VoteWitnessContract.Vote - .newBuilder(); + WitnessContract.VoteWitnessContract.Vote.newBuilder(); byte[] address = WalletClient.decodeFromBase58Check(addressBase58); logger.info("address ====== " + ByteArray.toHexString(address)); String value = witness.get(addressBase58); @@ -214,7 +211,7 @@ public Boolean voteWitness(HashMap witness, byte[] addRess, Stri e.printStackTrace(); } Account afterVote = queryAccount(ecKey, searchBlockingStubFull); - //Long afterVoteNum = afterVote.getVotes(0).getVoteCount(); + // Long afterVoteNum = afterVote.getVotes(0).getVoteCount(); for (String key : witness.keySet()) { for (int j = 0; j < afterVote.getVotesCount(); j++) { logger.info(Long.toString(Long.parseLong(witness.get(key)))); @@ -223,19 +220,15 @@ public Boolean voteWitness(HashMap witness, byte[] addRess, Stri logger.info("catch it"); logger.info(Long.toString(afterVote.getVotes(j).getVoteCount())); logger.info(Long.toString(Long.parseLong(witness.get(key)))); - Assert - .assertTrue(afterVote.getVotes(j).getVoteCount() == Long.parseLong(witness.get(key))); + Assert.assertTrue( + afterVote.getVotes(j).getVoteCount() == Long.parseLong(witness.get(key))); } - } } return true; } - /** - * constructor. - */ - + /** constructor. */ public GrpcAPI.Return createWitness2(byte[] owner, byte[] url, String priKey) { ECKey temKey = null; try { @@ -246,8 +239,8 @@ public GrpcAPI.Return createWitness2(byte[] owner, byte[] url, String priKey) { } final ECKey ecKey = temKey; - WitnessContract.WitnessCreateContract.Builder builder = WitnessContract.WitnessCreateContract - .newBuilder(); + WitnessContract.WitnessCreateContract.Builder builder = + WitnessContract.WitnessCreateContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(owner)); builder.setUrl(ByteString.copyFrom(url)); WitnessContract.WitnessCreateContract contract = builder.build(); @@ -280,13 +273,9 @@ public GrpcAPI.Return createWitness2(byte[] owner, byte[] url, String priKey) { return response; } return ret; - } - /** - * constructor. - */ - + /** constructor. */ public Return voteWitness2(HashMap witness, byte[] addRess, String priKey) { ECKey temKey = null; @@ -303,14 +292,13 @@ public Return voteWitness2(HashMap witness, byte[] addRess, Stri beforeVoteNum = beforeVote.getVotes(0).getVoteCount(); } - WitnessContract.VoteWitnessContract.Builder builder = WitnessContract.VoteWitnessContract - .newBuilder(); + WitnessContract.VoteWitnessContract.Builder builder = + WitnessContract.VoteWitnessContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(addRess)); for (String addressBase58 : witness.keySet()) { WitnessContract.VoteWitnessContract.Vote.Builder voteBuilder = - WitnessContract.VoteWitnessContract.Vote - .newBuilder(); + WitnessContract.VoteWitnessContract.Vote.newBuilder(); byte[] address = WalletClient.decodeFromBase58Check(addressBase58); logger.info("address ====== " + ByteArray.toHexString(address)); String value = witness.get(addressBase58); @@ -325,9 +313,9 @@ public Return voteWitness2(HashMap witness, byte[] addRess, Stri WitnessContract.VoteWitnessContract contract = builder.build(); - //Transaction transaction = blockingStubFull.voteWitnessAccount(contract); - GrpcAPI.TransactionExtention transactionExtention = blockingStubFull - .voteWitnessAccount2(contract); + // Transaction transaction = blockingStubFull.voteWitnessAccount(contract); + GrpcAPI.TransactionExtention transactionExtention = + blockingStubFull.voteWitnessAccount2(contract); if (transactionExtention == null) { return transactionExtention.getResult(); @@ -362,7 +350,7 @@ public Return voteWitness2(HashMap witness, byte[] addRess, Stri e.printStackTrace(); } Account afterVote = queryAccount(ecKey, searchBlockingStubFull); - //Long afterVoteNum = afterVote.getVotes(0).getVoteCount(); + // Long afterVoteNum = afterVote.getVotes(0).getVoteCount(); for (String key : witness.keySet()) { for (int j = 0; j < afterVote.getVotesCount(); j++) { logger.info(Long.toString(Long.parseLong(witness.get(key)))); @@ -371,26 +359,22 @@ public Return voteWitness2(HashMap witness, byte[] addRess, Stri logger.info("catch it"); logger.info(Long.toString(afterVote.getVotes(j).getVoteCount())); logger.info(Long.toString(Long.parseLong(witness.get(key)))); - Assert - .assertTrue(afterVote.getVotes(j).getVoteCount() == Long.parseLong(witness.get(key))); + Assert.assertTrue( + afterVote.getVotes(j).getVoteCount() == Long.parseLong(witness.get(key))); } - } } return ret; } - /** - * constructor. - */ - - public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDuration, - String priKey) { + /** constructor. */ + public Boolean freezeBalance( + byte[] addRess, long freezeBalance, long freezeDuration, String priKey) { byte[] address = addRess; long frozenBalance = freezeBalance; long frozenDuration = freezeDuration; - //String priKey = foundationKey2; + // String priKey = foundationKey2; ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -402,18 +386,20 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura Account beforeFronzen = queryAccount(ecKey, blockingStubFull); Long beforeFrozenBalance = 0L; - //Long beforeBandwidth = beforeFronzen.getBandwidth(); + // Long beforeBandwidth = beforeFronzen.getBandwidth(); if (beforeFronzen.getFrozenCount() != 0) { beforeFrozenBalance = beforeFronzen.getFrozen(0).getFrozenBalance(); - //beforeBandwidth = beforeFronzen.getBandwidth(); - //logger.info(Long.toString(beforeFronzen.getBandwidth())); + // beforeBandwidth = beforeFronzen.getBandwidth(); + // logger.info(Long.toString(beforeFronzen.getBandwidth())); logger.info(Long.toString(beforeFronzen.getFrozen(0).getFrozenBalance())); } FreezeBalanceContract.Builder builder = FreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess).setFrozenBalance(frozenBalance) + builder + .setOwnerAddress(byteAddreess) + .setFrozenBalance(frozenBalance) .setFrozenDuration(frozenDuration); FreezeBalanceContract contract = builder.build(); @@ -433,19 +419,20 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura } Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - Block searchCurrentBlock = searchBlockingStubFull.getNowBlock(GrpcAPI - .EmptyMessage.newBuilder().build()); + Block searchCurrentBlock = + searchBlockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); Integer wait = 0; while (searchCurrentBlock.getBlockHeader().getRawData().getNumber() - < currentBlock.getBlockHeader().getRawData().getNumber() + 1 && wait < 30) { + < currentBlock.getBlockHeader().getRawData().getNumber() + 1 + && wait < 30) { try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } logger.info("Another fullnode didn't syn the first fullnode data"); - searchCurrentBlock = searchBlockingStubFull.getNowBlock(GrpcAPI - .EmptyMessage.newBuilder().build()); + searchCurrentBlock = + searchBlockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); wait++; if (wait == 9) { logger.info("Didn't syn,skip to next case."); @@ -454,30 +441,30 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura Account afterFronzen = queryAccount(ecKey, searchBlockingStubFull); Long afterFrozenBalance = afterFronzen.getFrozen(0).getFrozenBalance(); - //Long afterBandwidth = afterFronzen.getBandwidth(); - //logger.info(Long.toString(afterFronzen.getBandwidth())); - //logger.info(Long.toString(afterFronzen.getFrozen(0).getFrozenBalance())); - //logger.info(Integer.toString(search.getFrozenCount())); + // Long afterBandwidth = afterFronzen.getBandwidth(); + // logger.info(Long.toString(afterFronzen.getBandwidth())); + // logger.info(Long.toString(afterFronzen.getFrozen(0).getFrozenBalance())); + // logger.info(Integer.toString(search.getFrozenCount())); logger.info( - "afterfrozenbalance =" + Long.toString(afterFrozenBalance) + "beforefrozenbalance = " - + beforeFrozenBalance + "freezebalance = " + Long.toString(freezeBalance)); - //logger.info("afterbandwidth = " + Long.toString(afterBandwidth) + " beforebandwidth = + "afterfrozenbalance =" + + Long.toString(afterFrozenBalance) + + "beforefrozenbalance = " + + beforeFrozenBalance + + "freezebalance = " + + Long.toString(freezeBalance)); + // logger.info("afterbandwidth = " + Long.toString(afterBandwidth) + " beforebandwidth = // " + Long.toString(beforeBandwidth)); - //if ((afterFrozenBalance - beforeFrozenBalance != freezeBalance) || + // if ((afterFrozenBalance - beforeFrozenBalance != freezeBalance) || // (freezeBalance * frozen_duration -(afterBandwidth - beforeBandwidth) !=0)){ // logger.info("After 20 second, two node still not synchronous"); // } Assert.assertTrue(afterFrozenBalance - beforeFrozenBalance == freezeBalance); - //Assert.assertTrue(freezeBalance * frozen_duration - (afterBandwidth - + // Assert.assertTrue(freezeBalance * frozen_duration - (afterBandwidth - // beforeBandwidth) <= 1000000); return true; - } - /** - * constructor. - */ - + /** constructor. */ public boolean unFreezeBalance(byte[] addRess, String priKey) { byte[] address = addRess; @@ -491,8 +478,7 @@ public boolean unFreezeBalance(byte[] addRess, String priKey) { ECKey ecKey = temKey; Account search = queryAccount(ecKey, blockingStubFull); - UnfreezeBalanceContract.Builder builder = UnfreezeBalanceContract - .newBuilder(); + UnfreezeBalanceContract.Builder builder = UnfreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddreess); @@ -511,14 +497,11 @@ public boolean unFreezeBalance(byte[] addRess, String priKey) { return response.getResult(); } - /** - * constructor. - */ - + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; @@ -534,25 +517,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ - + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ - + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -564,4 +540,3 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } } - diff --git a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/WithdrawBalance2Test.java b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/WithdrawBalance2Test.java index b89c6f7f..be082e94 100644 --- a/testcase/src/test/java/stest/tron/wallet/newaddinterface2/WithdrawBalance2Test.java +++ b/testcase/src/test/java/stest/tron/wallet/newaddinterface2/WithdrawBalance2Test.java @@ -26,11 +26,11 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; - import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; + @Slf4j @MultiNode public class WithdrawBalance2Test extends TronBaseTest { @@ -38,47 +38,47 @@ public class WithdrawBalance2Test extends TronBaseTest { { fullnode = config.getStringList("fullnode.ip.list").get(1); } - //key is only for test + // key is only for test + private final String notWitnessTestKey = - "8CB4480194192F30907E14B52498F594BD046E21D7C4D8FE866563A6760AC891"; private final byte[] notWitness = PublicMethod.getFinalAddress(notWitnessTestKey); private ManagedChannel searchChannelFull = null; private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; private String searchFullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + "8CB4480194192F30907E14B52498F594BD046E21D7C4D8FE866563A6760AC891"; + private final byte[] notWitness = PublicMethod.getFinalAddress(notWitnessTestKey); + private ManagedChannel searchChannelFull = null; + private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; + private String searchFullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - /** - * constructor. - */ - + /** constructor. */ @BeforeClass - public void beforeClass() { searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode) - .usePlaintext() - .build(); + public void beforeClass() { + searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode).usePlaintext().build(); searchBlockingStubFull = WalletGrpc.newBlockingStub(searchChannelFull); - } @Test public void testWithdrawBalance2() { - //Withdraw failed when you are not witness + // Withdraw failed when you are not witness Return ret1 = withdrawBalance2(notWitness, notWitnessTestKey); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), "Contract validate error : " - + "Account[41688b08971e740d7cecfa5d768f2787c1bb4c1268] is not a witnessAccount"); + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), + "Contract validate error : " + + "Account[41688b08971e740d7cecfa5d768f2787c1bb4c1268] is not a witnessAccount"); - //Withdraw failed when the latest time to withdraw within 1 day. + // Withdraw failed when the latest time to withdraw within 1 day. ret1 = withdrawBalance2(fromAddress, foundationKey2); Assert.assertEquals(ret1.getCode(), GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR); - Assert.assertEquals(ret1.getMessage().toStringUtf8(), + Assert.assertEquals( + ret1.getMessage().toStringUtf8(), " Contract validate error : witnessAccount does not have any allowance"); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { if (channelFull != null) { @@ -89,10 +89,7 @@ public void shutdown() throws InterruptedException { } } - /** - * constructor. - */ - + /** constructor. */ public boolean withdrawBalance(byte[] address, String priKey) { ECKey temKey = null; try { @@ -103,8 +100,7 @@ public boolean withdrawBalance(byte[] address, String priKey) { } ECKey ecKey = temKey; - WithdrawBalanceContract.Builder builder = WithdrawBalanceContract - .newBuilder(); + WithdrawBalanceContract.Builder builder = WithdrawBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddreess); WithdrawBalanceContract contract = builder.build(); @@ -123,10 +119,7 @@ public boolean withdrawBalance(byte[] address, String priKey) { return true; } - /** - * constructor. - */ - + /** constructor. */ public Return withdrawBalance2(byte[] address, String priKey) { ECKey temKey = null; try { @@ -136,8 +129,7 @@ public Return withdrawBalance2(byte[] address, String priKey) { ex.printStackTrace(); } - WithdrawBalanceContract.Builder builder = WithdrawBalanceContract - .newBuilder(); + WithdrawBalanceContract.Builder builder = WithdrawBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddreess); WithdrawBalanceContract contract = builder.build(); @@ -170,10 +162,7 @@ public Return withdrawBalance2(byte[] address, String priKey) { return ret; } - /** - * constructor. - */ - + /** constructor. */ public Boolean voteWitness(HashMap witness, byte[] address, String priKey) { ECKey temKey = null; @@ -195,8 +184,7 @@ public Boolean voteWitness(HashMap witness, byte[] address, Stri for (String addressBase58 : witness.keySet()) { String value = witness.get(addressBase58); long count = Long.parseLong(value); - VoteWitnessContract.Vote.Builder voteBuilder = VoteWitnessContract.Vote - .newBuilder(); + VoteWitnessContract.Vote.Builder voteBuilder = VoteWitnessContract.Vote.newBuilder(); byte[] addRess = WalletClient.decodeFromBase58Check(addressBase58); if (addRess == null) { continue; @@ -219,7 +207,7 @@ public Boolean voteWitness(HashMap witness, byte[] address, Stri return false; } Account afterVote = queryAccount(ecKey, searchBlockingStubFull); - //Long afterVoteNum = afterVote.getVotes(0).getVoteCount(); + // Long afterVoteNum = afterVote.getVotes(0).getVoteCount(); for (String key : witness.keySet()) { for (int j = 0; j < afterVote.getVotesCount(); j++) { if (key.equals(afterVote.getVotes(j).getVoteAddress())) { @@ -232,14 +220,11 @@ public Boolean voteWitness(HashMap witness, byte[] address, Stri return true; } - /** - * constructor. - */ - + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; @@ -255,25 +240,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ - + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ - + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -285,4 +263,3 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } } - diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/ContractEvent001.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/ContractEvent001.java index b79a2008..5a559623 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/ContractEvent001.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/ContractEvent001.java @@ -36,10 +36,10 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.JsonRpcBase; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.Utils; import zmq.ZMQ.Event; -import stest.tron.wallet.common.client.utils.MultiNode; @Slf4j @MultiNode @@ -73,8 +73,6 @@ public class ContractEvent001 extends JsonRpcBase { private Long maxFeeLimit = Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit"); - - /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { @@ -84,7 +82,9 @@ public void beforeClass() { blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } - @Test(enabled = true, groups = {"stress"}) + @Test( + enabled = true, + groups = {"stress"}) public void test1ContractEventAndLog() { ecKey1 = new ECKey(Utils.getRandom()); event001Address = ecKey1.getAddress(); @@ -436,7 +436,8 @@ public void test1ContractEventAndLog() { enabled = true, threadPoolSize = 5, invocationCount = 5, - description = "test eth_getFilterChanges", groups = {"stress"}) + description = "test eth_getFilterChanges", + groups = {"stress"}) public void testEthGetFilterChanges() throws InterruptedException { ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] event001Address = ecKey1.getAddress(); @@ -545,7 +546,8 @@ public void testEthGetFilterChanges() throws InterruptedException { enabled = true, threadPoolSize = 5, invocationCount = 5, - description = "Eth api of eth_getFilterChanges .", groups = {"stress"}) + description = "Eth api of eth_getFilterChanges .", + groups = {"stress"}) public void test09GetFilterChanges() { long sumSize = 0; while (true) { @@ -680,7 +682,10 @@ public static HttpResponse getJsonRpc(String jsonRpcNode, JsonObject jsonRpcObje return response; } - @Test(enabled = true, description = "Subscribe event client", groups = {"stress"}) + @Test( + enabled = true, + description = "Subscribe event client", + groups = {"stress"}) public void testEnergyCostDetail() { ZMQ.Context context = ZMQ.context(1); ZMQ.Socket req = context.socket(ZMQ.SUB); @@ -692,15 +697,16 @@ public void testEnergyCostDetail() { req.monitor("inproc://reqmoniter", ZMQ.EVENT_CONNECTED | ZMQ.EVENT_DISCONNECTED); final ZMQ.Socket moniter = context.socket(ZMQ.PAIR); moniter.connect("inproc://reqmoniter"); - new Thread(new Runnable() { - public void run() { - while (true) { - Event event = Event.read(moniter.base()); - System.out.println(event.event + " " + event.addr); - } - } - - }).start(); + new Thread( + new Runnable() { + public void run() { + while (true) { + Event event = Event.read(moniter.base()); + System.out.println(event.event + " " + event.addr); + } + } + }) + .start(); req.connect("tcp://47.94.197.215:55555"); req.setReceiveTimeOut(10000); @@ -712,9 +718,7 @@ public void run() { } } - - -// the keys below are for test, do not worry + // the keys below are for test, do not worry /* @Test(enabled = true, groups = {"stress"}) public void testSingForHex() { @@ -724,11 +728,13 @@ public void testSingForHex() { ByteArray.fromHexString( "6815B367FDDE637E53E9ADC8E69424E07724333C9A2B973CFA469975E20753FC"), true); - *//* ByteString sig = ByteString.copyFrom(cryptoEngine.Base64toBytes(cryptoEngine - .signHash(Sha256Hash.of(DBConfig.isECKeyCryptoEngine(), - ByteArray.fromHexString( - "ba989430c392dedef66a259a1f1112b178dbe7f2793975d8cf80f9b31ecd33ff")) - .getBytes())));*//* + */ + /* ByteString sig = ByteString.copyFrom(cryptoEngine.Base64toBytes(cryptoEngine + .signHash(Sha256Hash.of(DBConfig.isECKeyCryptoEngine(), + ByteArray.fromHexString( + "ba989430c392dedef66a259a1f1112b178dbe7f2793975d8cf80f9b31ecd33ff")) + .getBytes())));*/ + /* // ByteString sig = ByteString.copyFrom( diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/CreateReplayTestUsedAccount.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/CreateReplayTestUsedAccount.java index f72dace4..77bcbdd3 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/CreateReplayTestUsedAccount.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/CreateReplayTestUsedAccount.java @@ -1,13 +1,13 @@ package stest.tron.wallet.onlinestress; import com.google.protobuf.ByteString; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; +import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -18,115 +18,149 @@ import org.testng.annotations.Test; import org.tron.protos.Protocol.Account; import stest.tron.wallet.common.client.WalletClient; -import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class CreateReplayTestUsedAccount extends TronBaseTest { - //just test key + // just test key private final String foundationKey = "a79a37a3d868e66456d76b233cb894d664b75fd91861340f3843db05ab3a8c66"; private String fullnode = "47.94.243.150:50051"; - public static String fileName = "random200Account"; - public static HashMap accountMap = new HashMap<>(); + public static String fileName = "random200Account"; + public static HashMap accountMap = new HashMap<>(); @BeforeClass(enabled = true) - public void beforeClass() { getAccountList(); - - + public void beforeClass() { + getAccountList(); } - @Test(enabled = false, groups = {"stress"}) + @Test( + enabled = false, + groups = {"stress"}) public void create200TestAccountToCsv() { - for(int i = 0; i < 200;i++) { + for (int i = 0; i < 200; i++) { ECKey randomEckey = new ECKey(Utils.getRandom()); - String randomKey = ByteArray.toHexString(randomEckey.getPrivKeyBytes()); - byte[] randomAddressByte = randomEckey.getAddress(); - String randomAddress = WalletClient.encode58Check(randomAddressByte); + String randomKey = ByteArray.toHexString(randomEckey.getPrivKeyBytes()); + byte[] randomAddressByte = randomEckey.getAddress(); + String randomAddress = WalletClient.encode58Check(randomAddressByte); - writeDataToCsvFile("random200Account",randomKey + "," + randomAddress); + writeDataToCsvFile("random200Account", randomKey + "," + randomAddress); } } - - @Test(enabled = false, groups = {"stress"}) + @Test( + enabled = false, + groups = {"stress"}) public void sendCoinTo200TestAccount() { - for(String key : accountMap.keySet()) { + for (String key : accountMap.keySet()) { String address = accountMap.get(key); - String txid = PublicMethod.sendcoinGetTransactionId(WalletClient.decode58Check(address),100000000000000L,foundationAddress,foundationKey,blockingStubFull); + String txid = + PublicMethod.sendcoinGetTransactionId( + WalletClient.decode58Check(address), + 100000000000000L, + foundationAddress, + foundationKey, + blockingStubFull); try { Thread.sleep(100); - } catch (Exception e) { - + } catch (Exception expected) { + // expected } } } - - @Test(enabled = true, groups = {"stress"}) + @Test( + enabled = true, + groups = {"stress"}) public void create200TokenOneByOneAndDispatchTo200Account() { int i = 0; - for(String key : accountMap.keySet()) { + for (String key : accountMap.keySet()) { logger.info("当前个数:" + i++); - String address = accountMap.get(key); - if (!PublicMethod.queryAccount(key,blockingStubFull).getAssetIssuedID().toStringUtf8().contains("100")) { + String address = accountMap.get(key); + if (!PublicMethod.queryAccount(key, blockingStubFull) + .getAssetIssuedID() + .toStringUtf8() + .contains("100")) { long start = System.currentTimeMillis() + 10000; long end = System.currentTimeMillis() + 1000000000; - PublicMethod.createAssetIssueGetTxid(WalletClient.decode58Check(address), "replay_" + System.currentTimeMillis(), "replay_" + System.currentTimeMillis(),100000000000000000L, - 1, 1, start, end, 1, "wwwwww", "wwwwwwww", 0L, 0L, 1L, 1L, key, blockingStubFull); + PublicMethod.createAssetIssueGetTxid( + WalletClient.decode58Check(address), + "replay_" + System.currentTimeMillis(), + "replay_" + System.currentTimeMillis(), + 100000000000000000L, + 1, + 1, + start, + end, + 1, + "wwwwww", + "wwwwwwww", + 0L, + 0L, + 1L, + 1L, + key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); } else { continue; } Account getAssetIdFromThisAccount; - getAssetIdFromThisAccount = PublicMethod.queryAccount(WalletClient.decode58Check(address), blockingStubFull); + getAssetIdFromThisAccount = + PublicMethod.queryAccount(WalletClient.decode58Check(address), blockingStubFull); ByteString assetAccountId = getAssetIdFromThisAccount.getAssetIssuedID(); - - for(String toKey : accountMap.keySet()) { - if(toKey.equalsIgnoreCase(key)) { + for (String toKey : accountMap.keySet()) { + if (toKey.equalsIgnoreCase(key)) { continue; } String toAddress = accountMap.get(toKey); - Assert.assertTrue(PublicMethod.transferAsset(WalletClient.decode58Check(toAddress), assetAccountId.toByteArray(), - 100000L, WalletClient.decode58Check(address), key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + WalletClient.decode58Check(toAddress), + assetAccountId.toByteArray(), + 100000L, + WalletClient.decode58Check(address), + key, + blockingStubFull)); try { Thread.sleep(20); - } catch (Exception e) { - + } catch (Exception expected) { + // expected } } } } - - @Test(enabled = true, groups = {"stress"}) + @Test( + enabled = true, + groups = {"stress"}) public void sendTrc20To200Account() { - //just for test + // just for test String trc20OwnerKey = "44FE180410D7BF05E41388A881C3C5566C6667840116EC25C6FC924CE678FC4A"; - String trc20OwnerAddress = "TRRJbGw8BC8S5ueuium2aTBuRrLnkytnUi"; + String trc20OwnerAddress = "TRRJbGw8BC8S5ueuium2aTBuRrLnkytnUi"; List contractList = new ArrayList<>(); getContractList(contractList); - - for(int i = contractList.size()-1; i >= 0;i--) { + for (int i = contractList.size() - 1; i >= 0; i--) { logger.info("索引到:" + i); - //for(int i = 0; i < contractList.size();i++) { - for(String key : accountMap.keySet()) { + // for(int i = 0; i < contractList.size();i++) { + for (String key : accountMap.keySet()) { String address = accountMap.get(key); - String initParmes = "\"" + address + "\",\"10000\""; - String txid = PublicMethod.triggerContract( + String initParmes = "\"" + address + "\",\"10000\""; + String txid = + PublicMethod.triggerContract( WalletClient.decodeFromBase58Check(contractList.get(i)), "transfer(address,uint256)", - initParmes, + initParmes, false, 0, 1000000000L, @@ -136,54 +170,55 @@ public void sendTrc20To200Account() { try { Thread.sleep(10); - } catch (Exception e) { - + } catch (Exception expected) { + // expected } } - } - - } - - @Test(enabled = true, groups = {"stress"}) + @Test( + enabled = true, + groups = {"stress"}) public void sendTrc20To200Contract() { - //Every contract receive 50 trc10 token + // Every contract receive 50 trc10 token AtomicInteger contractIndex = new AtomicInteger(); - List contractList = new ArrayList<>(); getContractList(contractList); - int times = 0; - for(String key : accountMap.keySet()) { - if(times++ == 50) { + int times = 0; + for (String key : accountMap.keySet()) { + if (times++ == 50) { break; } String address = accountMap.get(key); - Account getAssetIdFromThisAccount; - getAssetIdFromThisAccount = PublicMethod.queryAccount(WalletClient.decode58Check(address), blockingStubFull); + getAssetIdFromThisAccount = + PublicMethod.queryAccount(WalletClient.decode58Check(address), blockingStubFull); ByteString assetAccountId = getAssetIdFromThisAccount.getAssetIssuedID(); + for (String contractAddress : contractList) { - for(String contractAddress : contractList) { - - Assert.assertTrue(PublicMethod.transferAsset(WalletClient.decode58Check(contractAddress), assetAccountId.toByteArray(), - 100000L, WalletClient.decode58Check(address), key, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + WalletClient.decode58Check(contractAddress), + assetAccountId.toByteArray(), + 100000L, + WalletClient.decode58Check(address), + key, + blockingStubFull)); try { Thread.sleep(20); - } catch (Exception e) { - + } catch (Exception expected) { + // expected } } } } - - public static void writeDataToCsvFile(String fileName,String writeData) { + public static void writeDataToCsvFile(String fileName, String writeData) { { try { @@ -195,23 +230,23 @@ public static void writeDataToCsvFile(String fileName,String writeData) { FileWriter fileWritter = new FileWriter(file.getName(), true); fileWritter.write(writeData + "\n"); fileWritter.close(); - //System.out.println("finish"); + // System.out.println("finish"); } catch (IOException e) { e.printStackTrace(); } } } - private static void getAccountList() { - String line=null; + String line = null; try { - //BufferedReader bufferedReader=new BufferedReader(new FileReader(filePath)); - BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(new FileInputStream(fileName),"utf-8")); - //int i=0; - while((line=bufferedReader.readLine())!=null){ + // BufferedReader bufferedReader=new BufferedReader(new FileReader(filePath)); + BufferedReader bufferedReader = + new BufferedReader(new InputStreamReader(new FileInputStream(fileName), "utf-8")); + // int i=0; + while ((line = bufferedReader.readLine()) != null) { String[] accountInforamtion = line.split(","); - accountMap.put(accountInforamtion[0],accountInforamtion[1]); + accountMap.put(accountInforamtion[0], accountInforamtion[1]); } } catch (FileNotFoundException e) { e.printStackTrace(); @@ -220,14 +255,15 @@ private static void getAccountList() { } } - private static void getContractList(List list) { - String line=null; + String line = null; try { - //BufferedReader bufferedReader=new BufferedReader(new FileReader(filePath)); - BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(new FileInputStream("trc20Contract.csv"),"utf-8")); - //int i=0; - while((line=bufferedReader.readLine())!=null){ + // BufferedReader bufferedReader=new BufferedReader(new FileReader(filePath)); + BufferedReader bufferedReader = + new BufferedReader( + new InputStreamReader(new FileInputStream("trc20Contract.csv"), "utf-8")); + // int i=0; + while ((line = bufferedReader.readLine()) != null) { list.add(line); } } catch (FileNotFoundException e) { @@ -236,7 +272,4 @@ private static void getContractList(List list) { e.printStackTrace(); } } - - } - diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/CycleMultiSign.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/CycleMultiSign.java index 2b661f6a..a2c69eda 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/CycleMultiSign.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/CycleMultiSign.java @@ -16,11 +16,11 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode @@ -29,11 +29,11 @@ public class CycleMultiSign extends TronBaseTest { private ManagedChannel searchChannelFull = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidityInFullnode = null; private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; - private String searchFullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String searchFullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private ManagedChannel channelSolidityInFullnode = null; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); private ECKey ecKey = new ECKey(Utils.getRandom()); private byte[] test001Address = ecKey.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey.getPrivKeyBytes()); @@ -50,29 +50,24 @@ public class CycleMultiSign extends TronBaseTest { byte[] test005Address = ecKey5.getAddress(); String sendAccountKey5 = ByteArray.toHexString(ecKey5.getPrivKeyBytes()); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass - public void beforeClass() { searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode) - .usePlaintext() - .build(); + public void beforeClass() { + searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode).usePlaintext().build(); searchBlockingStubFull = WalletGrpc.newBlockingStub(searchChannelFull); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - } - //(use no id) - @Test(enabled = true, groups = {"stress"}) + // (use no id) + @Test( + enabled = true, + groups = {"stress"}) public void testMultiSignActiveAddress() { - Assert.assertTrue(PublicMethod - .sendcoin(test001Address, 10000000000000L, foundationAddress, testKey002, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + test001Address, 10000000000000L, foundationAddress, testKey002, blockingStubFull)); Account test001AddressAccount = PublicMethod.queryAccount(test001Address, blockingStubFull); List permissionsList = test001AddressAccount.getActivePermissionList(); @@ -85,22 +80,28 @@ public void testMultiSignActiveAddress() { String[] permissionKeyString = new String[1]; permissionKeyString[0] = dev001Key; - String accountPermissionJson1 = + String accountPermissionJson1 = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":1,\"" - + "keys\":[{\"address\":\"" + PublicMethod.getAddressString(dev001Key) + + "keys\":[{\"address\":\"" + + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey4) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey4) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey5) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey5) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\"," + "\"threshold\":1,\"operations\":\"" + "0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(dev001Key) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}]} "; Account test001AddressAccount1 = PublicMethod.queryAccount(test001Address, blockingStubFull); @@ -111,70 +112,92 @@ public void testMultiSignActiveAddress() { logger.info(PublicMethodForMultiSign.printPermission(ownerPermission1)); logger.info(PublicMethodForMultiSign.printPermission(witnessPermission1)); logger.info("1-----------------------"); - String accountPermissionJson2 = + String accountPermissionJson2 = "{\"owner_permission\":{\"type\":0,\"permission_name\"" + ":\"owner\",\"threshold\":1,\"keys\":[{\"address\"" - + ":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + "\"active0\",\"threshold\":1,\"operations\"" + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey4) + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey4) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) + + "{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + "\",\"weight\":1}]}]} "; - String accountPermissionJson3 = "{\"owner_permission\":{\"type\":0,\"permission_name\":" - + "\"owner\",\"threshold\":1,\"keys\":[{\"address\"" - + ":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":" - + "\"active0\",\"threshold\":1,\"operations" - + "\":\"0100000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(dev001Key) - + "\",\"weight\":1}]}," - + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations" - + "\":\"0100000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]}"; - String accountPermissionJson4 = "{\"owner_permission\":{\"type\":0,\"" - + "permission_name\":\"owner\",\"threshold\":1,\"keys\":" - + "[{\"address\":\"" + PublicMethod.getAddressString(dev001Key) + "\",\"weight\":1}]}," - + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," - + "\"operations\":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}," - + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations\":" - + "\"0200000000000000000000000000000000000000000000000000000000000000\",\"keys\":" - + "[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey4) - + "\",\"weight\":1}]},{\"type\":2," - + "\"permission_name\":\"active0\",\"threshold\":1,\"operations\"" - + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," - + "\"keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}]}," - + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations\"" - + ":\"0100000000000000000000000000000000000000000000000000000000000000\",\"keys\"" - + ":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}," - + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations\":" - + "\"0200000000000000000000000000000000000000000000000000000000000000\",\"keys\"" - + ":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey2) - + "\",\"weight\":1}]},{\"type\":2," - + "\"permission_name\":\"active0\",\"threshold\":1,\"operations\":\"" - + "0200000000000000000000000000000000000000000000000000000000000000\",\"keys\":" - + "[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}," - + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations\"" - + ":\"0200000000000000000000000000000000000000000000000000000000000000\",\"" - + "keys\":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey5) - + "\",\"weight\":1}]}," - + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations\":" - + "\"0020000000000000000000000000000000000000000000000000000000000000\",\"keys\"" - + ":[{\"address\":\"" + PublicMethod.getAddressString(sendAccountKey3) - + "\",\"weight\":1}]}]}"; + String accountPermissionJson3 = + "{\"owner_permission\":{\"type\":0,\"permission_name\":" + + "\"owner\",\"threshold\":1,\"keys\":[{\"address\"" + + ":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":" + + "\"active0\",\"threshold\":1,\"operations" + + "\":\"0100000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations" + + "\":\"0100000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]}"; + String accountPermissionJson4 = + "{\"owner_permission\":{\"type\":0,\"" + + "permission_name\":\"owner\",\"threshold\":1,\"keys\":" + + "[{\"address\":\"" + + PublicMethod.getAddressString(dev001Key) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1," + + "\"operations\":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}," + + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations\":" + + "\"0200000000000000000000000000000000000000000000000000000000000000\",\"keys\":" + + "[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey4) + + "\",\"weight\":1}]},{\"type\":2," + + "\"permission_name\":\"active0\",\"threshold\":1,\"operations\"" + + ":\"0200000000000000000000000000000000000000000000000000000000000000\"," + + "\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}]}," + + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations\"" + + ":\"0100000000000000000000000000000000000000000000000000000000000000\",\"keys\"" + + ":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}," + + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations\":" + + "\"0200000000000000000000000000000000000000000000000000000000000000\",\"keys\"" + + ":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey2) + + "\",\"weight\":1}]},{\"type\":2," + + "\"permission_name\":\"active0\",\"threshold\":1,\"operations\":\"" + + "0200000000000000000000000000000000000000000000000000000000000000\",\"keys\":" + + "[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}," + + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations\"" + + ":\"0200000000000000000000000000000000000000000000000000000000000000\",\"" + + "keys\":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey5) + + "\",\"weight\":1}]}," + + "{\"type\":2,\"permission_name\":\"active0\",\"threshold\":1,\"operations\":" + + "\"0020000000000000000000000000000000000000000000000000000000000000\",\"keys\"" + + ":[{\"address\":\"" + + PublicMethod.getAddressString(sendAccountKey3) + + "\",\"weight\":1}]}]}"; while (true) { - PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson1, test001Address, - dev001Key, - blockingStubFull, 0, - permissionKeyString); + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson1, + test001Address, + dev001Key, + blockingStubFull, + 0, + permissionKeyString); addressPermission(dev001Key, accountPermissionJson2); addressPermission(dev001Key, accountPermissionJson3); addressPermission(dev001Key, accountPermissionJson4); @@ -188,34 +211,30 @@ public void testMultiSignActiveAddress() { } } - /** - * constructor. - */ + /** constructor. */ public void addressPermission(String addKey, String accountPermissionJson) { - PublicMethod.freezeBalanceForReceiver(test001Address, - 10000000L, 0, 0, - com.google.protobuf.ByteString.copyFrom(foundationAddress), testKey002, blockingStubFull); + PublicMethod.freezeBalanceForReceiver( + test001Address, + 10000000L, + 0, + 0, + com.google.protobuf.ByteString.copyFrom(foundationAddress), + testKey002, + blockingStubFull); String[] permissionKeyString = new String[1]; permissionKeyString[0] = addKey; - PublicMethodForMultiSign - .accountPermissionUpdateWithPermissionId(accountPermissionJson, test001Address, dev001Key, - blockingStubFull, 0, - permissionKeyString); - PublicMethod.unFreezeBalance(foundationAddress, testKey002, 0, - test001Address, blockingStubFull); + PublicMethodForMultiSign.accountPermissionUpdateWithPermissionId( + accountPermissionJson, test001Address, dev001Key, blockingStubFull, 0, permissionKeyString); + PublicMethod.unFreezeBalance( + foundationAddress, testKey002, 0, test001Address, blockingStubFull); } - - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { if (searchChannelFull != null) { + public void shutdown() throws InterruptedException { + if (searchChannelFull != null) { searchChannelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - - } diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/ExtCodeHashStressTest.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/ExtCodeHashStressTest.java index 8eaeee16..6d10c269 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/ExtCodeHashStressTest.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/ExtCodeHashStressTest.java @@ -34,10 +34,10 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode @@ -47,8 +47,8 @@ public class ExtCodeHashStressTest extends TronBaseTest { private AtomicLong count = new AtomicLong(); private AtomicLong errorCount = new AtomicLong(); private long startTime = System.currentTimeMillis(); - private String fullnodeLocal = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnodeLocal = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] extCodeHashContractAddress = null; private byte[] normalContractAddress = null; private byte[] testContractAddress = null; @@ -58,130 +58,163 @@ public class ExtCodeHashStressTest extends TronBaseTest { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); PublicMethod.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy a normal contract to be used for stress testing.", groups = {"stress"}) + @Test( + enabled = true, + description = "Deploy a normal contract to be used for stress testing.", + groups = {"stress"}) public void test01DeployNormalContract() { - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/extCodeHashStress.sol"; - String contractName = "TriggerNormal"; - //TBVEkA72g1wFoBBVLSXFZ2Bp944oL17NeU + String filePath = "./src/test/resources/soliditycode/extCodeHashStress.sol"; + String contractName = "TriggerNormal"; + // TBVEkA72g1wFoBBVLSXFZ2Bp944oL17NeU HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); normalContractAddress = deployContract(code, abi, contractName, blockingStubFull); - SmartContract smartContract = PublicMethod.getContract(normalContractAddress, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(normalContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "Deploy a extcodehash contract.", groups = {"stress"}) + @Test( + enabled = true, + description = "Deploy a extcodehash contract.", + groups = {"stress"}) public void test02DeployExtCodeHashContract() { - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 100_000_000L, foundationAddress, - testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 100_000_000L, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(dev001Address, - blockingStubFull); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/extCodeHashStress.sol"; - String contractName = "Trigger"; //THAx2PcAtRCerwrLGN237dahqSUfq5wLnR + String filePath = "./src/test/resources/soliditycode/extCodeHashStress.sol"; + String contractName = "Trigger"; // THAx2PcAtRCerwrLGN237dahqSUfq5wLnR HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); extCodeHashContractAddress = deployContract(code, abi, contractName, blockingStubFull); - SmartContract smartContract = PublicMethod.getContract(extCodeHashContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(extCodeHashContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - /** - * trigger. - */ - public byte[] deployContract(String bytecode, String abi, String contractName, + /** trigger. */ + public byte[] deployContract( + String bytecode, + String abi, + String contractName, WalletGrpc.WalletBlockingStub blockingStubFull) { - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, bytecode, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, dev001Key, - dev001Address, blockingStubFull); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + bytecode, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); if (infoById.get().getResultValue() != 0) { - Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() - .toStringUtf8()); + Assert.fail( + "deploy transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); } return infoById.get().getContractAddress().toByteArray(); } - /** - * trigger. - */ - public String triggerContractWithMaxFeeLimit(byte[] testAddress, byte[] user001Address, - String user001Key, long maxFeeLimit) { - Assert.assertTrue(PublicMethod.sendcoin(user001Address, 10000_000_000L, foundationAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(foundationAddress, - PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - Long callValue = Long.valueOf(0); - String param = "\"" + Base58.encode58Check(testAddress) + "\""; - final String triggerTxid = PublicMethod.triggerContract(extCodeHashContractAddress, - "test(address)", param, false, callValue, - maxFeeLimit, "0", 0, user001Address, user001Key, - blockingStubFull); + /** trigger. */ + public String triggerContractWithMaxFeeLimit( + byte[] testAddress, byte[] user001Address, String user001Key, long maxFeeLimit) { + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 10000_000_000L, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + foundationAddress, + PublicMethod.getFreezeBalanceCount( + user001Address, user001Key, 50000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(user001Address), + testKey002, + blockingStubFull)); + Long callValue = Long.valueOf(0); + String param = "\"" + Base58.encode58Check(testAddress) + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + extCodeHashContractAddress, + "test(address)", + param, + false, + callValue, + maxFeeLimit, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - scheduledExecutorService - .schedule(new CheckTask(triggerTxid, blockingStubFull), 15, TimeUnit.SECONDS); + scheduledExecutorService.schedule( + new CheckTask(triggerTxid, blockingStubFull), 15, TimeUnit.SECONDS); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); - logger - .info("transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + logger.info( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); if (infoById.get().getResMessage().toStringUtf8().toLowerCase().contains("cpu")) { throw new IllegalArgumentException(); @@ -192,64 +225,83 @@ public String triggerContractWithMaxFeeLimit(byte[] testAddress, byte[] user001A return "ok"; } - /** - * trigger. - */ - public String triggerAndGetExtCodeHashList(List testAddress, byte[] user001Address, - String user001Key, long maxFeeLimit, WalletGrpc.WalletBlockingStub blockingStubFull) { + /** trigger. */ + public String triggerAndGetExtCodeHashList( + List testAddress, + byte[] user001Address, + String user001Key, + long maxFeeLimit, + WalletGrpc.WalletBlockingStub blockingStubFull) { Long callValue = Long.valueOf(0); List params = new ArrayList<>(); for (int i = 0; i < testAddress.size(); i++) { params.add(Base58.encode58Check(testAddress.get(i))); } - final String triggerTxid = PublicMethod.triggerParamListContract(extCodeHashContractAddress, - "test(address[])", Arrays.asList(params), false, callValue, - maxFeeLimit, "0", 0, user001Address, user001Key, - blockingStubFull); + final String triggerTxid = + PublicMethod.triggerParamListContract( + extCodeHashContractAddress, + "test(address[])", + Arrays.asList(params), + false, + callValue, + maxFeeLimit, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); - scheduledExecutorService - .schedule(new CheckTask(triggerTxid, blockingStubFull), 15, TimeUnit.SECONDS); + scheduledExecutorService.schedule( + new CheckTask(triggerTxid, blockingStubFull), 15, TimeUnit.SECONDS); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); - logger - .info( - "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + logger.info( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); return "ok"; - } - /** - * trigger. - */ - public void triggerAndGetExtCodeHash(byte[] testAddress, byte[] user001Address, - String user001Key, long maxFeeLimit, WalletGrpc.WalletBlockingStub blockingStubFull) { + /** trigger. */ + public void triggerAndGetExtCodeHash( + byte[] testAddress, + byte[] user001Address, + String user001Key, + long maxFeeLimit, + WalletGrpc.WalletBlockingStub blockingStubFull) { Long callValue = Long.valueOf(0); - String param = "\"" + Base58.encode58Check(testAddress) + "\""; - final String triggerTxid = PublicMethod.triggerContract(normalContractAddress, - "test(address)", param, false, callValue, - 314982000, "0", 0, user001Address, user001Key, - blockingStubFull); + String param = "\"" + Base58.encode58Check(testAddress) + "\""; + final String triggerTxid = + PublicMethod.triggerContract( + normalContractAddress, + "test(address)", + param, + false, + callValue, + 314982000, + "0", + 0, + user001Address, + user001Key, + blockingStubFull); - scheduledExecutorService - .schedule(new CheckTask(triggerTxid, blockingStubFull), 15, TimeUnit.SECONDS); + scheduledExecutorService.schedule( + new CheckTask(triggerTxid, blockingStubFull), 15, TimeUnit.SECONDS); - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); - logger - .info( - "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + logger.info( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } private synchronized void wirteLine(String fileName, String line) { @@ -264,14 +316,16 @@ private synchronized void wirteLine(String fileName, String line) { } } - @Test(enabled = true, description = "Deploy multiple long bytecode contract " - + "and write address to file.", groups = {"stress"}) + @Test( + enabled = true, + description = "Deploy multiple long bytecode contract " + "and write address to file.", + groups = {"stress"}) public void test03DeployMultiLongByteCodeContract() { ExecutorService pool = Executors.newFixedThreadPool(30); Map addressMap = new ConcurrentHashMap<>(); - int size = 50_0_000; - int stubSize = 30; + int size = 50_0_000; + int stubSize = 30; List stubs = new ArrayList<>(); for (int i = 0; i < stubSize; i++) { stubs.add(WalletGrpc.newBlockingStub(channelFull)); @@ -283,7 +337,6 @@ public void test03DeployMultiLongByteCodeContract() { String contractName = "extcodehashContract" + i; logger.info("[" + i + "]contractName: " + contractName); pool.submit(new DeployTask(addressMap, i, count, stubs.get(i % stubSize))); - } try { @@ -297,34 +350,38 @@ public void test03DeployMultiLongByteCodeContract() { } } - @Test(enabled = true, description = "Calculate the contract maxfeelimit.", - threadPoolSize = 1, invocationCount = 1, groups = {"stress"}) + @Test( + enabled = true, + description = "Calculate the contract maxfeelimit.", + threadPoolSize = 1, + invocationCount = 1, + groups = {"stress"}) public void test04StressGetExtCodeHashContract() { ECKey ecKey2 = new ECKey(Utils.getRandom()); - byte[] user001Address = ecKey2.getAddress(); - String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + byte[] user001Address = ecKey2.getAddress(); + String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - extCodeHashContractAddress = WalletClient - .decodeFromBase58Check("TEsdDpJQrLBDPmJfDF2Ex53iMfzetqHvn9"); - // long bytecode contract + extCodeHashContractAddress = + WalletClient.decodeFromBase58Check("TEsdDpJQrLBDPmJfDF2Ex53iMfzetqHvn9"); + // long bytecode contract testContractAddress = WalletClient.decodeFromBase58Check("TDqSAv8gLFXQRfug5Pr1Ev6zrEj1efC8qe"); HashMap retMap = new HashMap<>(); long feeLimit = 314982000; - // long feeLimit = 393624800; - // long feeLimit = 406731800; + // long feeLimit = 393624800; + // long feeLimit = 406731800; long base = 100; long lastSuccess = feeLimit; - int failed = 0; + int failed = 0; for (int i = 0; i < 1000000000; i++) { try { - String retCode = triggerContractWithMaxFeeLimit(testContractAddress, user001Address, - user001Key, - feeLimit); + String retCode = + triggerContractWithMaxFeeLimit( + testContractAddress, user001Address, user001Key, feeLimit); logger.info("[" + i + "]retCode: " + retCode); logger.info("[" + i + "]feeLimit: " + feeLimit); lastSuccess = feeLimit; @@ -343,17 +400,20 @@ public void test04StressGetExtCodeHashContract() { } } - @Test(enabled = true, description = "Trigger extcodeHash contract stress.", groups = {"stress"}) + @Test( + enabled = true, + description = "Trigger extcodeHash contract stress.", + groups = {"stress"}) public void test05TriggerContract() throws FileNotFoundException { BufferedReader reader = null; List addresses = new ArrayList<>(); try { reader = new BufferedReader(new FileReader("src/test/resources/address2")); - String line = reader.readLine(); + String line = reader.readLine(); while (line != null) { System.out.println(line); - // read next line + // read next line line = reader.readLine(); addresses.add(line); } @@ -362,7 +422,7 @@ public void test05TriggerContract() throws FileNotFoundException { e.printStackTrace(); } ExecutorService pool = Executors.newFixedThreadPool(50); - int stubSize = 50; + int stubSize = 50; List stubs = new ArrayList<>(); for (int i = 0; i < stubSize; i++) { stubs.add(WalletGrpc.newBlockingStub(channelFull)); @@ -373,8 +433,10 @@ public void test05TriggerContract() throws FileNotFoundException { for (int i = 0; i + paramsSize < addresses.size(); i += paramsSize) { System.err.println(trigger++); System.err.println(i + " " + (i + paramsSize)); - pool.submit(new TriggerTask(addresses.subList(i, i + paramsSize), stubs.get( - (int) (Math.random() * 100 % stubSize)))); + pool.submit( + new TriggerTask( + addresses.subList(i, i + paramsSize), + stubs.get((int) (Math.random() * 100 % stubSize)))); } try { @@ -384,22 +446,27 @@ public void test05TriggerContract() throws FileNotFoundException { } } - /** - * trigger. - */ + /** trigger. */ public void triggerContact(String[] testList, WalletGrpc.WalletBlockingStub stub) { final byte[] user001Address = foundationAddress; - final String user001Key = testKey002; + final String user001Key = testKey002; - extCodeHashContractAddress = WalletClient - .decodeFromBase58Check("TJGYcUspHrwPgy72YeaVjD4Skep9Ji8Pnn"); - final long feeLimit = 102471600; + extCodeHashContractAddress = + WalletClient.decodeFromBase58Check("TJGYcUspHrwPgy72YeaVjD4Skep9Ji8Pnn"); + final long feeLimit = 102471600; count.getAndAdd(1); if (count.get() % 100 == 0) { long cost = (System.currentTimeMillis() - startTime) / 1000; - logger.info("Count:" + count.get() + ", cost:" + cost - + ", avg:" + count.get() / cost + ", errCount:" + errorCount); + logger.info( + "Count:" + + count.get() + + ", cost:" + + cost + + ", avg:" + + count.get() / cost + + ", errCount:" + + errorCount); } List addressList = new ArrayList<>(); @@ -410,18 +477,20 @@ public void triggerContact(String[] testList, WalletGrpc.WalletBlockingStub stub triggerAndGetExtCodeHashList(addressList, user001Address, user001Key, feeLimit, stub); } - @Test(enabled = true, description = "Trigger normal contract stress.", groups = {"stress"}) + @Test( + enabled = true, + description = "Trigger normal contract stress.", + groups = {"stress"}) public void test06TriggerNormalContract() throws FileNotFoundException { BufferedReader reader = null; List addresses = new ArrayList<>(); try { - reader = new BufferedReader(new FileReader( - "src/test/resources/address2")); - String line = reader.readLine(); + reader = new BufferedReader(new FileReader("src/test/resources/address2")); + String line = reader.readLine(); while (line != null) { System.out.println(line); - // read next line + // read next line line = reader.readLine(); addresses.add(line); } @@ -430,20 +499,21 @@ public void test06TriggerNormalContract() throws FileNotFoundException { e.printStackTrace(); } ExecutorService pool = Executors.newFixedThreadPool(50); - int stubSize = 50; + int stubSize = 50; List stubs = new ArrayList<>(); for (int i = 0; i < stubSize; i++) { stubs.add(WalletGrpc.newBlockingStub(channelFull)); } int paramsSize = 50; - int trigger = 0; + int trigger = 0; for (int i = 0; i + paramsSize < addresses.size(); i += 1) { System.err.println(trigger++); System.err.println(i + " " + (i + paramsSize)); pool.submit( - new TriggerNormalTask(addresses.subList(0, 0 + paramsSize), stubs.get( - (int) (Math.random() * 100 % stubSize)))); + new TriggerNormalTask( + addresses.subList(0, 0 + paramsSize), + stubs.get((int) (Math.random() * 100 % stubSize)))); } try { @@ -453,22 +523,27 @@ public void test06TriggerNormalContract() throws FileNotFoundException { } } - /** - * trigger. - */ + /** trigger. */ public void triggerNormalContact(String[] testList, WalletGrpc.WalletBlockingStub stub) { final byte[] user001Address = foundationAddress; - final String user001Key = testKey002; + final String user001Key = testKey002; - normalContractAddress = WalletClient - .decodeFromBase58Check("TFUSarvJtCSQhDifdRaioytThohLSLCjq4"); - final long feeLimit = 51079600; + normalContractAddress = + WalletClient.decodeFromBase58Check("TFUSarvJtCSQhDifdRaioytThohLSLCjq4"); + final long feeLimit = 51079600; count.getAndAdd(1); if (count.get() % 100 == 0) { long cost = (System.currentTimeMillis() - startTime) / 1000; - logger.info("Count:" + count.get() + ", cost:" + cost - + ", avg:" + count.get() / cost + ", errCount:" + errorCount); + logger.info( + "Count:" + + count.get() + + ", cost:" + + cost + + ", avg:" + + count.get() / cost + + ", errCount:" + + errorCount); } List addressList = new ArrayList<>(); @@ -477,24 +552,24 @@ public void triggerNormalContact(String[] testList, WalletGrpc.WalletBlockingStu addressList.add(WalletClient.decodeFromBase58Check(testList[k])); } - triggerAndGetExtCodeHash(normalContractAddress, user001Address, - user001Key, feeLimit, stub); + triggerAndGetExtCodeHash(normalContractAddress, user001Address, user001Key, feeLimit, stub); } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} class DeployTask implements Runnable { Map addressList; CountDownLatch countDownLatch; WalletGrpc.WalletBlockingStub stub; - int index; + int index; - DeployTask(Map addressList, int index, CountDownLatch countDownLatch, + DeployTask( + Map addressList, + int index, + CountDownLatch countDownLatch, WalletGrpc.WalletBlockingStub stub) { this.index = index; this.addressList = addressList; @@ -505,16 +580,12 @@ class DeployTask implements Runnable { @Override public void run() { logger.info("depoying :" + index); - String code = Configuration.getByPath("testng.conf") - .getString("code.code_veryLarge"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_veryLarge"); + String code = Configuration.getByPath("testng.conf").getString("code.code_veryLarge"); + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_veryLarge"); try { byte[] deployedAddress = deployContract(code, abi, "test" + index, stub); - String address = Base58.encode58Check(deployedAddress); - wirteLine( - "src/test/resources/addresses2", - address); + String address = Base58.encode58Check(deployedAddress); + wirteLine("src/test/resources/addresses2", address); logger.info("deployed : " + index + " " + address); } catch (Throwable e) { logger.error("deploy error: ", e); @@ -537,8 +608,8 @@ class CheckTask implements Runnable { @Override public void run() { - Optional infoById = PublicMethod - .getTransactionInfoById(this.txid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(this.txid, blockingStubFull); TransactionInfo transactionInfo = infoById.get(); if (infoById.get().getResultValue() != 0) { @@ -582,5 +653,3 @@ public void run() { } } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/HttpStressTest.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/HttpStressTest.java index d8b67014..e338391d 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/HttpStressTest.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/HttpStressTest.java @@ -23,17 +23,17 @@ public class HttpStressTest { private static final long now = System.currentTimeMillis(); private static final long totalSupply = 10000000000000000L; - static Integer connectionTimeout = Configuration.getByPath("testng.conf") - .getInt("defaultParameter.httpConnectionTimeout"); - static Integer soTimeout = Configuration.getByPath("testng.conf") - .getInt("defaultParameter.httpSoTimeout"); + static Integer connectionTimeout = + Configuration.getByPath("testng.conf").getInt("defaultParameter.httpConnectionTimeout"); + static Integer soTimeout = + Configuration.getByPath("testng.conf").getInt("defaultParameter.httpSoTimeout"); private static String name = "testAssetIssue002_" + Long.toString(now); private static String assetIssueId1; private static String assetIssueId2; private static Integer exchangeId; private static Long beforeInjectBalance; - private final String testKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); + private final String testKey002 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key1"); private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey002); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] exchangeOwnerAddress = ecKey1.getAddress(); @@ -42,46 +42,75 @@ public class HttpStressTest { byte[] asset2Address = ecKey2.getAddress(); String asset2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); Long amount = 2048000000L; - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private JSONObject responseContent; private HttpResponse response; - private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") - .get(0); + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); - /** - * constructor. - */ - @Test(enabled = true, threadPoolSize = 10, invocationCount = 10, groups = {"stress"}) + /** constructor. */ + @Test( + enabled = true, + threadPoolSize = 10, + invocationCount = 10, + groups = {"stress"}) public void test4InjectExchange() { final long now = System.currentTimeMillis(); final long totalSupply = 10000000000000000L; Long beforeInjectBalance; HttpClient httpClient = new DefaultHttpClient(); HttpPost httppost; - httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, - connectionTimeout); + httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, soTimeout); httppost = new HttpPost(url); httppost.setHeader("Content-type", "application/json; charset=utf-8"); httppost.setHeader("Connection", "Close"); - response = HttpMethod - .sendCoin(httpnode, fromAddress, exchangeOwnerAddress, amount, testKey002); + response = HttpMethod.sendCoin(httpnode, fromAddress, exchangeOwnerAddress, amount, testKey002); Assert.assertTrue(HttpMethod.verificationResult(response)); response = HttpMethod.sendCoin(httpnode, fromAddress, asset2Address, amount, testKey002); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); - //Create an asset issue - response = HttpMethod.assetIssue(httpnode, exchangeOwnerAddress, name, name, totalSupply, 1, 1, - System.currentTimeMillis() + 5000, System.currentTimeMillis() + 50000000, - 2, 3, description, url, 1000L, 1000L, exchangeOwnerKey); + // Create an asset issue + response = + HttpMethod.assetIssue( + httpnode, + exchangeOwnerAddress, + name, + name, + totalSupply, + 1, + 1, + System.currentTimeMillis() + 5000, + System.currentTimeMillis() + 50000000, + 2, + 3, + description, + url, + 1000L, + 1000L, + exchangeOwnerKey); Assert.assertTrue(HttpMethod.verificationResult(response)); - response = HttpMethod.assetIssue(httpnode, asset2Address, name, name, totalSupply, 1, 1, - System.currentTimeMillis() + 5000, System.currentTimeMillis() + 50000000, - 2, 3, description, url, 1000L, 1000L, asset2Key); + response = + HttpMethod.assetIssue( + httpnode, + asset2Address, + name, + name, + totalSupply, + 1, + 1, + System.currentTimeMillis() + 5000, + System.currentTimeMillis() + 50000000, + 2, + 3, + description, + url, + 1000L, + 1000L, + asset2Key); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); response = HttpMethod.getAccount(httpnode, exchangeOwnerAddress); @@ -94,17 +123,29 @@ public void test4InjectExchange() { assetIssueId2 = responseContent.getString("asset_issued_ID"); Assert.assertTrue(Integer.parseInt(assetIssueId2) > 1000000); - response = HttpMethod - .transferAsset(httpnode, asset2Address, exchangeOwnerAddress, assetIssueId2, - 100000000000000L, asset2Key); + response = + HttpMethod.transferAsset( + httpnode, + asset2Address, + exchangeOwnerAddress, + assetIssueId2, + 100000000000000L, + asset2Key); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); HttpMethod.waitToProduceOneBlock(httpnode); - //Create exchange. - response = HttpMethod.exchangeCreate(httpnode, exchangeOwnerAddress, assetIssueId1, - 50000000000000L, assetIssueId2, 50000000000000L, exchangeOwnerKey); + // Create exchange. + response = + HttpMethod.exchangeCreate( + httpnode, + exchangeOwnerAddress, + assetIssueId1, + 50000000000000L, + assetIssueId2, + 50000000000000L, + exchangeOwnerKey); Assert.assertTrue(HttpMethod.verificationResult(response)); HttpMethod.waitToProduceOneBlock(httpnode); @@ -124,35 +165,35 @@ public void test4InjectExchange() { while (times++ <= 10000) { HttpMethod.sendCoin(httpnode, fromAddress, exchangeOwnerAddress, 100L, testKey002); HttpMethod.sendCoin(httpnode, fromAddress, asset2Address, 100L, testKey002); - //Inject exchange. - HttpMethod.exchangeInject(httpnode, exchangeOwnerAddress, exchangeId, assetIssueId1, - 10L, exchangeOwnerKey); - HttpMethod.exchangeWithdraw(httpnode, exchangeOwnerAddress, exchangeId, assetIssueId1, - 10L, exchangeOwnerKey); - HttpMethod.exchangeTransaction(httpnode, exchangeOwnerAddress, exchangeId, assetIssueId1, - 100L, 1L, exchangeOwnerKey); - HttpMethod.exchangeTransaction(httpnode, exchangeOwnerAddress, exchangeId, assetIssueId2, - 100L, 1L, exchangeOwnerKey); - HttpMethod.transferAsset(httpnode, asset2Address, exchangeOwnerAddress, assetIssueId2, - 1L, asset2Key); - HttpMethod.transferAsset(httpnode, exchangeOwnerAddress, asset2Address, assetIssueId1, - 1L, exchangeOwnerKey); - HttpMethod.participateAssetIssue(httpnode, exchangeOwnerAddress, asset2Address, - assetIssueId1, 1L, asset2Key); - HttpMethod.participateAssetIssue(httpnode, asset2Address, exchangeOwnerAddress, - assetIssueId2, 1L, exchangeOwnerKey); - HttpMethod.freezeBalance(httpnode, fromAddress, 10000000000L, 0, 0, - exchangeOwnerAddress, testKey002); - HttpMethod.freezeBalance(httpnode, fromAddress, 10000000000L, 0, 1, - exchangeOwnerAddress, testKey002); - HttpMethod.unFreezeBalance(httpnode, fromAddress, 10000000000L,0, exchangeOwnerAddress, testKey002); - HttpMethod.unFreezeBalance(httpnode, fromAddress, 10000000000L,1, exchangeOwnerAddress, testKey002); + // Inject exchange. + HttpMethod.exchangeInject( + httpnode, exchangeOwnerAddress, exchangeId, assetIssueId1, 10L, exchangeOwnerKey); + HttpMethod.exchangeWithdraw( + httpnode, exchangeOwnerAddress, exchangeId, assetIssueId1, 10L, exchangeOwnerKey); + HttpMethod.exchangeTransaction( + httpnode, exchangeOwnerAddress, exchangeId, assetIssueId1, 100L, 1L, exchangeOwnerKey); + HttpMethod.exchangeTransaction( + httpnode, exchangeOwnerAddress, exchangeId, assetIssueId2, 100L, 1L, exchangeOwnerKey); + HttpMethod.transferAsset( + httpnode, asset2Address, exchangeOwnerAddress, assetIssueId2, 1L, asset2Key); + HttpMethod.transferAsset( + httpnode, exchangeOwnerAddress, asset2Address, assetIssueId1, 1L, exchangeOwnerKey); + HttpMethod.participateAssetIssue( + httpnode, exchangeOwnerAddress, asset2Address, assetIssueId1, 1L, asset2Key); + HttpMethod.participateAssetIssue( + httpnode, asset2Address, exchangeOwnerAddress, assetIssueId2, 1L, exchangeOwnerKey); + HttpMethod.freezeBalance( + httpnode, fromAddress, 10000000000L, 0, 0, exchangeOwnerAddress, testKey002); + HttpMethod.freezeBalance( + httpnode, fromAddress, 10000000000L, 0, 1, exchangeOwnerAddress, testKey002); + HttpMethod.unFreezeBalance( + httpnode, fromAddress, 10000000000L, 0, exchangeOwnerAddress, testKey002); + HttpMethod.unFreezeBalance( + httpnode, fromAddress, 10000000000L, 1, exchangeOwnerAddress, testKey002); } } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { HttpMethod.disConnect(); diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/JsonRpcTest.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/JsonRpcTest.java index fcd1d6e7..b29ef3fe 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/JsonRpcTest.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/JsonRpcTest.java @@ -51,9 +51,7 @@ import stest.tron.wallet.common.client.utils.Sha256Hash; import stest.tron.wallet.common.client.utils.Utils; - @Slf4j - public class JsonRpcTest extends JsonRpcBase { private JSONObject responseContent; private HttpResponse response; @@ -62,40 +60,34 @@ public class JsonRpcTest extends JsonRpcBase { byte[] getBalanceTestAddress = getBalanceECKey.getAddress(); String getBalanceTestKey = ByteArray.toHexString(getBalanceECKey.getPrivKeyBytes()); - private final String foundationKey001 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); - private Long sendAmount = 20000000L; + private final String foundationKey001 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key1"); + private Long sendAmount = 20000000L; private final Long transferAmount = 2L; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - //fullnode = "47.94.243.150:50051"; + // fullnode = "47.94.243.150:50051"; fullnode = "39.106.55.169:50051"; - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext() - .build(); + channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); blockingStubFull = WalletGrpc.newBlockingStub(channelFull); PublicMethod.printAddress(getBalanceTestKey); } - public void doCheck(ByteString address) throws Exception { if (addressSet.contains(address)) { return; } else { addressSet.add(address); - if(addressSet.size() % 100 == 0) { + if (addressSet.size() % 100 == 0) { logger.info("Set size : " + addressSet.size()); } } logger.info("checking :" + WalletClient.encode58Check(address.toByteArray())); checkTrxBalance(address); - //checkTrc10Balance(address); + // checkTrc10Balance(address); return; - } public void checkTrc10Balance(ByteString address) throws Exception { @@ -106,32 +98,51 @@ public void checkTrc10Balance(ByteString address) throws Exception { response = getJsonRpc(stateTreeNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); JSONArray jsonArray = responseContent.getJSONArray("result"); - for(int i = 0; i < jsonArray.size();i++) { - Long tokenId = Long.parseLong(jsonArray.getJSONObject(i).getString("key").substring(2),16); - Long assertBalance = Long.parseLong(jsonArray.getJSONObject(i).getString("value").substring(2),16); - - Long balanceFromGetAccount = PublicMethod.getAssetIssueValue(address.toByteArray(),ByteString.copyFromUtf8(tokenId.toString()),blockingStubFull); - Assert.assertEquals(assertBalance,balanceFromGetAccount); + for (int i = 0; i < jsonArray.size(); i++) { + Long tokenId = Long.parseLong(jsonArray.getJSONObject(i).getString("key").substring(2), 16); + Long assertBalance = + Long.parseLong(jsonArray.getJSONObject(i).getString("value").substring(2), 16); + + Long balanceFromGetAccount = + PublicMethod.getAssetIssueValue( + address.toByteArray(), ByteString.copyFromUtf8(tokenId.toString()), blockingStubFull); + Assert.assertEquals(assertBalance, balanceFromGetAccount); } - } public HashSet smartContractSet = new HashSet<>(); - public void compareBalance(ByteString userAddress,ByteString contractAddress) throws Exception { - if(smartContractSet.contains(Base58.encode58Check(userAddress.toByteArray()) + Base58.encode58Check(contractAddress.toByteArray()))) { + public void compareBalance(ByteString userAddress, ByteString contractAddress) throws Exception { + if (smartContractSet.contains( + Base58.encode58Check(userAddress.toByteArray()) + + Base58.encode58Check(contractAddress.toByteArray()))) { return; } - smartContractSet.add(Base58.encode58Check(userAddress.toByteArray()) + Base58.encode58Check(contractAddress.toByteArray())); - if(smartContractSet.size() % 100 == 0) { + smartContractSet.add( + Base58.encode58Check(userAddress.toByteArray()) + + Base58.encode58Check(contractAddress.toByteArray())); + if (smartContractSet.size() % 100 == 0) { logger.info("smartContractSet size : " + smartContractSet.size()); } String paramString = "\"" + Base58.encode58Check(userAddress.toByteArray()) + "\""; - BigInteger constantBalance = new BigInteger(ByteArray.toHexString(PublicMethod.triggerConstantContractForExtention(contractAddress.toByteArray(), - "balanceOf(address)",paramString, - false,0,1000000000L, "0", 0,userAddress.toByteArray(), - foundationKey001,blockingStubFull).getConstantResult(0).toByteArray()),16); - + BigInteger constantBalance = + new BigInteger( + ByteArray.toHexString( + PublicMethod.triggerConstantContractForExtention( + contractAddress.toByteArray(), + "balanceOf(address)", + paramString, + false, + 0, + 1000000000L, + "0", + 0, + userAddress.toByteArray(), + foundationKey001, + blockingStubFull) + .getConstantResult(0) + .toByteArray()), + 16); String addressParam = "000000000000000000000000" @@ -143,10 +154,9 @@ public void compareBalance(ByteString userAddress,ByteString contractAddress) th param.addProperty("gas", "0x0"); param.addProperty("gasPrice", "0x0"); param.addProperty("value", "0x0"); - //balanceOf(address) keccak encode + // balanceOf(address) keccak encode param.addProperty("data", "0x70a08231" + addressParam); - JsonArray params = new JsonArray(); params.add(param); params.add("0x" + Long.toHexString(blockNum)); @@ -156,32 +166,33 @@ public void compareBalance(ByteString userAddress,ByteString contractAddress) th responseContent = HttpMethod.parseResponseContent(response); String balance = responseContent.getString("result").substring(2); BigInteger jsonrpcBalanceOf = new BigInteger(balance, 16); - Assert.assertEquals(jsonrpcBalanceOf,constantBalance); - - - + Assert.assertEquals(jsonrpcBalanceOf, constantBalance); } - public void checkSmartContractBalanceOf(ByteString userAddress, ByteString contractAddress,String txid) throws Exception { - TransactionInfo transactionInfo = PublicMethod.getTransactionInfoById(txid,blockingStubFull).get(); - if(transactionInfo.getLogCount() == 1) { + public void checkSmartContractBalanceOf( + ByteString userAddress, ByteString contractAddress, String txid) throws Exception { + TransactionInfo transactionInfo = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get(); + if (transactionInfo.getLogCount() == 1) { String topic = ByteArray.toHexString(transactionInfo.getLog(0).getTopics(0).toByteArray()); - if(topic.equalsIgnoreCase("ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef") - ) { - byte[] fromAddress = ByteArray.fromHexString("41" + ByteArray.toHexString(transactionInfo.getLog(0).getTopics(1).toByteArray()).substring(24)); - byte[] toAddress = ByteArray.fromHexString("41" + ByteArray.toHexString(transactionInfo.getLog(0).getTopics(2).toByteArray()).substring(24)); + if (topic.equalsIgnoreCase( + "ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")) { + byte[] fromAddress = + ByteArray.fromHexString( + "41" + + ByteArray.toHexString(transactionInfo.getLog(0).getTopics(1).toByteArray()) + .substring(24)); + byte[] toAddress = + ByteArray.fromHexString( + "41" + + ByteArray.toHexString(transactionInfo.getLog(0).getTopics(2).toByteArray()) + .substring(24)); ByteString logContractAddress = transactionInfo.getLog(0).getAddress(); - compareBalance(ByteString.copyFrom(fromAddress),logContractAddress); - compareBalance(ByteString.copyFrom(toAddress),logContractAddress); - - - - - + compareBalance(ByteString.copyFrom(fromAddress), logContractAddress); + compareBalance(ByteString.copyFrom(toAddress), logContractAddress); } } - } public void checkTrxBalance(ByteString address) throws Exception { @@ -202,25 +213,28 @@ public void checkTrxBalance(ByteString address) throws Exception { responseContent = HttpMethod.parseResponseContent(response); balance = responseContent.getString("result").substring(2); Long stateTreeBalance = Long.parseLong(balance, 16); - Assert.assertEquals(stateTreeBalance,latestBalance); + Assert.assertEquals(stateTreeBalance, latestBalance); - Assert.assertEquals((long)stateTreeBalance,PublicMethod.queryAccount(address.toByteArray(),blockingStubFull).getBalance()); + Assert.assertEquals( + (long) stateTreeBalance, + PublicMethod.queryAccount(address.toByteArray(), blockingStubFull).getBalance()); } - //public String noStateTreeNode = "47.94.243.150:50545"; + // public String noStateTreeNode = "47.94.243.150:50545"; public String noStateTreeNode = "39.106.55.169:50545"; - //public String stateTreeNode = "39.106.110.245:50545"; + // public String stateTreeNode = "39.106.110.245:50545"; public String stateTreeNode = "39.106.55.169:50546"; public HashSet addressSet = new HashSet<>(); public Long blockNum = 6000L; - @Test(enabled = true, description = "State tree with eth_getBalance", groups = {"stress"}) + @Test( + enabled = true, + description = "State tree with eth_getBalance", + groups = {"stress"}) public void test01StateTreeWithEthGetBalance() throws Exception { - - Long startNum = blockNum; - //Long endNum = startNum - 20000;; + // Long endNum = startNum - 20000;; Long endNum = 0L; NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(startNum); @@ -234,8 +248,7 @@ public void test01StateTreeWithEthGetBalance() throws Exception { for (Transaction transaction : transactionList) { Any any = transaction.getRawData().getContract(0).getParameter(); - Integer contractType = transaction.getRawData().getContract(0).getType().getNumber(); - + Integer contractType = transaction.getRawData().getContract(0).getType().getNumber(); try { switch (contractType) { @@ -253,15 +266,17 @@ public void test01StateTreeWithEthGetBalance() throws Exception { TriggerSmartContract triggerSmartContract = any.unpack(TriggerSmartContract.class); doCheck(triggerSmartContract.getOwnerAddress()); doCheck(triggerSmartContract.getContractAddress()); - checkSmartContractBalanceOf(triggerSmartContract.getOwnerAddress(),triggerSmartContract.getContractAddress(), + checkSmartContractBalanceOf( + triggerSmartContract.getOwnerAddress(), + triggerSmartContract.getContractAddress(), ByteArray.toHexString( Sha256Hash.hash( CommonParameter.getInstance().isECKeyCryptoEngine(), transaction.getRawData().toByteArray()))); break; case 13: - WithdrawBalanceContract withdrawBalanceContract - = any.unpack(WithdrawBalanceContract.class); + WithdrawBalanceContract withdrawBalanceContract = + any.unpack(WithdrawBalanceContract.class); doCheck(withdrawBalanceContract.getOwnerAddress()); break; case 11: @@ -272,12 +287,13 @@ public void test01StateTreeWithEthGetBalance() throws Exception { AccountCreateContract accountCreateContract = any.unpack(AccountCreateContract.class); doCheck(accountCreateContract.getOwnerAddress()); break; - case 4: + case 4: VoteWitnessContract voteWitnessContract = any.unpack(VoteWitnessContract.class); doCheck(voteWitnessContract.getOwnerAddress()); + // fall through case 12: - UnfreezeBalanceContract unfreezeBalanceContract - = any.unpack(UnfreezeBalanceContract.class); + UnfreezeBalanceContract unfreezeBalanceContract = + any.unpack(UnfreezeBalanceContract.class); doCheck(unfreezeBalanceContract.getOwnerAddress()); break; case 30: @@ -285,80 +301,91 @@ public void test01StateTreeWithEthGetBalance() throws Exception { doCheck(createSmartContract.getOwnerAddress()); break; case 46: - AccountPermissionUpdateContract accountPermissionUpdateContract - = any.unpack(AccountPermissionUpdateContract.class); + AccountPermissionUpdateContract accountPermissionUpdateContract = + any.unpack(AccountPermissionUpdateContract.class); doCheck(accountPermissionUpdateContract.getOwnerAddress()); break; case 54: - FreezeBalanceV2Contract freezeBalanceV2Contract - = any.unpack(FreezeBalanceV2Contract.class); + FreezeBalanceV2Contract freezeBalanceV2Contract = + any.unpack(FreezeBalanceV2Contract.class); doCheck(freezeBalanceV2Contract.getOwnerAddress()); break; case 55: - UnfreezeBalanceV2Contract unfreezeBalanceV2Contract - = any.unpack(UnfreezeBalanceV2Contract.class); + UnfreezeBalanceV2Contract unfreezeBalanceV2Contract = + any.unpack(UnfreezeBalanceV2Contract.class); doCheck(unfreezeBalanceV2Contract.getOwnerAddress()); break; case 56: - WithdrawExpireUnfreezeContract withdrawExpireUnfreezeContract - = any.unpack(WithdrawExpireUnfreezeContract.class); + WithdrawExpireUnfreezeContract withdrawExpireUnfreezeContract = + any.unpack(WithdrawExpireUnfreezeContract.class); doCheck(withdrawExpireUnfreezeContract.getOwnerAddress()); break; case 57: - DelegateResourceContract delegateResourceContract - = any.unpack(DelegateResourceContract.class); + DelegateResourceContract delegateResourceContract = + any.unpack(DelegateResourceContract.class); doCheck(delegateResourceContract.getOwnerAddress()); doCheck(delegateResourceContract.getReceiverAddress()); break; case 58: - UnDelegateResourceContract unDelegateResourceContract - = any.unpack(UnDelegateResourceContract.class); + UnDelegateResourceContract unDelegateResourceContract = + any.unpack(UnDelegateResourceContract.class); doCheck(unDelegateResourceContract.getOwnerAddress()); doCheck(unDelegateResourceContract.getReceiverAddress()); break; default: logger.info("Unknown type:" + contractType); continue; - } } catch (Exception e) { e.printStackTrace(); - } - - - - - } } - - - } - - @Test(enabled = false, description = "State tree with tron_getToken10", groups = {"stress"}) + @Test( + enabled = false, + description = "State tree with tron_getToken10", + groups = {"stress"}) public void test02StateTreeWithTronGetToken10() throws Exception { - Assert.assertTrue(PublicMethod.transferAsset(getBalanceTestAddress, jsonRpcAssetId.getBytes(),sendAmount, - jsonRpcOwnerAddress,jsonRpcOwnerKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + getBalanceTestAddress, + jsonRpcAssetId.getBytes(), + sendAmount, + jsonRpcOwnerAddress, + jsonRpcOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); final Long beforeBalance = sendAmount; - final Long beforeBlockNumber = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + final Long beforeBlockNumber = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.transferAsset(getBalanceTestAddress, jsonRpcAssetId.getBytes(),transferAmount, - jsonRpcOwnerAddress,jsonRpcOwnerKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + getBalanceTestAddress, + jsonRpcAssetId.getBytes(), + transferAmount, + jsonRpcOwnerAddress, + jsonRpcOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); final Long afterBalance = sendAmount + transferAmount; - final Long afterBlockNumber = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); - - - //Assert before trc10 balance + final Long afterBlockNumber = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); + + // Assert before trc10 balance JsonArray params = new JsonArray(); params.add("0x" + ByteArray.toHexString(getBalanceTestAddress).substring(2)); params.add("0x" + Long.toHexString(beforeBlockNumber)); @@ -367,10 +394,9 @@ public void test02StateTreeWithTronGetToken10() throws Exception { responseContent = HttpMethod.parseResponseContent(response); String balance = responseContent.getString("result").substring(2); Long assertBalance = Long.parseLong(balance, 16); - Assert.assertEquals(assertBalance,beforeBalance); - + Assert.assertEquals(assertBalance, beforeBalance); - //Assert after balance + // Assert after balance params = new JsonArray(); params.add("0x" + ByteArray.toHexString(getBalanceTestAddress).substring(2)); params.add("0x" + Long.toHexString(afterBlockNumber)); @@ -379,11 +405,9 @@ public void test02StateTreeWithTronGetToken10() throws Exception { responseContent = HttpMethod.parseResponseContent(response); balance = responseContent.getString("result").substring(2); assertBalance = Long.parseLong(balance, 16); - Assert.assertEquals(assertBalance,afterBalance); - - + Assert.assertEquals(assertBalance, afterBalance); - //State tree not open didn't support block number + // State tree not open didn't support block number params = new JsonArray(); params.add("0x" + ByteArray.toHexString(getBalanceTestAddress).substring(2)); params.add("0x" + Long.toHexString(afterBlockNumber)); @@ -391,11 +415,13 @@ public void test02StateTreeWithTronGetToken10() throws Exception { response = getJsonRpc(jsonRpcNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); String wrongMessage = responseContent.getJSONObject("error").getString("message"); - Assert.assertEquals(wrongMessage,"QUANTITY not supported, just support TAG as latest"); + Assert.assertEquals(wrongMessage, "QUANTITY not supported, just support TAG as latest"); } - - @Test(enabled = false, description = "State tree with eth_call", groups = {"stress"}) + @Test( + enabled = false, + description = "State tree with eth_call", + groups = {"stress"}) public void test03StateTreeWithEthCall() throws Exception { String selector = "transfer(address,uint256)"; String addressParam = @@ -418,13 +444,16 @@ public void test03StateTreeWithEthCall() throws Exception { jsonRpcOwnerKey, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.getTransactionInfoById(trc20Txid,blockingStubFull).get() - .getLogCount() == 1); - - - final Long beforeBalance = Long.parseLong("100",16); - final Long beforeBlockNumber = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + Assert.assertTrue( + PublicMethod.getTransactionInfoById(trc20Txid, blockingStubFull).get().getLogCount() == 1); + + final Long beforeBalance = Long.parseLong("100", 16); + final Long beforeBlockNumber = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); PublicMethod.waitProduceNextBlock(blockingStubFull); trc20Txid = @@ -442,15 +471,18 @@ public void test03StateTreeWithEthCall() throws Exception { blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.getTransactionInfoById(trc20Txid,blockingStubFull).get() - .getLogCount() == 1); + Assert.assertTrue( + PublicMethod.getTransactionInfoById(trc20Txid, blockingStubFull).get().getLogCount() == 1); final Long afterBalance = beforeBalance + beforeBalance; - final Long afterBlockNumber = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); - - - //Assert before trc20 balance + final Long afterBlockNumber = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); + + // Assert before trc20 balance JsonObject param = new JsonObject(); HttpMethod.waitToProduceOneBlock(httpFullNode); param.addProperty("from", ByteArray.toHexString(getBalanceTestAddress)); @@ -458,10 +490,9 @@ public void test03StateTreeWithEthCall() throws Exception { param.addProperty("gas", "0x0"); param.addProperty("gasPrice", "0x0"); param.addProperty("value", "0x0"); - //balanceOf(address) keccak encode + // balanceOf(address) keccak encode param.addProperty("data", "0x70a08231" + addressParam); - JsonArray params = new JsonArray(); params.add(param); params.add("0x" + Long.toHexString(beforeBlockNumber)); @@ -471,10 +502,9 @@ public void test03StateTreeWithEthCall() throws Exception { responseContent = HttpMethod.parseResponseContent(response); String balance = responseContent.getString("result").substring(2); Long assertBalance = Long.parseLong(balance, 16); - Assert.assertEquals(assertBalance,beforeBalance); - + Assert.assertEquals(assertBalance, beforeBalance); - //Assert after balance + // Assert after balance params = new JsonArray(); params.add(param); params.add("0x" + Long.toHexString(afterBlockNumber)); @@ -483,11 +513,9 @@ public void test03StateTreeWithEthCall() throws Exception { responseContent = HttpMethod.parseResponseContent(response); balance = responseContent.getString("result").substring(2); assertBalance = Long.parseLong(balance, 16); - Assert.assertEquals(assertBalance,afterBalance); - - + Assert.assertEquals(assertBalance, afterBalance); - //State tree not open didn't support block number + // State tree not open didn't support block number params = new JsonArray(); params.add(param); params.add("0x" + Long.toHexString(afterBlockNumber)); @@ -495,15 +523,19 @@ public void test03StateTreeWithEthCall() throws Exception { response = getJsonRpc(jsonRpcNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); String wrongMessage = responseContent.getJSONObject("error").getString("message"); - Assert.assertEquals(wrongMessage,"QUANTITY not supported, just support TAG as latest"); + Assert.assertEquals(wrongMessage, "QUANTITY not supported, just support TAG as latest"); } - - @Test(enabled = false, description = "State tree with eth_getCode", groups = {"stress"}) + @Test( + enabled = false, + description = "State tree with eth_getCode", + groups = {"stress"}) public void test04StateTreeWithEthGetCode() throws Exception { - String getCodeFromGetContract = ByteArray - .toHexString(PublicMethod.getContract(selfDestructAddressByte,blockingStubFull) - .getBytecode().toByteArray()); + String getCodeFromGetContract = + ByteArray.toHexString( + PublicMethod.getContract(selfDestructAddressByte, blockingStubFull) + .getBytecode() + .toByteArray()); logger.info("Get contract bytecode: " + getCodeFromGetContract); @@ -514,15 +546,17 @@ public void test04StateTreeWithEthGetCode() throws Exception { JsonObject requestBody = getJsonRpcBody("eth_getCode", params); response = getJsonRpc(stateTreeNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); - String getCodeFromLatest= responseContent.getString("result").substring(2); + String getCodeFromLatest = responseContent.getString("result").substring(2); logger.info("Latest getCode:" + getCodeFromLatest); - //Assert.assertEquals(getCodeFromJsonRpc,getCodeFromGetContract); - + // Assert.assertEquals(getCodeFromJsonRpc,getCodeFromGetContract); - - final Long beforeBlockNumber = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + final Long beforeBlockNumber = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); PublicMethod.waitProduceNextBlock(blockingStubFull); txid = @@ -540,13 +574,17 @@ public void test04StateTreeWithEthGetCode() throws Exception { blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(PublicMethod.getTransactionInfoById(txid,blockingStubFull).get() - .getReceipt().getResult(), contractResult.SUCCESS); - final Long afterBlockNumber = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); - - - //Assert before selfDestruct eth_getCode + Assert.assertEquals( + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get().getReceipt().getResult(), + contractResult.SUCCESS); + final Long afterBlockNumber = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); + + // Assert before selfDestruct eth_getCode params = new JsonArray(); params.add(ByteArray.toHexString(selfDestructAddressByte)); params.add("0x" + Long.toHexString(beforeBlockNumber)); @@ -557,10 +595,9 @@ public void test04StateTreeWithEthGetCode() throws Exception { String getCodeFromBeforeKill = responseContent.getString("result").substring(2); logger.info("Before kill : " + getCodeFromBeforeKill); - Assert.assertEquals(getCodeFromBeforeKill,getCodeFromLatest); - + Assert.assertEquals(getCodeFromBeforeKill, getCodeFromLatest); - //Assert after self destruct + // Assert after self destruct params = new JsonArray(); params.add(ByteArray.toHexString(selfDestructAddressByte)); params.add("0x" + Long.toHexString(afterBlockNumber)); @@ -569,11 +606,9 @@ public void test04StateTreeWithEthGetCode() throws Exception { responseContent = HttpMethod.parseResponseContent(response); String getCodeFromAfterKill = responseContent.getString("result"); logger.info("After kill : " + getCodeFromAfterKill); - Assert.assertEquals(getCodeFromAfterKill,"0x"); - + Assert.assertEquals(getCodeFromAfterKill, "0x"); - - //State tree not open didn't support block number + // State tree not open didn't support block number params = new JsonArray(); params.add(ByteArray.toHexString(selfDestructAddressByte)); params.add("0x" + Long.toHexString(beforeBlockNumber)); @@ -581,10 +616,13 @@ public void test04StateTreeWithEthGetCode() throws Exception { response = getJsonRpc(jsonRpcNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); String wrongMessage = responseContent.getJSONObject("error").getString("message"); - Assert.assertEquals(wrongMessage,"QUANTITY not supported, just support TAG as latest"); + Assert.assertEquals(wrongMessage, "QUANTITY not supported, just support TAG as latest"); } - @Test(enabled = false, description = "State tree with eth_getStorageAt", groups = {"stress"}) + @Test( + enabled = false, + description = "State tree with eth_getStorageAt", + groups = {"stress"}) public void test05StateTreeWithEthGetStorageAt() throws Exception { JsonArray params = new JsonArray(); params.add(contractAddressFrom58); @@ -596,8 +634,12 @@ public void test05StateTreeWithEthGetStorageAt() throws Exception { String result = responseContent.getString("result").substring(2); long beforePos2 = Long.parseLong(result, 16); logger.info("beforePos2:" + beforePos2); - final Long beforeBlockNumber = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + final Long beforeBlockNumber = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); txid = PublicMethod.triggerContract( @@ -614,14 +656,18 @@ public void test05StateTreeWithEthGetStorageAt() throws Exception { blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertEquals(PublicMethod.getTransactionInfoById(txid,blockingStubFull).get() - .getReceipt().getResult(), contractResult.SUCCESS); - - final Long afterBlockNumber = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); - - - //Assert before pos2 eth_getStorageAt + Assert.assertEquals( + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get().getReceipt().getResult(), + contractResult.SUCCESS); + + final Long afterBlockNumber = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); + + // Assert before pos2 eth_getStorageAt params = new JsonArray(); params.add(contractAddressFrom58); params.add("0x2"); @@ -630,13 +676,13 @@ public void test05StateTreeWithEthGetStorageAt() throws Exception { requestBody = getJsonRpcBody("eth_getStorageAt", params); response = getJsonRpc(stateTreeNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); - Long beforeNumberEthGetStorageAt = Long.parseLong(responseContent.getString("result").substring(2),16); + Long beforeNumberEthGetStorageAt = + Long.parseLong(responseContent.getString("result").substring(2), 16); logger.info("Before change pos2 : " + beforeNumberEthGetStorageAt); - Assert.assertEquals((long)beforeNumberEthGetStorageAt,beforePos2); + Assert.assertEquals((long) beforeNumberEthGetStorageAt, beforePos2); - - //Assert after change pos2 + // Assert after change pos2 params = new JsonArray(); params.add(contractAddressFrom58); params.add("0x2"); @@ -644,13 +690,12 @@ public void test05StateTreeWithEthGetStorageAt() throws Exception { requestBody = getJsonRpcBody("eth_getStorageAt", params); response = getJsonRpc(stateTreeNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); - Long afterNumberEthGetStorageAt = Long.parseLong(responseContent.getString("result").substring(2),16); - - Assert.assertEquals((long)afterNumberEthGetStorageAt,2); + Long afterNumberEthGetStorageAt = + Long.parseLong(responseContent.getString("result").substring(2), 16); + Assert.assertEquals((long) afterNumberEthGetStorageAt, 2); - - //State tree not open didn't support block number + // State tree not open didn't support block number params = new JsonArray(); params.add(contractAddressFrom58); params.add("0x2"); @@ -659,23 +704,14 @@ public void test05StateTreeWithEthGetStorageAt() throws Exception { response = getJsonRpc(jsonRpcNode, requestBody); responseContent = HttpMethod.parseResponseContent(response); String wrongMessage = responseContent.getJSONObject("error").getString("message"); - Assert.assertEquals(wrongMessage,"QUANTITY not supported, just support TAG as latest"); + Assert.assertEquals(wrongMessage, "QUANTITY not supported, just support TAG as latest"); } - - - - - - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { if (channelFull != null) { channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - } diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/MainNetTransferSendOrAsset.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/MainNetTransferSendOrAsset.java index 588bfa6e..7f4c442a 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/MainNetTransferSendOrAsset.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/MainNetTransferSendOrAsset.java @@ -12,20 +12,20 @@ @Slf4j public class MainNetTransferSendOrAsset extends TronBaseTest { - //testng001、testng002、testng003、testng004 - //all keys are for test + // testng001、testng002、testng003、testng004 + // all keys are for test private final String testKey001 = "BC70ADC5A0971BA3F7871FBB7249E345D84CE7E5458828BE1E28BF8F98F2795B"; - //toAssetIssue + // toAssetIssue private final String testKey002 = "F153A0E1A65193846A3D48A091CD0335594C0A3D9817B3441390FDFF71684C84"; - //fromSend + // fromSend private final String testKey003 = "2514B1DD2942FF07F68C2DDC0EE791BC7FBE96FDD95E89B7B9BB3B4C4770FFAC"; - //toSend + // toSend private final String testKey004 = "56244EE6B33C14C46704DFB67ED5D2BBCBED952EE46F1FD88A50C32C8C5C64CE"; - //Default + // Default private final String defaultKey = "8DFBB4513AECF779A0803C7CEBF2CDCC51585121FAB1E086465C4E0B40724AF1"; private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey001); @@ -42,23 +42,35 @@ public class MainNetTransferSendOrAsset extends TronBaseTest { private Long beforeToAssetBalance = 0L; private Long afterToAssetBalance = 0L; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = false) - public void beforeClass() { Account fromAccount = PublicMethod.queryAccount(testKey001, blockingStubFull); + public void beforeClass() { + Account fromAccount = PublicMethod.queryAccount(testKey001, blockingStubFull); Account toAccount = PublicMethod.queryAccount(testKey002, blockingStubFull); if (fromAccount.getBalance() < 10000000000L) { - PublicMethod - .sendcoin(fromAddress, 10000000000L, defaultAddress, defaultKey, blockingStubFull); + PublicMethod.sendcoin( + fromAddress, 10000000000L, defaultAddress, defaultKey, blockingStubFull); } if (fromAccount.getAssetCount() == 0) { start = System.currentTimeMillis() + 2000; end = System.currentTimeMillis() + 1000000000; - PublicMethod.createAssetIssue(fromAddress, "testNetAsset", 1000000000000L, - 1, 1, start, end, 1, "wwwwww", "wwwwwwww", 100000L, - 100000L, 1L, 1L, testKey001, blockingStubFull); + PublicMethod.createAssetIssue( + fromAddress, + "testNetAsset", + 1000000000000L, + 1, + 1, + start, + end, + 1, + "wwwwww", + "wwwwwwww", + 100000L, + 100000L, + 1L, + 1L, + testKey001, + blockingStubFull); } beforeToBalance = toAccount.getBalance(); beforeToAssetBalance = toAccount.getAssetMap().get("testNetAsset"); @@ -66,8 +78,8 @@ public class MainNetTransferSendOrAsset extends TronBaseTest { Account fromSendAccount = PublicMethod.queryAccount(testKey003, blockingStubFull); Account toSendAccount = PublicMethod.queryAccount(testKey004, blockingStubFull); if (fromSendAccount.getBalance() < 1000000000L) { - PublicMethod - .sendcoin(fromSendAddress, 1000000000L, defaultAddress, defaultKey, blockingStubFull); + PublicMethod.sendcoin( + fromSendAddress, 1000000000L, defaultAddress, defaultKey, blockingStubFull); } beforeToBalance = toAccount.getBalance(); logger.info("Before From account balance is " + Long.toString(fromAccount.getBalance())); @@ -75,7 +87,11 @@ public class MainNetTransferSendOrAsset extends TronBaseTest { start = System.currentTimeMillis(); } - @Test(enabled = false, threadPoolSize = 20, invocationCount = 100000, groups = {"stress"}) + @Test( + enabled = false, + threadPoolSize = 20, + invocationCount = 100000, + groups = {"stress"}) public void freezeAnd() throws InterruptedException { Random rand = new Random(); Integer randNum = 0; @@ -88,16 +104,20 @@ public void freezeAnd() throws InterruptedException { Integer i = 0; while (i < 60) { - PublicMethod - .transferAsset(toAddress, "testNetAsset".getBytes(), transferAmount, fromAddress, - testKey001, blockingStubFull); + PublicMethod.transferAsset( + toAddress, + "testNetAsset".getBytes(), + transferAmount, + fromAddress, + testKey001, + blockingStubFull); try { Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } - PublicMethod.sendcoin(toSendAddress, sendAmount, fromSendAddress, testKey003, - blockingStubFull); + PublicMethod.sendcoin( + toSendAddress, sendAmount, fromSendAddress, testKey003, blockingStubFull); try { Thread.sleep(200); } catch (InterruptedException e) { @@ -106,10 +126,7 @@ public void freezeAnd() throws InterruptedException { } } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = false) public void shutdown() throws InterruptedException { end = System.currentTimeMillis(); @@ -119,7 +136,6 @@ public void shutdown() throws InterruptedException { afterToBalance = toAccount.getBalance(); afterToAssetBalance = toAccount.getAssetMap().get("testNetAsset"); - logger.info("Success times is " + Long.toString(afterToAssetBalance - beforeToAssetBalance)); } + logger.info("Success times is " + Long.toString(afterToAssetBalance - beforeToAssetBalance)); + } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/MainNetVoteOrFreezeOrCreate.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/MainNetVoteOrFreezeOrCreate.java index af01d6e7..28153953 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/MainNetVoteOrFreezeOrCreate.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/MainNetVoteOrFreezeOrCreate.java @@ -28,26 +28,26 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class MainNetVoteOrFreezeOrCreate extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static String name = "mainNetAsset_" + Long.toString(now); - //testng001、testng002、testng003、testng004 - //Devaccount just for test + // testng001、testng002、testng003、testng004 + // Devaccount just for test private final String testKey001 = "2514B1DD2942FF07F68C2DDC0EE791BC7FBE96FDD95E89B7B9BB3B4C4770FFAC"; - //Zion just for test + // Zion just for test private final String testKey002 = "56244EE6B33C14C46704DFB67ED5D2BBCBED952EE46F1FD88A50C32C8C5C64CE"; - //Default + // Default private final String defaultKey = - //Mainet just for test - //"8DFBB4513AECF779A0803C7CEBF2CDCC51585121FAB1E086465C4E0B40724AF1"; - //Beta Env just for test + // Mainet just for test + // "8DFBB4513AECF779A0803C7CEBF2CDCC51585121FAB1E086465C4E0B40724AF1"; + // Beta Env just for test "6815B367FDDE637E53E9ADC8E69424E07724333C9A2B973CFA469975E20753FC"; private final byte[] fromAddress = PublicMethod.getFinalAddress(testKey001); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey002); @@ -68,20 +68,23 @@ public class MainNetVoteOrFreezeOrCreate extends TronBaseTest { private Long end; private Long beforeToBalance; private Long afterToBalance; + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - /** - * constructor. - */ - public static Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDuration, - String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public static Boolean freezeBalance( + byte[] addRess, + long freezeBalance, + long freezeDuration, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address = addRess; long frozenBalance = freezeBalance; long frozenDuration = freezeDuration; - ECKey temKey = null; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -89,14 +92,16 @@ public static Boolean freezeBalance(byte[] addRess, long freezeBalance, long fre ex.printStackTrace(); } final ECKey ecKey = temKey; - Protocol.Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI - .EmptyMessage.newBuilder().build()); - final Long beforeBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); - BalanceContract.FreezeBalanceContract.Builder builder = BalanceContract.FreezeBalanceContract - .newBuilder(); + Protocol.Block currentBlock = + blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); + final Long beforeBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); + BalanceContract.FreezeBalanceContract.Builder builder = + BalanceContract.FreezeBalanceContract.newBuilder(); ByteString byteAddress = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddress).setFrozenBalance(frozenBalance) + builder + .setOwnerAddress(byteAddress) + .setFrozenBalance(frozenBalance) .setFrozenDuration(frozenDuration); BalanceContract.FreezeBalanceContract contract = builder.build(); @@ -118,17 +123,18 @@ public static Boolean freezeBalance(byte[] addRess, long freezeBalance, long fre return true; } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = false) - public void beforeClass() { startTime = System.currentTimeMillis(); + public void beforeClass() { + startTime = System.currentTimeMillis(); } - //@Test(enabled = false, groups = {"stress"}) - @Test(enabled = false, threadPoolSize = 2, invocationCount = 2, groups = {"stress"}) + // @Test(enabled = false, groups = {"stress"}) + @Test( + enabled = false, + threadPoolSize = 2, + invocationCount = 2, + groups = {"stress"}) public void freezeAndSendcoin() throws InterruptedException { Random rand = new Random(); Integer randNum = 0; @@ -138,23 +144,24 @@ public void freezeAndSendcoin() throws InterruptedException { } catch (InterruptedException e) { e.printStackTrace(); } - GrpcAPI.WitnessList witnesslist = blockingStubFull - .listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build()); + GrpcAPI.WitnessList witnesslist = + blockingStubFull.listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build()); Optional result = Optional.ofNullable(witnesslist); Integer i = 0; while (i++ < 3) { ret = false; Integer waitTime = 10; - ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] accountAddress = ecKey1.getAddress(); - String testKeyAccount = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] accountAddress = ecKey1.getAddress(); + String testKeyAccount = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); logger.info(Base58.encode58Check(accountAddress)); logger.info(testKeyAccount); Integer tryTimes = 0; while (!ret) { - ret = PublicMethod - .createAccount(defaultAddress, accountAddress, defaultKey, blockingStubFull); + ret = + PublicMethod.createAccount( + defaultAddress, accountAddress, defaultKey, blockingStubFull); logger.info("createAccount"); if (tryTimes++ == 10) { @@ -164,8 +171,9 @@ public void freezeAndSendcoin() throws InterruptedException { ret = false; while (!ret) { - ret = PublicMethod - .sendcoin(accountAddress, sendAmount, defaultAddress, defaultKey, blockingStubFull); + ret = + PublicMethod.sendcoin( + accountAddress, sendAmount, defaultAddress, defaultKey, blockingStubFull); logger.info("sendcoin"); } ret = false; @@ -174,15 +182,29 @@ public void freezeAndSendcoin() throws InterruptedException { totalSupply = System.currentTimeMillis(); start = System.currentTimeMillis() + 2000; end = System.currentTimeMillis() + 1000000000; - ret = PublicMethod.createAssetIssue(accountAddress, name, totalSupply, 1, 1, start, end, - 1, description, url, 3000L, 3000L, 1L, 1L, - testKeyAccount, blockingStubFull); + ret = + PublicMethod.createAssetIssue( + accountAddress, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 3000L, + 3000L, + 1L, + 1L, + testKeyAccount, + blockingStubFull); logger.info("createAssetIssue"); } ret = false; while (!ret) { - ret = freezeBalance(accountAddress, 1000000L, 3, testKeyAccount, - blockingStubFull); + ret = freezeBalance(accountAddress, 1000000L, 3, testKeyAccount, blockingStubFull); logger.info("freezeBalance"); } /* ret = false; @@ -194,8 +216,8 @@ public void freezeAndSendcoin() throws InterruptedException { }*/ ret = false; while (!ret) { - String voteStr = Base58 - .encode58Check(result.get().getWitnesses(i % 5).getAddress().toByteArray()); + String voteStr = + Base58.encode58Check(result.get().getWitnesses(i % 5).getAddress().toByteArray()); HashMap smallVoteMap = new HashMap(); smallVoteMap.put(voteStr, "1"); ret = voteWitness(smallVoteMap, accountAddress, testKeyAccount); @@ -204,20 +226,16 @@ public void freezeAndSendcoin() throws InterruptedException { } } - /** - * constructor. - */ - + /** constructor. */ @AfterClass(enabled = false) public void shutdown() throws InterruptedException { endTime = System.currentTimeMillis(); logger.info("Time is " + Long.toString(endTime - startTime)); Account fromAccount = PublicMethod.queryAccount(testKey001, blockingStubFull); - Account toAccount = PublicMethod.queryAccount(testKey002, blockingStubFull); } + Account toAccount = PublicMethod.queryAccount(testKey002, blockingStubFull); + } - /** - * constructor. - */ + /** constructor. */ public Boolean voteWitness(HashMap witness, byte[] addRess, String priKey) { ECKey temKey = null; @@ -229,21 +247,20 @@ public Boolean voteWitness(HashMap witness, byte[] addRess, Stri } ECKey ecKey = temKey; Account beforeVote = queryAccount(ecKey, blockingStubFull); - Long beforeVoteNum = 0L; + Long beforeVoteNum = 0L; if (beforeVote.getVotesCount() != 0) { beforeVoteNum = beforeVote.getVotes(0).getVoteCount(); } - WitnessContract.VoteWitnessContract.Builder builder = WitnessContract.VoteWitnessContract - .newBuilder(); + WitnessContract.VoteWitnessContract.Builder builder = + WitnessContract.VoteWitnessContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(addRess)); for (String addressBase58 : witness.keySet()) { String value = witness.get(addressBase58); - final long count = Long.parseLong(value); - WitnessContract.VoteWitnessContract.Vote.Builder voteBuilder = WitnessContract - .VoteWitnessContract.Vote - .newBuilder(); - byte[] address = WalletClient.decodeFromBase58Check(addressBase58); + final long count = Long.parseLong(value); + WitnessContract.VoteWitnessContract.Vote.Builder voteBuilder = + WitnessContract.VoteWitnessContract.Vote.newBuilder(); + byte[] address = WalletClient.decodeFromBase58Check(addressBase58); logger.info("address = " + ByteArray.toHexString(address)); if (address == null) { continue; @@ -256,7 +273,7 @@ public Boolean voteWitness(HashMap witness, byte[] addRess, Stri WitnessContract.VoteWitnessContract contract = builder.build(); Transaction transaction = blockingStubFull.voteWitnessAccount(contract); if (transaction == null || transaction.getRawData().getContractCount() == 0) { - //logger.info("transaction == null,\n contract:{},\n transaction:{}" , contract.toString(), + // logger.info("transaction == null,\n contract:{},\n transaction:{}" , contract.toString(), // transaction.toString()); logger.info("transaction == null"); return false; @@ -266,7 +283,7 @@ public Boolean voteWitness(HashMap witness, byte[] addRess, Stri if (response.getResult() == false) { logger.info(ByteArray.toStr(response.getMessage().toByteArray())); - //logger.info(response.getCode().toString()); + // logger.info(response.getCode().toString()); return false; } /* try { @@ -277,19 +294,17 @@ public Boolean voteWitness(HashMap witness, byte[] addRess, Stri return true; } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -299,23 +314,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -327,4 +337,3 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } } - diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/MainnetReplayQueryTest.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/MainnetReplayQueryTest.java index 1115a056..69871dc3 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/MainnetReplayQueryTest.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/MainnetReplayQueryTest.java @@ -12,273 +12,287 @@ import java.util.HashSet; import java.util.List; import java.util.Optional; -import java.util.concurrent.atomic.AtomicLong; import lombok.extern.slf4j.Slf4j; -import org.bouncycastle.util.encoders.Hex; -import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.tron.api.GrpcAPI.BytesMessage; -import org.tron.api.GrpcAPI.DecryptNotes; -import org.tron.api.GrpcAPI.DelegatedResourceList; -import org.tron.api.GrpcAPI.DiversifierMessage; import org.tron.api.GrpcAPI.EmptyMessage; -import org.tron.api.GrpcAPI.ExpandedSpendingKeyMessage; -import org.tron.api.GrpcAPI.IncomingViewingKeyDiversifierMessage; -import org.tron.api.GrpcAPI.IncomingViewingKeyMessage; -import org.tron.api.GrpcAPI.Note; -import org.tron.api.GrpcAPI.PaymentAddressMessage; import org.tron.api.GrpcAPI.TransactionExtention; import org.tron.api.GrpcAPI.TransactionInfoList; -import org.tron.api.GrpcAPI.ViewingKeyMessage; import org.tron.api.WalletGrpc; import org.tron.protos.Protocol; -import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.Block; -import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.CommonParameter; -import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.Sha256Hash; -import stest.tron.wallet.common.client.utils.ShieldAddressInfo; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.zen.address.DiversifierT; - @Slf4j public class MainnetReplayQueryTest extends TronBaseTest { private static Long replayTimes = 10000000L; - private static String[] trc20Contract = new String[]{ - //"TNUC9Qb1rRpS5CbWLmNMxXBjyFoydXjWFR",//WTRX - //"TN3W4H6rK2ce4vX9YnFQHwKENnHjoxb3m9",//BTC - //"THb4CqiFdwNHsWsQCs4JhzwjMWys4aqCbF",//ETH - "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",//USDT - "TPYmHEhy5n8TCEfYGqW2rPxsghSfzghPDn",//USDD - "TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8",//USDC - "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7",//WIN - //"TMwFHYXLJaRUPeW6421aqXL4ZEzPRFGkGT",//USDJ - //"TUpMhErZL2fhh4sVNULAbNKLokS4GjC1F4",//TUSD - "TCFLL5dx5ZJdKnWuesXxi1VPwjLVmWZZy9",//JST - "TSSMHYeV2uE9qYH95DqyoCuNCzEL1NvU3S"//SUN - }; - - /** - * constructor. - */ + private static String[] trc20Contract = + new String[] { + // "TNUC9Qb1rRpS5CbWLmNMxXBjyFoydXjWFR",//WTRX + // "TN3W4H6rK2ce4vX9YnFQHwKENnHjoxb3m9",//BTC + // "THb4CqiFdwNHsWsQCs4JhzwjMWys4aqCbF",//ETH + "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", // USDT + "TPYmHEhy5n8TCEfYGqW2rPxsghSfzghPDn", // USDD + "TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8", // USDC + "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7", // WIN + // "TMwFHYXLJaRUPeW6421aqXL4ZEzPRFGkGT",//USDJ + // "TUpMhErZL2fhh4sVNULAbNKLokS4GjC1F4",//TUSD + "TCFLL5dx5ZJdKnWuesXxi1VPwjLVmWZZy9", // JST + "TSSMHYeV2uE9qYH95DqyoCuNCzEL1NvU3S" // SUN + }; + + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { getAccountList(); } - @Test(enabled = true, threadPoolSize = 20, invocationCount = 20, groups = {"stress"}) + @Test( + enabled = true, + threadPoolSize = 20, + invocationCount = 20, + groups = {"stress"}) public void test01MainnetReplayQueryTest() throws InterruptedException { Integer threadId = Integer.valueOf(Thread.currentThread().getName().split("-")[2]); threadId = getQueryIndex(threadId); switch (threadId) { case 0: - //GetTransactionInfoByBlockNum,getTransactionInfoByid + // GetTransactionInfoByBlockNum,getTransactionInfoByid getTransactionInfo(blockingStubFull); + // fall through case 1: - //Get account + // Get account getAccountBalance(blockingStubFull); break; case 2: - //Get trc10 balance + // Get trc10 balance getAccountTrc10Balance(blockingStubFull); break; case 3: - //GetTransactionById,getblock + // GetTransactionById,getblock getTransaction(blockingStubFull); break; case 4: - //GetAccount resource + // GetAccount resource getAccountResource(blockingStubFull); break; case 5: - //Get assetissue by id + // Get assetissue by id getAssetIssue(blockingStubFull); break; case 6: - //Get delegateResource + // Get delegateResource getDelegateResource(blockingStubFull); break; case 7: - //Get contract + // Get contract getContract(blockingStubFull); break; default: - //Trc20 balanceOf + // Trc20 balanceOf queryTrc20ContractBalanceOf(blockingStubFull); break; } - - } - HashSet set = new HashSet<>(); + public void queryTrc20ContractBalanceOf(WalletGrpc.WalletBlockingStub blockingStubFull) { - for(int index = 0; index < replayTimes;index++) { + for (int index = 0; index < replayTimes; index++) { Integer queryAccountIndex = index % accountList.size(); - String paramStr = "\"" + accountList.get(queryAccountIndex) + "\""; - for(int i = 0; i < trc20Contract.length;i++) { - TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(WalletClient.decodeFromBase58Check(trc20Contract[i]), "balanceOf(address)", - paramStr, false, 0, 0, "0", 0, - foundationAddress, foundationKey, blockingStubFull); + String paramStr = "\"" + accountList.get(queryAccountIndex) + "\""; + for (int i = 0; i < trc20Contract.length; i++) { + TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + WalletClient.decodeFromBase58Check(trc20Contract[i]), + "balanceOf(address)", + paramStr, + false, + 0, + 0, + "0", + 0, + foundationAddress, + foundationKey, + blockingStubFull); /*System.out.println(Hex.toHexString(transactionExtention - .getConstantResult(0).toByteArray()));*/ - - /* if(!"0000000000000000000000000000000000000000000000000000000000000000".equalsIgnoreCase(Hex.toHexString(transactionExtention - .getConstantResult(0).toByteArray()))) { - set.add(queryAddress); - - if(set.size() == 300) { - for(String address : set) { - writeDataToCsvFile("useAccount.csv",address); - } - System.exit(1); - } - }*/ + .getConstantResult(0).toByteArray()));*/ + + /* + * if (!"00000000000000000000000000000000000000000000000000000000000000 + * 00".equalsIgnoreCase( + * Hex.toHexString(transactionExtention + * .getConstantResult(0).toByteArray()))) { + * set.add(queryAddress); + * if (set.size() == 300) { + * for (String address : set) { + * writeDataToCsvFile("useAccount.csv", address); + * } + * System.exit(1); + * } + * } + */ } } - - } public static void getAccountBalance(WalletGrpc.WalletBlockingStub blockingStubFull) { - for(int index = 0; index < replayTimes;index++) { + for (int index = 0; index < replayTimes; index++) { Integer queryAccountIndex = index % accountList.size(); - //System.out.println(PublicMethod.queryAccount(WalletClient.decodeFromBase58Check(accountList.get(queryAccountIndex)),blockingStubFull).getBalance()); - PublicMethod.queryAccount(WalletClient.decodeFromBase58Check(accountList.get(queryAccountIndex)),blockingStubFull); + // System.out.println(PublicMethod.queryAccount( + // WalletClient.decodeFromBase58Check( + // accountList.get(queryAccountIndex)), + // blockingStubFull).getBalance()); + PublicMethod.queryAccount( + WalletClient.decodeFromBase58Check(accountList.get(queryAccountIndex)), blockingStubFull); } } public static void getAccountResource(WalletGrpc.WalletBlockingStub blockingStubFull) { - for(int index = 0; index < replayTimes;index++) { + for (int index = 0; index < replayTimes; index++) { Integer queryAccountIndex = index % accountList.size(); - PublicMethod.getAccountResource(WalletClient.decodeFromBase58Check(accountList.get(queryAccountIndex)),blockingStubFull); + PublicMethod.getAccountResource( + WalletClient.decodeFromBase58Check(accountList.get(queryAccountIndex)), blockingStubFull); } } public static void getContract(WalletGrpc.WalletBlockingStub blockingStubFull) { - for(int index = 0; index < replayTimes;index++) { + for (int index = 0; index < replayTimes; index++) { Integer queryContractIndex = index % trc20Contract.length; try { - PublicMethod.getContract(WalletClient.decodeFromBase58Check(trc20Contract[queryContractIndex]),blockingStubFull); + PublicMethod.getContract( + WalletClient.decodeFromBase58Check(trc20Contract[queryContractIndex]), + blockingStubFull); } catch (Exception e) { e.printStackTrace(); } - } } public static void getDelegateResource(WalletGrpc.WalletBlockingStub blockingStubFull) { Optional delegatedResourceIndexResult = null; try { - delegatedResourceIndexResult = PublicMethod - .getDelegatedResourceAccountIndex(WalletClient.decodeFromBase58Check("TAGoxYjDfXPRigzDakBxZHZWd89MqcdPuP"), blockingStubFull); + delegatedResourceIndexResult = + PublicMethod.getDelegatedResourceAccountIndex( + WalletClient.decodeFromBase58Check("TAGoxYjDfXPRigzDakBxZHZWd89MqcdPuP"), + blockingStubFull); } catch (Exception e) { e.printStackTrace(); } - for(int index = 0; index < replayTimes;index++) { - if(index % 40 == 0) { + for (int index = 0; index < replayTimes; index++) { + if (index % 40 == 0) { try { - delegatedResourceIndexResult = PublicMethod - .getDelegatedResourceAccountIndex(WalletClient.decodeFromBase58Check("TAGoxYjDfXPRigzDakBxZHZWd89MqcdPuP"), blockingStubFull); + delegatedResourceIndexResult = + PublicMethod.getDelegatedResourceAccountIndex( + WalletClient.decodeFromBase58Check("TAGoxYjDfXPRigzDakBxZHZWd89MqcdPuP"), + blockingStubFull); } catch (Exception e) { e.printStackTrace(); + } } - } - for(int i = 0; i < delegatedResourceIndexResult.get().getToAccountsCount();i++) { + for (int i = 0; i < delegatedResourceIndexResult.get().getToAccountsCount(); i++) { try { - PublicMethod.getDelegatedResource(WalletClient.decodeFromBase58Check("TAGoxYjDfXPRigzDakBxZHZWd89MqcdPuP"), - delegatedResourceIndexResult.get().getToAccounts(i).toByteArray(),blockingStubFull); + PublicMethod.getDelegatedResource( + WalletClient.decodeFromBase58Check("TAGoxYjDfXPRigzDakBxZHZWd89MqcdPuP"), + delegatedResourceIndexResult.get().getToAccounts(i).toByteArray(), + blockingStubFull); } catch (Exception e) { e.printStackTrace(); } - } } } - public static void getAssetIssue(WalletGrpc.WalletBlockingStub blockingStubFull) { - for(int index = 0; index < replayTimes;index++) { - for(int assetId = 1000001; assetId < 1000001 + 3000; assetId++) { - PublicMethod.getAssetIssueById(String.valueOf(assetId),blockingStubFull); + for (int index = 0; index < replayTimes; index++) { + for (int assetId = 1000001; assetId < 1000001 + 3000; assetId++) { + PublicMethod.getAssetIssueById(String.valueOf(assetId), blockingStubFull); } } - - } - public static void getTransactionInfo(WalletGrpc.WalletBlockingStub blockingStubFull) { - for(int m = 0; m < replayTimes;m++) { - Long currentBlockNum = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()).getBlockHeader().getRawData().getNumber(); - TransactionInfoList transactionInfoList = PublicMethod.getTransactionInfoByBlockNum(currentBlockNum,blockingStubFull).get(); - for(int i = 0; i < transactionInfoList.getTransactionInfoCount();i++) { - if(i > 20) { + for (int m = 0; m < replayTimes; m++) { + Long currentBlockNum = + blockingStubFull + .getNowBlock(EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); + TransactionInfoList transactionInfoList = + PublicMethod.getTransactionInfoByBlockNum(currentBlockNum, blockingStubFull).get(); + for (int i = 0; i < transactionInfoList.getTransactionInfoCount(); i++) { + if (i > 20) { break; } try { - PublicMethod.getTransactionInfoById(ByteArray.toHexString(transactionInfoList.getTransactionInfo(i).getId().toByteArray()),blockingStubFull); + PublicMethod.getTransactionInfoById( + ByteArray.toHexString( + transactionInfoList.getTransactionInfo(i).getId().toByteArray()), + blockingStubFull); } catch (Exception e) { e.printStackTrace(); } -/* System.out.println("TransactionInfo timestamp:" + PublicMethod.getTransactionInfoById(ByteArray.toHexString(transactionInfoList.getTransactionInfo(i).getId().toByteArray()),blockingStubFull) - .get().getBlockTimeStamp());*/ + /* + * System.out.println("TransactionInfo timestamp:" + * + PublicMethod.getTransactionInfoById( + * ByteArray.toHexString( + * transactionInfoList.getTransactionInfo(i) + * .getId().toByteArray()), + * blockingStubFull) + * .get().getBlockTimeStamp()); + */ } } } - public static void getTransaction(WalletGrpc.WalletBlockingStub blockingStubFull) { - for(int m = 0; m < replayTimes;m++) { + for (int m = 0; m < replayTimes; m++) { Block block = blockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()); - for(int i = 0; i < block.getTransactionsCount();i++) { - if(i > 20) { + for (int i = 0; i < block.getTransactionsCount(); i++) { + if (i > 20) { break; } - String txid = ByteArray.toHexString( - Sha256Hash.hash( - CommonParameter.getInstance().isECKeyCryptoEngine(), - block.getTransactions(i).getRawData().toByteArray())); + String txid = + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + block.getTransactions(i).getRawData().toByteArray())); try { - PublicMethod.getTransactionById(txid,blockingStubFull); + PublicMethod.getTransactionById(txid, blockingStubFull); } catch (Exception e) { e.printStackTrace(); } - //System.out.println("TransactionByid sig count: " + PublicMethod.getTransactionById(txid,blockingStubFull).get().getSignatureCount()); + // System.out.println("TransactionByid sig count: " + + // PublicMethod.getTransactionById(txid,blockingStubFull).get().getSignatureCount()); } } - - } - public static void getAccountTrc10Balance(WalletGrpc.WalletBlockingStub blockingStubFull) { - for(int index = 0; index < replayTimes;index++) { + for (int index = 0; index < replayTimes; index++) { Integer queryAccountIndex = index % accountList.size(); PublicMethod.getAssetBalanceByAssetId( - ByteString.copyFromUtf8("1002000"), WalletClient.decodeFromBase58Check(accountList.get(queryAccountIndex)), blockingStubFull); + ByteString.copyFromUtf8("1002000"), + WalletClient.decodeFromBase58Check(accountList.get(queryAccountIndex)), + blockingStubFull); } } - - public static void writeDataToCsvFile(String fileName,String writeData) { + public static void writeDataToCsvFile(String fileName, String writeData) { { try { @@ -290,33 +304,35 @@ public static void writeDataToCsvFile(String fileName,String writeData) { FileWriter fileWritter = new FileWriter(file.getName(), true); fileWritter.write(writeData + "\n"); fileWritter.close(); - //System.out.println("finish"); + // System.out.println("finish"); } catch (IOException e) { e.printStackTrace(); } } } - - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} public static int getQueryIndex(Integer threadId) { return threadId % 14; } - public static List accountList = new ArrayList<>(); + private static void getAccountList() { String line = null; try { BufferedReader bufferedReader = - new BufferedReader(new InputStreamReader(new FileInputStream(System.getProperty("user.dir") + '/' + "src/test/resources/replay_account.csv"),"utf-8")); - //int i=0; + new BufferedReader( + new InputStreamReader( + new FileInputStream( + System.getProperty("user.dir") + + '/' + + "src/test/resources/replay_account.csv"), + "utf-8")); + // int i=0; while ((line = bufferedReader.readLine()) != null) { accountList.add(line); } @@ -326,4 +342,4 @@ private static void getAccountList() { e.printStackTrace(); } } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/MarketOrderTest.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/MarketOrderTest.java index d71774b4..68646dda 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/MarketOrderTest.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/MarketOrderTest.java @@ -1,63 +1,64 @@ package stest.tron.wallet.onlinestress; + import java.util.List; -import java.util.Optional; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.protos.Protocol.MarketOrder; -import org.tron.protos.Protocol.MarketOrderList; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TronBaseTest; + public class MarketOrderTest extends TronBaseTest { // test key, do not worry String[] addressList = { - "3d16a04b7d01712667b40cb7f4c9bbe73ca111ac14a13a4f8e12a7f557d2c89c", - "978c0a1832fd091c60dff74f9bca04dca39ec118480880f2a7ed2c90b5908640", - "7f1769c7882c3e9e488251005422f6a5fb373630e84589cff4d95e8b3f8a308f", - "ce6544fcfe704f74d11dfff1a61df3cc76f2261c5b7b9e3e838f4c2a77643554", - "8dce7a3612666fc594f6aa3ff29f3eb45902fa0c1a7e3922e21cf7a1409f13cd", - "b240970dcad14b3a9883359194979d4fdc0a49cbef40bb167d3d1700871ab83e", - "24c730b524312a43e3b6fdfffb115a85f05e823aaeb375b92751e25abcd95719", - "d3ace279734e51edd8e74c906bc6f5acdd8a22f0bf5759137d9619b4679effe4", - "f9f56379ab2be66e3e340621e3cc21514acec1fc7bb72eda3681ab7dc96af809", - "31a67a8041ff89475466662b3e0bc7164519b1abacdeceac28869b2c15a2330e", - "c74fb4d8101572041c6fab30e1602ba1ec8247e1ead19641fb985b3ed3a8261e", - "25f98ac22c9fd02aa8a2ef354db0aa13ebc2a6c31377ea7e2b342f0d3898af0d", - "939a2cec3768bd2d2834126c20d2b1c513e3711f085ce374f654a7b144aa409f", - "39862f4dd51972ca22ce50b7b9e629043387000120c33bf263399ad9b334da1a", - "79045aab0f3199ac456ce2039e809e6c942983ede0e3a398d571dedddb351348", - "d50fe9c48e95289cde324ffeff095f8275f9ab07375e5e843167a0a54d3e1462", - "61651f2b8a87e1ae0ced5e700807f2abb50e97fe7d3d3e6a8aa58f0a6b0149a6", - "bb03d70e5187258ffb6cddb1becade5c1b2606b7ea84636b7dfaeef6216610a5", - "25858c236634e353d018f310f61e077b78e1410766565ed56ff11ee7410dcf20", - "ede941a01eb8234866f60c7e8e95db4614bb0d05298d82bae0abea81f1861046", - "549c7797b351e48ab1c6bb5857138b418012d97526fc2acba022357d49c93ac0" + "3d16a04b7d01712667b40cb7f4c9bbe73ca111ac14a13a4f8e12a7f557d2c89c", + "978c0a1832fd091c60dff74f9bca04dca39ec118480880f2a7ed2c90b5908640", + "7f1769c7882c3e9e488251005422f6a5fb373630e84589cff4d95e8b3f8a308f", + "ce6544fcfe704f74d11dfff1a61df3cc76f2261c5b7b9e3e838f4c2a77643554", + "8dce7a3612666fc594f6aa3ff29f3eb45902fa0c1a7e3922e21cf7a1409f13cd", + "b240970dcad14b3a9883359194979d4fdc0a49cbef40bb167d3d1700871ab83e", + "24c730b524312a43e3b6fdfffb115a85f05e823aaeb375b92751e25abcd95719", + "d3ace279734e51edd8e74c906bc6f5acdd8a22f0bf5759137d9619b4679effe4", + "f9f56379ab2be66e3e340621e3cc21514acec1fc7bb72eda3681ab7dc96af809", + "31a67a8041ff89475466662b3e0bc7164519b1abacdeceac28869b2c15a2330e", + "c74fb4d8101572041c6fab30e1602ba1ec8247e1ead19641fb985b3ed3a8261e", + "25f98ac22c9fd02aa8a2ef354db0aa13ebc2a6c31377ea7e2b342f0d3898af0d", + "939a2cec3768bd2d2834126c20d2b1c513e3711f085ce374f654a7b144aa409f", + "39862f4dd51972ca22ce50b7b9e629043387000120c33bf263399ad9b334da1a", + "79045aab0f3199ac456ce2039e809e6c942983ede0e3a398d571dedddb351348", + "d50fe9c48e95289cde324ffeff095f8275f9ab07375e5e843167a0a54d3e1462", + "61651f2b8a87e1ae0ced5e700807f2abb50e97fe7d3d3e6a8aa58f0a6b0149a6", + "bb03d70e5187258ffb6cddb1becade5c1b2606b7ea84636b7dfaeef6216610a5", + "25858c236634e353d018f310f61e077b78e1410766565ed56ff11ee7410dcf20", + "ede941a01eb8234866f60c7e8e95db4614bb0d05298d82bae0abea81f1861046", + "549c7797b351e48ab1c6bb5857138b418012d97526fc2acba022357d49c93ac0" }; - private String fullnode = "39.107.225.170:50051"; + private String fullnode = "39.107.225.170:50051"; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} + @Test(groups = {"stress"}) - public void markerOrderCancle(){ + public void markerOrderCancle() { while (true) { - for(String key : addressList){ + for (String key : addressList) { byte[] addressByteArray = PublicMethod.getFinalAddress(key); - List OrderList = PublicMethod - .getMarketOrderByAccount(addressByteArray, blockingStubFull).get().getOrdersList(); - int single_times = 0; - for(MarketOrder order : OrderList){ + List OrderList = + PublicMethod.getMarketOrderByAccount(addressByteArray, blockingStubFull) + .get() + .getOrdersList(); + int single_times = 0; + for (MarketOrder order : OrderList) { byte[] orderId = order.getOrderId().toByteArray(); - String txid = PublicMethod - .marketCancelOrder(addressByteArray, key, orderId, blockingStubFull); - if(single_times++ >= 2) { + String txid = + PublicMethod.marketCancelOrder(addressByteArray, key, orderId, blockingStubFull); + if (single_times++ >= 2) { break; } } } } } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/Md5Util.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/Md5Util.java index 8d110cdc..c663129b 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/Md5Util.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/Md5Util.java @@ -9,12 +9,11 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.Utils; -/** - * Md5 工具 - */ +/** Md5 工具 */ public class Md5Util { private static MessageDigest md5 = null; + static { try { md5 = MessageDigest.getInstance("MD5"); @@ -23,12 +22,11 @@ public class Md5Util { } } - - public static String getMd5(MessageDigest md5,String str) { + public static String getMd5(MessageDigest md5, String str) { byte[] bs = md5.digest(str.getBytes()); StringBuilder sb = new StringBuilder(40); - for(byte x:bs) { - if((x & 0xff)>>4 == 0) { + for (byte x : bs) { + if ((x & 0xff) >> 4 == 0) { sb.append("0").append(Integer.toHexString(x & 0xff)); } else { sb.append(Integer.toHexString(x & 0xff)); @@ -37,7 +35,11 @@ public static String getMd5(MessageDigest md5,String str) { return sb.toString(); } - @Test(enabled = true, threadPoolSize = 20, invocationCount = 20, groups = {"stress"}) + @Test( + enabled = true, + threadPoolSize = 20, + invocationCount = 20, + groups = {"stress"}) public void createMd5Value() { MessageDigest md5 = null; try { @@ -48,19 +50,28 @@ public void createMd5Value() { Integer publicKeyCount = 100000; while (publicKeyCount-- > 0) { - long timestamp = System.currentTimeMillis()/1000; + long timestamp = System.currentTimeMillis() / 1000; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] event001Address = ecKey1.getAddress(); String address = Base58.encode58Check(event001Address); - String csvData = address + "," + timestamp + "," + getMd5(md5,address + "," + timestamp + "," + "CXFDNcFA3cc423Rc4F4FcVvcnvcvk4G5c3KSfGcF3F5FF54GV"); - writeDataToCsvFile("md5Value.csv",csvData); - + String csvData = + address + + "," + + timestamp + + "," + + getMd5( + md5, + address + + "," + + timestamp + + "," + + "CXFDNcFA3cc423Rc4F4FcVvcnvcvk4G5c3KSfGcF3F5FF54GV"); + writeDataToCsvFile("md5Value.csv", csvData); } } - - public static void writeDataToCsvFile(String fileName,String writeData) { + public static void writeDataToCsvFile(String fileName, String writeData) { { try { @@ -72,13 +83,10 @@ public static void writeDataToCsvFile(String fileName,String writeData) { FileWriter fileWritter = new FileWriter(file.getName(), true); fileWritter.write(writeData + "\n"); fileWritter.close(); - //System.out.println("finish"); + // System.out.println("finish"); } catch (IOException e) { e.printStackTrace(); } } } - - - -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/MultiSignStress.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/MultiSignStress.java index 209f184c..e6fea6c7 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/MultiSignStress.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/MultiSignStress.java @@ -9,11 +9,12 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class MultiSignStress extends TronBaseTest { ByteString assetAccountId1; +public class MultiSignStress extends TronBaseTest { + ByteString assetAccountId1; String[] permissionKeyString = new String[2]; String[] ownerKeyString = new String[1]; String accountPermissionJson = ""; @@ -30,14 +31,15 @@ public class MultiSignStress extends TronBaseTest { ByteString assetAccountId1; byte[] newAddress = ecKey4.getAddress(); String newKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, threadPoolSize = 20, invocationCount = 20, groups = {"stress"}) + @Test( + enabled = true, + threadPoolSize = 20, + invocationCount = 20, + groups = {"stress"}) public void testMultiSignForAccount() { Integer i = 0; while (i < 20) { @@ -58,55 +60,52 @@ public void testMultiSignForAccount() { newAddress = ecKey4.getAddress(); newKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); - PublicMethod.sendcoin(ownerAddress, 4000000L, foundationAddress, foundationKey, - blockingStubFull); - PublicMethod.sendcoin(ownerAddress, 4000000L, foundationAddress, foundationKey, - blockingStubFull); - PublicMethod.sendcoin(ownerAddress, 4000000L, foundationAddress, foundationKey, - blockingStubFull); + PublicMethod.sendcoin( + ownerAddress, 4000000L, foundationAddress, foundationKey, blockingStubFull); + PublicMethod.sendcoin( + ownerAddress, 4000000L, foundationAddress, foundationKey, blockingStubFull); + PublicMethod.sendcoin( + ownerAddress, 4000000L, foundationAddress, foundationKey, blockingStubFull); permissionKeyString[0] = manager1Key; permissionKeyString[1] = manager2Key; ownerKeyString[0] = ownerKey; - accountPermissionJson = "[{\"keys\":[{\"address\":\"" - + PublicMethod.getAddressString(ownerKey) - + "\",\"weight\":2}],\"name\":\"owner\",\"threshold\":2,\"parent\":\"owner\"}," - + "{\"parent\":\"owner\",\"keys\":[{\"address\":\"" - + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1},{\"address\":\"" - + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}],\"name\":\"active\"," - + "\"threshold\":2}]"; - //logger.info(accountPermissionJson); - PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerKeyString); - String updateName = Long.toString(System.currentTimeMillis()); + accountPermissionJson = + "[{\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":2}],\"name\":\"owner\",\"threshold\":2,\"parent\":\"owner\"}," + + "{\"parent\":\"owner\",\"keys\":[{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1},{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}],\"name\":\"active\"," + + "\"threshold\":2}]"; + // logger.info(accountPermissionJson); + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); + String updateName = Long.toString(System.currentTimeMillis()); - PublicMethodForMultiSign.sendcoin(newAddress, 1000000L, ownerAddress, ownerKey, - blockingStubFull, permissionKeyString); - PublicMethodForMultiSign.sendcoin(newAddress, 1000000L, ownerAddress, ownerKey, - blockingStubFull, permissionKeyString); - PublicMethodForMultiSign.sendcoin(newAddress, 1000000L, ownerAddress, ownerKey, - blockingStubFull, permissionKeyString); - PublicMethodForMultiSign.freezeBalance(ownerAddress, 1000000L, 0, - ownerKey, blockingStubFull, permissionKeyString); - PublicMethodForMultiSign.freezeBalance(ownerAddress, 1000000L, 0, - ownerKey, blockingStubFull, permissionKeyString); - PublicMethodForMultiSign.freezeBalance(ownerAddress, 1000000L, 0, - ownerKey, blockingStubFull, permissionKeyString); - PublicMethodForMultiSign.unFreezeBalance(ownerAddress, ownerKey, 0, null, - blockingStubFull, permissionKeyString); - PublicMethodForMultiSign.unFreezeBalance(ownerAddress, ownerKey, 0, null, - blockingStubFull, permissionKeyString); - PublicMethodForMultiSign.unFreezeBalance(ownerAddress, ownerKey, 0, null, - blockingStubFull, permissionKeyString); + PublicMethodForMultiSign.sendcoin( + newAddress, 1000000L, ownerAddress, ownerKey, blockingStubFull, permissionKeyString); + PublicMethodForMultiSign.sendcoin( + newAddress, 1000000L, ownerAddress, ownerKey, blockingStubFull, permissionKeyString); + PublicMethodForMultiSign.sendcoin( + newAddress, 1000000L, ownerAddress, ownerKey, blockingStubFull, permissionKeyString); + PublicMethodForMultiSign.freezeBalance( + ownerAddress, 1000000L, 0, ownerKey, blockingStubFull, permissionKeyString); + PublicMethodForMultiSign.freezeBalance( + ownerAddress, 1000000L, 0, ownerKey, blockingStubFull, permissionKeyString); + PublicMethodForMultiSign.freezeBalance( + ownerAddress, 1000000L, 0, ownerKey, blockingStubFull, permissionKeyString); + PublicMethodForMultiSign.unFreezeBalance( + ownerAddress, ownerKey, 0, null, blockingStubFull, permissionKeyString); + PublicMethodForMultiSign.unFreezeBalance( + ownerAddress, ownerKey, 0, null, blockingStubFull, permissionKeyString); + PublicMethodForMultiSign.unFreezeBalance( + ownerAddress, ownerKey, 0, null, blockingStubFull, permissionKeyString); } - - } - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/MultiValiSignPerformanceTest.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/MultiValiSignPerformanceTest.java index 072e68f8..6da79b15 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/MultiValiSignPerformanceTest.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/MultiValiSignPerformanceTest.java @@ -25,18 +25,17 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; - +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class MultiValiSignPerformanceTest extends TronBaseTest { - private final String fromKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String fromKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] fromAddress = PublicMethod.getFinalAddress(fromKey); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractDepAddress = ecKey1.getAddress(); @@ -45,52 +44,68 @@ public class MultiValiSignPerformanceTest extends TronBaseTest { byte[] nonexistentAddress = ecKey2.getAddress(); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private byte[] ecrecoverContractAddress = null; private byte[] multiValiSignContractAddress = null; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); - PublicMethod.printAddress(contractDepKey); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(contractDepKey); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } - - @Test(enabled = true, description = "deploy ecrecover contract", groups = {"stress"}) + @Test( + enabled = true, + description = "deploy ecrecover contract", + groups = {"stress"}) public void test01DeployEcrecoverContract() { - Assert.assertTrue(PublicMethod.sendcoin(contractDepAddress, 1000_000_000L, fromAddress, - fromKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(contractDepAddress, contractDepKey, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(contractDepAddress), fromKey, blockingStubFull)); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(contractDepAddress, - blockingStubFull); + Assert.assertTrue( + PublicMethod.sendcoin( + contractDepAddress, 1000_000_000L, fromAddress, fromKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + contractDepAddress, contractDepKey, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(contractDepAddress), + fromKey, + blockingStubFull)); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(contractDepAddress, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(contractDepKey, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "src/test/resources/soliditycode/multiValiSignPerformance01.sol"; - String contractName = "ecrecoverValidateSign"; + String filePath = "src/test/resources/soliditycode/multiValiSignPerformance01.sol"; + String contractName = "ecrecoverValidateSign"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, contractDepKey, - contractDepAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + contractDepKey, + contractDepAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(contractDepAddress, blockingStubFull); @@ -102,8 +117,8 @@ public void test01DeployEcrecoverContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -115,38 +130,59 @@ public void test01DeployEcrecoverContract() { ecrecoverContractAddress = infoById.get().getContractAddress().toByteArray(); logger.info("ecrecoverContractAddress:" + infoById.get().getContractAddress()); - SmartContract smartContract = PublicMethod.getContract(ecrecoverContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(ecrecoverContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "deploy multvalisign contract", groups = {"stress"}) + @Test( + enabled = true, + description = "deploy multvalisign contract", + groups = {"stress"}) public void test02DeployMultvalisignContract() { - Assert.assertTrue(PublicMethod.sendcoin(contractDepAddress, 1000_000_000L, fromAddress, - fromKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceForReceiver(fromAddress, - PublicMethod.getFreezeBalanceCount(contractDepAddress, contractDepKey, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(contractDepAddress), fromKey, blockingStubFull)); - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethod.getAccountResource(contractDepAddress, - blockingStubFull); + Assert.assertTrue( + PublicMethod.sendcoin( + contractDepAddress, 1000_000_000L, fromAddress, fromKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + PublicMethod.getFreezeBalanceCount( + contractDepAddress, contractDepKey, 170000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(contractDepAddress), + fromKey, + blockingStubFull)); + // before deploy, check account resource + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(contractDepAddress, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethod.queryAccount(contractDepKey, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "src/test/resources/soliditycode/multiValiSignPerformance02.sol"; - String contractName = "multiValidateSignContract"; + String filePath = "src/test/resources/soliditycode/multiValiSignPerformance02.sol"; + String contractName = "multiValidateSignContract"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - final String transferTokenTxid = PublicMethod - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", - maxFeeLimit, 0L, 0, 10000, - "0", 0, null, contractDepKey, - contractDepAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + final String transferTokenTxid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 0, + 10000, + "0", + 0, + null, + contractDepKey, + contractDepAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); accountResource = PublicMethod.getAccountResource(contractDepAddress, blockingStubFull); @@ -158,8 +194,8 @@ public void test02DeployMultvalisignContract() { logger.info("after energyUsage is " + Long.toString(energyUsage)); logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethod - .getTransactionInfoById(transferTokenTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(transferTokenTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); @@ -171,12 +207,15 @@ public void test02DeployMultvalisignContract() { multiValiSignContractAddress = infoById.get().getContractAddress().toByteArray(); logger.info("multiValiSignContractAddress:" + infoById.get().getContractAddress()); - SmartContract smartContract = PublicMethod.getContract(multiValiSignContractAddress, - blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(multiValiSignContractAddress, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "trigger ecrecover contract test", groups = {"stress"}) + @Test( + enabled = true, + description = "trigger ecrecover contract test", + groups = {"stress"}) public void test03triggerEcrecoverContract() { /*Assert.assertTrue(PublicMethod.sendcoin(contractDepAddress, 1000_000_000L, fromAddress, fromKey, blockingStubFull)); @@ -187,20 +226,20 @@ public void test03triggerEcrecoverContract() { }*/ List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - //test key - byte[] hash = ByteArray - .fromHexString("7d889f42b4a56ebe78264631a3b4daf21019e1170cce71929fb396761cdf532e"); + // test key + byte[] hash = + ByteArray.fromHexString("7d889f42b4a56ebe78264631a3b4daf21019e1170cce71929fb396761cdf532e"); logger.info("hash:" + Hex.toHexString(hash)); - int cnt = 15; + int cnt = 15; for (int i = 0; i < cnt; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); String[] inputArr = new String[parameters.size()]; - int i = 0; + int i = 0; for (Object parameter : parameters) { if (parameter instanceof List) { StringBuilder sb = new StringBuilder(); @@ -217,12 +256,19 @@ public void test03triggerEcrecoverContract() { } } String input = StringUtils.join(inputArr, ','); - String txid = ""; + String txid = ""; long start = System.currentTimeMillis(); - txid = PublicMethod - .triggerContract(PublicMethod.decode58Check("TDgdUs1gmn1JoeGMqQGkkxE1pcMNSo8kFj"), - "validateSign(bytes32,bytes[],address[])", input, - false, 0, maxFeeLimit, contractDepAddress, contractDepKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + PublicMethod.decode58Check("TDgdUs1gmn1JoeGMqQGkkxE1pcMNSo8kFj"), + "validateSign(bytes32,bytes[],address[])", + input, + false, + 0, + maxFeeLimit, + contractDepAddress, + contractDepKey, + blockingStubFull); long timeCosts = System.currentTimeMillis() - start; logger.info( "Ecrecover--cnt:" + cnt + ",timeCost:" + timeCosts + ",ms:" + (timeCosts * 1.0 / cnt)); @@ -233,8 +279,10 @@ public void test03triggerEcrecoverContract() { Assert.assertTrue(infoById.get().getResultValue() == 0); } - - @Test(enabled = true, description = "trigger mulivalisign contract test", groups = {"stress"}) + @Test( + enabled = true, + description = "trigger mulivalisign contract test", + groups = {"stress"}) public void test04triggerMuliValiSignContract() { /*Assert.assertTrue(PublicMethod.sendcoin(contractDepAddress, 1000_000_000L, fromAddress, fromKey, blockingStubFull)); @@ -245,20 +293,20 @@ public void test04triggerMuliValiSignContract() { }*/ List signatures = new ArrayList<>(); List addresses = new ArrayList<>(); - //just test key - byte[] hash = ByteArray - .fromHexString("7d889f42b4a56ebe78264631a3b4daf21019e1170cce71929fb396761cdf532e"); + // just test key + byte[] hash = + ByteArray.fromHexString("7d889f42b4a56ebe78264631a3b4daf21019e1170cce71929fb396761cdf532e"); logger.info("hash:" + Hex.toHexString(hash)); - int cnt = 15; + int cnt = 15; for (int i = 0; i < cnt; i++) { ECKey key = new ECKey(); - byte[] sign = key.sign(hash).toByteArray(); + byte[] sign = key.sign(hash).toByteArray(); signatures.add(Hex.toHexString(sign)); addresses.add(WalletClient.encode58Check(key.getAddress())); } List parameters = Arrays.asList("0x" + Hex.toHexString(hash), signatures, addresses); String[] inputArr = new String[parameters.size()]; - int i = 0; + int i = 0; for (Object parameter : parameters) { if (parameter instanceof List) { StringBuilder sb = new StringBuilder(); @@ -275,12 +323,19 @@ public void test04triggerMuliValiSignContract() { } } String input = StringUtils.join(inputArr, ','); - String txid = ""; + String txid = ""; long start = System.currentTimeMillis(); - txid = PublicMethod - .triggerContract(PublicMethod.decode58Check("TVpTLZbBbP82aufo7p3qmb4ELiowH3mjQW"), - "testArray(bytes32,bytes[],address[])", input, false, - 0, maxFeeLimit, contractDepAddress, contractDepKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + PublicMethod.decode58Check("TVpTLZbBbP82aufo7p3qmb4ELiowH3mjQW"), + "testArray(bytes32,bytes[],address[])", + input, + false, + 0, + maxFeeLimit, + contractDepAddress, + contractDepKey, + blockingStubFull); long timeCosts = System.currentTimeMillis() - start; logger.info( "MuliValiSign--cnt:" + cnt + ",timeCost:" + timeCosts + ",ms:" + (timeCosts * 1.0 / cnt)); @@ -291,14 +346,11 @@ public void test04triggerMuliValiSignContract() { Assert.assertTrue(infoById.get().getResultValue() == 0); } - /** - * constructor. - */ + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { if (channelFull1 != null) { + public void shutdown() throws InterruptedException { + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - - } diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/NewFeatureForSolc0811.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/NewFeatureForSolc0811.java index 41d3187a..e0853bc2 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/NewFeatureForSolc0811.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/NewFeatureForSolc0811.java @@ -12,127 +12,204 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class NewFeatureForSolc0811 extends TronBaseTest { - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testNetAccountKey = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); byte[] mapKeyContract = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(contractExcKey); Assert.assertTrue(PublicMethod - .sendcoin(contractExcAddress, 300100_000_000L, - testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethod.printAddress(contractExcKey); + Assert.assertTrue( + PublicMethod.sendcoin( + contractExcAddress, + 300100_000_000L, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/NewFeature0811-test.sol"; - String contractName = "C"; + String filePath = "src/test/resources/soliditycode/NewFeature0811-test.sol"; + String contractName = "C"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - mapKeyContract = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + mapKeyContract = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + contractExcKey, + contractExcAddress, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - SmartContractOuterClass.SmartContract smartContract = PublicMethod.getContract(mapKeyContract, - blockingStubFull); + SmartContractOuterClass.SmartContract smartContract = + PublicMethod.getContract(mapKeyContract, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "Get enum.min or enum.max", groups = {"stress"}) + @Test( + enabled = true, + description = "Get enum.min or enum.max", + groups = {"stress"}) public void test001GetEnumMinOrMax() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "getEnumMin()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "getEnumMin()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(0, result); - - transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "getEnumMax()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "getEnumMax()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(3, result); - } - - @Test(enabled = true,description = "User defined type of data", groups = {"stress"}) + @Test( + enabled = true, + description = "User defined type of data", + groups = {"stress"}) public void test002SupportUserDefinedTypeOfData() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "getUserDefinedValue()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "getUserDefinedValue()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); + int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); Assert.assertEquals(45, result); } - - @Test(enabled = true,description = "Get assembly address", groups = {"stress"}) + @Test( + enabled = true, + description = "Get assembly address", + groups = {"stress"}) public void test003GetAssemblyAddress() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "testGetAddress()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "testGetAddress()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertTrue(ByteArray.toHexString(transactionExtention.getConstantResult(0) - .toByteArray()).contains(ByteArray.toHexString(mapKeyContract).substring(2))); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertTrue( + ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray()) + .contains(ByteArray.toHexString(mapKeyContract).substring(2))); } - - @Test(enabled = true,description = "Get assembly selector", groups = {"stress"}) + @Test( + enabled = true, + description = "Get assembly selector", + groups = {"stress"}) public void test004GetAssemblySelector() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "testGetSelector()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "testGetSelector()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); long result = ByteArray.toLong(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(3781905051L, result); } - - @Test(enabled = true,description = "Get ABI-Encode calldata", groups = {"stress"}) + @Test( + enabled = true, + description = "Get ABI-Encode calldata", + groups = {"stress"}) public void test005GetAbiEncodedCalldata() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "fSignatureFromLiteralCall()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "fSignatureFromLiteralCall()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("" + Assert.assertEquals( + "" + "0000000000000000000000000000000000000000000000000000000000000020" + "0000000000000000000000000000000000000000000000000000000000000084" + "33d8581000000000000000000000000000000000000000000000000000000000" @@ -143,60 +220,84 @@ public void test005GetAbiEncodedCalldata() { ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); } - - @Test(enabled = true,description = "Support constructor read immutable value", groups = {"stress"}) + @Test( + enabled = true, + description = "Support constructor read immutable value", + groups = {"stress"}) public void test006SupportConstructorReadImmutableValue() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "readX()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "readX()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); - int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); + int result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(33, result); - - transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "readI()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "readI()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); result = ByteArray.toInt(transactionExtention.getConstantResult(0).toByteArray()); Assert.assertEquals(33, result); - - } - - @Test(enabled = true,description = "Fix immutable symbol bug", groups = {"stress"}) + @Test( + enabled = true, + description = "Fix immutable symbol bug", + groups = {"stress"}) public void test007FixImmutableSymbol() { - GrpcAPI.TransactionExtention transactionExtention = PublicMethod - .triggerConstantContractForExtention(mapKeyContract, - "fixBugTest()", "#", true, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + GrpcAPI.TransactionExtention transactionExtention = + PublicMethod.triggerConstantContractForExtention( + mapKeyContract, + "fixBugTest()", + "#", + true, + 0, + maxFeeLimit, + "0", + 0, + contractExcAddress, + contractExcKey, + blockingStubFull); Assert.assertEquals(true, transactionExtention.getResult().getResult()); - Assert.assertEquals("SUCESS", - transactionExtention.getTransaction().getRet(0).getRet().toString()); + Assert.assertEquals( + "SUCESS", transactionExtention.getTransaction().getRet(0).getRet().toString()); - Assert.assertEquals("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc", + Assert.assertEquals( + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc", ByteArray.toHexString(transactionExtention.getConstantResult(0).toByteArray())); } - - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethod.freeResource(contractExcAddress, contractExcKey, - testNetAccountAddress, blockingStubFull); } - - + PublicMethod.freeResource( + contractExcAddress, contractExcKey, testNetAccountAddress, blockingStubFull); + } } - diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/ScanBlockTools.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/ScanBlockTools.java index 38c055ce..10bbc3d7 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/ScanBlockTools.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/ScanBlockTools.java @@ -50,7 +50,6 @@ import org.tron.protos.contract.SmartContractOuterClass.CreateSmartContract; import org.tron.protos.contract.SmartContractOuterClass.TriggerSmartContract; import org.tron.protos.contract.WitnessContract.VoteWitnessContract; -import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.HttpMethod; @@ -72,19 +71,15 @@ public class ScanBlockTools extends TronBaseTest { Long currentBlockNum; private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode = "39.106.110.245:50051"; - private String fullnode1 = "39.106.110.245:50051"; - - /** - * constructor. - */ + private String fullnode = "39.106.110.245:50051"; + private String fullnode1 = "39.106.110.245:50051"; + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(witnessKey5); - PublicMethod.printAddress(witnessKey4); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(witnessKey4); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); currentBlock = blockingStubFull1.getNowBlock(EmptyMessage.newBuilder().build()); beforeBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); @@ -92,89 +87,100 @@ public void beforeClass() { } public static List listForTxid = new ArrayList<>(); - public static HashMap map = new HashMap<>(); - public static HashMap witnessMap = new HashMap<>(); - - @Test(enabled = true,threadPoolSize = 1, invocationCount = 1, groups = {"stress"}) + public static HashMap map = new HashMap<>(); + public static HashMap witnessMap = new HashMap<>(); + + @Test( + enabled = true, + threadPoolSize = 1, + invocationCount = 1, + groups = {"stress"}) public void test01ScanTransaction() { getTxidList(); witnessMap.clear(); map.clear(); - witnessMap.put(5,"41F08012B4881C320EB40B80F1228731898824E09D"); - witnessMap.put(10,"41DF309FEF25B311E7895562BD9E11AAB2A58816D2"); - witnessMap.put(15,"41BB7322198D273E39B940A5A4C955CB7199A0CDEE"); - witnessMap.put(20,"412080D8A0364E82150DD5235CE7A61A7B40F3F9EF"); - witnessMap.put(25,"4173FC381D3E2AFEFCCED94A57D49520291C38AFBB"); - witnessMap.put(30,"41AF6146B0AD9EE8BBEE811D5858F3252666DFC90C"); - witnessMap.put(35,"41AF6A9D9C0636BD9DF74F687B90C6F44C471A6AB3"); - witnessMap.put(40,"41AF730429E4AB7BF7B53FB15ACB1D45EF5B22F463"); - witnessMap.put(45,"41AF4AEA1C4CBCFA681D98C354C142938381C99389"); - witnessMap.put(50,"41AF53DC31D9DE64DFF59A847125EFCA89D97BC86D"); - witnessMap.put(55,"41AF49468FA1BA966244D76F7D0139FC2CA751FAA5"); - witnessMap.put(60,"41AF5360256F958D2A922D160C429F13D432EFC22F"); - witnessMap.put(65,"41AF5EF33FD79FECB0419A5688035D7BCD3AEFE236"); - witnessMap.put(70,"41AF68F90ED62BA9F6F7A7EABA384E417551CF83E5"); - witnessMap.put(75,"41AF619F8CE75A9E95A19E851BEBE63E89FCB1826E"); - witnessMap.put(80,"41AF71E98F91515D7E5D5379837B9EEFD1AB4650D2"); - witnessMap.put(85,"41AF498B43EE098B26926798CFEAE1AB1154EF4430"); - witnessMap.put(90,"41AF536672333170CB0FBFA78819CD90A05537D872"); - witnessMap.put(95,"41AF5FAC2D62DD1F5C9892BA9D6593337ABBEAAACB"); - witnessMap.put(100,"41AF6981D4562E7B0A6C9E8F8C22D4CCCD03D2F39A"); - witnessMap.put(105,"41AF72A34243836238A533B7E77F3B2B29FD056B14"); - witnessMap.put(110,"41AF49C25D14AED36186B7C89AF405EF37A01EF23D"); - witnessMap.put(115,"41AF53BA37D394575CAD99A2A2C5BE56DEA0227C87"); - witnessMap.put(120,"41AF6A761C941AE2CDC75890D9900AC4B89B7EFCDD"); - witnessMap.put(125,"41AF72B56845F0C4D37388B6E6DC3601A0538ABA71"); - witnessMap.put(130,"41AF4ACF25C1E192285C9BA98522CB3CF20FFBE392"); - witnessMap.put(100000,"416C0214C9995C6F3A61AB23F0EB84B0CDE7FD9C7C"); + witnessMap.put(5, "41F08012B4881C320EB40B80F1228731898824E09D"); + witnessMap.put(10, "41DF309FEF25B311E7895562BD9E11AAB2A58816D2"); + witnessMap.put(15, "41BB7322198D273E39B940A5A4C955CB7199A0CDEE"); + witnessMap.put(20, "412080D8A0364E82150DD5235CE7A61A7B40F3F9EF"); + witnessMap.put(25, "4173FC381D3E2AFEFCCED94A57D49520291C38AFBB"); + witnessMap.put(30, "41AF6146B0AD9EE8BBEE811D5858F3252666DFC90C"); + witnessMap.put(35, "41AF6A9D9C0636BD9DF74F687B90C6F44C471A6AB3"); + witnessMap.put(40, "41AF730429E4AB7BF7B53FB15ACB1D45EF5B22F463"); + witnessMap.put(45, "41AF4AEA1C4CBCFA681D98C354C142938381C99389"); + witnessMap.put(50, "41AF53DC31D9DE64DFF59A847125EFCA89D97BC86D"); + witnessMap.put(55, "41AF49468FA1BA966244D76F7D0139FC2CA751FAA5"); + witnessMap.put(60, "41AF5360256F958D2A922D160C429F13D432EFC22F"); + witnessMap.put(65, "41AF5EF33FD79FECB0419A5688035D7BCD3AEFE236"); + witnessMap.put(70, "41AF68F90ED62BA9F6F7A7EABA384E417551CF83E5"); + witnessMap.put(75, "41AF619F8CE75A9E95A19E851BEBE63E89FCB1826E"); + witnessMap.put(80, "41AF71E98F91515D7E5D5379837B9EEFD1AB4650D2"); + witnessMap.put(85, "41AF498B43EE098B26926798CFEAE1AB1154EF4430"); + witnessMap.put(90, "41AF536672333170CB0FBFA78819CD90A05537D872"); + witnessMap.put(95, "41AF5FAC2D62DD1F5C9892BA9D6593337ABBEAAACB"); + witnessMap.put(100, "41AF6981D4562E7B0A6C9E8F8C22D4CCCD03D2F39A"); + witnessMap.put(105, "41AF72A34243836238A533B7E77F3B2B29FD056B14"); + witnessMap.put(110, "41AF49C25D14AED36186B7C89AF405EF37A01EF23D"); + witnessMap.put(115, "41AF53BA37D394575CAD99A2A2C5BE56DEA0227C87"); + witnessMap.put(120, "41AF6A761C941AE2CDC75890D9900AC4B89B7EFCDD"); + witnessMap.put(125, "41AF72B56845F0C4D37388B6E6DC3601A0538ABA71"); + witnessMap.put(130, "41AF4ACF25C1E192285C9BA98522CB3CF20FFBE392"); + witnessMap.put(100000, "416C0214C9995C6F3A61AB23F0EB84B0CDE7FD9C7C"); for (String txid : listForTxid) { - long blockNum = PublicMethod.getTransactionInfoById(txid,blockingStubFull) - .get().getBlockNumber(); - String witnessAddress = ByteArray.toHexString(PublicMethod - .getBlock(blockNum,blockingStubFull).getBlockHeader().getRawData() - .getWitnessAddress().toByteArray()); - - map.put(witnessAddress.toLowerCase(), map.getOrDefault(witnessAddress,0) + 1); + long blockNum = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get().getBlockNumber(); + String witnessAddress = + ByteArray.toHexString( + PublicMethod.getBlock(blockNum, blockingStubFull) + .getBlockHeader() + .getRawData() + .getWitnessAddress() + .toByteArray()); + + map.put(witnessAddress.toLowerCase(), map.getOrDefault(witnessAddress, 0) + 1); logger.info("end"); } - } - @Test(enabled = true,threadPoolSize = 1, invocationCount = 1, groups = {"stress"}) + @Test( + enabled = true, + threadPoolSize = 1, + invocationCount = 1, + groups = {"stress"}) public void test02ScanBlockGetTransactionAndWriteToCsv() { witnessMap.clear(); map.clear(); - witnessMap.put(5,"41F08012B4881C320EB40B80F1228731898824E09D"); - witnessMap.put(10,"41DF309FEF25B311E7895562BD9E11AAB2A58816D2"); - witnessMap.put(15,"41BB7322198D273E39B940A5A4C955CB7199A0CDEE"); - witnessMap.put(20,"412080D8A0364E82150DD5235CE7A61A7B40F3F9EF"); - witnessMap.put(25,"4173FC381D3E2AFEFCCED94A57D49520291C38AFBB"); - witnessMap.put(30,"41AF6146B0AD9EE8BBEE811D5858F3252666DFC90C"); - witnessMap.put(35,"41AF6A9D9C0636BD9DF74F687B90C6F44C471A6AB3"); - witnessMap.put(40,"41AF730429E4AB7BF7B53FB15ACB1D45EF5B22F463"); - witnessMap.put(45,"41AF4AEA1C4CBCFA681D98C354C142938381C99389"); - witnessMap.put(50,"41AF53DC31D9DE64DFF59A847125EFCA89D97BC86D"); - witnessMap.put(55,"41AF49468FA1BA966244D76F7D0139FC2CA751FAA5"); - witnessMap.put(60,"41AF5360256F958D2A922D160C429F13D432EFC22F"); - witnessMap.put(65,"41AF5EF33FD79FECB0419A5688035D7BCD3AEFE236"); - witnessMap.put(70,"41AF68F90ED62BA9F6F7A7EABA384E417551CF83E5"); - witnessMap.put(75,"41AF619F8CE75A9E95A19E851BEBE63E89FCB1826E"); - witnessMap.put(80,"41AF71E98F91515D7E5D5379837B9EEFD1AB4650D2"); - witnessMap.put(85,"41AF498B43EE098B26926798CFEAE1AB1154EF4430"); - witnessMap.put(90,"41AF536672333170CB0FBFA78819CD90A05537D872"); - witnessMap.put(95,"41AF5FAC2D62DD1F5C9892BA9D6593337ABBEAAACB"); - witnessMap.put(100,"41AF6981D4562E7B0A6C9E8F8C22D4CCCD03D2F39A"); - witnessMap.put(105,"41AF72A34243836238A533B7E77F3B2B29FD056B14"); - witnessMap.put(110,"41AF49C25D14AED36186B7C89AF405EF37A01EF23D"); - witnessMap.put(115,"41AF53BA37D394575CAD99A2A2C5BE56DEA0227C87"); - witnessMap.put(120,"41AF6A761C941AE2CDC75890D9900AC4B89B7EFCDD"); - witnessMap.put(125,"41AF72B56845F0C4D37388B6E6DC3601A0538ABA71"); - witnessMap.put(130,"41AF4ACF25C1E192285C9BA98522CB3CF20FFBE392"); - witnessMap.put(100000,"416C0214C9995C6F3A61AB23F0EB84B0CDE7FD9C7C"); - Long startNum = 30855000L; - Long endNum = 30858000L; + witnessMap.put(5, "41F08012B4881C320EB40B80F1228731898824E09D"); + witnessMap.put(10, "41DF309FEF25B311E7895562BD9E11AAB2A58816D2"); + witnessMap.put(15, "41BB7322198D273E39B940A5A4C955CB7199A0CDEE"); + witnessMap.put(20, "412080D8A0364E82150DD5235CE7A61A7B40F3F9EF"); + witnessMap.put(25, "4173FC381D3E2AFEFCCED94A57D49520291C38AFBB"); + witnessMap.put(30, "41AF6146B0AD9EE8BBEE811D5858F3252666DFC90C"); + witnessMap.put(35, "41AF6A9D9C0636BD9DF74F687B90C6F44C471A6AB3"); + witnessMap.put(40, "41AF730429E4AB7BF7B53FB15ACB1D45EF5B22F463"); + witnessMap.put(45, "41AF4AEA1C4CBCFA681D98C354C142938381C99389"); + witnessMap.put(50, "41AF53DC31D9DE64DFF59A847125EFCA89D97BC86D"); + witnessMap.put(55, "41AF49468FA1BA966244D76F7D0139FC2CA751FAA5"); + witnessMap.put(60, "41AF5360256F958D2A922D160C429F13D432EFC22F"); + witnessMap.put(65, "41AF5EF33FD79FECB0419A5688035D7BCD3AEFE236"); + witnessMap.put(70, "41AF68F90ED62BA9F6F7A7EABA384E417551CF83E5"); + witnessMap.put(75, "41AF619F8CE75A9E95A19E851BEBE63E89FCB1826E"); + witnessMap.put(80, "41AF71E98F91515D7E5D5379837B9EEFD1AB4650D2"); + witnessMap.put(85, "41AF498B43EE098B26926798CFEAE1AB1154EF4430"); + witnessMap.put(90, "41AF536672333170CB0FBFA78819CD90A05537D872"); + witnessMap.put(95, "41AF5FAC2D62DD1F5C9892BA9D6593337ABBEAAACB"); + witnessMap.put(100, "41AF6981D4562E7B0A6C9E8F8C22D4CCCD03D2F39A"); + witnessMap.put(105, "41AF72A34243836238A533B7E77F3B2B29FD056B14"); + witnessMap.put(110, "41AF49C25D14AED36186B7C89AF405EF37A01EF23D"); + witnessMap.put(115, "41AF53BA37D394575CAD99A2A2C5BE56DEA0227C87"); + witnessMap.put(120, "41AF6A761C941AE2CDC75890D9900AC4B89B7EFCDD"); + witnessMap.put(125, "41AF72B56845F0C4D37388B6E6DC3601A0538ABA71"); + witnessMap.put(130, "41AF4ACF25C1E192285C9BA98522CB3CF20FFBE392"); + witnessMap.put(100000, "416C0214C9995C6F3A61AB23F0EB84B0CDE7FD9C7C"); + Long startNum = 30855000L; + Long endNum = 30858000L; Integer totalNum = 0; Integer successNum = 0; @@ -184,20 +190,26 @@ public void test02ScanBlockGetTransactionAndWriteToCsv() { logger.info("scan block num:" + endNum); builder.setNum(endNum); Block block = blockingStubFull1.getBlockByNum(builder.build()); - List transactionList = block.getTransactionsList(); - map.put(ByteArray.toHexString(block.getBlockHeader().getRawData().getWitnessAddress() - .toByteArray()).toLowerCase(), - map.getOrDefault(ByteArray.toHexString(block.getBlockHeader().getRawData() - .getWitnessAddress().toByteArray()).toLowerCase(),0) + 1); + List transactionList = block.getTransactionsList(); + map.put( + ByteArray.toHexString( + block.getBlockHeader().getRawData().getWitnessAddress().toByteArray()) + .toLowerCase(), + map.getOrDefault( + ByteArray.toHexString( + block.getBlockHeader().getRawData().getWitnessAddress().toByteArray()) + .toLowerCase(), + 0) + + 1); Integer transactionNumInThisBlock = transactionList.size(); totalNum = totalNum + transactionNumInThisBlock; for (Transaction transaction : transactionList) { - String txid = ByteArray.toHexString(Sha256Hash.hash(true, - transaction.getRawData().toByteArray())); - //String writeData = ByteArray.toHexString(Sha256Hash.hash(true, + String txid = + ByteArray.toHexString(Sha256Hash.hash(true, transaction.getRawData().toByteArray())); + // String writeData = ByteArray.toHexString(Sha256Hash.hash(true, // transaction.getRawData().toByteArray())); - writeDataToCsvFile("txid-stressss.csv",txid); - //System.out.println("Fee:" + PublicMethod.getTransactionInfoById(txid, + writeDataToCsvFile("txid-stressss.csv", txid); + // System.out.println("Fee:" + PublicMethod.getTransactionInfoById(txid, // blockingStubFull).get().getFee()); } for (Transaction transaction : transactionList) { @@ -205,10 +217,10 @@ public void test02ScanBlockGetTransactionAndWriteToCsv() { successNum++; } else { failedNum++; - String writeData = ByteArray.toHexString(Sha256Hash.hash(true, - transaction.getRawData().toByteArray())); + String writeData = + ByteArray.toHexString(Sha256Hash.hash(true, transaction.getRawData().toByteArray())); logger.info(writeData); - writeDataToCsvFile("28164160L-28167324L.csv",writeData); + writeDataToCsvFile("28164160L-28167324L.csv", writeData); } } endNum--; @@ -217,28 +229,31 @@ public void test02ScanBlockGetTransactionAndWriteToCsv() { logger.info("successNum:" + successNum); logger.info("failedNum:" + failedNum); logger.info("totalNum:" + totalNum); - logger.info("Success rate:" + (double)failedNum / (double)totalNum); - + logger.info("Success rate:" + (double) failedNum / (double) totalNum); } public static Account account; public HashSet addressSet = new HashSet<>(); public HashSet assetIssueSet = new HashSet<>(); - @Test(enabled = true, description = "Get account from transaction and compare " - + "account info from two different node", groups = {"stress"}) + @Test( + enabled = true, + description = + "Get account from transaction and compare " + "account info from two different node", + groups = {"stress"}) public void test03CompareTwoNodeAccountStatus() throws Exception { - account = PublicMethod.queryAccount( - "7400E3D0727F8A61041A8E8BF86599FE5597CE19DE451E59AED07D60967A5E25",blockingStubFull); - //扫描到28307530块了 + account = + PublicMethod.queryAccount( + "7400E3D0727F8A61041A8E8BF86599FE5597CE19DE451E59AED07D60967A5E25", blockingStubFull); + // 扫描到28307530块了 Long startNum = 29266108L; - Long endNum = 29266208L; + Long endNum = 29266208L; NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(startNum); - int retryTimes = 0; + int retryTimes = 0; HashSet set = new HashSet<>(); while (startNum++ <= endNum) { - //Block block = blockingStubFull412.getNowBlock(EmptyMessage.newBuilder().build()); + // Block block = blockingStubFull412.getNowBlock(EmptyMessage.newBuilder().build()); builder.setNum(startNum); Block block = blockingStubFull.getBlockByNum(builder.build()); logger.info("Start to scan block :" + block.getBlockHeader().getRawData().getNumber()); @@ -247,7 +262,7 @@ public void test03CompareTwoNodeAccountStatus() throws Exception { for (Transaction transaction : transactionList) { Any any = transaction.getRawData().getContract(0).getParameter(); - Integer contractType = transaction.getRawData().getContract(0).getType().getNumber(); + Integer contractType = transaction.getRawData().getContract(0).getType().getNumber(); try { switch (contractType) { @@ -259,14 +274,18 @@ public void test03CompareTwoNodeAccountStatus() throws Exception { TransferAssetContract transferAssetContract = any.unpack(TransferAssetContract.class); doCheck(transferAssetContract.getOwnerAddress()); if (!addressSet.contains(transferAssetContract.getAssetName())) { - Assert.assertEquals(PublicMethod.getAssetIssueById(ByteArray - .toStr(transferAssetContract.getAssetName().toByteArray()), - blockingStubFull), - PublicMethod.getAssetIssueById(ByteArray.toStr(transferAssetContract - .getAssetName().toByteArray()), blockingStubFull)); + Assert.assertEquals( + PublicMethod.getAssetIssueById( + ByteArray.toStr(transferAssetContract.getAssetName().toByteArray()), + blockingStubFull), + PublicMethod.getAssetIssueById( + ByteArray.toStr(transferAssetContract.getAssetName().toByteArray()), + blockingStubFull)); addressSet.add(transferAssetContract.getAssetName()); - logger.info("check token " + ByteArray.toStr(transferAssetContract - .getAssetName().toByteArray()) + " successfully"); + logger.info( + "check token " + + ByteArray.toStr(transferAssetContract.getAssetName().toByteArray()) + + " successfully"); } break; case 31: @@ -274,8 +293,8 @@ public void test03CompareTwoNodeAccountStatus() throws Exception { doCheck(triggerSmartContract.getOwnerAddress()); break; case 13: - WithdrawBalanceContract withdrawBalanceContract - = any.unpack(WithdrawBalanceContract.class); + WithdrawBalanceContract withdrawBalanceContract = + any.unpack(WithdrawBalanceContract.class); doCheck(withdrawBalanceContract.getOwnerAddress()); break; case 11: @@ -290,8 +309,8 @@ public void test03CompareTwoNodeAccountStatus() throws Exception { VoteWitnessContract voteWitnessContract = any.unpack(VoteWitnessContract.class); doCheck(voteWitnessContract.getOwnerAddress());*/ case 12: - UnfreezeBalanceContract unfreezeBalanceContract - = any.unpack(UnfreezeBalanceContract.class); + UnfreezeBalanceContract unfreezeBalanceContract = + any.unpack(UnfreezeBalanceContract.class); doCheck(unfreezeBalanceContract.getOwnerAddress()); break; case 30: @@ -299,63 +318,66 @@ public void test03CompareTwoNodeAccountStatus() throws Exception { doCheck(createSmartContract.getOwnerAddress()); break; case 46: - AccountPermissionUpdateContract accountPermissionUpdateContract - = any.unpack(AccountPermissionUpdateContract.class); + AccountPermissionUpdateContract accountPermissionUpdateContract = + any.unpack(AccountPermissionUpdateContract.class); doCheck(accountPermissionUpdateContract.getOwnerAddress()); break; default: logger.info("Unknown type:" + contractType); continue; - } } catch (Exception e) { e.printStackTrace(); - } - } } - } - @Test(enabled = true, description = "Get all info from smart contract transaction list", groups = {"stress"}) + @Test( + enabled = true, + description = "Get all info from smart contract transaction list", + groups = {"stress"}) public void test04GetEventTransactionAllInfoList() throws Exception { HashSet contractAndTopicList = new HashSet<>(); - Long startNum = 33662515L - 9500; - Long endNum = startNum - 1000; + Long startNum = 33662515L - 9500; + Long endNum = startNum - 1000; NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(startNum); - int retryTimes = 0; + int retryTimes = 0; HashSet set = new HashSet<>(); while (startNum-- >= endNum) { logger.info("current block num:" + startNum); builder.setNum(startNum); - TransactionInfoList transactionInfoList = blockingStubFull - .getTransactionInfoByBlockNum(builder.build()); + TransactionInfoList transactionInfoList = + blockingStubFull.getTransactionInfoByBlockNum(builder.build()); for (TransactionInfo transactionInfo : transactionInfoList.getTransactionInfoList()) { if (!transactionInfo.getContractAddress().isEmpty() && transactionInfo.getLogCount() > 0) { try { String txid = ByteArray.toHexString(transactionInfo.getId().toByteArray()); - Any any = PublicMethod.getTransactionById(txid, blockingStubFull).get().getRawData() - .getContract(0).getParameter(); + Any any = + PublicMethod.getTransactionById(txid, blockingStubFull) + .get() + .getRawData() + .getContract(0) + .getParameter(); TriggerSmartContract triggerSmartContract = any.unpack(TriggerSmartContract.class); StringBuffer stringBuffer = new StringBuffer(); - stringBuffer.append(ByteArray.toHexString(triggerSmartContract - .getOwnerAddress().toByteArray())); + stringBuffer.append( + ByteArray.toHexString(triggerSmartContract.getOwnerAddress().toByteArray())); stringBuffer.append(","); - stringBuffer.append(ByteArray.toHexString(transactionInfo - .getContractAddress().toByteArray())); + stringBuffer.append( + ByteArray.toHexString(transactionInfo.getContractAddress().toByteArray())); stringBuffer.append(","); - stringBuffer.append(ByteArray.toHexString(triggerSmartContract - .getData().toByteArray())); + stringBuffer.append( + ByteArray.toHexString(triggerSmartContract.getData().toByteArray())); stringBuffer.append(","); - //stringBuffer.append(blockHash); - //stringBuffer.append(","); - //stringBuffer.append(startNum); - //stringBuffer.append(","); + // stringBuffer.append(blockHash); + // stringBuffer.append(","); + // stringBuffer.append(startNum); + // stringBuffer.append(","); stringBuffer.append(txid); contractAndTopicList.add(stringBuffer.toString()); @@ -363,34 +385,39 @@ public void test04GetEventTransactionAllInfoList() throws Exception { ; } catch (Exception e) { e.printStackTrace(); - } } - } } for (String contractAddressAndTopic : contractAndTopicList) { writeDataToCsvFile("eth_blockHash.csv", contractAddressAndTopic); } - } - @Test(enabled = true, description = "Get eth block query information", groups = {"stress"}) + @Test( + enabled = true, + description = "Get eth block query information", + groups = {"stress"}) public void test05CreateEthBlockHash() throws Exception { HashSet contractAndTopicList = new HashSet<>(); - Long startNum = 33662515L; - Long endNum = startNum - 20000; + Long startNum = 33662515L; + Long endNum = startNum - 20000; NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(startNum); - int retryTimes = 0; + int retryTimes = 0; HashSet set = new HashSet<>(); while (startNum-- >= endNum) { logger.info("current block num:" + startNum); builder.setNum(startNum); - String blockHash = ByteArray.toHexString(PublicMethod.getBlock(startNum + 1, - blockingStubFull).getBlockHeader().getRawData().getParentHash().toByteArray()); + String blockHash = + ByteArray.toHexString( + PublicMethod.getBlock(startNum + 1, blockingStubFull) + .getBlockHeader() + .getRawData() + .getParentHash() + .toByteArray()); StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(blockHash); stringBuffer.append(","); @@ -401,26 +428,30 @@ public void test05CreateEthBlockHash() throws Exception { for (String contractAddressAndTopic : contractAndTopicList) { writeDataToCsvFile("eth_blockHash.csv", contractAddressAndTopic); } - } - ConcurrentHashMap certificationCosts = new ConcurrentHashMap<>(); + ConcurrentHashMap certificationCosts = new ConcurrentHashMap<>(); Set concurrentHashSet = certificationCosts.newKeySet(); private static HashSet existAddress = new HashSet<>(); List list1 = new ArrayList<>(); private static AtomicLong blockNum = new AtomicLong(30000523L - 20000L); private static AtomicLong times = new AtomicLong(5); - @Test(enabled = true, threadPoolSize = 10, invocationCount = 10, groups = {"stress"}) + @Test( + enabled = true, + threadPoolSize = 10, + invocationCount = 10, + groups = {"stress"}) public void test06ScanMainNetMostActiveAccounts() throws Exception { - getNowAddressList(); NumberMessage.Builder builder = NumberMessage.newBuilder(); + getNowAddressList(); + NumberMessage.Builder builder = NumberMessage.newBuilder(); long blockNumCurrent = blockNum.getAndAdd(-200); - int times = 200; + int times = 200; while (times-- >= 0) { if (concurrentHashSet.size() > 1000000) { break; } - //list1.add(blockNumCurrent); + // list1.add(blockNumCurrent); builder.setNum(blockNumCurrent--); Block block = blockingStubFull.getBlockByNum(builder.build()); logger.info("Start to scan block :" + block.getBlockHeader().getRawData().getNumber()); @@ -429,7 +460,7 @@ public void test06ScanMainNetMostActiveAccounts() throws Exception { for (Transaction transaction : transactionList) { Any any = transaction.getRawData().getContract(0).getParameter(); - Integer contractType = transaction.getRawData().getContract(0).getType().getNumber(); + Integer contractType = transaction.getRawData().getContract(0).getType().getNumber(); try { switch (contractType) { @@ -449,8 +480,8 @@ public void test06ScanMainNetMostActiveAccounts() throws Exception { isExist(triggerSmartContract.getOwnerAddress()); break; case 13: - WithdrawBalanceContract withdrawBalanceContract - = any.unpack(WithdrawBalanceContract.class); + WithdrawBalanceContract withdrawBalanceContract = + any.unpack(WithdrawBalanceContract.class); isExist(withdrawBalanceContract.getOwnerAddress()); break; @@ -464,8 +495,8 @@ public void test06ScanMainNetMostActiveAccounts() throws Exception { isExist(accountCreateContract.getAccountAddress()); break; case 12: - UnfreezeBalanceContract unfreezeBalanceContract - = any.unpack(UnfreezeBalanceContract.class); + UnfreezeBalanceContract unfreezeBalanceContract = + any.unpack(UnfreezeBalanceContract.class); isExist(unfreezeBalanceContract.getOwnerAddress()); break; case 30: @@ -473,8 +504,8 @@ public void test06ScanMainNetMostActiveAccounts() throws Exception { isExist(createSmartContract.getOwnerAddress()); break; case 46: - AccountPermissionUpdateContract accountPermissionUpdateContract - = any.unpack(AccountPermissionUpdateContract.class); + AccountPermissionUpdateContract accountPermissionUpdateContract = + any.unpack(AccountPermissionUpdateContract.class); isExist(accountPermissionUpdateContract.getOwnerAddress()); break; case 4: @@ -484,49 +515,62 @@ public void test06ScanMainNetMostActiveAccounts() throws Exception { default: logger.info("Unknown type:" + contractType); continue; - } } catch (Exception e) { e.printStackTrace(); - } - } } - } - @Test(enabled = true, threadPoolSize = 1, invocationCount = 1, groups = {"stress"}) + @Test( + enabled = true, + threadPoolSize = 1, + invocationCount = 1, + groups = {"stress"}) public void test07ScanAndCalculateTotalValueOrCallValue() throws Exception { getNowAddressList(); - int total1 = 0; - int total2 = 0; - int totalTrx = 0; - for (long blockNum = 20450668L; blockNum <= 20450790L;blockNum++) { + int total1 = 0; + int total2 = 0; + int totalTrx = 0; + for (long blockNum = 20450668L; blockNum <= 20450790L; blockNum++) { System.out.println("blockNum " + blockNum); - TransactionInfoList transactionList = PublicMethod.getTransactionInfoByBlockNum(blockNum, - blockingStubFull).get(); - for (int i = 0; i < transactionList.getTransactionInfoCount();i++) { - if (ByteArray.toHexString(transactionList.getTransactionInfo(i).getContractAddress() - .toByteArray()).equalsIgnoreCase("41DF42D1936F0DC3689BB65A19F279747084E13FBD")) { - - if (ByteArray.toHexString(transactionList.getTransactionInfo(i).getLog(0) - .getTopics(0).toByteArray()).equalsIgnoreCase( - "9b217a401a5ddf7c4d474074aff9958a18d48690d77cc2151c4706aa7348b401")) { - total1 += Integer.parseInt(ByteArray.toHexString(transactionList.getTransactionInfo(i) - .getLog(0).getData().toByteArray()),16); - } else if (ByteArray.toHexString(transactionList.getTransactionInfo(i).getLog(0) - .getTopics(0).toByteArray()).equalsIgnoreCase( + TransactionInfoList transactionList = + PublicMethod.getTransactionInfoByBlockNum(blockNum, blockingStubFull).get(); + for (int i = 0; i < transactionList.getTransactionInfoCount(); i++) { + if (ByteArray.toHexString( + transactionList.getTransactionInfo(i).getContractAddress().toByteArray()) + .equalsIgnoreCase("41DF42D1936F0DC3689BB65A19F279747084E13FBD")) { + + if (ByteArray.toHexString( + transactionList.getTransactionInfo(i).getLog(0).getTopics(0).toByteArray()) + .equalsIgnoreCase( + "9b217a401a5ddf7c4d474074aff9958a18d48690d77cc2151c4706aa7348b401")) { + total1 += + Integer.parseInt( + ByteArray.toHexString( + transactionList.getTransactionInfo(i).getLog(0).getData().toByteArray()), + 16); + } else if (ByteArray.toHexString( + transactionList.getTransactionInfo(i).getLog(0).getTopics(0).toByteArray()) + .equalsIgnoreCase( "31472eae9e158460fea5622d1fcb0c5bdc65b6ffb51827f7bc9ef5788410c34c")) { - total2 += Integer.parseInt(ByteArray.toHexString(transactionList.getTransactionInfo(i) - .getLog(0).getData().toByteArray()),16); - } else if (ByteArray.toHexString(transactionList.getTransactionInfo(i).getLog(0) - .getTopics(0).toByteArray()).equalsIgnoreCase( + total2 += + Integer.parseInt( + ByteArray.toHexString( + transactionList.getTransactionInfo(i).getLog(0).getData().toByteArray()), + 16); + } else if (ByteArray.toHexString( + transactionList.getTransactionInfo(i).getLog(0).getTopics(0).toByteArray()) + .equalsIgnoreCase( "3e799b2d61372379e767ef8f04d65089179b7a6f63f9be3065806456c7309f1b")) { - totalTrx += transactionList.getTransactionInfo(i).getInternalTransactions(4) - .getCallValueInfo(0).getCallValue(); + totalTrx += + transactionList + .getTransactionInfo(i) + .getInternalTransactions(4) + .getCallValueInfo(0) + .getCallValue(); } - } } } @@ -534,117 +578,98 @@ public void test07ScanAndCalculateTotalValueOrCallValue() throws Exception { System.out.println("total1 :" + total1); System.out.println("total2 :" + total2); System.out.println("total_callValue :" + totalTrx); - } @Test(groups = {"stress"}) public void test08ScanAndCalculateWitnessProductBlockStatus() { Long startNum = 33694340L; - Long endNum = 33694388L; + Long endNum = 33694388L; Integer testgroup014 = 0; Integer testgroup015 = 0; Integer testgroup016 = 0; Integer testgroup017 = 0; Integer testgroup018 = 0; - int transfer = 0; - int trigger = 0; + int transfer = 0; + int trigger = 0; while (startNum++ <= endNum) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(startNum); Block block = blockingStubFull.getBlockByNum(builder.build()); logger.info("current block:" + startNum); - String currentAddress = ByteArray.toHexString(block.getBlockHeader().getRawData() - .getWitnessAddress().toByteArray()); + String currentAddress = + ByteArray.toHexString( + block.getBlockHeader().getRawData().getWitnessAddress().toByteArray()); List transactionList = block.getTransactionsList(); for (Transaction transaction : transactionList) { - if (transaction.getRawData().getContract(0).getType().equals(ContractType - .TriggerSmartContract)) { + if (transaction + .getRawData() + .getContract(0) + .getType() + .equals(ContractType.TriggerSmartContract)) { trigger++; } else { transfer++; } } // all keys below are for test - if (currentAddress.equals(getHexAddress( - "0528dc17428585fc4dece68b79fa7912270a1fe8e85f244372f59eb7e8925e04")) - || currentAddress - .equals(getHexAddress( - "dbc78781ad27f3751358333412d5edc85b13e5eee129a1a77f7232baadafae0e")) - || currentAddress - .equals(getHexAddress( - "a79a37a3d868e66456d76b233cb894d664b75fd91861340f3843db05ab3a8c66")) - || currentAddress - .equals(getHexAddress( - "a8107ea1c97c90cd4d84e79cd79d327def6362cc6fd498fc3d3766a6a71924f6")) - || currentAddress - .equals(getHexAddress( - "b5076206430b2ca069ae2f4dc6f20dd0d74551559878990d1df12a723c228039")) - || currentAddress - .equals(getHexAddress( - "87cc8832b1b4860c3c69994bbfcdae9b520e6ce40cbe2a90566e707a7e04fc70")) - ) { + if (currentAddress.equals( + getHexAddress("0528dc17428585fc4dece68b79fa7912270a1fe8e85f244372f59eb7e8925e04")) + || currentAddress.equals( + getHexAddress("dbc78781ad27f3751358333412d5edc85b13e5eee129a1a77f7232baadafae0e")) + || currentAddress.equals( + getHexAddress("a79a37a3d868e66456d76b233cb894d664b75fd91861340f3843db05ab3a8c66")) + || currentAddress.equals( + getHexAddress("a8107ea1c97c90cd4d84e79cd79d327def6362cc6fd498fc3d3766a6a71924f6")) + || currentAddress.equals( + getHexAddress("b5076206430b2ca069ae2f4dc6f20dd0d74551559878990d1df12a723c228039")) + || currentAddress.equals( + getHexAddress("87cc8832b1b4860c3c69994bbfcdae9b520e6ce40cbe2a90566e707a7e04fc70"))) { testgroup014++; continue; } - if (currentAddress.equals(getHexAddress( - "553c7b0dee17d3f5b334925f5a90fe99fb0b93d47073d69ec33eead8459d171e")) - || currentAddress - .equals(getHexAddress( - "541a2d585fcea7e9b1803df4eb49af0eb09f1fa2ce06aa5b8ed60ac95655d66d")) - || currentAddress - .equals(getHexAddress( - "7d5a7396d6430edb7f66aa5736ef388f2bea862c9259de8ad8c2cfe080f6f5a0")) - || currentAddress - .equals(getHexAddress( - "7c4977817417495f4ca0c35ab3d5a25e247355d68f89f593f3fea2ab62c8644f")) - || currentAddress - .equals(getHexAddress( - "4521c13f65cc9f5c1daa56923b8598d4015801ad28379675c64106f5f6afec30")) - || currentAddress - .equals(getHexAddress( - "442513e2e801bc42d14d33b8148851dae756d08eeb48881a44e1b2002b3fb700")) - ) { + if (currentAddress.equals( + getHexAddress("553c7b0dee17d3f5b334925f5a90fe99fb0b93d47073d69ec33eead8459d171e")) + || currentAddress.equals( + getHexAddress("541a2d585fcea7e9b1803df4eb49af0eb09f1fa2ce06aa5b8ed60ac95655d66d")) + || currentAddress.equals( + getHexAddress("7d5a7396d6430edb7f66aa5736ef388f2bea862c9259de8ad8c2cfe080f6f5a0")) + || currentAddress.equals( + getHexAddress("7c4977817417495f4ca0c35ab3d5a25e247355d68f89f593f3fea2ab62c8644f")) + || currentAddress.equals( + getHexAddress("4521c13f65cc9f5c1daa56923b8598d4015801ad28379675c64106f5f6afec30")) + || currentAddress.equals( + getHexAddress("442513e2e801bc42d14d33b8148851dae756d08eeb48881a44e1b2002b3fb700"))) { testgroup015++; continue; } - if (currentAddress.equals(getHexAddress( - "324a2052e491e99026442d81df4d2777292840c1b3949e20696c49096c6bacb8")) - || currentAddress - .equals(getHexAddress( - "f33101ea976d90491dcb9669be568db8bbc1ad23d90be4dede094976b67d550e")) - || currentAddress - .equals(getHexAddress( - "1bb32958909299db452d3c9bbfd15fd745160d63e4985357874ee57708435a00")) - || currentAddress - .equals(getHexAddress( - "29c91bd8b27c807d8dc2d2991aa0fbeafe7f54f4de9fac1e1684aa57242e3922")) - || currentAddress - .equals(getHexAddress( - "97317d4d68a0c5ce14e74ad04dfc7521f142f5c0f247b632c8f94c755bdbe669")) - ) { + if (currentAddress.equals( + getHexAddress("324a2052e491e99026442d81df4d2777292840c1b3949e20696c49096c6bacb8")) + || currentAddress.equals( + getHexAddress("f33101ea976d90491dcb9669be568db8bbc1ad23d90be4dede094976b67d550e")) + || currentAddress.equals( + getHexAddress("1bb32958909299db452d3c9bbfd15fd745160d63e4985357874ee57708435a00")) + || currentAddress.equals( + getHexAddress("29c91bd8b27c807d8dc2d2991aa0fbeafe7f54f4de9fac1e1684aa57242e3922")) + || currentAddress.equals( + getHexAddress("97317d4d68a0c5ce14e74ad04dfc7521f142f5c0f247b632c8f94c755bdbe669"))) { testgroup016++; continue; } - if (currentAddress.equals(getHexAddress( - "ff5d867c4434ac17d264afc6696e15365832d5e8000f75733ebb336d66df148d")) - || currentAddress - .equals(getHexAddress( - "1fe1d91bbe3ac4ac5dc9866c157ef7615ec248e3fd4f7d2b49b0428da5e046b2")) - || currentAddress - .equals(getHexAddress( - "7c37ef485e186e07952bcc8e30cd911a6cd9f2a847736c89132762fb67a42329")) - || currentAddress - .equals(getHexAddress( - "bcc142d57d872cd2cc1235bca454f2efd5a87f612856c979cc5b45a7399272a8")) - || currentAddress - .equals(getHexAddress( - "6054824dc03546f903a06da1f405e72409379b83395d0bbb3d4563f56e828d52")) - ) { + if (currentAddress.equals( + getHexAddress("ff5d867c4434ac17d264afc6696e15365832d5e8000f75733ebb336d66df148d")) + || currentAddress.equals( + getHexAddress("1fe1d91bbe3ac4ac5dc9866c157ef7615ec248e3fd4f7d2b49b0428da5e046b2")) + || currentAddress.equals( + getHexAddress("7c37ef485e186e07952bcc8e30cd911a6cd9f2a847736c89132762fb67a42329")) + || currentAddress.equals( + getHexAddress("bcc142d57d872cd2cc1235bca454f2efd5a87f612856c979cc5b45a7399272a8")) + || currentAddress.equals( + getHexAddress("6054824dc03546f903a06da1f405e72409379b83395d0bbb3d4563f56e828d52"))) { testgroup017++; continue; } @@ -652,11 +677,18 @@ public void test08ScanAndCalculateWitnessProductBlockStatus() { testgroup018++; } - logger.info(testgroup014 + " " + testgroup015 + " " - + testgroup016 + " " + testgroup017 + " " + testgroup018); + logger.info( + testgroup014 + + " " + + testgroup015 + + " " + + testgroup016 + + " " + + testgroup017 + + " " + + testgroup018); logger.info(transfer + " " + trigger); - } @Test(groups = {"stress"}) @@ -666,14 +698,12 @@ public void test09GetEthFilterData() { Integer startBlockNumber = 35129811 - 2000; Integer endBlockNumber = startBlockNumber - 3000; - for (int blockNumber = startBlockNumber; blockNumber >= endBlockNumber;blockNumber-- - ) { + for (int blockNumber = startBlockNumber; blockNumber >= endBlockNumber; blockNumber--) { set.clear(); - HttpResponse response = HttpMethod - .getTransactionInfoByBlocknum("1.1.1.1:90", blockNumber); + HttpResponse response = HttpMethod.getTransactionInfoByBlocknum("1.1.1.1:90", blockNumber); List content = HttpMethod.parseResponseContentArray(response); - String blockNumberHex = "0x" + Integer.toHexString(blockNumber); + String blockNumberHex = "0x" + Integer.toHexString(blockNumber); System.out.println(content.size()); for (JSONObject info : content) { @@ -681,32 +711,29 @@ public void test09GetEthFilterData() { continue; } JSONArray logArray = info.getJSONArray("log"); - for (int i = 0; i < logArray.size();i++) { + for (int i = 0; i < logArray.size(); i++) { JSONObject log = logArray.getJSONObject(i); - String address = "0x" + log.getString("address"); - String topic = "0x" + log.getJSONArray("topics").getString(0); + String address = "0x" + log.getString("address"); + String topic = "0x" + log.getJSONArray("topics").getString(0); set.add(address + "," + topic + "," + blockNumberHex); - } - } for (String data : set) { writeDataToCsvFile("ys_filter_api.csv", data); } } - } public String getHexAddress(String key) { return ByteArray.toHexString(PublicMethod.getFinalAddress(key)); } - private static HashSet getFileList(String fileName,HashSet set) { + private static HashSet getFileList(String fileName, HashSet set) { String line = null; try { BufferedReader bufferedReader = - new BufferedReader(new InputStreamReader(new FileInputStream(fileName),"utf-8")); + new BufferedReader(new InputStreamReader(new FileInputStream(fileName), "utf-8")); while ((line = bufferedReader.readLine()) != null) { set.add(line); @@ -723,10 +750,10 @@ private static HashSet getFileList(String fileName,HashSet set) private static void getNowAddressList() { String line = null; try { - //BufferedReader bufferedReader=new BufferedReader(new FileReader(filePath)); + // BufferedReader bufferedReader=new BufferedReader(new FileReader(filePath)); BufferedReader bufferedReader = - new BufferedReader(new InputStreamReader(new FileInputStream("newAddress.csv"),"utf-8")); - //int i=0; + new BufferedReader(new InputStreamReader(new FileInputStream("newAddress.csv"), "utf-8")); + // int i=0; while ((line = bufferedReader.readLine()) != null) { existAddress.add(line); } @@ -737,10 +764,8 @@ private static void getNowAddressList() { } } - /** - * constructor. - */ - public static void writeDataToCsvFile(String fileName,String writeData) { + /** constructor. */ + public static void writeDataToCsvFile(String fileName, String writeData) { { try { @@ -752,19 +777,17 @@ public static void writeDataToCsvFile(String fileName,String writeData) { FileWriter fileWritter = new FileWriter(file.getName(), true); fileWritter.write(writeData + "\n"); fileWritter.close(); - //System.out.println("finish"); + // System.out.println("finish"); } catch (IOException e) { e.printStackTrace(); } } } - /** - * constructor. - */ + /** constructor. */ public void doCheck(ByteString address) throws Exception { if (addressSet.contains(address)) { - //logger.info("skip :" + ByteArray.toHexString(address.toByteArray())); + // logger.info("skip :" + ByteArray.toHexString(address.toByteArray())); return; } else { addressSet.add(address); @@ -774,19 +797,18 @@ public void doCheck(ByteString address) throws Exception { compareNet(address); compareAccountResource(address); return; - } - /** - * constructor. - */ + /** constructor. */ public void compareTwoAddress(ByteString address) { Assert.assertEquals( - PublicMethod.queryAccount(address.toByteArray(),blockingStubFull).toBuilder() + PublicMethod.queryAccount(address.toByteArray(), blockingStubFull) + .toBuilder() .clearFreeAssetNetUsageV2() - //.putAllFreeAssetNetUsageV2(account.getFreeAssetNetUsageV2Map()) - .setBalance(1L).setLatestOprationTime(1L) + // .putAllFreeAssetNetUsageV2(account.getFreeAssetNetUsageV2Map()) + .setBalance(1L) + .setLatestOprationTime(1L) .setAccountResource(AccountResource.newBuilder()) .setFreeNetUsage(1L) .setNetUsage(1L) @@ -795,12 +817,14 @@ public void compareTwoAddress(ByteString address) { .setLatestConsumeTime(1L) .setAllowance(1L) .clearAccountResource() - //.clearOldVotePower() + // .clearOldVotePower() .build(), - PublicMethod.queryAccount(address.toByteArray(),blockingStubFull).toBuilder() + PublicMethod.queryAccount(address.toByteArray(), blockingStubFull) + .toBuilder() .clearFreeAssetNetUsageV2() - //.putAllFreeAssetNetUsageV2(account.getFreeAssetNetUsageV2Map()) - .setBalance(1L).setLatestOprationTime(1L) + // .putAllFreeAssetNetUsageV2(account.getFreeAssetNetUsageV2Map()) + .setBalance(1L) + .setLatestOprationTime(1L) .setAccountResource(AccountResource.newBuilder()) .setFreeNetUsage(1L) .setNetUsage(1L) @@ -809,37 +833,32 @@ public void compareTwoAddress(ByteString address) { .clearAssetV2() .setAllowance(1L) .clearAccountResource() - .build() - ); - + .build()); } - /** - * constructor. - */ + /** constructor. */ public void compareNet(ByteString address) { Assert.assertEquals( - PublicMethod.getAccountNet(address.toByteArray(),blockingStubFull) - .toBuilder().setTotalNetWeight(1L) + PublicMethod.getAccountNet(address.toByteArray(), blockingStubFull) + .toBuilder() + .setTotalNetWeight(1L) .setNetUsed(1L) .setFreeNetUsed(1) .setNetLimit(1) .build(), - PublicMethod.getAccountNet(address.toByteArray(),blockingStubFull) - .toBuilder().setTotalNetWeight(1L) + PublicMethod.getAccountNet(address.toByteArray(), blockingStubFull) + .toBuilder() + .setTotalNetWeight(1L) .setNetUsed(1L) .setFreeNetUsed(1) .setNetLimit(1) - .build() - ); + .build()); } - /** - * constructor. - */ + /** constructor. */ public void compareAccountResource(ByteString address) throws Exception { Assert.assertEquals( - PublicMethod.getAccountResource(address.toByteArray(),blockingStubFull) + PublicMethod.getAccountResource(address.toByteArray(), blockingStubFull) .toBuilder() .setFreeNetUsed(1L) .setEnergyUsed(1L) @@ -849,7 +868,7 @@ public void compareAccountResource(ByteString address) throws Exception { .setNetLimit(1L) .setEnergyLimit(1L) .build(), - PublicMethod.getAccountResource(address.toByteArray(),blockingStubFull) + PublicMethod.getAccountResource(address.toByteArray(), blockingStubFull) .toBuilder() .setFreeNetUsed(1L) .setEnergyUsed(1L) @@ -858,16 +877,12 @@ public void compareAccountResource(ByteString address) throws Exception { .setTotalEnergyWeight(1L) .setTotalNetWeight(1L) .setEnergyLimit(1L) - .build() - ); - + .build()); } - /** - * constructor. - */ + /** constructor. */ public boolean isEqual(ByteString address) { - return PublicMethod.getAccountResource(address.toByteArray(),blockingStubFull) + return PublicMethod.getAccountResource(address.toByteArray(), blockingStubFull) .toBuilder() .setFreeNetUsed(1L) .setEnergyUsed(1L) @@ -876,28 +891,27 @@ public boolean isEqual(ByteString address) { .setNetUsed(1L) .setNetLimit(1L) .setEnergyLimit(1L) - .build().equals(PublicMethod.getAccountResource(address.toByteArray(),blockingStubFull) - .toBuilder() - .setFreeNetUsed(1L) - .setEnergyUsed(1L) - .setTotalEnergyWeight(1L) - .setTotalNetWeight(1L) - .setNetUsed(1L) - .setNetLimit(1L) - .setEnergyLimit(1L) - .build()); - + .build() + .equals( + PublicMethod.getAccountResource(address.toByteArray(), blockingStubFull) + .toBuilder() + .setFreeNetUsed(1L) + .setEnergyUsed(1L) + .setTotalEnergyWeight(1L) + .setTotalNetWeight(1L) + .setNetUsed(1L) + .setNetLimit(1L) + .setEnergyLimit(1L) + .build()); } - /** - * constructor. - */ + /** constructor. */ public void isExist(ByteString address1) { byte[] address = address1.toByteArray(); - byte[] hash0 = Sha256Sm3Hash.hash(address); - byte[] hash1 = Sha256Sm3Hash.hash(hash0); - byte[] checkSum = Arrays.copyOfRange(hash1, 0, 4); - byte[] addchecksum = new byte[address.length + 4]; + byte[] hash0 = Sha256Sm3Hash.hash(address); + byte[] hash1 = Sha256Sm3Hash.hash(hash0); + byte[] checkSum = Arrays.copyOfRange(hash1, 0, 4); + byte[] addchecksum = new byte[address.length + 4]; System.arraycopy(address, 0, addchecksum, 0, address.length); System.arraycopy(checkSum, 0, addchecksum, address.length, 4); if (!existAddress.contains(Base58.encode(addchecksum))) { @@ -905,18 +919,15 @@ public void isExist(ByteString address1) { } } - /** - * constructor. - */ + /** constructor. */ private static void getTxidList() { String line = null; try { - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new - FileInputStream("demo.csv"),"utf-8")); + BufferedReader bufferedReader = + new BufferedReader(new InputStreamReader(new FileInputStream("demo.csv"), "utf-8")); while ((line = bufferedReader.readLine()) != null) { listForTxid.add(line.toLowerCase()); - } } catch (FileNotFoundException e) { e.printStackTrace(); @@ -925,68 +936,67 @@ private static void getTxidList() { } } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { List list = new ArrayList<>(concurrentHashSet); for (ByteString target : list) { byte[] address = target.toByteArray(); - byte[] hash0 = Sha256Sm3Hash.hash(address); - byte[] hash1 = Sha256Sm3Hash.hash(hash0); - byte[] checkSum = Arrays.copyOfRange(hash1, 0, 4); - byte[] addchecksum = new byte[address.length + 4]; + byte[] hash0 = Sha256Sm3Hash.hash(address); + byte[] hash1 = Sha256Sm3Hash.hash(hash0); + byte[] checkSum = Arrays.copyOfRange(hash1, 0, 4); + byte[] addchecksum = new byte[address.length + 4]; System.arraycopy(address, 0, addchecksum, 0, address.length); System.arraycopy(checkSum, 0, addchecksum, address.length, 4); writeDataToCsvFile("newAddress.csv", Base58.encode(addchecksum)); } Collections.sort(list1); - int i = 1; + int i = 1; /* - afterTime = System.currentTimeMillis(); - try { - Thread.sleep(10000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - currentBlock = blockingStubFull1.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - afterBlockNum = currentBlock.getBlockHeader().getRawData().getNumber() + 2; - Long blockNum = beforeBlockNum; - Integer txsNum = 0; - Integer topNum = 0; - Integer totalNum = 0; - Long energyTotal = 0L; - String findOneTxid = ""; - - NumberMessage.Builder builder = NumberMessage.newBuilder(); - while (blockNum <= afterBlockNum) { - builder.setNum(blockNum); - txsNum = blockingStubFull1.getBlockByNum(builder.build()).getTransactionsCount(); - totalNum = totalNum + txsNum; - if (topNum < txsNum) { - topNum = txsNum; - findOneTxid = ByteArray.toHexString(Sha256Hash.hash(blockingStubFull1 - .getBlockByNum(builder.build()).getTransactionsList().get(2) - .getRawData().toByteArray())); - //logger.info("find one txid is " + findOneTxid); + afterTime = System.currentTimeMillis(); + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + e.printStackTrace(); } + currentBlock = blockingStubFull1.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); + afterBlockNum = currentBlock.getBlockHeader().getRawData().getNumber() + 2; + Long blockNum = beforeBlockNum; + Integer txsNum = 0; + Integer topNum = 0; + Integer totalNum = 0; + Long energyTotal = 0L; + String findOneTxid = ""; - blockNum++; - } - Long costTime = (afterTime - beforeTime - 31000) / 1000; - logger.info("Duration block num is " + (afterBlockNum - beforeBlockNum - 11)); - logger.info("Cost time are " + costTime); - logger.info("Top block txs num is " + topNum); - logger.info("Total transaction is " + (totalNum - 30)); - logger.info("Average Tps is " + (totalNum / costTime)); - - infoById = PublicMethod.getTransactionInfoById(findOneTxid, blockingStubFull1); - Long oneEnergyTotal = infoById.get().getReceipt().getEnergyUsageTotal(); - logger.info("EnergyTotal is " + oneEnergyTotal); - logger.info("Average energy is " + oneEnergyTotal * (totalNum / costTime)); - */ if (channelFull1 != null) { + NumberMessage.Builder builder = NumberMessage.newBuilder(); + while (blockNum <= afterBlockNum) { + builder.setNum(blockNum); + txsNum = blockingStubFull1.getBlockByNum(builder.build()).getTransactionsCount(); + totalNum = totalNum + txsNum; + if (topNum < txsNum) { + topNum = txsNum; + findOneTxid = ByteArray.toHexString(Sha256Hash.hash(blockingStubFull1 + .getBlockByNum(builder.build()).getTransactionsList().get(2) + .getRawData().toByteArray())); + //logger.info("find one txid is " + findOneTxid); + } + + blockNum++; + } + Long costTime = (afterTime - beforeTime - 31000) / 1000; + logger.info("Duration block num is " + (afterBlockNum - beforeBlockNum - 11)); + logger.info("Cost time are " + costTime); + logger.info("Top block txs num is " + topNum); + logger.info("Total transaction is " + (totalNum - 30)); + logger.info("Average Tps is " + (totalNum / costTime)); + + infoById = PublicMethod.getTransactionInfoById(findOneTxid, blockingStubFull1); + Long oneEnergyTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("EnergyTotal is " + oneEnergyTotal); + logger.info("Average energy is " + oneEnergyTotal * (totalNum / costTime)); + */ + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/ShieldTrc10Stress.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/ShieldTrc10Stress.java index fcca9635..8125f985 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/ShieldTrc10Stress.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/ShieldTrc10Stress.java @@ -15,11 +15,12 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.ShieldAddressInfo; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j -public class ShieldTrc10Stress extends TronBaseTest { List shieldOutList = new ArrayList<>(); +public class ShieldTrc10Stress extends TronBaseTest { + List shieldOutList = new ArrayList<>(); DecryptNotes notes; Note note; ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -30,52 +31,56 @@ public class ShieldTrc10Stress extends TronBaseTest { List shieldOutList String receiverPublicKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); Optional sendShieldAddressInfo; String sendshieldAddress; - private String foundationZenTokenKey = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenOwnerKey"); + private String foundationZenTokenKey = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenOwnerKey"); byte[] foundationZenTokenAddress = PublicMethod.getFinalAddress(foundationZenTokenKey); - private String zenTokenId = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenId"); + private String zenTokenId = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenId"); private byte[] tokenId = zenTokenId.getBytes(); - private Long zenTokenFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.zenTokenFee"); + private Long zenTokenFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.zenTokenFee"); private Long costTokenAmount = 20000 * zenTokenFee; - private Long zenTokenWhenCreateNewAddress = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.zenTokenWhenCreateNewAddress"); + private Long zenTokenWhenCreateNewAddress = + Configuration.getByPath("testng.conf") + .getLong("defaultParameter.zenTokenWhenCreateNewAddress"); - /** - * constructor. - */ - + /** constructor. */ - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - //Args.setFullNodeAllowShieldedTransaction(true); + // Args.setFullNodeAllowShieldedTransaction(true); PublicMethod.printAddress(foundationZenTokenKey); PublicMethod.printAddress(zenTokenOwnerKey); sendShieldAddressInfo = PublicMethod.generateShieldAddress(); sendshieldAddress = sendShieldAddressInfo.get().getAddress(); - String memo = "Use to TestZenToken004 shield address"; + String memo = "Use to TestZenToken004 shield address"; List shieldOutList = new ArrayList<>(); shieldOutList.clear(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendshieldAddress, - "" + costTokenAmount, memo); - Assert.assertTrue(PublicMethod.sendShieldCoin( - foundationZenTokenAddress, costTokenAmount + zenTokenFee, - null, null, - shieldOutList, - null, 0, - foundationZenTokenKey, blockingStubFull)); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, sendshieldAddress, "" + costTokenAmount, memo); + Assert.assertTrue( + PublicMethod.sendShieldCoin( + foundationZenTokenAddress, + costTokenAmount + zenTokenFee, + null, + null, + shieldOutList, + null, + 0, + foundationZenTokenKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - - } - @Test(enabled = true, threadPoolSize = 100, invocationCount = 100, groups = {"stress"}) + @Test( + enabled = true, + threadPoolSize = 100, + invocationCount = 100, + groups = {"stress"}) public void test1Shield2TwoShieldTransaction() { DecryptNotes notes; List shieldOutList = new ArrayList<>(); @@ -83,32 +88,43 @@ public void test1Shield2TwoShieldTransaction() { Integer times = 100; while (times-- > 0) { notes = PublicMethod.listShieldNote(sendShieldAddressInfo, blockingStubFull); - //logger.info("note size:" + notes.getNoteTxsCount()); - String memo1 = "Shield to shield address1 transaction" + System.currentTimeMillis(); + // logger.info("note size:" + notes.getNoteTxsCount()); + String memo1 = "Shield to shield address1 transaction" + System.currentTimeMillis(); shieldOutList.clear(); - Long sendToShiledAddress1Amount = + Long sendToShiledAddress1Amount = notes.getNoteTxs(notes.getNoteTxsCount() - 1).getNote().getValue() - zenTokenFee; - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendshieldAddress, - "" + sendToShiledAddress1Amount, memo1); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, sendshieldAddress, "" + sendToShiledAddress1Amount, memo1); try { PublicMethod.sendShieldCoin( - null, 0, - sendShieldAddressInfo.get(), notes.getNoteTxs(notes.getNoteTxsCount() - 1), + null, + 0, + sendShieldAddressInfo.get(), + notes.getNoteTxs(notes.getNoteTxsCount() - 1), shieldOutList, - null, 0, - zenTokenOwnerKey, blockingStubFull); + null, + 0, + zenTokenOwnerKey, + blockingStubFull); } catch (Exception e) { throw e; } } - } @AfterClass(enabled = false) public void shutdown() throws InterruptedException { - PublicMethod.transferAsset(foundationZenTokenAddress, tokenId, - PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, + PublicMethod.transferAsset( + foundationZenTokenAddress, + tokenId, + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull), zenTokenOwnerAddress, zenTokenOwnerKey, blockingStubFull); } -} \ No newline at end of file + blockingStubFull), + zenTokenOwnerAddress, + zenTokenOwnerKey, + blockingStubFull); + } +} diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/ShieldTrc20Stress.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/ShieldTrc20Stress.java index 21e80c35..5804e2d8 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/ShieldTrc20Stress.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/ShieldTrc20Stress.java @@ -21,28 +21,27 @@ import org.tron.api.WalletSolidityGrpc; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.HttpMethod; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.ShieldedAddressInfo; import stest.tron.wallet.common.client.utils.ZenTrc20Base; -import stest.tron.wallet.common.client.utils.MultiNode; @Slf4j @MultiNode public class ShieldTrc20Stress extends ZenTrc20Base { - private String fullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(0); - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String fullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0); + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); Optional sendShieldAddressInfo; private BigInteger publicFromAmount; List shieldOutList = new ArrayList<>(); - private String httpnode = Configuration.getByPath("testng.conf") - .getStringList("httpnode.ip.list").get(0); - + private String httpnode = + Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list").get(0); private AtomicInteger finishMintNumber = new AtomicInteger(0); private AtomicInteger finishCreateParameterNumber = new AtomicInteger(0); @@ -55,70 +54,80 @@ public class ShieldTrc20Stress extends ZenTrc20Base { private AtomicLong endmintNum = new AtomicLong(0); private Integer thread = 40; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext() - .build(); + channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); blockingStubFull = WalletGrpc.newBlockingStub(channelFull); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); publicFromAmount = getRandomAmount(); - //startQureyNum = HttpMethod.getNowBlockNum(httpnode); - startmintNum.addAndGet(blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber()); + // startQureyNum = HttpMethod.getNowBlockNum(httpnode); + startmintNum.addAndGet( + blockingStubFull + .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber()); } - /** - * wqs constructor. - */ - @Test(enabled = false, threadPoolSize = 50, invocationCount = 50, groups = {"stress"}) + /** wqs constructor. */ + @Test( + enabled = false, + threadPoolSize = 50, + invocationCount = 50, + groups = {"stress"}) public void test01ScanAndCreateThenTrigger() throws Exception { ManagedChannel channelFull = null; WalletGrpc.WalletBlockingStub blockingStubFull = null; - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext() - .build(); + channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); blockingStubFull = WalletGrpc.newBlockingStub(channelFull); ManagedChannel channelFull1 = null; WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); BigInteger publicFromAmount = getRandomAmount(); Optional sendShieldAddressInfo = getNewShieldedAddress(blockingStubFull); - Optional receiverShieldAddressInfo = getNewShieldedAddress( - blockingStubFull); + Optional receiverShieldAddressInfo = + getNewShieldedAddress(blockingStubFull); String memo = "Shield trc20 from T account to shield account in" + System.currentTimeMillis(); String sendShieldAddress = sendShieldAddressInfo.get().getAddress(); List shieldOutList = new ArrayList<>(); shieldOutList.clear(); - shieldOutList = addShieldTrc20OutputList(shieldOutList, sendShieldAddress, - "" + publicFromAmount, memo, blockingStubFull); - - //Create shiled trc20 parameters - GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters - = createShieldedTrc20Parameters(publicFromAmount, - null, null, shieldOutList, "", 0L, - blockingStubFull, blockingStubSolidity - ); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, sendShieldAddress, "" + publicFromAmount, memo, blockingStubFull); + + // Create shiled trc20 parameters + GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters = + createShieldedTrc20Parameters( + publicFromAmount, + null, + null, + shieldOutList, + "", + 0L, + blockingStubFull, + blockingStubSolidity); String data = encodeMintParamsToHexString(shieldedTrc20Parameters, publicFromAmount); - //Do mint transaction type - String txid = PublicMethod.triggerContract(shieldAddressByte, - mint, data, true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); + // Do mint transaction type + String txid = + PublicMethod.triggerContract( + shieldAddressByte, + mint, + data, + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); sendShieldAddress = sendShieldAddressInfo.get().getAddress(); @@ -127,18 +136,16 @@ public void test01ScanAndCreateThenTrigger() throws Exception { List inputList = new ArrayList<>(); inputShieldAddressList.add(sendShieldAddressInfo.get()); - sendNote = scanShieldedTrc20NoteByIvk(sendShieldAddressInfo.get(), - blockingStubFull1); + sendNote = scanShieldedTrc20NoteByIvk(sendShieldAddressInfo.get(), blockingStubFull1); while (sendNote.getNoteTxsCount() == 0) { - sendNote = scanShieldedTrc20NoteByIvk(sendShieldAddressInfo.get(), - blockingStubFull1); + sendNote = scanShieldedTrc20NoteByIvk(sendShieldAddressInfo.get(), blockingStubFull1); } Integer times = 20; while (times-- > 0) { - //receiverShieldAddressInfo = getNewShieldedAddress(blockingStubFull); - //Scan sender note + // receiverShieldAddressInfo = getNewShieldedAddress(blockingStubFull); + // Scan sender note /*sendNote = scanShieldedTrc20NoteByIvk(sendShieldAddressInfo.get(), blockingStubFull1); @@ -147,25 +154,37 @@ public void test01ScanAndCreateThenTrigger() throws Exception { blockingStubFull1); }*/ - sendNote = scanShieldedTrc20NoteByIvk(sendShieldAddressInfo.get(), - blockingStubFull1); + sendNote = scanShieldedTrc20NoteByIvk(sendShieldAddressInfo.get(), blockingStubFull1); String transferMemo = "Transfer type test " + System.currentTimeMillis(); shieldOutList.clear(); - shieldOutList = addShieldTrc20OutputList(shieldOutList, sendShieldAddress, - "" + publicFromAmount, transferMemo, blockingStubFull); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, + sendShieldAddress, + "" + publicFromAmount, + transferMemo, + blockingStubFull); - //logger.info("send note size:" + sendNote.getNoteTxsCount()); + // logger.info("send note size:" + sendNote.getNoteTxsCount()); - //Create transfer parameters + // Create transfer parameters try { - GrpcAPI.DecryptNotesTRC20 inputNoteFor2to2 = GrpcAPI.DecryptNotesTRC20.newBuilder() - .addNoteTxs(sendNote.getNoteTxs(sendNote.getNoteTxsCount() - 1)).build(); - shieldedTrc20Parameters - = createShieldedTrc20Parameters(BigInteger.valueOf(0), - inputNoteFor2to2, inputShieldAddressList, shieldOutList, "", 0L, - blockingStubFull1, blockingStubSolidity); + GrpcAPI.DecryptNotesTRC20 inputNoteFor2to2 = + GrpcAPI.DecryptNotesTRC20.newBuilder() + .addNoteTxs(sendNote.getNoteTxs(sendNote.getNoteTxsCount() - 1)) + .build(); + shieldedTrc20Parameters = + createShieldedTrc20Parameters( + BigInteger.valueOf(0), + inputNoteFor2to2, + inputShieldAddressList, + shieldOutList, + "", + 0L, + blockingStubFull1, + blockingStubSolidity); } catch (Exception e) { throw e; } @@ -176,38 +195,42 @@ public void test01ScanAndCreateThenTrigger() throws Exception { } data = encodeTransferParamsToHexString(shieldedTrc20Parameters); - txid = PublicMethod.triggerContract(shieldAddressByte, - transfer, data, true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); - - //sendShieldAddressInfo = receiverShieldAddressInfo; + txid = + PublicMethod.triggerContract( + shieldAddressByte, + transfer, + data, + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); + + // sendShieldAddressInfo = receiverShieldAddressInfo; } - } - - /** - * constructor. - */ - @Test(enabled = false, threadPoolSize = 40, invocationCount = 40, groups = {"stress"}) + /** constructor. */ + @Test( + enabled = false, + threadPoolSize = 40, + invocationCount = 40, + groups = {"stress"}) public void test02FirstScanCreateParameterThenCreateTrigger() throws Exception { ManagedChannel channelFull = null; WalletGrpc.WalletBlockingStub blockingStubFull = null; - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext() - .build(); + channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); blockingStubFull = WalletGrpc.newBlockingStub(channelFull); ManagedChannel channelFull1 = null; WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); Optional sendShieldAddressInfo = getNewShieldedAddress(blockingStubFull); - Optional receiverShieldAddressInfo = getNewShieldedAddress( - blockingStubFull); + Optional receiverShieldAddressInfo = + getNewShieldedAddress(blockingStubFull); Integer mintNumber = 50; @@ -219,15 +242,21 @@ public void test02FirstScanCreateParameterThenCreateTrigger() throws Exception { List shieldOutList = new ArrayList<>(); shieldOutList.clear(); - shieldOutList = addShieldTrc20OutputList(shieldOutList, sendShieldAddress, - "" + publicFromAmount, memo, blockingStubFull); - - //Create shiled trc20 parameters - GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters - = createShieldedTrc20Parameters(publicFromAmount, - null, null, shieldOutList, "", - 0L, blockingStubFull, blockingStubSolidity - ); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, sendShieldAddress, "" + publicFromAmount, memo, blockingStubFull); + + // Create shiled trc20 parameters + GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters = + createShieldedTrc20Parameters( + publicFromAmount, + null, + null, + shieldOutList, + "", + 0L, + blockingStubFull, + blockingStubSolidity); String data = ""; try { data = encodeMintParamsToHexString(shieldedTrc20Parameters, publicFromAmount); @@ -237,44 +266,58 @@ public void test02FirstScanCreateParameterThenCreateTrigger() throws Exception { } catch (Exception e1) { continue; } - } - String txid = PublicMethod.triggerContract(shieldAddressByte, - mint, data, true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + shieldAddressByte, + mint, + data, + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } - } PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); finishMintNumber.addAndGet(1); - endmintNum.getAndAdd(blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber()); + endmintNum.getAndAdd( + blockingStubFull + .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber()); while (finishMintNumber.get() != thread) { try { Thread.sleep(3000); if (finishMintNumber.get() % 10 == 0) { logger.info( - "Wait all thread finished mint,current finished thread is :" + finishMintNumber - .get()); + "Wait all thread finished mint,current finished thread is :" + + finishMintNumber.get()); } } catch (InterruptedException e) { e.printStackTrace(); } } - Long endMintNum = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + Long endMintNum = + blockingStubFull + .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); - GrpcAPI.DecryptNotesTRC20 sendNote = scanShieldedTrc20NoteByIvkWithRange( - sendShieldAddressInfo.get(), - startmintNum.get(), endMintNum, blockingStubFull1); + GrpcAPI.DecryptNotesTRC20 sendNote = + scanShieldedTrc20NoteByIvkWithRange( + sendShieldAddressInfo.get(), startmintNum.get(), endMintNum, blockingStubFull1); noteNumber.addAndGet(sendNote.getNoteTxsCount()); @@ -288,62 +331,92 @@ public void test02FirstScanCreateParameterThenCreateTrigger() throws Exception { List dataList = new ArrayList<>(); for (int i = 0; i < sendNote.getNoteTxsCount() - 1; i = i + 2) { - GrpcAPI.DecryptNotesTRC20 inputNoteFor2to2 = GrpcAPI.DecryptNotesTRC20.newBuilder() - .addNoteTxs(sendNote.getNoteTxs(i)) - .addNoteTxs(sendNote.getNoteTxs(i + 1)) - .build(); + GrpcAPI.DecryptNotesTRC20 inputNoteFor2to2 = + GrpcAPI.DecryptNotesTRC20.newBuilder() + .addNoteTxs(sendNote.getNoteTxs(i)) + .addNoteTxs(sendNote.getNoteTxs(i + 1)) + .build(); String transferMemo1 = "Transfer1 type test " + getRandomLongAmount() + getRandomLongAmount(); String transferMemo2 = "Transfer2 type test " + getRandomLongAmount() + getRandomLongAmount(); shieldOutList.clear(); - shieldOutList = addShieldTrc20OutputList(shieldOutList, - receiverShieldAddressInfo.get().getAddress(), - "" + sendNote.getNoteTxs(i).getNote().getValue(), transferMemo1, blockingStubFull); - shieldOutList = addShieldTrc20OutputList(shieldOutList, - receiverShieldAddressInfo.get().getAddress(), - "" + sendNote.getNoteTxs(i + 1).getNote().getValue(), transferMemo2, blockingStubFull); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, + receiverShieldAddressInfo.get().getAddress(), + "" + sendNote.getNoteTxs(i).getNote().getValue(), + transferMemo1, + blockingStubFull); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, + receiverShieldAddressInfo.get().getAddress(), + "" + sendNote.getNoteTxs(i + 1).getNote().getValue(), + transferMemo2, + blockingStubFull); GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters = null; if (i % 2 == 0) { try { - shieldedTrc20Parameters - = createShieldedTrc20Parameters(BigInteger.valueOf(0), - inputNoteFor2to2, inputShieldAddressList, shieldOutList, "", - 0L, blockingStubFull1, blockingStubSolidity); + shieldedTrc20Parameters = + createShieldedTrc20Parameters( + BigInteger.valueOf(0), + inputNoteFor2to2, + inputShieldAddressList, + shieldOutList, + "", + 0L, + blockingStubFull1, + blockingStubSolidity); } catch (Exception e) { try { - shieldedTrc20Parameters - = createShieldedTrc20Parameters(BigInteger.valueOf(0), - inputNoteFor2to2, inputShieldAddressList, shieldOutList, "", - 0L, blockingStubFull, blockingStubSolidity); + shieldedTrc20Parameters = + createShieldedTrc20Parameters( + BigInteger.valueOf(0), + inputNoteFor2to2, + inputShieldAddressList, + shieldOutList, + "", + 0L, + blockingStubFull, + blockingStubSolidity); } catch (Exception e1) { throw e1; } - } } else { try { - shieldedTrc20Parameters - = createShieldedTrc20Parameters(BigInteger.valueOf(0), - inputNoteFor2to2, inputShieldAddressList, shieldOutList, "", - 0L, blockingStubFull, blockingStubSolidity); + shieldedTrc20Parameters = + createShieldedTrc20Parameters( + BigInteger.valueOf(0), + inputNoteFor2to2, + inputShieldAddressList, + shieldOutList, + "", + 0L, + blockingStubFull, + blockingStubSolidity); } catch (Exception e) { try { - shieldedTrc20Parameters - = createShieldedTrc20Parameters(BigInteger.valueOf(0), - inputNoteFor2to2, inputShieldAddressList, shieldOutList, "", - 0L, blockingStubFull1, blockingStubSolidity); + shieldedTrc20Parameters = + createShieldedTrc20Parameters( + BigInteger.valueOf(0), + inputNoteFor2to2, + inputShieldAddressList, + shieldOutList, + "", + 0L, + blockingStubFull1, + blockingStubSolidity); } catch (Exception e2) { throw e2; } - - } } dataList.add(encodeTransferParamsToHexString(shieldedTrc20Parameters)); - //logger.info("dataList size:" + dataList.size()); + // logger.info("dataList size:" + dataList.size()); } @@ -353,27 +426,45 @@ public void test02FirstScanCreateParameterThenCreateTrigger() throws Exception { try { Thread.sleep(3000); if (finishCreateParameterNumber.get() % 10 == 0) { - logger.info("Wait all thread finished create parameter ,current finished thread is :" - + finishCreateParameterNumber.get()); + logger.info( + "Wait all thread finished create parameter ,current finished thread is :" + + finishCreateParameterNumber.get()); } } catch (InterruptedException e) { e.printStackTrace(); } } - startTriggerNum - .addAndGet(blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber()); + startTriggerNum.addAndGet( + blockingStubFull + .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber()); for (int i = 0; i < dataList.size(); i++) { if (i % 2 == 0) { - PublicMethod.triggerContract(shieldAddressByte, - transfer, dataList.get(i), true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); + PublicMethod.triggerContract( + shieldAddressByte, + transfer, + dataList.get(i), + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); } else { - PublicMethod.triggerContract(shieldAddressByte, - transfer, dataList.get(i), true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull1); + PublicMethod.triggerContract( + shieldAddressByte, + transfer, + dataList.get(i), + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull1); } try { Thread.sleep(3000); @@ -388,39 +479,35 @@ public void test02FirstScanCreateParameterThenCreateTrigger() throws Exception { Thread.sleep(3000); if (finishTriggerNumber.get() % 10 == 0) { logger.info( - "Wait all thread finished trigger ,current finished thread is :" + finishTriggerNumber - .get()); + "Wait all thread finished trigger ,current finished thread is :" + + finishTriggerNumber.get()); } } catch (InterruptedException e) { e.printStackTrace(); } } - - } - /** - * constructor. - */ - @Test(enabled = true, threadPoolSize = 40, invocationCount = 40, groups = {"stress"}) + /** constructor. */ + @Test( + enabled = true, + threadPoolSize = 40, + invocationCount = 40, + groups = {"stress"}) public void test03BurnStress() throws Exception { ManagedChannel channelFull = null; WalletGrpc.WalletBlockingStub blockingStubFull = null; - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext() - .build(); + channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext().build(); blockingStubFull = WalletGrpc.newBlockingStub(channelFull); ManagedChannel channelFull1 = null; WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); Optional sendShieldAddressInfo = getNewShieldedAddress(blockingStubFull); - Optional receiverShieldAddressInfo = getNewShieldedAddress( - blockingStubFull); + Optional receiverShieldAddressInfo = + getNewShieldedAddress(blockingStubFull); Integer mintNumber = 25; @@ -432,15 +519,21 @@ public void test03BurnStress() throws Exception { List shieldOutList = new ArrayList<>(); shieldOutList.clear(); - shieldOutList = addShieldTrc20OutputList(shieldOutList, sendShieldAddress, - "" + publicFromAmount, memo, blockingStubFull); - - //Create shiled trc20 parameters - GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters - = createShieldedTrc20Parameters(publicFromAmount, - null, null, shieldOutList, "", - 0L, blockingStubFull, blockingStubSolidity - ); + shieldOutList = + addShieldTrc20OutputList( + shieldOutList, sendShieldAddress, "" + publicFromAmount, memo, blockingStubFull); + + // Create shiled trc20 parameters + GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters = + createShieldedTrc20Parameters( + publicFromAmount, + null, + null, + shieldOutList, + "", + 0L, + blockingStubFull, + blockingStubSolidity); String data = ""; try { data = encodeMintParamsToHexString(shieldedTrc20Parameters, publicFromAmount); @@ -450,32 +543,42 @@ public void test03BurnStress() throws Exception { } catch (Exception e1) { continue; } - } - String txid = PublicMethod.triggerContract(shieldAddressByte, - mint, data, true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); + String txid = + PublicMethod.triggerContract( + shieldAddressByte, + mint, + data, + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } - } PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); finishMintNumber.addAndGet(1); - endmintNum.getAndAdd(blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber()); + endmintNum.getAndAdd( + blockingStubFull + .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber()); while (finishMintNumber.get() != thread) { try { Thread.sleep(3000); if (finishMintNumber.get() % 10 == 0) { logger.info( - "Wait all thread finished mint,current finished thread is :" + finishMintNumber - .get()); + "Wait all thread finished mint,current finished thread is :" + + finishMintNumber.get()); } } catch (InterruptedException e) { e.printStackTrace(); @@ -484,12 +587,16 @@ public void test03BurnStress() throws Exception { PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); - Long endMintNum = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber(); + Long endMintNum = + blockingStubFull + .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber(); - GrpcAPI.DecryptNotesTRC20 sendNote = scanShieldedTrc20NoteByIvkWithRange( - sendShieldAddressInfo.get(), - startmintNum.get(), endMintNum, blockingStubFull1); + GrpcAPI.DecryptNotesTRC20 sendNote = + scanShieldedTrc20NoteByIvkWithRange( + sendShieldAddressInfo.get(), startmintNum.get(), endMintNum, blockingStubFull1); noteNumber.addAndGet(sendNote.getNoteTxsCount()); @@ -504,53 +611,80 @@ public void test03BurnStress() throws Exception { List dataList = new ArrayList<>(); for (int i = 0; i < sendNote.getNoteTxsCount(); i++) { String burnnMemo1 = "burnnMemo1 type test " + getRandomLongAmount() + getRandomLongAmount(); - GrpcAPI.DecryptNotesTRC20 burnInput = GrpcAPI.DecryptNotesTRC20.newBuilder() - .addNoteTxs(sendNote.getNoteTxs(i)) - .build(); + GrpcAPI.DecryptNotesTRC20 burnInput = + GrpcAPI.DecryptNotesTRC20.newBuilder().addNoteTxs(sendNote.getNoteTxs(i)).build(); GrpcAPI.ShieldedTRC20Parameters shieldedTrc20Parameters = null; - createShieldedTrc20Parameters(BigInteger.valueOf(0), - burnInput, inputShieldAddressList, null, zenTrc20TokenOwnerAddressString, - burnInput.getNoteTxs(0).getNote().getValue(), blockingStubFull, blockingStubSolidity); + createShieldedTrc20Parameters( + BigInteger.valueOf(0), + burnInput, + inputShieldAddressList, + null, + zenTrc20TokenOwnerAddressString, + burnInput.getNoteTxs(0).getNote().getValue(), + blockingStubFull, + blockingStubSolidity); if (i % 2 == 0) { try { - shieldedTrc20Parameters = createShieldedTrc20Parameters(BigInteger.valueOf(0), - burnInput, inputShieldAddressList, null, zenTrc20TokenOwnerAddressString, - burnInput.getNoteTxs(0).getNote().getValue(), blockingStubFull, blockingStubSolidity); + shieldedTrc20Parameters = + createShieldedTrc20Parameters( + BigInteger.valueOf(0), + burnInput, + inputShieldAddressList, + null, + zenTrc20TokenOwnerAddressString, + burnInput.getNoteTxs(0).getNote().getValue(), + blockingStubFull, + blockingStubSolidity); } catch (Exception e) { try { - shieldedTrc20Parameters = createShieldedTrc20Parameters(BigInteger.valueOf(0), - burnInput, inputShieldAddressList, null, zenTrc20TokenOwnerAddressString, - burnInput.getNoteTxs(0).getNote().getValue(), blockingStubFull1, - blockingStubSolidity); + shieldedTrc20Parameters = + createShieldedTrc20Parameters( + BigInteger.valueOf(0), + burnInput, + inputShieldAddressList, + null, + zenTrc20TokenOwnerAddressString, + burnInput.getNoteTxs(0).getNote().getValue(), + blockingStubFull1, + blockingStubSolidity); } catch (Exception e1) { throw e1; } - } } else { try { - shieldedTrc20Parameters = createShieldedTrc20Parameters(BigInteger.valueOf(0), - burnInput, inputShieldAddressList, null, zenTrc20TokenOwnerAddressString, - burnInput.getNoteTxs(0).getNote().getValue(), blockingStubFull, blockingStubSolidity); + shieldedTrc20Parameters = + createShieldedTrc20Parameters( + BigInteger.valueOf(0), + burnInput, + inputShieldAddressList, + null, + zenTrc20TokenOwnerAddressString, + burnInput.getNoteTxs(0).getNote().getValue(), + blockingStubFull, + blockingStubSolidity); } catch (Exception e) { try { - shieldedTrc20Parameters = createShieldedTrc20Parameters(BigInteger.valueOf(0), - burnInput, inputShieldAddressList, null, zenTrc20TokenOwnerAddressString, - burnInput.getNoteTxs(0).getNote().getValue(), blockingStubFull1, - blockingStubSolidity); + shieldedTrc20Parameters = + createShieldedTrc20Parameters( + BigInteger.valueOf(0), + burnInput, + inputShieldAddressList, + null, + zenTrc20TokenOwnerAddressString, + burnInput.getNoteTxs(0).getNote().getValue(), + blockingStubFull1, + blockingStubSolidity); } catch (Exception e1) { throw e1; } - - } } dataList.add(shieldedTrc20Parameters.getTriggerContractInput()); - } finishCreateParameterNumber.addAndGet(1); @@ -559,27 +693,45 @@ public void test03BurnStress() throws Exception { try { Thread.sleep(3000); if (finishCreateParameterNumber.get() % 10 == 0) { - logger.info("Wait all thread finished create parameter ,current finished thread is :" - + finishCreateParameterNumber.get()); + logger.info( + "Wait all thread finished create parameter ,current finished thread is :" + + finishCreateParameterNumber.get()); } } catch (InterruptedException e) { e.printStackTrace(); } } - startTriggerNum - .addAndGet(blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber()); + startTriggerNum.addAndGet( + blockingStubFull + .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber()); for (int i = 0; i < dataList.size(); i++) { if (i % 2 == 0) { - PublicMethod.triggerContract(shieldAddressByte, - burn, dataList.get(i), true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull); + PublicMethod.triggerContract( + shieldAddressByte, + burn, + dataList.get(i), + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull); } else { - PublicMethod.triggerContract(shieldAddressByte, - burn, dataList.get(i), true, 0, maxFeeLimit, zenTrc20TokenOwnerAddress, - zenTrc20TokenOwnerKey, blockingStubFull1); + PublicMethod.triggerContract( + shieldAddressByte, + burn, + dataList.get(i), + true, + 0, + maxFeeLimit, + zenTrc20TokenOwnerAddress, + zenTrc20TokenOwnerKey, + blockingStubFull1); } try { Thread.sleep(3000); @@ -594,25 +746,29 @@ public void test03BurnStress() throws Exception { Thread.sleep(3000); if (finishTriggerNumber.get() % 10 == 0) { logger.info( - "Wait all thread finished trigger ,current finished thread is :" + finishTriggerNumber - .get()); + "Wait all thread finished trigger ,current finished thread is :" + + finishTriggerNumber.get()); } } catch (InterruptedException e) { e.printStackTrace(); } } - - } - /** - * constructor. - */ - @Test(enabled = true, threadPoolSize = 1, invocationCount = 1, groups = {"stress"}) + /** constructor. */ + @Test( + enabled = true, + threadPoolSize = 1, + invocationCount = 1, + groups = {"stress"}) public void test04QueryResult() throws Exception { - endTriggerNum.set(blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) - .getBlockHeader().getRawData().getNumber()); + endTriggerNum.set( + blockingStubFull + .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()) + .getBlockHeader() + .getRawData() + .getNumber()); Long endmintnum = endmintNum.longValue() / thread; Long starttriggernum = startTriggerNum.longValue() / thread; logger.info("Start trigger block number: " + starttriggernum); @@ -633,13 +789,12 @@ public void test04QueryResult() throws Exception { endTriggerNum.set(3060); while (startmintNum.get() < endmintnum) { - HttpResponse response = HttpMethod - .getTransactionInfoByBlocknum(httpnode, startmintNum.getAndAdd(1)); - List responseContentByBlocknum = HttpMethod - .parseResponseContentArray(response); + HttpResponse response = + HttpMethod.getTransactionInfoByBlocknum(httpnode, startmintNum.getAndAdd(1)); + List responseContentByBlocknum = HttpMethod.parseResponseContentArray(response); for (int i = 0; i < responseContentByBlocknum.size(); i++) { - String result = responseContentByBlocknum.get(i).getJSONObject("receipt") - .getString("result"); + String result = + responseContentByBlocknum.get(i).getJSONObject("receipt").getString("result"); logger.info(result); if (result == null) { notMintContract++; @@ -666,11 +821,10 @@ public void test04QueryResult() throws Exception { while (starttriggernum < endTriggerNum.get()) { HttpResponse response = HttpMethod.getTransactionInfoByBlocknum(httpnode, starttriggernum++); - List responseContentByBlocknum = HttpMethod - .parseResponseContentArray(response); + List responseContentByBlocknum = HttpMethod.parseResponseContentArray(response); for (int i = 0; i < responseContentByBlocknum.size(); i++) { - String result = responseContentByBlocknum.get(i).getJSONObject("receipt") - .getString("result"); + String result = + responseContentByBlocknum.get(i).getJSONObject("receipt").getString("result"); logger.info(result); if (result == null) { notTriggerContract++; @@ -700,22 +854,16 @@ public void test04QueryResult() throws Exception { logger.info("note size:" + noteNumber.get()); logger.info("data size:" + dataNumber.get()); - - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { - //endNum = HttpMethod.getNowBlockNum(httpnode); - //logger.info("startNum:" + startNum); - //logger.info("endNum:" + endNum); + // endNum = HttpMethod.getNowBlockNum(httpnode); + // logger.info("startNum:" + startNum); + // logger.info("endNum:" + endNum); if (channelFull != null) { channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/SupportTronlinkAutoTest.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/SupportTronlinkAutoTest.java index 85fb9998..a3f9967e 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/SupportTronlinkAutoTest.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/SupportTronlinkAutoTest.java @@ -14,15 +14,16 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class SupportTronlinkAutoTest extends TronBaseTest { - //just test key - private final String testKey002 - = "7400E3D0727F8A61041A8E8BF86599FE5597CE19DE451E59AED07D60967A5E25"; ByteString assetAccountId1; + // just test key + private final String testKey002 = + "7400E3D0727F8A61041A8E8BF86599FE5597CE19DE451E59AED07D60967A5E25"; + ByteString assetAccountId1; String[] permissionKeyString = new String[2]; String[] ownerKeyString = new String[1]; String accountPermissionJson = ""; @@ -38,19 +39,20 @@ public class SupportTronlinkAutoTest extends TronBaseTest { ECKey ecKey4 = new ECKey(Utils.getRandom()); byte[] newAddress = ecKey4.getAddress(); String newKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); - //Mainnet fullnode + // Mainnet fullnode private String fullnode = "47.252.19.181:50051"; - //dappchain fullnode - //private String fullnode = "47.252.7.241:50051"; - - /** - * constructor. - */ + // dappchain fullnode + // private String fullnode = "47.252.7.241:50051"; + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, threadPoolSize = 1, invocationCount = 1, groups = {"stress"}) + @Test( + enabled = true, + threadPoolSize = 1, + invocationCount = 1, + groups = {"stress"}) public void testMultiSignForAccount() { Integer i = 0; System.out.println("Start genterate address"); @@ -62,48 +64,55 @@ public void testMultiSignForAccount() { ecKey3 = new ECKey(Utils.getRandom()); ownerAddress = ecKey3.getAddress(); ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - //PublicMethod.printAddress(ownerKey); + // PublicMethod.printAddress(ownerKey); - PublicMethod.sendcoin(ownerAddress, 200000000000L, foundationAddress, testKey002, - blockingStubFull); + PublicMethod.sendcoin( + ownerAddress, 200000000000L, foundationAddress, testKey002, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); permissionKeyString[0] = manager1Key; permissionKeyString[1] = ownerKey; ownerKeyString[0] = ownerKey; - //ownerKeyString[1] = manager1Key; + // ownerKeyString[1] = manager1Key; accountPermissionJson = "{\"owner_permission\":{\"type\":0," + "\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2," + "\"permission_name\":\"active\",\"threshold\":2," + "\"operations\":\"" + "7fff1fc0033e0b00000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - //logger.info(accountPermissionJson); - PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerKeyString); + // logger.info(accountPermissionJson); + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); System.out.println("owner" + i + " --------------------------------------------------------"); PublicMethod.printAddress(ownerKey); - System.out.println("mutli sig address for owner " - + i + " ----------------------------------"); + System.out.println( + "mutli sig address for owner " + i + " ----------------------------------"); PublicMethod.printAddress(manager1Key); - System.out.println("-------------------------------" - + "-----------------------------------------"); - + System.out.println( + "-------------------------------" + "-----------------------------------------"); } - - } - - @Test(enabled = true, threadPoolSize = 1, invocationCount = 1, groups = {"stress"}) + @Test( + enabled = true, + threadPoolSize = 1, + invocationCount = 1, + groups = {"stress"}) public void test002CreateWitness() { Integer i = 0; System.out.println("Start genterate witness address"); @@ -111,218 +120,242 @@ public void test002CreateWitness() { ecKey3 = new ECKey(Utils.getRandom()); ownerAddress = ecKey3.getAddress(); ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); - //PublicMethod.printAddress(ownerKey); + // PublicMethod.printAddress(ownerKey); - PublicMethod.sendcoin(ownerAddress, 50000000000L, foundationAddress, testKey002, - blockingStubFull); + PublicMethod.sendcoin( + ownerAddress, 50000000000L, foundationAddress, testKey002, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String createWitnessUrl = "IOS-UI-Witness-00" + i; - byte[] createUrl = createWitnessUrl.getBytes(); + String createWitnessUrl = "IOS-UI-Witness-00" + i; + byte[] createUrl = createWitnessUrl.getBytes(); createWitness(ownerAddress, createUrl, ownerKey); PublicMethod.waitProduceNextBlock(blockingStubFull); - System.out.println("witness " + i + " -----------------------------" - + "---------------------------"); + System.out.println( + "witness " + i + " -----------------------------" + "---------------------------"); PublicMethod.printAddress(ownerKey); System.out.println("witness url is : " + createWitnessUrl); - System.out.println("-------------------------------------------" - + "-----------------------------"); - + System.out.println( + "-------------------------------------------" + "-----------------------------"); } - - } - - @Test(enabled = true, threadPoolSize = 1, invocationCount = 1, groups = {"stress"}) + @Test( + enabled = true, + threadPoolSize = 1, + invocationCount = 1, + groups = {"stress"}) public void test03MultiSignForAccount() { - //test keys + // test keys HashMap muti = new HashMap(); - muti.put("9a2ba173645be8d37a82084f984ba873fbcf817b589c62a59b3ba1494c3406e0", + muti.put( + "9a2ba173645be8d37a82084f984ba873fbcf817b589c62a59b3ba1494c3406e0", "cefba96470224724bde255f3402fca3d67b6c7c5d34deb7a8524c9482c58fe8b"); - muti.put("36f5430b4003f41ee8969421d9366ab1414e62111aec07a73d06eefcda8aad14", + muti.put( + "36f5430b4003f41ee8969421d9366ab1414e62111aec07a73d06eefcda8aad14", "3adcd73ad1fa03ce2fd4d29e29a7c96ef2f78bece85cba6e58997826682c4c1e"); - muti.put("4b47cf37528724dc8bc99188063f5aec9a7bc32aadfad5a96a9e9cccba7cede1", + muti.put( + "4b47cf37528724dc8bc99188063f5aec9a7bc32aadfad5a96a9e9cccba7cede1", "948d856ebeb787aabd495fc13627f7442e7c1f21e9ed784f795e14f13cbebb94"); - muti.put("75d0856799cf2b2c807ed0eb5bb091bb943f2caed830add4b8df14c537f86e9a", + muti.put( + "75d0856799cf2b2c807ed0eb5bb091bb943f2caed830add4b8df14c537f86e9a", "7fb13ad0b62d4ff116ebd3d901d458697902ce81a8fc30c20c60aba1ca6964ec"); - muti.put("327bf1b4a3193c2bebf239c1c5bda09a8d375251361ea9c7418aa2adf2d17b7e", + muti.put( + "327bf1b4a3193c2bebf239c1c5bda09a8d375251361ea9c7418aa2adf2d17b7e", "a8236968966db785ffe63d613174ee25e1baff03817b64db905c5940ed3dcc4b"); - muti.put("cf83d9494a9268fd3a75bd76bcfabaa7ec766e9084129a20e1823f81fbdca933", + muti.put( + "cf83d9494a9268fd3a75bd76bcfabaa7ec766e9084129a20e1823f81fbdca933", "1e53c948e949e39f60a3be2382382f9a50f88b658ea79c418ece1c5f9b169441"); - muti.put("19ff919e92462f07c7eced256d4cb588a66ac900d544d0d4d16ae49732de79cb", + muti.put( + "19ff919e92462f07c7eced256d4cb588a66ac900d544d0d4d16ae49732de79cb", "166ddc2cd6379e7971e2c65d224594b709ebb59b3c6051c156214c299129f420"); - muti.put("7901db57a410a26d333b6d7fe4e054ddffbdc646f94ca03577bfd5e87120b9af", + muti.put( + "7901db57a410a26d333b6d7fe4e054ddffbdc646f94ca03577bfd5e87120b9af", "89d9a47b37f5625e14082b575d5e657b21f6dae125125bee51fafd1e8cdf0804"); - muti.put("e3c7204d652a6fdcda05cbce061904d441dece7bf0a1778c1ddf0906aa36a279", + muti.put( + "e3c7204d652a6fdcda05cbce061904d441dece7bf0a1778c1ddf0906aa36a279", "7d308998f829c0581447831003d994216a3a003ba00eef6a4e48e28b3178fbb3"); - muti.put("826fc86d572ba9de06f20963fcbfb44f4c397875bd4d7b36fdcb83476df33f05", + muti.put( + "826fc86d572ba9de06f20963fcbfb44f4c397875bd4d7b36fdcb83476df33f05", "25aa122142a52ea8ba7bdf832c39a194d498774d4f675b8bcb17280c33990a08"); - muti.put("9705dd852465d04be349e94865142fc636d038138a4bfe8f94abc9b49f1dc14a", + muti.put( + "9705dd852465d04be349e94865142fc636d038138a4bfe8f94abc9b49f1dc14a", "0b675f14c1e06a6473c517dded162472ce2bb5c8934f198df1a791b75c30f983"); - muti.put("075f86d3d4053929714ddedb3e458467e6d494c3d4b0c71dafb63279de1beb89", + muti.put( + "075f86d3d4053929714ddedb3e458467e6d494c3d4b0c71dafb63279de1beb89", "4880695a6e31f4f69d6f261eedfa5dcb5fc1b9194483658f77625ec4e6b2e493"); - muti.put("91ae6c8a1bff0b71f6f2b9de54d3b39502bcab906f980569109ab8425cb0bdc5", + muti.put( + "91ae6c8a1bff0b71f6f2b9de54d3b39502bcab906f980569109ab8425cb0bdc5", "90ef4adb0772ee49089784ccad234867a10395064749788b461cbe91265424fb"); - muti.put("9acb90c4d15c87dd2a1f322eddaabdde22cd78fe5eab371bfcf0c8be80bef8a8", + muti.put( + "9acb90c4d15c87dd2a1f322eddaabdde22cd78fe5eab371bfcf0c8be80bef8a8", "951f03193e1d7d4bff016da100b74f8ac220aabfd9c2841438ee758702c8e3f4"); - muti.put("f8eae7be0fac4e9fab40139e58b405f7e5d5b13a83220a6e4955ffaacbbe2a7d", + muti.put( + "f8eae7be0fac4e9fab40139e58b405f7e5d5b13a83220a6e4955ffaacbbe2a7d", "66692c0aaad6cfd349bdffbf3fdd688558a6c7a95ff67f249e0e80847167013a"); - muti.put("2e20c1a4b9a3a79696cbf0d03dedc39d8021657028fbf3dbc5da85ea61ad5dff", + muti.put( + "2e20c1a4b9a3a79696cbf0d03dedc39d8021657028fbf3dbc5da85ea61ad5dff", "ae7ecb7fba0d77d116a23f96a4dfecdef09741e363f0be12f99c86b3815d8fff"); - muti.put("e5e60c52f3b11ce0cfbc4e86d078ab53435ebc2422fd851614a25b5063ae7040", + muti.put( + "e5e60c52f3b11ce0cfbc4e86d078ab53435ebc2422fd851614a25b5063ae7040", "42c575d8848809082c6872b2dcdb0e81d5f06ca120c636b90d0b062965ea0871"); - muti.put("fd4ee3a678a749c2049d5b1cba757648386c84ac2481be8de02069d41e4fb312", + muti.put( + "fd4ee3a678a749c2049d5b1cba757648386c84ac2481be8de02069d41e4fb312", "ef2095532f572be8d021886780f7e508665ef40c1499273b91813ddc27d1354b"); - muti.put("297f6e034e9366691922ff5394810f724094bd0a07b4ca60f0f281ec71562094", + muti.put( + "297f6e034e9366691922ff5394810f724094bd0a07b4ca60f0f281ec71562094", "4ab67f1c42db0b63bafc0f33cf59575998c3259e96f5f89ea379dac4298d2bd7"); - int i = 1; + int i = 1; for (HashMap.Entry entry : muti.entrySet()) { - //entry.getKey().toString(); - //entry.getValue().toString(); + // entry.getKey().toString(); + // entry.getValue().toString(); ownerKey = entry.getKey().toString(); ownerAddress = PublicMethod.getFinalAddress(ownerKey); manager1Key = entry.getValue().toString(); manager1Address = PublicMethod.getFinalAddress(manager1Key); - //System.out.println("ownerKey:" + ownerKey); - //System.out.println("manager1Key:" + manager1Key); - //System.exit(1); - PublicMethod.sendcoin(ownerAddress, 20000000000L, foundationAddress, testKey002, - blockingStubFull); + // System.out.println("ownerKey:" + ownerKey); + // System.out.println("manager1Key:" + manager1Key); + // System.exit(1); + PublicMethod.sendcoin( + ownerAddress, 20000000000L, foundationAddress, testKey002, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); permissionKeyString[0] = manager1Key; permissionKeyString[1] = ownerKey; ownerKeyString[0] = ownerKey; - //ownerKeyString[1] = manager1Key; + // ownerKeyString[1] = manager1Key; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"" + "threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"" + "active\",\"threshold\":2," + "\"operations\":\"" + "7fff1fc0033e0b00000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}" + "]}]}"; - //logger.info(accountPermissionJson); - PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerKeyString); - System.out.println("owner " + i++ + " -----------------" - + "---------------------------------------"); + // logger.info(accountPermissionJson); + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); + System.out.println( + "owner " + i++ + " -----------------" + "---------------------------------------"); PublicMethod.printAddress(ownerKey); - System.out.println("mutli sig address for owner " + i++ + " ------------" - + "----------------------"); + System.out.println( + "mutli sig address for owner " + i++ + " ------------" + "----------------------"); PublicMethod.printAddress(manager1Key); - System.out.println("-----------------------------------" - + "-------------------------------------"); - + System.out.println( + "-----------------------------------" + "-------------------------------------"); } - } - - @Test(enabled = true, threadPoolSize = 1, invocationCount = 1, groups = {"stress"}) + @Test( + enabled = true, + threadPoolSize = 1, + invocationCount = 1, + groups = {"stress"}) public void test004CreateWitness() { -//test keys + // test keys String[] witnessKey = { - - "c74fb4d8101572041c6fab30e1602ba1ec8247e1ead19641fb985b3ed3a8261e", - "25f98ac22c9fd02aa8a2ef354db0aa13ebc2a6c31377ea7e2b342f0d3898af0d", - "939a2cec3768bd2d2834126c20d2b1c513e3711f085ce374f654a7b144aa409f", - "39862f4dd51972ca22ce50b7b9e629043387000120c33bf263399ad9b334da1a", - "79045aab0f3199ac456ce2039e809e6c942983ede0e3a398d571dedddb351348", - "d50fe9c48e95289cde324ffeff095f8275f9ab07375e5e843167a0a54d3e1462", - "61651f2b8a87e1ae0ced5e700807f2abb50e97fe7d3d3e6a8aa58f0a6b0149a6", - "bb03d70e5187258ffb6cddb1becade5c1b2606b7ea84636b7dfaeef6216610a5", - "25858c236634e353d018f310f61e077b78e1410766565ed56ff11ee7410dcf20", - "ede941a01eb8234866f60c7e8e95db4614bb0d05298d82bae0abea81f1861046", - + "c74fb4d8101572041c6fab30e1602ba1ec8247e1ead19641fb985b3ed3a8261e", + "25f98ac22c9fd02aa8a2ef354db0aa13ebc2a6c31377ea7e2b342f0d3898af0d", + "939a2cec3768bd2d2834126c20d2b1c513e3711f085ce374f654a7b144aa409f", + "39862f4dd51972ca22ce50b7b9e629043387000120c33bf263399ad9b334da1a", + "79045aab0f3199ac456ce2039e809e6c942983ede0e3a398d571dedddb351348", + "d50fe9c48e95289cde324ffeff095f8275f9ab07375e5e843167a0a54d3e1462", + "61651f2b8a87e1ae0ced5e700807f2abb50e97fe7d3d3e6a8aa58f0a6b0149a6", + "bb03d70e5187258ffb6cddb1becade5c1b2606b7ea84636b7dfaeef6216610a5", + "25858c236634e353d018f310f61e077b78e1410766565ed56ff11ee7410dcf20", + "ede941a01eb8234866f60c7e8e95db4614bb0d05298d82bae0abea81f1861046", }; - int i = 1; + int i = 1; for (String ownerKey : witnessKey) { byte[] ownerAddress = PublicMethod.getFinalAddress(ownerKey); - PublicMethod.sendcoin(ownerAddress, 20000000000L, foundationAddress, testKey002, - blockingStubFull); + PublicMethod.sendcoin( + ownerAddress, 20000000000L, foundationAddress, testKey002, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - String createWitnessUrl = "IOS-UI-Witness-00" + i++; - byte[] createUrl = createWitnessUrl.getBytes(); + String createWitnessUrl = "IOS-UI-Witness-00" + i++; + byte[] createUrl = createWitnessUrl.getBytes(); createWitness(ownerAddress, createUrl, ownerKey); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.printAddress(ownerKey); System.out.println("witness url is : " + createWitnessUrl); System.out.println("---------------------------------------------------------------------"); - } - - } - - @Test(enabled = true, threadPoolSize = 1, invocationCount = 1, groups = {"stress"}) + @Test( + enabled = true, + threadPoolSize = 1, + invocationCount = 1, + groups = {"stress"}) public void test005SendTrc20() { String[] witnessKey = { - "TR8CyAPJFMjCvphCVuWeeVxBh5iTG7VWxe", - "TMhGDU7NiXwckCW64PqAvWFuC2kR1WSF5J", - "TDf3JZtjDeEqsFdPGp6vT9meG3JxMwmXwA", - "TEtG9fnVi2qythiog6owPrg4sD9rwFBQBN", - "TUvda1oqrNLbqDKhZDxDnrPhiDCdxem218", - "TKEH31jJ2YQ3Bteh1ngjwdT8667ztyYPSp", - "TAzrJHKa57nXnn3dZGFG87PDuWx12dY97s", - "TWhc6AAh6BWRr3k5dV8iMvkp8ys7NHzXCk", - "TSsaSxHnb3xLTop2A8LrDk1P896yiDeupe", - "TMDs8oTj8mVnakqiVyDKdp2ruWPdFeDgbq", - "TWv2FEsoPp5XKxujVHffoNwksgJSxvf3QG", - "TGamEmt6U9ZUg9bFsMq7KT9bRa3uvkdtHM", - "TXhQk442CCGLydh6cfyfqvM6yJanEGeQj1", - "TKktQcbjXsXZDKPYLvUm8sxox2cT83g5rP", - "TBQUhYhdQpMRksBGAbpbTWSiE7WkGgy3Km", - "TALf34yjuLZjF1WQqCaUkf73X8WbhfiEyM", - "TCGp3JAFM5vQZpsdNiKRTci7fVb7A2TPcu", - "TBExF3mNvnhmEFgHW4TmYXXdhevRchnQyb", - "TS8o6WcHroSnzWNt4AiserAuVkye5Msvcm", - "TBtMRD79NkLyAvMkCTTj5VC5KZnz2Po2XZ", + "TR8CyAPJFMjCvphCVuWeeVxBh5iTG7VWxe", + "TMhGDU7NiXwckCW64PqAvWFuC2kR1WSF5J", + "TDf3JZtjDeEqsFdPGp6vT9meG3JxMwmXwA", + "TEtG9fnVi2qythiog6owPrg4sD9rwFBQBN", + "TUvda1oqrNLbqDKhZDxDnrPhiDCdxem218", + "TKEH31jJ2YQ3Bteh1ngjwdT8667ztyYPSp", + "TAzrJHKa57nXnn3dZGFG87PDuWx12dY97s", + "TWhc6AAh6BWRr3k5dV8iMvkp8ys7NHzXCk", + "TSsaSxHnb3xLTop2A8LrDk1P896yiDeupe", + "TMDs8oTj8mVnakqiVyDKdp2ruWPdFeDgbq", + "TWv2FEsoPp5XKxujVHffoNwksgJSxvf3QG", + "TGamEmt6U9ZUg9bFsMq7KT9bRa3uvkdtHM", + "TXhQk442CCGLydh6cfyfqvM6yJanEGeQj1", + "TKktQcbjXsXZDKPYLvUm8sxox2cT83g5rP", + "TBQUhYhdQpMRksBGAbpbTWSiE7WkGgy3Km", + "TALf34yjuLZjF1WQqCaUkf73X8WbhfiEyM", + "TCGp3JAFM5vQZpsdNiKRTci7fVb7A2TPcu", + "TBExF3mNvnhmEFgHW4TmYXXdhevRchnQyb", + "TS8o6WcHroSnzWNt4AiserAuVkye5Msvcm", + "TBtMRD79NkLyAvMkCTTj5VC5KZnz2Po2XZ", }; - int i = 1; + int i = 1; for (String ownerKey : witnessKey) { - String triggerString = "\"" + ownerKey - + "\"" + ", 20000000000"; + String triggerString = "\"" + ownerKey + "\"" + ", 20000000000"; System.out.println(triggerString); - //dapp chain trc20 tract TXkdXbzjoLpxGAD2strP1zwjJzR6osNfD7 + // dapp chain trc20 tract TXkdXbzjoLpxGAD2strP1zwjJzR6osNfD7 byte[] contractAddress = PublicMethod.decode58Check("TXkdXbzjoLpxGAD2strP1zwjJzR6osNfD7"); - //main chain TRC 20 contract TCCcBZEdTHmS1NfFtCYfwpjBKeTv515n71 - //byte[] contractAddress = PublicMethod.decode58Check("TCCcBZEdTHmS1NfFtCYfwpjBKeTv515n71"); - - PublicMethod - .triggerContract(contractAddress, "transfer(address,uint256)", triggerString, false, - 0, 1000000000, "0", 0, foundationAddress, testKey002, blockingStubFull); + // main chain TRC 20 contract TCCcBZEdTHmS1NfFtCYfwpjBKeTv515n71 + // byte[] contractAddress = PublicMethod.decode58Check("TCCcBZEdTHmS1NfFtCYfwpjBKeTv515n71"); + + PublicMethod.triggerContract( + contractAddress, + "transfer(address,uint256)", + triggerString, + false, + 0, + 1000000000, + "0", + 0, + foundationAddress, + testKey002, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - - } - - } - - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ + /** constructor. */ public Boolean createWitness(byte[] owner, byte[] url, String priKey) { ECKey temKey = null; try { @@ -333,8 +366,8 @@ public Boolean createWitness(byte[] owner, byte[] url, String priKey) { } final ECKey ecKey = temKey; - WitnessContract.WitnessCreateContract.Builder builder = WitnessContract.WitnessCreateContract - .newBuilder(); + WitnessContract.WitnessCreateContract.Builder builder = + WitnessContract.WitnessCreateContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(owner)); builder.setUrl(ByteString.copyFrom(url)); WitnessContract.WitnessCreateContract contract = builder.build(); @@ -346,4 +379,4 @@ public Boolean createWitness(byte[] owner, byte[] url, String priKey) { GrpcAPI.Return response = blockingStubFull.broadcastTransaction(transaction); return response.getResult(); } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/TestApproveProposal.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/TestApproveProposal.java index 1453d4e4..899fbde8 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/TestApproveProposal.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/TestApproveProposal.java @@ -1,6 +1,5 @@ package stest.tron.wallet.onlinestress; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.HashMap; import java.util.Optional; @@ -21,66 +20,61 @@ public class TestApproveProposal extends TronBaseTest { private static final long now = System.currentTimeMillis(); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); - //Witness 47.93.33.201 - //Witness 123.56.10.6 - //Wtiness 39.107.80.135 - //Witness 47.93.184.2 + // Witness 47.93.33.201 + // Witness 123.56.10.6 + // Wtiness 39.107.80.135 + // Witness 47.93.184.2 private final byte[] witness001Address = PublicMethod.getFinalAddress(witnessKey); private final byte[] witness002Address = PublicMethod.getFinalAddress(witnessKey2); private final byte[] witness003Address = PublicMethod.getFinalAddress(witnessKey3); private final byte[] witness004Address = PublicMethod.getFinalAddress(witnessKey4); private final byte[] witness005Address = PublicMethod.getFinalAddress(witnessKey5); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass - public void beforeClass() { channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + public void beforeClass() { + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, groups = {"stress"}) + @Test( + enabled = true, + groups = {"stress"}) public void testApproveProposal() { HashMap proposalMap = new HashMap(); - //proposalMap.put(25L, 1L); + // proposalMap.put(25L, 1L); proposalMap.put(27L, 0L); - //proposalMap.put(28L, 1L); - Assert.assertTrue(PublicMethod.createProposal(witness001Address, witnessKey, - proposalMap, blockingStubFull)); + // proposalMap.put(28L, 1L); + Assert.assertTrue( + PublicMethod.createProposal(witness001Address, witnessKey, proposalMap, blockingStubFull)); try { Thread.sleep(20000); } catch (InterruptedException e) { e.printStackTrace(); } - //Get proposal list + // Get proposal list ProposalList proposalList = blockingStubFull.listProposals(EmptyMessage.newBuilder().build()); Optional listProposals = Optional.ofNullable(proposalList); - final Integer proposalId = listProposals.get().getProposalsCount(); + final Integer proposalId = listProposals.get().getProposalsCount(); logger.info(Integer.toString(proposalId)); - //Get proposal list after approve + // Get proposal list after approve proposalList = blockingStubFull.listProposals(EmptyMessage.newBuilder().build()); listProposals = Optional.ofNullable(proposalList); - //logger.info(Integer.toString(listProposals.get().getProposals(0).getApprovalsCount())); - //just test keys + // logger.info(Integer.toString(listProposals.get().getProposals(0).getApprovalsCount())); + // just test keys String[] witnessKey = { - - "369F095838EB6EED45D4F6312AF962D5B9DE52927DA9F04174EE49F9AF54BC77", - "9FD8E129DE181EA44C6129F727A6871440169568ADE002943EAD0E7A16D8EDAC", - + "369F095838EB6EED45D4F6312AF962D5B9DE52927DA9F04174EE49F9AF54BC77", + "9FD8E129DE181EA44C6129F727A6871440169568ADE002943EAD0E7A16D8EDAC", }; - byte[] witnessAddress; + byte[] witnessAddress; for (String key : witnessKey) { witnessAddress = PublicMethod.getFinalAddress(key); - PublicMethod.approveProposal(witnessAddress, key, proposalId, - true, blockingStubFull); + PublicMethod.approveProposal(witnessAddress, key, proposalId, true, blockingStubFull); try { Thread.sleep(1000); } catch (InterruptedException e) { @@ -89,9 +83,11 @@ public void testApproveProposal() { } } - @Test(enabled = true, groups = {"stress"}) + @Test( + enabled = true, + groups = {"stress"}) public void testGetChainParameters() { - //Set the default map + // Set the default map HashMap defaultCommitteeMap = new HashMap(); defaultCommitteeMap.put("MAINTENANCE_TIME_INTERVAL", 300000L); defaultCommitteeMap.put("ACCOUNT_UPGRADE_COST", 9999000000L); @@ -103,8 +99,8 @@ public void testGetChainParameters() { defaultCommitteeMap.put("CREATE_NEW_ACCOUNT_FEE_IN_SYSTEM_CONTRACT", 0L); defaultCommitteeMap.put("CREATE_NEW_ACCOUNT_BANDWIDTH_RATE", 1L); - ChainParameters chainParameters = blockingStubFull - .getChainParameters(EmptyMessage.newBuilder().build()); + ChainParameters chainParameters = + blockingStubFull.getChainParameters(EmptyMessage.newBuilder().build()); Optional getChainParameters = Optional.ofNullable(chainParameters); logger.info(Long.toString(getChainParameters.get().getChainParameterCount())); for (Integer i = 0; i < getChainParameters.get().getChainParameterCount(); i++) { @@ -112,14 +108,9 @@ public void testGetChainParameters() { logger.info(getChainParameters.get().getChainParameter(i).getKey()); logger.info(Long.toString(getChainParameters.get().getChainParameter(i).getValue())); } - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/TestExchangeTransaction.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/TestExchangeTransaction.java index 187ac9bf..e86a2837 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/TestExchangeTransaction.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/TestExchangeTransaction.java @@ -15,16 +15,15 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class TestExchangeTransaction extends TronBaseTest { private static final long now = System.currentTimeMillis(); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); Optional listExchange; Optional exchangeIdInfo; @@ -32,85 +31,140 @@ public class TestExchangeTransaction extends TronBaseTest { Integer exchangeRate = 10; Long firstTokenInitialBalance = 10000L; Long secondTokenInitialBalance = firstTokenInitialBalance * exchangeRate; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - /** - * constructor. - */ + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + /** constructor. */ @BeforeClass - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, groups = {"stress"}) + @Test( + enabled = true, + groups = {"stress"}) public void testCreateShieldToken() { - //just test key + // just test key String tokenOwnerKey = "2925e186bb1e88988855f11ebf20ea3a6e19ed92328b0ffb576122e769d45b68"; - byte[] tokenOwnerAddress = PublicMethod.getFinalAddress(tokenOwnerKey); + byte[] tokenOwnerAddress = PublicMethod.getFinalAddress(tokenOwnerKey); PublicMethod.printAddress(tokenOwnerKey); - Assert.assertTrue(PublicMethod.sendcoin(tokenOwnerAddress, 20480000000L, foundationAddress, - foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + tokenOwnerAddress, 20480000000L, foundationAddress, foundationKey, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - String name = "shieldToken"; - Long start = System.currentTimeMillis() + 20000; - Long end = System.currentTimeMillis() + 10000000000L; - Long totalSupply = 1500000000000001L; - String description = "This asset issue is use for exchange transaction stress"; - String url = "This asset issue is use for exchange transaction stress"; - Assert.assertTrue(PublicMethod.createAssetIssue(tokenOwnerAddress, name, totalSupply, 1, 1, - start, end, 1, description, url, 1000L, 1000L, - 1L, 1L, tokenOwnerKey, blockingStubFull)); + String name = "shieldToken"; + Long start = System.currentTimeMillis() + 20000; + Long end = System.currentTimeMillis() + 10000000000L; + Long totalSupply = 1500000000000001L; + String description = "This asset issue is use for exchange transaction stress"; + String url = "This asset issue is use for exchange transaction stress"; + Assert.assertTrue( + PublicMethod.createAssetIssue( + tokenOwnerAddress, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 1000L, + 1000L, + 1L, + 1L, + tokenOwnerKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account getAssetIdFromThisAccount = PublicMethod.queryAccount(tokenOwnerAddress, blockingStubFull); ByteString assetAccountId = getAssetIdFromThisAccount.getAssetIssuedID(); logger.info("AssetId:" + assetAccountId.toString()); - - } - @Test(enabled = true, threadPoolSize = 20, invocationCount = 20, groups = {"stress"}) + @Test( + enabled = true, + threadPoolSize = 20, + invocationCount = 20, + groups = {"stress"}) public void testExchangeTransaction() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] exchangeAddress = ecKey1.getAddress(); - String exchangeKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - ECKey ecKey2 = new ECKey(Utils.getRandom()); - final byte[] transactionAddress = ecKey2.getAddress(); - String transactionKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + byte[] exchangeAddress = ecKey1.getAddress(); + String exchangeKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + final byte[] transactionAddress = ecKey2.getAddress(); + String transactionKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); PublicMethod.printAddress(exchangeKey); PublicMethod.printAddress(transactionKey); - Assert.assertTrue(PublicMethod.sendcoin(exchangeAddress, 1500000000000000L, foundationAddress, - foundationKey, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(transactionAddress, 1500000000000000L, foundationAddress, - foundationKey, blockingStubFull)); - Long totalSupply = 1500000000000000L; + Assert.assertTrue( + PublicMethod.sendcoin( + exchangeAddress, + 1500000000000000L, + foundationAddress, + foundationKey, + blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + transactionAddress, + 1500000000000000L, + foundationAddress, + foundationKey, + blockingStubFull)); + Long totalSupply = 1500000000000000L; Random rand = new Random(); Integer randNum = rand.nextInt(900000000) + 1; - String name = "exchange_" + Long.toString(randNum); - Long start = System.currentTimeMillis() + 20000; - Long end = System.currentTimeMillis() + 10000000000L; - String description = "This asset issue is use for exchange transaction stress"; - String url = "This asset issue is use for exchange transaction stress"; - Assert.assertTrue(PublicMethod.createAssetIssue(exchangeAddress, name, totalSupply, 1, 1, - start, end, 1, description, url, 100000000L, 10000000000L, - 10L, 10L, exchangeKey, blockingStubFull)); + String name = "exchange_" + Long.toString(randNum); + Long start = System.currentTimeMillis() + 20000; + Long end = System.currentTimeMillis() + 10000000000L; + String description = "This asset issue is use for exchange transaction stress"; + String url = "This asset issue is use for exchange transaction stress"; + Assert.assertTrue( + PublicMethod.createAssetIssue( + exchangeAddress, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 100000000L, + 10000000000L, + 10L, + 10L, + exchangeKey, + blockingStubFull)); try { Thread.sleep(30000); } catch (InterruptedException e) { e.printStackTrace(); } - Assert.assertTrue(PublicMethod.transferAsset(transactionAddress, name.getBytes(), - 1500000000L, exchangeAddress, exchangeKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + transactionAddress, + name.getBytes(), + 1500000000L, + exchangeAddress, + exchangeKey, + blockingStubFull)); try { Thread.sleep(30000); } catch (InterruptedException e) { e.printStackTrace(); } - //500000000000000L //5000000L - Assert.assertTrue(PublicMethod.exchangeCreate(name.getBytes(), 500000000000000L, - "_".getBytes(), 500000000000000L, exchangeAddress, exchangeKey, blockingStubFull)); + // 500000000000000L //5000000L + Assert.assertTrue( + PublicMethod.exchangeCreate( + name.getBytes(), + 500000000000000L, + "_".getBytes(), + 500000000000000L, + exchangeAddress, + exchangeKey, + blockingStubFull)); try { Thread.sleep(300000); } catch (InterruptedException e) { @@ -121,15 +175,27 @@ public void testExchangeTransaction() { Integer i = 0; while (i++ < 10000) { - PublicMethod.exchangeTransaction(exchangeId, "_".getBytes(), 100000, 99, - transactionAddress, transactionKey, blockingStubFull); + PublicMethod.exchangeTransaction( + exchangeId, + "_".getBytes(), + 100000, + 99, + transactionAddress, + transactionKey, + blockingStubFull); try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } - PublicMethod.exchangeTransaction(exchangeId, name.getBytes(), 100000, 1, - transactionAddress, transactionKey, blockingStubFull); + PublicMethod.exchangeTransaction( + exchangeId, + name.getBytes(), + 100000, + 1, + transactionAddress, + transactionKey, + blockingStubFull); try { Thread.sleep(100); } catch (InterruptedException e) { @@ -138,12 +204,7 @@ public void testExchangeTransaction() { } } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/TestMapBigLongAndNumbers.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/TestMapBigLongAndNumbers.java index f03ce90c..d604a9e1 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/TestMapBigLongAndNumbers.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/TestMapBigLongAndNumbers.java @@ -13,26 +13,26 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; - //import java.io.FileWriter; -//import java.io.BufferedWriter; +import stest.tron.wallet.common.client.utils.Utils; +// import java.io.FileWriter; +// import java.io.BufferedWriter; @Slf4j public class TestMapBigLongAndNumbers extends TronBaseTest { - //testng001、testng002、testng003、testng004 - //the key is for test + // testng001、testng002、testng003、testng004 + // the key is for test private final String testKey002 = "FC8BF0238748587B9617EB6D15D47A66C0E07C1A1959033CF249C6532DC29FE6"; - //private final String testAddress41 = ByteArray.toHexString(foundationAddress); + // private final String testAddress41 = ByteArray.toHexString(foundationAddress); String kittyCoreAddressAndCut = ""; byte[] kittyCoreContractAddress = null; byte[] saleClockAuctionContractAddress = null; byte[] siringClockAuctionContractAddress = null; byte[] geneScienceInterfaceContractAddress = null; - //Integer consumeUserResourcePercent = 20; + // Integer consumeUserResourcePercent = 20; Integer consumeUserResourcePercent = 100; String txid = ""; Optional infoById = null; @@ -40,30 +40,44 @@ public class TestMapBigLongAndNumbers extends TronBaseTest { byte[] triggerAddress = ecKey2.getAddress(); String triggerKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { - PublicMethod.printAddress(triggerKey); } + PublicMethod.printAddress(triggerKey); + } - @Test(enabled = true, threadPoolSize = 10, invocationCount = 10, groups = {"stress"}) + @Test( + enabled = true, + threadPoolSize = 10, + invocationCount = 10, + groups = {"stress"}) public void deployErc721KittyCore() { Long maxFeeLimit = 1000000000L; - String contractName = "MappingExample"; - String code = Configuration.getByPath("testng.conf") - .getString("code.code_TestMapBigLongAndNumbers_deployErc721KittyCore"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_TestMapBigLongAndNumbers_deployErc721KittyCore"); - kittyCoreContractAddress = PublicMethod.deployContract(contractName, abi, code, "", - maxFeeLimit, 0L, consumeUserResourcePercent, null, testKey002, - foundationAddress, blockingStubFull); - String data1 = "a"; - String data2 = "b"; - String data3 = "c"; - String data4 = "d"; + String contractName = "MappingExample"; + String code = + Configuration.getByPath("testng.conf") + .getString("code.code_TestMapBigLongAndNumbers_deployErc721KittyCore"); + String abi = + Configuration.getByPath("testng.conf") + .getString("abi.abi_TestMapBigLongAndNumbers_deployErc721KittyCore"); + kittyCoreContractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + consumeUserResourcePercent, + null, + testKey002, + foundationAddress, + blockingStubFull); + String data1 = "a"; + String data2 = "b"; + String data3 = "c"; + String data4 = "d"; for (int i = 0; i < 13; i++) { data1 += data1; @@ -80,14 +94,14 @@ public void deployErc721KittyCore() { } String data; data = data1 + data2 + data3 + data4; - String data5 = "a"; + String data5 = "a"; Account account = PublicMethod.queryAccountByAddress(foundationAddress, blockingStubFull); System.out.println(Long.toString(account.getBalance())); long accountBalance = account.getBalance(); Random random = new Random(); - int randNumber = random.nextInt(15) + 15; + int randNumber = random.nextInt(15) + 15; System.out.println("random number:" + randNumber); @@ -99,35 +113,62 @@ public void deployErc721KittyCore() { for (int ii = 1; ii < 111100000; ii++) { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] userAddress = ecKey1.getAddress(); - String inputKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - String addresstest = Base58.encode58Check(userAddress); - String saleContractString = "\"" + data + "\"" + "," + "\"" - + Base58.encode58Check(userAddress) + "\""; + byte[] userAddress = ecKey1.getAddress(); + String inputKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + String addresstest = Base58.encode58Check(userAddress); + String saleContractString = + "\"" + data + "\"" + "," + "\"" + Base58.encode58Check(userAddress) + "\""; System.out.println("long string address:" + addresstest); - txid = PublicMethod.triggerContract(kittyCoreContractAddress, "update2(string,address)", - saleContractString, false, 0, 1000000000L, foundationAddress, testKey002, blockingStubFull); + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "update2(string,address)", + saleContractString, + false, + 0, + 1000000000L, + foundationAddress, + testKey002, + blockingStubFull); logger.info(txid); - String saleContractString1 = "\"" + data5 + "\"" + "," + "\"" - + Base58.encode58Check(userAddress) + "\""; + String saleContractString1 = + "\"" + data5 + "\"" + "," + "\"" + Base58.encode58Check(userAddress) + "\""; System.out.println("short string address:" + addresstest); - txid = PublicMethod.triggerContract(kittyCoreContractAddress, "update2(string,address)", - saleContractString1, false, 0, 1000000000L, foundationAddress, testKey002, blockingStubFull); + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "update2(string,address)", + saleContractString1, + false, + 0, + 1000000000L, + foundationAddress, + testKey002, + blockingStubFull); logger.info(txid); System.out.println("time out"); - txid = PublicMethod.triggerContract(kittyCoreContractAddress, "testUseCpu(uint256)", - "1000000000", false, 0, 1000000000L, foundationAddress, testKey002, blockingStubFull); + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "testUseCpu(uint256)", + "1000000000", + false, + 0, + 1000000000L, + foundationAddress, + testKey002, + blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); infoById.get().getResultValue(); - String isSuccess; + String isSuccess; if (infoById.get().getResultValue() == 0) { logger.info("success:" + " Number:" + ii); @@ -139,13 +180,7 @@ public void deployErc721KittyCore() { } } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } - + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/TestMultiSignStress.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/TestMultiSignStress.java index 6902f7a8..1f0bb4a9 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/TestMultiSignStress.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/TestMultiSignStress.java @@ -6,13 +6,12 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class TestMultiSignStress extends TronBaseTest { @@ -21,55 +20,67 @@ public class TestMultiSignStress extends TronBaseTest { String[] ownerKeyString = new String[1]; String accountPermissionJson = ""; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} - @Test(enabled = true, threadPoolSize = 30, invocationCount = 30, groups = {"stress"}) + @Test( + enabled = true, + threadPoolSize = 30, + invocationCount = 30, + groups = {"stress"}) public void testMultiSignForAccount() { PublicMethod.printAddress(testKey002); - ECKey ecKey4 = new ECKey(Utils.getRandom()); - byte[] newAddress = ecKey4.getAddress(); - String newKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); - ECKey ecKey3 = new ECKey(Utils.getRandom()); - byte[] ownerAddress = ecKey3.getAddress(); - - Assert.assertTrue(PublicMethod.sendcoin(ownerAddress, 9968981537400L, foundationAddress, testKey002, - blockingStubFull)); + ECKey ecKey4 = new ECKey(Utils.getRandom()); + byte[] newAddress = ecKey4.getAddress(); + String newKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); + ECKey ecKey3 = new ECKey(Utils.getRandom()); + byte[] ownerAddress = ecKey3.getAddress(); + + Assert.assertTrue( + PublicMethod.sendcoin( + ownerAddress, 9968981537400L, foundationAddress, testKey002, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] manager1Address = ecKey1.getAddress(); - String manager1Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] manager1Address = ecKey1.getAddress(); + String manager1Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); String[] permissionKeyString = new String[3]; permissionKeyString[0] = manager1Key; - ECKey ecKey2 = new ECKey(Utils.getRandom()); - byte[] manager2Address = ecKey2.getAddress(); - String manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] manager2Address = ecKey2.getAddress(); + String manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); permissionKeyString[1] = manager2Key; - String ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); + String ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); permissionKeyString[2] = ownerKey; String[] ownerKeyString = new String[1]; ownerKeyString[0] = ownerKey; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":3,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(ownerKey) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}]}," + + "{\"address\":\"" + + PublicMethod.getAddressString(ownerKey) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - PublicMethodForMultiSign.accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, - blockingStubFull, ownerKeyString); - //permissionKeyString[0] = ownerKey; + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, ownerAddress, ownerKey, blockingStubFull, ownerKeyString); + // permissionKeyString[0] = ownerKey; String[] ownerKeyString1 = new String[3]; ownerKeyString1[0] = ownerKey; @@ -92,25 +103,28 @@ public void testMultiSignForAccount() { PublicMethodForMultiSign.freezeBalanceGetEnergy( ownerAddress, 1000000L, 0, 1, ownerKey, blockingStubFull, ownerKeyString1); PublicMethodForMultiSign.freezeBalanceForReceiver( - ownerAddress, 1000000L, 0, 0, ByteString.copyFrom(newAddress), - ownerKey, blockingStubFull, ownerKeyString1); + ownerAddress, + 1000000L, + 0, + 0, + ByteString.copyFrom(newAddress), + ownerKey, + blockingStubFull, + ownerKeyString1); PublicMethodForMultiSign.unFreezeBalance( ownerAddress, ownerKey, 0, null, blockingStubFull, ownerKeyString1); PublicMethodForMultiSign.unFreezeBalance( ownerAddress, ownerKey, 0, newAddress, blockingStubFull, ownerKeyString1); PublicMethodForMultiSign.updateAccount( - ownerAddress, Long.toString(System.currentTimeMillis()).getBytes(), ownerKey, - blockingStubFull, ownerKeyString1); + ownerAddress, + Long.toString(System.currentTimeMillis()).getBytes(), + ownerKey, + blockingStubFull, + ownerKeyString1); } - - } - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/TestNetErc721Cat.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/TestNetErc721Cat.java index 39d40bd2..7b041e32 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/TestNetErc721Cat.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/TestNetErc721Cat.java @@ -15,18 +15,18 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class TestNetErc721Cat extends TronBaseTest { - //testng001、testng002、testng003、testng004 - //testng001、testng002、testng003、testng004 + // testng001、testng002、testng003、testng004 + // testng001、testng002、testng003、testng004 private final String testKey002 = - //"7306c6044ad7c03709980aa188b8555288b7e0608f5edbf76ff2381c5a7a15a8"; - //"3a54ba30e3ee41b602eca8fb3a3ca1f99f49a3d3ab5d8d646a2ccdd3ffd9c21d"; - //foundationAddress + // "7306c6044ad7c03709980aa188b8555288b7e0608f5edbf76ff2381c5a7a15a8"; + // "3a54ba30e3ee41b602eca8fb3a3ca1f99f49a3d3ab5d8d646a2ccdd3ffd9c21d"; + // foundationAddress "FC8BF0238748587B9617EB6D15D47A66C0E07C1A1959033CF249C6532DC29FE6"; String kittyCoreAddressAndCut = ""; byte[] kittyCoreContractAddress = null; @@ -44,21 +44,22 @@ public class TestNetErc721Cat extends TronBaseTest { byte[] triggerAddress = ecKey2.getAddress(); String triggerKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = false) public void beforeClass() { PublicMethod.printAddress(deployKey); - PublicMethod.printAddress(triggerKey); Assert.assertTrue(PublicMethod.sendcoin(deployAddress, 50000000000L, foundationAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.sendcoin(triggerAddress, 50000000000L, foundationAddress, - testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(deployAddress, 100000000L, - 3, 1, deployKey, blockingStubFull)); + PublicMethod.printAddress(triggerKey); + Assert.assertTrue( + PublicMethod.sendcoin( + deployAddress, 50000000000L, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + triggerAddress, 50000000000L, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + deployAddress, 100000000L, 3, 1, deployKey, blockingStubFull)); /* Assert.assertTrue(PublicMethod.freezeBalanceGetCpu(triggerAddress,100000000L, - 3,1,triggerKey,blockingStubFull));*/ + 3,1,triggerKey,blockingStubFull));*/ /*Assert.assertTrue(PublicMethod.buyStorage(500000000L,deployAddress,deployKey, blockingStubFull)); Assert.assertTrue(PublicMethod.buyStorage(500000000L,triggerAddress,triggerKey, @@ -70,269 +71,422 @@ public void beforeClass() { } - @Test(enabled = false, groups = {"stress"}) + @Test( + enabled = false, + groups = {"stress"}) public void deployErc721KittyCore() { - AccountResourceMessage accountResource = PublicMethod.getAccountResource(deployAddress, - blockingStubFull); - Long cpuLimit = accountResource.getEnergyLimit(); - //Long storageLimit = accountResource.getStorageLimit(); - Long cpuUsage = accountResource.getEnergyUsed(); - //Long storageUsage = accountResource.getStorageUsed(); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(deployAddress, blockingStubFull); + Long cpuLimit = accountResource.getEnergyLimit(); + // Long storageLimit = accountResource.getStorageLimit(); + Long cpuUsage = accountResource.getEnergyUsed(); + // Long storageUsage = accountResource.getStorageUsed(); Account account = PublicMethod.queryAccount(deployAddress, blockingStubFull); logger.info("before balance is " + Long.toString(account.getBalance())); logger.info("before cpu limit is " + Long.toString(cpuLimit)); logger.info("before cpu usage is " + Long.toString(cpuUsage)); - //logger.info("before storage limit is " + Long.toString(storageLimit)); - //logger.info("before storage usaged is " + Long.toString(storageUsage)); - Long maxFeeLimit = 3900000000L; - String contractName = "KittyCore"; - String code = Configuration.getByPath("testng.conf") - .getString("code.code_TestNetErc721Cat_deployErc721KittyCore"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_TestNetErc721Cat_deployErc721KittyCore"); + // logger.info("before storage limit is " + Long.toString(storageLimit)); + // logger.info("before storage usaged is " + Long.toString(storageUsage)); + Long maxFeeLimit = 3900000000L; + String contractName = "KittyCore"; + String code = + Configuration.getByPath("testng.conf") + .getString("code.code_TestNetErc721Cat_deployErc721KittyCore"); + String abi = + Configuration.getByPath("testng.conf") + .getString("abi.abi_TestNetErc721Cat_deployErc721KittyCore"); logger.info("Kitty Core"); - kittyCoreContractAddress = PublicMethod.deployContract(contractName, abi, code, "", - maxFeeLimit, 0L, consumeUserResourcePercent, null, deployKey, - deployAddress, blockingStubFull); - SmartContract smartContract = PublicMethod.getContract(kittyCoreContractAddress, - blockingStubFull); + kittyCoreContractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + consumeUserResourcePercent, + null, + deployKey, + deployAddress, + blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(kittyCoreContractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi() != null); accountResource = PublicMethod.getAccountResource(deployAddress, blockingStubFull); cpuLimit = accountResource.getEnergyLimit(); - //storageLimit = accountResource.getStorageLimit(); + // storageLimit = accountResource.getStorageLimit(); cpuUsage = accountResource.getEnergyUsed(); - //storageUsage = accountResource.getStorageUsed(); + // storageUsage = accountResource.getStorageUsed(); account = PublicMethod.queryAccount(deployKey, blockingStubFull); logger.info("after balance is " + Long.toString(account.getBalance())); logger.info("after cpu limit is " + Long.toString(cpuLimit)); logger.info("after cpu usage is " + Long.toString(cpuUsage)); - //logger.info("after storage limit is " + Long.toString(storageLimit)); - //logger.info("after storage usaged is " + Long.toString(storageUsage)); + // logger.info("after storage limit is " + Long.toString(storageLimit)); + // logger.info("after storage usaged is " + Long.toString(storageUsage)); logger.info(ByteArray.toHexString(kittyCoreContractAddress)); logger.info(ByteArray.toHexString(kittyCoreContractAddress).substring(2)); - kittyCoreAddressAndCut = "000000000000000000000000" + ByteArray - .toHexString(kittyCoreContractAddress).substring(2); - kittyCoreAddressAndCut = kittyCoreAddressAndCut + "0000000000000000000000000000000000000000000" - + "000000000000000000100"; + kittyCoreAddressAndCut = + "000000000000000000000000" + ByteArray.toHexString(kittyCoreContractAddress).substring(2); + kittyCoreAddressAndCut = + kittyCoreAddressAndCut + + "0000000000000000000000000000000000000000000" + + "000000000000000000100"; } - @Test(enabled = false, groups = {"stress"}) + @Test( + enabled = false, + groups = {"stress"}) public void deploySaleClockAuction() { - AccountResourceMessage accountResource = PublicMethod.getAccountResource(deployAddress, - blockingStubFull); - Long cpuLimit = accountResource.getEnergyLimit(); - //Long storageLimit = accountResource.getStorageLimit(); - Long cpuUsage = accountResource.getEnergyUsed(); - //Long storageUsage = accountResource.getStorageUsed(); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(deployAddress, blockingStubFull); + Long cpuLimit = accountResource.getEnergyLimit(); + // Long storageLimit = accountResource.getStorageLimit(); + Long cpuUsage = accountResource.getEnergyUsed(); + // Long storageUsage = accountResource.getStorageUsed(); Account account = PublicMethod.queryAccount(deployKey, blockingStubFull); logger.info("before balance is " + Long.toString(account.getBalance())); logger.info("before cpu limit is " + Long.toString(cpuLimit)); logger.info("before cpu usage is " + Long.toString(cpuUsage)); - //logger.info("before storage limit is " + Long.toString(storageLimit)); - //logger.info("before storage usaged is " + Long.toString(storageUsage)); - Long maxFeeLimit = 3900000000L; - String contractName = "SaleClockAuction"; + // logger.info("before storage limit is " + Long.toString(storageLimit)); + // logger.info("before storage usaged is " + Long.toString(storageUsage)); + Long maxFeeLimit = 3900000000L; + String contractName = "SaleClockAuction"; logger.info("Sale Clock Auction"); - String code = Configuration.getByPath("testng.conf") - .getString("code.code_TestNetErc721Cat_deploySaleClockAuction"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_TestNetErc721Cat_deploySaleClockAuction"); - saleClockAuctionContractAddress = PublicMethod.deployContract(contractName, abi, code, - "", maxFeeLimit, 0L, consumeUserResourcePercent, null, deployKey, - deployAddress, blockingStubFull); - SmartContract smartContract = PublicMethod.getContract(saleClockAuctionContractAddress, - blockingStubFull); + String code = + Configuration.getByPath("testng.conf") + .getString("code.code_TestNetErc721Cat_deploySaleClockAuction"); + String abi = + Configuration.getByPath("testng.conf") + .getString("abi.abi_TestNetErc721Cat_deploySaleClockAuction"); + saleClockAuctionContractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + consumeUserResourcePercent, + null, + deployKey, + deployAddress, + blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(saleClockAuctionContractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi() != null); accountResource = PublicMethod.getAccountResource(deployAddress, blockingStubFull); cpuLimit = accountResource.getEnergyLimit(); - //storageLimit = accountResource.getStorageLimit(); + // storageLimit = accountResource.getStorageLimit(); cpuUsage = accountResource.getEnergyUsed(); - //storageUsage = accountResource.getStorageUsed(); + // storageUsage = accountResource.getStorageUsed(); account = PublicMethod.queryAccount(deployKey, blockingStubFull); logger.info("after balance is " + Long.toString(account.getBalance())); logger.info("after cpu limit is " + Long.toString(cpuLimit)); logger.info("after cpu usage is " + Long.toString(cpuUsage)); - //logger.info("after storage limit is " + Long.toString(storageLimit)); - //logger.info("after storage usaged is " + Long.toString(storageUsage)); + // logger.info("after storage limit is " + Long.toString(storageLimit)); + // logger.info("after storage usaged is " + Long.toString(storageUsage)); } - @Test(enabled = false, groups = {"stress"}) + @Test( + enabled = false, + groups = {"stress"}) public void deploySiringClockAuction() { - AccountResourceMessage accountResource = PublicMethod.getAccountResource(deployAddress, - blockingStubFull); - Long cpuLimit = accountResource.getEnergyLimit(); - //Long storageLimit = accountResource.getStorageLimit(); - Long cpuUsage = accountResource.getEnergyUsed(); - //Long storageUsage = accountResource.getStorageUsed(); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(deployAddress, blockingStubFull); + Long cpuLimit = accountResource.getEnergyLimit(); + // Long storageLimit = accountResource.getStorageLimit(); + Long cpuUsage = accountResource.getEnergyUsed(); + // Long storageUsage = accountResource.getStorageUsed(); Account account = PublicMethod.queryAccount(deployKey, blockingStubFull); logger.info("before balance is " + Long.toString(account.getBalance())); logger.info("before cpu limit is " + Long.toString(cpuLimit)); logger.info("before cpu usage is " + Long.toString(cpuUsage)); - //logger.info("before storage limit is " + Long.toString(storageLimit)); - //logger.info("before storage usaged is " + Long.toString(storageUsage)); - Long maxFeeLimit = 3900000000L; - String contractName = "SiringClockAuction"; - String code = Configuration.getByPath("testng.conf") - .getString("code.code_TestNetErc721Cat_deploySiringClockAuction"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_TestNetErc721Cat_deploySiringClockAuction"); + // logger.info("before storage limit is " + Long.toString(storageLimit)); + // logger.info("before storage usaged is " + Long.toString(storageUsage)); + Long maxFeeLimit = 3900000000L; + String contractName = "SiringClockAuction"; + String code = + Configuration.getByPath("testng.conf") + .getString("code.code_TestNetErc721Cat_deploySiringClockAuction"); + String abi = + Configuration.getByPath("testng.conf") + .getString("abi.abi_TestNetErc721Cat_deploySiringClockAuction"); logger.info("Siring Clock Auction"); - siringClockAuctionContractAddress = PublicMethod.deployContract(contractName, abi, code, - "", maxFeeLimit, 0L, consumeUserResourcePercent, null, deployKey, - deployAddress, blockingStubFull); - SmartContract smartContract = PublicMethod.getContract(siringClockAuctionContractAddress, - blockingStubFull); + siringClockAuctionContractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + consumeUserResourcePercent, + null, + deployKey, + deployAddress, + blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(siringClockAuctionContractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi() != null); accountResource = PublicMethod.getAccountResource(deployAddress, blockingStubFull); cpuLimit = accountResource.getEnergyLimit(); - //storageLimit = accountResource.getStorageLimit(); + // storageLimit = accountResource.getStorageLimit(); cpuUsage = accountResource.getEnergyUsed(); - //storageUsage = accountResource.getStorageUsed(); + // storageUsage = accountResource.getStorageUsed(); account = PublicMethod.queryAccount(deployKey, blockingStubFull); logger.info("after balance is " + Long.toString(account.getBalance())); logger.info("after cpu limit is " + Long.toString(cpuLimit)); logger.info("after cpu usage is " + Long.toString(cpuUsage)); - //logger.info("after storage limit is " + Long.toString(storageLimit)); - //logger.info("after storage usaged is " + Long.toString(storageUsage)); + // logger.info("after storage limit is " + Long.toString(storageLimit)); + // logger.info("after storage usaged is " + Long.toString(storageUsage)); } - @Test(enabled = false, groups = {"stress"}) + @Test( + enabled = false, + groups = {"stress"}) public void deployGeneScienceInterface() { - AccountResourceMessage accountResource = PublicMethod.getAccountResource(deployAddress, - blockingStubFull); - Long cpuLimit = accountResource.getEnergyLimit(); - //Long storageLimit = accountResource.getStorageLimit(); - Long cpuUsage = accountResource.getEnergyUsed(); - //Long storageUsage = accountResource.getStorageUsed(); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(deployAddress, blockingStubFull); + Long cpuLimit = accountResource.getEnergyLimit(); + // Long storageLimit = accountResource.getStorageLimit(); + Long cpuUsage = accountResource.getEnergyUsed(); + // Long storageUsage = accountResource.getStorageUsed(); Account account = PublicMethod.queryAccount(deployKey, blockingStubFull); logger.info("before balance is " + Long.toString(account.getBalance())); logger.info("before cpu limit is " + Long.toString(cpuLimit)); logger.info("before cpu usage is " + Long.toString(cpuUsage)); - //logger.info("before storage limit is " + Long.toString(storageLimit)); - //logger.info("before storage usaged is " + Long.toString(storageUsage)); - Long maxFeeLimit = 3900000000L; - String contractName = "GeneScienceInterface"; - String code = Configuration.getByPath("testng.conf") - .getString("code.code_TestNetErc721Cat_deployGeneScienceInterface"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_TestNetErc721Cat_deployGeneScienceInterface"); + // logger.info("before storage limit is " + Long.toString(storageLimit)); + // logger.info("before storage usaged is " + Long.toString(storageUsage)); + Long maxFeeLimit = 3900000000L; + String contractName = "GeneScienceInterface"; + String code = + Configuration.getByPath("testng.conf") + .getString("code.code_TestNetErc721Cat_deployGeneScienceInterface"); + String abi = + Configuration.getByPath("testng.conf") + .getString("abi.abi_TestNetErc721Cat_deployGeneScienceInterface"); logger.info("gene Science Interface"); - geneScienceInterfaceContractAddress = PublicMethod.deployContract(contractName, abi, code, - "", maxFeeLimit, - 0L, consumeUserResourcePercent, null, deployKey, deployAddress, blockingStubFull); - SmartContract smartContract = PublicMethod.getContract(geneScienceInterfaceContractAddress, - blockingStubFull); + geneScienceInterfaceContractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + consumeUserResourcePercent, + null, + deployKey, + deployAddress, + blockingStubFull); + SmartContract smartContract = + PublicMethod.getContract(geneScienceInterfaceContractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi() != null); accountResource = PublicMethod.getAccountResource(deployAddress, blockingStubFull); cpuLimit = accountResource.getEnergyLimit(); - //storageLimit = accountResource.getStorageLimit(); + // storageLimit = accountResource.getStorageLimit(); cpuUsage = accountResource.getEnergyUsed(); - //storageUsage = accountResource.getStorageUsed(); + // storageUsage = accountResource.getStorageUsed(); account = PublicMethod.queryAccount(deployKey, blockingStubFull); logger.info("after balance is " + Long.toString(account.getBalance())); logger.info("after cpu limit is " + Long.toString(cpuLimit)); logger.info("after cpu usage is " + Long.toString(cpuUsage)); - //logger.info("after storage limit is " + Long.toString(storageLimit)); - //logger.info("after storage usaged is " + Long.toString(storageUsage)); + // logger.info("after storage limit is " + Long.toString(storageLimit)); + // logger.info("after storage usaged is " + Long.toString(storageUsage)); } - @Test(enabled = false, groups = {"stress"}) + @Test( + enabled = false, + groups = {"stress"}) public void triggerToSetThreeContractAddressToKittyCore() { - //Set SaleAuctionAddress to kitty core. + // Set SaleAuctionAddress to kitty core. String saleContractString = "\"" + Base58.encode58Check(saleClockAuctionContractAddress) + "\""; - txid = PublicMethod.triggerContract(kittyCoreContractAddress, "setSaleAuctionAddress(address)", - saleContractString, false, 0, 10000000L, deployAddress, deployKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "setSaleAuctionAddress(address)", + saleContractString, + false, + 0, + 10000000L, + deployAddress, + deployKey, + blockingStubFull); logger.info(txid); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - //Assert.assertTrue(infoById.get().getReceipt().getStorageDelta() > 50); - //Set SiringAuctionAddress to kitty core. - String siringContractString = "\"" + Base58.encode58Check(siringClockAuctionContractAddress) - + "\""; - txid = PublicMethod - .triggerContract(kittyCoreContractAddress, "setSiringAuctionAddress(address)", - siringContractString, false, 0, 10000000L, - deployAddress, deployKey, blockingStubFull); + // Assert.assertTrue(infoById.get().getReceipt().getStorageDelta() > 50); + // Set SiringAuctionAddress to kitty core. + String siringContractString = + "\"" + Base58.encode58Check(siringClockAuctionContractAddress) + "\""; + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "setSiringAuctionAddress(address)", + siringContractString, + false, + 0, + 10000000L, + deployAddress, + deployKey, + blockingStubFull); logger.info(txid); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - //Assert.assertTrue(infoById.get().getReceipt().getStorageDelta() > 50); - //Set gen contract to kitty core - String genContractString = "\"" + Base58.encode58Check(geneScienceInterfaceContractAddress) - + "\""; - txid = PublicMethod.triggerContract(kittyCoreContractAddress, - "setGeneScienceAddress(address)", genContractString, - false, 0, 10000000L, deployAddress, deployKey, blockingStubFull); + // Assert.assertTrue(infoById.get().getReceipt().getStorageDelta() > 50); + // Set gen contract to kitty core + String genContractString = + "\"" + Base58.encode58Check(geneScienceInterfaceContractAddress) + "\""; + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "setGeneScienceAddress(address)", + genContractString, + false, + 0, + 10000000L, + deployAddress, + deployKey, + blockingStubFull); logger.info(txid); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - //Assert.assertTrue(infoById.get().getReceipt().getStorageDelta() > 50); - //Start the game. - txid = PublicMethod.triggerContract(kittyCoreContractAddress, "unpause()", "", false, 0, - 10000000L, deployAddress, deployKey, blockingStubFull); + // Assert.assertTrue(infoById.get().getReceipt().getStorageDelta() > 50); + // Start the game. + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "unpause()", + "", + false, + 0, + 10000000L, + deployAddress, + deployKey, + blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); logger.info("start the game " + txid); - //Create one gen0 cat. - txid = PublicMethod.triggerContract(kittyCoreContractAddress, - "createGen0Auction(uint256)", "-1000000000000000", false, - 0, 100000000L, deployAddress, deployKey, blockingStubFull); + // Create one gen0 cat. + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "createGen0Auction(uint256)", + "-1000000000000000", + false, + 0, + 100000000L, + deployAddress, + deployKey, + blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - txid = PublicMethod.triggerContract(kittyCoreContractAddress, - "gen0CreatedCount()", "#", false, - 0, 100000000L, deployAddress, deployKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "gen0CreatedCount()", + "#", + false, + 0, + 100000000L, + deployAddress, + deployKey, + blockingStubFull); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); /* txid = PublicMethod.triggerContract(kittyCoreContractAddress, - "name()","#",false,0,10000000,triggerAddress, - triggerKey,blockingStubFull); - logger.info("getname " + txid);*/ + "name()","#",false,0,10000000,triggerAddress, + triggerKey,blockingStubFull); + logger.info("getname " + txid);*/ - txid = PublicMethod.triggerContract(kittyCoreContractAddress, - "getKitty(uint256)", "1", false, 0, 10000000, triggerAddress, - triggerKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "getKitty(uint256)", + "1", + false, + 0, + 10000000, + triggerAddress, + triggerKey, + blockingStubFull); logger.info("getKitty " + txid); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - String newCxoAddress = "\"" + Base58.encode58Check(triggerAddress) - + "\""; + String newCxoAddress = "\"" + Base58.encode58Check(triggerAddress) + "\""; - txid = PublicMethod.triggerContract(kittyCoreContractAddress, - "setCOO(address)", newCxoAddress, false, 0, 10000000, deployAddress, - deployKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "setCOO(address)", + newCxoAddress, + false, + 0, + 10000000, + deployAddress, + deployKey, + blockingStubFull); logger.info("COO " + txid); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - txid = PublicMethod.triggerContract(kittyCoreContractAddress, - "setCFO(address)", newCxoAddress, false, 0, 10000000, deployAddress, - deployKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "setCFO(address)", + newCxoAddress, + false, + 0, + 10000000, + deployAddress, + deployKey, + blockingStubFull); logger.info("CFO " + txid); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - txid = PublicMethod.triggerContract(kittyCoreContractAddress, - "setCEO(address)", newCxoAddress, false, 0, 1000000, deployAddress, - deployKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "setCEO(address)", + newCxoAddress, + false, + 0, + 1000000, + deployAddress, + deployKey, + blockingStubFull); logger.info("CEO " + txid); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); } - @Test(enabled = false, threadPoolSize = 1, invocationCount = 1, groups = {"stress"}) + @Test( + enabled = false, + threadPoolSize = 1, + invocationCount = 1, + groups = {"stress"}) public void unCreateKitty() { Integer times = 0; - logger.info("In create kitty, kitty core address is " + ByteArray - .toHexString(kittyCoreContractAddress)); + logger.info( + "In create kitty, kitty core address is " + + ByteArray.toHexString(kittyCoreContractAddress)); while (times++ < 20) { - txid = PublicMethod.triggerContract(kittyCoreContractAddress, - "createGen0Auction(uint256)", "0", false, - 0, 100000000L, triggerAddress, triggerKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + kittyCoreContractAddress, + "createGen0Auction(uint256)", + "0", + false, + 0, + 100000000L, + triggerAddress, + triggerKey, + blockingStubFull); logger.info("createGen0 " + txid); infoById = PublicMethod.getTransactionInfoById(txid, blockingStubFull); - //Assert.assertTrue(infoById.get().getResultValue() == 0); + // Assert.assertTrue(infoById.get().getResultValue() == 0); /* String promoKitty = "\"" + times.toString() + "\",\"" + Base58.encode58Check(kittyCoreContractAddress) + "\""; logger.info(promoKitty); @@ -347,17 +501,10 @@ public void unCreateKitty() { } catch (InterruptedException e) { e.printStackTrace(); } - } - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/TestNetFomo3D.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/TestNetFomo3D.java index d6a64543..c65cb570 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/TestNetFomo3D.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/TestNetFomo3D.java @@ -24,108 +24,145 @@ @Slf4j public class TestNetFomo3D extends TronBaseTest { - //testng001、testng002、testng003、testng004 are only for test + // testng001、testng002、testng003、testng004 are only for test private final String testNetAccountKey = "FC8BF0238748587B9617EB6D15D47A66C0E07C1A1959033CF249C6532DC29FE6"; - //"BC70ADC5A0971BA3F7871FBB7249E345D84CE7E5458828BE1E28BF8F98F2795B"; + // "BC70ADC5A0971BA3F7871FBB7249E345D84CE7E5458828BE1E28BF8F98F2795B"; private final byte[] testNetAccountAddress = PublicMethod.getFinalAddress(testNetAccountKey); Optional infoById = null; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = false) public void beforeClass() { - PublicMethod.printAddress(testNetAccountKey); logger.info(Long.toString(PublicMethod.queryAccount(testNetAccountKey, blockingStubFull) - .getBalance())); - //Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(testNetAccountAddress,10000000L, - //3,1,testNetAccountKey,blockingStubFull)); + PublicMethod.printAddress(testNetAccountKey); + logger.info( + Long.toString(PublicMethod.queryAccount(testNetAccountKey, blockingStubFull).getBalance())); + // Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(testNetAccountAddress,10000000L, + // 3,1,testNetAccountKey,blockingStubFull)); /* Assert.assertTrue(PublicMethod.buyStorage(50000000L,testNetAccountAddress, testNetAccountKey, blockingStubFull));*/ } - @Test(enabled = false, groups = {"stress"}) + @Test( + enabled = false, + groups = {"stress"}) public void deployErc721CryptoKitties() { - AccountResourceMessage accountResource = PublicMethod.getAccountResource(testNetAccountAddress, - blockingStubFull); - Long cpuLimit = accountResource.getEnergyLimit(); - //Long storageLimit = accountResource.getStorageLimit(); - Long cpuUsage = accountResource.getEnergyUsed(); - //Long storageUsage = accountResource.getStorageUsed(); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(testNetAccountAddress, blockingStubFull); + Long cpuLimit = accountResource.getEnergyLimit(); + // Long storageLimit = accountResource.getStorageLimit(); + Long cpuUsage = accountResource.getEnergyUsed(); + // Long storageUsage = accountResource.getStorageUsed(); Account account = PublicMethod.queryAccount(testNetAccountKey, blockingStubFull); logger.info("before balance is " + Long.toString(account.getBalance())); logger.info("before cpu limit is " + Long.toString(cpuLimit)); logger.info("before cpu usage is " + Long.toString(cpuUsage)); - //logger.info("before storage limit is " + Long.toString(storageLimit)); - //logger.info("before storage usaged is " + Long.toString(storageUsage)); - Long maxFeeLimit = 3900000000L; - String contractName = "Fomo3D"; - String code = Configuration.getByPath("testng.conf") - .getString("code.code_TestNetFomo3D_deployErc721CryptoKitties"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_TestNetFomo3D_deployErc721CryptoKitties"); - byte[] contractAddress = PublicMethod.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testNetAccountKey, testNetAccountAddress, blockingStubFull); - String code1 = Configuration.getByPath("testng.conf") - .getString("code.code1_TestNetFomo3D_deployErc721CryptoKitties"); - String abi1 = Configuration.getByPath("testng.conf") - .getString("abi.abi1_TestNetFomo3D_deployErc721CryptoKitties"); - String txid = PublicMethod.deployContractAndGetTransactionInfoById(contractName, abi1, - code1, "", maxFeeLimit, 0L, 100, null, - testNetAccountKey, testNetAccountAddress, blockingStubFull); - final SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); + // logger.info("before storage limit is " + Long.toString(storageLimit)); + // logger.info("before storage usaged is " + Long.toString(storageUsage)); + Long maxFeeLimit = 3900000000L; + String contractName = "Fomo3D"; + String code = + Configuration.getByPath("testng.conf") + .getString("code.code_TestNetFomo3D_deployErc721CryptoKitties"); + String abi = + Configuration.getByPath("testng.conf") + .getString("abi.abi_TestNetFomo3D_deployErc721CryptoKitties"); + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testNetAccountKey, + testNetAccountAddress, + blockingStubFull); + String code1 = + Configuration.getByPath("testng.conf") + .getString("code.code1_TestNetFomo3D_deployErc721CryptoKitties"); + String abi1 = + Configuration.getByPath("testng.conf") + .getString("abi.abi1_TestNetFomo3D_deployErc721CryptoKitties"); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi1, + code1, + "", + maxFeeLimit, + 0L, + 100, + null, + testNetAccountKey, + testNetAccountAddress, + blockingStubFull); + final SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); accountResource = PublicMethod.getAccountResource(testNetAccountAddress, blockingStubFull); cpuLimit = accountResource.getEnergyLimit(); - //storageLimit = accountResource.getStorageLimit(); + // storageLimit = accountResource.getStorageLimit(); cpuUsage = accountResource.getEnergyUsed(); - //storageUsage = accountResource.getStorageUsed(); + // storageUsage = accountResource.getStorageUsed(); account = PublicMethod.queryAccount(testNetAccountKey, blockingStubFull); logger.info("after balance is " + Long.toString(account.getBalance())); logger.info("after cpu limit is " + Long.toString(cpuLimit)); logger.info("after cpu usage is " + Long.toString(cpuUsage)); - //logger.info("after storage limit is " + Long.toString(storageLimit)); - //logger.info("after storage usaged is " + Long.toString(storageUsage)); - //Assert.assertTrue(storageUsage > 0); - //Assert.assertTrue(storageLimit > 0); + // logger.info("after storage limit is " + Long.toString(storageLimit)); + // logger.info("after storage usaged is " + Long.toString(storageUsage)); + // Assert.assertTrue(storageUsage > 0); + // Assert.assertTrue(storageLimit > 0); Assert.assertTrue(cpuLimit > 0); Assert.assertTrue(cpuUsage > 0); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - //logger.info(smartContract.getName()); - //logger.info(smartContract.getAbi().toString()); + // logger.info(smartContract.getName()); + // logger.info(smartContract.getAbi().toString()); } - @Test(enabled = false, groups = {"stress"}) + @Test( + enabled = false, + groups = {"stress"}) public void tooLargeStorage() throws IOException { - AccountResourceMessage accountResource = PublicMethod.getAccountResource(testNetAccountAddress, - blockingStubFull); - Long cpuLimit = accountResource.getEnergyLimit(); - Long cpuUsage = accountResource.getEnergyUsed(); + AccountResourceMessage accountResource = + PublicMethod.getAccountResource(testNetAccountAddress, blockingStubFull); + Long cpuLimit = accountResource.getEnergyLimit(); + Long cpuUsage = accountResource.getEnergyUsed(); Account account = PublicMethod.queryAccount(testNetAccountKey, blockingStubFull); logger.info("before balance is " + Long.toString(account.getBalance())); logger.info("before cpu limit is " + Long.toString(cpuLimit)); logger.info("before cpu usage is " + Long.toString(cpuUsage)); - Long maxFeeLimit = 100000000000000000L; - String contractName = "tooLargeStorage"; - String code = Configuration.getByPath("testng.conf") - .getString("code.code_TestNetFomo3D_tooLargeStorage"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_TestNetFomo3D_tooLargeStorage"); - String txid = PublicMethod.deployContractAndGetTransactionInfoById(contractName, abi, - code, "", maxFeeLimit, 0L, 100, null, - testNetAccountKey, testNetAccountAddress, blockingStubFull); + Long maxFeeLimit = 100000000000000000L; + String contractName = "tooLargeStorage"; + String code = + Configuration.getByPath("testng.conf").getString("code.code_TestNetFomo3D_tooLargeStorage"); + String abi = + Configuration.getByPath("testng.conf").getString("abi.abi_TestNetFomo3D_tooLargeStorage"); + String txid = + PublicMethod.deployContractAndGetTransactionInfoById( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + testNetAccountKey, + testNetAccountAddress, + blockingStubFull); infoById = getTransactionInfoById(txid, blockingStubFull); accountResource = PublicMethod.getAccountResource(testNetAccountAddress, blockingStubFull); cpuLimit = accountResource.getEnergyLimit(); - //storageLimit = accountResource.getStorageLimit(); + // storageLimit = accountResource.getStorageLimit(); cpuUsage = accountResource.getEnergyUsed(); - //storageUsage = accountResource.getStorageUsed(); + // storageUsage = accountResource.getStorageUsed(); account = PublicMethod.queryAccount(testNetAccountKey, blockingStubFull); logger.info("after balance is " + Long.toString(account.getBalance())); logger.info("after cpu limit is " + Long.toString(cpuLimit)); @@ -133,34 +170,44 @@ public void tooLargeStorage() throws IOException { /* String name = readFromXieChang();*/ String stringTimes = Integer.toString(7); - byte[] contractAddress = infoById.get().getContractAddress().toByteArray(); - txid = PublicMethod.triggerContract(contractAddress, "slice(uint256)", stringTimes, false, - 0, maxFeeLimit, testNetAccountAddress, testNetAccountKey, blockingStubFull); + byte[] contractAddress = infoById.get().getContractAddress().toByteArray(); + txid = + PublicMethod.triggerContract( + contractAddress, + "slice(uint256)", + stringTimes, + false, + 0, + maxFeeLimit, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); logger.info("slice " + txid); logger.info(Integer.toString(infoById.get().getResultValue())); infoById = getTransactionInfoById(txid, blockingStubFull); - txid = PublicMethod.triggerContract(contractAddress, "s()", "#", false, - 0, maxFeeLimit, testNetAccountAddress, testNetAccountKey, blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "s()", + "#", + false, + 0, + maxFeeLimit, + testNetAccountAddress, + testNetAccountKey, + blockingStubFull); logger.info(txid); logger.info(Integer.toString(infoById.get().getResultValue())); - - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ + /** constructor. */ public String readFromXieChang() throws IOException { - File file = new File( - "/Users/wangzihe/Desktop/ddd.txt"); + File file = new File("/Users/wangzihe/Desktop/ddd.txt"); FileReader reader = null; try { reader = new FileReader(file); @@ -169,7 +216,7 @@ public String readFromXieChang() throws IOException { } BufferedReader reAder = new BufferedReader(reader); StringBuilder sb = new StringBuilder(); - String s = ""; + String s = ""; while ((s = reAder.readLine()) != null) { sb.append(s); } @@ -179,5 +226,3 @@ public String readFromXieChang() throws IOException { return code; } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/TestOperations.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/TestOperations.java index 705ef70e..e5206150 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/TestOperations.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/TestOperations.java @@ -7,26 +7,32 @@ import org.testng.annotations.Test; import stest.tron.wallet.common.client.utils.ByteArray; - @Slf4j public class TestOperations { - @Test(enabled = true, groups = {"stress"}) + @Test( + enabled = true, + groups = {"stress"}) public void test002() { - Integer[] contractId = {0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 30, 31, 32, 33, - 41, 42, 43, 44, 45, 46, 48, 49, 52, 53, 54, 55, 56, 57, 58, 59}; + Integer[] contractId = { + 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 30, 31, 32, 33, 41, 42, + 43, 44, 45, 46, 48, 49, 52, 53, 54, 55, 56, 57, 58, 59 + }; List list = new ArrayList<>(Arrays.asList(contractId)); byte[] operations = new byte[32]; - list.forEach(e -> { - operations[e / 8] |= (1 << e % 8); - }); - //7fff1fc0037ef30f000000000000000000000000000000000000000000000000 + list.forEach( + e -> { + operations[e / 8] |= (1 << e % 8); + }); + // 7fff1fc0037ef30f000000000000000000000000000000000000000000000000 logger.info(ByteArray.toHexString(operations)); } - @Test(enabled = true, groups = {"stress"}) + @Test( + enabled = true, + groups = {"stress"}) public void test003() { - //active default value, without 46 + // active default value, without 46 String operations = "7fff1fc0033ef30f000000000000000000000000000000000000000000000000"; List contractId = new ArrayList<>(); for (int i = 0; i < operations.length(); i = i + 2) { diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/TestStorageAndCpu.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/TestStorageAndCpu.java index 11cd60ce..3b93b684 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/TestStorageAndCpu.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/TestStorageAndCpu.java @@ -40,26 +40,26 @@ public class TestStorageAndCpu extends TronBaseTest { private String fullnode = "47.94.243.150:50051"; private String fullnode1 = "47.94.243.150:50051"; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(witnessKey5); - PublicMethod.printAddress(witnessKey4); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(witnessKey4); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); currentBlock = blockingStubFull1.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); beforeBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); beforeTime = System.currentTimeMillis(); } - @Test(enabled = true,threadPoolSize = 1, invocationCount = 1, groups = {"stress"}) + @Test( + enabled = true, + threadPoolSize = 1, + invocationCount = 1, + groups = {"stress"}) public void scanBlock() { Long startNum = 26165658L; - Long endNum = 26166320L; + Long endNum = 26166320L; Integer totalNum = 0; Integer successNum = 0; Integer failedNum = 0; @@ -67,8 +67,8 @@ public void scanBlock() { while (startNum <= endNum) { logger.info("scan block num:" + startNum); builder.setNum(startNum); - List transactionList = blockingStubFull - .getBlockByNum(builder.build()).getTransactionsList(); + List transactionList = + blockingStubFull.getBlockByNum(builder.build()).getTransactionsList(); Integer transactionNumInThisBlock = transactionList.size(); totalNum = totalNum + transactionNumInThisBlock; for (Transaction transaction : transactionList) { @@ -84,120 +84,155 @@ public void scanBlock() { logger.info("successNum:" + successNum); logger.info("failedNum:" + failedNum); logger.info("totalNum:" + totalNum); - logger.info("Success rate:" + (double)failedNum / (double)totalNum); + logger.info("Success rate:" + (double) failedNum / (double) totalNum); } - @Test(enabled = true, threadPoolSize = 1, invocationCount = 1, groups = {"stress"}) + @Test( + enabled = true, + threadPoolSize = 1, + invocationCount = 1, + groups = {"stress"}) public void storageAndCpu() { Random rand = new Random(); Integer randNum = rand.nextInt(30) + 1; randNum = rand.nextInt(4000); - Long maxFeeLimit = 1000000000L; - String contractName = "StorageAndCpu" + Integer.toString(randNum); - String code = Configuration.getByPath("testng.conf") - .getString("code.code_TestStorageAndCpu_storageAndCpu"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_TestStorageAndCpu_storageAndCpu"); - PublicMethod - .freezeBalanceGetEnergy(foundationAddress, 1000000000000L, 3, 1, witnessKey5, blockingStubFull); - byte[] contractAddress = PublicMethod.deployContract(contractName, abi, code, - "", maxFeeLimit, - 0L, 100, null, witnessKey5, foundationAddress, blockingStubFull); + Long maxFeeLimit = 1000000000L; + String contractName = "StorageAndCpu" + Integer.toString(randNum); + String code = + Configuration.getByPath("testng.conf") + .getString("code.code_TestStorageAndCpu_storageAndCpu"); + String abi = + Configuration.getByPath("testng.conf").getString("abi.abi_TestStorageAndCpu_storageAndCpu"); + PublicMethod.freezeBalanceGetEnergy( + foundationAddress, 1000000000000L, 3, 1, witnessKey5, blockingStubFull); + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + witnessKey5, + foundationAddress, + blockingStubFull); try { Thread.sleep(30000); } catch (InterruptedException e) { e.printStackTrace(); } SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); - String txid; + String txid; - ChainParameters chainParameters = blockingStubFull - .getChainParameters(EmptyMessage.newBuilder().build()); + ChainParameters chainParameters = + blockingStubFull.getChainParameters(EmptyMessage.newBuilder().build()); Optional getChainParameters = Optional.ofNullable(chainParameters); Integer i = 1; while (i++ < 8000) { String initParmes = "\"" + "930" + "\""; - txid = PublicMethod.triggerContract(contractAddress, - "testUseCpu(uint256)", "9100", false, - 0, maxFeeLimit, foundationAddress, witnessKey5, blockingStubFull); - txid = PublicMethod.triggerContract(contractAddress, - "storage8Char()", "", false, - 0, maxFeeLimit, foundationAddress, witnessKey5, blockingStubFull); - //storage 9 EnergyUsageTotal is 211533, 10 is 236674, 5 is 110969,21 is 500000 - txid = PublicMethod.triggerContract(contractAddress, - "testUseStorage(uint256)", "21", false, - 0, maxFeeLimit, foundationAddress, witnessKey5, blockingStubFull); - //logger.info("i is " +Integer.toString(i) + " " + txid); - //txidList.add(txid); + txid = + PublicMethod.triggerContract( + contractAddress, + "testUseCpu(uint256)", + "9100", + false, + 0, + maxFeeLimit, + foundationAddress, + witnessKey5, + blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "storage8Char()", + "", + false, + 0, + maxFeeLimit, + foundationAddress, + witnessKey5, + blockingStubFull); + // storage 9 EnergyUsageTotal is 211533, 10 is 236674, 5 is 110969,21 is 500000 + txid = + PublicMethod.triggerContract( + contractAddress, + "testUseStorage(uint256)", + "21", + false, + 0, + maxFeeLimit, + foundationAddress, + witnessKey5, + blockingStubFull); + // logger.info("i is " +Integer.toString(i) + " " + txid); + // txidList.add(txid); try { Thread.sleep(50); } catch (InterruptedException e) { e.printStackTrace(); } if (i % 10 == 0) { - chainParameters = blockingStubFull - .getChainParameters(EmptyMessage.newBuilder().build()); + chainParameters = blockingStubFull.getChainParameters(EmptyMessage.newBuilder().build()); getChainParameters = Optional.ofNullable(chainParameters); logger.info(getChainParameters.get().getChainParameter(22).getKey()); logger.info(Long.toString(getChainParameters.get().getChainParameter(22).getValue())); logger.info(getChainParameters.get().getChainParameter(23).getKey()); logger.info(Long.toString(getChainParameters.get().getChainParameter(23).getValue())); - } } } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { /* - afterTime = System.currentTimeMillis(); - try { - Thread.sleep(10000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - currentBlock = blockingStubFull1.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - afterBlockNum = currentBlock.getBlockHeader().getRawData().getNumber() + 2; - Long blockNum = beforeBlockNum; - Integer txsNum = 0; - Integer topNum = 0; - Integer totalNum = 0; - Long energyTotal = 0L; - String findOneTxid = ""; + afterTime = System.currentTimeMillis(); + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + currentBlock = blockingStubFull1.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); + afterBlockNum = currentBlock.getBlockHeader().getRawData().getNumber() + 2; + Long blockNum = beforeBlockNum; + Integer txsNum = 0; + Integer topNum = 0; + Integer totalNum = 0; + Long energyTotal = 0L; + String findOneTxid = ""; - NumberMessage.Builder builder = NumberMessage.newBuilder(); - while (blockNum <= afterBlockNum) { - builder.setNum(blockNum); - txsNum = blockingStubFull1.getBlockByNum(builder.build()).getTransactionsCount(); - totalNum = totalNum + txsNum; - if (topNum < txsNum) { - topNum = txsNum; - findOneTxid = ByteArray.toHexString(Sha256Hash.hash(blockingStubFull1 - .getBlockByNum(builder.build()).getTransactionsList().get(2) - .getRawData().toByteArray())); - //logger.info("find one txid is " + findOneTxid); - } + NumberMessage.Builder builder = NumberMessage.newBuilder(); + while (blockNum <= afterBlockNum) { + builder.setNum(blockNum); + txsNum = blockingStubFull1.getBlockByNum(builder.build()).getTransactionsCount(); + totalNum = totalNum + txsNum; + if (topNum < txsNum) { + topNum = txsNum; + findOneTxid = ByteArray.toHexString(Sha256Hash.hash(blockingStubFull1 + .getBlockByNum(builder.build()).getTransactionsList().get(2) + .getRawData().toByteArray())); + //logger.info("find one txid is " + findOneTxid); + } - blockNum++; - } - Long costTime = (afterTime - beforeTime - 31000) / 1000; - logger.info("Duration block num is " + (afterBlockNum - beforeBlockNum - 11)); - logger.info("Cost time are " + costTime); - logger.info("Top block txs num is " + topNum); - logger.info("Total transaction is " + (totalNum - 30)); - logger.info("Average Tps is " + (totalNum / costTime)); + blockNum++; + } + Long costTime = (afterTime - beforeTime - 31000) / 1000; + logger.info("Duration block num is " + (afterBlockNum - beforeBlockNum - 11)); + logger.info("Cost time are " + costTime); + logger.info("Top block txs num is " + topNum); + logger.info("Total transaction is " + (totalNum - 30)); + logger.info("Average Tps is " + (totalNum / costTime)); - infoById = PublicMethod.getTransactionInfoById(findOneTxid, blockingStubFull1); - Long oneEnergyTotal = infoById.get().getReceipt().getEnergyUsageTotal(); - logger.info("EnergyTotal is " + oneEnergyTotal); - logger.info("Average energy is " + oneEnergyTotal * (totalNum / costTime)); -*/ if (channelFull1 != null) { + infoById = PublicMethod.getTransactionInfoById(findOneTxid, blockingStubFull1); + Long oneEnergyTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("EnergyTotal is " + oneEnergyTotal); + logger.info("Average energy is " + oneEnergyTotal * (totalNum / costTime)); + */ + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/TestStorageAndCpuStress.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/TestStorageAndCpuStress.java index a3b93c01..8ef94824 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/TestStorageAndCpuStress.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/TestStorageAndCpuStress.java @@ -70,19 +70,15 @@ public class TestStorageAndCpuStress extends TronBaseTest { Long currentBlockNum; private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode = "47.95.206.44:50051"; + private String fullnode = "47.95.206.44:50051"; private String fullnode1 = "47.95.206.44:50051"; - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { PublicMethod.printAddress(witnessKey5); - PublicMethod.printAddress(witnessKey4); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(witnessKey4); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); currentBlock = blockingStubFull1.getNowBlock(EmptyMessage.newBuilder().build()); beforeBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); @@ -90,121 +86,186 @@ public void beforeClass() { } public static List listForTxid = new ArrayList<>(); - public static HashMap map = new HashMap<>(); - public static HashMap witnessMap = new HashMap<>(); - - @Test(enabled = true,threadPoolSize = 1, invocationCount = 1, groups = {"stress"}) + public static HashMap map = new HashMap<>(); + public static HashMap witnessMap = new HashMap<>(); + + @Test( + enabled = true, + threadPoolSize = 1, + invocationCount = 1, + groups = {"stress"}) public void scanTransaction() { getTxidList(); witnessMap.clear(); map.clear(); - witnessMap.put(5,"41F08012B4881C320EB40B80F1228731898824E09D"); - witnessMap.put(10,"41DF309FEF25B311E7895562BD9E11AAB2A58816D2"); - witnessMap.put(15,"41BB7322198D273E39B940A5A4C955CB7199A0CDEE"); - witnessMap.put(20,"412080D8A0364E82150DD5235CE7A61A7B40F3F9EF"); - witnessMap.put(25,"4173FC381D3E2AFEFCCED94A57D49520291C38AFBB"); - witnessMap.put(30,"41AF6146B0AD9EE8BBEE811D5858F3252666DFC90C"); - witnessMap.put(35,"41AF6A9D9C0636BD9DF74F687B90C6F44C471A6AB3"); - witnessMap.put(40,"41AF730429E4AB7BF7B53FB15ACB1D45EF5B22F463"); - witnessMap.put(45,"41AF4AEA1C4CBCFA681D98C354C142938381C99389"); - witnessMap.put(50,"41AF53DC31D9DE64DFF59A847125EFCA89D97BC86D"); - witnessMap.put(55,"41AF49468FA1BA966244D76F7D0139FC2CA751FAA5"); - witnessMap.put(60,"41AF5360256F958D2A922D160C429F13D432EFC22F"); - witnessMap.put(65,"41AF5EF33FD79FECB0419A5688035D7BCD3AEFE236"); - witnessMap.put(70,"41AF68F90ED62BA9F6F7A7EABA384E417551CF83E5"); - witnessMap.put(75,"41AF619F8CE75A9E95A19E851BEBE63E89FCB1826E"); - witnessMap.put(80,"41AF71E98F91515D7E5D5379837B9EEFD1AB4650D2"); - witnessMap.put(85,"41AF498B43EE098B26926798CFEAE1AB1154EF4430"); - witnessMap.put(90,"41AF536672333170CB0FBFA78819CD90A05537D872"); - witnessMap.put(95,"41AF5FAC2D62DD1F5C9892BA9D6593337ABBEAAACB"); - witnessMap.put(100,"41AF6981D4562E7B0A6C9E8F8C22D4CCCD03D2F39A"); - witnessMap.put(105,"41AF72A34243836238A533B7E77F3B2B29FD056B14"); - witnessMap.put(110,"41AF49C25D14AED36186B7C89AF405EF37A01EF23D"); - witnessMap.put(115,"41AF53BA37D394575CAD99A2A2C5BE56DEA0227C87"); - witnessMap.put(120,"41AF6A761C941AE2CDC75890D9900AC4B89B7EFCDD"); - witnessMap.put(125,"41AF72B56845F0C4D37388B6E6DC3601A0538ABA71"); - witnessMap.put(130,"41AF4ACF25C1E192285C9BA98522CB3CF20FFBE392"); - witnessMap.put(100000,"416C0214C9995C6F3A61AB23F0EB84B0CDE7FD9C7C"); + witnessMap.put(5, "41F08012B4881C320EB40B80F1228731898824E09D"); + witnessMap.put(10, "41DF309FEF25B311E7895562BD9E11AAB2A58816D2"); + witnessMap.put(15, "41BB7322198D273E39B940A5A4C955CB7199A0CDEE"); + witnessMap.put(20, "412080D8A0364E82150DD5235CE7A61A7B40F3F9EF"); + witnessMap.put(25, "4173FC381D3E2AFEFCCED94A57D49520291C38AFBB"); + witnessMap.put(30, "41AF6146B0AD9EE8BBEE811D5858F3252666DFC90C"); + witnessMap.put(35, "41AF6A9D9C0636BD9DF74F687B90C6F44C471A6AB3"); + witnessMap.put(40, "41AF730429E4AB7BF7B53FB15ACB1D45EF5B22F463"); + witnessMap.put(45, "41AF4AEA1C4CBCFA681D98C354C142938381C99389"); + witnessMap.put(50, "41AF53DC31D9DE64DFF59A847125EFCA89D97BC86D"); + witnessMap.put(55, "41AF49468FA1BA966244D76F7D0139FC2CA751FAA5"); + witnessMap.put(60, "41AF5360256F958D2A922D160C429F13D432EFC22F"); + witnessMap.put(65, "41AF5EF33FD79FECB0419A5688035D7BCD3AEFE236"); + witnessMap.put(70, "41AF68F90ED62BA9F6F7A7EABA384E417551CF83E5"); + witnessMap.put(75, "41AF619F8CE75A9E95A19E851BEBE63E89FCB1826E"); + witnessMap.put(80, "41AF71E98F91515D7E5D5379837B9EEFD1AB4650D2"); + witnessMap.put(85, "41AF498B43EE098B26926798CFEAE1AB1154EF4430"); + witnessMap.put(90, "41AF536672333170CB0FBFA78819CD90A05537D872"); + witnessMap.put(95, "41AF5FAC2D62DD1F5C9892BA9D6593337ABBEAAACB"); + witnessMap.put(100, "41AF6981D4562E7B0A6C9E8F8C22D4CCCD03D2F39A"); + witnessMap.put(105, "41AF72A34243836238A533B7E77F3B2B29FD056B14"); + witnessMap.put(110, "41AF49C25D14AED36186B7C89AF405EF37A01EF23D"); + witnessMap.put(115, "41AF53BA37D394575CAD99A2A2C5BE56DEA0227C87"); + witnessMap.put(120, "41AF6A761C941AE2CDC75890D9900AC4B89B7EFCDD"); + witnessMap.put(125, "41AF72B56845F0C4D37388B6E6DC3601A0538ABA71"); + witnessMap.put(130, "41AF4ACF25C1E192285C9BA98522CB3CF20FFBE392"); + witnessMap.put(100000, "416C0214C9995C6F3A61AB23F0EB84B0CDE7FD9C7C"); for (String txid : listForTxid) { - long blockNum = PublicMethod.getTransactionInfoById(txid,blockingStubFull) - .get().getBlockNumber(); - String witnessAddress = ByteArray.toHexString(PublicMethod - .getBlock(blockNum,blockingStubFull).getBlockHeader().getRawData() - .getWitnessAddress().toByteArray()); - - map.put(witnessAddress.toLowerCase(), map.getOrDefault(witnessAddress,0) + 1); + long blockNum = + PublicMethod.getTransactionInfoById(txid, blockingStubFull).get().getBlockNumber(); + String witnessAddress = + ByteArray.toHexString( + PublicMethod.getBlock(blockNum, blockingStubFull) + .getBlockHeader() + .getRawData() + .getWitnessAddress() + .toByteArray()); + + map.put(witnessAddress.toLowerCase(), map.getOrDefault(witnessAddress, 0) + 1); logger.info("end"); } -// all keys below are for test - int ms_5 = map.containsKey("41F08012B4881C320EB40B80F1228731898824E09D".toLowerCase()) - ? map.get("41F08012B4881C320EB40B80F1228731898824E09D".toLowerCase()) : 0 ; - int ms_10 = map.containsKey("41DF309FEF25B311E7895562BD9E11AAB2A58816D2".toLowerCase()) - ? map.get("41DF309FEF25B311E7895562BD9E11AAB2A58816D2".toLowerCase()) : 0 ; - int ms_15 = map.containsKey("41BB7322198D273E39B940A5A4C955CB7199A0CDEE".toLowerCase()) - ? map.get("41BB7322198D273E39B940A5A4C955CB7199A0CDEE".toLowerCase()) : 0 ; - int ms_20 = map.containsKey("412080D8A0364E82150DD5235CE7A61A7B40F3F9EF".toLowerCase()) - ? map.get("412080D8A0364E82150DD5235CE7A61A7B40F3F9EF".toLowerCase()) : 0 ; - int ms_25 = map.containsKey("4173FC381D3E2AFEFCCED94A57D49520291C38AFBB".toLowerCase()) - ? map.get("4173FC381D3E2AFEFCCED94A57D49520291C38AFBB".toLowerCase()) : 0 ; - int ms_30 = map.containsKey("41AF6146B0AD9EE8BBEE811D5858F3252666DFC90C".toLowerCase()) - ? map.get("41AF6146B0AD9EE8BBEE811D5858F3252666DFC90C".toLowerCase()) : 0 ; - int ms_35 = map.containsKey("41AF6A9D9C0636BD9DF74F687B90C6F44C471A6AB3".toLowerCase()) - ? map.get("41AF6A9D9C0636BD9DF74F687B90C6F44C471A6AB3".toLowerCase()) : 0 ; - int ms_40 = map.containsKey("41AF730429E4AB7BF7B53FB15ACB1D45EF5B22F463".toLowerCase()) - ? map.get("41AF730429E4AB7BF7B53FB15ACB1D45EF5B22F463".toLowerCase()) : 0 ; - int ms_45 = map.containsKey("41AF4AEA1C4CBCFA681D98C354C142938381C99389".toLowerCase()) - ? map.get("41AF4AEA1C4CBCFA681D98C354C142938381C99389".toLowerCase()) : 0 ; - int ms_50 = map.containsKey("41AF53DC31D9DE64DFF59A847125EFCA89D97BC86D".toLowerCase()) - ? map.get("41AF53DC31D9DE64DFF59A847125EFCA89D97BC86D".toLowerCase()) : 0 ; - int ms_55 = map.containsKey("41AF49468FA1BA966244D76F7D0139FC2CA751FAA5".toLowerCase()) - ? map.get("41AF49468FA1BA966244D76F7D0139FC2CA751FAA5".toLowerCase()) : 0 ; - int ms_60 = map.containsKey("41AF5360256F958D2A922D160C429F13D432EFC22F".toLowerCase()) - ? map.get("41AF5360256F958D2A922D160C429F13D432EFC22F".toLowerCase()) : 0 ; - int ms_65 = map.containsKey("41AF5EF33FD79FECB0419A5688035D7BCD3AEFE236".toLowerCase()) - ? map.get("41AF5EF33FD79FECB0419A5688035D7BCD3AEFE236".toLowerCase()) : 0 ; - int ms_70 = map.containsKey("41AF68F90ED62BA9F6F7A7EABA384E417551CF83E5".toLowerCase()) - ? map.get("41AF68F90ED62BA9F6F7A7EABA384E417551CF83E5".toLowerCase()) : 0 ; - int ms_75 = map.containsKey("41AF619F8CE75A9E95A19E851BEBE63E89FCB1826E".toLowerCase()) - ? map.get("41AF619F8CE75A9E95A19E851BEBE63E89FCB1826E".toLowerCase()) : 0 ; - int ms_80 = map.containsKey("41AF71E98F91515D7E5D5379837B9EEFD1AB4650D2".toLowerCase()) - ? map.get("41AF71E98F91515D7E5D5379837B9EEFD1AB4650D2".toLowerCase()) : 0 ; - int ms_85 = map.containsKey("41AF498B43EE098B26926798CFEAE1AB1154EF4430".toLowerCase()) - ? map.get("41AF498B43EE098B26926798CFEAE1AB1154EF4430".toLowerCase()) : 0 ; - int ms_90 = map.containsKey("41AF536672333170CB0FBFA78819CD90A05537D872".toLowerCase()) - ? map.get("41AF536672333170CB0FBFA78819CD90A05537D872".toLowerCase()) : 0 ; - int ms_95 = map.containsKey("41AF5FAC2D62DD1F5C9892BA9D6593337ABBEAAACB".toLowerCase()) - ? map.get("41AF5FAC2D62DD1F5C9892BA9D6593337ABBEAAACB".toLowerCase()) : 0 ; - int ms_100 = map.containsKey("41AF6981D4562E7B0A6C9E8F8C22D4CCCD03D2F39A".toLowerCase()) - ? map.get("41AF6981D4562E7B0A6C9E8F8C22D4CCCD03D2F39A".toLowerCase()) : 0 ; - int ms_105 = map.containsKey("41AF72A34243836238A533B7E77F3B2B29FD056B14".toLowerCase()) - ? map.get("41AF72A34243836238A533B7E77F3B2B29FD056B14".toLowerCase()) : 0 ; - int ms_110 = map.containsKey("41AF49C25D14AED36186B7C89AF405EF37A01EF23D".toLowerCase()) - ? map.get("41AF49C25D14AED36186B7C89AF405EF37A01EF23D".toLowerCase()) : 0 ; - int ms_115 = map.containsKey("41AF53BA37D394575CAD99A2A2C5BE56DEA0227C87".toLowerCase()) - ? map.get("41AF53BA37D394575CAD99A2A2C5BE56DEA0227C87".toLowerCase()) : 0 ; - int ms_120 = map.containsKey("41AF6A761C941AE2CDC75890D9900AC4B89B7EFCDD".toLowerCase()) - ? map.get("41AF6A761C941AE2CDC75890D9900AC4B89B7EFCDD".toLowerCase()) : 0 ; - int ms_125 = map.containsKey("41AF72B56845F0C4D37388B6E6DC3601A0538ABA71".toLowerCase()) - ? map.get("41AF72B56845F0C4D37388B6E6DC3601A0538ABA71".toLowerCase()) : 0 ; - int ms_130 = map.containsKey("41AF4ACF25C1E192285C9BA98522CB3CF20FFBE392".toLowerCase()) - ? map.get("41AF4ACF25C1E192285C9BA98522CB3CF20FFBE392".toLowerCase()) : 0 ; - int cms_sr = map.containsKey("416C0214C9995C6F3A61AB23F0EB84B0CDE7FD9C7C".toLowerCase()) - ? map.get("416C0214C9995C6F3A61AB23F0EB84B0CDE7FD9C7C".toLowerCase()) : 0 ; - int g = 1; - + // all keys below are for test + int ms_5 = + map.containsKey("41F08012B4881C320EB40B80F1228731898824E09D".toLowerCase()) + ? map.get("41F08012B4881C320EB40B80F1228731898824E09D".toLowerCase()) + : 0; + int ms_10 = + map.containsKey("41DF309FEF25B311E7895562BD9E11AAB2A58816D2".toLowerCase()) + ? map.get("41DF309FEF25B311E7895562BD9E11AAB2A58816D2".toLowerCase()) + : 0; + int ms_15 = + map.containsKey("41BB7322198D273E39B940A5A4C955CB7199A0CDEE".toLowerCase()) + ? map.get("41BB7322198D273E39B940A5A4C955CB7199A0CDEE".toLowerCase()) + : 0; + int ms_20 = + map.containsKey("412080D8A0364E82150DD5235CE7A61A7B40F3F9EF".toLowerCase()) + ? map.get("412080D8A0364E82150DD5235CE7A61A7B40F3F9EF".toLowerCase()) + : 0; + int ms_25 = + map.containsKey("4173FC381D3E2AFEFCCED94A57D49520291C38AFBB".toLowerCase()) + ? map.get("4173FC381D3E2AFEFCCED94A57D49520291C38AFBB".toLowerCase()) + : 0; + int ms_30 = + map.containsKey("41AF6146B0AD9EE8BBEE811D5858F3252666DFC90C".toLowerCase()) + ? map.get("41AF6146B0AD9EE8BBEE811D5858F3252666DFC90C".toLowerCase()) + : 0; + int ms_35 = + map.containsKey("41AF6A9D9C0636BD9DF74F687B90C6F44C471A6AB3".toLowerCase()) + ? map.get("41AF6A9D9C0636BD9DF74F687B90C6F44C471A6AB3".toLowerCase()) + : 0; + int ms_40 = + map.containsKey("41AF730429E4AB7BF7B53FB15ACB1D45EF5B22F463".toLowerCase()) + ? map.get("41AF730429E4AB7BF7B53FB15ACB1D45EF5B22F463".toLowerCase()) + : 0; + int ms_45 = + map.containsKey("41AF4AEA1C4CBCFA681D98C354C142938381C99389".toLowerCase()) + ? map.get("41AF4AEA1C4CBCFA681D98C354C142938381C99389".toLowerCase()) + : 0; + int ms_50 = + map.containsKey("41AF53DC31D9DE64DFF59A847125EFCA89D97BC86D".toLowerCase()) + ? map.get("41AF53DC31D9DE64DFF59A847125EFCA89D97BC86D".toLowerCase()) + : 0; + int ms_55 = + map.containsKey("41AF49468FA1BA966244D76F7D0139FC2CA751FAA5".toLowerCase()) + ? map.get("41AF49468FA1BA966244D76F7D0139FC2CA751FAA5".toLowerCase()) + : 0; + int ms_60 = + map.containsKey("41AF5360256F958D2A922D160C429F13D432EFC22F".toLowerCase()) + ? map.get("41AF5360256F958D2A922D160C429F13D432EFC22F".toLowerCase()) + : 0; + int ms_65 = + map.containsKey("41AF5EF33FD79FECB0419A5688035D7BCD3AEFE236".toLowerCase()) + ? map.get("41AF5EF33FD79FECB0419A5688035D7BCD3AEFE236".toLowerCase()) + : 0; + int ms_70 = + map.containsKey("41AF68F90ED62BA9F6F7A7EABA384E417551CF83E5".toLowerCase()) + ? map.get("41AF68F90ED62BA9F6F7A7EABA384E417551CF83E5".toLowerCase()) + : 0; + int ms_75 = + map.containsKey("41AF619F8CE75A9E95A19E851BEBE63E89FCB1826E".toLowerCase()) + ? map.get("41AF619F8CE75A9E95A19E851BEBE63E89FCB1826E".toLowerCase()) + : 0; + int ms_80 = + map.containsKey("41AF71E98F91515D7E5D5379837B9EEFD1AB4650D2".toLowerCase()) + ? map.get("41AF71E98F91515D7E5D5379837B9EEFD1AB4650D2".toLowerCase()) + : 0; + int ms_85 = + map.containsKey("41AF498B43EE098B26926798CFEAE1AB1154EF4430".toLowerCase()) + ? map.get("41AF498B43EE098B26926798CFEAE1AB1154EF4430".toLowerCase()) + : 0; + int ms_90 = + map.containsKey("41AF536672333170CB0FBFA78819CD90A05537D872".toLowerCase()) + ? map.get("41AF536672333170CB0FBFA78819CD90A05537D872".toLowerCase()) + : 0; + int ms_95 = + map.containsKey("41AF5FAC2D62DD1F5C9892BA9D6593337ABBEAAACB".toLowerCase()) + ? map.get("41AF5FAC2D62DD1F5C9892BA9D6593337ABBEAAACB".toLowerCase()) + : 0; + int ms_100 = + map.containsKey("41AF6981D4562E7B0A6C9E8F8C22D4CCCD03D2F39A".toLowerCase()) + ? map.get("41AF6981D4562E7B0A6C9E8F8C22D4CCCD03D2F39A".toLowerCase()) + : 0; + int ms_105 = + map.containsKey("41AF72A34243836238A533B7E77F3B2B29FD056B14".toLowerCase()) + ? map.get("41AF72A34243836238A533B7E77F3B2B29FD056B14".toLowerCase()) + : 0; + int ms_110 = + map.containsKey("41AF49C25D14AED36186B7C89AF405EF37A01EF23D".toLowerCase()) + ? map.get("41AF49C25D14AED36186B7C89AF405EF37A01EF23D".toLowerCase()) + : 0; + int ms_115 = + map.containsKey("41AF53BA37D394575CAD99A2A2C5BE56DEA0227C87".toLowerCase()) + ? map.get("41AF53BA37D394575CAD99A2A2C5BE56DEA0227C87".toLowerCase()) + : 0; + int ms_120 = + map.containsKey("41AF6A761C941AE2CDC75890D9900AC4B89B7EFCDD".toLowerCase()) + ? map.get("41AF6A761C941AE2CDC75890D9900AC4B89B7EFCDD".toLowerCase()) + : 0; + int ms_125 = + map.containsKey("41AF72B56845F0C4D37388B6E6DC3601A0538ABA71".toLowerCase()) + ? map.get("41AF72B56845F0C4D37388B6E6DC3601A0538ABA71".toLowerCase()) + : 0; + int ms_130 = + map.containsKey("41AF4ACF25C1E192285C9BA98522CB3CF20FFBE392".toLowerCase()) + ? map.get("41AF4ACF25C1E192285C9BA98522CB3CF20FFBE392".toLowerCase()) + : 0; + int cms_sr = + map.containsKey("416C0214C9995C6F3A61AB23F0EB84B0CDE7FD9C7C".toLowerCase()) + ? map.get("416C0214C9995C6F3A61AB23F0EB84B0CDE7FD9C7C".toLowerCase()) + : 0; + int g = 1; } private static void getTxidList() { - String line=null; + String line = null; try { - //BufferedReader bufferedReader=new BufferedReader(new FileReader(filePath)); - BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(new FileInputStream("/Users/wangzihe/Documents/java-tron/framework/28108921L-28110620L.csv"),"utf-8")); - //int i=0; - while((line=bufferedReader.readLine())!=null){ + // BufferedReader bufferedReader=new BufferedReader(new FileReader(filePath)); + BufferedReader bufferedReader = + new BufferedReader( + new InputStreamReader( + new FileInputStream( + "/Users/wangzihe/Documents/java-tron/framework/28108921L-28110620L.csv"), + "utf-8")); + // int i=0; + while ((line = bufferedReader.readLine()) != null) { listForTxid.add(line.toLowerCase()); - } } catch (FileNotFoundException e) { e.printStackTrace(); @@ -213,39 +274,43 @@ private static void getTxidList() { } } - @Test(enabled = true,threadPoolSize = 1, invocationCount = 1, groups = {"stress"}) + @Test( + enabled = true, + threadPoolSize = 1, + invocationCount = 1, + groups = {"stress"}) public void scanBlock() { witnessMap.clear(); map.clear(); - witnessMap.put(5,"41F08012B4881C320EB40B80F1228731898824E09D"); - witnessMap.put(10,"41DF309FEF25B311E7895562BD9E11AAB2A58816D2"); - witnessMap.put(15,"41BB7322198D273E39B940A5A4C955CB7199A0CDEE"); - witnessMap.put(20,"412080D8A0364E82150DD5235CE7A61A7B40F3F9EF"); - witnessMap.put(25,"4173FC381D3E2AFEFCCED94A57D49520291C38AFBB"); - witnessMap.put(30,"41AF6146B0AD9EE8BBEE811D5858F3252666DFC90C"); - witnessMap.put(35,"41AF6A9D9C0636BD9DF74F687B90C6F44C471A6AB3"); - witnessMap.put(40,"41AF730429E4AB7BF7B53FB15ACB1D45EF5B22F463"); - witnessMap.put(45,"41AF4AEA1C4CBCFA681D98C354C142938381C99389"); - witnessMap.put(50,"41AF53DC31D9DE64DFF59A847125EFCA89D97BC86D"); - witnessMap.put(55,"41AF49468FA1BA966244D76F7D0139FC2CA751FAA5"); - witnessMap.put(60,"41AF5360256F958D2A922D160C429F13D432EFC22F"); - witnessMap.put(65,"41AF5EF33FD79FECB0419A5688035D7BCD3AEFE236"); - witnessMap.put(70,"41AF68F90ED62BA9F6F7A7EABA384E417551CF83E5"); - witnessMap.put(75,"41AF619F8CE75A9E95A19E851BEBE63E89FCB1826E"); - witnessMap.put(80,"41AF71E98F91515D7E5D5379837B9EEFD1AB4650D2"); - witnessMap.put(85,"41AF498B43EE098B26926798CFEAE1AB1154EF4430"); - witnessMap.put(90,"41AF536672333170CB0FBFA78819CD90A05537D872"); - witnessMap.put(95,"41AF5FAC2D62DD1F5C9892BA9D6593337ABBEAAACB"); - witnessMap.put(100,"41AF6981D4562E7B0A6C9E8F8C22D4CCCD03D2F39A"); - witnessMap.put(105,"41AF72A34243836238A533B7E77F3B2B29FD056B14"); - witnessMap.put(110,"41AF49C25D14AED36186B7C89AF405EF37A01EF23D"); - witnessMap.put(115,"41AF53BA37D394575CAD99A2A2C5BE56DEA0227C87"); - witnessMap.put(120,"41AF6A761C941AE2CDC75890D9900AC4B89B7EFCDD"); - witnessMap.put(125,"41AF72B56845F0C4D37388B6E6DC3601A0538ABA71"); - witnessMap.put(130,"41AF4ACF25C1E192285C9BA98522CB3CF20FFBE392"); - witnessMap.put(100000,"416C0214C9995C6F3A61AB23F0EB84B0CDE7FD9C7C"); - Long startNum = 30855000L; - Long endNum = 30858000L; + witnessMap.put(5, "41F08012B4881C320EB40B80F1228731898824E09D"); + witnessMap.put(10, "41DF309FEF25B311E7895562BD9E11AAB2A58816D2"); + witnessMap.put(15, "41BB7322198D273E39B940A5A4C955CB7199A0CDEE"); + witnessMap.put(20, "412080D8A0364E82150DD5235CE7A61A7B40F3F9EF"); + witnessMap.put(25, "4173FC381D3E2AFEFCCED94A57D49520291C38AFBB"); + witnessMap.put(30, "41AF6146B0AD9EE8BBEE811D5858F3252666DFC90C"); + witnessMap.put(35, "41AF6A9D9C0636BD9DF74F687B90C6F44C471A6AB3"); + witnessMap.put(40, "41AF730429E4AB7BF7B53FB15ACB1D45EF5B22F463"); + witnessMap.put(45, "41AF4AEA1C4CBCFA681D98C354C142938381C99389"); + witnessMap.put(50, "41AF53DC31D9DE64DFF59A847125EFCA89D97BC86D"); + witnessMap.put(55, "41AF49468FA1BA966244D76F7D0139FC2CA751FAA5"); + witnessMap.put(60, "41AF5360256F958D2A922D160C429F13D432EFC22F"); + witnessMap.put(65, "41AF5EF33FD79FECB0419A5688035D7BCD3AEFE236"); + witnessMap.put(70, "41AF68F90ED62BA9F6F7A7EABA384E417551CF83E5"); + witnessMap.put(75, "41AF619F8CE75A9E95A19E851BEBE63E89FCB1826E"); + witnessMap.put(80, "41AF71E98F91515D7E5D5379837B9EEFD1AB4650D2"); + witnessMap.put(85, "41AF498B43EE098B26926798CFEAE1AB1154EF4430"); + witnessMap.put(90, "41AF536672333170CB0FBFA78819CD90A05537D872"); + witnessMap.put(95, "41AF5FAC2D62DD1F5C9892BA9D6593337ABBEAAACB"); + witnessMap.put(100, "41AF6981D4562E7B0A6C9E8F8C22D4CCCD03D2F39A"); + witnessMap.put(105, "41AF72A34243836238A533B7E77F3B2B29FD056B14"); + witnessMap.put(110, "41AF49C25D14AED36186B7C89AF405EF37A01EF23D"); + witnessMap.put(115, "41AF53BA37D394575CAD99A2A2C5BE56DEA0227C87"); + witnessMap.put(120, "41AF6A761C941AE2CDC75890D9900AC4B89B7EFCDD"); + witnessMap.put(125, "41AF72B56845F0C4D37388B6E6DC3601A0538ABA71"); + witnessMap.put(130, "41AF4ACF25C1E192285C9BA98522CB3CF20FFBE392"); + witnessMap.put(100000, "416C0214C9995C6F3A61AB23F0EB84B0CDE7FD9C7C"); + Long startNum = 30855000L; + Long endNum = 30858000L; Integer totalNum = 0; Integer successNum = 0; @@ -255,26 +320,39 @@ public void scanBlock() { logger.info("scan block num:" + endNum); builder.setNum(endNum); Block block = blockingStubFull1.getBlockByNum(builder.build()); - List transactionList = block.getTransactionsList(); - map.put(ByteArray.toHexString(block.getBlockHeader().getRawData().getWitnessAddress().toByteArray()).toLowerCase(), map.getOrDefault(ByteArray.toHexString(block.getBlockHeader().getRawData().getWitnessAddress().toByteArray()).toLowerCase(),0) + 1); + List transactionList = block.getTransactionsList(); + map.put( + ByteArray.toHexString( + block.getBlockHeader().getRawData().getWitnessAddress().toByteArray()) + .toLowerCase(), + map.getOrDefault( + ByteArray.toHexString( + block.getBlockHeader().getRawData().getWitnessAddress().toByteArray()) + .toLowerCase(), + 0) + + 1); Integer transactionNumInThisBlock = transactionList.size(); totalNum = totalNum + transactionNumInThisBlock; for (Transaction transaction : transactionList) { - String txid = ByteArray.toHexString(Sha256Hash.hash(true, transaction.getRawData().toByteArray())); - //String writeData = ByteArray.toHexString(Sha256Hash.hash(true, transaction.getRawData().toByteArray())); - //createRosettaApiCsvData.writeDataToCsvFile("txid-stressss.csv",txid); - //System.out.println("Fee:" + PublicMethod.getTransactionInfoById(txid,blockingStubFull).get().getFee()); + String txid = + ByteArray.toHexString(Sha256Hash.hash(true, transaction.getRawData().toByteArray())); + // String writeData = ByteArray.toHexString(Sha256Hash.hash(true, + // transaction.getRawData().toByteArray())); + // createRosettaApiCsvData.writeDataToCsvFile("txid-stressss.csv",txid); + // System.out.println("Fee:" + + // PublicMethod.getTransactionInfoById(txid,blockingStubFull).get().getFee()); } -/* for (Transaction transaction : transactionList) { - if (transaction.getRet(0).getContractRet().name().equals("SUCCESS")) { - successNum++; - } else { - failedNum++; - String writeData = ByteArray.toHexString(Sha256Hash.hash(true, transaction.getRawData().toByteArray())); - logger.info(writeData); - createRosettaApiCsvData.writeDataToCsvFile("28164160L-28167324L.csv",writeData); - } - }*/ + /* for (Transaction transaction : transactionList) { + if (transaction.getRet(0).getContractRet().name().equals("SUCCESS")) { + successNum++; + } else { + failedNum++; + String writeData = ByteArray + .toHexString(Sha256Hash.hash(true, transaction.getRawData().toByteArray())); + logger.info(writeData); + createRosettaApiCsvData.writeDataToCsvFile("28164160L-28167324L.csv",writeData); + } + }*/ endNum--; } @@ -282,133 +360,226 @@ public void scanBlock() { logger.info("successNum:" + successNum); logger.info("failedNum:" + failedNum); logger.info("totalNum:" + totalNum); - logger.info("Success rate:" + (double)failedNum / (double)totalNum); - int ms_5 = map.containsKey("41F08012B4881C320EB40B80F1228731898824E09D".toLowerCase()) - ? map.get("41F08012B4881C320EB40B80F1228731898824E09D".toLowerCase()) : 0 ; - int ms_10 = map.containsKey("41DF309FEF25B311E7895562BD9E11AAB2A58816D2".toLowerCase()) - ? map.get("41DF309FEF25B311E7895562BD9E11AAB2A58816D2".toLowerCase()) : 0 ; - int ms_15 = map.containsKey("41BB7322198D273E39B940A5A4C955CB7199A0CDEE".toLowerCase()) - ? map.get("41BB7322198D273E39B940A5A4C955CB7199A0CDEE".toLowerCase()) : 0 ; - int ms_20 = map.containsKey("412080D8A0364E82150DD5235CE7A61A7B40F3F9EF".toLowerCase()) - ? map.get("412080D8A0364E82150DD5235CE7A61A7B40F3F9EF".toLowerCase()) : 0 ; - int ms_25 = map.containsKey("4173FC381D3E2AFEFCCED94A57D49520291C38AFBB".toLowerCase()) - ? map.get("4173FC381D3E2AFEFCCED94A57D49520291C38AFBB".toLowerCase()) : 0 ; - int ms_30 = map.containsKey("41AF6146B0AD9EE8BBEE811D5858F3252666DFC90C".toLowerCase()) - ? map.get("41AF6146B0AD9EE8BBEE811D5858F3252666DFC90C".toLowerCase()) : 0 ; - int ms_35 = map.containsKey("41AF6A9D9C0636BD9DF74F687B90C6F44C471A6AB3".toLowerCase()) - ? map.get("41AF6A9D9C0636BD9DF74F687B90C6F44C471A6AB3".toLowerCase()) : 0 ; - int ms_40 = map.containsKey("41AF730429E4AB7BF7B53FB15ACB1D45EF5B22F463".toLowerCase()) - ? map.get("41AF730429E4AB7BF7B53FB15ACB1D45EF5B22F463".toLowerCase()) : 0 ; - int ms_45 = map.containsKey("41AF4AEA1C4CBCFA681D98C354C142938381C99389".toLowerCase()) - ? map.get("41AF4AEA1C4CBCFA681D98C354C142938381C99389".toLowerCase()) : 0 ; - int ms_50 = map.containsKey("41AF53DC31D9DE64DFF59A847125EFCA89D97BC86D".toLowerCase()) - ? map.get("41AF53DC31D9DE64DFF59A847125EFCA89D97BC86D".toLowerCase()) : 0 ; - int ms_55 = map.containsKey("41AF49468FA1BA966244D76F7D0139FC2CA751FAA5".toLowerCase()) - ? map.get("41AF49468FA1BA966244D76F7D0139FC2CA751FAA5".toLowerCase()) : 0 ; - int ms_60 = map.containsKey("41AF5360256F958D2A922D160C429F13D432EFC22F".toLowerCase()) - ? map.get("41AF5360256F958D2A922D160C429F13D432EFC22F".toLowerCase()) : 0 ; - int ms_65 = map.containsKey("41AF5EF33FD79FECB0419A5688035D7BCD3AEFE236".toLowerCase()) - ? map.get("41AF5EF33FD79FECB0419A5688035D7BCD3AEFE236".toLowerCase()) : 0 ; - int ms_70 = map.containsKey("41AF68F90ED62BA9F6F7A7EABA384E417551CF83E5".toLowerCase()) - ? map.get("41AF68F90ED62BA9F6F7A7EABA384E417551CF83E5".toLowerCase()) : 0 ; - int ms_75 = map.containsKey("41AF619F8CE75A9E95A19E851BEBE63E89FCB1826E".toLowerCase()) - ? map.get("41AF619F8CE75A9E95A19E851BEBE63E89FCB1826E".toLowerCase()) : 0 ; - int ms_80 = map.containsKey("41AF71E98F91515D7E5D5379837B9EEFD1AB4650D2".toLowerCase()) - ? map.get("41AF71E98F91515D7E5D5379837B9EEFD1AB4650D2".toLowerCase()) : 0 ; - int ms_85 = map.containsKey("41AF498B43EE098B26926798CFEAE1AB1154EF4430".toLowerCase()) - ? map.get("41AF498B43EE098B26926798CFEAE1AB1154EF4430".toLowerCase()) : 0 ; - int ms_90 = map.containsKey("41AF536672333170CB0FBFA78819CD90A05537D872".toLowerCase()) - ? map.get("41AF536672333170CB0FBFA78819CD90A05537D872".toLowerCase()) : 0 ; - int ms_95 = map.containsKey("41AF5FAC2D62DD1F5C9892BA9D6593337ABBEAAACB".toLowerCase()) - ? map.get("41AF5FAC2D62DD1F5C9892BA9D6593337ABBEAAACB".toLowerCase()) : 0 ; - int ms_100 = map.containsKey("41AF6981D4562E7B0A6C9E8F8C22D4CCCD03D2F39A".toLowerCase()) - ? map.get("41AF6981D4562E7B0A6C9E8F8C22D4CCCD03D2F39A".toLowerCase()) : 0 ; - int ms_105 = map.containsKey("41AF72A34243836238A533B7E77F3B2B29FD056B14".toLowerCase()) - ? map.get("41AF72A34243836238A533B7E77F3B2B29FD056B14".toLowerCase()) : 0 ; - int ms_110 = map.containsKey("41AF49C25D14AED36186B7C89AF405EF37A01EF23D".toLowerCase()) - ? map.get("41AF49C25D14AED36186B7C89AF405EF37A01EF23D".toLowerCase()) : 0 ; - int ms_115 = map.containsKey("41AF53BA37D394575CAD99A2A2C5BE56DEA0227C87".toLowerCase()) - ? map.get("41AF53BA37D394575CAD99A2A2C5BE56DEA0227C87".toLowerCase()) : 0 ; - int ms_120 = map.containsKey("41AF6A761C941AE2CDC75890D9900AC4B89B7EFCDD".toLowerCase()) - ? map.get("41AF6A761C941AE2CDC75890D9900AC4B89B7EFCDD".toLowerCase()) : 0 ; - int ms_125 = map.containsKey("41AF72B56845F0C4D37388B6E6DC3601A0538ABA71".toLowerCase()) - ? map.get("41AF72B56845F0C4D37388B6E6DC3601A0538ABA71".toLowerCase()) : 0 ; - int ms_130 = map.containsKey("41AF4ACF25C1E192285C9BA98522CB3CF20FFBE392".toLowerCase()) - ? map.get("41AF4ACF25C1E192285C9BA98522CB3CF20FFBE392".toLowerCase()) : 0 ; - int cms_sr = map.containsKey("416C0214C9995C6F3A61AB23F0EB84B0CDE7FD9C7C".toLowerCase()) - ? map.get("416C0214C9995C6F3A61AB23F0EB84B0CDE7FD9C7C".toLowerCase()) : 0 ; - int p = 0; - + logger.info("Success rate:" + (double) failedNum / (double) totalNum); + int ms_5 = + map.containsKey("41F08012B4881C320EB40B80F1228731898824E09D".toLowerCase()) + ? map.get("41F08012B4881C320EB40B80F1228731898824E09D".toLowerCase()) + : 0; + int ms_10 = + map.containsKey("41DF309FEF25B311E7895562BD9E11AAB2A58816D2".toLowerCase()) + ? map.get("41DF309FEF25B311E7895562BD9E11AAB2A58816D2".toLowerCase()) + : 0; + int ms_15 = + map.containsKey("41BB7322198D273E39B940A5A4C955CB7199A0CDEE".toLowerCase()) + ? map.get("41BB7322198D273E39B940A5A4C955CB7199A0CDEE".toLowerCase()) + : 0; + int ms_20 = + map.containsKey("412080D8A0364E82150DD5235CE7A61A7B40F3F9EF".toLowerCase()) + ? map.get("412080D8A0364E82150DD5235CE7A61A7B40F3F9EF".toLowerCase()) + : 0; + int ms_25 = + map.containsKey("4173FC381D3E2AFEFCCED94A57D49520291C38AFBB".toLowerCase()) + ? map.get("4173FC381D3E2AFEFCCED94A57D49520291C38AFBB".toLowerCase()) + : 0; + int ms_30 = + map.containsKey("41AF6146B0AD9EE8BBEE811D5858F3252666DFC90C".toLowerCase()) + ? map.get("41AF6146B0AD9EE8BBEE811D5858F3252666DFC90C".toLowerCase()) + : 0; + int ms_35 = + map.containsKey("41AF6A9D9C0636BD9DF74F687B90C6F44C471A6AB3".toLowerCase()) + ? map.get("41AF6A9D9C0636BD9DF74F687B90C6F44C471A6AB3".toLowerCase()) + : 0; + int ms_40 = + map.containsKey("41AF730429E4AB7BF7B53FB15ACB1D45EF5B22F463".toLowerCase()) + ? map.get("41AF730429E4AB7BF7B53FB15ACB1D45EF5B22F463".toLowerCase()) + : 0; + int ms_45 = + map.containsKey("41AF4AEA1C4CBCFA681D98C354C142938381C99389".toLowerCase()) + ? map.get("41AF4AEA1C4CBCFA681D98C354C142938381C99389".toLowerCase()) + : 0; + int ms_50 = + map.containsKey("41AF53DC31D9DE64DFF59A847125EFCA89D97BC86D".toLowerCase()) + ? map.get("41AF53DC31D9DE64DFF59A847125EFCA89D97BC86D".toLowerCase()) + : 0; + int ms_55 = + map.containsKey("41AF49468FA1BA966244D76F7D0139FC2CA751FAA5".toLowerCase()) + ? map.get("41AF49468FA1BA966244D76F7D0139FC2CA751FAA5".toLowerCase()) + : 0; + int ms_60 = + map.containsKey("41AF5360256F958D2A922D160C429F13D432EFC22F".toLowerCase()) + ? map.get("41AF5360256F958D2A922D160C429F13D432EFC22F".toLowerCase()) + : 0; + int ms_65 = + map.containsKey("41AF5EF33FD79FECB0419A5688035D7BCD3AEFE236".toLowerCase()) + ? map.get("41AF5EF33FD79FECB0419A5688035D7BCD3AEFE236".toLowerCase()) + : 0; + int ms_70 = + map.containsKey("41AF68F90ED62BA9F6F7A7EABA384E417551CF83E5".toLowerCase()) + ? map.get("41AF68F90ED62BA9F6F7A7EABA384E417551CF83E5".toLowerCase()) + : 0; + int ms_75 = + map.containsKey("41AF619F8CE75A9E95A19E851BEBE63E89FCB1826E".toLowerCase()) + ? map.get("41AF619F8CE75A9E95A19E851BEBE63E89FCB1826E".toLowerCase()) + : 0; + int ms_80 = + map.containsKey("41AF71E98F91515D7E5D5379837B9EEFD1AB4650D2".toLowerCase()) + ? map.get("41AF71E98F91515D7E5D5379837B9EEFD1AB4650D2".toLowerCase()) + : 0; + int ms_85 = + map.containsKey("41AF498B43EE098B26926798CFEAE1AB1154EF4430".toLowerCase()) + ? map.get("41AF498B43EE098B26926798CFEAE1AB1154EF4430".toLowerCase()) + : 0; + int ms_90 = + map.containsKey("41AF536672333170CB0FBFA78819CD90A05537D872".toLowerCase()) + ? map.get("41AF536672333170CB0FBFA78819CD90A05537D872".toLowerCase()) + : 0; + int ms_95 = + map.containsKey("41AF5FAC2D62DD1F5C9892BA9D6593337ABBEAAACB".toLowerCase()) + ? map.get("41AF5FAC2D62DD1F5C9892BA9D6593337ABBEAAACB".toLowerCase()) + : 0; + int ms_100 = + map.containsKey("41AF6981D4562E7B0A6C9E8F8C22D4CCCD03D2F39A".toLowerCase()) + ? map.get("41AF6981D4562E7B0A6C9E8F8C22D4CCCD03D2F39A".toLowerCase()) + : 0; + int ms_105 = + map.containsKey("41AF72A34243836238A533B7E77F3B2B29FD056B14".toLowerCase()) + ? map.get("41AF72A34243836238A533B7E77F3B2B29FD056B14".toLowerCase()) + : 0; + int ms_110 = + map.containsKey("41AF49C25D14AED36186B7C89AF405EF37A01EF23D".toLowerCase()) + ? map.get("41AF49C25D14AED36186B7C89AF405EF37A01EF23D".toLowerCase()) + : 0; + int ms_115 = + map.containsKey("41AF53BA37D394575CAD99A2A2C5BE56DEA0227C87".toLowerCase()) + ? map.get("41AF53BA37D394575CAD99A2A2C5BE56DEA0227C87".toLowerCase()) + : 0; + int ms_120 = + map.containsKey("41AF6A761C941AE2CDC75890D9900AC4B89B7EFCDD".toLowerCase()) + ? map.get("41AF6A761C941AE2CDC75890D9900AC4B89B7EFCDD".toLowerCase()) + : 0; + int ms_125 = + map.containsKey("41AF72B56845F0C4D37388B6E6DC3601A0538ABA71".toLowerCase()) + ? map.get("41AF72B56845F0C4D37388B6E6DC3601A0538ABA71".toLowerCase()) + : 0; + int ms_130 = + map.containsKey("41AF4ACF25C1E192285C9BA98522CB3CF20FFBE392".toLowerCase()) + ? map.get("41AF4ACF25C1E192285C9BA98522CB3CF20FFBE392".toLowerCase()) + : 0; + int cms_sr = + map.containsKey("416C0214C9995C6F3A61AB23F0EB84B0CDE7FD9C7C".toLowerCase()) + ? map.get("416C0214C9995C6F3A61AB23F0EB84B0CDE7FD9C7C".toLowerCase()) + : 0; + int p = 0; } - @Test(enabled = false, threadPoolSize = 1, invocationCount = 1, groups = {"stress"}) + @Test( + enabled = false, + threadPoolSize = 1, + invocationCount = 1, + groups = {"stress"}) public void storageAndCpu() { Random rand = new Random(); Integer randNum = rand.nextInt(30) + 1; randNum = rand.nextInt(4000); - Long maxFeeLimit = 1000000000L; - String contractName = "StorageAndCpu" + Integer.toString(randNum); - String code = Configuration.getByPath("testng.conf") - .getString("code.code_TestStorageAndCpu_storageAndCpu"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_TestStorageAndCpu_storageAndCpu"); - PublicMethod - .freezeBalanceGetEnergy(foundationAddress, 1000000000000L, 3, 1, witnessKey5, blockingStubFull); - byte[] contractAddress = PublicMethod.deployContract(contractName, abi, code, - "", maxFeeLimit, - 0L, 100, null, witnessKey5, foundationAddress, blockingStubFull); + Long maxFeeLimit = 1000000000L; + String contractName = "StorageAndCpu" + Integer.toString(randNum); + String code = + Configuration.getByPath("testng.conf") + .getString("code.code_TestStorageAndCpu_storageAndCpu"); + String abi = + Configuration.getByPath("testng.conf").getString("abi.abi_TestStorageAndCpu_storageAndCpu"); + PublicMethod.freezeBalanceGetEnergy( + foundationAddress, 1000000000000L, 3, 1, witnessKey5, blockingStubFull); + byte[] contractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + witnessKey5, + foundationAddress, + blockingStubFull); try { Thread.sleep(30000); } catch (InterruptedException e) { e.printStackTrace(); } SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); - String txid; + String txid; - ChainParameters chainParameters = blockingStubFull - .getChainParameters(EmptyMessage.newBuilder().build()); + ChainParameters chainParameters = + blockingStubFull.getChainParameters(EmptyMessage.newBuilder().build()); Optional getChainParameters = Optional.ofNullable(chainParameters); Integer i = 1; while (i++ < 8000) { String initParmes = "\"" + "930" + "\""; - txid = PublicMethod.triggerContract(contractAddress, - "testUseCpu(uint256)", "9100", false, - 0, maxFeeLimit, foundationAddress, witnessKey5, blockingStubFull); - txid = PublicMethod.triggerContract(contractAddress, - "storage8Char()", "", false, - 0, maxFeeLimit, foundationAddress, witnessKey5, blockingStubFull); - //storage 9 EnergyUsageTotal is 211533, 10 is 236674, 5 is 110969,21 is 500000 - txid = PublicMethod.triggerContract(contractAddress, - "testUseStorage(uint256)", "21", false, - 0, maxFeeLimit, foundationAddress, witnessKey5, blockingStubFull); - //logger.info("i is " +Integer.toString(i) + " " + txid); - //txidList.add(txid); + txid = + PublicMethod.triggerContract( + contractAddress, + "testUseCpu(uint256)", + "9100", + false, + 0, + maxFeeLimit, + foundationAddress, + witnessKey5, + blockingStubFull); + txid = + PublicMethod.triggerContract( + contractAddress, + "storage8Char()", + "", + false, + 0, + maxFeeLimit, + foundationAddress, + witnessKey5, + blockingStubFull); + // storage 9 EnergyUsageTotal is 211533, 10 is 236674, 5 is 110969,21 is 500000 + txid = + PublicMethod.triggerContract( + contractAddress, + "testUseStorage(uint256)", + "21", + false, + 0, + maxFeeLimit, + foundationAddress, + witnessKey5, + blockingStubFull); + // logger.info("i is " +Integer.toString(i) + " " + txid); + // txidList.add(txid); try { Thread.sleep(50); } catch (InterruptedException e) { e.printStackTrace(); } if (i % 10 == 0) { - chainParameters = blockingStubFull - .getChainParameters(EmptyMessage.newBuilder().build()); + chainParameters = blockingStubFull.getChainParameters(EmptyMessage.newBuilder().build()); getChainParameters = Optional.ofNullable(chainParameters); logger.info(getChainParameters.get().getChainParameter(22).getKey()); logger.info(Long.toString(getChainParameters.get().getChainParameter(22).getValue())); logger.info(getChainParameters.get().getChainParameter(23).getKey()); logger.info(Long.toString(getChainParameters.get().getChainParameter(23).getValue())); - } } } - @Test(enabled = false, description = "Get asset issue net resource", groups = {"stress"}) + @Test( + enabled = false, + description = "Get asset issue net resource", + groups = {"stress"}) public void test12GetAssetIssueNet() throws Exception { Long startNum = 29266108L; - Long endNum = 29266208L; - int energy = 0; - int bandwidth = 0; - int tronpower = 0; + Long endNum = 29266208L; + int energy = 0; + int bandwidth = 0; + int tronpower = 0; while (startNum++ <= endNum) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(startNum); @@ -423,21 +594,21 @@ public void test12GetAssetIssueNet() throws Exception { switch (contractType) { case 11: FreezeBalanceContract freezeBalanceContract = any.unpack(FreezeBalanceContract.class); - int type = freezeBalanceContract.getResource().getNumber(); - if(type == 0) { + int type = freezeBalanceContract.getResource().getNumber(); + if (type == 0) { bandwidth++; - } else if(type == 1) { + } else if (type == 1) { energy++; - } else if(type == 2){ + } else if (type == 2) { tronpower++; } - + // fall through default: logger.info("Unknown type:" + contractType); continue; } - } catch (Exception e) { - + } catch (Exception expected) { + // expected } } } @@ -451,20 +622,25 @@ public void test12GetAssetIssueNet() throws Exception { public HashSet addressSet = new HashSet<>(); public HashSet assetIssueSet = new HashSet<>(); - @Test(enabled = true, description = "Get asset issue net resource", groups = {"stress"}) - public void test02GetAssetIssueNet() throws Exception{ - //compareDelegateResource("4C0056A3BD796094EA0677597E6E2152EE42E21F5DA289DF65E000"); - - account = PublicMethod.queryAccount("7400E3D0727F8A61041A8E8BF86599FE5597CE19DE451E59AED07D60967A5E25",blockingStubFull); - //扫描到28307530块了 + @Test( + enabled = true, + description = "Get asset issue net resource", + groups = {"stress"}) + public void test02GetAssetIssueNet() throws Exception { + // compareDelegateResource("4C0056A3BD796094EA0677597E6E2152EE42E21F5DA289DF65E000"); + + account = + PublicMethod.queryAccount( + "7400E3D0727F8A61041A8E8BF86599FE5597CE19DE451E59AED07D60967A5E25", blockingStubFull); + // 扫描到28307530块了 Long startNum = 29266108L; - Long endNum = 29266208L; + Long endNum = 29266208L; NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(startNum); - int retryTimes = 0; + int retryTimes = 0; HashSet set = new HashSet<>(); while (startNum++ <= endNum) { - //Block block = blockingStubFull412.getNowBlock(EmptyMessage.newBuilder().build()); + // Block block = blockingStubFull412.getNowBlock(EmptyMessage.newBuilder().build()); builder.setNum(startNum); Block block = blockingStubFull.getBlockByNum(builder.build()); logger.info("Start to scan block :" + block.getBlockHeader().getRawData().getNumber()); @@ -473,124 +649,145 @@ public void test02GetAssetIssueNet() throws Exception{ for (Transaction transaction : transactionList) { Any any = transaction.getRawData().getContract(0).getParameter(); - Integer contractType = transaction.getRawData().getContract(0).getType().getNumber(); + Integer contractType = transaction.getRawData().getContract(0).getType().getNumber(); try { switch (contractType) { case 1: TransferContract transferContract = any.unpack(TransferContract.class); set.add(transferContract.getOwnerAddress()); - //doCheck(transferContract.getOwnerAddress()); + // doCheck(transferContract.getOwnerAddress()); + // fall through case 2: TransferAssetContract transferAssetContract = any.unpack(TransferAssetContract.class); doCheck(transferAssetContract.getOwnerAddress()); - if(!addressSet.contains(transferAssetContract.getAssetName())) { - Assert.assertEquals(PublicMethod.getAssetIssueById(ByteArray.toStr(transferAssetContract.getAssetName().toByteArray()), blockingStubFull), - PublicMethod.getAssetIssueById(ByteArray.toStr(transferAssetContract.getAssetName().toByteArray()), blockingStubFull)); + if (!addressSet.contains(transferAssetContract.getAssetName())) { + Assert.assertEquals( + PublicMethod.getAssetIssueById( + ByteArray.toStr(transferAssetContract.getAssetName().toByteArray()), + blockingStubFull), + PublicMethod.getAssetIssueById( + ByteArray.toStr(transferAssetContract.getAssetName().toByteArray()), + blockingStubFull)); addressSet.add(transferAssetContract.getAssetName()); - logger.info("check token " + ByteArray.toStr(transferAssetContract.getAssetName().toByteArray()) + " successfully"); + logger.info( + "check token " + + ByteArray.toStr(transferAssetContract.getAssetName().toByteArray()) + + " successfully"); } - + // fall through case 31: TriggerSmartContract triggerSmartContract = any.unpack(TriggerSmartContract.class); doCheck(triggerSmartContract.getOwnerAddress()); + // fall through case 13: - WithdrawBalanceContract withdrawBalanceContract = any.unpack(WithdrawBalanceContract.class); + WithdrawBalanceContract withdrawBalanceContract = + any.unpack(WithdrawBalanceContract.class); doCheck(withdrawBalanceContract.getOwnerAddress()); + // fall through case 11: FreezeBalanceContract freezeBalanceContract = any.unpack(FreezeBalanceContract.class); doCheck(freezeBalanceContract.getOwnerAddress()); + // fall through case 0: AccountCreateContract accountCreateContract = any.unpack(AccountCreateContract.class); doCheck(accountCreateContract.getOwnerAddress()); -/* case 4: + /* case 4: VoteWitnessContract voteWitnessContract = any.unpack(VoteWitnessContract.class); doCheck(voteWitnessContract.getOwnerAddress());*/ + // fall through case 12: - UnfreezeBalanceContract unfreezeBalanceContract = any.unpack(UnfreezeBalanceContract.class); + UnfreezeBalanceContract unfreezeBalanceContract = + any.unpack(UnfreezeBalanceContract.class); doCheck(unfreezeBalanceContract.getOwnerAddress()); + // fall through case 30: CreateSmartContract createSmartContract = any.unpack(CreateSmartContract.class); doCheck(createSmartContract.getOwnerAddress()); + // fall through case 46: - AccountPermissionUpdateContract accountPermissionUpdateContract = any.unpack(AccountPermissionUpdateContract.class); + AccountPermissionUpdateContract accountPermissionUpdateContract = + any.unpack(AccountPermissionUpdateContract.class); doCheck(accountPermissionUpdateContract.getOwnerAddress()); + // fall through default: logger.info("Unknown type:" + contractType); continue; - } - } catch (Exception e) { - + } catch (Exception expected) { + // expected } - } } - } - @Test(enabled = true, description = "Get asset issue net resource", groups = {"stress"}) - public void test03CatchContractAddressAndTopic() throws Exception{ - //compareDelegateResource("4C0056A3BD796094EA0677597E6E2152EE42E21F5DA289DF65E000"); + @Test( + enabled = true, + description = "Get asset issue net resource", + groups = {"stress"}) + public void test03CatchContractAddressAndTopic() throws Exception { + // compareDelegateResource("4C0056A3BD796094EA0677597E6E2152EE42E21F5DA289DF65E000"); HashSet contractAndTopicList = new HashSet<>(); - Long startNum = 34678216L; - Long endNum = startNum + 10L; + Long startNum = 34678216L; + Long endNum = startNum + 10L; NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(startNum); - int retryTimes = 0; + int retryTimes = 0; HashSet set = new HashSet<>(); while (startNum++ <= endNum) { logger.info("current block num:" + startNum); builder.setNum(startNum); - TransactionInfoList transactionInfoList = blockingStubFull.getTransactionInfoByBlockNum(builder.build()); + TransactionInfoList transactionInfoList = + blockingStubFull.getTransactionInfoByBlockNum(builder.build()); for (TransactionInfo transactionInfo : transactionInfoList.getTransactionInfoList()) { - if(!transactionInfo.getContractAddress().isEmpty() && transactionInfo.getLogCount() > 0) { + if (!transactionInfo.getContractAddress().isEmpty() && transactionInfo.getLogCount() > 0) { for (TransactionInfo.Log log : transactionInfo.getLogList()) { try { contractAndTopicList.add( - ByteArray.toHexString(transactionInfo.getContractAddress().toByteArray()).substring(2) - + - ",0x" - + ByteArray.toHexString(log.getTopics(0).toByteArray()) - + "," - + ByteArray.toHexString(transactionInfo.getId().toByteArray()) - ) - ; - } catch (Exception e) { - + ByteArray.toHexString(transactionInfo.getContractAddress().toByteArray()) + .substring(2) + + ",0x" + + ByteArray.toHexString(log.getTopics(0).toByteArray()) + + "," + + ByteArray.toHexString(transactionInfo.getId().toByteArray())); + } catch (Exception expected) { + // expected } - } } - } } for (String contractAddressAndTopic : contractAndTopicList) { writeDataToCsvFile("eth_contractAddressAndTopic2.csv", contractAddressAndTopic); } - } - ConcurrentHashMap certificationCosts = new ConcurrentHashMap<>(); + ConcurrentHashMap certificationCosts = new ConcurrentHashMap<>(); Set concurrentHashSet = certificationCosts.newKeySet(); private static HashSet existAddress = new HashSet<>(); List list1 = new ArrayList<>(); private static AtomicLong blockNum = new AtomicLong(34988101L - 4000L); private static AtomicLong times = new AtomicLong(5); - @Test(enabled = true, threadPoolSize = 10, invocationCount = 10, groups = {"stress"}) - public void test07CreateAddressCsv() throws Exception{ - getNowAddressList(); NumberMessage.Builder builder = NumberMessage.newBuilder(); + + @Test( + enabled = true, + threadPoolSize = 10, + invocationCount = 10, + groups = {"stress"}) + public void test07CreateAddressCsv() throws Exception { + getNowAddressList(); + NumberMessage.Builder builder = NumberMessage.newBuilder(); long blockNumCurrent = blockNum.getAndAdd(-200); - int times = 200; - while (times-->= 0) { - if(concurrentHashSet.size() > 1000000) { + int times = 200; + while (times-- >= 0) { + if (concurrentHashSet.size() > 1000000) { break; } - //list1.add(blockNumCurrent); + // list1.add(blockNumCurrent); builder.setNum(blockNumCurrent--); Block block = blockingStubFull.getBlockByNum(builder.build()); logger.info("Start to scan block :" + block.getBlockHeader().getRawData().getNumber()); @@ -599,7 +796,7 @@ public void test07CreateAddressCsv() throws Exception{ for (Transaction transaction : transactionList) { Any any = transaction.getRawData().getContract(0).getParameter(); - Integer contractType = transaction.getRawData().getContract(0).getType().getNumber(); + Integer contractType = transaction.getRawData().getContract(0).getType().getNumber(); try { switch (contractType) { @@ -619,7 +816,8 @@ public void test07CreateAddressCsv() throws Exception{ isExist(triggerSmartContract.getOwnerAddress()); break; case 13: - WithdrawBalanceContract withdrawBalanceContract = any.unpack(WithdrawBalanceContract.class); + WithdrawBalanceContract withdrawBalanceContract = + any.unpack(WithdrawBalanceContract.class); isExist(withdrawBalanceContract.getOwnerAddress()); break; @@ -633,7 +831,8 @@ public void test07CreateAddressCsv() throws Exception{ isExist(accountCreateContract.getAccountAddress()); break; case 12: - UnfreezeBalanceContract unfreezeBalanceContract = any.unpack(UnfreezeBalanceContract.class); + UnfreezeBalanceContract unfreezeBalanceContract = + any.unpack(UnfreezeBalanceContract.class); isExist(unfreezeBalanceContract.getOwnerAddress()); break; case 30: @@ -641,33 +840,33 @@ public void test07CreateAddressCsv() throws Exception{ isExist(createSmartContract.getOwnerAddress()); break; case 46: - AccountPermissionUpdateContract accountPermissionUpdateContract = any.unpack(AccountPermissionUpdateContract.class); + AccountPermissionUpdateContract accountPermissionUpdateContract = + any.unpack(AccountPermissionUpdateContract.class); isExist(accountPermissionUpdateContract.getOwnerAddress()); break; case 4: VoteWitnessContract voteWitnessContract = any.unpack(VoteWitnessContract.class); isExist(voteWitnessContract.getOwnerAddress()); + // fall through default: logger.info("Unknown type:" + contractType); continue; - } - } catch (Exception e) { - + } catch (Exception expected) { + // expected } - } } - } - private static HashSet getFileList(String fileName,HashSet set) { - String line=null; + private static HashSet getFileList(String fileName, HashSet set) { + String line = null; try { - //BufferedReader bufferedReader=new BufferedReader(new FileReader(filePath)); - BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(new FileInputStream(fileName),"utf-8")); - //int i=0; - while((line=bufferedReader.readLine())!=null){ + // BufferedReader bufferedReader=new BufferedReader(new FileReader(filePath)); + BufferedReader bufferedReader = + new BufferedReader(new InputStreamReader(new FileInputStream(fileName), "utf-8")); + // int i=0; + while ((line = bufferedReader.readLine()) != null) { set.add(line); } } catch (FileNotFoundException e) { @@ -680,12 +879,14 @@ private static HashSet getFileList(String fileName,HashSet set) } private static void getNowAddressList() { - String line=null; + String line = null; try { - //BufferedReader bufferedReader=new BufferedReader(new FileReader(filePath)); - BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(new FileInputStream("mainnet_newAddress.csv"),"utf-8")); - //int i=0; - while((line=bufferedReader.readLine())!=null){ + // BufferedReader bufferedReader=new BufferedReader(new FileReader(filePath)); + BufferedReader bufferedReader = + new BufferedReader( + new InputStreamReader(new FileInputStream("mainnet_newAddress.csv"), "utf-8")); + // int i=0; + while ((line = bufferedReader.readLine()) != null) { existAddress.add(line); } System.out.println(existAddress.size()); @@ -696,7 +897,7 @@ private static void getNowAddressList() { } } - public static void writeDataToCsvFile(String fileName,String writeData) { + public static void writeDataToCsvFile(String fileName, String writeData) { { try { @@ -708,16 +909,16 @@ public static void writeDataToCsvFile(String fileName,String writeData) { FileWriter fileWritter = new FileWriter(file.getName(), true); fileWritter.write(writeData + "\n"); fileWritter.close(); - //System.out.println("finish"); + // System.out.println("finish"); } catch (IOException e) { e.printStackTrace(); } } } - public void doCheck(ByteString address) throws Exception{ - if(addressSet.contains(address)) { - //logger.info("skip :" + ByteArray.toHexString(address.toByteArray())); + public void doCheck(ByteString address) throws Exception { + if (addressSet.contains(address)) { + // logger.info("skip :" + ByteArray.toHexString(address.toByteArray())); return; } else { addressSet.add(address); @@ -727,15 +928,18 @@ public void doCheck(ByteString address) throws Exception{ compareNet(address); compareAccountResource(address); return; - } public void compareTwoAddress(ByteString address) { Assert.assertEquals( - PublicMethod.queryAccount(address.toByteArray(),blockingStubFull).toBuilder().clearFreeAssetNetUsageV2() - //.putAllFreeAssetNetUsageV2(account.getFreeAssetNetUsageV2Map()) - .setBalance(1L).setLatestOprationTime(1L).setAccountResource(AccountResource.newBuilder()) + PublicMethod.queryAccount(address.toByteArray(), blockingStubFull) + .toBuilder() + .clearFreeAssetNetUsageV2() + // .putAllFreeAssetNetUsageV2(account.getFreeAssetNetUsageV2Map()) + .setBalance(1L) + .setLatestOprationTime(1L) + .setAccountResource(AccountResource.newBuilder()) .setFreeNetUsage(1L) .setNetUsage(1L) .clearAssetV2() @@ -743,11 +947,15 @@ public void compareTwoAddress(ByteString address) { .setLatestConsumeTime(1L) .setAllowance(1L) .clearAccountResource() - //.clearOldVotePower() + // .clearOldVotePower() .build(), - PublicMethod.queryAccount(address.toByteArray(),blockingStubFull).toBuilder().clearFreeAssetNetUsageV2() - //.putAllFreeAssetNetUsageV2(account.getFreeAssetNetUsageV2Map()) - .setBalance(1L).setLatestOprationTime(1L).setAccountResource(AccountResource.newBuilder()) + PublicMethod.queryAccount(address.toByteArray(), blockingStubFull) + .toBuilder() + .clearFreeAssetNetUsageV2() + // .putAllFreeAssetNetUsageV2(account.getFreeAssetNetUsageV2Map()) + .setBalance(1L) + .setLatestOprationTime(1L) + .setAccountResource(AccountResource.newBuilder()) .setFreeNetUsage(1L) .setNetUsage(1L) .setLatestConsumeFreeTime(1L) @@ -755,36 +963,36 @@ public void compareTwoAddress(ByteString address) { .clearAssetV2() .setAllowance(1L) .clearAccountResource() - .build() - ); - //long vote413 = PublicMethod.queryAccount(address.toByteArray(),blockingStubFull413).getOldVotePower(); - //logger.info("checking :" + ByteArray.toHexString(address.toByteArray())); - //logger.info("vote413:" + vote413); - //Assert.assertTrue(vote413 == 0 || vote413 >= 1000000); - //Assert.assertTrue(vote413 >= 0); + .build()); + // long vote413 = + // PublicMethod.queryAccount(address.toByteArray(),blockingStubFull413).getOldVotePower(); + // logger.info("checking :" + ByteArray.toHexString(address.toByteArray())); + // logger.info("vote413:" + vote413); + // Assert.assertTrue(vote413 == 0 || vote413 >= 1000000); + // Assert.assertTrue(vote413 >= 0); } public void compareNet(ByteString address) { Assert.assertEquals( - PublicMethod.getAccountNet(address.toByteArray(),blockingStubFull) - .toBuilder().setTotalNetWeight(1L) + PublicMethod.getAccountNet(address.toByteArray(), blockingStubFull) + .toBuilder() + .setTotalNetWeight(1L) .setNetUsed(1L) .setFreeNetUsed(1) .setNetLimit(1) - .build() - , - PublicMethod.getAccountNet(address.toByteArray(),blockingStubFull) - .toBuilder().setTotalNetWeight(1L) + .build(), + PublicMethod.getAccountNet(address.toByteArray(), blockingStubFull) + .toBuilder() + .setTotalNetWeight(1L) .setNetUsed(1L) .setFreeNetUsed(1) .setNetLimit(1) - .build() - ); + .build()); } - public void compareAccountResource(ByteString address) throws Exception{ -/* int notEqualTimes = 0; + public void compareAccountResource(ByteString address) throws Exception { + /* int notEqualTimes = 0; while (!isEqual(address)) { notEqualTimes++; } @@ -794,7 +1002,7 @@ public void compareAccountResource(ByteString address) throws Exception{ }*/ Assert.assertEquals( - PublicMethod.getAccountResource(address.toByteArray(),blockingStubFull) + PublicMethod.getAccountResource(address.toByteArray(), blockingStubFull) .toBuilder() .setFreeNetUsed(1L) .setEnergyUsed(1L) @@ -803,9 +1011,8 @@ public void compareAccountResource(ByteString address) throws Exception{ .setNetUsed(1L) .setNetLimit(1L) .setEnergyLimit(1L) - .build() - , - PublicMethod.getAccountResource(address.toByteArray(),blockingStubFull) + .build(), + PublicMethod.getAccountResource(address.toByteArray(), blockingStubFull) .toBuilder() .setFreeNetUsed(1L) .setEnergyUsed(1L) @@ -814,13 +1021,11 @@ public void compareAccountResource(ByteString address) throws Exception{ .setTotalEnergyWeight(1L) .setTotalNetWeight(1L) .setEnergyLimit(1L) - .build() - ); - + .build()); } public boolean isEqual(ByteString address) { - return PublicMethod.getAccountResource(address.toByteArray(),blockingStubFull) + return PublicMethod.getAccountResource(address.toByteArray(), blockingStubFull) .toBuilder() .setFreeNetUsed(1L) .setEnergyUsed(1L) @@ -829,95 +1034,94 @@ public boolean isEqual(ByteString address) { .setNetUsed(1L) .setNetLimit(1L) .setEnergyLimit(1L) - .build().equals(PublicMethod.getAccountResource(address.toByteArray(),blockingStubFull) - .toBuilder() - .setFreeNetUsed(1L) - .setEnergyUsed(1L) - .setTotalEnergyWeight(1L) - .setTotalNetWeight(1L) - .setNetUsed(1L) - .setNetLimit(1L) - .setEnergyLimit(1L) - .build()); - + .build() + .equals( + PublicMethod.getAccountResource(address.toByteArray(), blockingStubFull) + .toBuilder() + .setFreeNetUsed(1L) + .setEnergyUsed(1L) + .setTotalEnergyWeight(1L) + .setTotalNetWeight(1L) + .setNetUsed(1L) + .setNetLimit(1L) + .setEnergyLimit(1L) + .build()); } public void isExist(ByteString address1) { byte[] address = address1.toByteArray(); - byte[] hash0 = Sha256Sm3Hash.hash(address); - byte[] hash1 = Sha256Sm3Hash.hash(hash0); - byte[] checkSum = Arrays.copyOfRange(hash1, 0, 4); - byte[] addchecksum = new byte[address.length + 4]; + byte[] hash0 = Sha256Sm3Hash.hash(address); + byte[] hash1 = Sha256Sm3Hash.hash(hash0); + byte[] checkSum = Arrays.copyOfRange(hash1, 0, 4); + byte[] addchecksum = new byte[address.length + 4]; System.arraycopy(address, 0, addchecksum, 0, address.length); System.arraycopy(checkSum, 0, addchecksum, address.length, 4); - if(!existAddress.contains(Base58.encode(addchecksum))) { - concurrentHashSet.add(address1); + if (!existAddress.contains(Base58.encode(addchecksum))) { + concurrentHashSet.add(address1); } } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { List list = new ArrayList<>(concurrentHashSet); - for(ByteString target : list) { + for (ByteString target : list) { byte[] address = target.toByteArray(); - byte[] hash0 = Sha256Sm3Hash.hash(address); - byte[] hash1 = Sha256Sm3Hash.hash(hash0); - byte[] checkSum = Arrays.copyOfRange(hash1, 0, 4); - byte[] addchecksum = new byte[address.length + 4]; + byte[] hash0 = Sha256Sm3Hash.hash(address); + byte[] hash1 = Sha256Sm3Hash.hash(hash0); + byte[] checkSum = Arrays.copyOfRange(hash1, 0, 4); + byte[] addchecksum = new byte[address.length + 4]; System.arraycopy(address, 0, addchecksum, 0, address.length); System.arraycopy(checkSum, 0, addchecksum, address.length, 4); writeDataToCsvFile("mainnet_newAddress.csv", Base58.encode(addchecksum)); } Collections.sort(list1); - int i = 1; + int i = 1; /* - afterTime = System.currentTimeMillis(); - try { - Thread.sleep(10000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - currentBlock = blockingStubFull1.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - afterBlockNum = currentBlock.getBlockHeader().getRawData().getNumber() + 2; - Long blockNum = beforeBlockNum; - Integer txsNum = 0; - Integer topNum = 0; - Integer totalNum = 0; - Long energyTotal = 0L; - String findOneTxid = ""; - - NumberMessage.Builder builder = NumberMessage.newBuilder(); - while (blockNum <= afterBlockNum) { - builder.setNum(blockNum); - txsNum = blockingStubFull1.getBlockByNum(builder.build()).getTransactionsCount(); - totalNum = totalNum + txsNum; - if (topNum < txsNum) { - topNum = txsNum; - findOneTxid = ByteArray.toHexString(Sha256Hash.hash(blockingStubFull1 - .getBlockByNum(builder.build()).getTransactionsList().get(2) - .getRawData().toByteArray())); - //logger.info("find one txid is " + findOneTxid); - } + afterTime = System.currentTimeMillis(); + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + currentBlock = blockingStubFull1.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); + afterBlockNum = currentBlock.getBlockHeader().getRawData().getNumber() + 2; + Long blockNum = beforeBlockNum; + Integer txsNum = 0; + Integer topNum = 0; + Integer totalNum = 0; + Long energyTotal = 0L; + String findOneTxid = ""; + + NumberMessage.Builder builder = NumberMessage.newBuilder(); + while (blockNum <= afterBlockNum) { + builder.setNum(blockNum); + txsNum = blockingStubFull1.getBlockByNum(builder.build()).getTransactionsCount(); + totalNum = totalNum + txsNum; + if (topNum < txsNum) { + topNum = txsNum; + findOneTxid = ByteArray.toHexString(Sha256Hash.hash(blockingStubFull1 + .getBlockByNum(builder.build()).getTransactionsList().get(2) + .getRawData().toByteArray())); + //logger.info("find one txid is " + findOneTxid); + } - blockNum++; - } - Long costTime = (afterTime - beforeTime - 31000) / 1000; - logger.info("Duration block num is " + (afterBlockNum - beforeBlockNum - 11)); - logger.info("Cost time are " + costTime); - logger.info("Top block txs num is " + topNum); - logger.info("Total transaction is " + (totalNum - 30)); - logger.info("Average Tps is " + (totalNum / costTime)); - - infoById = PublicMethod.getTransactionInfoById(findOneTxid, blockingStubFull1); - Long oneEnergyTotal = infoById.get().getReceipt().getEnergyUsageTotal(); - logger.info("EnergyTotal is " + oneEnergyTotal); - logger.info("Average energy is " + oneEnergyTotal * (totalNum / costTime)); -*/ if (channelFull1 != null) { + blockNum++; + } + Long costTime = (afterTime - beforeTime - 31000) / 1000; + logger.info("Duration block num is " + (afterBlockNum - beforeBlockNum - 11)); + logger.info("Cost time are " + costTime); + logger.info("Top block txs num is " + topNum); + logger.info("Total transaction is " + (totalNum - 30)); + logger.info("Average Tps is " + (totalNum / costTime)); + + infoById = PublicMethod.getTransactionInfoById(findOneTxid, blockingStubFull1); + Long oneEnergyTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("EnergyTotal is " + oneEnergyTotal); + logger.info("Average energy is " + oneEnergyTotal * (totalNum / costTime)); + */ + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/TestTransferTokenInContract.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/TestTransferTokenInContract.java index b351dbe2..598a3b22 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/TestTransferTokenInContract.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/TestTransferTokenInContract.java @@ -19,161 +19,228 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode public class TestTransferTokenInContract extends TronBaseTest { private static final long TotalSupply = 1000000L; - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private AtomicLong count = new AtomicLong(); private AtomicLong errorCount = new AtomicLong(); private long startTime = System.currentTimeMillis(); private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private static int randomInt(int minInt, int maxInt) { return (int) Math.round(Math.random() * (maxInt - minInt) + minInt); } - - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + public void beforeClass() { + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } - /** - * constructor. - */ + /** constructor. */ public ByteString createAssetissue(byte[] devAddress, String devKey, String tokenName) { ByteString assetAccountId = null; ByteString addressBS1 = ByteString.copyFrom(devAddress); Account request1 = Account.newBuilder().setAddress(addressBS1).build(); - GrpcAPI.AssetIssueList assetIssueList1 = blockingStubFull - .getAssetIssueByAccount(request1); + GrpcAPI.AssetIssueList assetIssueList1 = blockingStubFull.getAssetIssueByAccount(request1); Optional queryAssetByAccount = Optional.ofNullable(assetIssueList1); if (queryAssetByAccount.get().getAssetIssueCount() == 0) { Long start = System.currentTimeMillis() + 2000; - Long end = System.currentTimeMillis() + 1000000000; + Long end = System.currentTimeMillis() + 1000000000; logger.info("The token name: " + tokenName); - //Create a new AssetIssue success. - Assert.assertTrue(PublicMethod.createAssetIssue(devAddress, tokenName, TotalSupply, 1, - 100, start, end, 1, description, url, 10000L, 10000L, - 1L, 1L, devKey, blockingStubFull)); + // Create a new AssetIssue success. + Assert.assertTrue( + PublicMethod.createAssetIssue( + devAddress, + tokenName, + TotalSupply, + 1, + 100, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + devKey, + blockingStubFull)); Account getAssetIdFromThisAccount = PublicMethod.queryAccount(devAddress, blockingStubFull); assetAccountId = getAssetIdFromThisAccount.getAssetIssuedID(); } else { logger.info("This account already create an assetisue"); Optional queryAssetByAccount1 = Optional.ofNullable(assetIssueList1); - tokenName = ByteArray.toStr(queryAssetByAccount1.get().getAssetIssue(0) - .getName().toByteArray()); + tokenName = + ByteArray.toStr(queryAssetByAccount1.get().getAssetIssue(0).getName().toByteArray()); } return assetAccountId; } - @Test(enabled = true, threadPoolSize = 2, invocationCount = 2, groups = {"stress"}) + @Test( + enabled = true, + threadPoolSize = 2, + invocationCount = 2, + groups = {"stress"}) public void continueRun() { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] dev001Address = ecKey1.getAddress(); - String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - ECKey ecKey2 = new ECKey(Utils.getRandom()); - byte[] user001Address = ecKey2.getAddress(); - String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - - Assert - .assertTrue(PublicMethod.sendcoin(dev001Address, 2048000000, foundationAddress, - testKey002, blockingStubFull)); - Assert - .assertTrue(PublicMethod.sendcoin(user001Address, 4048000000L, foundationAddress, - testKey002, blockingStubFull)); - // freeze balance - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(dev001Address, 204800000, - 0, 1, dev001Key, blockingStubFull)); - - Assert.assertTrue(PublicMethod.freezeBalanceGetEnergy(user001Address, 2048000000, - 0, 1, user001Key, blockingStubFull)); - String tokenName = "testAI_" + randomInt(10000, 90000); + byte[] dev001Address = ecKey1.getAddress(); + String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] user001Address = ecKey2.getAddress(); + String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 2048000000, foundationAddress, testKey002, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + user001Address, 4048000000L, foundationAddress, testKey002, blockingStubFull)); + // freeze balance + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + dev001Address, 204800000, 0, 1, dev001Key, blockingStubFull)); + + Assert.assertTrue( + PublicMethod.freezeBalanceGetEnergy( + user001Address, 2048000000, 0, 1, user001Key, blockingStubFull)); + String tokenName = "testAI_" + randomInt(10000, 90000); ByteString tokenId = createAssetissue(user001Address, user001Key, tokenName); - // devAddress transfer token to A - PublicMethod.transferAsset(dev001Address, tokenId.toByteArray(), 101, user001Address, - user001Key, blockingStubFull); - // deploy transferTokenContract + // devAddress transfer token to A + PublicMethod.transferAsset( + dev001Address, tokenId.toByteArray(), 101, user001Address, user001Key, blockingStubFull); + // deploy transferTokenContract String contractName = "transferTokenContract"; - String code = "608060405260e2806100126000396000f300608060405260043610603e5763ffffffff7c01000000" - + "000000000000000000000000000000000000000000000000006000350416633be9ece781146043575b600080" - + "fd5b606873ffffffffffffffffffffffffffffffffffffffff60043516602435604435606a565b005b604051" - + "73ffffffffffffffffffffffffffffffffffffffff84169082156108fc029083908590600081818185878a8a" - + "d094505050505015801560b0573d6000803e3d6000fd5b505050505600a165627a7a723058200ba246bdb58b" - + "e0f221ad07e1b19de843ab541150b329ddd01558c2f1cefe1e270029"; - String abi = "[{\"constant\":false,\"inputs\":[{\"name\":\"toAddress\",\"type\":\"address\"}," - + "{\"name\":\"id\",\"type\":\"trcToken\"},{\"name\":\"amount\",\"type\":\"uint256\"}]," - + "\"name\":\"TransferTokenTo\",\"outputs\":[],\"payable\":true,\"stateMutability\":" - + "\"payable\",\"type\":\"function\"},{\"inputs\":[],\"payable\":true,\"stateMutability\"" - + ":\"payable\",\"type\":\"constructor\"}]"; - byte[] transferTokenContractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, 10000, tokenId.toStringUtf8(), - 100, null, dev001Key, dev001Address, + String code = + "608060405260e2806100126000396000f300608060405260043610603e5763ffffffff7c01000000" + + "000000000000000000000000000000000000000000000000006000350416633be9ece781146043575b60" + + "0080" + + "fd5b606873ffffffffffffffffffffffffffffffffffffffff60043516602435604435606a565b005b60" + + "4051" + + "73ffffffffffffffffffffffffffffffffffffffff84169082156108fc02908390859060008181818587" + + "8a8a" + + "d094505050505015801560b0573d6000803e3d6000fd5b505050505600a165627a7a723058200ba246bd" + + "b58b" + + "e0f221ad07e1b19de843ab541150b329ddd01558c2f1cefe1e270029"; + String abi = + "[{\"constant\":false,\"inputs\":[{\"name\":\"toAddress\",\"type\":\"address\"}," + + "{\"name\":\"id\",\"type\":\"trcToken\"},{\"name\":\"amount\",\"type\":\"uint256\"}]," + + "\"name\":\"TransferTokenTo\",\"outputs\":[],\"payable\":true,\"stateMutability\":" + + "\"payable\",\"type\":\"function\"},{\"inputs\":[],\"payable\":true,\"stateMutability" + + "\"" + + ":\"payable\",\"type\":\"constructor\"}]"; + byte[] transferTokenContractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + 10000, + tokenId.toStringUtf8(), + 100, + null, + dev001Key, + dev001Address, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - // deploy receiveTokenContract + // deploy receiveTokenContract contractName = "recieveTokenContract"; - code = "60806040526000805560c5806100166000396000f30060806040526004361060485763ffffffff7c0100000" - + "00000000000000000000000000000000000000000000000000060003504166362548c7b8114604a578063890" - + "eba68146050575b005b6048608c565b348015605b57600080fd5b50d38015606757600080fd5b50d28015607" - + "357600080fd5b50607a6093565b60408051918252519081900360200190f35b6001600055565b60005481560" - + "0a165627a7a723058204c4f1bb8eca0c4f1678cc7cc1179e03d99da2a980e6792feebe4d55c89c022830029"; - abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"setFlag\",\"outputs\":[],\"payable\":true," - + "\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[]," - + "\"name\":\"flag\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false," - + "\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"payable\":true," - + "\"stateMutability\":\"payable\",\"type\":\"constructor\"},{\"payable\":true," - + "\"stateMutability\":\"payable\",\"type\":\"fallback\"}]"; - byte[] receiveTokenContractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, dev001Key, dev001Address, blockingStubFull); + code = + "60806040526000805560c5806100166000396000f30060806040526004361060485763ffffffff7c0100000" + + "00000000000000000000000000000000000000000000000000060003504166362548c7b8114604a57806" + + "3890" + + "eba68146050575b005b6048608c565b348015605b57600080fd5b50d38015606757600080fd5b50d2801" + + "5607" + + "357600080fd5b50607a6093565b60408051918252519081900360200190f35b6001600055565b6000548" + + "1560" + + "0a165627a7a723058204c4f1bb8eca0c4f1678cc7cc1179e03d99da2a980e6792feebe4d55c89c022830" + + "029"; + abi = + "[{\"constant\":false,\"inputs\":[],\"name\":\"setFlag\",\"outputs\":[],\"payable\":true," + + "\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\"" + + ":[]," + + "\"name\":\"flag\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":fal" + + "se," + + "\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"payable\":true," + + "\"stateMutability\":\"payable\",\"type\":\"constructor\"},{\"payable\":true," + + "\"stateMutability\":\"payable\",\"type\":\"fallback\"}]"; + byte[] receiveTokenContractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - // deploy tokenBalanceContract + // deploy tokenBalanceContract contractName = "tokenBalanceContract"; - code = "608060405260ff806100126000396000f30060806040526004361060485763ffffffff7c010000000000000" - + "0000000000000000000000000000000000000000000600035041663a730416e8114604d578063b69ef8a8146" - + "081575b600080fd5b606f73ffffffffffffffffffffffffffffffffffffffff6004351660243560ab565b604" - + "08051918252519081900360200190f35b348015608c57600080fd5b50d38015609857600080fd5b50d280156" - + "0a457600080fd5b50606f60cd565b73ffffffffffffffffffffffffffffffffffffffff90911690d16000908" - + "15590565b600054815600a165627a7a723058202b6235122df66c062c2e723ad58a9fea93346f3bc19898971" - + "8f211aa1dbd2d7a0029"; - abi = "[{\"constant\":false,\"inputs\":[{\"name\":\"toAddress\",\"type\":\"address\"}," - + "{\"name\":\"tokenId\",\"type\":\"trcToken\"}],\"name\":\"getTokenBalnce\",\"outputs\":" - + "[{\"name\":\"b\",\"type\":\"uint256\"}],\"payable\":true,\"stateMutability\":" - + "\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":" - + "\"balance\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false," - + "\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"payable\":true," - + "\"stateMutability\":\"payable\",\"type\":\"constructor\"}]"; - byte[] tokenBalanceContractAddress = PublicMethod - .deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, dev001Key, dev001Address, blockingStubFull); - // devAddress transfer token to userAddress - PublicMethod.transferAsset(user001Address, tokenId.toByteArray(), 100, dev001Address, dev001Key, - blockingStubFull); + code = + "608060405260ff806100126000396000f30060806040526004361060485763ffffffff7c010000000000000" + + "0000000000000000000000000000000000000000000600035041663a730416e8114604d578063b69ef8a" + + "8146" + + "081575b600080fd5b606f73ffffffffffffffffffffffffffffffffffffffff6004351660243560ab565" + + "b604" + + "08051918252519081900360200190f35b348015608c57600080fd5b50d38015609857600080fd5b50d28" + + "0156" + + "0a457600080fd5b50606f60cd565b73ffffffffffffffffffffffffffffffffffffffff90911690d1600" + + "0908" + + "15590565b600054815600a165627a7a723058202b6235122df66c062c2e723ad58a9fea93346f3bc1989" + + "8971" + + "8f211aa1dbd2d7a0029"; + abi = + "[{\"constant\":false,\"inputs\":[{\"name\":\"toAddress\"," + + "\"type\":\"address\"},{\"name\":\"tokenId\"," + + "\"type\":\"trcToken\"}],\"name\":\"getTokenBalnce\"," + + "\"outputs\":[{\"name\":\"b\",\"type\":\"uint256\"}]," + + "\"payable\":true,\"stateMutability\":" + + "\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":" + + "\"balance\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false," + + "\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"payable\":true," + + "\"stateMutability\":\"payable\",\"type\":\"constructor\"}]"; + byte[] tokenBalanceContractAddress = + PublicMethod.deployContract( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + null, + dev001Key, + dev001Address, + blockingStubFull); + // devAddress transfer token to userAddress + PublicMethod.transferAsset( + user001Address, tokenId.toByteArray(), 100, dev001Address, dev001Key, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull1); @@ -183,15 +250,32 @@ public void continueRun() { count.getAndAdd(4); if (count.get() % 500 == 0) { long cost = (System.currentTimeMillis() - startTime) / 1000; - logger.info("Count:" + count.get() + ", cost:" + cost - + ", avg:" + count.get() / cost + ", errCount:" + errorCount); + logger.info( + "Count:" + + count.get() + + ", cost:" + + cost + + ", avg:" + + count.get() / cost + + ", errCount:" + + errorCount); } - PublicMethod.freezeBalanceForReceiver(user001Address, - PublicMethod.getFreezeBalanceCount(user001Address, - user001Key, 300000L, blockingStubFull), 0, - 1, ByteString.copyFrom(foundationAddress), testKey002, blockingStubFull); - PublicMethod.freezeBalanceForReceiver(user001Address, 10_000_000L, - 0, 0, ByteString.copyFrom(foundationAddress), testKey002, blockingStubFull); + PublicMethod.freezeBalanceForReceiver( + user001Address, + PublicMethod.getFreezeBalanceCount(user001Address, user001Key, 300000L, blockingStubFull), + 0, + 1, + ByteString.copyFrom(foundationAddress), + testKey002, + blockingStubFull); + PublicMethod.freezeBalanceForReceiver( + user001Address, + 10_000_000L, + 0, + 0, + ByteString.copyFrom(foundationAddress), + testKey002, + blockingStubFull); try { Thread.sleep(3000); } catch (InterruptedException e) { @@ -199,17 +283,27 @@ public void continueRun() { } // user trigger A to transfer token to B String param = - "\"" + Base58.encode58Check(receiveTokenContractAddress) + "\",\"" + tokenId - .toStringUtf8() + "\"" + + Base58.encode58Check(receiveTokenContractAddress) + + "\",\"" + + tokenId.toStringUtf8() + "\",\"5\""; - String triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "TransferTokenTo(address,trcToken,uint256)", - param, false, 0, 100000000L, tokenId.toStringUtf8(), - 10, user001Address, user001Key, - blockingStubFull); - - Optional infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + String triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "TransferTokenTo(address,trcToken,uint256)", + param, + false, + 0, + 100000000L, + tokenId.toStringUtf8(), + 10, + user001Address, + user001Key, + blockingStubFull); + + Optional infoById = + PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { errorCount.incrementAndGet(); @@ -217,16 +311,25 @@ public void continueRun() { // user trigger A to transfer token to devAddress param = - "\"" + Base58.encode58Check(dev001Address) + "\",\"" + tokenId.toStringUtf8() + "\"" + + Base58.encode58Check(dev001Address) + + "\",\"" + + tokenId.toStringUtf8() + "\",\"5\""; - triggerTxid = PublicMethod.triggerContract(transferTokenContractAddress, - "TransferTokenTo(address,trcToken,uint256)", - param, false, 0, 100000000L, user001Address, - user001Key, blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + transferTokenContractAddress, + "TransferTokenTo(address,trcToken,uint256)", + param, + false, + 0, + 100000000L, + user001Address, + user001Key, + blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { errorCount.incrementAndGet(); @@ -234,57 +337,80 @@ public void continueRun() { // user trigger C to get B's token balance param = - "\"" + Base58.encode58Check(receiveTokenContractAddress) + "\",\"" + tokenId - .toStringUtf8() + "\"" + + Base58.encode58Check(receiveTokenContractAddress) + + "\",\"" + + tokenId.toStringUtf8() + "\""; - triggerTxid = PublicMethod - .triggerContract(tokenBalanceContractAddress, "getTokenBalnce(address,trcToken)", - param, false, 0, 1000000000L, user001Address, - user001Key, blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + tokenBalanceContractAddress, + "getTokenBalnce(address,trcToken)", + param, + false, + 0, + 1000000000L, + user001Address, + user001Key, + blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { errorCount.incrementAndGet(); } - PublicMethod.triggerContract(tokenBalanceContractAddress, "balance()", - "#", false, 0, 1000000000L, user001Address, - user001Key, blockingStubFull); - // user trigger C to get devAddress's token balance + PublicMethod.triggerContract( + tokenBalanceContractAddress, + "balance()", + "#", + false, + 0, + 1000000000L, + user001Address, + user001Key, + blockingStubFull); + // user trigger C to get devAddress's token balance param = "\"" + Base58.encode58Check(dev001Address) + "\",\"" + tokenId.toStringUtf8() + "\""; - triggerTxid = PublicMethod - .triggerContract(tokenBalanceContractAddress, "getTokenBalnce(address,trcToken)", - param, false, 0, 1000000000L, user001Address, - user001Key, blockingStubFull); + triggerTxid = + PublicMethod.triggerContract( + tokenBalanceContractAddress, + "getTokenBalnce(address,trcToken)", + param, + false, + 0, + 1000000000L, + user001Address, + user001Key, + blockingStubFull); - infoById = PublicMethod - .getTransactionInfoById(triggerTxid, blockingStubFull); + infoById = PublicMethod.getTransactionInfoById(triggerTxid, blockingStubFull); if (infoById.get().getResultValue() != 0) { errorCount.incrementAndGet(); } - PublicMethod.triggerContract(tokenBalanceContractAddress, "balance()", - "#", false, 0, 1000000000L, user001Address, - user001Key, blockingStubFull); + PublicMethod.triggerContract( + tokenBalanceContractAddress, + "balance()", + "#", + false, + 0, + 1000000000L, + user001Address, + user001Key, + blockingStubFull); - PublicMethod.unFreezeBalance(foundationAddress, user001Key, 1, - user001Address, blockingStubFull); - PublicMethod.unFreezeBalance(foundationAddress, user001Key, 0, - user001Address, blockingStubFull); + PublicMethod.unFreezeBalance( + foundationAddress, user001Key, 1, user001Address, blockingStubFull); + PublicMethod.unFreezeBalance( + foundationAddress, user001Key, 0, user001Address, blockingStubFull); } } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} } - - diff --git a/testcase/src/test/java/stest/tron/wallet/onlinestress/WalletTestZenTokenStress.java b/testcase/src/test/java/stest/tron/wallet/onlinestress/WalletTestZenTokenStress.java index 04ce6565..bd27c8fc 100644 --- a/testcase/src/test/java/stest/tron/wallet/onlinestress/WalletTestZenTokenStress.java +++ b/testcase/src/test/java/stest/tron/wallet/onlinestress/WalletTestZenTokenStress.java @@ -28,15 +28,15 @@ import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.ShieldAddressInfo; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.zen.address.DiversifierT; - @Slf4j public class WalletTestZenTokenStress extends TronBaseTest { - private static ByteString assetAccountId = null; Optional sendShieldAddressInfo; + private static ByteString assetAccountId = null; + Optional sendShieldAddressInfo; Optional receiverShieldAddressInfo; String sendShieldAddress; String receiverShieldAddress; @@ -65,76 +65,96 @@ public class WalletTestZenTokenStress extends TronBaseTest { String zenTokenOwnerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelSolidity1 = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity1 = null; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - private String soliditynode1 = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1); - private String foundationZenTokenKey = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenOwnerKey"); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + private String soliditynode1 = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(1); + private String foundationZenTokenKey = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenOwnerKey"); byte[] foundationZenTokenAddress = PublicMethod.getFinalAddress(foundationZenTokenKey); - private String zenTokenId = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenId"); + private String zenTokenId = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenId"); private byte[] tokenId = zenTokenId.getBytes(); - private Long zenTokenFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.zenTokenFee"); + private Long zenTokenFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.zenTokenFee"); private Long costTokenAmount = 1 * zenTokenFee + 1; private Long sendTokenAmount = 1 * zenTokenFee; - /** - * constructor. - */ + /** constructor. */ @BeforeClass(enabled = true) public void beforeClass() { initSolidityChannel(); PublicMethod.printAddress(foundationZenTokenKey); - PublicMethod.printAddress(zenTokenOwnerKey); channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); - channelSolidity1 = ManagedChannelBuilder.forTarget(soliditynode1) - .usePlaintext() - .build(); + PublicMethod.printAddress(zenTokenOwnerKey); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); + channelSolidity1 = ManagedChannelBuilder.forTarget(soliditynode1).usePlaintext().build(); blockingStubSolidity1 = WalletSolidityGrpc.newBlockingStub(channelSolidity1); - Assert.assertTrue(PublicMethod.transferAsset(zenTokenOwnerAddress, tokenId, - costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.transferAsset( + zenTokenOwnerAddress, + tokenId, + costTokenAmount, + foundationZenTokenAddress, + foundationZenTokenKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Args.setFullNodeAllowShieldedTransaction(true); - + // Args.setFullNodeAllowShieldedTransaction(true); } - @Test(enabled = true, threadPoolSize = 3, invocationCount = 3, groups = {"stress"}) + @Test( + enabled = true, + threadPoolSize = 3, + invocationCount = 3, + groups = {"stress"}) public void test1Shield2ShieldTransaction() throws InterruptedException { List shieldOutList = new ArrayList<>(); Integer times = 0; Optional sendShieldAddressInfo = PublicMethod.generateShieldAddress(); - String sendShieldAddress = sendShieldAddressInfo.get().getAddress(); - String memo = "7"; - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress, - "" + zenTokenFee, memo); + String sendShieldAddress = sendShieldAddressInfo.get().getAddress(); + String memo = "7"; + shieldOutList = + PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress, "" + zenTokenFee, memo); while (times++ < 10000) { ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] zenTokenOwnerAddress = ecKey1.getAddress(); + byte[] zenTokenOwnerAddress = ecKey1.getAddress(); - PublicMethod.transferAsset(zenTokenOwnerAddress, tokenId, - zenTokenFee * 2, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull); + PublicMethod.transferAsset( + zenTokenOwnerAddress, + tokenId, + zenTokenFee * 2, + foundationZenTokenAddress, + foundationZenTokenKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); memo = times + ":shield note number"; shieldOutList.clear(); - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, sendShieldAddress, - "" + zenTokenFee, memo); - String zenTokenOwnerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - PublicMethod.sendShieldCoin(zenTokenOwnerAddress, 2 * zenTokenFee, null, - null, shieldOutList, null, 0, zenTokenOwnerKey, blockingStubFull); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, sendShieldAddress, "" + zenTokenFee, memo); + String zenTokenOwnerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + PublicMethod.sendShieldCoin( + zenTokenOwnerAddress, + 2 * zenTokenFee, + null, + null, + shieldOutList, + null, + 0, + zenTokenOwnerKey, + blockingStubFull); /* logger.info("Note number:" - + PublicMethod.getShieldNotesCount(sendShieldAddressInfo,blockingStubFull));*/ + + PublicMethod.getShieldNotesCount(sendShieldAddressInfo,blockingStubFull));*/ } - - } - @Test(enabled = true, threadPoolSize = 30, invocationCount = 30, groups = {"stress"}) + @Test( + enabled = true, + threadPoolSize = 30, + invocationCount = 30, + groups = {"stress"}) public void test2Shield2ShieldTransaction() throws InterruptedException { BytesMessage ak; BytesMessage nk; @@ -155,39 +175,39 @@ public void test2Shield2ShieldTransaction() throws InterruptedException { Integer times = 0; while (times++ < 10000) { sk = blockingStubFull.getSpendingKey(EmptyMessage.newBuilder().build()); - //logger.info("sk: " + ByteArray.toHexString(sk.getValue().toByteArray())); + // logger.info("sk: " + ByteArray.toHexString(sk.getValue().toByteArray())); diversifierMessage1 = blockingStubFull.getDiversifier(EmptyMessage.newBuilder().build()); - //logger.info("d1: " + ByteArray.toHexString(diversifierMessage1.getD().toByteArray())); + // logger.info("d1: " + ByteArray.toHexString(diversifierMessage1.getD().toByteArray())); diversifierMessage2 = blockingStubFull.getDiversifier(EmptyMessage.newBuilder().build()); - //logger.info("d2: " + ByteArray.toHexString(diversifierMessage2.getD().toByteArray())); + // logger.info("d2: " + ByteArray.toHexString(diversifierMessage2.getD().toByteArray())); diversifierMessage3 = blockingStubFull.getDiversifier(EmptyMessage.newBuilder().build()); - //logger.info("d3: " + ByteArray.toHexString(diversifierMessage3.getD().toByteArray())); + // logger.info("d3: " + ByteArray.toHexString(diversifierMessage3.getD().toByteArray())); expandedSpendingKeyMessage = blockingStubFull.getExpandedSpendingKey(sk); BytesMessage.Builder askBuilder = BytesMessage.newBuilder(); askBuilder.setValue(expandedSpendingKeyMessage.getAsk()); ak = blockingStubFull.getAkFromAsk(askBuilder.build()); - //logger.info("ak: " + ByteArray.toHexString(ak.getValue().toByteArray())); + // logger.info("ak: " + ByteArray.toHexString(ak.getValue().toByteArray())); BytesMessage.Builder nskBuilder = BytesMessage.newBuilder(); nskBuilder.setValue(expandedSpendingKeyMessage.getNsk()); nk = blockingStubFull.getNkFromNsk(nskBuilder.build()); - //logger.info("nk: " + ByteArray.toHexString(nk.getValue().toByteArray())); + // logger.info("nk: " + ByteArray.toHexString(nk.getValue().toByteArray())); ViewingKeyMessage.Builder viewBuilder = ViewingKeyMessage.newBuilder(); viewBuilder.setAk(ak.getValue()); viewBuilder.setNk(nk.getValue()); ivk = blockingStubFull.getIncomingViewingKey(viewBuilder.build()); - //logger.info("ivk: " + ByteArray.toHexString(ivk.getIvk().toByteArray())); + // logger.info("ivk: " + ByteArray.toHexString(ivk.getIvk().toByteArray())); IncomingViewingKeyDiversifierMessage.Builder builder = IncomingViewingKeyDiversifierMessage.newBuilder(); builder.setD(diversifierMessage1); builder.setIvk(ivk); PaymentAddressMessage addressMessage = blockingStubFull.getZenPaymentAddress(builder.build()); - //System.out.println("address1: " + addressMessage.getPaymentAddress()); + // System.out.println("address1: " + addressMessage.getPaymentAddress()); addressInfo1.setSk(sk.getValue().toByteArray()); addressInfo1.setD(new DiversifierT(diversifierMessage1.getD().toByteArray())); addressInfo1.setIvk(ivk.getIvk().toByteArray()); @@ -200,7 +220,7 @@ public void test2Shield2ShieldTransaction() throws InterruptedException { builder.setD(diversifierMessage2); builder.setIvk(ivk); addressMessage = blockingStubFull.getZenPaymentAddress(builder.build()); - //System.out.println("address2: " + addressMessage.getPaymentAddress()); + // System.out.println("address2: " + addressMessage.getPaymentAddress()); addressInfo2.setSk(sk.getValue().toByteArray()); addressInfo2.setD(new DiversifierT(diversifierMessage2.getD().toByteArray())); addressInfo2.setIvk(ivk.getIvk().toByteArray()); @@ -213,7 +233,7 @@ public void test2Shield2ShieldTransaction() throws InterruptedException { builder.setD(diversifierMessage3); builder.setIvk(ivk); addressMessage = blockingStubFull.getZenPaymentAddress(builder.build()); - //System.out.println("address3: " + addressMessage.getPaymentAddress()); + // System.out.println("address3: " + addressMessage.getPaymentAddress()); addressInfo3.setSk(sk.getValue().toByteArray()); addressInfo3.setD(new DiversifierT(diversifierMessage3.getD().toByteArray())); addressInfo3.setIvk(ivk.getIvk().toByteArray()); @@ -221,19 +241,23 @@ public void test2Shield2ShieldTransaction() throws InterruptedException { addressInfo3.setPkD(addressMessage.getPkD().toByteArray()); receiverAddressInfo3 = Optional.of(addressInfo3); } - } - /** - * constructor. - */ + /** constructor. */ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { - PublicMethod.transferAsset(foundationZenTokenAddress, tokenId, - PublicMethod.getAssetIssueValue(zenTokenOwnerAddress, + PublicMethod.transferAsset( + foundationZenTokenAddress, + tokenId, + PublicMethod.getAssetIssueValue( + zenTokenOwnerAddress, PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull), zenTokenOwnerAddress, zenTokenOwnerKey, blockingStubFull); if (channelSolidity1 != null) { + blockingStubFull), + zenTokenOwnerAddress, + zenTokenOwnerKey, + blockingStubFull); + if (channelSolidity1 != null) { channelSolidity1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } -} \ No newline at end of file +} diff --git a/testcase/src/test/java/stest/tron/wallet/other/TestUpdateOnlineTxs.java b/testcase/src/test/java/stest/tron/wallet/other/TestUpdateOnlineTxs.java index 6437802f..e79fd13f 100644 --- a/testcase/src/test/java/stest/tron/wallet/other/TestUpdateOnlineTxs.java +++ b/testcase/src/test/java/stest/tron/wallet/other/TestUpdateOnlineTxs.java @@ -1,6 +1,5 @@ package stest.tron.wallet.other; -import io.grpc.ManagedChannel; import java.util.Optional; import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; @@ -10,12 +9,13 @@ import org.testng.annotations.Test; import org.tron.protos.Protocol.TransactionInfo; import stest.tron.wallet.common.client.utils.PublicMethod; - import stest.tron.wallet.common.client.utils.TronBaseTest; + @Slf4j -public class TestUpdateOnlineTxs extends TronBaseTest { private byte[] transferTokenContractAddress = null; +public class TestUpdateOnlineTxs extends TronBaseTest { + private byte[] transferTokenContractAddress = null; - //just test key + // just test key private String dev001Key = "8132dd4fe6c1140d60fadd69eab3975831fe681e4b28705f78c89b94d44af2f4"; private byte[] dev001Address = PublicMethod.getFinalAddress(dev001Key); @@ -24,9 +24,11 @@ public class TestUpdateOnlineTxs extends TronBaseTest { private byte[] transfer /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { PublicMethod.printAddress(dev001Key); Assert.assertTrue(PublicMethod - .sendcoin(dev001Address, 300100_000_000L, - fromAddress, foundationKey2, blockingStubFull)); + public void beforeClass() { + PublicMethod.printAddress(dev001Key); + Assert.assertTrue( + PublicMethod.sendcoin( + dev001Address, 300100_000_000L, fromAddress, foundationKey2, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); } @@ -51,13 +53,20 @@ public void sunswapV1() { long deadline = System.currentTimeMillis() / 1000 + 3000; String param = "100000,1654933319"; long feeLimit = 1000000000L; - String exchangeAdd = "TQn9Y2khEsLJW1ChVWFMSMeRDow5KcbLSE"; //usdt - String txid1 = PublicMethod.triggerContract(PublicMethod.decode58Check(exchangeAdd), - methodSign, param, false, 50000000, maxFeeLimit, dev001Address, - dev001Key, blockingStubFull); + String exchangeAdd = "TQn9Y2khEsLJW1ChVWFMSMeRDow5KcbLSE"; // usdt + String txid1 = + PublicMethod.triggerContract( + PublicMethod.decode58Check(exchangeAdd), + methodSign, + param, + false, + 50000000, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info1 = - PublicMethod.getTransactionInfoById(txid1, blockingStubFull); + Optional info1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); System.out.println(info1.toString()); } @@ -65,13 +74,20 @@ public void sunswapV1() { public void sunswapV11() { String methodSign = "trxToTokenSwapInput(uint256,uint256)"; String param = "1091242047502,1654933319"; - String exchangeAdd = "TSJWbBJAS8HgQCMJfY5drVwYDa7JBAm6Es"; //usdd - String txid1 = PublicMethod.triggerContract(PublicMethod.decode58Check(exchangeAdd), - methodSign, param, false, 50000000, maxFeeLimit, dev001Address, - dev001Key, blockingStubFull); + String exchangeAdd = "TSJWbBJAS8HgQCMJfY5drVwYDa7JBAm6Es"; // usdd + String txid1 = + PublicMethod.triggerContract( + PublicMethod.decode58Check(exchangeAdd), + methodSign, + param, + false, + 50000000, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info1 = - PublicMethod.getTransactionInfoById(txid1, blockingStubFull); + Optional info1 = PublicMethod.getTransactionInfoById(txid1, blockingStubFull); System.out.println(info1.toString()); } @@ -90,12 +106,20 @@ public void sunswapV2() { public void sunio2PoolAddliq() { String methedStr = "add_liquidity(uint256[2],uint256)"; String argsStr = "[1000000,1000000000000000000],1"; - String pool = "TAUGwRhmCP518Bm4VBqv7hDun9fg8kYjC4"; //old 2pool - String txid = PublicMethod.triggerContract(PublicMethod.decode58Check(pool), methedStr, argsStr, - false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String pool = "TAUGwRhmCP518Bm4VBqv7hDun9fg8kYjC4"; // old 2pool + String txid = + PublicMethod.triggerContract( + PublicMethod.decode58Check(pool), + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = - PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); System.out.println(info.toString()); } @@ -103,45 +127,65 @@ public void sunio2PoolAddliq() { public void sunio2PoolDeposit() { String methedStr = "deposit(uint256)"; String argsStr = "\"99308209820\""; - String gague = "TBSRZYLZ2pguF3EqLz86Kt9hZ4eqKEQMSY"; //old 2pool - String txid = PublicMethod.triggerContract(PublicMethod.decode58Check(gague), - methedStr, argsStr, false, 0, maxFeeLimit, dev001Address, - dev001Key, blockingStubFull); + String gague = "TBSRZYLZ2pguF3EqLz86Kt9hZ4eqKEQMSY"; // old 2pool + String txid = + PublicMethod.triggerContract( + PublicMethod.decode58Check(gague), + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = - PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); System.out.println(info.toString()); } @Test(enabled = true) public void justlendBorrow() { String methedStr = "borrow(uint256)"; - String argsStr = "1313828980000"; //USDD + String argsStr = "1313828980000"; // USDD // String argsStr = "1"; String jusdd = "TX7kybeP6UwTBRHLNPYmswFESHfyjm9bAS"; // String jUSDT = "TXJgMdjVX5dKiQaUi9QobwNxtSQaFqccvd"; - String txid = PublicMethod.triggerContract(PublicMethod.decode58Check(jusdd), - methedStr, argsStr, false, 0, maxFeeLimit, dev001Address, - dev001Key, blockingStubFull); + String txid = + PublicMethod.triggerContract( + PublicMethod.decode58Check(jusdd), + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = - PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); System.out.println(info.toString()); - } @Test(enabled = true) public void justlendMint() { String methedStr = "mint()"; String argsStr = "10000000"; - String jtrx = "TE2RzoSV3wFK99w6J9UnnZ4vLfXYoxvRwP"; //USDD - String txid = PublicMethod.triggerContract(PublicMethod.decode58Check(jtrx), methedStr, argsStr, - false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String jtrx = "TE2RzoSV3wFK99w6J9UnnZ4vLfXYoxvRwP"; // USDD + String txid = + PublicMethod.triggerContract( + PublicMethod.decode58Check(jtrx), + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = - PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); System.out.println(info.toString()); - } // @@ -149,31 +193,45 @@ public void justlendMint() { public void justlendRepayBorrow() { String methedStr = "repayBorrow(uint256)"; String argsStr = "1000000000000"; - String jtrx = "TSXv71Fy5XdL3Rh2QfBoUu3NAaM4sMif8R"; //tusd - String txid = PublicMethod.triggerContract(PublicMethod.decode58Check(jtrx), methedStr, argsStr, - false, 0, maxFeeLimit, dev001Address, dev001Key, blockingStubFull); + String jtrx = "TSXv71Fy5XdL3Rh2QfBoUu3NAaM4sMif8R"; // tusd + String txid = + PublicMethod.triggerContract( + PublicMethod.decode58Check(jtrx), + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = - PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); System.out.println(info.toString()); - } @Test(enabled = true) public void bttcDepositJst() { String methedStr = "depositFor(address,address,bytes)"; - String argsStr = "\"TH48niZfbwHMyqZwEB8wmHfzcvR8ZzJKC6\"," - + "\"TCFLL5dx5ZJdKnWuesXxi1VPwjLVmWZZy9\"," - + "\"0x000000000000000000000000000000000000000000000000000000e8d4a51000\""; - String rootChainManager = "TDgrSuii9e7HLfY1DhEBxkcFa3vrLgS3Gx"; //tusd - String txid = PublicMethod.triggerContract(PublicMethod.decode58Check(rootChainManager), - methedStr, argsStr, false, 0, maxFeeLimit, - dev001Address, dev001Key, blockingStubFull); + String argsStr = + "\"TH48niZfbwHMyqZwEB8wmHfzcvR8ZzJKC6\"," + + "\"TCFLL5dx5ZJdKnWuesXxi1VPwjLVmWZZy9\"," + + "\"0x000000000000000000000000000000000000000000000000000000e8d4a51000\""; + String rootChainManager = "TDgrSuii9e7HLfY1DhEBxkcFa3vrLgS3Gx"; // tusd + String txid = + PublicMethod.triggerContract( + PublicMethod.decode58Check(rootChainManager), + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = - PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); System.out.println(info.toString()); - } @Test(enabled = true) @@ -183,20 +241,24 @@ public void approve() { String argsStr = add + ",-1"; // String token = "TPYmHEhy5n8TCEfYGqW2rPxsghSfzghPDn";//usdd // String token = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t";//usdt - String token = "TXcJ6pCEGKeLEYXrVnLhqpCVuKfV6wgsfC"; //old2pool - String txid = PublicMethod.triggerContract(PublicMethod.decode58Check(token), - methedStr, argsStr, false, 0, maxFeeLimit, dev001Address, - dev001Key, blockingStubFull); + String token = "TXcJ6pCEGKeLEYXrVnLhqpCVuKfV6wgsfC"; // old2pool + String txid = + PublicMethod.triggerContract( + PublicMethod.decode58Check(token), + methedStr, + argsStr, + false, + 0, + maxFeeLimit, + dev001Address, + dev001Key, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional info = - PublicMethod.getTransactionInfoById(txid, blockingStubFull); + Optional info = PublicMethod.getTransactionInfoById(txid, blockingStubFull); System.out.println(info.toString()); - } - /** - * constructor. - */ + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { // PublicMethod.freeResource(dev001Address, dev001Key, fromAddress, blockingStubFull); @@ -205,4 +267,3 @@ public void shutdown() throws InterruptedException { } } } - diff --git a/testcase/src/test/java/stest/tron/wallet/other/deployMainGateway.java b/testcase/src/test/java/stest/tron/wallet/other/deployMainGateway.java index f4b8eee4..901053ba 100644 --- a/testcase/src/test/java/stest/tron/wallet/other/deployMainGateway.java +++ b/testcase/src/test/java/stest/tron/wallet/other/deployMainGateway.java @@ -1,13 +1,11 @@ package stest.tron.wallet.other; -import io.grpc.ManagedChannel; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.protos.Protocol.Account; @@ -17,37 +15,35 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class deployMainGateway extends TronBaseTest { - private final String testDepositTrx = "324a2052e491e99026442d81df4d2777292840c1b3949e20696c49096" - + "c6bacb7"; + private final String testDepositTrx = + "324a2052e491e99026442d81df4d2777292840c1b3949e20696c49096" + "c6bacb7"; private final byte[] testDepositAddress = PublicMethod.getFinalAddress(testDepositTrx); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] depositAddress = ecKey1.getAddress(); String testKeyFordeposit = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - private Long maxFeeLimit = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.maxFeeLimit"); - /** - * constructor. - */ + private Long maxFeeLimit = + Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit"); + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} @Test(enabled = true, description = "deploy Main Chain Gateway") public void test1DepositTrc20001() { PublicMethod.printAddress(testKeyFordeposit); - Assert.assertTrue(PublicMethod - .sendcoin(depositAddress, 1000_000_000L, testDepositAddress, testDepositTrx, - blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + depositAddress, 1000_000_000L, testDepositAddress, testDepositTrx, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Account accountOralce = PublicMethod.queryAccount(depositAddress, blockingStubFull); @@ -55,29 +51,35 @@ public void test1DepositTrc20001() { logger.info("OralceBalance: " + OralceBalance); String contractName = "gateWayContract"; - String code = Configuration.getByPath("testng.conf") - .getString("code.code_MainGateway"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_MainGateway"); + String code = Configuration.getByPath("testng.conf").getString("code.code_MainGateway"); + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_MainGateway"); String parame = "\"" + Base58.encode58Check(testDepositAddress) + "\""; - String deployTxid = PublicMethod - .deployContractWithConstantParame(contractName, abi, code, "constructor(address)", - parame, "", + String deployTxid = + PublicMethod.deployContractWithConstantParame( + contractName, + abi, + code, + "constructor(address)", + parame, + "", maxFeeLimit, - 0L, 100, null, testKeyFordeposit, depositAddress, + 0L, + 100, + null, + testKeyFordeposit, + depositAddress, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(deployTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(deployTxid, blockingStubFull); byte[] mainChainGateway = infoById.get().getContractAddress().toByteArray(); String mainChainGatewayAddress = WalletClient.encode58Check(mainChainGateway); Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertNotNull(mainChainGateway); - SmartContract smartContract = PublicMethod.getContract(mainChainGateway, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(mainChainGateway, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); String outputPath = "./src/test/resources/mainChainGatewayAddress"; @@ -93,7 +95,5 @@ public void test1DepositTrc20001() { } catch (Exception e) { e.printStackTrace(); } - - } - } +} diff --git a/testcase/src/test/java/stest/tron/wallet/other/deploySideGateway.java b/testcase/src/test/java/stest/tron/wallet/other/deploySideGateway.java index c849f824..4f4a87bf 100644 --- a/testcase/src/test/java/stest/tron/wallet/other/deploySideGateway.java +++ b/testcase/src/test/java/stest/tron/wallet/other/deploySideGateway.java @@ -1,13 +1,11 @@ package stest.tron.wallet.other; -import io.grpc.ManagedChannel; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.protos.Protocol.TransactionInfo; @@ -16,36 +14,31 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; -import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; @Slf4j public class deploySideGateway extends TronBaseTest { - private final String testDepositTrx = "324a2052e491e99026442d81df4d2777292840c1b3949e20696c49096" - + "c6bacb7"; + private final String testDepositTrx = + "324a2052e491e99026442d81df4d2777292840c1b3949e20696c49096" + "c6bacb7"; private final byte[] testDepositAddress = PublicMethod.getFinalAddress(testDepositTrx); ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] depositAddress = ecKey1.getAddress(); String testKeyFordeposit = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - private Long maxFeeLimit = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.maxFeeLimit"); - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + private Long maxFeeLimit = + Configuration.getByPath("testng.conf").getLong("defaultParameter.maxFeeLimit"); + private String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + private String url = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); private String fullnode = "127.0.0.1:50151"; - - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { } + public void beforeClass() {} @Test(enabled = true, description = "deploy Side Chain Gateway") public void test1DepositTrc20001() { @@ -53,29 +46,35 @@ public void test1DepositTrc20001() { PublicMethod.printAddress(testKeyFordeposit); String contractName = "gateWaysidechainContract"; - String code = Configuration.getByPath("testng.conf") - .getString("code.code_SideGateway"); - String abi = Configuration.getByPath("testng.conf") - .getString("abi.abi_SideGateway"); + String code = Configuration.getByPath("testng.conf").getString("code.code_SideGateway"); + String abi = Configuration.getByPath("testng.conf").getString("abi.abi_SideGateway"); String parame = "\"" + Base58.encode58Check(testDepositAddress) + "\""; - String deployTxid = PublicMethod - .deployContractWithConstantParame(contractName, abi, code, "constructor(address)", - parame, "", + String deployTxid = + PublicMethod.deployContractWithConstantParame( + contractName, + abi, + code, + "constructor(address)", + parame, + "", maxFeeLimit, - 0L, 100, null, testKeyFordeposit, depositAddress, + 0L, + 100, + null, + testKeyFordeposit, + depositAddress, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionInfoById(deployTxid, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionInfoById(deployTxid, blockingStubFull); byte[] mainChainGateway = infoById.get().getContractAddress().toByteArray(); String mainChainGatewayAddress = WalletClient.encode58Check(mainChainGateway); Assert.assertEquals(0, infoById.get().getResultValue()); Assert.assertNotNull(mainChainGateway); - SmartContract smartContract = PublicMethod.getContract(mainChainGateway, - blockingStubFull); + SmartContract smartContract = PublicMethod.getContract(mainChainGateway, blockingStubFull); Assert.assertNotNull(smartContract.getAbi()); String outputPath = "./src/test/resources/sideChainGatewayAddress"; @@ -91,7 +90,5 @@ public void test1DepositTrc20001() { } catch (Exception e) { e.printStackTrace(); } - - } - } +} diff --git a/testcase/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer001.java b/testcase/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer001.java index 4d16355a..80ccaaa6 100644 --- a/testcase/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer001.java +++ b/testcase/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer001.java @@ -23,72 +23,75 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode -public class WalletTestTransfer001 extends TronBaseTest { private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); +public class WalletTestTransfer001 extends TronBaseTest { + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); - //send account + // send account ECKey ecKey1 = new ECKey(Utils.getRandom()); final byte[] sendAccountAddress = ecKey1.getAddress(); String sendAccountKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - //receipt account + // receipt account ECKey ecKey2 = new ECKey(Utils.getRandom()); final byte[] receiptAccountAddress = ecKey2.getAddress(); String receiptAccountKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); private ManagedChannel searchChannelFull = null; private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; - private String searchFullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private String searchFullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass - public void beforeClass() { searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode) - .usePlaintext() - .build(); + public void beforeClass() { + searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode).usePlaintext().build(); searchBlockingStubFull = WalletGrpc.newBlockingStub(searchChannelFull); } @Test(groups = {"smoke"}) public void testSendCoin() { - //send account + // send account ecKey1 = new ECKey(Utils.getRandom()); final byte[] sendAccountAddress = ecKey1.getAddress(); sendAccountKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - //receipt account + // receipt account ecKey2 = new ECKey(Utils.getRandom()); final byte[] receiptAccountAddress = ecKey2.getAddress(); receiptAccountKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(sendAccountAddress, 90000000000L, - foundationAddress, foundationKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + sendAccountAddress, 90000000000L, foundationAddress, foundationKey, blockingStubFull)); logger.info(receiptAccountKey); - //Test send coin. + // Test send coin. Account sendAccount = PublicMethod.queryAccount(sendAccountKey, blockingStubFull); - Long sendAccountBeforeBalance = sendAccount.getBalance(); + Long sendAccountBeforeBalance = sendAccount.getBalance(); Assert.assertTrue(sendAccountBeforeBalance == 90000000000L); Account receiptAccount = PublicMethod.queryAccount(receiptAccountKey, blockingStubFull); - Long receiptAccountBeforeBalance = receiptAccount.getBalance(); + Long receiptAccountBeforeBalance = receiptAccount.getBalance(); Assert.assertTrue(receiptAccountBeforeBalance == 0); - //Test send coin + // Test send coin PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethod.sendcoin(receiptAccountAddress, 49880000000L, - sendAccountAddress, sendAccountKey, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + receiptAccountAddress, + 49880000000L, + sendAccountAddress, + sendAccountKey, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); sendAccount = PublicMethod.queryAccount(sendAccountKey, blockingStubFull); @@ -100,34 +103,30 @@ public void testSendCoin() { Long receiptAccountAfterBalance = receiptAccount.getBalance(); logger.info(Long.toString(receiptAccountAfterBalance)); Assert.assertTrue(receiptAccountAfterBalance == 49880000000L); - //Send coin failed due to no enough balance. + // Send coin failed due to no enough balance. Assert.assertFalse(sendcoin(toAddress, 9199999999999999999L, foundationAddress, foundationKey)); - //Send coin failed due to the amount is 0. + // Send coin failed due to the amount is 0. Assert.assertFalse(sendcoin(toAddress, 0L, foundationAddress, foundationKey)); - //Send coin failed due to the amount is -1Trx. + // Send coin failed due to the amount is -1Trx. Assert.assertFalse(sendcoin(toAddress, -1000000L, foundationAddress, foundationKey)); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { if (searchChannelFull != null) { + public void shutdown() throws InterruptedException { + if (searchChannelFull != null) { searchChannelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - /** - * constructor. - */ - public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDuration, - String priKey) { + /** constructor. */ + public Boolean freezeBalance( + byte[] addRess, long freezeBalance, long freezeDuration, String priKey) { byte[] address = addRess; long frozenBalance = freezeBalance; long frozenDuration = freezeDuration; - //String priKey = foundationKey; - ECKey temKey = null; + // String priKey = foundationKey; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -136,22 +135,24 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura } ECKey ecKey = temKey; Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - final Long beforeBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); + final Long beforeBlockNum = currentBlock.getBlockHeader().getRawData().getNumber(); Account beforeFronzen = queryAccount(ecKey, blockingStubFull); - Long beforeFrozenBalance = 0L; - //Long beforeBandwidth = beforeFronzen.getBandwidth(); + Long beforeFrozenBalance = 0L; + // Long beforeBandwidth = beforeFronzen.getBandwidth(); if (beforeFronzen.getFrozenCount() != 0) { beforeFrozenBalance = beforeFronzen.getFrozen(0).getFrozenBalance(); - //beforeBandwidth = beforeFronzen.getBandwidth(); - //logger.info(Long.toString(beforeFronzen.getBandwidth())); + // beforeBandwidth = beforeFronzen.getBandwidth(); + // logger.info(Long.toString(beforeFronzen.getBandwidth())); logger.info(Long.toString(beforeFronzen.getFrozen(0).getFrozenBalance())); } - BalanceContract.FreezeBalanceContract.Builder builder = BalanceContract.FreezeBalanceContract - .newBuilder(); + BalanceContract.FreezeBalanceContract.Builder builder = + BalanceContract.FreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess).setFrozenBalance(frozenBalance) + builder + .setOwnerAddress(byteAddreess) + .setFrozenBalance(frozenBalance) .setFrozenDuration(frozenDuration); BalanceContract.FreezeBalanceContract contract = builder.build(); @@ -174,8 +175,8 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura Long afterBlockNum = 0L; Integer wait = 0; while (afterBlockNum < beforeBlockNum + 1 && wait < 10) { - Block currentBlock1 = searchBlockingStubFull - .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); + Block currentBlock1 = + searchBlockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); afterBlockNum = currentBlock1.getBlockHeader().getRawData().getNumber(); wait++; try { @@ -187,28 +188,26 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura } Account afterFronzen = queryAccount(ecKey, searchBlockingStubFull); - Long afterFrozenBalance = afterFronzen.getFrozen(0).getFrozenBalance(); - //Long afterBandwidth = afterFronzen.getBandwidth(); - //logger.info(Long.toString(afterFronzen.getBandwidth())); + Long afterFrozenBalance = afterFronzen.getFrozen(0).getFrozenBalance(); + // Long afterBandwidth = afterFronzen.getBandwidth(); + // logger.info(Long.toString(afterFronzen.getBandwidth())); logger.info(Long.toString(afterFronzen.getFrozen(0).getFrozenBalance())); - //logger.info(Integer.toString(search.getFrozenCount())); + // logger.info(Integer.toString(search.getFrozenCount())); logger.info( - "beforefronen" + beforeFrozenBalance.toString() + " afterfronzen" + afterFrozenBalance - .toString()); + "beforefronen" + + beforeFrozenBalance.toString() + + " afterfronzen" + + afterFrozenBalance.toString()); Assert.assertTrue(afterFrozenBalance - beforeFrozenBalance == freezeBalance); - //Assert.assertTrue(afterBandwidth - beforeBandwidth == freezeBalance * frozen_duration); + // Assert.assertTrue(afterBandwidth - beforeBandwidth == freezeBalance * frozen_duration); return true; - - } - /** - * constructor. - */ + /** constructor. */ public Boolean sendcoin(byte[] to, long amount, byte[] owner, String priKey) { - //String priKey = foundationKey; - ECKey temKey = null; + // String priKey = foundationKey; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -218,8 +217,8 @@ public Boolean sendcoin(byte[] to, long amount, byte[] owner, String priKey) { ECKey ecKey = temKey; Account search = queryAccount(ecKey, blockingStubFull); - BalanceContract.TransferContract.Builder builder = BalanceContract.TransferContract - .newBuilder(); + BalanceContract.TransferContract.Builder builder = + BalanceContract.TransferContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); ByteString bsOwner = ByteString.copyFrom(owner); builder.setToAddress(bsTo); @@ -236,19 +235,17 @@ public Boolean sendcoin(byte[] to, long amount, byte[] owner, String priKey) { return response.getResult(); } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -258,23 +255,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -286,5 +278,3 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer003.java b/testcase/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer003.java index 67b9d1a6..e79e58ae 100644 --- a/testcase/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer003.java +++ b/testcase/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer003.java @@ -29,13 +29,12 @@ import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.CommonParameter; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.Sha256Hash; import stest.tron.wallet.common.client.utils.TransactionUtils; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; - +import stest.tron.wallet.common.client.utils.Utils; @Slf4j @MultiNode @@ -44,11 +43,11 @@ public class WalletTestTransfer003 extends TronBaseTest { private static final long now = System.currentTimeMillis(); private static final String name = "transaction007_" + Long.toString(now); private static Protocol.Transaction sendCoinTransaction; - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); private final Long createUseFee = 100000L; - //get account + // get account ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] sendCoinAddress = ecKey1.getAddress(); String testKeyForSendCoin = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -58,10 +57,11 @@ public class WalletTestTransfer003 extends TronBaseTest { private ManagedChannel channelFull1 = null; private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; private WalletExtensionGrpc.WalletExtensionBlockingStub blockingStubExtension = null; - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String fullnode1 = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); @@ -76,13 +76,15 @@ private static Transaction signTransaction(ECKey ecKey, Transaction transaction) return TransactionUtils.sign(transaction, ecKey); } - /** - * constructor. - */ - public static Protocol.Transaction sendcoin(byte[] to, long amount, byte[] owner, String priKey, + /** constructor. */ + public static Protocol.Transaction sendcoin( + byte[] to, + long amount, + byte[] owner, + String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - //String priKey = foundationKey; - ECKey temKey = null; + // String priKey = foundationKey; + ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); temKey = ECKey.fromPrivate(priK); @@ -90,10 +92,10 @@ public static Protocol.Transaction sendcoin(byte[] to, long amount, byte[] owner ex.printStackTrace(); } final ECKey ecKey = temKey; - //Protocol.Account search = queryAccount(priKey, blockingStubFull); + // Protocol.Account search = queryAccount(priKey, blockingStubFull); - BalanceContract.TransferContract.Builder builder = BalanceContract.TransferContract - .newBuilder(); + BalanceContract.TransferContract.Builder builder = + BalanceContract.TransferContract.newBuilder(); ByteString bsTo = ByteString.copyFrom(to); ByteString bsOwner = ByteString.copyFrom(owner); builder.setToAddress(bsTo); @@ -113,28 +115,23 @@ public static Protocol.Transaction sendcoin(byte[] to, long amount, byte[] owner return transaction; } - /** - * constructor. - */ - + /** constructor. */ @BeforeClass public void beforeClass() { initSolidityChannel(); - logger.info(testKeyForSendCoin); channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext() - .build(); + logger.info(testKeyForSendCoin); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1).usePlaintext().build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubExtension = WalletExtensionGrpc.newBlockingStub(channelSolidity); - } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void test1UseFeeOrNet() { - //get account + // get account ecKey1 = new ECKey(Utils.getRandom()); sendCoinAddress = ecKey1.getAddress(); testKeyForSendCoin = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -143,41 +140,44 @@ public void test1UseFeeOrNet() { newAccountAddress = ecKey2.getAddress(); testKeyForNewAccount = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); - Assert.assertTrue(PublicMethod.sendcoin(sendCoinAddress, 200000L, - foundationAddress, foundationKey, blockingStubFull)); - Long feeNum = 0L; - Long netNum = 0L; - Long sendNum = 0L; - Long feeCost = 0L; - Long times = 0L; + Assert.assertTrue( + PublicMethod.sendcoin( + sendCoinAddress, 200000L, foundationAddress, foundationKey, blockingStubFull)); + Long feeNum = 0L; + Long netNum = 0L; + Long sendNum = 0L; + Long feeCost = 0L; + Long times = 0L; Account sendAccountInfo = PublicMethod.queryAccount(testKeyForSendCoin, blockingStubFull); - final Long beforeBalance = sendAccountInfo.getBalance(); - Long netUsed1 = 0L; - Long netUsed2 = 1L; + final Long beforeBalance = sendAccountInfo.getBalance(); + Long netUsed1 = 0L; + Long netUsed2 = 1L; logger.info("Before test, the account balance is " + Long.toString(beforeBalance)); while (!(netUsed1.equals(netUsed2))) { sendAccountInfo = PublicMethod.queryAccount(testKeyForSendCoin, blockingStubFull); netUsed1 = sendAccountInfo.getFreeNetUsage(); - sendCoinTransaction = sendcoin(foundationAddress, 1L, sendCoinAddress, - testKeyForSendCoin, blockingStubFull); + sendCoinTransaction = + sendcoin(foundationAddress, 1L, sendCoinAddress, testKeyForSendCoin, blockingStubFull); sendAccountInfo = PublicMethod.queryAccount(testKeyForSendCoin, blockingStubFull); netUsed2 = sendAccountInfo.getFreeNetUsage(); if (times++ < 1) { PublicMethod.waitProduceNextBlock(blockingStubFull); - //PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity); - String txId = ByteArray.toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), sendCoinTransaction - .getRawData().toByteArray())); + // PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity); + String txId = + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + sendCoinTransaction.getRawData().toByteArray())); logger.info(txId); ByteString bsTxid = ByteString.copyFrom(ByteArray.fromHexString(txId)); BytesMessage request = BytesMessage.newBuilder().setValue(bsTxid).build(); - TransactionInfo transactionInfo = blockingStubFull.getTransactionInfoById(request); + TransactionInfo transactionInfo = blockingStubFull.getTransactionInfoById(request); Optional getTransactionById = Optional.ofNullable(transactionInfo); - logger.info("solidity block num is " + Long.toString(getTransactionById - .get().getBlockNumber())); + logger.info( + "solidity block num is " + Long.toString(getTransactionById.get().getBlockNumber())); Assert.assertTrue(getTransactionById.get().getBlockNumber() > 0); } @@ -190,39 +190,46 @@ public void test1UseFeeOrNet() { } } Assert.assertTrue(netUsed2 > 4500); - //Next time, use fee - sendCoinTransaction = sendcoin(foundationAddress, 1L, sendCoinAddress, - testKeyForSendCoin, blockingStubFull); + // Next time, use fee + sendCoinTransaction = + sendcoin(foundationAddress, 1L, sendCoinAddress, testKeyForSendCoin, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - //PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity); - String txId = ByteArray.toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), sendCoinTransaction - .getRawData().toByteArray())); + // PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity); + String txId = + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + sendCoinTransaction.getRawData().toByteArray())); logger.info(txId); ByteString bsTxid = ByteString.copyFrom(ByteArray.fromHexString(txId)); BytesMessage request = BytesMessage.newBuilder().setValue(bsTxid).build(); TransactionInfo transactionInfo = blockingStubFull.getTransactionInfoById(request); Optional getTransactionById = Optional.ofNullable(transactionInfo); logger.info(getTransactionById.get().toString()); - logger.info("when use fee, the block num is " + Long.toString(getTransactionById - .get().getBlockNumber())); + logger.info( + "when use fee, the block num is " + + Long.toString(getTransactionById.get().getBlockNumber())); Assert.assertTrue(getTransactionById.get().getFee() > 0); Assert.assertTrue(getTransactionById.get().getBlockNumber() > 0); } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void test2CreateAccountUseFee() { Account sendAccountInfo = PublicMethod.queryAccount(testKeyForSendCoin, blockingStubFull); - final Long beforeBalance = sendAccountInfo.getBalance(); + final Long beforeBalance = sendAccountInfo.getBalance(); logger.info("before balance " + Long.toString(beforeBalance)); - Long times = 0L; - sendCoinTransaction = sendcoin(newAccountAddress, 1L, sendCoinAddress, - testKeyForSendCoin, blockingStubFull); + Long times = 0L; + sendCoinTransaction = + sendcoin(newAccountAddress, 1L, sendCoinAddress, testKeyForSendCoin, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - //PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity); - String txId = ByteArray.toHexString(Sha256Hash.hash(CommonParameter.getInstance() - .isECKeyCryptoEngine(), sendCoinTransaction - .getRawData().toByteArray())); + // PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity); + String txId = + ByteArray.toHexString( + Sha256Hash.hash( + CommonParameter.getInstance().isECKeyCryptoEngine(), + sendCoinTransaction.getRawData().toByteArray())); logger.info(txId); ByteString bsTxid = ByteString.copyFrom(ByteArray.fromHexString(txId)); BytesMessage request = BytesMessage.newBuilder().setValue(bsTxid).build(); @@ -233,12 +240,14 @@ public void test2CreateAccountUseFee() { Assert.assertTrue(getTransactionById.get().getFee() == createUseFee); sendAccountInfo = PublicMethod.queryAccount(testKeyForSendCoin, blockingStubFull); - final Long afterBalance = sendAccountInfo.getBalance(); + final Long afterBalance = sendAccountInfo.getBalance(); logger.info("after balance " + Long.toString(afterBalance)); Assert.assertTrue(afterBalance + 1L + createUseFee == beforeBalance); } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void test3InvalidGetTransactionById() { String txId = ""; ByteString bsTxid = ByteString.copyFrom(ByteArray.fromHexString(txId)); @@ -255,44 +264,41 @@ public void test3InvalidGetTransactionById() { Assert.assertTrue(getTransactionById.get().getRawData().getContractCount() == 0); } - @Test(enabled = true, groups = {"smoke"}) + @Test( + enabled = true, + groups = {"smoke"}) public void test4NoBalanceCanSend() { Long feeNum = 0L; Account sendAccountInfo = PublicMethod.queryAccount(testKeyForSendCoin, blockingStubFull); - Long beforeBalance = sendAccountInfo.getBalance(); + Long beforeBalance = sendAccountInfo.getBalance(); logger.info("Before test, the account balance is " + Long.toString(beforeBalance)); while (feeNum < 250) { - sendCoinTransaction = sendcoin(foundationAddress, 10L, sendCoinAddress, - testKeyForSendCoin, blockingStubFull); + sendCoinTransaction = + sendcoin(foundationAddress, 10L, sendCoinAddress, testKeyForSendCoin, blockingStubFull); feeNum++; } Assert.assertTrue(PublicMethod.waitProduceNextBlock(blockingStubFull)); - } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { if (channelFull1 != null) { + public void shutdown() throws InterruptedException { + if (channelFull1 != null) { channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -302,30 +308,26 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } - /** - * constructor. - */ - public Protocol.Transaction updateAccount(byte[] addressBytes, byte[] accountNameBytes, - String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { + /** constructor. */ + public Protocol.Transaction updateAccount( + byte[] addressBytes, + byte[] accountNameBytes, + String priKey, + WalletGrpc.WalletBlockingStub blockingStubFull) { ECKey temKey = null; try { @@ -356,5 +358,3 @@ public Protocol.Transaction updateAccount(byte[] addressBytes, byte[] accountNam return transaction; } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer004.java b/testcase/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer004.java index 952b1502..bd341939 100644 --- a/testcase/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer004.java +++ b/testcase/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer004.java @@ -1,7 +1,6 @@ package stest.tron.wallet.transfer; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -20,23 +19,22 @@ import stest.tron.wallet.common.client.utils.TransactionUtils; import stest.tron.wallet.common.client.utils.TronBaseTest; - @Slf4j public class WalletTestTransfer004 extends TronBaseTest { private static final long now = System.currentTimeMillis(); - private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); private WalletExtensionGrpc.WalletExtensionBlockingStub blockingStubExtension = null; - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); + private String soliditynode = + Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - /* @Test(enabled = true, groups = {"smoke"}) public void testGetTransactionsByTimestamp() { long start = now - 16400000; @@ -179,38 +177,29 @@ public void testExceptionTimeToGetGetTransactionsByTimestamp() { }*/ - /** - * constructor. - */ - + /** constructor. */ @BeforeClass public void beforeClass() { - initSolidityChannel(); channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext() - .build(); + initSolidityChannel(); + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode).usePlaintext().build(); blockingStubExtension = WalletExtensionGrpc.newBlockingStub(channelSolidity); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass - public void shutdown() throws InterruptedException { } + public void shutdown() throws InterruptedException {} - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); ecKey = ECKey.fromPublicOnly(pubKeyHex); } return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); @@ -220,18 +209,14 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); @@ -247,5 +232,3 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } } - - diff --git a/testcase/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer007.java b/testcase/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer007.java index 4384d0e5..4a95ffc2 100644 --- a/testcase/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer007.java +++ b/testcase/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer007.java @@ -18,70 +18,78 @@ import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; +import stest.tron.wallet.common.client.utils.TronBaseTest; import stest.tron.wallet.common.client.utils.Utils; -import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; @Slf4j @MultiNode -public class WalletTestTransfer007 extends TronBaseTest { private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); - private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); private ManagedChannel searchChannelFull = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidityInFullnode = null; - - private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; private String searchFullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); +public class WalletTestTransfer007 extends TronBaseTest { + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); + private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); + private ManagedChannel searchChannelFull = null; + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidityInFullnode = null; + + private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; + private String searchFullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); private ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] sendAccountAddress = ecKey1.getAddress(); - String sendAccountKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); private ManagedChannel channelSolidityInFullnode = null; /* private String solidityInFullnode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(1);*/ - - /** - * constructor. - */ + String sendAccountKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + private ManagedChannel channelSolidityInFullnode = + null; /* private String solidityInFullnode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(1);*/ + /** constructor. */ @BeforeClass - public void beforeClass() { searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode) - .usePlaintext() - .build(); - searchBlockingStubFull = WalletGrpc.newBlockingStub(searchChannelFull); /* channelSolidityInFullnode = ManagedChannelBuilder.forTarget(solidityInFullnode) - .usePlaintext() - .build(); - blockingStubSolidityInFullnode = WalletSolidityGrpc.newBlockingStub(channelSolidityInFullnode); - */ + public void beforeClass() { + searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode).usePlaintext().build(); + searchBlockingStubFull = WalletGrpc.newBlockingStub(searchChannelFull); + /* + * channelSolidityInFullnode = + * ManagedChannelBuilder.forTarget(solidityInFullnode) + * .usePlaintext() + * .build(); + * blockingStubSolidityInFullnode = WalletSolidityGrpc + * .newBlockingStub(channelSolidityInFullnode); + */ } @Test public void testSendCoin() { initSolidityChannel(); - String transactionId = PublicMethod.sendcoinGetTransactionId(sendAccountAddress, 90000000000L, - fromAddress, foundationKey2, blockingStubFull); - Optional infoById = PublicMethod - .getTransactionById(transactionId, blockingStubFull); - Long timestamptis = PublicMethod.printTransactionRow(infoById.get().getRawData()); - Long timestamptispBlockOne = PublicMethod.getBlock(1, blockingStubFull).getBlockHeader() - .getRawData().getTimestamp(); - Assert.assertTrue(timestamptis >= timestamptispBlockOne); + String transactionId = + PublicMethod.sendcoinGetTransactionId( + sendAccountAddress, 90000000000L, foundationAddress2, foundationKey2, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionById(transactionId, blockingStubFull); + Long timestampFromTxid = PublicMethod.printTransactionRow(infoById.get().getRawData()); + Long timestampFromBlockOne = + PublicMethod.getBlock(1, blockingStubFull).getBlockHeader().getRawData().getTimestamp(); + Assert.assertTrue(timestampFromTxid >= timestampFromBlockOne); } @Test public void testSendCoin2() { - String transactionId = PublicMethod.sendcoinGetTransactionId(sendAccountAddress, 90000000000L, - fromAddress, foundationKey2, blockingStubFull); + String transactionId = + PublicMethod.sendcoinGetTransactionId( + sendAccountAddress, 90000000000L, foundationAddress2, foundationKey2, blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethod - .getTransactionById(transactionId, blockingStubFull); + Optional infoById = + PublicMethod.getTransactionById(transactionId, blockingStubFull); Long timestamptis = PublicMethod.printTransactionRow(infoById.get().getRawData()); - Long timestampBlockOne = PublicMethod.getBlock(1, blockingStubFull).getBlockHeader() - .getRawData().getTimestamp(); + Long timestampBlockOne = + PublicMethod.getBlock(1, blockingStubFull).getBlockHeader().getRawData().getTimestamp(); Assert.assertTrue(timestamptis >= timestampBlockOne); PublicMethod.waitSolidityNodeSynFullNodeData(blockingStubFull, blockingStubSolidity); infoById = PublicMethod.getTransactionById(transactionId, blockingStubSolidity); timestamptis = PublicMethod.printTransactionRow(infoById.get().getRawData()); - timestampBlockOne = PublicMethod.getBlock(1, blockingStubFull).getBlockHeader() - .getRawData().getTimestamp(); + timestampBlockOne = + PublicMethod.getBlock(1, blockingStubFull).getBlockHeader().getRawData().getTimestamp(); Assert.assertTrue(timestamptis >= timestampBlockOne); ByteString bsTxid = ByteString.copyFrom(ByteArray.fromHexString(transactionId)); @@ -94,15 +102,12 @@ public void testSendCoin2() { transactionInfo = blockingStubFull.getTransactionInfoById(request); Assert.assertTrue(transactionInfo.getBlockTimeStamp() >= timestampBlockOne); - //transactionInfo = blockingStubSolidityInFullnode.getTransactionInfoById(request); - //Assert.assertTrue(transactionInfo.getBlockTimeStamp() >= timestampBlockOne); + // transactionInfo = blockingStubSolidityInFullnode.getTransactionInfoById(request); + // Assert.assertTrue(transactionInfo.getBlockTimeStamp() >= timestampBlockOne); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { if (channelFull != null) { @@ -112,5 +117,4 @@ public void shutdown() throws InterruptedException { searchChannelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); } } - } diff --git a/testcase/src/test/java/stest/tron/wallet/updateCompatibility/MultisignOperatorErgodicTest.java b/testcase/src/test/java/stest/tron/wallet/updateCompatibility/MultisignOperatorErgodicTest.java index 2fc5be04..0354fbe6 100644 --- a/testcase/src/test/java/stest/tron/wallet/updateCompatibility/MultisignOperatorErgodicTest.java +++ b/testcase/src/test/java/stest/tron/wallet/updateCompatibility/MultisignOperatorErgodicTest.java @@ -1,14 +1,12 @@ package stest.tron.wallet.updateCompatibility; import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; @@ -27,20 +25,21 @@ import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.PublicMethodForMultiSign; import stest.tron.wallet.common.client.utils.ShieldAddressInfo; -import stest.tron.wallet.common.client.utils.Utils; import stest.tron.wallet.common.client.utils.TronBaseTest; +import stest.tron.wallet.common.client.utils.Utils; + @Slf4j public class MultisignOperatorErgodicTest extends TronBaseTest { - final String updateName = Long.toString(System.currentTimeMillis()); private final String operations = Configuration.getByPath("testng.conf") - .getString("defaultParameter.operations"); + final String updateName = Long.toString(System.currentTimeMillis()); + private final String operations = + Configuration.getByPath("testng.conf").getString("defaultParameter.operations"); String[] permissionKeyString = new String[2]; String[] ownerKeyString = new String[2]; String accountPermissionJson = ""; - String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); + String description = + Configuration.getByPath("testng.conf").getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf").getString("defaultParameter.assetUrl"); Optional shieldAddressInfo; String shieldAddress; List shieldOutList = new ArrayList<>(); @@ -64,27 +63,30 @@ public class MultisignOperatorErgodicTest extends TronBaseTest { String multisignAccountKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); ECKey ecKey4 = new ECKey(Utils.getRandom()); byte[] newAddress = ecKey4.getAddress(); - String newKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); private String foundationZenTokenKey = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenOwnerKey"); + String newKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); + private String foundationZenTokenKey = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenOwnerKey"); byte[] foundationZenTokenAddress = PublicMethod.getFinalAddress(foundationZenTokenKey); - private String zenTokenId = Configuration.getByPath("testng.conf") - .getString("defaultParameter.zenTokenId"); + private String zenTokenId = + Configuration.getByPath("testng.conf").getString("defaultParameter.zenTokenId"); private byte[] tokenId = zenTokenId.getBytes(); - private Long zenTokenFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.zenTokenFee"); - private long multiSignFee = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.multiSignFee"); + private Long zenTokenFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.zenTokenFee"); + private long multiSignFee = + Configuration.getByPath("testng.conf").getLong("defaultParameter.multiSignFee"); private Long costTokenAmount = 8 * zenTokenFee; private Long sendTokenAmount = 3 * zenTokenFee; - /** - * constructor. - */ + /** constructor. */ @BeforeSuite(enabled = false) public void beforeSuite() { if (PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getCreateTime() == 0) { - PublicMethod.sendcoin(foundationZenTokenAddress, 20480000000000L, fromAddress, - foundationKey2, blockingStubFull); + PublicMethod.sendcoin( + foundationZenTokenAddress, + 20480000000000L, + fromAddress, + foundationKey2, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); String name = "shieldToken"; Long start = System.currentTimeMillis() + 20000; @@ -92,9 +94,23 @@ public void beforeSuite() { Long totalSupply = 15000000000000001L; String description = "This asset issue is use for exchange transaction stress"; String url = "This asset issue is use for exchange transaction stress"; - PublicMethod.createAssetIssue(foundationZenTokenAddress, name, totalSupply, 1, 1, - start, end, 1, description, url, 1000L, 1000L, - 1L, 1L, foundationZenTokenKey, blockingStubFull); + PublicMethod.createAssetIssue( + foundationZenTokenAddress, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 1000L, + 1000L, + 1L, + 1L, + foundationZenTokenKey, + blockingStubFull); PublicMethod.waitProduceNextBlock(blockingStubFull); Account getAssetIdFromThisAccount = PublicMethod.queryAccount(foundationZenTokenAddress, blockingStubFull); @@ -103,111 +119,218 @@ public void beforeSuite() { } } - /** - * constructor. - */ - + /** constructor. */ @BeforeClass(enabled = true) - public void beforeClass() { Assert.assertTrue(PublicMethod.sendcoin(multisignAccountAddress, 1000_000_000_000L, fromAddress, - foundationKey2, blockingStubFull)); - //updatepermission权限,账户交易所需钱等前置条件写在这 + public void beforeClass() { + Assert.assertTrue( + PublicMethod.sendcoin( + multisignAccountAddress, + 1000_000_000_000L, + fromAddress, + foundationKey2, + blockingStubFull)); + // updatepermission权限,账户交易所需钱等前置条件写在这 permissionKeyString[0] = manager1Key; permissionKeyString[1] = manager2Key; ownerKeyString[0] = manager1Key; ownerKeyString[1] = manager2Key; accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; logger.info(accountPermissionJson); - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, multisignAccountAddress, multisignAccountKey, - blockingStubFull, new String[]{multisignAccountKey})); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, + multisignAccountAddress, + multisignAccountKey, + blockingStubFull, + new String[] {multisignAccountKey})); PublicMethod.waitProduceNextBlock(blockingStubFull); } @Test(enabled = true) public void test001MultiSignGodicAccountTypeTransaction() { Assert.assertTrue( - PublicMethodForMultiSign.setAccountId1(("" + System.currentTimeMillis()).getBytes(), - multisignAccountAddress, multisignAccountKey, 2, blockingStubFull, + PublicMethodForMultiSign.setAccountId1( + ("" + System.currentTimeMillis()).getBytes(), + multisignAccountAddress, + multisignAccountKey, + 2, + blockingStubFull, + permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.createAccountWhtiPermissionId( + multisignAccountAddress, + newAddress, + multisignAccountKey, + blockingStubFull, + 2, + permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.sendcoinWithPermissionId( + newAddress, + 100L, + multisignAccountAddress, + 2, + multisignAccountKey, + blockingStubFull, + permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.freezeBalanceWithPermissionId( + multisignAccountAddress, + 1000000L, + 0, + 2, + multisignAccountKey, + blockingStubFull, + permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.freezeBalanceGetEnergyWithPermissionId( + multisignAccountAddress, + 1000000L, + 0, + 1, + multisignAccountKey, + blockingStubFull, + 2, + permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.freezeBalanceForReceiverWithPermissionId( + multisignAccountAddress, + 1000000L, + 0, + 0, + ByteString.copyFrom(newAddress), + multisignAccountKey, + blockingStubFull, + 2, + permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.unFreezeBalanceWithPermissionId( + multisignAccountAddress, + multisignAccountKey, + 0, + null, + 2, + blockingStubFull, + permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.unFreezeBalanceWithPermissionId( + multisignAccountAddress, + multisignAccountKey, + 0, + newAddress, + 2, + blockingStubFull, + permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.updateAccountWithPermissionId( + multisignAccountAddress, + updateName.getBytes(), + multisignAccountKey, + blockingStubFull, + 2, permissionKeyString)); - Assert.assertTrue(PublicMethodForMultiSign.createAccountWhtiPermissionId( - multisignAccountAddress, newAddress, multisignAccountKey, blockingStubFull, - 2, permissionKeyString)); - Assert.assertTrue(PublicMethodForMultiSign.sendcoinWithPermissionId( - newAddress, 100L, multisignAccountAddress, 2, - multisignAccountKey, blockingStubFull, permissionKeyString)); - Assert.assertTrue(PublicMethodForMultiSign.freezeBalanceWithPermissionId( - multisignAccountAddress, 1000000L, 0, 2, - multisignAccountKey, blockingStubFull, permissionKeyString)); - Assert.assertTrue(PublicMethodForMultiSign.freezeBalanceGetEnergyWithPermissionId( - multisignAccountAddress, 1000000L, 0, 1, - multisignAccountKey, blockingStubFull, 2, permissionKeyString)); - Assert.assertTrue(PublicMethodForMultiSign.freezeBalanceForReceiverWithPermissionId( - multisignAccountAddress, 1000000L, 0, 0, - ByteString.copyFrom(newAddress), - multisignAccountKey, blockingStubFull, 2, permissionKeyString)); - Assert.assertTrue(PublicMethodForMultiSign.unFreezeBalanceWithPermissionId( - multisignAccountAddress, multisignAccountKey, 0, null, - 2, blockingStubFull, permissionKeyString)); - Assert.assertTrue(PublicMethodForMultiSign.unFreezeBalanceWithPermissionId( - multisignAccountAddress, multisignAccountKey, 0, newAddress, - 2, blockingStubFull, permissionKeyString)); - Assert.assertTrue(PublicMethodForMultiSign.updateAccountWithPermissionId( - multisignAccountAddress, updateName.getBytes(), multisignAccountKey, blockingStubFull, - 2, permissionKeyString)); } @Test(enabled = true) public void test002MultiSignGodicContractTypeTransaction() { Long maxFeeLimit = 1000000000L; - //String contractName = "StorageAndCpu" + Integer.toString(randNum); + // String contractName = "StorageAndCpu" + Integer.toString(randNum); String filePath = "./src/test/resources/soliditycode/walletTestMultiSign004.sol"; String contractName = "timeoutTest"; HashMap retMap = PublicMethod.getBycodeAbi(filePath, contractName); String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - byte[] contractAddress = PublicMethodForMultiSign.deployContractWithPermissionId( - contractName, abi, code, "", maxFeeLimit, - 0L, 100, maxFeeLimit, "0", 0L, null, - multisignAccountKey, multisignAccountAddress, blockingStubFull, permissionKeyString, 2); + byte[] contractAddress = + PublicMethodForMultiSign.deployContractWithPermissionId( + contractName, + abi, + code, + "", + maxFeeLimit, + 0L, + 100, + maxFeeLimit, + "0", + 0L, + null, + multisignAccountKey, + multisignAccountAddress, + blockingStubFull, + permissionKeyString, + 2); PublicMethod.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethod.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString() != null); String txid; String initParmes = "\"" + "930" + "\""; - txid = PublicMethodForMultiSign.triggerContractWithPermissionId(contractAddress, - "testUseCpu(uint256)", initParmes, false, - 0, maxFeeLimit, "0", 0L, multisignAccountAddress, - multisignAccountKey, blockingStubFull, permissionKeyString, 2); + txid = + PublicMethodForMultiSign.triggerContractWithPermissionId( + contractAddress, + "testUseCpu(uint256)", + initParmes, + false, + 0, + maxFeeLimit, + "0", + 0L, + multisignAccountAddress, + multisignAccountKey, + blockingStubFull, + permissionKeyString, + 2); PublicMethod.waitProduceNextBlock(blockingStubFull); Assert.assertTrue( PublicMethodForMultiSign.updateSettingWithPermissionId( - contractAddress, 50, multisignAccountKey, - multisignAccountAddress, 2, blockingStubFull, permissionKeyString)); + contractAddress, + 50, + multisignAccountKey, + multisignAccountAddress, + 2, + blockingStubFull, + permissionKeyString)); Assert.assertTrue( PublicMethodForMultiSign.updateEnergyLimitWithPermissionId( - contractAddress, 50, multisignAccountKey, - multisignAccountAddress, 2, blockingStubFull, permissionKeyString)); + contractAddress, + 50, + multisignAccountKey, + multisignAccountAddress, + 2, + blockingStubFull, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethodForMultiSign - .clearContractAbi(contractAddress, multisignAccountAddress, multisignAccountKey, - blockingStubFull, 2, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.clearContractAbi( + contractAddress, + multisignAccountAddress, + multisignAccountKey, + blockingStubFull, + 2, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - } @Test(enabled = true) @@ -220,31 +343,60 @@ public void test003MultiSignGodicTokenTypeTransaction() { Long end = System.currentTimeMillis() + 1000000000; logger.info("try create asset issue"); - Assert.assertTrue(PublicMethodForMultiSign - .createAssetIssueWithpermissionId(multisignAccountAddress, name, totalSupply, 1, - 1, start, end, 1, description, url, 2000L, 2000L, - 1L, 1L, multisignAccountKey, blockingStubFull, 2, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.createAssetIssueWithpermissionId( + multisignAccountAddress, + name, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 2000L, + 2000L, + 1L, + 1L, + multisignAccountKey, + blockingStubFull, + 2, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Assert.assertTrue(PublicMethodForMultiSign.unFreezeAsset(multisignAccountAddress, + // Assert.assertTrue(PublicMethodForMultiSign.unFreezeAsset(multisignAccountAddress, // multisignAccountKey,2,ownerKeyString,blockingStubFull)); Account getAssetIdFromOwnerAccount; - getAssetIdFromOwnerAccount = PublicMethod.queryAccount( - multisignAccountAddress, blockingStubFull); + getAssetIdFromOwnerAccount = + PublicMethod.queryAccount(multisignAccountAddress, blockingStubFull); assetAccountId1 = getAssetIdFromOwnerAccount.getAssetIssuedID(); - Assert.assertTrue(PublicMethodForMultiSign.transferAssetWithpermissionId(manager1Address, - assetAccountId1.toByteArray(), 10, multisignAccountAddress, - multisignAccountKey, blockingStubFull, 2, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.transferAssetWithpermissionId( + manager1Address, + assetAccountId1.toByteArray(), + 10, + multisignAccountAddress, + multisignAccountKey, + blockingStubFull, + 2, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethodForMultiSign - .updateAssetWithPermissionId(multisignAccountAddress, description.getBytes(), url.getBytes(), - 100L, 100L, multisignAccountKey, - 2, blockingStubFull, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.updateAssetWithPermissionId( + multisignAccountAddress, + description.getBytes(), + url.getBytes(), + 100L, + 100L, + multisignAccountKey, + 2, + blockingStubFull, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - } @Test(enabled = true) @@ -260,106 +412,172 @@ public void test004MultiSignGodicExchangeTypeTransaction() { String name1 = "exchange001_1_" + Long.toString(now); final long totalSupply = 1000000001L; - org.junit.Assert - .assertTrue(PublicMethod.sendcoin(secondExchange001Address, 10240000000L, fromAddress, - foundationKey2, blockingStubFull)); - org.junit.Assert.assertTrue(PublicMethod - .freezeBalanceForReceiver(fromAddress, 100000000000L, 0, 0, + org.junit.Assert.assertTrue( + PublicMethod.sendcoin( + secondExchange001Address, 10240000000L, fromAddress, foundationKey2, blockingStubFull)); + org.junit.Assert.assertTrue( + PublicMethod.freezeBalanceForReceiver( + fromAddress, + 100000000000L, + 0, + 0, ByteString.copyFrom(secondExchange001Address), - foundationKey2, blockingStubFull)); + foundationKey2, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); Long start = System.currentTimeMillis() + 5000L; Long end = System.currentTimeMillis() + 5000000L; - org.junit.Assert - .assertTrue(PublicMethod.createAssetIssue(secondExchange001Address, name2, totalSupply, 1, - 1, start, end, 1, description, url, 10000L, 10000L, - 1L, 1L, secondExchange001Key, blockingStubFull)); + org.junit.Assert.assertTrue( + PublicMethod.createAssetIssue( + secondExchange001Address, + name2, + totalSupply, + 1, + 1, + start, + end, + 1, + description, + url, + 10000L, + 10000L, + 1L, + 1L, + secondExchange001Key, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); listExchange = PublicMethod.getExchangeList(blockingStubFull); exchangeId = listExchange.get().getExchangesCount(); Account getAssetIdFromThisAccount; - getAssetIdFromThisAccount = PublicMethod.queryAccount(multisignAccountAddress, blockingStubFull); + getAssetIdFromThisAccount = + PublicMethod.queryAccount(multisignAccountAddress, blockingStubFull); assetAccountId1 = getAssetIdFromThisAccount.getAssetIssuedID(); - getAssetIdFromThisAccount = PublicMethod - .queryAccount(secondExchange001Address, blockingStubFull); + getAssetIdFromThisAccount = + PublicMethod.queryAccount(secondExchange001Address, blockingStubFull); assetAccountId2 = getAssetIdFromThisAccount.getAssetIssuedID(); firstAccount = PublicMethod.queryAccount(multisignAccountAddress, blockingStubFull); - org.junit.Assert.assertTrue(PublicMethod.transferAsset( - multisignAccountAddress, assetAccountId2.toByteArray(), - secondTransferAssetToFirstAccountNum, secondExchange001Address, - secondExchange001Key, blockingStubFull)); + org.junit.Assert.assertTrue( + PublicMethod.transferAsset( + multisignAccountAddress, assetAccountId2.toByteArray(), + secondTransferAssetToFirstAccountNum, secondExchange001Address, + secondExchange001Key, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); org.junit.Assert.assertTrue( PublicMethodForMultiSign.exchangeCreate1( - assetAccountId1.toByteArray(), firstTokenInitialBalance, - assetAccountId2.toByteArray(), secondTokenInitialBalance, multisignAccountAddress, - multisignAccountKey, blockingStubFull, 2, permissionKeyString)); + assetAccountId1.toByteArray(), + firstTokenInitialBalance, + assetAccountId2.toByteArray(), + secondTokenInitialBalance, + multisignAccountAddress, + multisignAccountKey, + blockingStubFull, + 2, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); listExchange = PublicMethod.getExchangeList(blockingStubFull); exchangeId = listExchange.get().getExchangesCount(); org.junit.Assert.assertTrue( PublicMethodForMultiSign.injectExchange1( - exchangeId, assetAccountId1.toByteArray(), 100, - multisignAccountAddress, multisignAccountKey, blockingStubFull, 2, permissionKeyString)); + exchangeId, + assetAccountId1.toByteArray(), + 100, + multisignAccountAddress, + multisignAccountKey, + blockingStubFull, + 2, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); org.junit.Assert.assertTrue( PublicMethodForMultiSign.exchangeWithdraw1( - exchangeId, assetAccountId1.toByteArray(), 200, - multisignAccountAddress, multisignAccountKey, blockingStubFull, 2, permissionKeyString)); + exchangeId, + assetAccountId1.toByteArray(), + 200, + multisignAccountAddress, + multisignAccountKey, + blockingStubFull, + 2, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); firstAccount = PublicMethod.queryAccount(multisignAccountAddress, blockingStubFull); org.junit.Assert.assertTrue( - PublicMethodForMultiSign - .exchangeTransaction1(exchangeId, assetAccountId1.toByteArray(), 50, 1, - multisignAccountAddress, multisignAccountKey, blockingStubFull, - 2, permissionKeyString)); + PublicMethodForMultiSign.exchangeTransaction1( + exchangeId, + assetAccountId1.toByteArray(), + 50, + 1, + multisignAccountAddress, + multisignAccountKey, + blockingStubFull, + 2, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); firstAccount = PublicMethod.queryAccount(multisignAccountAddress, blockingStubFull); - Assert.assertTrue(PublicMethodForMultiSign.participateAssetIssueWithPermissionId( - secondExchange001Address, - assetAccountId2.toByteArray(), 1, multisignAccountAddress, multisignAccountKey, 2, - blockingStubFull, ownerKeyString)); - + Assert.assertTrue( + PublicMethodForMultiSign.participateAssetIssueWithPermissionId( + secondExchange001Address, + assetAccountId2.toByteArray(), + 1, + multisignAccountAddress, + multisignAccountKey, + 2, + blockingStubFull, + ownerKeyString)); } @Test(enabled = true) public void test005MultiSignGodicShieldTransaction() { - Assert.assertTrue(PublicMethod.transferAsset(multisignAccountAddress, tokenId, - costTokenAmount, foundationZenTokenAddress, foundationZenTokenKey, blockingStubFull)); - //Args.setFullNodeAllowShieldedTransaction(true); + Assert.assertTrue( + PublicMethod.transferAsset( + multisignAccountAddress, + tokenId, + costTokenAmount, + foundationZenTokenAddress, + foundationZenTokenKey, + blockingStubFull)); + // Args.setFullNodeAllowShieldedTransaction(true); shieldAddressInfo = PublicMethod.generateShieldAddress(); shieldAddress = shieldAddressInfo.get().getAddress(); logger.info("shieldAddress:" + shieldAddress); - final Long beforeAssetBalance = PublicMethod.getAssetIssueValue(multisignAccountAddress, - PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), - blockingStubFull); - final Long beforeBalance = PublicMethod - .queryAccount(multisignAccountAddress, blockingStubFull).getBalance(); - final Long beforeNetUsed = PublicMethod - .getAccountResource(multisignAccountAddress, blockingStubFull).getFreeNetUsed(); + final Long beforeAssetBalance = + PublicMethod.getAssetIssueValue( + multisignAccountAddress, + PublicMethod.queryAccount(foundationZenTokenKey, blockingStubFull).getAssetIssuedID(), + blockingStubFull); + final Long beforeBalance = + PublicMethod.queryAccount(multisignAccountAddress, blockingStubFull).getBalance(); + final Long beforeNetUsed = + PublicMethod.getAccountResource(multisignAccountAddress, blockingStubFull).getFreeNetUsed(); String memo = "aaaaaaa"; - shieldOutList = PublicMethod.addShieldOutputList(shieldOutList, shieldAddress, - "" + (sendTokenAmount - zenTokenFee), memo); + shieldOutList = + PublicMethod.addShieldOutputList( + shieldOutList, shieldAddress, "" + (sendTokenAmount - zenTokenFee), memo); - Assert.assertTrue(PublicMethodForMultiSign.sendShieldCoin( - multisignAccountAddress, sendTokenAmount, - null, null, - shieldOutList, - null, 0, - multisignAccountKey, blockingStubFull, 2, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.sendShieldCoin( + multisignAccountAddress, + sendTokenAmount, + null, + null, + shieldOutList, + null, + 0, + multisignAccountKey, + blockingStubFull, + 2, + permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); } @@ -373,41 +591,61 @@ public void test006MultiSignGodicWitnessTransaction() { PublicMethod.printAddress(newKey); accountPermissionJson = "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}]}," + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," - + "\"operations\":\"" + operations + "\"," + + "\"operations\":\"" + + operations + + "\"," + "\"keys\":[" - + "{\"address\":\"" + PublicMethod.getAddressString(manager1Key) + "\",\"weight\":1}," - + "{\"address\":\"" + PublicMethod.getAddressString(manager2Key) + "\",\"weight\":1}" + + "{\"address\":\"" + + PublicMethod.getAddressString(manager1Key) + + "\",\"weight\":1}," + + "{\"address\":\"" + + PublicMethod.getAddressString(manager2Key) + + "\",\"weight\":1}" + "]}]}"; - Assert.assertTrue(PublicMethod.sendcoin(newAddress, 1000000_000_000L, fromAddress, - foundationKey2, blockingStubFull)); + Assert.assertTrue( + PublicMethod.sendcoin( + newAddress, 1000000_000_000L, fromAddress, foundationKey2, blockingStubFull)); logger.info(accountPermissionJson); - Assert.assertTrue(PublicMethodForMultiSign - .accountPermissionUpdate(accountPermissionJson, newAddress, newKey, - blockingStubFull, new String[]{newKey})); + Assert.assertTrue( + PublicMethodForMultiSign.accountPermissionUpdate( + accountPermissionJson, newAddress, newKey, blockingStubFull, new String[] {newKey})); PublicMethod.waitProduceNextBlock(blockingStubFull); long now = System.currentTimeMillis(); String url = "MultiSign001_" + Long.toString(now) + ".com"; - Assert.assertTrue(PublicMethodForMultiSign.createWitness(url, newAddress, - newKey, 2, permissionKeyString, blockingStubFull)); + Assert.assertTrue( + PublicMethodForMultiSign.createWitness( + url, newAddress, newKey, 2, permissionKeyString, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - Assert - .assertTrue(PublicMethodForMultiSign.updateWitness2(newAddress, "newWitness.com".getBytes(), - newKey, 2, permissionKeyString, blockingStubFull)); + Assert.assertTrue( + PublicMethodForMultiSign.updateWitness2( + newAddress, + "newWitness.com".getBytes(), + newKey, + 2, + permissionKeyString, + blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); String voteStr = Base58.encode58Check(newAddress); HashMap smallVoteMap = new HashMap(); smallVoteMap.put(voteStr, "1"); - Assert.assertTrue(PublicMethodForMultiSign.voteWitnessWithPermissionId( - smallVoteMap, multisignAccountAddress, multisignAccountKey, blockingStubFull, - 2, permissionKeyString)); - + Assert.assertTrue( + PublicMethodForMultiSign.voteWitnessWithPermissionId( + smallVoteMap, + multisignAccountAddress, + multisignAccountKey, + blockingStubFull, + 2, + permissionKeyString)); } @Test(enabled = true) @@ -417,36 +655,40 @@ public void test007MultiSignGodicProposalTypeTransaction() { HashMap proposalMap = new HashMap(); proposalMap.put(0L, 81000L); Assert.assertTrue( - PublicMethodForMultiSign.createProposalWithPermissionId(newAddress, newKey, - proposalMap, 2, blockingStubFull, permissionKeyString)); + PublicMethodForMultiSign.createProposalWithPermissionId( + newAddress, newKey, proposalMap, 2, blockingStubFull, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Get proposal list + // Get proposal list ProposalList proposalList = blockingStubFull.listProposals(EmptyMessage.newBuilder().build()); Optional listProposals = Optional.ofNullable(proposalList); final Integer proposalId = listProposals.get().getProposalsCount(); logger.info(Integer.toString(proposalId)); - Assert.assertTrue(PublicMethodForMultiSign.approveProposalWithPermission( - newAddress, newKey, proposalId, - true, 2, blockingStubFull, permissionKeyString)); + Assert.assertTrue( + PublicMethodForMultiSign.approveProposalWithPermission( + newAddress, newKey, proposalId, true, 2, blockingStubFull, permissionKeyString)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Delete proposal list after approve - Assert.assertTrue(PublicMethodForMultiSign.deleteProposalWithPermissionId( - newAddress, newKey, proposalId, 2, blockingStubFull, permissionKeyString)); + // Delete proposal list after approve + Assert.assertTrue( + PublicMethodForMultiSign.deleteProposalWithPermissionId( + newAddress, newKey, proposalId, 2, blockingStubFull, permissionKeyString)); } @Test(enabled = true) public void test008MultiSignGodicWithdrawBanlanceTransaction() { long MaintenanceTimeInterval = -1L; - ChainParameters chainParameters = blockingStubFull - .getChainParameters(EmptyMessage.newBuilder().build()); + ChainParameters chainParameters = + blockingStubFull.getChainParameters(EmptyMessage.newBuilder().build()); Optional getChainParameters = Optional.ofNullable(chainParameters); logger.info(Long.toString(getChainParameters.get().getChainParameterCount())); for (Integer i = 0; i < getChainParameters.get().getChainParameterCount(); i++) { logger.info("Index is:" + i); logger.info(getChainParameters.get().getChainParameter(i).getKey()); logger.info(Long.toString(getChainParameters.get().getChainParameter(i).getValue())); - if (getChainParameters.get().getChainParameter(i).getKey() + if (getChainParameters + .get() + .getChainParameter(i) + .getKey() .equals("getMaintenanceTimeInterval")) { MaintenanceTimeInterval = getChainParameters.get().getChainParameter(i).getValue(); break; @@ -458,8 +700,8 @@ public void test008MultiSignGodicWithdrawBanlanceTransaction() { } catch (InterruptedException e) { e.printStackTrace(); } - Assert.assertTrue(PublicMethodForMultiSign.withdrawBalance(newAddress, newKey, - 2, permissionKeyString, blockingStubFull)); + Assert.assertTrue( + PublicMethodForMultiSign.withdrawBalance( + newAddress, newKey, 2, permissionKeyString, blockingStubFull)); } } - diff --git a/testcase/src/test/java/stest/tron/wallet/witness/WalletTestWitness001.java b/testcase/src/test/java/stest/tron/wallet/witness/WalletTestWitness001.java index 9c8492e6..26636c8c 100644 --- a/testcase/src/test/java/stest/tron/wallet/witness/WalletTestWitness001.java +++ b/testcase/src/test/java/stest/tron/wallet/witness/WalletTestWitness001.java @@ -29,41 +29,40 @@ import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.ByteArray; import stest.tron.wallet.common.client.utils.ECKey; +import stest.tron.wallet.common.client.utils.MultiNode; import stest.tron.wallet.common.client.utils.PublicMethod; import stest.tron.wallet.common.client.utils.TransactionUtils; - import stest.tron.wallet.common.client.utils.TronBaseTest; -import stest.tron.wallet.common.client.utils.MultiNode; + @Slf4j @MultiNode public class WalletTestWitness001 extends TronBaseTest { { fullnode = config.getStringList("fullnode.ip.list").get(1); - } private final String testKey003 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); + } + + private final String testKey003 = + Configuration.getByPath("testng.conf").getString("foundationAccount.key2"); private final byte[] toAddress = PublicMethod.getFinalAddress(testKey003); - private final byte[] witnessAddress = PublicMethod.getFinalAddress(witnessKey); private ManagedChannel searchChannelFull = null; private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; private String searchFullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); + private final byte[] witnessAddress = PublicMethod.getFinalAddress(witnessKey); + private ManagedChannel searchChannelFull = null; + private WalletGrpc.WalletBlockingStub searchBlockingStubFull = null; + private String searchFullnode = + Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(1); public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass public void beforeClass() { WalletClient.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); - logger.info("Pre fix byte ===== " + WalletClient.getAddressPreFixByte()); searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode) - .usePlaintext() - .build(); + logger.info("Pre fix byte ===== " + WalletClient.getAddressPreFixByte()); + searchChannelFull = ManagedChannelBuilder.forTarget(searchFullnode).usePlaintext().build(); searchBlockingStubFull = WalletGrpc.newBlockingStub(searchChannelFull); } @@ -82,31 +81,28 @@ public void testVoteWitness() { HashMap wrongDropMap = new HashMap(); wrongDropMap.put(voteStr, "10000000000000000"); - //Vote failed due to no freeze balance. - //Assert.assertFalse(VoteWitness(smallVoteMap, NO_FROZEN_ADDRESS, no_frozen_balance_testKey)); + // Vote failed due to no freeze balance. + // Assert.assertFalse(VoteWitness(smallVoteMap, NO_FROZEN_ADDRESS, no_frozen_balance_testKey)); - //Freeze balance to get vote ability. - Assert.assertTrue(PublicMethod.freezeBalanceGetTronPower(fromAddress, 1200000L, 3L, - 2,null,foundationKey2, blockingStubFull)); + // Freeze balance to get vote ability. + Assert.assertTrue( + PublicMethod.freezeBalanceGetTronPower( + foundationAddress2, 1200000L, 3L, 2, null, foundationKey2, blockingStubFull)); PublicMethod.waitProduceNextBlock(blockingStubFull); - //Vote failed when the vote is large than the freeze balance. - Assert.assertFalse(voteWitness(veryLargeMap, fromAddress, foundationKey2)); - //Vote failed due to 0 vote. - Assert.assertFalse(voteWitness(zeroVoteMap, fromAddress, foundationKey2)); - //Vote failed duo to -1 vote. - Assert.assertFalse(voteWitness(wrongVoteMap, fromAddress, foundationKey2)); - //Vote is so large, vote failed. - Assert.assertFalse(voteWitness(wrongDropMap, fromAddress, foundationKey2)); - - //Vote success - Assert.assertTrue(voteWitness(smallVoteMap, fromAddress, foundationKey2)); - + // Vote failed when the vote is large than the freeze balance. + Assert.assertFalse(voteWitness(veryLargeMap, foundationAddress2, foundationKey2)); + // Vote failed due to 0 vote. + Assert.assertFalse(voteWitness(zeroVoteMap, foundationAddress2, foundationKey2)); + // Vote failed duo to -1 vote. + Assert.assertFalse(voteWitness(wrongVoteMap, foundationAddress2, foundationKey2)); + // Vote is so large, vote failed. + Assert.assertFalse(voteWitness(wrongDropMap, foundationAddress2, foundationKey2)); + + // Vote success + Assert.assertTrue(voteWitness(smallVoteMap, foundationAddress2, foundationKey2)); } - /** - * constructor. - */ - + /** constructor. */ @AfterClass public void shutdown() throws InterruptedException { if (channelFull != null) { @@ -117,10 +113,7 @@ public void shutdown() throws InterruptedException { } } - /** - * constructor. - */ - + /** constructor. */ public Boolean voteWitness(HashMap witness, byte[] addRess, String priKey) { ECKey temKey = null; @@ -142,8 +135,7 @@ public Boolean voteWitness(HashMap witness, byte[] addRess, Stri for (String addressBase58 : witness.keySet()) { String value = witness.get(addressBase58); final long count = Long.parseLong(value); - VoteWitnessContract.Vote.Builder voteBuilder = VoteWitnessContract.Vote - .newBuilder(); + VoteWitnessContract.Vote.Builder voteBuilder = VoteWitnessContract.Vote.newBuilder(); byte[] address = WalletClient.decodeFromBase58Check(addressBase58); logger.info("address ====== " + ByteArray.toHexString(address)); if (address == null) { @@ -174,7 +166,7 @@ public Boolean voteWitness(HashMap witness, byte[] addRess, Stri e.printStackTrace(); } Account afterVote = queryAccount(ecKey, searchBlockingStubFull); - //Long afterVoteNum = afterVote.getVotes(0).getVoteCount(); + // Long afterVoteNum = afterVote.getVotes(0).getVoteCount(); for (String key : witness.keySet()) { for (int j = 0; j < afterVote.getVotesCount(); j++) { logger.info(Long.toString(Long.parseLong(witness.get(key)))); @@ -183,26 +175,22 @@ public Boolean voteWitness(HashMap witness, byte[] addRess, Stri logger.info("catch it"); logger.info(Long.toString(afterVote.getVotes(j).getVoteCount())); logger.info(Long.toString(Long.parseLong(witness.get(key)))); - Assert - .assertTrue(afterVote.getVotes(j).getVoteCount() == Long.parseLong(witness.get(key))); + Assert.assertTrue( + afterVote.getVotes(j).getVoteCount() == Long.parseLong(witness.get(key))); } - } } return true; } - /** - * constructor. - */ - - public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDuration, - String priKey) { + /** constructor. */ + public Boolean freezeBalance( + byte[] addRess, long freezeBalance, long freezeDuration, String priKey) { byte[] address = addRess; long frozenBalance = freezeBalance; long frozenDuration = freezeDuration; - //String priKey = foundationKey2; + // String priKey = foundationKey2; ECKey temKey = null; try { BigInteger priK = new BigInteger(priKey, 16); @@ -214,18 +202,20 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura Account beforeFronzen = queryAccount(ecKey, blockingStubFull); Long beforeFrozenBalance = 0L; - //Long beforeBandwidth = beforeFronzen.getBandwidth(); + // Long beforeBandwidth = beforeFronzen.getBandwidth(); if (beforeFronzen.getFrozenCount() != 0) { beforeFrozenBalance = beforeFronzen.getFrozen(0).getFrozenBalance(); - //beforeBandwidth = beforeFronzen.getBandwidth(); - //logger.info(Long.toString(beforeFronzen.getBandwidth())); + // beforeBandwidth = beforeFronzen.getBandwidth(); + // logger.info(Long.toString(beforeFronzen.getBandwidth())); logger.info(Long.toString(beforeFronzen.getFrozen(0).getFrozenBalance())); } FreezeBalanceContract.Builder builder = FreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddreess).setFrozenBalance(frozenBalance) + builder + .setOwnerAddress(byteAddreess) + .setFrozenBalance(frozenBalance) .setFrozenDuration(frozenDuration); FreezeBalanceContract contract = builder.build(); @@ -245,19 +235,20 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura } Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); - Block searchCurrentBlock = searchBlockingStubFull.getNowBlock(GrpcAPI - .EmptyMessage.newBuilder().build()); + Block searchCurrentBlock = + searchBlockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); Integer wait = 0; while (searchCurrentBlock.getBlockHeader().getRawData().getNumber() - < currentBlock.getBlockHeader().getRawData().getNumber() + 1 && wait < 30) { + < currentBlock.getBlockHeader().getRawData().getNumber() + 1 + && wait < 30) { try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } logger.info("Another fullnode didn't syn the first fullnode data"); - searchCurrentBlock = searchBlockingStubFull.getNowBlock(GrpcAPI - .EmptyMessage.newBuilder().build()); + searchCurrentBlock = + searchBlockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); wait++; if (wait == 9) { logger.info("Didn't syn,skip to next case."); @@ -266,30 +257,30 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura Account afterFronzen = queryAccount(ecKey, searchBlockingStubFull); Long afterFrozenBalance = afterFronzen.getFrozen(0).getFrozenBalance(); - //Long afterBandwidth = afterFronzen.getBandwidth(); - //logger.info(Long.toString(afterFronzen.getBandwidth())); - //logger.info(Long.toString(afterFronzen.getFrozen(0).getFrozenBalance())); - //logger.info(Integer.toString(search.getFrozenCount())); + // Long afterBandwidth = afterFronzen.getBandwidth(); + // logger.info(Long.toString(afterFronzen.getBandwidth())); + // logger.info(Long.toString(afterFronzen.getFrozen(0).getFrozenBalance())); + // logger.info(Integer.toString(search.getFrozenCount())); logger.info( - "afterfrozenbalance =" + Long.toString(afterFrozenBalance) + "beforefrozenbalance = " - + beforeFrozenBalance + "freezebalance = " + Long.toString(freezeBalance)); - //logger.info("afterbandwidth = " + Long.toString(afterBandwidth) + " beforebandwidth = + "afterfrozenbalance =" + + Long.toString(afterFrozenBalance) + + "beforefrozenbalance = " + + beforeFrozenBalance + + "freezebalance = " + + Long.toString(freezeBalance)); + // logger.info("afterbandwidth = " + Long.toString(afterBandwidth) + " beforebandwidth = // " + Long.toString(beforeBandwidth)); - //if ((afterFrozenBalance - beforeFrozenBalance != freezeBalance) || + // if ((afterFrozenBalance - beforeFrozenBalance != freezeBalance) || // (freezeBalance * frozen_duration -(afterBandwidth - beforeBandwidth) !=0)){ // logger.info("After 20 second, two node still not synchronous"); // } Assert.assertTrue(afterFrozenBalance - beforeFrozenBalance == freezeBalance); - //Assert.assertTrue(freezeBalance * frozen_duration - (afterBandwidth - + // Assert.assertTrue(freezeBalance * frozen_duration - (afterBandwidth - // beforeBandwidth) <= 1000000); return true; - } - /** - * constructor. - */ - + /** constructor. */ public boolean unFreezeBalance(byte[] addRess, String priKey) { byte[] address = addRess; @@ -303,8 +294,7 @@ public boolean unFreezeBalance(byte[] addRess, String priKey) { ECKey ecKey = temKey; Account search = queryAccount(ecKey, blockingStubFull); - UnfreezeBalanceContract.Builder builder = UnfreezeBalanceContract - .newBuilder(); + UnfreezeBalanceContract.Builder builder = UnfreezeBalanceContract.newBuilder(); ByteString byteAddreess = ByteString.copyFrom(address); builder.setOwnerAddress(byteAddreess); @@ -323,14 +313,11 @@ public boolean unFreezeBalance(byte[] addRess, String priKey) { return response.getResult(); } - /** - * constructor. - */ - + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; @@ -346,25 +333,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ - + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ - + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -376,4 +356,3 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { return TransactionUtils.sign(transaction, ecKey); } } - diff --git a/testcase/src/test/java/stest/tron/wallet/witness/WalletTestWitness002.java b/testcase/src/test/java/stest/tron/wallet/witness/WalletTestWitness002.java index 240cbb4e..505f6d25 100644 --- a/testcase/src/test/java/stest/tron/wallet/witness/WalletTestWitness002.java +++ b/testcase/src/test/java/stest/tron/wallet/witness/WalletTestWitness002.java @@ -10,7 +10,6 @@ import org.apache.commons.lang3.StringUtils; import org.bouncycastle.util.encoders.Hex; import org.testng.Assert; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.tron.api.GrpcAPI; @@ -25,29 +24,26 @@ import stest.tron.wallet.common.client.WalletClient; import stest.tron.wallet.common.client.utils.ECKey; import stest.tron.wallet.common.client.utils.TransactionUtils; - import stest.tron.wallet.common.client.utils.TronBaseTest; + @Slf4j -public class WalletTestWitness002 extends TronBaseTest { private ManagedChannel channelSolidity = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; public static String loadPubKey() { +public class WalletTestWitness002 extends TronBaseTest { + public static String loadPubKey() { char[] buf = new char[0x100]; return String.valueOf(buf, 32, 130); } - - - /** - * constructor. - */ - + /** constructor. */ @BeforeClass public void beforeClass() { initSolidityChannel(); - WalletClient.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); } + WalletClient.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } @Test(enabled = true) public void testQueryAllWitness() { - GrpcAPI.WitnessList witnesslist = blockingStubFull - .listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build()); + GrpcAPI.WitnessList witnesslist = + blockingStubFull.listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build()); Optional result = Optional.ofNullable(witnesslist); if (result.isPresent()) { GrpcAPI.WitnessList witnessList = result.get(); @@ -64,7 +60,7 @@ public void testQueryAllWitness() { for (int j = 0; j < result.get().getWitnessesCount(); j++) { Assert.assertFalse(result.get().getWitnesses(j).getAddress().isEmpty()); Assert.assertFalse(result.get().getWitnesses(j).getUrl().isEmpty()); - //Assert.assertTrue(result.get().getWitnesses(j).getLatestSlotNum() > 0); + // Assert.assertTrue(result.get().getWitnesses(j).getLatestSlotNum() > 0); result.get().getWitnesses(j).getUrlBytes(); result.get().getWitnesses(j).getLatestBlockNum(); result.get().getWitnesses(j).getLatestSlotNum(); @@ -72,7 +68,7 @@ public void testQueryAllWitness() { result.get().getWitnesses(j).getTotalProduced(); } - //Improve coverage. + // Improve coverage. witnesslist.equals(result.get()); witnesslist.hashCode(); witnesslist.getSerializedSize(); @@ -81,8 +77,8 @@ public void testQueryAllWitness() { @Test(enabled = true) public void testSolidityQueryAllWitness() { - GrpcAPI.WitnessList solidityWitnessList = blockingStubSolidity - .listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build()); + GrpcAPI.WitnessList solidityWitnessList = + blockingStubSolidity.listWitnesses(GrpcAPI.EmptyMessage.newBuilder().build()); Optional result = Optional.ofNullable(solidityWitnessList); if (result.isPresent()) { GrpcAPI.WitnessList witnessList = result.get(); @@ -101,14 +97,12 @@ public void testSolidityQueryAllWitness() { Assert.assertFalse(result.get().getWitnesses(j).getUrl().isEmpty()); } } - /** - * constructor. - */ + /** constructor. */ public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) { byte[] address; if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] + String pubKey = loadPubKey(); // 04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; @@ -124,25 +118,18 @@ public byte[] getAddress(ECKey ecKey) { return ecKey.getAddress(); } - /** - * constructor. - */ - + /** constructor. */ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { ByteString addressBs = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBs).build(); return blockingStubFull.getAccount(request); } - /** - * constructor. - */ - + /** constructor. */ public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { NumberMessage.Builder builder = NumberMessage.newBuilder(); builder.setNum(blockNum); return blockingStubFull.getBlockByNum(builder.build()); - } private Transaction signTransaction(ECKey ecKey, Transaction transaction) { @@ -157,9 +144,8 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { class WitnessComparator implements Comparator { public int compare(Object o1, Object o2) { - return Long - .compare(((Protocol.Witness) o2).getVoteCount(), ((Protocol.Witness) o1).getVoteCount()); + return Long.compare( + ((Protocol.Witness) o2).getVoteCount(), ((Protocol.Witness) o1).getVoteCount()); } } } - diff --git a/testcase/src/test/resources/daily-build-main.xml b/testcase/src/test/resources/daily-build-main.xml index 1b0dd8e4..16f606b6 100644 --- a/testcase/src/test/resources/daily-build-main.xml +++ b/testcase/src/test/resources/daily-build-main.xml @@ -2,7 +2,6 @@ - diff --git a/testcase/src/test/resources/daily-build.xml b/testcase/src/test/resources/daily-build.xml index a0cea129..e69396b9 100644 --- a/testcase/src/test/resources/daily-build.xml +++ b/testcase/src/test/resources/daily-build.xml @@ -1,6 +1,9 @@ + + + diff --git a/testcase/src/test/resources/testng.conf b/testcase/src/test/resources/testng.conf index 35a08664..1e64971c 100644 --- a/testcase/src/test/resources/testng.conf +++ b/testcase/src/test/resources/testng.conf @@ -203,7 +203,6 @@ defaultParameter = { zenTrc20TokenOwnerKey = ede941a01eb8234866f60c7e8e95db4614bb0d05298d82bae0abea81f1861046 jsonRpcOwnerKey = dbc78781ad27f3751358333412d5edc85b13e5eee129a1a77f7232baadafae0e blackHoleAddress = THmtHi1Rzq4gSKYGEKv1DPkV7au6xU1AUB - ReportFlag = "Serial Case" }